Solved Plugin won't work

Discussion in 'Plugin Development' started by Ian0526, Jul 25, 2013.

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

    Ian0526

    I am almost finished but the plugin won't do what I want it to do. Players won't receive their money with the permission.
    Code:java
    1. package me.Ian0526.ZetaCraftFJDonor;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import net.milkbowl.vault.economy.Economy;
    6. import net.milkbowl.vault.economy.EconomyResponse;
    7.  
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.player.PlayerLoginEvent;
    15. import org.bukkit.inventory.ItemStack;
    16. import org.bukkit.plugin.Plugin;
    17. import org.bukkit.plugin.RegisteredServiceProvider;
    18. import org.bukkit.plugin.java.JavaPlugin;
    19.  
    20. public class Core extends JavaPlugin implements Listener {
    21. public static Plugin plugin;
    22. public final Logger logger = Logger.getLogger("Minecraft");
    23. public static Economy econ = null;
    24.  
    25. public void onEnable() {
    26. getServer().getPluginManager().registerEvents(this, this);
    27. if (!setupEconomy() ) {
    28. logger.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
    29. getServer().getPluginManager().disablePlugin(this);
    30. return;
    31. }
    32. }
    33.  
    34. private boolean setupEconomy() {
    35. if (getServer().getPluginManager().getPlugin("Vault") == null) {
    36. return false;
    37. }
    38. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    39. if (rsp == null) {
    40. return false;
    41. }
    42. econ = rsp.getProvider();
    43. return econ != null;
    44. }
    45.  
    46. public void onDisable() {
    47. this.logger.info("[ZetaCraftFJDonor] Plugin Disabled");
    48. logger.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
    49. }
    50. @EventHandler
    51. public void PlayerJoin(PlayerLoginEvent event) {
    52. Player player = event.getPlayer();
    53. if(!event.getPlayer().hasPlayedBefore()) {
    54. econ.depositPlayer(player.getName(), 0);
    55. } else {
    56. if(player.hasPermission("donor.knight")) {
    57. econ.depositPlayer(player.getName(), 1000);
    58. player.sendMessage("§a$1000 has been added to your account, due to a previous donation.");
    59. }
    60. }
    61. }
    62. }
     
  2. Offline

    soulofw0lf

    does the message get sent? have you tried putting a message in for the first join check? any errors in console?
     
  3. Offline

    Ian0526

    No errors, and I haven't tried sending a message, do you mind showing me how? soulofw0lf
     
  4. Offline

    soulofw0lf

    econ.depositPlayer(player.getName(), 0);
    system.out.print("This is a test message to the console, a new player has gotten money");
     
  5. Offline

    Ian0526

    soulofw0lf system is underlined red, is their a variable for it
     
  6. Offline

    soulofw0lf

    System sorry :p
     
  7. Offline

    Ian0526

  8. Offline

    soulofw0lf

    ok that's a good thing, it's helping to narrow down the problem, just place little messages like that foryourself in all the different parts of the code to narrow down exactly where it's stopping what it should be doing.
     
  9. Offline

    SnipsRevival

    Use System.out.println(message)
     
  10. Offline

    xTrollxDudex

    Ian0526
    Have you opped yourself or given yourself the permission?
     
  11. Offline

    soulofw0lf

    the only difference between print and println is a carriage return which in no way effects anything here at all... there's no need to tell someone to use something else when they are obviously new to coding and just trying to learn how to do trouble shooting. please don't confuse the matter.
     
  12. Offline

    Ian0526

    xTrollxDudex Yeah I have here is my current eventhandler
    Code:java
    1. @EventHandler
    2. public void PlayerJoin(PlayerLoginEvent event) {
    3. Player player = event.getPlayer();
    4. if(!event.getPlayer().hasPlayedBefore()) {
    5. econ.depositPlayer(player.getName(), 0);
    6. } else {
    7. if(player.hasPermission("donor.knight")) {
    8. econ.depositPlayer(player.getName(), 1000);
    9. event.getPlayer().sendMessage("§a$1000 has been added to your account, due to a previous donation.");
    10. System.out.print("This is a test message to the console, a new player has gotten money");


    soulofw0lf Hey do you think you can still help me?

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

    soulofw0lf

    @Ian0526 did you ever put in all the system print messages to see where it was cutting off?
    @EventHandler
    publicvoid PlayerJoin(PlayerLoginEvent event){
    System.out.print("beginning of event");
    Player player = event.getPlayer();
    System.out.print("Player set");
    if(!event.getPlayer().hasPlayedBefore()){
    System.out.print("player has not played");
    econ.depositPlayer(player.getName(), 0);
    System.out.print("player now has 0");
    }else{
    System.out.print("player has played!");
    if(player.hasPermission("donor.knight")){
    System.out.print("player is a donor!");
    econ.depositPlayer(player.getName(), 1000);
    System.out.print("giving away 1000!!");
    event.getPlayer().sendMessage("§a$1000 has been added to your account, due to a previous donation.");
    System.out.print("This is a test message to the console, a new player has gotten money");
     
  14. Offline

    Ian0526

    soulofw0lf Okay I got the messages.
    1. beginning of event
    2. player set
    3. player has played
    4. player did not receive money
    I edited the code like so
    Code:java
    1. @EventHandler
    2. public void PlayerJoin(PlayerLoginEvent event){
    3. System.out.print("beginning of event");
    4. Player player = event.getPlayer();
    5. System.out.print("Player set");
    6. if(!event.getPlayer().hasPlayedBefore()){
    7. System.out.print("player has played");
    8. econ.depositPlayer(player.getName(), 0);
    9. System.out.print("player did not receive money");
    10. }else{
    11. System.out.print("player has not played!");
    12. if(player.hasPermission("donor.knight")){
    13. System.out.print("player is a donor!");
    14. econ.depositPlayer(player.getName(), 1000);
    15. System.out.print("giving away 1000!!");
    16. event.getPlayer().sendMessage("§a$1000 has been added to your account, due to a previous donation.");
    17. System.out.print("This is a test message to the console, a new player has gotten money");
     
  15. Offline

    SnipsRevival

    When you say
    Code:
    if(!event.getPlayer().hasPlayedBefore())
    what you are really saying is
    Code:
    if(event.getPlayer().hasPlayedBefore() == false)
    Based on your debugging messages, you want the if statement to say the opposite, so get rid of the exclamation mark at the beginning of the if statement.
     
  16. Offline

    Ian0526

    SnipsRevival I relogged and got the same responses
     
  17. Offline

    SnipsRevival

    You put
    Code:
    if(event.getPlayer().hasPlayedBefore())
    once you corrected it, right?
     
  18. Offline

    Ian0526

    Okay I did that, now everytime I join it gives me 1000 x) SnipsRevival

    I lied.

    Ah HA, I had the incorrect event. I was using PlayerLoginEvent, it is suppose to be PlayerJoinEvent. If anyone has this issue I hope this aides you in the future :) Here is my coding.
    Code:java
    1. @EventHandler
    2. public void PlayerJoin(PlayerJoinEvent event){
    3. System.out.print("beginning of event");
    4. Player player = event.getPlayer();
    5. System.out.print("Player set");
    6. if(player.hasPlayedBefore()){
    7. System.out.print("player has played");
    8. econ.depositPlayer(player.getName(), 0);
    9. System.out.print("player now has 0");
    10. }else{
    11. System.out.print("player has not played");
    12. if(player.hasPermission("donor.knight")){
    13. System.out.print("player is a donor!");
    14. econ.depositPlayer(player.getName(), 1000);
    15. System.out.print("giving away 1000!!");
    16. event.getPlayer().sendMessage("§a$1000 has been added to your account, due to a previous donation.");
    17. System.out.print("This is a test message to the console, a new player has gotten money");


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page