Plugin is perfect - Need someone to double check though

Discussion in 'Plugin Development' started by Slokh, Oct 1, 2013.

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

    Slokh

    My plugin works exactly like I intended it to. The only problem is random lag spikes. So if someone were to be kind enough to just check this out real quick, it would be a great help and I would really appreciate it.

    http://pastebin.com/JCXc779h
     
  2. Offline

    felixfritz

    It would be nice to get some more information. What is your plugin supposed to do? Could you potentially also add some comments in the code so it's easier to understand what you were trying to do? When does it get laggy?
     
    1Achmed1 likes this.
  3. Offline

    oscarshi1995

    May I suggest splitting your plugin into more than one file?
     
  4. I would like to check it out, but can you split it in multiple files and put it on GitHub? It just gets much less complicated that way. Documention works as well.
     
  5. Offline

    Plo124

    Code:java
    1.  
    2. if(event.getEntity() instanceof Player){
    3. if(event.getCause() == EntityDamageEvent.DamageCause.FALL){ // EntityDamageEvent shouldn't be there
    4. event.setCancelled(true);
    5. }
    6. }
    7.  

    Problem 1: EntityDamageEvent is not required for the DamageCause event

    Code:java
    1.  
    2. for(Player p : Bukkit.getOnlinePlayers()){
    3. if(p != e.getPlayer()){
    4. p.sendMessage(ChatColor.LIGHT_PURPLE + e.getPlayer().getName() + " has joined the PvP Arena!");
    5. }
    6. }
    7.  

    Problem 2: Why do you want the original player not to have the join message, you can also use Bukkit.broadcastMessage("message") if you want to broadcast the join message. At the very least you could reduce the load on the server by sending blank lines...
    Code:java
    1. q.sendMessage("");
    2. q.sendMessage("");
    3. q.sendMessage("");
    4. q.sendMessage("");
    5. q.sendMessage("");
    6.  



    Code:java
    1.  
    2. @EventHandler
    3. public void onTeleport(PlayerTeleportEvent event)
    4. {
    5. Player player = event.getPlayer();
    6. for (Player p : Bukkit.getOnlinePlayers())
    7. {
    8. if (p.canSee(player))
    9. p.showPlayer(player);
    10. }
    11. }

    Warning 3: Do you really need to show the player to all the players, this is the possible lag cause, I understand its the new TP lag when they teleport though.


    And I haven't checked the onCommand method (I gotta go)
     
  6. Offline

    MrSnare

    You should create a bot that makes this comment on every single thread :p
     
  7. Offline

    Loogeh

    This is only for cleanliness but in the onEnable() you can make the for loops 1 line.

    e.g

    Code:
    for (String key : this.getConfig().getConfigurationSection("hwinstreak").getKeys(false)) hwinstreak.put(key, this.getConfig().getInt("hwinstreak." + key));
    
     
    1Achmed1 likes this.
  8. Offline

    Ultimate_n00b

    It's not really cleaner to use a sing line.
     
  9. Offline

    Loogeh

    Ultimate_n00b In my opinion it is, but they can have it however he wants I was just putting it out there in case they didn't know you can do that.
     
  10. Offline

    Slokh

    Alright guys thanks a lot. I'll be doing some of the things stated here.
    Plo124 especially. Just wondering, if I have multiple classes can it reduce lag?
     
  11. Offline

    Plo124

    Slokh Multiple classes makes it easier to organise your data, it might reduce lag, but probably not.
     
  12. Offline

    FurmigaHumana

    Try removing this and see if the lag stops:

    Code:java
    1. @EventHandler
    2. public void onTeleport(PlayerTeleportEvent event)
    3. {
    4. Player player = event.getPlayer();
    5. for (Player p : Bukkit.getOnlinePlayers())
    6. {
    7. if (p.canSee(player))
    8. p.showPlayer(player);
    9. }
    10. }


    It is probably the only intensive operation;
     
  13. Offline

    Slokh

    Plo124 and FurmigaHumana So do you know any other way to make it so that people aren't invisible on teleport?
     
  14. Offline

    Loogeh

    Slokh I don't know how to do this but you can resend the packet for visible people. I don't know what packet it is either, but I know you can because VanishNoPacket stops a packet from being sent (i think). So, you could just do the opposite.

    Also, going by the code which FurmigaHumana posted, you're checking if the players can see the other player. Then inside that if statement you're showing the player. I think you wanted to check if the player can't see another player instead.
     
Thread Status:
Not open for further replies.

Share This Page