Save player kill when iam star command.

Discussion in 'Plugin Development' started by samsung0104, Nov 9, 2021.

  1. Offline

    samsung0104

    Hi! I have problem.
    I wolud like to save player kills when iam run command (startevent), save player kill all player, and after the wait 10 min check how many player have more than kill 5,10,20.
    If 5 kill or lower give 1000$
    if 10 <=5 give 4000$
    ...
    Can you help how to make this?
    This code:https://pastebin.com/Ua107C7F
     
  2. Offline

    pixelrider2000

    I would first put the BukkitRunnable in a seperate class. Than you should make a PlayerDeathEvent. When someone dies you check if the BukkitRunnable is running and if it does you save the killer's kills in a hashmap. When the timer ends, you can loop through the hashmap and give the players their money.

    EDIT: Please don't put everything in your Main since that's a very bad practice.
     
  3. Offline

    samsung0104

    Thank you for helping! I try , and i try split main :D
     
  4. Offline

    Strahan

    Also you know if a method does nothing, it's no sense having it. In the pastebin you posted, the onEnable and onDisable are pointless. Remove the onDisable. Leave onEnable, as you're gonna need it when you setup the event pixelrider mentioned. Also as pixel said, it's best to keep things separated. One thing to keep in mind when you do the different classes is that if you need access to an instance of the plugin, I'd recommend you use the dependency injection method. So if you need plugin in the player death event for example, I'd do my code like
    Code:
    public class Main extends JavaPlugin {
      @Override
      public void onEnable() {
        getServer().getPluginManager().registerEvents(new PlayerDeath(this), this);
      }
    }
    
    public class PlayerDeath implements Listener {
      Main plugin;
    
      public PlayerDeath(Main plugin) {
        this.plugin = plugin;
      }
    
      @EventHandler
      public void onPlayerDeath(PlayerDeathEvent e) {
        plugin.getLogger().info(e.getEntity().getName() + " has died!");
      }
    }
    That allows me to reference the plugin instance in my separate class, as shown.
     
  5. Offline

    samsung0104

    Iam failed.
    Im so conused.
    Im created Array String[] playerek;
    string p = getName();
    Im try to ad player to array playerek +=p;
    I dont understand java ... :(
     
  6. Offline

    pixelrider2000

    Please post your code so we can help you.
     

Share This Page