Solved while sword is in hand i want to be able to pvp

Discussion in 'Plugin Development' started by MajorSkillage, Sep 23, 2014.

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

    MajorSkillage

    Code:
    package me.rockinroll99.dspvp;
     
     
    import org.bukkit.Bukkit;
    import org.bukkit.GameMode;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin implements Listener{
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
        }
        @EventHandler
        public void onSwordHandEvent(PlayerMoveEvent e){
            Player p = e.getPlayer();
            ItemStack dhelmet = new ItemStack(Material.DIAMOND_HELMET);
            ItemStack dchest = new ItemStack(Material.DIAMOND_CHESTPLATE);
            ItemStack dlegs = new ItemStack(Material.DIAMOND_LEGGINGS);
            ItemStack dboots = new ItemStack(Material.DIAMOND_BOOTS);
            ItemStack air = new ItemStack(Material.AIR);
            ItemStack dsword = new ItemStack(Material.DIAMOND_SWORD);
            if(p.getItemInHand().equals(dsword) && !p.hasPermission("ds.pvp") && e.getFrom().getX() != e.getTo().getX() || e.getFrom().getZ() != e.getTo().getZ()){
                p.setGameMode(GameMode.SURVIVAL);
                p.getInventory().setHelmet(dhelmet);
                p.getInventory().setChestplate(dchest);
                p.getInventory().setLeggings(dlegs);
                p.getInventory().setBoots(dboots);
                Bukkit.getServer().dispatchCommand(getServer().getConsoleSender(), "manuaddp " + p.getName() + " ds.pvp");
                }
            if(e.getFrom().getX() != e.getTo().getX() || e.getFrom().getZ() != e.getTo().getZ() && !p.getItemInHand().equals(Material.DIAMOND_SWORD)){
                Bukkit.getServer().dispatchCommand(getServer().getConsoleSender(), "manudelp " + p.getName() + " ds.pvp");
            } else if(!p.hasPermission("ds.pvp")){
                p.getInventory().setHelmet(air);
                p.getInventory().setChestplate(air);
                p.getInventory().setLeggings(air);
                p.getInventory().setBoots(air);
            }
            /*
            * I'm trying to make it so onMoveEvent when the user has a diamond sword in his hand it will make him gamemode survival
            * it will give him diamond armor and it will allow him to pvp
            */
        }
        @EventHandler
        public void stopPvP(EntityDamageEvent e){
            if(e.getEntity() instanceof Player){
                Player player = (Player)e.getEntity();
                if(!player.hasPermission("ds.pvp")){
                e.setCancelled(true);
                }
            }
        }
    }
    
    I'm trying to make it so onMoveEvent when the user has a diamond sword in his hand it will make him gamemode survival
    it will give him diamond armor and it will allow him to pvp


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  2. Offline

    CoolGuy2001

    Please explain better what you are trying to do when they damage an entity... I will help! :)
     
  3. Offline

    _Cookie_

    Is there an error that you are getting? Have you tried debugging?
     
  4. Offline

    rbrick

    Gerov likes this.
  5. Offline

    MajorSkillage

    What i am trying to do is 1. make a small anti-pvp thing where a permission is required 2. make it so the user's gamemode is set to survival and is equipped with diamond armor when you have the diamond sword and also give permission while they're holding the sword to pvp

    oh and remove the armour and permission when they don't have the sword in their hand

    also rbrick wouldn't that be if it were in a certain spot in the hotbar? For example if i have a dsword in slot 1 and am not holding it ._. because what is happening right now (with just my method) is when i move at all i get gamemode survival and the armour with or without the sword D:<

    so any help? anyone D:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
Thread Status:
Not open for further replies.

Share This Page