/
minecraftbackup
/
AnarchyExploitFixes
Обзор
Документация
Войти
/
minecraftbackup
/
AnarchyExploitFixes
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/Burrow.java
155 строк
7 KB
Ginko
2.7.2 release (#233)
13 авг 2024, 08:21
Не верифицирован
13 авг 2024, 08:21
d20da6e
Код
Авторство
О чём код?
package me.xginko.aef.modules.combat; import com.cryptomorin.xseries.XMaterial; import com.cryptomorin.xseries.XTag; import me.xginko.aef.modules.AEFModule; import me.xginko.aef.utils.EntityUtil; import me.xginko.aef.utils.MaterialUtil; import me.xginko.aef.utils.PlatformUtil; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerMoveEvent; import java.util.EnumSet; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; public class Burrow extends AEFModule implements Listener { private final Set<Material> ignoredMaterial; private final double damageWhenMovingInBurrow; private final boolean shouldTeleportUp, preventIfBlockAboveBurrow, breakAnvilInsteadOfTP, allowSlabs; public Burrow() { super("combat.prevent-burrow"); this.damageWhenMovingInBurrow = config.getDouble(configPath + ".damage-when-moving",1.0, "1.0 = Half a heart of damage every time you move."); this.shouldTeleportUp = config.getBoolean(configPath + ".teleport-above-block", true); this.preventIfBlockAboveBurrow = config.getBoolean(configPath + ".prevent-if-block-above-burrow", false, "Prevent burrow even if there is a block above the block they\n" + "are burrowing in.\n" + "Please note this may allow creating an 'elevator', players will\n" + "keep teleporting up until they hit air."); this.breakAnvilInsteadOfTP = config.getBoolean(configPath + ".break-anvil-instead-of-teleport", true); this.allowSlabs = config.getBoolean(configPath + ".allow-slabs-in-burrow", PlatformUtil.getMinecraftVersion() > 12, "Needs to be enabled to prevent a bug where players are teleported\n" + "above a slab when the slab is underwater."); List<String> defaults = Stream.concat(XTag.SHULKER_BOXES.getValues().stream(), Stream.of(XMaterial.AIR, XMaterial.DIRT, XMaterial.DIRT_PATH, XMaterial.SAND, XMaterial.GRAVEL)) .filter(XMaterial::isSupported) .map(XMaterial::parseMaterial) .map(Enum::name) .collect(Collectors.toList()); this.ignoredMaterial = config.getList(configPath + ".ignored-materials", defaults) .stream() .map(ignored -> { try { return Material.valueOf(ignored); } catch (IllegalArgumentException e) { notRecognized(Material.class, ignored); return null; } }) .filter(Objects::nonNull) .collect(Collectors.toCollection(() -> EnumSet.noneOf(Material.class))); } @Override public void enable() { plugin.getServer().getPluginManager().registerEvents(this, plugin); } @Override public boolean shouldEnable() { return config.getBoolean(configPath + ".enable", false); } @Override public void disable() { HandlerList.unregisterAll(this); } private void teleportUpAndCenter(Player player, Location from) { player.teleport(from.clone().add(0.5, 1, 0.5)); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onSelfPlace(BlockPlaceEvent event) { final Location blockLoc = event.getBlock().getLocation(); Location legsLoc = event.getPlayer().getLocation().toBlockLocation(); if (legsLoc.equals(blockLoc) || legsLoc.add(0, 1, 0).equals(blockLoc)) { event.setCancelled(true); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); if (player.getGameMode() != GameMode.SURVIVAL) return; if (player.isInsideVehicle() || player.isGliding() || EntityUtil.isSwimming(player)) return; final Location playerLocation = player.getLocation(); final Block burrowBlock = playerLocation.getBlock(); if (ignoredMaterial.contains(burrowBlock.getType())) return; if (!preventIfBlockAboveBurrow && burrowBlock.getRelative(BlockFace.UP).getType() != XMaterial.AIR.parseMaterial()) { return; } // Beacon and Indestructibles if (MaterialUtil.SOLID_INDESTRUCTIBLES.contains(burrowBlock.getType()) || burrowBlock.getType() == XMaterial.BEACON.parseMaterial()) { player.damage(damageWhenMovingInBurrow); if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation()); return; } // Occluding blocks that do not lower the player into themselves if (burrowBlock.getType().isOccluding() && !MaterialUtil.SINK_IN_BLOCKS.contains(burrowBlock.getType())) { if (!allowSlabs || !MaterialUtil.SLAB_LIKE.contains(burrowBlock.getType())) { player.damage(damageWhenMovingInBurrow); if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation()); } return; } // Anvil if (MaterialUtil.ANVILS.contains(burrowBlock.getType())) { player.damage(damageWhenMovingInBurrow); if (breakAnvilInsteadOfTP) { burrowBlock.setType(XMaterial.AIR.parseMaterial()); } else { if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation()); } return; } // Ender chest & Blocks that are slightly lower in height if (burrowBlock.getType() == XMaterial.ENDER_CHEST.parseMaterial() || MaterialUtil.SINK_IN_BLOCKS.contains(burrowBlock.getType())) { if (playerLocation.getY() - playerLocation.getBlockY() < 0.875) { player.damage(damageWhenMovingInBurrow); if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation()); } return; } // Enchantment Table if (burrowBlock.getType() == XMaterial.ENCHANTING_TABLE.parseMaterial()) { if (playerLocation.getY() - playerLocation.getBlockY() < 0.75) { player.damage(damageWhenMovingInBurrow); if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation()); } } } }