Where have I gone wrong?

Discussion in 'Plugin Development' started by ZapChance, Mar 10, 2014.

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

    ZapChance

    Code:java
    1. package com.zapchance.reportrts.command;
    2.  
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandExecutor;
    5. import org.bukkit.command.CommandSender;
    6. import com.zapchance.reportrts.RTSPermissions;
    7. import com.zapchance.reportrts.ReportRTS;
    8. import com.zapchance.reportrts.util.Message;
    9.  
    10. public class ModlistCommand implements CommandExecutor {
    11.  
    12. public boolean onCommand(CommandSender sender, Command cmd, String label,
    13. String[] args) {
    14. if (!RTSPermissions.canListStaff(sender)) {
    15. return true;
    16. }
    17. double start = 0.0D;
    18. if (ReportRTS.getPlugin().debugMode) {
    19. start = System.nanoTime();
    20. }
    21. String staff = "";
    22. String separator = Message.parse("modlistMessageSeparator",
    23. new Object[0]);
    24. for (String name : ReportRTS.getPlugin().moderatorMap) {
    25. staff = staff + name + separator;
    26. }
    27. if (staff.length() == 0) {
    28. sender.sendMessage(Message.parse("modlistNoMods", new Object[0]));
    29. return true;
    30. }
    31. staff = staff.substring(0, staff.length() - separator.length());
    32.  
    33. sender.sendMessage(Message.parse("modlistMessage",
    34. new Object[] { staff }));
    35. if (ReportRTS.getPlugin().debugMode) {
    36. Message.debug(sender.getName(), getClass().getSimpleName(), start,
    37. cmd.getName(), args);
    38. }
    39. return true;
    40. }
    41.  
    42. }
    43.  


    Code:java
    1. package com.zapchance.reportrts;
    2.  
    3. import java.sql.ResultSet;
    4. import java.sql.SQLException;
    5. import java.util.ArrayList;
    6. import java.util.Iterator;
    7. import java.util.Map;
    8.  
    9. import org.bukkit.block.Block;
    10. import org.bukkit.block.Sign;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.EventPriority;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.block.SignChangeEvent;
    15. import org.bukkit.event.player.PlayerJoinEvent;
    16. import org.bukkit.event.player.PlayerQuitEvent;
    17.  
    18. import com.btilm305.meep.meepteleport.CrossServerLocation;
    19. import com.zapchance.reportrts.data.HelpRequest;
    20. import com.zapchance.reportrts.persistance.DatabaseManager;
    21. import com.zapchance.reportrts.util.Message;
    22.  
    23. public class RTSListener implements Listener {
    24.  
    25. private final ReportRTS plugin;
    26.  
    27. public RTSListener(ReportRTS plugin) {
    28. this.plugin = plugin;
    29. }
    30.  
    31. @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    32. public void onPlayerJoin(PlayerJoinEvent event) {
    33. if (this.plugin.notificationMap.size() > 0) {
    34. @SuppressWarnings({ "unchecked", "rawtypes" })
    35. ArrayList<Integer> keys = new ArrayList();
    36. for (Map.Entry<Integer, String> entry : this.plugin.notificationMap
    37. .entrySet()) {
    38. if (((String) entry.getValue()).equals(event.getPlayer()
    39. .getName())) {
    40. ResultSet rs = DatabaseManager.getDatabase().getTicketById(
    41. ((Integer) entry.getKey()).intValue());
    42. try {
    43. if (this.plugin.storageType.equalsIgnoreCase("mysql")) {
    44. rs.first();
    45. }
    46. event.getPlayer().sendMessage(
    47. Message.parse("completedUserOffline",
    48. new Object[0]));
    49. String comment = rs.getString("mod_comment");
    50. if (comment == null) {
    51. comment = "";
    52. }
    53. event.getPlayer().sendMessage(
    54. Message.parse("completedText", new Object[] {
    55. rs.getString("text"), comment }));
    56. rs.close();
    57. if (!DatabaseManager.getDatabase()
    58. .setNotificationStatus(
    59. ((Integer) entry.getKey()).intValue(),
    60. 1)) {
    61. this.plugin.getLogger().warning(
    62. "Unable to set notification status to 1.");
    63. }
    64. keys.add(entry.getKey());
    65. } catch (SQLException e) {
    66. e.printStackTrace();
    67. }
    68. }
    69. }
    70. int key;
    71. for (@SuppressWarnings("rawtypes")
    72. Iterator i$ = keys.iterator(); i$.hasNext(); this.plugin.notificationMap
    73. .remove(Integer.valueOf(key))) {
    74. key = ((Integer) i$.next()).intValue();
    75. }
    76. }
    77. if (!RTSPermissions.isModerator(event.getPlayer())) {
    78. return;
    79. }
    80. if (!this.plugin.moderatorMap.contains(event.getPlayer().getName())) {
    81. this.plugin.moderatorMap.add(event.getPlayer().getName());
    82. this.plugin.request(event.getPlayer().getName(), "RTSJoin");
    83. }
    84. int openRequests = this.plugin.requestMap.size();
    85. if ((openRequests < 1) && (!this.plugin.hideNotification)) {
    86. event.getPlayer().sendMessage(
    87. Message.parse("generalNoRequests", new Object[0]));
    88. }
    89. if (openRequests > 0) {
    90. event.getPlayer().sendMessage(
    91. Message.parse("generalOpenRequests",
    92. new Object[] { Integer.valueOf(openRequests) }));
    93. }
    94. if ((event.getPlayer().isOp()) && (this.plugin.outdated)) {
    95. event.getPlayer().sendMessage(
    96. Message.parse("outdatedPlugin",
    97. new Object[] { this.plugin.versionString }));
    98. }
    99. }
    100.  
    101. @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    102. public void onSignChange(SignChangeEvent event) {
    103. Block block = event.getBlock();
    104. if (!(block.getState() instanceof Sign)) {
    105. return;
    106. }
    107. if (!event.getLine(0).equalsIgnoreCase("[help]")) {
    108. return;
    109. }
    110. if (!RTSPermissions.canFileRequest(event.getPlayer())) {
    111. block.breakNaturally();
    112. return;
    113. }
    114. String[] text = new String[3];
    115. System.arraycopy(event.getLines(), 1, text, 0, 3);
    116. String message = RTSFunctions.cleanUpSign(text);
    117. if (message.length() == 0) {
    118. event.getPlayer().sendMessage(
    119. Message.parse("generalInternalError",
    120. new Object[] { "Help signs can't be empty." }));
    121. block.breakNaturally();
    122. return;
    123. }
    124. if ((RTSFunctions.getOpenRequestsByUser(event.getPlayer()) >= this.plugin.maxRequests)
    125. && (ReportRTS.permission != null ? !ReportRTS.permission
    126. .has(event.getPlayer(),
    127. "reportrts.command.modreq.unlimited") : !event
    128. .getPlayer().hasPermission(
    129. "reportrts.command.modreq.unlimited"))) {
    130. event.getPlayer().sendMessage(
    131. Message.parse("modreqTooManyOpen", new Object[0]));
    132. block.breakNaturally();
    133. return;
    134. }
    135. int userId = DatabaseManager.getDatabase().getUserId(
    136. event.getPlayer().getName(), true);
    137. if (DatabaseManager.getDatabase().fileRequest(
    138. event.getPlayer().getName(),
    139. new CrossServerLocation(event.getPlayer().getLocation()),
    140. message, userId)) {
    141. int ticketId = DatabaseManager.getDatabase()
    142. .getLatestTicketIdByUser(userId);
    143. this.plugin.requestMap.put(Integer.valueOf(ticketId),
    144. new HelpRequest(event.getPlayer().getName(), ticketId,
    145. System.currentTimeMillis() / 1000L, message, 0,
    146. event.getPlayer().getLocation().getBlockX(), event
    147. .getPlayer().getLocation().getBlockY(),
    148. event.getPlayer().getLocation().getBlockZ(), event
    149. .getPlayer().getLocation().getYaw(), event
    150. .getPlayer().getLocation().getPitch(),
    151. event.getPlayer().getWorld().getName(),
    152. CrossServerLocation.getCurrentServer()));
    153. event.getPlayer().sendMessage(
    154. Message.parse("modreqFiledUser", new Object[0]));
    155. RTSFunctions.messageMods(
    156. Message.parse(
    157. "modreqFiledMod",
    158. new Object[] { event.getPlayer().getName(),
    159. Integer.valueOf(ticketId) }), true);
    160. }
    161. }
    162.  
    163. @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    164. public void onPlayerQuit(PlayerQuitEvent event) {
    165. if (this.plugin.moderatorMap.contains(event.getPlayer().getName())) {
    166. this.plugin.moderatorMap.remove(event.getPlayer().getName());
    167. this.plugin.request(event.getPlayer().getName(), "RTSQuit");
    168. }
    169. }
    170. }
    171.  


    Code:java
    1. package com.zapchance.reportrts;
    2.  
    3. import java.io.UnsupportedEncodingException;
    4.  
    5. import lilypad.client.connect.api.event.MessageEvent;
    6. import lilypad.client.connect.api.event.EventListener;
    7.  
    8. public class MessageListener {
    9.  
    10. private final ReportRTS plugin;
    11.  
    12. public MessageListener(ReportRTS plugin) {
    13. this.plugin = plugin;
    14. }
    15.  
    16. public void onLilyPadMessageEvent(MessageEvent event) {
    17. String channel = event.getChannel();
    18. if (channel.equals("RTSJoin")) {
    19. try {
    20.  
    21. String messageAsString = event.getMessageAsString();
    22. if (!this.plugin.moderatorMap.contains(messageAsString)) {
    23. this.plugin.moderatorMap.add(messageAsString);
    24. }
    25.  
    26. } catch (UnsupportedEncodingException exception) {
    27.  
    28. }
    29. } else if (channel.equals("RTSQuit")) {
    30. try {
    31. String messageAsString = event.getMessageAsString();
    32. if (this.plugin.moderatorMap.contains(messageAsString)) {
    33. this.plugin.moderatorMap.remove(messageAsString);
    34. }
    35.  
    36. } catch (UnsupportedEncodingException exception) {
    37.  
    38. }
    39. }
    40. }
    41.  
    42. }
    43.  


    The player is added to the moderatorMap successfully, but, when the command is executed, is not shown. Where have I gone wrong?!
     
  2. Offline

    ZapChance

  3. Offline

    MrAwellstein

    Could you not?
    Btw please include StackTrace.

    Shouldnt MessageListener implement listener?

    Edit1: What about your main method?

    Edit2:
    Code:java
    1. } catch (UnsupportedEncodingException exception) {
    2.  
    3. }

    As shown above, you don't print out StackTraces, or any debug type of message. Try and Catches aren't just for making sure your code doesn't error out you know.

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

    ZapChance

    There is no stack trace.

    No, it should not. And in this case, I do not wNt to print the StackTrace as is would fire most often, seeing it is connecting to an external server.

    Please educate yourself before you make rude posts like I don't know what I am doing :) Also, I am permitted to bump the thread seeing it is over a week old.
     
  5. Offline

    MrAwellstein

    I don't think you understand, part of the knowledge of basic programming is having the ability to know to have system.outs eveRywhere when you are debugging, and know a general idea where your problem is. Honestly, no one has to help you, and it would have helped for you to tell us exactly what you were trying to do.

    Edit: considering its a week old, I'm assuming you haven't tried anything on your own...
     
  6. Offline

    ProjectInfinity

    Not sure you should be asking LilyPad related questions here as most people here only work with Bukkit and thus cannot debug your LilyPad specific code that may or may not interfere with the result of the command.

    Also you are not very specific with what you are trying to do, but from what I can tell it's either not what I intended when I created ReportRTS (which is cool, but makes me clueless about what's actually going on) or it's specific to a non-Bukkit server software/wrapper.
     
    MrAwellstein likes this.
  7. Offline

    ZapChance

    FYI, I have tried it all. Debugging w/ System.out returned successful, yet it does not seem to work.

    Correct, this is a modified version of ReportRTS integrated to work with the LilyPad server system. But, the reason I have posted this here on bukkit.org, is due to the fact I have checked and doubled checked that the issues lies not within the LilyPad parts, yet the RTS parts.

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

    AoH_Ruthless

    ZapChance
    We don't even know what the code is supposed to be doing. We can't help you if we don't know what the desired function of your code is.

    In your try / catch blocks, if you don't want to print your stacktrace, use System.out.println("debug1");. Stuff like that.

    Also, visit here to report your issue and get help and support. Unofficial Builds are not supported here. It doesn't matter if the issue isn't related to the LilyPad. Because your code uses Lilypad in it's build path, we cannot help you.
     
  9. Offline

    TnT

    Locked. Seek support for the software you are using from the place you found that software.
     
    MrAwellstein likes this.
Thread Status:
Not open for further replies.

Share This Page