UHC death event help

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

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

    1928i

    Well, I have good news and bad news, the event is now working, but I still can't craft golden heads. Can you guys help? Here is my code again:


    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.event.player.PlayerJoinEvent;
    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.material.MaterialData;
    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){
            if(e.getEntity() instanceof Player){
                Player p = e.getEntity();
                String name = p.getName();
                Location loc = p.getLocation();
                ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
                SkullMeta headMeta = (SkullMeta) head.getItemMeta();
                headMeta.setOwner(name);
                head.setItemMeta(headMeta);
                p.getLocation().getWorld().dropItem(loc, head);
                p.setGameMode(GameMode.SPECTATOR);
            }
        }
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e){
            Player p = e.getPlayer();
            p.sendMessage("You joined!");
        }
       
        @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_ITEM);
            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;
           
        }
       
    }
    
     
  2. Just going to say this now, but this thread is 91 (make that 92...) posts deep and the problem still hasn't been solved.
    @1928i You have to register the recipe under your onEnable. The only thing you are doing is making the recipe.
     
  3. Offline

    1928i

  4. Offline

    mythbusterma

    @1928i

    You're still hijacking Minecraft's logger and keeping a static reference to your plugin for no reason.

    Also, you forgot to register your recipe with Server#addRecipe(Recipe)
     
  5. Offline

    1928i

    I added the statement and the recipe just still doesn't work. Can anyone help me?


    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.event.player.PlayerJoinEvent;
    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){
            if(e.getEntity() instanceof Player){
                Player p = e.getEntity();
                String name = p.getName();
                Location loc = p.getLocation();
                ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
                SkullMeta headMeta = (SkullMeta) head.getItemMeta();
                headMeta.setOwner(name);
                head.setItemMeta(headMeta);
                p.getLocation().getWorld().dropItem(loc, head);
                p.setGameMode(GameMode.SPECTATOR);
            }
        }
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e){
            Player p = e.getPlayer();
            p.sendMessage("You joined!");
        }
       
        @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_ITEM);
            getServer().addRecipe(headApple);
            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;
           
        }
       
    }
    
     
  6. Offline

    mythbusterma

    @1928i

    Why are you still hijacking Minecraft's logger and maintaining a useless reference to your plugin even after the people in the thread have told you multiple times not to do that?

    I'm willing to bet your plugin is generating a stack trace somewhere as well.
     
  7. Offline

    1928i

    @mythbusterma
    Why don't you try to help with the problem at hand?
     
  8. Offline

    1Rogue

    I think plenty of people have:
    [​IMG]

    You're just not listening.
     
  9. Offline

    Skionz

    @1928i You need to register the recipe. Bukkit isn't going to magically get your recipe and register it for you.
     
  10. Offline

    1928i

    @Skionz
    I did, now what? It still doesn't work, check out my code before posting.
     
  11. Offline

    Skionz

    @1928i My bad; I was looking at an outdated version. First this
    Then post your server's log and read the stickied thread on how to read a stack-trace
     
  12. Offline

    mythbusterma


    Why don't you try and put in a little effort into writing good software? See how being petty gets us nowhere?
     
  13. Offline

    1928i

    Ok guys, I have good news and bad news!

    The good news is was I stopped stealing Minecraft's logger and I also figured out the problem, without looking at the console.
    The bad news is, I don't know how to fix it. I am checking for skeleton heads, not player heads. How do I set the skull type to 3? I tried adding another column and it says that it is depreciated.
     
  14. Offline

    nverdier

  15. Offline

    1928i

    @nverdier
    You can't set an ingredient in a recipe to an ItemStack so that wouldn't work.
     
  16. Offline

    nverdier

    How is this true?
     
  17. Offline

    mythbusterma

    @1928i

    "Deprecation" does not mean "not working," look and see why it's deprecated, if you know and understand why, and are certain it won't affect you, you may still use it.
     
Thread Status:
Not open for further replies.

Share This Page