Crashing when dealing with fake players

Discussion in 'Plugin Development' started by Jobi, Oct 16, 2014.

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

    Jobi

    I'm currently writing an own modified anticheat plugin and I've got some problems with a kill aura hack detection. The problem is not that it's not working, but that the clients, when more than one player is online, are randomly crashing, usually when the other client joins. Sometimes the client is not crashing and I receive an error when I'm trying the join. I'm using ProtocolLib version 3.4.0 and it's only crashing 1.7 clients, 1.8 works fine.

    Crash Report
    http://paste.multicu.be/niqenutoli

    Most common error
    [​IMG]

    My code
    Code:java
    1.  
    2. import be.multicu.core.util.ModifiableFinal;
    3. import be.multicu.rubix.Rubix;
    4. import static be.multicu.rubix.Rubix.random;
    5. import be.multicu.rubix.anticheat.Module;
    6. import com.comphenix.packetwrapper.WrapperPlayClientUseEntity;
    7. import com.comphenix.packetwrapper.WrapperPlayServerEntityDestroy;
    8. import com.comphenix.packetwrapper.WrapperPlayServerNamedEntitySpawn;
    9. import com.comphenix.protocol.ProtocolLibrary;
    10. import com.comphenix.protocol.events.PacketAdapter;
    11. import com.comphenix.protocol.events.PacketEvent;
    12. import com.comphenix.protocol.wrappers.WrappedDataWatcher;
    13. import java.util.HashMap;
    14. import java.util.UUID;
    15. import org.bukkit.Bukkit;
    16. import org.bukkit.entity.Player;
    17. import org.bukkit.scheduler.BukkitTask;
    18. import org.bukkit.util.Vector;
    19.  
    20. /**
    21.  *
    22.  * @author Jonas
    23.  */
    24. public class KillAuraModule extends Module {
    25.  
    26. private HashMap<Player, KillAuraCheck> activeChecks;
    27. private BukkitTask task;
    28.  
    29. @Override
    30. protected void startModule() {
    31. activeChecks = new HashMap<>();
    32. registerPacketListener();
    33. startCheckLoop();
    34. }
    35.  
    36. @Override
    37. protected void stopModule() {
    38. unregisterPacketListener();
    39. task.cancel();
    40. }
    41.  
    42. @Override
    43. protected void punish(Player player) {
    44. punish(player, player.getName() + " seems to be using a kill aura hack.");
    45. }
    46.  
    47. private void startCheckLoop() {
    48. final ModifiableFinal<Integer> tick = new ModifiableFinal<>(0);
    49. task = Bukkit.getScheduler().runTaskTimer(Rubix.getInstance(), new Runnable() {
    50. @Override
    51. public void run() {
    52. for(Player player : Bukkit.getOnlinePlayers()) {
    53. if(activeChecks.containsKey(player)) {
    54. KillAuraCheck check = activeChecks.get(player);
    55. if(check.getDurationLeft() == 0) {
    56. check.end();
    57. activeChecks.remove(player);
    58. }
    59. else {
    60. check.setDurationLeft(check.getDurationLeft() - 1);
    61. }
    62. }
    63. else {
    64. if(tick.getValue() % 200 == 0) {
    65. Bukkit.broadcastMessage("Checking " + player.getName());
    66. activeChecks.put(player, new KillAuraCheck(player));
    67. }
    68. }
    69. }
    70. tick.setValue(tick.getValue() + 1);
    71. }
    72. }, 0, 1);
    73. }
    74.  
    75. public void registerPacketListener() {
    76. ProtocolLibrary.getProtocolManager().addPacketListener(
    77. new PacketAdapter(Rubix.getInstance(), WrapperPlayClientUseEntity.TYPE) {
    78. @Override
    79. public void onPacketReceiving(PacketEvent event) {
    80. if (event.getPacketType() == WrapperPlayClientUseEntity.TYPE) {
    81. int entID = new WrapperPlayClientUseEntity(event.getPacket()).getTargetID();
    82. if (activeChecks.containsKey(event.getPlayer())) {
    83. KillAuraCheck check = activeChecks.get(event.getPlayer());
    84. if(entID == check.getEntityID()) {
    85. event.setCancelled(true);
    86. check.end();
    87. punish(event.getPlayer());
    88. activeChecks.remove(event.getPlayer());
    89. }
    90. }
    91. }
    92. }
    93. }
    94. );
    95. }
    96.  
    97. public void unregisterPacketListener() {
    98. ProtocolLibrary.getProtocolManager().removePacketListeners(Rubix.getInstance());
    99. }
    100.  
    101. private static class KillAuraCheck {
    102.  
    103. private int duration = 5;
    104. private final int entityID;
    105. private final Player player;
    106.  
    107. protected KillAuraCheck(Player player) {
    108. this.player = player;
    109. WrapperPlayServerNamedEntitySpawn packet = getWrapper(player.getLocation().toVector().subtract(player.getLocation().getDirection().setY(0).normalize()));
    110. entityID = packet.getEntityID();
    111. packet.sendPacket(player);
    112. }
    113.  
    114. protected int getEntityID() {
    115. return entityID;
    116. }
    117.  
    118. private WrapperPlayServerNamedEntitySpawn getWrapper(Vector loc) {
    119. WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
    120. wrapper.setEntityID(random.nextInt(20000));
    121. wrapper.setPosition(loc);
    122. wrapper.setPlayerUUID(UUID.randomUUID().toString());
    123. wrapper.setPlayerName("FAKE" + String.valueOf(random.nextInt(10000)));
    124. wrapper.setYaw(0);
    125. wrapper.setPitch(-45);
    126. wrapper.setCurrentItem((short)0);
    127. WrappedDataWatcher watcher = new WrappedDataWatcher();
    128. watcher.setObject(0, (byte)0x20);
    129. watcher.setObject(6, 0.5f);
    130. watcher.setObject(11, (byte)1);
    131. wrapper.setMetadata(watcher);
    132. return wrapper;
    133. }
    134.  
    135. public void end() {
    136. WrapperPlayServerEntityDestroy packet = new WrapperPlayServerEntityDestroy();
    137. packet.setEntities(new int[]{entityID});
    138. packet.sendPacket(player);
    139. }
    140.  
    141. public int getDurationLeft() {
    142. return duration;
    143. }
    144.  
    145. public void setDurationLeft(int duration) {
    146. this.duration = duration;
    147. }
    148. }
    149. }


    Update: It's usually crashing/kicking everyone when a new player joins.

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

    teej107

    Jobi Stacktrace from the server console?
     
  3. Offline

    Jobi

    There is no stacktrace since there was no error.
     
  4. Offline

    teej107

    Are you using an NPC library?
     
  5. Offline

    teej107

    Assist Ah lol, this doesn't have to do with creating server side fake players.
    Jobi Don't know exactly how to fix this problem, but try having your arguments for your WrapperPlayServerNamedEntitySpawn setters be smaller values.
     
  6. Offline

    Jobi

    No, thats not causing it.
     
  7. Offline

    Jobi

    Does anyone have an idea?
     
  8. Offline

    fireblast709

  9. Offline

    Jobi

    Thank you, simply removing it fixed it!
     
Thread Status:
Not open for further replies.

Share This Page