Points system help?

Discussion in 'Plugin Development' started by thewalkingplay, Nov 17, 2014.

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

    thewalkingplay

    Hi, i'm making a minigame plugin and trying to make a player points system, the points for player works fine, but i cannot use the method "addsoul(Player, int)" in other classes. :
    http://prntscr.com/57ct7t

    Main class:
    Code:java
    1. package com.minigame;
    2.  
    3. import java.io.File;
    4. import java.util.Arrays;
    5.  
    6. import me.confuser.barapi.BarAPI;
    7.  
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.configuration.file.FileConfiguration;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.player.PlayerJoinEvent;
    14. import org.bukkit.plugin.PluginManager;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16.  
    17. import com.minigame.guns.AK47;
    18. import com.minigame.guns.NoveMM;
    19. import com.minigame.guns.ShotGun;
    20. import com.minigame.guns.Sniper;
    21. import com.minigame.handlers.Kit;
    22. import com.minigame.listeners.entity.EntityDamageByEntity;
    23. import com.minigame.listeners.inventory.InventoryClick;
    24. import com.minigame.listeners.player.AsyncPlayerChat;
    25. import com.minigame.listeners.player.AsyncPlayerPreLogin;
    26. import com.minigame.listeners.player.PlayerDeath;
    27. import com.minigame.listeners.player.PlayerFall;
    28. import com.minigame.listeners.player.PlayerInteract;
    29. import com.minigame.listeners.player.PlayerJoin;
    30. import com.minigame.listeners.player.PlayerQuit;
    31. import com.minigame.magicclock.ClockFunctions;
    32. import com.minigame.magicclock.ClockInteract;
    33. import com.minigame.threads.GameCountdown;
    34. import com.minigame.threads.StartCountdown;
    35. import com.minigame.utils.MotdUtilities;
    36.  
    37. public class Minigame extends JavaPlugin implements Listener {
    38.  
    39. public void onEnable(){
    40. GameState.setState(GameState.IN_LOBBY);
    41. PluginManager pm = getServer().getPluginManager();
    42. pm.registerEvents(this, this);
    43. pm.registerEvents(new PlayerJoin(this), this);
    44. pm.registerEvents(new PlayerQuit(this), this);
    45. pm.registerEvents(new PlayerDeath(this), this);
    46. pm.registerEvents(new PlayerFall(this), this);
    47. pm.registerEvents(new AsyncPlayerPreLogin(this), this);
    48. pm.registerEvents(new AsyncPlayerChat(this), this);
    49. pm.registerEvents(new EntityDamageByEntity(this), this);
    50. pm.registerEvents(new PlayerInteract(this), this);
    51. pm.registerEvents(new InventoryClick(this), this);
    52. pm.registerEvents(new ClockFunctions(), this);
    53. pm.registerEvents(new ClockInteract(), this);
    54. pm.registerEvents(new MotdUtilities(), this);
    55. pm.registerEvents(new NoveMM(this), this);
    56. pm.registerEvents(new ShotGun(this), this);
    57. pm.registerEvents(new AK47(this), this);
    58. pm.registerEvents(new Sniper(this), this);
    59. setUpConfig();
    60. registerKits();
    61. new Thread(new StartCountdown()).start();
    62. new Thread(new GameCountdown()).start();
    63. BarAPI.setMessage(ChatColor.RED + "Esperando por mais players");
    64. }
    65.  
    66. public void onDisable() {
    67.  
    68. }
    69.  
    70. public void setUpConfig() {
    71.  
    72. File resetFile = new File(getDataFolder(), "RESET.FILE");
    73. if (resetFile.exists()) return;
    74. if (!(resetFile.exists())){
    75.  
    76. getConfig().set("Kits.9mm.Items", Arrays.asList(417));
    77. getConfig().set("Kits.9mm.DisplayItem", 417);
    78.  
    79. getConfig().set("Kits.Shotgun.Items", Arrays.asList(418));
    80. getConfig().set("Kits.Shotgun.DisplayItem", 418);
    81.  
    82. getConfig().set("Kits.AK47.Items", Arrays.asList(294));
    83. getConfig().set("Kits.AK47.DisplayItem", 294);
    84.  
    85. getConfig().set("Kits.Sniper.Items", Arrays.asList(419));
    86. getConfig().set("Kits.Sniper.DisplayItem", 419);
    87. saveConfig();
    88. try{
    89. resetFile.createNewFile();
    90. } catch (Exception e) {
    91. e.printStackTrace();
    92. }
    93. }
    94.  
    95. }
    96.  
    97. public void registerKits(){
    98. FileConfiguration config = getConfig();
    99. for (String s : config.getConfigurationSection("Kits").getKeys(false)){
    100. String path = "Kits." + s + ".";
    101. new Kit(s, config.getStringList(path + "Items"), config.getInt(path + "DisplayItem"));
    102. }
    103. }
    104.  
    105. @EventHandler
    106. public void onJoin(PlayerJoinEvent e) {
    107. Player p = e.getPlayer();
    108.  
    109. if (!(getConfig().contains(p.getName()))){
    110. getConfig().set(p.getName() + ".Almas", 0);
    111. saveConfig();
    112. }
    113. }
    114.  
    115. }
    116.  


    Soul Mananger (almas)
    Code:java
    1. package com.minigame.souls;
    2.  
    3. import org.bukkit.entity.Player;
    4.  
    5. import com.minigame.Minigame;
    6. import com.minigame.utils.ChatUtilities;
    7.  
    8. public class SoulMananger extends Minigame {
    9.  
    10. public void addSoul(Player p, int i) {
    11. getConfig().set(p.getName() + ".Almas", getConfig().getInt(p.getName() + ".Almas", 0) +i);
    12. saveConfig();
    13. ChatUtilities.sendMessage(p, "+ " + i + " Almas!");
    14. }
    15.  
    16. public void removeSoul(Player p, int i){
    17. getConfig().set(p.getName() + ".Almas", getConfig().getInt(p.getName() + ".Almas", 0) -i);
    18. saveConfig();
    19. ChatUtilities.sendMessage(p, "- " + i + " Almas!");
    20. }
    21.  
    22. }
    23.  


    Can anyone help me?
    Sorry for my english, i'm brazilian
     
  2. Offline

    Skionz

    Use constructors or make it static.
     
  3. Offline

    thewalkingplay

  4. Offline

    Skionz

    thewalkingplay Create an instance of your class that Extends the JavaPlugin class.
    Code:
    Plugin plugin = this;
     
  5. Offline

    thewalkingplay

    Skionz type the MGListener: ?
    Code:java
    1. package com.minigame.listeners;
    2.  
    3. import org.bukkit.event.Listener;
    4.  
    5. import com.minigame.Minigame;
    6.  
    7. public class MGListener implements Listener{
    8.  
    9. protected Minigame plugin;
    10. public MGListener(Minigame pl){
    11. plugin = pl;
    12. }
    13.  
    14. }
    15.  
     
  6. Offline

    Skionz

  7. Offline

    thewalkingplay

    Skionz i'm brazilian :/

    The eclipse show me to change the plugin to static, but, when i change, the clipse show a error in " = this"
    http://prntscr.com/57dd5i
     
  8. Offline

    timtower Administrator Administrator Moderator

    thewalkingplay, Monkey_Swag This is an English community, so no Portuguese or Spanish or anything besides English please.
     
  9. Offline

    thewalkingplay

    timtower I'm not very good at English, but I try: /

    Anyone?

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

    Th3Br1x

    You have to create an instance of your SoulManager class:
    Code:java
    1. SoulManager sm = new SoulManager();


    Then you can call your methods from "sm".

    You may should read a bit about basic java stuff. There should be a ton of information in a lot of languages :)
     
  11. Offline

    thewalkingplay

    Th3Br1x internal error =P

    Code:
    [19:03:16] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'start' in plugin Terrorism v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:740) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:957) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:818) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:258) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    Caused by: java.lang.ExceptionInInitializerError
        at com.minigame.Minigame.onCommand(Minigame.java:123) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        ... 13 more
    Caused by: java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:98) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at com.minigame.Minigame.<init>(Minigame.java:40) ~[?:?]
        at com.minigame.souls.SoulMananger.<init>(SoulMananger.java:8) ~[?:?]
        at com.minigame.souls.SoulMananger.<clinit>(SoulMananger.java:10) ~[?:?]
        at com.minigame.Minigame.onCommand(Minigame.java:123) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        ... 13 more
    Caused by: java.lang.IllegalStateException: Initial initialization
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:101) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at com.minigame.Minigame.<init>(Minigame.java:40) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.7.0_67]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_67]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_67]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.7.0_67]
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_67]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:52) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:127) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugins(CraftServer.java:364) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.<init>(CraftServer.java:326) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.PlayerList.<init>(PlayerList.java:68) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.DedicatedPlayerList.<init>(SourceFile:14) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.java:133) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:436) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        ... 1 more
    
    Soul Manager class:
    Code:java
    1. package com.minigame.souls;
    2.  
    3. import org.bukkit.entity.Player;
    4.  
    5. import com.minigame.Minigame;
    6. import com.minigame.utils.ChatUtilities;
    7.  
    8. public class SoulMananger extends Minigame {
    9.  
    10. static SoulMananger sm = new SoulMananger();
    11.  
    12.  
    13. public static void addSoul(Player p, int i) {
    14. sm.getConfig().set(p.getName() + ".Almas", sm.getConfig().getInt(p.getName() + ".Almas", 0) +i);
    15. sm.saveConfig();
    16. ChatUtilities.sendMessage(p, "+ " + i + " Almas!");
    17. }
    18.  
    19. public static void removeSoul(Player p, int i){
    20. sm.getConfig().set(p.getName() + ".Almas", sm.getConfig().getInt(p.getName() + ".Almas", 0) -i);
    21. sm.saveConfig();
    22. ChatUtilities.sendMessage(p, "- " + i + " Almas!");
    23. }
    24.  
    25.  
    26.  
    27. }



    Command:
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    3. if (cmd.getName().equalsIgnoreCase("start")) {
    4. Player player = (Player) sender;
    5. SoulMananger.addSoul(player, 100);
    6. return true;
    7. }
    8. return false;
    9. }
     
  12. Offline

    Th3Br1x

    thewalkingplay
    Well that can't work :)

    Does your SoulManager class need to extend your Minigames class?
    because then, you won't be able to call the constructor of it since it tries to create a new instance of your plugin too. That's what your error is.

    Just pass your plugin's instance to your static methods:
    Code:java
    1. public static void addSoul(Minigame m, Player p, int i){
    2. ...
    3. }


    And then change your
    Code:java
    1. sm.getConfig()....

    stuff into
    Code:java
    1. m.getConfig()...


    Then simply call the method from the onCommand:
    Code:java
    1. SoulManager.addSoul(this, player, 100);


    This assumes that your onCommand(...) method is inside of your Minigame class.

    In general, I'm not into posting the correct code. But as you already missunderstood the previous stuff, it would actually take a lot of time, which i don't have at the moment :) I would suggest that you search for some java beginner guides in the internet (or bookstore maybe?). That should increase your general java knowledge and help you to understand what static references are used for etc. :)
     
  13. Offline

    thewalkingplay

    Th3Br1x tanks :) but, can you help me with more one thing?

    My minigame is a gun game and, have a method to give "Almas" to the Killer?
    the event PlayerKillEvent don't exists :(

    My player death class:
    Code:java
    1. package com.minigame.listeners.player;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.EventPriority;
    8. import org.bukkit.event.entity.PlayerDeathEvent;
    9.  
    10. import com.minigame.GameState;
    11. import com.minigame.Minigame;
    12. import com.minigame.handlers.Team;
    13. import com.minigame.listeners.MGListener;
    14. import com.minigame.utils.ChatUtilities;
    15.  
    16. public class PlayerDeath extends MGListener{
    17.  
    18. public PlayerDeath(Minigame pl) {
    19. super(pl);
    20. }
    21.  
    22.  
    23. @EventHandler(priority=EventPriority.MONITOR)
    24. public void onPlayerDeathLol(PlayerDeathEvent event){
    25. if (GameState.isState(GameState.IN_LOBBY)) return;
    26. event.setDeathMessage(null);
    27. event.getEntity().getPlayer().kickPlayer(ChatColor.RED + "Perdeu Playboy!");
    28. Player player = (Player) event.getEntity();
    29. String playername = player.getName();
    30. int op = Bukkit.getOnlinePlayers().length;
    31. ChatUtilities.broadcast(playername + " foi eliminado(a), " + ChatColor.AQUA + op + ChatColor.WHITE + " players restantes");
    32. Team.getTeam(player).remove(player);
    33. }
    34.  
    35.  
    36.  
    37. }
    38.  


    is there any way like this : ?
    Code:java
    1. Snowball s = // i don't know what i put here
    2. Player killer = s.getShooter;
    3. SoulMananger.addSoul(this, killer, 10);
     
  14. Offline

    Monkey_Swag

    timtower if someone needs help on a different language, I see no reason why communicating in a different language is a problem :/
     
  15. Offline

    thewalkingplay

    Monkey_Swag I agree, but answering your previous question, no , I do not speak Spanish, my language is Portuguese
     
  16. Offline

    Monkey_Swag

  17. Offline

    timtower Administrator Administrator Moderator

    Monkey_Swag Besides that the amount of people that can read it and help with it are significantly less?
     
  18. Offline

    mythbusterma

    Monkey_Swag timtower

    If I answer a question in this fashion, I tend to do it in both English and the speaker's language. This is beneficial to both the OP and anyone else who may need the help.
     
  19. Offline

    timtower Administrator Administrator Moderator

    mythbusterma I am okay with both. But they were only speaking their language.
     
  20. Offline

    thewalkingplay

    timtower no, i just spoke in Spanish because he spoke Spanish
    I never spoke portuguese here

    Sorry for my english again :/



    Anyone can help me?

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

    SuperOriginal

    Pretty sure there's a player#getKiller method
     
Thread Status:
Not open for further replies.

Share This Page