forked from Upstream/CitizensCMD
Cleanup
This commit is contained in:
parent
abf8b875c0
commit
4c0e4dbb3f
@ -18,6 +18,27 @@
|
||||
|
||||
package me.mattstudios.citizenscmd;
|
||||
|
||||
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.info;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import ch.jalu.configme.SettingsManagerBuilder;
|
||||
import dev.triumphteam.cmd.bukkit.BukkitCommandManager;
|
||||
@ -55,27 +76,6 @@ import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.LEGACY;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.TAG;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.info;
|
||||
|
||||
public final class CitizensCMD extends JavaPlugin {
|
||||
|
||||
private LangHandler lang;
|
||||
@ -122,7 +122,7 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
|
||||
commandManager = BukkitCommandManager.create(this);
|
||||
|
||||
Metrics metrics = new Metrics(this, 2652);
|
||||
final Metrics metrics = new Metrics(this, 2652);
|
||||
Util.setUpMetrics(metrics, settings);
|
||||
|
||||
console.sendMessage(TAG.append(LEGACY.deserialize("&3Citizens&cCMD &8&o" + getDescription().getVersion())));
|
||||
@ -169,7 +169,7 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
}
|
||||
|
||||
if (settings.getProperty(Settings.CHECK_UPDATES)) {
|
||||
SpigotUpdater updater = new SpigotUpdater(this, 30224);
|
||||
final SpigotUpdater updater = new SpigotUpdater(this, 30224);
|
||||
try {
|
||||
// If there's an update, tell the user that they can update
|
||||
if (updater.checkForUpdates()) {
|
||||
@ -178,7 +178,7 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
console.sendMessage(TAG.append(lang.getMessage(Messages.STARTUP_NEW_VERSION).style(Style.style(NamedTextColor.AQUA, TextDecoration.ITALIC))));
|
||||
console.sendMessage(TAG.append(Component.text(updater.getResourceURL()).style(Style.style(NamedTextColor.AQUA, TextDecoration.ITALIC))));
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
} catch (final Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -252,20 +252,20 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
new PriceCommand(this),
|
||||
new ReloadCommand(this),
|
||||
new RemoveCommand(this)
|
||||
).forEach(commandManager::registerCommand);
|
||||
).forEach(commandManager::registerCommand);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all the events to be used
|
||||
*/
|
||||
private void registerEvents() {
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
final PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvents(new UpdateEvent(this), this);
|
||||
pm.registerEvents(new NPCClickListener(this), this);
|
||||
|
||||
try {
|
||||
pm.registerEvents(new NPCListener(this), this);
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
info(color("&cCould not register clone event, please update your Citizens."));
|
||||
}
|
||||
}
|
||||
@ -279,7 +279,7 @@ public final class CitizensCMD extends JavaPlugin {
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return false;
|
||||
}
|
||||
RegisteredServiceProvider<Economy> registeredServiceProvider = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
final RegisteredServiceProvider<Economy> registeredServiceProvider = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (registeredServiceProvider == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -12,35 +12,35 @@ public final class Settings implements SettingsHolder {
|
||||
|
||||
@Comment({"", "Enables Checking for update."})
|
||||
public static final Property<Boolean> CHECK_UPDATES = PropertyInitializer
|
||||
.newProperty("check-updates", true);
|
||||
.newProperty("check-updates", true);
|
||||
|
||||
@Comment({"", "Available languages EN, PT, BG, RO, NO, CH"})
|
||||
public static final Property<String> LANG = PropertyInitializer
|
||||
.newProperty("lang", "EN");
|
||||
.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> MINIMESSAGE = PropertyInitializer
|
||||
.newProperty("minimessage", false);
|
||||
.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> MINIMESSAGE_LANG = PropertyInitializer
|
||||
.newProperty("minimessage-lang", false);
|
||||
.newProperty("minimessage-lang", false);
|
||||
|
||||
@Comment({"", "The default npc cooldown in seconds"})
|
||||
public static final Property<Integer> DEFAULT_COOLDOWN = PropertyInitializer
|
||||
.newProperty("default-cooldown", 0);
|
||||
.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);
|
||||
.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");
|
||||
.newProperty("cooldown-time-display", "MEDIUM");
|
||||
|
||||
@Comment({"", "Disables citizens check on startup"})
|
||||
public static final Property<Boolean> CITIZENS_CHECK = PropertyInitializer
|
||||
.newProperty("citizens-check", true);
|
||||
.newProperty("citizens-check", true);
|
||||
|
||||
@Override
|
||||
public void registerComments(final CommentsConfiguration conf) {
|
||||
@ -52,6 +52,6 @@ public final class Settings implements SettingsHolder {
|
||||
"GitHub: https://github.com/HexedHero/CitizensCMD",
|
||||
"Spigot: https://www.spigotmc.org/resources/30224/",
|
||||
""
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,14 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.CommandFlags;
|
||||
import dev.triumphteam.cmd.core.annotation.Flag;
|
||||
@ -9,14 +18,6 @@ import dev.triumphteam.cmd.core.flag.Flags;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
public class AddCommand extends Npcmd {
|
||||
|
||||
@ -29,15 +30,15 @@ public class AddCommand extends Npcmd {
|
||||
@SubCommand("add")
|
||||
@Permission("citizenscmd.add")
|
||||
@CommandFlags({
|
||||
@Flag(flag = "n"),
|
||||
@Flag(flag = "l"),
|
||||
@Flag(flag = "d", argument = double.class)
|
||||
@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);
|
||||
|
||||
final Audience audience = plugin.getAudiences().sender(sender);
|
||||
@ -69,8 +70,8 @@ public class AddCommand extends Npcmd {
|
||||
final String finalString = (flags.hasFlag("n") ? "{display} " + command : command).trim();
|
||||
|
||||
plugin
|
||||
.getDataHandler()
|
||||
.addCommand(selectedNpc.getAsInt(), permissionBuilder.toString(), finalString, audience, flags.hasFlag("l"));
|
||||
.getDataHandler()
|
||||
.addCommand(selectedNpc.getAsInt(), permissionBuilder.toString(), finalString, audience, flags.hasFlag("l"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,16 +1,17 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
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 net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
public class CooldownCommand extends Npcmd {
|
||||
|
||||
|
@ -1,5 +1,14 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.SubCommand;
|
||||
import dev.triumphteam.cmd.core.annotation.Suggestion;
|
||||
@ -7,14 +16,6 @@ import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
public class EditCommand extends Npcmd {
|
||||
|
||||
@ -32,7 +33,7 @@ public class EditCommand extends Npcmd {
|
||||
@Suggestion("click") final String clickString,
|
||||
final int id,
|
||||
final List<String> arguments
|
||||
) {
|
||||
) {
|
||||
final OptionalInt selectedNpc = getSelectedNpcId(sender);
|
||||
|
||||
final Audience audience = plugin.getAudiences().sender(sender);
|
||||
@ -68,10 +69,10 @@ public class EditCommand extends Npcmd {
|
||||
|
||||
switch (clickString.toLowerCase()) {
|
||||
case "left":
|
||||
int leftCommandSize = plugin.getDataHandler().getClickCommandsData(
|
||||
final int leftCommandSize = plugin.getDataHandler().getClickCommandsData(
|
||||
selectedNpc.getAsInt(),
|
||||
EnumTypes.ClickType.LEFT
|
||||
).size();
|
||||
).size();
|
||||
|
||||
if (leftCommandSize == 0) {
|
||||
audience.sendMessage(HEADER);
|
||||
@ -89,10 +90,10 @@ public class EditCommand extends Npcmd {
|
||||
break;
|
||||
|
||||
case "right":
|
||||
int rightCommandSize = plugin.getDataHandler().getClickCommandsData(
|
||||
final int rightCommandSize = plugin.getDataHandler().getClickCommandsData(
|
||||
selectedNpc.getAsInt(),
|
||||
EnumTypes.ClickType.RIGHT
|
||||
).size();
|
||||
).size();
|
||||
|
||||
if (rightCommandSize == 0) {
|
||||
audience.sendMessage(HEADER);
|
||||
@ -115,7 +116,9 @@ public class EditCommand extends Npcmd {
|
||||
}
|
||||
|
||||
String finalString = String.join(" ", arguments).trim();
|
||||
if (finalString.startsWith("/")) finalString = finalString.substring(1);
|
||||
if (finalString.startsWith("/")) {
|
||||
finalString = finalString.substring(1);
|
||||
}
|
||||
|
||||
plugin.getDataHandler().edit(selectedNpc.getAsInt(), id, click, type, finalString, audience);
|
||||
}
|
||||
|
@ -1,5 +1,13 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
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;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.Default;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
@ -13,13 +21,6 @@ import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.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;
|
||||
|
||||
public class HelpCommand extends Npcmd {
|
||||
|
||||
@ -39,139 +40,139 @@ public class HelpCommand extends Npcmd {
|
||||
final TextComponent.Builder builder = Component.text();
|
||||
|
||||
builder
|
||||
.append(HEADER)
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_VERSION))
|
||||
.append(space())
|
||||
.append(text(plugin.getDescription().getVersion()).style(Style.style(NamedTextColor.RED, TextDecoration.ITALIC)))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_INFO))
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &cadd &b<console &b| &bmessage &b| &bplayer | &bpermission &b| &bserver &b| &bsound &b> &6<command> &d[-l]"))
|
||||
.clickEvent(ClickEvent.suggestCommand("/npcmd add "))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_DESCRIPTION_ADD))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_EXAMPLE))
|
||||
.append(newline())
|
||||
.append(LEGACY.deserialize("&3&o/npcmd &c&oadd &b&ossentials.heal &6&oheal"))
|
||||
.build()
|
||||
)
|
||||
)
|
||||
)
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &ccooldown &6<time>"))
|
||||
.clickEvent(ClickEvent.suggestCommand("/npcmd cooldown "))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_DESCRIPTION_COOLDOWN))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_EXAMPLE))
|
||||
.append(newline())
|
||||
.append(LEGACY.deserialize("&3&o/npcmd &c&ocooldown &6&o15"))
|
||||
.build()
|
||||
)
|
||||
).build()
|
||||
)
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &cprice &6<price>"))
|
||||
.clickEvent(ClickEvent.suggestCommand("/npcmd price "))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_DESCRIPTION_PRICE))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_EXAMPLE))
|
||||
.append(newline())
|
||||
.append(LEGACY.deserialize("&3&o/npcmd &c&oprice &6&o250"))
|
||||
.build()
|
||||
)
|
||||
).build()
|
||||
)
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &clist"))
|
||||
.clickEvent(ClickEvent.suggestCommand("/npcmd list"))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_DESCRIPTION_LIST))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_EXAMPLE))
|
||||
.append(newline())
|
||||
.append(LEGACY.deserialize("&3&o/npcmd &c&olist"))
|
||||
.build()
|
||||
)
|
||||
).build()
|
||||
)
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &cedit &b<cmd | perm> &b<left | right> &6<id> &6<new command | new permission>"))
|
||||
.clickEvent(ClickEvent.suggestCommand("/npcmd edit "))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_DESCRIPTION_EDIT))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_EXAMPLE))
|
||||
.append(newline())
|
||||
.append(LEGACY.deserialize("&3&o/npcmd &c&oedit &b&ocmd &b&oright &6&o1 fly"))
|
||||
.build()
|
||||
)
|
||||
).build()
|
||||
)
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &cremove &b<left | right> &6<id>"))
|
||||
.clickEvent(ClickEvent.suggestCommand("/npcmd remove "))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_DESCRIPTION_REMOVE))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_EXAMPLE))
|
||||
.append(newline())
|
||||
.append(LEGACY.deserialize("&3&o/npcmd &c&oremove &b&oright &6&o1"))
|
||||
.build()
|
||||
)
|
||||
).build()
|
||||
)
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &cpermission &b<set | remove> &6<custom.permission>"))
|
||||
.clickEvent(ClickEvent.suggestCommand("/npcmd permission "))
|
||||
.append(HEADER)
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_VERSION))
|
||||
.append(space())
|
||||
.append(text(plugin.getDescription().getVersion()).style(Style.style(NamedTextColor.RED, TextDecoration.ITALIC)))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_INFO))
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &cadd &b<console &b| &bmessage &b| &bplayer | &bpermission &b| &bserver &b| &bsound &b> &6<command> &d[-l]"))
|
||||
.clickEvent(ClickEvent.suggestCommand("/npcmd add "))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_DESCRIPTION_ADD))
|
||||
.append(newline())
|
||||
.append(plugin.getLang().getMessage(Messages.HELP_EXAMPLE))
|
||||
.append(newline())
|
||||
.append(LEGACY.deserialize("&3&o/npcmd &c&oadd &b&ossentials.heal &6&oheal"))
|
||||
.build()
|
||||
)
|
||||
.append(newline())
|
||||
.append(
|
||||
Component.text()
|
||||
.append(LEGACY.deserialize("&3/npcmd &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()
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
.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,19 +1,5 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.SubCommand;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.LEGACY;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
@ -23,6 +9,21 @@ 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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.SubCommand;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
|
||||
public class ListCommand extends Npcmd {
|
||||
|
||||
private final CitizensCMD plugin;
|
||||
@ -46,41 +47,41 @@ public class ListCommand extends Npcmd {
|
||||
final TextComponent.Builder builder = Component.text();
|
||||
|
||||
final int npc = selectedNpc.getAsInt();
|
||||
List<String> leftCommands = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT) != null ? plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT) : new ArrayList<>();
|
||||
List<String> rightCommands = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT) != null ? plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT) : new ArrayList<>();
|
||||
final List<String> leftCommands = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT) != null ? plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.LEFT) : new ArrayList<>();
|
||||
final List<String> rightCommands = plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT) != null ? plugin.getDataHandler().getClickCommandsData(npc, EnumTypes.ClickType.RIGHT) : new ArrayList<>();
|
||||
|
||||
builder.append(HEADER).append(newline());
|
||||
builder.append(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.LIST_COOLDOWN))
|
||||
.append(text(plugin.getDataHandler().getNPCCooldown(npc)))
|
||||
.hoverEvent(showText(plugin.getLang().getMessage(Messages.LIST_TOOLTIP)))
|
||||
.clickEvent(suggestCommand("/npcmd cooldown "))
|
||||
.build()
|
||||
);
|
||||
.append(plugin.getLang().getMessage(Messages.LIST_COOLDOWN))
|
||||
.append(text(plugin.getDataHandler().getNPCCooldown(npc)))
|
||||
.hoverEvent(showText(plugin.getLang().getMessage(Messages.LIST_TOOLTIP)))
|
||||
.clickEvent(suggestCommand("/npcmd cooldown "))
|
||||
.build()
|
||||
);
|
||||
builder.append(newline());
|
||||
builder.append(
|
||||
Component.text()
|
||||
.append(plugin.getLang().getMessage(Messages.LIST_PRICE))
|
||||
.append(text(plugin.getDataHandler().getPrice(npc)))
|
||||
.hoverEvent(showText(plugin.getLang().getMessage(Messages.LIST_TOOLTIP)))
|
||||
.clickEvent(suggestCommand("/npcmd price "))
|
||||
.build()
|
||||
);
|
||||
.append(plugin.getLang().getMessage(Messages.LIST_PRICE))
|
||||
.append(text(plugin.getDataHandler().getPrice(npc)))
|
||||
.hoverEvent(showText(plugin.getLang().getMessage(Messages.LIST_TOOLTIP)))
|
||||
.clickEvent(suggestCommand("/npcmd price "))
|
||||
.build()
|
||||
);
|
||||
builder.append(newline());
|
||||
builder.append(newline());
|
||||
builder.append(plugin.getLang().getMessage(Messages.LIST_COUNT_RIGHT, "{count}", String.valueOf(rightCommands.size())));
|
||||
builder.append(newline());
|
||||
|
||||
int rightCount = 1;
|
||||
for (String command : rightCommands) {
|
||||
for (final String command : rightCommands) {
|
||||
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()
|
||||
);
|
||||
.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++;
|
||||
}
|
||||
@ -88,14 +89,14 @@ public class ListCommand extends Npcmd {
|
||||
builder.append(plugin.getLang().getMessage(Messages.LIST_COUNT_LEFT, "{count}", String.valueOf(leftCommands.size())));
|
||||
|
||||
int leftCount = 1;
|
||||
for (String command : leftCommands) {
|
||||
for (final String command : leftCommands) {
|
||||
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()
|
||||
);
|
||||
.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++;
|
||||
}
|
||||
|
@ -1,18 +1,19 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.SubCommand;
|
||||
import dev.triumphteam.cmd.core.annotation.Suggestion;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
public class PermissionCommand extends Npcmd {
|
||||
|
||||
@ -28,7 +29,7 @@ public class PermissionCommand extends Npcmd {
|
||||
final CommandSender sender,
|
||||
@Suggestion("set") final String set,
|
||||
final String permission
|
||||
) {
|
||||
) {
|
||||
final OptionalInt selectedNpc = getSelectedNpcId(sender);
|
||||
|
||||
final Audience audience = plugin.getAudiences().sender(sender);
|
||||
|
@ -1,16 +1,17 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
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 net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
public class PriceCommand extends Npcmd {
|
||||
|
||||
|
@ -1,5 +1,9 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.SubCommand;
|
||||
@ -8,9 +12,6 @@ import me.mattstudios.citizenscmd.Settings;
|
||||
import me.mattstudios.citizenscmd.utility.DisplayFormat;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
|
||||
public class ReloadCommand extends Npcmd {
|
||||
|
||||
|
@ -1,5 +1,13 @@
|
||||
package me.mattstudios.citizenscmd.commands;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import dev.triumphteam.cmd.bukkit.annotation.Permission;
|
||||
import dev.triumphteam.cmd.core.annotation.SubCommand;
|
||||
import dev.triumphteam.cmd.core.annotation.Suggestion;
|
||||
@ -7,13 +15,6 @@ import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getSelectedNpcId;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.sendNotSelectedMessage;
|
||||
|
||||
public class RemoveCommand extends Npcmd {
|
||||
|
||||
@ -39,7 +40,7 @@ public class RemoveCommand extends Npcmd {
|
||||
|
||||
switch (clickString.toLowerCase()) {
|
||||
case "left":
|
||||
int leftCommandSize = plugin.getDataHandler().getClickCommandsData(selectedNpc.getAsInt(), EnumTypes.ClickType.LEFT).size();
|
||||
final int leftCommandSize = plugin.getDataHandler().getClickCommandsData(selectedNpc.getAsInt(), EnumTypes.ClickType.LEFT).size();
|
||||
|
||||
if (leftCommandSize == 0) {
|
||||
audience.sendMessage(HEADER);
|
||||
@ -57,7 +58,7 @@ public class RemoveCommand extends Npcmd {
|
||||
break;
|
||||
|
||||
case "right":
|
||||
int rightCommandSize = plugin.getDataHandler().getClickCommandsData(selectedNpc.getAsInt(), EnumTypes.ClickType.RIGHT).size();
|
||||
final int rightCommandSize = plugin.getDataHandler().getClickCommandsData(selectedNpc.getAsInt(), EnumTypes.ClickType.RIGHT).size();
|
||||
|
||||
if (rightCommandSize == 0) {
|
||||
audience.sendMessage(HEADER);
|
||||
|
@ -18,11 +18,8 @@
|
||||
|
||||
package me.mattstudios.citizenscmd.files;
|
||||
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.Util;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.info;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -30,12 +27,16 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.info;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.Util;
|
||||
|
||||
public class CooldownHandler {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private final CitizensCMD plugin;
|
||||
private File cooldownsFile;
|
||||
private File dir;
|
||||
|
||||
@ -51,7 +52,7 @@ public class CooldownHandler {
|
||||
* Creates the basic of the class and starts the HashMap
|
||||
*/
|
||||
public void initialize() {
|
||||
File pluginFolder = plugin.getDataFolder();
|
||||
final File pluginFolder = plugin.getDataFolder();
|
||||
dir = new File(pluginFolder + "/data");
|
||||
cooldownsFile = new File(dir.getPath(), "cooldowns.yml");
|
||||
cooldownsConfigurator = new YamlConfiguration();
|
||||
@ -65,12 +66,14 @@ public class CooldownHandler {
|
||||
* Creates files and folders
|
||||
*/
|
||||
private void createBasics() {
|
||||
if (!dir.exists()) dir.mkdirs();
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
if (!cooldownsFile.exists()) {
|
||||
try {
|
||||
cooldownsFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
info(color("&cError creating cooldowns file.."));
|
||||
}
|
||||
}
|
||||
@ -83,16 +86,18 @@ public class CooldownHandler {
|
||||
try {
|
||||
cooldownsConfigurator.load(cooldownsFile);
|
||||
|
||||
if (!cooldownsConfigurator.contains("cooldown-data")) return;
|
||||
if (!cooldownsConfigurator.contains("cooldown-data")) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Integer> cachedDataFromSaves = plugin.getDataHandler().getCachedCooldownByID();
|
||||
final Map<String, Integer> cachedDataFromSaves = plugin.getDataHandler().getCachedCooldownByID();
|
||||
|
||||
for (String parent : Objects.requireNonNull(cooldownsConfigurator.getConfigurationSection("cooldown-data")).getKeys(false)) {
|
||||
for (String child : Objects.requireNonNull(cooldownsConfigurator.getConfigurationSection("cooldown-data." + parent)).getKeys(false)) {
|
||||
for (String npc : cachedDataFromSaves.keySet()) {
|
||||
if (npc.equalsIgnoreCase(parent) && ((Util.getSecondsDifference(cooldownsConfigurator.getLong("cooldown-data." + parent + "." + child)) < cachedDataFromSaves.get(npc)) || cachedDataFromSaves.get(npc) == -1))
|
||||
for (final String parent : Objects.requireNonNull(cooldownsConfigurator.getConfigurationSection("cooldown-data")).getKeys(false)) {
|
||||
for (final String child : Objects.requireNonNull(cooldownsConfigurator.getConfigurationSection("cooldown-data." + parent)).getKeys(false)) {
|
||||
for (final String npc : cachedDataFromSaves.keySet()) {
|
||||
if (npc.equalsIgnoreCase(parent) && ((Util.getSecondsDifference(cooldownsConfigurator.getLong("cooldown-data." + parent + "." + child)) < cachedDataFromSaves.get(npc)) || cachedDataFromSaves.get(npc) == -1)) {
|
||||
cooldownData.put("cooldown-data." + parent + "." + child, cooldownsConfigurator.getLong("cooldown-data." + parent + "." + child));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -111,7 +116,7 @@ public class CooldownHandler {
|
||||
|
||||
cooldownsConfigurator.set("cooldown-data", null);
|
||||
|
||||
for (String path : cooldownData.keySet()) {
|
||||
for (final String path : cooldownData.keySet()) {
|
||||
cooldownsConfigurator.set(path, cooldownData.get(path));
|
||||
}
|
||||
|
||||
@ -129,10 +134,11 @@ public class CooldownHandler {
|
||||
* @param time the time it was clicked from System.nanoTime();
|
||||
*/
|
||||
public void addInteraction(int npc, String uuid, long time) {
|
||||
if (cooldownData.containsKey("cooldown-data.npc-" + npc + "." + uuid))
|
||||
if (cooldownData.containsKey("cooldown-data.npc-" + npc + "." + uuid)) {
|
||||
cooldownData.replace("cooldown-data.npc-" + npc + "." + uuid, time);
|
||||
else
|
||||
} else {
|
||||
cooldownData.put("cooldown-data.npc-" + npc + "." + uuid, time);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,10 +161,11 @@ public class CooldownHandler {
|
||||
*/
|
||||
public boolean onCooldown(int npc, String uuid) {
|
||||
if (cooldownData.containsKey("cooldown-data.npc-" + npc + "." + uuid)) {
|
||||
if (plugin.getDataHandler().getNPCCooldown(npc) == -1)
|
||||
if (plugin.getDataHandler().getNPCCooldown(npc) == -1) {
|
||||
return true;
|
||||
else
|
||||
} else {
|
||||
return Util.getSecondsDifference(cooldownData.get("cooldown-data.npc-" + npc + "." + uuid)) < plugin.getDataHandler().getNPCCooldown(npc);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -18,15 +18,9 @@
|
||||
|
||||
package me.mattstudios.citizenscmd.files;
|
||||
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import me.mattstudios.citizenscmd.utility.Util;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.info;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -37,9 +31,16 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.color;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.info;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.EnumTypes;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import me.mattstudios.citizenscmd.utility.Util;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class DataHandler {
|
||||
@ -60,7 +61,7 @@ public class DataHandler {
|
||||
* Creates file and folder
|
||||
*/
|
||||
public void initialize() {
|
||||
File pluginFolder = plugin.getDataFolder();
|
||||
final File pluginFolder = plugin.getDataFolder();
|
||||
dir = new File(pluginFolder + "/data");
|
||||
savesFile = new File(dir.getPath(), "saves.yml");
|
||||
dataConfigurator = new YamlConfiguration();
|
||||
@ -73,12 +74,14 @@ public class DataHandler {
|
||||
* Creates files and folders
|
||||
*/
|
||||
private void createBasics() {
|
||||
if (!dir.exists()) dir.mkdirs();
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
if (!savesFile.exists()) {
|
||||
try {
|
||||
savesFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
info(color("&cError creating saves file.."));
|
||||
}
|
||||
}
|
||||
@ -92,10 +95,12 @@ public class DataHandler {
|
||||
try {
|
||||
dataConfigurator.load(savesFile);
|
||||
|
||||
if (!dataConfigurator.contains("npc-data")) return;
|
||||
if (!dataConfigurator.contains("npc-data")) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String parent : Objects.requireNonNull(dataConfigurator.getConfigurationSection("npc-data")).getKeys(false)) {
|
||||
for (String child : Objects.requireNonNull(dataConfigurator.getConfigurationSection("npc-data." + parent)).getKeys(false)) {
|
||||
for (final String parent : Objects.requireNonNull(dataConfigurator.getConfigurationSection("npc-data")).getKeys(false)) {
|
||||
for (final String child : Objects.requireNonNull(dataConfigurator.getConfigurationSection("npc-data." + parent)).getKeys(false)) {
|
||||
switch (child.toLowerCase()) {
|
||||
case "permission":
|
||||
data.put("npc-data." + parent + "." + child, dataConfigurator.getString("npc-data." + parent + "." + child));
|
||||
@ -140,27 +145,32 @@ public class DataHandler {
|
||||
createBasics();
|
||||
dataConfigurator.load(savesFile);
|
||||
|
||||
List<String> commandList = data.containsKey("npc-data.npc-" + npc + ".right-click-commands") ? (List<String>) data.get("npc-data.npc-" + npc + ".right-click-commands") : new ArrayList<>();
|
||||
List<String> commandListLeft = data.containsKey("npc-data.npc-" + npc + ".left-click-commands") ? (List<String>) data.get("npc-data.npc-" + npc + ".left-click-commands") : new ArrayList<>();
|
||||
final List<String> commandList = data.containsKey("npc-data.npc-" + npc + ".right-click-commands") ? (List<String>) data.get("npc-data.npc-" + npc + ".right-click-commands") : new ArrayList<>();
|
||||
final List<String> commandListLeft = data.containsKey("npc-data.npc-" + npc + ".left-click-commands") ? (List<String>) data.get("npc-data.npc-" + npc + ".left-click-commands") : new ArrayList<>();
|
||||
|
||||
if (!data.containsKey("npc-data.npc-" + npc + ".cooldown")) {
|
||||
data.put("npc-data.npc-" + npc + ".cooldown", Util.getDefaultCooldown(plugin));
|
||||
dataConfigurator.set("npc-data.npc-" + npc + ".cooldown", Util.getDefaultCooldown(plugin));
|
||||
}
|
||||
|
||||
if (left) commandListLeft.add("[" + permission + "] " + command);
|
||||
else commandList.add("[" + permission + "] " + command);
|
||||
if (left) {
|
||||
commandListLeft.add("[" + permission + "] " + command);
|
||||
} else {
|
||||
commandList.add("[" + permission + "] " + command);
|
||||
}
|
||||
|
||||
if (data.containsKey("npc-data.npc-" + npc + ".right-click-commands"))
|
||||
if (data.containsKey("npc-data.npc-" + npc + ".right-click-commands")) {
|
||||
data.replace("npc-data.npc-" + npc + ".right-click-commands", commandList);
|
||||
else
|
||||
} else {
|
||||
data.put("npc-data.npc-" + npc + ".right-click-commands", commandList);
|
||||
}
|
||||
dataConfigurator.set("npc-data.npc-" + npc + ".right-click-commands", commandList);
|
||||
|
||||
if (data.containsKey("npc-data.npc-" + npc + ".left-click-commands"))
|
||||
if (data.containsKey("npc-data.npc-" + npc + ".left-click-commands")) {
|
||||
data.replace("npc-data.npc-" + npc + ".left-click-commands", commandListLeft);
|
||||
else
|
||||
} else {
|
||||
data.put("npc-data.npc-" + npc + ".left-click-commands", commandListLeft);
|
||||
}
|
||||
dataConfigurator.set("npc-data.npc-" + npc + ".left-click-commands", commandListLeft);
|
||||
|
||||
if (!data.containsKey("npc-data.npc-" + npc + ".price")) {
|
||||
@ -193,27 +203,32 @@ public class DataHandler {
|
||||
createBasics();
|
||||
dataConfigurator.load(savesFile);
|
||||
|
||||
List<String> commandList = data.containsKey("npc-data.npc-" + npc + ".right-click-commands") ? (List<String>) data.get("npc-data.npc-" + npc + ".right-click-commands") : new ArrayList<>();
|
||||
List<String> commandListLeft = data.containsKey("npc-data.npc-" + npc + ".left-click-commands") ? (List<String>) data.get("npc-data.npc-" + npc + ".left-click-commands") : new ArrayList<>();
|
||||
final List<String> commandList = data.containsKey("npc-data.npc-" + npc + ".right-click-commands") ? (List<String>) data.get("npc-data.npc-" + npc + ".right-click-commands") : new ArrayList<>();
|
||||
final List<String> commandListLeft = data.containsKey("npc-data.npc-" + npc + ".left-click-commands") ? (List<String>) data.get("npc-data.npc-" + npc + ".left-click-commands") : new ArrayList<>();
|
||||
|
||||
if (!data.containsKey("npc-data.npc-" + npc + ".cooldown")) {
|
||||
data.put("npc-data.npc-" + npc + ".cooldown", Util.getDefaultCooldown(plugin));
|
||||
dataConfigurator.set("npc-data.npc-" + npc + ".cooldown", Util.getDefaultCooldown(plugin));
|
||||
}
|
||||
|
||||
if (left) commandListLeft.add("[" + permission + "] " + command);
|
||||
else commandList.add("[" + permission + "] " + command);
|
||||
if (left) {
|
||||
commandListLeft.add("[" + permission + "] " + command);
|
||||
} else {
|
||||
commandList.add("[" + permission + "] " + command);
|
||||
}
|
||||
|
||||
if (data.containsKey("npc-data.npc-" + npc + ".right-click-commands"))
|
||||
if (data.containsKey("npc-data.npc-" + npc + ".right-click-commands")) {
|
||||
data.replace("npc-data.npc-" + npc + ".right-click-commands", commandList);
|
||||
else
|
||||
} else {
|
||||
data.put("npc-data.npc-" + npc + ".right-click-commands", commandList);
|
||||
}
|
||||
dataConfigurator.set("npc-data.npc-" + npc + ".right-click-commands", commandList);
|
||||
|
||||
if (data.containsKey("npc-data.npc-" + npc + ".left-click-commands"))
|
||||
if (data.containsKey("npc-data.npc-" + npc + ".left-click-commands")) {
|
||||
data.replace("npc-data.npc-" + npc + ".left-click-commands", commandListLeft);
|
||||
else
|
||||
} else {
|
||||
data.put("npc-data.npc-" + npc + ".left-click-commands", commandListLeft);
|
||||
}
|
||||
dataConfigurator.set("npc-data.npc-" + npc + ".left-click-commands", commandListLeft);
|
||||
|
||||
if (!data.containsKey("npc-data.npc-" + npc + ".price")) {
|
||||
@ -321,8 +336,9 @@ public class DataHandler {
|
||||
createBasics();
|
||||
dataConfigurator.load(savesFile);
|
||||
|
||||
if (dataConfigurator.contains("npc-data.npc-" + npc + ".permission"))
|
||||
if (dataConfigurator.contains("npc-data.npc-" + npc + ".permission")) {
|
||||
dataConfigurator.set("npc-data.npc-" + npc + ".permission", null);
|
||||
}
|
||||
|
||||
data.remove("npc-data.npc-" + npc + ".permission");
|
||||
|
||||
@ -363,10 +379,11 @@ public class DataHandler {
|
||||
* @return Returns arrays with strings to show on tab completion event
|
||||
*/
|
||||
public String[] getCompleteCommandsNumbers(int npc, EnumTypes.ClickType click) {
|
||||
List<String> commandList = (List<String>) data.get("npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands");
|
||||
String[] commandSet = new String[commandList.size()];
|
||||
for (int i = 0; i < commandList.size(); i++)
|
||||
final List<String> commandList = (List<String>) data.get("npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands");
|
||||
final String[] commandSet = new String[commandList.size()];
|
||||
for (int i = 0; i < commandList.size(); i++) {
|
||||
commandSet[i] = "" + (i + 1);
|
||||
}
|
||||
return commandSet;
|
||||
}
|
||||
|
||||
@ -378,9 +395,10 @@ public class DataHandler {
|
||||
* @return Returns true if has and false if not
|
||||
*/
|
||||
public boolean hasNoCommands(int npc, EnumTypes.ClickType click) {
|
||||
String key = "npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands";
|
||||
if (data.containsKey(key))
|
||||
final String key = "npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands";
|
||||
if (data.containsKey(key)) {
|
||||
return ((List<String>) data.get(key)).isEmpty();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -391,8 +409,10 @@ public class DataHandler {
|
||||
* @return True or false depending if it has or not.
|
||||
*/
|
||||
public boolean hasNPCData(int npc) {
|
||||
for (String key : data.keySet()) {
|
||||
if (key.contains("npc-" + npc)) return true;
|
||||
for (final String key : data.keySet()) {
|
||||
if (key.contains("npc-" + npc)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -431,11 +451,11 @@ public class DataHandler {
|
||||
createBasics();
|
||||
dataConfigurator.load(savesFile);
|
||||
|
||||
List<String> commands = getClickCommandsData(npc, click);
|
||||
final List<String> commands = getClickCommandsData(npc, click);
|
||||
|
||||
commands.remove(commandID - 1);
|
||||
|
||||
String key = "npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands";
|
||||
final String key = "npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands";
|
||||
data.replace(key, commands);
|
||||
dataConfigurator.set(key, commands);
|
||||
|
||||
@ -465,7 +485,7 @@ public class DataHandler {
|
||||
createBasics();
|
||||
dataConfigurator.load(savesFile);
|
||||
|
||||
List<String> commandsData = getClickCommandsData(npc, click);
|
||||
final List<String> commandsData = getClickCommandsData(npc, click);
|
||||
|
||||
final String typeText;
|
||||
switch (type) {
|
||||
@ -485,7 +505,7 @@ public class DataHandler {
|
||||
typeText = "";
|
||||
}
|
||||
|
||||
String key = "npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands";
|
||||
final String key = "npc-data.npc-" + npc + "." + click.toString().toLowerCase() + "-click-commands";
|
||||
data.replace(key, commandsData);
|
||||
dataConfigurator.set(key, commandsData);
|
||||
|
||||
@ -510,7 +530,9 @@ public class DataHandler {
|
||||
createBasics();
|
||||
dataConfigurator.load(savesFile);
|
||||
|
||||
if (dataConfigurator.contains("npc-data.npc-" + npc)) dataConfigurator.set("npc-data.npc-" + npc, null);
|
||||
if (dataConfigurator.contains("npc-data.npc-" + npc)) {
|
||||
dataConfigurator.set("npc-data.npc-" + npc, null);
|
||||
}
|
||||
|
||||
data.keySet().removeIf(key -> key.contains("npc-data.npc-" + npc));
|
||||
|
||||
@ -533,11 +555,11 @@ public class DataHandler {
|
||||
createBasics();
|
||||
dataConfigurator.load(savesFile);
|
||||
|
||||
Map<String, Object> newNpcData = new HashMap<>();
|
||||
final Map<String, Object> newNpcData = new HashMap<>();
|
||||
|
||||
for (String key : data.keySet()) {
|
||||
for (final String key : data.keySet()) {
|
||||
if (key.contains("npc-" + npc)) {
|
||||
String newKey = key.replace("npc-" + npc, "npc-" + npcClone);
|
||||
final String newKey = key.replace("npc-" + npc, "npc-" + npcClone);
|
||||
newNpcData.put(newKey, data.get(key));
|
||||
dataConfigurator.set(newKey, data.get(key));
|
||||
}
|
||||
@ -557,12 +579,13 @@ public class DataHandler {
|
||||
* @return The cached cooldowns
|
||||
*/
|
||||
Map<String, Integer> getCachedCooldownByID() {
|
||||
Map<String, Integer> cachedData = new HashMap<>();
|
||||
final Map<String, Integer> cachedData = new HashMap<>();
|
||||
|
||||
for (String key : data.keySet()) {
|
||||
String[] components = key.split("\\.");
|
||||
if (components[2].equalsIgnoreCase("cooldown"))
|
||||
for (final String key : data.keySet()) {
|
||||
final String[] components = key.split("\\.");
|
||||
if (components[2].equalsIgnoreCase("cooldown")) {
|
||||
cachedData.put(components[1], (Integer) data.get(key));
|
||||
}
|
||||
}
|
||||
return cachedData;
|
||||
}
|
||||
|
@ -18,14 +18,8 @@
|
||||
|
||||
package me.mattstudios.citizenscmd.files;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.Settings;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.LEGACY;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.MINI;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -35,8 +29,15 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.LEGACY;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.MINI;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.Settings;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class LangHandler {
|
||||
|
||||
@ -58,8 +59,8 @@ public class LangHandler {
|
||||
*/
|
||||
private void cacheMessage() {
|
||||
try {
|
||||
File langFile = new File(plugin.getDataFolder(), "lang/" + lang + ".yml");
|
||||
FileConfiguration langConf = new YamlConfiguration();
|
||||
final File langFile = new File(plugin.getDataFolder(), "lang/" + lang + ".yml");
|
||||
final FileConfiguration langConf = new YamlConfiguration();
|
||||
// InputStream langStream = CitizensCMD.class.getClassLoader().getResourceAsStream("lang/" + lang + ".yml");
|
||||
|
||||
if (!langFile.exists()) {
|
||||
@ -68,8 +69,8 @@ public class LangHandler {
|
||||
|
||||
langConf.load(langFile);
|
||||
|
||||
for (String parent : Objects.requireNonNull(langConf.getConfigurationSection("messages")).getKeys(false)) {
|
||||
for (String child : Objects.requireNonNull(langConf.getConfigurationSection("messages." + parent)).getKeys(false)) {
|
||||
for (final String parent : Objects.requireNonNull(langConf.getConfigurationSection("messages")).getKeys(false)) {
|
||||
for (final String child : Objects.requireNonNull(langConf.getConfigurationSection("messages." + parent)).getKeys(false)) {
|
||||
messages.put("messages." + parent + "." + child, langConf.getString("messages." + parent + "." + child));
|
||||
}
|
||||
}
|
||||
@ -98,7 +99,9 @@ public class LangHandler {
|
||||
value = value.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
if (settings.getProperty(Settings.MINIMESSAGE_LANG)) return MINI.deserialize(value);
|
||||
if (settings.getProperty(Settings.MINIMESSAGE_LANG)) {
|
||||
return MINI.deserialize(value);
|
||||
}
|
||||
return LEGACY.deserialize(value);
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,28 @@
|
||||
|
||||
package me.mattstudios.citizenscmd.listeners;
|
||||
|
||||
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 org.bukkit.Bukkit.getScheduler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.google.common.primitives.Floats;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.Settings;
|
||||
@ -32,25 +53,6 @@ import net.citizensnpcs.api.event.NPCRightClickEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.LEGACY;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.MINI;
|
||||
import static me.mattstudios.citizenscmd.utility.Util.getFormattedTime;
|
||||
import static org.bukkit.Bukkit.getScheduler;
|
||||
|
||||
public class NPCClickListener implements Listener {
|
||||
|
||||
@ -67,14 +69,18 @@ public class NPCClickListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onRightClick(NPCRightClickEvent event) {
|
||||
NPC npc = event.getNPC();
|
||||
Player player = event.getClicker();
|
||||
final NPC npc = event.getNPC();
|
||||
final Player player = event.getClicker();
|
||||
final Audience audience = plugin.getAudiences().player(player);
|
||||
|
||||
if (!player.hasPermission("citizenscmd.use")) return;
|
||||
if (!player.hasPermission("citizenscmd.use")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getDataHandler().hasCustomPermission(npc.getId())) {
|
||||
if (!player.hasPermission(plugin.getDataHandler().getCustomPermission(npc.getId()))) return;
|
||||
if (!player.hasPermission(plugin.getDataHandler().getCustomPermission(npc.getId()))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!plugin.getWaitingList().containsKey(player.getUniqueId() + "." + npc.getId())) {
|
||||
@ -93,10 +99,12 @@ public class NPCClickListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.getDataHandler().hasNoCommands(npc.getId(), EnumTypes.ClickType.RIGHT)) return;
|
||||
if (plugin.getDataHandler().hasNoCommands(npc.getId(), EnumTypes.ClickType.RIGHT)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
double price = plugin.getDataHandler().getPrice(npc.getId());
|
||||
final double price = plugin.getDataHandler().getPrice(npc.getId());
|
||||
|
||||
if (price > 0.0) {
|
||||
if (CitizensCMD.getEconomy() != null) {
|
||||
@ -105,8 +113,11 @@ public class NPCClickListener implements Listener {
|
||||
final Map<String, String> replacements = new HashMap<>();
|
||||
replacements.put("{price}", String.valueOf(price));
|
||||
|
||||
if (!plugin.isShift()) replacements.put("{shift}", "");
|
||||
else replacements.put("{shift}", "Shift ");
|
||||
if (!plugin.isShift()) {
|
||||
replacements.put("{shift}", "");
|
||||
} else {
|
||||
replacements.put("{shift}", "Shift ");
|
||||
}
|
||||
|
||||
final Component messageConfirm = plugin.getLang().getMessage(Messages.PAY_CONFIRM, replacements);
|
||||
|
||||
@ -141,14 +152,18 @@ public class NPCClickListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onLeftClick(NPCLeftClickEvent event) {
|
||||
NPC npc = event.getNPC();
|
||||
Player player = event.getClicker();
|
||||
final NPC npc = event.getNPC();
|
||||
final Player player = event.getClicker();
|
||||
final Audience audience = plugin.getAudiences().player(player);
|
||||
|
||||
if (!player.hasPermission("citizenscmd.use")) return;
|
||||
if (!player.hasPermission("citizenscmd.use")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getDataHandler().hasCustomPermission(npc.getId())) {
|
||||
if (!player.hasPermission(plugin.getDataHandler().getCustomPermission(npc.getId()))) return;
|
||||
if (!player.hasPermission(plugin.getDataHandler().getCustomPermission(npc.getId()))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!plugin.getWaitingList().containsKey(player.getUniqueId() + "." + npc.getId())) {
|
||||
@ -168,10 +183,12 @@ public class NPCClickListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.getDataHandler().hasNoCommands(npc.getId(), EnumTypes.ClickType.LEFT)) return;
|
||||
if (plugin.getDataHandler().hasNoCommands(npc.getId(), EnumTypes.ClickType.LEFT)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
double price = plugin.getDataHandler().getPrice(npc.getId());
|
||||
final double price = plugin.getDataHandler().getPrice(npc.getId());
|
||||
|
||||
if (price > 0.0) {
|
||||
if (CitizensCMD.getEconomy() != null) {
|
||||
@ -180,8 +197,11 @@ public class NPCClickListener implements Listener {
|
||||
final Map<String, String> replacements = new HashMap<>();
|
||||
replacements.put("{price}", String.valueOf(price));
|
||||
|
||||
if (!plugin.isShift()) replacements.put("{shift}", "");
|
||||
else replacements.put("{shift}", "Shift ");
|
||||
if (!plugin.isShift()) {
|
||||
replacements.put("{shift}", "");
|
||||
} else {
|
||||
replacements.put("{shift}", "Shift ");
|
||||
}
|
||||
|
||||
final Component messageConfirm = plugin.getLang().getMessage(Messages.PAY_CONFIRM, replacements);
|
||||
|
||||
@ -191,7 +211,9 @@ public class NPCClickListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.isShift() && !player.isSneaking()) return;
|
||||
if (plugin.isShift() && !player.isSneaking()) {
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getWaitingList().remove(player.getUniqueId() + "." + npc.getId());
|
||||
audience.sendMessage(plugin.getLang().getMessage(Messages.PAY_CANCELED));
|
||||
@ -208,7 +230,9 @@ public class NPCClickListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onRemoveNPC(NPCRemoveEvent event) {
|
||||
if (!plugin.getDataHandler().hasNPCData(event.getNPC().getId())) return;
|
||||
if (!plugin.getDataHandler().hasNPCData(event.getNPC().getId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDataHandler().removeNPCData(event.getNPC().getId());
|
||||
}
|
||||
@ -221,11 +245,11 @@ public class NPCClickListener implements Listener {
|
||||
* @param clickType The type of click, either left or right.
|
||||
*/
|
||||
private void doCommands(NPC npc, Player player, EnumTypes.ClickType clickType) {
|
||||
List<String> permissions = new ArrayList<>();
|
||||
List<String> commands = new ArrayList<>();
|
||||
final List<String> permissions = new ArrayList<>();
|
||||
final List<String> commands = new ArrayList<>();
|
||||
|
||||
for (String list : plugin.getDataHandler().getClickCommandsData(npc.getId(), clickType)) {
|
||||
Matcher matcher = MAIN_PATTERN.matcher(list);
|
||||
for (final String list : plugin.getDataHandler().getClickCommandsData(npc.getId(), clickType)) {
|
||||
final Matcher matcher = MAIN_PATTERN.matcher(list);
|
||||
if (matcher.find()) {
|
||||
|
||||
permissions.add(matcher.group(1));
|
||||
@ -242,22 +266,24 @@ public class NPCClickListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (permissions.size() != commands.size()) return;
|
||||
if (permissions.size() != commands.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < permissions.size(); i++) {
|
||||
|
||||
double delay = 0;
|
||||
|
||||
if (permissions.get(i).contains("(")) {
|
||||
Matcher matcher = PERMISSION_PATTERN.matcher(permissions.get(i));
|
||||
final Matcher matcher = PERMISSION_PATTERN.matcher(permissions.get(i));
|
||||
if (matcher.find()) {
|
||||
delay = Double.parseDouble(matcher.group(2));
|
||||
String permission = matcher.group(1);
|
||||
final String permission = matcher.group(1);
|
||||
permissions.set(i, permission);
|
||||
}
|
||||
}
|
||||
|
||||
int finalI = i;
|
||||
final int finalI = i;
|
||||
switch (permissions.get(i).toLowerCase()) {
|
||||
case "console":
|
||||
getScheduler().runTaskLater(plugin, () -> plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), commands.get(finalI)), (int) delay * 20);
|
||||
@ -299,17 +325,21 @@ public class NPCClickListener implements Listener {
|
||||
if (matcher.find()) {
|
||||
sound = matcher.group("sound");
|
||||
|
||||
String volumeString = matcher.group("volume");
|
||||
String pitchString = matcher.group("pitch");
|
||||
final String volumeString = matcher.group("volume");
|
||||
final String pitchString = matcher.group("pitch");
|
||||
|
||||
if (volumeString != null) {
|
||||
final Float nullableVolume = Floats.tryParse(volumeString);
|
||||
if (nullableVolume != null) volume = nullableVolume;
|
||||
if (nullableVolume != null) {
|
||||
volume = nullableVolume;
|
||||
}
|
||||
}
|
||||
|
||||
if (pitchString != null) {
|
||||
final Float nullablePitch = Floats.tryParse(pitchString);
|
||||
if (nullablePitch != null) volume = nullablePitch;
|
||||
if (nullablePitch != null) {
|
||||
volume = nullablePitch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,15 @@
|
||||
package me.mattstudios.citizenscmd.listeners;
|
||||
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import net.citizensnpcs.api.event.NPCCloneEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import net.citizensnpcs.api.event.NPCCloneEvent;
|
||||
|
||||
public class NPCListener implements Listener {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private final CitizensCMD plugin;
|
||||
|
||||
public NPCListener(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -16,7 +17,9 @@ public class NPCListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void on(NPCCloneEvent event) {
|
||||
if (!plugin.getDataHandler().hasNPCData(event.getNPC().getId())) return;
|
||||
if (!plugin.getDataHandler().hasNPCData(event.getNPC().getId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDataHandler().cloneData(event.getNPC().getId(), event.getClone().getId());
|
||||
}
|
||||
|
@ -18,20 +18,21 @@
|
||||
|
||||
package me.mattstudios.citizenscmd.listeners;
|
||||
|
||||
import static me.mattstudios.citizenscmd.utility.Util.HEADER;
|
||||
import static net.kyori.adventure.text.Component.newline;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import static me.mattstudios.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 {
|
||||
|
||||
@ -43,7 +44,9 @@ public class UpdateEvent implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (!plugin.isUpdateStatus() || !event.getPlayer().hasPermission("citizenscmd.update")) return;
|
||||
if (!plugin.isUpdateStatus() || !event.getPlayer().hasPermission("citizenscmd.update")) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Audience audience = plugin.getAudiences().player(event.getPlayer());
|
||||
|
||||
@ -54,11 +57,11 @@ public class UpdateEvent implements Listener {
|
||||
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()
|
||||
);
|
||||
.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());
|
||||
}
|
||||
|
@ -19,17 +19,18 @@
|
||||
package me.mattstudios.citizenscmd.permissions;
|
||||
|
||||
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
|
||||
public class PermissionsManager {
|
||||
|
||||
private HashMap<UUID, PermissionAttachment> permissionsData;
|
||||
private CitizensCMD plugin;
|
||||
private final HashMap<UUID, PermissionAttachment> permissionsData;
|
||||
private final CitizensCMD plugin;
|
||||
|
||||
public PermissionsManager(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -43,9 +44,9 @@ public class PermissionsManager {
|
||||
* @param permission The permission node
|
||||
*/
|
||||
public void setPermission(Player player, String permission) {
|
||||
PermissionAttachment permissionAttachment = player.addAttachment(plugin);
|
||||
final PermissionAttachment permissionAttachment = player.addAttachment(plugin);
|
||||
permissionsData.put(player.getUniqueId(), permissionAttachment);
|
||||
PermissionAttachment permissionAttachment1 = permissionsData.get(player.getUniqueId());
|
||||
final PermissionAttachment permissionAttachment1 = permissionsData.get(player.getUniqueId());
|
||||
permissionAttachment1.setPermission(permission, true);
|
||||
}
|
||||
|
||||
|
@ -18,11 +18,12 @@
|
||||
|
||||
package me.mattstudios.citizenscmd.schedulers;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.utility.Messages;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class ConfirmScheduler extends BukkitRunnable {
|
||||
|
||||
|
@ -18,9 +18,10 @@
|
||||
|
||||
package me.mattstudios.citizenscmd.schedulers;
|
||||
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
|
||||
public class CooldownScheduler extends BukkitRunnable {
|
||||
|
||||
private final CitizensCMD plugin;
|
||||
|
@ -18,14 +18,15 @@
|
||||
|
||||
package me.mattstudios.citizenscmd.schedulers;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.Settings;
|
||||
import me.mattstudios.citizenscmd.updater.SpigotUpdater;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class UpdateScheduler extends BukkitRunnable {
|
||||
|
||||
private CitizensCMD plugin;
|
||||
private final CitizensCMD plugin;
|
||||
|
||||
public UpdateScheduler(CitizensCMD plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -36,15 +37,17 @@ public class UpdateScheduler extends BukkitRunnable {
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugin.getSettings().getProperty(Settings.CHECK_UPDATES)) return;
|
||||
if (plugin.getSettings().getProperty(Settings.CHECK_UPDATES)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SpigotUpdater updater = new SpigotUpdater(plugin, 30224);
|
||||
final SpigotUpdater updater = new SpigotUpdater(plugin, 30224);
|
||||
try {
|
||||
if (updater.checkForUpdates()) {
|
||||
plugin.setUpdateStatus(true);
|
||||
plugin.setNewVersion(updater.getLatestVersion());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package me.mattstudios.citizenscmd.updater;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
/**
|
||||
* Created by GlareMasters on 5/30/2018.
|
||||
*/
|
||||
@ -24,7 +24,7 @@ public class SpigotUpdater {
|
||||
this.project = projectID;
|
||||
try {
|
||||
this.checkURL = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + projectID);
|
||||
} catch (MalformedURLException ignored) {}
|
||||
} catch (final MalformedURLException ignored) {}
|
||||
}
|
||||
|
||||
public JavaPlugin getPlugin() {
|
||||
@ -38,7 +38,7 @@ public class SpigotUpdater {
|
||||
* @throws Exception I/O Exception
|
||||
*/
|
||||
public String getLatestVersion() throws Exception {
|
||||
URLConnection con = checkURL.openConnection();
|
||||
final URLConnection con = checkURL.openConnection();
|
||||
this.newVersion = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
|
||||
return newVersion;
|
||||
}
|
||||
@ -59,7 +59,7 @@ public class SpigotUpdater {
|
||||
* @throws Exception I/O Exception
|
||||
*/
|
||||
public boolean checkForUpdates() throws Exception {
|
||||
URLConnection con = checkURL.openConnection();
|
||||
final URLConnection con = checkURL.openConnection();
|
||||
this.newVersion = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
|
||||
return !plugin.getDescription().getVersion().equals(newVersion);
|
||||
}
|
||||
|
@ -18,23 +18,6 @@
|
||||
|
||||
package me.mattstudios.citizenscmd.utility;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.Settings;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
@ -45,6 +28,24 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import me.mattstudios.citizenscmd.CitizensCMD;
|
||||
import me.mattstudios.citizenscmd.Settings;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
public class Util {
|
||||
|
||||
private Util() {}
|
||||
@ -95,7 +96,9 @@ public class Util {
|
||||
*/
|
||||
public static OptionalInt getSelectedNpcId(final CommandSender sender) {
|
||||
final NPC npc = CitizensAPI.getDefaultNPCSelector().getSelected(sender);
|
||||
if (npc == null) return OptionalInt.empty();
|
||||
if (npc == null) {
|
||||
return OptionalInt.empty();
|
||||
}
|
||||
return OptionalInt.of(npc.getId());
|
||||
}
|
||||
|
||||
@ -168,12 +171,12 @@ public class Util {
|
||||
* @param server the server name
|
||||
*/
|
||||
public static void changeServer(CitizensCMD plugin, Player player, String server) {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
|
||||
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
final DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
|
||||
try {
|
||||
dataOutputStream.writeUTF("Connect");
|
||||
dataOutputStream.writeUTF(server);
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
player.sendPluginMessage(plugin, "BungeeCord", byteArrayOutputStream.toByteArray());
|
||||
@ -193,21 +196,21 @@ public class Util {
|
||||
String minutePlural = "";
|
||||
String secondPlural = "";
|
||||
|
||||
TimeUtil timeUtil = new TimeUtil(seconds);
|
||||
final TimeUtil timeUtil = new TimeUtil(seconds);
|
||||
|
||||
String[] messagesString = new String[4];
|
||||
final String[] messagesString = new String[4];
|
||||
messagesString[0] = plugin.getLang().getUncoloredMessage(Messages.SECONDS);
|
||||
messagesString[1] = plugin.getLang().getUncoloredMessage(Messages.MINUTES);
|
||||
messagesString[2] = plugin.getLang().getUncoloredMessage(Messages.HOURS);
|
||||
messagesString[3] = plugin.getLang().getUncoloredMessage(Messages.DAYS);
|
||||
|
||||
String[] shorts = new String[4];
|
||||
String[] mediums = new String[4];
|
||||
String[] fulls = new String[4];
|
||||
final String[] shorts = new String[4];
|
||||
final String[] mediums = new String[4];
|
||||
final String[] fulls = new String[4];
|
||||
|
||||
Pattern pattern = Pattern.compile("\\[([^]]*)], \\[([^]]*)], \\[([^]]*)]");
|
||||
final Pattern pattern = Pattern.compile("\\[([^]]*)], \\[([^]]*)], \\[([^]]*)]");
|
||||
for (int i = 0; i < messagesString.length; i++) {
|
||||
Matcher matcher = pattern.matcher(messagesString[i]);
|
||||
final Matcher matcher = pattern.matcher(messagesString[i]);
|
||||
if (matcher.find()) {
|
||||
shorts[i] = matcher.group(1);
|
||||
mediums[i] = matcher.group(2);
|
||||
@ -222,13 +225,13 @@ public class Util {
|
||||
|
||||
switch (format) {
|
||||
case MEDIUM:
|
||||
String[] mediumsAfter = new String[4];
|
||||
String[] mediumsPlurals = new String[4];
|
||||
Pattern patternMediums = Pattern.compile("([^]]*)\\(([^]]*)\\)");
|
||||
final String[] mediumsAfter = new String[4];
|
||||
final String[] mediumsPlurals = new String[4];
|
||||
final Pattern patternMediums = Pattern.compile("([^]]*)\\(([^]]*)\\)");
|
||||
|
||||
for (int i = 0; i < mediums.length; i++) {
|
||||
if (mediums[i].contains("(") && mediums[i].contains(")")) {
|
||||
Matcher matcher = patternMediums.matcher(mediums[i]);
|
||||
final Matcher matcher = patternMediums.matcher(mediums[i]);
|
||||
if (matcher.find()) {
|
||||
mediumsAfter[i] = matcher.group(1);
|
||||
mediumsPlurals[i] = matcher.group(2);
|
||||
@ -250,13 +253,13 @@ public class Util {
|
||||
break;
|
||||
|
||||
case FULL:
|
||||
String[] fullsAfter = new String[4];
|
||||
String[] fullsPlurals = new String[4];
|
||||
Pattern patternFulls = Pattern.compile("([^]]*)\\(([^]]*)\\)");
|
||||
final String[] fullsAfter = new String[4];
|
||||
final String[] fullsPlurals = new String[4];
|
||||
final Pattern patternFulls = Pattern.compile("([^]]*)\\(([^]]*)\\)");
|
||||
|
||||
for (int i = 0; i < fulls.length; i++) {
|
||||
if (fulls[i].contains("(") && fulls[i].contains(")")) {
|
||||
Matcher matcher = patternFulls.matcher(fulls[i]);
|
||||
final Matcher matcher = patternFulls.matcher(fulls[i]);
|
||||
if (matcher.find()) {
|
||||
fullsAfter[i] = matcher.group(1);
|
||||
fullsPlurals[i] = matcher.group(2);
|
||||
@ -285,7 +288,7 @@ public class Util {
|
||||
break;
|
||||
}
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
if (timeUtil.getDays() != 0) {
|
||||
if (format != DisplayFormat.SHORT) {
|
||||
@ -339,8 +342,10 @@ public class Util {
|
||||
}
|
||||
|
||||
public static boolean soundExists(String soundName) {
|
||||
for (Sound sound : Sound.values()) {
|
||||
if (sound.name().equalsIgnoreCase(soundName)) return true;
|
||||
for (final Sound sound : Sound.values()) {
|
||||
if (sound.name().equalsIgnoreCase(soundName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user