added AntiHack

added dragonrider coolness
This commit is contained in:
Chiss 2013-10-16 08:10:45 +11:00
parent 230ad4aa7b
commit ec80d8a568
4 changed files with 273 additions and 32 deletions

View File

@ -0,0 +1,210 @@
package mineplex.core.antihack;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map.Entry;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerVelocityEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class AntiHack extends MiniPlugin
{
public static AntiHack Instance;
//Record Offesnes
private HashMap<Player, HashMap<String, Integer>> _offenses = new HashMap<Player, HashMap<String, Integer>>();
//Ignore Player
private HashMap<Player, Long> _ignore = new HashMap<Player, Long>();
//Hack Data
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>> _riseTicks = new HashMap<Player, Entry<Integer, Double>>(); //Ticks, PrevY
private HashMap<Player, Entry<Double, Double>> _momentum = new HashMap<Player, Entry<Double, Double>>(); //Momentum, PrevY
//Hack Requirements
private int _floatHackTicks = 20;
private int _hoverHackTicks = 20;
private int _riseHackTicks = 20;
protected AntiHack(JavaPlugin plugin)
{
super("Recharge", plugin);
}
public static void Initialize(JavaPlugin plugin)
{
Instance = new AntiHack(plugin);
}
@EventHandler
public void PlayerVelocity(PlayerVelocityEvent event)
{
_ignore.put(event.getPlayer(), System.currentTimeMillis() + 2000);
}
@EventHandler
public void PlayerQuit(PlayerQuitEvent event)
{
Reset(event.getPlayer());
}
@EventHandler
public void Update(PlayerMoveEvent event)
{
Player player = event.getPlayer();
//Allowed 'cheaty' movement
if (UtilEnt.isGrounded(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
{
Reset(player);
return;
}
//Not actually moved, just looking around
if (UtilMath.offset(event.getFrom(), event.getTo()) <= 0)
{
UpdateFloat(player);
return;
}
UpdateHover(player);
UpdateRise(player);
UpdateMomentum(player);
}
private void UpdateFloat(Player player)
{
int count = 0;
if (_floatTicks.containsKey(player))
{
if (player.getLocation().getY() == _floatTicks.get(player).getValue())
{
count = _floatTicks.get(player).getKey() + 1;
}
else
{
count = 0;
}
}
if (count > _floatHackTicks)
{
AddOffense(player, "Float");
count = 0;
}
_floatTicks.put(player, new AbstractMap.SimpleEntry<Integer, Double>(count, player.getLocation().getY()));
}
private void UpdateHover(Player player)
{
int count = 0;
if (_hoverTicks.containsKey(player))
{
if (player.getLocation().getY() == _hoverTicks.get(player).getValue())
{
count = _hoverTicks.get(player).getKey() + 1;
}
else
{
count = 0;
}
}
if (count > _hoverHackTicks)
{
AddOffense(player, "Hover");
count = 0;
}
_hoverTicks.put(player, new AbstractMap.SimpleEntry<Integer, Double>(count, player.getLocation().getY()));
}
private void UpdateRise(Player player)
{
int count = 0;
if (_riseTicks.containsKey(player))
{
if (player.getLocation().getY() > _riseTicks.get(player).getValue())
{
count = _riseTicks.get(player).getKey() + 1;
}
else
{
count = 0;
}
}
if (count > _riseHackTicks)
{
AddOffense(player, "Rise");
count = 0;
}
_riseTicks.put(player, new AbstractMap.SimpleEntry<Integer, Double>(count, player.getLocation().getY()));
}
private void UpdateMomentum(Player player)
{
double newMomentum = 0;
if (_momentum.containsKey(player))
{
newMomentum = player.getLocation().getY() - _riseTicks.get(player).getValue();
double oldMomentum = _riseTicks.get(player).getKey();
if (oldMomentum < 0 && newMomentum > 0)
{
AddOffense(player, "Momentum");
return;
}
}
_momentum.put(player, new AbstractMap.SimpleEntry<Double, Double>(newMomentum, player.getLocation().getY()));
}
private void AddOffense(Player player, String type)
{
if (!_offenses.containsKey(player))
_offenses.put(player, new HashMap<String, Integer>());
int previous = 0;
if (_offenses.get(player).containsKey(type))
previous = _offenses.get(player).get(type);
_offenses.get(player).put(type, previous + 1);
//Report (Debug)
for (Player admin : UtilServer.getPlayers())
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)
{
_hoverTicks.remove(player);
_riseTicks.remove(player);
_momentum.remove(player);
}
}

View File

@ -1,11 +1,13 @@
package nautilus.game.arcade.game.games.dragonriders;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import nautilus.game.arcade.ArcadeManager;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEnderDragon;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -13,6 +15,8 @@ import org.bukkit.util.Vector;
public class DragonData
{
ArcadeManager Manager;
public EnderDragon Dragon;
public Player Rider;
@ -25,6 +29,8 @@ public class DragonData
public DragonData(ArcadeManager manager, Player rider)
{
Manager = manager;
Rider = rider;
Velocity = rider.getLocation().getDirection().setY(0).normalize();
@ -39,45 +45,19 @@ public class DragonData
manager.GetGame().CreatureAllowOverride = false;
rider.getWorld().playSound(rider.getLocation(), Sound.ENDERDRAGON_GROWL, 20f, 1f);
Dragon.setPassenger(Rider);
}
public void Move()
{
Turn();
Location.add(Velocity);
Location.add(0, -Pitch, 0);
Location.setPitch(-1 * Pitch);
Location.setYaw(180 + UtilAlg.GetYaw(Velocity));
Dragon.eject();
Dragon.teleport(Location);
Dragon.setPassenger(Rider);
((CraftEnderDragon)Dragon).getHandle().setTargetBlock(GetTarget().getBlockX(), GetTarget().getBlockY(), GetTarget().getBlockZ());
Manager.GetExplosion().BlockExplosion(UtilBlock.getInRadius(Dragon.getLocation(), 10d).keySet(), Dragon.getLocation());
}
public Location GetTarget()
{
return Rider.getLocation().add(Rider.getLocation().getDirection().multiply(40));
}
private void Turn()
{
//Pitch
float desiredPitch = UtilAlg.GetPitch(UtilAlg.getTrajectory(Location, GetTarget()));
if (desiredPitch < Pitch) Pitch = (float)(Pitch - 0.05);
if (desiredPitch > Pitch) Pitch = (float)(Pitch + 0.05);
if (Pitch > 0.5) Pitch = 0.5f;
if (Pitch < -0.5) Pitch = -0.5f;
//Flat
Vector desired = UtilAlg.getTrajectory2d(Location, GetTarget());
desired.subtract(UtilAlg.Normalize(new Vector(Velocity.getX(), 0, Velocity.getZ())));
desired.multiply(0.075);
Velocity.add(desired);
//Speed
UtilAlg.Normalize(Velocity);
}
}

View File

@ -4,6 +4,9 @@ import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.itemstack.ItemStackFactory;
@ -12,7 +15,6 @@ import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkDragonRider;
import nautilus.game.arcade.kit.perks.PerkFletcher;
public class KitRider extends Kit
{
@ -36,6 +38,7 @@ public class KitRider extends Kit
public void GiveItems(Player player)
{
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.BOW));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.ARROW, 64));
player.getInventory().setHelmet(ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_HELMET));
player.getInventory().setChestplate(ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_CHESTPLATE));

