Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #4

Merged
merged 6 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.1.0</version>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>io.papermc</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class TaggerNationLib extends JavaPlugin {

public static TaggerNationLib plugin;
public static Placeholder papiHook;
@Getter
public static SpigotMessenger messenger;
public static MiniMessage miniMessage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ConfigManager {
private File file;
private FileConfiguration config;
private final Plugin plugin;
private String configVersion;

/**
* Initializes the Config.
Expand Down Expand Up @@ -85,6 +86,15 @@ public ConfigManager(Plugin plugin, String fileName, String path, boolean force,
this.config = YamlConfiguration.loadConfiguration(this.file);
}

/**
* Set the version of the config. useful for updating the config.
* @param configVersion Version of the config
* @return ConfigManager
*/
public ConfigManager setConfigVersion(String configVersion) {
this.configVersion = configVersion;
return this;
}
/**
* Get Initialized file
* @return File object
Expand Down Expand Up @@ -141,17 +151,16 @@ public void copy( boolean force, String path) {

/**
* Update the Config with the newer version of the file
* @param currentVersion String
* @param versionPath String
*/
public void updateConfig(@NotNull String currentVersion, @NotNull String versionPath) {
public void updateConfig( @NotNull String versionPath) {
String version = null;
try {
version = this.getString(versionPath);
}catch (NullPointerException e) {
plugin.getLogger().info("No version found in config.yml... Creating new version of the config");
}
if (version == null || !version.equals(currentVersion)) {
if (version == null || !version.equals(this.configVersion)) {
File newFile = new File(file.getParentFile(), "old_" + version + "_" + getFile().getName());
File oldFile = getFile();
if (oldFile.renameTo(newFile)) {
Expand Down Expand Up @@ -179,7 +188,7 @@ public void update(String path, Object value) {
}

/**
* Set the given path with given value.
* Set the given path with given value. And save the config.
* @param path String
* @param value Object
*/
Expand All @@ -206,6 +215,15 @@ public List<String> getStringList(String path) {
return config.getStringList(path);
}

/**
* Add value to list of strings
* @param path Path to add string with node
* @param value String to add to list
*/
public void addToStringList(String path, String value) {
set(path,getStringList(path).add(value));
save();
}
/**
* Get the given path as a boolean.
* @param path String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package com.taggernation.taggernationlib.updatechecker;

import com.google.gson.Gson;
import com.taggernation.taggernationlib.logger.Logger;
import com.taggernation.taggernationlib.updatechecker.downloads.DownloadManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -56,7 +55,7 @@ public void setUpdate(Update update) {
private boolean opNotify = false;
private final URL url;
private DownloadManager downloadManager = null;
Gson gson = new Gson();
public Gson gson = new Gson();

private void setReader(InputStreamReader reader) {
this.reader = reader;
Expand All @@ -81,53 +80,6 @@ public UpdateChecker(Plugin plugin, URL url, int interval) throws IOException {
this.update = gson.fromJson(reader, Update.class);
}

private void processMessage() {
List<String> formatter = new ArrayList<>();
for (String list : update.message) {
if (list.contains("{pluginName}")) {
list = list.replace("{pluginName}", plugin.getName());
}
if (list.contains("{pluginVersion}")) {
list = list.replace("{pluginVersion}", plugin.getDescription().getVersion());
}
if (list.contains("{updateLink}")) {
list = list.replace("{updateLink}", update.updateLink);
}
if (list.contains("{latestVersion}")) {
list = list.replace("{latestVersion}", update.version);
}
if (list.contains("{changeLog}")) {
list = list.replace("{changeLog}", String.join("\n", update.changeLog));
}
if (list.contains("{type}")) {
list = list.replace("{type}", getUpdateType());
}
formatter.add(list);
}
if (Double.parseDouble(update.version) <= Double.parseDouble(plugin.getDescription().getVersion())) {
message = Collections.singletonList("No updates found for " + plugin.getName() + ".");
} else {
message = formatter;
}
}

private String getUpdateType() {
if (update.hotFix) {
return "Hotfix";
} else if (update.bugFix) {
return "Bugfix";
} else if (update.newFeature) {
return "New Feature";
} else {
return "Update";
}

}

public List<String> getMessage() {
return message;
}

/**
* Set Interval to check for an update in ticks.
*
Expand Down Expand Up @@ -229,13 +181,11 @@ private void checkForUpdate() {
public void run() {
processMessage();
for (Player player : Bukkit.getOnlinePlayers()) {
if (Bukkit.getOnlinePlayers().size() > 0 && player.hasPermission("greetings.update")) {
for (final String message : instance.getMessage()) {
messenger.sendMessage(player, message);
}
if (Bukkit.getOnlinePlayers().size() > 0 && player.hasPermission(getNotificationPermission())) {
getMessage().forEach(message -> messenger.sendMessage(player,message));
}
}
new Logger(plugin).info(message, true);
getMessage().forEach(message -> messenger.sendConsoleMessage(message));
try {
reader = new InputStreamReader(url.openStream());
setReader(reader);
Expand All @@ -252,4 +202,50 @@ public void run() {
}
}.runTaskTimerAsynchronously(plugin, 250, interval);
}

private void processMessage() {
List<String> formatter = new ArrayList<>();
update.message.forEach(list -> {
if (list.contains("{pluginName}")) {
list = list.replace("{pluginName}", plugin.getName());
}
if (list.contains("{pluginVersion}")) {
list = list.replace("{pluginVersion}", plugin.getDescription().getVersion());
}
if (list.contains("{updateLink}")) {
list = list.replace("{updateLink}", update.updateLink);
}
if (list.contains("{latestVersion}")) {
list = list.replace("{latestVersion}", update.version);
}
if (list.contains("{changeLog}")) {
list = list.replace("{changeLog}", String.join("\n", update.changeLog));
}
if (list.contains("{type}")) {
list = list.replace("{type}", getUpdateType());
}
formatter.add(list);
});
if (Double.parseDouble(update.version) <= Double.parseDouble(plugin.getDescription().getVersion())) {
message = Collections.singletonList("No updates found for " + plugin.getName() + ".");
} else {
message = formatter;
}
}

private String getUpdateType() {
if (update.hotFix) {
return "Hotfix";
} else if (update.bugFix) {
return "Bugfix";
} else if (update.newFeature) {
return "New Feature";
} else {
return "Update";
}

}
public List<String> getMessage() {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import static com.taggernation.taggernationlib.TaggerNationLib.messenger;


public class UpdateListener implements Listener {

private final UpdateChecker instance;
Expand All @@ -39,9 +40,7 @@ public void playerJoinNotification(PlayerJoinEvent event) {
if ((player.isOp() && instance.isOpNotificationEnabled()) ||
(instance.getNotificationPermission() != null &&
player.hasPermission(instance.getNotificationPermission()))) {
for (final String message : instance.getMessage()) {
messenger.sendMessage(player, message);
}
instance.getMessage().forEach(message -> messenger.sendMessage(player, message));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;


@SuppressWarnings("unused")
public class DownloadManager {

URL downloadUrl;
Expand Down

This file was deleted.

3 changes: 2 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: TaggerNationLib
version: '${project.version}'
main: com.taggernation.taggernationlib.TaggerNationLib
api-version: 1.13
api-version: 1.13
discription: TaggerNationLib