Added anti-hack
This commit is contained in:
parent
40e49dd3d4
commit
2a836f3464
@ -9,6 +9,7 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class UtilBlock
|
public class UtilBlock
|
||||||
|
@ -15,6 +15,7 @@ import net.minecraft.server.v1_6_R3.PathfinderGoalSelector;
|
|||||||
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity;
|
||||||
@ -373,4 +374,38 @@ public class UtilEnt
|
|||||||
|
|
||||||
damagee.getWorld().playSound(damagee.getLocation(), sound, 1.5f + (float)(0.5f * Math.random()), 0.8f + (float)(0.4f * Math.random()));
|
damagee.getWorld().playSound(damagee.getLocation(), sound, 1.5f + (float)(0.5f * Math.random()), 0.8f + (float)(0.4f * Math.random()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean onBlock(Player player)
|
||||||
|
{
|
||||||
|
//Side Standing
|
||||||
|
double xMod = player.getLocation().getX() % 1;
|
||||||
|
if (player.getLocation().getX() < 0)
|
||||||
|
xMod += 1;
|
||||||
|
|
||||||
|
double zMod = player.getLocation().getZ() % 1;
|
||||||
|
if (player.getLocation().getZ() < 0)
|
||||||
|
zMod += 1;
|
||||||
|
|
||||||
|
int xMin = 0;
|
||||||
|
int xMax = 0;
|
||||||
|
int zMin = 0;
|
||||||
|
int zMax = 0;
|
||||||
|
|
||||||
|
if (xMod < 0.3) xMin = -1;
|
||||||
|
if (xMod > 0.7) xMax = 1;
|
||||||
|
|
||||||
|
if (zMod < 0.3) zMin = -1;
|
||||||
|
if (zMod > 0.7) zMax = 1;
|
||||||
|
|
||||||
|
for (int x=xMin ; x<=xMax ; x++)
|
||||||
|
{
|
||||||
|
for (int z=zMin ; z<=zMax ; z++)
|
||||||
|
{
|
||||||
|
if (player.getLocation().add(x, -0.5, z).getBlock().getType() != Material.AIR)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,15 @@
|
|||||||
</buildCommand>
|
</buildCommand>
|
||||||
<buildCommand>
|
<buildCommand>
|
||||||
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
|
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
|
||||||
<triggers>auto,full,incremental,</triggers>
|
<triggers>full,incremental,</triggers>
|
||||||
<arguments>
|
<arguments>
|
||||||
<dictionary>
|
<dictionary>
|
||||||
<key>LaunchConfigHandle</key>
|
<key>LaunchConfigHandle</key>
|
||||||
<value><project>/.externalToolBuilders/Core.launch</value>
|
<value><project>/.externalToolBuilders/Core Builder.launch</value>
|
||||||
|
</dictionary>
|
||||||
|
<dictionary>
|
||||||
|
<key>incclean</key>
|
||||||
|
<value>true</value>
|
||||||
</dictionary>
|
</dictionary>
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
|
@ -2,15 +2,18 @@ package mineplex.core.antihack;
|
|||||||
|
|
||||||
import java.util.AbstractMap;
|
import java.util.AbstractMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import mineplex.core.MiniPlugin;
|
import mineplex.core.MiniPlugin;
|
||||||
import mineplex.core.common.util.F;
|
import mineplex.core.common.util.C;
|
||||||
|
import mineplex.core.common.util.UtilAlg;
|
||||||
import mineplex.core.common.util.UtilEnt;
|
import mineplex.core.common.util.UtilEnt;
|
||||||
import mineplex.core.common.util.UtilGear;
|
|
||||||
import mineplex.core.common.util.UtilMath;
|
import mineplex.core.common.util.UtilMath;
|
||||||
import mineplex.core.common.util.UtilPlayer;
|
|
||||||
import mineplex.core.common.util.UtilServer;
|
import mineplex.core.common.util.UtilServer;
|
||||||
|
import mineplex.core.common.util.UtilTime;
|
||||||
|
import mineplex.core.updater.UpdateType;
|
||||||
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -20,6 +23,9 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
|||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.player.PlayerVelocityEvent;
|
import org.bukkit.event.player.PlayerVelocityEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class AntiHack extends MiniPlugin
|
public class AntiHack extends MiniPlugin
|
||||||
{
|
{
|
||||||
@ -29,22 +35,29 @@ public class AntiHack extends MiniPlugin
|
|||||||
private HashMap<Player, HashMap<String, Integer>> _offenses = new HashMap<Player, HashMap<String, Integer>>();
|
private HashMap<Player, HashMap<String, Integer>> _offenses = new HashMap<Player, HashMap<String, Integer>>();
|
||||||
|
|
||||||
//Ignore Player
|
//Ignore Player
|
||||||
|
private HashSet<Player> _ignoreStart = new HashSet<Player>();
|
||||||
private HashMap<Player, Long> _ignore = new HashMap<Player, Long>();
|
private HashMap<Player, Long> _ignore = new HashMap<Player, Long>();
|
||||||
|
|
||||||
//Hack Data
|
//Hack Data
|
||||||
private HashMap<Player, Entry<Integer, Double>> _floatTicks = new HashMap<Player, Entry<Integer, Double>>(); //Ticks, PrevY
|
private HashMap<Player, Entry<Integer, Double>> _floatTicks = new HashMap<Player, Entry<Integer, Double>>(); //Ticks, PrevY
|
||||||
private HashMap<Player, Entry<Integer, Double>> _hoverTicks = new HashMap<Player, Entry<Integer, Double>>(); //Ticks, PrevY
|
private HashMap<Player, Entry<Integer, Double>> _hoverTicks = new HashMap<Player, Entry<Integer, Double>>(); //Ticks, PrevY
|
||||||
private HashMap<Player, Entry<Integer, Double>> _riseTicks = new HashMap<Player, Entry<Integer, Double>>(); //Ticks, PrevY
|
private HashMap<Player, Entry<Integer, Double>> _riseTicks = new HashMap<Player, Entry<Integer, Double>>(); //Ticks, PrevY
|
||||||
private HashMap<Player, Entry<Double, Double>> _momentum = new HashMap<Player, Entry<Double, Double>>(); //Momentum, PrevY
|
private HashMap<Player, Vector> _momentum = new HashMap<Player, Vector>();
|
||||||
|
|
||||||
|
private HashMap<Player, Long> _lastMove = new HashMap<Player, Long>(); //Ticks, PrevY
|
||||||
|
|
||||||
|
private HashMap<Player, Entry<Integer, Long>> _speedTicks = new HashMap<Player, Entry<Integer, Long>>(); //Ticks, PrevY
|
||||||
|
|
||||||
//Hack Requirements
|
//Hack Requirements
|
||||||
private int _floatHackTicks = 20;
|
private int _floatHackTicks = 4;
|
||||||
private int _hoverHackTicks = 20;
|
private int _hoverHackTicks = 4;
|
||||||
private int _riseHackTicks = 20;
|
private int _riseHackTicks = 8;
|
||||||
|
private int _speedHackTicks = 4;
|
||||||
|
private int _freecamTime = 8000;
|
||||||
|
|
||||||
protected AntiHack(JavaPlugin plugin)
|
protected AntiHack(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super("Recharge", plugin);
|
super("AntiHack", plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Initialize(JavaPlugin plugin)
|
public static void Initialize(JavaPlugin plugin)
|
||||||
@ -55,26 +68,35 @@ public class AntiHack extends MiniPlugin
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void PlayerVelocity(PlayerVelocityEvent event)
|
public void PlayerVelocity(PlayerVelocityEvent event)
|
||||||
{
|
{
|
||||||
_ignore.put(event.getPlayer(), System.currentTimeMillis() + 2000);
|
_ignoreStart.add(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void PlayerQuit(PlayerQuitEvent event)
|
public void PlayerQuit(PlayerQuitEvent event)
|
||||||
{
|
{
|
||||||
Reset(event.getPlayer());
|
ResetAll(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void Update(PlayerMoveEvent event)
|
public void UpdateFlyhack(PlayerMoveEvent event)
|
||||||
{
|
{
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
_lastMove.put(player, System.currentTimeMillis());
|
||||||
|
|
||||||
|
//Start Ignore
|
||||||
|
if (_ignoreStart.contains(player) && event.getTo().getY() > event.getFrom().getY())
|
||||||
|
{
|
||||||
|
_ignore.put(player, System.currentTimeMillis() + 2000);
|
||||||
|
_ignoreStart.remove(player);
|
||||||
|
}
|
||||||
|
|
||||||
//Allowed 'cheaty' movement
|
//Allowed 'cheaty' movement
|
||||||
if (UtilEnt.isGrounded(player) || player.getLocation().getBlock().getType() != Material.AIR || //Grounded + Swimming/Ladder/etc
|
if (UtilEnt.onBlock(player) || player.getLocation().getBlock().getType() != Material.AIR || //Grounded + Swimming/Ladder/etc
|
||||||
player.isFlying() || player.isInsideVehicle() || player.getGameMode() != GameMode.SURVIVAL || //Flying + Vehicle + Gamemode
|
player.isFlying() || player.isInsideVehicle() || player.getGameMode() != GameMode.SURVIVAL || //Flying + Vehicle + Gamemode
|
||||||
(_ignore.containsKey(player) && System.currentTimeMillis() < _ignore.get(player))) //Ignore
|
(_ignore.containsKey(player) && System.currentTimeMillis() < _ignore.get(player))) //Ignore
|
||||||
{
|
{
|
||||||
Reset(player);
|
ResetFly(player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +109,56 @@ public class AntiHack extends MiniPlugin
|
|||||||
|
|
||||||
UpdateHover(player);
|
UpdateHover(player);
|
||||||
UpdateRise(player);
|
UpdateRise(player);
|
||||||
UpdateMomentum(player);
|
UpdateMomentum(player, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void UpdateFreeCam(UpdateEvent event)
|
||||||
|
{
|
||||||
|
if (event.getType() != UpdateType.FAST)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (Player player : UtilServer.getPlayers())
|
||||||
|
{
|
||||||
|
//Allowed 'cheaty' movement
|
||||||
|
if (UtilEnt.onBlock(player) || player.getLocation().getBlock().getType() != Material.AIR || //Grounded + Swimming/Ladder/etc
|
||||||
|
player.isFlying() || player.isInsideVehicle() || player.getGameMode() != GameMode.SURVIVAL || //Flying + Vehicle + Gamemode
|
||||||
|
(_ignore.containsKey(player) && System.currentTimeMillis() < _ignore.get(player))) //Ignore
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_lastMove.containsKey(player))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!UtilTime.elapsed(_lastMove.get(player), _freecamTime))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
player.kickPlayer(C.cGold + "Mineplex " + C.cRed + "Anti-Hack " + C.cWhite + "Kicked for Lagging / Free Cam.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void UpdateSpeedhack(PlayerMoveEvent event)
|
||||||
|
{
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
//Start Ignore
|
||||||
|
if (_ignoreStart.contains(player) && event.getTo().getY() > event.getFrom().getY())
|
||||||
|
{
|
||||||
|
_ignore.put(player, System.currentTimeMillis() + 2000);
|
||||||
|
_ignoreStart.remove(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Allowed 'cheaty' movement
|
||||||
|
if (player.isFlying() || player.isInsideVehicle() || player.getGameMode() != GameMode.SURVIVAL || //Flying + Vehicle + Gamemode
|
||||||
|
(_ignore.containsKey(player) && System.currentTimeMillis() < _ignore.get(player))) //Ignore
|
||||||
|
{
|
||||||
|
_speedTicks.remove(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateSpeed(player, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateFloat(Player player)
|
private void UpdateFloat(Player player)
|
||||||
@ -108,7 +179,7 @@ public class AntiHack extends MiniPlugin
|
|||||||
|
|
||||||
if (count > _floatHackTicks)
|
if (count > _floatHackTicks)
|
||||||
{
|
{
|
||||||
AddOffense(player, "Float");
|
AddOffense(player, "Fly (Float)");
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +204,7 @@ public class AntiHack extends MiniPlugin
|
|||||||
|
|
||||||
if (count > _hoverHackTicks)
|
if (count > _hoverHackTicks)
|
||||||
{
|
{
|
||||||
AddOffense(player, "Hover");
|
AddOffense(player, "Fly (Hover)");
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,30 +229,78 @@ public class AntiHack extends MiniPlugin
|
|||||||
|
|
||||||
if (count > _riseHackTicks)
|
if (count > _riseHackTicks)
|
||||||
{
|
{
|
||||||
AddOffense(player, "Rise");
|
AddOffense(player, "Fly (Rise)");
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_riseTicks.put(player, new AbstractMap.SimpleEntry<Integer, Double>(count, player.getLocation().getY()));
|
_riseTicks.put(player, new AbstractMap.SimpleEntry<Integer, Double>(count, player.getLocation().getY()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateMomentum(Player player)
|
private void UpdateMomentum(Player player, PlayerMoveEvent event)
|
||||||
{
|
{
|
||||||
double newMomentum = 0;
|
if (!_momentum.containsKey(player))
|
||||||
|
_momentum.put(player, UtilAlg.getTrajectory2d(event.getFrom(), event.getTo()));
|
||||||
|
|
||||||
if (_momentum.containsKey(player))
|
Vector newVel = UtilAlg.getTrajectory2d(event.getFrom(), event.getTo());
|
||||||
{
|
Vector oldVel = _momentum.get(player);
|
||||||
newMomentum = player.getLocation().getY() - _riseTicks.get(player).getValue();
|
|
||||||
double oldMomentum = _riseTicks.get(player).getKey();
|
|
||||||
|
|
||||||
if (oldMomentum < 0 && newMomentum > 0)
|
//Not within 90 degrees of rotation in perfect circle
|
||||||
|
if (oldVel.subtract(newVel).length() > 1.42 && UtilMath.offset2d(event.getFrom(), event.getTo()) > 0.3) //Ignore low velocity switch
|
||||||
{
|
{
|
||||||
AddOffense(player, "Momentum");
|
AddOffense(player, "Fly (Momentum)");
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
_momentum.put(player, newVel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateSpeed(Player player, PlayerMoveEvent event)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
if (_speedTicks.containsKey(player))
|
||||||
|
{
|
||||||
|
double offset;
|
||||||
|
if (event.getFrom().getY() > event.getTo().getY())
|
||||||
|
{
|
||||||
|
offset = UtilMath.offset2d(event.getFrom(), event.getTo());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
offset = UtilMath.offset(event.getFrom(), event.getTo());
|
||||||
|
}
|
||||||
|
|
||||||
|
//Limit
|
||||||
|
double limit = 0.74;
|
||||||
|
if (UtilEnt.isGrounded(player))
|
||||||
|
limit = 0.32;
|
||||||
|
|
||||||
|
for (PotionEffect effect : player.getActivePotionEffects())
|
||||||
|
if (effect.getType().equals(PotionEffectType.SPEED))
|
||||||
|
{
|
||||||
|
if (UtilEnt.isGrounded(player))
|
||||||
|
limit += 0.08 * (effect.getAmplifier() + 1);
|
||||||
|
else
|
||||||
|
limit += 0.04 * (effect.getAmplifier() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check
|
||||||
|
if (offset > limit && !UtilTime.elapsed(_speedTicks.get(player).getValue(), 200))//Counters Lag
|
||||||
|
{
|
||||||
|
count = _speedTicks.get(player).getKey() + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
count = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_momentum.put(player, new AbstractMap.SimpleEntry<Double, Double>(newMomentum, player.getLocation().getY()));
|
if (count > _speedHackTicks)
|
||||||
|
{
|
||||||
|
AddOffense(player, "Speed");
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
_speedTicks.put(player, new AbstractMap.SimpleEntry<Integer, Long>(count, System.currentTimeMillis()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddOffense(Player player, String type)
|
private void AddOffense(Player player, String type)
|
||||||
@ -195,16 +314,28 @@ public class AntiHack extends MiniPlugin
|
|||||||
|
|
||||||
_offenses.get(player).put(type, previous + 1);
|
_offenses.get(player).put(type, previous + 1);
|
||||||
|
|
||||||
//Report (Debug)
|
//Print (Debug)
|
||||||
for (Player admin : UtilServer.getPlayers())
|
System.out.println("[Offense] " + player.getName() + " received offense for " + type + ".");
|
||||||
if (admin.isOp() && UtilGear.isMat(admin.getItemInHand(), Material.BOOK_AND_QUILL))
|
|
||||||
UtilPlayer.message(admin, F.main("Anti-Hack", F.elem(player.getName()) + " fired offense for " + F.elem(type) + "."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Reset(Player player)
|
private void ResetFly(Player player)
|
||||||
{
|
{
|
||||||
|
_floatTicks.remove(player);
|
||||||
_hoverTicks.remove(player);
|
_hoverTicks.remove(player);
|
||||||
_riseTicks.remove(player);
|
_riseTicks.remove(player);
|
||||||
_momentum.remove(player);
|
_momentum.remove(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ResetAll(Player player)
|
||||||
|
{
|
||||||
|
ResetFly(player);
|
||||||
|
|
||||||
|
_lastMove.remove(player);
|
||||||
|
|
||||||
|
_speedTicks.remove(player);
|
||||||
|
|
||||||
|
_ignore.remove(player);
|
||||||
|
_ignoreStart.remove(player);
|
||||||
|
_offenses.remove(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import java.io.InputStreamReader;
|
|||||||
|
|
||||||
import me.chiss.Core.Config.Config;
|
import me.chiss.Core.Config.Config;
|
||||||
import mineplex.core.account.CoreClientManager;
|
import mineplex.core.account.CoreClientManager;
|
||||||
|
import mineplex.core.antihack.AntiHack;
|
||||||
import mineplex.core.antistack.AntiStack;
|
import mineplex.core.antistack.AntiStack;
|
||||||
import mineplex.core.blockrestore.BlockRestore;
|
import mineplex.core.blockrestore.BlockRestore;
|
||||||
import mineplex.core.command.CommandCenter;
|
import mineplex.core.command.CommandCenter;
|
||||||
@ -99,6 +100,8 @@ public class Arcade extends JavaPlugin implements INautilusPlugin, IPlugin
|
|||||||
_clientManager = CoreClientManager.Initialize(this, GetWebServerAddress());
|
_clientManager = CoreClientManager.Initialize(this, GetWebServerAddress());
|
||||||
|
|
||||||
CommandCenter.Initialize(this, _clientManager);
|
CommandCenter.Initialize(this, _clientManager);
|
||||||
|
|
||||||
|
AntiHack.Initialize(this);
|
||||||
ItemStackFactory.Initialize(this, false);
|
ItemStackFactory.Initialize(this, false);
|
||||||
Recharge.Initialize(this);
|
Recharge.Initialize(this);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user