forked from Upstream/CitizensCMD
Heavy update, fixed json issues, now using adventure, added minimessage
This commit is contained in:
parent
009b0c7667
commit
0316105d8a
35
pom.xml
35
pom.xml
@ -23,6 +23,10 @@
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repo</id>
|
||||
<url>https://repo.triumphteam.dev/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Citizens-Repo</id>
|
||||
<url>https://repo.citizensnpcs.co/</url>
|
||||
@ -85,32 +89,35 @@
|
||||
</dependency>
|
||||
|
||||
<!-- Compile -->
|
||||
<!-- JSON Message -->
|
||||
<!-- Adventure! -->
|
||||
<dependency>
|
||||
<groupId>me.rayzr522</groupId>
|
||||
<artifactId>jsonmessage</artifactId>
|
||||
<version>${jsonmsg.version}</version>
|
||||
<scope>compile</scope>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.1.0</version>
|
||||
</dependency>
|
||||
<!-- Matt's utils -->
|
||||
<dependency>
|
||||
<groupId>com.github.ipsk</groupId>
|
||||
<artifactId>MattUtils</artifactId>
|
||||
<version>${utils.version}</version>
|
||||
<scope>compile</scope>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.10.1</version>
|
||||
</dependency>
|
||||
<!-- Configuration -->
|
||||
<dependency>
|
||||
<groupId>ch.jalu</groupId>
|
||||
<artifactId>configme</artifactId>
|
||||
<version>1.3.0</version>
|
||||
</dependency>
|
||||
<!-- Matt's Framework -->
|
||||
<dependency>
|
||||
<groupId>me.mattstudios.utils</groupId>
|
||||
<artifactId>matt-framework</artifactId>
|
||||
<version>1.4.3</version>
|
||||
<groupId>dev.triumphteam</groupId>
|
||||
<artifactId>triumph-cmd-bukkit</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- bStats -->
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>1.5</version>
|
||||
<version>3.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -18,6 +18,12 @@
|
||||
|
||||
package me.mattstudios.citizenscmd;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import ch.jalu.configme.SettingsManagerBuilder;
|
||||
import dev.triumphteam.cmd.bukkit.BukkitCommandManager;
|
||||
import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey;
|
||||
import dev.triumphteam.cmd.core.message.MessageKey;
|
||||
import dev.triumphteam.cmd.core.suggestion.SuggestionKey;
|
||||
import me.mattstudios.citizenscmd.api.CitizensCMDAPI;
|
||||
import me.mattstudios.citizenscmd.commands.AddCommand;
|
||||
import me.mattstudios.citizenscmd.commands.CooldownCommand;
|
||||
@ -40,26 +46,33 @@ import me.mattstudios.citizenscmd.schedulers.UpdateScheduler;
|
||||
import me.mattstudios.citizenscmd.updater.SpigotUpdater;
|
||||
import me.mattstudios.citizenscmd.utility.DisplayFormat;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import me.mattstudios.citizenscmd.utility.Util;
|
||||
import me.mattstudios.mf.base.CommandManager;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.LEGACY;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.TAG;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.disablePlugin;
|
||||
import static me.mattstudios.utils.MessageUtils.color;
|
||||
import static me.mattstudios.utils.MessageUtils.info;
|
||||
import static me.mattstudios.utils.YamlUtils.copyDefaults;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.info;
|
||||
|
||||
public final class CitizensCMD extends JavaPlugin {
|
||||
|
||||
@ -68,11 +81,14 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
private CooldownHandler cooldownHandler;
|
||||
private PermissionsManager permissionsManager;
|
||||
|
||||
private BukkitAudiences audiences;
|
||||
|
||||
private static CitizensCMDAPI api;
|
||||
private static Economy economy;
|
||||
|
||||
private boolean papi = false;
|
||||
private CommandManager commandManager;
|
||||
private BukkitCommandManager<CommandSender> commandManager;
|
||||
private SettingsManager settings;
|
||||
|
||||
private boolean updateStatus = false;
|
||||
private boolean shift = false;
|
||||
@ -84,22 +100,28 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
copyDefaults(getClassLoader().getResourceAsStream("config.yml"), new File(getDataFolder().getPath(), "config.yml"));
|
||||
|
||||
setLang(Objects.requireNonNull(getConfig().getString("lang")));
|
||||
settings = SettingsManagerBuilder
|
||||
.withYamlFile(Paths.get(getDataFolder().getPath(), "config.yml"))
|
||||
.configurationData(Settings.class)
|
||||
.useDefaultMigrationService()
|
||||
.create();
|
||||
|
||||
if (!hasCitizens() && getConfig().getBoolean("citizens-check")) {
|
||||
audiences = BukkitAudiences.create(this);
|
||||
|
||||
setLang(settings.getProperty(Settings.LANG));
|
||||
|
||||
if (!hasCitizens() && settings.getProperty(Settings.CITIZENS_CHECK)) {
|
||||
disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
commandManager = new CommandManager(this, true);
|
||||
commandManager = BukkitCommandManager.create(this);
|
||||
|
||||
Metrics metrics = new Metrics(this);
|
||||
Util.setUpMetrics(metrics, getConfig());
|
||||
//Metrics metrics = new Metrics(this);
|
||||
//Util.setUpMetrics(metrics, settings);
|
||||
|
||||
info(color(Util.TAG + "&3Citizens&cCMD &8&o" + getDescription().getVersion() + " &8By &3Mateus Moreira &c@LichtHund"));
|
||||
final Audience console = audiences.console();
|
||||
console.sendMessage(TAG.append(LEGACY.deserialize("&3Citizens&cCMD &8&o" + getDescription().getVersion() + " &8By &3Mateus Moreira &c@LichtHund")));
|
||||
|
||||
permissionsManager = new PermissionsManager(this);
|
||||
|
||||
@ -112,48 +134,44 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
registerCommands();
|
||||
registerEvents();
|
||||
|
||||
info(color(Util.TAG + lang.getMessage(Messages.USING_LANGUAGE)));
|
||||
console.sendMessage(TAG.append(lang.getMessage(Messages.USING_LANGUAGE)));
|
||||
|
||||
if (hasPAPI()) {
|
||||
info(color(Util.TAG + lang.getMessage(Messages.PAPI_AVAILABLE)));
|
||||
console.sendMessage(TAG.append(lang.getMessage(Messages.PAPI_AVAILABLE)));
|
||||
papi = true;
|
||||
}
|
||||
|
||||
if (setupEconomy()) {
|
||||
info(color(Util.TAG + lang.getUncoloredMessage(Messages.VAULT_AVAILABLE)));
|
||||
console.sendMessage(TAG.append(lang.getMessage(Messages.VAULT_AVAILABLE)));
|
||||
}
|
||||
|
||||
waitingList = new HashMap<>();
|
||||
|
||||
setShift(getConfig().getBoolean("shift-confirm"));
|
||||
setShift(settings.getProperty(Settings.SHIT_CONFIRM));
|
||||
|
||||
if (getConfig().contains("cooldown-time-display")) {
|
||||
switch (Objects.requireNonNull(getConfig().getString("cooldown-time-display")).toLowerCase()) {
|
||||
case "short":
|
||||
displayFormat = DisplayFormat.SHORT;
|
||||
break;
|
||||
switch (settings.getProperty(Settings.TIME_DISPLAY).toLowerCase()) {
|
||||
case "short":
|
||||
displayFormat = DisplayFormat.SHORT;
|
||||
break;
|
||||
|
||||
case "full":
|
||||
displayFormat = DisplayFormat.FULL;
|
||||
break;
|
||||
case "full":
|
||||
displayFormat = DisplayFormat.FULL;
|
||||
break;
|
||||
|
||||
default:
|
||||
displayFormat = DisplayFormat.MEDIUM;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
displayFormat = DisplayFormat.MEDIUM;
|
||||
default:
|
||||
displayFormat = DisplayFormat.MEDIUM;
|
||||
break;
|
||||
}
|
||||
|
||||
if (getConfig().getBoolean("check-updates")) {
|
||||
if (settings.getProperty(Settings.CHECK_UPDATES)) {
|
||||
SpigotUpdater updater = new SpigotUpdater(this, 30224);
|
||||
try {
|
||||
// If there's an update, tell the user that they can update
|
||||
if (updater.checkForUpdates()) {
|
||||
updateStatus = true;
|
||||
newVersion = updater.getLatestVersion();
|
||||
info(color(Util.TAG + "&b&o" + lang.getUncoloredMessage(Messages.STARTUP_NEW_VERSION)));
|
||||
info(color(Util.TAG + "&b&o" + updater.getResourceURL()));
|
||||
console.sendMessage(TAG.append(lang.getMessage(Messages.STARTUP_NEW_VERSION).style(Style.style(NamedTextColor.AQUA, TextDecoration.ITALIC))));
|
||||
console.sendMessage(TAG.append(Component.text(updater.getResourceURL()).style(Style.style(NamedTextColor.AQUA, TextDecoration.ITALIC))));
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
@ -182,30 +200,41 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
* Registers all the commands to be used
|
||||
*/
|
||||
private void registerCommands() {
|
||||
commandManager.getCompletionHandler().register("#permissions", input -> Arrays.asList("console", "player", "permission", "server", "message", "sound"));
|
||||
commandManager.getCompletionHandler().register("#type", input -> Arrays.asList("cmd", "perm"));
|
||||
commandManager.getCompletionHandler().register("#click", input -> Arrays.asList("left", "right"));
|
||||
commandManager.getCompletionHandler().register("#set", input -> Arrays.asList("set", "remove"));
|
||||
commandManager.registerSuggestion(SuggestionKey.of("permissions"), (sender, context) -> Arrays.asList("console", "player", "permission", "server", "message", "sound"));
|
||||
commandManager.registerSuggestion(SuggestionKey.of("type"), (sender, context) -> Arrays.asList("cmd", "perm"));
|
||||
commandManager.registerSuggestion(SuggestionKey.of("click"), (sender, context) -> Arrays.asList("left", "right"));
|
||||
commandManager.registerSuggestion(SuggestionKey.of("set"), (sender, context) -> Arrays.asList("set", "remove"));
|
||||
commandManager.registerSuggestion(SuggestionKey.of("range"), (sender, context) -> IntStream.rangeClosed(1, 9).mapToObj(String::valueOf).collect(Collectors.toList()));
|
||||
|
||||
commandManager.getMessageHandler().register("cmd.no.permission", sender -> {
|
||||
sender.sendMessage(color(Util.HEADER));
|
||||
sender.sendMessage(lang.getMessage(Messages.NO_PERMISSION));
|
||||
commandManager.registerMessage(BukkitMessageKey.NO_PERMISSION, (sender, context) -> {
|
||||
final Audience audience = audiences.sender(sender);
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(lang.getMessage(Messages.NO_PERMISSION));
|
||||
});
|
||||
commandManager.getMessageHandler().register("cmd.no.console", sender -> {
|
||||
sender.sendMessage(color(Util.HEADER));
|
||||
sender.sendMessage(lang.getMessage(Messages.CONSOLE_NOT_ALLOWED));
|
||||
commandManager.registerMessage(BukkitMessageKey.PLAYER_ONLY, (sender, context) -> {
|
||||
final Audience audience = audiences.sender(sender);
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(lang.getMessage(Messages.CONSOLE_NOT_ALLOWED));
|
||||
});
|
||||
commandManager.getMessageHandler().register("cmd.no.exists", sender -> {
|
||||
sender.sendMessage(color(Util.HEADER));
|
||||
sender.sendMessage(lang.getMessage(Messages.WRONG_USAGE));
|
||||
commandManager.registerMessage(MessageKey.UNKNOWN_COMMAND, (sender, context) -> {
|
||||
final Audience audience = audiences.sender(sender);
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(lang.getMessage(Messages.WRONG_USAGE));
|
||||
});
|
||||
commandManager.getMessageHandler().register("cmd.wrong.usage", sender -> {
|
||||
sender.sendMessage(color(Util.HEADER));
|
||||
sender.sendMessage(lang.getMessage(Messages.WRONG_USAGE));
|
||||
commandManager.registerMessage(MessageKey.INVALID_ARGUMENT, (sender, context) -> {
|
||||
final Audience audience = audiences.sender(sender);
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(lang.getMessage(Messages.WRONG_USAGE));
|
||||
});
|
||||
commandManager.getMessageHandler().register("arg.must.be.number", sender -> {
|
||||
sender.sendMessage(color(Util.HEADER));
|
||||
sender.sendMessage(lang.getMessage(Messages.INVALID_NUMBER));
|
||||
commandManager.registerMessage(MessageKey.TOO_MANY_ARGUMENTS, (sender, context) -> {
|
||||
final Audience audience = audiences.sender(sender);
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(lang.getMessage(Messages.WRONG_USAGE));
|
||||
});
|
||||
commandManager.registerMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, (sender, context) -> {
|
||||
final Audience audience = audiences.sender(sender);
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(lang.getMessage(Messages.WRONG_USAGE));
|
||||
});
|
||||
|
||||
Stream.of(
|
||||
@ -218,7 +247,7 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
new PriceCommand(this),
|
||||
new ReloadCommand(this),
|
||||
new RemoveCommand(this)
|
||||
).forEach(commandManager::register);
|
||||
).forEach(commandManager::registerCommand);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -250,10 +279,28 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
return false;
|
||||
}
|
||||
economy = registeredServiceProvider.getProvider();
|
||||
shift = getConfig().getBoolean("shift-confirm");
|
||||
shift = settings.getProperty(Settings.SHIT_CONFIRM);
|
||||
return economy != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings manager, should use this instead of default config.
|
||||
*
|
||||
* @return The settings manager.
|
||||
*/
|
||||
public SettingsManager getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets adventure's audiences for JSON messages.
|
||||
*
|
||||
* @return The BukkitAudiences.
|
||||
*/
|
||||
public BukkitAudiences getAudiences() {
|
||||
return audiences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the language that is supposed to be used
|
||||
*/
|
||||
|
58
src/main/java/me/mattstudios/citizenscmd/Settings.java
Normal file
58
src/main/java/me/mattstudios/citizenscmd/Settings.java
Normal file
@ -0,0 +1,58 @@
|
||||
package me.mattstudios.citizenscmd;
|
||||
|
||||
import ch.jalu.configme.Comment;
|
||||
import ch.jalu.configme.SettingsHolder;
|
||||
import ch.jalu.configme.configurationdata.CommentsConfiguration;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
import ch.jalu.configme.properties.PropertyInitializer;
|
||||
|
||||
public final class Settings implements SettingsHolder {
|
||||
|
||||
private Settings() {}
|
||||
|
||||
@Comment({"", "Enables Checking for update."})
|
||||
public static final Property<Boolean> CHECK_UPDATES = PropertyInitializer
|
||||
.newProperty("check-updates", true);
|
||||
|
||||
@Comment({"", "Available languages EN, PT, BG, RO, NO, CH"})
|
||||
public static final Property<String> LANG = PropertyInitializer
|
||||
.newProperty("lang", "EN");
|
||||
|
||||
@Comment({"", "Toggle this on to enable using Minimessage style for message commands.", "https://docs.adventure.kyori.net/minimessage/format.html"})
|
||||
public static final Property<Boolean> MINI_MESSAGE = PropertyInitializer
|
||||
.newProperty("minimessage", false);
|
||||
|
||||
@Comment({"", "Toggle this on to enable using Minimessage style for your language files.", "https://docs.adventure.kyori.net/minimessage/format.html"})
|
||||
public static final Property<Boolean> MINI_MESSAGE_LANG = PropertyInitializer
|
||||
.newProperty("minimessage-lang", false);
|
||||
|
||||
@Comment({"", "The default npc cooldown in seconds"})
|
||||
public static final Property<Integer> DEFAULT_COOLDOWN = PropertyInitializer
|
||||
.newProperty("default-cooldown", 0);
|
||||
|
||||
@Comment({"", "When using a NPC with price, true means that to confirm the use the player needs to seek or press shift"})
|
||||
public static final Property<Boolean> SHIT_CONFIRM = PropertyInitializer
|
||||
.newProperty("shift-confirm", true);
|
||||
|
||||
@Comment({"", "Select cooldown display format, SHORT = 3m 3s | MEDIUM = 3 min 3 sec | FULL - 3 minutes 3 seconds"})
|
||||
public static final Property<String> TIME_DISPLAY = PropertyInitializer
|
||||
.newProperty("cooldown-time-display", "MEDIUM");
|
||||
|
||||
@Comment({"", "Disables citizens check on startup"})
|
||||
public static final Property<Boolean> CITIZENS_CHECK = PropertyInitializer
|
||||
.newProperty("citizens-check", true);
|
||||
|
||||
@Override
|
||||
public void registerComments(final CommentsConfiguration conf) {
|
||||
conf.setComment(
|
||||
"",
|
||||
"Citizens CMD Plugin by Mateus Moreira",
|
||||
"@LichtHund",
|
||||
"Version ${project.version}",
|
||||
"Wiki: https://github.com/ipsk/CitizensCMD/wiki",
|
||||
"GitHub: https://github.com/ipsk/CitizensCMD",
|
||||
"Spigot: https://www.spigotmc.org/resources/citizens-cmd.30224/",
|
||||
""
|
||||
);
|
||||
}
|
||||
}
|
@ -1,109 +1,76 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.CommandFlags;
|
||||
import dev.triumphteam.cmd.core.annotation.Flag;
|
||||
import dev.triumphteam.cmd.core.annotation.SubCommand;
|
||||
import dev.triumphteam.cmd.core.annotation.Suggestion;
|
||||
import dev.triumphteam.cmd.core.flag.Flags;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Completion;
|
||||
import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.annotations.SubCommand;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
||||
import static me.mattstudios.utils.MessageUtils.color;
|
||||
import static me.mattstudios.utils.NumbersUtils.isDouble;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
@Command("npcmd")
|
||||
public class AddCommand extends CommandBase {
|
||||
public class AddCommand extends Npcmd {
|
||||
|
||||
private final CitizensCMD plugin;
|
||||
|
||||
public AddCommand(CitizensCMD plugin) {
|
||||
public AddCommand(final CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a command to an NPC via ingame command
|
||||
*
|
||||
* @param sender Gets the sender to check for which NPC is selected and send messages.
|
||||
* @param permission The permission node or other to add.
|
||||
* @param arguments Gets the command to be added to the NPC.
|
||||
*/
|
||||
@SubCommand("add")
|
||||
@Permission("citizenscmd.add")
|
||||
public void addCommand(final CommandSender sender, @Completion("#permissions") String permission, String[] arguments) {
|
||||
@CommandFlags({
|
||||
@Flag(flag = "n"),
|
||||
@Flag(flag = "l"),
|
||||
@Flag(flag = "d", argument = double.class)
|
||||
})
|
||||
public void addCommand(
|
||||
final CommandSender sender,
|
||||
@Suggestion("permissions") final String permission,
|
||||
final Flags flags
|
||||
) {
|
||||
final OptionalInt selectedNpc = getSelectedNpcId(sender);
|
||||
|
||||
if (npcNotSelected(plugin, sender)) return;
|
||||
final Audience audience = plugin.getAudiences().sender(sender);
|
||||
|
||||
StringBuilder permissionBuilder = new StringBuilder(permission);
|
||||
boolean left = false;
|
||||
boolean displayName = false;
|
||||
boolean hasDelayError = false;
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (arguments[0].startsWith("/")) arguments[0] = arguments[0].substring(1);
|
||||
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
|
||||
if (arguments[i].equalsIgnoreCase("")) continue;
|
||||
|
||||
if (arguments[i].equalsIgnoreCase("-n")) {
|
||||
displayName = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arguments[i].equalsIgnoreCase("-l")) {
|
||||
left = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arguments[i].equalsIgnoreCase("-d")) {
|
||||
if (i + 1 >= arguments.length) {
|
||||
hasDelayError = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isDouble(arguments[i + 1])) {
|
||||
hasDelayError = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
permissionBuilder.append("(").append(arguments[i + 1]).append(")");
|
||||
arguments[i + 1] = "";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i == arguments.length - 1) stringBuilder.append(arguments[i]);
|
||||
else stringBuilder.append(arguments[i]).append(" ");
|
||||
}
|
||||
|
||||
if (hasDelayError) {
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NPC_ADD_DELAY_FAIL));
|
||||
if (!selectedNpc.isPresent()) {
|
||||
sendNotSelectedMessage(plugin, audience);
|
||||
return;
|
||||
}
|
||||
|
||||
String finalString;
|
||||
|
||||
if (displayName) {
|
||||
finalString = "{display} " + stringBuilder.toString().trim();
|
||||
} else {
|
||||
finalString = stringBuilder.toString().trim();
|
||||
}
|
||||
|
||||
if (permissionBuilder.toString().equalsIgnoreCase("sound")) {
|
||||
if (arguments.length < 2) {
|
||||
finalString += " 1 1";
|
||||
} else {
|
||||
if (arguments.length < 3) {
|
||||
finalString += " 1";
|
||||
}
|
||||
final StringBuilder permissionBuilder = new StringBuilder(permission);
|
||||
if (flags.hasFlag("d")) {
|
||||
final Optional<Double> delay = flags.getValue("d", Double.TYPE);
|
||||
if (!delay.isPresent()) {
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.NPC_ADD_DELAY_FAIL));
|
||||
return;
|
||||
}
|
||||
permissionBuilder.append("(").append(delay.get()).append(")");
|
||||
}
|
||||
|
||||
plugin.getDataHandler().addCommand(getSelectedNpcId(sender), permissionBuilder.toString(), finalString, sender, left);
|
||||
final String command = flags.getText();
|
||||
|
||||
if (command.isEmpty()) {
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.WRONG_USAGE));
|
||||
return;
|
||||
}
|
||||
|
||||
final String finalString = (flags.hasFlag("n") ? "{display} " + command : command).trim();
|
||||
|
||||
plugin
|
||||
.getDataHandler()
|
||||
.addCommand(selectedNpc.getAsInt(), permissionBuilder.toString(), finalString, audience, flags.hasFlag("l"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,31 +1,38 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.SubCommand;
|
||||
import dev.triumphteam.cmd.core.annotation.Suggestion;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Completion;
|
||||
import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.annotations.SubCommand;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
@Command("npcmd")
|
||||
public class CooldownCommand extends CommandBase {
|
||||
public class CooldownCommand extends Npcmd {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private final CitizensCMD plugin;
|
||||
|
||||
public CooldownCommand(CitizensCMD plugin) {
|
||||
public CooldownCommand(final CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@SubCommand("cooldown")
|
||||
@Permission("citizenscmd.cooldown")
|
||||
public void cooldown(CommandSender sender, @Completion("#range:9") Integer cooldown) {
|
||||
if (npcNotSelected(plugin, sender)) return;
|
||||
public void cooldown(final CommandSender sender, @Suggestion("range") final int cooldown) {
|
||||
final OptionalInt selectedNpc = getSelectedNpcId(sender);
|
||||
|
||||
plugin.getDataHandler().setCooldown(getSelectedNpcId(sender), cooldown, sender);
|
||||
final Audience audience = plugin.getAudiences().sender(sender);
|
||||
|
||||
if (!selectedNpc.isPresent()) {
|
||||
sendNotSelectedMessage(plugin, audience);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDataHandler().setCooldown(selectedNpc.getAsInt(), cooldown, audience);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,37 +1,47 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.SubCommand;
|
||||
import dev.triumphteam.cmd.core.annotation.Suggestion;
|
||||
import jdk.internal.joptsimple.internal.Strings;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Completion;
|
||||
import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.annotations.SubCommand;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
||||
import static me.mattstudios.utils.MessageUtils.color;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
@Command("npcmd")
|
||||
public class EditCommand extends CommandBase {
|
||||
public class EditCommand extends Npcmd {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private final CitizensCMD plugin;
|
||||
|
||||
public EditCommand(CitizensCMD plugin) {
|
||||
public EditCommand(final CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@SubCommand("edit")
|
||||
@Permission("citizenscmd.edit")
|
||||
@Completion({"#type", "#click"})
|
||||
public void edit(CommandSender sender, String typeString, String clickString, Integer id, String[] arguments) {
|
||||
public void edit(
|
||||
final CommandSender sender,
|
||||
@Suggestion("type") final String typeString,
|
||||
@Suggestion("click") final String clickString,
|
||||
final int id,
|
||||
final List<String> arguments
|
||||
) {
|
||||
final OptionalInt selectedNpc = getSelectedNpcId(sender);
|
||||
|
||||
if (npcNotSelected(plugin, sender)) return;
|
||||
final Audience audience = plugin.getAudiences().sender(sender);
|
||||
|
||||
int npc = getSelectedNpcId(sender);
|
||||
if (!selectedNpc.isPresent()) {
|
||||
sendNotSelectedMessage(plugin, audience);
|
||||
return;
|
||||
}
|
||||
|
||||
EnumTypes.ClickType click;
|
||||
EnumTypes.EditType type;
|
||||
@ -42,9 +52,9 @@ public class EditCommand extends CommandBase {
|
||||
break;
|
||||
|
||||
case "perm":
|
||||
if (arguments.length > 1) {
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.INVALID_PERMISSION));
|
||||
if (arguments.size() > 1) {
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.INVALID_PERMISSION));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -52,24 +62,27 @@ public class EditCommand extends CommandBase {
|
||||
break;
|
||||
|
||||
default:
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ARGUMENTS));
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ARGUMENTS));
|
||||
return;
|
||||
}
|
||||
|
||||
switch (clickString.toLowerCase()) {
|
||||
case "left":
|
||||
int leftCommandSize = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT).size();
|
||||
int leftCommandSize = plugin.getDataHandler().getClickCommandsData(
|
||||
selectedNpc.getAsInt(),
|
||||
EnumTypes.ClickType.LEFT
|
||||
).size();
|
||||
|
||||
if (leftCommandSize == 0) {
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NO_COMMANDS));
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.NO_COMMANDS));
|
||||
return;
|
||||
}
|
||||
|
||||
if (id < 1 || id > leftCommandSize) {
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ID_NUMBER));
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ID_NUMBER));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -77,37 +90,35 @@ public class EditCommand extends CommandBase {
|
||||
break;
|
||||
|
||||
case "right":
|
||||
int rightCommandSize = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT).size();
|
||||
int rightCommandSize = plugin.getDataHandler().getClickCommandsData(
|
||||
selectedNpc.getAsInt(),
|
||||
EnumTypes.ClickType.RIGHT
|
||||
).size();
|
||||
|
||||
if (rightCommandSize == 0) {
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NO_COMMANDS));
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.NO_COMMANDS));
|
||||
return;
|
||||
}
|
||||
|
||||
if (id < 1 || id > rightCommandSize) {
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ID_NUMBER));
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ID_NUMBER));
|
||||
return;
|
||||
}
|
||||
click = EnumTypes.ClickType.RIGHT;
|
||||
break;
|
||||
|
||||
default:
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.INVALID_CLICK_TYPE));
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.INVALID_CLICK_TYPE));
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
arguments[0] = arguments[0].replace("/", "");
|
||||
String finalString = Strings.join(arguments, " ").trim();
|
||||
if (finalString.startsWith("/")) finalString = finalString.substring(1);
|
||||
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
if (i == arguments.length - 1) stringBuilder.append(arguments[i]);
|
||||
else stringBuilder.append(arguments[i]).append(" ");
|
||||
}
|
||||
|
||||
plugin.getDataHandler().edit(npc, id, click, type, stringBuilder.toString().trim(), sender);
|
||||
plugin.getDataHandler().edit(selectedNpc.getAsInt(), id, click, type, finalString, audience);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,40 +1,180 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.Default;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Default;
|
||||
import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import me.rayzr522.jsonmessage.JSONMessage;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.utils.MessageUtils.color;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.LEGACY;
|
||||
import static net.kyori.adventure.text.Component.newline;
|
||||
import static net.kyori.adventure.text.Component.space;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
@Command("npcmd")
|
||||
public class HelpCommand extends CommandBase {
|
||||
public class HelpCommand extends Npcmd {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private final CitizensCMD plugin;
|
||||
private final BukkitAudiences audiences;
|
||||
|
||||
public HelpCommand(CitizensCMD plugin) {
|
||||
public HelpCommand(final CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
this.audiences = plugin.getAudiences();
|
||||
}
|
||||
|
||||
@Default
|
||||
@Permission("citizenscmd.npcmd")
|
||||
public void help(Player player) {
|
||||
JSONMessage.create(color(HEADER)).send(player);
|
||||
JSONMessage.create(color(plugin.getLang().getUncoloredMessage(Messages.HELP_VERSION) + " &c&o" + plugin.getDescription().getVersion())).send(player);
|
||||
JSONMessage.create(color(plugin.getLang().getUncoloredMessage(Messages.HELP_INFO))).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &cadd &b<console &b| &bmessage &b| &bplayer | &bpermission &b| &bserver &b| &bsound &b> &6<command> &d[-l]")).suggestCommand("/npcmd add ").tooltip(color(plugin.getLang().getUncoloredMessage(Messages.HELP_DESCRIPTION_ADD) + "\n" + plugin.getLang().getUncoloredMessage(Messages.HELP_EXAMPLE) + "\n&3&o/npcmd &c&oadd &b&ossentials.heal &6&oheal")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &ccooldown &6<time>")).suggestCommand("/npcmd cooldown ").tooltip(color(plugin.getLang().getUncoloredMessage(Messages.HELP_DESCRIPTION_COOLDOWN) + "\n" + plugin.getLang().getUncoloredMessage(Messages.HELP_EXAMPLE) + "\n&3&o/npcmd &c&ocooldown &6&o15")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &cprice &6<price>")).suggestCommand("/npcmd price ").tooltip(color(plugin.getLang().getUncoloredMessage(Messages.HELP_DESCRIPTION_PRICE) + "\n" + plugin.getLang().getUncoloredMessage(Messages.HELP_EXAMPLE) + "\n&3&o/npcmd &c&oprice &6&o250")).send(player);
|
||||
JSONMessage.create(color("&3/npcmd &clist")).suggestCommand("/npcmd list").tooltip(color(plugin.getLang().getUncoloredMessage(Messages.HELP_DESCRIPTION_LIST) + "\n&8" + plugin.getLang().getUncoloredMessage(Messages.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(Messages.HELP_DESCRIPTION_EDIT) + "\n" + plugin.getLang().getUncoloredMessage(Messages.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(Messages.HELP_DESCRIPTION_REMOVE) + "\n" + plugin.getLang().getUncoloredMessage(Messages.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(Messages.HELP_DESCRIPTION_RELOAD) + "\n" + plugin.getLang().getUncoloredMessage(Messages.HELP_EXAMPLE) + "\n&3&o/npcmd &c&oreload")).send(player);
|
||||
final Audience audience = audiences.player(player);
|
||||
|
||||
final TextComponent.Builder builder = Component.text();
|
||||
|
||||
builder
|
||||
.append(HEADER)
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_VERSION))
|
||||
.append(space())
|
||||
.append(text(plugin.getDescription().getVersion()).style(Style.style(NamedTextColor.RED, TextDecoration.ITALIC)))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_INFO))
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &cadd &b<console &b| &bmessage &b| &bplayer | &bpermission &b| &bserver &b| &bsound &b> &6<command> &d[-l]"))
|
||||
.clickEvent(ClickEvent.suggestCommand("/npcmd add "))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_DESCRIPTION_ADD))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_EXAMPLE))
|
||||
.append(newline())
|
||||
.append(LEGACY.deserialize("&3&o/npcmd &c&oadd &b&ossentials.heal &6&oheal"))
|
||||
.build()
|
||||
)
|
||||
)
|
||||
)
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &ccooldown &6<time>"))
|
||||
.clickEvent(ClickEvent.suggestCommand("/npcmd cooldown "))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_DESCRIPTION_COOLDOWN))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_EXAMPLE))
|
||||
.append(newline())
|
||||
.append(LEGACY.deserialize("&3&o/npcmd &c&ocooldown &6&o15"))
|
||||
.build()
|
||||
)
|
||||
).build()
|
||||
)
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &cprice &6<price>"))
|
||||
.clickEvent(ClickEvent.suggestCommand("/npcmd price "))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_DESCRIPTION_PRICE))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_EXAMPLE))
|
||||
.append(newline())
|
||||
.append(LEGACY.deserialize("&3&o/npcmd &c&oprice &6&o250"))
|
||||
.build()
|
||||
)
|
||||
).build()
|
||||
)
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &clist"))
|
||||
.clickEvent(ClickEvent.suggestCommand("/npcmd list"))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_DESCRIPTION_LIST))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_EXAMPLE))
|
||||
.append(newline())
|
||||
.append(LEGACY.deserialize("&3&o/npcmd &c&olist"))
|
||||
.build()
|
||||
)
|
||||
).build()
|
||||
)
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &cedit &b<cmd | perm> &b<left | right> &6<id> &6<new command | new permission>"))
|
||||
.clickEvent(ClickEvent.suggestCommand("/npcmd edit "))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_DESCRIPTION_EDIT))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_EXAMPLE))
|
||||
.append(newline())
|
||||
.append(LEGACY.deserialize("&3&o/npcmd &c&oedit &b&ocmd &b&oright &6&o1 fly"))
|
||||
.build()
|
||||
)
|
||||
).build()
|
||||
)
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &cremove &b<left | right> &6<id>"))
|
||||
.clickEvent(ClickEvent.suggestCommand("/npcmd remove "))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_DESCRIPTION_REMOVE))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_EXAMPLE))
|
||||
.append(newline())
|
||||
.append(LEGACY.deserialize("&3&o/npcmd &c&oremove &b&oright &6&o1"))
|
||||
.build()
|
||||
)
|
||||
).build()
|
||||
)
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &cpermission &b<set | remove> &6<custom.permission>"))
|
||||
.clickEvent(ClickEvent.suggestCommand("/npcmd permission "))
|
||||
.build()
|
||||
)
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &creload"))
|
||||
.clickEvent(ClickEvent.suggestCommand("/npcmd reload"))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_DESCRIPTION_RELOAD))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_EXAMPLE))
|
||||
.append(newline())
|
||||
.append(LEGACY.deserialize("&3&o/npcmd &c&oreload"))
|
||||
.build()
|
||||
)
|
||||
)
|
||||
.build()
|
||||
);
|
||||
|
||||
audience.sendMessage(builder.build());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,27 +1,31 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.SubCommand;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.annotations.SubCommand;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import me.rayzr522.jsonmessage.JSONMessage;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.LEGACY;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
||||
import static me.mattstudios.utils.MessageUtils.color;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
import static net.kyori.adventure.text.Component.newline;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.event.ClickEvent.suggestCommand;
|
||||
import static net.kyori.adventure.text.event.HoverEvent.showText;
|
||||
|
||||
@Command("npcmd")
|
||||
public class ListCommand extends CommandBase {
|
||||
public class ListCommand extends Npcmd {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private final CitizensCMD plugin;
|
||||
|
||||
public ListCommand(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -30,34 +34,72 @@ public class ListCommand extends CommandBase {
|
||||
@SubCommand("list")
|
||||
@Permission("citizenscmd.list")
|
||||
public void list(Player player) {
|
||||
final Audience audience = plugin.getAudiences().player(player);
|
||||
|
||||
if (npcNotSelected(plugin, player)) return;
|
||||
final OptionalInt selectedNpc = getSelectedNpcId(player);
|
||||
|
||||
int npc = getSelectedNpcId(player);
|
||||
if (!selectedNpc.isPresent()) {
|
||||
sendNotSelectedMessage(plugin, audience);
|
||||
return;
|
||||
}
|
||||
|
||||
final TextComponent.Builder builder = Component.text();
|
||||
|
||||
final int npc = selectedNpc.getAsInt();
|
||||
List<String> leftCommands = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT) != null ? plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT) : new ArrayList<>();
|
||||
List<String> rightCommands = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT) != null ? plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT) : new ArrayList<>();
|
||||
|
||||
player.sendMessage(color(HEADER));
|
||||
JSONMessage.create(color(plugin.getLang().getUncoloredMessage(Messages.LIST_COOLDOWN) + plugin.getDataHandler().getNPCCooldown(npc))).tooltip(plugin.getLang().getMessage(Messages.LIST_TOOLTIP)).suggestCommand("/npcmd cooldown ").send(player);
|
||||
JSONMessage.create(color(plugin.getLang().getUncoloredMessage(Messages.LIST_PRICE) + plugin.getDataHandler().getPrice(npc))).tooltip(plugin.getLang().getMessage(Messages.LIST_TOOLTIP)).suggestCommand("/npcmd price ").send(player);
|
||||
player.sendMessage("");
|
||||
player.sendMessage(plugin.getLang().getMessage(Messages.LIST_COUNT_RIGHT).replace("{count}", String.valueOf(rightCommands.size())));
|
||||
builder.append(HEADER).append(newline());
|
||||
builder.append(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.LIST_COOLDOWN))
|
||||
.append(text(plugin.getDataHandler().getNPCCooldown(npc)))
|
||||
.hoverEvent(showText(plugin.getLang().getMessage(Messages.LIST_TOOLTIP)))
|
||||
.clickEvent(suggestCommand("/npcmd cooldown "))
|
||||
.build()
|
||||
);
|
||||
builder.append(newline());
|
||||
builder.append(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.LIST_PRICE))
|
||||
.append(text(plugin.getDataHandler().getPrice(npc)))
|
||||
.hoverEvent(showText(plugin.getLang().getMessage(Messages.LIST_TOOLTIP)))
|
||||
.clickEvent(suggestCommand("/npcmd price "))
|
||||
.build()
|
||||
);
|
||||
builder.append(newline());
|
||||
builder.append(newline());
|
||||
builder.append(plugin.getLang().getMessage(Messages.LIST_COUNT_RIGHT, "{count}", String.valueOf(rightCommands.size())));
|
||||
builder.append(newline());
|
||||
|
||||
int rightCount = 1;
|
||||
for (String command : rightCommands) {
|
||||
JSONMessage.create(color("&c" + rightCount + " &7- &7" + command.replace("[", "&8[&c").replace("]", "&8]&b"))).suggestCommand("/npcmd edit cmd right " + rightCount + " ").tooltip(plugin.getLang().getMessage(Messages.LIST_TOOLTIP)).send(player);
|
||||
builder.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&c" + rightCount + " &7- &7" + command.replace("[", "&8[&c").replace("]", "&8]&b")))
|
||||
.clickEvent(suggestCommand("/npcmd edit cmd right " + rightCount + " "))
|
||||
.hoverEvent(showText(plugin.getLang().getMessage(Messages.LIST_TOOLTIP)))
|
||||
.build()
|
||||
);
|
||||
builder.append(newline());
|
||||
rightCount++;
|
||||
}
|
||||
|
||||
player.sendMessage("");
|
||||
player.sendMessage(plugin.getLang().getMessage(Messages.LIST_COUNT_LEFT).replace("{count}", String.valueOf(leftCommands.size())));
|
||||
builder.append(plugin.getLang().getMessage(Messages.LIST_COUNT_LEFT, "{count}", String.valueOf(leftCommands.size())));
|
||||
|
||||
int leftCount = 1;
|
||||
for (String command : leftCommands) {
|
||||
JSONMessage.create(color("&c" + leftCount + " &7- &7" + command.replace("[", "&8[&c").replace("]", "&8]&b"))).suggestCommand("/npcmd edit cmd left " + leftCount + " ").tooltip(plugin.getLang().getMessage(Messages.LIST_TOOLTIP)).send(player);
|
||||
builder.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&c" + leftCount + " &7- &7" + command.replace("[", "&8[&c").replace("]", "&8]&b")))
|
||||
.clickEvent(suggestCommand("/npcmd edit cmd left " + leftCount + " "))
|
||||
.hoverEvent(showText(plugin.getLang().getMessage(Messages.LIST_TOOLTIP)))
|
||||
.build()
|
||||
);
|
||||
builder.append(newline());
|
||||
leftCount++;
|
||||
}
|
||||
}
|
||||
|
||||
audience.sendMessage(builder.build());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import dev.triumphteam.cmd.core.BaseCommand;
|
||||
import dev.triumphteam.cmd.core.annotation.Command;
|
||||
|
||||
@Command("npcmd")
|
||||
public class Npcmd extends BaseCommand {}
|
@ -1,23 +1,22 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.SubCommand;
|
||||
import dev.triumphteam.cmd.core.annotation.Suggestion;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Completion;
|
||||
import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.annotations.SubCommand;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
||||
import static me.mattstudios.utils.MessageUtils.color;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
@Command("npcmd")
|
||||
public class PermissionCommand extends CommandBase {
|
||||
public class PermissionCommand extends Npcmd {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private final CitizensCMD plugin;
|
||||
|
||||
public PermissionCommand(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -25,22 +24,32 @@ public class PermissionCommand extends CommandBase {
|
||||
|
||||
@SubCommand("permission")
|
||||
@Permission("citizenscmd.permission")
|
||||
public void permission(CommandSender sender, @Completion("#set") String set, String permission) {
|
||||
public void permission(
|
||||
final CommandSender sender,
|
||||
@Suggestion("set") final String set,
|
||||
final String permission
|
||||
) {
|
||||
final OptionalInt selectedNpc = getSelectedNpcId(sender);
|
||||
|
||||
if (npcNotSelected(plugin, sender)) return;
|
||||
final Audience audience = plugin.getAudiences().sender(sender);
|
||||
|
||||
if (!selectedNpc.isPresent()) {
|
||||
sendNotSelectedMessage(plugin, audience);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (set.toLowerCase()) {
|
||||
case "set":
|
||||
plugin.getDataHandler().setCustomPermission(getSelectedNpcId(sender), permission, sender);
|
||||
plugin.getDataHandler().setCustomPermission(selectedNpc.getAsInt(), permission, audience);
|
||||
break;
|
||||
|
||||
case "remove":
|
||||
plugin.getDataHandler().removeCustomPermission(getSelectedNpcId(sender), sender);
|
||||
plugin.getDataHandler().removeCustomPermission(selectedNpc.getAsInt(), audience);
|
||||
break;
|
||||
|
||||
default:
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.WRONG_USAGE));
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.WRONG_USAGE));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,18 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.SubCommand;
|
||||
import dev.triumphteam.cmd.core.annotation.Suggestion;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Completion;
|
||||
import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.annotations.SubCommand;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
@Command("npcmd")
|
||||
public class PriceCommand extends CommandBase {
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
public class PriceCommand extends Npcmd {
|
||||
|
||||
private final CitizensCMD plugin;
|
||||
|
||||
@ -22,10 +22,16 @@ public class PriceCommand extends CommandBase {
|
||||
|
||||
@SubCommand("price")
|
||||
@Permission("citizenscmd.price")
|
||||
@Completion("#range:9")
|
||||
public void price(final CommandSender sender, final Double price) {
|
||||
if (npcNotSelected(plugin, sender)) return;
|
||||
plugin.getDataHandler().setPrice(getSelectedNpcId(sender), price, sender);
|
||||
}
|
||||
public void price(final CommandSender sender, @Suggestion("range") final double price) {
|
||||
final OptionalInt selectedNpc = getSelectedNpcId(sender);
|
||||
|
||||
final Audience audience = plugin.getAudiences().sender(sender);
|
||||
|
||||
if (!selectedNpc.isPresent()) {
|
||||
sendNotSelectedMessage(plugin, audience);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDataHandler().setPrice(selectedNpc.getAsInt(), price, audience);
|
||||
}
|
||||
}
|
||||
|
@ -1,59 +1,59 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.SubCommand;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.Settings;
|
||||
import me.mattstudios.citizenscmd.utility.DisplayFormat;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.annotations.SubCommand;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.utils.MessageUtils.color;
|
||||
|
||||
@Command("npcmd")
|
||||
public class ReloadCommand extends CommandBase {
|
||||
public class ReloadCommand extends Npcmd {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private final CitizensCMD plugin;
|
||||
private final SettingsManager settings;
|
||||
|
||||
public ReloadCommand(CitizensCMD plugin) {
|
||||
public ReloadCommand(final CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
this.settings = plugin.getSettings();
|
||||
}
|
||||
|
||||
@SubCommand("reload")
|
||||
@Permission("citizenscmd.reload")
|
||||
public void reload(CommandSender player) {
|
||||
public void reload(final CommandSender player) {
|
||||
|
||||
plugin.reloadConfig();
|
||||
plugin.saveDefaultConfig();
|
||||
plugin.setLang(Objects.requireNonNull(plugin.getConfig().getString("lang")));
|
||||
final Audience audience = plugin.getAudiences().sender(player);
|
||||
|
||||
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 "full":
|
||||
plugin.setDisplayFormat(DisplayFormat.FULL);
|
||||
break;
|
||||
default:
|
||||
plugin.setDisplayFormat(DisplayFormat.MEDIUM);
|
||||
break;
|
||||
}
|
||||
} else
|
||||
plugin.setDisplayFormat(DisplayFormat.MEDIUM);
|
||||
settings.reload();
|
||||
plugin.setLang(settings.getProperty(Settings.LANG));
|
||||
|
||||
if (CitizensCMD.getEconomy() != null)
|
||||
plugin.setShift(plugin.getConfig().getBoolean("shift-confirm"));
|
||||
final String timeFormat = settings.getProperty(Settings.TIME_DISPLAY);
|
||||
|
||||
switch (timeFormat.toLowerCase()) {
|
||||
case "short":
|
||||
plugin.setDisplayFormat(DisplayFormat.SHORT);
|
||||
break;
|
||||
case "full":
|
||||
plugin.setDisplayFormat(DisplayFormat.FULL);
|
||||
break;
|
||||
default:
|
||||
plugin.setDisplayFormat(DisplayFormat.MEDIUM);
|
||||
break;
|
||||
}
|
||||
|
||||
if (CitizensCMD.getEconomy() != null) {
|
||||
plugin.setShift(settings.getProperty(Settings.SHIT_CONFIRM));
|
||||
}
|
||||
|
||||
plugin.getDataHandler().reload();
|
||||
plugin.getCooldownHandler().reload();
|
||||
|
||||
player.sendMessage(color(HEADER));
|
||||
player.sendMessage(plugin.getLang().getMessage(Messages.RELOAD));
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.RELOAD));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,52 +1,55 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.SubCommand;
|
||||
import dev.triumphteam.cmd.core.annotation.Suggestion;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Completion;
|
||||
import me.mattstudios.mf.annotations.Permission;
|
||||
import me.mattstudios.mf.annotations.SubCommand;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
||||
import static me.mattstudios.utils.MessageUtils.color;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
@Command("npcmd")
|
||||
public class RemoveCommand extends CommandBase {
|
||||
public class RemoveCommand extends Npcmd {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private final CitizensCMD plugin;
|
||||
|
||||
public RemoveCommand(CitizensCMD plugin) {
|
||||
public RemoveCommand(final CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@SubCommand("remove")
|
||||
@Permission("citizenscmd.remove")
|
||||
@Completion("#click")
|
||||
public void remove(CommandSender sender, String clickString, Integer id) {
|
||||
public void remove(final CommandSender sender, @Suggestion("click") final String clickString, final int id) {
|
||||
final OptionalInt selectedNpc = getSelectedNpcId(sender);
|
||||
|
||||
if (npcNotSelected(plugin, sender)) return;
|
||||
final Audience audience = plugin.getAudiences().sender(sender);
|
||||
|
||||
if (!selectedNpc.isPresent()) {
|
||||
sendNotSelectedMessage(plugin, audience);
|
||||
return;
|
||||
}
|
||||
|
||||
int npc = getSelectedNpcId(sender);
|
||||
EnumTypes.ClickType click;
|
||||
|
||||
switch (clickString.toLowerCase()) {
|
||||
case "left":
|
||||
int leftCommandSize = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT).size();
|
||||
int leftCommandSize = plugin.getDataHandler().getClickCommandsData(selectedNpc.getAsInt(), EnumTypes.ClickType.LEFT).size();
|
||||
|
||||
if (leftCommandSize == 0) {
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NO_COMMANDS));
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.NO_COMMANDS));
|
||||
return;
|
||||
}
|
||||
|
||||
if (id < 1 || id > leftCommandSize) {
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ID_NUMBER));
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ID_NUMBER));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -54,17 +57,17 @@ public class RemoveCommand extends CommandBase {
|
||||
break;
|
||||
|
||||
case "right":
|
||||
int rightCommandSize = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT).size();
|
||||
int rightCommandSize = plugin.getDataHandler().getClickCommandsData(selectedNpc.getAsInt(), EnumTypes.ClickType.RIGHT).size();
|
||||
|
||||
if (rightCommandSize == 0) {
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NO_COMMANDS));
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.NO_COMMANDS));
|
||||
return;
|
||||
}
|
||||
|
||||
if (id < 0 || id > rightCommandSize) {
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ID_NUMBER));
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ID_NUMBER));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -72,13 +75,11 @@ public class RemoveCommand extends CommandBase {
|
||||
break;
|
||||
|
||||
default:
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.INVALID_CLICK_TYPE));
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.INVALID_CLICK_TYPE));
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDataHandler().removeCommand(npc, id, click, sender);
|
||||
|
||||
plugin.getDataHandler().removeCommand(selectedNpc.getAsInt(), id, click, audience);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,12 +26,12 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static me.mattstudios.utils.MessageUtils.color;
|
||||
import static me.mattstudios.utils.MessageUtils.info;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.info;
|
||||
|
||||
public class CooldownHandler {
|
||||
|
||||
@ -41,7 +41,7 @@ public class CooldownHandler {
|
||||
|
||||
private FileConfiguration cooldownsConfigurator;
|
||||
|
||||
private Map<String, Long> cooldownData;
|
||||
private final Map<String, Long> cooldownData = new ConcurrentHashMap<>();
|
||||
|
||||
public CooldownHandler(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -56,8 +56,6 @@ public class CooldownHandler {
|
||||
cooldownsFile = new File(dir.getPath(), "cooldowns.yml");
|
||||
cooldownsConfigurator = new YamlConfiguration();
|
||||
|
||||
cooldownData = new HashMap<>();
|
||||
|
||||
createBasics();
|
||||
cacheData();
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import me.mattstudios.citizenscmd.utility.Util;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@ -35,20 +35,22 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static me.mattstudios.utils.MessageUtils.color;
|
||||
import static me.mattstudios.utils.MessageUtils.info;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.info;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class DataHandler {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private final CitizensCMD plugin;
|
||||
private static File savesFile;
|
||||
private static File dir;
|
||||
|
||||
private static FileConfiguration dataConfigurator;
|
||||
|
||||
private Map<String, Object> data;
|
||||
private final Map<String, Object> data = new ConcurrentHashMap<>();
|
||||
|
||||
public DataHandler(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -63,8 +65,6 @@ public class DataHandler {
|
||||
savesFile = new File(dir.getPath(), "saves.yml");
|
||||
dataConfigurator = new YamlConfiguration();
|
||||
|
||||
data = new HashMap<>();
|
||||
|
||||
createBasics();
|
||||
cacheData();
|
||||
}
|
||||
@ -90,7 +90,6 @@ public class DataHandler {
|
||||
*/
|
||||
private void cacheData() {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
|
||||
try {
|
||||
dataConfigurator.load(savesFile);
|
||||
|
||||
@ -136,7 +135,7 @@ public class DataHandler {
|
||||
* @param sender The player who run 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, CommandSender sender, boolean left) {
|
||||
public void addCommand(int npc, String permission, String command, Audience sender, boolean left) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
createBasics();
|
||||
@ -170,12 +169,12 @@ public class DataHandler {
|
||||
dataConfigurator.set("npc-data.npc-" + npc + ".price", 0);
|
||||
}
|
||||
|
||||
sender.sendMessage(color(Util.HEADER));
|
||||
sender.sendMessage(HEADER);
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NPC_ADDED));
|
||||
|
||||
dataConfigurator.save(savesFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
sender.sendMessage(color(Util.HEADER));
|
||||
sender.sendMessage(HEADER);
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NPC_ADD_FAIL));
|
||||
}
|
||||
});
|
||||
@ -236,7 +235,7 @@ public class DataHandler {
|
||||
* @param cooldown The cooldown in seconds to be added
|
||||
* @param sender The player who run the command
|
||||
*/
|
||||
public void setCooldown(int npc, int cooldown, CommandSender sender) {
|
||||
public void setCooldown(int npc, int cooldown, Audience sender) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
createBasics();
|
||||
@ -246,12 +245,12 @@ public class DataHandler {
|
||||
|
||||
data.replace("npc-data.npc-" + npc + ".cooldown", cooldown);
|
||||
|
||||
sender.sendMessage(color(Util.HEADER));
|
||||
sender.sendMessage(HEADER);
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NPC_COOLDOWN_SET));
|
||||
|
||||
dataConfigurator.save(savesFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
sender.sendMessage(color(Util.HEADER));
|
||||
sender.sendMessage(HEADER);
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NPC_COOLDOWN_SET_ERROR));
|
||||
}
|
||||
});
|
||||
@ -264,7 +263,7 @@ public class DataHandler {
|
||||
* @param price The price in seconds to be added
|
||||
* @param sender The player who run the command
|
||||
*/
|
||||
public void setPrice(int npc, double price, CommandSender sender) {
|
||||
public void setPrice(int npc, double price, Audience sender) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
createBasics();
|
||||
@ -274,7 +273,7 @@ public class DataHandler {
|
||||
|
||||
data.replace("npc-data.npc-" + npc + ".price", price);
|
||||
|
||||
sender.sendMessage(color(Util.HEADER));
|
||||
sender.sendMessage(HEADER);
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NPC_PRICE_SET));
|
||||
|
||||
dataConfigurator.save(savesFile);
|
||||
@ -291,7 +290,7 @@ public class DataHandler {
|
||||
* @param permission The permission to be added
|
||||
* @param sender The player who run the command
|
||||
*/
|
||||
public void setCustomPermission(int npc, String permission, CommandSender sender) {
|
||||
public void setCustomPermission(int npc, String permission, Audience sender) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
createBasics();
|
||||
@ -301,7 +300,7 @@ public class DataHandler {
|
||||
|
||||
data.replace("npc-data.npc-" + npc + ".permission", permission);
|
||||
|
||||
sender.sendMessage(color(Util.HEADER));
|
||||
sender.sendMessage(HEADER);
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.PERMISSION_SET));
|
||||
|
||||
dataConfigurator.save(savesFile);
|
||||
@ -317,7 +316,7 @@ public class DataHandler {
|
||||
* @param npc The NPC id
|
||||
* @param sender The player who run the command
|
||||
*/
|
||||
public void removeCustomPermission(int npc, CommandSender sender) {
|
||||
public void removeCustomPermission(int npc, Audience sender) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
createBasics();
|
||||
@ -328,7 +327,7 @@ public class DataHandler {
|
||||
|
||||
data.remove("npc-data.npc-" + npc + ".permission");
|
||||
|
||||
sender.sendMessage(color(Util.HEADER));
|
||||
sender.sendMessage(HEADER);
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.PERMISSION_REMOVED));
|
||||
|
||||
dataConfigurator.save(savesFile);
|
||||
@ -428,7 +427,7 @@ public class DataHandler {
|
||||
* @param click The click type, either left or right
|
||||
* @param sender The player to send the message to
|
||||
*/
|
||||
public void removeCommand(int npc, int commandID, EnumTypes.ClickType click, CommandSender sender) {
|
||||
public void removeCommand(int npc, int commandID, EnumTypes.ClickType click, Audience sender) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
createBasics();
|
||||
@ -442,7 +441,7 @@ public class DataHandler {
|
||||
data.replace(key, commands);
|
||||
dataConfigurator.set(key, commands);
|
||||
|
||||
sender.sendMessage(color(Util.HEADER));
|
||||
sender.sendMessage(HEADER);
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.REMOVED_COMMAND));
|
||||
|
||||
dataConfigurator.save(savesFile);
|
||||
@ -462,7 +461,7 @@ public class DataHandler {
|
||||
* @param newValue the new value for either the command or the permission
|
||||
* @param sender The player to send messages
|
||||
*/
|
||||
public void edit(int npc, int commandID, EnumTypes.ClickType click, EnumTypes.EditType type, String newValue, CommandSender sender) {
|
||||
public void edit(int npc, int commandID, EnumTypes.ClickType click, EnumTypes.EditType type, String newValue, Audience sender) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
createBasics();
|
||||
@ -470,8 +469,7 @@ public class DataHandler {
|
||||
|
||||
List<String> commandsData = getClickCommandsData(npc, click);
|
||||
|
||||
String typeText = "";
|
||||
|
||||
final String typeText;
|
||||
switch (type) {
|
||||
case CMD:
|
||||
String tempCommand = commandsData.get(commandID - 1);
|
||||
@ -485,14 +483,16 @@ public class DataHandler {
|
||||
commandsData.set(commandID - 1, tempPerm);
|
||||
typeText = "PERM";
|
||||
break;
|
||||
default:
|
||||
typeText = "";
|
||||
}
|
||||
|
||||
String key = "npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands";
|
||||
data.replace(key, commandsData);
|
||||
dataConfigurator.set(key, commandsData);
|
||||
|
||||
sender.sendMessage(color(Util.HEADER));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.EDITED_COMMAND).replace("{type}", typeText));
|
||||
sender.sendMessage(HEADER);
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.EDITED_COMMAND, "{type}", typeText));
|
||||
|
||||
dataConfigurator.save(savesFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
|
@ -18,36 +18,39 @@
|
||||
|
||||
package me.mattstudios.citizenscmd.files;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.Settings;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.simpleyaml.configuration.file.YamlFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
import static me.mattstudios.utils.MessageUtils.color;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.LEGACY;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.MINI;
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public class LangHandler {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private String lang;
|
||||
private final CitizensCMD plugin;
|
||||
private final SettingsManager settings;
|
||||
private final String lang;
|
||||
|
||||
private HashMap<String, String> messages;
|
||||
private final Map<String, String> messages = new HashMap<>();
|
||||
|
||||
public LangHandler(CitizensCMD plugin, String lang) {
|
||||
public LangHandler(final CitizensCMD plugin, final String lang) {
|
||||
this.plugin = plugin;
|
||||
this.lang = lang;
|
||||
|
||||
messages = new HashMap<>();
|
||||
this.settings = plugin.getSettings();
|
||||
this.lang = lang.toLowerCase(Locale.ROOT);
|
||||
cacheMessage();
|
||||
}
|
||||
|
||||
@ -58,21 +61,10 @@ public class LangHandler {
|
||||
try {
|
||||
File langFile = new File(plugin.getDataFolder(), "lang/" + lang + ".yml");
|
||||
FileConfiguration langConf = new YamlConfiguration();
|
||||
InputStream langStream = CitizensCMD.class.getClassLoader().getResourceAsStream("lang/" + lang + ".yml");
|
||||
// InputStream langStream = CitizensCMD.class.getClassLoader().getResourceAsStream("lang/" + lang + ".yml");
|
||||
|
||||
if (!langFile.exists()) {
|
||||
if (langStream == null) {
|
||||
langFile.createNewFile();
|
||||
saveDefaults(CitizensCMD.class.getClassLoader().getResourceAsStream("lang/en.yml"), langFile);
|
||||
} else {
|
||||
plugin.saveResource("lang/" + lang + ".yml", false);
|
||||
}
|
||||
} else {
|
||||
if (langStream == null) {
|
||||
//saveDefaults(CitizensCMD.class.getClassLoader().getResourceAsStream("lang/en.yml"), langFile);
|
||||
} else {
|
||||
//saveDefaults(langStream, langFile);
|
||||
}
|
||||
plugin.saveResource("lang/" + lang + ".yml", false);
|
||||
}
|
||||
|
||||
langConf.load(langFile);
|
||||
@ -82,7 +74,6 @@ public class LangHandler {
|
||||
messages.put("messages." + parent + "." + child, langConf.getString("messages." + parent + "." + child));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -94,8 +85,22 @@ public class LangHandler {
|
||||
* @param path String with the path to the message
|
||||
* @return Returns String with colored message from file
|
||||
*/
|
||||
public String getMessage(Messages path) {
|
||||
return color(messages.get(path.getPath()));
|
||||
public Component getMessage(Messages path) {
|
||||
return getMessage(path, "", "");
|
||||
}
|
||||
|
||||
public Component getMessage(Messages path, String match, String replace) {
|
||||
return getMessage(path, Collections.singletonMap(match, replace));
|
||||
}
|
||||
|
||||
public Component getMessage(Messages path, Map<String, String> replacements) {
|
||||
String value = messages.get(path.getPath());
|
||||
for (final Map.Entry<String, String> entry : replacements.entrySet()) {
|
||||
value = value.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
if (settings.getProperty(Settings.MINI_MESSAGE_LANG)) return MINI.deserialize(value);
|
||||
return LEGACY.deserialize(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,56 +121,4 @@ public class LangHandler {
|
||||
public String getLanguage() {
|
||||
return lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets file from resources and copies the changes to the main one, preserving comments.
|
||||
* Used for my messages.
|
||||
*
|
||||
* @param inputFile The file from resources.
|
||||
* @param outputFile The output file.
|
||||
*/
|
||||
private static void saveDefaults(InputStream inputFile, File outputFile) {
|
||||
try {
|
||||
if (inputFile == null) return;
|
||||
|
||||
File tempFile = File.createTempFile("npcmdCfg" + gen(), "yml");
|
||||
FileUtils.copyInputStreamToFile(inputFile, tempFile);
|
||||
|
||||
inputFile.close();
|
||||
|
||||
YamlFile resourceYaml = new YamlFile(tempFile);
|
||||
YamlFile savedYaml = new YamlFile(outputFile);
|
||||
|
||||
resourceYaml.load();
|
||||
savedYaml.load();
|
||||
|
||||
boolean edited = false;
|
||||
|
||||
for (String parent : resourceYaml.getConfigurationSection("messages").getKeys(false)) {
|
||||
for (String child : resourceYaml.getConfigurationSection("messages." + parent).getKeys(false)) {
|
||||
String key = "messages." + parent + "." + child;
|
||||
|
||||
if (!savedYaml.contains(key)) continue;
|
||||
|
||||
edited = true;
|
||||
resourceYaml.set(key, savedYaml.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
if (edited) resourceYaml.saveWithComments();
|
||||
|
||||
|
||||
FileUtils.copyFile(tempFile, outputFile);
|
||||
tempFile.delete();
|
||||
|
||||
} catch (IOException | org.simpleyaml.exceptions.InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static int gen() {
|
||||
Random r = new Random(System.currentTimeMillis());
|
||||
return 10000 + r.nextInt(20000);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,8 +18,10 @@
|
||||
|
||||
package me.mattstudios.citizenscmd.listeners;
|
||||
|
||||
import com.google.common.primitives.Floats;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.Settings;
|
||||
import me.mattstudios.citizenscmd.schedulers.ConfirmScheduler;
|
||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
@ -28,6 +30,8 @@ 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 net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Sound;
|
||||
@ -37,16 +41,23 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.LEGACY;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.MINI;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getFormattedTime;
|
||||
import static me.mattstudios.utils.MessageUtils.color;
|
||||
import static org.bukkit.Bukkit.getScheduler;
|
||||
|
||||
public class NPCClickListener implements Listener {
|
||||
|
||||
private static final Pattern MAIN_PATTERN = Pattern.compile("\\[([^]]*)] (.*)");
|
||||
private static final Pattern PERMISSION_PATTERN = Pattern.compile("(.*)\\(([^]]*)\\)");
|
||||
private static final Pattern SOUND_PATTERN = Pattern.compile("(?<sound>\\w+)\\s?(?<volume>[\\d.]+) ?(?<pitch>[\\d.]+)?");
|
||||
|
||||
private final CitizensCMD plugin;
|
||||
|
||||
public NPCClickListener(CitizensCMD plugin) {
|
||||
@ -58,6 +69,7 @@ public class NPCClickListener implements Listener {
|
||||
public void onRightClick(NPCRightClickEvent event) {
|
||||
NPC npc = event.getNPC();
|
||||
Player player = event.getClicker();
|
||||
final Audience audience = plugin.getAudiences().player(player);
|
||||
|
||||
if (!player.hasPermission("citizenscmd.use")) return;
|
||||
|
||||
@ -65,18 +77,18 @@ public class NPCClickListener implements Listener {
|
||||
if (!player.hasPermission(plugin.getDataHandler().getCustomPermission(npc.getId()))) return;
|
||||
}
|
||||
|
||||
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc.getId())) {
|
||||
if (!plugin.getWaitingList().containsKey(player.getUniqueId() + "." + npc.getId())) {
|
||||
if (!player.hasPermission("citizenscmd.bypass")) {
|
||||
if (plugin.getCooldownHandler().onCooldown(npc.getId(), player.getUniqueId().toString())) {
|
||||
String cooldownMessage;
|
||||
final Component cooldownMessage;
|
||||
final String time = getFormattedTime(plugin, plugin.getCooldownHandler().getTimeLeft(npc.getId(), player.getUniqueId().toString()), plugin.getDisplayFormat());
|
||||
if (plugin.getDataHandler().getNPCCooldown(npc.getId()) == -1) {
|
||||
cooldownMessage = plugin.getLang().getMessage(Messages.ONE_TIME_CLICK);
|
||||
cooldownMessage = plugin.getLang().getMessage(Messages.ONE_TIME_CLICK, "{time}", time);
|
||||
} else {
|
||||
cooldownMessage = plugin.getLang().getMessage(Messages.ON_COOLDOWN);
|
||||
}
|
||||
if (!"".equals(cooldownMessage)) {
|
||||
player.sendMessage(cooldownMessage.replace("{time}", getFormattedTime(plugin, plugin.getCooldownHandler().getTimeLeft(npc.getId(), player.getUniqueId().toString()), plugin.getDisplayFormat())));
|
||||
cooldownMessage = plugin.getLang().getMessage(Messages.ON_COOLDOWN, "{time}", time);
|
||||
}
|
||||
|
||||
audience.sendMessage(cooldownMessage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -89,15 +101,17 @@ public class NPCClickListener implements Listener {
|
||||
if (price > 0.0) {
|
||||
if (CitizensCMD.getEconomy() != null) {
|
||||
|
||||
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc.getId())) {
|
||||
String messageConfirm = plugin.getLang().getMessage(Messages.PAY_CONFIRM);
|
||||
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.getId(), true);
|
||||
if (!plugin.getWaitingList().containsKey(player.getUniqueId() + "." + npc.getId())) {
|
||||
final Map<String, String> replacements = new HashMap<>();
|
||||
replacements.put("{price}", String.valueOf(price));
|
||||
|
||||
if (!plugin.isShift()) replacements.put("{shift}", "");
|
||||
else replacements.put("{shift}", "Shift ");
|
||||
|
||||
final Component messageConfirm = plugin.getLang().getMessage(Messages.PAY_CONFIRM, replacements);
|
||||
|
||||
audience.sendMessage(messageConfirm);
|
||||
plugin.getWaitingList().put(player.getUniqueId() + "." + npc.getId(), true);
|
||||
new ConfirmScheduler(plugin, player, npc.getId()).runTaskLaterAsynchronously(plugin, 300L);
|
||||
return;
|
||||
}
|
||||
@ -107,14 +121,13 @@ public class NPCClickListener implements Listener {
|
||||
}
|
||||
|
||||
if (CitizensCMD.getEconomy().getBalance(player) < price) {
|
||||
player.sendMessage(plugin.getLang().getMessage(Messages.PAY_NO_MONEY));
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.PAY_NO_MONEY));
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getWaitingList().remove(player.getUniqueId().toString() + "." + npc.getId());
|
||||
plugin.getWaitingList().remove(player.getUniqueId() + "." + npc.getId());
|
||||
CitizensCMD.getEconomy().withdrawPlayer(player, price);
|
||||
player.sendMessage(plugin.getLang().getMessage(Messages.PAY_COMPLETED).replace("{price}", String.valueOf(price)));
|
||||
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.PAY_COMPLETED, "price", String.valueOf(price)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,6 +143,7 @@ public class NPCClickListener implements Listener {
|
||||
public void onLeftClick(NPCLeftClickEvent event) {
|
||||
NPC npc = event.getNPC();
|
||||
Player player = event.getClicker();
|
||||
final Audience audience = plugin.getAudiences().player(player);
|
||||
|
||||
if (!player.hasPermission("citizenscmd.use")) return;
|
||||
|
||||
@ -137,18 +151,19 @@ public class NPCClickListener implements Listener {
|
||||
if (!player.hasPermission(plugin.getDataHandler().getCustomPermission(npc.getId()))) return;
|
||||
}
|
||||
|
||||
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc.getId())) {
|
||||
if (!plugin.getWaitingList().containsKey(player.getUniqueId() + "." + npc.getId())) {
|
||||
if (!player.hasPermission("citizenscmd.bypass")) {
|
||||
if (plugin.getCooldownHandler().onCooldown(npc.getId(), player.getUniqueId().toString())) {
|
||||
String cooldownMessage;
|
||||
final Component cooldownMessage;
|
||||
final String time = getFormattedTime(plugin, plugin.getCooldownHandler().getTimeLeft(npc.getId(), player.getUniqueId().toString()), plugin.getDisplayFormat());
|
||||
|
||||
if (plugin.getDataHandler().getNPCCooldown(npc.getId()) == -1) {
|
||||
cooldownMessage = plugin.getLang().getMessage(Messages.ONE_TIME_CLICK);
|
||||
cooldownMessage = plugin.getLang().getMessage(Messages.ONE_TIME_CLICK, "{time}", time);
|
||||
} else {
|
||||
cooldownMessage = plugin.getLang().getMessage(Messages.ON_COOLDOWN);
|
||||
}
|
||||
if (!"".equals(cooldownMessage)) {
|
||||
player.sendMessage(cooldownMessage.replace("{time}", getFormattedTime(plugin, plugin.getCooldownHandler().getTimeLeft(npc.getId(), player.getUniqueId().toString()), plugin.getDisplayFormat())));
|
||||
cooldownMessage = plugin.getLang().getMessage(Messages.ON_COOLDOWN, "{time}", time);
|
||||
}
|
||||
|
||||
audience.sendMessage(cooldownMessage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -161,24 +176,25 @@ public class NPCClickListener implements Listener {
|
||||
if (price > 0.0) {
|
||||
if (CitizensCMD.getEconomy() != null) {
|
||||
|
||||
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc.getId())) {
|
||||
String messageConfirm = plugin.getLang().getMessage(Messages.PAY_CONFIRM);
|
||||
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.getId(), true);
|
||||
if (!plugin.getWaitingList().containsKey(player.getUniqueId() + "." + npc.getId())) {
|
||||
final Map<String, String> replacements = new HashMap<>();
|
||||
replacements.put("{price}", String.valueOf(price));
|
||||
|
||||
if (!plugin.isShift()) replacements.put("{shift}", "");
|
||||
else replacements.put("{shift}", "Shift ");
|
||||
|
||||
final Component messageConfirm = plugin.getLang().getMessage(Messages.PAY_CONFIRM, replacements);
|
||||
|
||||
audience.sendMessage(messageConfirm);
|
||||
plugin.getWaitingList().put(player.getUniqueId() + "." + npc.getId(), true);
|
||||
new ConfirmScheduler(plugin, player, npc.getId()).runTaskLaterAsynchronously(plugin, 300L);
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.isShift() && !player.isSneaking()) return;
|
||||
|
||||
plugin.getWaitingList().remove(player.getUniqueId().toString() + "." + npc.getId());
|
||||
player.sendMessage(plugin.getLang().getMessage(Messages.PAY_CANCELED));
|
||||
plugin.getWaitingList().remove(player.getUniqueId() + "." + npc.getId());
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.PAY_CANCELED));
|
||||
|
||||
}
|
||||
}
|
||||
@ -209,8 +225,7 @@ public class NPCClickListener implements Listener {
|
||||
List<String> commands = new ArrayList<>();
|
||||
|
||||
for (String list : plugin.getDataHandler().getClickCommandsData(npc.getId(), clickType)) {
|
||||
Pattern pattern = Pattern.compile("\\[([^]]*)] (.*)");
|
||||
Matcher matcher = pattern.matcher(list);
|
||||
Matcher matcher = MAIN_PATTERN.matcher(list);
|
||||
if (matcher.find()) {
|
||||
|
||||
permissions.add(matcher.group(1));
|
||||
@ -234,8 +249,7 @@ public class NPCClickListener implements Listener {
|
||||
double delay = 0;
|
||||
|
||||
if (permissions.get(i).contains("(")) {
|
||||
Pattern pattern = Pattern.compile("(.*)\\(([^]]*)\\)");
|
||||
Matcher matcher = pattern.matcher(permissions.get(i));
|
||||
Matcher matcher = PERMISSION_PATTERN.matcher(permissions.get(i));
|
||||
if (matcher.find()) {
|
||||
delay = Double.parseDouble(matcher.group(2));
|
||||
String permission = matcher.group(1);
|
||||
@ -250,33 +264,64 @@ public class NPCClickListener implements Listener {
|
||||
break;
|
||||
|
||||
case "none":
|
||||
getScheduler().runTaskLater(plugin, () -> player.chat("/" + commands.get(finalI)), (int) delay * 20);
|
||||
getScheduler().runTaskLater(plugin, () -> player.chat("/" + commands.get(finalI)), (int) delay * 20L);
|
||||
break;
|
||||
|
||||
case "server":
|
||||
getScheduler().runTaskLater(plugin, () -> Util.changeServer(plugin, player, commands.get(finalI)), (int) delay * 20);
|
||||
getScheduler().runTaskLater(plugin, () -> Util.changeServer(plugin, player, commands.get(finalI)), (int) delay * 20L);
|
||||
break;
|
||||
|
||||
case "message":
|
||||
getScheduler().runTaskLater(plugin, () -> {
|
||||
String finalMessage;
|
||||
if (commands.get(finalI).contains("{display}")) {
|
||||
String tmpStr = commands.get(finalI).replace("{display}", plugin.getLang().getMessage(Messages.MESSAGE_DISPLAY));
|
||||
finalMessage = tmpStr.replace("{name}", npc.getFullName());
|
||||
} else
|
||||
finalMessage = commands.get(finalI);
|
||||
player.sendMessage(color(finalMessage));
|
||||
}, (int) delay * 20);
|
||||
final String finalMessage = commands.get(finalI)
|
||||
.replace("{display}", plugin.getLang().getUncoloredMessage(Messages.MESSAGE_DISPLAY))
|
||||
.replace("{name}", npc.getFullName());
|
||||
|
||||
final Audience audience = plugin.getAudiences().player(player);
|
||||
|
||||
if (plugin.getSettings().getProperty(Settings.MINI_MESSAGE)) {
|
||||
audience.sendMessage(MINI.deserialize(finalMessage));
|
||||
return;
|
||||
}
|
||||
|
||||
audience.sendMessage(LEGACY.deserialize(finalMessage));
|
||||
}, (int) delay * 20L);
|
||||
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() && Util.soundExists(matcher.group(1))) {
|
||||
player.playSound(player.getLocation(), Sound.valueOf(matcher.group(1)), Float.parseFloat(matcher.group(2)), Float.parseFloat(matcher.group(3)));
|
||||
String sound = commands.get(finalI);
|
||||
final Matcher matcher = SOUND_PATTERN.matcher(sound);
|
||||
|
||||
float volume = 1f;
|
||||
final float pitch = 1f;
|
||||
|
||||
if (matcher.find()) {
|
||||
sound = matcher.group("sound");
|
||||
|
||||
String volumeString = matcher.group("volume");
|
||||
String pitchString = matcher.group("pitch");
|
||||
|
||||
if (volumeString != null) {
|
||||
final Float nullableVolume = Floats.tryParse(volumeString);
|
||||
if (nullableVolume != null) volume = nullableVolume;
|
||||
}
|
||||
|
||||
if (pitchString != null) {
|
||||
final Float nullablePitch = Floats.tryParse(pitchString);
|
||||
if (nullablePitch != null) volume = nullablePitch;
|
||||
}
|
||||
}
|
||||
}, (int) delay * 20);
|
||||
|
||||
if (!Util.soundExists(sound)) {
|
||||
player.playSound(player.getLocation(), sound, volume, pitch);
|
||||
return;
|
||||
}
|
||||
|
||||
final Sound bukkitSound = Sound.valueOf(sound);
|
||||
|
||||
player.playSound(player.getLocation(), bukkitSound, volume, pitch);
|
||||
}, (int) delay * 20L);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -284,7 +329,7 @@ public class NPCClickListener implements Listener {
|
||||
plugin.getPermissionsManager().setPermission(player, permissions.get(finalI));
|
||||
player.chat("/" + commands.get(finalI));
|
||||
plugin.getPermissionsManager().unsetPermission(player, permissions.get(finalI));
|
||||
}, (int) delay * 20);
|
||||
}, (int) delay * 20L);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -20,30 +20,47 @@ package me.mattstudios.citizenscmd.listeners;
|
||||
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import me.mattstudios.citizenscmd.utility.Util;
|
||||
import me.rayzr522.jsonmessage.JSONMessage;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import static me.mattstudios.utils.MessageUtils.color;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static net.kyori.adventure.text.Component.newline;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class UpdateEvent implements Listener {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private final CitizensCMD plugin;
|
||||
|
||||
public UpdateEvent(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler (priority = EventPriority.NORMAL)
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (plugin.isUpdateStatus() && event.getPlayer().hasPermission("citizenscmd.update")) {
|
||||
JSONMessage.create(color(Util.HEADER)).send(event.getPlayer());
|
||||
JSONMessage.create(color(plugin.getLang().getUncoloredMessage(Messages.NEW_VERSION) + plugin.getNewVersion())).send(event.getPlayer());
|
||||
JSONMessage.create(color(plugin.getLang().getUncoloredMessage(Messages.DOWNLOAD_AT) + " spigotmc.org/resources/citizens-CMD.30224/")).openURL("https://spigotmc.org/resources/citizens-CMD.30224/").send(event.getPlayer());
|
||||
}
|
||||
if (!plugin.isUpdateStatus() || !event.getPlayer().hasPermission("citizenscmd.update")) return;
|
||||
|
||||
final Audience audience = plugin.getAudiences().player(event.getPlayer());
|
||||
|
||||
final TextComponent.Builder builder = Component.text();
|
||||
builder.append(HEADER).append(newline());
|
||||
builder.append(plugin.getLang().getMessage(Messages.NEW_VERSION));
|
||||
builder.append(text(plugin.getNewVersion()));
|
||||
builder.append(newline());
|
||||
builder.append(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.DOWNLOAD_AT))
|
||||
.append(text(" spigotmc.org/resources/citizens-CMD.30224/"))
|
||||
.clickEvent(ClickEvent.openUrl("https://spigotmc.org/resources/citizens-CMD.30224/"))
|
||||
.build()
|
||||
);
|
||||
|
||||
audience.sendMessage(builder.build());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,17 +20,20 @@ package me.mattstudios.citizenscmd.schedulers;
|
||||
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class ConfirmScheduler extends BukkitRunnable {
|
||||
|
||||
private Player player;
|
||||
private int npc;
|
||||
private CitizensCMD plugin;
|
||||
private final Player player;
|
||||
private final Audience audience;
|
||||
private final int npc;
|
||||
private final CitizensCMD plugin;
|
||||
|
||||
public ConfirmScheduler(CitizensCMD plugin, Player player, int npc) {
|
||||
this.player = player;
|
||||
this.audience = plugin.getAudiences().player(player);
|
||||
this.npc = npc;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@ -40,10 +43,9 @@ public class ConfirmScheduler extends BukkitRunnable {
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc)) {
|
||||
player.sendMessage(plugin.getLang().getMessage(Messages.PAY_CANCELED));
|
||||
plugin.getWaitingList().remove(player.getUniqueId().toString() + "." + npc);
|
||||
if (plugin.getWaitingList().containsKey(player.getUniqueId() + "." + npc)) {
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.PAY_CANCELED));
|
||||
plugin.getWaitingList().remove(player.getUniqueId() + "." + npc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class CooldownScheduler extends BukkitRunnable {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private final CitizensCMD plugin;
|
||||
|
||||
public CooldownScheduler(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
|
@ -19,6 +19,7 @@
|
||||
package me.mattstudios.citizenscmd.schedulers;
|
||||
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.Settings;
|
||||
import me.mattstudios.citizenscmd.updater.SpigotUpdater;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@ -35,7 +36,7 @@ public class UpdateScheduler extends BukkitRunnable {
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugin.getConfig().getBoolean("check-updates")) return;
|
||||
if (plugin.getSettings().getProperty(Settings.CHECK_UPDATES)) return;
|
||||
|
||||
SpigotUpdater updater = new SpigotUpdater(plugin, 30224);
|
||||
try {
|
||||
|
@ -13,10 +13,10 @@ import java.net.URLConnection;
|
||||
*/
|
||||
public class SpigotUpdater {
|
||||
|
||||
private int project;
|
||||
private final int project;
|
||||
private URL checkURL;
|
||||
private String newVersion;
|
||||
private JavaPlugin plugin;
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
public SpigotUpdater(JavaPlugin plugin, int projectID) {
|
||||
this.plugin = plugin;
|
||||
@ -24,8 +24,7 @@ public class SpigotUpdater {
|
||||
this.project = projectID;
|
||||
try {
|
||||
this.checkURL = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + projectID);
|
||||
} catch (MalformedURLException ignored) {
|
||||
}
|
||||
} catch (MalformedURLException ignored) {}
|
||||
}
|
||||
|
||||
public JavaPlugin getPlugin() {
|
||||
|
@ -85,7 +85,7 @@ public enum Messages {
|
||||
HOURS("messages.time-format.hours"),
|
||||
DAYS("messages.time-format.days");
|
||||
|
||||
private String path;
|
||||
private final String path;
|
||||
|
||||
Messages(String path) {
|
||||
this.path = path;
|
||||
|
@ -2,10 +2,10 @@ package me.mattstudios.citizenscmd.utility;
|
||||
|
||||
public class TimeUtil {
|
||||
|
||||
private int days;
|
||||
private int hours;
|
||||
private int minutes;
|
||||
private int seconds;
|
||||
private final int days;
|
||||
private final int hours;
|
||||
private final int minutes;
|
||||
private final int seconds;
|
||||
|
||||
private static final int SECONDS_IN_MINUTE = 60;
|
||||
private static final int SECONDS_IN_HOUR = 60 * SECONDS_IN_MINUTE;
|
||||
@ -13,9 +13,9 @@ public class TimeUtil {
|
||||
|
||||
public TimeUtil(long seconds) {
|
||||
days = (int) (seconds / SECONDS_IN_DAY);
|
||||
seconds = seconds - (days * SECONDS_IN_DAY);
|
||||
seconds = seconds - ((long) days * SECONDS_IN_DAY);
|
||||
hours = (int) (seconds / SECONDS_IN_HOUR);
|
||||
seconds = seconds - (hours * SECONDS_IN_HOUR);
|
||||
seconds = seconds - ((long) hours * SECONDS_IN_HOUR);
|
||||
minutes = (int) (seconds / SECONDS_IN_MINUTE);
|
||||
this.seconds = (int) (seconds - (minutes * SECONDS_IN_MINUTE));
|
||||
}
|
||||
|
@ -18,48 +18,59 @@
|
||||
|
||||
package me.mattstudios.citizenscmd.utility;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.Settings;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static me.mattstudios.utils.MessageUtils.color;
|
||||
import static me.mattstudios.utils.MessageUtils.info;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Util {
|
||||
|
||||
private Util() {}
|
||||
|
||||
public static final LegacyComponentSerializer LEGACY = LegacyComponentSerializer.legacyAmpersand();
|
||||
public static final MiniMessage MINI = MiniMessage.miniMessage();
|
||||
|
||||
/**
|
||||
* String with CitizensCMD default header and tag
|
||||
*/
|
||||
public static final String HEADER = "&c&m-&6&m-&e&m-&a&m-&b&m-&3&l CitizensCMD &b&m-&a&m-&e&m-&6&m-&c&m-";
|
||||
public static final String TAG = "&f[&3Citizens&cCMD&f]&r ";
|
||||
public static final Component HEADER = LEGACY.deserialize("&c&m-&6&m-&e&m-&a&m-&b&m-&3&l CitizensCMD &b&m-&a&m-&e&m-&6&m-&c&m-");
|
||||
public static final Component TAG = LEGACY.deserialize("&f[&3Citizens&cCMD&f]&r ");
|
||||
|
||||
/**
|
||||
* Checks if player has or not selected an NPC
|
||||
*
|
||||
* @param sender The player to check if it has any NPC selected or not
|
||||
* @return Returns true if has an NPC selected and false if not
|
||||
*/
|
||||
public static boolean npcNotSelected(final CitizensCMD plugin, final CommandSender sender) {
|
||||
if (CitizensAPI.getDefaultNPCSelector().getSelected(sender) != null) return false;
|
||||
public static String color(String message) {
|
||||
return ChatColor.translateAlternateColorCodes('&', message);
|
||||
}
|
||||
|
||||
sender.sendMessage(color(HEADER));
|
||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NO_NPC));
|
||||
return true;
|
||||
public static void info(String message) {
|
||||
Bukkit.getConsoleSender().sendMessage(message);
|
||||
}
|
||||
|
||||
public static List<String> color(final List<String> messages) {
|
||||
return messages.stream()
|
||||
.map((message) -> ChatColor.translateAlternateColorCodes('&', message))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,19 +83,26 @@ public class Util {
|
||||
return CitizensAPI.getDefaultNPCSelector().getSelected(player) == null;
|
||||
}
|
||||
|
||||
public static void sendNotSelectedMessage(final CitizensCMD plugin, final Audience audience) {
|
||||
audience.sendMessage(HEADER);
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.NO_NPC));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the NPC id
|
||||
*
|
||||
* @param sender To get the id of the NPC the player has selected
|
||||
* @return Returns the id of the NPC
|
||||
*/
|
||||
public static int getSelectedNpcId(final CommandSender sender) {
|
||||
return CitizensAPI.getDefaultNPCSelector().getSelected(sender).getId();
|
||||
public static OptionalInt getSelectedNpcId(final CommandSender sender) {
|
||||
final NPC npc = CitizensAPI.getDefaultNPCSelector().getSelected(sender);
|
||||
if (npc == null) return OptionalInt.empty();
|
||||
return OptionalInt.of(npc.getId());
|
||||
}
|
||||
|
||||
public static void setUpMetrics(Metrics metrics, FileConfiguration config) {
|
||||
metrics.addCustomChart(new Metrics.SimplePie("lang", () -> {
|
||||
switch (Objects.requireNonNull(config.getString("lang", "en")).toLowerCase()) {
|
||||
public static void setUpMetrics(Metrics metrics, SettingsManager settings) {
|
||||
metrics.addCustomChart(new SimplePie("lang", () -> {
|
||||
switch (settings.getProperty(Settings.LANG).toLowerCase()) {
|
||||
case "en":
|
||||
return "English";
|
||||
|
||||
@ -111,12 +129,12 @@ public class Util {
|
||||
}
|
||||
}));
|
||||
|
||||
metrics.addCustomChart(new Metrics.SimplePie("cooldown_display", () -> {
|
||||
switch (Objects.requireNonNull(config.getString("cooldown-time-display", "MEDIUM")).toLowerCase()) {
|
||||
case "FULL":
|
||||
metrics.addCustomChart(new SimplePie("cooldown_display", () -> {
|
||||
switch (settings.getProperty(Settings.TIME_DISPLAY).toLowerCase()) {
|
||||
case "full":
|
||||
return "Full";
|
||||
|
||||
case "SMALL":
|
||||
case "small":
|
||||
return "Small";
|
||||
|
||||
default:
|
||||
@ -131,7 +149,7 @@ public class Util {
|
||||
* @return returns the seconds from the config
|
||||
*/
|
||||
public static int getDefaultCooldown(CitizensCMD plugin) {
|
||||
return plugin.getConfig().getInt("default-cooldown");
|
||||
return plugin.getSettings().getProperty(Settings.DEFAULT_COOLDOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -150,9 +168,10 @@ public class Util {
|
||||
* @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!"));
|
||||
info(color(TAG + "&cDisabling CitizensCMD..."));
|
||||
final Logger logger = plugin.getLogger();
|
||||
logger.info(color(TAG + "&cCitizens &7is needed for this plugin to work!"));
|
||||
logger.info(color(TAG + "&cCitizens.jar &7is not installed on the server!"));
|
||||
logger.info(color(TAG + "&cDisabling CitizensCMD..."));
|
||||
Bukkit.getServer().getPluginManager().disablePlugin(plugin);
|
||||
}
|
||||
|
||||
@ -191,10 +210,10 @@ public class Util {
|
||||
TimeUtil timeUtil = new TimeUtil(seconds);
|
||||
|
||||
String[] messagesString = new String[4];
|
||||
messagesString[0] = plugin.getLang().getMessage(Messages.SECONDS);
|
||||
messagesString[1] = plugin.getLang().getMessage(Messages.MINUTES);
|
||||
messagesString[2] = plugin.getLang().getMessage(Messages.HOURS);
|
||||
messagesString[3] = plugin.getLang().getMessage(Messages.DAYS);
|
||||
messagesString[0] = plugin.getLang().getUncoloredMessage(Messages.SECONDS);
|
||||
messagesString[1] = plugin.getLang().getUncoloredMessage(Messages.MINUTES);
|
||||
messagesString[2] = plugin.getLang().getUncoloredMessage(Messages.HOURS);
|
||||
messagesString[3] = plugin.getLang().getUncoloredMessage(Messages.DAYS);
|
||||
|
||||
String[] shorts = new String[4];
|
||||
String[] mediums = new String[4];
|
||||
@ -331,7 +350,6 @@ public class Util {
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
|
||||
}
|
||||
|
||||
public static boolean soundExists(String soundName) {
|
||||
|
@ -1,25 +0,0 @@
|
||||
# Citizens CMD Plugin by Mateus Moreira
|
||||
# @LichtHund
|
||||
# Version ${project.version}
|
||||
# Wiki: https://github.com/ipsk/CitizensCMD/wiki
|
||||
# GitHub: https://github.com/ipsk/CitizensCMD
|
||||
# Spigot: https://www.spigotmc.org/resources/citizens-cmd.30224/
|
||||
|
||||
#
|
||||
# Enables Checking for update.
|
||||
check-updates: true
|
||||
#
|
||||
# Available languages EN, PT, BG, RO, NO, CH
|
||||
lang: 'en'
|
||||
#
|
||||
# The default npc cooldown in seconds
|
||||
default-cooldown: 0
|
||||
#
|
||||
# When using a NPC with price, true means that to confirm the use the player needs to seek or press shift
|
||||
shift-confirm: true
|
||||
#
|
||||
# Select cooldown display format, SHORT = 3m 3s | MEDIUM = 3 min 3 sec | FULL - 3 minutes 3 seconds
|
||||
cooldown-time-display: MEDIUM
|
||||
#
|
||||
# Disables citizens check on startup
|
||||
citizens-check: true
|
Loading…
Reference in New Issue
Block a user