Last active
August 29, 2015 14:04
-
-
Save DarkArc/7b518d8d54c4750a3252 to your computer and use it in GitHub Desktop.
Anti Jump Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.sk89q.commandbook.CommandBook; | |
import com.skelril.aurora.util.ChatUtil; | |
import com.skelril.aurora.util.LocationUtil; | |
import com.zachsthings.libcomponents.ComponentInformation; | |
import com.zachsthings.libcomponents.bukkit.BukkitComponent; | |
import com.zachsthings.libcomponents.config.ConfigurationBase; | |
import com.zachsthings.libcomponents.config.Setting; | |
import org.bukkit.Location; | |
import org.bukkit.Server; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.EventPriority; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.block.BlockPlaceEvent; | |
import org.bukkit.event.player.PlayerTeleportEvent; | |
import java.util.logging.Logger; | |
@ComponentInformation(friendlyName = "Anti Jump", desc = "Stop the jump hackers") | |
public class AntiJumpComponent extends BukkitComponent implements Listener { | |
private final CommandBook inst = CommandBook.inst(); | |
private final Logger log = inst.getLogger(); | |
private final Server server = CommandBook.server(); | |
private LocalConfiguration config; | |
@Override | |
public void enable() { | |
config = configure(new LocalConfiguration()); | |
//noinspection AccessStaticViaInstance | |
inst.registerEvents(this); | |
} | |
@Override | |
public void reload() { | |
super.reload(); | |
configure(config); | |
} | |
private static class LocalConfiguration extends ConfigurationBase { | |
@Setting("upwards-velocity") | |
public double upwardsVelocity = .1; | |
@Setting("leap-distance") | |
public double leapDistance = 1.2; | |
@Setting("radius") | |
public double radius = 2; | |
} | |
@EventHandler(priority = EventPriority.MONITOR) | |
public void onBlockPlace(BlockPlaceEvent event) { | |
if (event.isCancelled()) { | |
final Player player = event.getPlayer(); | |
final Location playerLoc = player.getLocation(); | |
final Location blockLoc = event.getBlock().getLocation(); | |
final int blockY = blockLoc.getBlockY(); | |
if (Math.abs(player.getVelocity().getY()) > config.upwardsVelocity && playerLoc.getY() > blockY) { | |
server.getScheduler().runTaskLater(inst, () -> { | |
if (player.getLocation().getY() >= (blockY + config.leapDistance)) { | |
if (LocationUtil.distanceSquared2D(playerLoc, blockLoc) > config.radius * config.radius) { | |
return; | |
} | |
ChatUtil.sendWarning(player, "Hack jumping detected."); | |
playerLoc.setY(blockY); | |
player.teleport(playerLoc, PlayerTeleportEvent.TeleportCause.UNKNOWN); | |
} | |
}, 4); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment