forked from Upstream/CitizensCMD
Changed from System.nanoTime() to System.currentTimeMillis().
Reverted Citizens download. Reverted static use of instance and using DI instead. Fixed misspelling on permission node.
This commit is contained in:
parent
c23c4c447c
commit
094e7c2cd0
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
\.idea/
|
||||
|
||||
dependency-reduced-pom\.xml
|
||||
|
||||
citizens-cmd\.iml
|
||||
|
||||
target/
|
2
pom.xml
2
pom.xml
@ -92,7 +92,7 @@
|
||||
<dependency>
|
||||
<groupId>net.citizensnpcs</groupId>
|
||||
<artifactId>citizensapi</artifactId>
|
||||
<version>2.0.23-SNAPSHOT</version>
|
||||
<version>2.0.24-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -34,13 +34,11 @@ import me.mattmoreira.citizenscmd.utility.DisplayFormat;
|
||||
import me.mattmoreira.citizenscmd.utility.Util;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.*;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -53,8 +51,6 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
*/
|
||||
private final String[] REGISTERED_LANG_FILES = {"en", "pt", "ro", "bg", "no", "ch"};
|
||||
|
||||
private static CitizensCMD plugin;
|
||||
|
||||
private static CommandHandler commandHandler = null;
|
||||
private static LangHandler lang = null;
|
||||
private static DataHandler dataHandler = null;
|
||||
@ -70,43 +66,32 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
|
||||
private static HashMap<String, Boolean> waitingList;
|
||||
|
||||
public void onLoad() {
|
||||
if (!hasCitizensFile()) {
|
||||
info(color(TAG + "&cCitizens &7is needed for this plugin to work!"));
|
||||
info(color(TAG + "&cCitizens.jar &7is not installed on the server!"));
|
||||
info(color(TAG + "&cDownloading Citizens jar..."));
|
||||
Util.downloadCitizens();
|
||||
}
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
|
||||
if (!hasCitizens()) Util.loadCitizens();
|
||||
if (!hasCitizens()) Util.disablePlugin(this);
|
||||
|
||||
plugin = this;
|
||||
|
||||
commandHandler = new CommandHandler();
|
||||
commandHandler = new CommandHandler(this);
|
||||
commandHandler.enable();
|
||||
|
||||
checkOldConfig();
|
||||
checkOldConfig(this);
|
||||
|
||||
new Metrics(this);
|
||||
|
||||
info(color(TAG + "&3Citizens&cCMD &8&o" + getDescription().getVersion() + " &8By &3Mateus Moreira &c@LichtHund"));
|
||||
|
||||
permissionsManager = new PermissionsManager();
|
||||
permissionsManager = new PermissionsManager(this);
|
||||
|
||||
dataHandler = new DataHandler();
|
||||
dataHandler = new DataHandler(this);
|
||||
dataHandler.initialize();
|
||||
|
||||
cooldownHandler = new CooldownHandler();
|
||||
cooldownHandler = new CooldownHandler(this);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> cooldownHandler.initialize(), 30L);
|
||||
|
||||
saveDefaultConfig();
|
||||
registerCommands();
|
||||
registerEvents();
|
||||
|
||||
registerLangs();
|
||||
registerLangs(this);
|
||||
setLang(getConfig().getString("lang"));
|
||||
|
||||
if (hasPAPI()) {
|
||||
@ -175,7 +160,7 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
} else
|
||||
displayFormat = DisplayFormat.MEDIUM;
|
||||
|
||||
if (upCheck()) {
|
||||
if (upCheck(this)) {
|
||||
SpigotUpdater updater = new SpigotUpdater(this, 30224);
|
||||
try {
|
||||
// If there's an update, tell the user that they can update
|
||||
@ -211,8 +196,8 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
new UpdateScheduler().runTaskTimerAsynchronously(this, 72000L, 72000L);
|
||||
new CooldownScheduler().runTaskTimerAsynchronously(this, 36000L, 36000L);
|
||||
new UpdateScheduler(this).runTaskTimerAsynchronously(this, 72000L, 72000L);
|
||||
new CooldownScheduler(this).runTaskTimerAsynchronously(this, 36000L, 36000L);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -221,16 +206,6 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
cooldownHandler.saveToFile();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if Citizens is installed or not on the server
|
||||
*
|
||||
* @return Returns true if Citizens is found and false if not
|
||||
*/
|
||||
private boolean hasCitizensFile() {
|
||||
return Util.doesCitizensExist();
|
||||
}
|
||||
|
||||
private boolean hasCitizens() {
|
||||
return Bukkit.getPluginManager().isPluginEnabled("Citizens");
|
||||
}
|
||||
@ -249,7 +224,7 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
*/
|
||||
private void registerCommands() {
|
||||
getCommand("npcmd").setExecutor(commandHandler);
|
||||
Stream.of(new CMDHelp(), new CMDAdd(), new CMDCooldown(), new CMDList(), new CMDReload(), new CMDRemove(), new CMDEdit(), new CMDPrice(), new CMDSound()).forEach(commandHandler::register);
|
||||
Stream.of(new CMDHelp(this), new CMDAdd(this), new CMDCooldown(this), new CMDList(this), new CMDReload(this), new CMDRemove(this), new CMDEdit(this), new CMDPrice(this), new CMDSound()).forEach(commandHandler::register);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -257,8 +232,8 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
*/
|
||||
private void registerEvents() {
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvents(new UpdateEvent(), this);
|
||||
pm.registerEvents(new NPCListener(), this);
|
||||
pm.registerEvents(new UpdateEvent(this), this);
|
||||
pm.registerEvents(new NPCListener(this), this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -279,26 +254,17 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
return economy != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin instance
|
||||
*
|
||||
* @return Returns instance of the plugin
|
||||
*/
|
||||
public static CitizensCMD getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates all the language files
|
||||
*/
|
||||
private void registerLangs() {
|
||||
private void registerLangs(CitizensCMD plugin) {
|
||||
File langFile;
|
||||
|
||||
for (String registeredLangFile : REGISTERED_LANG_FILES) {
|
||||
langFile = new File(CitizensCMD.getPlugin().getDataFolder(), "lang/" + registeredLangFile + ".yml");
|
||||
langFile = new File(plugin.getDataFolder(), "lang/" + registeredLangFile + ".yml");
|
||||
|
||||
if (!langFile.exists())
|
||||
CitizensCMD.getPlugin().saveResource("lang/" + registeredLangFile + ".yml", false);
|
||||
plugin.saveResource("lang/" + registeredLangFile + ".yml", false);
|
||||
}
|
||||
|
||||
}
|
||||
@ -311,41 +277,41 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
case "en":
|
||||
case "eng":
|
||||
case "english":
|
||||
lang = new LangHandler("en");
|
||||
lang = new LangHandler(this, "en");
|
||||
break;
|
||||
|
||||
case "pt":
|
||||
case "port":
|
||||
case "portuguese":
|
||||
lang = new LangHandler("pt");
|
||||
lang = new LangHandler(this, "pt");
|
||||
break;
|
||||
|
||||
case "ro":
|
||||
case "roma":
|
||||
case "romanian":
|
||||
lang = new LangHandler("ro");
|
||||
lang = new LangHandler(this, "ro");
|
||||
break;
|
||||
|
||||
case "bg":
|
||||
case "bulg":
|
||||
case "bulgarian":
|
||||
lang = new LangHandler("bg");
|
||||
lang = new LangHandler(this, "bg");
|
||||
break;
|
||||
|
||||
case "no":
|
||||
case "norw":
|
||||
case "norwegian":
|
||||
lang = new LangHandler("no");
|
||||
lang = new LangHandler(this, "no");
|
||||
break;
|
||||
|
||||
case "ch":
|
||||
case "chi":
|
||||
case "chinese":
|
||||
lang = new LangHandler("ch");
|
||||
lang = new LangHandler(this, "ch");
|
||||
break;
|
||||
|
||||
default:
|
||||
lang = new LangHandler("en");
|
||||
lang = new LangHandler(this, "en");
|
||||
break;
|
||||
}
|
||||
lang.initialize();
|
||||
|
@ -29,8 +29,11 @@ import static me.mattmoreira.citizenscmd.utility.Util.npcNotSelected;
|
||||
|
||||
public class CMDAdd extends CommandBase {
|
||||
|
||||
public CMDAdd() {
|
||||
private CitizensCMD plugin;
|
||||
|
||||
public CMDAdd(CitizensCMD plugin) {
|
||||
super("add", "citizenscmd.add", false, null, 2, 512);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,7 +45,7 @@ public class CMDAdd extends CommandBase {
|
||||
@Override
|
||||
public void execute(Player player, String[] args) {
|
||||
|
||||
if (npcNotSelected(player)) return;
|
||||
if (npcNotSelected(plugin, player)) return;
|
||||
|
||||
String permission = args[0];
|
||||
boolean left = false;
|
||||
@ -76,7 +79,7 @@ public class CMDAdd extends CommandBase {
|
||||
|
||||
boolean finalLeft = left;
|
||||
|
||||
CitizensCMD.getPlugin().getDataHandler().addCommand(getSelectedNpcId(player), permission, finalString, player, finalLeft);
|
||||
plugin.getDataHandler().addCommand(getSelectedNpcId(player), permission, finalString, player, finalLeft);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,22 +27,25 @@ import static me.mattmoreira.citizenscmd.utility.Util.*;
|
||||
|
||||
public class CMDCooldown extends CommandBase {
|
||||
|
||||
public CMDCooldown() {
|
||||
private CitizensCMD plugin;
|
||||
|
||||
public CMDCooldown(CitizensCMD plugin) {
|
||||
super("cooldown", "citizenscmd.cooldown", false, new String[]{"cd"}, 1, 1);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player player, String[] args) {
|
||||
|
||||
if (npcNotSelected(player)) return;
|
||||
if (npcNotSelected(plugin, player)) return;
|
||||
|
||||
if (notInteger(args[0])) {
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.INVALID_COOLDOWN));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.INVALID_COOLDOWN));
|
||||
return;
|
||||
}
|
||||
|
||||
CitizensCMD.getPlugin().getDataHandler().setCooldown(getSelectedNpcId(player), Integer.valueOf(args[0]), player);
|
||||
plugin.getDataHandler().setCooldown(getSelectedNpcId(player), Integer.valueOf(args[0]), player);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,18 +30,21 @@ import static me.mattmoreira.citizenscmd.utility.Util.*;
|
||||
|
||||
public class CMDEdit extends CommandBase {
|
||||
|
||||
public CMDEdit() {
|
||||
private CitizensCMD plugin;
|
||||
|
||||
public CMDEdit(CitizensCMD plugin) {
|
||||
super("edit", "citizenscmd.edit", false, null, 4, 512);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player player, String[] args) {
|
||||
|
||||
if (npcNotSelected(player)) return;
|
||||
if (npcNotSelected(plugin, player)) return;
|
||||
|
||||
if (notInteger(args[2])) {
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.INVALID_ID_NUMBER));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.INVALID_ID_NUMBER));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -57,49 +60,49 @@ public class CMDEdit extends CommandBase {
|
||||
case "perm":
|
||||
if (args.length > 4) {
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.INVALID_PERMISSION));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.INVALID_PERMISSION));
|
||||
return;
|
||||
}
|
||||
type = EnumTypes.EditType.PERM;
|
||||
break;
|
||||
default:
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.INVALID_ARGUMENTS));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.INVALID_ARGUMENTS));
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "left":
|
||||
int leftCommandSize = CitizensCMD.getPlugin().getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT).size();
|
||||
int leftCommandSize = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT).size();
|
||||
if (leftCommandSize == 0) {
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.NO_COMMANDS));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.NO_COMMANDS));
|
||||
return;
|
||||
}
|
||||
if (commandID < 1 || commandID > leftCommandSize) {
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.INVALID_ID_NUMBER));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.INVALID_ID_NUMBER));
|
||||
return;
|
||||
}
|
||||
click = EnumTypes.ClickType.LEFT;
|
||||
break;
|
||||
case "right":
|
||||
int rightCommandSize = CitizensCMD.getPlugin().getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT).size();
|
||||
int rightCommandSize = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT).size();
|
||||
if (rightCommandSize == 0) {
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.NO_COMMANDS));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.NO_COMMANDS));
|
||||
return;
|
||||
}
|
||||
if (commandID < 1 || commandID > rightCommandSize) {
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.INVALID_ID_NUMBER));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.INVALID_ID_NUMBER));
|
||||
return;
|
||||
}
|
||||
click = EnumTypes.ClickType.RIGHT;
|
||||
break;
|
||||
default:
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.INVALID_CLICK_TYPE));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.INVALID_CLICK_TYPE));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -112,6 +115,6 @@ public class CMDEdit extends CommandBase {
|
||||
else stringBuilder.append(commandsArray[i]).append(" ");
|
||||
}
|
||||
|
||||
CitizensCMD.getPlugin().getDataHandler().edit(npc, commandID, click, type, stringBuilder.toString().trim(), player);
|
||||
plugin.getDataHandler().edit(npc, commandID, click, type, stringBuilder.toString().trim(), player);
|
||||
}
|
||||
}
|
||||
|
@ -32,23 +32,26 @@ import static me.mattmoreira.citizenscmd.utility.Util.color;
|
||||
*/
|
||||
public class CMDHelp extends CommandBase {
|
||||
|
||||
public CMDHelp() {
|
||||
private CitizensCMD plugin;
|
||||
|
||||
public CMDHelp(CitizensCMD plugin) {
|
||||
super("help", "citizenscmd.npcmd", false, null, 0, 0);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player player, String[] args) {
|
||||
JSONMessage.create(color(HEADER)).send(player);
|
||||
JSONMessage.create(color(CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_VERSION) + " &c&o" + CitizensCMD.getPlugin().getDescription().getVersion())).send(player);
|
||||
JSONMessage.create(color(CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_INFO))).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &cadd &b<console &b| &bmessage &b| &bnone | &bpermission &b| &b> &6<command> &d[-l]")).suggestCommand("/npcmd add ").tooltip(color(CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_DESCRIPTION_ADD) + "\n" + CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_EXAMPLE) + "\n&3&o/npcmd &c&oadd &b&ossentials.heal &6&oheal")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &ccooldown &6<time>")).suggestCommand("/npcmd cooldown ").tooltip(color(CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_DESCRIPTION_COOLDOWN) + "\n" + CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_EXAMPLE) + "\n&3&o/npcmd &c&ocooldown &6&o15")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &cprice &6<price>")).suggestCommand("/npcmd price ").tooltip(color(CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_DESCRIPTION_PRICE) + "\n" + CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_EXAMPLE) + "\n&3&o/npcmd &c&oprice &6&o250")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &clist")).suggestCommand("/npcmd list").tooltip(color(CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_DESCRIPTION_LIST) + "\n&8" + CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_EXAMPLE) + "\n&3&o/npcmd &c&olist")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &cedit &b<cmd | perm> &b<left | right> &6<id> &6<new command | new permission>")).suggestCommand("/npcmd edit ").tooltip(color(CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_DESCRIPTION_EDIT) + "\n" + CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_EXAMPLE) + "\n&3&o/npcmd &c&oedit &b&ocmd &b&oright &6&o1 fly")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &csound &b<sound> &d[volume] &d[pitch]")).suggestCommand("/npcmd sound ").tooltip(color(CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_DESCRIPTION_SOUND) + "\n" + CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_EXAMPLE) + "\n&3&o/npcmd &c&osound &b&oENTITY_VILLAGER_YES")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &cremove &b<left | right> &6<id>")).suggestCommand("/npcmd remove ").tooltip(color(CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_DESCRIPTION_REMOVE) + "\n" + CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_EXAMPLE) + "\n&3&o/npcmd &c&oremove &b&oright &6&o1")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &creload")).suggestCommand("/npcmd reload").tooltip(color(CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_DESCRIPTION_RELOAD) + "\n" + CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.HELP_EXAMPLE) + "\n&3&o/npcmd &c&oreload")).send(player);
|
||||
JSONMessage.create(color(plugin.getLang().getUncoloredMessage(Path.HELP_VERSION) + " &c&o" + plugin.getDescription().getVersion())).send(player);
|
||||
JSONMessage.create(color(plugin.getLang().getUncoloredMessage(Path.HELP_INFO))).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &cadd &b<console &b| &bmessage &b| &bnone | &bpermission &b| &b> &6<command> &d[-l]")).suggestCommand("/npcmd add ").tooltip(color(plugin.getLang().getUncoloredMessage(Path.HELP_DESCRIPTION_ADD) + "\n" + plugin.getLang().getUncoloredMessage(Path.HELP_EXAMPLE) + "\n&3&o/npcmd &c&oadd &b&ossentials.heal &6&oheal")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &ccooldown &6<time>")).suggestCommand("/npcmd cooldown ").tooltip(color(plugin.getLang().getUncoloredMessage(Path.HELP_DESCRIPTION_COOLDOWN) + "\n" + plugin.getLang().getUncoloredMessage(Path.HELP_EXAMPLE) + "\n&3&o/npcmd &c&ocooldown &6&o15")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &cprice &6<price>")).suggestCommand("/npcmd price ").tooltip(color(plugin.getLang().getUncoloredMessage(Path.HELP_DESCRIPTION_PRICE) + "\n" + plugin.getLang().getUncoloredMessage(Path.HELP_EXAMPLE) + "\n&3&o/npcmd &c&oprice &6&o250")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &clist")).suggestCommand("/npcmd list").tooltip(color(plugin.getLang().getUncoloredMessage(Path.HELP_DESCRIPTION_LIST) + "\n&8" + plugin.getLang().getUncoloredMessage(Path.HELP_EXAMPLE) + "\n&3&o/npcmd &c&olist")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &cedit &b<cmd | perm> &b<left | right> &6<id> &6<new command | new permission>")).suggestCommand("/npcmd edit ").tooltip(color(plugin.getLang().getUncoloredMessage(Path.HELP_DESCRIPTION_EDIT) + "\n" + plugin.getLang().getUncoloredMessage(Path.HELP_EXAMPLE) + "\n&3&o/npcmd &c&oedit &b&ocmd &b&oright &6&o1 fly")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &csound &b<sound> &d[volume] &d[pitch]")).suggestCommand("/npcmd sound ").tooltip(color(plugin.getLang().getUncoloredMessage(Path.HELP_DESCRIPTION_SOUND) + "\n" + plugin.getLang().getUncoloredMessage(Path.HELP_EXAMPLE) + "\n&3&o/npcmd &c&osound &b&oENTITY_VILLAGER_YES")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &cremove &b<left | right> &6<id>")).suggestCommand("/npcmd remove ").tooltip(color(plugin.getLang().getUncoloredMessage(Path.HELP_DESCRIPTION_REMOVE) + "\n" + plugin.getLang().getUncoloredMessage(Path.HELP_EXAMPLE) + "\n&3&o/npcmd &c&oremove &b&oright &6&o1")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &creload")).suggestCommand("/npcmd reload").tooltip(color(plugin.getLang().getUncoloredMessage(Path.HELP_DESCRIPTION_RELOAD) + "\n" + plugin.getLang().getUncoloredMessage(Path.HELP_EXAMPLE) + "\n&3&o/npcmd &c&oreload")).send(player);
|
||||
|
||||
}
|
||||
|
||||
|
@ -32,38 +32,41 @@ import static me.mattmoreira.citizenscmd.utility.Util.*;
|
||||
|
||||
public class CMDList extends CommandBase {
|
||||
|
||||
public CMDList() {
|
||||
super("list", "citizescmd.list", false, new String[]{"l"}, 0, 0);
|
||||
private CitizensCMD plugin;
|
||||
|
||||
public CMDList(CitizensCMD plugin) {
|
||||
super("list", "citizenscmd.list", false, new String[]{"l"}, 0, 0);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player player, String[] args) {
|
||||
|
||||
if (npcNotSelected(player)) return;
|
||||
if (npcNotSelected(plugin, player)) return;
|
||||
|
||||
int npc = getSelectedNpcId(player);
|
||||
|
||||
List<String> leftCommands = CitizensCMD.getPlugin().getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT) != null ? CitizensCMD.getPlugin().getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT) : new ArrayList<>();
|
||||
List<String> rightCommands = CitizensCMD.getPlugin().getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT) != null ? CitizensCMD.getPlugin().getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT) : new ArrayList<>();
|
||||
List<String> leftCommands = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT) != null ? plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT) : new ArrayList<>();
|
||||
List<String> rightCommands = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT) != null ? plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT) : new ArrayList<>();
|
||||
|
||||
player.sendMessage(color(HEADER));
|
||||
JSONMessage.create(color(CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.LIST_COOLDOWN) + CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc))).tooltip(CitizensCMD.getPlugin().getLang().getMessage(Path.LIST_TOOLTIP)).suggestCommand("/npcmd cooldown ").send(player);
|
||||
JSONMessage.create(color(CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.LIST_PRICE) + CitizensCMD.getPlugin().getDataHandler().getPrice(npc))).tooltip(CitizensCMD.getPlugin().getLang().getMessage(Path.LIST_TOOLTIP)).suggestCommand("/npcmd price ").send(player);
|
||||
JSONMessage.create(color(plugin.getLang().getUncoloredMessage(Path.LIST_COOLDOWN) + plugin.getDataHandler().getNPCCooldown(npc))).tooltip(plugin.getLang().getMessage(Path.LIST_TOOLTIP)).suggestCommand("/npcmd cooldown ").send(player);
|
||||
JSONMessage.create(color(plugin.getLang().getUncoloredMessage(Path.LIST_PRICE) + plugin.getDataHandler().getPrice(npc))).tooltip(plugin.getLang().getMessage(Path.LIST_TOOLTIP)).suggestCommand("/npcmd price ").send(player);
|
||||
player.sendMessage("");
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.LIST_COUNT_RIGHT).replace("{count}", String.valueOf(rightCommands.size())));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.LIST_COUNT_RIGHT).replace("{count}", String.valueOf(rightCommands.size())));
|
||||
|
||||
int rightCount = 1;
|
||||
for (String command : rightCommands) {
|
||||
JSONMessage.create(color("&c" + rightCount + " &7- &7" + command.replace("[", "&8[&c").replace("]", "&8]&b"))).suggestCommand("/npcmd edit cmd right " + rightCount + " ").tooltip(CitizensCMD.getPlugin().getLang().getMessage(Path.LIST_TOOLTIP)).send(player);
|
||||
JSONMessage.create(color("&c" + rightCount + " &7- &7" + command.replace("[", "&8[&c").replace("]", "&8]&b"))).suggestCommand("/npcmd edit cmd right " + rightCount + " ").tooltip(plugin.getLang().getMessage(Path.LIST_TOOLTIP)).send(player);
|
||||
rightCount++;
|
||||
}
|
||||
|
||||
player.sendMessage("");
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.LIST_COUNT_LEFT).replace("{count}", String.valueOf(leftCommands.size())));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.LIST_COUNT_LEFT).replace("{count}", String.valueOf(leftCommands.size())));
|
||||
|
||||
int leftCount = 1;
|
||||
for (String command : leftCommands) {
|
||||
JSONMessage.create(color("&c" + leftCount + " &7- &7" + command.replace("[", "&8[&c").replace("]", "&8]&b"))).suggestCommand("/npcmd edit cmd left " + leftCount + " ").tooltip(CitizensCMD.getPlugin().getLang().getMessage(Path.LIST_TOOLTIP)).send(player);
|
||||
JSONMessage.create(color("&c" + leftCount + " &7- &7" + command.replace("[", "&8[&c").replace("]", "&8]&b"))).suggestCommand("/npcmd edit cmd left " + leftCount + " ").tooltip(plugin.getLang().getMessage(Path.LIST_TOOLTIP)).send(player);
|
||||
leftCount++;
|
||||
}
|
||||
}
|
||||
|
@ -27,22 +27,25 @@ import static me.mattmoreira.citizenscmd.utility.Util.*;
|
||||
|
||||
public class CMDPrice extends CommandBase {
|
||||
|
||||
public CMDPrice() {
|
||||
private CitizensCMD plugin;
|
||||
|
||||
public CMDPrice(CitizensCMD plugin) {
|
||||
super("price", "citizenscmd.price", false, new String[]{"p"}, 1, 1);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player player, String[] args) {
|
||||
|
||||
if (npcNotSelected(player)) return;
|
||||
if (npcNotSelected(plugin, player)) return;
|
||||
|
||||
if (notDouble(args[0])) {
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.INVALID_PRICE));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.INVALID_PRICE));
|
||||
return;
|
||||
}
|
||||
|
||||
CitizensCMD.getPlugin().getDataHandler().setPrice(getSelectedNpcId(player), Double.valueOf(args[0]), player);
|
||||
plugin.getDataHandler().setPrice(getSelectedNpcId(player), Double.valueOf(args[0]), player);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,74 +30,77 @@ import static me.mattmoreira.citizenscmd.utility.Util.color;
|
||||
|
||||
public class CMDReload extends CommandBase {
|
||||
|
||||
public CMDReload() {
|
||||
private CitizensCMD plugin;
|
||||
|
||||
public CMDReload(CitizensCMD plugin) {
|
||||
super("reload", "citizenscmd.reload", true, null, 0, 0);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player player, String[] args) {
|
||||
CitizensCMD.getPlugin().reloadConfig();
|
||||
CitizensCMD.getPlugin().saveDefaultConfig();
|
||||
CitizensCMD.getPlugin().setLang(CitizensCMD.getPlugin().getConfig().getString("lang"));
|
||||
plugin.reloadConfig();
|
||||
plugin.saveDefaultConfig();
|
||||
plugin.setLang(plugin.getConfig().getString("lang"));
|
||||
|
||||
if (CitizensCMD.getPlugin().getConfig().contains("cooldown-time-display")) {
|
||||
switch (CitizensCMD.getPlugin().getConfig().getString("cooldown-time-display").toLowerCase()) {
|
||||
if (plugin.getConfig().contains("cooldown-time-display")) {
|
||||
switch (plugin.getConfig().getString("cooldown-time-display").toLowerCase()) {
|
||||
case "short":
|
||||
CitizensCMD.getPlugin().setDisplayFormat(DisplayFormat.SHORT);
|
||||
plugin.setDisplayFormat(DisplayFormat.SHORT);
|
||||
break;
|
||||
case "medium":
|
||||
CitizensCMD.getPlugin().setDisplayFormat(DisplayFormat.MEDIUM);
|
||||
plugin.setDisplayFormat(DisplayFormat.MEDIUM);
|
||||
break;
|
||||
case "full":
|
||||
CitizensCMD.getPlugin().setDisplayFormat(DisplayFormat.FULL);
|
||||
plugin.setDisplayFormat(DisplayFormat.FULL);
|
||||
break;
|
||||
default:
|
||||
CitizensCMD.getPlugin().setDisplayFormat(DisplayFormat.MEDIUM);
|
||||
plugin.setDisplayFormat(DisplayFormat.MEDIUM);
|
||||
}
|
||||
} else
|
||||
CitizensCMD.getPlugin().setDisplayFormat(DisplayFormat.MEDIUM);
|
||||
plugin.setDisplayFormat(DisplayFormat.MEDIUM);
|
||||
|
||||
if (CitizensCMD.getEconomy() != null)
|
||||
CitizensCMD.getPlugin().setShift(CitizensCMD.getPlugin().getConfig().getBoolean("shift-confirm"));
|
||||
plugin.setShift(plugin.getConfig().getBoolean("shift-confirm"));
|
||||
|
||||
CitizensCMD.getPlugin().getDataHandler().reload();
|
||||
CitizensCMD.getPlugin().getCooldownHandler().reload();
|
||||
plugin.getDataHandler().reload();
|
||||
plugin.getCooldownHandler().reload();
|
||||
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.RELOAD));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.RELOAD));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
CitizensCMD.getPlugin().reloadConfig();
|
||||
CitizensCMD.getPlugin().saveConfig();
|
||||
CitizensCMD.getPlugin().setLang(CitizensCMD.getPlugin().getConfig().getString("lang"));
|
||||
plugin.reloadConfig();
|
||||
plugin.saveConfig();
|
||||
plugin.setLang(plugin.getConfig().getString("lang"));
|
||||
|
||||
if (CitizensCMD.getPlugin().getConfig().contains("cooldonw-time-display")) {
|
||||
switch (CitizensCMD.getPlugin().getConfig().getString("cooldonw-time-display").toLowerCase()) {
|
||||
if (plugin.getConfig().contains("cooldonw-time-display")) {
|
||||
switch (plugin.getConfig().getString("cooldonw-time-display").toLowerCase()) {
|
||||
case "short":
|
||||
CitizensCMD.getPlugin().setDisplayFormat(DisplayFormat.SHORT);
|
||||
plugin.setDisplayFormat(DisplayFormat.SHORT);
|
||||
break;
|
||||
case "medium":
|
||||
CitizensCMD.getPlugin().setDisplayFormat(DisplayFormat.MEDIUM);
|
||||
plugin.setDisplayFormat(DisplayFormat.MEDIUM);
|
||||
break;
|
||||
case "full":
|
||||
CitizensCMD.getPlugin().setDisplayFormat(DisplayFormat.FULL);
|
||||
plugin.setDisplayFormat(DisplayFormat.FULL);
|
||||
break;
|
||||
default:
|
||||
CitizensCMD.getPlugin().setDisplayFormat(DisplayFormat.MEDIUM);
|
||||
plugin.setDisplayFormat(DisplayFormat.MEDIUM);
|
||||
}
|
||||
} else
|
||||
CitizensCMD.getPlugin().setDisplayFormat(DisplayFormat.MEDIUM);
|
||||
plugin.setDisplayFormat(DisplayFormat.MEDIUM);
|
||||
|
||||
if (CitizensCMD.getEconomy() != null)
|
||||
CitizensCMD.getPlugin().setShift(CitizensCMD.getPlugin().getConfig().getBoolean("shift-confirm"));
|
||||
plugin.setShift(plugin.getConfig().getBoolean("shift-confirm"));
|
||||
|
||||
CitizensCMD.getPlugin().getDataHandler().reload();
|
||||
CitizensCMD.getPlugin().getCooldownHandler().reload();
|
||||
plugin.getDataHandler().reload();
|
||||
plugin.getCooldownHandler().reload();
|
||||
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.RELOAD));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Path.RELOAD));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,18 +28,21 @@ import static me.mattmoreira.citizenscmd.utility.Util.*;
|
||||
|
||||
public class CMDRemove extends CommandBase {
|
||||
|
||||
public CMDRemove() {
|
||||
private CitizensCMD plugin;
|
||||
|
||||
public CMDRemove(CitizensCMD plugin) {
|
||||
super("remove", "citizenscmd.remove", false, new String[]{"delete", "del", "rem"}, 2, 2);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player player, String[] args) {
|
||||
|
||||
if (npcNotSelected(player)) return;
|
||||
if (npcNotSelected(plugin, player)) return;
|
||||
|
||||
if (notInteger(args[1])) {
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.INVALID_ID_NUMBER));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.INVALID_ID_NUMBER));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -49,40 +52,40 @@ public class CMDRemove extends CommandBase {
|
||||
|
||||
switch (args[0]) {
|
||||
case "left":
|
||||
int leftCommandSize = CitizensCMD.getPlugin().getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT).size();
|
||||
int leftCommandSize = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT).size();
|
||||
if (leftCommandSize == 0) {
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.NO_COMMANDS));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.NO_COMMANDS));
|
||||
return;
|
||||
}
|
||||
if (commandID < 1 || commandID > leftCommandSize) {
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.INVALID_ID_NUMBER));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.INVALID_ID_NUMBER));
|
||||
return;
|
||||
}
|
||||
click = EnumTypes.ClickType.LEFT;
|
||||
break;
|
||||
case "right":
|
||||
int rightCommandSize = CitizensCMD.getPlugin().getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT).size();
|
||||
int rightCommandSize = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT).size();
|
||||
if (rightCommandSize == 0) {
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.NO_COMMANDS));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.NO_COMMANDS));
|
||||
return;
|
||||
}
|
||||
if (commandID < 0 || commandID > rightCommandSize) {
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.INVALID_ID_NUMBER));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.INVALID_ID_NUMBER));
|
||||
return;
|
||||
}
|
||||
click = EnumTypes.ClickType.RIGHT;
|
||||
break;
|
||||
default:
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.INVALID_CLICK_TYPE));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.INVALID_CLICK_TYPE));
|
||||
return;
|
||||
}
|
||||
|
||||
CitizensCMD.getPlugin().getDataHandler().removeCommand(npc, commandID, click, player);
|
||||
plugin.getDataHandler().removeCommand(npc, commandID, click, player);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,7 @@
|
||||
|
||||
package me.mattmoreira.citizenscmd.commands;
|
||||
|
||||
import me.mattmoreira.citizenscmd.CitizensCMD;
|
||||
import me.mattmoreira.citizenscmd.commands.base.CommandBase;
|
||||
import me.mattmoreira.citizenscmd.utility.Path;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -34,12 +32,12 @@ public class CMDSound extends CommandBase {
|
||||
|
||||
public void execute(Player player, String[] args) {
|
||||
|
||||
if (npcNotSelected(player)) return;
|
||||
//if (npcNotSelected(player)) return;
|
||||
|
||||
int npc = getSelectedNpcId(player);
|
||||
|
||||
if (args.length == 0) {
|
||||
CitizensCMD.getPlugin().getDataHandler().removeSound(npc, player);
|
||||
//CitizensCMD.getPlugin().getDataHandler().removeSound(npc, player);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -60,11 +58,11 @@ public class CMDSound extends CommandBase {
|
||||
sound = Sound.valueOf(soundString);
|
||||
} catch (Exception e) {
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.INVALID_SOUND));
|
||||
//player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.INVALID_SOUND));
|
||||
return;
|
||||
}
|
||||
|
||||
CitizensCMD.getPlugin().getDataHandler().setSound(npc, sound, volume, pitch, player);
|
||||
//CitizensCMD.getPlugin().getDataHandler().setSound(npc, sound, volume, pitch, player);
|
||||
|
||||
}
|
||||
|
||||
|
@ -40,8 +40,13 @@ import static me.mattmoreira.citizenscmd.utility.Util.*;
|
||||
*/
|
||||
public class CommandHandler implements CommandExecutor, TabCompleter, IHandler {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private List<CommandBase> commands;
|
||||
|
||||
public CommandHandler(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
commands = new ArrayList<>();
|
||||
@ -78,13 +83,13 @@ public class CommandHandler implements CommandExecutor, TabCompleter, IHandler {
|
||||
|
||||
if (!command.allowConsole() && !(sender instanceof Player)) {
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.CONSOLE_NOT_ALLOWED));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Path.CONSOLE_NOT_ALLOWED));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission(command.getPermission())) {
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.NO_PERMISSION));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Path.NO_PERMISSION));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -94,7 +99,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter, IHandler {
|
||||
|| (command.getMaximumArguments() != -1
|
||||
&& command.getMaximumArguments() < args.length)) {
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.WRONG_USAGE));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Path.WRONG_USAGE));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -110,7 +115,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter, IHandler {
|
||||
}
|
||||
}
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.WRONG_USAGE));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Path.WRONG_USAGE));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -202,7 +207,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter, IHandler {
|
||||
*/
|
||||
private List<String> getCommandNames(String subCMD, String[] args, int arg, Player player) {
|
||||
List<String> commandNames = new ArrayList<>();
|
||||
String[][] argsComplete = getTabCompleteArgs(subCMD, player);
|
||||
String[][] argsComplete = getTabCompleteArgs(plugin, subCMD, player);
|
||||
|
||||
if (!args[arg - 1].equals("")) {
|
||||
for (String commandName : argsComplete[arg - 1]) {
|
||||
|
@ -31,6 +31,7 @@ import static me.mattmoreira.citizenscmd.utility.Util.*;
|
||||
|
||||
public class CooldownHandler {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private static File cooldownsFile;
|
||||
private static File dir;
|
||||
|
||||
@ -38,11 +39,15 @@ public class CooldownHandler {
|
||||
|
||||
private static HashMap<String, Long> cooldownData;
|
||||
|
||||
public CooldownHandler(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Createst the basic of the class and starts the HashMap
|
||||
*/
|
||||
public void initialize() {
|
||||
File pluginFolder = CitizensCMD.getPlugin().getDataFolder();
|
||||
File pluginFolder = plugin.getDataFolder();
|
||||
dir = new File(pluginFolder + "/data");
|
||||
cooldownsFile = new File(dir.getPath(), "cooldowns.yml");
|
||||
cooldownsConfigurator = new YamlConfiguration();
|
||||
@ -78,7 +83,7 @@ public class CooldownHandler {
|
||||
|
||||
if (!cooldownsConfigurator.contains("cooldown-data")) return;
|
||||
|
||||
HashMap<String, Integer> cachedDataFromSaves = CitizensCMD.getPlugin().getDataHandler().getCachedCooldownByID();
|
||||
HashMap<String, Integer> cachedDataFromSaves = plugin.getDataHandler().getCachedCooldownByID();
|
||||
|
||||
for (String parent : cooldownsConfigurator.getConfigurationSection("cooldown-data").getKeys(false)) {
|
||||
for (String child : cooldownsConfigurator.getConfigurationSection("cooldown-data." + parent).getKeys(false)) {
|
||||
@ -136,7 +141,7 @@ public class CooldownHandler {
|
||||
* @return returns in seconds the time left
|
||||
*/
|
||||
public long getTimeLeft(int npc, String uuid) {
|
||||
return CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc) - getSecondsDifference(cooldownData.get("cooldown-data.npc-" + npc + "." + uuid));
|
||||
return plugin.getDataHandler().getNPCCooldown(npc) - getSecondsDifference(cooldownData.get("cooldown-data.npc-" + npc + "." + uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -148,10 +153,10 @@ public class CooldownHandler {
|
||||
*/
|
||||
public boolean onCooldown(int npc, String uuid) {
|
||||
if (cooldownData.containsKey("cooldown-data.npc-" + npc + "." + uuid)) {
|
||||
if (CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc) == -1)
|
||||
if (plugin.getDataHandler().getNPCCooldown(npc) == -1)
|
||||
return true;
|
||||
else
|
||||
return getSecondsDifference(cooldownData.get("cooldown-data.npc-" + npc + "." + uuid)) < CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc);
|
||||
return getSecondsDifference(cooldownData.get("cooldown-data.npc-" + npc + "." + uuid)) < plugin.getDataHandler().getNPCCooldown(npc);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import static me.mattmoreira.citizenscmd.utility.Util.*;
|
||||
|
||||
public class DataHandler {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private static File savesFile;
|
||||
private static File dir;
|
||||
|
||||
@ -44,11 +45,15 @@ public class DataHandler {
|
||||
|
||||
private HashMap<String, Object> data;
|
||||
|
||||
public DataHandler(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates file and folder
|
||||
*/
|
||||
public void initialize() {
|
||||
File pluginFolder = CitizensCMD.getPlugin().getDataFolder();
|
||||
File pluginFolder = plugin.getDataFolder();
|
||||
dir = new File(pluginFolder + "/data");
|
||||
savesFile = new File(dir.getPath(), "saves.yml");
|
||||
dataConfigurator = new YamlConfiguration();
|
||||
@ -139,8 +144,8 @@ public class DataHandler {
|
||||
List<String> commandListLeft = data.containsKey("npc-data.npc-" + npc + ".left-click-commands") ? (List<String>) data.get("npc-data.npc-" + npc + ".left-click-commands") : new ArrayList<>();
|
||||
|
||||
if (!data.containsKey("npc-data.npc-" + npc + ".cooldown")) {
|
||||
data.put("npc-data.npc-" + npc + ".cooldown", getDefaultCooldown());
|
||||
dataConfigurator.set("npc-data.npc-" + npc + ".cooldown", getDefaultCooldown());
|
||||
data.put("npc-data.npc-" + npc + ".cooldown", getDefaultCooldown(plugin));
|
||||
dataConfigurator.set("npc-data.npc-" + npc + ".cooldown", getDefaultCooldown(plugin));
|
||||
}
|
||||
|
||||
if (left) commandListLeft.add("[" + permission + "] " + command);
|
||||
@ -169,12 +174,12 @@ public class DataHandler {
|
||||
}
|
||||
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.NPC_ADDED));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.NPC_ADDED));
|
||||
|
||||
dataConfigurator.save(savesFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.NPC_ADD_FAIL));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.NPC_ADD_FAIL));
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
@ -197,12 +202,12 @@ public class DataHandler {
|
||||
data.replace("npc-data.npc-" + npc + ".cooldown", cooldown);
|
||||
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.NPC_COOLDOWN_SET));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.NPC_COOLDOWN_SET));
|
||||
|
||||
dataConfigurator.save(savesFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.NPC_COOLDOWN_SET_ERROR));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.NPC_COOLDOWN_SET_ERROR));
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
@ -225,7 +230,7 @@ public class DataHandler {
|
||||
data.replace("npc-data.npc-" + npc + ".price", price);
|
||||
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.NPC_PRICE_SET));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.NPC_PRICE_SET));
|
||||
|
||||
dataConfigurator.save(savesFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
@ -263,7 +268,7 @@ public class DataHandler {
|
||||
data.put("npc-data.npc-" + npc + ".sound", soundProperties);
|
||||
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.SOUND_ADDED));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.SOUND_ADDED));
|
||||
|
||||
dataConfigurator.save(savesFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
@ -363,7 +368,7 @@ public class DataHandler {
|
||||
dataConfigurator.set("npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands", commands);
|
||||
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.REMOVED_COMMAND));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.REMOVED_COMMAND));
|
||||
|
||||
dataConfigurator.save(savesFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
@ -384,7 +389,7 @@ public class DataHandler {
|
||||
dataConfigurator.set("npc-data.npc-" + npc + ".sound", soundProperties);
|
||||
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.SOUND_REMOVED));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.SOUND_REMOVED));
|
||||
|
||||
dataConfigurator.save(savesFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
@ -432,7 +437,7 @@ public class DataHandler {
|
||||
dataConfigurator.set("npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands", commandsData);
|
||||
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.EDITED_COMMAND).replace("{type}", typeText));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.EDITED_COMMAND).replace("{type}", typeText));
|
||||
|
||||
dataConfigurator.save(savesFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
@ -455,8 +460,8 @@ public class DataHandler {
|
||||
if (dataConfigurator.contains("npc-data.npc-" + npc))
|
||||
dataConfigurator.set("npc-data.npc-" + npc, null);
|
||||
|
||||
clearCache();
|
||||
cacheData();
|
||||
/*clearCache();
|
||||
cacheData();*/
|
||||
|
||||
dataConfigurator.save(savesFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
|
@ -32,11 +32,13 @@ import static me.mattmoreira.citizenscmd.utility.Util.*;
|
||||
|
||||
public class LangHandler {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private String lang;
|
||||
|
||||
private HashMap<String, String> messages;
|
||||
|
||||
public LangHandler(String lang) {
|
||||
public LangHandler(CitizensCMD plugin, String lang) {
|
||||
this.plugin = plugin;
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
@ -81,10 +83,10 @@ public class LangHandler {
|
||||
FileConfiguration langConf;
|
||||
|
||||
try {
|
||||
langFile = new File(CitizensCMD.getPlugin().getDataFolder(), "lang/" + lang + ".yml");
|
||||
langFile = new File(plugin.getDataFolder(), "lang/" + lang + ".yml");
|
||||
langConf = new YamlConfiguration();
|
||||
|
||||
if (!langFile.exists()) CitizensCMD.getPlugin().saveResource("lang/" + lang + ".yml", false);
|
||||
if (!langFile.exists()) plugin.saveResource("lang/" + lang + ".yml", false);
|
||||
|
||||
langConf.load(langFile);
|
||||
|
||||
|
@ -47,66 +47,69 @@ import static me.mattmoreira.citizenscmd.utility.Util.color;
|
||||
|
||||
public class NPCListener implements Listener {
|
||||
|
||||
public NPCListener() {
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(CitizensCMD.getPlugin(), "BungeeCord");
|
||||
private CitizensCMD plugin;
|
||||
|
||||
public NPCListener(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord");
|
||||
}
|
||||
|
||||
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onRightClick(NPCRightClickEvent event) {
|
||||
int npc = event.getNPC().getId();
|
||||
Player player = event.getClicker();
|
||||
|
||||
if (!player.hasPermission("citizenscmd.use")) return;
|
||||
|
||||
if (!CitizensCMD.getPlugin().getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc)) {
|
||||
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc)) {
|
||||
if (!player.hasPermission("citizenscmd.bypass")) {
|
||||
if (CitizensCMD.getPlugin().getCooldownHandler().onCooldown(npc, player.getUniqueId().toString())) {
|
||||
if (plugin.getCooldownHandler().onCooldown(npc, player.getUniqueId().toString())) {
|
||||
String cooldownMessage;
|
||||
if (CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc) == -1)
|
||||
cooldownMessage = CitizensCMD.getPlugin().getLang().getMessage(Path.ONE_TIME_CLICK);
|
||||
if (plugin.getDataHandler().getNPCCooldown(npc) == -1)
|
||||
cooldownMessage = plugin.getLang().getMessage(Path.ONE_TIME_CLICK);
|
||||
else
|
||||
cooldownMessage = CitizensCMD.getPlugin().getLang().getMessage(Path.ON_COOLDOWN);
|
||||
player.sendMessage(cooldownMessage.replace("{time}", getFormattedTime(CitizensCMD.getPlugin().getCooldownHandler().getTimeLeft(npc, player.getUniqueId().toString()), CitizensCMD.getPlugin().getDisplayFormat())));
|
||||
cooldownMessage = plugin.getLang().getMessage(Path.ON_COOLDOWN);
|
||||
player.sendMessage(cooldownMessage.replace("{time}", getFormattedTime(plugin, plugin.getCooldownHandler().getTimeLeft(npc, player.getUniqueId().toString()), plugin.getDisplayFormat())));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (CitizensCMD.getPlugin().getDataHandler().hasSound(npc)) {
|
||||
List<String> soundProperties = CitizensCMD.getPlugin().getDataHandler().getNPCSound(npc);
|
||||
if (plugin.getDataHandler().hasSound(npc)) {
|
||||
List<String> soundProperties = plugin.getDataHandler().getNPCSound(npc);
|
||||
player.playSound(player.getLocation(), Sound.valueOf(soundProperties.get(0).toUpperCase()), Float.parseFloat(soundProperties.get(1)), Float.parseFloat(soundProperties.get(2)));
|
||||
}
|
||||
|
||||
if (CitizensCMD.getPlugin().getDataHandler().hasNoCommands(npc, EnumTypes.ClickType.RIGHT)) return;
|
||||
if (plugin.getDataHandler().hasNoCommands(npc, EnumTypes.ClickType.RIGHT)) return;
|
||||
}
|
||||
|
||||
double price = CitizensCMD.getPlugin().getDataHandler().getPrice(npc);
|
||||
double price = plugin.getDataHandler().getPrice(npc);
|
||||
|
||||
if (price > 0.0) {
|
||||
if (CitizensCMD.getEconomy() != null) {
|
||||
|
||||
if (!CitizensCMD.getPlugin().getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc)) {
|
||||
String messageConfirm = CitizensCMD.getPlugin().getLang().getMessage(Path.PAY_CONFIRM);
|
||||
if (!CitizensCMD.getPlugin().shouldShift())
|
||||
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc)) {
|
||||
String messageConfirm = plugin.getLang().getMessage(Path.PAY_CONFIRM);
|
||||
if (!plugin.shouldShift())
|
||||
messageConfirm = messageConfirm.replace("{shift}", "");
|
||||
else
|
||||
messageConfirm = messageConfirm.replace("{shift}", "Shift ");
|
||||
messageConfirm = messageConfirm.replace("{price}", String.valueOf(price));
|
||||
player.sendMessage(messageConfirm);
|
||||
CitizensCMD.getPlugin().getWaitingList().put(player.getUniqueId().toString() + "." + npc, true);
|
||||
new ConfirmScheduler(player, npc).runTaskLaterAsynchronously(CitizensCMD.getPlugin(), 300L);
|
||||
plugin.getWaitingList().put(player.getUniqueId().toString() + "." + npc, true);
|
||||
new ConfirmScheduler(plugin, player, npc).runTaskLaterAsynchronously(plugin, 300L);
|
||||
return;
|
||||
}
|
||||
|
||||
if (CitizensCMD.getPlugin().shouldShift() && !player.isSneaking()) return;
|
||||
if (plugin.shouldShift() && !player.isSneaking()) return;
|
||||
|
||||
if (CitizensCMD.getEconomy().getBalance(player) < price) {
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.PAY_NO_MONEY));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.PAY_NO_MONEY));
|
||||
return;
|
||||
}
|
||||
|
||||
CitizensCMD.getPlugin().getWaitingList().remove(player.getUniqueId().toString() + "." + npc);
|
||||
plugin.getWaitingList().remove(player.getUniqueId().toString() + "." + npc);
|
||||
CitizensCMD.getEconomy().withdrawPlayer(player, price);
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.PAY_COMPLETED).replace("{price}", String.valueOf(price)));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.PAY_COMPLETED).replace("{price}", String.valueOf(price)));
|
||||
|
||||
}
|
||||
}
|
||||
@ -114,20 +117,18 @@ public class NPCListener implements Listener {
|
||||
List<String> permissions = new ArrayList<>();
|
||||
List<String> commands = new ArrayList<>();
|
||||
|
||||
for (String list : CitizensCMD.getPlugin().getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT)) {
|
||||
for (String list : plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT)) {
|
||||
Pattern pattern = Pattern.compile("\\[([^]]*)] ([^]]*)");
|
||||
Matcher matcher = pattern.matcher(list);
|
||||
if (matcher.find()) {
|
||||
permissions.add(matcher.group(1));
|
||||
String command = matcher.group(2);
|
||||
if (command.contains("%p%"))
|
||||
command = command.replace("%p%", player.getName());
|
||||
if (command.contains("%player%"))
|
||||
command = command.replace("%player%", player.getName());
|
||||
if (CitizensCMD.getPlugin().papiEnabled())
|
||||
if (command.contains("%p%")) command = command.replace("%p%", player.getName());
|
||||
if (command.contains("%player%")) command = command.replace("%player%", player.getName());
|
||||
if (plugin.papiEnabled())
|
||||
commands.add(PlaceholderAPI.setPlaceholders((OfflinePlayer) player, command));
|
||||
else
|
||||
commands.add(command);
|
||||
else commands.add(command);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,7 +138,7 @@ public class NPCListener implements Listener {
|
||||
switch (permissions.get(i).toLowerCase()) {
|
||||
|
||||
case "console":
|
||||
CitizensCMD.getPlugin().getServer().dispatchCommand(CitizensCMD.getPlugin().getServer().getConsoleSender(), commands.get(i));
|
||||
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), commands.get(i));
|
||||
break;
|
||||
|
||||
case "none":
|
||||
@ -151,7 +152,7 @@ public class NPCListener implements Listener {
|
||||
case "message":
|
||||
String finalMessage;
|
||||
if (commands.get(i).contains("{display}")) {
|
||||
String tmpStr = commands.get(i).replace("{display}", CitizensCMD.getPlugin().getLang().getMessage(Path.MESSAGE_DISPLAY));
|
||||
String tmpStr = commands.get(i).replace("{display}", plugin.getLang().getMessage(Path.MESSAGE_DISPLAY));
|
||||
finalMessage = tmpStr.replace("{name}", event.getNPC().getFullName());
|
||||
} else
|
||||
finalMessage = commands.get(i);
|
||||
@ -159,67 +160,68 @@ public class NPCListener implements Listener {
|
||||
break;
|
||||
|
||||
default:
|
||||
CitizensCMD.getPlugin().getPermissionsManager().setPermission(player, permissions.get(i));
|
||||
plugin.getPermissionsManager().setPermission(player, permissions.get(i));
|
||||
player.chat("/" + commands.get(i));
|
||||
CitizensCMD.getPlugin().getPermissionsManager().unsetPermission(player, permissions.get(i));
|
||||
plugin.getPermissionsManager().unsetPermission(player, permissions.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
if (!player.hasPermission("citizenscmd.bypass") || CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc) != 0)
|
||||
CitizensCMD.getPlugin().getCooldownHandler().addInteraction(npc, player.getUniqueId().toString(), System.nanoTime());
|
||||
if (!player.hasPermission("citizenscmd.bypass") || plugin.getDataHandler().getNPCCooldown(npc) != 0) {
|
||||
plugin.getCooldownHandler().addInteraction(npc, player.getUniqueId().toString(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onLeftClick(NPCLeftClickEvent event) {
|
||||
int npc = event.getNPC().getId();
|
||||
Player player = event.getClicker();
|
||||
|
||||
if (!player.hasPermission("citizenscmd.use")) return;
|
||||
|
||||
if (!CitizensCMD.getPlugin().getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc)) {
|
||||
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc)) {
|
||||
if (!player.hasPermission("citizenscmd.bypass")) {
|
||||
if (CitizensCMD.getPlugin().getCooldownHandler().onCooldown(npc, player.getUniqueId().toString())) {
|
||||
if (plugin.getCooldownHandler().onCooldown(npc, player.getUniqueId().toString())) {
|
||||
String cooldownMessage;
|
||||
if (CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc) == -1)
|
||||
cooldownMessage = CitizensCMD.getPlugin().getLang().getMessage(Path.ONE_TIME_CLICK);
|
||||
if (plugin.getDataHandler().getNPCCooldown(npc) == -1)
|
||||
cooldownMessage = plugin.getLang().getMessage(Path.ONE_TIME_CLICK);
|
||||
else
|
||||
cooldownMessage = CitizensCMD.getPlugin().getLang().getMessage(Path.ON_COOLDOWN);
|
||||
player.sendMessage(cooldownMessage.replace("{time}", getFormattedTime(CitizensCMD.getPlugin().getCooldownHandler().getTimeLeft(npc, player.getUniqueId().toString()), CitizensCMD.getPlugin().getDisplayFormat())));
|
||||
cooldownMessage = plugin.getLang().getMessage(Path.ON_COOLDOWN);
|
||||
player.sendMessage(cooldownMessage.replace("{time}", getFormattedTime(plugin, plugin.getCooldownHandler().getTimeLeft(npc, player.getUniqueId().toString()), plugin.getDisplayFormat())));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (CitizensCMD.getPlugin().getDataHandler().hasSound(npc)) {
|
||||
List<String> soundProperties = CitizensCMD.getPlugin().getDataHandler().getNPCSound(npc);
|
||||
if (plugin.getDataHandler().hasSound(npc)) {
|
||||
List<String> soundProperties = plugin.getDataHandler().getNPCSound(npc);
|
||||
player.playSound(player.getLocation(), Sound.valueOf(soundProperties.get(0)), Float.parseFloat(soundProperties.get(1)), Float.parseFloat(soundProperties.get(2)));
|
||||
}
|
||||
|
||||
if (CitizensCMD.getPlugin().getDataHandler().hasNoCommands(npc, EnumTypes.ClickType.LEFT)) return;
|
||||
if (plugin.getDataHandler().hasNoCommands(npc, EnumTypes.ClickType.LEFT)) return;
|
||||
}
|
||||
|
||||
double price = CitizensCMD.getPlugin().getDataHandler().getPrice(npc);
|
||||
double price = plugin.getDataHandler().getPrice(npc);
|
||||
|
||||
if (price > 0.0) {
|
||||
if (CitizensCMD.getEconomy() != null) {
|
||||
|
||||
if (!CitizensCMD.getPlugin().getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc)) {
|
||||
String messageConfirm = CitizensCMD.getPlugin().getLang().getMessage(Path.PAY_CONFIRM);
|
||||
if (!CitizensCMD.getPlugin().shouldShift())
|
||||
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc)) {
|
||||
String messageConfirm = plugin.getLang().getMessage(Path.PAY_CONFIRM);
|
||||
if (!plugin.shouldShift())
|
||||
messageConfirm = messageConfirm.replace("{shift}", "");
|
||||
else
|
||||
messageConfirm = messageConfirm.replace("{shift}", "Shift ");
|
||||
messageConfirm = messageConfirm.replace("{price}", String.valueOf(price));
|
||||
player.sendMessage(messageConfirm);
|
||||
CitizensCMD.getPlugin().getWaitingList().put(player.getUniqueId().toString() + "." + npc, true);
|
||||
new ConfirmScheduler(player, npc).runTaskLaterAsynchronously(CitizensCMD.getPlugin(), 300L);
|
||||
plugin.getWaitingList().put(player.getUniqueId().toString() + "." + npc, true);
|
||||
new ConfirmScheduler(plugin, player, npc).runTaskLaterAsynchronously(plugin, 300L);
|
||||
return;
|
||||
}
|
||||
|
||||
if (CitizensCMD.getPlugin().shouldShift() && !player.isSneaking()) return;
|
||||
if (plugin.shouldShift() && !player.isSneaking()) return;
|
||||
|
||||
CitizensCMD.getPlugin().getWaitingList().remove(player.getUniqueId().toString() + "." + npc);
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.PAY_CANCELED));
|
||||
plugin.getWaitingList().remove(player.getUniqueId().toString() + "." + npc);
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.PAY_CANCELED));
|
||||
|
||||
}
|
||||
}
|
||||
@ -227,7 +229,7 @@ public class NPCListener implements Listener {
|
||||
List<String> permissions = new ArrayList<>();
|
||||
List<String> commands = new ArrayList<>();
|
||||
|
||||
for (String list : CitizensCMD.getPlugin().getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT)) {
|
||||
for (String list : plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT)) {
|
||||
Pattern pattern = Pattern.compile("\\[([^]]*)] ([^]]*)");
|
||||
Matcher matcher = pattern.matcher(list);
|
||||
if (matcher.find()) {
|
||||
@ -237,7 +239,7 @@ public class NPCListener implements Listener {
|
||||
command = command.replace("%p%", player.getName());
|
||||
if (command.contains("%player%"))
|
||||
command = command.replace("%player%", player.getName());
|
||||
if (CitizensCMD.getPlugin().papiEnabled())
|
||||
if (plugin.papiEnabled())
|
||||
commands.add(PlaceholderAPI.setPlaceholders((OfflinePlayer) player, command));
|
||||
else
|
||||
commands.add(command);
|
||||
@ -250,7 +252,7 @@ public class NPCListener implements Listener {
|
||||
switch (permissions.get(i).toLowerCase()) {
|
||||
|
||||
case "console":
|
||||
CitizensCMD.getPlugin().getServer().dispatchCommand(CitizensCMD.getPlugin().getServer().getConsoleSender(), commands.get(i));
|
||||
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), commands.get(i));
|
||||
break;
|
||||
|
||||
case "none":
|
||||
@ -264,7 +266,7 @@ public class NPCListener implements Listener {
|
||||
case "message":
|
||||
String finalMessage;
|
||||
if (commands.get(i).contains("{display}")) {
|
||||
String tmpStr = commands.get(i).replace("{display}", CitizensCMD.getPlugin().getLang().getMessage(Path.MESSAGE_DISPLAY));
|
||||
String tmpStr = commands.get(i).replace("{display}", plugin.getLang().getMessage(Path.MESSAGE_DISPLAY));
|
||||
finalMessage = tmpStr.replace("{name}", event.getNPC().getFullName());
|
||||
} else
|
||||
finalMessage = commands.get(i);
|
||||
@ -272,19 +274,20 @@ public class NPCListener implements Listener {
|
||||
break;
|
||||
|
||||
default:
|
||||
CitizensCMD.getPlugin().getPermissionsManager().setPermission(player, permissions.get(i));
|
||||
plugin.getPermissionsManager().setPermission(player, permissions.get(i));
|
||||
player.chat("/" + commands.get(i));
|
||||
CitizensCMD.getPlugin().getPermissionsManager().unsetPermission(player, permissions.get(i));
|
||||
plugin.getPermissionsManager().unsetPermission(player, permissions.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
if (!player.hasPermission("citizenscmd.bypass") || CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc) != 0)
|
||||
CitizensCMD.getPlugin().getCooldownHandler().addInteraction(npc, player.getUniqueId().toString(), System.nanoTime());
|
||||
if (!player.hasPermission("citizenscmd.bypass") || plugin.getDataHandler().getNPCCooldown(npc) != 0) {
|
||||
plugin.getCooldownHandler().addInteraction(npc, player.getUniqueId().toString(), System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler (priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onRemoveNPC(NPCRemoveEvent event) {
|
||||
CitizensCMD.getPlugin().getDataHandler().removeNPCData(event.getNPC().getId());
|
||||
plugin.getDataHandler().removeNPCData(event.getNPC().getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -302,7 +305,7 @@ public class NPCListener implements Listener {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
player.sendPluginMessage(CitizensCMD.getPlugin(), "BungeeCord", byteArrayOutputStream.toByteArray());
|
||||
player.sendPluginMessage(plugin, "BungeeCord", byteArrayOutputStream.toByteArray());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,12 +31,18 @@ import static me.mattmoreira.citizenscmd.utility.Util.color;
|
||||
|
||||
public class UpdateEvent implements Listener {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
|
||||
public UpdateEvent(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler (priority = EventPriority.NORMAL)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (CitizensCMD.getPlugin().getUpdateStatus() && event.getPlayer().hasPermission("citizenscmd.update")) {
|
||||
if (plugin.getUpdateStatus() && event.getPlayer().hasPermission("citizenscmd.update")) {
|
||||
JSONMessage.create(color(HEADER)).send(event.getPlayer());
|
||||
JSONMessage.create(color(CitizensCMD.getPlugin().getLang().getUncoloredMessage(Path.NEW_VERSION) + CitizensCMD.getPlugin().getNewVersion())).send(event.getPlayer());
|
||||
JSONMessage.create(color(CitizensCMD.getPlugin().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(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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,10 @@ import java.util.UUID;
|
||||
public class PermissionsManager {
|
||||
|
||||
private HashMap<UUID, PermissionAttachment> permissionsData;
|
||||
private CitizensCMD plugin;
|
||||
|
||||
public PermissionsManager() {
|
||||
public PermissionsManager(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
permissionsData = new HashMap<>();
|
||||
}
|
||||
|
||||
@ -41,7 +43,7 @@ public class PermissionsManager {
|
||||
* @param permission The permission node
|
||||
*/
|
||||
public void setPermission(Player player, String permission) {
|
||||
PermissionAttachment permissionAttachment = player.addAttachment(CitizensCMD.getPlugin());
|
||||
PermissionAttachment permissionAttachment = player.addAttachment(plugin);
|
||||
permissionsData.put(player.getUniqueId(), permissionAttachment);
|
||||
PermissionAttachment permissionAttachment1 = permissionsData.get(player.getUniqueId());
|
||||
permissionAttachment1.setPermission(permission, true);
|
||||
|
@ -27,10 +27,12 @@ public class ConfirmScheduler extends BukkitRunnable {
|
||||
|
||||
private Player player;
|
||||
private int npc;
|
||||
private CitizensCMD plugin;
|
||||
|
||||
public ConfirmScheduler(Player player, int npc) {
|
||||
public ConfirmScheduler(CitizensCMD plugin, Player player, int npc) {
|
||||
this.player = player;
|
||||
this.npc = npc;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,9 +40,9 @@ public class ConfirmScheduler extends BukkitRunnable {
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
if (CitizensCMD.getPlugin().getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc)) {
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.PAY_CANCELED));
|
||||
CitizensCMD.getPlugin().getWaitingList().remove(player.getUniqueId().toString() + "." + npc);
|
||||
if (plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc)) {
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.PAY_CANCELED));
|
||||
plugin.getWaitingList().remove(player.getUniqueId().toString() + "." + npc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,12 +23,18 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class CooldownScheduler extends BukkitRunnable {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
|
||||
public CooldownScheduler(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the cached cooldowns on file every 30 minutes
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
CitizensCMD.getPlugin().getCooldownHandler().saveToFile();
|
||||
plugin.getCooldownHandler().saveToFile();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,16 +24,22 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class UpdateScheduler extends BukkitRunnable {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
|
||||
public UpdateScheduler(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for updates every hour and tells the player on join
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
SpigotUpdater updater = new SpigotUpdater(CitizensCMD.getPlugin(), 30224);
|
||||
SpigotUpdater updater = new SpigotUpdater(plugin, 30224);
|
||||
try {
|
||||
if (updater.checkForUpdates()) {
|
||||
CitizensCMD.getPlugin().setUpdateStatus(true);
|
||||
CitizensCMD.getPlugin().setNewVersion(updater.getLatestVersion());
|
||||
plugin.setUpdateStatus(true);
|
||||
plugin.setNewVersion(updater.getLatestVersion());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -47,13 +47,13 @@ public class TimeUtil {
|
||||
* @param seconds The time in seconds to be converted
|
||||
* @return String with the time like "2d 2h 2m 2s"
|
||||
*/
|
||||
public static String getFormattedTime(long seconds, DisplayFormat format) {
|
||||
public static String getFormattedTime(CitizensCMD plugin, long seconds, DisplayFormat format) {
|
||||
|
||||
String messagesString[] = new String[4];
|
||||
messagesString[0] = CitizensCMD.getPlugin().getLang().getMessage(Path.SECONDS);
|
||||
messagesString[1] = CitizensCMD.getPlugin().getLang().getMessage(Path.MINUTES);
|
||||
messagesString[2] = CitizensCMD.getPlugin().getLang().getMessage(Path.HOURS);
|
||||
messagesString[3] = CitizensCMD.getPlugin().getLang().getMessage(Path.DAYS);
|
||||
messagesString[0] = plugin.getLang().getMessage(Path.SECONDS);
|
||||
messagesString[1] = plugin.getLang().getMessage(Path.MINUTES);
|
||||
messagesString[2] = plugin.getLang().getMessage(Path.HOURS);
|
||||
messagesString[3] = plugin.getLang().getMessage(Path.DAYS);
|
||||
|
||||
String shorts[] = new String[4];
|
||||
String mediums[] = new String[4];
|
||||
|
@ -27,14 +27,9 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.InvalidDescriptionException;
|
||||
import org.bukkit.plugin.InvalidPluginException;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Util {
|
||||
@ -90,11 +85,11 @@ public class Util {
|
||||
* @param player The player to check if it has any NPC selected or not
|
||||
* @return Returns true if has an NPC selected and false if not
|
||||
*/
|
||||
public static boolean npcNotSelected(Player player) {
|
||||
public static boolean npcNotSelected(CitizensCMD plugin, Player player) {
|
||||
if (CitizensAPI.getDefaultNPCSelector().getSelected(player) != null) return false;
|
||||
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(CitizensCMD.getPlugin().getLang().getMessage(Path.NO_NPC));
|
||||
player.sendMessage(plugin.getLang().getMessage(Path.NO_NPC));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -123,8 +118,8 @@ public class Util {
|
||||
*
|
||||
* @return Returns true if CheckUpdates is true on the config and false if not
|
||||
*/
|
||||
public static boolean upCheck() {
|
||||
return CitizensCMD.getPlugin().getConfig().getBoolean("check-updates");
|
||||
public static boolean upCheck(CitizensCMD plugin) {
|
||||
return plugin.getConfig().getBoolean("check-updates");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -151,8 +146,8 @@ public class Util {
|
||||
*
|
||||
* @return returns the seconds from the config
|
||||
*/
|
||||
public static int getDefaultCooldown() {
|
||||
return CitizensCMD.getPlugin().getConfig().getInt("default-cooldown");
|
||||
public static int getDefaultCooldown(CitizensCMD plugin) {
|
||||
return plugin.getConfig().getInt("default-cooldown");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -160,7 +155,7 @@ public class Util {
|
||||
*
|
||||
* @return Returns 2d string array with arguments for tab completion
|
||||
*/
|
||||
public static String[][] getTabCompleteArgs(String subCMD, Player player) {
|
||||
public static String[][] getTabCompleteArgs(CitizensCMD plugin, String subCMD, Player player) {
|
||||
String[][] argComplete = new String[5][];
|
||||
|
||||
switch (subCMD.toLowerCase()) {
|
||||
@ -169,14 +164,14 @@ public class Util {
|
||||
break;
|
||||
case "remove":
|
||||
argComplete[0] = new String[]{"left", "right"};
|
||||
argComplete[1] = CitizensCMD.getPlugin().getDataHandler().getCompleteCommandsNumbers(getSelectedNpcId(player), EnumTypes.ClickType.LEFT);
|
||||
argComplete[2] = CitizensCMD.getPlugin().getDataHandler().getCompleteCommandsNumbers(getSelectedNpcId(player), EnumTypes.ClickType.RIGHT);
|
||||
argComplete[1] = plugin.getDataHandler().getCompleteCommandsNumbers(getSelectedNpcId(player), EnumTypes.ClickType.LEFT);
|
||||
argComplete[2] = plugin.getDataHandler().getCompleteCommandsNumbers(getSelectedNpcId(player), EnumTypes.ClickType.RIGHT);
|
||||
break;
|
||||
case "edit":
|
||||
argComplete[0] = new String[]{"perm", "cmd"};
|
||||
argComplete[1] = new String[]{"left", "right"};
|
||||
argComplete[2] = CitizensCMD.getPlugin().getDataHandler().getCompleteCommandsNumbers(getSelectedNpcId(player), EnumTypes.ClickType.LEFT);
|
||||
argComplete[3] = CitizensCMD.getPlugin().getDataHandler().getCompleteCommandsNumbers(getSelectedNpcId(player), EnumTypes.ClickType.RIGHT);
|
||||
argComplete[2] = plugin.getDataHandler().getCompleteCommandsNumbers(getSelectedNpcId(player), EnumTypes.ClickType.LEFT);
|
||||
argComplete[3] = plugin.getDataHandler().getCompleteCommandsNumbers(getSelectedNpcId(player), EnumTypes.ClickType.RIGHT);
|
||||
argComplete[4] = new String[]{"console", "none", "permission", "server", "message"};
|
||||
break;
|
||||
|
||||
@ -205,13 +200,13 @@ public class Util {
|
||||
* @return returns the difference in seconds
|
||||
*/
|
||||
public static long getSecondsDifference(long storedTime) {
|
||||
return TimeUnit.SECONDS.convert((System.nanoTime() - storedTime), TimeUnit.NANOSECONDS);
|
||||
return TimeUnit.SECONDS.convert((System.currentTimeMillis() - storedTime), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for old config and renames it
|
||||
*/
|
||||
public static void checkOldConfig() {
|
||||
public static void checkOldConfig(CitizensCMD plugin) {
|
||||
File configFile;
|
||||
File configFileNew;
|
||||
FileConfiguration configConf;
|
||||
@ -224,8 +219,8 @@ public class Util {
|
||||
}
|
||||
|
||||
try {
|
||||
configFile = new File(CitizensCMD.getPlugin().getDataFolder(), "config.yml");
|
||||
configFileNew = new File(CitizensCMD.getPlugin().getDataFolder(), "config_old.yml");
|
||||
configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
configFileNew = new File(plugin.getDataFolder(), "config_old.yml");
|
||||
configConf = new YamlConfiguration();
|
||||
|
||||
if (configFile.exists()) {
|
||||
@ -252,29 +247,14 @@ public class Util {
|
||||
}
|
||||
}
|
||||
|
||||
public static void downloadCitizens() {
|
||||
try {
|
||||
Files.copy(new URL("http://ci.citizensnpcs.co/job/Citizens2/lastSuccessfulBuild/artifact/dist/target/citizens-2.0.24-SNAPSHOT.jar").openStream(), new File(Bukkit.getServer().getUpdateFolderFile().getParentFile(), "Citizens.jar").toPath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadCitizens() {
|
||||
File pluginFolder = Bukkit.getServer().getUpdateFolderFile().getParentFile();
|
||||
Plugin loadedPlugin;
|
||||
try {
|
||||
loadedPlugin = Bukkit.getPluginManager().loadPlugin(new File(pluginFolder, "Citizens.jar"));
|
||||
loadedPlugin.onLoad();
|
||||
Bukkit.getPluginManager().enablePlugin(loadedPlugin);
|
||||
} catch (InvalidPluginException | InvalidDescriptionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public static void disablePlugin(CitizensCMD plugin) {
|
||||
info(color(TAG + "&cCitizens &7is needed for this plugin to work!"));
|
||||
info(color(TAG + "&cCitizens.jar &7is not installed on the server!"));
|
||||
info(color(TAG + "&cDisabling CitizensCMD..."));
|
||||
Bukkit.getServer().getPluginManager().disablePlugin(plugin);
|
||||
}
|
||||
|
||||
public static boolean doesCitizensExist() {
|
||||
File pluginFolder = Bukkit.getServer().getUpdateFolderFile().getParentFile();
|
||||
File citizens = new File(pluginFolder, "Citizens.jar");
|
||||
return citizens.exists();
|
||||
return Bukkit.getPluginManager().isPluginEnabled("Citizens");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user