How to not allow players to go into negative money

Discussion in 'Plugin Development' started by BladdonB, Jul 3, 2015.

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

    BladdonB

    I am making a plugin and I want playes to lose 50 bucks when then die, but I dont want them to lose it if they are have at less than 51 dollars, what do I do?

    Code:
    package me.pvp.listeners;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    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 me.pvp.main.Main;
    
    public class PlayerListeners implements Listener{
       
        Main plugin;
        public PlayerListeners(Main instance) {
            this.plugin = instance;
        }
       
        //When player join the server
        @EventHandler
        public void PlayerJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            String pname = p.getName();
            p.getInventory().clear();
            //Message to send the seerver on join
            Bukkit.broadcastMessage("" + ChatColor.AQUA + ChatColor.BOLD + pname + ChatColor.RESET + ChatColor.GOLD + " has join the KIT PVP server");
       
        }
       
        //END OF PLAYER JOINING SERVER
       
        //When player leaves servah
        @EventHandler
        public void PlayerLeave(PlayerQuitEvent e) {
            Player p = e.getPlayer();
            String pname = p.getName();
            p.getInventory().clear();
            //Message to send the server on quit
            Bukkit.broadcastMessage("" + ChatColor.AQUA + ChatColor.BOLD + pname + ChatColor.RESET + ChatColor.GOLD + " has left the KIT PVP server");
    
        }
       
        //End OF PLAYER LEAVING DA SERVAH
        @EventHandler
        public void Death(PlayerDeathEvent e) {
       
            Player p = e.getEntity();
            Player k = p.getKiller();
            e.setDeathMessage("" + ChatColor.BLUE + p.getName() + ChatColor.AQUA + " was killed by " + ChatColor.RED + k.getName());
            p.sendMessage(ChatColor.AQUA + "You were killed by " + ChatColor.RED + k.getName() + ChatColor.BLUE + " you have lost 50 dollars");
            String cmd = "money " + "give " + k.getName() + " 100";
            String cmd1 = "money " + "take " + p.getName() + " 50";
            //Console commands don't have a "/"
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
            if
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd1);
            k.sendMessage(ChatColor.AQUA + "Congrats! You killed " + ChatColor.RED + p.getName() + ChatColor.BLUE + " you got 100 dollars");
          
        }}
        
     
  2. Offline

    Eos

    Code:
    if (player.checkmoneymethod() < 50){
    return false;
    }
     
  3. Offline

    Zombie_Striker

    @BladdonB
    Why are you not doing a simple Balance check? Why have you not thought of this already?

    [edit], if the /money plugin is not an API, don't use it for this.
     
Thread Status:
Not open for further replies.

Share This Page