Enable/disable PvP?

Discussion in 'Plugin Development' started by dabananaboat, Dec 21, 2011.

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

    dabananaboat

    Hello.

    How do you enable/disable PvP in Bukkit?
    I tried
    Code:
    this.getServer().getWorld()---
    
    but that didn't have the option to manipulate it.

    I tried looking it up on google, but that only gave plugins as result.
     
  2. Offline

    skore87

    I think you'll have to separately intercept the events and cancel them. Unless you mean what's in the server.properties file, that is likely something else.
     
  3. Offline

    Wundark

    You mean like this?

    PHP:
    Bukkit.getWorld("world").setPVP(true);
     
  4. Offline

    dabananaboat

    Yeah, something like that.
     
  5. Offline

    KaiBB

    Except if he was to publish this plugin, it wouldn't be the world 'world', or whatever he has. He would have to make a variable so it works for the world the player is in.
     
  6. Offline

    dabananaboat

    I tried the code.
    This is my java file:
    PHP:
    package nl.DBB.BukkitPvPTest;

    import java.util.logging.Logger;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class 
    Main extends JavaPlugin {
        
    Logger log Logger.getLogger("Minecraft");
        public 
    boolean PvPEnabled false;
        public 
    void onEnable() {
            
    log.info("PvP Test enabled.");
        }
        public 
    void onDisable() {
            
    log.info("PvP Test disabled.");
        }
        public 
    boolean onCommand(CommandSender senderCommand cmdString commandLabelString[] args) {
            if(
    sender instanceof Player) {
                if(
    commandLabel.equalsIgnoreCase("togglepvp")) {
                    if(
    PvPEnabled) {
                        
    this.getServer().getWorld("PluginTestWorld").setPVP(false);
                        
    PvPEnabled false;
                    } else {
                        
    this.getServer().getWorld("PluginTestWorld").setPVP(true);
                        
    PvPEnabled true;
                    }
                    
    sender.sendMessage("PvP set to " Boolean.toString(this.getServer().getWorld("PluginTestWorld").getPVP()));
                }
            }
            return 
    true;
        }
    }
    Result: 'Switches' the PvP state, but doesn't enable or disable it. I tried it locally on a bukkit server.
     
  7. Offline

    Wundark

    You have made a fatal floor by making 'PvPEnabled' false. In the onEnable() you would need,
    Code:
    PvPEnabled = getServer().getWorld("PluginTestWorld").getPVP();
    It was an example as OP wanted to enable/disable PVP. If you want to toggle all of your loaded worlds PVP, then use this.

    PHP:
    for(World wld getServer().getWorlds()){
        
    wld.setPVP(!wld.getPVP());
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 22, 2016
Thread Status:
Not open for further replies.

Share This Page