Skip to content

Commit

Permalink
some improvements for modules iterating over entities
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Feb 16, 2024
1 parent d2c8671 commit bc9e7dd
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public String category() {

@Override
public void enable() {
this.scheduledTask = plugin.getServer().getGlobalRegionScheduler().runAtFixedRate(plugin, task -> run(), check_period_in_ticks, check_period_in_ticks);
this.scheduledTask = plugin.getServer().getGlobalRegionScheduler()
.runAtFixedRate(plugin, task -> run(), check_period_in_ticks, check_period_in_ticks);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import me.moomoo.anarchyexploitfixes.config.Config;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import org.bukkit.World;
import org.bukkit.entity.WitherSkull;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;

public class RemoveAllSkullsPeriodically implements AnarchyExploitFixesModule {

Expand Down Expand Up @@ -49,8 +50,10 @@ public void disable() {

private void run() {
for (World world : plugin.getServer().getWorlds()) {
for (WitherSkull witherSkull : world.getEntitiesByClass(WitherSkull.class)) {
witherSkull.getScheduler().run(plugin, kill -> witherSkull.remove(), null);
for (Entity entity : world.getEntities()) {
if (entity.getType() == EntityType.WITHER_SKULL) {
entity.getScheduler().run(plugin, kill -> entity.remove(), null);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import me.moomoo.anarchyexploitfixes.config.Config;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import org.bukkit.World;
import org.bukkit.entity.WitherSkull;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;

public class RemoveSkullsAfterXTicks implements AnarchyExploitFixesModule {

Expand Down Expand Up @@ -56,12 +57,14 @@ public void disable() {

private void run() {
for (World world : plugin.getServer().getWorlds()) {
for (WitherSkull witherSkull : world.getEntitiesByClass(WitherSkull.class)) {
witherSkull.getScheduler().run(plugin, killIfOld -> {
if (witherSkull.getTicksLived() > maxAgeInTicks) {
witherSkull.remove();
}
}, null);
for (Entity entity : world.getEntities()) {
if (entity.getType() == EntityType.WITHER_SKULL) {
entity.getScheduler().run(plugin, killIfOld -> {
if (entity.getTicksLived() > maxAgeInTicks) {
entity.remove();
}
}, null);
}
}
}
}
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.LocationUtil;
import me.moomoo.anarchyexploitfixes.utils.LogUtil;
import net.kyori.adventure.text.TextReplacementConfig;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
Expand All @@ -18,6 +19,7 @@

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

public class WitherSpawningAtSpawn implements AnarchyExploitFixesModule, Listener {

Expand All @@ -35,8 +37,12 @@ public WitherSpawningAtSpawn() {
defaults.put("world_the_end", 5000);
ConfigSection section = config.getConfigSection("preventions.withers.disable-wither-spawning-at-spawn.worlds", defaults);
for (String world : section.getKeys(false)) {
Integer radius = Integer.valueOf(section.getString(world));
this.worldsAndTheirRadiuses.put(world, radius);
try {
Integer radius = Integer.valueOf(section.getString(world));
this.worldsAndTheirRadiuses.put(world, radius);
} catch (NumberFormatException e) {
LogUtil.moduleLog(Level.WARNING, name(), "Radius for world '" + world + "' is not a valid integer.");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import me.moomoo.anarchyexploitfixes.config.Config;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import org.bukkit.World;
import org.bukkit.entity.WitherSkull;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;

public class RemoveAllSkullsPeriodically implements AnarchyExploitFixesModule, Runnable {

Expand Down Expand Up @@ -43,8 +44,10 @@ public boolean shouldEnable() {
@Override
public void run() {
for (World world : plugin.getServer().getWorlds()) {
for (WitherSkull witherSkull : world.getEntitiesByClass(WitherSkull.class)) {
witherSkull.remove();
for (Entity entity : world.getEntities()) {
if (entity.getType() == EntityType.WITHER_SKULL) {
entity.remove();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import me.moomoo.anarchyexploitfixes.config.Config;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import org.bukkit.World;
import org.bukkit.entity.WitherSkull;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;

public class RemoveSkullsAfterXTicks implements AnarchyExploitFixesModule, Runnable {

Expand Down Expand Up @@ -50,9 +51,11 @@ public boolean shouldEnable() {
@Override
public void run() {
for (World world : plugin.getServer().getWorlds()) {
for (WitherSkull witherSkull : world.getEntitiesByClass(WitherSkull.class)) {
if (witherSkull.getTicksLived() > maxAgeInTicks) {
witherSkull.remove();
for (Entity entity : world.getEntities()) {
if (entity.getType() == EntityType.WITHER_SKULL) {
if (entity.getTicksLived() > maxAgeInTicks) {
entity.remove();
}
}
}
}
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.LocationUtil;
import me.moomoo.anarchyexploitfixes.utils.LogUtil;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
Expand All @@ -16,6 +17,7 @@

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

public class WitherSpawningAtSpawn implements AnarchyExploitFixesModule, Listener {

Expand All @@ -32,10 +34,12 @@ public WitherSpawningAtSpawn() {
defaults.put("world_nether", 5000);
defaults.put("world_the_end", 5000);
ConfigSection section = config.getConfigSection("preventions.withers.disable-wither-spawning-at-spawn.worlds", defaults);
if (section != null) {
for (String world : section.getKeys(false)) {
for (String world : section.getKeys(false)) {
try {
Integer radius = Integer.valueOf(section.getString(world));
worldsAndTheirRadiuses.put(world, radius);
this.worldsAndTheirRadiuses.put(world, radius);
} catch (NumberFormatException e) {
LogUtil.moduleLog(Level.WARNING, name(), "Radius for world '" + world + "' is not a valid integer.");
}
}
}
Expand Down

0 comments on commit bc9e7dd

Please sign in to comment.