View File

@ -2,11 +2,20 @@ package nautilus.game.arcade.kit.perks;
import java.util.HashMap;
import org.bukkit.Sound;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.game.Game.GameState;
@ -63,4 +72,43 @@ public class PerkDragonRider extends Perk
{
event.setCancelled(true);
}
@EventHandler
public void ShootWeb(PlayerInteractEvent event)
{
if (event.isCancelled())
return;
if (event.getAction() != Action.LEFT_CLICK_AIR && event.getAction() != Action.LEFT_CLICK_BLOCK)
return;
if (UtilBlock.usable(event.getClickedBlock()))
return;
if (event.getPlayer().getItemInHand() == null)
return;
if (!event.getPlayer().getItemInHand().getType().toString().contains("BOW"))
return;
Player player = event.getPlayer();
if (!Kit.HasKit(player))
return;
if (!Recharge.Instance.use(player, GetName(), 1000, true))
return;
event.setCancelled(true);
UtilInv.Update(player);
Fireball ball = _dragons.get(player).Dragon.launchProjectile(Fireball.class);
//Inform
UtilPlayer.message(player, F.main("Game", "You used " + F.skill("Dragon Blast") + "."));
//Effect
player.getWorld().playSound(player.getLocation(), Sound.BLAZE_BREATH, 2f, 1f);
}
}