Please help!

Discussion in 'Plugin Development' started by BeefyPlays, May 4, 2014.

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

    BeefyPlays

    I was wondering this for a while. Why won't this points system work?
    Code:java
    1. package minedexnetwork.net.stats;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Sound;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.entity.PlayerDeathEvent;
    12. import org.bukkit.event.player.AsyncPlayerChatEvent;
    13.  
    14. public class StatsL implements Listener {
    15.  
    16. private static HashMap<Player, Integer> points = new HashMap<Player, Integer>();
    17.  
    18.  
    19. public void System(PlayerDeathEvent event) {
    20. Player killed = (Player) event.getEntity().getPlayer();
    21. Player killer = (Player) event.getEntity().getKiller();
    22.  
    23. if(!points.containsKey(killed)){
    24. points.put(killed, + 88);
    25.  
    26. } else if(points.containsKey(killed)){
    27. points.put(killed, points.get(killed) - points.get(killed)/8);
    28.  
    29. } else if(points.containsKey(killer)){
    30. points.put(killer, points.get(killer) + points.get(killed)/8);
    31.  
    32. } else if(!points.containsKey(killer)){
    33. points.put(killer, points.get(killer) + 112);
    34. }
    35. }
    36. @EventHandler
    37. public void onPlayerChat(AsyncPlayerChatEvent e) {
    38. Player player = (Player) e.getPlayer();
    39. e.setFormat(ChatColor.AQUA + "[" + ChatColor.DARK_GRAY + points.get(player) + ChatColor.AQUA + "] " + ChatColor.YELLOW + "%s" + ChatColor.YELLOW + ChatColor.BOLD + " >>> " + ChatColor.WHITE + "%s");
    40. player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 0);
    41. }
    42. }
    43.  
     
  2. Offline

    jthort

    BeefyPlays You don't have @Eventhandler on the death event. Also why do you have System as the event name? It's not a good idea to use reserved words in java

    You will also need to register your events for the events to work.
    (If you haven't done this in the main class)

    Another suggestion would be a config, or else all the points would clear during a reload.
     
  3. Offline

    BeefyPlays

    I know, I was planing to add the config later. I do have my events registered. I forgot System was a java word. I will try changing it and I will give you more infomation
     
  4. Offline

    Rocoty

    jthort System is not a reserved word in Java.
    I think you meant @EventHandler and not @OnEnable. System was the method name. Not the event name.

    I still agree that they shouldn't use System as the method name seeing as it breaks convention by starting with an uppercase letter and is a misleading name.
     
  5. Offline

    BeefyPlays


    I feel like a complete idiot. I was making it a method not a event. Now the problem is when I kill someone my points stay at 95 or null. Here is the error http://pastebin.com/YuL9xn9w

    Nevermind! I've fixed this but how would you go about saving the players scores in the config?

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

    jthort

    Your right sorry I said the wrong one
     
  7. Offline

    ImPhantom

    BeefyPlays
    BTW... When i looked at this stack trace: http://pastebin.com/YuL9xn9w

    I couldn't help but notice that your package is formatted all wrong:

    Code:java
    1. minedexnetwork.net.stats.StatsL.kills(StatsL.java:46)


    it should be:

    Code:java
    1. net.minedexnetwork.stats.StatsL
     
Thread Status:
Not open for further replies.

Share This Page