Question what is the problem in my code?

Discussion in 'Bukkit Help' started by zsemi02, Jul 29, 2015.

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

    zsemi02

    i heave a question. what is the problem in my money(and mini shop) code?
    this plugin is give u 1 money when u kill a player :)
    but it's don't work :(
    what is the problem?

    Code:
    public class Buysign extends JavaPlugin implements Listener{
    
    
    
    Logger log = Logger.getLogger("Minecraft");
    
    
        @Override
        public void onEnable(){
            log.info("[Buysign] sikeresen elindult");
            getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults(true);
            saveConfig();
       
        }
    
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e){
            Player p = e.getPlayer();
            if(!getConfig().contains(p.getName())){
                getConfig().createSection(p.getName());
                getConfig().set(p.getName(), 0);
                saveConfig();
            }
       
       
       
       
       
       
        }
    
    
    
    
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e){
            if(e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.LEFT_CLICK_AIR){
            Block clicked = e.getClickedBlock();
            Player p = e.getPlayer();
            Location min1 = new Location(Bukkit.getWorld("world"),-185, 121, 1070);
            Location max1 = new Location(Bukkit.getWorld("world"),-182, 125, 1074);
            if(clicked.getType() == Material.LEVER && clicked.getLocation().getX() > min1.getX() && clicked.getLocation().getX() < max1.getX()+1 && clicked.getLocation().getY() > min1.getY() && clicked.getLocation().getY() < max1.getY() && clicked.getLocation().getZ() > min1.getZ() && clicked.getLocation().getZ() < max1.getZ()){
           
                    if(p.getItemInHand().getType() == Material.EMERALD && p.getItemInHand().getAmount() >= 20){
                   
                        ItemStack a = new ItemStack(Material.LEATHER_HELMET);
                   
                        p.getInventory().setHelmet(a);
                   
                    }
                    }
               
           
           
                }
                }
               
           
       
       
       
       
    
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e){
            if(e.getEntity().getKiller() instanceof Player){
            Player p = (Player)e.getEntity().getKiller();
            getConfig().set(p.getName(), getConfig().getInt(p.getName()+1));
       
            saveConfig();
    
       
       
    
       
            }
        }
        @Override
        public void onDisable(){
            saveConfig();
        }
    }
    
     
    Last edited: Jul 29, 2015
  2. Offline

    moe097

    @zsemi02
    If you want to implement in-game currency with your plugins you should download the Vault plugin, run it on your server and use it as an API. There are many tutorials out there on how to use this API.

    Vault Link: http://dev.bukkit.org/bukkit-plugins/vault/

    You should also move this post to the "Plugin Developers" section on the forums, you will find more help there.
     
    Last edited: Jul 31, 2015
  3. Offline

    Boomer

    Throw some debug statements in to see where it gets to
    A bukkit broadcast when it gets past the first interaction IF test
    A bukkit broadcast when it gets past that second IF monster. Your numbers are hardcoded in the plugin, and should pass the test, so if that first debug shows up, proving it hits this if, but does not show up, showing it didn't pass the if test, then there is something wrong with the construction and ma require some brackets to break up the logic more clearly, or a step back and printout out what the IF arguments evaluate to for just the x, just the y, just the z by themseves, and each other test condition - something fails that probably shouldn't, identify where, then you will be able to identify what the system might be doing to generate such results, and realize there is a very particular trick to use that solves the issue.

    This appears that you are using your own, own code to keep track of money or points, rather than actually using an economy system and money, you have a integer tracker number for each player, which is increased when they are the killer of a player who dies.

    getConfig().set(p.getName(), getConfig().getInt(p.getName()+1));

    That part is likely wehre you are thinking "I will get the players value from the config, then add one to the value and save the config"
    but you are actually saying
    Set the value-pair for player JoeCoolPlayer by getting the integer value stored under "JoeCoolPlayer1" and saving that

    p.getName() + 1 = stringname + string "1"
    that is not the .getInt(keystring) + 1 numerical addition you want
     
    Last edited: Jul 31, 2015
    zsemi02 and nlthijs48 like this.
Thread Status:
Not open for further replies.

Share This Page