UHC death event help

Discussion in 'Plugin Development' started by 1928i, Jan 31, 2015.

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

    1928i

    Hello, I am currently setting up a UHC based plugin, but I'm having issues with death events. When I die, none of the things happen. Can anyone help me? Here is my code:

    Code:
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e){
            Player p = e.getEntity();
            String name = p.getName();
            Location loc = p.getLocation();
            ItemStack head = new ItemStack(Material.SKULL, 1, (short) 3);
            SkullMeta headMeta = (SkullMeta) head.getItemMeta();
            headMeta.setOwner(name);
            head.setItemMeta(headMeta);
            p.getLocation().getWorld().dropItem(loc, head);
            p.setGameMode(GameMode.SPECTATOR);
        }
     
  2. Offline

    Skionz

    @1928i Post all relevant classes. Your Listener is probably not registered.
     
  3. Offline

    1928i

    @Skionz
    My listener is already registered.
     
  4. Offline

    Skionz

    @1928i Debug and see if the method is actually being called.
     
    GrandmaJam likes this.
  5. Offline

    leon3001

    @1928i Have you registered your event(s)?
    EDIT: ninja'd
     
  6. Offline

    1928i

    Ok, here is some extra code:


    Code:
        @Override
        public void onEnable(){
            this.logger.info("UHC Plugin Has been enabled!");
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this, this);
            ItemStack headApplePlugin = new ItemStack(Material.GOLDEN_APPLE);
            ItemMeta appleMeta = headApplePlugin.getItemMeta();
            appleMeta.setDisplayName("Head Apple");
            headApplePlugin.setItemMeta(appleMeta);
            ShapedRecipe headApple = new ShapedRecipe(headApplePlugin);
            headApple.shape(new String[]{"***","*%*","***"}).setIngredient('*', Material.GOLD_INGOT).setIngredient('%', Material.SKULL);
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
    Will that suffice?
     
  7. Offline

    Skionz

    @1928i That still does not help. Post all relevant classes; it will make everything a lot faster.
     
  8. Offline

    1928i

    @Skionz
    What do you mean, I posted everything relevant to you.

    Can anyone else help me?
     
    Last edited by a moderator: Jan 31, 2015
  9. Offline

    leon3001

    @1928i Only if you provide us with more information. The code you posted until now looks fine to me (and to @Skionz too, apparently).
     
  10. Offline

    1928i

    @leon3001
    What other information do you need?
     
  11. Offline

    leon3001

    @1928i
    That'd be helpful. :p
     
  12. Offline

    Skionz

    @1928i Nobody is going to steal code that doesn't work. Your writing a Bukkit plugin, not Facebook.
     
  13. Offline

    1928i

    @leon3001 @Skionz
    Ok, well I have posted everything relevant, literally, that's everything. there's no need for the entire main class. It implements listener. That is all the relevant information that I have.
     
  14. Offline

    leon3001

    @1928i Okay; can't help you any further then.
     
    ReadySetPawn likes this.
  15. Offline

    1928i

    Can anyone actually help me?
     
  16. Offline

    nverdier

    @1928i
    Just post the whole thing.
     
  17. Offline

    Konato_K

    I might have gone crazy, but don't you need to use SKULL_ITEM instead?
     
  18. Offline

    1928i

    Here:

    Code:
    package me.i1928i.UHC;
    
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.inventory.meta.SkullMeta;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Core extends JavaPlugin implements Listener{
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Core plugin;
       
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e){
            Player p = e.getEntity();
            String name = p.getName();
            Location loc = p.getLocation();
            ItemStack head = new ItemStack(Material.SKULL, 1, (short) 3);
            SkullMeta headMeta = (SkullMeta) head.getItemMeta();
            headMeta.setOwner(name);
            head.setItemMeta(headMeta);
            p.getLocation().getWorld().dropItem(loc, head);
            p.setGameMode(GameMode.SPECTATOR);
        }
       
        @Override
        public void onDisable(){
            this.logger.info("UHC Plugin Has been disabled!");
        }
    
        @Override
        public void onEnable(){
            this.logger.info("UHC Plugin Has been enabled!");
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this, this);
            ItemStack headApplePlugin = new ItemStack(Material.GOLDEN_APPLE);
            ItemMeta appleMeta = headApplePlugin.getItemMeta();
            appleMeta.setDisplayName("Head Apple");
            headApplePlugin.setItemMeta(appleMeta);
            ShapedRecipe headApple = new ShapedRecipe(headApplePlugin);
            headApple.shape(new String[]{"***","*%*","***"}).setIngredient('*', Material.GOLD_INGOT).setIngredient('%', Material.SKULL);
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
       
        private static int timeId;
        int time = 0;
        public void startTime() {
            timeId = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                @Override
                public void run(){
                    if(time % 20 == 0){
                        if(plugin.getConfig().isSet("EpisodeNumber")){
                            int hi = plugin.getConfig().getInt("EpisodeNumber")+1;
                            Bukkit.broadcastMessage(ChatColor.GOLD + "[Episode End] " + ChatColor.GREEN + "We are " + time + " minutes in.");
                            plugin.getConfig().set("EpisodeNumber", hi);
                        }else{
                            plugin.getConfig().set("EpisodeNumber", 2);
                            Bukkit.broadcastMessage(ChatColor.GOLD + "[Episode End] " + ChatColor.GREEN + "We are " + time + " minutes in.");
                        }
                    }
                    time++;
                }
            },0l,120l);
        }
        public void stopTime() {
            Bukkit.getServer().getScheduler().cancelTask(timeId);
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String cl, String[] args){
            Player p = (Player) sender;
            if(cl.equalsIgnoreCase("start")){
                if(p.isOp()){
                    startTime();
                }
            }
            return false;
           
        }
       
    }
    
     
  19. Offline

    SuperOriginal

    Please don't steal Minecraft's logger. Use your own. Also, public static Core plugin; is completely useless.
    @Konato_K
    Is it just me or do most of your posts involve you going crazy?
     
  20. Offline

    Treeline1

    Unless im blind, which is probably so, I dont see that you've registered your Listeners...
    *Edit*Nvm, found it...
     
  21. Offline

    nverdier

    @Treeline1
    Nope, you're blind.
     
  22. Offline

    Treeline1

    Yeah I found it xD
     
    nverdier likes this.
  23. Offline

    ReadySetPawn

    I know this won't help, but your code management is terrible. I recommend you fix it now before you proceed to write your plugin as it will make debugging and editing your plugin a whole lot easier in the future.
     
  24. Offline

    1928i

    Does anyone actually know the problem? It will not drop a head and set their gamemode to spectator when they die.
     
  25. Offline

    SuperOriginal

    @1928i did you debug?

    Also, you cast player to sender without checking even though console is perfectly capable of doing that command.
     
  26. Offline

    1928i

    @SuperOriginal
    The command works! I need help with death event! I have debugged and their are no issues!
     
  27. Offline

    WesJD

    @1928i Try using Material.SKULL_ITEM.
     
  28. Offline

    1928i

    @WesJD
    Actually, it something with event registration because I tried to make it a broadcast a message when someone died and it didn't work.

    Does anyone know how to fix my problem?

    <Edit by mrCookieSlime: Merged posts. Please don't double post. There is an Edit Button right next to the Date.>
     
    Last edited by a moderator: Feb 1, 2015
  29. Offline

    WesJD

    @1928i Are you sure you have the plugin on your server?
     
  30. Offline

    1928i

    @WesJD
    Yes because the command works perfectly but the event does not.

    Does anyone know the problem?

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

Share This Page