diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index 017ab46..9c24d9c 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -539,7 +539,7 @@
-
+
@@ -2242,7 +2242,7 @@
-
+
@@ -2550,7 +2550,7 @@
-
+
@@ -3316,7 +3316,7 @@
-
+
diff --git a/.idea/scopes/Config_files.xml b/.idea/scopes/Config_files.xml
new file mode 100644
index 0000000..b774958
--- /dev/null
+++ b/.idea/scopes/Config_files.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
deleted file mode 100644
index 1cda7c8..0000000
--- a/.idea/workspace.xml
+++ /dev/null
@@ -1,769 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- C:\Users\Antonin\AppData\Roaming\Subversion
-
-
-
-
- 1640711331713
-
-
- 1640711331713
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1643734096292
-
-
-
- 1643734096292
-
-
- 1644090056417
-
-
-
- 1644090056417
-
-
- 1644091470934
-
-
-
- 1644091470934
-
-
- 1644103105430
-
-
-
- 1644103105430
-
-
- 1644233336973
-
-
-
- 1644233336973
-
-
- 1644234547114
-
-
-
- 1644234547114
-
-
- 1644422915651
-
-
-
- 1644422915651
-
-
- 1644436426611
-
-
-
- 1644436426611
-
-
- 1644446452142
-
-
-
- 1644446452142
-
-
- 1644497736648
-
-
-
- 1644497736648
-
-
- 1644574740499
-
-
-
- 1644574740499
-
-
- 1644592419216
-
-
-
- 1644592419216
-
-
- 1644855719852
-
-
-
- 1644855719852
-
-
- 1644861263034
-
-
-
- 1644861263034
-
-
- 1645104280559
-
-
-
- 1645104280559
-
-
- 1645461080266
-
-
-
- 1645461080266
-
-
- 1645534073964
-
-
-
- 1645534073964
-
-
- 1645535120886
-
-
-
- 1645535120886
-
-
- 1645546744706
-
-
-
- 1645546744706
-
-
- 1645604682043
-
-
-
- 1645604682043
-
-
- 1645609462466
-
-
-
- 1645609462466
-
-
- 1645692215707
-
-
-
- 1645692215707
-
-
- 1645692500871
-
-
-
- 1645692500871
-
-
- 1645692734918
-
-
-
- 1645692734918
-
-
- 1645695983533
-
-
-
- 1645695983533
-
-
- 1645698248934
-
-
-
- 1645698248934
-
-
- 1645791738824
-
-
-
- 1645791738824
-
-
- 1645873698731
-
-
-
- 1645873698731
-
-
- 1646059274185
-
-
-
- 1646059274185
-
-
- 1646081334887
-
-
-
- 1646081334887
-
-
- 1646293799015
-
-
-
- 1646293799015
-
-
- 1646302108556
-
-
-
- 1646302108556
-
-
- 1646302771671
-
-
-
- 1646302771671
-
-
- 1646313303431
-
-
-
- 1646313303431
-
-
- 1646382712202
-
-
-
- 1646382712202
-
-
- 1646385923915
-
-
-
- 1646385923915
-
-
- 1647501789511
-
-
-
- 1647501789511
-
-
- 1647596708846
-
-
-
- 1647596708846
-
-
- 1647597824079
-
-
-
- 1647597824079
-
-
- 1647632764658
-
-
-
- 1647632764658
-
-
- 1647801919201
-
-
-
- 1647801919201
-
-
- 1647808181550
-
-
-
- 1647808181550
-
-
- 1647808525498
-
-
-
- 1647808525498
-
-
- 1647809216534
-
-
-
- 1647809216535
-
-
- 1650206946667
-
-
-
- 1650206946668
-
-
- 1650207441056
-
-
-
- 1650207441056
-
-
- 1650214612668
-
-
-
- 1650214612668
-
-
- 1650214657488
-
-
-
- 1650214657488
-
-
- 1650439654753
-
-
-
- 1650439654754
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/VoteReward.java b/src/main/java/fr/lataverne/votereward/VoteReward.java
index 912aa96..0eb0fe6 100644
--- a/src/main/java/fr/lataverne/votereward/VoteReward.java
+++ b/src/main/java/fr/lataverne/votereward/VoteReward.java
@@ -1,6 +1,7 @@
package fr.lataverne.votereward;
import fr.lataverne.votereward.commands.VoteRewardCommand;
+import fr.lataverne.votereward.commands.VoteRewardConsoleCommand;
import fr.lataverne.votereward.managers.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -88,6 +89,7 @@ public void onEnable() {
this.chatResponseManager = new ChatResponseManager(this);
new VoteRewardCommand();
+ new VoteRewardConsoleCommand();
Listener eventListener = new EventListener(this);
Bukkit.getPluginManager().registerEvents(eventListener, this);
diff --git a/src/main/java/fr/lataverne/votereward/commands/AdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/AdminCommand.java
deleted file mode 100644
index ffca238..0000000
--- a/src/main/java/fr/lataverne/votereward/commands/AdminCommand.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package fr.lataverne.votereward.commands;
-
-import fr.lataverne.votereward.commands.admin.BagAdminCommand;
-import fr.lataverne.votereward.commands.admin.FakeVoteCommand;
-import fr.lataverne.votereward.commands.admin.RewardsGroupAdminCommand;
-import fr.lataverne.votereward.commands.admin.RewardsGroupsAdminCommand;
-import org.jetbrains.annotations.NotNull;
-
-public class AdminCommand extends CompositeCommand {
-
- public AdminCommand(@NotNull CompositeCommand parent) {
- super(parent, "admin");
- }
-
- @Override
- protected void setup() {
- this.setPermission("votereward.admin");
-
- new FakeVoteCommand(this);
- new BagAdminCommand(this);
- new RewardsGroupsAdminCommand(this);
- new RewardsGroupAdminCommand(this);
- }
-}
diff --git a/src/main/java/fr/lataverne/votereward/commands/BagCommand.java b/src/main/java/fr/lataverne/votereward/commands/BagCommand.java
deleted file mode 100644
index 1137f0d..0000000
--- a/src/main/java/fr/lataverne/votereward/commands/BagCommand.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package fr.lataverne.votereward.commands;
-
-import fr.lataverne.votereward.commands.bag.GetBagCommand;
-import fr.lataverne.votereward.commands.bag.SeeBagCommand;
-import org.jetbrains.annotations.NotNull;
-
-public class BagCommand extends CompositeCommand {
-
- protected BagCommand(@NotNull CompositeCommand parent) {
- super(parent, "bag");
- }
-
- @Override
- protected void setup() {
- this.setPermission("votereward.bag");
- this.setOnlyPlayer(true);
-
- new GetBagCommand(this);
- new SeeBagCommand(this);
- }
-}
diff --git a/src/main/java/fr/lataverne/votereward/commands/DynamicCommand.java b/src/main/java/fr/lataverne/votereward/commands/DynamicCommand.java
deleted file mode 100644
index d3fee75..0000000
--- a/src/main/java/fr/lataverne/votereward/commands/DynamicCommand.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package fr.lataverne.votereward.commands;
-
-@FunctionalInterface
-public interface DynamicCommand {
-
- boolean isDynamicCommand(String label);
-}
diff --git a/src/main/java/fr/lataverne/votereward/commands/VoteRewardCommand.java b/src/main/java/fr/lataverne/votereward/commands/VoteRewardCommand.java
index 9b65a44..998623e 100644
--- a/src/main/java/fr/lataverne/votereward/commands/VoteRewardCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/VoteRewardCommand.java
@@ -1,5 +1,11 @@
package fr.lataverne.votereward.commands;
+import fr.lataverne.votereward.commands.common.ConfirmCommand;
+import fr.lataverne.votereward.commands.votereward.AdminCommand;
+import fr.lataverne.votereward.commands.votereward.BagCommand;
+import fr.lataverne.votereward.commands.votereward.TopVoteCommand;
+import fr.lataverne.votereward.commands.votereward.VoteCommand;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
@@ -18,12 +24,10 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
@Override
protected void setup() {
- new BagCommand(this);
- new AdminCommand(this);
- new ConfirmCommand(this);
- new TopVoteCommand(this);
- new VoteCommand(this);
-
- new AddVoteConsoleCommand(this);
+ this.addChildren(new BagCommand(this));
+ this.addChildren(new AdminCommand(this));
+ this.addChildren(new ConfirmCommand(this));
+ this.addChildren(new TopVoteCommand(this));
+ this.addChildren(new VoteCommand(this));
}
}
diff --git a/src/main/java/fr/lataverne/votereward/commands/AddVoteConsoleCommand.java b/src/main/java/fr/lataverne/votereward/commands/VoteRewardConsoleCommand.java
similarity index 84%
rename from src/main/java/fr/lataverne/votereward/commands/AddVoteConsoleCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/VoteRewardConsoleCommand.java
index b761741..9860c75 100644
--- a/src/main/java/fr/lataverne/votereward/commands/AddVoteConsoleCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/VoteRewardConsoleCommand.java
@@ -4,6 +4,7 @@
import fr.lataverne.votereward.objects.Bag;
import fr.lataverne.votereward.objects.rewards.Reward;
import fr.lataverne.votereward.objects.votes.Vote;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
@@ -14,10 +15,10 @@
import java.time.LocalDate;
import java.util.List;
-public class AddVoteConsoleCommand extends CompositeCommand {
+public class VoteRewardConsoleCommand extends CompositeCommand {
- protected AddVoteConsoleCommand(@NotNull CompositeCommand parent) {
- super(parent, "addVote");
+ public VoteRewardConsoleCommand() {
+ super("votereward-console", "vr-console", "vrc");
}
@Override
@@ -59,7 +60,9 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
" voted but he has never played on the server");
}
} else {
- return this.parent.execute(sender, label, args);
+ sender.sendMessage(this.plugin.getConfig()
+ .getString("messages.error.no-permission")
+ .replace("[permission]", this.getPermission()));
}
return true;
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/BagAdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/admin/BagAdminCommand.java
deleted file mode 100644
index a151c1d..0000000
--- a/src/main/java/fr/lataverne/votereward/commands/admin/BagAdminCommand.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package fr.lataverne.votereward.commands.admin;
-
-import fr.lataverne.votereward.commands.CompositeCommand;
-import fr.lataverne.votereward.commands.admin.bag.GetBagAdminCommand;
-import fr.lataverne.votereward.commands.admin.bag.SeeBagAdminCommand;
-import org.jetbrains.annotations.NotNull;
-
-public class BagAdminCommand extends CompositeCommand {
-
- public BagAdminCommand(@NotNull CompositeCommand parent) {
- super(parent, "bag");
- }
-
- @Override
- protected void setup() {
- this.setPermission("votereward.admin.bag");
- this.setOnlyPlayer(true);
-
- new GetBagAdminCommand(this);
- new SeeBagAdminCommand(this);
- }
-}
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/DynRewardsGroupAdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/admin/DynRewardsGroupAdminCommand.java
deleted file mode 100644
index 8ab22e3..0000000
--- a/src/main/java/fr/lataverne/votereward/commands/admin/DynRewardsGroupAdminCommand.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package fr.lataverne.votereward.commands.admin;
-
-import fr.lataverne.votereward.commands.CompositeCommand;
-import fr.lataverne.votereward.commands.DynamicCommand;
-import fr.lataverne.votereward.commands.admin.rewardsgroup.AddRewardAdminCommand;
-import fr.lataverne.votereward.commands.admin.rewardsgroup.RewardAdminCommand;
-import fr.lataverne.votereward.commands.admin.rewardsgroup.SeeRewardsGroupAdminCommand;
-import org.jetbrains.annotations.NotNull;
-
-public class DynRewardsGroupAdminCommand extends CompositeCommand implements DynamicCommand {
-
- public DynRewardsGroupAdminCommand(@NotNull CompositeCommand parent) {
- super(parent, "");
- }
-
- @Override
- public boolean isDynamicCommand(String label) {
- return this.plugin.getRewardsGroupManager()
- .getRewardsGroups()
- .keySet()
- .stream()
- .anyMatch(subCmdLabel -> subCmdLabel.equalsIgnoreCase(label));
- }
-
- @Override
- protected void setup() {
- this.setPermission("votereward.admin.rewardsgroup");
-
- new AddRewardAdminCommand(this);
- new SeeRewardsGroupAdminCommand(this);
- new RewardAdminCommand(this);
- }
-}
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/RewardsGroupsAdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/admin/RewardsGroupsAdminCommand.java
deleted file mode 100644
index 6e330c1..0000000
--- a/src/main/java/fr/lataverne/votereward/commands/admin/RewardsGroupsAdminCommand.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package fr.lataverne.votereward.commands.admin;
-
-import fr.lataverne.votereward.commands.CompositeCommand;
-import fr.lataverne.votereward.commands.admin.rewardsgroups.ActivateRewardsGroupAdminCommand;
-import fr.lataverne.votereward.commands.admin.rewardsgroups.CreateRewardsGroupAdminCommand;
-import fr.lataverne.votereward.commands.admin.rewardsgroups.DeleteRewardsGroupAdminCommand;
-import fr.lataverne.votereward.commands.admin.rewardsgroups.RewardsGroupListAdminCommand;
-import org.bukkit.command.CommandSender;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.List;
-
-public class RewardsGroupsAdminCommand extends CompositeCommand {
-
- public RewardsGroupsAdminCommand(@NotNull CompositeCommand parent) {
- super(parent, "rewardsgroups", "rgroups");
- }
-
- @Override
- protected boolean execute(@NotNull CommandSender sender, @NotNull String label, @NotNull List args) {
- List cmdArgs = args.subList(this.level, args.size());
-
- if (cmdArgs.size() == 1) {
- sender.sendMessage(this.plugin.getConfig().getString("messages.admin.rewards-group.unknown-rewards-group"));
- } else {
- this.misuseCommand(sender);
- }
-
- return true;
- }
-
- @Override
- protected void setup() {
- this.setPermission("votereward.admin.rewardsgroups");
-
- new CreateRewardsGroupAdminCommand(this);
- new DeleteRewardsGroupAdminCommand(this);
- new RewardsGroupListAdminCommand(this);
- new ActivateRewardsGroupAdminCommand(this);
- }
-}
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/bag/package-info.java b/src/main/java/fr/lataverne/votereward/commands/admin/bag/package-info.java
deleted file mode 100644
index 241f5e2..0000000
--- a/src/main/java/fr/lataverne/votereward/commands/admin/bag/package-info.java
+++ /dev/null
@@ -1 +0,0 @@
-package fr.lataverne.votereward.commands.admin.bag;
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/package-info.java b/src/main/java/fr/lataverne/votereward/commands/admin/package-info.java
deleted file mode 100644
index 467720a..0000000
--- a/src/main/java/fr/lataverne/votereward/commands/admin/package-info.java
+++ /dev/null
@@ -1 +0,0 @@
-package fr.lataverne.votereward.commands.admin;
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/RewardAdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/RewardAdminCommand.java
deleted file mode 100644
index 9eb9288..0000000
--- a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/RewardAdminCommand.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package fr.lataverne.votereward.commands.admin.rewardsgroup;
-
-import fr.lataverne.votereward.commands.CompositeCommand;
-import fr.lataverne.votereward.commands.admin.rewardsgroup.reward.ModifyAdminCommand;
-import org.jetbrains.annotations.NotNull;
-
-public class RewardAdminCommand extends CompositeCommand {
-
- public RewardAdminCommand(@NotNull CompositeCommand parent) {
- super(parent, "reward");
- }
-
- @Override
- protected void setup() {
- this.setPermission("votereward.admin.rewardsgroup..reward");
-
- new ModifyAdminCommand(this);
- }
-}
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/package-info.java b/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/package-info.java
deleted file mode 100644
index c4d70bf..0000000
--- a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/package-info.java
+++ /dev/null
@@ -1 +0,0 @@
-package fr.lataverne.votereward.commands.admin.rewardsgroup;
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/reward/modify/DynRewardListAdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/reward/modify/DynRewardListAdminCommand.java
deleted file mode 100644
index 33e8984..0000000
--- a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/reward/modify/DynRewardListAdminCommand.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package fr.lataverne.votereward.commands.admin.rewardsgroup.reward.modify;
-
-import fr.lataverne.votereward.commands.CompositeCommand;
-import fr.lataverne.votereward.commands.DynamicCommand;
-import org.jetbrains.annotations.NotNull;
-
-public class DynRewardListAdminCommand extends CompositeCommand implements DynamicCommand {
-
- public DynRewardListAdminCommand(@NotNull CompositeCommand parent) {
- super(parent, "");
- }
-
- @Override
- public boolean isDynamicCommand(String label) {
- try {
- Double.parseDouble(label);
- return true;
- } catch (NumberFormatException ignored) {
- return false;
- }
- }
-
- @Override
- protected void setup() {
- this.inheritPermission();
-
- new PercentageAdminCommand(this);
- }
-}
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/reward/modify/package-info.java b/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/reward/modify/package-info.java
deleted file mode 100644
index c7f89e9..0000000
--- a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/reward/modify/package-info.java
+++ /dev/null
@@ -1 +0,0 @@
-package fr.lataverne.votereward.commands.admin.rewardsgroup.reward.modify;
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/reward/package-info.java b/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/reward/package-info.java
deleted file mode 100644
index e0a279f..0000000
--- a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/reward/package-info.java
+++ /dev/null
@@ -1 +0,0 @@
-package fr.lataverne.votereward.commands.admin.rewardsgroup.reward;
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroups/package-info.java b/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroups/package-info.java
deleted file mode 100644
index 5414c07..0000000
--- a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroups/package-info.java
+++ /dev/null
@@ -1 +0,0 @@
-package fr.lataverne.votereward.commands.admin.rewardsgroups;
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/commands/bag/package-info.java b/src/main/java/fr/lataverne/votereward/commands/bag/package-info.java
deleted file mode 100644
index 4f90163..0000000
--- a/src/main/java/fr/lataverne/votereward/commands/bag/package-info.java
+++ /dev/null
@@ -1 +0,0 @@
-package fr.lataverne.votereward.commands.bag;
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/commands/ConfirmCommand.java b/src/main/java/fr/lataverne/votereward/commands/common/ConfirmCommand.java
similarity index 89%
rename from src/main/java/fr/lataverne/votereward/commands/ConfirmCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/common/ConfirmCommand.java
index efe77d6..a7ea061 100644
--- a/src/main/java/fr/lataverne/votereward/commands/ConfirmCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/common/ConfirmCommand.java
@@ -1,5 +1,7 @@
-package fr.lataverne.votereward.commands;
+package fr.lataverne.votereward.commands.common;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
+import fr.lataverne.votereward.utils.commands.ConfirmableCommand;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.bukkit.Bukkit;
@@ -15,7 +17,7 @@ public class ConfirmCommand extends CompositeCommand {
private final Map> toBeConfirmed = new HashMap<>();
- protected ConfirmCommand(@NotNull CompositeCommand parent) {
+ public ConfirmCommand(@NotNull CompositeCommand parent) {
super(parent, "confirm");
}
diff --git a/src/main/java/fr/lataverne/votereward/commands/HelpCommand.java b/src/main/java/fr/lataverne/votereward/commands/common/HelpCommand.java
similarity index 84%
rename from src/main/java/fr/lataverne/votereward/commands/HelpCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/common/HelpCommand.java
index ea37e8f..e1e4eca 100644
--- a/src/main/java/fr/lataverne/votereward/commands/HelpCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/common/HelpCommand.java
@@ -1,5 +1,6 @@
-package fr.lataverne.votereward.commands;
+package fr.lataverne.votereward.commands.common;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
@@ -29,7 +30,7 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String label, @No
}
sender.sendMessage(" ");
- sender.sendMessage(HelpCommand.HELP_HEADER);
+ sender.sendMessage(HELP_HEADER);
if (this.parent.hasSubCommands()) {
Collection subCommands = this.parent.getSubCommands();
@@ -56,17 +57,17 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String label, @No
String usage = this.plugin.getConfig().getString("messages.help.usage");
String descriptionMessage = this.plugin.getConfig()
.getString("messages.help.description")
- .replace(HelpCommand.PARENT_COMMAND_DESCRIPTION, commandDescription);
+ .replace(PARENT_COMMAND_DESCRIPTION, commandDescription);
usage = commandParameters == null || commandParameters.isEmpty()
- ? usage.replace(HelpCommand.PARENT_COMMAND_USAGE, commandUsage)
- : usage.replace(HelpCommand.PARENT_COMMAND_USAGE, commandUsage + " " + commandParameters);
+ ? usage.replace(PARENT_COMMAND_USAGE, commandUsage)
+ : usage.replace(PARENT_COMMAND_USAGE, commandUsage + " " + commandParameters);
sender.sendMessage(usage);
sender.sendMessage(descriptionMessage);
}
- sender.sendMessage(HelpCommand.HELP_FOOTER);
+ sender.sendMessage(HELP_FOOTER);
return true;
}
@@ -74,7 +75,7 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String label, @No
@Override
public @NotNull String getUsage() {
String usage = super.getUsage();
- return usage.replace(HelpCommand.PARENT_COMMAND_USAGE, this.parent.getUsage());
+ return usage.replace(PARENT_COMMAND_USAGE, this.parent.getUsage());
}
@Override
diff --git a/src/main/java/fr/lataverne/votereward/commands/common/package-info.java b/src/main/java/fr/lataverne/votereward/commands/common/package-info.java
new file mode 100644
index 0000000..11889bb
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/commands/common/package-info.java
@@ -0,0 +1 @@
+package fr.lataverne.votereward.commands.common;
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/commands/votereward/AdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/AdminCommand.java
new file mode 100644
index 0000000..0b0b782
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/AdminCommand.java
@@ -0,0 +1,23 @@
+package fr.lataverne.votereward.commands.votereward;
+
+import fr.lataverne.votereward.commands.votereward.admin.BagCommand;
+import fr.lataverne.votereward.commands.votereward.admin.FakeVoteCommand;
+import fr.lataverne.votereward.commands.votereward.admin.RewardsGroupCommand;
+import fr.lataverne.votereward.commands.votereward.admin.RewardsGroupsCommand;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
+import org.jetbrains.annotations.NotNull;
+
+public class AdminCommand extends CompositeCommand {
+
+ public AdminCommand(@NotNull CompositeCommand parent) {
+ super(parent, "admin");
+ }
+
+ @Override
+ protected void setup() {
+ this.addChildren(new FakeVoteCommand(this));
+ this.addChildren(new BagCommand(this));
+ this.addChildren(new RewardsGroupsCommand(this));
+ this.addChildren(new RewardsGroupCommand(this));
+ }
+}
diff --git a/src/main/java/fr/lataverne/votereward/commands/votereward/BagCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/BagCommand.java
new file mode 100644
index 0000000..2805ed8
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/BagCommand.java
@@ -0,0 +1,21 @@
+package fr.lataverne.votereward.commands.votereward;
+
+import fr.lataverne.votereward.commands.votereward.bag.GetCommand;
+import fr.lataverne.votereward.commands.votereward.bag.SeeCommand;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
+import org.jetbrains.annotations.NotNull;
+
+public class BagCommand extends CompositeCommand {
+
+ public BagCommand(@NotNull CompositeCommand parent) {
+ super(parent, "bag");
+ }
+
+ @Override
+ protected void setup() {
+ this.setOnlyPlayer(true);
+
+ this.addChildren(new GetCommand(this));
+ this.addChildren(new SeeCommand(this));
+ }
+}
diff --git a/src/main/java/fr/lataverne/votereward/commands/TopVoteCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/TopVoteCommand.java
similarity index 98%
rename from src/main/java/fr/lataverne/votereward/commands/TopVoteCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/votereward/TopVoteCommand.java
index d331377..b32a47c 100644
--- a/src/main/java/fr/lataverne/votereward/commands/TopVoteCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/TopVoteCommand.java
@@ -1,8 +1,9 @@
-package fr.lataverne.votereward.commands;
+package fr.lataverne.votereward.commands.votereward;
import fr.lataverne.votereward.VoteReward;
import fr.lataverne.votereward.objects.votes.ETimeRange;
import fr.lataverne.votereward.objects.votes.VotingUser;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
@@ -74,7 +75,6 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
@Override
protected void setup() {
- this.setPermission("votereward.topvote");
}
@Override
diff --git a/src/main/java/fr/lataverne/votereward/commands/VoteCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/VoteCommand.java
similarity index 96%
rename from src/main/java/fr/lataverne/votereward/commands/VoteCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/votereward/VoteCommand.java
index b9df377..eafda7a 100644
--- a/src/main/java/fr/lataverne/votereward/commands/VoteCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/VoteCommand.java
@@ -1,8 +1,9 @@
-package fr.lataverne.votereward.commands;
+package fr.lataverne.votereward.commands.votereward;
import fr.lataverne.votereward.VoteReward;
import fr.lataverne.votereward.objects.votes.ETimeRange;
import fr.lataverne.votereward.objects.votes.VotingUser;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
@@ -77,7 +78,6 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
@Override
protected void setup() {
- this.setPermission("votereward.vote");
}
@Override
diff --git a/src/main/java/fr/lataverne/votereward/commands/votereward/admin/BagCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/BagCommand.java
new file mode 100644
index 0000000..cbddf7f
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/BagCommand.java
@@ -0,0 +1,21 @@
+package fr.lataverne.votereward.commands.votereward.admin;
+
+import fr.lataverne.votereward.commands.votereward.admin.bag.GetCommand;
+import fr.lataverne.votereward.commands.votereward.admin.bag.SeeCommand;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
+import org.jetbrains.annotations.NotNull;
+
+public class BagCommand extends CompositeCommand {
+
+ public BagCommand(@NotNull CompositeCommand parent) {
+ super(parent, "bag");
+ }
+
+ @Override
+ protected void setup() {
+ this.setOnlyPlayer(true);
+
+ this.addChildren(new GetCommand(this));
+ this.addChildren(new SeeCommand(this));
+ }
+}
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/FakeVoteCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/FakeVoteCommand.java
similarity index 84%
rename from src/main/java/fr/lataverne/votereward/commands/admin/FakeVoteCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/votereward/admin/FakeVoteCommand.java
index ec417f0..b480cc9 100644
--- a/src/main/java/fr/lataverne/votereward/commands/admin/FakeVoteCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/FakeVoteCommand.java
@@ -1,8 +1,8 @@
-package fr.lataverne.votereward.commands.admin;
+package fr.lataverne.votereward.commands.votereward.admin;
-import fr.lataverne.votereward.commands.CompositeCommand;
import fr.lataverne.votereward.objects.Bag;
import fr.lataverne.votereward.objects.rewards.Reward;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -61,12 +61,12 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
if (amount > 1) {
message = Objects.requireNonNullElse(this.plugin.getConfig()
.getString("messages.admin.fakevote.multiple"), "messages.admin.fakevote.multiple");
- message = message.replace(FakeVoteCommand.NB_FAKEVOTE, Integer.toString(amount))
- .replace(FakeVoteCommand.NB_GIVEN_REWARDS, Integer.toString(nbGivenRewards));
+ message = message.replace(NB_FAKEVOTE, Integer.toString(amount))
+ .replace(NB_GIVEN_REWARDS, Integer.toString(nbGivenRewards));
} else {
message = Objects.requireNonNullElse(this.plugin.getConfig()
.getString("messages.admin.fakevote.one"), "messages.admin.fakevote.one");
- message = message.replace(FakeVoteCommand.NB_GIVEN_REWARDS, Integer.toString(nbGivenRewards));
+ message = message.replace(NB_GIVEN_REWARDS, Integer.toString(nbGivenRewards));
}
sender.sendMessage(message);
@@ -77,7 +77,6 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
@Override
protected void setup() {
- this.setPermission("votereward.admin.fakevote");
this.setOnlyPlayer(true);
}
}
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/RewardsGroupAdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/RewardsGroupCommand.java
similarity index 62%
rename from src/main/java/fr/lataverne/votereward/commands/admin/RewardsGroupAdminCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/votereward/admin/RewardsGroupCommand.java
index 1da0ef3..feb8c9b 100644
--- a/src/main/java/fr/lataverne/votereward/commands/admin/RewardsGroupAdminCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/RewardsGroupCommand.java
@@ -1,23 +1,22 @@
-package fr.lataverne.votereward.commands.admin;
+package fr.lataverne.votereward.commands.votereward.admin;
-import fr.lataverne.votereward.commands.CompositeCommand;
+import fr.lataverne.votereward.commands.votereward.admin.rewardsgroup.DynRewardsGroupCommand;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
-public class RewardsGroupAdminCommand extends CompositeCommand {
+public class RewardsGroupCommand extends CompositeCommand {
- public RewardsGroupAdminCommand(@NotNull CompositeCommand parent) {
+ public RewardsGroupCommand(@NotNull CompositeCommand parent) {
super(parent, "rewardsgroup", "rgroup");
}
@Override
protected void setup() {
- this.setPermission("votereward.admin.rewardsgroup");
-
- new DynRewardsGroupAdminCommand(this);
+ this.addChildren(new DynRewardsGroupCommand(this));
}
@Override
diff --git a/src/main/java/fr/lataverne/votereward/commands/votereward/admin/RewardsGroupsCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/RewardsGroupsCommand.java
new file mode 100644
index 0000000..cbdb288
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/RewardsGroupsCommand.java
@@ -0,0 +1,39 @@
+package fr.lataverne.votereward.commands.votereward.admin;
+
+import fr.lataverne.votereward.commands.votereward.admin.rewardsgroups.ActivateCommand;
+import fr.lataverne.votereward.commands.votereward.admin.rewardsgroups.CreateCommand;
+import fr.lataverne.votereward.commands.votereward.admin.rewardsgroups.DeleteCommand;
+import fr.lataverne.votereward.commands.votereward.admin.rewardsgroups.ListCommand;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
+import org.bukkit.command.CommandSender;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+
+public class RewardsGroupsCommand extends CompositeCommand {
+
+ public RewardsGroupsCommand(@NotNull CompositeCommand parent) {
+ super(parent, "rewardsgroups", "rgroups");
+ }
+
+ @Override
+ protected boolean execute(@NotNull CommandSender sender, @NotNull String label, @NotNull List args) {
+ List cmdArgs = args.subList(this.level, args.size());
+
+ if (cmdArgs.size() == 1) {
+ sender.sendMessage(this.plugin.getConfig().getString("messages.admin.rewards-group.unknown-rewards-group"));
+ } else {
+ this.misuseCommand(sender);
+ }
+
+ return true;
+ }
+
+ @Override
+ protected void setup() {
+ this.addChildren(new CreateCommand(this));
+ this.addChildren(new DeleteCommand(this));
+ this.addChildren(new ListCommand(this));
+ this.addChildren(new ActivateCommand(this));
+ }
+}
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/bag/GetBagAdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/bag/GetCommand.java
similarity index 88%
rename from src/main/java/fr/lataverne/votereward/commands/admin/bag/GetBagAdminCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/votereward/admin/bag/GetCommand.java
index c82ad67..556a6ce 100644
--- a/src/main/java/fr/lataverne/votereward/commands/admin/bag/GetBagAdminCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/bag/GetCommand.java
@@ -1,9 +1,9 @@
-package fr.lataverne.votereward.commands.admin.bag;
+package fr.lataverne.votereward.commands.votereward.admin.bag;
import fr.lataverne.votereward.Constant;
-import fr.lataverne.votereward.commands.CompositeCommand;
import fr.lataverne.votereward.managers.BagManager;
import fr.lataverne.votereward.objects.Bag;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
@@ -14,11 +14,11 @@
import java.util.ArrayList;
import java.util.List;
-public class GetBagAdminCommand extends CompositeCommand {
+public class GetCommand extends CompositeCommand {
private static final String PLAYER = "[player]";
- public GetBagAdminCommand(@NotNull CompositeCommand parent) {
+ public GetCommand(@NotNull CompositeCommand parent) {
super(parent, "get");
}
@@ -58,7 +58,6 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
@Override
protected void setup() {
- this.setPermission("votereward.admin.bag.get");
}
@Override
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/bag/SeeBagAdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/bag/SeeCommand.java
similarity index 86%
rename from src/main/java/fr/lataverne/votereward/commands/admin/bag/SeeBagAdminCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/votereward/admin/bag/SeeCommand.java
index 79b1128..9ae0b99 100644
--- a/src/main/java/fr/lataverne/votereward/commands/admin/bag/SeeBagAdminCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/bag/SeeCommand.java
@@ -1,8 +1,8 @@
-package fr.lataverne.votereward.commands.admin.bag;
+package fr.lataverne.votereward.commands.votereward.admin.bag;
-import fr.lataverne.votereward.commands.CompositeCommand;
import fr.lataverne.votereward.gui.BagView;
import fr.lataverne.votereward.objects.Bag;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
@@ -12,11 +12,11 @@
import java.util.ArrayList;
import java.util.List;
-public class SeeBagAdminCommand extends CompositeCommand {
+public class SeeCommand extends CompositeCommand {
private static final String PLAYER = "[player]";
- public SeeBagAdminCommand(@NotNull CompositeCommand parent) {
+ public SeeCommand(@NotNull CompositeCommand parent) {
super(parent, "see");
}
@@ -50,7 +50,6 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
@Override
protected void setup() {
- this.setPermission("votereward.admin.bag.see");
}
@Override
diff --git a/src/main/java/fr/lataverne/votereward/commands/votereward/admin/bag/package-info.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/bag/package-info.java
new file mode 100644
index 0000000..e6b2361
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/bag/package-info.java
@@ -0,0 +1 @@
+package fr.lataverne.votereward.commands.votereward.admin.bag;
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/commands/votereward/admin/package-info.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/package-info.java
new file mode 100644
index 0000000..12d5ad4
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/package-info.java
@@ -0,0 +1 @@
+package fr.lataverne.votereward.commands.votereward.admin;
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/DynRewardsGroupCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/DynRewardsGroupCommand.java
new file mode 100644
index 0000000..996b78a
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/DynRewardsGroupCommand.java
@@ -0,0 +1,27 @@
+package fr.lataverne.votereward.commands.votereward.admin.rewardsgroup;
+
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
+import fr.lataverne.votereward.utils.commands.DynamicCommand;
+import org.jetbrains.annotations.NotNull;
+
+public class DynRewardsGroupCommand extends DynamicCommand {
+
+ public DynRewardsGroupCommand(@NotNull CompositeCommand parent) {
+ super(parent, "");
+ }
+
+ @Override
+ public boolean isDynamicCommand(String label) {
+ return this.plugin.getRewardsGroupManager()
+ .getRewardsGroups()
+ .keySet()
+ .stream()
+ .anyMatch(subCmdLabel -> subCmdLabel.equalsIgnoreCase(label));
+ }
+
+ @Override
+ protected void setup() {
+ this.addChildren(new SeeCommand(this));
+ this.addChildren(new RewardsCommand(this));
+ }
+}
diff --git a/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/RewardsCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/RewardsCommand.java
new file mode 100644
index 0000000..e2b9b71
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/RewardsCommand.java
@@ -0,0 +1,19 @@
+package fr.lataverne.votereward.commands.votereward.admin.rewardsgroup;
+
+import fr.lataverne.votereward.commands.votereward.admin.rewardsgroup.rewards.AddCommand;
+import fr.lataverne.votereward.commands.votereward.admin.rewardsgroup.rewards.ModifyCommand;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
+import org.jetbrains.annotations.NotNull;
+
+public class RewardsCommand extends CompositeCommand {
+
+ public RewardsCommand(@NotNull CompositeCommand parent) {
+ super(parent, "rewards");
+ }
+
+ @Override
+ protected void setup() {
+ this.addChildren(new ModifyCommand(this));
+ this.addChildren(new AddCommand(this));
+ }
+}
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/SeeRewardsGroupAdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/SeeCommand.java
similarity index 79%
rename from src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/SeeRewardsGroupAdminCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/SeeCommand.java
index 4c63a42..d27763f 100644
--- a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/SeeRewardsGroupAdminCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/SeeCommand.java
@@ -1,8 +1,8 @@
-package fr.lataverne.votereward.commands.admin.rewardsgroup;
+package fr.lataverne.votereward.commands.votereward.admin.rewardsgroup;
-import fr.lataverne.votereward.commands.CompositeCommand;
import fr.lataverne.votereward.gui.admin.RewardsGroupView;
import fr.lataverne.votereward.objects.RewardsGroup;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -10,9 +10,9 @@
import java.util.List;
-public class SeeRewardsGroupAdminCommand extends CompositeCommand {
+public class SeeCommand extends CompositeCommand {
- public SeeRewardsGroupAdminCommand(@NotNull CompositeCommand parent) {
+ public SeeCommand(@NotNull CompositeCommand parent) {
super(parent, "see");
}
@@ -47,7 +47,6 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
@Override
protected void setup() {
- this.setPermission("votereward.admin.rewardsgroup..see");
this.setOnlyPlayer(true);
}
}
diff --git a/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/package-info.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/package-info.java
new file mode 100644
index 0000000..9493ba0
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/package-info.java
@@ -0,0 +1 @@
+package fr.lataverne.votereward.commands.votereward.admin.rewardsgroup;
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/AddRewardAdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/AddCommand.java
similarity index 84%
rename from src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/AddRewardAdminCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/AddCommand.java
index 7210550..19601eb 100644
--- a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/AddRewardAdminCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/AddCommand.java
@@ -1,9 +1,9 @@
-package fr.lataverne.votereward.commands.admin.rewardsgroup;
+package fr.lataverne.votereward.commands.votereward.admin.rewardsgroup.rewards;
-import fr.lataverne.votereward.commands.CompositeCommand;
import fr.lataverne.votereward.objects.AchievableReward;
import fr.lataverne.votereward.objects.RewardsGroup;
import fr.lataverne.votereward.objects.rewards.Reward;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -12,14 +12,14 @@
import java.util.List;
-public class AddRewardAdminCommand extends CompositeCommand {
+public class AddCommand extends CompositeCommand {
private static final String PERCENTAGE = "[percentage]";
private static final String REWARDS_GROUP_NAME = "[rewards-group-name]";
- public AddRewardAdminCommand(@NotNull CompositeCommand parent) {
- super(parent, "addreward", "add");
+ public AddCommand(@NotNull CompositeCommand parent) {
+ super(parent, "add");
}
@Override
@@ -48,7 +48,7 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
sender.sendMessage(this.plugin.getConfig()
.getString("messages.admin.rewards-group.add-reward.nothing-in-main-hand"));
} else {
- String rewardsGroupName = args.get(this.level - 2);
+ String rewardsGroupName = args.get(this.level - 3);
RewardsGroup rewardsGroup = this.plugin.getRewardsGroupManager().getRewardGroup(rewardsGroupName);
Reward reward = Reward.getReward(item);
@@ -70,7 +70,6 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
@Override
protected void setup() {
- this.setPermission("votereward.admin.rewardsgroup..addreward");
this.setOnlyPlayer(true);
}
}
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/reward/ModifyAdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/ModifyCommand.java
similarity index 61%
rename from src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/reward/ModifyAdminCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/ModifyCommand.java
index 3d77774..ede1429 100644
--- a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/reward/ModifyAdminCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/ModifyCommand.java
@@ -1,30 +1,32 @@
-package fr.lataverne.votereward.commands.admin.rewardsgroup.reward;
+package fr.lataverne.votereward.commands.votereward.admin.rewardsgroup.rewards;
-import fr.lataverne.votereward.commands.CompositeCommand;
-import fr.lataverne.votereward.commands.admin.rewardsgroup.reward.modify.DynRewardListAdminCommand;
+import fr.lataverne.votereward.commands.votereward.admin.rewardsgroup.rewards.modify.DynRewardListCommand;
import fr.lataverne.votereward.objects.RewardsGroup;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
-public class ModifyAdminCommand extends CompositeCommand {
+public class ModifyCommand extends CompositeCommand {
- public ModifyAdminCommand(@NotNull CompositeCommand parent) {
+ public ModifyCommand(@NotNull CompositeCommand parent) {
super(parent, "modify");
}
@Override
protected void setup() {
- this.setPermission("votereward.admin.rewardsgroup..reward.modify");
-
- new DynRewardListAdminCommand(this);
+ this.addChildren(new DynRewardListCommand(this));
}
@Override
protected @NotNull List tabComplete(@NotNull CommandSender sender, @NotNull String label, @NotNull List args) {
- RewardsGroup rewardsGroup = this.plugin.getRewardsGroupManager().getRewardGroup(args.get(this.level - 2));
+ RewardsGroup rewardsGroup = this.plugin.getRewardsGroupManager().getRewardGroup(args.get(this.level - 3));
+
+ if (rewardsGroup == null) {
+ return new ArrayList<>();
+ }
List cmdArgs = args.subList(this.level, args.size());
return cmdArgs.isEmpty() || cmdArgs.size() == 1
diff --git a/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/modify/DynRewardListCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/modify/DynRewardListCommand.java
new file mode 100644
index 0000000..7c4dc6d
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/modify/DynRewardListCommand.java
@@ -0,0 +1,27 @@
+package fr.lataverne.votereward.commands.votereward.admin.rewardsgroup.rewards.modify;
+
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
+import fr.lataverne.votereward.utils.commands.DynamicCommand;
+import org.jetbrains.annotations.NotNull;
+
+public class DynRewardListCommand extends DynamicCommand {
+
+ public DynRewardListCommand(@NotNull CompositeCommand parent) {
+ super(parent, "");
+ }
+
+ @Override
+ public boolean isDynamicCommand(String label) {
+ try {
+ Double.parseDouble(label);
+ return true;
+ } catch (NumberFormatException ignored) {
+ return false;
+ }
+ }
+
+ @Override
+ protected void setup() {
+ this.addChildren(new PercentageCommand(this));
+ }
+}
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/reward/modify/PercentageAdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/modify/PercentageCommand.java
similarity index 84%
rename from src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/reward/modify/PercentageAdminCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/modify/PercentageCommand.java
index 20e9bae..090c91d 100644
--- a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroup/reward/modify/PercentageAdminCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/modify/PercentageCommand.java
@@ -1,15 +1,15 @@
-package fr.lataverne.votereward.commands.admin.rewardsgroup.reward.modify;
+package fr.lataverne.votereward.commands.votereward.admin.rewardsgroup.rewards.modify;
-import fr.lataverne.votereward.commands.CompositeCommand;
import fr.lataverne.votereward.objects.RewardsGroup;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
-public class PercentageAdminCommand extends CompositeCommand {
+public class PercentageCommand extends CompositeCommand {
- public PercentageAdminCommand(@NotNull CompositeCommand parent) {
+ public PercentageCommand(@NotNull CompositeCommand parent) {
super(parent, "percentage");
}
diff --git a/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/modify/package-info.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/modify/package-info.java
new file mode 100644
index 0000000..252ccd6
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/modify/package-info.java
@@ -0,0 +1 @@
+package fr.lataverne.votereward.commands.votereward.admin.rewardsgroup.rewards.modify;
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/package-info.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/package-info.java
new file mode 100644
index 0000000..93569ca
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroup/rewards/package-info.java
@@ -0,0 +1 @@
+package fr.lataverne.votereward.commands.votereward.admin.rewardsgroup.rewards;
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroups/ActivateRewardsGroupAdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroups/ActivateCommand.java
similarity index 84%
rename from src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroups/ActivateRewardsGroupAdminCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroups/ActivateCommand.java
index b951656..3c32a7f 100644
--- a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroups/ActivateRewardsGroupAdminCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroups/ActivateCommand.java
@@ -1,18 +1,18 @@
-package fr.lataverne.votereward.commands.admin.rewardsgroups;
+package fr.lataverne.votereward.commands.votereward.admin.rewardsgroups;
-import fr.lataverne.votereward.commands.CompositeCommand;
import fr.lataverne.votereward.objects.RewardsGroup;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
-public class ActivateRewardsGroupAdminCommand extends CompositeCommand {
+public class ActivateCommand extends CompositeCommand {
private static final String REWARDS_GROUP_NAME = "[rewards-group-name]";
- public ActivateRewardsGroupAdminCommand(@NotNull CompositeCommand parent) {
+ public ActivateCommand(@NotNull CompositeCommand parent) {
super(parent, "activate");
}
@@ -44,7 +44,6 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
@Override
protected void setup() {
- this.setPermission("votereward.admin.rewardsgroups.activate");
}
@Override
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroups/CreateRewardsGroupAdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroups/CreateCommand.java
similarity index 60%
rename from src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroups/CreateRewardsGroupAdminCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroups/CreateCommand.java
index a513e6f..3a8e3d6 100644
--- a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroups/CreateRewardsGroupAdminCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroups/CreateCommand.java
@@ -1,16 +1,16 @@
-package fr.lataverne.votereward.commands.admin.rewardsgroups;
+package fr.lataverne.votereward.commands.votereward.admin.rewardsgroups;
-import fr.lataverne.votereward.commands.CompositeCommand;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
-public class CreateRewardsGroupAdminCommand extends CompositeCommand {
+public class CreateCommand extends CompositeCommand {
private static final String REWARDS_GROUP_NAME = "[rewards-group-name]";
- public CreateRewardsGroupAdminCommand(@NotNull CompositeCommand parent) {
+ public CreateCommand(@NotNull CompositeCommand parent) {
super(parent, "create");
}
@@ -27,19 +27,19 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
if (this.plugin.getRewardsGroupManager().getRewardsGroups().containsKey(name)) {
sender.sendMessage(this.plugin.getConfig()
.getString("messages.admin.rewards-group.rewards-group-already-exists")
- .replace(CreateRewardsGroupAdminCommand.REWARDS_GROUP_NAME, name));
+ .replace(REWARDS_GROUP_NAME, name));
return true;
}
this.plugin.getRewardsGroupManager().createNewRewardsGroup(name);
- sender.sendMessage(this.plugin.getConfig().getString("messages.admin.rewards-group.rewards-group-created")
- .replace(CreateRewardsGroupAdminCommand.REWARDS_GROUP_NAME, name));
+ sender.sendMessage(this.plugin.getConfig()
+ .getString("messages.admin.rewards-group.rewards-group-created")
+ .replace(REWARDS_GROUP_NAME, name));
return true;
}
@Override
protected void setup() {
- this.setPermission("votereward.admin.rewardsgroups.create");
}
}
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroups/DeleteRewardsGroupAdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroups/DeleteCommand.java
similarity index 83%
rename from src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroups/DeleteRewardsGroupAdminCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroups/DeleteCommand.java
index 6149148..3fd9b90 100644
--- a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroups/DeleteRewardsGroupAdminCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroups/DeleteCommand.java
@@ -1,35 +1,23 @@
-package fr.lataverne.votereward.commands.admin.rewardsgroups;
+package fr.lataverne.votereward.commands.votereward.admin.rewardsgroups;
-import fr.lataverne.votereward.commands.CompositeCommand;
-import fr.lataverne.votereward.commands.ConfirmableCommand;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
+import fr.lataverne.votereward.utils.commands.ConfirmableCommand;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
-public class DeleteRewardsGroupAdminCommand extends ConfirmableCommand {
+public class DeleteCommand extends ConfirmableCommand {
private static final String REWARDS_GROUP_NAME = "[rewards-group-name]";
- public DeleteRewardsGroupAdminCommand(@NotNull CompositeCommand parent) {
+ public DeleteCommand(@NotNull CompositeCommand parent) {
super(parent, "delete");
}
@Override
- protected void setup() {
- this.setPermission("votereward.admin.rewardsgroups.delete");
- }
-
- protected @NotNull List tabComplete(@NotNull CommandSender sender, @NotNull String label, @NotNull List args) {
- List cmdArgs = args.subList(this.level, args.size());
- return cmdArgs.isEmpty() || cmdArgs.size() == 1
- ? this.plugin.getRewardsGroupManager().getRewardsGroups().keySet().stream().toList()
- : new ArrayList<>();
- }
-
- @Override
- protected boolean toBeExecuted(@NotNull CommandSender sender, @NotNull String label, @NotNull List args) {
+ public boolean toBeExecuted(@NotNull CommandSender sender, @NotNull String label, @NotNull List args) {
List cmdArgs = args.subList(this.level, args.size());
String rewardsGroupName = cmdArgs.get(0);
@@ -48,6 +36,17 @@ protected boolean toBeExecuted(@NotNull CommandSender sender, @NotNull String la
return true;
}
+ protected void setup() {
+ this.setPermission("votereward.admin.rewardsgroups.delete");
+ }
+
+ protected @NotNull List tabComplete(@NotNull CommandSender sender, @NotNull String label, @NotNull List args) {
+ List cmdArgs = args.subList(this.level, args.size());
+ return cmdArgs.isEmpty() || cmdArgs.size() == 1
+ ? this.plugin.getRewardsGroupManager().getRewardsGroups().keySet().stream().toList()
+ : new ArrayList<>();
+ }
+
@Override
protected boolean validate(@NotNull CommandSender sender, @NotNull String label, @NotNull List args) {
List cmdArgs = args.subList(this.level, args.size());
diff --git a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroups/RewardsGroupListAdminCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroups/ListCommand.java
similarity index 73%
rename from src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroups/RewardsGroupListAdminCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroups/ListCommand.java
index 70f882e..ee92ec1 100644
--- a/src/main/java/fr/lataverne/votereward/commands/admin/rewardsgroups/RewardsGroupListAdminCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroups/ListCommand.java
@@ -1,7 +1,7 @@
-package fr.lataverne.votereward.commands.admin.rewardsgroups;
+package fr.lataverne.votereward.commands.votereward.admin.rewardsgroups;
-import fr.lataverne.votereward.commands.CompositeCommand;
import fr.lataverne.votereward.gui.admin.RewardsGroupListAdminView;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@@ -11,12 +11,12 @@
import java.util.List;
import java.util.Set;
-public class RewardsGroupListAdminCommand extends CompositeCommand {
+public class ListCommand extends CompositeCommand {
public static final String HEADER_LIST =
ChatColor.GREEN + "========== " + ChatColor.DARK_GREEN + "REWARDS GROUPS" + ChatColor.GREEN + " ==========";
- public RewardsGroupListAdminCommand(@NotNull CompositeCommand parent) {
+ public ListCommand(@NotNull CompositeCommand parent) {
super(parent, "list");
}
@@ -47,16 +47,14 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
} else {
String enabledRewardsGroup = this.plugin.getRewardsGroupManager().getEnabledRewardsGroupName();
- sender.sendMessage(RewardsGroupListAdminCommand.HEADER_LIST);
+ sender.sendMessage(HEADER_LIST);
for (String rewardsGroupName : rewardsGroups) {
StringBuilder message = new StringBuilder(rewardsGroupName);
- if (rewardsGroupName.equals(enabledRewardsGroup)) {
- message.insert(0, ChatColor.RED + "" + ChatColor.BOLD + "> ");
- } else {
- message.insert(0, ChatColor.YELLOW + " ");
- }
+ message.insert(0, rewardsGroupName.equals(enabledRewardsGroup)
+ ? ChatColor.RED + "" + ChatColor.BOLD + "> "
+ : ChatColor.YELLOW + " ");
sender.sendMessage(message.toString());
}
@@ -67,6 +65,5 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
@Override
protected void setup() {
- this.setPermission("votereward.admin.rewardsgroups.list");
}
}
diff --git a/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroups/package-info.java b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroups/package-info.java
new file mode 100644
index 0000000..5fa6213
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/admin/rewardsgroups/package-info.java
@@ -0,0 +1 @@
+package fr.lataverne.votereward.commands.votereward.admin.rewardsgroups;
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/commands/bag/GetBagCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/bag/GetCommand.java
similarity index 83%
rename from src/main/java/fr/lataverne/votereward/commands/bag/GetBagCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/votereward/bag/GetCommand.java
index ee77c5f..30e26b9 100644
--- a/src/main/java/fr/lataverne/votereward/commands/bag/GetBagCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/bag/GetCommand.java
@@ -1,9 +1,9 @@
-package fr.lataverne.votereward.commands.bag;
+package fr.lataverne.votereward.commands.votereward.bag;
import fr.lataverne.votereward.Constant;
-import fr.lataverne.votereward.commands.CompositeCommand;
import fr.lataverne.votereward.managers.BagManager;
import fr.lataverne.votereward.objects.Bag;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -11,9 +11,9 @@
import java.util.List;
-public class GetBagCommand extends CompositeCommand {
+public class GetCommand extends CompositeCommand {
- public GetBagCommand(@NotNull CompositeCommand parent) {
+ public GetCommand(@NotNull CompositeCommand parent) {
super(parent, "get");
}
@@ -46,6 +46,5 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String label, @No
@Override
protected void setup() {
- this.setPermission("votereward.bag.get");
}
}
diff --git a/src/main/java/fr/lataverne/votereward/commands/bag/SeeBagCommand.java b/src/main/java/fr/lataverne/votereward/commands/votereward/bag/SeeCommand.java
similarity index 77%
rename from src/main/java/fr/lataverne/votereward/commands/bag/SeeBagCommand.java
rename to src/main/java/fr/lataverne/votereward/commands/votereward/bag/SeeCommand.java
index 3dee38d..b2057ee 100644
--- a/src/main/java/fr/lataverne/votereward/commands/bag/SeeBagCommand.java
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/bag/SeeCommand.java
@@ -1,17 +1,17 @@
-package fr.lataverne.votereward.commands.bag;
+package fr.lataverne.votereward.commands.votereward.bag;
-import fr.lataverne.votereward.commands.CompositeCommand;
import fr.lataverne.votereward.gui.BagView;
import fr.lataverne.votereward.objects.Bag;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
-public class SeeBagCommand extends CompositeCommand {
+public class SeeCommand extends CompositeCommand {
- public SeeBagCommand(@NotNull CompositeCommand parent) {
+ public SeeCommand(@NotNull CompositeCommand parent) {
super(parent, "see");
}
@@ -35,6 +35,5 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
@Override
protected void setup() {
- this.setPermission("votereward.bag.see");
}
}
diff --git a/src/main/java/fr/lataverne/votereward/commands/votereward/bag/package-info.java b/src/main/java/fr/lataverne/votereward/commands/votereward/bag/package-info.java
new file mode 100644
index 0000000..c331f89
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/bag/package-info.java
@@ -0,0 +1 @@
+package fr.lataverne.votereward.commands.votereward.bag;
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/commands/votereward/package-info.java b/src/main/java/fr/lataverne/votereward/commands/votereward/package-info.java
new file mode 100644
index 0000000..3a3164c
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/commands/votereward/package-info.java
@@ -0,0 +1 @@
+package fr.lataverne.votereward.commands.votereward;
\ No newline at end of file
diff --git a/src/main/java/fr/lataverne/votereward/managers/CommandsManager.java b/src/main/java/fr/lataverne/votereward/managers/CommandsManager.java
index 5e1815f..bebbddd 100644
--- a/src/main/java/fr/lataverne/votereward/managers/CommandsManager.java
+++ b/src/main/java/fr/lataverne/votereward/managers/CommandsManager.java
@@ -1,7 +1,7 @@
package fr.lataverne.votereward.managers;
import fr.lataverne.votereward.VoteReward;
-import fr.lataverne.votereward.commands.CompositeCommand;
+import fr.lataverne.votereward.utils.commands.CompositeCommand;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
diff --git a/src/main/java/fr/lataverne/votereward/commands/CompositeCommand.java b/src/main/java/fr/lataverne/votereward/utils/commands/CompositeCommand.java
similarity index 88%
rename from src/main/java/fr/lataverne/votereward/commands/CompositeCommand.java
rename to src/main/java/fr/lataverne/votereward/utils/commands/CompositeCommand.java
index 94a296c..1a1a3cb 100644
--- a/src/main/java/fr/lataverne/votereward/commands/CompositeCommand.java
+++ b/src/main/java/fr/lataverne/votereward/utils/commands/CompositeCommand.java
@@ -1,6 +1,8 @@
-package fr.lataverne.votereward.commands;
+package fr.lataverne.votereward.utils.commands;
import fr.lataverne.votereward.VoteReward;
+import fr.lataverne.votereward.commands.common.ConfirmCommand;
+import fr.lataverne.votereward.commands.common.HelpCommand;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -17,14 +19,14 @@ public abstract class CompositeCommand extends Command {
protected final int level;
- @SuppressWarnings("FieldNotUsedInToString")
protected final @Nullable CompositeCommand parent;
- @SuppressWarnings("FieldNotUsedInToString")
protected final VoteReward plugin;
private final String configPath;
+ private final Collection parameters = new ArrayList<>();
+
private final Map subCommandAliases = new LinkedHashMap<>();
private final Map subCommands = new LinkedHashMap<>();
@@ -48,10 +50,11 @@ protected CompositeCommand(String label, String... aliases) {
this.setDescription(this.configPath + ".description");
this.setUsage(this.configPath + ".usage");
+ this.setPermission();
this.setup();
if (this.getSubCommand("help") == null && !"help".equals(label)) {
- new HelpCommand(this);
+ this.addChildren(new HelpCommand(this));
}
if (this.plugin.getCommand(label) == null) {
@@ -81,10 +84,31 @@ protected CompositeCommand(@NotNull CompositeCommand parent, String label, Strin
this.setDescription(this.configPath + ".description");
this.setUsage(this.configPath + ".usage");
+ this.setPermission();
this.setup();
if (this.getSubCommand("help") == null && !"help".equals(label)) {
- new HelpCommand(this);
+ this.addChildren(new HelpCommand(this));
+ }
+ }
+
+ public boolean canExecute(CommandSender sender, boolean sendMessage) {
+ if (this.onlyPlayer && !(sender instanceof Player)) {
+ if (sendMessage) {
+ sender.sendMessage(this.plugin.getConfig().getString("messages.error.use-only-in-game"));
+ }
+ return false;
+ }
+
+ if (sender.isOp() || this.getPermission() == null || sender.hasPermission(this.getPermission())) {
+ return true;
+ } else {
+ if (sendMessage) {
+ sender.sendMessage(this.plugin.getConfig()
+ .getString("messages.error.no-permission")
+ .replace("[permission]", this.getPermission()));
+ }
+ return false;
}
}
@@ -119,6 +143,10 @@ public final boolean execute(@NotNull CommandSender sender, @NotNull String comm
COMMANDS + this.description);
}
+ public final @Nullable String getParameters() {
+ return this.plugin.getConfig().getString(COMMANDS + this.configPath + ".parameters");
+ }
+
@Contract(pure = true)
public final @NotNull Collection getSubCommands() {
return this.subCommands.values().stream().filter(compositeCommand -> !compositeCommand.hidden).toList();
@@ -148,11 +176,11 @@ public void setHidden(boolean hidden) {
public final void misuseCommand(@NotNull CommandSender sender) {
String usage = this.getUsage();
- String parameters = this.getParameters();
+ String params = this.getParameters();
sender.sendMessage(this.plugin.getConfig().getString("messages.error.misuse-command"));
- sender.sendMessage(ChatColor.RED + usage + (parameters != null
- ? " " + parameters
+ sender.sendMessage(ChatColor.RED + usage + (params != null
+ ? " " + params
: ""));
sender.sendMessage(ChatColor.RED + this.plugin.getConfig().getString("messages.tips.help-command"));
}
@@ -161,13 +189,15 @@ public void setOnlyPlayer(boolean onlyPlayer) {
this.onlyPlayer = onlyPlayer;
}
+ public void setPermission() {
+ super.setPermission(this.parent == null
+ ? this.getLabel()
+ : this.parent.getPermission() + "." + this.getLabel());
+ }
+
public boolean showHelp(CommandSender sender) {
CompositeCommand helpCommand = this.getSubCommand("help");
- if (helpCommand != null) {
- return helpCommand.call(sender, "help", new ArrayList<>());
- } else {
- return false;
- }
+ return helpCommand != null && helpCommand.call(sender, "help", new ArrayList<>());
}
@Override
@@ -206,37 +236,16 @@ public boolean showHelp(CommandSender sender) {
}
}
- @Override
- public final @NotNull String toString() {
- return "CompositeCommand{" + "configPath='" + this.configPath + "'" + ", label='" + this.getLabel() + "'" +
- ", subCommands=" + this.subCommands + ", subCommandAliases=" + this.subCommandAliases +
- ", permission='" + this.getPermission() + "'" + ", level=" + this.level + ", topLabel='" +
- this.topLabel + "'" + ", description='" + this.description + "'" + ", usageMessage='" +
- this.usageMessage + "'" + ", onlyPlayer=" + this.onlyPlayer + ", hidden=" + this.hidden + "}";
+ protected void addChildren(@NotNull CompositeCommand subCommand) {
+ this.parameters.add(new Parameter(subCommand.getLabel(), false));
}
- protected final boolean call(CommandSender sender, String label, List args) {
- return this.canExecute(sender, true) && this.execute(sender, label, args);
+ protected void addChildren(String parameter, boolean isOptional) {
+ this.parameters.add(new Parameter(parameter, isOptional));
}
- protected boolean canExecute(CommandSender sender, boolean sendMessage) {
- if (this.onlyPlayer && !(sender instanceof Player)) {
- if (sendMessage) {
- sender.sendMessage(this.plugin.getConfig().getString("messages.error.use-only-in-game"));
- }
- return false;
- }
-
- if (sender.isOp() || this.getPermission() == null || sender.hasPermission(this.getPermission())) {
- return true;
- } else {
- if (sendMessage) {
- sender.sendMessage(this.plugin.getConfig()
- .getString("messages.error.no-permission")
- .replace("[permission]", this.getPermission()));
- }
- return false;
- }
+ protected final boolean call(CommandSender sender, String label, List args) {
+ return this.canExecute(sender, true) && this.execute(sender, label, args);
}
protected boolean execute(@NotNull CommandSender sender, @NotNull String label, @NotNull List args) {
@@ -244,10 +253,6 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
return true;
}
- protected final @Nullable String getParameters() {
- return this.plugin.getConfig().getString(COMMANDS + this.configPath + ".parameters");
- }
-
protected @Nullable CompositeCommand getSubCommand(@NotNull String label) {
String lowerLabel = label.toLowerCase(Locale.ENGLISH);
@@ -265,7 +270,7 @@ protected boolean execute(@NotNull CommandSender sender, @NotNull String label,
.findFirst();
if (dynamicCommand.isPresent()) {
- subCommand = (CompositeCommand) dynamicCommand.get();
+ subCommand = dynamicCommand.get();
}
}
}
diff --git a/src/main/java/fr/lataverne/votereward/commands/ConfirmableCommand.java b/src/main/java/fr/lataverne/votereward/utils/commands/ConfirmableCommand.java
similarity index 69%
rename from src/main/java/fr/lataverne/votereward/commands/ConfirmableCommand.java
rename to src/main/java/fr/lataverne/votereward/utils/commands/ConfirmableCommand.java
index a735bd3..fcfe84b 100644
--- a/src/main/java/fr/lataverne/votereward/commands/ConfirmableCommand.java
+++ b/src/main/java/fr/lataverne/votereward/utils/commands/ConfirmableCommand.java
@@ -1,5 +1,6 @@
-package fr.lataverne.votereward.commands;
+package fr.lataverne.votereward.utils.commands;
+import fr.lataverne.votereward.commands.common.ConfirmCommand;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
@@ -13,6 +14,8 @@ protected ConfirmableCommand(@NotNull CompositeCommand parent, String label, Str
super(parent, label, aliases);
}
+ public abstract boolean toBeExecuted(@NotNull CommandSender sender, @NotNull String label, @NotNull List args);
+
@Override
protected final boolean execute(@NotNull CommandSender sender, @NotNull String label, @NotNull List args) {
if (!this.validate(sender, label, args)) {
@@ -25,15 +28,14 @@ protected final boolean execute(@NotNull CommandSender sender, @NotNull String l
} else {
confirmCommand.addCommandToBeConfirmed(this, sender, label, args);
- String message = this.plugin.getConfig().getString("messages.confirm-command.confirm")
- .replace(ConfirmableCommand.CONFIRM_COMMAND_USAGE, confirmCommand.getUsage());
+ String message = this.plugin.getConfig()
+ .getString("messages.confirm-command.confirm")
+ .replace(CONFIRM_COMMAND_USAGE, confirmCommand.getUsage());
sender.sendMessage(message);
return true;
}
}
- protected abstract boolean toBeExecuted(@NotNull CommandSender sender, @NotNull String label, @NotNull List args);
-
protected abstract boolean validate(@NotNull CommandSender sender, @NotNull String label, @NotNull List args);
}
diff --git a/src/main/java/fr/lataverne/votereward/utils/commands/DynamicCommand.java b/src/main/java/fr/lataverne/votereward/utils/commands/DynamicCommand.java
new file mode 100644
index 0000000..d1d7bad
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/utils/commands/DynamicCommand.java
@@ -0,0 +1,16 @@
+package fr.lataverne.votereward.utils.commands;
+
+import org.jetbrains.annotations.NotNull;
+
+public abstract class DynamicCommand extends CompositeCommand {
+
+ protected DynamicCommand(@NotNull CompositeCommand parent, String label, String... aliases) {
+ super(parent, label, aliases);
+ }
+
+ public final void setPermission() {
+ this.inheritPermission();
+ }
+
+ protected abstract boolean isDynamicCommand(String label);
+}
diff --git a/src/main/java/fr/lataverne/votereward/utils/commands/Parameter.java b/src/main/java/fr/lataverne/votereward/utils/commands/Parameter.java
new file mode 100644
index 0000000..faf02fe
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/utils/commands/Parameter.java
@@ -0,0 +1,21 @@
+package fr.lataverne.votereward.utils.commands;
+
+class Parameter {
+
+ private final boolean isOptional;
+
+ private final String label;
+
+ Parameter(String label, boolean isOptional) {
+ this.label = label;
+ this.isOptional = isOptional;
+ }
+
+ public String getLabel() {
+ return this.label;
+ }
+
+ public boolean isOptional() {
+ return this.isOptional;
+ }
+}
diff --git a/src/main/java/fr/lataverne/votereward/utils/commands/package-info.java b/src/main/java/fr/lataverne/votereward/utils/commands/package-info.java
new file mode 100644
index 0000000..099e19f
--- /dev/null
+++ b/src/main/java/fr/lataverne/votereward/utils/commands/package-info.java
@@ -0,0 +1 @@
+package fr.lataverne.votereward.utils.commands;
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index b03b67e..6891766 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -14,75 +14,6 @@ api-version: 1.18
softdepend:
- ItemReward
-permissions:
- votereward.bag:
- description: Allows bag commands usage
- default: true
- children:
- votereward.bag.get:
- description: Allows using /votereward bag get
- default: true
- votereward.bag.see:
- description: Allows using /votereward bag see
- default: true
- votereward.admin:
- description: Allows admin command usage
- default: op
- children:
- votereward.admin.fakevote:
- description: Allows using /votereward fakevote
- default: op
- votereward.admin.bag:
- description: Allows bag admin commands usage
- default: op
- children:
- votereward.admin.bag.get:
- description: Allows using /votereward admin bag get
- default: op
- votereward.admin.bag.see:
- description: Allows using /votereward admin bag see
- default: op
- votereward.admin.rewardsgroups:
- description: Allows admin commands to manage the rewards groups
- default: op
- children:
- votereward.admin.rewardsgroups.create:
- description: Allows using /votereward admin rewardsgroups create
- default: op
- votereward.admin.rewardsgroups.delete:
- description: Allows using /votereward admin rewardsgroups delete
- default: op
- votereward.admin.rewardsgroups.list:
- description: Allows using /votereward admin rewardsgroups list
- default: op
- votereward.admin.rewardsgroups.activate:
- description: Allows using /votereward admin rewardsgroups activate
- default: op
- votereward.admin.rewardsgroup:
- description: Allows admin command to manage a rewards group
- default: op
- children:
- votereward.admin.rewardsgroup.:
- description: Allows the commands to manage a rewards group
- default: op
- children:
- votereward.admin.rewardsgroup..addreward:
- description: Allows using /votereward admin rewardsgroups addReward
- default: op
- votereward.admin.rewardsgroup..see:
- description: Allows using /votereward admin rewardsgroups see
- default: op
- votereward.admin.rewardsgroup..reward:
- description: Allows the commands to manage a reward of a rewards group
- default: op
- children:
- votereward.admin.rewardsgroup..reward.modify:
- description: Allows the commands to modify a reward of a rewards group
- default: op
- children:
- votereward.admin.rewardsgroup..reward.modify.percentage:
- description: Allows to modify the percentage of a reward
- default: op
votereward.topvote:
description: Allows using /votereward topvote
default: true