Stats

Discussion in 'Plugin Development' started by XxZHALO13Xx, Oct 15, 2014.

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

    XxZHALO13Xx

    How would i make a plugin where on enable. creates a config (The config page for bukkit hasnt helped me at all) then on join. add the player to a config. then on a kill adds a kill to the player and on death adds a death to the player. i cant seem to figure it out. thanks for any help
     
  2. Offline

    Jaaakee224

  3. Offline

    XxZHALO13Xx

    Jaaakee224 i dont have anytyhing. i cant get configs to work
     
  4. Offline

    Jaaakee224

    XxZHALO13Xx
    We aren't going to give you code, so either keep searching or at least attempt to do something.
     
  5. Offline

    Monkey_Swag

  6. Offline

    XxZHALO13Xx

    Jaaakee224 Monkey_Swag i have attempted... i can do the kill counter but idk how to save it to a config or any of that with a config
     
  7. Offline

    CMPSCdev

    If you have attempted to do so, please show the code you have.
     
  8. Offline

    XxZHALO13Xx

    CMPSCdev
    Code:java
    1. import org.bukkit.entity.Player;
    2. import org.bukkit.event.EventHandler;
    3. import org.bukkit.event.Listener;
    4. import org.bukkit.event.entity.PlayerDeathEvent;
    5.  
    6. public class KillTracker implements Listener{
    7.  
    8. @EventHandler
    9. public void onDeath(PlayerDeathEvent e){
    10. Player v = e.getEntity().getPlayer();
    11. Player k = e.getEntity().getKiller();
    12.  
    13. if(k instanceof Player){
    14.  
    15.  
    16. }
    17. else{
    18. return; //Ignores none player kills.
    19. }
    20. }
    21.  
    22. }
    23.  
     
  9. Offline

    MeRPG

    This will help. Seriously.
    http://wiki.bukkit.org/Configuration_API_Reference#Setting_Values
    http://wiki.bukkit.org/Configuration_API_Reference#Getting_Values

    EDIT:
    Where is your onEnable? If that is supposed to be the main class, you need to add
    Code:java
    1. extends JavaPlugin
    to the class header.
     
  10. Offline

    XxZHALO13Xx

    CMPSCdev i removed the config code cause it doesnt work

    MeRPG CMPSCdev how do i do it per player? i figured out how to store it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  11. Offline

    CMPSCdev

    Guessing here.

    For the killer (k) do something like this:

    int kills = getConfig().getInt("players." + k.getUniqueId().toString() + ".kills");
    getConfig().set("players." + k.getUniqueId().toString() + ".kills", (Integer.valueOf(kills) + 1));
    saveConfig();
     
  12. Offline

    XxZHALO13Xx

    CMPSCdev what about storing each person?

    CMPSCdev

    my class
    Code:java
    1. public class KillTracker implements Listener{
    2. Core configGetter;
    3. public KillTracker(Core plugin){
    4. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    5. configGetter = plugin;
    6.  
    7. }
    8.  
    9.  
    10. @EventHandler
    11. public void onDeath(PlayerDeathEvent e){
    12. Player v = e.getEntity().getPlayer();
    13. Player k = e.getEntity().getKiller();
    14.  
    15. if(k instanceof Player && v instanceof Player){
    16.  
    17. int killcount = configGetter.getConfig().getInt("kills");
    18. int deathcount = configGetter.getConfig().getInt("deaths");
    19.  
    20. int kills = configGetter.getConfig().getInt("players." + k.getUniqueId().toString() + ".kills");
    21. configGetter.getConfig().set("players." + k.getUniqueId().toString() + ".kills", (Integer.valueOf(kills) + 1));
    22. configGetter.saveConfig();
    23. k.sendMessage(ChatColor.DARK_GREEN + "You killed " + v.getName() + "! You have a total of " + killcount + " kills!");
    24.  
    25. configGetter.saveConfig();
    26. }
    27. }
    28.  
    29.  
    30.  
    31. }
    32.  


    Core

    Code:java
    1. public class Core extends JavaPlugin{
    2.  
    3. public static Core pl;
    4. public Core plugin;
    5. public void onEnable(){
    6. getLogger().info("Bukkit Server. V" + getVersion() + " Loaded... Starting Plugins.");
    7. getLogger().info("Magic Fight Loaded.");
    8. this.getConfig().addDefault("kills", 0);
    9. this.getConfig().addDefault("players.", null);
    10. this.getConfig().options().copyDefaults(true);
    11. saveConfig();
    12. getServer().getPluginManager().registerEvents(new KillTracker(plugin), this);
    13. getServer().getPluginManager().registerEvents(new FireRod(), this); //REGISTER LISTENERS:
    14. getServer().getPluginManager().registerEvents(new BoomArrow(), this);
    15. getServer().getPluginManager().registerEvents(new ArrowStick(), this);
    16. getServer().getPluginManager().registerEvents(new MagicBar(), this);
    17. getServer().getPluginManager().registerEvents(new FlyFeather(), this);
    18. getServer().getPluginManager().registerEvents(new EggLaunch(), this);
    19. getServer().getPluginManager().registerEvents(new Nugget(), this);
    20. getServer().getPluginManager().registerEvents(new Join(), this);
    21. getServer().getPluginManager().registerEvents(new SnowballPull(), this);
    22. getCommand("magicfight").setExecutor(new MFC()); //REGISTER COMMANDS:
    23. getCommand("marrow").setExecutor(new BoomArrow());
    24. getCommand("magicitems").setExecutor(new ItemsInfo());
    25. getCommand("magicinfo").setExecutor(new MagicInfo());
    26. plugin = this;
    27. pl = this;
    28. }
    29.  
    30. private static String getVersion(){
    31. return MinecraftServer.getServer().getVersion();
    32. }
    33.  
    34. public static Plugin getPlugin() {
    35.  
    36. // TODO Auto-generated method stub
    37. return pl;
    38.  
    39. }
    40.  
    41. public void onDisable(){
    42. saveConfig();
    43. }
    44.  
    45. }
    46.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  13. Offline

    fireblast709

    XxZHALO13Xx please remove
    • That static instance.
    • It's complementary getter method.
    • The enable messages. Especially the MC version, since you are adding a versioned dependency for no reason.
    Moreover:
    • PlayerDeathEvent#getEntity() returns a Player, that getPlayer() call is redundant.
    • getKiller() will always return Player. Rather, check if that is not null.
    • Integer.valueOf(int) is redundant in this case.
    • killcount is not the kill count of the player, rather use the kills variable since that is the kill count - 1.
     
  14. Offline

    MeRPG

  15. Offline

    fireblast709

    MeRPG such a long time ago xD
     
Thread Status:
Not open for further replies.

Share This Page