Solved Blocking a command?

Discussion in 'Plugin Development' started by Jomens235, Mar 31, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Jomens235

    I'm currently trying to block a command or a list of commands that I store in a Array, then put it into the config. I fear this will not work. Can someone please tell me how I could/would properly block commands in the plugin? Thanks.
    Code:
    @EventHandler
        public void onChat(AsyncPlayerChatEvent event) {
            Player player = event.getPlayer();
            CombatTimerMain getMain = CombatTimerMain.getInstance();
            String title = CombatTimerMain.getInstance().title;
            if (getMain.hasCooldown(player.getName())) {
                if (!getMain.commands.contains(event.getMessage())
                        && event.getMessage().startsWith("/")) {
                    if (!getMain.commands.contains(event.getMessage())
                            && event.getFormat().startsWith("/")) {
                        event.setCancelled(true);
                        player.sendMessage(title + ChatColor.RED
                                + "You cannot use commands in combat.");
                    }
                }
            }
        }
    EDIT: Forgot to show you how I was saving to a hashmap and such;
    Code:
    @Override
        public void onEnable() {
            saveDefaultConfig();
            initialiseConfig();
            getLogger().info("CombatTimer has been enabled.");
            getServer().getPluginManager().registerEvents(new CombatTimerEvents(),
                    this);
            instance = this;
            commands.clear();
            commands.add(getConfig().getString("combattimer.allowedcommands"));
        }
    
        private void initialiseConfig() {
            FileConfiguration config = getConfig();
    
            config.addDefault("combattimer.cooldown", "");
            config.addDefault("combattimer.firstjoin.cooldown", "");
            config.addDefault("combattimer.allowedcommands", "");
            config.options().copyDefaults(true);
        }
    
        @Override
        public void onDisable() {
            getLogger().info("CombatTimer has been disabled.");
            saveConfig();
            instance = null;
            commands.clear();
        }
    And the command to add the blocked commands:
    Code:
     else if (args[0].equalsIgnoreCase("add") && player.isOp()) {
                    if (args.length == 2) {
                        String newCommand = StringUtils.join(args, " ", 2,
                                args.length);
                        player.sendMessage(title + ChatColor.GRAY
                                + "You have allowed " + newCommand
                                + " to be used in combat.");
                        commands.add(newCommand);
                        getConfig().set("combattimer.allowedcommands", commands);
                        saveConfig();
                    }
     
  2. Jomens235 likes this.
  3. Offline

    Derpiee

  4. Offline

    Jomens235

Thread Status:
Not open for further replies.

Share This Page