Plz tell me what i did wrong in files...

Discussion in 'Plugin Development' started by horse2950, Jul 11, 2012.

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

    horse2950

    okay so i tried remaking Blockey right? So i got to the point where their is no errors, But it still dosent work i mean when i load it on server everything is loaded and no errors but after /blockey and the player grabs the slimeball it dosent do ANYTHING plz tell me what i did wrong u might need a z-zip software to open the Jar.
    http://dl.dropbox.com/u/61894340/Blockey1.0.0.jar -Old
    http://dl.dropbox.com/u/61894340/Blockey1.0.5.jar -2nd To Latest
    http://dl.dropbox.com/u/61894340/Blockey1.0.6.jar -Latest
    http://dl.dropbox.com/u/61894340/BlockeyINDEV.0.0.2.jar -Oldest (Dosen't Register under Console Recomend only for refrense)



    Here is what blockey is about http://forums.bukkit.org/threads/fu...game-in-minecraft-with-this-plugin-953.24900/

    If u don't want to open jars just check comments ;D
     
  2. Offline

    EnvisionRed

    How about rather than giving us broken jars, give us code?

    It's not worth the time to me to decompile all your broken jars and look into them to find your errors.
     
  3. Offline

    horse2950

    okay theirs just alot of files

    Blockey.java
    Code:
    package me.horse2950.Blockey;
     
    import java.util.HashMap;
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Blockey extends JavaPlugin{
        private Player carrier = null;
        private final BlockeyPlayerListenerMove playerListener = new BlockeyPlayerListenerMove(this);
        private final BlockeyPlayerListenerDrop playerListener1 = new BlockeyPlayerListenerDrop(this);
        private final BlockeyPlayerListenerPick playerListener2 = new BlockeyPlayerListenerPick(this);
        private HashMap<Player,Boolean> players = new HashMap<Player,Boolean>();
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Blockey plugin;
       
        @Override
        public void onDisable() {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this.playerListener, this);
            pm.registerEvents(this.playerListener1, this);
            pm.registerEvents(this.playerListener2, this);
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Has Been Disabled");
        }
       
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " VERSION " + pdfFile.getVersion() + " Has Been Enabled");
           
        }
       
        public boolean registered(Player player){
            if(players.containsKey(player)){
                return players.get(player);
            } else {
                return false;
            }
        }
           
            public void toggleRegister(Player player){
                if(registered(player)){
                    players.put(player, false);
                    player.sendMessage(ChatColor.GREEN + "You May No longer Enter Blockey!");
                } else {
                    players.put(player,true);
                    player.sendMessage(ChatColor.BLUE + "You May Enter Blockey!!");
                }
            }
           
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
                if(label.equalsIgnoreCase("Blockey")){
                    toggleRegister((Player) sender);
                    return true;
                }
                return false;
            }
           
            public Player getCarrier(){
                return carrier;
            }
           
            public void setCarrier(Player player){
                carrier = player;
            }   
    }
    BlockeyPlayerListener.Java

    Code:
    package me.horse2950.Blockey;
     
    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.player.PlayerDropItemEvent;
     
    public class BlockeyPlayerListenerDrop implements Listener{
        public static Blockey plugin;
        public int tasknumber;
       
        public BlockeyPlayerListenerDrop(Blockey instance){
            plugin = instance;
        }
       
       
        @EventHandler
        public void PlayerDropItem(PlayerDropItemEvent event){
            Player player = event.getPlayer();
            if(plugin.registered(player) && player.equals(plugin.getCarrier())){
                if(event.getItemDrop().getItemStack().getTypeId()==Material.SLIME_BALL.getId()){
                    plugin.getServer().getScheduler().cancelTask(tasknumber);
                    player.sendMessage(ChatColor.RED + "You dropped the ball...");
                    plugin.setCarrier(null);
                    player.setDisplayName(player.getName());
                }
            }
        }
    }
    BlockeyPlayerListenerMove.java

    Code:
    package me.horse2950.Blockey;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.ItemStack;
     
    public class BlockeyPlayerListenerMove implements Listener{
        public static Blockey plugin;
        public int tasknumber;
       
        public BlockeyPlayerListenerMove(Blockey instance){
            plugin = instance;
        }
       
        @EventHandler
        public void PlayerMove(PlayerMoveEvent event){
            Player player = event.getPlayer();
            if(plugin.registered(player) && player.equals(plugin.getCarrier())){
                Location start = event.getFrom();
                Location end = event.getTo();
                if(start.getX()!=end.getX() || start.getY()!=end.getY()){
                    event.setCancelled(true);
                }
            }
        }
        public class PlayerTimer implements Runnable {
           
            public PlayerTimer(){}
           
            public void run(){
                Player player=plugin.getCarrier();
                if(player!=null){
                    plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new PlayerTimer(), 200);
                    player.sendMessage(ChatColor.RED + "You dropped the ball...");
                    ItemStack ball = new ItemStack(Material.SLIME_BALL, 1);
                    Location location = player.getTargetBlock(null,20).getLocation();
                    player.getWorld().dropItem(location,ball);
                    player.getInventory().remove(Material.SLIME_BALL);
                    plugin.setCarrier(null);
                    player.setDisplayName(player.getName());
                }
            }
        }
    }
    BlockeyPlayerListenerPick.java

    Code:
    package me.horse2950.Blockey;
     
    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.player.PlayerPickupItemEvent;
     
    public class BlockeyPlayerListenerPick implements Listener{
        public static Blockey plugin;
        public int tasknumber;
       
        public BlockeyPlayerListenerPick(Blockey instance){
            plugin = instance;
        }
       
       
        @EventHandler
        public void PlayerPickupItem(PlayerPickupItemEvent event){
            Player player = event.getPlayer();
            if(plugin.registered(player) && event.getItem().getItemStack().getTypeId()==Material.SLIME_BALL.getId()){
                player.sendMessage(ChatColor.BLUE + "You Have The Ball!");
                plugin.setCarrier(player);
                player.setDisplayName("The Carrier");
            }
        }
    }
        
    EnvisionRed Their u goes like i said above i don't know whats wrong!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  4. Talk about unefficiency... first, why not paste all of them in ONE post ? :confused:
    Then, you don't need an individual class for each event :confused: wtf, just use a single class and paste all your events in there, would be less files to handle... you could even use the events inside your main class to not use any other classes at all.

    But that's unrelated to the problem, you said when player picks up slimeball nothing happens ? Then why don't you look in the PlayerPickupItemEvent ... print some messages before anything else, maybe some of your methods aren't returning what they should.

    Also, don't store Player, use String with player's names.
    And instead of that hashmap you can just use a HashSet...
    Code:
    private HashSet<String> players = new HashSet<String>();
    
    //...
    
        public boolean registered(Player player){
            return players.contains(player.getName());
        }
     
  5. Offline

    horse2950

    Digi im conffused? Like i said im VERY new to bukkit coding and i don't get what i did wrong also ill use the hashset.
     
  6. Should I rephrase that ?

    In your BlockeyPlayerListenerPick.java, change to:
    Code:
        @EventHandler
        public void PlayerPickupItem(PlayerPickupItemEvent event){
            Player player = event.getPlayer();
    
            System.out.print("DEBUG: " + player.getName() + " picked up " + event,.getItem().getItemStack());
    
            if(plugin.registered(player) && event.getItem().getItemStack().getTypeId()==Material.SLIME_BALL.getId()){
                player.sendMessage(ChatColor.BLUE + "You Have The Ball!");
                plugin.setCarrier(player);
                player.setDisplayName("The Carrier");
            }
        }
    And then pick up the ball, see if the event triggers... if the DEBUG message displays but the "You have the ball!" does not, then one of your conditions is wrong...
    I get that you're new but you obviously know some basic stuff, you should be able to debug with messages to learn what code doesn't trigger instead of throwing the entire code and let us to do guesswork :p

    EDIT:
    Just another small tip, you can use itemstack's .getType() and directly compare it against Materials.
    Code:
    event.getItem().getItemStack().getType() == Material.SLIME_BALL
     
  7. Offline

    horse2950

    okayz Tyvm :D
     
Thread Status:
Not open for further replies.

Share This Page