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>
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>repo</id>
|
||||||
|
<url>https://repo.triumphteam.dev/snapshots/</url>
|
||||||
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>Citizens-Repo</id>
|
<id>Citizens-Repo</id>
|
||||||
<url>https://repo.citizensnpcs.co/</url>
|
<url>https://repo.citizensnpcs.co/</url>
|
||||||
@ -85,32 +89,35 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Compile -->
|
<!-- Compile -->
|
||||||
<!-- JSON Message -->
|
<!-- Adventure! -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.rayzr522</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>jsonmessage</artifactId>
|
<artifactId>adventure-platform-bukkit</artifactId>
|
||||||
<version>${jsonmsg.version}</version>
|
<version>4.1.0</version>
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Matt's utils -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.ipsk</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>MattUtils</artifactId>
|
<artifactId>adventure-text-minimessage</artifactId>
|
||||||
<version>${utils.version}</version>
|
<version>4.10.1</version>
|
||||||
<scope>compile</scope>
|
</dependency>
|
||||||
|
<!-- Configuration -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.jalu</groupId>
|
||||||
|
<artifactId>configme</artifactId>
|
||||||
|
<version>1.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Matt's Framework -->
|
<!-- Matt's Framework -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.mattstudios.utils</groupId>
|
<groupId>dev.triumphteam</groupId>
|
||||||
<artifactId>matt-framework</artifactId>
|
<artifactId>triumph-cmd-bukkit</artifactId>
|
||||||
<version>1.4.3</version>
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- bStats -->
|
<!-- bStats -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bstats</groupId>
|
<groupId>org.bstats</groupId>
|
||||||
<artifactId>bstats-bukkit</artifactId>
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
<version>1.5</version>
|
<version>3.0.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -18,6 +18,12 @@
|
|||||||
|
|
||||||
package me.mattstudios.citizenscmd;
|
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.api.CitizensCMDAPI;
|
||||||
import me.mattstudios.citizenscmd.commands.AddCommand;
|
import me.mattstudios.citizenscmd.commands.AddCommand;
|
||||||
import me.mattstudios.citizenscmd.commands.CooldownCommand;
|
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.updater.SpigotUpdater;
|
||||||
import me.mattstudios.citizenscmd.utility.DisplayFormat;
|
import me.mattstudios.citizenscmd.utility.DisplayFormat;
|
||||||
import me.mattstudios.citizenscmd.utility.Messages;
|
import me.mattstudios.citizenscmd.utility.Messages;
|
||||||
import me.mattstudios.citizenscmd.utility.Util;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import me.mattstudios.mf.base.CommandManager;
|
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 net.milkbowl.vault.economy.Economy;
|
||||||
import org.bstats.bukkit.Metrics;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.nio.file.Paths;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
import java.util.stream.Stream;
|
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.citizenscmd.utility.Util.disablePlugin;
|
||||||
import static me.mattstudios.utils.MessageUtils.color;
|
import static me.mattstudios.citizenscmd.utility.Util.info;
|
||||||
import static me.mattstudios.utils.MessageUtils.info;
|
|
||||||
import static me.mattstudios.utils.YamlUtils.copyDefaults;
|
|
||||||
|
|
||||||
public final class CitizensCMD extends JavaPlugin {
|
public final class CitizensCMD extends JavaPlugin {
|
||||||
|
|
||||||
@ -68,11 +81,14 @@ public final class CitizensCMD extends JavaPlugin {
|
|||||||
private CooldownHandler cooldownHandler;
|
private CooldownHandler cooldownHandler;
|
||||||
private PermissionsManager permissionsManager;
|
private PermissionsManager permissionsManager;
|
||||||
|
|
||||||
|
private BukkitAudiences audiences;
|
||||||
|
|
||||||
private static CitizensCMDAPI api;
|
private static CitizensCMDAPI api;
|
||||||
private static Economy economy;
|
private static Economy economy;
|
||||||
|
|
||||||
private boolean papi = false;
|
private boolean papi = false;
|
||||||
private CommandManager commandManager;
|
private BukkitCommandManager<CommandSender> commandManager;
|
||||||
|
private SettingsManager settings;
|
||||||
|
|
||||||
private boolean updateStatus = false;
|
private boolean updateStatus = false;
|
||||||
private boolean shift = false;
|
private boolean shift = false;
|
||||||
@ -84,22 +100,28 @@ public final class CitizensCMD extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
saveDefaultConfig();
|
settings = SettingsManagerBuilder
|
||||||
copyDefaults(getClassLoader().getResourceAsStream("config.yml"), new File(getDataFolder().getPath(), "config.yml"));
|
.withYamlFile(Paths.get(getDataFolder().getPath(), "config.yml"))
|
||||||
|
.configurationData(Settings.class)
|
||||||
|
.useDefaultMigrationService()
|
||||||
|
.create();
|
||||||
|
|
||||||
setLang(Objects.requireNonNull(getConfig().getString("lang")));
|
audiences = BukkitAudiences.create(this);
|
||||||
|
|
||||||
if (!hasCitizens() && getConfig().getBoolean("citizens-check")) {
|
setLang(settings.getProperty(Settings.LANG));
|
||||||
|
|
||||||
|
if (!hasCitizens() && settings.getProperty(Settings.CITIZENS_CHECK)) {
|
||||||
disablePlugin(this);
|
disablePlugin(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
commandManager = new CommandManager(this, true);
|
commandManager = BukkitCommandManager.create(this);
|
||||||
|
|
||||||
Metrics metrics = new Metrics(this);
|
//Metrics metrics = new Metrics(this);
|
||||||
Util.setUpMetrics(metrics, getConfig());
|
//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);
|
permissionsManager = new PermissionsManager(this);
|
||||||
|
|
||||||
@ -112,23 +134,22 @@ public final class CitizensCMD extends JavaPlugin {
|
|||||||
registerCommands();
|
registerCommands();
|
||||||
registerEvents();
|
registerEvents();
|
||||||
|
|
||||||
info(color(Util.TAG + lang.getMessage(Messages.USING_LANGUAGE)));
|
console.sendMessage(TAG.append(lang.getMessage(Messages.USING_LANGUAGE)));
|
||||||
|
|
||||||
if (hasPAPI()) {
|
if (hasPAPI()) {
|
||||||
info(color(Util.TAG + lang.getMessage(Messages.PAPI_AVAILABLE)));
|
console.sendMessage(TAG.append(lang.getMessage(Messages.PAPI_AVAILABLE)));
|
||||||
papi = true;
|
papi = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setupEconomy()) {
|
if (setupEconomy()) {
|
||||||
info(color(Util.TAG + lang.getUncoloredMessage(Messages.VAULT_AVAILABLE)));
|
console.sendMessage(TAG.append(lang.getMessage(Messages.VAULT_AVAILABLE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
waitingList = new HashMap<>();
|
waitingList = new HashMap<>();
|
||||||
|
|
||||||
setShift(getConfig().getBoolean("shift-confirm"));
|
setShift(settings.getProperty(Settings.SHIT_CONFIRM));
|
||||||
|
|
||||||
if (getConfig().contains("cooldown-time-display")) {
|
switch (settings.getProperty(Settings.TIME_DISPLAY).toLowerCase()) {
|
||||||
switch (Objects.requireNonNull(getConfig().getString("cooldown-time-display")).toLowerCase()) {
|
|
||||||
case "short":
|
case "short":
|
||||||
displayFormat = DisplayFormat.SHORT;
|
displayFormat = DisplayFormat.SHORT;
|
||||||
break;
|
break;
|
||||||
@ -141,19 +162,16 @@ public final class CitizensCMD extends JavaPlugin {
|
|||||||
displayFormat = DisplayFormat.MEDIUM;
|
displayFormat = DisplayFormat.MEDIUM;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
displayFormat = DisplayFormat.MEDIUM;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getConfig().getBoolean("check-updates")) {
|
if (settings.getProperty(Settings.CHECK_UPDATES)) {
|
||||||
SpigotUpdater updater = new SpigotUpdater(this, 30224);
|
SpigotUpdater updater = new SpigotUpdater(this, 30224);
|
||||||
try {
|
try {
|
||||||
// If there's an update, tell the user that they can update
|
// If there's an update, tell the user that they can update
|
||||||
if (updater.checkForUpdates()) {
|
if (updater.checkForUpdates()) {
|
||||||
updateStatus = true;
|
updateStatus = true;
|
||||||
newVersion = updater.getLatestVersion();
|
newVersion = updater.getLatestVersion();
|
||||||
info(color(Util.TAG + "&b&o" + lang.getUncoloredMessage(Messages.STARTUP_NEW_VERSION)));
|
console.sendMessage(TAG.append(lang.getMessage(Messages.STARTUP_NEW_VERSION).style(Style.style(NamedTextColor.AQUA, TextDecoration.ITALIC))));
|
||||||
info(color(Util.TAG + "&b&o" + updater.getResourceURL()));
|
console.sendMessage(TAG.append(Component.text(updater.getResourceURL()).style(Style.style(NamedTextColor.AQUA, TextDecoration.ITALIC))));
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
@ -182,30 +200,41 @@ public final class CitizensCMD extends JavaPlugin {
|
|||||||
* Registers all the commands to be used
|
* Registers all the commands to be used
|
||||||
*/
|
*/
|
||||||
private void registerCommands() {
|
private void registerCommands() {
|
||||||
commandManager.getCompletionHandler().register("#permissions", input -> Arrays.asList("console", "player", "permission", "server", "message", "sound"));
|
commandManager.registerSuggestion(SuggestionKey.of("permissions"), (sender, context) -> Arrays.asList("console", "player", "permission", "server", "message", "sound"));
|
||||||
commandManager.getCompletionHandler().register("#type", input -> Arrays.asList("cmd", "perm"));
|
commandManager.registerSuggestion(SuggestionKey.of("type"), (sender, context) -> Arrays.asList("cmd", "perm"));
|
||||||
commandManager.getCompletionHandler().register("#click", input -> Arrays.asList("left", "right"));
|
commandManager.registerSuggestion(SuggestionKey.of("click"), (sender, context) -> Arrays.asList("left", "right"));
|
||||||
commandManager.getCompletionHandler().register("#set", input -> Arrays.asList("set", "remove"));
|
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 -> {
|
commandManager.registerMessage(BukkitMessageKey.NO_PERMISSION, (sender, context) -> {
|
||||||
sender.sendMessage(color(Util.HEADER));
|
final Audience audience = audiences.sender(sender);
|
||||||
sender.sendMessage(lang.getMessage(Messages.NO_PERMISSION));
|
audience.sendMessage(HEADER);
|
||||||
|
audience.sendMessage(lang.getMessage(Messages.NO_PERMISSION));
|
||||||
});
|
});
|
||||||
commandManager.getMessageHandler().register("cmd.no.console", sender -> {
|
commandManager.registerMessage(BukkitMessageKey.PLAYER_ONLY, (sender, context) -> {
|
||||||
sender.sendMessage(color(Util.HEADER));
|
final Audience audience = audiences.sender(sender);
|
||||||
sender.sendMessage(lang.getMessage(Messages.CONSOLE_NOT_ALLOWED));
|
audience.sendMessage(HEADER);
|
||||||
|
audience.sendMessage(lang.getMessage(Messages.CONSOLE_NOT_ALLOWED));
|
||||||
});
|
});
|
||||||
commandManager.getMessageHandler().register("cmd.no.exists", sender -> {
|
commandManager.registerMessage(MessageKey.UNKNOWN_COMMAND, (sender, context) -> {
|
||||||
sender.sendMessage(color(Util.HEADER));
|
final Audience audience = audiences.sender(sender);
|
||||||
sender.sendMessage(lang.getMessage(Messages.WRONG_USAGE));
|
audience.sendMessage(HEADER);
|
||||||
|
audience.sendMessage(lang.getMessage(Messages.WRONG_USAGE));
|
||||||
});
|
});
|
||||||
commandManager.getMessageHandler().register("cmd.wrong.usage", sender -> {
|
commandManager.registerMessage(MessageKey.INVALID_ARGUMENT, (sender, context) -> {
|
||||||
sender.sendMessage(color(Util.HEADER));
|
final Audience audience = audiences.sender(sender);
|
||||||
sender.sendMessage(lang.getMessage(Messages.WRONG_USAGE));
|
audience.sendMessage(HEADER);
|
||||||
|
audience.sendMessage(lang.getMessage(Messages.WRONG_USAGE));
|
||||||
});
|
});
|
||||||
commandManager.getMessageHandler().register("arg.must.be.number", sender -> {
|
commandManager.registerMessage(MessageKey.TOO_MANY_ARGUMENTS, (sender, context) -> {
|
||||||
sender.sendMessage(color(Util.HEADER));
|
final Audience audience = audiences.sender(sender);
|
||||||
sender.sendMessage(lang.getMessage(Messages.INVALID_NUMBER));
|
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(
|
Stream.of(
|
||||||
@ -218,7 +247,7 @@ public final class CitizensCMD extends JavaPlugin {
|
|||||||
new PriceCommand(this),
|
new PriceCommand(this),
|
||||||
new ReloadCommand(this),
|
new ReloadCommand(this),
|
||||||
new RemoveCommand(this)
|
new RemoveCommand(this)
|
||||||
).forEach(commandManager::register);
|
).forEach(commandManager::registerCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -250,10 +279,28 @@ public final class CitizensCMD extends JavaPlugin {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
economy = registeredServiceProvider.getProvider();
|
economy = registeredServiceProvider.getProvider();
|
||||||
shift = getConfig().getBoolean("shift-confirm");
|
shift = settings.getProperty(Settings.SHIT_CONFIRM);
|
||||||
return economy != null;
|
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
|
* 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;
|
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.CitizensCMD;
|
||||||
import me.mattstudios.citizenscmd.utility.Messages;
|
import me.mattstudios.citizenscmd.utility.Messages;
|
||||||
import me.mattstudios.mf.annotations.Command;
|
import net.kyori.adventure.audience.Audience;
|
||||||
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 org.bukkit.command.CommandSender;
|
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.HEADER;
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||||
import static me.mattstudios.utils.MessageUtils.color;
|
|
||||||
import static me.mattstudios.utils.NumbersUtils.isDouble;
|
|
||||||
|
|
||||||
@Command("npcmd")
|
public class AddCommand extends Npcmd {
|
||||||
public class AddCommand extends CommandBase {
|
|
||||||
|
|
||||||
private final CitizensCMD plugin;
|
private final CitizensCMD plugin;
|
||||||
|
|
||||||
public AddCommand(CitizensCMD plugin) {
|
public AddCommand(final CitizensCMD plugin) {
|
||||||
this.plugin = 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")
|
@SubCommand("add")
|
||||||
@Permission("citizenscmd.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);
|
if (!selectedNpc.isPresent()) {
|
||||||
boolean left = false;
|
sendNotSelectedMessage(plugin, audience);
|
||||||
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));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String finalString;
|
final StringBuilder permissionBuilder = new StringBuilder(permission);
|
||||||
|
if (flags.hasFlag("d")) {
|
||||||
if (displayName) {
|
final Optional<Double> delay = flags.getValue("d", Double.TYPE);
|
||||||
finalString = "{display} " + stringBuilder.toString().trim();
|
if (!delay.isPresent()) {
|
||||||
} else {
|
audience.sendMessage(HEADER);
|
||||||
finalString = stringBuilder.toString().trim();
|
audience.sendMessage(plugin.getLang().getMessage(Messages.NPC_ADD_DELAY_FAIL));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
permissionBuilder.append("(").append(delay.get()).append(")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (permissionBuilder.toString().equalsIgnoreCase("sound")) {
|
final String command = flags.getText();
|
||||||
if (arguments.length < 2) {
|
|
||||||
finalString += " 1 1";
|
if (command.isEmpty()) {
|
||||||
} else {
|
audience.sendMessage(HEADER);
|
||||||
if (arguments.length < 3) {
|
audience.sendMessage(plugin.getLang().getMessage(Messages.WRONG_USAGE));
|
||||||
finalString += " 1";
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getDataHandler().addCommand(getSelectedNpcId(sender), permissionBuilder.toString(), finalString, sender, left);
|
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;
|
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.CitizensCMD;
|
||||||
import me.mattstudios.mf.annotations.Command;
|
import net.kyori.adventure.audience.Audience;
|
||||||
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 org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
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 Npcmd {
|
||||||
public class CooldownCommand extends CommandBase {
|
|
||||||
|
|
||||||
private CitizensCMD plugin;
|
private final CitizensCMD plugin;
|
||||||
|
|
||||||
public CooldownCommand(CitizensCMD plugin) {
|
public CooldownCommand(final CitizensCMD plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubCommand("cooldown")
|
@SubCommand("cooldown")
|
||||||
@Permission("citizenscmd.cooldown")
|
@Permission("citizenscmd.cooldown")
|
||||||
public void cooldown(CommandSender sender, @Completion("#range:9") Integer cooldown) {
|
public void cooldown(final CommandSender sender, @Suggestion("range") final int cooldown) {
|
||||||
if (npcNotSelected(plugin, sender)) return;
|
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;
|
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.CitizensCMD;
|
||||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||||
import me.mattstudios.citizenscmd.utility.Messages;
|
import me.mattstudios.citizenscmd.utility.Messages;
|
||||||
import me.mattstudios.mf.annotations.Command;
|
import net.kyori.adventure.audience.Audience;
|
||||||
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 org.bukkit.command.CommandSender;
|
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.HEADER;
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||||
import static me.mattstudios.utils.MessageUtils.color;
|
|
||||||
|
|
||||||
@Command("npcmd")
|
public class EditCommand extends Npcmd {
|
||||||
public class EditCommand extends CommandBase {
|
|
||||||
|
|
||||||
private CitizensCMD plugin;
|
private final CitizensCMD plugin;
|
||||||
|
|
||||||
public EditCommand(CitizensCMD plugin) {
|
public EditCommand(final CitizensCMD plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubCommand("edit")
|
@SubCommand("edit")
|
||||||
@Permission("citizenscmd.edit")
|
@Permission("citizenscmd.edit")
|
||||||
@Completion({"#type", "#click"})
|
public void edit(
|
||||||
public void edit(CommandSender sender, String typeString, String clickString, Integer id, String[] arguments) {
|
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.ClickType click;
|
||||||
EnumTypes.EditType type;
|
EnumTypes.EditType type;
|
||||||
@ -42,9 +52,9 @@ public class EditCommand extends CommandBase {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "perm":
|
case "perm":
|
||||||
if (arguments.length > 1) {
|
if (arguments.size() > 1) {
|
||||||
sender.sendMessage(color(HEADER));
|
audience.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.INVALID_PERMISSION));
|
audience.sendMessage(plugin.getLang().getMessage(Messages.INVALID_PERMISSION));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,24 +62,27 @@ public class EditCommand extends CommandBase {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sender.sendMessage(color(HEADER));
|
audience.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ARGUMENTS));
|
audience.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ARGUMENTS));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (clickString.toLowerCase()) {
|
switch (clickString.toLowerCase()) {
|
||||||
case "left":
|
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) {
|
if (leftCommandSize == 0) {
|
||||||
sender.sendMessage(color(HEADER));
|
audience.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NO_COMMANDS));
|
audience.sendMessage(plugin.getLang().getMessage(Messages.NO_COMMANDS));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id < 1 || id > leftCommandSize) {
|
if (id < 1 || id > leftCommandSize) {
|
||||||
sender.sendMessage(color(HEADER));
|
audience.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ID_NUMBER));
|
audience.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ID_NUMBER));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,37 +90,35 @@ public class EditCommand extends CommandBase {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "right":
|
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) {
|
if (rightCommandSize == 0) {
|
||||||
sender.sendMessage(color(HEADER));
|
audience.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NO_COMMANDS));
|
audience.sendMessage(plugin.getLang().getMessage(Messages.NO_COMMANDS));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id < 1 || id > rightCommandSize) {
|
if (id < 1 || id > rightCommandSize) {
|
||||||
sender.sendMessage(color(HEADER));
|
audience.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ID_NUMBER));
|
audience.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ID_NUMBER));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
click = EnumTypes.ClickType.RIGHT;
|
click = EnumTypes.ClickType.RIGHT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sender.sendMessage(color(HEADER));
|
audience.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.INVALID_CLICK_TYPE));
|
audience.sendMessage(plugin.getLang().getMessage(Messages.INVALID_CLICK_TYPE));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
String finalString = Strings.join(arguments, " ").trim();
|
||||||
arguments[0] = arguments[0].replace("/", "");
|
if (finalString.startsWith("/")) finalString = finalString.substring(1);
|
||||||
|
|
||||||
for (int i = 0; i < arguments.length; i++) {
|
plugin.getDataHandler().edit(selectedNpc.getAsInt(), id, click, type, finalString, audience);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,40 +1,180 @@
|
|||||||
package me.mattstudios.citizenscmd.commands;
|
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.CitizensCMD;
|
||||||
import me.mattstudios.citizenscmd.utility.Messages;
|
import me.mattstudios.citizenscmd.utility.Messages;
|
||||||
import me.mattstudios.mf.annotations.Command;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import me.mattstudios.mf.annotations.Default;
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
import me.mattstudios.mf.annotations.Permission;
|
import net.kyori.adventure.text.Component;
|
||||||
import me.mattstudios.mf.base.CommandBase;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import me.rayzr522.jsonmessage.JSONMessage;
|
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 org.bukkit.entity.Player;
|
||||||
|
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
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 Npcmd {
|
||||||
public class HelpCommand extends CommandBase {
|
|
||||||
|
|
||||||
private CitizensCMD plugin;
|
private final CitizensCMD plugin;
|
||||||
|
private final BukkitAudiences audiences;
|
||||||
|
|
||||||
public HelpCommand(CitizensCMD plugin) {
|
public HelpCommand(final CitizensCMD plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.audiences = plugin.getAudiences();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Default
|
@Default
|
||||||
@Permission("citizenscmd.npcmd")
|
@Permission("citizenscmd.npcmd")
|
||||||
public void help(Player player) {
|
public void help(Player player) {
|
||||||
JSONMessage.create(color(HEADER)).send(player);
|
final Audience audience = audiences.player(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);
|
final TextComponent.Builder builder = Component.text();
|
||||||
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);
|
builder
|
||||||
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);
|
.append(HEADER)
|
||||||
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);
|
.append(newline())
|
||||||
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);
|
.append(plugin.getLang().getMessage(Messages.HELP_VERSION))
|
||||||
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);
|
.append(space())
|
||||||
JSONMessage.create(color("&3/npcmd &cpermission &b<set | remove> &6<custom.permission>")).suggestCommand("/npcmd permission ").send(player);
|
.append(text(plugin.getDescription().getVersion()).style(Style.style(NamedTextColor.RED, TextDecoration.ITALIC)))
|
||||||
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);
|
.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;
|
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.CitizensCMD;
|
||||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||||
import me.mattstudios.citizenscmd.utility.Messages;
|
import me.mattstudios.citizenscmd.utility.Messages;
|
||||||
import me.mattstudios.mf.annotations.Command;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import me.mattstudios.mf.annotations.Permission;
|
import net.kyori.adventure.text.Component;
|
||||||
import me.mattstudios.mf.annotations.SubCommand;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import me.mattstudios.mf.base.CommandBase;
|
|
||||||
import me.rayzr522.jsonmessage.JSONMessage;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
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.getSelectedNpcId;
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||||
import static me.mattstudios.utils.MessageUtils.color;
|
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 Npcmd {
|
||||||
public class ListCommand extends CommandBase {
|
|
||||||
|
|
||||||
private CitizensCMD plugin;
|
private final CitizensCMD plugin;
|
||||||
|
|
||||||
public ListCommand(CitizensCMD plugin) {
|
public ListCommand(CitizensCMD plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -30,34 +34,72 @@ public class ListCommand extends CommandBase {
|
|||||||
@SubCommand("list")
|
@SubCommand("list")
|
||||||
@Permission("citizenscmd.list")
|
@Permission("citizenscmd.list")
|
||||||
public void list(Player player) {
|
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> 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<>();
|
List<String> rightCommands = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT) != null ? plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT) : new ArrayList<>();
|
||||||
|
|
||||||
player.sendMessage(color(HEADER));
|
builder.append(HEADER).append(newline());
|
||||||
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);
|
builder.append(
|
||||||
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);
|
Component.text()
|
||||||
player.sendMessage("");
|
.append(plugin.getLang().getMessage(Messages.LIST_COOLDOWN))
|
||||||
player.sendMessage(plugin.getLang().getMessage(Messages.LIST_COUNT_RIGHT).replace("{count}", String.valueOf(rightCommands.size())));
|
.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;
|
int rightCount = 1;
|
||||||
for (String command : rightCommands) {
|
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++;
|
rightCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.sendMessage("");
|
builder.append(plugin.getLang().getMessage(Messages.LIST_COUNT_LEFT, "{count}", String.valueOf(leftCommands.size())));
|
||||||
player.sendMessage(plugin.getLang().getMessage(Messages.LIST_COUNT_LEFT).replace("{count}", String.valueOf(leftCommands.size())));
|
|
||||||
|
|
||||||
int leftCount = 1;
|
int leftCount = 1;
|
||||||
for (String command : leftCommands) {
|
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++;
|
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;
|
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.CitizensCMD;
|
||||||
import me.mattstudios.citizenscmd.utility.Messages;
|
import me.mattstudios.citizenscmd.utility.Messages;
|
||||||
import me.mattstudios.mf.annotations.Command;
|
import net.kyori.adventure.audience.Audience;
|
||||||
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 org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||||
import static me.mattstudios.utils.MessageUtils.color;
|
|
||||||
|
|
||||||
@Command("npcmd")
|
public class PermissionCommand extends Npcmd {
|
||||||
public class PermissionCommand extends CommandBase {
|
|
||||||
|
|
||||||
private CitizensCMD plugin;
|
private final CitizensCMD plugin;
|
||||||
|
|
||||||
public PermissionCommand(CitizensCMD plugin) {
|
public PermissionCommand(CitizensCMD plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -25,22 +24,32 @@ public class PermissionCommand extends CommandBase {
|
|||||||
|
|
||||||
@SubCommand("permission")
|
@SubCommand("permission")
|
||||||
@Permission("citizenscmd.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()) {
|
switch (set.toLowerCase()) {
|
||||||
case "set":
|
case "set":
|
||||||
plugin.getDataHandler().setCustomPermission(getSelectedNpcId(sender), permission, sender);
|
plugin.getDataHandler().setCustomPermission(selectedNpc.getAsInt(), permission, audience);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "remove":
|
case "remove":
|
||||||
plugin.getDataHandler().removeCustomPermission(getSelectedNpcId(sender), sender);
|
plugin.getDataHandler().removeCustomPermission(selectedNpc.getAsInt(), audience);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sender.sendMessage(color(HEADER));
|
audience.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.WRONG_USAGE));
|
audience.sendMessage(plugin.getLang().getMessage(Messages.WRONG_USAGE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
package me.mattstudios.citizenscmd.commands;
|
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.CitizensCMD;
|
||||||
import me.mattstudios.mf.annotations.Command;
|
import net.kyori.adventure.audience.Audience;
|
||||||
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 org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
import java.util.OptionalInt;
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
|
||||||
|
|
||||||
@Command("npcmd")
|
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||||
public class PriceCommand extends CommandBase {
|
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||||
|
|
||||||
|
public class PriceCommand extends Npcmd {
|
||||||
|
|
||||||
private final CitizensCMD plugin;
|
private final CitizensCMD plugin;
|
||||||
|
|
||||||
@ -22,10 +22,16 @@ public class PriceCommand extends CommandBase {
|
|||||||
|
|
||||||
@SubCommand("price")
|
@SubCommand("price")
|
||||||
@Permission("citizenscmd.price")
|
@Permission("citizenscmd.price")
|
||||||
@Completion("#range:9")
|
public void price(final CommandSender sender, @Suggestion("range") final double price) {
|
||||||
public void price(final CommandSender sender, final Double price) {
|
final OptionalInt selectedNpc = getSelectedNpcId(sender);
|
||||||
if (npcNotSelected(plugin, sender)) return;
|
|
||||||
plugin.getDataHandler().setPrice(getSelectedNpcId(sender), price, sender);
|
final Audience audience = plugin.getAudiences().sender(sender);
|
||||||
|
|
||||||
|
if (!selectedNpc.isPresent()) {
|
||||||
|
sendNotSelectedMessage(plugin, audience);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugin.getDataHandler().setPrice(selectedNpc.getAsInt(), price, audience);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,38 +1,39 @@
|
|||||||
package me.mattstudios.citizenscmd.commands;
|
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.CitizensCMD;
|
||||||
|
import me.mattstudios.citizenscmd.Settings;
|
||||||
import me.mattstudios.citizenscmd.utility.DisplayFormat;
|
import me.mattstudios.citizenscmd.utility.DisplayFormat;
|
||||||
import me.mattstudios.citizenscmd.utility.Messages;
|
import me.mattstudios.citizenscmd.utility.Messages;
|
||||||
import me.mattstudios.mf.annotations.Command;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import me.mattstudios.mf.annotations.Permission;
|
|
||||||
import me.mattstudios.mf.annotations.SubCommand;
|
|
||||||
import me.mattstudios.mf.base.CommandBase;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||||
import static me.mattstudios.utils.MessageUtils.color;
|
|
||||||
|
|
||||||
@Command("npcmd")
|
public class ReloadCommand extends Npcmd {
|
||||||
public class ReloadCommand extends CommandBase {
|
|
||||||
|
|
||||||
private CitizensCMD plugin;
|
private final CitizensCMD plugin;
|
||||||
|
private final SettingsManager settings;
|
||||||
|
|
||||||
public ReloadCommand(CitizensCMD plugin) {
|
public ReloadCommand(final CitizensCMD plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.settings = plugin.getSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubCommand("reload")
|
@SubCommand("reload")
|
||||||
@Permission("citizenscmd.reload")
|
@Permission("citizenscmd.reload")
|
||||||
public void reload(CommandSender player) {
|
public void reload(final CommandSender player) {
|
||||||
|
|
||||||
plugin.reloadConfig();
|
final Audience audience = plugin.getAudiences().sender(player);
|
||||||
plugin.saveDefaultConfig();
|
|
||||||
plugin.setLang(Objects.requireNonNull(plugin.getConfig().getString("lang")));
|
|
||||||
|
|
||||||
if (plugin.getConfig().contains("cooldown-time-display")) {
|
settings.reload();
|
||||||
switch (Objects.requireNonNull(plugin.getConfig().getString("cooldown-time-display")).toLowerCase()) {
|
plugin.setLang(settings.getProperty(Settings.LANG));
|
||||||
|
|
||||||
|
final String timeFormat = settings.getProperty(Settings.TIME_DISPLAY);
|
||||||
|
|
||||||
|
switch (timeFormat.toLowerCase()) {
|
||||||
case "short":
|
case "short":
|
||||||
plugin.setDisplayFormat(DisplayFormat.SHORT);
|
plugin.setDisplayFormat(DisplayFormat.SHORT);
|
||||||
break;
|
break;
|
||||||
@ -43,17 +44,16 @@ public class ReloadCommand extends CommandBase {
|
|||||||
plugin.setDisplayFormat(DisplayFormat.MEDIUM);
|
plugin.setDisplayFormat(DisplayFormat.MEDIUM);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else
|
|
||||||
plugin.setDisplayFormat(DisplayFormat.MEDIUM);
|
|
||||||
|
|
||||||
if (CitizensCMD.getEconomy() != null)
|
if (CitizensCMD.getEconomy() != null) {
|
||||||
plugin.setShift(plugin.getConfig().getBoolean("shift-confirm"));
|
plugin.setShift(settings.getProperty(Settings.SHIT_CONFIRM));
|
||||||
|
}
|
||||||
|
|
||||||
plugin.getDataHandler().reload();
|
plugin.getDataHandler().reload();
|
||||||
plugin.getCooldownHandler().reload();
|
plugin.getCooldownHandler().reload();
|
||||||
|
|
||||||
player.sendMessage(color(HEADER));
|
audience.sendMessage(HEADER);
|
||||||
player.sendMessage(plugin.getLang().getMessage(Messages.RELOAD));
|
audience.sendMessage(plugin.getLang().getMessage(Messages.RELOAD));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,52 +1,55 @@
|
|||||||
package me.mattstudios.citizenscmd.commands;
|
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.CitizensCMD;
|
||||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||||
import me.mattstudios.citizenscmd.utility.Messages;
|
import me.mattstudios.citizenscmd.utility.Messages;
|
||||||
import me.mattstudios.mf.annotations.Command;
|
import net.kyori.adventure.audience.Audience;
|
||||||
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 org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||||
import static me.mattstudios.citizenscmd.utility.Util.npcNotSelected;
|
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||||
import static me.mattstudios.utils.MessageUtils.color;
|
|
||||||
|
|
||||||
@Command("npcmd")
|
public class RemoveCommand extends Npcmd {
|
||||||
public class RemoveCommand extends CommandBase {
|
|
||||||
|
|
||||||
private CitizensCMD plugin;
|
private final CitizensCMD plugin;
|
||||||
|
|
||||||
public RemoveCommand(CitizensCMD plugin) {
|
public RemoveCommand(final CitizensCMD plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubCommand("remove")
|
@SubCommand("remove")
|
||||||
@Permission("citizenscmd.remove")
|
@Permission("citizenscmd.remove")
|
||||||
@Completion("#click")
|
public void remove(final CommandSender sender, @Suggestion("click") final String clickString, final int id) {
|
||||||
public void remove(CommandSender sender, String clickString, Integer 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;
|
EnumTypes.ClickType click;
|
||||||
|
|
||||||
switch (clickString.toLowerCase()) {
|
switch (clickString.toLowerCase()) {
|
||||||
case "left":
|
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) {
|
if (leftCommandSize == 0) {
|
||||||
sender.sendMessage(color(HEADER));
|
audience.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NO_COMMANDS));
|
audience.sendMessage(plugin.getLang().getMessage(Messages.NO_COMMANDS));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id < 1 || id > leftCommandSize) {
|
if (id < 1 || id > leftCommandSize) {
|
||||||
sender.sendMessage(color(HEADER));
|
audience.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ID_NUMBER));
|
audience.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ID_NUMBER));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,17 +57,17 @@ public class RemoveCommand extends CommandBase {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "right":
|
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) {
|
if (rightCommandSize == 0) {
|
||||||
sender.sendMessage(color(HEADER));
|
audience.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NO_COMMANDS));
|
audience.sendMessage(plugin.getLang().getMessage(Messages.NO_COMMANDS));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id < 0 || id > rightCommandSize) {
|
if (id < 0 || id > rightCommandSize) {
|
||||||
sender.sendMessage(color(HEADER));
|
audience.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ID_NUMBER));
|
audience.sendMessage(plugin.getLang().getMessage(Messages.INVALID_ID_NUMBER));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,13 +75,11 @@ public class RemoveCommand extends CommandBase {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sender.sendMessage(color(HEADER));
|
audience.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.INVALID_CLICK_TYPE));
|
audience.sendMessage(plugin.getLang().getMessage(Messages.INVALID_CLICK_TYPE));
|
||||||
return;
|
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.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import static me.mattstudios.utils.MessageUtils.color;
|
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||||
import static me.mattstudios.utils.MessageUtils.info;
|
import static me.mattstudios.citizenscmd.utility.Util.info;
|
||||||
|
|
||||||
public class CooldownHandler {
|
public class CooldownHandler {
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ public class CooldownHandler {
|
|||||||
|
|
||||||
private FileConfiguration cooldownsConfigurator;
|
private FileConfiguration cooldownsConfigurator;
|
||||||
|
|
||||||
private Map<String, Long> cooldownData;
|
private final Map<String, Long> cooldownData = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public CooldownHandler(CitizensCMD plugin) {
|
public CooldownHandler(CitizensCMD plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -56,8 +56,6 @@ public class CooldownHandler {
|
|||||||
cooldownsFile = new File(dir.getPath(), "cooldowns.yml");
|
cooldownsFile = new File(dir.getPath(), "cooldowns.yml");
|
||||||
cooldownsConfigurator = new YamlConfiguration();
|
cooldownsConfigurator = new YamlConfiguration();
|
||||||
|
|
||||||
cooldownData = new HashMap<>();
|
|
||||||
|
|
||||||
createBasics();
|
createBasics();
|
||||||
cacheData();
|
cacheData();
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@ import me.mattstudios.citizenscmd.CitizensCMD;
|
|||||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||||
import me.mattstudios.citizenscmd.utility.Messages;
|
import me.mattstudios.citizenscmd.utility.Messages;
|
||||||
import me.mattstudios.citizenscmd.utility.Util;
|
import me.mattstudios.citizenscmd.utility.Util;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@ -35,20 +35,22 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import static me.mattstudios.utils.MessageUtils.color;
|
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||||
import static me.mattstudios.utils.MessageUtils.info;
|
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||||
|
import static me.mattstudios.citizenscmd.utility.Util.info;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class DataHandler {
|
public class DataHandler {
|
||||||
|
|
||||||
private CitizensCMD plugin;
|
private final CitizensCMD plugin;
|
||||||
private static File savesFile;
|
private static File savesFile;
|
||||||
private static File dir;
|
private static File dir;
|
||||||
|
|
||||||
private static FileConfiguration dataConfigurator;
|
private static FileConfiguration dataConfigurator;
|
||||||
|
|
||||||
private Map<String, Object> data;
|
private final Map<String, Object> data = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public DataHandler(CitizensCMD plugin) {
|
public DataHandler(CitizensCMD plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -63,8 +65,6 @@ public class DataHandler {
|
|||||||
savesFile = new File(dir.getPath(), "saves.yml");
|
savesFile = new File(dir.getPath(), "saves.yml");
|
||||||
dataConfigurator = new YamlConfiguration();
|
dataConfigurator = new YamlConfiguration();
|
||||||
|
|
||||||
data = new HashMap<>();
|
|
||||||
|
|
||||||
createBasics();
|
createBasics();
|
||||||
cacheData();
|
cacheData();
|
||||||
}
|
}
|
||||||
@ -90,7 +90,6 @@ public class DataHandler {
|
|||||||
*/
|
*/
|
||||||
private void cacheData() {
|
private void cacheData() {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dataConfigurator.load(savesFile);
|
dataConfigurator.load(savesFile);
|
||||||
|
|
||||||
@ -136,7 +135,7 @@ public class DataHandler {
|
|||||||
* @param sender The player who run the command
|
* @param sender The player who run the command
|
||||||
* @param left If the command should be added to the left or right click
|
* @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, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
@ -170,12 +169,12 @@ public class DataHandler {
|
|||||||
dataConfigurator.set("npc-data.npc-" + npc + ".price", 0);
|
dataConfigurator.set("npc-data.npc-" + npc + ".price", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(color(Util.HEADER));
|
sender.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NPC_ADDED));
|
sender.sendMessage(plugin.getLang().getMessage(Messages.NPC_ADDED));
|
||||||
|
|
||||||
dataConfigurator.save(savesFile);
|
dataConfigurator.save(savesFile);
|
||||||
} catch (IOException | InvalidConfigurationException e) {
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
sender.sendMessage(color(Util.HEADER));
|
sender.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NPC_ADD_FAIL));
|
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 cooldown The cooldown in seconds to be added
|
||||||
* @param sender The player who run the command
|
* @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, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
@ -246,12 +245,12 @@ public class DataHandler {
|
|||||||
|
|
||||||
data.replace("npc-data.npc-" + npc + ".cooldown", cooldown);
|
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));
|
sender.sendMessage(plugin.getLang().getMessage(Messages.NPC_COOLDOWN_SET));
|
||||||
|
|
||||||
dataConfigurator.save(savesFile);
|
dataConfigurator.save(savesFile);
|
||||||
} catch (IOException | InvalidConfigurationException e) {
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
sender.sendMessage(color(Util.HEADER));
|
sender.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NPC_COOLDOWN_SET_ERROR));
|
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 price The price in seconds to be added
|
||||||
* @param sender The player who run the command
|
* @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, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
@ -274,7 +273,7 @@ public class DataHandler {
|
|||||||
|
|
||||||
data.replace("npc-data.npc-" + npc + ".price", price);
|
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));
|
sender.sendMessage(plugin.getLang().getMessage(Messages.NPC_PRICE_SET));
|
||||||
|
|
||||||
dataConfigurator.save(savesFile);
|
dataConfigurator.save(savesFile);
|
||||||
@ -291,7 +290,7 @@ public class DataHandler {
|
|||||||
* @param permission The permission to be added
|
* @param permission The permission to be added
|
||||||
* @param sender The player who run the command
|
* @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, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
@ -301,7 +300,7 @@ public class DataHandler {
|
|||||||
|
|
||||||
data.replace("npc-data.npc-" + npc + ".permission", permission);
|
data.replace("npc-data.npc-" + npc + ".permission", permission);
|
||||||
|
|
||||||
sender.sendMessage(color(Util.HEADER));
|
sender.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.PERMISSION_SET));
|
sender.sendMessage(plugin.getLang().getMessage(Messages.PERMISSION_SET));
|
||||||
|
|
||||||
dataConfigurator.save(savesFile);
|
dataConfigurator.save(savesFile);
|
||||||
@ -317,7 +316,7 @@ public class DataHandler {
|
|||||||
* @param npc The NPC id
|
* @param npc The NPC id
|
||||||
* @param sender The player who run the command
|
* @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, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
@ -328,7 +327,7 @@ public class DataHandler {
|
|||||||
|
|
||||||
data.remove("npc-data.npc-" + npc + ".permission");
|
data.remove("npc-data.npc-" + npc + ".permission");
|
||||||
|
|
||||||
sender.sendMessage(color(Util.HEADER));
|
sender.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.PERMISSION_REMOVED));
|
sender.sendMessage(plugin.getLang().getMessage(Messages.PERMISSION_REMOVED));
|
||||||
|
|
||||||
dataConfigurator.save(savesFile);
|
dataConfigurator.save(savesFile);
|
||||||
@ -428,7 +427,7 @@ public class DataHandler {
|
|||||||
* @param click The click type, either left or right
|
* @param click The click type, either left or right
|
||||||
* @param sender The player to send the message to
|
* @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, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
@ -442,7 +441,7 @@ public class DataHandler {
|
|||||||
data.replace(key, commands);
|
data.replace(key, commands);
|
||||||
dataConfigurator.set(key, commands);
|
dataConfigurator.set(key, commands);
|
||||||
|
|
||||||
sender.sendMessage(color(Util.HEADER));
|
sender.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.REMOVED_COMMAND));
|
sender.sendMessage(plugin.getLang().getMessage(Messages.REMOVED_COMMAND));
|
||||||
|
|
||||||
dataConfigurator.save(savesFile);
|
dataConfigurator.save(savesFile);
|
||||||
@ -462,7 +461,7 @@ public class DataHandler {
|
|||||||
* @param newValue the new value for either the command or the permission
|
* @param newValue the new value for either the command or the permission
|
||||||
* @param sender The player to send messages
|
* @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, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
try {
|
try {
|
||||||
createBasics();
|
createBasics();
|
||||||
@ -470,8 +469,7 @@ public class DataHandler {
|
|||||||
|
|
||||||
List<String> commandsData = getClickCommandsData(npc, click);
|
List<String> commandsData = getClickCommandsData(npc, click);
|
||||||
|
|
||||||
String typeText = "";
|
final String typeText;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case CMD:
|
case CMD:
|
||||||
String tempCommand = commandsData.get(commandID - 1);
|
String tempCommand = commandsData.get(commandID - 1);
|
||||||
@ -485,14 +483,16 @@ public class DataHandler {
|
|||||||
commandsData.set(commandID - 1, tempPerm);
|
commandsData.set(commandID - 1, tempPerm);
|
||||||
typeText = "PERM";
|
typeText = "PERM";
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
typeText = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
String key = "npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands";
|
String key = "npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands";
|
||||||
data.replace(key, commandsData);
|
data.replace(key, commandsData);
|
||||||
dataConfigurator.set(key, commandsData);
|
dataConfigurator.set(key, commandsData);
|
||||||
|
|
||||||
sender.sendMessage(color(Util.HEADER));
|
sender.sendMessage(HEADER);
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.EDITED_COMMAND).replace("{type}", typeText));
|
sender.sendMessage(plugin.getLang().getMessage(Messages.EDITED_COMMAND, "{type}", typeText));
|
||||||
|
|
||||||
dataConfigurator.save(savesFile);
|
dataConfigurator.save(savesFile);
|
||||||
} catch (IOException | InvalidConfigurationException e) {
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
|
@ -18,36 +18,39 @@
|
|||||||
|
|
||||||
package me.mattstudios.citizenscmd.files;
|
package me.mattstudios.citizenscmd.files;
|
||||||
|
|
||||||
|
import ch.jalu.configme.SettingsManager;
|
||||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||||
|
import me.mattstudios.citizenscmd.Settings;
|
||||||
import me.mattstudios.citizenscmd.utility.Messages;
|
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.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.simpleyaml.configuration.file.YamlFile;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
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")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
public class LangHandler {
|
public class LangHandler {
|
||||||
|
|
||||||
private CitizensCMD plugin;
|
private final CitizensCMD plugin;
|
||||||
private String lang;
|
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.plugin = plugin;
|
||||||
this.lang = lang;
|
this.settings = plugin.getSettings();
|
||||||
|
this.lang = lang.toLowerCase(Locale.ROOT);
|
||||||
messages = new HashMap<>();
|
|
||||||
cacheMessage();
|
cacheMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,22 +61,11 @@ public class LangHandler {
|
|||||||
try {
|
try {
|
||||||
File langFile = new File(plugin.getDataFolder(), "lang/" + lang + ".yml");
|
File langFile = new File(plugin.getDataFolder(), "lang/" + lang + ".yml");
|
||||||
FileConfiguration langConf = new YamlConfiguration();
|
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 (!langFile.exists()) {
|
||||||
if (langStream == null) {
|
|
||||||
langFile.createNewFile();
|
|
||||||
saveDefaults(CitizensCMD.class.getClassLoader().getResourceAsStream("lang/en.yml"), langFile);
|
|
||||||
} else {
|
|
||||||
plugin.saveResource("lang/" + lang + ".yml", false);
|
plugin.saveResource("lang/" + lang + ".yml", false);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (langStream == null) {
|
|
||||||
//saveDefaults(CitizensCMD.class.getClassLoader().getResourceAsStream("lang/en.yml"), langFile);
|
|
||||||
} else {
|
|
||||||
//saveDefaults(langStream, langFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
langConf.load(langFile);
|
langConf.load(langFile);
|
||||||
|
|
||||||
@ -82,7 +74,6 @@ public class LangHandler {
|
|||||||
messages.put("messages." + parent + "." + child, langConf.getString("messages." + parent + "." + child));
|
messages.put("messages." + parent + "." + child, langConf.getString("messages." + parent + "." + child));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException | InvalidConfigurationException e) {
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -94,8 +85,22 @@ public class LangHandler {
|
|||||||
* @param path String with the path to the message
|
* @param path String with the path to the message
|
||||||
* @return Returns String with colored message from file
|
* @return Returns String with colored message from file
|
||||||
*/
|
*/
|
||||||
public String getMessage(Messages path) {
|
public Component getMessage(Messages path) {
|
||||||
return color(messages.get(path.getPath()));
|
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() {
|
public String getLanguage() {
|
||||||
return lang;
|
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;
|
package me.mattstudios.citizenscmd.listeners;
|
||||||
|
|
||||||
|
import com.google.common.primitives.Floats;
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||||
|
import me.mattstudios.citizenscmd.Settings;
|
||||||
import me.mattstudios.citizenscmd.schedulers.ConfirmScheduler;
|
import me.mattstudios.citizenscmd.schedulers.ConfirmScheduler;
|
||||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||||
import me.mattstudios.citizenscmd.utility.Messages;
|
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.NPCRemoveEvent;
|
||||||
import net.citizensnpcs.api.event.NPCRightClickEvent;
|
import net.citizensnpcs.api.event.NPCRightClickEvent;
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
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.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
@ -37,16 +41,23 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
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.citizenscmd.utility.Util.getFormattedTime;
|
||||||
import static me.mattstudios.utils.MessageUtils.color;
|
|
||||||
import static org.bukkit.Bukkit.getScheduler;
|
import static org.bukkit.Bukkit.getScheduler;
|
||||||
|
|
||||||
public class NPCClickListener implements Listener {
|
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;
|
private final CitizensCMD plugin;
|
||||||
|
|
||||||
public NPCClickListener(CitizensCMD plugin) {
|
public NPCClickListener(CitizensCMD plugin) {
|
||||||
@ -58,6 +69,7 @@ public class NPCClickListener implements Listener {
|
|||||||
public void onRightClick(NPCRightClickEvent event) {
|
public void onRightClick(NPCRightClickEvent event) {
|
||||||
NPC npc = event.getNPC();
|
NPC npc = event.getNPC();
|
||||||
Player player = event.getClicker();
|
Player player = event.getClicker();
|
||||||
|
final Audience audience = plugin.getAudiences().player(player);
|
||||||
|
|
||||||
if (!player.hasPermission("citizenscmd.use")) return;
|
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 (!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 (!player.hasPermission("citizenscmd.bypass")) {
|
||||||
if (plugin.getCooldownHandler().onCooldown(npc.getId(), player.getUniqueId().toString())) {
|
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) {
|
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 {
|
} else {
|
||||||
cooldownMessage = plugin.getLang().getMessage(Messages.ON_COOLDOWN);
|
cooldownMessage = plugin.getLang().getMessage(Messages.ON_COOLDOWN, "{time}", time);
|
||||||
}
|
|
||||||
if (!"".equals(cooldownMessage)) {
|
|
||||||
player.sendMessage(cooldownMessage.replace("{time}", getFormattedTime(plugin, plugin.getCooldownHandler().getTimeLeft(npc.getId(), player.getUniqueId().toString()), plugin.getDisplayFormat())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
audience.sendMessage(cooldownMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,15 +101,17 @@ public class NPCClickListener implements Listener {
|
|||||||
if (price > 0.0) {
|
if (price > 0.0) {
|
||||||
if (CitizensCMD.getEconomy() != null) {
|
if (CitizensCMD.getEconomy() != null) {
|
||||||
|
|
||||||
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc.getId())) {
|
if (!plugin.getWaitingList().containsKey(player.getUniqueId() + "." + npc.getId())) {
|
||||||
String messageConfirm = plugin.getLang().getMessage(Messages.PAY_CONFIRM);
|
final Map<String, String> replacements = new HashMap<>();
|
||||||
if (!plugin.isShift())
|
replacements.put("{price}", String.valueOf(price));
|
||||||
messageConfirm = messageConfirm.replace("{shift}", "");
|
|
||||||
else
|
if (!plugin.isShift()) replacements.put("{shift}", "");
|
||||||
messageConfirm = messageConfirm.replace("{shift}", "Shift ");
|
else replacements.put("{shift}", "Shift ");
|
||||||
messageConfirm = messageConfirm.replace("{price}", String.valueOf(price));
|
|
||||||
player.sendMessage(messageConfirm);
|
final Component messageConfirm = plugin.getLang().getMessage(Messages.PAY_CONFIRM, replacements);
|
||||||
plugin.getWaitingList().put(player.getUniqueId().toString() + "." + npc.getId(), true);
|
|
||||||
|
audience.sendMessage(messageConfirm);
|
||||||
|
plugin.getWaitingList().put(player.getUniqueId() + "." + npc.getId(), true);
|
||||||
new ConfirmScheduler(plugin, player, npc.getId()).runTaskLaterAsynchronously(plugin, 300L);
|
new ConfirmScheduler(plugin, player, npc.getId()).runTaskLaterAsynchronously(plugin, 300L);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -107,14 +121,13 @@ public class NPCClickListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (CitizensCMD.getEconomy().getBalance(player) < price) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getWaitingList().remove(player.getUniqueId().toString() + "." + npc.getId());
|
plugin.getWaitingList().remove(player.getUniqueId() + "." + npc.getId());
|
||||||
CitizensCMD.getEconomy().withdrawPlayer(player, price);
|
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) {
|
public void onLeftClick(NPCLeftClickEvent event) {
|
||||||
NPC npc = event.getNPC();
|
NPC npc = event.getNPC();
|
||||||
Player player = event.getClicker();
|
Player player = event.getClicker();
|
||||||
|
final Audience audience = plugin.getAudiences().player(player);
|
||||||
|
|
||||||
if (!player.hasPermission("citizenscmd.use")) return;
|
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 (!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 (!player.hasPermission("citizenscmd.bypass")) {
|
||||||
if (plugin.getCooldownHandler().onCooldown(npc.getId(), player.getUniqueId().toString())) {
|
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) {
|
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 {
|
} else {
|
||||||
cooldownMessage = plugin.getLang().getMessage(Messages.ON_COOLDOWN);
|
cooldownMessage = plugin.getLang().getMessage(Messages.ON_COOLDOWN, "{time}", time);
|
||||||
}
|
|
||||||
if (!"".equals(cooldownMessage)) {
|
|
||||||
player.sendMessage(cooldownMessage.replace("{time}", getFormattedTime(plugin, plugin.getCooldownHandler().getTimeLeft(npc.getId(), player.getUniqueId().toString()), plugin.getDisplayFormat())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
audience.sendMessage(cooldownMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,24 +176,25 @@ public class NPCClickListener implements Listener {
|
|||||||
if (price > 0.0) {
|
if (price > 0.0) {
|
||||||
if (CitizensCMD.getEconomy() != null) {
|
if (CitizensCMD.getEconomy() != null) {
|
||||||
|
|
||||||
if (!plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc.getId())) {
|
if (!plugin.getWaitingList().containsKey(player.getUniqueId() + "." + npc.getId())) {
|
||||||
String messageConfirm = plugin.getLang().getMessage(Messages.PAY_CONFIRM);
|
final Map<String, String> replacements = new HashMap<>();
|
||||||
if (!plugin.isShift()) {
|
replacements.put("{price}", String.valueOf(price));
|
||||||
messageConfirm = messageConfirm.replace("{shift}", "");
|
|
||||||
} else {
|
if (!plugin.isShift()) replacements.put("{shift}", "");
|
||||||
messageConfirm = messageConfirm.replace("{shift}", "Shift ");
|
else replacements.put("{shift}", "Shift ");
|
||||||
}
|
|
||||||
messageConfirm = messageConfirm.replace("{price}", String.valueOf(price));
|
final Component messageConfirm = plugin.getLang().getMessage(Messages.PAY_CONFIRM, replacements);
|
||||||
player.sendMessage(messageConfirm);
|
|
||||||
plugin.getWaitingList().put(player.getUniqueId().toString() + "." + npc.getId(), true);
|
audience.sendMessage(messageConfirm);
|
||||||
|
plugin.getWaitingList().put(player.getUniqueId() + "." + npc.getId(), true);
|
||||||
new ConfirmScheduler(plugin, player, npc.getId()).runTaskLaterAsynchronously(plugin, 300L);
|
new ConfirmScheduler(plugin, player, npc.getId()).runTaskLaterAsynchronously(plugin, 300L);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.isShift() && !player.isSneaking()) return;
|
if (plugin.isShift() && !player.isSneaking()) return;
|
||||||
|
|
||||||
plugin.getWaitingList().remove(player.getUniqueId().toString() + "." + npc.getId());
|
plugin.getWaitingList().remove(player.getUniqueId() + "." + npc.getId());
|
||||||
player.sendMessage(plugin.getLang().getMessage(Messages.PAY_CANCELED));
|
audience.sendMessage(plugin.getLang().getMessage(Messages.PAY_CANCELED));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -209,8 +225,7 @@ public class NPCClickListener implements Listener {
|
|||||||
List<String> commands = new ArrayList<>();
|
List<String> commands = new ArrayList<>();
|
||||||
|
|
||||||
for (String list : plugin.getDataHandler().getClickCommandsData(npc.getId(), clickType)) {
|
for (String list : plugin.getDataHandler().getClickCommandsData(npc.getId(), clickType)) {
|
||||||
Pattern pattern = Pattern.compile("\\[([^]]*)] (.*)");
|
Matcher matcher = MAIN_PATTERN.matcher(list);
|
||||||
Matcher matcher = pattern.matcher(list);
|
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
|
|
||||||
permissions.add(matcher.group(1));
|
permissions.add(matcher.group(1));
|
||||||
@ -234,8 +249,7 @@ public class NPCClickListener implements Listener {
|
|||||||
double delay = 0;
|
double delay = 0;
|
||||||
|
|
||||||
if (permissions.get(i).contains("(")) {
|
if (permissions.get(i).contains("(")) {
|
||||||
Pattern pattern = Pattern.compile("(.*)\\(([^]]*)\\)");
|
Matcher matcher = PERMISSION_PATTERN.matcher(permissions.get(i));
|
||||||
Matcher matcher = pattern.matcher(permissions.get(i));
|
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
delay = Double.parseDouble(matcher.group(2));
|
delay = Double.parseDouble(matcher.group(2));
|
||||||
String permission = matcher.group(1);
|
String permission = matcher.group(1);
|
||||||
@ -250,33 +264,64 @@ public class NPCClickListener implements Listener {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "none":
|
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;
|
break;
|
||||||
|
|
||||||
case "server":
|
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;
|
break;
|
||||||
|
|
||||||
case "message":
|
case "message":
|
||||||
getScheduler().runTaskLater(plugin, () -> {
|
getScheduler().runTaskLater(plugin, () -> {
|
||||||
String finalMessage;
|
final String finalMessage = commands.get(finalI)
|
||||||
if (commands.get(finalI).contains("{display}")) {
|
.replace("{display}", plugin.getLang().getUncoloredMessage(Messages.MESSAGE_DISPLAY))
|
||||||
String tmpStr = commands.get(finalI).replace("{display}", plugin.getLang().getMessage(Messages.MESSAGE_DISPLAY));
|
.replace("{name}", npc.getFullName());
|
||||||
finalMessage = tmpStr.replace("{name}", npc.getFullName());
|
|
||||||
} else
|
final Audience audience = plugin.getAudiences().player(player);
|
||||||
finalMessage = commands.get(finalI);
|
|
||||||
player.sendMessage(color(finalMessage));
|
if (plugin.getSettings().getProperty(Settings.MINI_MESSAGE)) {
|
||||||
}, (int) delay * 20);
|
audience.sendMessage(MINI.deserialize(finalMessage));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
audience.sendMessage(LEGACY.deserialize(finalMessage));
|
||||||
|
}, (int) delay * 20L);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "sound":
|
case "sound":
|
||||||
getScheduler().runTaskLater(plugin, () -> {
|
getScheduler().runTaskLater(plugin, () -> {
|
||||||
Pattern pattern = Pattern.compile("(\\w+)\\s([\\d.]+)\\s([\\d.]+)");
|
String sound = commands.get(finalI);
|
||||||
Matcher matcher = pattern.matcher(commands.get(finalI));
|
final Matcher matcher = SOUND_PATTERN.matcher(sound);
|
||||||
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)));
|
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;
|
||||||
}
|
}
|
||||||
}, (int) delay * 20);
|
|
||||||
|
if (pitchString != null) {
|
||||||
|
final Float nullablePitch = Floats.tryParse(pitchString);
|
||||||
|
if (nullablePitch != null) volume = nullablePitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -284,7 +329,7 @@ public class NPCClickListener implements Listener {
|
|||||||
plugin.getPermissionsManager().setPermission(player, permissions.get(finalI));
|
plugin.getPermissionsManager().setPermission(player, permissions.get(finalI));
|
||||||
player.chat("/" + commands.get(finalI));
|
player.chat("/" + commands.get(finalI));
|
||||||
plugin.getPermissionsManager().unsetPermission(player, permissions.get(finalI));
|
plugin.getPermissionsManager().unsetPermission(player, permissions.get(finalI));
|
||||||
}, (int) delay * 20);
|
}, (int) delay * 20L);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,30 +20,47 @@ package me.mattstudios.citizenscmd.listeners;
|
|||||||
|
|
||||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||||
import me.mattstudios.citizenscmd.utility.Messages;
|
import me.mattstudios.citizenscmd.utility.Messages;
|
||||||
import me.mattstudios.citizenscmd.utility.Util;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import me.rayzr522.jsonmessage.JSONMessage;
|
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.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
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 {
|
public class UpdateEvent implements Listener {
|
||||||
|
|
||||||
private CitizensCMD plugin;
|
private final CitizensCMD plugin;
|
||||||
|
|
||||||
public UpdateEvent(CitizensCMD plugin) {
|
public UpdateEvent(CitizensCMD plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler (priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
if (plugin.isUpdateStatus() && event.getPlayer().hasPermission("citizenscmd.update")) {
|
if (!plugin.isUpdateStatus() || !event.getPlayer().hasPermission("citizenscmd.update")) return;
|
||||||
JSONMessage.create(color(Util.HEADER)).send(event.getPlayer());
|
|
||||||
JSONMessage.create(color(plugin.getLang().getUncoloredMessage(Messages.NEW_VERSION) + plugin.getNewVersion())).send(event.getPlayer());
|
final Audience audience = plugin.getAudiences().player(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());
|
|
||||||
}
|
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.CitizensCMD;
|
||||||
import me.mattstudios.citizenscmd.utility.Messages;
|
import me.mattstudios.citizenscmd.utility.Messages;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
public class ConfirmScheduler extends BukkitRunnable {
|
public class ConfirmScheduler extends BukkitRunnable {
|
||||||
|
|
||||||
private Player player;
|
private final Player player;
|
||||||
private int npc;
|
private final Audience audience;
|
||||||
private CitizensCMD plugin;
|
private final int npc;
|
||||||
|
private final CitizensCMD plugin;
|
||||||
|
|
||||||
public ConfirmScheduler(CitizensCMD plugin, Player player, int npc) {
|
public ConfirmScheduler(CitizensCMD plugin, Player player, int npc) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
this.audience = plugin.getAudiences().player(player);
|
||||||
this.npc = npc;
|
this.npc = npc;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
@ -40,10 +43,9 @@ public class ConfirmScheduler extends BukkitRunnable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (plugin.getWaitingList().containsKey(player.getUniqueId().toString() + "." + npc)) {
|
if (plugin.getWaitingList().containsKey(player.getUniqueId() + "." + npc)) {
|
||||||
player.sendMessage(plugin.getLang().getMessage(Messages.PAY_CANCELED));
|
audience.sendMessage(plugin.getLang().getMessage(Messages.PAY_CANCELED));
|
||||||
plugin.getWaitingList().remove(player.getUniqueId().toString() + "." + npc);
|
plugin.getWaitingList().remove(player.getUniqueId() + "." + npc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
|
|
||||||
public class CooldownScheduler extends BukkitRunnable {
|
public class CooldownScheduler extends BukkitRunnable {
|
||||||
|
|
||||||
private CitizensCMD plugin;
|
private final CitizensCMD plugin;
|
||||||
|
|
||||||
public CooldownScheduler(CitizensCMD plugin) {
|
public CooldownScheduler(CitizensCMD plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package me.mattstudios.citizenscmd.schedulers;
|
package me.mattstudios.citizenscmd.schedulers;
|
||||||
|
|
||||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||||
|
import me.mattstudios.citizenscmd.Settings;
|
||||||
import me.mattstudios.citizenscmd.updater.SpigotUpdater;
|
import me.mattstudios.citizenscmd.updater.SpigotUpdater;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ public class UpdateScheduler extends BukkitRunnable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (plugin.getConfig().getBoolean("check-updates")) return;
|
if (plugin.getSettings().getProperty(Settings.CHECK_UPDATES)) return;
|
||||||
|
|
||||||
SpigotUpdater updater = new SpigotUpdater(plugin, 30224);
|
SpigotUpdater updater = new SpigotUpdater(plugin, 30224);
|
||||||
try {
|
try {
|
||||||
|
@ -13,10 +13,10 @@ import java.net.URLConnection;
|
|||||||
*/
|
*/
|
||||||
public class SpigotUpdater {
|
public class SpigotUpdater {
|
||||||
|
|
||||||
private int project;
|
private final int project;
|
||||||
private URL checkURL;
|
private URL checkURL;
|
||||||
private String newVersion;
|
private String newVersion;
|
||||||
private JavaPlugin plugin;
|
private final JavaPlugin plugin;
|
||||||
|
|
||||||
public SpigotUpdater(JavaPlugin plugin, int projectID) {
|
public SpigotUpdater(JavaPlugin plugin, int projectID) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -24,8 +24,7 @@ public class SpigotUpdater {
|
|||||||
this.project = projectID;
|
this.project = projectID;
|
||||||
try {
|
try {
|
||||||
this.checkURL = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + projectID);
|
this.checkURL = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + projectID);
|
||||||
} catch (MalformedURLException ignored) {
|
} catch (MalformedURLException ignored) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaPlugin getPlugin() {
|
public JavaPlugin getPlugin() {
|
||||||
|
@ -85,7 +85,7 @@ public enum Messages {
|
|||||||
HOURS("messages.time-format.hours"),
|
HOURS("messages.time-format.hours"),
|
||||||
DAYS("messages.time-format.days");
|
DAYS("messages.time-format.days");
|
||||||
|
|
||||||
private String path;
|
private final String path;
|
||||||
|
|
||||||
Messages(String path) {
|
Messages(String path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
@ -2,10 +2,10 @@ package me.mattstudios.citizenscmd.utility;
|
|||||||
|
|
||||||
public class TimeUtil {
|
public class TimeUtil {
|
||||||
|
|
||||||
private int days;
|
private final int days;
|
||||||
private int hours;
|
private final int hours;
|
||||||
private int minutes;
|
private final int minutes;
|
||||||
private int seconds;
|
private final int seconds;
|
||||||
|
|
||||||
private static final int SECONDS_IN_MINUTE = 60;
|
private static final int SECONDS_IN_MINUTE = 60;
|
||||||
private static final int SECONDS_IN_HOUR = 60 * SECONDS_IN_MINUTE;
|
private static final int SECONDS_IN_HOUR = 60 * SECONDS_IN_MINUTE;
|
||||||
@ -13,9 +13,9 @@ public class TimeUtil {
|
|||||||
|
|
||||||
public TimeUtil(long seconds) {
|
public TimeUtil(long seconds) {
|
||||||
days = (int) (seconds / SECONDS_IN_DAY);
|
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);
|
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);
|
minutes = (int) (seconds / SECONDS_IN_MINUTE);
|
||||||
this.seconds = (int) (seconds - (minutes * SECONDS_IN_MINUTE));
|
this.seconds = (int) (seconds - (minutes * SECONDS_IN_MINUTE));
|
||||||
}
|
}
|
||||||
|
@ -18,48 +18,59 @@
|
|||||||
|
|
||||||
package me.mattstudios.citizenscmd.utility;
|
package me.mattstudios.citizenscmd.utility;
|
||||||
|
|
||||||
|
import ch.jalu.configme.SettingsManager;
|
||||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||||
|
import me.mattstudios.citizenscmd.Settings;
|
||||||
import net.citizensnpcs.api.CitizensAPI;
|
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.bukkit.Metrics;
|
||||||
|
import org.bstats.charts.SimplePie;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.List;
|
||||||
|
import java.util.OptionalInt;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import static me.mattstudios.utils.MessageUtils.color;
|
|
||||||
import static me.mattstudios.utils.MessageUtils.info;
|
|
||||||
|
|
||||||
public class Util {
|
public class Util {
|
||||||
|
|
||||||
private Util() {}
|
private Util() {}
|
||||||
|
|
||||||
|
public static final LegacyComponentSerializer LEGACY = LegacyComponentSerializer.legacyAmpersand();
|
||||||
|
public static final MiniMessage MINI = MiniMessage.miniMessage();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String with CitizensCMD default header and tag
|
* 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 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 String TAG = "&f[&3Citizens&cCMD&f]&r ";
|
public static final Component TAG = LEGACY.deserialize("&f[&3Citizens&cCMD&f]&r ");
|
||||||
|
|
||||||
/**
|
public static String color(String message) {
|
||||||
* Checks if player has or not selected an NPC
|
return ChatColor.translateAlternateColorCodes('&', message);
|
||||||
*
|
}
|
||||||
* @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;
|
|
||||||
|
|
||||||
sender.sendMessage(color(HEADER));
|
public static void info(String message) {
|
||||||
sender.sendMessage(plugin.getLang().getMessage(Messages.NO_NPC));
|
Bukkit.getConsoleSender().sendMessage(message);
|
||||||
return true;
|
}
|
||||||
|
|
||||||
|
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;
|
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
|
* Gets the NPC id
|
||||||
*
|
*
|
||||||
* @param sender To get the id of the NPC the player has selected
|
* @param sender To get the id of the NPC the player has selected
|
||||||
* @return Returns the id of the NPC
|
* @return Returns the id of the NPC
|
||||||
*/
|
*/
|
||||||
public static int getSelectedNpcId(final CommandSender sender) {
|
public static OptionalInt getSelectedNpcId(final CommandSender sender) {
|
||||||
return CitizensAPI.getDefaultNPCSelector().getSelected(sender).getId();
|
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) {
|
public static void setUpMetrics(Metrics metrics, SettingsManager settings) {
|
||||||
metrics.addCustomChart(new Metrics.SimplePie("lang", () -> {
|
metrics.addCustomChart(new SimplePie("lang", () -> {
|
||||||
switch (Objects.requireNonNull(config.getString("lang", "en")).toLowerCase()) {
|
switch (settings.getProperty(Settings.LANG).toLowerCase()) {
|
||||||
case "en":
|
case "en":
|
||||||
return "English";
|
return "English";
|
||||||
|
|
||||||
@ -111,12 +129,12 @@ public class Util {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
metrics.addCustomChart(new Metrics.SimplePie("cooldown_display", () -> {
|
metrics.addCustomChart(new SimplePie("cooldown_display", () -> {
|
||||||
switch (Objects.requireNonNull(config.getString("cooldown-time-display", "MEDIUM")).toLowerCase()) {
|
switch (settings.getProperty(Settings.TIME_DISPLAY).toLowerCase()) {
|
||||||
case "FULL":
|
case "full":
|
||||||
return "Full";
|
return "Full";
|
||||||
|
|
||||||
case "SMALL":
|
case "small":
|
||||||
return "Small";
|
return "Small";
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -131,7 +149,7 @@ public class Util {
|
|||||||
* @return returns the seconds from the config
|
* @return returns the seconds from the config
|
||||||
*/
|
*/
|
||||||
public static int getDefaultCooldown(CitizensCMD plugin) {
|
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.
|
* @param plugin The plugin to disable.
|
||||||
*/
|
*/
|
||||||
public static void disablePlugin(CitizensCMD plugin) {
|
public static void disablePlugin(CitizensCMD plugin) {
|
||||||
info(color(TAG + "&cCitizens &7is needed for this plugin to work!"));
|
final Logger logger = plugin.getLogger();
|
||||||
info(color(TAG + "&cCitizens.jar &7is not installed on the server!"));
|
logger.info(color(TAG + "&cCitizens &7is needed for this plugin to work!"));
|
||||||
info(color(TAG + "&cDisabling CitizensCMD..."));
|
logger.info(color(TAG + "&cCitizens.jar &7is not installed on the server!"));
|
||||||
|
logger.info(color(TAG + "&cDisabling CitizensCMD..."));
|
||||||
Bukkit.getServer().getPluginManager().disablePlugin(plugin);
|
Bukkit.getServer().getPluginManager().disablePlugin(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,10 +210,10 @@ public class Util {
|
|||||||
TimeUtil timeUtil = new TimeUtil(seconds);
|
TimeUtil timeUtil = new TimeUtil(seconds);
|
||||||
|
|
||||||
String[] messagesString = new String[4];
|
String[] messagesString = new String[4];
|
||||||
messagesString[0] = plugin.getLang().getMessage(Messages.SECONDS);
|
messagesString[0] = plugin.getLang().getUncoloredMessage(Messages.SECONDS);
|
||||||
messagesString[1] = plugin.getLang().getMessage(Messages.MINUTES);
|
messagesString[1] = plugin.getLang().getUncoloredMessage(Messages.MINUTES);
|
||||||
messagesString[2] = plugin.getLang().getMessage(Messages.HOURS);
|
messagesString[2] = plugin.getLang().getUncoloredMessage(Messages.HOURS);
|
||||||
messagesString[3] = plugin.getLang().getMessage(Messages.DAYS);
|
messagesString[3] = plugin.getLang().getUncoloredMessage(Messages.DAYS);
|
||||||
|
|
||||||
String[] shorts = new String[4];
|
String[] shorts = new String[4];
|
||||||
String[] mediums = new String[4];
|
String[] mediums = new String[4];
|
||||||
@ -331,7 +350,6 @@ public class Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return stringBuilder.toString();
|
return stringBuilder.toString();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean soundExists(String soundName) {
|
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