Code cleanup. Per NPC permission. Command delay.

This commit is contained in:
Mateus 2019-06-14 01:55:50 +01:00
parent ab1eeffa84
commit 645bbf5fd5
38 changed files with 1165 additions and 1042 deletions

16
pom.xml
View File

@ -85,13 +85,13 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<version>1.14.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>citizensapi</artifactId>
<version>2.0.24-SNAPSHOT</version>
<version>2.0.25-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -111,5 +111,17 @@
<version>da407c0059</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>13.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,21 @@
package me.mattmoreira.citizenscmd.API;
import me.mattmoreira.citizenscmd.files.DataHandler;
public class CitizensCMDAPI {
private final DataHandler dataHandler;
public CitizensCMDAPI (DataHandler dataHandler) {
this.dataHandler = dataHandler;
}
public void addCommand(int npcID, String permission, String command, boolean left) {
dataHandler.addCommand(npcID, permission, command, left);
}
public void removeNPCData(int npcID) {
dataHandler.removeNPCData(npcID);
}
}

View File

@ -1,23 +1,26 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd;
import lombok.Getter;
import lombok.Setter;
import me.mattmoreira.citizenscmd.API.CitizensCMDAPI;
import me.mattmoreira.citizenscmd.commands.*;
import me.mattmoreira.citizenscmd.commands.base.CommandHandler;
import me.mattmoreira.citizenscmd.files.CooldownHandler;
@ -40,10 +43,13 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.HashMap;
import java.util.Objects;
import java.util.stream.Stream;
import static me.mattmoreira.citizenscmd.utility.Util.*;
@Getter
@Setter
public final class CitizensCMD extends JavaPlugin {
/**
@ -51,20 +57,26 @@ public final class CitizensCMD extends JavaPlugin {
*/
private final String[] REGISTERED_LANG_FILES = {"en", "pt", "ro", "bg", "no", "ch"};
private static CommandHandler commandHandler = null;
private static LangHandler lang = null;
private static DataHandler dataHandler = null;
private static CooldownHandler cooldownHandler = null;
private static PermissionsManager permissionsManager = null;
private LangHandler lang = null;
private DataHandler dataHandler = null;
private CooldownHandler cooldownHandler = null;
private PermissionsManager permissionsManager = null;
@Getter
private static CitizensCMDAPI api;
@Getter
private static Economy economy = null;
private static boolean papi = false;
private static boolean updateStatus = false;
private static boolean shift = false;
private static String newVersion;
private static DisplayFormat displayFormat;
private boolean papi = false;
private CommandHandler commandHandler = null;
private static HashMap<String, Boolean> waitingList;
private boolean updateStatus = false;
private boolean shift = false;
private String newVersion;
private DisplayFormat displayFormat;
private HashMap<String, Boolean> waitingList;
public void onEnable() {
@ -95,7 +107,7 @@ public final class CitizensCMD extends JavaPlugin {
registerEvents();
registerLangs(this);
setLang(getConfig().getString("lang"));
setLang(Objects.requireNonNull(getConfig().getString("lang")));
if (hasPAPI()) {
switch (lang.getLanguage()) {
@ -147,13 +159,10 @@ public final class CitizensCMD extends JavaPlugin {
waitingList = new HashMap<>();
if (getConfig().contains("cooldown-time-display")) {
switch (getConfig().getString("cooldown-time-display").toLowerCase()) {
switch (Objects.requireNonNull(getConfig().getString("cooldown-time-display")).toLowerCase()) {
case "short":
displayFormat = DisplayFormat.SHORT;
break;
case "medium":
displayFormat = DisplayFormat.MEDIUM;
break;
case "full":
displayFormat = DisplayFormat.FULL;
break;
@ -175,7 +184,7 @@ public final class CitizensCMD extends JavaPlugin {
info(color(TAG + "&cA new version of CitizensCMD is now available:"));
break;
case "pt":
info(color(TAG + "&cA new version of CitizensCMD is now available:"));
info(color(TAG + "&cA nova versão de CitizensCMD está disponivel:"));
break;
case "ro":
info(color(TAG + "&cO noua versiune a CitizensCMD este acum valabila:"));
@ -199,6 +208,8 @@ public final class CitizensCMD extends JavaPlugin {
}
}
api = new CitizensCMDAPI(dataHandler);
new UpdateScheduler(this).runTaskTimerAsynchronously(this, 72000L, 72000L);
new CooldownScheduler(this).runTaskTimerAsynchronously(this, 36000L, 36000L);
}
@ -228,8 +239,18 @@ public final class CitizensCMD extends JavaPlugin {
* Registers all the commands to be used
*/
private void registerCommands() {
getCommand("npcmd").setExecutor(commandHandler);
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)).forEach(commandHandler::register);
Objects.requireNonNull(getCommand("npcmd")).setExecutor(commandHandler);
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 CMDPermission(this)
).forEach(commandHandler::register);
}
/**
@ -279,12 +300,6 @@ public final class CitizensCMD extends JavaPlugin {
*/
public void setLang(String language) {
switch (language.toLowerCase()) {
case "en":
case "eng":
case "english":
lang = new LangHandler(this, "en");
break;
case "pt":
case "port":
case "portuguese":
@ -322,114 +337,6 @@ public final class CitizensCMD extends JavaPlugin {
lang.initialize();
}
/**
* 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) {
CitizensCMD.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) {
CitizensCMD.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) {
CitizensCMD.shift = shift;
}
/**
* Checks is PAPI is present or not
*
@ -438,22 +345,4 @@ public final class CitizensCMD extends JavaPlugin {
public boolean papiEnabled() {
return papi;
}
/**
* 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) {
CitizensCMD.displayFormat = displayFormat;
}
}

View File

@ -1,38 +1,38 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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.entity.Player;
import java.util.Arrays;
import static me.mattmoreira.citizenscmd.utility.Util.getSelectedNpcId;
import static me.mattmoreira.citizenscmd.utility.Util.npcNotSelected;
import static me.mattmoreira.citizenscmd.utility.Util.*;
public class CMDAdd extends CommandBase {
private CitizensCMD plugin;
public CMDAdd(CitizensCMD plugin) {
super("add", "citizenscmd.add", false, null, 2, 512);
super("add", "citizenscmd.add", false, null, 2, 2048);
this.plugin = plugin;
}
@ -47,36 +47,64 @@ public class CMDAdd extends CommandBase {
if (npcNotSelected(plugin, player)) return;
String permission = args[0];
StringBuilder permission = new StringBuilder(args[0]);
boolean left = false;
boolean displayName = false;
boolean hasDelayError = false;
StringBuilder stringBuilder = new StringBuilder();
String[] commandsArray = Arrays.copyOfRange(args, 1, args.length);
commandsArray[0] = commandsArray[0].replace("/", "");
for (int i = 0; i < commandsArray.length; i++) {
if (commandsArray[i].equalsIgnoreCase("-d")) {
if (commandsArray[i].equalsIgnoreCase("")) continue;
if (commandsArray[i].equalsIgnoreCase("-n")) {
displayName = true;
commandsArray[i] = "";
continue;
}
if (commandsArray[i].equalsIgnoreCase("-l")) {
left = true;
break;
continue;
}
if (commandsArray[i].equalsIgnoreCase("-d")) {
if (i + 1 >= commandsArray.length) {
hasDelayError = true;
continue;
}
if (notDouble(commandsArray[i + 1])) {
hasDelayError = true;
continue;
}
permission.append("(").append(commandsArray[i + 1]).append(")");
commandsArray[i + 1] = "";
continue;
}
if (i == commandsArray.length - 1) stringBuilder.append(commandsArray[i]);
else stringBuilder.append(commandsArray[i]).append(" ");
}
if (hasDelayError) {
player.sendMessage(color(HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.NPC_ADD_DELAY_FAIL));
return;
}
String finalString;
if (displayName) {
finalString = "{display} " + stringBuilder.toString().trim();
} else
} else {
finalString = stringBuilder.toString().trim();
}
if (permission.equalsIgnoreCase("sound")) {
if (permission.toString().equalsIgnoreCase("sound")) {
if (commandsArray.length < 2) {
finalString += " 1 1";
} else {
@ -86,7 +114,7 @@ public class CMDAdd extends CommandBase {
}
}
plugin.getDataHandler().addCommand(getSelectedNpcId(player), permission, finalString, player, left);
plugin.getDataHandler().addCommand(getSelectedNpcId(player), permission.toString(), finalString, player, left);
}
}

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.commands;

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.commands;

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.commands;
@ -50,6 +50,7 @@ public class CMDHelp extends CommandBase {
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 &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 &cpermission &b<set | remove> &6<custom.permission>")).suggestCommand("/npcmd permission ").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);
}

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.commands;

View File

@ -0,0 +1,67 @@
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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.entity.Player;
import static me.mattmoreira.citizenscmd.utility.Util.*;
public class CMDPermission extends CommandBase {
private CitizensCMD plugin;
public CMDPermission(CitizensCMD plugin) {
super("permission", "citizenscmd.permission", false, null, 1, 2);
this.plugin = plugin;
}
@Override
public void execute(Player player, String[] args) {
if (npcNotSelected(plugin, player)) return;
switch (args[0]) {
case "set":
if (args.length < 2) {
player.sendMessage(color(HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.WRONG_USAGE));
return;
}
plugin.getDataHandler().setCustomPermission(getSelectedNpcId(player), args[1], player);
break;
case "remove":
if (args.length > 1) {
player.sendMessage(color(HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.WRONG_USAGE));
return;
}
plugin.getDataHandler().removeCustomPermission(getSelectedNpcId(player), player);
break;
default:
player.sendMessage(color(HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.WRONG_USAGE));
}
}
}

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.commands;

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.commands;
@ -25,6 +25,8 @@ import me.mattmoreira.citizenscmd.utility.Path;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Objects;
import static me.mattmoreira.citizenscmd.utility.Util.HEADER;
import static me.mattmoreira.citizenscmd.utility.Util.color;
@ -41,16 +43,13 @@ public class CMDReload extends CommandBase {
public void execute(Player player, String[] args) {
plugin.reloadConfig();
plugin.saveDefaultConfig();
plugin.setLang(plugin.getConfig().getString("lang"));
plugin.setLang(Objects.requireNonNull(plugin.getConfig().getString("lang")));
if (plugin.getConfig().contains("cooldown-time-display")) {
switch (plugin.getConfig().getString("cooldown-time-display").toLowerCase()) {
switch (Objects.requireNonNull(plugin.getConfig().getString("cooldown-time-display")).toLowerCase()) {
case "short":
plugin.setDisplayFormat(DisplayFormat.SHORT);
break;
case "medium":
plugin.setDisplayFormat(DisplayFormat.MEDIUM);
break;
case "full":
plugin.setDisplayFormat(DisplayFormat.FULL);
break;
@ -74,16 +73,13 @@ public class CMDReload extends CommandBase {
public void execute(CommandSender sender, String[] args) {
plugin.reloadConfig();
plugin.saveConfig();
plugin.setLang(plugin.getConfig().getString("lang"));
plugin.setLang(Objects.requireNonNull(plugin.getConfig().getString("lang")));
if (plugin.getConfig().contains("cooldonw-time-display")) {
switch (plugin.getConfig().getString("cooldonw-time-display").toLowerCase()) {
if (plugin.getConfig().contains("cooldown-time-display")) {
switch (Objects.requireNonNull(plugin.getConfig().getString("cooldown-time-display")).toLowerCase()) {
case "short":
plugin.setDisplayFormat(DisplayFormat.SHORT);
break;
case "medium":
plugin.setDisplayFormat(DisplayFormat.MEDIUM);
break;
case "full":
plugin.setDisplayFormat(DisplayFormat.FULL);
break;

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.commands;

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.commands.base;
@ -69,19 +69,19 @@ public abstract class CommandBase {
return permission;
}
public boolean allowConsole() {
boolean allowConsole() {
return allowConsole;
}
public List<String> getAliases() {
List<String> getAliases() {
return aliases;
}
public int getMinimumArguments() {
int getMinimumArguments() {
return minimumArguments;
}
public int getMaximumArguments() {
int getMaximumArguments() {
return maximumArguments;
}
}

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.commands.base;
@ -26,6 +26,7 @@ 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;
@ -63,7 +64,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter, IHandler {
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, Command cmd, @NotNull String commandLabel, @NotNull String[] args) {
if (!cmd.getName().equalsIgnoreCase("npcmd")) {
return true;
}
@ -71,7 +72,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter, IHandler {
if (args.length == 0 || args[0].isEmpty()) {
if (sender.hasPermission("citizenscmd.npcmd"))
if (sender instanceof Player)
getCommand("help").execute((Player) sender, args);
getCommand().execute((Player) sender, args);
return true;
}
@ -119,9 +120,9 @@ public class CommandHandler implements CommandExecutor, TabCompleter, IHandler {
return true;
}
private CommandBase getCommand(String name) {
private CommandBase getCommand() {
return commands.stream().filter(
command -> command.getName() != null && command.getName().equalsIgnoreCase(name))
command -> command.getName() != null && command.getName().equalsIgnoreCase("help"))
.findFirst().orElse(null);
}
@ -130,8 +131,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter, IHandler {
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String commandLabel,
String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, Command cmd, @NotNull String commandLabel, @NotNull String[] args) {
if (cmd.getName().equalsIgnoreCase("npcmd")) {
if (args.length == 1) {
List<String> commandNames = new ArrayList<>();
@ -164,6 +164,11 @@ public class CommandHandler implements CommandExecutor, TabCompleter, IHandler {
}
break;
case "permission":
case "cooldown":
if (args.length == 2) return getCommandNames(subCMD, args, 1, (Player) sender);
break;
case "remove":
if (npcNotSelectedNM((Player) sender)) break;
if (args.length == 2) return getCommandNames(subCMD, args, 1, (Player) sender);

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.files;
@ -26,25 +26,26 @@ import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Objects;
import static me.mattmoreira.citizenscmd.utility.Util.*;
public class CooldownHandler {
private CitizensCMD plugin;
private static File cooldownsFile;
private static File dir;
private File cooldownsFile;
private File dir;
private static FileConfiguration cooldownsConfigurator;
private FileConfiguration cooldownsConfigurator;
private static HashMap<String, Long> cooldownData;
private HashMap<String, Long> cooldownData;
public CooldownHandler(CitizensCMD plugin) {
this.plugin = plugin;
}
/**
* Createst the basic of the class and starts the HashMap
* Creates the basic of the class and starts the HashMap
*/
public void initialize() {
File pluginFolder = plugin.getDataFolder();
@ -62,6 +63,7 @@ public class CooldownHandler {
/**
* Creates files and folders
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
private void createBasics() {
if (!dir.exists()) dir.mkdirs();
@ -85,8 +87,8 @@ public class CooldownHandler {
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)) {
for (String parent : Objects.requireNonNull(cooldownsConfigurator.getConfigurationSection("cooldown-data")).getKeys(false)) {
for (String child : Objects.requireNonNull(cooldownsConfigurator.getConfigurationSection("cooldown-data." + parent)).getKeys(false)) {
for (String npc : cachedDataFromSaves.keySet()) {
if (npc.equalsIgnoreCase(parent) && ((getSecondsDifference(cooldownsConfigurator.getLong("cooldown-data." + parent + "." + child)) < cachedDataFromSaves.get(npc)) || cachedDataFromSaves.get(npc) == -1))
cooldownData.put("cooldown-data." + parent + "." + child, cooldownsConfigurator.getLong("cooldown-data." + parent + "." + child));

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.files;
@ -21,7 +21,6 @@ package me.mattmoreira.citizenscmd.files;
import me.mattmoreira.citizenscmd.CitizensCMD;
import me.mattmoreira.citizenscmd.utility.EnumTypes;
import me.mattmoreira.citizenscmd.utility.Path;
import org.bukkit.Sound;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@ -32,9 +31,11 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import static me.mattmoreira.citizenscmd.utility.Util.*;
@SuppressWarnings("unchecked")
public class DataHandler {
private CitizensCMD plugin;
@ -67,6 +68,7 @@ public class DataHandler {
/**
* Creates files and folders
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
private void createBasics() {
if (!dir.exists()) dir.mkdirs();
@ -90,14 +92,17 @@ public class DataHandler {
if (!dataConfigurator.contains("npc-data")) return;
for (String parent : dataConfigurator.getConfigurationSection("npc-data").getKeys(false)) {
for (String child : dataConfigurator.getConfigurationSection("npc-data." + parent).getKeys(false)) {
for (String parent : Objects.requireNonNull(dataConfigurator.getConfigurationSection("npc-data")).getKeys(false)) {
for (String child : Objects.requireNonNull(dataConfigurator.getConfigurationSection("npc-data." + parent)).getKeys(false)) {
switch (child.toLowerCase()) {
case "permission":
data.put("npc-data." + parent + "." + child, dataConfigurator.getString("npc-data." + parent + "." + child));
break;
case "cooldown":
data.put("npc-data." + parent + "." + child, dataConfigurator.getInt("npc-data." + parent + "." + child));
break;
case "sound":
case "right-click-commands":
case "left-click-commands":
data.put("npc-data." + parent + "." + child, dataConfigurator.getStringList("npc-data." + parent + "." + child));
@ -118,13 +123,6 @@ public class DataHandler {
}).start();
}
/**
* Clears the data from the cache
*/
private void clearCache() {
data.clear();
}
/**
* Adds a new command to the NPC
*
@ -168,11 +166,6 @@ public class DataHandler {
dataConfigurator.set("npc-data.npc-" + npc + ".price", 0);
}
if (!data.containsKey("npc-data.npc-" + npc + ".sound")) {
data.put("npc-data.npc-" + npc + ".sound", new ArrayList<>());
dataConfigurator.set("npc-data.npc-" + npc + ".sound", new ArrayList<>());
}
player.sendMessage(color(HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.NPC_ADDED));
@ -184,6 +177,54 @@ public class DataHandler {
}).start();
}
/**
* Adds a new command to the NPC
*
* @param npc The NPC id
* @param permission The permission to access the command
* @param command The command
* @param left If the command should be added to the left or right click
*/
public void addCommand(int npc, String permission, String command, boolean left) {
new Thread(() -> {
try {
createBasics();
dataConfigurator.load(savesFile);
List<String> commandList = data.containsKey("npc-data.npc-" + npc + ".right-click-commands") ? (List<String>) data.get("npc-data.npc-" + npc + ".right-click-commands") : new ArrayList<>();
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(plugin));
dataConfigurator.set("npc-data.npc-" + npc + ".cooldown", getDefaultCooldown(plugin));
}
if (left) commandListLeft.add("[" + permission + "] " + command);
else commandList.add("[" + permission + "] " + command);
if (data.containsKey("npc-data.npc-" + npc + ".right-click-commands"))
data.replace("npc-data.npc-" + npc + ".right-click-commands", commandList);
else
data.put("npc-data.npc-" + npc + ".right-click-commands", commandList);
dataConfigurator.set("npc-data.npc-" + npc + ".right-click-commands", commandList);
if (data.containsKey("npc-data.npc-" + npc + ".left-click-commands"))
data.replace("npc-data.npc-" + npc + ".left-click-commands", commandListLeft);
else
data.put("npc-data.npc-" + npc + ".left-click-commands", commandListLeft);
dataConfigurator.set("npc-data.npc-" + npc + ".left-click-commands", commandListLeft);
if (!data.containsKey("npc-data.npc-" + npc + ".price")) {
data.put("npc-data.npc-" + npc + ".price", 0);
dataConfigurator.set("npc-data.npc-" + npc + ".price", 0);
}
dataConfigurator.save(savesFile);
} catch (IOException | InvalidConfigurationException ignored) {
}
}).start();
}
/**
* Sets the cooldown of the NPC command
*
@ -240,35 +281,24 @@ public class DataHandler {
}
/**
* Sets the sound of the NPC command
* Sets the permission of the NPC
*
* @param npc The NPC id
* @param sound The sound to play
* @param volume the volume
* @param pitch the pitch
* @param permission The permission to be added
* @param player The player who run the command
*/
public void setSound(int npc, Sound sound, float volume, float pitch, Player player) {
public void setCustomPermission(int npc, String permission, Player player) {
new Thread(() -> {
try {
createBasics();
dataConfigurator.load(savesFile);
List<String> soundProperties = new ArrayList<>();
dataConfigurator.set("npc-data.npc-" + npc + ".permission", permission);
soundProperties.add(sound.name());
soundProperties.add(String.valueOf(volume));
soundProperties.add(String.valueOf(pitch));
dataConfigurator.set("npc-data.npc-" + npc + ".sound", soundProperties);
if (data.containsKey("npc-data.npc-" + npc + ".sound"))
data.replace("npc-data.npc-" + npc + ".sound", soundProperties);
else
data.put("npc-data.npc-" + npc + ".sound", soundProperties);
data.replace("npc-data.npc-" + npc + ".permission", permission);
player.sendMessage(color(HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.SOUND_ADDED));
player.sendMessage(plugin.getLang().getMessage(Path.PERMISSION_SET));
dataConfigurator.save(savesFile);
} catch (IOException | InvalidConfigurationException e) {
@ -277,6 +307,41 @@ public class DataHandler {
}).start();
}
/**
* Remove the permission of the NPC
*
* @param npc The NPC id
* @param player The player who run the command
*/
public void removeCustomPermission(int npc, Player player) {
new Thread(() -> {
try {
createBasics();
dataConfigurator.load(savesFile);
if (dataConfigurator.contains("npc-data.npc-" + npc + ".permission"))
dataConfigurator.set("npc-data.npc-" + npc + ".permission", null);
data.remove("npc-data.npc-" + npc + ".permission");
player.sendMessage(color(HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.PERMISSION_REMOVED));
dataConfigurator.save(savesFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}).start();
}
public String getCustomPermission(int npc) {
return (String) data.get("npc-data.npc-" + npc + ".permission");
}
public boolean hasCustomPermission(int npc) {
return data.containsKey("npc-data.npc-" + npc + ".permission");
}
/**
* Gets the click commands from the saves.yml
*
@ -297,7 +362,7 @@ public class DataHandler {
*/
public String[] getCompleteCommandsNumbers(int npc, EnumTypes.ClickType click) {
List<String> commandList = (List<String>) data.get("npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands");
String commandSet[] = new String[commandList.size()];
String[] commandSet = new String[commandList.size()];
for (int i = 0; i < commandList.size(); i++)
commandSet[i] = "" + (i + 1);
return commandSet;
@ -311,14 +376,22 @@ public class DataHandler {
* @return Returns true if has and false if not
*/
public boolean hasNoCommands(int npc, EnumTypes.ClickType click) {
if (data.containsKey("npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands"))
return ((List<String>) data.get("npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands")).isEmpty();
String key = "npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands";
if (data.containsKey(key))
return ((List<String>) data.get(key)).isEmpty();
return true;
}
public boolean hasSound(int npc) {
if (data.containsKey("npc-data.npc-" + npc + ".sound"))
return !(((List<String>) data.get("npc-data.npc-" + npc + ".sound")).isEmpty());
/**
* Checks if there is NPC data for the ID.
*
* @param npc The NPC ID.
* @return True or false depending if it has or not.
*/
public boolean hasNPCData(int npc) {
for (String key : data.keySet()) {
if (key.contains("npc-" + npc)) return true;
}
return false;
}
@ -332,10 +405,6 @@ public class DataHandler {
return data.containsKey("npc-data.npc-" + npc + ".cooldown") ? (int) data.get("npc-data.npc-" + npc + ".cooldown") : 0;
}
public List<String> getNPCSound(int npc) {
return (List<String>) data.get("npc-data.npc-" + npc + ".sound");
}
/**
* Gets the price of the NPC
*
@ -364,8 +433,9 @@ public class DataHandler {
commands.remove(commandID - 1);
data.replace("npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands", commands);
dataConfigurator.set("npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands", commands);
String key = "npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands";
data.replace(key, commands);
dataConfigurator.set(key, commands);
player.sendMessage(color(HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.REMOVED_COMMAND));
@ -377,27 +447,6 @@ public class DataHandler {
}).start();
}
public void removeSound(int npc, Player player) {
new Thread(() -> {
try {
createBasics();
dataConfigurator.load(savesFile);
List<String> soundProperties = new ArrayList<>();
data.replace("npc-data.npc-" + npc + ".sound", soundProperties);
dataConfigurator.set("npc-data.npc-" + npc + ".sound", soundProperties);
player.sendMessage(color(HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.SOUND_REMOVED));
dataConfigurator.save(savesFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}).start();
}
/**
* Edits a command or permission from the NPC
*
@ -433,8 +482,9 @@ public class DataHandler {
break;
}
data.replace("npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands", commandsData);
dataConfigurator.set("npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands", commandsData);
String key = "npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands";
data.replace(key, commandsData);
dataConfigurator.set(key, commandsData);
player.sendMessage(color(HEADER));
player.sendMessage(plugin.getLang().getMessage(Path.EDITED_COMMAND).replace("{type}", typeText));
@ -460,8 +510,9 @@ public class DataHandler {
if (dataConfigurator.contains("npc-data.npc-" + npc))
dataConfigurator.set("npc-data.npc-" + npc, null);
/*clearCache();
cacheData();*/
for (String key : data.keySet()) {
if (key.contains("npc-data.npc-" + npc)) data.remove(key);
}
dataConfigurator.save(savesFile);
} catch (IOException | InvalidConfigurationException e) {
@ -479,7 +530,7 @@ public class DataHandler {
HashMap<String, Integer> cachedData = new HashMap<>();
for (String key : data.keySet()) {
String components[] = key.split("\\.");
String[] components = key.split("\\.");
if (components[2].equalsIgnoreCase("cooldown"))
cachedData.put(components[1], (Integer) data.get(key));
}
@ -487,7 +538,6 @@ public class DataHandler {
}
public void reload() {
cacheData();
initialize();
}
}

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.files;
@ -27,6 +27,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Objects;
import static me.mattmoreira.citizenscmd.utility.Util.*;
@ -93,90 +94,6 @@ public class LangHandler {
if (!langConf.contains(Path.MESSAGE_DISPLAY))
langConf.set(Path.MESSAGE_DISPLAY, "{name}:&r");
if (!langConf.contains(Path.INVALID_SOUND)) {
switch (lang) {
case "en":
langConf.set(Path.INVALID_SOUND, "&cPlease enter a valid sound!");
break;
case "pt":
langConf.set(Path.INVALID_SOUND, "&cSelecione um som válido!");
break;
case "ro":
langConf.set(Path.INVALID_SOUND, "&cIntroduceți un sunet valid!");
break;
case "bg":
langConf.set(Path.INVALID_SOUND, "&cМоля, въведете валиден звук!");
break;
case "no":
langConf.set(Path.INVALID_SOUND, "&cVennligst skriv inn en gyldig lyd!");
break;
case "ch":
langConf.set(Path.INVALID_SOUND, "&c请输入有效的声音!");
break;
}
}
if (!langConf.contains(Path.SOUND_ADDED)) {
switch (lang) {
case "en":
langConf.set(Path.SOUND_ADDED, "&aSound added successfully!");
break;
case "pt":
langConf.set(Path.SOUND_ADDED, "&aSom adicionado com sucesso!");
break;
case "ro":
langConf.set(Path.SOUND_ADDED, "&aSunetul a fost adăugat cu succes!");
break;
case "bg":
langConf.set(Path.SOUND_ADDED, "&aЗвукът е добавен успешно!");
break;
case "no":
langConf.set(Path.SOUND_ADDED, "&aLyd lagt til!");
break;
case "ch":
langConf.set(Path.SOUND_ADDED, "&a声音成功添加");
break;
}
}
if (!langConf.contains(Path.SOUND_REMOVED)) {
switch (lang) {
case "en":
langConf.set(Path.SOUND_REMOVED, "&aSound removed successfully!");
break;
case "pt":
langConf.set(Path.SOUND_REMOVED, "&aSom removido com sucesso!");
break;
case "ro":
langConf.set(Path.SOUND_REMOVED, "&aSunetul a fost eliminat cu succes!");
break;
case "bg":
langConf.set(Path.SOUND_REMOVED, "&aЗвукът е премахнат успешно!");
break;
case "no":
langConf.set(Path.SOUND_REMOVED, "&aLyden fjernet vellykket!");
break;
case "ch":
langConf.set(Path.SOUND_REMOVED, "&a声音已成功删除");
break;
}
}
if (!langConf.contains(Path.HELP_DESCRIPTION_SOUND)) {
switch (lang) {
case "en":
@ -205,8 +122,168 @@ public class LangHandler {
}
}
for (String parent : langConf.getConfigurationSection("messages").getKeys(false)) {
for (String child : langConf.getConfigurationSection("messages." + parent).getKeys(false))
if (!langConf.contains(Path.NPC_ADD_DELAY_FAIL)) {
switch (lang) {
case "en":
langConf.set(Path.NPC_ADD_DELAY_FAIL, "&cWhen adding &d-d &cthe delay must be a number!");
break;
case "pt":
langConf.set(Path.NPC_ADD_DELAY_FAIL, "&cAo adicionar &d-d &co atraso deve ser um número!");
break;
case "ro":
langConf.set(Path.NPC_ADD_DELAY_FAIL, "&cCând adăugați &d-d &cdelay-ul trebuie să fie un număr!");
break;
case "bg":
langConf.set(Path.NPC_ADD_DELAY_FAIL, "&cПри добавяне &d-d &cзакъснението трябва да бъде число!");
break;
case "no":
langConf.set(Path.NPC_ADD_DELAY_FAIL, "&cNår du legger til &d-d &cforsinkelsen må være et tall!");
break;
case "ch":
langConf.set(Path.NPC_ADD_DELAY_FAIL, "&c添加&d-d&c时延迟必须是数字!");
break;
case "fr":
langConf.set(Path.NPC_ADD_DELAY_FAIL, "&cLors de l'ajout de &d-d &cle délai doit être un nombre!");
break;
}
}
if (!langConf.contains(Path.LIST_COUNT_RIGHT)) {
switch (lang) {
case "en":
langConf.set(Path.LIST_COUNT_RIGHT, "&c&o{count} &7&o- Right click commands:");
break;
case "pt":
langConf.set(Path.LIST_COUNT_RIGHT, "&c&o{count} &7&o- Comandos de clique direito:");
break;
case "ro":
langConf.set(Path.LIST_COUNT_RIGHT, "&c&o{count} &7&o- Comenzile cu click dreapta:");
break;
case "bg":
langConf.set(Path.LIST_COUNT_RIGHT, "&c&o{count} &7&o- Команди с Десен Клик:");
break;
case "no":
langConf.set(Path.LIST_COUNT_RIGHT, "&c&o{count} &7&o- Høyre klikk:");
break;
case "ch":
langConf.set(Path.LIST_COUNT_RIGHT, "&c&o{count} &7&o- 右鍵指令:");
break;
case "fr":
langConf.set(Path.LIST_COUNT_RIGHT, "&c&o{count} &7&o- Commandes de clic droit:");
break;
}
}
if (!langConf.contains(Path.LIST_COUNT_LEFT)) {
switch (lang) {
case "en":
langConf.set(Path.LIST_COUNT_LEFT, "&c&o{count} &7&o- left click commands:");
break;
case "pt":
langConf.set(Path.LIST_COUNT_LEFT, "&c&o{count} &7&o- Comandos de clique esquerdo:");
break;
case "ro":
langConf.set(Path.LIST_COUNT_LEFT, "&c&o{count} &7&o- Comenzile cu click stanga:");
break;
case "bg":
langConf.set(Path.LIST_COUNT_LEFT, "&c&o{count} &7&o- Команди с Ляв Клик:");
break;
case "no":
langConf.set(Path.LIST_COUNT_LEFT, "&c&o{count} &7&o- Venstre klikk:");
break;
case "ch":
langConf.set(Path.LIST_COUNT_RIGHT, "&c&o{count} &7&o- 左鍵指令:");
break;
case "fr":
langConf.set(Path.LIST_COUNT_RIGHT, "&c&o{count} &7&o- Commandes de clic gauche:");
break;
}
}
if (!langConf.contains(Path.PERMISSION_SET)) {
switch (lang) {
case "en":
langConf.set(Path.PERMISSION_SET, "&aPermission set successfully!");
break;
case "pt":
langConf.set(Path.PERMISSION_SET, "&aPermissão definida com sucesso!");
break;
case "ro":
langConf.set(Path.PERMISSION_SET, "&aPermisiunea este setată cu succes!");
break;
case "bg":
langConf.set(Path.PERMISSION_SET, "&aРазрешението е успешно!");
break;
case "no":
langConf.set(Path.PERMISSION_SET, "&aTillatelse vellykket!");
break;
case "ch":
langConf.set(Path.PERMISSION_SET, "&a权限设置成功!");
break;
case "fr":
langConf.set(Path.PERMISSION_SET, "&aPermission définie avec succès!");
break;
}
}
if (!langConf.contains(Path.PERMISSION_REMOVED)) {
switch (lang) {
case "en":
langConf.set(Path.PERMISSION_REMOVED, "&aPermission removed successfully!");
break;
case "pt":
langConf.set(Path.PERMISSION_REMOVED, "&aPermissão removida com sucesso!");
break;
case "ro":
langConf.set(Path.PERMISSION_REMOVED, "&aPermisiunea a fost eliminată cu succes!");
break;
case "bg":
langConf.set(Path.PERMISSION_REMOVED, "&aРазрешението бе премахнато успешно!");
break;
case "no":
langConf.set(Path.PERMISSION_REMOVED, "&aTillatelse fjernet vellykket!");
break;
case "ch":
langConf.set(Path.PERMISSION_REMOVED, "&a权限已成功删除!");
break;
case "fr":
langConf.set(Path.PERMISSION_REMOVED, "&aPermission supprimée avec succès!");
break;
}
}
for (String parent : Objects.requireNonNull(langConf.getConfigurationSection("messages")).getKeys(false)) {
for (String child : Objects.requireNonNull(langConf.getConfigurationSection("messages." + parent)).getKeys(false))
messages.put("messages." + parent + "." + child, langConf.getString("messages." + parent + "." + child));
}

View File

@ -1,24 +1,23 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.listeners;
import me.clip.placeholderapi.PlaceholderAPI;
import me.mattmoreira.citizenscmd.CitizensCMD;
import me.mattmoreira.citizenscmd.schedulers.ConfirmScheduler;
import me.mattmoreira.citizenscmd.utility.EnumTypes;
@ -26,24 +25,15 @@ import me.mattmoreira.citizenscmd.utility.Path;
import net.citizensnpcs.api.event.NPCLeftClickEvent;
import net.citizensnpcs.api.event.NPCRemoveEvent;
import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static me.mattmoreira.citizenscmd.utility.TimeUtil.getFormattedTime;
import static me.mattmoreira.citizenscmd.utility.Util.color;
import static me.mattmoreira.citizenscmd.utility.Util.doCommands;
public class NPCListener implements Listener {
@ -54,264 +44,138 @@ public class NPCListener implements Listener {
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord");
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.HIGHEST)
public void onRightClick(NPCRightClickEvent event) {
int npc = event.getNPC().getId();
NPC npc = event.getNPC();
Player player = event.getClicker();
if (!player.hasPermission("citizenscmd.use")) return;
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc)) {
if (plugin.getDataHandler().hasCustomPermission(npc.getId())) {
if (!player.hasPermission(plugin.getDataHandler().getCustomPermission(npc.getId()))) return;
}
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc.getId())) {
if (!player.hasPermission("citizenscmd.bypass")) {
if (plugin.getCooldownHandler().onCooldown(npc, player.getUniqueId().toString())) {
if (plugin.getCooldownHandler().onCooldown(npc.getId(), player.getUniqueId().toString())) {
String cooldownMessage;
if (plugin.getDataHandler().getNPCCooldown(npc) == -1)
if (plugin.getDataHandler().getNPCCooldown(npc.getId()) == -1)
cooldownMessage = plugin.getLang().getMessage(Path.ONE_TIME_CLICK);
else
cooldownMessage = plugin.getLang().getMessage(Path.ON_COOLDOWN);
player.sendMessage(cooldownMessage.replace("{time}", getFormattedTime(plugin, plugin.getCooldownHandler().getTimeLeft(npc, player.getUniqueId().toString()), plugin.getDisplayFormat())));
player.sendMessage(cooldownMessage.replace("{time}", getFormattedTime(plugin, plugin.getCooldownHandler().getTimeLeft(npc.getId(), player.getUniqueId().toString()), plugin.getDisplayFormat())));
return;
}
}
if (plugin.getDataHandler().hasNoCommands(npc, EnumTypes.ClickType.RIGHT)) return;
if (plugin.getDataHandler().hasNoCommands(npc.getId(), EnumTypes.ClickType.RIGHT)) return;
}
double price = plugin.getDataHandler().getPrice(npc);
double price = plugin.getDataHandler().getPrice(npc.getId());
if (price > 0.0) {
if (CitizensCMD.getEconomy() != null) {
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc)) {
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc.getId())) {
String messageConfirm = plugin.getLang().getMessage(Path.PAY_CONFIRM);
if (!plugin.shouldShift())
if (!plugin.isShift())
messageConfirm = messageConfirm.replace("{shift}", "");
else
messageConfirm = messageConfirm.replace("{shift}", "Shift ");
messageConfirm = messageConfirm.replace("{price}", String.valueOf(price));
player.sendMessage(messageConfirm);
plugin.getWaitingList().put(player.getUniqueId().toString() + "." + npc, true);
new ConfirmScheduler(plugin, player, npc).runTaskLaterAsynchronously(plugin, 300L);
new ConfirmScheduler(plugin, player, npc.getId()).runTaskLaterAsynchronously(plugin, 300L);
return;
}
if (plugin.shouldShift() && !player.isSneaking()) return;
if (plugin.isShift() && !player.isSneaking()) return;
if (CitizensCMD.getEconomy().getBalance(player) < price) {
player.sendMessage(plugin.getLang().getMessage(Path.PAY_NO_MONEY));
return;
}
plugin.getWaitingList().remove(player.getUniqueId().toString() + "." + npc);
plugin.getWaitingList().remove(player.getUniqueId().toString() + "." + npc.getId());
CitizensCMD.getEconomy().withdrawPlayer(player, price);
player.sendMessage(plugin.getLang().getMessage(Path.PAY_COMPLETED).replace("{price}", String.valueOf(price)));
}
}
List<String> permissions = new ArrayList<>();
List<String> commands = new ArrayList<>();
doCommands(plugin, npc, player, 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 (plugin.papiEnabled())
commands.add(PlaceholderAPI.setPlaceholders((OfflinePlayer) player, command));
else commands.add(command);
}
}
if (permissions.size() != commands.size()) return;
for (int i = 0; i < permissions.size(); i++) {
switch (permissions.get(i).toLowerCase()) {
case "console":
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), commands.get(i));
break;
case "none":
player.chat("/" + commands.get(i));
break;
case "server":
changeServer(player, commands.get(i));
break;
case "message":
String finalMessage;
if (commands.get(i).contains("{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);
player.sendMessage(color(finalMessage));
break;
case "sound":
Pattern pattern = Pattern.compile("(\\w+)\\s([\\d\\.]+)\\s([\\d\\.]+)");
Matcher matcher = pattern.matcher(commands.get(i));
if (matcher.find()) {
player.playSound(player.getLocation(), Sound.valueOf(matcher.group(1)), Float.parseFloat(matcher.group(2)), Float.parseFloat(matcher.group(3)));
}
break;
default:
plugin.getPermissionsManager().setPermission(player, permissions.get(i));
player.chat("/" + commands.get(i));
plugin.getPermissionsManager().unsetPermission(player, permissions.get(i));
}
}
if (!player.hasPermission("citizenscmd.bypass") || plugin.getDataHandler().getNPCCooldown(npc) != 0) {
plugin.getCooldownHandler().addInteraction(npc, player.getUniqueId().toString(), System.currentTimeMillis());
if (!player.hasPermission("citizenscmd.bypass") || plugin.getDataHandler().getNPCCooldown(npc.getId()) != 0) {
plugin.getCooldownHandler().addInteraction(npc.getId(), player.getUniqueId().toString(), System.currentTimeMillis());
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.HIGHEST)
public void onLeftClick(NPCLeftClickEvent event) {
int npc = event.getNPC().getId();
NPC npc = event.getNPC();
Player player = event.getClicker();
if (!player.hasPermission("citizenscmd.use")) return;
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc)) {
if (plugin.getDataHandler().hasCustomPermission(npc.getId())) {
if (!player.hasPermission(plugin.getDataHandler().getCustomPermission(npc.getId()))) return;
}
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc.getId())) {
if (!player.hasPermission("citizenscmd.bypass")) {
if (plugin.getCooldownHandler().onCooldown(npc, player.getUniqueId().toString())) {
if (plugin.getCooldownHandler().onCooldown(npc.getId(), player.getUniqueId().toString())) {
String cooldownMessage;
if (plugin.getDataHandler().getNPCCooldown(npc) == -1)
if (plugin.getDataHandler().getNPCCooldown(npc.getId()) == -1)
cooldownMessage = plugin.getLang().getMessage(Path.ONE_TIME_CLICK);
else
cooldownMessage = plugin.getLang().getMessage(Path.ON_COOLDOWN);
player.sendMessage(cooldownMessage.replace("{time}", getFormattedTime(plugin, plugin.getCooldownHandler().getTimeLeft(npc, player.getUniqueId().toString()), plugin.getDisplayFormat())));
player.sendMessage(cooldownMessage.replace("{time}", getFormattedTime(plugin, plugin.getCooldownHandler().getTimeLeft(npc.getId(), player.getUniqueId().toString()), plugin.getDisplayFormat())));
return;
}
}
if (plugin.getDataHandler().hasNoCommands(npc, EnumTypes.ClickType.LEFT)) return;
if (plugin.getDataHandler().hasNoCommands(npc.getId(), EnumTypes.ClickType.LEFT)) return;
}
double price = plugin.getDataHandler().getPrice(npc);
double price = plugin.getDataHandler().getPrice(npc.getId());
if (price > 0.0) {
if (CitizensCMD.getEconomy() != null) {
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc)) {
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc.getId())) {
String messageConfirm = plugin.getLang().getMessage(Path.PAY_CONFIRM);
if (!plugin.shouldShift())
if (!plugin.isShift())
messageConfirm = messageConfirm.replace("{shift}", "");
else
messageConfirm = messageConfirm.replace("{shift}", "Shift ");
messageConfirm = messageConfirm.replace("{price}", String.valueOf(price));
player.sendMessage(messageConfirm);
plugin.getWaitingList().put(player.getUniqueId().toString() + "." + npc, true);
new ConfirmScheduler(plugin, player, npc).runTaskLaterAsynchronously(plugin, 300L);
plugin.getWaitingList().put(player.getUniqueId().toString() + "." + npc.getId(), true);
new ConfirmScheduler(plugin, player, npc.getId()).runTaskLaterAsynchronously(plugin, 300L);
return;
}
if (plugin.shouldShift() && !player.isSneaking()) return;
if (plugin.isShift() && !player.isSneaking()) return;
plugin.getWaitingList().remove(player.getUniqueId().toString() + "." + npc);
plugin.getWaitingList().remove(player.getUniqueId().toString() + "." + npc.getId());
player.sendMessage(plugin.getLang().getMessage(Path.PAY_CANCELED));
}
}
List<String> permissions = new ArrayList<>();
List<String> commands = new ArrayList<>();
doCommands(plugin, npc, player, 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()) {
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 (plugin.papiEnabled())
commands.add(PlaceholderAPI.setPlaceholders((OfflinePlayer) player, command));
else
commands.add(command);
}
}
if (permissions.size() != commands.size()) return;
for (int i = 0; i < permissions.size(); i++) {
switch (permissions.get(i).toLowerCase()) {
case "console":
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), commands.get(i));
break;
case "none":
player.chat("/" + commands.get(i));
break;
case "server":
changeServer(player, commands.get(i));
break;
case "message":
String finalMessage;
if (commands.get(i).contains("{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);
player.sendMessage(color(finalMessage));
break;
case "sound":
Pattern pattern = Pattern.compile("(\\w+)\\s([\\d\\.]+)\\s([\\d\\.]+)");
Matcher matcher = pattern.matcher(commands.get(i));
if (matcher.find()) {
player.playSound(player.getLocation(), Sound.valueOf(matcher.group(1)), Float.parseFloat(matcher.group(2)), Float.parseFloat(matcher.group(3)));
}
break;
default:
plugin.getPermissionsManager().setPermission(player, permissions.get(i));
player.chat("/" + commands.get(i));
plugin.getPermissionsManager().unsetPermission(player, permissions.get(i));
}
}
if (!player.hasPermission("citizenscmd.bypass") || plugin.getDataHandler().getNPCCooldown(npc) != 0) {
plugin.getCooldownHandler().addInteraction(npc, player.getUniqueId().toString(), System.currentTimeMillis());
if (!player.hasPermission("citizenscmd.bypass") || plugin.getDataHandler().getNPCCooldown(npc.getId()) != 0) {
plugin.getCooldownHandler().addInteraction(npc.getId(), player.getUniqueId().toString(), System.currentTimeMillis());
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onRemoveNPC(NPCRemoveEvent event) {
if (!plugin.getDataHandler().hasNPCData(event.getNPC().getId())) return;
plugin.getDataHandler().removeNPCData(event.getNPC().getId());
}
/**
* Bungee cord connection method
*
* @param player The player to be sent to the server
* @param server the server name
*/
private void changeServer(Player player, String server) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
try {
dataOutputStream.writeUTF("Connect");
dataOutputStream.writeUTF(server);
} catch (IOException e) {
e.printStackTrace();
}
player.sendPluginMessage(plugin, "BungeeCord", byteArrayOutputStream.toByteArray());
}
}

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.listeners;
@ -39,7 +39,7 @@ public class UpdateEvent implements Listener {
@EventHandler (priority = EventPriority.NORMAL)
public void onPlayerJoin(PlayerJoinEvent event) {
if (plugin.getUpdateStatus() && event.getPlayer().hasPermission("citizenscmd.update")) {
if (plugin.isUpdateStatus() && event.getPlayer().hasPermission("citizenscmd.update")) {
JSONMessage.create(color(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

@ -27,6 +27,7 @@ import java.util.zip.GZIPOutputStream;
*
* Check out https://bStats.org/ to learn more about bStats!
*/
@SuppressWarnings("all")
public class Metrics {
static {

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.permissions;

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.schedulers;

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.schedulers;

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.schedulers;

View File

@ -1,21 +1,3 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.updater;
import org.bukkit.plugin.java.JavaPlugin;

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.utility;

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.utility;

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.utility;

View File

@ -1,19 +1,19 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.utility;
@ -27,20 +27,20 @@ public class Path {
public static final String NPC_ADDED = MAIN_PATH_COMMANDS + "npc-add-command-added";
public static final String NPC_ADD_FAIL = MAIN_PATH_COMMANDS + "npc-add-command-failed";
public static final String NPC_ADD_DELAY_FAIL = MAIN_PATH_COMMANDS + "npc-add-command-delay-failed";
public static final String NPC_COOLDOWN_SET = MAIN_PATH_COMMANDS + "npc-cooldown-set";
public static final String NPC_COOLDOWN_SET_ERROR = MAIN_PATH_COMMANDS + "npc-cooldown-error";
public static final String NPC_PRICE_SET = MAIN_PATH_COMMANDS + "npc-price-set";
public static final String LIST_COUNT_RIGHT = MAIN_PATH_COMMANDS + "list-commnads-counter-right";
public static final String LIST_COUNT_LEFT = MAIN_PATH_COMMANDS + "list-commnads-counter-left";
public static final String LIST_COUNT_RIGHT = MAIN_PATH_COMMANDS + "list-commands-counter-right";
public static final String LIST_COUNT_LEFT = MAIN_PATH_COMMANDS + "list-commands-counter-left";
public static final String LIST_TOOLTIP = MAIN_PATH_COMMANDS + "list-tooltip";
public static final String LIST_COOLDOWN = MAIN_PATH_COMMANDS + "list-cooldown";
public static final String LIST_PRICE = MAIN_PATH_COMMANDS + "list-price";
public static final String RELOAD = MAIN_PATH_COMMANDS + "reload-command";
public static final String REMOVED_COMMAND = MAIN_PATH_COMMANDS + "removed-command";
public static final String EDITED_COMMAND = MAIN_PATH_COMMANDS + "edit-command";
public static final String INVALID_SOUND = MAIN_PATH_COMMANDS + "invalid-sound";
public static final String SOUND_ADDED = MAIN_PATH_COMMANDS + "sound-added";
public static final String SOUND_REMOVED = MAIN_PATH_COMMANDS + "sound-removed";
public static final String PERMISSION_SET = MAIN_PATH_COMMANDS + "set-permission";
public static final String PERMISSION_REMOVED = MAIN_PATH_COMMANDS + "remove-permission";
/**
* WARNINGS

View File

@ -1,25 +1,25 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* <p>
* A special thanks to @ExtendedClip for letting me use and modify this class from PlaceholderAPI
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
<p>
A special thanks to @ExtendedClip for letting me use and modify this class from PlaceholderAPI
*/
/**
* A special thanks to @ExtendedClip for letting me use and modify this class from PlaceholderAPI
/*
A special thanks to @ExtendedClip for letting me use and modify this class from PlaceholderAPI
*/
package me.mattmoreira.citizenscmd.utility;
@ -49,15 +49,15 @@ public class TimeUtil {
*/
public static String getFormattedTime(CitizensCMD plugin, long seconds, DisplayFormat format) {
String messagesString[] = new String[4];
String[] messagesString = new String[4];
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];
String fulls[] = new String[4];
String[] shorts = new String[4];
String[] mediums = new String[4];
String[] fulls = new String[4];
Pattern pattern = Pattern.compile("\\[([^]]*)], \\[([^]]*)], \\[([^]]*)]");
for (int i = 0; i < messagesString.length; i++) {
@ -77,8 +77,8 @@ public class TimeUtil {
secondFormat = shorts[0];
break;
case MEDIUM:
String mediumsAfter[] = new String[4];
String mediumsPlurals[] = new String[4];
String[] mediumsAfter = new String[4];
String[] mediumsPlurals = new String[4];
Pattern patternMediums = Pattern.compile("([^]]*)\\(([^]]*)\\)");
for (int i = 0; i < mediums.length; i++) {
if (mediums[i].contains("(") && mediums[i].contains(")")) {
@ -102,8 +102,8 @@ public class TimeUtil {
secondPlural = mediumsPlurals[0];
break;
case FULL:
String fullsAfter[] = new String[4];
String fullsPlurals[] = new String[4];
String[] fullsAfter = new String[4];
String[] fullsPlurals = new String[4];
Pattern patternFulls = Pattern.compile("([^]]*)\\(([^]]*)\\)");
for (int i = 0; i < fulls.length; i++) {
if (fulls[i].contains("(") && fulls[i].contains(")")) {
@ -140,18 +140,18 @@ public class TimeUtil {
if (minutes < 60) {
if (minutes == 1 && !format.equals(DisplayFormat.SHORT)) {
if (secondsLeft > 0) {
if (secondsLeft == 1 && !format.equals(DisplayFormat.SHORT))
return String.valueOf(minutes + minuteFormat + " " + secondsLeft + secondFormat);
return String.valueOf(minutes + minuteFormat + " " + secondsLeft + secondFormat + secondPlural);
if (secondsLeft == 1)
return minutes + minuteFormat + " " + secondsLeft + secondFormat;
return minutes + minuteFormat + " " + secondsLeft + secondFormat + secondPlural;
} else
return String.valueOf(minutes + minuteFormat);
return minutes + minuteFormat;
} else {
if (secondsLeft > 0) {
if (secondsLeft == 1 && !format.equals(DisplayFormat.SHORT))
return String.valueOf(minutes + minuteFormat + minutePlural + " " + secondsLeft + secondFormat);
return String.valueOf(minutes + minuteFormat + minutePlural + " " + secondsLeft + secondFormat + secondPlural);
return minutes + minuteFormat + minutePlural + " " + secondsLeft + secondFormat;
return minutes + minuteFormat + minutePlural + " " + secondsLeft + secondFormat + secondPlural;
} else
return String.valueOf(minutes + minuteFormat + minutePlural);
return minutes + minuteFormat + minutePlural;
}
}

View File

@ -1,36 +1,47 @@
/**
* CitizensCMD - Add-on for Citizens
* Copyright (C) 2018 Mateus Moreira
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
CitizensCMD - Add-on for Citizens
Copyright (C) 2018 Mateus Moreira
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<p>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me.mattmoreira.citizenscmd.utility;
import me.clip.placeholderapi.PlaceholderAPI;
import me.mattmoreira.citizenscmd.CitizensCMD;
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;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static org.bukkit.Bukkit.getScheduler;
public class Util {
@ -66,19 +77,6 @@ public class Util {
return false;
}
/**
* @param str String to check if it is a float 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 isFloat(String str) {
try {
Float.parseFloat(str);
} catch (NumberFormatException | NullPointerException e) {
return false;
}
return true;
}
/**
* Checks if player has or not selected an NPC
*
@ -123,7 +121,7 @@ public class Util {
}
/**
* Utility to use color codes easierly
* Utility to use color codes easily
*
* @param msg The message String
* @return returns the string with color
@ -162,14 +160,24 @@ public class Util {
case "add":
argComplete[0] = new String[]{"console", "none", "permission", "server", "message", "sound"};
argComplete[1] = getSoundsList();
argComplete[2] = new String[]{"1","0.5"};
argComplete[3] = new String[]{"1","0.5"};
argComplete[2] = new String[]{"1", "0.5"};
argComplete[3] = new String[]{"1", "0.5"};
break;
case "remove":
argComplete[0] = new String[]{"left", "right"};
argComplete[1] = plugin.getDataHandler().getCompleteCommandsNumbers(getSelectedNpcId(player), EnumTypes.ClickType.LEFT);
argComplete[2] = plugin.getDataHandler().getCompleteCommandsNumbers(getSelectedNpcId(player), EnumTypes.ClickType.RIGHT);
break;
case "cooldown":
argComplete[0] = new String[]{"1", "2", "5", "10"};
break;
case "permission":
argComplete[0] = new String[]{"set", "remove"};
break;
case "edit":
argComplete[0] = new String[]{"perm", "cmd"};
argComplete[1] = new String[]{"left", "right"};
@ -205,6 +213,7 @@ public class Util {
/**
* Checks for old config and renames it
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
public static void checkOldConfig(CitizensCMD plugin) {
File configFile;
File configFileNew;
@ -212,7 +221,7 @@ public class Util {
boolean isNew = true;
boolean contains[] = new boolean[5];
boolean[] contains = new boolean[5];
for (int i = 0; i < contains.length; i++) {
contains[i] = false;
}
@ -247,6 +256,11 @@ public class Util {
}
}
/**
* Disables the plugin if Citizens is not present.
*
* @param plugin The plugin to disable.
*/
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!"));
@ -254,7 +268,120 @@ public class Util {
Bukkit.getServer().getPluginManager().disablePlugin(plugin);
}
public static boolean doesCitizensExist() {
return Bukkit.getPluginManager().isPluginEnabled("Citizens");
/**
* Bungee cord connection method
*
* @param player The player to be sent to the server
* @param server the server name
*/
private static void changeServer(CitizensCMD plugin, Player player, String server) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
try {
dataOutputStream.writeUTF("Connect");
dataOutputStream.writeUTF(server);
} catch (IOException e) {
e.printStackTrace();
}
player.sendPluginMessage(plugin, "BungeeCord", byteArrayOutputStream.toByteArray());
}
/**
* Does the main commands for both left and right clicks.
*
* @param plugin The CitizensCMD plugin.
* @param npc The NPC to get ID.
* @param player The player using the NPC.
* @param clickType The type of click, either left or right.
*/
public static void doCommands(CitizensCMD plugin, NPC npc, Player player, EnumTypes.ClickType clickType) {
List<String> permissions = new ArrayList<>();
List<String> commands = new ArrayList<>();
for (String list : plugin.getDataHandler().getClickCommandsData(npc.getId(), clickType)) {
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 (plugin.papiEnabled())
commands.add(PlaceholderAPI.setPlaceholders((OfflinePlayer) player, command));
else commands.add(command);
}
}
if (permissions.size() != commands.size()) return;
for (int i = 0; i < permissions.size(); i++) {
double delay = 0;
if (permissions.get(i).contains("(")) {
Pattern pattern = Pattern.compile("(.*)\\(([^]]*)\\)");
Matcher matcher = pattern.matcher(permissions.get(i));
if (matcher.find()) {
delay = Double.parseDouble(matcher.group(2));
String permission = matcher.group(1);
permissions.set(i, permission);
}
}
int finalI = i;
switch (permissions.get(i).toLowerCase()) {
case "console":
getScheduler().runTaskLater(plugin, () -> plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), commands.get(finalI)), (int) delay * 20);
break;
case "none":
getScheduler().runTaskLater(plugin, () -> player.chat("/" + commands.get(finalI)), (int) delay * 20);
break;
case "server":
getScheduler().runTaskLater(plugin, () -> changeServer(plugin, player, commands.get(finalI)), (int) delay * 20);
break;
case "message":
getScheduler().runTaskLater(plugin, () -> {
String finalMessage;
if (commands.get(finalI).contains("{display}")) {
String tmpStr = commands.get(finalI).replace("{display}", plugin.getLang().getMessage(Path.MESSAGE_DISPLAY));
finalMessage = tmpStr.replace("{name}", npc.getFullName());
} else
finalMessage = commands.get(finalI);
player.sendMessage(color(finalMessage));
}, (int) delay * 20);
break;
case "sound":
getScheduler().runTaskLater(plugin, () -> {
Pattern pattern = Pattern.compile("(\\w+)\\s([\\d.]+)\\s([\\d.]+)");
Matcher matcher = pattern.matcher(commands.get(finalI));
if (matcher.find()) {
if (soundExists(matcher.group(1))) {
player.playSound(player.getLocation(), Sound.valueOf(matcher.group(1)), Float.parseFloat(matcher.group(2)), Float.parseFloat(matcher.group(3)));
}
}
}, (int) delay * 20);
break;
default:
getScheduler().runTaskLater(plugin, () -> {
plugin.getPermissionsManager().setPermission(player, permissions.get(finalI));
player.chat("/" + commands.get(finalI));
plugin.getPermissionsManager().unsetPermission(player, permissions.get(finalI));
}, (int) delay * 20);
}
}
}
private static boolean soundExists(String soundName) {
for (Sound sound : Sound.values()) {
if (sound.name().equalsIgnoreCase(soundName)) return true;
}
return false;
}
}

View File

@ -10,20 +10,20 @@ messages:
commands:
npc-add-command-added: "&aУспешно добавихте команда към NPC-то!"
npc-add-command-failed: "&cДобавянето на команда не бе успешно!"
npc-add-command-delay-failed: "&cПри добавяне &d-d &cзакъснението трябва да бъде число!"
npc-cooldown-set: "&aВремето за изчакване бе променено успешно!"
npc-cooldown-error: "&cПояви се грешка при променянето за времето за изчакване!"
npc-price-set: "&aЦената бе променена успешно!"
list-commnads-counter-right: "&c&o{count} &7&o- Команди с Десен Клик:"
list-commnads-counter-left: "&c&o{count} &7&o- Команди с Ляв Клик:"
list-commands-counter-right: "&c&o{count} &7&o- Команди с Десен Клик:"
list-commands-counter-left: "&c&o{count} &7&o- Команди с Ляв Клик:"
list-cooldown: "&7Време за изчакване: &c"
list-price: "&7Цена: &c"
list-tooltip: "&7Кликни за да промениш!"
reload-command: "&aВсичко файлове бяха презаредени успешно!"
removed-command: "&aКомандата бе премахната успешно!"
edit-command: "&a{type} бе променен/а успешно!"
invalid-sound: "&cМоля, въведете валиден звук!"
sound-added: "&aЗвукът е добавен успешно!"
sound-removed: "&aЗвукът е премахнат успешно!"
set-permission: "&aРазрешението е успешно!"
remove-permission: "&aРазрешението бе премахнато успешно!"
warnings:
no-npc-selected: "&cИзбери NPC първо!"
invalid-cooldown: "&cВремето за изчакване трябва да бъде число!"

View File

@ -10,20 +10,20 @@ messages:
commands:
npc-add-command-added: "&a你已經成功新增指令到這個npc!"
npc-add-command-failed: "&c新增指令到這個npc失敗!"
npc-add-command-delay-failed: "&c添加&d-d&c时延迟必须是数字!"
npc-cooldown-set: "&a你已經成功設定冷卻時間!"
npc-cooldown-error: "&c設定冷卻時間時有錯誤!"
npc-price-set: "&a你已經成功設定價格!"
list-commnads-counter-right: "&c&o{count} &7&o- 右鍵指令:"
list-commnads-counter-left: "&c&o{count} &7&o- 左鍵指令:"
list-commands-counter-right: "&c&o{count} &7&o- 右鍵指令:"
list-commands-counter-left: "&c&o{count} &7&o- 左鍵指令:"
list-cooldown: "&7冷卻時間: &c"
list-price: "&7價格: &c"
list-tooltip: "&7按下來編輯!"
reload-command: "&a所有檔案已經被重新載入!"
removed-command: "&a這個指令已經被成功移除!"
edit-command: "&a {type} 已經被編輯!"
invalid-sound: "&c请输入有效的声音!"
sound-added: "&a声音成功添加"
sound-removed: "&a声音已成功删除"
set-permission: "&a权限设置成功!"
remove-permission: "&a权限已成功删除!"
warnings:
no-npc-selected: "&c你一定要選擇NPC來執行那個指令!"
invalid-cooldown: "&c冷卻時間並不是數字!"

View File

@ -10,20 +10,20 @@ messages:
commands:
npc-add-command-added: "&aYou have successfully added a command to the NPC!"
npc-add-command-failed: "&cFailed to add command to the NPC!"
npc-add-command-delay-failed: "&cWhen adding &d-d &cthe delay must be a number!"
npc-cooldown-set: "&aYou have successfully set the cooldown!"
npc-cooldown-error: "&cAn error occurred while setting the cooldown!"
npc-price-set: "&aYou have successfully set the price!"
list-commnads-counter-right: "&c&o{count} &7&o- Right click commands:"
list-commnads-counter-left: "&c&o{count} &7&o- Left click commands:"
list-commands-counter-right: "&c&o{count} &7&o- Right click commands:"
list-commands-counter-left: "&c&o{count} &7&o- Left click commands:"
list-cooldown: "&7Cooldown: &c"
list-price: "&7Price: &c"
list-tooltip: "&7Click to edit!"
reload-command: "&aAll files have been reloaded successfully!"
removed-command: "&aThe command was removed successfully!"
edit-command: "&aThe {type} was edited successfully!"
invalid-sound: "&cPlease enter a valid sound!"
sound-added: "&aSound added successfully!"
sound-removed: "&aSound removed successfully!"
set-permission: "&aPermission set successfully!"
remove-permission: "&aPermission removed successfully!"
warnings:
no-npc-selected: "&cYou must have an NPC selected to execute that command!"
invalid-cooldown: "&cThe cooldown must be a number!"

View File

@ -10,20 +10,20 @@ messages:
commands:
npc-add-command-added: "&aVous avez ajouté une commande au PNJ avec succès!"
npc-add-command-failed: "&cImpossible d'ajouter une commande au PNJ!"
npc-add-command-delay-failed: "&cLors de l'ajout de &d-d &cle délai doit être un nombre!"
npc-cooldown-set: "&aVous avez défini le temps de recharge avec succès!"
npc-cooldown-error: "&cUne erreur s'est produite lors de la configuration du temps de recharge!"
npc-price-set: "&aVous avez réussi à fixer le prix!"
list-commnads-counter-right: "&c&o{count} &7&o- Commandes de clic droit:"
list-commnads-counter-left: "&c&o{count} &7&o- Commandes de clic gauche:"
list-commands-counter-right: "&c&o{count} &7&o- Commandes de clic droit:"
list-commands-counter-left: "&c&o{count} &7&o- Commandes de clic gauche:"
list-cooldown: "&7Cooldown: &c"
list-price: "&7Prix: &c"
list-tooltip: "&7Cliquez pour éditer!"
reload-command: "&aTous les fichiers ont été rechargés avec succès!"
removed-command: "&aLa commande a été supprimée avec succès!"
edit-command: "&aLe {type} a été édité avec succès!"
invalid-sound: "&cVeuillez entrer un son valide!"
sound-added: "&aSon ajouté avec succès!"
sound-removed: "&aSon enlevé avec succès!"
set-permission: "&aPermission définie avec succès!"
remove-permission: "&aPermission supprimée avec succès!"
warnings:
no-npc-selected: "&cVous devez avoir un PNJ sélectionné pour exécuter cette commande!"
invalid-cooldown: "&cLe temps de recharge doit être un nombre!"

View File

@ -10,20 +10,20 @@ messages:
commands:
npc-add-command-added: "&aDu har lagt til kommandoen til NPCen!"
npc-add-command-failed: "&cKunne ikke legge til kommandoen!"
npc-add-command-delay-failed: "&cNår du legger til &d-d &cforsinkelsen må være et tall!"
npc-cooldown-set: "&aEn nedtelling ble lagt til!"
npc-cooldown-error: "&cEn error ble oppdaget når du skulle legge til en nedtelling!"
npc-price-set: "&aDu har satt en pris!"
list-commnads-counter-right: "&c&o{count} &7&o- Høyre klikk:"
list-commnads-counter-left: "&c&o{count} &7&o- Venstre klikk"
list-commands-counter-right: "&c&o{count} &7&o- Høyre klikk:"
list-commands-counter-left: "&c&o{count} &7&o- Venstre klikk:"
list-cooldown: "&7Nedtelling: &c"
list-price: "&7Pris: &c"
list-tooltip: "&7Klikk for å endre!"
reload-command: "&aAlle fillene har blitt reloadet!"
removed-command: "&aKommandoen ble fjernet!"
edit-command: "&a{type} ble endret!"
invalid-sound: "&cVennligst skriv inn en gyldig lyd!"
sound-added: "&aLyd lagt til!"
sound-removed: "&aLyden fjernet vellykket!"
set-permission: "&aTillatelse vellykket!"
remove-permission: "&aTillatelse fjernet vellykket!"
warnings:
no-npc-selected: "&cDu må velge en NPC for å utføre denne kommandoen!"
invalid-cooldown: "&cNedtellingen må være et tall!"

View File

@ -10,19 +10,20 @@ messages:
commands:
npc-add-command-added: "&aVocê adicionou um comando ao NPC com sucesso!"
npc-add-command-failed: "&cFalha ao adicionar comando ao NPC!"
npc-add-command-delay-failed: "&cAo adicionar &d-d &co atraso deve ser um número!"
npc-cooldown-set: "&aVocê definiu com o cooldown sucesso!"
npc-cooldown-error: "&cOcorreu um erro ao definir o cooldown!"
npc-price-set: "&aVocê definiu o preço com sucesso!"
list-commnads-counter-right: "&c&o{count} &7&o- Comandos de clique direito:"
list-commnads-counter-left: "&c&o{count} &7&o- Comandos de clique esquerdo:"
list-commands-counter-right: "&c&o{count} &7&o- Comandos de clique direito:"
list-commands-counter-left: "&c&o{count} &7&o- Comandos de clique esquerdo:"
list-cooldown: "&7Cooldown: &c"
list-price: "&7Preço: &c"
list-tooltip: "&7Clique para editar!"
reload-command: "&aTodos os arquivos foram recarregados com sucesso!"
removed-command: "&aO comando foi removido com sucesso!"
edit-command: "&aO {type} foi editado com sucesso!"
invalid-sound: "&cSelecione um som válido!"
sound-added: "&aSom adicionado com sucesso!"
set-permission: "&aPermissão definida com sucesso!"
remove-permission: "&aPermissão removida com sucesso!"
warnings:
no-npc-selected: "&cVocê deve ter um NPC selecionado para executar esse comando!"
invalid-cooldown: "&cO cooldown deve ser um número!"

View File

@ -10,20 +10,20 @@ messages:
commands:
npc-add-command-added: "&aAti adaugat cu succes o comanda acestui NPC!"
npc-add-command-failed: "&cAdaugarea comenzi acestui NPC a esuat!"
npc-add-command-delay-failed: "&cCând adăugați &d-d &cdelay-ul trebuie să fie un număr!"
npc-cooldown-set: "&aAti setat cu succes cooldown-ul!"
npc-cooldown-error: "&cA aparut o eroare la setarea cooldown-ului!"
npc-price-set: "&aAti setat pretul cu succes!"
list-commnads-counter-right: "&c&o{count} &7&o- Comenzile cu click dreapta:"
list-commnads-counter-left: "&c&o{count} &7&o- Comenzile cu click stanga:"
list-commands-counter-right: "&c&o{count} &7&o- Comenzile cu click dreapta:"
list-commands-counter-left: "&c&o{count} &7&o- Comenzile cu click stanga:"
list-cooldown: "&7Cooldown: &c"
list-price: "&7Pret: &c"
list-tooltip: "&7Click pentru a edita!"
reload-command: "&aToate fisierele au fost reincarcate cu succes!"
removed-command: "&aComanda a fost eliminata cu succes!"
edit-command: "&a{type} a fost editat cu succes!"
invalid-sound: "&cIntroduceți un sunet valid!"
sound-added: "&aSunetul a fost adăugat cu succes!"
sound-removed: "&aSunetul a fost eliminat cu succes!"
set-permission: "&aPermisiunea este setată cu succes!"
remove-permission: "&aPermisiunea a fost eliminată cu succes!"
warnings:
no-npc-selected: "&cTrebuie sa ai un NPC selectat pentru a executa aceasta comanda!"
invalid-cooldown: "&cCooldown-ul trebuie sa fie un numar!"