Skip to content

Commit

Permalink
a range of more various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 3, 2024
1 parent 63c5ba1 commit 25f6591
Show file tree
Hide file tree
Showing 17 changed files with 343 additions and 415 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.moomoo.anarchyexploitfixes.modules.combat;

import com.destroystokyo.paper.MaterialTags;
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.config.Config;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
Expand All @@ -24,11 +25,15 @@ public class Burrow implements AnarchyExploitFixesModule, Listener {
public Burrow() {
shouldEnable();
Config config = AnarchyExploitFixes.getConfiguration();
this.damageWhenMovingInBurrow = config.getDouble("combat.prevent-burrow.damage-when-moving",1.0, "1.0 = Half a heart of damage every time you move.");
this.damageWhenMovingInBurrow = config.getDouble("combat.prevent-burrow.damage-when-moving",1.0,
"1.0 = Half a heart of damage every time you move.");
this.shouldTeleportUp = config.getBoolean("combat.prevent-burrow.teleport-above-block", true);
this.preventIfBlockAboveBurrow = config.getBoolean("combat.prevent-burrow.prevent-if-block-above-burrow", false, "Prevent burrow even if there is a block above the block they are burrowing in, please note this may allow creating an \"elevator\", players will keep teleporting up until they hit air");
this.preventIfBlockAboveBurrow = config.getBoolean("combat.prevent-burrow.prevent-if-block-above-burrow", false,
"Prevent burrow even if there is a block above the block they are burrowing in. \n" +
"Please note this may allow creating an \"elevator\", players will keep teleporting up until they hit air");
this.breakAnvilInsteadOfTP = config.getBoolean("combat.prevent-burrow.break-anvil-instead-of-teleport", true);
this.allowSlabs = config.getBoolean("combat.prevent-burrow.allow-slabs-in-burrow", true, "Needs to be enabled to prevent a bug where players are teleported above a slab when the slab is underwater, only happens in newer versions.");
this.allowSlabs = config.getBoolean("combat.prevent-burrow.allow-slabs-in-burrow", true,
"Needs to be enabled to prevent a bug where players are teleported above a slab when the slab is underwater, only happens in newer versions.");
}

@Override
Expand Down Expand Up @@ -76,7 +81,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
|| burrowMaterial.equals(Material.DIRT) // Fixes false positives when trampling farmland
|| burrowMaterial.equals(Material.SAND)
|| burrowMaterial.equals(Material.GRAVEL)
|| MaterialUtil.isShulkerBox(burrowMaterial)
|| MaterialTags.SHULKER_BOXES.isTagged(burrowMaterial)
) return;

