mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-07-10 15:54:20 +00:00
Unregister disabled commands (#4026)
Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com>
This commit is contained in:
parent
0668e4c48a
commit
edf664e19a
6 changed files with 155 additions and 4 deletions
|
@ -13,6 +13,7 @@ import com.earth2me.essentials.utils.NumberUtil;
|
|||
import net.ess3.api.IEssentials;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
@ -35,6 +36,7 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
@ -49,6 +51,7 @@ public class Settings implements net.ess3.api.ISettings {
|
|||
private static final BigDecimal MINMONEY = new BigDecimal("-10000000000000");
|
||||
private final transient EssentialsConf config;
|
||||
private final transient IEssentials ess;
|
||||
private final transient AtomicInteger reloadCount = new AtomicInteger(0);
|
||||
private final Map<String, String> chatFormats = Collections.synchronizedMap(new HashMap<>());
|
||||
private int chatRadius = 0;
|
||||
// #easteregg
|
||||
|
@ -58,6 +61,7 @@ public class Settings implements net.ess3.api.ISettings {
|
|||
private boolean teleportSafety;
|
||||
private boolean forceDisableTeleportSafety;
|
||||
private Set<String> disabledCommands = new HashSet<>();
|
||||
private final transient Map<String, Command> disabledBukkitCommands = new HashMap<>();
|
||||
private ConfigurationSection commandCosts;
|
||||
private Set<String> socialSpyCommands = new HashSet<>();
|
||||
private Set<String> muteCommands = new HashSet<>();
|
||||
|
@ -277,7 +281,29 @@ public class Settings implements net.ess3.api.ISettings {
|
|||
return disabledCommands.contains(label);
|
||||
}
|
||||
|
||||
private Set<String> getDisabledCommands() {
|
||||
@Override
|
||||
public Set<String> getDisabledCommands() {
|
||||
return disabledCommands;
|
||||
}
|
||||
|
||||
private void _addAlternativeCommand(final String label, final Command current) {
|
||||
Command cmd = ess.getAlternativeCommandsHandler().getAlternative(label);
|
||||
if (cmd == null) {
|
||||
for (final Map.Entry<String, Command> entry : ess.getKnownCommandsProvider().getKnownCommands().entrySet()) {
|
||||
final String[] split = entry.getKey().split(":");
|
||||
if (entry.getValue() != current && split[split.length - 1].equals(label)) {
|
||||
cmd = entry.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd != null) {
|
||||
ess.getKnownCommandsProvider().getKnownCommands().put(label, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> _getDisabledCommands() {
|
||||
final Set<String> disCommands = new HashSet<>();
|
||||
for (final String c : config.getStringList("disabled-commands")) {
|
||||
disCommands.add(c.toLowerCase(Locale.ENGLISH));
|
||||
|
@ -627,7 +653,55 @@ public class Settings implements net.ess3.api.ISettings {
|
|||
signUsePerSecond = _getSignUsePerSecond();
|
||||
chatFormats.clear();
|
||||
changeDisplayName = _changeDisplayName();
|
||||
disabledCommands = getDisabledCommands();
|
||||
disabledCommands = _getDisabledCommands();
|
||||
|
||||
// This will be late loaded
|
||||
if (ess.getKnownCommandsProvider() != null) {
|
||||
boolean mapModified = false;
|
||||
if (!disabledBukkitCommands.isEmpty()) {
|
||||
if (isDebug()) {
|
||||
logger.log(Level.INFO, "Re-adding " + disabledBukkitCommands.size() + " disabled commands!");
|
||||
}
|
||||
ess.getKnownCommandsProvider().getKnownCommands().putAll(disabledBukkitCommands);
|
||||
disabledBukkitCommands.clear();
|
||||
mapModified = true;
|
||||
}
|
||||
|
||||
for (final String command : disabledCommands) {
|
||||
final Command toDisable = ess.getPluginCommand(command);
|
||||
if (toDisable != null) {
|
||||
if (isDebug()) {
|
||||
logger.log(Level.INFO, "Attempting removal of " + command);
|
||||
}
|
||||
final Command removed = ess.getKnownCommandsProvider().getKnownCommands().remove(toDisable.getName());
|
||||
if (removed != null) {
|
||||
if (isDebug()) {
|
||||
logger.log(Level.INFO, "Adding command " + command + " to disabled map!");
|
||||
}
|
||||
disabledBukkitCommands.put(command, removed);
|
||||
}
|
||||
|
||||
// This is 2 because Settings are reloaded twice in the startup lifecycle
|
||||
if (reloadCount.get() < 2) {
|
||||
ess.scheduleSyncDelayedTask(() -> _addAlternativeCommand(command, toDisable));
|
||||
} else {
|
||||
_addAlternativeCommand(command, toDisable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mapModified) {
|
||||
if (isDebug()) {
|
||||
logger.log(Level.INFO, "Syncing commands");
|
||||
}
|
||||
if (reloadCount.get() < 2) {
|
||||
ess.scheduleSyncDelayedTask(() -> ess.getSyncCommandsProvider().syncCommands());
|
||||
} else {
|
||||
ess.getSyncCommandsProvider().syncCommands();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nicknamePrefix = _getNicknamePrefix();
|
||||
operatorColor = _getOperatorColor();
|
||||
changePlayerListName = _changePlayerListName();
|
||||
|
@ -677,6 +751,8 @@ public class Settings implements net.ess3.api.ISettings {
|
|||
bindingItemPolicy = _getBindingItemsPolicy();
|
||||
currencySymbol = _getCurrencySymbol();
|
||||
worldAliases = _getWorldAliases();
|
||||
|
||||
reloadCount.incrementAndGet();
|
||||
}
|
||||
|
||||
void _lateLoadItemSpawnBlacklist() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue