Longs not working correctly

Discussion in 'Plugin Development' started by Mike111177, Jun 10, 2012.

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

    Mike111177

    For some reason the variable check outputs two numbers and so it checks the second one and it automaticly cancels the event
    Code:java
    1. package net.othercraft.steelsecurity.listeners;
    2.  
    3. import java.util.HashMap;
    4. import java.util.List;
    5. import java.util.Map;
    6.  
    7. import net.othercraft.steelsecurity.Main;
    8. import net.othercraft.steelsecurity.utils.SSCmdExe;
    9.  
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.player.PlayerChatEvent;
    13.  
    14. public class ChatFilter extends SSCmdExe implements Listener {
    15.  
    16. public Main plugin;
    17.  
    18. Map<String, Long> chattimes = new HashMap<String, Long>();// for tracking the speed of chat
    19.  
    20. public ChatFilter(String name, Main instance) {
    21. super(name, true);//true only if its a listener, false if it isnt
    22. this.plugin = instance;
    23. }
    24.  
    25. @EventHandler
    26. public void onPlayerChat(PlayerChatEvent event){
    27. try {
    28. Boolean spam = true;//if this is true at the end cancel the event
    29. System.out.println(spam);//debug
    30. String name = event.getPlayer().getName();//name of the player for use in the hashmap
    31. Long time = System.currentTimeMillis();//current time
    32. Long lasttime = chattimes.get(name);//last time the player has chatted
    33. if(lasttime == null)lasttime = Long.valueOf(time - 1000);// default if the player hasnt chatted yet
    34. long check = (time - lasttime);//used to compare to the configured speed
    35. System.out.println(check);//debug
    36. chattimes.put(name, time);//overwrites the old time with the new one
    37. if (check > plugin.getConfig().getInt("AntiSpam.AntiFlood.Speed") || plugin.getConfig().getBoolean("AntiSpam.AntiFlood.Enabled") == false) {//checks if the speed of chat is faster than what is configured
    38. spam = false;//sets spam to false
    39. System.out.println(spam);//debug
    40. }
    41. System.out.println(spam);//debug
    42. String message = event.getMessage();//prepairs message for editing
    43. if ((spam == false)) {//only bothers with the anticaps and the censoring if it isnt spam.
    44. System.out.println(spam);//debug
    45. if (plugin.getConfig().getBoolean("AntiSpam.Censoring.Enabled") && event.getPlayer().hasPermission("steelsecurity.antispam.bypasscensor") == false) {//checks if it so scan for configured word
    46. @SuppressWarnings("unchecked")
    47. List<String> list = (List<String>) plugin.getConfig().getList("AntiSpam.Censoring.Block_Words");//retreives the list of blocked words
    48. int wordcount = list.size();//the length of the list of blocked words
    49. int wordcounter = 0;//i like using this instead of for loops becasue these are less restricting
    50. while (wordcounter<wordcount) {
    51. String newword;
    52. String badword = list.get(wordcounter);
    53. int lettercount = list.get(wordcounter).toCharArray().length;//word length
    54. int lettercounter = 0;
    55. newword = "";
    56. while (lettercounter < lettercount) {//used to generate a new word considting of *s
    57. newword = (newword + "*");
    58. ++lettercounter;
    59. }
    60. message = message.replaceAll("(?i)" + badword, newword);
    61. ++wordcounter;
    62. }
    63. }
    64.  
    65. if (event.getMessage().length()>plugin.getConfig().getInt("AntiSpam.AntiCaps.Minimum_Length")){//
    66. if (plugin.getConfig().getBoolean("AntiSpam.AntiCaps.Enabled") && event.getPlayer().hasPermission("steelsecurity.antispam.bypassanticaps") == false) {//checks for if it should do the anticaps check
    67. double percent = plugin.getConfig().getInt("AntiSpam.AntiCaps.Percent");//gets the configured percent
    68. int capcount = message.length();
    69. int capcounter = 0;
    70. Double uppercase = 0.0;
    71. Double lowercase = 0.0;
    72. while (capcounter<capcount) {
    73. if (message.toCharArray()[capcounter] == message.toLowerCase().toCharArray()[capcounter]) {//counts both upper case and lower case letters
    74. ++lowercase;
    75. }
    76. else {
    77. ++uppercase;
    78. }
    79. ++capcounter;
    80. }
    81. double total = uppercase + lowercase;
    82. double result = uppercase/total;
    83. percent = percent/100;
    84. if (percent<result){//converts to lowercase if needed
    85. message = message.toLowerCase();
    86. }
    87. }
    88. }
    89. event.setMessage(message);//changes message to newly generated one
    90. System.out.println(spam);//debug
    91. }
    92. System.out.println(spam);//debug
    93. event.setCancelled(spam);//cancel if it spam from the beginning
    94. }
    95. catch (Exception e){
    96. catchListenerException(e, event.getEventName());
    97. }
    98. }
    99.  
    100. }

    does anyone know how to fix this?
     
  2. I dont get what your problem is
     
  3. Offline

    Mike111177

    system.out.println(check); returns two numbers
     
  4. mayby you registered the event 2 times?
     
  5. Offline

    Mike111177

    i just checked but no it is only registered once.

    no wait never mind i did register it twice ty

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

Share This Page