diff --git a/Core.iml b/Core.iml
index 0db5ae1..dff817f 100644
--- a/Core.iml
+++ b/Core.iml
@@ -20,16 +20,16 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index a32cdad..b12116c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -96,6 +96,7 @@
org.spigotmc
spigot-api
1.9.2-R0.1-SNAPSHOT
+ provided
diff --git a/src/main/java/eu/univento/cloud/client/CloudMessenger.java b/src/main/java/eu/univento/cloud/client/CloudMessenger.java
new file mode 100644
index 0000000..832c7e3
--- /dev/null
+++ b/src/main/java/eu/univento/cloud/client/CloudMessenger.java
@@ -0,0 +1,22 @@
+package eu.univento.cloud.client;
+
+import eu.univento.core.antihack.Hack;
+import eu.univento.core.api.player.CustomPlayer;
+
+public class CloudMessenger {
+
+ public static void sendModModeMessage(ModModePrefix prefix, String message) {
+ //TODO: add stuff + server
+ }
+
+ public static void sendHackMessage(Hack hack, CustomPlayer player) {
+ //add function
+ }
+
+ public enum ModModePrefix {
+ HACK,
+ CMD,
+ AD,
+ ERROR;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/Core.java b/src/main/java/eu/univento/core/Core.java
index 0dd6b4b..2f53d90 100644
--- a/src/main/java/eu/univento/core/Core.java
+++ b/src/main/java/eu/univento/core/Core.java
@@ -1,5 +1,6 @@
package eu.univento.core;
+import eu.univento.core.antihack.AntiHack;
import eu.univento.core.api.Blackscreen;
import eu.univento.core.api.Config;
import eu.univento.core.api.database.MongoDB;
@@ -32,7 +33,7 @@ public class Core extends JavaPlugin{
/**
* plugin instance
*/
- public static Core instance;
+ private static Core instance;
/**
* @return plugin instance
*/
@@ -106,6 +107,7 @@ public class Core extends JavaPlugin{
new Build(this, "build", "build", "b");
pm.registerEvents(new Blocks(), this);
}
+ AntiHack.registerListeners();
new RunAs(this, "RunAs", "runas");
new SystemInfo(this, "SystemInfo", "systeminfo");
diff --git a/src/main/java/eu/univento/core/antihack/AntiHack.java b/src/main/java/eu/univento/core/antihack/AntiHack.java
new file mode 100644
index 0000000..71b0fd8
--- /dev/null
+++ b/src/main/java/eu/univento/core/antihack/AntiHack.java
@@ -0,0 +1,47 @@
+package eu.univento.core.antihack;
+
+import eu.univento.cloud.client.CloudMessenger;
+import eu.univento.core.Core;
+import eu.univento.core.antihack.modules.*;
+import eu.univento.core.antihack.utils.PacketInjector;
+import eu.univento.core.api.player.CustomPlayer;
+import org.bukkit.Bukkit;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.plugin.PluginManager;
+
+import java.util.Map;
+
+public class AntiHack implements Listener{
+
+ public static PacketInjector packetInjector = new PacketInjector();
+
+ public static void registerListeners() {
+ PluginManager pm = Bukkit.getPluginManager();
+ pm.registerEvents(new AntiHack(), Core.getInstance());
+ pm.registerEvents(new Glide(), Core.getInstance());
+ pm.registerEvents(new Fly(), Core.getInstance());
+ pm.registerEvents(new AutoClicker(), Core.getInstance());
+ pm.registerEvents(new Criticals(), Core.getInstance());
+ pm.registerEvents(new Reach(), Core.getInstance());
+ pm.registerEvents(new NoSlowDown(), Core.getInstance());
+ pm.registerEvents(new Regen(), Core.getInstance());
+ pm.registerEvents(new AutoRespawn(), Core.getInstance());
+ pm.registerEvents(new FastPlace(), Core.getInstance());
+ pm.registerEvents(new KillAura(), Core.getInstance());
+
+ for(Map.Entry entry : AutoClicker.clicks.entrySet()) {
+ if(entry.getValue() > 16) {
+ CloudMessenger.sendHackMessage(Hack.AUTOCLICKER, entry.getKey());
+ entry.getKey().warn(Hack.AUTOCLICKER);
+ }
+ AutoClicker.clicks.remove(entry.getKey());
+ }
+ }
+
+ @EventHandler
+ public void onJoin(PlayerJoinEvent e) {
+ packetInjector.addPlayer(e.getPlayer());
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/antihack/Hack.java b/src/main/java/eu/univento/core/antihack/Hack.java
new file mode 100644
index 0000000..6ba5a08
--- /dev/null
+++ b/src/main/java/eu/univento/core/antihack/Hack.java
@@ -0,0 +1,26 @@
+package eu.univento.core.antihack;
+
+public enum Hack {
+ //int represents warn points
+ CRITICALS(10),
+ AUTOCLICKER(10),
+ GLIDE(10),
+ REACH(10),
+ NOSLOWDOWN(10),
+ REGEN(10),
+ AUTORESPAWN(10),
+ FASTPLACE(10),
+ KILLAURA(10),
+ FLY(10);
+
+ private int id;
+ private Hack(int id) {
+ this.setId(id);
+ }
+ public int getId() {
+ return id;
+ }
+ public void setId(int id) {
+ this.id = id;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/antihack/modules/AutoClicker.java b/src/main/java/eu/univento/core/antihack/modules/AutoClicker.java
new file mode 100644
index 0000000..ef2b1cc
--- /dev/null
+++ b/src/main/java/eu/univento/core/antihack/modules/AutoClicker.java
@@ -0,0 +1,26 @@
+package eu.univento.core.antihack.modules;
+
+import eu.univento.core.api.player.CustomPlayer;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.Action;
+import org.bukkit.event.player.PlayerInteractEvent;
+
+import java.util.HashMap;
+
+public class AutoClicker implements Listener {
+
+ public static HashMap clicks = new HashMap<>();
+
+ @EventHandler
+ public void onClick(PlayerInteractEvent e) {
+ CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
+ if(e.getAction() == Action.LEFT_CLICK_AIR ||e.getAction() == Action.LEFT_CLICK_BLOCK) {
+ if(clicks.containsKey(p)) {
+ clicks.put(p, clicks.get(p) + 1);
+ }else{
+ clicks.put(p, 1);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/antihack/modules/AutoRespawn.java b/src/main/java/eu/univento/core/antihack/modules/AutoRespawn.java
new file mode 100644
index 0000000..7ab947d
--- /dev/null
+++ b/src/main/java/eu/univento/core/antihack/modules/AutoRespawn.java
@@ -0,0 +1,33 @@
+package eu.univento.core.antihack.modules;
+
+import eu.univento.cloud.client.CloudMessenger;
+import eu.univento.core.antihack.Hack;
+import eu.univento.core.api.player.CustomPlayer;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.PlayerDeathEvent;
+import org.bukkit.event.player.PlayerRespawnEvent;
+
+import java.util.HashMap;
+
+public class AutoRespawn implements Listener {
+
+ private HashMap time = new HashMap<>();
+
+ @EventHandler
+ public void onDeath(PlayerDeathEvent e) {
+ time.put(CustomPlayer.getPlayer(e.getEntity()), System.currentTimeMillis());
+ }
+
+ @EventHandler
+ public void onRespawn(PlayerRespawnEvent e) {
+ CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
+ if(time.containsKey(p)) {
+ if(System.currentTimeMillis() - time.get(p) <= 200L) {
+ CloudMessenger.sendHackMessage(Hack.AUTORESPAWN, p);
+ p.warn(Hack.AUTORESPAWN);
+ }
+ time.remove(p);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/antihack/modules/Criticals.java b/src/main/java/eu/univento/core/antihack/modules/Criticals.java
new file mode 100644
index 0000000..9c9ad1e
--- /dev/null
+++ b/src/main/java/eu/univento/core/antihack/modules/Criticals.java
@@ -0,0 +1,55 @@
+package eu.univento.core.antihack.modules;
+
+import eu.univento.cloud.client.CloudMessenger;
+import eu.univento.core.Core;
+import eu.univento.core.antihack.Hack;
+import eu.univento.core.api.player.CustomPlayer;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.EntityDamageByEntityEvent;
+import org.bukkit.event.player.PlayerMoveEvent;
+
+import java.util.ArrayList;
+
+public class Criticals implements Listener {
+
+ private ArrayList players = new ArrayList<>();
+
+ @EventHandler
+ public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
+ if(e.getDamager() instanceof Player && e.getEntity() instanceof Player) {
+ CustomPlayer damager = CustomPlayer.getPlayer((Player) e.getDamager());
+ CustomPlayer p = CustomPlayer.getPlayer((Player) e.getEntity());
+ if(!players.contains(p)) {
+ players.add(p);
+ Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> players.remove(p), 5L);
+ }
+ }
+ }
+
+ @EventHandler
+ public void onMove(PlayerMoveEvent e) {
+ CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
+ Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
+ final double x1 = e.getFrom().getY();
+ final double x2 = p.getLocation().getY();
+ double fark = 0.0;
+ if (x1 > x2) {
+ fark = x1 - x2;
+ } else if (x2 > x1) {
+ fark = x2 - x1;
+ } else {
+ fark = 200.0;
+ }
+ if (!players.contains(p)) {
+ return;
+ }
+ if (fark == 0.125 || fark == 1.0 || fark == 1.3 || fark == 0.6190840103302007 || fark == 0.4414162352399398 || fark == 200.0) {
+ CloudMessenger.sendHackMessage(Hack.CRITICALS, p);
+ p.warn(Hack.CRITICALS);
+ }
+ }, 6L);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/antihack/modules/FastPlace.java b/src/main/java/eu/univento/core/antihack/modules/FastPlace.java
new file mode 100644
index 0000000..87eca15
--- /dev/null
+++ b/src/main/java/eu/univento/core/antihack/modules/FastPlace.java
@@ -0,0 +1,27 @@
+package eu.univento.core.antihack.modules;
+
+import eu.univento.cloud.client.CloudMessenger;
+import eu.univento.core.antihack.Hack;
+import eu.univento.core.api.player.CustomPlayer;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.BlockPlaceEvent;
+
+import java.util.HashMap;
+
+public class FastPlace implements Listener{
+
+ private HashMap time = new HashMap<>();
+
+ @EventHandler
+ public void onPlace(BlockPlaceEvent e) {
+ CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
+ if(time.containsKey(p)) {
+ if(System.currentTimeMillis() - time.get(p) <= 110L) {
+ CloudMessenger.sendHackMessage(Hack.FASTPLACE, p);
+ p.warn(Hack.FASTPLACE);
+ }
+ }
+ time.put(p, System.currentTimeMillis());
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/antihack/modules/Fly.java b/src/main/java/eu/univento/core/antihack/modules/Fly.java
new file mode 100644
index 0000000..6430946
--- /dev/null
+++ b/src/main/java/eu/univento/core/antihack/modules/Fly.java
@@ -0,0 +1,21 @@
+package eu.univento.core.antihack.modules;
+
+import eu.univento.cloud.client.CloudMessenger;
+import eu.univento.core.antihack.Hack;
+import eu.univento.core.api.player.CustomPlayer;
+import org.bukkit.GameMode;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerMoveEvent;
+
+public class Fly implements Listener{
+
+ @EventHandler
+ public void onFly(PlayerMoveEvent e) {
+ CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
+ if(p.getGameMode() != GameMode.CREATIVE && e.getTo().getY() > e.getFrom().getY() + 1.5) {
+ CloudMessenger.sendHackMessage(Hack.FLY, p);
+ p.warn(Hack.FLY);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/antihack/modules/Glide.java b/src/main/java/eu/univento/core/antihack/modules/Glide.java
new file mode 100644
index 0000000..ebdf334
--- /dev/null
+++ b/src/main/java/eu/univento/core/antihack/modules/Glide.java
@@ -0,0 +1,21 @@
+package eu.univento.core.antihack.modules;
+
+import eu.univento.cloud.client.CloudMessenger;
+import eu.univento.core.antihack.Hack;
+import eu.univento.core.api.player.CustomPlayer;
+import org.bukkit.Material;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerMoveEvent;
+
+public class Glide implements Listener{
+
+ @EventHandler
+ public void onGlide(PlayerMoveEvent e) {
+ CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
+ if(e.getTo().getY() - e.getFrom().getY() == -0.125 && e.getTo().clone().subtract(0.0, 1.0, 0.0).getBlock().getType().equals(Material.AIR)) {
+ CloudMessenger.sendHackMessage(Hack.GLIDE, p);
+ p.warn(Hack.GLIDE);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/antihack/modules/KillAura.java b/src/main/java/eu/univento/core/antihack/modules/KillAura.java
new file mode 100644
index 0000000..bc3fb0c
--- /dev/null
+++ b/src/main/java/eu/univento/core/antihack/modules/KillAura.java
@@ -0,0 +1,36 @@
+package eu.univento.core.antihack.modules;
+
+import com.mojang.authlib.GameProfile;
+import eu.univento.core.Core;
+import eu.univento.core.api.fakeplayer.FakePlayer;
+import eu.univento.core.api.player.CustomPlayer;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.EntityDamageByEntityEvent;
+
+import java.util.HashMap;
+import java.util.Random;
+import java.util.UUID;
+
+public class KillAura implements Listener{
+
+ public static HashMap players = new HashMap<>();
+
+ @EventHandler
+ public void onEntityDamage(EntityDamageByEntityEvent e) {
+ if (e.getDamager() instanceof Player && e.getEntity() instanceof Player) {
+ CustomPlayer damager = CustomPlayer.getPlayer((Player) e.getDamager());
+ CustomPlayer p = CustomPlayer.getPlayer((Player) e.getEntity());
+ FakePlayer fp = new FakePlayer(new GameProfile(UUID.randomUUID(), ""), false, p);
+ players.put(p, fp);
+ fp.spawn(p.getLocation().add((double) new Random().nextInt(2), 0.01, (double) new Random().nextInt(2)));
+ Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
+ fp.removeTablist();
+ fp.despawn();
+ if(players.containsKey(p)) players.remove(p);
+ }, 5L);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/antihack/modules/NoSlowDown.java b/src/main/java/eu/univento/core/antihack/modules/NoSlowDown.java
new file mode 100644
index 0000000..8482b61
--- /dev/null
+++ b/src/main/java/eu/univento/core/antihack/modules/NoSlowDown.java
@@ -0,0 +1,35 @@
+package eu.univento.core.antihack.modules;
+
+import eu.univento.cloud.client.CloudMessenger;
+import eu.univento.core.antihack.Hack;
+import eu.univento.core.api.player.CustomPlayer;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.EntityShootBowEvent;
+import org.bukkit.event.entity.FoodLevelChangeEvent;
+
+public class NoSlowDown implements Listener{
+
+ @EventHandler
+ public void onShootBow(EntityShootBowEvent e) {
+ if(e.getEntity() instanceof Player) {
+ CustomPlayer p = CustomPlayer.getPlayer((Player) e.getEntity());
+ if(p.isSprinting()) {
+ CloudMessenger.sendHackMessage(Hack.NOSLOWDOWN, p);
+ p.warn(Hack.NOSLOWDOWN);
+ }
+ }
+ }
+
+ @EventHandler
+ public void onFoodChange(FoodLevelChangeEvent e) {
+ if(e.getEntity() instanceof Player) {
+ CustomPlayer p = CustomPlayer.getPlayer((Player) e.getEntity());
+ if(e.getFoodLevel() > p.getFoodLevel() && p.isSprinting()) {
+ CloudMessenger.sendHackMessage(Hack.NOSLOWDOWN, p);
+ p.warn(Hack.NOSLOWDOWN);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/antihack/modules/Reach.java b/src/main/java/eu/univento/core/antihack/modules/Reach.java
new file mode 100644
index 0000000..83b748a
--- /dev/null
+++ b/src/main/java/eu/univento/core/antihack/modules/Reach.java
@@ -0,0 +1,39 @@
+package eu.univento.core.antihack.modules;
+
+import eu.univento.cloud.client.CloudMessenger;
+import eu.univento.core.antihack.Hack;
+import eu.univento.core.api.player.CustomPlayer;
+import org.bukkit.block.Block;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.BlockBreakEvent;
+import org.bukkit.event.entity.EntityDamageByEntityEvent;
+
+public class Reach implements Listener{
+
+ @EventHandler
+ public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
+ if(e.getDamager() instanceof Player && e.getEntity() instanceof Player) {
+ CustomPlayer damager = CustomPlayer.getPlayer((Player) e.getDamager());
+ CustomPlayer p = CustomPlayer.getPlayer((Player) e.getEntity());
+ if(damager.getLocation().distance(p.getLocation()) > 4.0) {
+ e.setCancelled(true);
+ CloudMessenger.sendHackMessage(Hack.REACH, damager);
+ p.warn(Hack.REACH);
+ }
+ }
+ }
+
+ @EventHandler
+ public void onBlockBreak(BlockBreakEvent e ) {
+ CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
+ Block b = e.getBlock();
+ if(p.getLocation().distance(b.getLocation()) > 6.1) {
+ e.setCancelled(true);
+ CloudMessenger.sendHackMessage(Hack.REACH, p);
+ p.warn(Hack.REACH);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/antihack/modules/Regen.java b/src/main/java/eu/univento/core/antihack/modules/Regen.java
new file mode 100644
index 0000000..f637b0f
--- /dev/null
+++ b/src/main/java/eu/univento/core/antihack/modules/Regen.java
@@ -0,0 +1,53 @@
+package eu.univento.core.antihack.modules;
+
+import eu.univento.cloud.client.CloudMessenger;
+import eu.univento.core.Core;
+import eu.univento.core.antihack.Hack;
+import eu.univento.core.api.player.CustomPlayer;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.EntityRegainHealthEvent;
+
+import java.util.ArrayList;
+
+public class Regen implements Listener {
+
+ private ArrayList a = new ArrayList<>();
+ private ArrayList b = new ArrayList<>();
+
+ @EventHandler
+ public void onRegainHealth(EntityRegainHealthEvent e) {
+ if (e.getEntity() instanceof Player) {
+ CustomPlayer p = CustomPlayer.getPlayer((Player) e.getEntity());
+
+ if (p.getFoodLevel() > 16 && e.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED) {
+ if (a.contains(p) && b.contains(p)) {
+ a.remove(p);
+ }
+ if (e.getAmount() > 1.0) {
+ p.setFoodLevel(0);
+ CloudMessenger.sendHackMessage(Hack.REGEN, p);
+ p.warn(Hack.REGEN);
+ return;
+ }
+ if (!b.contains(p) && !a.contains(p)) {
+ a.add(p);
+ b.add(p);
+ Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
+ if (!a.contains(p)) {
+ p.setFoodLevel(0);
+ b.remove(p);
+ CloudMessenger.sendHackMessage(Hack.REGEN, p);
+ p.warn(Hack.REGEN);
+ } else if (a.contains(p)) {
+ a.remove(p);
+ b.remove(p);
+ }
+ }, 10L);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/antihack/utils/PacketHandler.java b/src/main/java/eu/univento/core/antihack/utils/PacketHandler.java
new file mode 100644
index 0000000..f93b5a4
--- /dev/null
+++ b/src/main/java/eu/univento/core/antihack/utils/PacketHandler.java
@@ -0,0 +1,88 @@
+package eu.univento.core.antihack.utils;
+
+import com.mojang.authlib.GameProfile;
+import eu.univento.cloud.client.CloudMessenger;
+import eu.univento.core.Core;
+import eu.univento.core.antihack.Hack;
+import eu.univento.core.antihack.modules.KillAura;
+import eu.univento.core.api.fakeplayer.FakePlayer;
+import eu.univento.core.api.player.CustomPlayer;
+import io.netty.channel.ChannelDuplexHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelPromise;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Random;
+import java.util.UUID;
+
+public class PacketHandler extends ChannelDuplexHandler {
+ private Player player;
+ private HashMap killAura = new HashMap<>();
+ private HashMap count = new HashMap<>();
+ private HashMap inventory = new HashMap<>();
+ private ArrayList swing = new ArrayList<>();
+
+ public PacketHandler(final Player player) {
+ this.player = player;
+ }
+
+ public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) throws Exception {
+ super.write(ctx, msg, promise);
+ }
+
+ public void destroy(final FakePlayer fp, Player p) {
+ Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
+ fp.removeTablist();
+ fp.despawn();
+ if (KillAura.players.containsKey(p)) {
+ KillAura.players.remove(p);
+ }
+ }, 5L);
+ }
+
+ public void channelRead(final ChannelHandlerContext c, final Object m) throws Exception {
+ if (m.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInArmAnimation")) {
+ swing.add(player);
+ }
+ if (m.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInUseEntity")) {
+ final int id = (int) Reflection.getFieldValue(m, "a");
+ if (Reflection.getFieldValue(m, "action").toString().equals("ATTACK") && KillAura.players.containsKey(player) && id == KillAura.players.get(player).getEntityID()) {
+ if (!killAura.containsKey(player)) {
+ final FakePlayer fp = new FakePlayer(new GameProfile(UUID.randomUUID(), ""), false, player);
+ KillAura.players.put(player, fp);
+ fp.spawn(player.getLocation().subtract((double) new Random().nextInt(2), 0.01, (double) new Random().nextInt(2)));
+ destroy(fp, player);
+ killAura.put(player, 1);
+ return;
+ }
+ if (killAura.containsKey(player) && killAura.get(player) == 1) {
+ final FakePlayer fp = new FakePlayer(new GameProfile(UUID.randomUUID(), ""), false, player);
+ KillAura.players.put(player, fp);
+ fp.spawn(player.getLocation().subtract((double) new Random().nextInt(2), 0.01, (double) new Random().nextInt(2)));
+ destroy(fp, player);
+ killAura.put(player, 2);
+ return;
+ }
+ if (count.get(player) < 4) {
+ count.put(player, count.get(player) + 1);
+ } else {
+ count.remove(player);
+ CustomPlayer p = CustomPlayer.getPlayer(player);
+ CloudMessenger.sendHackMessage(Hack.KILLAURA, p);
+ p.warn(Hack.KILLAURA);
+ }
+ killAura.remove(player);
+ }
+ }
+ if (m.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInClientCommand")) {
+ final String s = Reflection.getFieldValue(m, "a").toString();
+ if (s.equals("OPEN_INVENTORY_ACHIEVEMENT")) {
+ inventory.put(player, System.currentTimeMillis());
+ }
+ }
+ super.channelRead(c, m);
+ }
+}
diff --git a/src/main/java/eu/univento/core/antihack/utils/PacketInjector.java b/src/main/java/eu/univento/core/antihack/utils/PacketInjector.java
new file mode 100644
index 0000000..2f5c1de
--- /dev/null
+++ b/src/main/java/eu/univento/core/antihack/utils/PacketInjector.java
@@ -0,0 +1,75 @@
+package eu.univento.core.antihack.utils;
+
+import io.netty.channel.Channel;
+import org.bukkit.entity.Player;
+
+import java.lang.reflect.Field;
+
+public class PacketInjector {
+
+ private Field EntityPlayer_playerConnection;
+ private Class> PlayerConnection;
+ private Field PlayerConnection_networkManager;
+ private Class> NetworkManager;
+ private Field k;
+ private Field m;
+
+ public PacketInjector() {
+ try {
+ this.EntityPlayer_playerConnection = Reflection.getField(Reflection.getClass("{nms}.EntityPlayer"), "playerConnection");
+ this.PlayerConnection = Reflection.getClass("{nms}.PlayerConnection");
+ this.PlayerConnection_networkManager = Reflection.getField(this.PlayerConnection, "networkManager");
+ this.NetworkManager = Reflection.getClass("{nms}.NetworkManager");
+ Field[] fields2;
+ for (int length = (fields2 = this.NetworkManager.getFields()).length, i = 0; i < length; ++i) {
+ final Field fields = fields2[i];
+ if (fields.getType().equals(Channel.class)) {
+ this.k = fields;
+ }
+ }
+ if (this.k == null) {
+ this.k = Reflection.getField(this.NetworkManager, "i");
+ }
+ this.m = Reflection.getField(this.NetworkManager, "m");
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+ public void addPlayer(final Player p) {
+ try {
+ final Channel ch = this.getChannel(this.getNetworkManager(Reflection.getNmsPlayer(p)));
+ if (ch.pipeline().get("PacketInjector") == null) {
+ final PacketHandler h = new PacketHandler(p);
+ ch.pipeline().addBefore("packet_handler", "PacketInjector", h);
+ }
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+ public void removePlayer(final Player p) {
+ try {
+ final Channel ch = this.getChannel(this.getNetworkManager(Reflection.getNmsPlayer(p)));
+ if (ch.pipeline().get("PacketInjector") != null) {
+ ch.pipeline().remove("PacketInjector");
+ }
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+ private Object getNetworkManager(final Object ep) {
+ return Reflection.getFieldValue(this.PlayerConnection_networkManager, (Object) Reflection.getFieldValue(this.EntityPlayer_playerConnection, ep));
+ }
+
+ private Channel getChannel(final Object networkManager) {
+ Channel ch = null;
+ try {
+ ch = Reflection.getFieldValue(this.k, networkManager);
+ } catch (Exception e) {
+ ch = Reflection.getFieldValue(this.m, networkManager);
+ }
+ return ch;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/eu/univento/core/antihack/utils/PacketReader.java b/src/main/java/eu/univento/core/antihack/utils/PacketReader.java
new file mode 100644
index 0000000..aab388f
--- /dev/null
+++ b/src/main/java/eu/univento/core/antihack/utils/PacketReader.java
@@ -0,0 +1,41 @@
+package eu.univento.core.antihack.utils;
+
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.MessageToMessageDecoder;
+import net.minecraft.server.v1_9_R1.Packet;
+import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
+import org.bukkit.entity.Player;
+
+import java.util.List;
+
+public class PacketReader {
+
+ Player player;
+ Channel channel;
+
+ public PacketReader(final Player player) {
+ this.player = player;
+ }
+
+ public void inject() {
+ final CraftPlayer player = (CraftPlayer) this.player;
+ this.channel = player.getHandle().playerConnection.networkManager.channel;
+ this.channel.pipeline().addAfter("decoder", "PacketInjector", (ChannelHandler) new MessageToMessageDecoder>() {
+ protected void decode(final ChannelHandlerContext arg0, final Packet> packet, final List