Skip to content

Commit

Permalink
2356 better deletion (#2364)
Browse files Browse the repository at this point in the history
* Fix 1.20.4 backwards compatibility

* Improve deletion speed and memory usage
  • Loading branch information
tastybento committed May 11, 2024
1 parent 83698c2 commit d288528
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
<postgresql.version>42.2.18</postgresql.version>
<hikaricp.version>5.0.1</hikaricp.version>
<!-- More visible way to change dependency versions -->
<spigot.version>1.20.5-R0.1-SNAPSHOT</spigot.version>
<spigot.version>1.20.6-R0.1-SNAPSHOT</spigot.version>
<!-- Might differ from the last Spigot release for short periods
of time -->
<paper.version>1.20.4-R0.1-SNAPSHOT</paper.version>
<paper.version>1.20.6-R0.1-SNAPSHOT</paper.version>
<bstats.version>3.0.0</bstats.version>
<vault.version>1.7.1</vault.version>
<placeholderapi.version>2.10.9</placeholderapi.version>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/world/bentobox/bentobox/BentoBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import world.bentobox.bentobox.listeners.JoinLeaveListener;
import world.bentobox.bentobox.listeners.PanelListenerManager;
import world.bentobox.bentobox.listeners.PrimaryIslandListener;
import world.bentobox.bentobox.listeners.SeedWorldMakerListener;
import world.bentobox.bentobox.listeners.StandardSpawnProtectionListener;
import world.bentobox.bentobox.listeners.teleports.EntityTeleportListener;
import world.bentobox.bentobox.listeners.teleports.PlayerTeleportListener;
Expand Down Expand Up @@ -313,6 +314,8 @@ private void registerListeners() {
manager.registerEvents(islandDeletionManager, this);
// Primary Island Listener
manager.registerEvents(new PrimaryIslandListener(this), this);
// Seed world chunk generator
manager.registerEvents(new SeedWorldMakerListener(this), this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ public void setGlow(boolean glow) {
}
if (meta != null) {
if (glow) {
meta.addEnchant(Enchantment.POWER, 0, glow);
meta.addEnchant(Enchantment.LURE, 0, glow);
} else {
meta.removeEnchant(Enchantment.POWER);
meta.removeEnchant(Enchantment.LURE);
}
icon.setItemMeta(meta);

Expand Down
17 changes: 11 additions & 6 deletions src/main/java/world/bentobox/bentobox/api/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,21 @@ public class User implements MetaDataAble {
Map<Particle, Class<?>> v = new EnumMap<>(Particle.class);
v.put(Enums.getIfPresent(Particle.class, "DUST")
.or(Enums.getIfPresent(Particle.class, "REDSTONE").or(Particle.FLAME)), Particle.DustOptions.class);
v.put(Particle.ITEM, ItemStack.class);
v.put(Particle.ITEM_COBWEB, ItemStack.class);
if (Enums.getIfPresent(Particle.class, "ITEM").isPresent()) {
// 1.20.6 Particles
v.put(Particle.ITEM, ItemStack.class);
v.put(Particle.ITEM_COBWEB, ItemStack.class);
v.put(Particle.BLOCK, BlockData.class);
v.put(Particle.DUST_PILLAR, BlockData.class);
v.put(Particle.ENTITY_EFFECT, Color.class);
}
v.put(Particle.FALLING_DUST, BlockData.class);
v.put(Particle.BLOCK, BlockData.class);
v.put(Particle.BLOCK_MARKER, BlockData.class);
v.put(Particle.DUST_COLOR_TRANSITION, DustTransition.class);
v.put(Particle.DUST_PILLAR, BlockData.class);
v.put(Particle.VIBRATION, Vibration.class);
v.put(Particle.SCULK_CHARGE, Float.class);
v.put(Particle.SHRIEK, Integer.class);
v.put(Particle.ENTITY_EFFECT, Color.class);

VALIDATION_CHECK = Collections.unmodifiableMap(v);
}

Expand Down Expand Up @@ -732,7 +736,8 @@ public void spawnParticle(Particle particle, @Nullable Object dustOptions, doubl
// Check if this particle is beyond the viewing distance of the server
if (this.player != null && this.player.getLocation().toVector().distanceSquared(new Vector(x, y,
z)) < (Bukkit.getServer().getViewDistance() * 256 * Bukkit.getServer().getViewDistance())) {
if (particle.equals(Particle.DUST)) {
if (particle.equals(Enums.getIfPresent(Particle.class, "DUST")
.or(Enums.getIfPresent(Particle.class, "REDSTONE").or(Particle.FLAME)))) {
player.spawnParticle(particle, x, y, z, 1, 0, 0, 0, 1, dustOptions);
} else if (dustOptions != null) {
player.spawnParticle(particle, x, y, z, 1, dustOptions);
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/world/bentobox/bentobox/hooks/LangUtilsHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.bukkit.potion.PotionType;
import org.jetbrains.annotations.Nullable;

import com.google.common.base.Enums;
import com.meowj.langutils.lang.LanguageHelper;

import world.bentobox.bentobox.BentoBox;
Expand Down Expand Up @@ -286,10 +287,6 @@ private static String generalPotionName(PotionType potionType) {
case LUCK -> "Potion of Luck";
case TURTLE_MASTER -> "Potion of the Turtle Master";
case SLOW_FALLING -> "Potion of Slow Falling";
case HARMING -> "Potion of Harming";
case HEALING -> "Potion of Healing";
case INFESTED -> "Infested Potion";
case LEAPING -> "Potion of Leaping";
case LONG_FIRE_RESISTANCE -> "Potion of Long Fire Resistance";
case LONG_INVISIBILITY -> "Potion of Long Invisibility";
case LONG_NIGHT_VISION -> "Potion of Long Night Vision";
Expand All @@ -302,8 +299,6 @@ private static String generalPotionName(PotionType potionType) {
case LONG_TURTLE_MASTER -> "Potion of Long Turtle Master";
case LONG_WATER_BREATHING -> "Potion of Long Water Breathing";
case LONG_WEAKNESS -> "Potion of Long Weakness";
case OOZING -> "Potion of Oozing";
case REGENERATION -> "Potion of Regeneration";
case STRONG_HARMING -> "Potion of Strong Harming";
case STRONG_HEALING -> "Potion of Strong Healing";
case STRONG_LEAPING -> "Potion of Strong Leaping";
Expand All @@ -313,10 +308,7 @@ private static String generalPotionName(PotionType potionType) {
case STRONG_STRENGTH -> "Potion of Strong Strength";
case STRONG_SWIFTNESS -> "Potion of Swiftness";
case STRONG_TURTLE_MASTER -> "Potion of Strong Turtle Master";
case SWIFTNESS -> "Potion of Swiftness";
case WEAVING -> "Potion of Weaving";
case WIND_CHARGED -> "Potion of Wind Charged";
default -> "Potion (Unknown)";
default -> "Potion of " + Util.prettifyText(potionType.name());
};

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package world.bentobox.bentobox.listeners;

import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent;

import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
import world.bentobox.bentobox.util.Util;

/**
* Updates chunks in seed worlds if they have been generated in the main world
* @author tastybento
*/
public class SeedWorldMakerListener implements Listener {

private final BentoBox plugin;

/**
* Whether BentoBox is ready or not.
* This helps to avoid hanging out the server on startup as a lot of {@link ChunkLoadEvent} are called at this time.
* @since 1.1
*/
private boolean ready;


public SeedWorldMakerListener(BentoBox bentoBox) {
this.plugin = bentoBox;
}

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBentoBoxReady(BentoBoxReadyEvent e) {
ready = true;
}

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onChunkLoad(ChunkLoadEvent e) {
if (!ready || !e.getChunk().isGenerated()) {
return;
}
World world = e.getWorld();
plugin.getIWM().getAddon(world).filter(GameModeAddon::isUsesNewChunkGeneration).ifPresent(gma -> {
World seed = Bukkit.getWorld(world.getName() + "/bentobox");
int x = e.getChunk().getX();
int z = e.getChunk().getZ();
if (seed != null && !seed.getChunkAt(x, z, false).isGenerated()) {
Util.getChunkAtAsync(seed, x, z, true);
}
});

}



}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import world.bentobox.bentobox.hooks.ItemsAdderHook;
import world.bentobox.bentobox.hooks.SlimefunHook;
import world.bentobox.bentobox.util.MyBiomeGrid;
import world.bentobox.bentobox.util.Util;

/**
* Regenerates by using a seed world. The seed world is created using the same generator as the game
Expand Down Expand Up @@ -101,7 +102,10 @@ public void run() {
}
final int x = chunkX;
final int z = chunkZ;
newTasks.add(regenerateChunk(di, world, x, z));
// Only add chunks that are generated
if (world.getChunkAt(x, z, false).isGenerated()) {
newTasks.add(regenerateChunk(di, world, x, z));
}
chunkZ++;
if (chunkZ > di.getMaxZChunk()) {
chunkZ = di.getMinZChunk();
Expand All @@ -126,6 +130,11 @@ public CompletableFuture<Void> regenerateChunk(Chunk chunk) {
private CompletableFuture<Void> regenerateChunk(@Nullable IslandDeletion di, @NonNull World world, int chunkX,
int chunkZ) {

// Check if chunk has been generated
if (!world.getChunkAt(chunkX, chunkZ, false).isGenerated()) {
return CompletableFuture.completedFuture(null);
}

CompletableFuture<Chunk> seedWorldFuture = getSeedWorldChunk(world, chunkX, chunkZ);

// Set up a future to get the chunk requests using Paper's Lib. If Paper is used, this should be done async
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/world/bentobox/bentobox/util/ItemParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ private static ItemStack parseBanner(String[] part) {
PatternType pt = Enums.getIfPresent(PatternType.class, part[i]).orNull();
if (pt == null) {
// Try to convert old to new
if (part[i].trim().equals("STRIPE_SMALL")) {
if (part[i].trim().equals("STRIPE_SMALL")
&& Enums.getIfPresent(PatternType.class, "SMALL_STRIPES").isPresent()) {
pt = PatternType.SMALL_STRIPES;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/world/bentobox/bentobox/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ public static PasteHandler getPasteHandler() {
String serverPackageName = Bukkit.getServer().getClass().getPackage().getName();
String pluginPackageName = plugin.getClass().getPackage().getName();
String version = serverPackageName.substring(serverPackageName.lastIndexOf('.') + 1);
BentoBox.getInstance().log("Optimizing for " + version);
PasteHandler handler;
try {
Class<?> clazz = Class.forName(pluginPackageName + ".nms." + version + ".PasteHandlerImpl");
Expand Down

0 comments on commit d288528

Please sign in to comment.