Added the ability to block commands.

This commit is contained in:
Brianna O'Keefe 2019-02-28 17:26:36 -05:00
parent ed55fadd9d
commit 89212cdaba
5 changed files with 45 additions and 2 deletions

View File

@ -63,6 +63,7 @@ public class UltimateModeration extends JavaPlugin {
this.commandManager = new CommandManager(this);
// Register Listeners
Bukkit.getPluginManager().registerEvents(new CommandListener(this), this);
Bukkit.getPluginManager().registerEvents(new DeathListener(this), this);
Bukkit.getPluginManager().registerEvents(new MoveListener(this), this);
Bukkit.getPluginManager().registerEvents(new DropListener(this), this);

View File

@ -42,7 +42,6 @@ public class CommandToggleChat extends AbstractCommand {
continue;
player.sendMessage(Methods.formatText(locale.getMessage("command.togglechat.bypass")));
}
if (!(sender instanceof Player))

View File

@ -0,0 +1,39 @@
package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.utils.SettingsManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.util.ArrayList;
import java.util.List;
public class CommandListener implements Listener {
private UltimateModeration instance;
public CommandListener(UltimateModeration ultimateModeration) {
this.instance = ultimateModeration;
}
@EventHandler
public void onCommand(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
List<String> blockedCommands = SettingsManager.Setting.BLOCKED_COMMANDS.getStringList();
for (String cmd : blockedCommands) {
if (event.getMessage().toUpperCase().startsWith("/" + cmd.toUpperCase())
&& !player.hasPermission("um.commandblock.bypass")) {
event.setCancelled(true);
event.setMessage("-");
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.blocked"));
}
}
}
}

View File

@ -173,6 +173,8 @@ public class SettingsManager implements Listener {
VANISH_BATS("Main.Release Bats On Vanish", true),
VANISH_PARTICLE("Main.Vanish Particle", "EXPLOSION_NORMAL"),
BLOCKED_COMMANDS("Main.Blocked Commands", Arrays.asList("Fly", "Op", "Plugins", "Pl")),
GLASS_TYPE_1("Interfaces.Glass Type 1", 7),
GLASS_TYPE_2("Interfaces.Glass Type 2", 11),
GLASS_TYPE_3("Interfaces.Glass Type 3", 3),

View File

@ -24,4 +24,6 @@ command.revive.success = "&7You have revived &6%player% &7successfully."
command.revive.revived = "&7You have been revived."
command.spy.returned = "&7You were returned to your previous location"
command.spy.success = "&7You are now spying on &6%player%&7. Use the command &6/spy &7to return to your previous location&7"
command.spy.success = "&7You are now spying on &6%player%&7. Use the command &6/spy &7to return to your previous location&7"
command.blocked = "&cYou cannot use that command..."