diff --git a/build.gradle b/build.gradle index 4b7c2f4..0c1deed 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group = 'io.github.lofrol' -version = '1.0' +version = '1.1' repositories { mavenCentral() diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/ClanAdminCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/ClanAdminCommand.java index de1ddb9..43b602b 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/ClanAdminCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/ClanAdminCommand.java @@ -17,10 +17,9 @@ public final class ClanAdminCommand extends Command { - public static boolean CreateDefaultInts() { - ClanAdminCommand tempClanAdminCommand = new ClanAdminCommand("ClanAdmin", "Default command for access to the clan system", + public static ClanAdminCommand CreateDefaultInts() { + return new ClanAdminCommand("ClanAdmin", "Default command for access to the clan system", "Use &5/Clan help&r for learning more", Stream.of("clanadmin", "ClanAdmin", "clad", "ClAd").collect(Collectors.toList())); - return getServer().getCommandMap().register("[UselessClan]", tempClanAdminCommand); } diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/ClanChatCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/ClanChatCommand.java index 72d2111..cb8a22d 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/ClanChatCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/ClanChatCommand.java @@ -15,10 +15,9 @@ import static org.bukkit.Bukkit.getServer; public final class ClanChatCommand extends Command { - public static boolean CreateDefaultInst() { - ClanChatCommand tempClanChatCommand = new ClanChatCommand("ClanChat", "Default command for clan chat", + public static ClanChatCommand CreateDefaultInst() { + return new ClanChatCommand("ClanChat", "Default command for clan chat", "Use &5/Clan help&r for learning more", Stream.of("ucc").collect(Collectors.toList())); - return getServer().getCommandMap().register("[UselessClan]", tempClanChatCommand); } private ClanChatCommand(@NotNull String name, @NotNull String description, @NotNull String usageMessage, @NotNull List aliases) { diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/ClanCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/ClanCommand.java index a51b87c..0cbeeab 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/ClanCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/ClanCommand.java @@ -18,10 +18,10 @@ public final class ClanCommand extends Command { - public static boolean CreateDefaultInst() { - ClanCommand tempClanCommand = new ClanCommand("Clan", "Default command for access to the clan system", + @NotNull + public static ClanCommand CreateDefaultInst() { + return new ClanCommand("Clan", "Default command for access to the clan system", "Use &5/Clan help&r for learning more", Stream.of("clan", "Clan").collect(Collectors.toList())); - return getServer().getCommandMap().register("[UselessClan]", tempClanCommand); } private ClanCommand(@NotNull String name, @NotNull String description, diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/calclvlAdminCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/calclvlAdminCommand.java index 955ee57..d8cae72 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/calclvlAdminCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/calclvlAdminCommand.java @@ -5,6 +5,7 @@ import io.github.lofrol.UselessClan.UselessClan; import io.github.lofrol.UselessClan.Utils.ChatSender; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; public class calclvlAdminCommand extends CommandBase { @Override @@ -12,6 +13,11 @@ public boolean havePermission(CommandSender sender) { return true; } + @Override + public @NotNull String commandDescription() { + return "Description.Admin.calclvl"; + } + @Override public boolean executeCommand(CommandSender sender, String[] args) { if (args.length == 1) { diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/debugInfoAdminCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/debugInfoAdminCommand.java index 9f3fff7..ab6fa77 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/debugInfoAdminCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/debugInfoAdminCommand.java @@ -5,6 +5,7 @@ import io.github.lofrol.UselessClan.UselessClan; import io.github.lofrol.UselessClan.Utils.ChatSender; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; public class debugInfoAdminCommand extends CommandBase { @Override @@ -12,6 +13,11 @@ public boolean havePermission(CommandSender sender) { return true; } + @Override + public @NotNull String commandDescription() { + return "Description.Admin.debugInfo"; + } + @Override public boolean executeCommand(CommandSender sender, String[] args) { if (args.length == 1) { diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/deleteAdminCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/deleteAdminCommand.java index 34c7c86..2f84af5 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/deleteAdminCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/deleteAdminCommand.java @@ -5,12 +5,19 @@ import io.github.lofrol.UselessClan.UselessClan; import io.github.lofrol.UselessClan.Utils.ChatSender; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; public class deleteAdminCommand extends CommandBase { @Override public boolean havePermission(CommandSender sender) { return true; } + + @Override + public @NotNull String commandDescription() { + return "Description.Admin.delete"; + } + @Override public boolean executeCommand(CommandSender sender, String[] args) { if (args.length == 1) { diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/forceJoinAdminCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/forceJoinAdminCommand.java index 72c85d6..5c95459 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/forceJoinAdminCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/forceJoinAdminCommand.java @@ -7,6 +7,7 @@ import io.github.lofrol.UselessClan.Utils.ChatSender; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; public class forceJoinAdminCommand extends CommandBase { @Override @@ -14,6 +15,12 @@ public boolean havePermission(CommandSender sender) { return sender instanceof Player; } + @Override + public @NotNull String commandDescription() { + return "Description.Admin.forceJoin"; + } + + @Override public boolean executeCommand(CommandSender sender, String[] args) { if (args.length == 1) { diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/helpAdminCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/helpAdminCommand.java index d88a4c2..93331f6 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/helpAdminCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/helpAdminCommand.java @@ -3,6 +3,7 @@ import io.github.lofrol.UselessClan.ClanCommands.Commands.CommandBase; import io.github.lofrol.UselessClan.Utils.ChatSender; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; public class helpAdminCommand extends CommandBase { @Override @@ -10,6 +11,12 @@ public boolean havePermission(CommandSender sender) { return true; } + @Override + public @NotNull String commandDescription() { + return "Description.Admin.help"; + } + + @Override public boolean executeCommand(CommandSender sender, String[] args) { ChatSender.MessageTo(sender, "&4UselessClan","########## CLAN ADMIN HELP ##########"); diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/homeAdminCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/homeAdminCommand.java index 8dac1a0..952d4de 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/homeAdminCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/homeAdminCommand.java @@ -6,6 +6,7 @@ import io.github.lofrol.UselessClan.Utils.ChatSender; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; public class homeAdminCommand extends CommandBase { @Override @@ -13,6 +14,12 @@ public boolean havePermission(CommandSender sender) { return true; } + @Override + public @NotNull String commandDescription() { + return "Description.Admin.home"; + } + + @Override public boolean executeCommand(CommandSender sender, String[] args) { if (args.length == 1) { diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/infoAdminCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/infoAdminCommand.java index fc49ab0..21452bb 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/infoAdminCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/infoAdminCommand.java @@ -5,6 +5,7 @@ import io.github.lofrol.UselessClan.UselessClan; import io.github.lofrol.UselessClan.Utils.ChatSender; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; public class infoAdminCommand extends CommandBase { @Override @@ -12,6 +13,12 @@ public boolean havePermission(CommandSender sender) { return true; } + @Override + public @NotNull String commandDescription() { + return "Description.Admin.info"; + } + + @Override public boolean executeCommand(CommandSender sender, String[] args) { if (args.length == 1) { diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/levelAdminCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/levelAdminCommand.java index 083cba5..eb28fe3 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/levelAdminCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/levelAdminCommand.java @@ -6,6 +6,7 @@ import io.github.lofrol.UselessClan.UselessClan; import io.github.lofrol.UselessClan.Utils.ChatSender; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; public class levelAdminCommand extends CommandBase { @Override @@ -13,6 +14,12 @@ public boolean havePermission(CommandSender sender) { return true; } + @Override + public @NotNull String commandDescription() { + return "Description.Admin.level"; + } + + @Override public boolean executeCommand(CommandSender sender, String[] args) { if (args.length == 1) { diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/listAdminCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/listAdminCommand.java index fe8a2bc..2077edc 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/listAdminCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/listAdminCommand.java @@ -5,6 +5,7 @@ import io.github.lofrol.UselessClan.UselessClan; import io.github.lofrol.UselessClan.Utils.ChatSender; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; public class listAdminCommand extends CommandBase { @Override @@ -12,6 +13,12 @@ public boolean havePermission(CommandSender sender) { return true; } + @Override + public @NotNull String commandDescription() { + return "Description.Admin.list"; + } + + @Override public boolean executeCommand(CommandSender sender, String[] args) { ChatSender.MessageTo(sender, "&4UselessClan","########## CLAN LIST ##########"); diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/matesAdminCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/matesAdminCommand.java index 5477317..d8975b9 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/matesAdminCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/matesAdminCommand.java @@ -6,6 +6,7 @@ import io.github.lofrol.UselessClan.UselessClan; import io.github.lofrol.UselessClan.Utils.ChatSender; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; public class matesAdminCommand extends CommandBase { @Override @@ -13,6 +14,12 @@ public boolean havePermission(CommandSender sender) { return true; } + @Override + public @NotNull String commandDescription() { + return "Description.Admin.mates"; + } + + @Override public boolean executeCommand(CommandSender sender, String[] args) { if (args.length == 1) { diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/requestsAdminCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/requestsAdminCommand.java index b6e1928..589df4a 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/requestsAdminCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/requestsAdminCommand.java @@ -6,6 +6,7 @@ import io.github.lofrol.UselessClan.UselessClan; import io.github.lofrol.UselessClan.Utils.ChatSender; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; public class requestsAdminCommand extends CommandBase { @Override @@ -13,6 +14,12 @@ public boolean havePermission(CommandSender sender) { return true; } + @Override + public @NotNull String commandDescription() { + return "Description.Admin.requests"; + } + + @Override public boolean executeCommand(CommandSender sender, String[] args) { if (args.length == 1) { diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/treasureAdminCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/treasureAdminCommand.java new file mode 100644 index 0000000..6a22887 --- /dev/null +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/AdminCommands/treasureAdminCommand.java @@ -0,0 +1,38 @@ +package io.github.lofrol.UselessClan.ClanCommands.Commands.AdminCommands; + +import io.github.lofrol.UselessClan.ClanCommands.Commands.CommandBase; +import io.github.lofrol.UselessClan.ClanObjects.Clan; +import io.github.lofrol.UselessClan.UselessClan; +import io.github.lofrol.UselessClan.Utils.ChatSender; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public class treasureAdminCommand extends CommandBase { + @Override + public boolean havePermission(CommandSender sender) { + return true; + } + + @Override + public @NotNull String commandDescription() { + return "Description.Admin.treasure"; + } + + + @Override + public boolean executeCommand(CommandSender sender, String[] args) { + if (args.length == 1) { + ChatSender.MessageTo(sender, "&4UselessClan","You forgot about clan %name, use /ClAd home %name, %name = name of clan"); + } + else { + Clan findedClan = UselessClan.getMainManager().getServerClans().get(args[1]); + if (findedClan == null) { + ChatSender.MessageTo(sender, "&4UselessClan","&cThis clan didnt exist!"); + return false; + } + if (sender instanceof Player tempPlayer) tempPlayer.teleport(findedClan.getTreasureClan()); + } + return true; + } +} diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/CommandBase.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/CommandBase.java index 1550734..654cd4e 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/CommandBase.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/CommandBase.java @@ -2,8 +2,11 @@ import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; public abstract class CommandBase { + public abstract @NotNull String commandDescription(); + public abstract boolean executeCommand(CommandSender sender, String[] args); public abstract boolean havePermission(CommandSender sender); diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/CommandsManager/AdminClanCommands.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/CommandsManager/AdminClanCommands.java index 03a18e2..346fcd0 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/CommandsManager/AdminClanCommands.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/CommandsManager/AdminClanCommands.java @@ -23,6 +23,7 @@ public class AdminClanCommands { entry("requests", new requestsAdminCommand()), entry("delete", new deleteAdminCommand()), entry("home", new homeAdminCommand()), + entry("treasure", new treasureAdminCommand()), entry("calclvl", new calclvlAdminCommand()), entry("level", new levelAdminCommand()), entry("debuginfo", new debugInfoAdminCommand()), diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/CommandsManager/BaseClanCommands.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/CommandsManager/BaseClanCommands.java index b96cda7..f2fec0c 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/CommandsManager/BaseClanCommands.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/CommandsManager/BaseClanCommands.java @@ -21,6 +21,7 @@ public class BaseClanCommands { entry("requests", new requestsUserCommand()), entry("top", new topUserCommand()), entry("claim", new claimUserCommand()), + entry("calclvl", new calclvlUserCommand()), entry("create", new createUserCommand()), entry("delete", new deleteUserCommand()), entry("leave", new leaveUserCommand()), @@ -28,6 +29,9 @@ public class BaseClanCommands { entry("withdraw", new withdrawUserCommand()), entry("home", new homeUserCommand()), entry("sethome", new sethomeUserCommand()), + entry("rename", new renameUserCommand()), + entry("redesc", new redescUserCommand()), + entry("settreasure",new settreasureUserCommand()), entry("info", new infoUserCommand()), entry("mates", new matesUserCommand()), entry("accept", new acceptUserCommand()), diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/CommandsManager/PluginClanCommands.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/CommandsManager/PluginClanCommands.java new file mode 100644 index 0000000..079ccce --- /dev/null +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/CommandsManager/PluginClanCommands.java @@ -0,0 +1,40 @@ +package io.github.lofrol.UselessClan.ClanCommands.Commands.CommandsManager; + +import io.github.lofrol.UselessClan.ClanCommands.Commands.CommandBase; +import io.github.lofrol.UselessClan.ClanCommands.Commands.DefaultCommands.*; +import io.github.lofrol.UselessClan.ClanCommands.Commands.PlayerCommandBase; +import io.github.lofrol.UselessClan.ClanCommands.Commands.PluginCommands.reloadGeneralCommand; +import io.github.lofrol.UselessClan.ClanCommands.Commands.PluginCommands.versionUserCommand; +import io.github.lofrol.UselessClan.ClanObjects.Clan; +import io.github.lofrol.UselessClan.ClanObjects.EClanRole; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +import static java.util.Map.entry; + +public class PluginClanCommands { + private static final Map ClanCommands = Map.ofEntries( + entry("version", new versionUserCommand()), + entry("reload", new reloadGeneralCommand()) + ); + + public static CommandBase getCommand(String key) { + return ClanCommands.get(key); + } + + public static @NotNull Collection getExecutableCommands(Player tempPlayer, Clan senderClan, EClanRole senderRole) { + Collection tempCommandArray = new ArrayList<>(); + for (CommandBase tempBase : ClanCommands.values()) { + if (tempBase instanceof PlayerCommandBase tempPlayerCommand) { + if (tempPlayerCommand.havePermission(tempPlayer, senderClan, senderRole)) { + tempCommandArray.add(tempPlayerCommand); + } + } + } + return tempCommandArray; + } +} diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/acceptUserCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/acceptUserCommand.java index b236916..7e1f73c 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/acceptUserCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/acceptUserCommand.java @@ -55,7 +55,6 @@ public boolean executeCommand(Player tempPlayer, Clan senderClan, String[] args) return false; } senderClan.PlayerJoinToClan(senderClan.getSettingsClan().DefaultJoinRole, AcceptedPlayerName); - UselessClan.getMainManager().CalculateClanLevel(senderClan); senderClan.RemoveFromRequest(AcceptedPlayerName); Player AcceptedPlayer = getPlayer(AcceptedPlayerName); diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/calclvlUserCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/calclvlUserCommand.java new file mode 100644 index 0000000..83c5901 --- /dev/null +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/calclvlUserCommand.java @@ -0,0 +1,45 @@ +package io.github.lofrol.UselessClan.ClanCommands.Commands.DefaultCommands; + +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import io.github.lofrol.UselessClan.ClanCommands.Commands.CommandBase; +import io.github.lofrol.UselessClan.ClanCommands.Commands.PlayerCommandBase; +import io.github.lofrol.UselessClan.ClanObjects.Clan; +import io.github.lofrol.UselessClan.ClanObjects.EClanRole; +import io.github.lofrol.UselessClan.UselessClan; +import io.github.lofrol.UselessClan.Utils.ChatSender; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import static org.bukkit.Bukkit.getOfflinePlayer; + +public class calclvlUserCommand extends PlayerCommandBase { + + @Override + public @NotNull String commandDescription() { + return "Description.CalculateLevel"; + } + + @Override + public boolean havePermission(Player tempPlayer, Clan senderClan, EClanRole senderRole) { + if (WorldGuardPlugin.inst() == null || senderClan == null) return false; + return (senderRole.ordinal() >= EClanRole.OFFICER.ordinal()); + } + + @Override + public boolean executeCommand(Player tempPlayer, Clan senderClan, String[] args) { + if (UselessClan.EconomyPtr != null) { + if (!UselessClan.EconomyPtr.has(getOfflinePlayer(tempPlayer.getName()), 1000)) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Economy.NotEnoughMoneyForCalculate"); + return false; + } + else { + UselessClan.EconomyPtr.withdrawPlayer(getOfflinePlayer(tempPlayer.getName()), 1000); + } + } + + UselessClan.getMainManager().CalculateClanLevel(senderClan); + ChatSender.MessageTo(tempPlayer, "&4UselessClan", "Treasure.SuccessfullyCalculation"); + return true; + } +} diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/claimUserCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/claimUserCommand.java index e794652..3c2d377 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/claimUserCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/claimUserCommand.java @@ -25,6 +25,9 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import static com.sk89q.worldguard.protection.flags.Flags.GREET_MESSAGE; +import static com.sk89q.worldguard.protection.flags.Flags.NOTIFY_ENTER; + public class claimUserCommand extends PlayerCommandBase { @@ -58,10 +61,10 @@ public boolean executeCommand(Player tempPlayer, Clan senderClan, String[] args) return false; } - if (senderClan.getClanLevel() < 1) { - ChatSender.MessageTo(tempPlayer, "UselessClan", "WG.ZeroLvlClanClaim"); - return false; - } + //if (senderClan.getClanLevel() < 1) { + // ChatSender.MessageTo(tempPlayer, "UselessClan", "WG.ZeroLvlClanClaim"); + // return false; + //} RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); RegionManager tempRegionManager = container.get(BukkitAdapter.adapt(tempPlayer.getWorld())); @@ -95,10 +98,11 @@ public boolean executeCommand(Player tempPlayer, Clan senderClan, String[] args) { double tempDistance = Math.sqrt(Math.pow(tempRegion.getMaximumPoint().getBlockX() - tempRegion.getMinimumPoint().getBlockX(), 2) + Math.pow(tempRegion.getMaximumPoint().getBlockZ() - tempRegion.getMinimumPoint().getBlockZ(), 2)); - if (tempDistance > senderClan.getClanLevel() * 50) { + // @todo distance from config + if (tempDistance > (senderClan.getClanLevel() + 1) * 75) { ChatSender.NonTranslateMessageTo(tempPlayer, "UselessClan", String.format(UselessClan.getLocalManager().getLocalizationMessage( - "WG.SelectedAreaIsTooBig"), senderClan.getClanLevel() * 75, tempDistance)); + "WG.SelectedAreaIsTooBig"), (senderClan.getClanLevel() + 1) * 75, (int)tempDistance)); return false; } } diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/declineUserCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/declineUserCommand.java index c31eb6e..7d82320 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/declineUserCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/declineUserCommand.java @@ -32,20 +32,19 @@ public boolean executeCommand(Player tempPlayer, Clan senderClan, String[] args) if (args.length == 1) { ChatSender.MessageTo(tempPlayer, "UselessClan", "Enter.ClanDeclineWithoutArgs"); - + return false; } - else { - String AcceptedPlayerName = args[1]; - if (!senderClan.HaveRequestFromPlayer(AcceptedPlayerName)) { - ChatSender.MessageTo(tempPlayer, "UselessClan", "Enter.CantFindRequest"); - return false; - } - senderClan.RemoveFromRequest(AcceptedPlayerName); - - ChatSender.NonTranslateMessageTo(tempPlayer, "UselessClan", - String.format(UselessClan.getLocalManager().getLocalizationMessage( - "Enter.PlayersRequestDeclined"), AcceptedPlayerName)); + + String AcceptedPlayerName = args[1]; + if (!senderClan.HaveRequestFromPlayer(AcceptedPlayerName)) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Enter.CantFindRequest"); + return false; } + senderClan.RemoveFromRequest(AcceptedPlayerName); + + ChatSender.NonTranslateMessageTo(tempPlayer, "UselessClan", + String.format(UselessClan.getLocalManager().getLocalizationMessage( + "Enter.PlayersRequestDeclined"), AcceptedPlayerName)); return true; } } diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/homeUserCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/homeUserCommand.java index 432b230..61c7b3a 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/homeUserCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/homeUserCommand.java @@ -17,7 +17,7 @@ public class homeUserCommand extends PlayerCommandBase { @Override public boolean havePermission(Player tempPlayer, Clan senderClan, EClanRole senderRole) { - return true; + return senderClan != null; } @Override diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/infoUserCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/infoUserCommand.java index ac5bf43..502318b 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/infoUserCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/infoUserCommand.java @@ -31,6 +31,8 @@ public boolean executeCommand(Player tempPlayer, Clan senderClan, String[] args) ChatSender.MessageTo(tempPlayer, "UselessClan", "Info.Label"); ChatSender.NonTranslateMessageTo(tempPlayer, "UselessClan", String.format( UselessClan.getLocalManager().getLocalizationMessage("Info.ClanName"), senderClan.getNameClan())); + ChatSender.NonTranslateMessageTo(tempPlayer, "UselessClan", String.format( + UselessClan.getLocalManager().getLocalizationMessage("Info.ClanDescription"), senderClan.getDescriptionClan())); ChatSender.NonTranslateMessageTo(tempPlayer, "UselessClan", String.format( UselessClan.getLocalManager().getLocalizationMessage("Info.ClanPrefix"), senderClan.getPrefixClan())); ChatSender.NonTranslateMessageTo(tempPlayer, "UselessClan", String.format( diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/redescUserCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/redescUserCommand.java new file mode 100644 index 0000000..779c6f5 --- /dev/null +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/redescUserCommand.java @@ -0,0 +1,55 @@ +package io.github.lofrol.UselessClan.ClanCommands.Commands.DefaultCommands; + +import io.github.lofrol.UselessClan.ClanCommands.Commands.PlayerCommandBase; +import io.github.lofrol.UselessClan.ClanObjects.Clan; +import io.github.lofrol.UselessClan.ClanObjects.EClanRole; +import io.github.lofrol.UselessClan.Utils.ChatSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public class redescUserCommand extends PlayerCommandBase { + + @Override + public @NotNull String commandDescription() { + return "Description.Redescription"; + } + + @Override + public boolean havePermission(Player tempPlayer, Clan senderClan, EClanRole senderRole) { + if (senderClan == null || senderRole == null) return false; + return (senderRole.ordinal() == EClanRole.LEADER.ordinal()); + } + + @Override + public boolean executeCommand(Player tempPlayer, Clan senderClan, String[] args) { + if (senderClan == null) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Base.HavntClan"); + return false; + } + + if (args.length == 1) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Rename.ClanRedescWithoutArgs"); + return false; + } + + StringBuilder tempBuilder = new StringBuilder(); + for (int i = 1; i < args.length; ++i) { + tempBuilder.append(args[i]); + tempBuilder.append(" "); + } + String tempStringName = tempBuilder.toString(); + + if (tempStringName.length() < 5 || tempStringName.length() > 220) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Rename.ClanRedescIncorrectLength"); + return false; + } + + if (!senderClan.setClanDescription(tempStringName)) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Rename.ClanRedescIncorrectSymbols"); + return false; + } + + ChatSender.MessageTo(tempPlayer, "UselessClan", "Rename.ClanRedescSuccessful"); + return true; + } +} diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/renameUserCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/renameUserCommand.java new file mode 100644 index 0000000..2c7025c --- /dev/null +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/renameUserCommand.java @@ -0,0 +1,56 @@ +package io.github.lofrol.UselessClan.ClanCommands.Commands.DefaultCommands; + +import io.github.lofrol.UselessClan.ClanCommands.Commands.PlayerCommandBase; +import io.github.lofrol.UselessClan.ClanObjects.Clan; +import io.github.lofrol.UselessClan.ClanObjects.EClanRole; +import io.github.lofrol.UselessClan.UselessClan; +import io.github.lofrol.UselessClan.Utils.ChatSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public class renameUserCommand extends PlayerCommandBase { + + @Override + public @NotNull String commandDescription() { + return "Description.Rename"; + } + + @Override + public boolean havePermission(Player tempPlayer, Clan senderClan, EClanRole senderRole) { + if (senderClan == null || senderRole == null) return false; + return (senderRole.ordinal() == EClanRole.LEADER.ordinal()); + } + + @Override + public boolean executeCommand(Player tempPlayer, Clan senderClan, String[] args) { + if (senderClan == null) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Base.HavntClan"); + return false; + } + + if (args.length == 1) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Rename.ClanRenameWithoutArgs"); + return false; + } + + StringBuilder tempBuilder = new StringBuilder(); + for (int i = 1; i < args.length; ++i) { + tempBuilder.append(args[i]); + tempBuilder.append(" "); + } + String tempStringName = tempBuilder.toString(); + + if (tempStringName.length() < 5 || tempStringName.length() > 22) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Rename.ClanRenameIncorrectLength"); + return false; + } + + if (!senderClan.setClanName(tempStringName)) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Rename.ClanRenameIncorrectSymbols"); + return false; + } + + ChatSender.MessageTo(tempPlayer, "UselessClan", "Rename.ClanRenameSuccessful"); + return true; + } +} diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/sethomeUserCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/sethomeUserCommand.java index f8068cc..6f19df0 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/sethomeUserCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/sethomeUserCommand.java @@ -1,5 +1,13 @@ package io.github.lofrol.UselessClan.ClanCommands.Commands.DefaultCommands; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.RegionContainer; import io.github.lofrol.UselessClan.ClanCommands.Commands.PlayerCommandBase; import io.github.lofrol.UselessClan.ClanObjects.Clan; import io.github.lofrol.UselessClan.ClanObjects.EClanRole; @@ -34,6 +42,30 @@ public boolean executeCommand(Player tempPlayer, Clan senderClan, String[] args) } Location tempLoc = tempPlayer.getLocation(); + + RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); + RegionManager tempRegionManager = container.get(BukkitAdapter.adapt(tempPlayer.getWorld())); + + if (tempRegionManager == null) { + return false; + } + + ApplicableRegionSet tempRegion = tempRegionManager.getApplicableRegions(BlockVector3.at(tempLoc.getX(),tempLoc.getY(),tempLoc.getZ())); + + { + boolean isClanTerritory = false; + for (var tempReg : tempRegion.getRegions()) { + if (tempReg.getId().equals(senderClan.getClanRegionId())) { + isClanTerritory = true; + } + } + + if (!isClanTerritory) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Home.WrongRegionToSet"); + return false; + } + } + senderClan.setHomeClan(tempLoc); ChatSender.MessageTo(tempPlayer, "UselessClan", "Home.HomeSuccessSet"); return true; diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/settingsUserCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/settingsUserCommand.java index cbe02f4..9dda6b6 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/settingsUserCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/settingsUserCommand.java @@ -70,6 +70,7 @@ else if (args[1].equalsIgnoreCase("RoleCanAccept")) { "Setting.SelectedWithoutArgs"), "RoleCanAccept")); } else if (args[1].equalsIgnoreCase("help")) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Setting.Description.Info"); ChatSender.MessageTo(tempPlayer, "UselessClan", "Setting.Description.RoleCanSetHome"); ChatSender.MessageTo(tempPlayer, "UselessClan", "Setting.Description.RoleCanKick"); ChatSender.MessageTo(tempPlayer, "UselessClan", "Settings.Description.DefaultJoinRole"); diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/settreasureUserCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/settreasureUserCommand.java new file mode 100644 index 0000000..ceb5485 --- /dev/null +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/DefaultCommands/settreasureUserCommand.java @@ -0,0 +1,73 @@ +package io.github.lofrol.UselessClan.ClanCommands.Commands.DefaultCommands; + +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.RegionContainer; +import io.github.lofrol.UselessClan.ClanCommands.Commands.PlayerCommandBase; +import io.github.lofrol.UselessClan.ClanObjects.Clan; +import io.github.lofrol.UselessClan.ClanObjects.EClanRole; +import io.github.lofrol.UselessClan.UselessClan; +import io.github.lofrol.UselessClan.Utils.ChatSender; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public class settreasureUserCommand extends PlayerCommandBase { + + @Override + public @NotNull String commandDescription() { + return "Description.Settreasure"; + } + + @Override + public boolean havePermission(Player tempPlayer, Clan senderClan, EClanRole senderRole) { + if (senderClan == null || senderRole == null) return false; + return (senderRole == EClanRole.LEADER); + } + + @Override + public boolean executeCommand(Player tempPlayer, Clan senderClan, String[] args) { + if (senderClan == null) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Base.HavntClan"); + return false; + } + + if (!tempPlayer.getWorld().getName().equals("world")) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Treasure.WrongWorldToSet"); + return false; + } + + Location tempLoc = tempPlayer.getLocation(); + + RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); + RegionManager tempRegionManager = container.get(BukkitAdapter.adapt(tempPlayer.getWorld())); + + if (tempRegionManager == null) { + return false; + } + + ApplicableRegionSet tempRegion = tempRegionManager.getApplicableRegions(BlockVector3.at(tempLoc.getX(),tempLoc.getY(),tempLoc.getZ())); + + { + boolean isClanTerritory = false; + for (var tempReg : tempRegion.getRegions()) { + if (tempReg.getId().equals(senderClan.getClanRegionId())) { + isClanTerritory = true; + } + } + + if (!isClanTerritory) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Treasure.WrongRegionToSet"); + return false; + } + } + + senderClan.setTreasureClan(tempLoc); + //UselessClan.getMainManager().CalculateClanLevel(senderClan); + ChatSender.MessageTo(tempPlayer, "UselessClan", "Treasure.TreasureSuccessSet"); + return true; + } +} diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/PlayerCommandBase.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/PlayerCommandBase.java index c5fc62d..c2b35c3 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/PlayerCommandBase.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/PlayerCommandBase.java @@ -39,7 +39,6 @@ public boolean havePermission(CommandSender sender) { return havePermission(tempPlayer, senderClan, senderRole); } - public abstract @NotNull String commandDescription(); public abstract boolean havePermission(Player tempPlayer, @Nullable Clan senderClan, @Nullable EClanRole senderRole); public abstract boolean executeCommand(Player tempPlayer, Clan senderClan, String[] args); } \ No newline at end of file diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/PluginCommands/reloadGeneralCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/PluginCommands/reloadGeneralCommand.java new file mode 100644 index 0000000..514c490 --- /dev/null +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/PluginCommands/reloadGeneralCommand.java @@ -0,0 +1,28 @@ +package io.github.lofrol.UselessClan.ClanCommands.Commands.PluginCommands; + +import io.github.lofrol.UselessClan.ClanCommands.Commands.CommandBase; +import io.github.lofrol.UselessClan.UselessClan; +import io.github.lofrol.UselessClan.Utils.ChatSender; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +public class reloadGeneralCommand extends CommandBase { + @Override + public @NotNull String commandDescription() { + return "Description.General.reload"; + } + + @Override + public boolean havePermission(CommandSender sender) { + return sender.hasPermission("UselessClan.Admin"); + } + + @Override + public boolean executeCommand(CommandSender sender, String[] args) { + UselessClan tempPlugin = UselessClan.getPlugin(UselessClan.class); + if (tempPlugin.isEnabled()){ + tempPlugin.reloadPlugin(); + } + return true; + } +} \ No newline at end of file diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/PluginCommands/versionUserCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/PluginCommands/versionUserCommand.java new file mode 100644 index 0000000..cc28a1f --- /dev/null +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/Commands/PluginCommands/versionUserCommand.java @@ -0,0 +1,30 @@ +package io.github.lofrol.UselessClan.ClanCommands.Commands.PluginCommands; + +import io.github.lofrol.UselessClan.ClanCommands.Commands.CommandBase; +import io.github.lofrol.UselessClan.ClanObjects.Clan; +import io.github.lofrol.UselessClan.ClanObjects.EClanRole; +import io.github.lofrol.UselessClan.UselessClan; +import io.github.lofrol.UselessClan.Utils.ChatSender; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class versionUserCommand extends CommandBase { + @Override + public @NotNull String commandDescription() { + return "Description.General.version"; + } + + @Override + public boolean havePermission(CommandSender sender) { + return true; + } + + @Override + public boolean executeCommand(CommandSender sender, String[] args) { + ChatSender.NonTranslateMessageTo(sender, "UselessClan", UselessClan.getConfigManager().getServerVersion()); + return true; + } +} diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanCommands/PluginCommand.java b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/PluginCommand.java new file mode 100644 index 0000000..382b156 --- /dev/null +++ b/src/main/java/io/github/lofrol/UselessClan/ClanCommands/PluginCommand.java @@ -0,0 +1,53 @@ +package io.github.lofrol.UselessClan.ClanCommands; + +import io.github.lofrol.UselessClan.ClanCommands.Commands.CommandBase; +import io.github.lofrol.UselessClan.ClanCommands.Commands.CommandsManager.BaseClanCommands; +import io.github.lofrol.UselessClan.ClanCommands.Commands.CommandsManager.PluginClanCommands; +import io.github.lofrol.UselessClan.Utils.ChatSender; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.bukkit.Bukkit.getServer; + +public class PluginCommand extends Command { + public static PluginCommand CreateDefaultInst() { + return new PluginCommand("UselessClan", "Default command for access to the clan system", + "Use &5/UselessClan help&r for learning more", Stream.of("UselessClan", "uselessclan", "UsCl", "UC").collect(Collectors.toList())); + } + + private PluginCommand(@NotNull String name, @NotNull String description, + @NotNull String usageMessage, + @NotNull List aliases) { + super(name, description, usageMessage, aliases); + } + + @Override + public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) { + if (!(sender instanceof Player tempPlayer)) return false; + + if (args.length == 0) { + ChatSender.MessageTo(tempPlayer,"UselessClan", "Main.ClanCommandWithoutArgs"); + return false; + } + + CommandBase tempCommand = PluginClanCommands.getCommand(args[0]); + + if (tempCommand == null) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Main.InvalidClanCommand"); + return false; + } + + if (!tempCommand.havePermission(sender)) { + ChatSender.MessageTo(tempPlayer, "UselessClan", "Main.InvalidPermissionToCommand"); + return false; + } + + return tempCommand.executeCommand(sender, args); + } +} diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanConfigManager.java b/src/main/java/io/github/lofrol/UselessClan/ClanConfigManager.java index 2662f5d..c418d4c 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanConfigManager.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanConfigManager.java @@ -1,20 +1,13 @@ package io.github.lofrol.UselessClan; -import com.sk89q.worldedit.util.collection.DoubleArrayList; -import io.github.lofrol.UselessClan.ClanObjects.EClanRole; import io.github.lofrol.UselessClan.Configurations.ClanConfigConfiguration; import org.bukkit.configuration.file.FileConfiguration; -import org.checkerframework.checker.nullness.qual.Nullable; import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; -import java.util.List; -import java.util.Map; import java.util.logging.Level; -import static java.util.Map.entry; - public class ClanConfigManager { private final UselessClan OwnerPlugin; @@ -56,4 +49,8 @@ public void saveConfig(FileConfiguration config) { public ClanConfigConfiguration getClanConfig() { return ClanConfig; } + + public String getServerVersion() { + return OwnerPlugin.getDescription().getVersion(); + } } \ No newline at end of file diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanManager.java b/src/main/java/io/github/lofrol/UselessClan/ClanManager.java index be1e9bc..bf70a57 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanManager.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanManager.java @@ -1,13 +1,22 @@ package io.github.lofrol.UselessClan; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.managers.RemovalStrategy; +import com.sk89q.worldguard.protection.regions.RegionContainer; import io.github.lofrol.UselessClan.ClanObjects.*; import io.github.lofrol.UselessClan.Extensions.ClanManagerExtension; import io.github.lofrol.UselessClan.Utils.ChatSender; import io.github.lofrol.UselessClan.Utils.TopClanCounter; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; @@ -46,16 +55,70 @@ public static String ClanRoleSolver(EClanRole role) { default -> ""; }; } - public void CalculateClanLevel(Clan ClanToLevel) { + public void CalculateClanLevel(@NotNull Clan ClanToLevel) { + if (UselessClan.getConfigManager().getClanConfig().isUseExtendCalculateClanLevels()) { + CalculateClanLevelExtension(ClanToLevel); + } + else { + CalculateClanLevelDefault(ClanToLevel); + } + } + + public void CalculateClanLevelExtension(@NotNull Clan ClanToLevel) { // Overriding by extensions if needed - if (UselessClan.getConfigManager().getClanConfig().isNeedCalculateClanLevels()) { - Extension.CalculateClanLevel(ClanToLevel); + Extension.CalculateClanLevel(ClanToLevel); + } + + public void CalculateClanLevelDefault(@NotNull Clan ClanToLevel) { + Location tempTreasure = ClanToLevel.getTreasureClan(); + if (tempTreasure == null) { + ClanToLevel.setClanLevel(0); + return; } + float radius = 5; + float tempX = tempTreasure.getBlockX() + radius + 1; + float tempY = tempTreasure.getBlockY() + 5; + float tempZ = tempTreasure.getBlockZ() + radius + 1; + int GoldBlockCount = 0; + int DiamondBlockCount = 0; + int EmeraldBlockCount = 0; + + for (int i = tempTreasure.getBlockX() - (int)radius; i < tempX; ++i) { + for (int j = tempTreasure.getBlockY(); j < tempY; ++j) { + for (int k = tempTreasure.getBlockZ() - (int)radius; k < tempZ; ++ k) { + Block tempBlock = tempTreasure.getWorld().getBlockAt(i,j,k); + if (tempBlock.getType() == Material.GOLD_BLOCK) { + GoldBlockCount++; + } + else if (tempBlock.getType() == Material.DIAMOND_BLOCK) { + DiamondBlockCount++; + } + else if (tempBlock.getType() == Material.EMERALD_BLOCK) { + EmeraldBlockCount++; + } + } + } + } + int MaxRating = 1200; + float Rating = (GoldBlockCount + (DiamondBlockCount * 2) + (EmeraldBlockCount * 3)) * 1.5f; + float level = Rating / MaxRating * 10.f; + + getServer().getLogger().log(Level.INFO, + String.format("[UselessClan] Calculated level of clan %s, Points = %d, Max Points = %d", + ClanToLevel.getPrefixClan(), (int)Rating, MaxRating)); + ClanToLevel.setClanLevel((int)level); } - public void CalculateAllClansLevels() { - for (Clan tempClan : ServerClans.values()) { - CalculateClanLevel(tempClan); + public void CalculateAllClansLevels(boolean isDefault) { + if (isDefault) { + for (Clan tempClan : ServerClans.values()) { + CalculateClanLevelDefault(tempClan); + } + } + else { + for (Clan tempClan : ServerClans.values()) { + CalculateClanLevelExtension(tempClan); + } } } public void CreateClan(String ClanName, Player LeaderPlayer) { @@ -69,6 +132,13 @@ public void CreateClan(String ClanName, Player LeaderPlayer) { public void DeleteClan(Clan clanToDelete) { Clan ClanToDelete = ServerClans.get(clanToDelete.getPrefixClan()); if (ClanToDelete == null) return; + if (OnlineClanPlayers.entrySet().toArray()[0] instanceof Player tempPlayer) { + RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); + RegionManager tempRegionManager = container.get(BukkitAdapter.adapt(tempPlayer.getWorld())); + if (tempRegionManager != null) { + tempRegionManager.removeRegion(clanToDelete.getClanRegionId(),RemovalStrategy.REMOVE_CHILDREN); + } + } ServerClans.remove(clanToDelete.getPrefixClan()); for (Map.Entry tempEntry : OnlineClanPlayers.entrySet()) { @@ -123,7 +193,7 @@ public void SaveClans() { private void SaveClan(Clan clanToSave, File clanFolder) throws IOException { File tempClanFile = new File(clanFolder, String.format("%s.yml", clanToSave.getPrefixClan())); - FileConfiguration ClanConfig = clanToSave.SaveClanToConfig(); + FileConfiguration ClanConfig = clanToSave.SaveClanToConfig(false); if (ClanConfig == null) { OwnerPlugin.getLogger().log(Level.FINE, String.format("%s was skipped save", clanToSave.getNameClan())); return; @@ -138,7 +208,7 @@ private void RemoveClanToDeletedClanFolder(Clan clanToDelete) { File tempDeleteDir = UselessClan.getSerilManager().checkClanFolderOrCreate(DeletedClanFolder); File tempClanDir = UselessClan.getSerilManager().checkClanFolderOrCreate(ClanFolderName); - FileConfiguration ClanConfig = clanToDelete.SaveClanToConfig(); + FileConfiguration ClanConfig = clanToDelete.SaveClanToConfig(true); boolean isDeleted = false; @@ -223,9 +293,11 @@ public void OnPlayerJoin(Player player) { RegisterOnlineClanPlayer(tempClan, player); getServer().getScheduler().runTaskLater(OwnerPlugin, () -> { if (playerRole == EClanRole.LEADER || playerRole == EClanRole.OFFICER) { - ChatSender.NonTranslateMessageTo(player,"UselessClan", String.format( - UselessClan.getLocalManager().getLocalizationMessage( - "Enter.HaveRequestsOnJoin"), tempClan.getRequestCount())); + if (tempClan.getRequestCount() > 0) { + ChatSender.NonTranslateMessageTo(player,"UselessClan", String.format( + UselessClan.getLocalManager().getLocalizationMessage( + "Enter.HaveRequestsOnJoin"), tempClan.getRequestCount())); + } } }, 200); @@ -256,7 +328,7 @@ public void createClansBackups() { for (Clan tempClan : ServerClans.values()) { File tempClanFile = new File(todayBackupFile, String.format("%s.yml", tempClan.getPrefixClan())); - FileConfiguration tempConfig = tempClan.SaveClanToConfig(); + FileConfiguration tempConfig = tempClan.SaveClanToConfig(false); if (tempConfig == null) continue; try { tempConfig.save(tempClanFile); diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanObjects/Clan.java b/src/main/java/io/github/lofrol/UselessClan/ClanObjects/Clan.java index ad5fd2e..989a691 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanObjects/Clan.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanObjects/Clan.java @@ -21,31 +21,23 @@ public class Clan { * Variables */ private final String PrefixClan; - private String NameClan; - private final String DescriptionClan; - + private String DescriptionClan; private final List Members; - private final List Requests; - private final transient Map OnlineMembers; - private String LeaderName; - private Location HomeClan; - + private Location TreasureClan; private final ClanSettings SettingsClan; - private double MoneyClan; private int ClanLevel; private String ClanRegionId; - private boolean NeedToSave; // Creating by file loader private Clan(String ClanPrefix, String ClanName, String LeaderName, - Double MoneyClan, Location HomeClan, List Requests, + Double MoneyClan, Location HomeClan, Location TreasureClan, List Requests, List Members, String DescriptionClan, ClanSettings SettingsClan, int level, String RegionName) { this.PrefixClan = ClanPrefix; @@ -56,6 +48,7 @@ private Clan(String ClanPrefix, String ClanName, String LeaderName, this.MoneyClan = MoneyClan; this.DescriptionClan = DescriptionClan; this.HomeClan = HomeClan; + this.TreasureClan = TreasureClan; this.SettingsClan = SettingsClan; this.ClanLevel = level; this.ClanRegionId = RegionName; @@ -65,8 +58,8 @@ private Clan(String ClanPrefix, String ClanName, String LeaderName, } // return null if didn't need to save - public FileConfiguration SaveClanToConfig() { - if (!NeedToSave) return null; + public FileConfiguration SaveClanToConfig(boolean forceSave) { + if (!NeedToSave && !forceSave) return null; FileConfiguration ClanConfig = new YamlConfiguration(); @@ -78,7 +71,6 @@ public FileConfiguration SaveClanToConfig() { ClanConfig.set("UselessClan.ClanLevel", ClanLevel); ClanConfig.set("UselessClan.ClanRegionName", ClanRegionId); - ClanConfig.set("UselessClan.Requests.size", Requests.size()); for (int i = 0; i< Requests.size(); ++i) { ClanConfig.set(String.format("UselessClan.Requests.%d", i), Requests.get(i)); @@ -91,6 +83,13 @@ public FileConfiguration SaveClanToConfig() { ClanConfig.set("UselessClan.Home.Z",HomeClan.getBlockZ()); } + ClanConfig.set("UselessClan.Treasure.exists", (TreasureClan != null)); + if (TreasureClan != null) { + ClanConfig.set("UselessClan.Treasure.X",TreasureClan.getBlockX()); + ClanConfig.set("UselessClan.Treasure.Y",TreasureClan.getBlockY()); + ClanConfig.set("UselessClan.Treasure.Z",TreasureClan.getBlockZ()); + } + ClanConfig.set("UselessClan.Members.size", Members.size()); for (int i = 0; i< Members.size(); ++i) { ClanMember tempMember = Members.get(i); @@ -125,6 +124,17 @@ public static Clan CreateClanFromConfig(FileConfiguration ClanConfig) { } // Home end + // Treasure start + Location TreasureClan = null; + if (ClanConfig.getBoolean("UselessClan.Treasure.exists")) { + int tempX = ClanConfig.getInt("UselessClan.Treasure.X"); + int tempY = ClanConfig.getInt("UselessClan.Treasure.Y"); + int tempZ = ClanConfig.getInt("UselessClan.Treasure.Z"); + World tempWorld = getServer().getWorld("world"); + TreasureClan = new Location(tempWorld, tempX,tempY,tempZ); + } + // Treasure end + // Requests start List TempRequest = new ArrayList<>(); int tempSize = ClanConfig.getInt("UselessClan.Requests.size"); @@ -189,7 +199,7 @@ else if (Stage == 2) { if (ClanPrefix != null && ClanName != null && LeaderName != null && DescriptionClan != null) { return new Clan(ClanPrefix, ClanName, LeaderName, MoneyClan, - HomeClan, TempRequest, TempMembers, DescriptionClan, + HomeClan, TreasureClan, TempRequest, TempMembers, DescriptionClan, TempSettings, ClanLevel, ClanRegion); } return null; @@ -208,6 +218,7 @@ public Clan(String ClanPrefix, String CreatorName) { ClanRegionId = null; DescriptionClan = "Description of your clan"; HomeClan = null; + TreasureClan = null; SettingsClan = new ClanSettings(); NeedToSave = true; @@ -377,6 +388,8 @@ else if (o1.getMemberRole().ordinal() < o2.getMemberRole().ordinal()) { public String getPrefixClan() { return PrefixClan; } public double getMoneyClan() { return MoneyClan; } public Location getHomeClan() { return HomeClan; } + public Location getTreasureClan() { return TreasureClan; } + public List getRequests() { return Requests; } public int getRequestCount() { return Requests.size(); } public String getClanRegionId() { return ClanRegionId; } @@ -388,7 +401,7 @@ else if (o1.getMemberRole().ordinal() < o2.getMemberRole().ordinal()) { * Setters Functions */ public boolean setClanName(String newNameClan) { - if (newNameClan.length() >= 5 && newNameClan.length() <=15) { + if (newNameClan.length() >= 5 && newNameClan.length() <= 22) { for (char tempChar : newNameClan.toCharArray()) { // check for 0-9 or A-Z or a-z or space or _ if (!((tempChar >= 48 && tempChar <= 57) || @@ -405,11 +418,35 @@ public boolean setClanName(String newNameClan) { return false; } + public boolean setClanDescription(String newDescriptionClan) { + if (newDescriptionClan.length() >= 5 && newDescriptionClan.length() <= 220) { + for (char tempChar : newDescriptionClan.toCharArray()) { + // check for 0-9 or A-Z or a-z or space or _ + if (!((tempChar >= 48 && tempChar <= 57) || + (tempChar >= 65 && tempChar <= 90) || + (tempChar >= 97 && tempChar <= 122) || + tempChar == ' ' || tempChar == '_')) { + return false; + } + } + DescriptionClan = newDescriptionClan; + NeedToSave = true; + return true; + } + return false; + } + public void setHomeClan(Location newHomeLocation) { HomeClan = newHomeLocation; NeedToSave = true; } + public void setTreasureClan(Location newTreasureClan) { + TreasureClan = newTreasureClan; + NeedToSave = true; + } + + public void DepositMoneyToClan(double moneyClan) { MoneyClan += moneyClan; NeedToSave = true; diff --git a/src/main/java/io/github/lofrol/UselessClan/Configurations/ClanConfigConfiguration.java b/src/main/java/io/github/lofrol/UselessClan/Configurations/ClanConfigConfiguration.java index a6a088a..76f6ef3 100644 --- a/src/main/java/io/github/lofrol/UselessClan/Configurations/ClanConfigConfiguration.java +++ b/src/main/java/io/github/lofrol/UselessClan/Configurations/ClanConfigConfiguration.java @@ -32,6 +32,14 @@ private ClanConfigConfiguration() {} tempThis.set("NeedCalculateClanLevels", tempThis.NeedCalculateClanLevels); } + String tempUseExtendCalculateClanLevels = tempConfig.getString("UseExtendCalculateClanLevels"); + if (tempUseExtendCalculateClanLevels == null) { + tempThis.initUseExtendCalculateClanLevelsDefault(); + } + else { + tempThis.UseExtendCalculateClanLevels = Boolean.parseBoolean(tempUseExtendCalculateClanLevels); + tempThis.set("UseExtendCalculateClanLevels", tempThis.UseExtendCalculateClanLevels); + } String tempBackupDelay = tempConfig.getString("Delay.ClanBackup"); if (tempBackupDelay == null) { @@ -148,7 +156,9 @@ private ClanConfigConfiguration() {} return tempThis; } + private boolean NeedCalculateClanLevels; + private boolean UseExtendCalculateClanLevels; private String LocalizationKey; private int backupDelay; private int autoSaveDelay; @@ -170,6 +180,7 @@ private ClanConfigConfiguration() {} * */ public String getLocalizationKey() { return LocalizationKey; } public boolean isNeedCalculateClanLevels() { return NeedCalculateClanLevels; } + public boolean isUseExtendCalculateClanLevels() { return UseExtendCalculateClanLevels; } public int getBackupDelay() { return backupDelay; } public int getAutoSaveDelay() { return autoSaveDelay; } public int getCalcClanLvlDelay() { return calcClanLvlDelay; } @@ -196,6 +207,12 @@ private void initNeedCalculateClanLevelsDefault() { set("NeedCalculateClanLevels", tempDefault); NeedCalculateClanLevels = tempDefault; } + private void initUseExtendCalculateClanLevelsDefault() { + var tempDefault = true; + set("UseExtendCalculateClanLevels", tempDefault); + UseExtendCalculateClanLevels = tempDefault; + } + private void initDelayClanBackupDefault() { var tempDefault = 864000; set("Delay.ClanBackup", tempDefault); diff --git a/src/main/java/io/github/lofrol/UselessClan/Configurations/DefaultLocalizationConfiguration.java b/src/main/java/io/github/lofrol/UselessClan/Configurations/DefaultLocalizationConfiguration.java index 0748437..8e29d20 100644 --- a/src/main/java/io/github/lofrol/UselessClan/Configurations/DefaultLocalizationConfiguration.java +++ b/src/main/java/io/github/lofrol/UselessClan/Configurations/DefaultLocalizationConfiguration.java @@ -101,9 +101,11 @@ public DefaultLocalizationConfiguration() { set("Economy.NotEnoughMoney", "&cYou cant withdraw &a%s&c from you clan"); set("Economy.DepositPlayer", "Player &a%s&b deposit &a%s&b to your clan!"); set("Economy.WithdrawPlayer", "Player &a%s&b withdraw &a%s&b from clan balance"); + // @todo 1000$ must be in plugin config + set("Economy.NotEnoughMoneyForCalculate", "&cYou need 1000$ for force calculate clan level!"); setComments("Economy", List.of(" ", " ")); - set("Help.Label", "------------- CLAN HELP %d -------------"); + set("Help.Label", "--------- CLAN HELP %d ---------"); set("Help.ClanPageCommand", "Type &a/Clan help %d&b - to show commands in page %d"); set("Help.WrongPage", "&cThis page of help isnt found"); setComments("Help", List.of(" ", " ")); @@ -113,10 +115,18 @@ public DefaultLocalizationConfiguration() { set("Home.WrongWorldToTeleport", "&cYou cant teleport clan home from this world!"); set("Home.HomeSuccessSet", "&aClan home set successfully!"); set("Home.HomeTeleportation", "&aYou teleported to clan home!"); + set("Home.WrongRegionToSet", "&cYou cant set clan home out of clan region!"); setComments("Home", List.of(" ", " ")); - set("Info.Label", "---------- CLAN INFO ----------"); + set("Treasure.TreasureSuccessSet", "&aClan treasure set successfully!"); + set("Treasure.WrongWorldToSet", "&cYou cant set clan treasure in this world!"); + set("Treasure.SuccessfullyCalculation", "&aClan level successfully calculated!"); + set("Treasure.WrongRegionToSet", "&cYou cant set clan treasure out of clan region!"); + setComments("Treasure", List.of(" ", " ")); + + set("Info.Label", "--------- CLAN INFO ---------"); set("Info.ClanName", "- Name: %s"); + set("Info.ClanDescription", "- Description: %s"); set("Info.ClanPrefix", "- Prefix: %s"); set("Info.ClanLevel", "- Level: %s"); set("Info.LeaderName", "- LeaderName: %s"); @@ -125,6 +135,16 @@ public DefaultLocalizationConfiguration() { set("Info.Rank", "- Your rank: %s"); setComments("Info", List.of(" ", " ")); + set("Rename.ClanRenameWithoutArgs", "&cYou forgot about new clan %name, use &a/Clan rename %name&b, %name = new clan name"); + set("Rename.ClanRenameIncorrectLength", "&cYour clan name had incorrect length!"); + set("Rename.ClanRenameIncorrectSymbols", "&cYour clan name had incorrect symbols!"); + set("Rename.ClanRenameSuccessful", "&aClan name successfully changed!"); + set("Rename.ClanRedescWithoutArgs", "&cYou forgot about new clan %description, use &a/Clan redesc %description&b, %%description = new clan description"); + set("Rename.ClanRedescIncorrectLength", "&cYour clan description had incorrect length!"); + set("Rename.ClanRedescIncorrectSymbols", "&cYour clan description had incorrect symbols!"); + set("Rename.ClanRedescSuccessful", "&aClan description successfully changed!"); + setComments("Rename", List.of(" ", " ")); + set("Mates.Label", "------- CLANMATES -------"); setComments("Mates", List.of(" ", " ")); @@ -136,14 +156,16 @@ public DefaultLocalizationConfiguration() { set("Setting.Info", "&a/Clan setting info - show info about setting clan"); set("Setting.UseExample", "&cWrong arguments, example &a/Clan setting %s"); set("Setting.Changed", "&a%s successfully changed to %s!"); + + set("Setting.Description.Info", "&a/Clan setting info - To see clan settings"); set("Setting.Description.RoleCanSetHome", "&a/Clan setting RoleCanSetHome [Role] - set min role to change home location [1-4]"); set("Setting.Description.RoleCanKick", "&a/Clan setting RoleCanKick [Role] - set min role, which can kick members [1-4]"); - set("Settings.Description.DefaultJoinRole", "&a/Clan setting DefaultJoinRole [Role] - set min default join role [1-3]"); - set("Settings.Description.RoleCanWithdraw", "&a/Clan setting RoleCanWithdraw [Role] - set min role, which can kick withdraw money [1-4]"); - set("Settings.Description.RoleCanAccept", "&a/Clan setting RoleCanAccept [Role] - set min role, which can accept/decline players to clan [1-4]"); + set("Setting.Description.DefaultJoinRole", "&a/Clan setting DefaultJoinRole [Role] - set min default join role [1-3]"); + set("Setting.Description.RoleCanWithdraw", "&a/Clan setting RoleCanWithdraw [Role] - set min role, which can kick withdraw money [1-4]"); + set("Setting.Description.RoleCanAccept", "&a/Clan setting RoleCanAccept [Role] - set min role, which can accept/decline players to clan [1-4]"); setComments("Setting", List.of(" ", " ")); - set("Top.Label", "&b---------- CLAN TOP %d ----------"); + set("Top.Label", "&b--------- CLAN TOP %d ---------"); set("Top.PageCommand", "Type &a/Clan top %d&b - to show commands in page %d"); set("Top.WrongPage", "&cThis page of clans top isnt found"); setComments("Top", List.of(" ", " ")); @@ -153,6 +175,8 @@ public DefaultLocalizationConfiguration() { set("Description.Create", "&a/Clan create %name&b - to create your own clan with name %name"); set("Description.Decline", "&a/Clan decline %name&b - to decline request for join from player %name"); set("Description.Delete", "&a/Clan delete&b - to delete your clan"); + set("Description.Rename", "&a/Clan rename %name&b - to change name of your clan (Prefix wont change)"); + set("Description.Redescription", "&a/Clan redesc %description&b - to change description of your clan"); set("Description.Demote", "&a/Clan demote %name&b - to demote player %name of your clan"); set("Description.Deposit", "&a/Clan deposit %value&b - to deposit money to your clan"); set("Description.Help", "&a/Clan help&b - to call this menu"); @@ -165,9 +189,27 @@ public DefaultLocalizationConfiguration() { set("Description.Promote", "&a/Clan promote %name&b - to promote player %name of your clan"); set("Description.Requests", "&a/Clan requests&b - to see list of all requests to join your clan"); set("Description.Sethome", "&a/Clan sethome&b - to set home location of your clan"); - set("Description.Settings", "&a/Clan settings help&b - to show help about settings of your clan"); + set("Description.Settreasure", "&a/Clan settreasure&b - to set treasure location of your clan"); + // @todo add 1000$ for PluginConfig + set("Description.CalculateLevel", "&a/Clan calclvl&b - to force recalculate clan level for 1000$"); + set("Description.Settings", "&a/Clan setting help&b - to show help about settings of your clan"); set("Description.Top", "&a/Clan top&b - top of all clans"); set("Description.Withdraw", "&a/Clan withdraw %value&b - to withdraw money from your clan"); + + set("Description.Admin.calclvl", "&a/ClAd calclvl %name&b - force recalculate %name clan level"); + set("Description.Admin.debugInfo", "&a/ClAd debuginfo %name&b - show debug info about clan %name"); + set("Description.Admin.delete", "&a/ClAd calclvl %name&b - force delete clan %name"); + set("Description.Admin.forceJoin", "&a/ClAd forcejoin %name&b - force join to clan %name"); + set("Description.Admin.help", "&a/ClAd help - to show this menu"); + set("Description.Admin.treasure", "&a/ClAd home %name&b - teleport to treasure of clan %name"); + set("Description.Admin.home", "&a/ClAd home %name&b - teleport to home of clan %name"); + set("Description.Admin.info", "&a/ClAd info %name&b - show info about clan %name"); + set("Description.Admin.level", "&a/ClAd level %name&b %level - to set %level for clan %name"); + set("Description.Admin.list", "&a/ClAd list - to show all server clans"); + set("Description.Admin.mates", "&a/ClAd mates %name&b - to show all mates in clan %name"); + set("Description.Admin.requests", "&a/ClAd requests %name&b - to show all requests in clan %name"); + + set("Description.General.version", "&a/UselessClan version - to show plugin version"); setComments("Description", List.of(" ", " ")); } } diff --git a/src/main/java/io/github/lofrol/UselessClan/UselessClan.java b/src/main/java/io/github/lofrol/UselessClan/UselessClan.java index d70eb11..1dcc869 100644 --- a/src/main/java/io/github/lofrol/UselessClan/UselessClan.java +++ b/src/main/java/io/github/lofrol/UselessClan/UselessClan.java @@ -1,5 +1,6 @@ package io.github.lofrol.UselessClan; +import io.github.lofrol.UselessClan.ClanCommands.PluginCommand; import io.github.lofrol.UselessClan.Extensions.ClanManagerExtension; import io.github.lofrol.UselessClan.External.UselessClanPlaceholder; import io.github.lofrol.UselessClan.ClanCommands.ClanAdminCommand; @@ -8,12 +9,18 @@ import io.github.lofrol.UselessClan.Listeners.UselessListeners; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import net.milkbowl.vault.economy.Economy; +import org.bukkit.command.Command; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.Nullable; +import java.util.HashSet; +import java.util.Set; import java.util.logging.Level; +import static org.bukkit.Bukkit.getServer; + public final class UselessClan extends JavaPlugin { @Nullable @@ -27,10 +34,14 @@ public final class UselessClan extends JavaPlugin { private static SerializationManager SerilManager; + private static Set ActiveTasks; + + private static Set RegisteredCommands; + @Override public void onEnable() { if (!checkHardDepends()) { - getPluginLoader().disablePlugin(this); + getPluginLoader().disablePlugin(this); } SerilManager = new SerializationManager(this); @@ -41,12 +52,7 @@ public void onEnable() { getServer().getPluginManager().registerEvents(new UselessListeners(), this); - if (ClanCommand.CreateDefaultInst()) getLogger().log(Level.INFO, "Clan Command Loaded successfully!"); - else getLogger().log(Level.SEVERE, "Clan Command cant be loaded!"); - if (ClanAdminCommand.CreateDefaultInts()) getLogger().log(Level.INFO, "Admin Clan Command Loaded successfully!"); - else getLogger().log(Level.SEVERE, "Admin Clan Command cant be loaded!"); - if (ClanChatCommand.CreateDefaultInst()) getLogger().log(Level.INFO, "Clan Chat Command Loaded successfully!"); - else getLogger().log(Level.SEVERE, "Clan Chat Command cant be loaded!"); + if (RegisteredCommands == null) registerAllCommands(); MainManager.LoadClans(); runServerTasks(); @@ -59,6 +65,24 @@ public void onDisable() { MainManager.SaveClans(); } + public void reloadPlugin() { + onDisable(); + for (var tempPlayer : getServer().getOnlinePlayers()) { + MainManager.OnPlayerLeave(tempPlayer); + } + MainManager.getServerClans().clear(); + MainManager.getOnlineClanPlayers().clear(); + for (var tempTask : ActiveTasks) { + tempTask.cancel(); + } + ActiveTasks.clear(); + reloadConfig(); + + onEnable(); + for (var tempPlayer : getServer().getOnlinePlayers()) { + MainManager.OnPlayerJoin(tempPlayer); + } + } /* * Getters section */ @@ -110,26 +134,60 @@ private boolean checkHardDepends() { return true; } + private void registerAllCommands() { + RegisteredCommands = new HashSet<>(); + Command tempClanCommand = ClanCommand.CreateDefaultInst(); + if (getServer().getCommandMap().register("[UselessClan]", tempClanCommand)) { + getLogger().log(Level.INFO, "Clan Command Loaded successfully!"); + RegisteredCommands.add(tempClanCommand); + } + else getLogger().log(Level.SEVERE, "Clan Command cant be loaded!"); + + Command tempClanAdminCommand = ClanAdminCommand.CreateDefaultInts(); + if (getServer().getCommandMap().register("[UselessClan]", tempClanAdminCommand)) { + getLogger().log(Level.INFO, "Admin Clan Command Loaded successfully!"); + RegisteredCommands.add(tempClanAdminCommand); + } + else getLogger().log(Level.SEVERE, "Admin Clan Command cant be loaded!"); + + Command tempClanChatCommand = ClanChatCommand.CreateDefaultInst(); + if (getServer().getCommandMap().register("[UselessClan]", tempClanChatCommand)) { + getLogger().log(Level.INFO, "Clan Chat Command Loaded successfully!"); + RegisteredCommands.add(tempClanChatCommand); + } + else getLogger().log(Level.SEVERE, "Clan Chat Command cant be loaded!"); + + Command tempPluginCommand = PluginCommand.CreateDefaultInst(); + if (getServer().getCommandMap().register("[UselessClan]", tempPluginCommand)) { + getLogger().log(Level.INFO, "Clan Plugin Command Loaded successfully!"); + RegisteredCommands.add(tempPluginCommand); + } + else getLogger().log(Level.SEVERE, "Clan Plugin Command cant be loaded!"); + } + private void runServerTasks() { - getServer().getScheduler().runTaskTimer(this, () -> { + ActiveTasks = new HashSet<>(); + ActiveTasks.add(getServer().getScheduler().runTaskTimer(this, () -> { getMainManager().SaveClans(); getLogger().log(Level.INFO, "Clans was saved by AutoSave"); }, getConfigManager().getClanConfig().getAutoSaveDelay(), - getConfigManager().getClanConfig().getAutoSaveDelay()); + getConfigManager().getClanConfig().getAutoSaveDelay())); if (getConfigManager().getClanConfig().isNeedCalculateClanLevels()) { - getServer().getScheduler().runTaskTimerAsynchronously(this, () -> { - getMainManager().CalculateAllClansLevels(); }, + ActiveTasks.add(getServer().getScheduler().runTaskTimerAsynchronously(this, () -> { + getMainManager().CalculateAllClansLevels( + getConfigManager().getClanConfig().isUseExtendCalculateClanLevels()); + }, getConfigManager().getClanConfig().getCalcClanLvlDelay(), - getConfigManager().getClanConfig().getCalcClanLvlDelay()); + getConfigManager().getClanConfig().getCalcClanLvlDelay())); } - getServer().getScheduler().runTaskTimerAsynchronously(this, () -> { + ActiveTasks.add(getServer().getScheduler().runTaskTimerAsynchronously(this, () -> { getMainManager().createClansBackups(); }, - 0, getConfigManager().getClanConfig().getBackupDelay()); + 0, getConfigManager().getClanConfig().getBackupDelay())); - getServer().getScheduler().runTaskTimerAsynchronously(this, () -> { + ActiveTasks.add(getServer().getScheduler().runTaskTimerAsynchronously(this, () -> { getMainManager().getTopClans().CalculateTop(); }, - 0, getConfigManager().getClanConfig().getCalcClanTopDelay()); + 0, getConfigManager().getClanConfig().getCalcClanTopDelay())); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7cdac22..2c3d5ca 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: UselessClan -version: 1.0 +version: 1.1 main: io.github.lofrol.UselessClan.UselessClan api-version: 1.19 softdepend: [ ]