Skip to content

Commit

Permalink
rework withers section
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Aug 17, 2024
1 parent 0675ec8 commit 16c343a
Show file tree
Hide file tree
Showing 18 changed files with 272 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public MapCursorLag() {

@Override
public void enable() {
if (EntityUtil.canDisableMapPositionCursor())
if (EntityUtil.MAP_SET_TRACKING_POS_AVAILABLE)
plugin.getServer().getPluginManager().registerEvents(this, plugin);
PacketEvents.getAPI().getEventManager().registerListener(asAbstract);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class RateLimitWitherSkulls extends AEFModule implements Listener {
private final ExpiringSet<UUID> targetingPlayers, targetingOther, notTargeting;

public RateLimitWitherSkulls() {
super("preventions.withers.rate-limit-wither-skulls");
super("preventions.withers.rate-limit-shooting-skulls");
config.addComment(configPath + ".enable", """
This can help combat lag caused by a ton of wither skulls\s
spawning but weakens withers.""");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.world.ChunkLoadEvent;

public class RemoveSkullsOnChunkload extends AEFModule implements Listener {

public RemoveSkullsOnChunkload() {
super("preventions.withers.remove-flying-wither-skulls.on-chunk-load");
super("preventions.withers.remove-skulls-on-chunk-load");
config.addComment(configPath, """
Removes wither skulls when the chunk gets loaded.\s
Use if you have a ton of them at spawn and they are causing lag.""");
Expand All @@ -33,6 +34,13 @@ public void disable() {
HandlerList.unregisterAll(this);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onProjectileLaunch(ProjectileLaunchEvent event) {
if (event.getEntityType() == XEntityType.WITHER_SKULL.get()) {
event.getEntity().setPersistent(false); // Don't save skull when chunk unloads
}
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
private void onChunkLoad(ChunkLoadEvent event) {
if (event.isNewChunk()) return;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package me.xginko.aef.modules.preventions.withers;

import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
import me.xginko.aef.modules.AEFModule;
import me.xginko.aef.utils.LocationUtil;
import org.bukkit.entity.EntityType;
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.EntityExplodeEvent;
import org.bukkit.util.NumberConversions;

import java.util.HashMap;
import java.util.Map;

public class WitherSkullDropsAtSpawn extends AEFModule implements Listener {

private final Map<String, Double> worldsAndTheirRadiuses = new HashMap<>();

public WitherSkullDropsAtSpawn() {
super("preventions.withers.disable-item-drops-at-spawn");
config.addComment(configPath + ".enable",
"Prevents wither skulls from dropping items when they hit a block\n" +
"within a certain radius from 00. Can help with lag.");
Map<String, Object> defaults = new HashMap<>();
defaults.put("world", 5000);
defaults.put("world_nether", 5000);
defaults.put("world_the_end", 5000);
ConfigSection section = config.getConfigSection(configPath + ".worlds", defaults);
for (String world : section.getKeys(false)) {
try {
double radiusSquared = NumberConversions.square(Integer.parseInt(section.getString(world)));
this.worldsAndTheirRadiuses.put(world, radiusSquared);
} catch (NumberFormatException e) {
warn("Radius for world '" + world + "' is not a valid integer.");
}
}
}

@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);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onEntityExplode(EntityExplodeEvent event) {
if (event.getEntityType() != EntityType.WITHER_SKULL) return;
if (!worldsAndTheirRadiuses.containsKey(event.getLocation().getWorld().getName())) return;

if (LocationUtil.getSquaredDistance2DTo00(event.getLocation())
<= worldsAndTheirRadiuses.get(event.getLocation().getWorld().getName())) {
event.setYield(0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import java.util.HashMap;
import java.util.Map;

public class WitherSpawningAtSpawn extends AEFModule implements Listener {
public class WitherSummonAtSpawn extends AEFModule implements Listener {

private final Map<String, Integer> worldsAndTheirRadiuses = new HashMap<>();
private final boolean playersShouldBeInformed;

public WitherSpawningAtSpawn() {
super("preventions.withers.disable-wither-spawning-at-spawn");
public WitherSummonAtSpawn() {
super("preventions.withers.disable-summon-at-spawn");
config.addComment(configPath + ".enable", """
Disables spawning withers near a configurable radius around\s
spawn. Helps if players are generating endless amounts of withers\s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.commons.math3.util.FastMath;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.util.NumberConversions;

public class LocationUtil {

Expand All @@ -16,10 +17,37 @@ public static boolean isNetherCeiling(Location location) {
&& location.y() > AnarchyExploitFixes.config().nether_ceiling_max_y;
}

public static double getSquaredDistance2DTo00(Location location) {
return NumberConversions.square(location.getX()) + NumberConversions.square(location.getZ());
}

public static double getDistance2DTo00(Location location) {
return FastMath.hypot(location.getX(), location.getZ());
}

public static double getRelSquaredDistance2D(Location from, Location to) {
double toX = to.getX();
double toZ = to.getZ();
double fromX = from.getX();
double fromZ = from.getZ();

final World.Environment toEnv = to.getWorld().getEnvironment();
final World.Environment fromEnv = from.getWorld().getEnvironment();
if (toEnv != fromEnv) {
if (fromEnv == World.Environment.NETHER) {
fromX *= 8;
fromZ *= 8;
}
if (toEnv == World.Environment.NETHER) {
toX *= 8;
toZ *= 8;
}
}

return NumberConversions.square(toX - fromX) +
NumberConversions.square(toZ - fromZ);
}

public static double getRelDistance2D(Location from, Location to) {
double toX = to.x();
double toZ = to.z();
Expand All @@ -42,6 +70,30 @@ public static double getRelDistance2D(Location from, Location to) {
return FastMath.hypot(toX - fromX, toZ - fromZ);
}

public static double getRelSquaredDistance3D(Location from, Location to) {
double toX = to.getX();
double toZ = to.getZ();
double fromX = from.getX();
double fromZ = from.getZ();

final World.Environment toEnv = to.getWorld().getEnvironment();
final World.Environment fromEnv = from.getWorld().getEnvironment();
if (toEnv != fromEnv) {
if (fromEnv == World.Environment.NETHER) {
fromX *= 8;
fromZ *= 8;
}
if (toEnv == World.Environment.NETHER) {
toX *= 8;
toZ *= 8;
}
}

return NumberConversions.square(toX - fromX) +
NumberConversions.square(from.getY() - to.getY()) +
NumberConversions.square(toZ - fromZ);
}

public static double getRelDistance3D(Location from, Location to) {
double toX = to.x();
double toZ = to.z();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class RateLimitWitherSkulls extends AEFModule implements Listener {
private final ExpiringSet<UUID> targetingPlayers, targetingOther, notTargeting;

public RateLimitWitherSkulls() {
super("preventions.withers.rate-limit-wither-skulls");
super("preventions.withers.rate-limit-shooting-skulls");
config.addComment(configPath + ".enable",
"This can help combat lag caused by a ton of wither skulls\n" +
"spawning but weakens withers.");
Expand Down
Loading

0 comments on commit 16c343a

Please sign in to comment.