mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-17 21:02:20 +01:00
Switch to timer-based chunk deletion
This commit is contained in:
parent
b51178518a
commit
7c1e195eaf
@ -109,7 +109,7 @@ public class Database<T> {
|
|||||||
handler.deleteObject(object);
|
handler.deleteObject(object);
|
||||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||||
| IntrospectionException e) {
|
| IntrospectionException e) {
|
||||||
logger.severe(() -> "Could not delete config! Error: " + e.getMessage());
|
logger.severe(() -> "Could not delete object! Error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,172 @@
|
|||||||
|
package world.bentobox.bentobox.database.objects;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
|
|
||||||
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data object to store islands in deletion
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class DeletedIslandDO implements DataObject {
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
private String uniqueId = "";
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
private World world;
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
private int minXChunk;
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
private int maxXChunk;
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
private int minZChunk;
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
private int maxZChunk;
|
||||||
|
|
||||||
|
public DeletedIslandDO() {}
|
||||||
|
|
||||||
|
public DeletedIslandDO(Location location, int minXChunk, int maxXChunk, int minZChunk, int maxZChunk) {
|
||||||
|
this.uniqueId = Util.getStringLocation(location);
|
||||||
|
this.world = location.getWorld();
|
||||||
|
this.minXChunk = minXChunk;
|
||||||
|
this.maxXChunk = maxXChunk;
|
||||||
|
this.minZChunk = minZChunk;
|
||||||
|
this.maxZChunk = maxZChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeletedIslandDO(Island island) {
|
||||||
|
uniqueId = Util.getStringLocation(island.getCenter());
|
||||||
|
world = island.getCenter().getWorld();
|
||||||
|
minXChunk = island.getMinX() >> 4;
|
||||||
|
maxXChunk = (island.getRange() * 2 + island.getMinX() - 1) >> 4;
|
||||||
|
minZChunk = island.getMinZ() >> 4;
|
||||||
|
maxZChunk = (island.getRange() * 2 + island.getMinZ() - 1) >> 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUniqueId() {
|
||||||
|
return uniqueId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUniqueId(String uniqueId) {
|
||||||
|
this.uniqueId = uniqueId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the world
|
||||||
|
*/
|
||||||
|
public World getWorld() {
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the minXChunk
|
||||||
|
*/
|
||||||
|
public int getMinXChunk() {
|
||||||
|
return minXChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the maxXChunk
|
||||||
|
*/
|
||||||
|
public int getMaxXChunk() {
|
||||||
|
return maxXChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the minZChunk
|
||||||
|
*/
|
||||||
|
public int getMinZChunk() {
|
||||||
|
return minZChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the maxZChunk
|
||||||
|
*/
|
||||||
|
public int getMaxZChunk() {
|
||||||
|
return maxZChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param world the world to set
|
||||||
|
*/
|
||||||
|
public void setWorld(World world) {
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param minXChunk the minXChunk to set
|
||||||
|
*/
|
||||||
|
public void setMinXChunk(int minXChunk) {
|
||||||
|
this.minXChunk = minXChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param maxXChunk the maxXChunk to set
|
||||||
|
*/
|
||||||
|
public void setMaxXChunk(int maxXChunk) {
|
||||||
|
this.maxXChunk = maxXChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param minZChunk the minZChunk to set
|
||||||
|
*/
|
||||||
|
public void setMinZChunk(int minZChunk) {
|
||||||
|
this.minZChunk = minZChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param maxZChunk the maxZChunk to set
|
||||||
|
*/
|
||||||
|
public void setMaxZChunk(int maxZChunk) {
|
||||||
|
this.maxZChunk = maxZChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#hashCode()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#equals(java.lang.Object)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!(obj instanceof DeletedIslandDO)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
DeletedIslandDO other = (DeletedIslandDO) obj;
|
||||||
|
if (uniqueId == null) {
|
||||||
|
if (other.uniqueId != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!uniqueId.equals(other.uniqueId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -24,9 +24,13 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||||
|
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||||
|
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.Database;
|
import world.bentobox.bentobox.database.Database;
|
||||||
|
import world.bentobox.bentobox.database.objects.DeletedIslandDO;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.lists.Flags;
|
import world.bentobox.bentobox.lists.Flags;
|
||||||
import world.bentobox.bentobox.managers.island.IslandCache;
|
import world.bentobox.bentobox.managers.island.IslandCache;
|
||||||
@ -244,6 +248,11 @@ public class IslandsManager {
|
|||||||
if (island == null) {
|
if (island == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Fire event
|
||||||
|
IslandBaseEvent event = IslandEvent.builder().island(island).reason(Reason.DELETE).build();
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Set the owner of the island to no one.
|
// Set the owner of the island to no one.
|
||||||
island.setOwner(null);
|
island.setOwner(null);
|
||||||
island.setFlag(Flags.LOCK, RanksManager.VISITOR_RANK);
|
island.setFlag(Flags.LOCK, RanksManager.VISITOR_RANK);
|
||||||
@ -255,7 +264,7 @@ public class IslandsManager {
|
|||||||
// Remove players from island
|
// Remove players from island
|
||||||
removePlayersFromIsland(island);
|
removePlayersFromIsland(island);
|
||||||
// Remove blocks from world
|
// Remove blocks from world
|
||||||
new DeleteIslandChunks(plugin, island);
|
new DeleteIslandChunks(plugin, new DeletedIslandDO(island));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package world.bentobox.bentobox.util;
|
package world.bentobox.bentobox.util;
|
||||||
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||||
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
|
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.DeletedIslandDO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes islands fast using chunk regeneration
|
* Deletes islands fast using chunk regeneration
|
||||||
@ -16,42 +16,34 @@ import world.bentobox.bentobox.database.objects.Island;
|
|||||||
*/
|
*/
|
||||||
public class DeleteIslandChunks {
|
public class DeleteIslandChunks {
|
||||||
|
|
||||||
/**
|
private int x;
|
||||||
* Deletes the island
|
private int z;
|
||||||
* @param plugin - plugin object
|
private BukkitTask task;
|
||||||
* @param island - island to delete
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public DeleteIslandChunks(final BentoBox plugin, final Island island) {
|
|
||||||
// Fire event
|
|
||||||
IslandBaseEvent event = IslandEvent.builder().island(island).reason(Reason.DELETE).build();
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final World world = island.getCenter().getWorld();
|
|
||||||
if (world == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int minXChunk = island.getMinX() >> 4;
|
|
||||||
int maxXChunk = (island.getRange() * 2 + island.getMinX() - 1) >> 4;
|
|
||||||
int minZChunk = island.getMinZ() >> 4;
|
|
||||||
int maxZChunk = (island.getRange() * 2 + island.getMinZ() - 1) >> 4;
|
|
||||||
for (int x = minXChunk; x <= maxXChunk; x++) {
|
|
||||||
for (int z = minZChunk; z<=maxZChunk; z++) {
|
|
||||||
world.regenerateChunk(x, z);
|
|
||||||
//System.out.println("regenerating = " + x + "," + z);
|
|
||||||
if (plugin.getIWM().isNetherGenerate(world) && plugin.getIWM().isNetherIslands(world)) {
|
|
||||||
plugin.getIWM().getNetherWorld(world).regenerateChunk(x, z);
|
|
||||||
|
|
||||||
}
|
@SuppressWarnings("deprecation")
|
||||||
if (plugin.getIWM().isEndGenerate(world) && plugin.getIWM().isEndIslands(world)) {
|
public DeleteIslandChunks(BentoBox plugin, DeletedIslandDO di) {
|
||||||
plugin.getIWM().getEndWorld(world).regenerateChunk(x, z);
|
x = di.getMinXChunk();
|
||||||
|
z = di.getMinZChunk();
|
||||||
|
task = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||||
|
di.getWorld().regenerateChunk(x, z);
|
||||||
|
//System.out.println("regenerating = " + x + "," + z);
|
||||||
|
if (plugin.getIWM().isNetherGenerate(di.getWorld()) && plugin.getIWM().isNetherIslands(di.getWorld())) {
|
||||||
|
plugin.getIWM().getNetherWorld(di.getWorld()).regenerateChunk(x, z);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (plugin.getIWM().isEndGenerate(di.getWorld()) && plugin.getIWM().isEndIslands(di.getWorld())) {
|
||||||
|
plugin.getIWM().getEndWorld(di.getWorld()).regenerateChunk(x, z);
|
||||||
|
}
|
||||||
|
z++;
|
||||||
|
if (z > di.getMaxZChunk()) {
|
||||||
|
z = di.getMinZChunk();
|
||||||
|
x++;
|
||||||
|
if (x > di.getMaxXChunk()) {
|
||||||
|
task.cancel();
|
||||||
|
// Fire event
|
||||||
|
IslandEvent.builder().location(Util.getLocationString(di.getUniqueId())).reason(Reason.DELETED).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}, 0L, 1L);
|
||||||
// Fire event
|
|
||||||
IslandEvent.builder().island(island).reason(Reason.DELETED).build();
|
|
||||||
|
|
||||||
}
|
}}
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user