if (preventIfBlockAboveBurrow || burrowBlock.getRelative(BlockFace.UP).getType().equals(Material.AIR)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;

import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.*;

public class IncompatibleEnchants implements AnarchyExploitFixesModule, Listener {

private final AnarchyExploitFixes plugin;
private ScheduledTask periodicInvCheck;
private final boolean whitelistIsEnabled, useWhitelistAsBlacklist, enableStrictPrevention;
private final HashSet<Material> whitelistedItems = new HashSet<>();
private ScheduledTask periodicInvCheck;
private final long checkPeriod;
private final boolean whitelistIsEnabled, useWhitelistAsBlacklist, enableStrictPrevention;

public IncompatibleEnchants() {
shouldEnable();
Expand Down Expand Up @@ -144,75 +144,52 @@ private void filterBasedOnType(ItemStack item) {
}

private void filterCurses(ItemStack item) {
HashMap<Enchantment, Integer> enchantments = new HashMap<>(item.getEnchantments());
if (enchantments.isEmpty()) return;
if (
enchantments.containsKey(Enchantment.BINDING_CURSE)
&& enchantments.containsKey(Enchantment.VANISHING_CURSE)
) {
Map<Enchantment, Integer> enchantments = item.getEnchantments();
if (enchantments.containsKey(Enchantment.BINDING_CURSE) && enchantments.containsKey(Enchantment.VANISHING_CURSE)) {
item.removeEnchantment(Enchantment.BINDING_CURSE);
}
}

private void filterCrossbow(ItemStack item) {
HashMap<Enchantment, Integer> enchantments = new HashMap<>(item.getEnchantments());
if (enchantments.isEmpty()) return;
if (
enchantments.containsKey(Enchantment.MULTISHOT)
&& enchantments.containsKey(Enchantment.PIERCING)
) {
Map<Enchantment, Integer> enchantments = item.getEnchantments();
if (enchantments.containsKey(Enchantment.MULTISHOT) && enchantments.containsKey(Enchantment.PIERCING)) {
item.removeEnchantment(Enchantment.MULTISHOT);
}
}

private void filterTrident(ItemStack item) {
HashMap<Enchantment, Integer> enchantments = new HashMap<>(item.getEnchantments());
if (enchantments.isEmpty()) return;
Map<Enchantment, Integer> enchantments = item.getEnchantments();
if (enchantments.containsKey(Enchantment.RIPTIDE)) {
if (
enchantments.containsKey(Enchantment.LOYALTY)
|| enchantments.containsKey(Enchantment.CHANNELING)
) {
if (enchantments.containsKey(Enchantment.LOYALTY) || enchantments.containsKey(Enchantment.CHANNELING)) {
item.removeEnchantment(Enchantment.RIPTIDE);
}
}
}

private void filterBow(ItemStack item) {
HashMap<Enchantment, Integer> enchantments = new HashMap<>(item.getEnchantments());
if (enchantments.isEmpty()) return;
if (
enchantments.containsKey(Enchantment.MENDING)
&& enchantments.containsKey(Enchantment.ARROW_INFINITE)
) {
Map<Enchantment, Integer> enchantments = item.getEnchantments();
if (enchantments.containsKey(Enchantment.MENDING) && enchantments.containsKey(Enchantment.ARROW_INFINITE)) {
item.removeEnchantment(Enchantment.ARROW_INFINITE);
}
}

private void filterTools(ItemStack item) {
HashMap<Enchantment, Integer> enchantments = new HashMap<>(item.getEnchantments());
Map<Enchantment, Integer> enchantments = item.getEnchantments();
if (enchantments.isEmpty()) return;
if (
enchantments.containsKey(Enchantment.SILK_TOUCH)
&& enchantments.containsKey(Enchantment.LOOT_BONUS_BLOCKS)
) {
if (enchantments.containsKey(Enchantment.SILK_TOUCH) && enchantments.containsKey(Enchantment.LOOT_BONUS_BLOCKS)) {
item.removeEnchantment(Enchantment.LOOT_BONUS_BLOCKS);
}
}

private void filterBoots(ItemStack item) {
HashMap<Enchantment, Integer> enchantments = new HashMap<>(item.getEnchantments());
if (enchantments.isEmpty()) return;
if (
enchantments.containsKey(Enchantment.DEPTH_STRIDER)
&& enchantments.containsKey(Enchantment.FROST_WALKER)
) {
Map<Enchantment, Integer> enchantments = item.getEnchantments();
if (enchantments.containsKey(Enchantment.DEPTH_STRIDER) && enchantments.containsKey(Enchantment.FROST_WALKER)) {
item.removeEnchantment(Enchantment.FROST_WALKER);
}
}

private void filterSharpnessEnchants(ItemStack item) {
HashMap<Enchantment, Integer> enchantments = new HashMap<>(item.getEnchantments());
Map<Enchantment, Integer> enchantments = item.getEnchantments();
if (enchantments.isEmpty()) return;

// Prefer keeping Sharpness enchantment if it is present
Expand All @@ -230,8 +207,9 @@ private void filterSharpnessEnchants(ItemStack item) {
}

private void filterProtectionEnchants(ItemStack item) {
HashMap<Enchantment, Integer> enchantments = new HashMap<>(item.getEnchantments());
Map<Enchantment, Integer> enchantments = item.getEnchantments();
if (enchantments.isEmpty()) return;

// Prefer keeping Protection enchantment if it is present
if (enchantments.containsKey(Enchantment.PROTECTION_ENVIRONMENTAL)) {
if (enchantments.containsKey(Enchantment.PROTECTION_EXPLOSIONS))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.config.Config;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import me.moomoo.anarchyexploitfixes.utils.MaterialUtil;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
Expand All @@ -15,8 +16,6 @@
import java.util.HashSet;
import java.util.List;

import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isIndestructible;

public class PistonExplodePermBlockRemoval implements AnarchyExploitFixesModule, Listener {

private final AnarchyExploitFixes plugin;
Expand All @@ -27,7 +26,8 @@ public PistonExplodePermBlockRemoval() {
this.plugin = AnarchyExploitFixes.getInstance();
Config config = AnarchyExploitFixes.getConfiguration();
this.whitelistedWorlds.addAll(config.getList("preventions.permanent-block-breaking.by-exploding-pistons.whitelisted-worlds", List.of("example_world_name")));
config.getBoolean("preventions.permanent-block-breaking.by-exploding-pistons.only-for-portals-and-gateways", false, "If enabled, will only protect portals and end gateways");
config.getBoolean("preventions.permanent-block-breaking.by-exploding-pistons.only-for-portals-and-gateways", false,
"If enabled, will only protect portals and end gateways");
}

@Override
Expand Down Expand Up @@ -62,7 +62,7 @@ private void onPistonExplode(EntityExplodeEvent event) {
event.blockList().removeIf(block -> {
if (MaterialTags.PISTONS.isTagged(block.getType())) {
for (BlockFace face : BlockFace.values()) {
if (isIndestructible(block.getRelative(face).getType())) {
if (MaterialUtil.isIndestructible(block.getRelative(face).getType())) {
plugin.getServer().getRegionScheduler().runDelayed(plugin, block.getLocation(),
removePiston -> block.setType(Material.AIR), 5);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import me.moomoo.anarchyexploitfixes.utils.MaterialUtil;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
Expand All @@ -11,8 +12,6 @@
import java.util.HashSet;
import java.util.List;

import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isIndestructible;

public class PistonPlaceWhileRetractPermBlockRemoval implements AnarchyExploitFixesModule, Listener {

private final HashSet<String> whitelistedWorlds = new HashSet<>();
Expand Down Expand Up @@ -53,7 +52,7 @@ public void disable() {
private void onPistonRetract(BlockPistonRetractEvent event) {
if (whitelistedWorlds.contains(event.getBlock().getWorld().getName())) return;

if (isIndestructible(event.getBlock().getRelative(event.getDirection().getOppositeFace()).getType())) {
if (MaterialUtil.isIndestructible(event.getBlock().getRelative(event.getDirection().getOppositeFace()).getType())) {
event.setCancelled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.moomoo.anarchyexploitfixes.config.Config;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import me.moomoo.anarchyexploitfixes.utils.LogUtil;
import me.moomoo.anarchyexploitfixes.utils.MaterialUtil;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
Expand Down Expand Up @@ -88,9 +89,8 @@ public void disable() {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onBlockDispense(BlockDispenseEvent event) {
final String dispenseMaterial = event.getItem().getType().toString();
if (
dispenseMaterial.endsWith("_BUCKET") && !dispenseMaterial.startsWith("MILK")
MaterialUtil.isLiquidBucket(event.getItem().getType())
&& event.getVelocity().clone().toLocation(event.getBlock().getWorld()).getBlock().getType().equals(Material.END_PORTAL)
) {
event.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import org.bukkit.entity.Player;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
Expand All @@ -13,7 +13,8 @@ public class PreventAllEntitiesInPortals implements AnarchyExploitFixesModule, L

public PreventAllEntitiesInPortals() {
shouldEnable();
AnarchyExploitFixes.getConfiguration().addComment("preventions.portals.prevent-all-entities-in-portals", "only enable if you must. Does not affect players.");
AnarchyExploitFixes.getConfiguration().addComment("preventions.portals.prevent-all-entities-in-portals",
"only enable if you must. Does not affect players.");
}

@Override
Expand Down Expand Up @@ -42,9 +43,9 @@ public void disable() {
HandlerList.unregisterAll(this);
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPortalUse(EntityPortalEvent event) {
if (!(event.getEntity() instanceof Player)) {
if (!event.getEntityType().equals(EntityType.PLAYER)) {
event.setCancelled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.config.Config;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityPortalEvent;

import java.util.HashSet;

public class PreventProjectilesInPortals implements AnarchyExploitFixesModule, Listener {

private final HashSet<EntityType> PROJECTILE_TYPES = new HashSet<>();

public PreventProjectilesInPortals() {
shouldEnable();
AnarchyExploitFixes.getConfiguration().addComment("preventions.portals.prevent-projectiles-in-portals",
Expand Down Expand Up @@ -50,8 +55,14 @@ public void disable() {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onEntityPortal(EntityPortalEvent event) {
if (PROJECTILE_TYPES.contains(event.getEntityType())) {
event.setCancelled(true);
return;
}

if (event.getEntity() instanceof Projectile) {
event.setCancelled(true);
PROJECTILE_TYPES.add(event.getEntityType());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@

public class MaterialUtil {

public static boolean isLiquidBucket(ItemStack item) {
if (item == null) return false;
return isLiquidBucket(item.getType());
}

public static boolean isLiquidBucket(Material material) {
if (material == null) return false;
return switch (material) {
case WATER_BUCKET,
LAVA_BUCKET,
COD_BUCKET,
SALMON_BUCKET,
PUFFERFISH_BUCKET,
TROPICAL_FISH_BUCKET,
AXOLOTL_BUCKET,
TADPOLE_BUCKET,
POWDER_SNOW_BUCKET
-> true;
default -> false;
};
}

public static boolean isIndestructible(Material material) {
return switch (material) {
case BEDROCK,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.moomoo.anarchyexploitfixes.modules.combat;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XTag;
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.config.Config;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
Expand All @@ -23,18 +22,13 @@

public class Burrow implements AnarchyExploitFixesModule, Listener {

private final HashSet<Material> ANVILS, SINK_IN_BLOCKS, SLAB_LIKE;
private final Material AIR, SAND, GRAVEL, DIRT, ENCHANTING_TABLE, ENDER_CHEST, BEDROCK, BEACON;
private final HashSet<Material> SINK_IN_BLOCKS, SLAB_LIKE;
private final Material AIR, SAND, GRAVEL, DIRT, ENCHANTING_TABLE, ENDER_CHEST, BEACON;
private final double damageWhenMovingInBurrow;
private final boolean shouldTeleportUp, preventIfBlockAboveBurrow, breakAnvilInsteadOfTP, allowSlabs;

public Burrow() {
shouldEnable();
// Anvils
this.ANVILS = XTag.ANVIL.getValues().stream()
.filter(XMaterial::isSupported)
.map(XMaterial::parseMaterial)
.collect(Collectors.toCollection(HashSet::new));
// Blocks that the player gets lowered into slightly when walking on them
this.SINK_IN_BLOCKS = new HashSet<>(3);
this.SINK_IN_BLOCKS.add(XMaterial.SOUL_SAND.parseMaterial());
Expand All @@ -55,7 +49,6 @@ public Burrow() {
this.GRAVEL = XMaterial.GRAVEL.parseMaterial();
this.ENCHANTING_TABLE = XMaterial.ENCHANTING_TABLE.parseMaterial();
this.ENDER_CHEST = XMaterial.ENDER_CHEST.parseMaterial();
this.BEDROCK = XMaterial.BEDROCK.parseMaterial();
this.BEACON = XMaterial.BEACON.parseMaterial();
this.DIRT = XMaterial.DIRT.parseMaterial();

Expand Down Expand Up @@ -113,7 +106,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
|| burrowMaterial.equals(DIRT) // Fixes false positives when trampling farmland
|| burrowMaterial.equals(SAND)
|| burrowMaterial.equals(GRAVEL)
|| MaterialUtil.isShulkerBox(burrowMaterial)
|| MaterialUtil.SHULKER_BOXES.contains(burrowMaterial)
) return;

if (preventIfBlockAboveBurrow || burrowBlock.getRelative(BlockFace.UP).getType().equals(AIR)) {
Expand Down Expand Up @@ -146,7 +139,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
}

// Anvils
if (ANVILS.contains(burrowMaterial)) {
if (MaterialUtil.ANVILS.contains(burrowMaterial)) {
player.damage(damageWhenMovingInBurrow);
if (breakAnvilInsteadOfTP) {
burrowBlock.breakNaturally();
Expand All @@ -157,7 +150,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
}

// Beacons and Indestructibles
if (burrowMaterial.equals(BEACON) || MaterialUtil.isIndestructible(burrowMaterial)) {
if (burrowMaterial.equals(BEACON) || MaterialUtil.INDESTRUCTIBLES.contains(burrowMaterial)) {
player.damage(damageWhenMovingInBurrow);
if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation());
}
Expand Down
Loading

0 comments on commit 25f6591

Please sign in to comment.