Solved What the heck is wrong with this?

Discussion in 'Plugin Development' started by BlueMustache, Jul 6, 2014.

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

    BlueMustache

    Hey Guys,
    Quick question.

    I have some code I have been testing, and it is not up to snuff.
    Here are the symptoms:
    - No errors are made.
    - When I fire the events, it only shows me, not all players. (e.g. Block Break)

    The idea is that if someone breaks a block, or something else, it will notify everyone who has toggle debug on.
    What am I doing wrong?
    Please help.
    -Blue

    Code:java
    1. package core.bluemustache.modanalyzer;
    2.  
    3. import java.util.HashMap;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.Location;
    6. import org.bukkit.block.Block;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Entity;
    10. import org.bukkit.entity.EntityType;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.block.Action;
    15. import org.bukkit.event.block.BlockBreakEvent;
    16. import org.bukkit.event.block.BlockEvent;
    17. import org.bukkit.event.block.BlockFadeEvent;
    18. import org.bukkit.event.block.BlockFormEvent;
    19. import org.bukkit.event.block.BlockPlaceEvent;
    20. import org.bukkit.event.entity.EntityDeathEvent;
    21. import org.bukkit.event.player.PlayerInteractEntityEvent;
    22. import org.bukkit.event.player.PlayerInteractEvent;
    23. import org.bukkit.plugin.PluginManager;
    24. import org.bukkit.plugin.java.JavaPlugin;
    25.  
    26. public class PluginCore extends JavaPlugin
    27. implements Listener
    28. {
    29. public static HashMap<Player, String> active = new HashMap<Player, String>();
    30. public static int tid = 0;
    31. public static int running = 0;
    32. int interval = 30;
    33.  
    34. @SuppressWarnings("deprecation")
    35. public void onEnable()
    36. {
    37. getLogger().info("is now enabled");
    38. PluginManager pm = getServer().getPluginManager();
    39. pm.registerEvents(this, this);
    40. tid = Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable()
    41. {
    42. public void run()
    43. {
    44. System.runFinalization();
    45. System.gc();
    46. }
    47. }
    48. , 0L, this.interval * 20);
    49. }
    50.  
    51. public void onDisable()
    52. {
    53. getLogger().info("is now disabled");
    54. }
    55.  
    56. @EventHandler
    57. public void onBreak(BlockBreakEvent e) {
    58. Block blk = e.getBlock();
    59. Player pl = e.getPlayer();
    60. for (Player p : Bukkit.getOnlinePlayers())
    61. if (active.containsKey(p)) {
    62. p.sendMessage("BROKEN: " + blk.getType() + " + " + blk.getTypeId() + " + " + blk.getData());
    63. p.sendMessage("LOCATION: " + blk.getX() + " " + blk.getY() + " " + blk.getZ());
    64. p.sendMessage("PLAYER: " + pl.getName() + " + " + pl.getDisplayName());
    65. p.sendMessage("");
    66. } else {
    67. return;
    68. }
    69. }
    70.  
    71. @EventHandler
    72. public void onDerp(BlockEvent e) {
    73. Block blk = e.getBlock();
    74. for (Player p : Bukkit.getOnlinePlayers())
    75. if (active.containsKey(p)) {
    76. p.sendMessage("BLOCK: " + blk.getType() + " + " + blk.getTypeId() + " + " + blk.getData());
    77. p.sendMessage("LOCATION: " + blk.getX() + " " + blk.getY() + " " + blk.getZ());
    78. p.sendMessage("");
    79. } else {
    80. return;
    81. }
    82. }
    83.  
    84. @EventHandler
    85. public void onPlace(BlockPlaceEvent e) {
    86. Block blk = e.getBlock();
    87. Player pl = e.getPlayer();
    88. for (Player p : Bukkit.getOnlinePlayers())
    89. if (active.containsKey(p)) {
    90. p.sendMessage("PLACED: " + blk.getType() + " + " + blk.getTypeId() + " + " + blk.getData());
    91. p.sendMessage("LOCATION: " + blk.getX() + " " + blk.getY() + " " + blk.getZ());
    92. p.sendMessage("PLAYER: " + pl.getName() + " + " + pl.getDisplayName());
    93. p.sendMessage("");
    94. } else {
    95. return;
    96. }
    97. }
    98.  
    99. @EventHandler
    100. public void onForm(BlockFormEvent e)
    101. {
    102. Block blk = e.getBlock();
    103. for (Player p : Bukkit.getOnlinePlayers())
    104. if (active.containsKey(p)) {
    105. p.sendMessage("FORM: " + blk.getType() + " + " + blk.getTypeId() + " + " + blk.getData());
    106. p.sendMessage("LOCATION: " + blk.getX() + " " + blk.getY() + " " + blk.getZ());
    107. p.sendMessage("");
    108. } else {
    109. return;
    110. }
    111. }
    112.  
    113. @EventHandler
    114. public void onFade(BlockFadeEvent e) {
    115. Block blk = e.getBlock();
    116. for (Player p : Bukkit.getOnlinePlayers())
    117. if (active.containsKey(p)) {
    118. p.sendMessage("FADE: " + blk.getType() + " + " + blk.getTypeId() + " + " + blk.getData());
    119. p.sendMessage("LOCATION: " + blk.getX() + " " + blk.getY() + " " + blk.getZ());
    120. p.sendMessage("");
    121. } else {
    122. return;
    123. }
    124. }
    125.  
    126. @EventHandler
    127. public void onDeath(EntityDeathEvent e) {
    128. Entity ent = e.getEntity();
    129. Location loc = ent.getLocation();
    130. EntityType typ = ent.getType();
    131. for (Player p : Bukkit.getOnlinePlayers())
    132. if (active.containsKey(p)) {
    133. p.sendMessage("DEATH: " + ent.getType() + " + " + typ.getTypeId() + " + " + typ.getName());
    134. p.sendMessage("LOCATION: " + loc.getX() + " " + loc.getY() + " " + loc.getZ());
    135. p.sendMessage("");
    136. } else {
    137. return;
    138. }
    139. }
    140.  
    141. @EventHandler
    142. public void onClick(PlayerInteractEvent e) {
    143. Player p = e.getPlayer();
    144. Block blk = e.getClickedBlock();
    145. if (active.containsKey(p)) {
    146. if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    147. p.sendMessage("CLICK: " + blk.getType() + " + " + blk.getTypeId() + " + " + blk.getData());
    148. p.sendMessage("LOCATION: " + blk.getX() + " " + blk.getY() + " " + blk.getZ());
    149. p.sendMessage("");
    150. }
    151. }
    152. else;
    153. }
    154.  
    155. @EventHandler
    156. public void onEntityInteract(PlayerInteractEntityEvent e)
    157. {
    158. Player p = e.getPlayer();
    159. Entity ent = e.getRightClicked();
    160. Location loc = ent.getLocation();
    161. EntityType typ = ent.getType();
    162. if (active.containsKey(p)) {
    163. p.sendMessage("ENTITY: " + ent.getType() + " + " + typ.getTypeId() + " + " + typ.getName());
    164. p.sendMessage("LOCATION: " + loc.getX() + " " + loc.getY() + " " + loc.getZ());
    165. p.sendMessage("");
    166. }
    167. else;
    168. }
    169.  
    170. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    171. {
    172. if (!(sender instanceof Player)) {
    173. sender.sendMessage("Nope, Chuck Testa! ;)");
    174. }
    175. else if (commandLabel.equalsIgnoreCase("toggledebug")) {
    176. Player player = (Player)sender;
    177. if (active.containsKey(player)) {
    178. active.remove(player);
    179. player.sendMessage("OFF: Debugging disabled!");
    180. player.sendMessage("");
    181. } else {
    182. active.put(player, null);
    183. player.sendMessage("ON: Debugging activated.");
    184. player.sendMessage("");
    185. }
    186. }
    187.  
    188. return false;
    189. }
    190. }
     
  2. Offline

    Gamesareme

    Would a bukkit brodcast work?
     
  3. Offline

    DevRosemberg

    BlueMustache Why are you using a HashMap? use an ArrayList or a HashSet, do not store player objects, store their UUIDS or Names.
     
  4. Offline

    BlueMustache

    Gamesareme
    I want it to be only announced to those that have it enabled.
    DevRosemberg
    Because I am using the hashmaps, and they work.
    Also, this is for a pre-uuid server. (I hate UUID's, and it is no reason, it wouldn't work, which it does.)
     
  5. Offline

    Gater12

    BlueMustache
    You should use a List or a Set. HashMap should be use if you want to associate a value with an object. A List or a Set well... creates a list or a set of some object.

    You should use player names, if not UUIDs.
     
  6. Offline

    BlueMustache

    Gater12
    Examples?
    If I had known to do this, I would have done it.
    I just want to print those events to everyone who has toggledebug enabled, no matter who or what triggered the event.
     
  7. Offline

    Gater12

  8. Offline

    BlueMustache

    Solved!
    Thanks.
     
Thread Status:
Not open for further replies.

Share This Page