Better config modification checker.

This commit is contained in:
Mateus 2019-07-24 12:26:44 +01:00
parent ae41395e5f
commit b6a166739b
18 changed files with 266 additions and 148 deletions

58
pom.xml
View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.mattstudios.plugins</groupId>
<artifactId>citizens-cmd</artifactId>
<version>2.3.2</version>
<version>2.3.3</version>
<packaging>jar</packaging>
<name>CitizensCMD</name>
@ -14,6 +14,12 @@
<description>citizens-cmd</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spigot.version>1.14.4-R0.1-SNAPSHOT</spigot.version>
<citizens.version>2.0.25-SNAPSHOT</citizens.version>
<papi.version>2.10.2</papi.version>
<vault.version>da407c0059</vault.version>
<jsonmsg.version>1.0.0</jsonmsg.version>
<utils.version>636229e</utils.version>
</properties>
<build>
@ -59,10 +65,6 @@
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>rayzr-repo</id>
<url>https://cdn.rawgit.com/Rayzr522/maven-repo/master/</url>
@ -82,46 +84,50 @@
</repositories>
<dependencies>
<!-- Provided -->
<!-- Spigot API -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14.3-R0.1-SNAPSHOT</version>
<version>${spigot.version}</version>
<scope>provided</scope>
</dependency>
<!-- Citizens API -->
<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>citizensapi</artifactId>
<version>2.0.25-SNAPSHOT</version>
<version>${citizens.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.rayzr522</groupId>
<artifactId>jsonmessage</artifactId>
<version>1.0.0</version>
</dependency>
<!-- PAPI API -->
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.2</version>
<version>${papi.version}</version>
<scope>provided</scope>
</dependency>
<!-- Vault API -->
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>da407c0059</version>
<version>${vault.version}</version>
<scope>provided</scope>
</dependency>
<!-- Compile -->
<!-- Json message repo -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>13.0</version>
<groupId>me.rayzr522</groupId>
<artifactId>jsonmessage</artifactId>
<version>${jsonmsg.version}</version>
</dependency>
<!-- My utils -->
<dependency>
<groupId>com.github.ipsk</groupId>
<artifactId>MattUtils</artifactId>
<version>${utils.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
</project>

View File

@ -18,10 +18,16 @@
package me.mattstudios.citizenscmd;
import lombok.Getter;
import lombok.Setter;
import me.mattstudios.citizenscmd.api.CitizensCMDAPI;
import me.mattstudios.citizenscmd.commands.*;
import me.mattstudios.citizenscmd.commands.CMDAdd;
import me.mattstudios.citizenscmd.commands.CMDCooldown;
import me.mattstudios.citizenscmd.commands.CMDEdit;
import me.mattstudios.citizenscmd.commands.CMDHelp;
import me.mattstudios.citizenscmd.commands.CMDList;
import me.mattstudios.citizenscmd.commands.CMDPermission;
import me.mattstudios.citizenscmd.commands.CMDPrice;
import me.mattstudios.citizenscmd.commands.CMDReload;
import me.mattstudios.citizenscmd.commands.CMDRemove;
import me.mattstudios.citizenscmd.commands.base.CommandHandler;
import me.mattstudios.citizenscmd.files.CooldownHandler;
import me.mattstudios.citizenscmd.files.DataHandler;
@ -47,8 +53,10 @@ import java.util.HashMap;
import java.util.Objects;
import java.util.stream.Stream;
@Getter
@Setter
import static me.mattstudios.utils.MessageUtils.color;
import static me.mattstudios.utils.MessageUtils.info;
import static me.mattstudios.utils.YamlUtils.copyDefaults;
public final class CitizensCMD extends JavaPlugin {
/**
@ -61,9 +69,7 @@ public final class CitizensCMD extends JavaPlugin {
private CooldownHandler cooldownHandler = null;
private PermissionsManager permissionsManager = null;
@Getter
private static CitizensCMDAPI api;
@Getter
private static Economy economy = null;
private boolean papi = false;
@ -79,8 +85,8 @@ public final class CitizensCMD extends JavaPlugin {
public void onEnable() {
Util.checkOldConfig(this);
saveDefaultConfig();
copyDefaults(getClassLoader().getResourceAsStream("config.yml"), new File(getDataFolder().getPath(), "config.yml"));
if (!hasCitizens() && getConfig().getBoolean("citizens-check")) {
Util.disablePlugin(this);
@ -92,7 +98,7 @@ public final class CitizensCMD extends JavaPlugin {
new Metrics(this);
Util.info(Util.color(Util.TAG + "&3Citizens&cCMD &8&o" + getDescription().getVersion() + " &8By &3Mateus Moreira &c@LichtHund"));
info(color(Util.TAG + "&3Citizens&cCMD &8&o" + getDescription().getVersion() + " &8By &3Mateus Moreira &c@LichtHund"));
permissionsManager = new PermissionsManager(this);
@ -111,22 +117,22 @@ public final class CitizensCMD extends JavaPlugin {
if (hasPAPI()) {
switch (lang.getLanguage()) {
case "en":
Util.info(Util.color(Util.TAG + "&7Using &aPlaceholderAPI&7!"));
info(color(Util.TAG + "&7Using &aPlaceholderAPI&7!"));
break;
case "pt":
Util.info(Util.color(Util.TAG + "&7Usando &aPlaceholderAPI&7!"));
info(color(Util.TAG + "&7Usando &aPlaceholderAPI&7!"));
break;
case "ro":
Util.info(Util.color(Util.TAG + "&7Folositi &aPlaceholderAPI&7!"));
info(color(Util.TAG + "&7Folositi &aPlaceholderAPI&7!"));
break;
case "bg":
Util.info(Util.color(Util.TAG + "&7Използвайки &aPlaceholderAPI&7!"));
info(color(Util.TAG + "&7Използвайки &aPlaceholderAPI&7!"));
break;
case "no":
Util.info(Util.color(Util.TAG + "&7Bruk &aPlaceholderAPI&7!"));
info(color(Util.TAG + "&7Bruk &aPlaceholderAPI&7!"));
break;
case "ch":
Util.info(Util.color(Util.TAG + "&7运用 &aPlaceholderAPI&7!"));
info(color(Util.TAG + "&7运用 &aPlaceholderAPI&7!"));
break;
}
papi = true;
@ -135,22 +141,22 @@ public final class CitizensCMD extends JavaPlugin {
if (setupEconomy()) {
switch (lang.getLanguage()) {
case "en":
Util.info(Util.color(Util.TAG + "&7Using &aVault&7!"));
info(color(Util.TAG + "&7Using &aVault&7!"));
break;
case "pt":
Util.info(Util.color(Util.TAG + "&7Usando &aVault&7!"));
info(color(Util.TAG + "&7Usando &aVault&7!"));
break;
case "ro":
Util.info(Util.color(Util.TAG + "&7Folositi &aVault&7!"));
info(color(Util.TAG + "&7Folositi &aVault&7!"));
break;
case "bg":
Util.info(Util.color(Util.TAG + "&7Използвайки &aVault&7!"));
info(color(Util.TAG + "&7Използвайки &aVault&7!"));
break;
case "no":
Util.info(Util.color(Util.TAG + "&7Bruk &aVault&7!"));
info(color(Util.TAG + "&7Bruk &aVault&7!"));
break;
case "ch":
Util.info(Util.color(Util.TAG + "&7运用 &aVault&7!"));
info(color(Util.TAG + "&7运用 &aVault&7!"));
break;
}
}
@ -180,29 +186,29 @@ public final class CitizensCMD extends JavaPlugin {
newVersion = updater.getLatestVersion();
switch (lang.getLanguage()) {
case "en":
Util.info(Util.color(Util.TAG + "&cA new version of CitizensCMD is now available:"));
info(color(Util.TAG + "&cA new version of CitizensCMD is now available:"));
break;
case "pt":
Util.info(Util.color(Util.TAG + "&cA nova versão de CitizensCMD está disponivel:"));
info(color(Util.TAG + "&cA nova versão de CitizensCMD está disponivel:"));
break;
case "ro":
Util.info(Util.color(Util.TAG + "&cO noua versiune a CitizensCMD este acum valabila:"));
info(color(Util.TAG + "&cO noua versiune a CitizensCMD este acum valabila:"));
break;
case "bg":
Util.info(Util.color(Util.TAG + "&cНалична е нова версия на CitizensCMD:"));
info(color(Util.TAG + "&cНалична е нова версия на CitizensCMD:"));
break;
case "no":
Util.info(Util.color(Util.TAG + "&cEn ny versjon av CitizensCMD er nå tilgjengelig:"));
info(color(Util.TAG + "&cEn ny versjon av CitizensCMD er nå tilgjengelig:"));
break;
case "ch":
Util.info(Util.color(Util.TAG + "&cCitizensCMD的新版本现已推出:"));
info(color(Util.TAG + "&cCitizensCMD的新版本现已推出:"));
break;
}
Util.info(Util.color(Util.TAG + "&b&o" + updater.getResourceURL()));
info(color(Util.TAG + "&b&o" + updater.getResourceURL()));
}
} catch (Exception e) {
// If it can't check for an update, tell the user and throw an error.
Util.info("Could not check for updates! Stacktrace:");
info("Could not check for updates! Stacktrace:");
e.printStackTrace();
}
}
@ -263,7 +269,7 @@ public final class CitizensCMD extends JavaPlugin {
try {
pm.registerEvents(new NPCListener(this), this);
} catch (Exception ex) {
Util.info(Util.color("&cCould not register clone event, please update your Citizens."));
info(color("&cCould not register clone event, please update your Citizens."));
}
}
@ -350,4 +356,142 @@ public final class CitizensCMD extends JavaPlugin {
public boolean papiEnabled() {
return papi;
}
/**
* Gets the language that is selected on the config
*
* @return returns the language
*/
public LangHandler getLang() {
return lang;
}
/**
* Gets if or not should alert player of new update on join
*
* @return Returns update status
*/
public boolean getUpdateStatus() {
return updateStatus;
}
/**
* Sets new update status from scheduler
*
* @param newUpdateStatus New boolean with the update status;
*/
public void setUpdateStatus(boolean newUpdateStatus) {
this.updateStatus = newUpdateStatus;
}
/**
* Gets String with new version
*
* @return the new version
*/
public String getNewVersion() {
return newVersion;
}
/**
* Sets the new version string
*
* @param newVersion the new version to be set
*/
public void setNewVersion(String newVersion) {
this.newVersion = newVersion;
}
/**
* Gets the NPC data to be used in other classes without needing to open the file
*
* @return returns the DataHandler class
*/
public DataHandler getDataHandler() {
return dataHandler;
}
/**
* Gets the cooldown handler to check for cooldown informations
*
* @return Returns the cooldown handler
*/
public CooldownHandler getCooldownHandler() {
return cooldownHandler;
}
/**
* Gets the permission manager to set and unset permission
*
* @return the permission manager class
*/
public PermissionsManager getPermissionsManager() {
return permissionsManager;
}
/**
* Gets the economy to be used
*
* @return Returns the economy
*/
public static Economy getEconomy() {
return economy;
}
/**
* Gets the hashmap with the players waiting to confirm the NPC payment
*
* @return returns the list of players
*/
public HashMap<String, Boolean> getWaitingList() {
return waitingList;
}
/**
* Checks if player needs to shift or not to confirm payment
*
* @return Returns the boolean of whether or not players should shift
*/
public boolean shouldShift() {
return shift;
}
/**
* Sets the new shifting rule
*
* @param shift The new shifting rule
*/
public void setShift(boolean shift) {
this.shift = shift;
}
/**
* Gets the display format to be used
*
* @return Returns either SHORT, MEDIUM OR FULL
*/
public DisplayFormat getDisplayFormat() {
return displayFormat;
}
/**
* Sets the new display format when reloading
*
* @param displayFormat The new display format
*/
public void setDisplayFormat(DisplayFormat displayFormat) {
this.displayFormat = displayFormat;
}
public CitizensCMDAPI getApi() {
return api;
}
public boolean isShift() {
return shift;
}
public boolean isUpdateStatus() {
return updateStatus;
}
}

View File

@ -26,10 +26,10 @@ import org.bukkit.entity.Player;
import java.util.Arrays;
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
import static me.mattstudios.citizenscmd.utility.Util.color;
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
import static me.mattstudios.citizenscmd.utility.Util.notDouble;
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
import static me.mattstudios.utils.MessageUtils.color;
import static me.mattstudios.utils.NumbersUtils.isDouble;
public class CMDAdd extends CommandBase {
@ -81,7 +81,7 @@ public class CMDAdd extends CommandBase {
continue;
}
if (notDouble(commandsArray[i + 1])) {
if (!isDouble(commandsArray[i + 1])) {
hasDelayError = true;
continue;
}

View File

@ -24,10 +24,10 @@ import me.mattstudios.citizenscmd.paths.Path;
import org.bukkit.entity.Player;
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
import static me.mattstudios.citizenscmd.utility.Util.color;
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
import static me.mattstudios.citizenscmd.utility.Util.notInteger;
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
import static me.mattstudios.utils.MessageUtils.color;
import static me.mattstudios.utils.NumbersUtils.isInteger;
public class CMDCooldown extends CommandBase {
@ -43,7 +43,7 @@ public class CMDCooldown extends CommandBase {
if (npcNotSelected(plugin, player)) return;
if (notInteger(args[0])) {
if (!isInteger(args[0])) {
player.sendMessage(color(HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.INVALID_COOLDOWN));
return;

View File

@ -27,10 +27,10 @@ import org.bukkit.entity.Player;
import java.util.Arrays;
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
import static me.mattstudios.citizenscmd.utility.Util.color;
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
import static me.mattstudios.citizenscmd.utility.Util.notInteger;
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
import static me.mattstudios.utils.MessageUtils.color;
import static me.mattstudios.utils.NumbersUtils.isInteger;
public class CMDEdit extends CommandBase {
@ -47,7 +47,7 @@ public class CMDEdit extends CommandBase {
if (npcNotSelected(plugin, player)) return;
if (notInteger(args[2])) {
if (!isInteger(args[2])) {
player.sendMessage(color(HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.INVALID_ID_NUMBER));
return;

View File

@ -25,7 +25,7 @@ import me.rayzr522.jsonmessage.JSONMessage;
import org.bukkit.entity.Player;
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
import static me.mattstudios.citizenscmd.utility.Util.color;
import static me.mattstudios.utils.MessageUtils.color;
/**
* Thank you GlareMasters for creating this class as an example!

View File

@ -29,9 +29,9 @@ import java.util.ArrayList;
import java.util.List;
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
import static me.mattstudios.citizenscmd.utility.Util.color;
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
import static me.mattstudios.utils.MessageUtils.color;
public class CMDList extends CommandBase {

View File

@ -24,9 +24,9 @@ import me.mattstudios.citizenscmd.paths.Path;
import org.bukkit.entity.Player;
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
import static me.mattstudios.citizenscmd.utility.Util.color;
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
import static me.mattstudios.utils.MessageUtils.color;
public class CMDPermission extends CommandBase {

View File

@ -24,10 +24,10 @@ import me.mattstudios.citizenscmd.paths.Path;
import org.bukkit.entity.Player;
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
import static me.mattstudios.citizenscmd.utility.Util.color;
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
import static me.mattstudios.citizenscmd.utility.Util.notDouble;
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
import static me.mattstudios.utils.MessageUtils.color;
import static me.mattstudios.utils.NumbersUtils.isDouble;
public class CMDPrice extends CommandBase {
@ -44,7 +44,7 @@ public class CMDPrice extends CommandBase {
if (npcNotSelected(plugin, player)) return;
if (notDouble(args[0])) {
if (!isDouble(args[0])) {
player.sendMessage(color(HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.INVALID_PRICE));
return;

View File

@ -28,7 +28,7 @@ import org.bukkit.entity.Player;
import java.util.Objects;
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
import static me.mattstudios.citizenscmd.utility.Util.color;
import static me.mattstudios.utils.MessageUtils.color;
public class CMDReload extends CommandBase {

View File

@ -25,10 +25,10 @@ import me.mattstudios.citizenscmd.utility.EnumTypes;
import org.bukkit.entity.Player;
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
import static me.mattstudios.citizenscmd.utility.Util.color;
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
import static me.mattstudios.citizenscmd.utility.Util.notInteger;
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
import static me.mattstudios.utils.MessageUtils.color;
import static me.mattstudios.utils.NumbersUtils.isInteger;
public class CMDRemove extends CommandBase {
@ -45,7 +45,7 @@ public class CMDRemove extends CommandBase {
if (npcNotSelected(plugin, player)) return;
if (notInteger(args[1])) {
if (!isInteger(args[1])) {
player.sendMessage(color(HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.INVALID_ID_NUMBER));
return;

View File

@ -26,7 +26,6 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
@ -35,9 +34,9 @@ import java.util.List;
import java.util.stream.Collectors;
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
import static me.mattstudios.citizenscmd.utility.Util.color;
import static me.mattstudios.citizenscmd.utility.Util.getTabCompleteArgs;
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelectedNM;
import static me.mattstudios.utils.MessageUtils.color;
/**
* Thank you GlareMasters for creating this class!
@ -67,7 +66,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter, IHandler {
}
@Override
public boolean onCommand(@NotNull CommandSender sender, Command cmd, @NotNull String commandLabel, @NotNull String[] args) {
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (!cmd.getName().equalsIgnoreCase("npcmd")) {
return true;
}
@ -134,7 +133,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter, IHandler {
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, Command cmd, @NotNull String commandLabel, @NotNull String[] args) {
public List<String> onTabComplete(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (cmd.getName().equalsIgnoreCase("npcmd")) {
if (args.length == 1) {
List<String> commandNames = new ArrayList<>();

View File

@ -29,6 +29,9 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Objects;
import static me.mattstudios.utils.MessageUtils.color;
import static me.mattstudios.utils.MessageUtils.info;
public class CooldownHandler {
private CitizensCMD plugin;
@ -70,7 +73,7 @@ public class CooldownHandler {
try {
cooldownsFile.createNewFile();
} catch (IOException e) {
Util.info(Util.color("&cError creating cooldowns file.."));
info(color("&cError creating cooldowns file.."));
}
}
}

View File

@ -34,6 +34,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import static me.mattstudios.utils.MessageUtils.color;
import static me.mattstudios.utils.MessageUtils.info;
@SuppressWarnings("unchecked")
public class DataHandler {
@ -75,7 +78,7 @@ public class DataHandler {
try {
savesFile.createNewFile();
} catch (IOException e) {
Util.info(Util.color("&cError creating saves file.."));
info(color("&cError creating saves file.."));
}
}
}
@ -165,12 +168,12 @@ public class DataHandler {
dataConfigurator.set("npc-data.npc-" + npc + ".price", 0);
}
player.sendMessage(Util.color(Util.HEADER));
player.sendMessage(color(Util.HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.NPC_ADDED));
dataConfigurator.save(savesFile);
} catch (IOException | InvalidConfigurationException e) {
player.sendMessage(Util.color(Util.HEADER));
player.sendMessage(color(Util.HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.NPC_ADD_FAIL));
}
}).start();
@ -241,12 +244,12 @@ public class DataHandler {
data.replace("npc-data.npc-" + npc + ".cooldown", cooldown);
player.sendMessage(Util.color(Util.HEADER));
player.sendMessage(color(Util.HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.NPC_COOLDOWN_SET));
dataConfigurator.save(savesFile);
} catch (IOException | InvalidConfigurationException e) {
player.sendMessage(Util.color(Util.HEADER));
player.sendMessage(color(Util.HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.NPC_COOLDOWN_SET_ERROR));
}
}).start();
@ -269,7 +272,7 @@ public class DataHandler {
data.replace("npc-data.npc-" + npc + ".price", price);
player.sendMessage(Util.color(Util.HEADER));
player.sendMessage(color(Util.HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.NPC_PRICE_SET));
dataConfigurator.save(savesFile);
@ -296,7 +299,7 @@ public class DataHandler {
data.replace("npc-data.npc-" + npc + ".permission", permission);
player.sendMessage(Util.color(Util.HEADER));
player.sendMessage(color(Util.HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.PERMISSION_SET));
dataConfigurator.save(savesFile);
@ -323,7 +326,7 @@ public class DataHandler {
data.remove("npc-data.npc-" + npc + ".permission");
player.sendMessage(Util.color(Util.HEADER));
player.sendMessage(color(Util.HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.PERMISSION_REMOVED));
dataConfigurator.save(savesFile);
@ -437,7 +440,7 @@ public class DataHandler {
data.replace(key, commands);
dataConfigurator.set(key, commands);
player.sendMessage(Util.color(Util.HEADER));
player.sendMessage(color(Util.HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.REMOVED_COMMAND));
dataConfigurator.save(savesFile);
@ -486,7 +489,7 @@ public class DataHandler {
data.replace(key, commandsData);
dataConfigurator.set(key, commandsData);
player.sendMessage(Util.color(Util.HEADER));
player.sendMessage(color(Util.HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.EDITED_COMMAND).replace("{type}", typeText));
dataConfigurator.save(savesFile);

View File

@ -30,6 +30,9 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Objects;
import static me.mattstudios.utils.MessageUtils.color;
import static me.mattstudios.utils.MessageUtils.info;
public class LangHandler {
private CitizensCMD plugin;
@ -48,25 +51,25 @@ public class LangHandler {
public void initialize() {
switch (lang) {
case "en":
Util.info(Util.color(Util.TAG + "&7Using &aEnglish &7messages!"));
info(color(Util.TAG + "&7Using &aEnglish &7messages!"));
break;
case "pt":
Util.info(Util.color(Util.TAG + "&7Usando mensagens em Portugues!"));
info(color(Util.TAG + "&7Usando mensagens em Portugues!"));
break;
case "ro":
Util.info(Util.color(Util.TAG + "&7Folositi mesajele in Limba &aRomana&7!"));
info(color(Util.TAG + "&7Folositi mesajele in Limba &aRomana&7!"));
break;
case "bg":
Util.info(Util.color(Util.TAG + "&7Използване на &aбългарски &7език!"));
info(color(Util.TAG + "&7Използване на &aбългарски &7език!"));
break;
case "no":
Util.info(Util.color(Util.TAG + "&aNorsk &7Oversettelse!"));
info(color(Util.TAG + "&aNorsk &7Oversettelse!"));
break;
case "ch":
Util.info(Util.color(Util.TAG + "&7使用&a中文&7消息!"));
info(color(Util.TAG + "&7使用&a中文&7消息!"));
break;
}
@ -299,7 +302,7 @@ public class LangHandler {
* @return Returns String with colored message from file
*/
public String getMessage(String path) {
return Util.color(messages.get(path));
return color(messages.get(path));
}
/**

View File

@ -1,17 +1,19 @@
package me.mattstudios.citizenscmd.listeners;
import lombok.AllArgsConstructor;
import me.mattstudios.citizenscmd.CitizensCMD;
import net.citizensnpcs.api.event.NPCCloneEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@AllArgsConstructor
public class NPCListener implements Listener {
private CitizensCMD plugin;
public NPCListener(CitizensCMD plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void on(NPCCloneEvent event) {
if (!plugin.getDataHandler().hasNPCData(event.getNPC().getId())) return;

View File

@ -27,6 +27,8 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import static me.mattstudios.utils.MessageUtils.color;
public class UpdateEvent implements Listener {
private CitizensCMD plugin;
@ -38,9 +40,9 @@ public class UpdateEvent implements Listener {
@EventHandler (priority = EventPriority.NORMAL)
public void onPlayerJoin(PlayerJoinEvent event) {
if (plugin.isUpdateStatus() && event.getPlayer().hasPermission("citizenscmd.update")) {
JSONMessage.create(Util.color(Util.HEADER)).send(event.getPlayer());
JSONMessage.create(Util.color(plugin.getLang().getUncoloredMessage(Path.NEW_VERSION) + plugin.getNewVersion())).send(event.getPlayer());
JSONMessage.create(Util.color(plugin.getLang().getUncoloredMessage(Path.DOWNLOAD_AT) + " spigotmc.org/resources/citizens-CMD.30224/")).openURL("https://spigotmc.org/resources/citizens-CMD.30224/").send(event.getPlayer());
JSONMessage.create(color(Util.HEADER)).send(event.getPlayer());
JSONMessage.create(color(plugin.getLang().getUncoloredMessage(Path.NEW_VERSION) + plugin.getNewVersion())).send(event.getPlayer());
JSONMessage.create(color(plugin.getLang().getUncoloredMessage(Path.DOWNLOAD_AT) + " spigotmc.org/resources/citizens-CMD.30224/")).openURL("https://spigotmc.org/resources/citizens-CMD.30224/").send(event.getPlayer());
}
}

View File

@ -24,7 +24,6 @@ import me.mattstudios.citizenscmd.paths.Path;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.Sound;
import org.bukkit.configuration.InvalidConfigurationException;
@ -42,6 +41,8 @@ import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static me.mattstudios.utils.MessageUtils.color;
import static me.mattstudios.utils.MessageUtils.info;
import static org.bukkit.Bukkit.getScheduler;
public class Util {
@ -52,32 +53,6 @@ public class Util {
public static final String HEADER = "&c&m-&6&m-&e&m-&a&m-&b&m-&3&l CitizensCMD &b&m-&a&m-&e&m-&6&m-&c&m-";
public static final String TAG = "&f[&3Citizens&cCMD&f]&r ";
/**
* @param str String to check if it is a number or not
* @return Returns true if it is a number false if it is a string or contains any non numeric character
*/
public static boolean notInteger(String str) {
try {
Integer.parseInt(str);
} catch (NumberFormatException | NullPointerException e) {
return true;
}
return false;
}
/**
* @param str String to check if it is a double number or not
* @return Returns true if it is a number false if it is a string or contains any non numeric character
*/
public static boolean notDouble(String str) {
try {
Double.parseDouble(str);
} catch (NumberFormatException | NullPointerException e) {
return true;
}
return false;
}
/**
* Checks if player has or not selected an NPC
*
@ -121,25 +96,6 @@ public class Util {
return plugin.getConfig().getBoolean("check-updates");
}
/**
* Utility to use color codes easily
*
* @param msg The message String
* @return returns the string with color
*/
public static String color(String msg) {
return ChatColor.translateAlternateColorCodes('&', msg);
}
/**
* Simplified way for sending console messages
*
* @param msg the message to be sent to the console
*/
public static void info(String msg) {
Bukkit.getServer().getConsoleSender().sendMessage(msg);
}
/**
* Gets default cooldown set on the config
*