Disable ALL Commands in a certain MultiVerse world?

Discussion in 'Plugin Development' started by PlumTheDev, Dec 23, 2012.

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

    PlumTheDev

    Hi there. I'm trying to make a plugin which would disable ALL commands once a player enters a world via Multiverse. I want to do this as this world is planned to be 100% vanilla.

    The aim is for this plugin to do the following when ANY command is typed:

    • Do nothing when the command is executed.
    • Send the player a message saying that they may not execute commands in this world.

    I'm not even sure if this is programmatically possible, but any feedback / help would be greatly appreciated! [pig]
     
  2. Offline

    EnvisionRed

    Handle a commandPreProcess event. If the player is in that world, just set the event to cancelled and send them the message.
     
    gomeow likes this.
  3. Offline

    PlumTheDev

    Okay, i've done some work with that, how can I make it so it cancels ALL commands? Is there a way to do this without making a colossal list of them?
     
  4. Offline

    EnvisionRed

    I'm pretty sure you can just get the player involved, then check if he is in the world, and if he is, do what you wanted. You don't even have to use getMessage().
     
  5. Offline

    Assult

    Code:
    @EventHandler
    public void onCommand(PlayerCommandPreprocessEvent e){
    if(player.getWorld().getName() == "world"){
    e.setCancelled(true);
    }else{
     
    }
     
    }
    its not tested but it should work
     
    PlumTheDev likes this.
  6. Offline

    PlumTheDev

    Okay, i've done some attempts, but it doesn't seem to block the command, I think i'm missing something obvious...

    vanilla.java
    Code:
    package com.gmail.<Censored :3>.servervanillavanilla;
     
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class ServerVanilla extends JavaPlugin {
       
        public void onEnable()
        {
            getLogger().info("ServerVanilla v0.1 Activated.");
            getConfig().options().copyDefaults(true);
            saveConfig();
               
        }
       
        public void onDisable()
        {
            getLogger().info("ServerVanilla v0.1 Deactivated.");
        }
       
        public void onCommand(PlayerCommandPreprocessEvent e){
            Player player = e.getPlayer();
            if(player.getWorld().getName() == getConfig().getString("World")){
                if(player.hasPermission("ServerVanilla.bypass")){
                    e.setCancelled(false);
                }else{
            e.setCancelled(true);
            player.sendMessage("You cannot use commands in this world!");
                }
            }else{
           
            }
           
            }
     
    }
    
    config.yml
    Code:
    World: vanilla
    I'm not sure why it's not working. The worldname is vanilla, but it's not stopping me from typing commands... Any ideas? Am I missing something obvious?
     
  7. Offline

    ImDeJay

    you need to register events and such.

    I fixed up the code for you, all you need to do is copy/paste and import what is needed.

    Code:
    package com.gmail.<Censored :3>.servervanillavanilla;
     
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class ServerVanilla extends JavaPlugin implements Listener{
     
        public void onEnable()
        {
            this.getServer().getPluginManager().registerEvents(this,  this);
            getConfig().options().copyDefaults(true);
            saveConfig();
             
        }
     
        public void onDisable()
        {
     
        }
     
        @EventHandler
        public void onCommand(PlayerCommandPreprocessEvent e){
            Player player = e.getPlayer();
            if(player.getWorld().getName() == getConfig().getString("World")){
                if(player.hasPermission("ServerVanilla.bypass")){
                    //do nothing here
                }else{
            e.setCancelled(true);
            player.sendMessage("You cannot use commands in this world!");
                }
            }else{
         
            }
         
            }
     
    }
     
  8. Offline

    fireblast709

    And for god's sake, don't compare Strings with ==. Use .equals()
     
  9. Offline

    Wafer_5000

Thread Status:
Not open for further replies.

Share This Page