Solved I want to add a command...

Discussion in 'Spigot Plugin Development' started by Kieraaaan, Jun 5, 2017.

  1. Hello everyone,

    I am attempting to add a command to this plugin (Death Messages) and I would like to know where and how to add the command, there are already some values set which show the kills the player killer, etc.
    Do I need a separate class for this? I'm not a very good coder so I can't do super complex things.

    Here is my code:
    Code (Text):
    package deathmessages;

    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;

    public class Main extends JavaPlugin implements Listener {
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);

        public void onDeath(PlayerDeathEvent event) {
            Player killed = event.getEntity();
            Player killer = event.getEntity().getKiller();
            Material item = killer.getItemInHand().getType();
            if (!getConfig().contains("Kills." + killer.getName())) {
                getConfig().set("Kills." + killer.getName(), Integer.valueOf(1));
            if (!getConfig().contains("Kills." + killed.getName())) {
                getConfig().set("Kills." + killed.getName(), Integer.valueOf(0));
            int n = getConfig().getInt("Kills." + killer.getName());
            int e = getConfig().getInt("Kills." + killed.getName());

            String deathMessage = getConfig().getString("Death-Message").replaceAll("%killer%", killer.getName())
                    .replaceAll("%killerkills%", String.valueOf(n)).replaceAll("%killedkills%", String.valueOf(e))
                    .replaceAll("%killed%", killed.getName()).replaceAll("%item%", String.valueOf(item))
                    .replaceAll("&", "ยง");
            if ((!(killer instanceof Player)) && (!(killed instanceof Player))) {
    I'm wanting to do like player.sendMessage("You have <kills>"). I realise this is going to have to retrieve information from the config.yml so i don't know if this is possible or not...

    Thank you for your help :)
  2. I just registered the command but how can I read of the config.yml to see how many kills someone has?
  3. getConfig()#getInt(Int Path);
  4. I'm not that great at coding so my question might sound retarded.
    Do I send that in the message so player.sendMessage(getConfig()#getInt(Int Path); + "kills.") or something similar to that or do I need to make some weird big as code for it?
  5. Also when you intinalized the Killer you never made a check to make sure it's a player killing and not a mob.Which can cause errors in the future
  6. Would I do an instanceof Player to check?
  7. Yes :p, you have one at the bottom where it doesn't really effect anything because all the stuff happens before then
  8. Code (Text):
    //Config example
        Kills: 1

    //Code example
    player.sendMessage(getConfig()#getInt("Player.Kills") + " kills.");