mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 02:04:44 +02:00
Merge branch 'v6' into feature/v6/json. It builds!
# Conflicts: # Bukkit/build.gradle # Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java # Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java # Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java # Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java # Bukkit/src/main/java/com/plotsquared/bukkit/queue/ChunkCoordinator.java # Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java # Core/src/main/java/com/plotsquared/core/PlotSquared.java # Core/src/main/java/com/plotsquared/core/command/Area.java # Core/src/main/java/com/plotsquared/core/command/Clear.java # Core/src/main/java/com/plotsquared/core/command/Debug.java # Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java # Core/src/main/java/com/plotsquared/core/command/Relight.java # Core/src/main/java/com/plotsquared/core/command/Set.java # Core/src/main/java/com/plotsquared/core/command/Template.java # Core/src/main/java/com/plotsquared/core/command/Trim.java # Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java # Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java # Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java # Core/src/main/java/com/plotsquared/core/plot/Plot.java # Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java # Core/src/main/java/com/plotsquared/core/queue/AreaBoundDelegateQueueCoordinator.java # Core/src/main/java/com/plotsquared/core/queue/ChunkQueueCoordinator.java # Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java # Core/src/main/java/com/plotsquared/core/util/ChunkUtil.java # Core/src/main/java/com/plotsquared/core/util/EntityUtil.java # Core/src/main/java/com/plotsquared/core/util/RegionManager.java # Core/src/main/java/com/plotsquared/core/util/WorldUtil.java # Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java # build.gradle
This commit is contained in:
@ -2,6 +2,7 @@ plugins {
|
||||
id "com.github.johnrengelman.shadow"
|
||||
}
|
||||
repositories {
|
||||
mavenLocal()
|
||||
maven { url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }
|
||||
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||
maven { url = "https://jitpack.io" }
|
||||
@ -15,7 +16,7 @@ repositories {
|
||||
maven { url = "https://mvn.intellectualsites.com/content/repositories/snapshots" }
|
||||
maven { url = "https://repo.wea-ondara.net/repository/public/" }
|
||||
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||
mavenLocal()
|
||||
maven { url = "http://repo.mvdw-software.be/content/groups/public/" }
|
||||
}
|
||||
|
||||
|
||||
@ -25,7 +26,7 @@ dependencies {
|
||||
compile(project(":PlotSquared-Core"))
|
||||
compile("com.destroystokyo.paper:paper-api:1.16.1-R0.1-SNAPSHOT")
|
||||
implementation("org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT")
|
||||
compile(group: "com.sk89q.worldedit", name: "worldedit-bukkit", version: "7.1.0") {
|
||||
compile(group: "com.sk89q.worldedit", name: "worldedit-bukkit", version: "7.2.0-SNAPSHOT") {
|
||||
exclude(module: "bukkit")
|
||||
|
||||
}
|
||||
@ -44,8 +45,10 @@ dependencies {
|
||||
implementation('net.kyori:adventure-text-minimessage:3.0.0-SNAPSHOT')
|
||||
compile("se.hyperver.hyperverse:Core:0.6.0-SNAPSHOT"){ transitive = false }
|
||||
compile('com.sk89q:squirrelid:1.0.0-SNAPSHOT'){ transitive = false }
|
||||
compile('be.maximvdw:MVdWPlaceholderAPI:2.1.1-SNAPSHOT'){ transitive = false }
|
||||
// logging
|
||||
implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.8.1')
|
||||
compile('be.maximvdw:MVdWPlaceholderAPI:3.1.1-SNAPSHOT'){ transitive = false }
|
||||
}
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
|
@ -27,7 +27,7 @@
|
||||
<dependency>
|
||||
<groupId>com.plotsquared</groupId>
|
||||
<artifactId>PlotSquared-Core</artifactId>
|
||||
<version>5.12.5</version>
|
||||
<version>6.0.0-SUPER-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -39,7 +39,7 @@
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<version>7.1.0</version>
|
||||
<version>7.2.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
@ -90,10 +90,22 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>be.maximvdw</groupId>
|
||||
<artifactId>MVdWPlaceholderAPI</artifactId>
|
||||
<version>3.1.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>*</artifactId>
|
||||
<groupId>*</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-core</artifactId>
|
||||
<version>7.0.0</version>
|
||||
<version>7.2.0-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
@ -110,30 +122,6 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>text-api</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>text-serializer-gson</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>text-serializer-legacy</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>text-serializer-plain</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
@ -182,6 +170,18 @@
|
||||
<version>4.0-dev-106</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
|
@ -36,15 +36,19 @@ import com.plotsquared.bukkit.inject.BackupModule;
|
||||
import com.plotsquared.bukkit.inject.BukkitModule;
|
||||
import com.plotsquared.bukkit.inject.PermissionModule;
|
||||
import com.plotsquared.bukkit.inject.WorldManagerModule;
|
||||
import com.plotsquared.bukkit.listener.BlockEventListener;
|
||||
import com.plotsquared.bukkit.listener.ChunkListener;
|
||||
import com.plotsquared.bukkit.listener.EntityEventListener;
|
||||
import com.plotsquared.bukkit.listener.EntitySpawnListener;
|
||||
import com.plotsquared.bukkit.listener.PaperListener;
|
||||
import com.plotsquared.bukkit.listener.PlayerEvents;
|
||||
import com.plotsquared.bukkit.listener.PlayerEventListener;
|
||||
import com.plotsquared.bukkit.listener.ProjectileEventListener;
|
||||
import com.plotsquared.bukkit.listener.ServerListener;
|
||||
import com.plotsquared.bukkit.listener.SingleWorldListener;
|
||||
import com.plotsquared.bukkit.listener.WorldEvents;
|
||||
import com.plotsquared.bukkit.placeholder.PlaceholderFormatter;
|
||||
import com.plotsquared.bukkit.placeholder.Placeholders;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||
import com.plotsquared.bukkit.placeholder.PAPIPlaceholders;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
||||
import com.plotsquared.bukkit.util.task.BukkitTaskManager;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
@ -94,7 +98,6 @@ import com.plotsquared.core.plot.flag.implementations.ServerPlotFlag;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.plot.world.SinglePlotArea;
|
||||
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
|
||||
import com.plotsquared.core.queue.GlobalBlockQueue;
|
||||
import com.plotsquared.core.setup.PlotAreaBuilder;
|
||||
import com.plotsquared.core.setup.SettingsNodesWrapper;
|
||||
import com.plotsquared.core.util.ConsoleColors;
|
||||
@ -160,7 +163,8 @@ import static com.plotsquared.core.util.PremiumVerification.getResourceID;
|
||||
import static com.plotsquared.core.util.PremiumVerification.getUserID;
|
||||
import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
|
||||
@SuppressWarnings("unused") public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPlatform<Player> {
|
||||
@SuppressWarnings("unused")
|
||||
public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPlatform<Player> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitPlatform.class.getSimpleName());
|
||||
private static final int BSTATS_ID = 1404;
|
||||
@ -233,10 +237,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
final PlotSquared plotSquared = new PlotSquared(this, "Bukkit");
|
||||
|
||||
if (PlotSquared.platform().getServerVersion()[1] < 13) {
|
||||
System.out.println(
|
||||
"You can't use this version of PlotSquared on a server less than Minecraft 1.13.2.");
|
||||
System.out
|
||||
.println("Please check the download page for the link to the legacy versions.");
|
||||
System.out.println("You can't use this version of PlotSquared on a server less than Minecraft 1.13.2.");
|
||||
System.out.println("Please check the download page for the link to the legacy versions.");
|
||||
System.out.println("The server will now be shutdown to prevent any corruption.");
|
||||
Bukkit.shutdown();
|
||||
return;
|
||||
@ -244,11 +246,9 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
|
||||
// We create the injector after PlotSquared has been initialized, so that we have access
|
||||
// to generated instances and settings
|
||||
this.injector = Guice.createInjector(Stage.PRODUCTION, new PermissionModule(),
|
||||
new WorldManagerModule(),
|
||||
new PlotSquaredModule(),
|
||||
new BukkitModule(this),
|
||||
new BackupModule());
|
||||
this.injector = Guice
|
||||
.createInjector(Stage.PRODUCTION, new PermissionModule(), new WorldManagerModule(), new PlotSquaredModule(), new BukkitModule(this),
|
||||
new BackupModule());
|
||||
this.injector.injectMembers(this);
|
||||
|
||||
this.serverLocale = Locale.forLanguageTag(Settings.Enabled_Components.DEFAULT_LOCALE);
|
||||
@ -292,8 +292,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
|
||||
// Do stuff that was previously done in PlotSquared
|
||||
// Kill entities
|
||||
if (Settings.Enabled_Components.KILL_ROAD_MOBS
|
||||
|| Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
||||
if (Settings.Enabled_Components.KILL_ROAD_MOBS || Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
||||
this.runEntityTask();
|
||||
}
|
||||
|
||||
@ -311,7 +310,11 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
}
|
||||
|
||||
if (Settings.Enabled_Components.EVENTS) {
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(PlayerEvents.class), this);
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(PlayerEventListener.class), this);
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(BlockEventListener.class), this);
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(EntityEventListener.class), this);
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(ProjectileEventListener.class), this);
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(ServerListener.class), this);
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(EntitySpawnListener.class), this);
|
||||
if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) {
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(PaperListener.class), this);
|
||||
@ -325,10 +328,6 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(ChunkListener.class), this);
|
||||
}
|
||||
|
||||
// Start the global block queue
|
||||
final GlobalBlockQueue globalBlockQueue = this.injector.getInstance(GlobalBlockQueue.class);
|
||||
globalBlockQueue.runTask();
|
||||
|
||||
// Commands
|
||||
if (Settings.Enabled_Components.COMMANDS) {
|
||||
this.registerCommands();
|
||||
@ -372,9 +371,9 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
continue;
|
||||
}
|
||||
if (!worldUtil.isWorld(world) && !world.equals("*")) {
|
||||
logger.warn("[P2] `{}` was not properly loaded - {} will now try to load it properly",
|
||||
world, this.getPluginName());
|
||||
logger.warn("[P2] - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml");
|
||||
logger.warn("[P2] `{}` was not properly loaded - {} will now try to load it properly", world, this.getPluginName());
|
||||
logger.warn(
|
||||
"[P2] - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml");
|
||||
logger.warn("[P2] - Your world management plugin may be faulty (or non existent)");
|
||||
logger.warn("[P2] This message may also be a false positive and could be ignored.");
|
||||
this.setGenerator(world);
|
||||
@ -408,16 +407,14 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
final SQLiteUUIDService sqLiteUUIDService = new SQLiteUUIDService("user_cache.db");
|
||||
|
||||
final SQLiteUUIDService legacyUUIDService;
|
||||
if (Settings.UUID.LEGACY_DATABASE_SUPPORT &&
|
||||
FileUtils.getFile(PlotSquared.platform().getDirectory(), "usercache.db").exists()) {
|
||||
if (Settings.UUID.LEGACY_DATABASE_SUPPORT && FileUtils.getFile(PlotSquared.platform().getDirectory(), "usercache.db").exists()) {
|
||||
legacyUUIDService = new SQLiteUUIDService("usercache.db");
|
||||
} else {
|
||||
legacyUUIDService = null;
|
||||
}
|
||||
|
||||
final LuckPermsUUIDService luckPermsUUIDService;
|
||||
if (Settings.UUID.SERVICE_LUCKPERMS &&
|
||||
Bukkit.getPluginManager().getPlugin("LuckPerms") != null) {
|
||||
if (Settings.UUID.SERVICE_LUCKPERMS && Bukkit.getPluginManager().getPlugin("LuckPerms") != null) {
|
||||
luckPermsUUIDService = new LuckPermsUUIDService();
|
||||
logger.info("[P2] (UUID) Using LuckPerms as a complementary UUID service");
|
||||
} else {
|
||||
@ -425,8 +422,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
}
|
||||
|
||||
final BungeePermsUUIDService bungeePermsUUIDService;
|
||||
if (Settings.UUID.SERVICE_BUNGEE_PERMS &&
|
||||
Bukkit.getPluginManager().getPlugin("BungeePerms") != null) {
|
||||
if (Settings.UUID.SERVICE_BUNGEE_PERMS && Bukkit.getPluginManager().getPlugin("BungeePerms") != null) {
|
||||
bungeePermsUUIDService = new BungeePermsUUIDService();
|
||||
logger.info("[P2] (UUID) Using BungeePerms as a complementary UUID service");
|
||||
} else {
|
||||
@ -474,11 +470,9 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
this.backgroundPipeline.registerService(essentialsUUIDService);
|
||||
}
|
||||
|
||||
final SquirrelIdUUIDService impromptuMojangService =
|
||||
new SquirrelIdUUIDService(Settings.UUID.IMPROMPTU_LIMIT);
|
||||
final SquirrelIdUUIDService impromptuMojangService = new SquirrelIdUUIDService(Settings.UUID.IMPROMPTU_LIMIT);
|
||||
this.impromptuPipeline.registerService(impromptuMojangService);
|
||||
final SquirrelIdUUIDService backgroundMojangService =
|
||||
new SquirrelIdUUIDService(Settings.UUID.BACKGROUND_LIMIT);
|
||||
final SquirrelIdUUIDService backgroundMojangService = new SquirrelIdUUIDService(Settings.UUID.BACKGROUND_LIMIT);
|
||||
this.backgroundPipeline.registerService(backgroundMojangService);
|
||||
} else {
|
||||
this.impromptuPipeline.registerService(sqLiteUUIDService);
|
||||
@ -499,7 +493,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
injector.getInstance(Placeholders.class).register();
|
||||
injector.getInstance(PAPIPlaceholders.class).register();
|
||||
if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) {
|
||||
ChatFormatter.formatters.add(getInjector().getInstance(PlaceholderFormatter.class));
|
||||
}
|
||||
@ -537,8 +531,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
this.methodUnloadSetup = true;
|
||||
try {
|
||||
ReflectionUtils.RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
|
||||
this.methodUnloadChunk0 = classCraftWorld.getRealClass()
|
||||
.getDeclaredMethod("unloadChunk0", int.class, int.class, boolean.class);
|
||||
this.methodUnloadChunk0 = classCraftWorld.getRealClass().getDeclaredMethod("unloadChunk0", int.class, int.class, boolean.class);
|
||||
this.methodUnloadChunk0.setAccessible(true);
|
||||
} catch (Throwable event) {
|
||||
event.printStackTrace();
|
||||
@ -569,8 +562,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
}
|
||||
final Plot plot = area.getOwnedPlot(id);
|
||||
if (plot != null) {
|
||||
if (!plot.getFlag(ServerPlotFlag.class) || PlotSquared.platform().getPlayerManager()
|
||||
.getPlayerIfExists(plot.getOwner()) == null) {
|
||||
if (!plot.getFlag(ServerPlotFlag.class) || PlotSquared.platform().getPlayerManager().getPlayerIfExists(plot.getOwner()) == null) {
|
||||
if (world.getKeepSpawnInMemory()) {
|
||||
world.setKeepSpawnInMemory(false);
|
||||
return;
|
||||
@ -588,8 +580,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
boolean result;
|
||||
if (methodUnloadChunk0 != null) {
|
||||
try {
|
||||
result = (boolean) methodUnloadChunk0
|
||||
.invoke(world, chunkI.getX(), chunkI.getZ(), true);
|
||||
result = (boolean) methodUnloadChunk0.invoke(world, chunkI.getX(), chunkI.getZ(), true);
|
||||
} catch (Throwable e) {
|
||||
methodUnloadChunk0 = null;
|
||||
e.printStackTrace();
|
||||
@ -612,8 +603,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
}
|
||||
}
|
||||
|
||||
private void startUuidCaching(@Nonnull final SQLiteUUIDService sqLiteUUIDService,
|
||||
@Nonnull final CacheUUIDService cacheUUIDService) {
|
||||
private void startUuidCaching(@Nonnull final SQLiteUUIDService sqLiteUUIDService, @Nonnull final CacheUUIDService cacheUUIDService) {
|
||||
// Load all uuids into a big chunky boi queue
|
||||
final Queue<UUID> uuidQueue = new LinkedBlockingQueue<>();
|
||||
PlotSquared.get().forEachPlotRaw(plot -> {
|
||||
@ -653,8 +643,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
// fresh batch
|
||||
secondRun = false;
|
||||
// Populate the request list
|
||||
for (int i = 0;
|
||||
i < Settings.UUID.BACKGROUND_LIMIT && !uuidQueue.isEmpty(); i++) {
|
||||
for (int i = 0; i < Settings.UUID.BACKGROUND_LIMIT && !uuidQueue.isEmpty(); i++) {
|
||||
uuidList.add(uuidQueue.poll());
|
||||
read++;
|
||||
}
|
||||
@ -760,8 +749,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
case "MINECART_TNT":
|
||||
case "BOAT":
|
||||
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
||||
com.plotsquared.core.location.Location location =
|
||||
BukkitUtil.adapt(entity.getLocation());
|
||||
com.plotsquared.core.location.Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
Plot plot = location.getPlot();
|
||||
if (plot == null) {
|
||||
if (location.isPlotArea()) {
|
||||
@ -791,9 +779,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
case "FIREBALL":
|
||||
case "DRAGON_FIREBALL":
|
||||
case "DROPPED_ITEM":
|
||||
if (Settings.Enabled_Components.KILL_ROAD_ITEMS && plotArea
|
||||
.getOwnedPlotAbs(BukkitUtil.adapt(entity.getLocation()))
|
||||
== null) {
|
||||
if (Settings.Enabled_Components.KILL_ROAD_ITEMS
|
||||
&& plotArea.getOwnedPlotAbs(BukkitUtil.adapt(entity.getLocation())) == null) {
|
||||
entity.remove();
|
||||
}
|
||||
// dropped item
|
||||
@ -817,15 +804,12 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
|
||||
PlotId originalPlotId = (PlotId) meta.get(0).value();
|
||||
if (originalPlotId != null) {
|
||||
com.plotsquared.core.location.Location pLoc =
|
||||
BukkitUtil.adapt(entity.getLocation());
|
||||
com.plotsquared.core.location.Location pLoc = BukkitUtil.adapt(entity.getLocation());
|
||||
PlotArea area = pLoc.getPlotArea();
|
||||
if (area != null) {
|
||||
PlotId currentPlotId = area.getPlotAbs(pLoc).getId();
|
||||
if (!originalPlotId.equals(currentPlotId) && (
|
||||
currentPlotId == null || !area
|
||||
.getPlot(originalPlotId)
|
||||
.equals(area.getPlot(currentPlotId)))) {
|
||||
if (!originalPlotId.equals(currentPlotId) && (currentPlotId == null || !area.getPlot(originalPlotId)
|
||||
.equals(area.getPlot(currentPlotId)))) {
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
@ -836,15 +820,12 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
}
|
||||
} else {
|
||||
//This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java)
|
||||
com.plotsquared.core.location.Location pLoc =
|
||||
BukkitUtil.adapt(entity.getLocation());
|
||||
com.plotsquared.core.location.Location pLoc = BukkitUtil.adapt(entity.getLocation());
|
||||
PlotArea area = pLoc.getPlotArea();
|
||||
if (area != null) {
|
||||
PlotId currentPlotId = area.getPlotAbs(pLoc).getId();
|
||||
if (currentPlotId != null) {
|
||||
entity.setMetadata("shulkerPlot",
|
||||
new FixedMetadataValue(
|
||||
(Plugin) PlotSquared.platform(), currentPlotId));
|
||||
entity.setMetadata("shulkerPlot", new FixedMetadataValue((Plugin) PlotSquared.platform(), currentPlotId));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -925,11 +906,9 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
if (BukkitUtil.adapt(location).isPlotRoad()) {
|
||||
if (entity instanceof LivingEntity) {
|
||||
LivingEntity livingEntity = (LivingEntity) entity;
|
||||
if (!livingEntity.isLeashed() || !entity
|
||||
.hasMetadata("keep")) {
|
||||
if (!livingEntity.isLeashed() || !entity.hasMetadata("keep")) {
|
||||
Entity passenger = entity.getPassenger();
|
||||
if (!(passenger instanceof Player) && entity
|
||||
.getMetadata("keep").isEmpty()) {
|
||||
if (!(passenger instanceof Player) && entity.getMetadata("keep").isEmpty()) {
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
@ -940,8 +919,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
}
|
||||
} else {
|
||||
Entity passenger = entity.getPassenger();
|
||||
if (!(passenger instanceof Player) && entity
|
||||
.getMetadata("keep").isEmpty()) {
|
||||
if (!(passenger instanceof Player) && entity.getMetadata("keep").isEmpty()) {
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
@ -962,9 +940,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
}), TaskTime.seconds(1L));
|
||||
}
|
||||
|
||||
@Override @Nullable
|
||||
public final ChunkGenerator getDefaultWorldGenerator(@Nonnull final String worldName,
|
||||
final String id) {
|
||||
@Override @Nullable public final ChunkGenerator getDefaultWorldGenerator(@Nonnull final String worldName, final String id) {
|
||||
final IndependentPlotGenerator result;
|
||||
if (id != null && id.equalsIgnoreCase("single")) {
|
||||
result = getInjector().getInstance(SingleWorldGenerator.class);
|
||||
@ -977,8 +953,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
return (ChunkGenerator) result.specify(worldName);
|
||||
}
|
||||
|
||||
@Override @Nullable public GeneratorWrapper<?> getGenerator(@Nonnull final String world,
|
||||
@Nullable final String name) {
|
||||
@Override @Nullable public GeneratorWrapper<?> getGenerator(@Nonnull final String world, @Nullable final String name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
@ -990,8 +965,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
}
|
||||
return new BukkitPlotGenerator(world, gen, this.plotAreaManager);
|
||||
} else {
|
||||
return new BukkitPlotGenerator(world, getInjector()
|
||||
.getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class)), this.plotAreaManager);
|
||||
return new BukkitPlotGenerator(world, getInjector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class)),
|
||||
this.plotAreaManager);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1011,19 +986,14 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
map.put(plotAreaType.name().toLowerCase(), terrainTypes);
|
||||
}
|
||||
for (final PlotArea plotArea : this.plotAreaManager.getAllPlotAreas()) {
|
||||
final Map<String, Integer> terrainTypeMap =
|
||||
map.get(plotArea.getType().name().toLowerCase());
|
||||
terrainTypeMap.put(plotArea.getTerrain().name().toLowerCase(),
|
||||
terrainTypeMap.get(plotArea.getTerrain().name().toLowerCase()) + 1);
|
||||
final Map<String, Integer> terrainTypeMap = map.get(plotArea.getType().name().toLowerCase());
|
||||
terrainTypeMap.put(plotArea.getTerrain().name().toLowerCase(), terrainTypeMap.get(plotArea.getTerrain().name().toLowerCase()) + 1);
|
||||
}
|
||||
return map;
|
||||
}));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("premium",
|
||||
() -> PremiumVerification.isPremium() ? "Premium" : "Non-Premium"));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("premium", () -> PremiumVerification.isPremium() ? "Premium" : "Non-Premium"));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("worldedit_implementation",
|
||||
() -> Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null ?
|
||||
"FastAsyncWorldEdit" :
|
||||
"WorldEdit"));
|
||||
() -> Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null ? "FastAsyncWorldEdit" : "WorldEdit"));
|
||||
}
|
||||
|
||||
@Override public void unregister(@Nonnull final PlotPlayer<?> player) {
|
||||
@ -1036,12 +1006,10 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
// create world
|
||||
ConfigurationSection worldConfig = this.worldConfiguration.getConfigurationSection("worlds." + worldName);
|
||||
String manager = worldConfig.getString("generator.plugin", getPluginName());
|
||||
PlotAreaBuilder builder = PlotAreaBuilder.newBuilder().plotManager(manager)
|
||||
.generatorName(worldConfig.getString("generator.init", manager))
|
||||
.plotAreaType(ConfigurationUtil.getType(worldConfig))
|
||||
.terrainType(ConfigurationUtil.getTerrain(worldConfig))
|
||||
.settingsNodesWrapper(new SettingsNodesWrapper(new ConfigurationNode[0], null))
|
||||
.worldName(worldName);
|
||||
PlotAreaBuilder builder =
|
||||
PlotAreaBuilder.newBuilder().plotManager(manager).generatorName(worldConfig.getString("generator.init", manager))
|
||||
.plotAreaType(ConfigurationUtil.getType(worldConfig)).terrainType(ConfigurationUtil.getTerrain(worldConfig))
|
||||
.settingsNodesWrapper(new SettingsNodesWrapper(new ConfigurationNode[0], null)).worldName(worldName);
|
||||
getInjector().getInstance(SetupUtils.class).setupWorld(builder);
|
||||
world = Bukkit.getWorld(worldName);
|
||||
} else {
|
||||
@ -1071,16 +1039,14 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
return name.substring(name.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
@Override public GeneratorWrapper<?> wrapPlotGenerator(@Nullable final String world,
|
||||
@Nonnull final IndependentPlotGenerator generator) {
|
||||
@Override public GeneratorWrapper<?> wrapPlotGenerator(@Nullable final String world, @Nonnull final IndependentPlotGenerator generator) {
|
||||
return new BukkitPlotGenerator(world, generator, this.plotAreaManager);
|
||||
}
|
||||
|
||||
@Override public List<Map.Entry<Map.Entry<String, String>, Boolean>> getPluginIds() {
|
||||
List<Map.Entry<Map.Entry<String, String>, Boolean>> names = new ArrayList<>();
|
||||
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
Map.Entry<String, String> id = new AbstractMap.SimpleEntry<>(plugin.getName(),
|
||||
plugin.getDescription().getVersion());
|
||||
Map.Entry<String, String> id = new AbstractMap.SimpleEntry<>(plugin.getName(), plugin.getDescription().getVersion());
|
||||
names.add(new AbstractMap.SimpleEntry<>(id, plugin.isEnabled()));
|
||||
}
|
||||
return names;
|
||||
@ -1115,11 +1081,11 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
}
|
||||
|
||||
@Override @Nonnull public PlatformWorldManager<?> getWorldManager() {
|
||||
return getInjector().getInstance(Key.get(new TypeLiteral<PlatformWorldManager<World>>() {}));
|
||||
return getInjector().getInstance(Key.get(new TypeLiteral<PlatformWorldManager<World>>() {
|
||||
}));
|
||||
}
|
||||
|
||||
@Override @Nonnull @SuppressWarnings("ALL")
|
||||
public PlayerManager<? extends PlotPlayer<Player>, ? extends Player> getPlayerManager() {
|
||||
@Override @Nonnull @SuppressWarnings("ALL") public PlayerManager<? extends PlotPlayer<Player>, ? extends Player> getPlayerManager() {
|
||||
return (PlayerManager<BukkitPlayer, Player>) getInjector().getInstance(PlayerManager.class);
|
||||
}
|
||||
|
||||
|
@ -30,8 +30,9 @@ import com.plotsquared.core.generator.IndependentPlotGenerator;
|
||||
import com.plotsquared.core.location.ChunkWrapper;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.queue.LocalBlockQueue;
|
||||
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.queue.ScopedQueueCoordinator;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
@ -44,30 +45,25 @@ final class BlockStatePopulator extends BlockPopulator {
|
||||
private final IndependentPlotGenerator plotGenerator;
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
|
||||
private LocalBlockQueue queue;
|
||||
private QueueCoordinator queue;
|
||||
|
||||
public BlockStatePopulator(@Nonnull final IndependentPlotGenerator plotGenerator,
|
||||
@Nonnull final PlotAreaManager plotAreaManager) {
|
||||
public BlockStatePopulator(@Nonnull final IndependentPlotGenerator plotGenerator, @Nonnull final PlotAreaManager plotAreaManager) {
|
||||
this.plotGenerator = plotGenerator;
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(@Nonnull final World world, @Nonnull final Random random,
|
||||
@Nonnull final Chunk source) {
|
||||
@Override public void populate(@Nonnull final World world, @Nonnull final Random random, @Nonnull final Chunk source) {
|
||||
if (this.queue == null) {
|
||||
this.queue = PlotSquared.platform().getGlobalBlockQueue()
|
||||
.getNewQueue(world.getName(), false);
|
||||
this.queue = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(new BukkitWorld(world));
|
||||
}
|
||||
final PlotArea area = this.plotAreaManager.getPlotArea(world.getName(), null);
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
final ChunkWrapper wrap =
|
||||
new ChunkWrapper(area.getWorldName(), source.getX(), source.getZ());
|
||||
final ScopedLocalBlockQueue chunk = this.queue.getForChunk(wrap.x, wrap.z);
|
||||
final ChunkWrapper wrap = new ChunkWrapper(area.getWorldName(), source.getX(), source.getZ());
|
||||
final ScopedQueueCoordinator chunk = this.queue.getForChunk(wrap.x, wrap.z);
|
||||
if (this.plotGenerator.populateChunk(chunk, area)) {
|
||||
this.queue.flush();
|
||||
this.queue.enqueue();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ import com.plotsquared.core.generator.SingleWorldGenerator;
|
||||
import com.plotsquared.core.location.ChunkWrapper;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
|
||||
import com.plotsquared.core.queue.ScopedQueueCoordinator;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import org.bukkit.World;
|
||||
@ -62,7 +62,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
|
||||
private final String levelName;
|
||||
|
||||
public BukkitPlotGenerator(@Nonnull final String name,
|
||||
public BukkitPlotGenerator(@Nonnull final String name,
|
||||
@Nonnull final IndependentPlotGenerator generator,
|
||||
@Nonnull final PlotAreaManager plotAreaManager) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
@ -186,7 +186,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
return result.getChunkData();
|
||||
}
|
||||
|
||||
private void generate(BlockVector2 loc, World world, ScopedLocalBlockQueue result) {
|
||||
private void generate(BlockVector2 loc, World world, ScopedQueueCoordinator result) {
|
||||
// Load if improperly loaded
|
||||
if (!this.loaded) {
|
||||
String name = world.getName();
|
||||
|
@ -31,7 +31,7 @@ import com.plotsquared.core.generator.IndependentPlotGenerator;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
|
||||
import com.plotsquared.core.queue.ScopedQueueCoordinator;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import org.bukkit.World;
|
||||
@ -63,7 +63,7 @@ final class DelegatePlotGenerator extends IndependentPlotGenerator {
|
||||
return PlotSquared.platform().getDefaultGenerator().getNewPlotArea(world, id, min, max);
|
||||
}
|
||||
|
||||
@Override public void generateChunk(final ScopedLocalBlockQueue result, PlotArea settings) {
|
||||
@Override public void generateChunk(final ScopedQueueCoordinator result, PlotArea settings) {
|
||||
World world = BukkitUtil.getWorld(this.world);
|
||||
Location min = result.getMin();
|
||||
int chunkX = min.getX() >> 4;
|
||||
@ -71,11 +71,7 @@ final class DelegatePlotGenerator extends IndependentPlotGenerator {
|
||||
Random random = new Random(MathMan.pair((short) chunkX, (short) chunkZ));
|
||||
try {
|
||||
ChunkGenerator.BiomeGrid grid = new ChunkGenerator.BiomeGrid() {
|
||||
@Override
|
||||
public void setBiome(
|
||||
final int x,
|
||||
final int z,
|
||||
@Nonnull final Biome biome) {
|
||||
@Override public void setBiome(int x, int z, @Nonnull Biome biome) {
|
||||
result.setBiome(x, z, BukkitAdapter.adapt(biome));
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,8 @@ import com.google.inject.Singleton;
|
||||
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||
import com.plotsquared.bukkit.BukkitPlatform;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
||||
import com.plotsquared.bukkit.queue.BukkitLocalQueue;
|
||||
import com.plotsquared.bukkit.queue.BukkitChunkCoordinator;
|
||||
import com.plotsquared.bukkit.queue.BukkitQueueCoordinator;
|
||||
import com.plotsquared.bukkit.schematic.BukkitSchematicHandler;
|
||||
import com.plotsquared.bukkit.util.BukkitChunkManager;
|
||||
import com.plotsquared.bukkit.util.BukkitEconHandler;
|
||||
@ -45,10 +46,13 @@ import com.plotsquared.core.generator.HybridGen;
|
||||
import com.plotsquared.core.generator.IndependentPlotGenerator;
|
||||
import com.plotsquared.core.inject.annotations.ConsoleActor;
|
||||
import com.plotsquared.core.inject.annotations.DefaultGenerator;
|
||||
import com.plotsquared.core.inject.factory.ChunkCoordinatorBuilderFactory;
|
||||
import com.plotsquared.core.inject.factory.ChunkCoordinatorFactory;
|
||||
import com.plotsquared.core.inject.factory.HybridPlotWorldFactory;
|
||||
import com.plotsquared.core.plot.world.DefaultPlotAreaManager;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
|
||||
import com.plotsquared.core.queue.ChunkCoordinator;
|
||||
import com.plotsquared.core.queue.GlobalBlockQueue;
|
||||
import com.plotsquared.core.queue.QueueProvider;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
@ -88,8 +92,7 @@ public class BukkitModule extends AbstractModule {
|
||||
bind(InventoryUtil.class).to(BukkitInventoryUtil.class);
|
||||
bind(SetupUtils.class).to(BukkitSetupUtils.class);
|
||||
bind(WorldUtil.class).to(BukkitUtil.class);
|
||||
bind(GlobalBlockQueue.class).toInstance(new GlobalBlockQueue(
|
||||
QueueProvider.of(BukkitLocalQueue.class, BukkitLocalQueue.class), 1, Settings.QUEUE.TARGET_TIME));
|
||||
bind(GlobalBlockQueue.class).toInstance(new GlobalBlockQueue(QueueProvider.of(BukkitQueueCoordinator.class)));
|
||||
bind(ChunkManager.class).to(BukkitChunkManager.class);
|
||||
bind(RegionManager.class).to(BukkitRegionManager.class);
|
||||
bind(SchematicHandler.class).to(BukkitSchematicHandler.class);
|
||||
@ -99,6 +102,8 @@ public class BukkitModule extends AbstractModule {
|
||||
bind(PlotAreaManager.class).to(DefaultPlotAreaManager.class);
|
||||
}
|
||||
install(new FactoryModuleBuilder().build(HybridPlotWorldFactory.class));
|
||||
install(new FactoryModuleBuilder().implement(ChunkCoordinator.class, BukkitChunkCoordinator.class).build(ChunkCoordinatorFactory.class));
|
||||
install(new FactoryModuleBuilder().build(ChunkCoordinatorBuilderFactory.class));
|
||||
}
|
||||
|
||||
@Provides @Singleton @Nullable EconHandler provideEconHandler() {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,330 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.flag.implementations.DisablePhysicsFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.ExplosionFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.InvincibleFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.MobPlaceFlag;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.EntityCombustByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.event.vehicle.VehicleCreateEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.inject.Inject;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class EntityEventListener implements Listener {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private float lastRadius;
|
||||
|
||||
@Inject public EntityEventListener(@Nonnull final PlotAreaManager plotAreaManager) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST) public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
|
||||
EntityDamageByEntityEvent eventChange =
|
||||
new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), EntityDamageEvent.DamageCause.FIRE_TICK, event.getDuration());
|
||||
onEntityDamageByEntityEvent(eventChange);
|
||||
if (eventChange.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST) public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
||||
Entity damager = event.getDamager();
|
||||
Location location = BukkitUtil.adapt(damager.getLocation());
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
Entity victim = event.getEntity();
|
||||
/*
|
||||
if (victim.getType().equals(EntityType.ITEM_FRAME)) {
|
||||
Plot plot = BukkitUtil.getLocation(victim).getPlot();
|
||||
if (plot != null && !plot.isAdded(damager.getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
*/
|
||||
if (!BukkitEntityUtil.entityDamage(damager, victim, event.getCause())) {
|
||||
if (event.isCancelled()) {
|
||||
if (victim instanceof Ageable) {
|
||||
Ageable ageable = (Ageable) victim;
|
||||
if (ageable.getAge() == -24000) {
|
||||
ageable.setAge(0);
|
||||
ageable.setAdult();
|
||||
}
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void creatureSpawnEvent(CreatureSpawnEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason();
|
||||
switch (reason.toString()) {
|
||||
case "DISPENSE_EGG":
|
||||
case "EGG":
|
||||
case "OCELOT_BABY":
|
||||
case "SPAWNER_EGG":
|
||||
if (!area.isSpawnEggs()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "REINFORCEMENTS":
|
||||
case "NATURAL":
|
||||
case "MOUNT":
|
||||
case "PATROL":
|
||||
case "RAID":
|
||||
case "SHEARED":
|
||||
case "SHOULDER_ENTITY":
|
||||
case "SILVERFISH_BLOCK":
|
||||
case "TRAP":
|
||||
case "VILLAGE_DEFENSE":
|
||||
case "VILLAGE_INVASION":
|
||||
case "BEEHIVE":
|
||||
case "CHUNK_GEN":
|
||||
if (!area.isMobSpawning()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
case "BREEDING":
|
||||
if (!area.isSpawnBreeding()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "BUILD_IRONGOLEM":
|
||||
case "BUILD_SNOWMAN":
|
||||
case "BUILD_WITHER":
|
||||
case "CUSTOM":
|
||||
if (!area.isSpawnCustom() && entity.getType() != EntityType.ARMOR_STAND) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "SPAWNER":
|
||||
if (!area.isMobSpawnerSpawning()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
Plot plot = area.getOwnedPlotAbs(location);
|
||||
if (plot == null) {
|
||||
if (!area.isMobSpawning()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (BukkitEntityUtil.checkEntity(entity, plot)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onEntityFall(EntityChangeBlockEvent event) {
|
||||
if (event.getEntityType() != EntityType.FALLING_BLOCK) {
|
||||
return;
|
||||
}
|
||||
Block block = event.getBlock();
|
||||
World world = block.getWorld();
|
||||
String worldName = world.getName();
|
||||
if (!this.plotAreaManager.hasPlotArea(worldName)) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlotAbs(location);
|
||||
if (plot == null || plot.getFlag(DisablePhysicsFlag.class)) {
|
||||
event.setCancelled(true);
|
||||
plot.debug("Falling block event was cancelled because disable-physics = true");
|
||||
return;
|
||||
}
|
||||
if (event.getTo().hasGravity()) {
|
||||
Entity entity = event.getEntity();
|
||||
List<MetadataValue> meta = entity.getMetadata("plot");
|
||||
if (meta.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Plot origin = (Plot) meta.get(0).value();
|
||||
if (origin != null && !origin.equals(plot)) {
|
||||
event.setCancelled(true);
|
||||
entity.remove();
|
||||
}
|
||||
} else if (event.getTo() == Material.AIR) {
|
||||
event.getEntity().setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH) public void onDamage(EntityDamageEvent event) {
|
||||
if (event.getEntityType() != EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.adapt(event.getEntity().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot == null) {
|
||||
if (area.isRoadFlags() && area.getRoadFlag(InvincibleFlag.class)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (plot.getFlag(InvincibleFlag.class)) {
|
||||
plot.debug(event.getEntity().getName() + " could not take damage because invincible = true");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBigBoom(EntityExplodeEvent event) {
|
||||
Location location = BukkitUtil.adapt(event.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
boolean plotArea = location.isPlotArea();
|
||||
if (!plotArea) {
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlot(location);
|
||||
if (plot != null) {
|
||||
if (plot.getFlag(ExplosionFlag.class)) {
|
||||
List<MetadataValue> meta = event.getEntity().getMetadata("plot");
|
||||
Plot origin;
|
||||
if (meta.isEmpty()) {
|
||||
origin = plot;
|
||||
} else {
|
||||
origin = (Plot) meta.get(0).value();
|
||||
}
|
||||
if (this.lastRadius != 0) {
|
||||
List<Entity> nearby = event.getEntity().getNearbyEntities(this.lastRadius, this.lastRadius, this.lastRadius);
|
||||
for (Entity near : nearby) {
|
||||
if (near instanceof TNTPrimed || near.getType().equals(EntityType.MINECART_TNT)) {
|
||||
if (!near.hasMetadata("plot")) {
|
||||
near.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot));
|
||||
}
|
||||
}
|
||||
}
|
||||
this.lastRadius = 0;
|
||||
}
|
||||
Iterator<Block> iterator = event.blockList().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Block block = iterator.next();
|
||||
location = BukkitUtil.adapt(block.getLocation());
|
||||
if (!area.contains(location.getX(), location.getZ()) || !origin.equals(area.getOwnedPlot(location))) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
plot.debug("Explosion was cancelled because explosion = false");
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPeskyMobsChangeTheWorldLikeWTFEvent(EntityChangeBlockEvent event) {
|
||||
Entity e = event.getEntity();
|
||||
if (!(e instanceof FallingBlock)) {
|
||||
Location location = BukkitUtil.adapt(event.getBlock().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area != null) {
|
||||
Plot plot = area.getOwnedPlot(location);
|
||||
if (plot != null && plot.getFlag(MobPlaceFlag.class)) {
|
||||
plot.debug(e.getType() + " could not change block because mob-place = false");
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler public void onPrime(ExplosionPrimeEvent event) {
|
||||
this.lastRadius = event.getRadius() + 1;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onVehicleCreate(VehicleCreateEvent event) {
|
||||
Vehicle entity = event.getVehicle();
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlotAbs(location);
|
||||
if (plot == null || BukkitEntityUtil.checkEntity(entity, plot)) {
|
||||
entity.remove();
|
||||
return;
|
||||
}
|
||||
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
||||
entity.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot));
|
||||
}
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
@ -66,8 +67,7 @@ public class EntitySpawnListener implements Listener {
|
||||
|
||||
public static void testNether(final Entity entity) {
|
||||
@Nonnull World world = entity.getWorld();
|
||||
if (world.getEnvironment() != World.Environment.NETHER
|
||||
&& world.getEnvironment() != World.Environment.THE_END) {
|
||||
if (world.getEnvironment() != World.Environment.NETHER && world.getEnvironment() != World.Environment.THE_END) {
|
||||
return;
|
||||
}
|
||||
test(entity);
|
||||
@ -91,8 +91,7 @@ public class EntitySpawnListener implements Listener {
|
||||
List<MetadataValue> meta = entity.getMetadata(KEY);
|
||||
if (meta.isEmpty()) {
|
||||
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world.getName())) {
|
||||
entity.setMetadata(KEY,
|
||||
new FixedMetadataValue((Plugin) PlotSquared.platform(), entity.getLocation()));
|
||||
entity.setMetadata(KEY, new FixedMetadataValue((Plugin) PlotSquared.platform(), entity.getLocation()));
|
||||
}
|
||||
} else {
|
||||
org.bukkit.Location origin = (org.bukkit.Location) meta.get(0).value();
|
||||
@ -123,8 +122,7 @@ public class EntitySpawnListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void creatureSpawnEvent(EntitySpawnEvent event) {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void creatureSpawnEvent(EntitySpawnEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
@ -155,13 +153,12 @@ public class EntitySpawnListener implements Listener {
|
||||
}
|
||||
switch (entity.getType()) {
|
||||
case ENDER_CRYSTAL:
|
||||
if (PlayerEvents.checkEntity(entity, plot)) {
|
||||
if (BukkitEntityUtil.checkEntity(entity, plot)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
case SHULKER:
|
||||
if (!entity.hasMetadata("shulkerPlot")) {
|
||||
entity.setMetadata("shulkerPlot",
|
||||
new FixedMetadataValue((Plugin) PlotSquared.platform(), plot.getId()));
|
||||
entity.setMetadata("shulkerPlot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -192,8 +189,7 @@ public class EntitySpawnListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void vehicleMove(VehicleMoveEvent event) {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void vehicleMove(VehicleMoveEvent event) {
|
||||
testNether(event.getVehicle());
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,163 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotHandler;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.ThrownPotion;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.LingeringPotionSplashEvent;
|
||||
import org.bukkit.event.entity.PotionSplashEvent;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.bukkit.projectiles.BlockProjectileSource;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.inject.Inject;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ProjectileEventListener implements Listener {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
|
||||
@Inject public ProjectileEventListener(@Nonnull final PlotAreaManager plotAreaManager) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPotionSplash(LingeringPotionSplashEvent event) {
|
||||
Projectile entity = event.getEntity();
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
if (!this.onProjectileHit(event)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPotionSplash(PotionSplashEvent event) {
|
||||
ThrownPotion damager = event.getPotion();
|
||||
Location location = BukkitUtil.adapt(damager.getLocation());
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
int count = 0;
|
||||
for (LivingEntity victim : event.getAffectedEntities()) {
|
||||
if (!BukkitEntityUtil.entityDamage(damager, victim)) {
|
||||
event.setIntensity(victim, 0);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if ((count > 0 && count == event.getAffectedEntities().size()) || !onProjectileHit(event)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler public void onProjectileLaunch(ProjectileLaunchEvent event) {
|
||||
Projectile entity = event.getEntity();
|
||||
if (!(entity instanceof ThrownPotion)) {
|
||||
return;
|
||||
}
|
||||
ProjectileSource shooter = entity.getShooter();
|
||||
if (!(shooter instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
PlotPlayer<Player> pp = BukkitUtil.adapt((Player) shooter);
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot != null && !plot.isAdded(pp.getUUID())) {
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"BooleanMethodIsAlwaysInverted", "cos it's not... dum IntelliJ"}) @EventHandler
|
||||
public boolean onProjectileHit(ProjectileHitEvent event) {
|
||||
Projectile entity = event.getEntity();
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return true;
|
||||
}
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return true;
|
||||
}
|
||||
Plot plot = area.getPlot(location);
|
||||
ProjectileSource shooter = entity.getShooter();
|
||||
if (shooter instanceof Player) {
|
||||
PlotPlayer<?> pp = BukkitUtil.adapt((Player) shooter);
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_PROJECTILE_UNOWNED)) {
|
||||
entity.remove();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (plot.isAdded(pp.getUUID()) || Permissions
|
||||
.hasPermission(pp, Permission.PERMISSION_PROJECTILE_OTHER)) {
|
||||
return true;
|
||||
}
|
||||
entity.remove();
|
||||
return false;
|
||||
}
|
||||
if (!(shooter instanceof Entity) && shooter != null) {
|
||||
if (plot == null) {
|
||||
entity.remove();
|
||||
return false;
|
||||
}
|
||||
Location sLoc =
|
||||
BukkitUtil.adapt(((BlockProjectileSource) shooter).getBlock().getLocation());
|
||||
if (!area.contains(sLoc.getX(), sLoc.getZ())) {
|
||||
entity.remove();
|
||||
return false;
|
||||
}
|
||||
Plot sPlot = area.getOwnedPlotAbs(sLoc);
|
||||
if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) {
|
||||
entity.remove();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.plotsquared.bukkit.BukkitPlatform;
|
||||
import com.plotsquared.bukkit.placeholder.MVdWPlaceholders;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.player.ConsolePlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerLoadEvent;
|
||||
|
||||
public class ServerListener implements Listener {
|
||||
|
||||
private final BukkitPlatform plugin;
|
||||
|
||||
public ServerListener(BukkitPlatform plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler public void onServerLoad(ServerLoadEvent event) {
|
||||
if (Bukkit.getPluginManager().getPlugin("MVdWPlaceholderAPI") != null) {
|
||||
new MVdWPlaceholders(this.plugin, PlotSquared.get().getPlaceholderRegistry());
|
||||
ConsolePlayer.getConsole().sendMessage(TranslatableCaption.of("placeholder.hooked"));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.placeholder;
|
||||
|
||||
import be.maximvdw.placeholderapi.PlaceholderAPI;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.util.placeholders.Placeholder;
|
||||
import com.plotsquared.core.util.placeholders.PlaceholderRegistry;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Placeholder support for MVdWPlaceholderAPI
|
||||
*/
|
||||
public class MVdWPlaceholders {
|
||||
|
||||
private static final String PREFIX = "plotsquared_";
|
||||
private final Plugin plugin;
|
||||
private final PlaceholderRegistry registry;
|
||||
|
||||
public MVdWPlaceholders(@Nonnull final Plugin plugin, @Nonnull final PlaceholderRegistry registry) {
|
||||
this.plugin = plugin;
|
||||
this.registry = registry;
|
||||
for (final Placeholder placeholder : registry.getPlaceholders()) {
|
||||
this.addPlaceholder(placeholder);
|
||||
}
|
||||
PlotSquared.get().getEventDispatcher().registerListener(this);
|
||||
}
|
||||
|
||||
@Subscribe public void onNewPlaceholder(@Nonnull final PlaceholderRegistry.PlaceholderAddedEvent event) {
|
||||
this.addPlaceholder(event.getPlaceholder());
|
||||
}
|
||||
|
||||
private void addPlaceholder(@Nonnull final Placeholder placeholder) {
|
||||
PlaceholderAPI.registerPlaceholder(plugin, PREFIX + String.format("%s", placeholder.getKey()), placeholderReplaceEvent -> {
|
||||
if (!placeholderReplaceEvent.isOnline() || placeholderReplaceEvent.getPlayer() == null) {
|
||||
return "";
|
||||
}
|
||||
final PlotPlayer<Player> player = BukkitUtil.adapt(placeholderReplaceEvent.getPlayer());
|
||||
String key = placeholderReplaceEvent.getPlaceholder().substring(PREFIX.length());
|
||||
return registry.getPlaceholderValue(key, player);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.placeholder;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PAPIPlaceholders extends PlaceholderExpansion {
|
||||
|
||||
public PAPIPlaceholders() {
|
||||
}
|
||||
|
||||
@Override public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public boolean canRegister() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public String getAuthor() {
|
||||
return "IntellectualSites";
|
||||
}
|
||||
|
||||
@Override public String getIdentifier() {
|
||||
return "plotsquared";
|
||||
}
|
||||
|
||||
@Override public String getVersion() {
|
||||
return "3";
|
||||
}
|
||||
|
||||
@Override public String onPlaceholderRequest(Player p, String identifier) {
|
||||
final PlotPlayer<?> pl = PlotSquared.platform().getPlayerManager().getPlayerIfExists(p.getUniqueId());
|
||||
|
||||
if (pl == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// PAPI specific ones that don't translate well over into other placeholder APIs
|
||||
if (identifier.startsWith("has_plot_")) {
|
||||
identifier = identifier.substring("has_plot_".length());
|
||||
if (identifier.isEmpty())
|
||||
return "";
|
||||
|
||||
return pl.getPlotCount(identifier) > 0 ?
|
||||
PlaceholderAPIPlugin.booleanTrue() :
|
||||
PlaceholderAPIPlugin.booleanFalse();
|
||||
}
|
||||
|
||||
if (identifier.startsWith("plot_count_")) {
|
||||
identifier = identifier.substring("plot_count_".length());
|
||||
if (identifier.isEmpty())
|
||||
return "";
|
||||
|
||||
return String.valueOf(pl.getPlotCount(identifier));
|
||||
}
|
||||
|
||||
// PlotSquared placeholders
|
||||
return PlotSquared.get().getPlaceholderRegistry().getPlaceholderValue(identifier, pl);
|
||||
}
|
||||
|
||||
}
|
@ -1,213 +0,0 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.placeholder;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Placeholders extends PlaceholderExpansion {
|
||||
|
||||
public Placeholders() {
|
||||
}
|
||||
|
||||
@Override public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public boolean canRegister() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public String getAuthor() {
|
||||
return "NotMyFault";
|
||||
}
|
||||
|
||||
@Override public String getIdentifier() {
|
||||
return "plotsquared";
|
||||
}
|
||||
|
||||
@Override public String getVersion() {
|
||||
return "2.5";
|
||||
}
|
||||
|
||||
@Override public String onPlaceholderRequest(Player p, String identifier) {
|
||||
final PlotPlayer pl = PlotSquared.platform().getPlayerManager().getPlayerIfExists(p.getUniqueId());
|
||||
|
||||
if (pl == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (identifier.startsWith("has_plot_")) {
|
||||
identifier = identifier.substring("has_plot_".length());
|
||||
if (identifier.isEmpty())
|
||||
return "";
|
||||
|
||||
return pl.getPlotCount(identifier) > 0 ?
|
||||
PlaceholderAPIPlugin.booleanTrue() :
|
||||
PlaceholderAPIPlugin.booleanFalse();
|
||||
}
|
||||
|
||||
if (identifier.startsWith("plot_count_")) {
|
||||
identifier = identifier.substring("plot_count_".length());
|
||||
if (identifier.isEmpty())
|
||||
return "";
|
||||
|
||||
return String.valueOf(pl.getPlotCount(identifier));
|
||||
}
|
||||
|
||||
switch (identifier) {
|
||||
case "currentplot_world": {
|
||||
return p.getWorld().getName();
|
||||
}
|
||||
case "has_plot": {
|
||||
return (pl.getPlotCount() > 0) ?
|
||||
PlaceholderAPIPlugin.booleanTrue() :
|
||||
PlaceholderAPIPlugin.booleanFalse();
|
||||
}
|
||||
case "allowed_plot_count": {
|
||||
return String.valueOf(pl.getAllowedPlots());
|
||||
}
|
||||
case "plot_count": {
|
||||
return String.valueOf(pl.getPlotCount());
|
||||
}
|
||||
}
|
||||
|
||||
Plot plot = pl.getCurrentPlot();
|
||||
|
||||
if (plot == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
switch (identifier) {
|
||||
case "currentplot_alias": {
|
||||
return plot.getAlias();
|
||||
}
|
||||
case "currentplot_owner": {
|
||||
final UUID plotOwner = plot.getOwnerAbs();
|
||||
if (plotOwner == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
try {
|
||||
return PlayerManager.getName(plotOwner, false);
|
||||
} catch (final Exception ignored) {}
|
||||
|
||||
final String name = Bukkit.getOfflinePlayer(plotOwner).getName();
|
||||
return name != null ? name : "unknown";
|
||||
}
|
||||
case "currentplot_members": {
|
||||
if (plot.getMembers() == null && plot.getTrusted() == null) {
|
||||
return "0";
|
||||
}
|
||||
return String.valueOf(plot.getMembers().size() + plot.getTrusted().size());
|
||||
}
|
||||
case "currentplot_members_added": {
|
||||
if (plot.getMembers() == null) {
|
||||
return "0";
|
||||
}
|
||||
return String.valueOf(plot.getMembers().size());
|
||||
}
|
||||
case "currentplot_members_trusted": {
|
||||
if (plot.getTrusted() == null) {
|
||||
return "0";
|
||||
}
|
||||
return String.valueOf(plot.getTrusted().size());
|
||||
}
|
||||
case "currentplot_members_denied": {
|
||||
if (plot.getDenied() == null) {
|
||||
return "0";
|
||||
}
|
||||
return String.valueOf(plot.getDenied().size());
|
||||
}
|
||||
case "has_build_rights": {
|
||||
return plot.isAdded(pl.getUUID()) ?
|
||||
PlaceholderAPIPlugin.booleanTrue() :
|
||||
PlaceholderAPIPlugin.booleanFalse();
|
||||
}
|
||||
case "currentplot_x": {
|
||||
return String.valueOf(plot.getId().getX());
|
||||
}
|
||||
case "currentplot_y": {
|
||||
return String.valueOf(plot.getId().getY());
|
||||
}
|
||||
case "currentplot_xy": {
|
||||
return plot.getId().getX() + ";" + plot.getId().getY();
|
||||
}
|
||||
case "currentplot_rating": {
|
||||
return String.valueOf(plot.getAverageRating());
|
||||
}
|
||||
case "currentplot_biome": {
|
||||
return plot.getBiomeSynchronous() + "";
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (identifier.startsWith("currentplot_localflag_")) {
|
||||
return getFlagValue(plot, identifier.substring("currentplot_localflag_".length()),
|
||||
false);
|
||||
}
|
||||
if (identifier.startsWith("currentplot_flag_")) {
|
||||
return getFlagValue(plot, identifier.substring("currentplot_flag_".length()), true);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the flag value from its name on the current plot.
|
||||
* If the flag doesn't exist it returns an empty string.
|
||||
* If the flag exists but it is not set on current plot and the parameter inherit is set to true,
|
||||
* it returns the default value.
|
||||
*
|
||||
* @param plot Current plot where the player is
|
||||
* @param flagName Name of flag to get from current plot
|
||||
* @param inherit Define if it returns only the flag set on currentplot or also inherited flag
|
||||
* @return The value of flag serialized in string
|
||||
*/
|
||||
private String getFlagValue(final Plot plot, final String flagName, final boolean inherit) {
|
||||
if (flagName.isEmpty())
|
||||
return "";
|
||||
final PlotFlag<?, ?> flag = GlobalFlagContainer.getInstance().getFlagFromString(flagName);
|
||||
if (flag == null)
|
||||
return "";
|
||||
|
||||
if (inherit) {
|
||||
return plot.getFlag(flag).toString();
|
||||
} else {
|
||||
final PlotFlag<?, ?> plotFlag = plot.getFlagContainer().queryLocal(flag.getClass());
|
||||
return (plotFlag != null) ? plotFlag.getValue().toString() : "";
|
||||
}
|
||||
}
|
||||
}
|
@ -73,10 +73,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
|
||||
private static boolean CHECK_EFFECTIVE = true;
|
||||
public final Player player;
|
||||
private final EconHandler econHandler;
|
||||
private String name;
|
||||
private String lastMessage = "";
|
||||
private long lastMessageTime = 0L;
|
||||
/**
|
||||
* <p>Please do not use this method. Instead use
|
||||
* BukkitUtil.getPlayer(Player), as it caches player objects.</p>
|
||||
@ -94,7 +91,6 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
@Nonnull final PermissionHandler permissionHandler) {
|
||||
super(plotAreaManager, eventDispatcher, econHandler, permissionHandler);
|
||||
this.player = player;
|
||||
this.econHandler = econHandler;
|
||||
this.setupPermissionProfile();
|
||||
if (realPlayer) {
|
||||
super.populatePersistentMetaMap();
|
||||
@ -153,13 +149,6 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean hasPermission(@Nonnull final String permission) {
|
||||
if (this.offline && this.econHandler != null) {
|
||||
return this.econHandler.hasPermission(getName(), permission);
|
||||
}
|
||||
return this.player.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override @Nonnegative public int hasPermissionRange(@Nonnull final String stub,
|
||||
@Nonnegative final int range) {
|
||||
if (hasPermission(Permission.PERMISSION_ADMIN.toString())) {
|
||||
|
@ -0,0 +1,225 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.queue;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.plotsquared.bukkit.BukkitPlatform;
|
||||
import com.plotsquared.core.queue.ChunkCoordinator;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.task.TaskTime;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Utility that allows for the loading and coordination of chunk actions
|
||||
* <p>
|
||||
* The coordinator takes in collection of chunk coordinates, loads them
|
||||
* and allows the caller to specify a sink for the loaded chunks. The
|
||||
* coordinator will prevent the chunks from being unloaded until the sink
|
||||
* has fully consumed the chunk
|
||||
* <p>
|
||||
**/
|
||||
public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
|
||||
private final List<ProgressSubscriber> progressSubscribers = new LinkedList<>();
|
||||
|
||||
private final Queue<BlockVector2> requestedChunks;
|
||||
private final Queue<Chunk> availableChunks;
|
||||
private final long maxIterationTime;
|
||||
private final Plugin plugin;
|
||||
private final Consumer<BlockVector2> chunkConsumer;
|
||||
private final org.bukkit.World bukkitWorld;
|
||||
private final Runnable whenDone;
|
||||
private final Consumer<Throwable> throwableConsumer;
|
||||
private final boolean unloadAfter;
|
||||
private final int totalSize;
|
||||
|
||||
private final AtomicInteger expectedSize;
|
||||
private int batchSize;
|
||||
|
||||
@Inject private BukkitChunkCoordinator(@Assisted final long maxIterationTime,
|
||||
@Assisted final int initialBatchSize,
|
||||
@Assisted @Nonnull final Consumer<BlockVector2> chunkConsumer,
|
||||
@Assisted @Nonnull final World world,
|
||||
@Assisted @Nonnull final Collection<BlockVector2> requestedChunks,
|
||||
@Assisted @Nonnull final Runnable whenDone,
|
||||
@Assisted @Nonnull final Consumer<Throwable> throwableConsumer,
|
||||
@Assisted final boolean unloadAfter) {
|
||||
this.requestedChunks = new LinkedBlockingQueue<>(requestedChunks);
|
||||
this.availableChunks = new LinkedBlockingQueue<>();
|
||||
this.totalSize = requestedChunks.size();
|
||||
this.expectedSize = new AtomicInteger(this.totalSize);
|
||||
this.batchSize = initialBatchSize;
|
||||
this.chunkConsumer = chunkConsumer;
|
||||
this.maxIterationTime = maxIterationTime;
|
||||
this.whenDone = whenDone;
|
||||
this.throwableConsumer = throwableConsumer;
|
||||
this.unloadAfter = unloadAfter;
|
||||
this.plugin = JavaPlugin.getPlugin(BukkitPlatform.class);
|
||||
this.bukkitWorld = Bukkit.getWorld(world.getName());
|
||||
}
|
||||
|
||||
@Override public void start() {
|
||||
// Request initial batch
|
||||
this.requestBatch();
|
||||
// Wait until next tick to give the chunks a chance to be loaded
|
||||
TaskManager.runTaskLater(() -> TaskManager.runTaskRepeat(this, TaskTime.ticks(1)), TaskTime.ticks(1));
|
||||
}
|
||||
|
||||
@Override public void runTask() {
|
||||
Chunk chunk = this.availableChunks.poll();
|
||||
if (chunk == null) {
|
||||
return;
|
||||
}
|
||||
long iterationTime;
|
||||
int processedChunks = 0;
|
||||
do {
|
||||
final long start = System.currentTimeMillis();
|
||||
try {
|
||||
this.chunkConsumer.accept(BlockVector2.at(chunk.getX(), chunk.getZ()));
|
||||
} catch (final Throwable throwable) {
|
||||
this.throwableConsumer.accept(throwable);
|
||||
}
|
||||
if (unloadAfter) {
|
||||
this.freeChunk(chunk);
|
||||
}
|
||||
processedChunks++;
|
||||
final long end = System.currentTimeMillis();
|
||||
// Update iteration time
|
||||
iterationTime = end - start;
|
||||
} while (2 * iterationTime /* last chunk + next chunk */ < this.maxIterationTime && (chunk = availableChunks.poll()) != null);
|
||||
if (processedChunks < this.batchSize) {
|
||||
// Adjust batch size based on the amount of processed chunks per tick
|
||||
this.batchSize = processedChunks;
|
||||
}
|
||||
|
||||
final int expected = this.expectedSize.addAndGet(-processedChunks);
|
||||
|
||||
final float progress = ((float) totalSize - (float) expected) / (float) totalSize;
|
||||
for (final ProgressSubscriber subscriber : this.progressSubscribers) {
|
||||
subscriber.notifyProgress(this, progress);
|
||||
}
|
||||
|
||||
if (expected <= 0) {
|
||||
try {
|
||||
this.whenDone.run();
|
||||
} catch (final Throwable throwable) {
|
||||
this.throwableConsumer.accept(throwable);
|
||||
}
|
||||
this.cancel();
|
||||
} else {
|
||||
if (this.availableChunks.size() < processedChunks) {
|
||||
this.requestBatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests a batch of chunks to be loaded
|
||||
*/
|
||||
private void requestBatch() {
|
||||
BlockVector2 chunk;
|
||||
for (int i = 0; i < this.batchSize && (chunk = this.requestedChunks.poll()) != null; i++) {
|
||||
// This required PaperLib to be bumped to version 1.0.4 to mark the request as urgent
|
||||
PaperLib.getChunkAtAsync(this.bukkitWorld, chunk.getX(), chunk.getZ(), true, true).whenComplete((chunkObject, throwable) -> {
|
||||
if (throwable != null) {
|
||||
throwable.printStackTrace();
|
||||
// We want one less because this couldn't be processed
|
||||
this.expectedSize.decrementAndGet();
|
||||
} else {
|
||||
this.processChunk(chunkObject);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Once a chunk has been loaded, process it (add a plugin ticket and add to available chunks list)
|
||||
*/
|
||||
private void processChunk(@Nonnull final Chunk chunk) {
|
||||
if (!chunk.isLoaded()) {
|
||||
throw new IllegalArgumentException(String.format("Chunk %d;%d is is not loaded", chunk.getX(), chunk.getZ()));
|
||||
}
|
||||
chunk.addPluginChunkTicket(this.plugin);
|
||||
this.availableChunks.add(chunk);
|
||||
}
|
||||
|
||||
/**
|
||||
* Once a chunk has been used, free it up for unload by removing the plugin ticket
|
||||
*/
|
||||
private void freeChunk(@Nonnull final Chunk chunk) {
|
||||
if (!chunk.isLoaded()) {
|
||||
throw new IllegalArgumentException(String.format("Chunk %d;%d is is not loaded", chunk.getX(), chunk.getZ()));
|
||||
}
|
||||
chunk.removePluginChunkTicket(this.plugin);
|
||||
}
|
||||
|
||||
@Override public int getRemainingChunks() {
|
||||
return this.expectedSize.get();
|
||||
}
|
||||
|
||||
@Override public int getTotalChunks() {
|
||||
return this.totalSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to coordinator progress updates
|
||||
*
|
||||
* @param subscriber Subscriber
|
||||
*/
|
||||
public void subscribeToProgress(@Nonnull final BukkitChunkCoordinator.ProgressSubscriber subscriber) {
|
||||
this.progressSubscribers.add(subscriber);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ProgressSubscriber {
|
||||
|
||||
/**
|
||||
* Notify about a progress update in the coordinator
|
||||
*
|
||||
* @param coordinator Coordinator instance that triggered the notification
|
||||
* @param progress Progress in the range [0, 1]
|
||||
*/
|
||||
void notifyProgress(@Nonnull final BukkitChunkCoordinator coordinator, final float progress);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,239 +0,0 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.queue;
|
||||
|
||||
import com.plotsquared.bukkit.schematic.StateWrapper;
|
||||
import com.plotsquared.bukkit.util.BukkitBlockUtil;
|
||||
import com.plotsquared.core.queue.BasicLocalBlockQueue;
|
||||
import com.plotsquared.core.util.BlockUtil;
|
||||
import com.plotsquared.core.util.ChunkUtil;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Container;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class BukkitLocalQueue extends BasicLocalBlockQueue {
|
||||
|
||||
public BukkitLocalQueue(String world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
@Override public LocalChunk getLocalChunk(int x, int z) {
|
||||
return new BasicLocalChunk(this, x, z) {
|
||||
// Custom stuff?
|
||||
};
|
||||
}
|
||||
|
||||
@Override public void optimize() {
|
||||
|
||||
}
|
||||
|
||||
@Override public BlockState getBlock(int x, int y, int z) {
|
||||
World worldObj = Bukkit.getWorld(getWorld());
|
||||
if (worldObj != null) {
|
||||
Block block = worldObj.getBlockAt(x, y, z);
|
||||
return BukkitBlockUtil.get(block);
|
||||
} else {
|
||||
return BlockUtil.get(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void refreshChunk(int x, int z) {
|
||||
World worldObj = Bukkit.getWorld(getWorld());
|
||||
if (worldObj != null) {
|
||||
worldObj.refreshChunk(x, z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void fixChunkLighting(int x, int z) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override public final void regenChunk(int x, int z) {
|
||||
World worldObj = Bukkit.getWorld(getWorld());
|
||||
if (worldObj != null) {
|
||||
try {
|
||||
worldObj.regenerateChunk(x, z);
|
||||
} catch (UnsupportedOperationException e) {
|
||||
com.sk89q.worldedit.world.World world = BukkitAdapter.adapt(worldObj);
|
||||
try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory()
|
||||
.getEditSession(world, -1);) {
|
||||
CuboidRegion region =
|
||||
new CuboidRegion(world, BlockVector3.at((x << 4), 0, (z << 4)),
|
||||
BlockVector3.at((x << 4) + 15, 255, (z << 4) + 15));
|
||||
world.regenerate(region, editSession);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override public final void setComponents(LocalChunk lc)
|
||||
throws ExecutionException, InterruptedException {
|
||||
setBaseBlocks(lc);
|
||||
}
|
||||
|
||||
public void setBaseBlocks(LocalChunk localChunk) {
|
||||
World worldObj = Bukkit.getWorld(getWorld());
|
||||
if (worldObj == null) {
|
||||
throw new NullPointerException("World cannot be null.");
|
||||
}
|
||||
final Consumer<Chunk> chunkConsumer = chunk -> {
|
||||
for (int layer = 0; layer < localChunk.baseblocks.length; layer++) {
|
||||
BaseBlock[] blocksLayer = localChunk.baseblocks[layer];
|
||||
if (blocksLayer != null) {
|
||||
for (int j = 0; j < blocksLayer.length; j++) {
|
||||
if (blocksLayer[j] != null) {
|
||||
BaseBlock block = blocksLayer[j];
|
||||
int x = ChunkUtil.getX(j);
|
||||
int y = ChunkUtil.getY(layer, j);
|
||||
int z = ChunkUtil.getZ(j);
|
||||
|
||||
BlockData blockData = BukkitAdapter.adapt(block);
|
||||
|
||||
Block existing = chunk.getBlock(x, y, z);
|
||||
final BlockState existingBaseBlock =
|
||||
BukkitAdapter.adapt(existing.getBlockData());
|
||||
if (BukkitBlockUtil.get(existing).equals(existingBaseBlock) && existing
|
||||
.getBlockData().matches(blockData)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (existing.getState() instanceof Container) {
|
||||
((Container) existing.getState()).getInventory().clear();
|
||||
}
|
||||
|
||||
existing.setType(BukkitAdapter.adapt(block.getBlockType()), false);
|
||||
existing.setBlockData(blockData, false);
|
||||
if (block.hasNbtData()) {
|
||||
CompoundTag tag = block.getNbtData();
|
||||
StateWrapper sw = new StateWrapper(tag);
|
||||
|
||||
sw.restoreTag(worldObj.getName(), existing.getX(), existing.getY(),
|
||||
existing.getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (setBiome() && localChunk.biomes != null) {
|
||||
for (int x = 0; x < localChunk.biomes.length; x++) {
|
||||
BiomeType[] biomeZ = localChunk.biomes[x];
|
||||
if (biomeZ != null) {
|
||||
for (int z = 0; z < biomeZ.length; z++) {
|
||||
if (biomeZ[z] != null) {
|
||||
BiomeType biomeType = biomeZ[z];
|
||||
|
||||
Biome biome = BukkitAdapter.adapt(biomeType);
|
||||
worldObj.setBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z,
|
||||
biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
if (isForceSync()) {
|
||||
chunkConsumer.accept(getChunk(worldObj, localChunk));
|
||||
} else {
|
||||
PaperLib.getChunkAtAsync(worldObj, localChunk.getX(), localChunk.getZ(), true)
|
||||
.thenAccept(chunkConsumer);
|
||||
}
|
||||
}
|
||||
|
||||
private Chunk getChunk(final World world, final LocalChunk localChunk) {
|
||||
Chunk chunk = null;
|
||||
if (this.getChunkObject() != null && this.getChunkObject() instanceof Chunk) {
|
||||
chunk = (Chunk) this.getChunkObject();
|
||||
}
|
||||
if (chunk == null) {
|
||||
chunk = world.getChunkAt(localChunk.getX(), localChunk.getZ());
|
||||
}
|
||||
if (!chunk.isLoaded()) {
|
||||
chunk.load(true);
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
private void setMaterial(@Nonnull final BlockState plotBlock, @Nonnull final Block block) {
|
||||
Material material = BukkitAdapter.adapt(plotBlock.getBlockType());
|
||||
block.setType(material, false);
|
||||
}
|
||||
|
||||
private boolean equals(@Nonnull final BlockState plotBlock, @Nonnull final Block block) {
|
||||
return plotBlock.equals(BukkitBlockUtil.get(block));
|
||||
}
|
||||
|
||||
public void setBiomes(LocalChunk lc) {
|
||||
World worldObj = Bukkit.getWorld(getWorld());
|
||||
if (worldObj == null) {
|
||||
throw new NullPointerException("World cannot be null.");
|
||||
}
|
||||
if (lc.biomes == null) {
|
||||
throw new NullPointerException("Biomes cannot be null.");
|
||||
}
|
||||
final Consumer<Chunk> chunkConsumer = chunk -> {
|
||||
for (int x = 0; x < lc.biomes.length; x++) {
|
||||
BiomeType[] biomeZ = lc.biomes[x];
|
||||
if (biomeZ != null) {
|
||||
for (int z = 0; z < biomeZ.length; z++) {
|
||||
if (biomeZ[z] != null) {
|
||||
BiomeType biomeType = biomeZ[z];
|
||||
|
||||
Biome biome = BukkitAdapter.adapt(biomeType);
|
||||
worldObj
|
||||
.setBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z, biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
if (this.isForceSync()) {
|
||||
chunkConsumer.accept(getChunk(worldObj, lc));
|
||||
} else {
|
||||
PaperLib.getChunkAtAsync(worldObj, lc.getX(), lc.getZ(), true)
|
||||
.thenAccept(chunkConsumer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,241 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.queue;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.bukkit.schematic.StateWrapper;
|
||||
import com.plotsquared.bukkit.util.BukkitBlockUtil;
|
||||
import com.plotsquared.core.inject.factory.ChunkCoordinatorBuilderFactory;
|
||||
import com.plotsquared.core.inject.factory.ChunkCoordinatorFactory;
|
||||
import com.plotsquared.core.queue.BasicQueueCoordinator;
|
||||
import com.plotsquared.core.queue.ChunkCoordinator;
|
||||
import com.plotsquared.core.queue.LocalChunk;
|
||||
import com.plotsquared.core.util.BlockUtil;
|
||||
import com.plotsquared.core.util.ChunkUtil;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Container;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
|
||||
private final SideEffectSet sideEffectSet;
|
||||
private org.bukkit.World bukkitWorld;
|
||||
@Inject private ChunkCoordinatorBuilderFactory chunkCoordinatorBuilderFactory;
|
||||
@Inject private ChunkCoordinatorFactory chunkCoordinatorFactory;
|
||||
private ChunkCoordinator chunkCoordinator;
|
||||
|
||||
@Inject public BukkitQueueCoordinator(@Nonnull World world) {
|
||||
super(world);
|
||||
sideEffectSet = SideEffectSet.none().with(SideEffect.LIGHTING, SideEffect.State.OFF).with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
|
||||
}
|
||||
|
||||
@Override public BlockState getBlock(int x, int y, int z) {
|
||||
org.bukkit.World worldObj = BukkitAdapter.adapt(getWorld());
|
||||
if (worldObj != null) {
|
||||
Block block = worldObj.getBlockAt(x, y, z);
|
||||
return BukkitBlockUtil.get(block);
|
||||
} else {
|
||||
return BlockUtil.get(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void start() {
|
||||
chunkCoordinator.start();
|
||||
}
|
||||
|
||||
//TODO: implement cancellation
|
||||
@Override public void cancel() {
|
||||
chunkCoordinator.cancel();
|
||||
}
|
||||
|
||||
@Override public boolean enqueue() {
|
||||
final Clipboard regenClipboard;
|
||||
if (isRegen()) {
|
||||
BlockVector3 start = BlockVector3.at(getRegenStart()[0] << 4, 0, getRegenStart()[1] << 4);
|
||||
BlockVector3 end = BlockVector3.at((getRegenEnd()[0] << 4) + 15, 255, (getRegenEnd()[1] << 4) + 15);
|
||||
Region region = new CuboidRegion(start, end);
|
||||
regenClipboard = new BlockArrayClipboard(region);
|
||||
regenClipboard.setOrigin(start);
|
||||
getWorld().regenerate(region, regenClipboard);
|
||||
} else if (getRegenRegion() != null) {
|
||||
regenClipboard = new BlockArrayClipboard(getRegenRegion());
|
||||
regenClipboard.setOrigin(getRegenRegion().getMinimumPoint());
|
||||
getWorld().regenerate(getRegenRegion(), regenClipboard);
|
||||
} else {
|
||||
regenClipboard = null;
|
||||
}
|
||||
Consumer<BlockVector2> consumer = getChunkConsumer();
|
||||
if (consumer == null) {
|
||||
consumer = blockVector2 -> {
|
||||
LocalChunk localChunk = getBlockChunks().get(blockVector2);
|
||||
boolean isRegenChunk =
|
||||
regenClipboard != null && blockVector2.getBlockX() > getRegenStart()[0] && blockVector2.getBlockZ() > getRegenStart()[1]
|
||||
&& blockVector2.getBlockX() < getRegenEnd()[0] && blockVector2.getBlockZ() < getRegenEnd()[1];
|
||||
if (isRegenChunk) {
|
||||
for (int layer = 0; layer < 16; layer++) {
|
||||
for (int y = layer << 4; y < 16; y++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
BaseBlock block = regenClipboard.getFullBlock(BlockVector3.at(x, y, z));
|
||||
if (block != null) {
|
||||
setWorldBlock(x, y, z, block, blockVector2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Allow regen and then blocks to be placed (plot schematic etc)
|
||||
if (localChunk == null) {
|
||||
return;
|
||||
}
|
||||
int sx = blockVector2.getX() << 4;
|
||||
int sz = blockVector2.getZ() << 4;
|
||||
for (int layer = 0; layer < localChunk.getBaseblocks().length; layer++) {
|
||||
BaseBlock[] blocksLayer = localChunk.getBaseblocks()[layer];
|
||||
if (blocksLayer == null) {
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < blocksLayer.length; j++) {
|
||||
if (blocksLayer[j] == null) {
|
||||
continue;
|
||||
}
|
||||
BaseBlock block = blocksLayer[j];
|
||||
|
||||
if (block != null) {
|
||||
int x = sx + ChunkUtil.getX(j);
|
||||
int y = ChunkUtil.getY(layer, j);
|
||||
int z = sz + ChunkUtil.getZ(j);
|
||||
setWorldBlock(x, y, z, block, blockVector2);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int layer = 0; layer < localChunk.getBaseblocks().length; layer++) {
|
||||
BiomeType[] biomesLayer = localChunk.getBiomes()[layer];
|
||||
if (biomesLayer == null) {
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < biomesLayer.length; j++) {
|
||||
if (biomesLayer[j] == null) {
|
||||
continue;
|
||||
}
|
||||
BiomeType biome = biomesLayer[j];
|
||||
if (biome != null) {
|
||||
int x = sx + ChunkUtil.getX(j);
|
||||
int y = ChunkUtil.getY(layer, j);
|
||||
int z = sz + ChunkUtil.getZ(j);
|
||||
getWorld().setBiome(BlockVector3.at(x, y, z), biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (localChunk.getTiles().size() > 0) {
|
||||
localChunk.getTiles().forEach(((blockVector3, tag) -> {
|
||||
try {
|
||||
BaseBlock block = getWorld().getBlock(blockVector3).toBaseBlock(tag);
|
||||
getWorld().setBlock(blockVector3, block, sideEffectSet);
|
||||
} catch (WorldEditException ignored) {
|
||||
StateWrapper sw = new StateWrapper(tag);
|
||||
sw.restoreTag(getWorld().getName(), blockVector3.getX(), blockVector3.getY(), blockVector3.getZ());
|
||||
}
|
||||
}));
|
||||
}
|
||||
if (localChunk.getEntities().size() > 0) {
|
||||
localChunk.getEntities().forEach((location, entity) -> {
|
||||
getWorld().createEntity(location, entity);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
Collection<BlockVector2> read = new ArrayList<>();
|
||||
if (getReadChunks().size() > 0) {
|
||||
read.addAll(getReadChunks());
|
||||
}
|
||||
chunkCoordinator =
|
||||
chunkCoordinatorBuilderFactory.create(chunkCoordinatorFactory).inWorld(getWorld()).withChunks(getBlockChunks().keySet()).withChunks(read)
|
||||
.withInitialBatchSize(3).withMaxIterationTime(40).withThrowableConsumer(Throwable::printStackTrace).withFinalAction(getCompleteTask())
|
||||
.withConsumer(consumer).unloadAfter(isUnloadAfter()).build();
|
||||
return super.enqueue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a block to the world. First tries WNA but defaults to normal block setting methods if that fails
|
||||
*/
|
||||
private void setWorldBlock(int x, int y, int z, @Nonnull BaseBlock block, @Nonnull BlockVector2 blockVector2) {
|
||||
try {
|
||||
getWorld().setBlock(BlockVector3.at(x, y, z), block, sideEffectSet);
|
||||
} catch (WorldEditException ignored) {
|
||||
// Fallback to not so nice method
|
||||
BlockData blockData = BukkitAdapter.adapt(block);
|
||||
|
||||
if (bukkitWorld == null) {
|
||||
bukkitWorld = Bukkit.getWorld(getWorld().getName());
|
||||
}
|
||||
Chunk chunk = bukkitWorld.getChunkAt(blockVector2.getX(), blockVector2.getZ());
|
||||
|
||||
Block existing = chunk.getBlock(x, y, z);
|
||||
final BlockState existingBaseBlock = BukkitAdapter.adapt(existing.getBlockData());
|
||||
if (BukkitBlockUtil.get(existing).equals(existingBaseBlock) && existing.getBlockData().matches(blockData)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (existing.getState() instanceof Container) {
|
||||
((Container) existing.getState()).getInventory().clear();
|
||||
}
|
||||
|
||||
existing.setType(BukkitAdapter.adapt(block.getBlockType()), false);
|
||||
existing.setBlockData(blockData, false);
|
||||
if (block.hasNbtData()) {
|
||||
CompoundTag tag = block.getNbtData();
|
||||
StateWrapper sw = new StateWrapper(tag);
|
||||
|
||||
sw.restoreTag(getWorld().getName(), existing.getX(), existing.getY(), existing.getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -30,7 +30,7 @@ import com.plotsquared.bukkit.util.BukkitBlockUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.location.ChunkWrapper;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
|
||||
import com.plotsquared.core.queue.ScopedQueueCoordinator;
|
||||
import com.plotsquared.core.util.ChunkUtil;
|
||||
import com.plotsquared.core.util.PatternUtil;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
@ -39,16 +39,17 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GenChunk extends ScopedLocalBlockQueue {
|
||||
public class GenChunk extends ScopedQueueCoordinator {
|
||||
|
||||
public final Biome[] biomes;
|
||||
public BlockState[][] result;
|
||||
@ -64,7 +65,18 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
this.biomes = Biome.values();
|
||||
}
|
||||
|
||||
public Chunk getChunk() {
|
||||
@Nullable public ChunkData getChunkData() {
|
||||
return this.chunkData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the internal Bukkit chunk data
|
||||
*/
|
||||
public void setChunkData(@Nonnull ChunkData chunkData) {
|
||||
this.chunkData = chunkData;
|
||||
}
|
||||
|
||||
@Nonnull public Chunk getChunk() {
|
||||
if (chunk == null) {
|
||||
World worldObj = BukkitUtil.getWorld(world);
|
||||
if (worldObj != null) {
|
||||
@ -74,32 +86,40 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
public void setChunk(Chunk chunk) {
|
||||
/**
|
||||
* Set the chunk being represented
|
||||
*/
|
||||
public void setChunk(@Nonnull Chunk chunk) {
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
public void setChunk(ChunkWrapper wrap) {
|
||||
|
||||
/**
|
||||
* Set the world and XZ of the chunk being represented via {@link ChunkWrapper}
|
||||
*/
|
||||
public void setChunk(@Nonnull ChunkWrapper wrap) {
|
||||
chunk = null;
|
||||
world = wrap.world;
|
||||
chunkX = wrap.x;
|
||||
chunkZ = wrap.z;
|
||||
}
|
||||
|
||||
@Override public void fillBiome(BiomeType biomeType) {
|
||||
@Override public void fillBiome(@Nonnull BiomeType biomeType) {
|
||||
if (biomeGrid == null) {
|
||||
return;
|
||||
}
|
||||
Biome biome = BukkitAdapter.adapt(biomeType);
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
this.biomeGrid.setBiome(x, z, biome);
|
||||
for (int y = 0; y < 256; y++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
this.biomeGrid.setBiome(x, y, z, biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void setCuboid(Location pos1, Location pos2, BlockState block) {
|
||||
if (result != null && pos1.getX() == 0 && pos1.getZ() == 0 && pos2.getX() == 15
|
||||
&& pos2.getZ() == 15) {
|
||||
@Override public void setCuboid(@Nonnull Location pos1, @Nonnull Location pos2, @Nonnull BlockState block) {
|
||||
if (result != null && pos1.getX() == 0 && pos1.getZ() == 0 && pos2.getX() == 15 && pos2.getZ() == 15) {
|
||||
for (int y = pos1.getY(); y <= pos2.getY(); y++) {
|
||||
int layer = y >> 4;
|
||||
BlockState[] data = result[layer];
|
||||
@ -117,28 +137,39 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
int maxX = Math.max(pos1.getX(), pos2.getX());
|
||||
int maxY = Math.max(pos1.getY(), pos2.getY());
|
||||
int maxZ = Math.max(pos1.getZ(), pos2.getZ());
|
||||
chunkData
|
||||
.setRegion(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1, BukkitAdapter.adapt(block));
|
||||
chunkData.setRegion(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1, BukkitAdapter.adapt(block));
|
||||
}
|
||||
|
||||
@Override public boolean setBiome(int x, int z, BiomeType biomeType) {
|
||||
@Override public boolean setBiome(int x, int z, @Nonnull BiomeType biomeType) {
|
||||
return setBiome(x, z, BukkitAdapter.adapt(biomeType));
|
||||
}
|
||||
|
||||
public boolean setBiome(int x, int z, Biome biome) {
|
||||
/**
|
||||
* Set the in the whole column of XZ
|
||||
*/
|
||||
public boolean setBiome(int x, int z, @Nonnull Biome biome) {
|
||||
if (this.biomeGrid != null) {
|
||||
this.biomeGrid.setBiome(x, z, biome);
|
||||
for (int y = 0; y < 256; y++) {
|
||||
this.setBiome(x, y, z, biome);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean setBiome(int x, int y, int z, @Nonnull Biome biome) {
|
||||
if (this.biomeGrid != null) {
|
||||
this.biomeGrid.setBiome(x, y, z, biome);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean setBlock(int x, int y, int z, @Nonnull Pattern pattern) {
|
||||
return setBlock(x, y, z, PatternUtil
|
||||
.apply(Preconditions.checkNotNull(pattern, "Pattern may not be null"), x, y, z));
|
||||
return setBlock(x, y, z, PatternUtil.apply(Preconditions.checkNotNull(pattern, "Pattern may not be null"), x, y, z));
|
||||
}
|
||||
|
||||
@Override public boolean setBlock(int x, int y, int z, BlockState id) {
|
||||
@Override public boolean setBlock(int x, int y, int z, @Nonnull BlockState id) {
|
||||
if (this.result == null) {
|
||||
this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id));
|
||||
return true;
|
||||
@ -148,7 +179,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void storeCache(final int x, final int y, final int z, final BlockState id) {
|
||||
private void storeCache(final int x, final int y, final int z, @Nonnull final BlockState id) {
|
||||
int i = y >> 4;
|
||||
BlockState[] v = this.result[i];
|
||||
if (v == null) {
|
||||
@ -158,7 +189,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
v[j] = id;
|
||||
}
|
||||
|
||||
@Override public boolean setBlock(int x, int y, int z, BaseBlock id) {
|
||||
@Override public boolean setBlock(int x, int y, int z, @Nonnull BaseBlock id) {
|
||||
if (this.result == null) {
|
||||
this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id));
|
||||
return true;
|
||||
@ -168,7 +199,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public BlockState getBlock(int x, int y, int z) {
|
||||
@Override @Nullable public BlockState getBlock(int x, int y, int z) {
|
||||
int i = y >> 4;
|
||||
if (result == null) {
|
||||
return BukkitBlockUtil.get(chunkData.getType(x, y, z));
|
||||
@ -189,19 +220,19 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
return chunk == null ? chunkZ : chunk.getZ();
|
||||
}
|
||||
|
||||
@Override public String getWorld() {
|
||||
return chunk == null ? world : chunk.getWorld().getName();
|
||||
@Override @Nonnull public com.sk89q.worldedit.world.World getWorld() {
|
||||
return chunk == null ? BukkitAdapter.adapt(Bukkit.getWorld(world)) : BukkitAdapter.adapt(chunk.getWorld());
|
||||
}
|
||||
|
||||
@Override public Location getMax() {
|
||||
return Location.at(getWorld(), 15 + (getX() << 4), 255, 15 + (getZ() << 4));
|
||||
@Override @Nonnull public Location getMax() {
|
||||
return Location.at(getWorld().getName(), 15 + (getX() << 4), 255, 15 + (getZ() << 4));
|
||||
}
|
||||
|
||||
@Override public Location getMin() {
|
||||
return Location.at(getWorld(), getX() << 4, 0, getZ() << 4);
|
||||
@Override @Nonnull public Location getMin() {
|
||||
return Location.at(getWorld().getName(), getX() << 4, 0, getZ() << 4);
|
||||
}
|
||||
|
||||
public GenChunk clone() {
|
||||
@Nonnull public GenChunk clone() {
|
||||
GenChunk toReturn = new GenChunk();
|
||||
if (this.result != null) {
|
||||
for (int i = 0; i < this.result.length; i++) {
|
||||
@ -215,12 +246,4 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
toReturn.chunkData = this.chunkData;
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public ChunkData getChunkData() {
|
||||
return this.chunkData;
|
||||
}
|
||||
|
||||
public void setChunkData(ChunkData chunkData) {
|
||||
this.chunkData = chunkData;
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ package com.plotsquared.bukkit.schematic;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.plotsquared.core.queue.LocalBlockQueue;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.util.SchematicHandler;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
@ -44,7 +44,7 @@ import javax.annotation.Nonnull;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean restoreTile(LocalBlockQueue queue, CompoundTag ct, int x, int y, int z) {
|
||||
return new StateWrapper(ct).restoreTag(queue.getWorld(), x, y, z);
|
||||
public boolean restoreTile(QueueCoordinator queue, CompoundTag ct, int x, int y, int z) {
|
||||
return new StateWrapper(ct).restoreTag(queue.getWorld().getName(), x, y, z);
|
||||
}
|
||||
}
|
||||
|
@ -26,140 +26,23 @@
|
||||
package com.plotsquared.bukkit.util;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.listener.WEExtent;
|
||||
import com.plotsquared.core.queue.LocalBlockQueue;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.entity.EntityCategories;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static com.plotsquared.core.util.entity.EntityCategories.CAP_ANIMAL;
|
||||
import static com.plotsquared.core.util.entity.EntityCategories.CAP_ENTITY;
|
||||
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MISC;
|
||||
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MOB;
|
||||
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MONSTER;
|
||||
import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
||||
|
||||
@Singleton public class BukkitChunkManager extends ChunkManager {
|
||||
@Singleton
|
||||
public class BukkitChunkManager extends ChunkManager {
|
||||
|
||||
public static boolean isIn(CuboidRegion region, int x, int z) {
|
||||
return x >= region.getMinimumPoint().getX() && x <= region.getMaximumPoint().getX()
|
||||
&& z >= region.getMinimumPoint().getZ() && z <= region.getMaximumPoint().getZ();
|
||||
return x >= region.getMinimumPoint().getX() && x <= region.getMaximumPoint().getX() && z >= region.getMinimumPoint().getZ() && z <= region
|
||||
.getMaximumPoint().getZ();
|
||||
}
|
||||
|
||||
public static ContentMap swapChunk(World world1, World world2, Chunk pos1, Chunk pos2,
|
||||
CuboidRegion r1, CuboidRegion r2) {
|
||||
ContentMap map = new ContentMap();
|
||||
int relX = r2.getMinimumPoint().getX() - r1.getMinimumPoint().getX();
|
||||
int relZ = r2.getMinimumPoint().getZ() - r1.getMinimumPoint().getZ();
|
||||
|
||||
map.saveEntitiesIn(pos1, r1, relX, relZ, true);
|
||||
map.saveEntitiesIn(pos2, r2, -relX, -relZ, true);
|
||||
|
||||
int sx = pos1.getX() << 4;
|
||||
int sz = pos1.getZ() << 4;
|
||||
|
||||
String worldName1 = world1.getName();
|
||||
String worldName2 = world2.getName();
|
||||
|
||||
BukkitWorld bukkitWorld1 = new BukkitWorld(world1);
|
||||
BukkitWorld bukkitWorld2 = new BukkitWorld(world2);
|
||||
|
||||
LocalBlockQueue queue1 = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(worldName1, false);
|
||||
LocalBlockQueue queue2 = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(worldName2, false);
|
||||
|
||||
for (int x = Math.max(r1.getMinimumPoint().getX(), sx);
|
||||
x <= Math.min(r1.getMaximumPoint().getX(), sx + 15); x++) {
|
||||
for (int z = Math.max(r1.getMinimumPoint().getZ(), sz);
|
||||
z <= Math.min(r1.getMaximumPoint().getZ(), sz + 15); z++) {
|
||||
for (int y = 0; y < 256; y++) {
|
||||
Block block1 = world1.getBlockAt(x, y, z);
|
||||
BaseBlock baseBlock1 = bukkitWorld1.getFullBlock(BlockVector3.at(x, y, z));
|
||||
BlockData data1 = block1.getBlockData();
|
||||
|
||||
int xx = x + relX;
|
||||
int zz = z + relZ;
|
||||
|
||||
Block block2 = world2.getBlockAt(xx, y, zz);
|
||||
BaseBlock baseBlock2 = bukkitWorld2.getFullBlock(BlockVector3.at(xx, y, zz));
|
||||
BlockData data2 = block2.getBlockData();
|
||||
|
||||
if (block1.isEmpty()) {
|
||||
if (!block2.isEmpty()) {
|
||||
queue1.setBlock(x, y, z, baseBlock2);
|
||||
queue2.setBlock(xx, y, zz, WEExtent.AIRBASE);
|
||||
}
|
||||
} else if (block2.isEmpty()) {
|
||||
queue1.setBlock(x, y, z, WEExtent.AIRBASE);
|
||||
queue2.setBlock(xx, y, zz, baseBlock1);
|
||||
} else if (block1.equals(block2)) {
|
||||
if (!data1.matches(data2)) {
|
||||
block1.setBlockData(data2);
|
||||
block2.setBlockData(data1);
|
||||
}
|
||||
} else {
|
||||
queue1.setBlock(x, y, z, baseBlock2);
|
||||
queue2.setBlock(xx, y, zz, baseBlock1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
queue1.enqueue();
|
||||
queue2.enqueue();
|
||||
return map;
|
||||
@Override public CompletableFuture<?> loadChunk(String world, BlockVector2 chunkLoc, boolean force) {
|
||||
return PaperLib.getChunkAtAsync(BukkitUtil.getWorld(world), chunkLoc.getX(), chunkLoc.getZ(), force);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<?> loadChunk(String world, BlockVector2 chunkLoc, boolean force) {
|
||||
return PaperLib
|
||||
.getChunkAtAsync(BukkitUtil.getWorld(world), chunkLoc.getX(), chunkLoc.getZ(), force);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadChunk(final String world, final BlockVector2 chunkLoc, final boolean save) {
|
||||
if (!PlotSquared.get().isMainThread(Thread.currentThread())) {
|
||||
TaskManager.runTask(() -> BukkitUtil.getWorld(world)
|
||||
.unloadChunk(chunkLoc.getX(), chunkLoc.getZ(), save));
|
||||
} else {
|
||||
BukkitUtil.getWorld(world).unloadChunk(chunkLoc.getX(), chunkLoc.getZ(), save);
|
||||
}
|
||||
}
|
||||
|
||||
private void count(int[] count, Entity entity) {
|
||||
final com.sk89q.worldedit.world.entity.EntityType entityType =
|
||||
BukkitAdapter.adapt(entity.getType());
|
||||
|
||||
if (EntityCategories.PLAYER.contains(entityType)) {
|
||||
return;
|
||||
} else if (EntityCategories.PROJECTILE.contains(entityType) || EntityCategories.OTHER
|
||||
.contains(entityType) || EntityCategories.HANGING.contains(entityType)) {
|
||||
count[CAP_MISC]++;
|
||||
} else if (EntityCategories.ANIMAL.contains(entityType) || EntityCategories.VILLAGER
|
||||
.contains(entityType) || EntityCategories.TAMEABLE.contains(entityType)) {
|
||||
count[CAP_MOB]++;
|
||||
count[CAP_ANIMAL]++;
|
||||
} else if (EntityCategories.VEHICLE.contains(entityType)) {
|
||||
count[CAP_VEHICLE]++;
|
||||
} else if (EntityCategories.HOSTILE.contains(entityType)) {
|
||||
count[CAP_MOB]++;
|
||||
count[CAP_MONSTER]++;
|
||||
}
|
||||
count[CAP_ENTITY]++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,381 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.util;
|
||||
|
||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.flag.implementations.AnimalAttackFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.AnimalCapFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.EntityCapFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.HangingBreakFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.HostileAttackFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.HostileCapFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.MiscBreakFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.MiscCapFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.MobCapFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.PveFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.PvpFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.TamedAttackFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.VehicleCapFlag;
|
||||
import com.plotsquared.core.util.EntityUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.entity.EntityCategories;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.projectiles.BlockProjectileSource;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class BukkitEntityUtil {
|
||||
|
||||
public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE =
|
||||
new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake");
|
||||
|
||||
public static boolean entityDamage(Entity damager, Entity victim) {
|
||||
return entityDamage(damager, victim, null);
|
||||
}
|
||||
|
||||
public static boolean entityDamage(Entity damager, Entity victim, EntityDamageEvent.DamageCause cause) {
|
||||
Location dloc = BukkitUtil.adapt(damager.getLocation());
|
||||
Location vloc = BukkitUtil.adapt(victim.getLocation());
|
||||
PlotArea dArea = dloc.getPlotArea();
|
||||
PlotArea vArea;
|
||||
if (dArea != null && dArea.contains(vloc.getX(), vloc.getZ())) {
|
||||
vArea = dArea;
|
||||
} else {
|
||||
vArea = vloc.getPlotArea();
|
||||
}
|
||||
if (dArea == null && vArea == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Plot dplot;
|
||||
if (dArea != null) {
|
||||
dplot = dArea.getPlot(dloc);
|
||||
} else {
|
||||
dplot = null;
|
||||
}
|
||||
Plot vplot;
|
||||
if (vArea != null) {
|
||||
vplot = vArea.getPlot(vloc);
|
||||
} else {
|
||||
vplot = null;
|
||||
}
|
||||
|
||||
Plot plot;
|
||||
String stub;
|
||||
boolean isPlot = true;
|
||||
if (dplot == null && vplot == null) {
|
||||
if (dArea == null) {
|
||||
return true;
|
||||
}
|
||||
plot = null;
|
||||
stub = "road";
|
||||
isPlot = false;
|
||||
} else {
|
||||
// Prioritize plots for close to seamless pvp zones
|
||||
if (victim.getTicksLived() > damager.getTicksLived()) {
|
||||
if (dplot == null || !(victim instanceof Player)) {
|
||||
if (vplot == null) {
|
||||
plot = dplot;
|
||||
} else {
|
||||
plot = vplot;
|
||||
}
|
||||
} else {
|
||||
plot = dplot;
|
||||
}
|
||||
} else if (dplot == null || !(victim instanceof Player)) {
|
||||
if (vplot == null) {
|
||||
plot = dplot;
|
||||
} else {
|
||||
plot = vplot;
|
||||
}
|
||||
} else if (vplot == null) {
|
||||
plot = dplot;
|
||||
} else {
|
||||
plot = vplot;
|
||||
}
|
||||
if (plot.hasOwner()) {
|
||||
stub = "other";
|
||||
} else {
|
||||
stub = "unowned";
|
||||
}
|
||||
}
|
||||
boolean roadFlags = vArea != null ? vArea.isRoadFlags() : dArea.isRoadFlags();
|
||||
PlotArea area = vArea != null ? vArea : dArea;
|
||||
|
||||
Player player;
|
||||
if (damager instanceof Player) { // attacker is player
|
||||
player = (Player) damager;
|
||||
} else if (damager instanceof Projectile) {
|
||||
Projectile projectile = (Projectile) damager;
|
||||
ProjectileSource shooter = projectile.getShooter();
|
||||
if (shooter instanceof Player) { // shooter is player
|
||||
player = (Player) shooter;
|
||||
} else { // shooter is not player
|
||||
if (shooter instanceof BlockProjectileSource) {
|
||||
Location sLoc = BukkitUtil
|
||||
.adapt(((BlockProjectileSource) shooter).getBlock().getLocation());
|
||||
dplot = dArea.getPlot(sLoc);
|
||||
}
|
||||
player = null;
|
||||
}
|
||||
} else { // Attacker is not player
|
||||
player = null;
|
||||
}
|
||||
if (player != null) {
|
||||
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
|
||||
|
||||
final com.sk89q.worldedit.world.entity.EntityType entityType;
|
||||
|
||||
// Create a fake entity type if the type does not have a name
|
||||
if (victim.getType().getName() == null) {
|
||||
entityType = FAKE_ENTITY_TYPE;
|
||||
} else {
|
||||
entityType = BukkitAdapter.adapt(victim.getType());
|
||||
}
|
||||
|
||||
if (EntityCategories.HANGING.contains(entityType)) { // hanging
|
||||
if (plot != null && (plot.getFlag(HangingBreakFlag.class) || plot
|
||||
.isAdded(plotPlayer.getUUID()))) {
|
||||
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
||||
if (!Permissions
|
||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", "plots.admin.build.other")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.destroy." + stub)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", "plots.admin.destroy." + stub)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} else if (victim.getType() == EntityType.ARMOR_STAND) {
|
||||
if (plot != null && (plot.getFlag(MiscBreakFlag.class) || plot
|
||||
.isAdded(plotPlayer.getUUID()))) {
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.destroy." + stub)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", "plots.admin.destroy." + stub)
|
||||
);
|
||||
if (plot != null) {
|
||||
plot.debug(player.getName()
|
||||
+ " could not break armor stand because misc-break = false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else if (EntityCategories.HOSTILE.contains(entityType)) {
|
||||
if (isPlot) {
|
||||
if (plot.getFlag(HostileAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
||||
.isAdded(plotPlayer.getUUID())) {
|
||||
return true;
|
||||
}
|
||||
} else if (roadFlags && (area.getRoadFlag(HostileAttackFlag.class) || area
|
||||
.getFlag(PveFlag.class))) {
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", "plots.admin.pve." + stub)
|
||||
);
|
||||
if (plot != null) {
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false OR hostile-attack = false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else if (EntityCategories.TAMEABLE.contains(entityType)) { // victim is tameable
|
||||
if (isPlot) {
|
||||
if (plot.getFlag(TamedAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
||||
.isAdded(plotPlayer.getUUID())) {
|
||||
return true;
|
||||
}
|
||||
} else if (roadFlags && (area.getRoadFlag(TamedAttackFlag.class) || area
|
||||
.getFlag(PveFlag.class))) {
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", "plots.admin.pve." + stub)
|
||||
);
|
||||
if (plot != null) {
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false OR tamed-attack = false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else if (EntityCategories.PLAYER.contains(entityType)) {
|
||||
if (isPlot) {
|
||||
if (!plot.getFlag(PvpFlag.class) && !Permissions
|
||||
.hasPermission(plotPlayer, "plots.admin.pvp." + stub)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", "plots.admin.pvp." + stub)
|
||||
);
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else if (roadFlags && area.getRoadFlag(PvpFlag.class)) {
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pvp." + stub)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", "plots.admin.pvp." + stub)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} else if (EntityCategories.ANIMAL.contains(entityType)) { // victim is animal
|
||||
if (isPlot) {
|
||||
if (plot.getFlag(AnimalAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
||||
.isAdded(plotPlayer.getUUID())) {
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false OR animal-attack = false");
|
||||
return true;
|
||||
}
|
||||
} else if (roadFlags && (area.getRoadFlag(AnimalAttackFlag.class) || area
|
||||
.getFlag(PveFlag.class))) {
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", "plots.admin.pve." + stub)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (EntityCategories.VEHICLE
|
||||
.contains(entityType)) { // Vehicles are managed in vehicle destroy event
|
||||
return true;
|
||||
} else { // victim is something else
|
||||
if (isPlot) {
|
||||
if (plot.getFlag(PveFlag.class) || plot.isAdded(plotPlayer.getUUID())) {
|
||||
return true;
|
||||
}
|
||||
} else if (roadFlags && area.getRoadFlag(PveFlag.class)) {
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", "plots.admin.pve." + stub)
|
||||
);
|
||||
if (plot != null) {
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (dplot != null && (!dplot.equals(vplot) || Objects
|
||||
.equals(dplot.getOwnerAbs(), vplot.getOwnerAbs()))) {
|
||||
return vplot != null && vplot.getFlag(PveFlag.class);
|
||||
}
|
||||
//disable the firework damage. too much of a headache to support at the moment.
|
||||
if (vplot != null) {
|
||||
if (EntityDamageEvent.DamageCause.ENTITY_EXPLOSION == cause
|
||||
&& damager.getType() == EntityType.FIREWORK) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (vplot == null && roadFlags && area.getRoadFlag(PveFlag.class)) {
|
||||
return true;
|
||||
}
|
||||
return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow
|
||||
&& !(victim instanceof Creature)));
|
||||
}
|
||||
|
||||
public static boolean checkEntity(Entity entity, Plot plot) {
|
||||
if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot.getArea()
|
||||
.getFlagContainer().getFlagMap().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final com.sk89q.worldedit.world.entity.EntityType entityType =
|
||||
BukkitAdapter.adapt(entity.getType());
|
||||
|
||||
if (EntityCategories.PLAYER.contains(entityType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (EntityCategories.PROJECTILE.contains(entityType) || EntityCategories.OTHER
|
||||
.contains(entityType) || EntityCategories.HANGING.contains(entityType)) {
|
||||
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED,
|
||||
MiscCapFlag.MISC_CAP_UNLIMITED);
|
||||
}
|
||||
|
||||
// Has to go go before vehicle as horses are both
|
||||
// animals and vehicles
|
||||
if (EntityCategories.ANIMAL.contains(entityType) || EntityCategories.VILLAGER
|
||||
.contains(entityType) || EntityCategories.TAMEABLE.contains(entityType)) {
|
||||
return EntityUtil
|
||||
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
|
||||
AnimalCapFlag.ANIMAL_CAP_UNLIMITED);
|
||||
}
|
||||
|
||||
if (EntityCategories.HOSTILE.contains(entityType)) {
|
||||
return EntityUtil
|
||||
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
|
||||
HostileCapFlag.HOSTILE_CAP_UNLIMITED);
|
||||
}
|
||||
|
||||
if (EntityCategories.VEHICLE.contains(entityType)) {
|
||||
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED,
|
||||
VehicleCapFlag.VEHICLE_CAP_UNLIMITED);
|
||||
}
|
||||
|
||||
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED);
|
||||
}
|
||||
|
||||
}
|
@ -27,29 +27,24 @@ package com.plotsquared.bukkit.util;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.plotsquared.bukkit.BukkitPlatform;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.generator.AugmentedUtils;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.location.PlotLoc;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotManager;
|
||||
import com.plotsquared.core.queue.LocalBlockQueue;
|
||||
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
|
||||
import com.plotsquared.core.queue.GlobalBlockQueue;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.queue.ScopedQueueCoordinator;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.RegionUtil;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.entity.EntityCategories;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.task.TaskTime;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import io.papermc.lib.PaperLib;
|
||||
@ -62,16 +57,11 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.plotsquared.core.util.entity.EntityCategories.CAP_ANIMAL;
|
||||
import static com.plotsquared.core.util.entity.EntityCategories.CAP_ENTITY;
|
||||
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MISC;
|
||||
@ -79,44 +69,17 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_MOB;
|
||||
import static com.plotsquared.core.util.entity.EntityCategories.CAP_MONSTER;
|
||||
import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
||||
|
||||
@Singleton public class BukkitRegionManager extends RegionManager {
|
||||
@Singleton
|
||||
public class BukkitRegionManager extends RegionManager {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitRegionManager.class.getSimpleName());
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger("P2/" + BukkitRegionManager.class.getSimpleName());
|
||||
private final GlobalBlockQueue blockQueue;
|
||||
|
||||
@Inject public BukkitRegionManager(@Nonnull final ChunkManager chunkManager) {
|
||||
super(chunkManager);
|
||||
}
|
||||
|
||||
public static boolean isIn(CuboidRegion region, int x, int z) {
|
||||
return x >= region.getMinimumPoint().getX() && x <= region.getMaximumPoint().getX()
|
||||
&& z >= region.getMinimumPoint().getZ() && z <= region.getMaximumPoint().getZ();
|
||||
}
|
||||
|
||||
@Override public Set<BlockVector2> getChunkChunks(String world) {
|
||||
Set<BlockVector2> chunks = super.getChunkChunks(world);
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world)).getLoadedChunks()) {
|
||||
BlockVector2 loc = BlockVector2.at(chunk.getX() >> 5, chunk.getZ() >> 5);
|
||||
chunks.add(loc);
|
||||
}
|
||||
} else {
|
||||
final Semaphore semaphore = new Semaphore(1);
|
||||
try {
|
||||
semaphore.acquire();
|
||||
Bukkit.getScheduler().runTask(BukkitPlatform.getPlugin(BukkitPlatform.class), () -> {
|
||||
for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world))
|
||||
.getLoadedChunks()) {
|
||||
BlockVector2 loc = BlockVector2.at(chunk.getX() >> 5, chunk.getZ() >> 5);
|
||||
chunks.add(loc);
|
||||
}
|
||||
semaphore.release();
|
||||
});
|
||||
semaphore.acquireUninterruptibly();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return chunks;
|
||||
@Inject
|
||||
public BukkitRegionManager(@Nonnull WorldUtil worldUtil, @Nonnull GlobalBlockQueue blockQueue) {
|
||||
super(worldUtil, blockQueue);
|
||||
this.blockQueue = blockQueue;
|
||||
}
|
||||
|
||||
@Override public boolean handleClear(Plot plot, Runnable whenDone, PlotManager manager) {
|
||||
@ -131,7 +94,6 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
||||
}
|
||||
PlotArea area = plot.getArea();
|
||||
World world = BukkitUtil.getWorld(area.getWorldName());
|
||||
|
||||
Location bot = plot.getBottomAbs();
|
||||
Location top = plot.getTopAbs();
|
||||
int bx = bot.getX() >> 4;
|
||||
@ -199,65 +161,9 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean copyRegion(Location pos1, Location pos2, Location newPos,
|
||||
final Runnable whenDone) {
|
||||
final int relX = newPos.getX() - pos1.getX();
|
||||
final int relZ = newPos.getZ() - pos1.getZ();
|
||||
|
||||
final CuboidRegion region =
|
||||
RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||
final World oldWorld = Bukkit.getWorld(pos1.getWorldName());
|
||||
final BukkitWorld oldBukkitWorld = new BukkitWorld(oldWorld);
|
||||
final World newWorld = Bukkit.getWorld(newPos.getWorldName());
|
||||
assert newWorld != null;
|
||||
assert oldWorld != null;
|
||||
final String newWorldName = newWorld.getName();
|
||||
final ContentMap map = new ContentMap();
|
||||
final LocalBlockQueue queue = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(newWorldName, false);
|
||||
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
|
||||
@Override public void run(int[] value) {
|
||||
int bx = value[2];
|
||||
int bz = value[3];
|
||||
int tx = value[4];
|
||||
int tz = value[5];
|
||||
BlockVector2 loc = BlockVector2.at(value[0], value[1]);
|
||||
int cxx = loc.getX() << 4;
|
||||
int czz = loc.getZ() << 4;
|
||||
PaperLib.getChunkAtAsync(oldWorld, loc.getX(), loc.getZ())
|
||||
.thenAccept(chunk1 -> map.saveEntitiesIn(chunk1, region)).thenRun(() -> {
|
||||
for (int x = bx & 15; x <= (tx & 15); x++) {
|
||||
for (int z = bz & 15; z <= (tz & 15); z++) {
|
||||
map.saveBlocks(oldBukkitWorld, 256, cxx + x, czz + z, relX, relZ);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, () -> {
|
||||
for (Entry<PlotLoc, BaseBlock[]> entry : map.allBlocks.entrySet()) {
|
||||
PlotLoc loc = entry.getKey();
|
||||
BaseBlock[] blocks = entry.getValue();
|
||||
for (int y = 0; y < blocks.length; y++) {
|
||||
if (blocks[y] != null) {
|
||||
BaseBlock block = blocks[y];
|
||||
queue.setBlock(loc.getX(), y, loc.getZ(), block);
|
||||
}
|
||||
}
|
||||
}
|
||||
queue.enqueue();
|
||||
PlotSquared.platform().getGlobalBlockQueue().addEmptyTask(() -> {
|
||||
//map.restoreBlocks(newWorld, 0, 0);
|
||||
map.restoreEntities(newWorld, relX, relZ);
|
||||
TaskManager.runTask(whenDone);
|
||||
});
|
||||
}, 5);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean regenerateRegion(final Location pos1, final Location pos2,
|
||||
@Override public boolean regenerateRegion(final Location pos1, final Location pos2,
|
||||
final boolean ignoreAugment, final Runnable whenDone) {
|
||||
final String world = pos1.getWorldName();
|
||||
final BukkitWorld world = new BukkitWorld((World) pos1.getWorld());
|
||||
|
||||
final int p1x = pos1.getX();
|
||||
final int p1z = pos1.getZ();
|
||||
@ -268,144 +174,123 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
||||
final int tcx = p2x >> 4;
|
||||
final int tcz = p2z >> 4;
|
||||
|
||||
final List<BlockVector2> chunks = new ArrayList<>();
|
||||
final QueueCoordinator queue = blockQueue.getNewQueue(world);
|
||||
final QueueCoordinator regenQueue = blockQueue.getNewQueue(world);
|
||||
queue.addReadChunks(
|
||||
new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()).getChunks());
|
||||
queue.setChunkConsumer(chunk -> {
|
||||
|
||||
for (int x = bcx; x <= tcx; x++) {
|
||||
for (int z = bcz; z <= tcz; z++) {
|
||||
chunks.add(BlockVector2.at(x, z));
|
||||
int x = chunk.getX();
|
||||
int z = chunk.getZ();
|
||||
int xxb = x << 4;
|
||||
int zzb = z << 4;
|
||||
int xxt = xxb + 15;
|
||||
int zzt = zzb + 15;
|
||||
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
|
||||
AugmentedUtils
|
||||
.bypass(ignoreAugment, () -> regenQueue.regenChunk(chunk.getX(), chunk.getZ()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
final World worldObj = Bukkit.getWorld(world);
|
||||
checkNotNull(worldObj, "Critical error during regeneration.");
|
||||
final BukkitWorld bukkitWorldObj = new BukkitWorld(worldObj);
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override public void run() {
|
||||
long start = System.currentTimeMillis();
|
||||
while (!chunks.isEmpty() && System.currentTimeMillis() - start < 5) {
|
||||
final BlockVector2 chunk = chunks.remove(0);
|
||||
int x = chunk.getX();
|
||||
int z = chunk.getZ();
|
||||
int xxb = x << 4;
|
||||
int zzb = z << 4;
|
||||
int xxt = xxb + 15;
|
||||
int zzt = zzb + 15;
|
||||
PaperLib.getChunkAtAsync(worldObj, x, z, false).thenAccept(chunkObj -> {
|
||||
if (chunkObj == null) {
|
||||
return;
|
||||
}
|
||||
final LocalBlockQueue queue = PlotSquared.platform().getGlobalBlockQueue()
|
||||
.getNewQueue(world, false);
|
||||
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
|
||||
AugmentedUtils.bypass(ignoreAugment,
|
||||
() -> queue.regenChunkSafe(chunk.getX(), chunk.getZ()));
|
||||
return;
|
||||
}
|
||||
boolean checkX1 = false;
|
||||
boolean checkX1 = false;
|
||||
|
||||
int xxb2;
|
||||
int xxb2;
|
||||
|
||||
if (x == bcx) {
|
||||
xxb2 = p1x - 1;
|
||||
checkX1 = true;
|
||||
} else {
|
||||
xxb2 = xxb;
|
||||
}
|
||||
boolean checkX2 = false;
|
||||
int xxt2;
|
||||
if (x == tcx) {
|
||||
xxt2 = p2x + 1;
|
||||
checkX2 = true;
|
||||
} else {
|
||||
xxt2 = xxt;
|
||||
}
|
||||
boolean checkZ1 = false;
|
||||
int zzb2;
|
||||
if (z == bcz) {
|
||||
zzb2 = p1z - 1;
|
||||
checkZ1 = true;
|
||||
} else {
|
||||
zzb2 = zzb;
|
||||
}
|
||||
boolean checkZ2 = false;
|
||||
int zzt2;
|
||||
if (z == tcz) {
|
||||
zzt2 = p2z + 1;
|
||||
checkZ2 = true;
|
||||
} else {
|
||||
zzt2 = zzt;
|
||||
}
|
||||
final ContentMap map = new ContentMap();
|
||||
if (checkX1) {
|
||||
map.saveRegion(bukkitWorldObj, xxb, xxb2, zzb2, zzt2); //
|
||||
}
|
||||
if (checkX2) {
|
||||
map.saveRegion(bukkitWorldObj, xxt2, xxt, zzb2, zzt2); //
|
||||
}
|
||||
if (checkZ1) {
|
||||
map.saveRegion(bukkitWorldObj, xxb2, xxt2, zzb, zzb2); //
|
||||
}
|
||||
if (checkZ2) {
|
||||
map.saveRegion(bukkitWorldObj, xxb2, xxt2, zzt2, zzt); //
|
||||
}
|
||||
if (checkX1 && checkZ1) {
|
||||
map.saveRegion(bukkitWorldObj, xxb, xxb2, zzb, zzb2); //
|
||||
}
|
||||
if (checkX2 && checkZ1) {
|
||||
map.saveRegion(bukkitWorldObj, xxt2, xxt, zzb, zzb2); // ?
|
||||
}
|
||||
if (checkX1 && checkZ2) {
|
||||
map.saveRegion(bukkitWorldObj, xxb, xxb2, zzt2, zzt); // ?
|
||||
}
|
||||
if (checkX2 && checkZ2) {
|
||||
map.saveRegion(bukkitWorldObj, xxt2, xxt, zzt2, zzt); //
|
||||
}
|
||||
CuboidRegion currentPlotClear = RegionUtil
|
||||
.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||
map.saveEntitiesOut(chunkObj, currentPlotClear);
|
||||
AugmentedUtils.bypass(ignoreAugment, () -> ChunkManager
|
||||
.setChunkInPlotArea(null, new RunnableVal<ScopedLocalBlockQueue>() {
|
||||
@Override public void run(ScopedLocalBlockQueue value) {
|
||||
Location min = value.getMin();
|
||||
int bx = min.getX();
|
||||
int bz = min.getZ();
|
||||
for (int x1 = 0; x1 < 16; x1++) {
|
||||
for (int z1 = 0; z1 < 16; z1++) {
|
||||
PlotLoc plotLoc = new PlotLoc(bx + x1, bz + z1);
|
||||
BaseBlock[] ids = map.allBlocks.get(plotLoc);
|
||||
if (ids != null) {
|
||||
for (int y = 0;
|
||||
y < Math.min(128, ids.length); y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
} else {
|
||||
value.setBlock(x1, y, z1,
|
||||
BlockTypes.AIR.getDefaultState());
|
||||
}
|
||||
}
|
||||
for (int y = Math.min(128, ids.length);
|
||||
y < ids.length; y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (x == bcx) {
|
||||
xxb2 = p1x - 1;
|
||||
checkX1 = true;
|
||||
} else {
|
||||
xxb2 = xxb;
|
||||
}
|
||||
boolean checkX2 = false;
|
||||
int xxt2;
|
||||
if (x == tcx) {
|
||||
xxt2 = p2x + 1;
|
||||
checkX2 = true;
|
||||
} else {
|
||||
xxt2 = xxt;
|
||||
}
|
||||
boolean checkZ1 = false;
|
||||
int zzb2;
|
||||
if (z == bcz) {
|
||||
zzb2 = p1z - 1;
|
||||
checkZ1 = true;
|
||||
} else {
|
||||
zzb2 = zzb;
|
||||
}
|
||||
boolean checkZ2 = false;
|
||||
int zzt2;
|
||||
if (z == tcz) {
|
||||
zzt2 = p2z + 1;
|
||||
checkZ2 = true;
|
||||
} else {
|
||||
zzt2 = zzt;
|
||||
}
|
||||
final ContentMap map = new ContentMap();
|
||||
if (checkX1) {
|
||||
map.saveRegion(world, xxb, xxb2, zzb2, zzt2); //
|
||||
}
|
||||
if (checkX2) {
|
||||
map.saveRegion(world, xxt2, xxt, zzb2, zzt2); //
|
||||
}
|
||||
if (checkZ1) {
|
||||
map.saveRegion(world, xxb2, xxt2, zzb, zzb2); //
|
||||
}
|
||||
if (checkZ2) {
|
||||
map.saveRegion(world, xxb2, xxt2, zzt2, zzt); //
|
||||
}
|
||||
if (checkX1 && checkZ1) {
|
||||
map.saveRegion(world, xxb, xxb2, zzb, zzb2); //
|
||||
}
|
||||
if (checkX2 && checkZ1) {
|
||||
map.saveRegion(world, xxt2, xxt, zzb, zzb2); // ?
|
||||
}
|
||||
if (checkX1 && checkZ2) {
|
||||
map.saveRegion(world, xxb, xxb2, zzt2, zzt); // ?
|
||||
}
|
||||
if (checkX2 && checkZ2) {
|
||||
map.saveRegion(world, xxt2, xxt, zzt2, zzt); //
|
||||
}
|
||||
CuboidRegion currentPlotClear =
|
||||
RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||
map.saveEntitiesOut(Bukkit.getWorld(world.getName()).getChunkAt(x, z),
|
||||
currentPlotClear);
|
||||
AugmentedUtils.bypass(ignoreAugment, () -> ChunkManager
|
||||
.setChunkInPlotArea(null, new RunnableVal<ScopedQueueCoordinator>() {
|
||||
@Override public void run(ScopedQueueCoordinator value) {
|
||||
Location min = value.getMin();
|
||||
int bx = min.getX();
|
||||
int bz = min.getZ();
|
||||
for (int x1 = 0; x1 < 16; x1++) {
|
||||
for (int z1 = 0; z1 < 16; z1++) {
|
||||
PlotLoc plotLoc = new PlotLoc(bx + x1, bz + z1);
|
||||
BaseBlock[] ids = map.allBlocks.get(plotLoc);
|
||||
if (ids != null) {
|
||||
for (int y = 0; y < Math.min(128, ids.length); y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
} else {
|
||||
value.setBlock(x1, y, z1,
|
||||
BlockTypes.AIR.getDefaultState());
|
||||
}
|
||||
}
|
||||
for (int y = Math.min(128, ids.length); y < ids.length; y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, world, chunk));
|
||||
//map.restoreBlocks(worldObj, 0, 0);
|
||||
map.restoreEntities(worldObj, 0, 0);
|
||||
});
|
||||
}
|
||||
if (!chunks.isEmpty()) {
|
||||
TaskManager.runTaskLater(this, TaskTime.ticks(1L));
|
||||
} else {
|
||||
TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, world.getName(), chunk));
|
||||
//map.restoreBlocks(worldObj, 0, 0);
|
||||
map.restoreEntities(Bukkit.getWorld(world.getName()), 0, 0);
|
||||
});
|
||||
regenQueue.setCompleteTask(whenDone);
|
||||
queue.setCompleteTask(regenQueue::enqueue);
|
||||
queue.enqueue();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -438,59 +323,6 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void swap(Location bot1, Location top1, Location bot2, Location top2,
|
||||
final Runnable whenDone) {
|
||||
CuboidRegion region1 =
|
||||
RegionUtil.createRegion(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ());
|
||||
CuboidRegion region2 =
|
||||
RegionUtil.createRegion(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ());
|
||||
final World world1 = Bukkit.getWorld(bot1.getWorldName());
|
||||
final World world2 = Bukkit.getWorld(bot2.getWorldName());
|
||||
checkNotNull(world1, "Critical error during swap.");
|
||||
checkNotNull(world2, "Critical error during swap.");
|
||||
int relX = bot2.getX() - bot1.getX();
|
||||
int relZ = bot2.getZ() - bot1.getZ();
|
||||
|
||||
final ArrayDeque<ContentMap> maps = new ArrayDeque<>();
|
||||
|
||||
for (int x = bot1.getX() >> 4; x <= top1.getX() >> 4; x++) {
|
||||
for (int z = bot1.getZ() >> 4; z <= top1.getZ() >> 4; z++) {
|
||||
Chunk chunk1 = world1.getChunkAt(x, z);
|
||||
Chunk chunk2 = world2.getChunkAt(x + (relX >> 4), z + (relZ >> 4));
|
||||
maps.add(
|
||||
BukkitChunkManager.swapChunk(world1, world2, chunk1, chunk2, region1, region2));
|
||||
}
|
||||
}
|
||||
PlotSquared.platform().getGlobalBlockQueue().addEmptyTask(() -> {
|
||||
for (ContentMap map : maps) {
|
||||
map.restoreEntities(world1, 0, 0);
|
||||
TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(final CuboidRegion region, final int extendBiome, final BiomeType biome,
|
||||
final String world, final Runnable whenDone) {
|
||||
Location pos1 = Location.at(world, region.getMinimumPoint().getX() - extendBiome,
|
||||
region.getMinimumPoint().getY(), region.getMinimumPoint().getZ() - extendBiome);
|
||||
Location pos2 = Location.at(world, region.getMaximumPoint().getX() + extendBiome,
|
||||
region.getMaximumPoint().getY(), region.getMaximumPoint().getZ() + extendBiome);
|
||||
final LocalBlockQueue queue = PlotSquared.platform().getGlobalBlockQueue()
|
||||
.getNewQueue(world, false);
|
||||
|
||||
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
|
||||
@Override public void run(int[] value) {
|
||||
BlockVector2 loc = BlockVector2.at(value[0], value[1]);
|
||||
PlotSquared.platform().getChunkManager().loadChunk(world, loc, false).thenRun(() -> {
|
||||
WorldUtil.setBiome(world, value[2], value[3], value[4], value[5], biome);
|
||||
queue.refreshChunk(value[0], value[1]);
|
||||
});
|
||||
}
|
||||
}, whenDone, 5);
|
||||
}
|
||||
|
||||
private void count(int[] count, Entity entity) {
|
||||
final com.sk89q.worldedit.world.entity.EntityType entityType =
|
||||
BukkitAdapter.adapt(entity.getType());
|
||||
|
@ -25,7 +25,6 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit.util;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.plotsquared.bukkit.BukkitPlatform;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||
@ -38,7 +37,6 @@ import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.util.BlockUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.StringComparison;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
@ -106,12 +104,14 @@ import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.IntConsumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||
@Singleton public class BukkitUtil extends WorldUtil {
|
||||
@Singleton
|
||||
public class BukkitUtil extends WorldUtil {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitUtil.class.getSimpleName());
|
||||
|
||||
@ -121,10 +121,6 @@ import java.util.stream.Stream;
|
||||
|
||||
private final Collection<BlockType> tileEntityTypes = new HashSet<>();
|
||||
|
||||
@Inject public BukkitUtil(@Nonnull final RegionManager regionManager) {
|
||||
super(regionManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a Bukkit {@link Player} into a PlotSquared {@link PlotPlayer}
|
||||
*
|
||||
@ -144,8 +140,9 @@ import java.util.stream.Stream;
|
||||
* @return PlotSquared location
|
||||
*/
|
||||
@Nonnull public static Location adapt(@Nonnull final org.bukkit.Location location) {
|
||||
return Location.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()),
|
||||
MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()));
|
||||
return Location
|
||||
.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()), MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()),
|
||||
MathMan.roundInt(location.getZ()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -156,9 +153,9 @@ import java.util.stream.Stream;
|
||||
* @return PlotSquared location
|
||||
*/
|
||||
@Nonnull public static Location adaptComplete(@Nonnull final org.bukkit.Location location) {
|
||||
return Location.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()),
|
||||
MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()), location.getYaw(),
|
||||
location.getPitch());
|
||||
return Location
|
||||
.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()), MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()),
|
||||
MathMan.roundInt(location.getZ()), location.getYaw(), location.getPitch());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -169,8 +166,7 @@ import java.util.stream.Stream;
|
||||
* @return Bukkit location
|
||||
*/
|
||||
@Nonnull public static org.bukkit.Location adapt(@Nonnull final Location location) {
|
||||
return new org.bukkit.Location((World) location.getWorld().getPlatformWorld(), location.getX(),
|
||||
location.getY(), location.getZ());
|
||||
return new org.bukkit.Location((World) location.getWorld().getPlatformWorld(), location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,30 +179,24 @@ import java.util.stream.Stream;
|
||||
return Bukkit.getWorld(string);
|
||||
}
|
||||
|
||||
private static void ensureLoaded(@Nonnull final String world, final int x, final int z,
|
||||
@Nonnull final Consumer<Chunk> chunkConsumer) {
|
||||
PaperLib.getChunkAtAsync(Objects.requireNonNull(getWorld(world)),
|
||||
x >> 4, z >> 4, true)
|
||||
private static void ensureLoaded(@Nonnull final String world, final int x, final int z, @Nonnull final Consumer<Chunk> chunkConsumer) {
|
||||
PaperLib.getChunkAtAsync(Objects.requireNonNull(getWorld(world)), x >> 4, z >> 4, true)
|
||||
.thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk));
|
||||
}
|
||||
|
||||
private static void ensureLoaded(@Nonnull final Location location, @Nonnull final Consumer<Chunk> chunkConsumer) {
|
||||
PaperLib.getChunkAtAsync(adapt(location), true)
|
||||
.thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk));
|
||||
PaperLib.getChunkAtAsync(adapt(location), true).thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk));
|
||||
}
|
||||
|
||||
private static <T> void ensureMainThread(@Nonnull final Consumer<T> consumer,
|
||||
@Nonnull final T value) {
|
||||
private static <T> void ensureMainThread(@Nonnull final Consumer<T> consumer, @Nonnull final T value) {
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
consumer.accept(value);
|
||||
} else {
|
||||
Bukkit.getScheduler()
|
||||
.runTask(BukkitPlatform.getPlugin(BukkitPlatform.class), () -> consumer.accept(value));
|
||||
Bukkit.getScheduler().runTask(BukkitPlatform.getPlugin(BukkitPlatform.class), () -> consumer.accept(value));
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean isBlockSame(@Nonnull final BlockState block1,
|
||||
@Nonnull final BlockState block2) {
|
||||
@Override public boolean isBlockSame(@Nonnull final BlockState block1, @Nonnull final BlockState block2) {
|
||||
if (block1.equals(block2)) {
|
||||
return true;
|
||||
}
|
||||
@ -219,20 +209,15 @@ import java.util.stream.Stream;
|
||||
return getWorld(worldName) != null;
|
||||
}
|
||||
|
||||
@Override public void getBiome(@Nonnull final String world, final int x,
|
||||
final int z, @Nonnull final Consumer<BiomeType> result) {
|
||||
ensureLoaded(world, x, z,
|
||||
chunk -> result.accept(BukkitAdapter.adapt(getWorld(world).getBiome(x, z))));
|
||||
@Override public void getBiome(@Nonnull final String world, final int x, final int z, @Nonnull final Consumer<BiomeType> result) {
|
||||
ensureLoaded(world, x, z, chunk -> result.accept(BukkitAdapter.adapt(getWorld(world).getBiome(x, z))));
|
||||
}
|
||||
|
||||
@Override @Nonnull public BiomeType getBiomeSynchronous(@Nonnull final String world,
|
||||
final int x, final int z) {
|
||||
@Override @Nonnull public BiomeType getBiomeSynchronous(@Nonnull final String world, final int x, final int z) {
|
||||
return BukkitAdapter.adapt(Objects.requireNonNull(getWorld(world)).getBiome(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getHighestBlock(@Nonnull final String world, final int x, final int z,
|
||||
@Nonnull final IntConsumer result) {
|
||||
@Override public void getHighestBlock(@Nonnull final String world, final int x, final int z, @Nonnull final IntConsumer result) {
|
||||
ensureLoaded(world, x, z, chunk -> {
|
||||
final World bukkitWorld = Objects.requireNonNull(getWorld(world));
|
||||
// Skip top and bottom block
|
||||
@ -258,9 +243,7 @@ import java.util.stream.Stream;
|
||||
});
|
||||
}
|
||||
|
||||
@Override @Nonnegative
|
||||
public int getHighestBlockSynchronous(@Nonnull final String world,
|
||||
final int x, final int z) {
|
||||
@Override @Nonnegative public int getHighestBlockSynchronous(@Nonnull final String world, final int x, final int z) {
|
||||
final World bukkitWorld = Objects.requireNonNull(getWorld(world));
|
||||
// Skip top and bottom block
|
||||
int air = 1;
|
||||
@ -282,10 +265,8 @@ import java.util.stream.Stream;
|
||||
return bukkitWorld.getMaxHeight() - 1;
|
||||
}
|
||||
|
||||
@Override @Nonnull
|
||||
public String[] getSignSynchronous(@Nonnull final Location location) {
|
||||
Block block = Objects.requireNonNull(getWorld(location.getWorldName()))
|
||||
.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
@Override @Nonnull public String[] getSignSynchronous(@Nonnull final Location location) {
|
||||
Block block = Objects.requireNonNull(getWorld(location.getWorldName())).getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
try {
|
||||
return TaskManager.getPlatformImplementation().sync(() -> {
|
||||
if (block.getState() instanceof Sign) {
|
||||
@ -300,11 +281,9 @@ import java.util.stream.Stream;
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override @Nonnull
|
||||
public Location getSpawn(@Nonnull final String world) {
|
||||
@Override @Nonnull public Location getSpawn(@Nonnull final String world) {
|
||||
final org.bukkit.Location temp = getWorld(world).getSpawnLocation();
|
||||
return Location.at(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(),
|
||||
temp.getYaw(), temp.getPitch());
|
||||
return Location.at(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(), temp.getYaw(), temp.getPitch());
|
||||
}
|
||||
|
||||
@Override public void setSpawn(@Nonnull final Location location) {
|
||||
@ -362,16 +341,12 @@ import java.util.stream.Stream;
|
||||
});
|
||||
}
|
||||
|
||||
@Override @Nonnull
|
||||
public StringComparison<BlockState>.ComparisonResult getClosestBlock(@Nonnull String name) {
|
||||
@Override @Nonnull public StringComparison<BlockState>.ComparisonResult getClosestBlock(@Nonnull String name) {
|
||||
BlockState state = BlockUtil.get(name);
|
||||
return new StringComparison<BlockState>().new ComparisonResult(1, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiomes(@Nonnull final String worldName,
|
||||
@Nonnull final CuboidRegion region,
|
||||
@Nonnull final BiomeType biomeType) {
|
||||
@Override public void setBiomes(@Nonnull final String worldName, @Nonnull final CuboidRegion region, @Nonnull final BiomeType biomeType) {
|
||||
final World world = getWorld(worldName);
|
||||
if (world == null) {
|
||||
logger.warn("[P2] An error occured while setting the biome because the world was null", new RuntimeException());
|
||||
@ -379,8 +354,7 @@ import java.util.stream.Stream;
|
||||
}
|
||||
final Biome biome = BukkitAdapter.adapt(biomeType);
|
||||
for (int x = region.getMinimumPoint().getX(); x <= region.getMaximumPoint().getX(); x++) {
|
||||
for (int z = region.getMinimumPoint().getZ();
|
||||
z <= region.getMaximumPoint().getZ(); z++) {
|
||||
for (int z = region.getMinimumPoint().getZ(); z <= region.getMaximumPoint().getZ(); z++) {
|
||||
if (world.getBiome(x, z) != biome) {
|
||||
world.setBiome(x, z, biome);
|
||||
}
|
||||
@ -392,50 +366,41 @@ import java.util.stream.Stream;
|
||||
return new BukkitWorld(Bukkit.getWorld(world));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBlock(@Nonnull final Location location,
|
||||
@Nonnull final Consumer<BlockState> result) {
|
||||
@Override public void refreshChunk(int x, int z, String world) {
|
||||
Bukkit.getWorld(world).refreshChunk(x, z);
|
||||
}
|
||||
|
||||
@Override public void getBlock(@Nonnull final Location location, @Nonnull final Consumer<BlockState> result) {
|
||||
ensureLoaded(location, chunk -> {
|
||||
final World world = getWorld(location.getWorldName());
|
||||
final Block block = Objects.requireNonNull(world)
|
||||
.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
result.accept(Objects.requireNonNull(BukkitAdapter
|
||||
.asBlockType(block.getType())).getDefaultState());
|
||||
final Block block = Objects.requireNonNull(world).getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
result.accept(Objects.requireNonNull(BukkitAdapter.asBlockType(block.getType())).getDefaultState());
|
||||
});
|
||||
}
|
||||
|
||||
@Override @Nonnull public BlockState getBlockSynchronous(@Nonnull final Location location) {
|
||||
final World world = getWorld(location.getWorldName());
|
||||
final Block block = Objects.requireNonNull(world)
|
||||
.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
return Objects.requireNonNull(BukkitAdapter
|
||||
.asBlockType(block.getType())).getDefaultState();
|
||||
final Block block = Objects.requireNonNull(world).getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
return Objects.requireNonNull(BukkitAdapter.asBlockType(block.getType())).getDefaultState();
|
||||
}
|
||||
|
||||
@Override @Nonnegative public double getHealth(@Nonnull final PlotPlayer player) {
|
||||
return Objects.requireNonNull(Bukkit
|
||||
.getPlayer(player.getUUID())).getHealth();
|
||||
return Objects.requireNonNull(Bukkit.getPlayer(player.getUUID())).getHealth();
|
||||
}
|
||||
|
||||
@Override @Nonnegative public int getFoodLevel(@Nonnull final PlotPlayer<?> player) {
|
||||
return Objects.requireNonNull(Bukkit.getPlayer(player.getUUID()))
|
||||
.getFoodLevel();
|
||||
return Objects.requireNonNull(Bukkit.getPlayer(player.getUUID())).getFoodLevel();
|
||||
}
|
||||
|
||||
@Override public void setHealth(@Nonnull final PlotPlayer<?> player,
|
||||
@Nonnegative final double health) {
|
||||
Objects.requireNonNull(Bukkit.getPlayer(player.getUUID()))
|
||||
.setHealth(health);
|
||||
@Override public void setHealth(@Nonnull final PlotPlayer<?> player, @Nonnegative final double health) {
|
||||
Objects.requireNonNull(Bukkit.getPlayer(player.getUUID())).setHealth(health);
|
||||
}
|
||||
|
||||
@Override public void setFoodLevel(@Nonnull final PlotPlayer<?> player,
|
||||
@Nonnegative final int foodLevel) {
|
||||
@Override public void setFoodLevel(@Nonnull final PlotPlayer<?> player, @Nonnegative final int foodLevel) {
|
||||
Bukkit.getPlayer(player.getUUID()).setFoodLevel(foodLevel);
|
||||
}
|
||||
|
||||
@Override @Nonnull
|
||||
public Set<com.sk89q.worldedit.world.entity.EntityType> getTypesInCategory(
|
||||
@Nonnull final String category) {
|
||||
@Override @Nonnull public Set<com.sk89q.worldedit.world.entity.EntityType> getTypesInCategory(@Nonnull final String category) {
|
||||
final Collection<Class<?>> allowedInterfaces = new HashSet<>();
|
||||
switch (category) {
|
||||
case "animal": {
|
||||
@ -524,28 +489,45 @@ import java.util.stream.Stream;
|
||||
tileEntityTypes.addAll(BlockCategories.FLOWER_POTS.getAll());
|
||||
// Individual Types
|
||||
// Add these from strings
|
||||
Stream.of("barrel", "beacon", "beehive", "bee_nest", "bell", "blast_furnace",
|
||||
"brewing_stand", "campfire", "chest", "ender_chest", "trapped_chest",
|
||||
"command_block", "end_gateway", "hopper", "jigsaw", "jubekox",
|
||||
"lectern", "note_block", "black_shulker_box", "blue_shulker_box",
|
||||
"brown_shulker_box", "cyan_shulker_box", "gray_shulker_box", "green_shulker_box",
|
||||
"light_blue_shulker_box", "light_gray_shulker_box", "lime_shulker_box",
|
||||
"magenta_shulker_box", "orange_shulker_box", "pink_shulker_box",
|
||||
"purple_shulker_box", "red_shulker_box", "shulker_box", "white_shulker_box",
|
||||
"yellow_shulker_box", "smoker", "structure_block", "structure_void")
|
||||
.map(BlockTypes::get)
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(tileEntityTypes::add);
|
||||
Stream.of("barrel", "beacon", "beehive", "bee_nest", "bell", "blast_furnace", "brewing_stand", "campfire", "chest", "ender_chest",
|
||||
"trapped_chest", "command_block", "end_gateway", "hopper", "jigsaw", "jubekox", "lectern", "note_block", "black_shulker_box",
|
||||
"blue_shulker_box", "brown_shulker_box", "cyan_shulker_box", "gray_shulker_box", "green_shulker_box", "light_blue_shulker_box",
|
||||
"light_gray_shulker_box", "lime_shulker_box", "magenta_shulker_box", "orange_shulker_box", "pink_shulker_box", "purple_shulker_box",
|
||||
"red_shulker_box", "shulker_box", "white_shulker_box", "yellow_shulker_box", "smoker", "structure_block", "structure_void")
|
||||
.map(BlockTypes::get).filter(Objects::nonNull).forEach(tileEntityTypes::add);
|
||||
}
|
||||
return this.tileEntityTypes;
|
||||
}
|
||||
|
||||
@Override @Nonnegative
|
||||
public int getTileEntityCount(@Nonnull final String world,
|
||||
@Nonnull final BlockVector2 chunk) {
|
||||
@Override @Nonnegative public int getTileEntityCount(@Nonnull final String world, @Nonnull final BlockVector2 chunk) {
|
||||
return Objects.requireNonNull(getWorld(world)).
|
||||
getChunkAt(chunk.getBlockX(), chunk.getBlockZ())
|
||||
.getTileEntities().length;
|
||||
getChunkAt(chunk.getBlockX(), chunk.getBlockZ()).getTileEntities().length;
|
||||
}
|
||||
|
||||
@Override public Set<BlockVector2> getChunkChunks(String world) {
|
||||
Set<BlockVector2> chunks = super.getChunkChunks(world);
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world)).getLoadedChunks()) {
|
||||
BlockVector2 loc = BlockVector2.at(chunk.getX() >> 5, chunk.getZ() >> 5);
|
||||
chunks.add(loc);
|
||||
}
|
||||
} else {
|
||||
final Semaphore semaphore = new Semaphore(1);
|
||||
try {
|
||||
semaphore.acquire();
|
||||
Bukkit.getScheduler().runTask(BukkitPlatform.getPlugin(BukkitPlatform.class), () -> {
|
||||
for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world)).getLoadedChunks()) {
|
||||
BlockVector2 loc = BlockVector2.at(chunk.getX() >> 5, chunk.getZ() >> 5);
|
||||
chunks.add(loc);
|
||||
}
|
||||
semaphore.release();
|
||||
});
|
||||
semaphore.acquireUninterruptibly();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ load: STARTUP
|
||||
description: "Easy, yet powerful Plot World generation and management."
|
||||
authors: [Citymonstret, Empire92, MattBDev, dordsor21, NotMyFault, SirYwell]
|
||||
website: https://www.spigotmc.org/resources/77506/
|
||||
softdepend: [Vault, PlaceholderAPI, Essentials, LuckPerms, BungeePerms]
|
||||
softdepend: [Vault, PlaceholderAPI, Essentials, LuckPerms, BungeePerms, MVdWPlaceholderAPI]
|
||||
loadbefore: [MultiWorld, Multiverse-Core]
|
||||
depend: [WorldEdit]
|
||||
database: false
|
||||
|
Reference in New Issue
Block a user