-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathArgAdmin.java
More file actions
165 lines (146 loc) · 7.13 KB
/
ArgAdmin.java
File metadata and controls
165 lines (146 loc) · 7.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package dev.espi.protectionstones.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import dev.espi.protectionstones.utils.upgrade.LegacyUpgrade;
import dev.espi.protectionstones.PSL;
import dev.espi.protectionstones.ProtectionStones;
import dev.espi.protectionstones.gui.screens.admin.AdminMenuGui;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import java.util.*;
/*
* To add new sub commands, add them here, and in ArgAdminHelp manually
*/
public class ArgAdmin implements PSCommandArg {
// has to be a method, because the base command config option is not available until the plugin is loaded
public static String getCleanupHelp() {
return ChatColor.AQUA + "> " + ChatColor.GRAY + "/" + ProtectionStones.getInstance().getConfigOptions().base_command +
" admin cleanup [remove|preview] [-t typealias (optional)] [days] [world (optional)]";
}
public static String getFlagHelp() {
return ChatColor.AQUA + "> " + ChatColor.GRAY + "/" + ProtectionStones.getInstance().getConfigOptions().base_command +
" admin flag [world] [flagname] [value|null|default]";
}
public static String getChangeBlockHelp() {
return ChatColor.AQUA + "> " + ChatColor.GRAY + "/" + ProtectionStones.getInstance().getConfigOptions().base_command +
" admin changeblock [world] [oldtypealias] [newtypealias]";
}
public static String getChangeRegionTypeHelp() {
return ChatColor.AQUA + "> " + ChatColor.GRAY + "/" + ProtectionStones.getInstance().getConfigOptions().base_command +
" admin changeregiontype [world] [oldtype] [newtype]";
}
public static String getForceMergeHelp() {
return ChatColor.AQUA + "> " + ChatColor.GRAY + "/" + ProtectionStones.getInstance().getConfigOptions().base_command +
" admin forcemerge [world]";
}
@Override
public List<String> getNames() {
return Collections.singletonList("admin");
}
@Override
public boolean allowNonPlayersToExecute() {
return true;
}
@Override
public List<String> getPermissionsToExecute() {
return Collections.singletonList("protectionstones.admin");
}
@Override
public HashMap<String, Boolean> getRegisteredFlags() {
return null;
}
// /ps admin [arg]
@Override
public boolean executeArgument(CommandSender s, String[] args, HashMap<String, String> flags) {
if (!s.hasPermission("protectionstones.admin")) {
return PSL.msg(s, PSL.NO_PERMISSION_ADMIN.msg());
}
if (args.length < 2) {
// If enabled, show GUI menu for players; otherwise fall back to text help.
if (s instanceof Player p) {
var cfg = ProtectionStones.getInstance().getConfigOptions();
boolean guiMode = Boolean.TRUE.equals(cfg.guiEnabled) && Boolean.TRUE.equals(cfg.guiCommandAdmin);
if (guiMode) {
ProtectionStones.getInstance().getGuiManager().open(p, new AdminMenuGui(ProtectionStones.getInstance().getGuiManager()));
return true;
}
}
ArgAdminHelp.argumentAdminHelp(s, args);
return true;
}
switch (args[1].toLowerCase()) {
case "help":
return ArgAdminHelp.argumentAdminHelp(s, args);
case "version":
s.sendMessage(ChatColor.AQUA + "ProtectionStones: " + ChatColor.GRAY + ProtectionStones.getInstance().getDescription().getVersion());
s.sendMessage(ChatColor.AQUA + "Developers: " + ChatColor.GRAY + ProtectionStones.getInstance().getDescription().getAuthors());
s.sendMessage(ChatColor.AQUA + "Bukkit: " + ChatColor.GRAY + Bukkit.getVersion());
s.sendMessage(ChatColor.AQUA + "WG: " + ChatColor.GRAY + WorldGuardPlugin.inst().getDescription().getVersion());
break;
case "hide":
return ArgAdminHide.argumentAdminHide(s, args);
case "unhide":
return ArgAdminHide.argumentAdminHide(s, args);
case "cleanup":
return ArgAdminCleanup.argumentAdminCleanup(s, args);
case "stats":
return ArgAdminStats.argumentAdminStats(s, args);
case "lastlogon":
return ArgAdminLastlogon.argumentAdminLastLogon(s, args);
case "lastlogons":
return ArgAdminLastlogon.argumentAdminLastLogons(s, args);
case "flag":
return ArgAdminFlag.argumentAdminFlag(s, args);
case "recreate":
return ArgAdminRecreate.argumentAdminRecreate(s, args);
case "changeblock":
return ArgAdminChangeblock.argumentAdminChangeblock(s, args);
case "changeregiontype":
return ArgAdminChangeType.argumentAdminChangeType(s, args);
case "forcemerge":
return ArgAdminForceMerge.argumentAdminForceMerge(s, args);
case "settaxautopayers":
return ArgAdminSetTaxAutopayers.argumentAdminSetTaxAutopayers(s, args);
case "fixregions":
s.sendMessage(ChatColor.YELLOW + "Fixing...");
LegacyUpgrade.upgradeRegions();
s.sendMessage(ChatColor.YELLOW + "Done!");
break;
case "debug":
if (ProtectionStones.getInstance().isDebug()) {
s.sendMessage(ChatColor.YELLOW + "Debug mode is now off.");
ProtectionStones.getInstance().setDebug(false);
} else {
s.sendMessage(ChatColor.YELLOW + "Debug mode is now on.");
ProtectionStones.getInstance().setDebug(true);
}
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
if (args.length == 2) {
List<String> arg = Arrays.asList("version", "hide", "unhide", "cleanup", "stats", "lastlogon", "lastlogons", "flag", "recreate", "fixregions", "debug", "forcemerge", "changeblock", "changeregiontype", "settaxautopayers");
return StringUtil.copyPartialMatches(args[1], arg, new ArrayList<>());
} else if (args.length >= 3 && args[1].equals("forcemerge")) {
return ArgAdminForceMerge.tabComplete(sender, alias, args);
}
return null;
}
}