My code doesnt work? can you help?

Discussion in 'Plugin Development' started by Kipnugget, Sep 18, 2016.

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

    Kipnugget

    So i was finished with the base of a kitpvp plugin, but the PlayerJoin and the PlayerDeath events didnt work :(

    can you guys help?:

    Code:
    package me.mepvp.listeners;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    import me.mepvp.main.Main;
    
    public class PlayerListeners implements Listener {
    
        Main plugin;
    
        public PlayerListeners(Main instance) {
            this.plugin = instance;
    
        }
      
        @EventHandler
        public void PlayerJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            String pname = p.getName();
            p.getInventory().clear();
            Bukkit.broadcastMessage("" + ChatColor.GRAY + pname + ChatColor.RED + " Has joined KitPvP!");
    
            ItemStack kitselector = new ItemStack(Material.COMPASS);
            ItemMeta m = kitselector.getItemMeta();
            m.setDisplayName(ChatColor.RED + "Kit Selector");
            p.getInventory().setItem(4, kitselector);
            kitselector.setItemMeta(m);
    
        }
    
        @EventHandler
        public void PlayerLeave(PlayerQuitEvent e) {
            Player p = e.getPlayer();
            String pname = p.getName();
            p.getInventory().clear();
            Bukkit.broadcastMessage("" + ChatColor.GRAY + pname + ChatColor.RED + " Has left KitPvP!");
    
        }
      
        @EventHandler
        public void Death(PlayerDeathEvent e) {
    
            Player p = e.getEntity();
            Player k = p.getKiller();
            e.getDrops().clear();
            p.sendMessage(ChatColor.RED + "You got Killed by " + ChatColor.GRAY + k.getName());
        }
    
        @EventHandler
        public void Respawn(PlayerRespawnEvent e) {
            Player p = e.getPlayer();
    
        }
    
    }
    Main:
    Code:
    package me.mepvp.main;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Arrow;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import me.mepvp.listeners.PlayerListeners;
    
    public class Main extends JavaPlugin {
    
        private static Main instance;
    
        public void log(String string) {
            System.out.println(string);
          
        }
    
        public void registerCommands() {
    
        }
    
        public static Main getInstance() {
            return instance;
    
        }
    
        public void registerListeners() {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(new PlayerListeners(this), this);
    
        }
    
        public void onEnable() {
            registerListeners();
            registerCommands();
            instance = null;
        }
    
        public void onDisable() {
            instance = null;
          
        }
    
        public boolean onCommand(Command sender, Command cmd, String commandLabel, String[] args) {
    
            if (cmd.getName().equalsIgnoreCase("Warrior") && sender instanceof Player) {
    
                Player p = (Player) sender;
    
                p.getInventory().clear();
                ItemStack WarriorSword = new ItemStack(Material.STONE_SWORD);
                ItemMeta m = WarriorSword.getItemMeta();
                WarriorSword.setItemMeta(m);
                p.getInventory().clear();
                p.getInventory().addItem(WarriorSword);
                p.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
    
            }
    
            if (cmd.getName().equalsIgnoreCase("Archer") && sender instanceof Player) {
    
                Player p = (Player) sender;
    
                p.getInventory().clear();
                ItemStack ArcherBow = new ItemStack(Material.BOW);
                ItemMeta m = ArcherBow.getItemMeta();
                ArcherBow.addEnchantment(Enchantment.ARROW_INFINITE, 1);
                ArcherBow.setItemMeta(m);
                p.getInventory().clear();
                p.getInventory().addItem(new ItemStack(Material.WOOD_SWORD));
                p.getInventory().addItem(ArcherBow);
                p.getInventory().addItem(new ItemStack(Material.ARROW, 1));
                p.getInventory().setChestplate(new ItemStack(Material.LEATHER_CHESTPLATE));
                p.getInventory().setChestplate(new ItemStack(Material.LEATHER_LEGGINGS));
            }
            return false;
    
        }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 18, 2016
  2. Online

    timtower Moderator Moderator

    Moved to plugin development.
     
  3. Offline

    Mindlessmink

    @Kipnugget Register your Listeners on onEnable. Or at least call the

    "public void registerListeners(){
    }"
    on your onEnable.
     
Thread Status:
Not open for further replies.

Share This Page