mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Initial annotation usage cleanup + EditorConfig
This commit is contained in:
parent
8b332adbe7
commit
57fc51d013
1013
.editorconfig
Normal file
1013
.editorconfig
Normal file
File diff suppressed because it is too large
Load Diff
14
.github/workflows/build.yml
vendored
14
.github/workflows/build.yml
vendored
@ -10,11 +10,11 @@ jobs:
|
|||||||
os: ["ubuntu-18.04"]
|
os: ["ubuntu-18.04"]
|
||||||
runs-on: "${{ matrix.os }}"
|
runs-on: "${{ matrix.os }}"
|
||||||
steps:
|
steps:
|
||||||
- name: "Checkout Repository"
|
- name: "Checkout Repository"
|
||||||
uses: "actions/checkout@v2.3.4"
|
uses: "actions/checkout@v2.3.4"
|
||||||
- name: "Setup JDK ${{ matrix.java }}"
|
- name: "Setup JDK ${{ matrix.java }}"
|
||||||
uses: "actions/setup-java@v1.4.3"
|
uses: "actions/setup-java@v1.4.3"
|
||||||
with:
|
with:
|
||||||
java-version: "${{ matrix.java }}"
|
java-version: "${{ matrix.java }}"
|
||||||
- name: "Clean Build"
|
- name: "Clean Build"
|
||||||
run: "./gradlew clean build"
|
run: "./gradlew clean build"
|
||||||
|
@ -93,7 +93,6 @@ tasks.named<ShadowJar>("shadowJar") {
|
|||||||
relocate("org.apache.logging.slf4j", "com.plotsquared.logging.apache.slf4j")
|
relocate("org.apache.logging.slf4j", "com.plotsquared.logging.apache.slf4j")
|
||||||
relocate("org.slf4j", "com.plotsquared.logging.slf4j")
|
relocate("org.slf4j", "com.plotsquared.logging.slf4j")
|
||||||
relocate("com.google.inject", "com.plotsquared.google")
|
relocate("com.google.inject", "com.plotsquared.google")
|
||||||
relocate("javax.inject", "com.plotsquared.core.inject.javax")
|
|
||||||
relocate("org.aopalliance", "com.plotsquared.core.aopalliance")
|
relocate("org.aopalliance", "com.plotsquared.core.aopalliance")
|
||||||
relocate("com.intellectualsites.services", "com.plotsquared.core.services")
|
relocate("com.intellectualsites.services", "com.plotsquared.core.services")
|
||||||
relocate("com.intellectualsites.arkitektonika", "com.plotsquared.core.arkitektonika")
|
relocate("com.intellectualsites.arkitektonika", "com.plotsquared.core.arkitektonika")
|
||||||
|
@ -46,22 +46,26 @@ import java.util.List;
|
|||||||
public class BukkitCommand implements CommandExecutor, TabCompleter {
|
public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, Command command, String commandLabel,
|
public boolean onCommand(
|
||||||
String[] args) {
|
CommandSender commandSender, Command command, String commandLabel,
|
||||||
|
String[] args
|
||||||
|
) {
|
||||||
if (commandSender instanceof Player) {
|
if (commandSender instanceof Player) {
|
||||||
return MainCommand.onCommand(BukkitUtil.adapt((Player) commandSender), args);
|
return MainCommand.onCommand(BukkitUtil.adapt((Player) commandSender), args);
|
||||||
}
|
}
|
||||||
if (commandSender instanceof ConsoleCommandSender
|
if (commandSender instanceof ConsoleCommandSender
|
||||||
|| commandSender instanceof ProxiedCommandSender
|
|| commandSender instanceof ProxiedCommandSender
|
||||||
|| commandSender instanceof RemoteConsoleCommandSender) {
|
|| commandSender instanceof RemoteConsoleCommandSender) {
|
||||||
return MainCommand.onCommand(ConsolePlayer.getConsole(), args);
|
return MainCommand.onCommand(ConsolePlayer.getConsole(), args);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(CommandSender commandSender, Command command, String s,
|
public List<String> onTabComplete(
|
||||||
String[] args) {
|
CommandSender commandSender, Command command, String s,
|
||||||
|
String[] args
|
||||||
|
) {
|
||||||
if (!(commandSender instanceof Player)) {
|
if (!(commandSender instanceof Player)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -70,7 +74,7 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
|||||||
return Collections.singletonList("plots");
|
return Collections.singletonList("plots");
|
||||||
}
|
}
|
||||||
Collection<com.plotsquared.core.command.Command> objects =
|
Collection<com.plotsquared.core.command.Command> objects =
|
||||||
MainCommand.getInstance().tab(player, args, s.endsWith(" "));
|
MainCommand.getInstance().tab(player, args, s.endsWith(" "));
|
||||||
if (objects == null) {
|
if (objects == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -80,4 +84,5 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -136,11 +136,11 @@ import org.bukkit.metadata.FixedMetadataValue;
|
|||||||
import org.bukkit.metadata.MetadataValue;
|
import org.bukkit.metadata.MetadataValue;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -165,7 +165,8 @@ import static com.plotsquared.core.util.PremiumVerification.getResourceID;
|
|||||||
import static com.plotsquared.core.util.PremiumVerification.getUserID;
|
import static com.plotsquared.core.util.PremiumVerification.getUserID;
|
||||||
import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
@SuppressWarnings("unused") @Singleton
|
@SuppressWarnings("unused")
|
||||||
|
@Singleton
|
||||||
public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPlatform<Player> {
|
public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPlatform<Player> {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitPlatform.class.getSimpleName());
|
private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitPlatform.class.getSimpleName());
|
||||||
@ -188,19 +189,34 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
|
|
||||||
private Injector injector;
|
private Injector injector;
|
||||||
|
|
||||||
@Inject private PlotAreaManager plotAreaManager;
|
@Inject
|
||||||
@Inject private EventDispatcher eventDispatcher;
|
private PlotAreaManager plotAreaManager;
|
||||||
@Inject private PlotListener plotListener;
|
@Inject
|
||||||
@Inject @WorldConfig private YamlConfiguration worldConfiguration;
|
private EventDispatcher eventDispatcher;
|
||||||
@Inject @WorldFile private File worldfile;
|
@Inject
|
||||||
@Inject private BukkitPlayerManager playerManager;
|
private PlotListener plotListener;
|
||||||
@Inject private BackupManager backupManager;
|
@Inject
|
||||||
@Inject @ImpromptuPipeline private UUIDPipeline impromptuPipeline;
|
@WorldConfig
|
||||||
@Inject @BackgroundPipeline private UUIDPipeline backgroundPipeline;
|
private YamlConfiguration worldConfiguration;
|
||||||
@Inject private PlatformWorldManager<World> worldManager;
|
@Inject
|
||||||
|
@WorldFile
|
||||||
|
private File worldfile;
|
||||||
|
@Inject
|
||||||
|
private BukkitPlayerManager playerManager;
|
||||||
|
@Inject
|
||||||
|
private BackupManager backupManager;
|
||||||
|
@Inject
|
||||||
|
@ImpromptuPipeline
|
||||||
|
private UUIDPipeline impromptuPipeline;
|
||||||
|
@Inject
|
||||||
|
@BackgroundPipeline
|
||||||
|
private UUIDPipeline backgroundPipeline;
|
||||||
|
@Inject
|
||||||
|
private PlatformWorldManager<World> worldManager;
|
||||||
private Locale serverLocale;
|
private Locale serverLocale;
|
||||||
|
|
||||||
@Override @Nonnull public int[] serverVersion() {
|
@Override
|
||||||
|
public @NonNull int[] serverVersion() {
|
||||||
if (this.version == null) {
|
if (this.version == null) {
|
||||||
try {
|
try {
|
||||||
this.version = new int[3];
|
this.version = new int[3];
|
||||||
@ -212,17 +228,19 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return new int[] {1, 13, 0};
|
return new int[]{1, 13, 0};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.version;
|
return this.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public String serverImplementation() {
|
@Override
|
||||||
|
public @NonNull String serverImplementation() {
|
||||||
return Bukkit.getVersion();
|
return Bukkit.getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onEnable() {
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
this.pluginName = getDescription().getName();
|
this.pluginName = getDescription().getName();
|
||||||
|
|
||||||
final TaskTime.TimeConverter timeConverter;
|
final TaskTime.TimeConverter timeConverter;
|
||||||
@ -241,8 +259,13 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
// We create the injector after PlotSquared has been initialized, so that we have access
|
// We create the injector after PlotSquared has been initialized, so that we have access
|
||||||
// to generated instances and settings
|
// to generated instances and settings
|
||||||
this.injector = Guice
|
this.injector = Guice
|
||||||
.createInjector(Stage.PRODUCTION, new PermissionModule(), new WorldManagerModule(), new PlotSquaredModule(), new BukkitModule(this),
|
.createInjector(Stage.PRODUCTION,
|
||||||
new BackupModule());
|
new PermissionModule(),
|
||||||
|
new WorldManagerModule(),
|
||||||
|
new PlotSquaredModule(),
|
||||||
|
new BukkitModule(this),
|
||||||
|
new BackupModule()
|
||||||
|
);
|
||||||
this.injector.injectMembers(this);
|
this.injector.injectMembers(this);
|
||||||
|
|
||||||
this.serverLocale = Locale.forLanguageTag(Settings.Enabled_Components.DEFAULT_LOCALE);
|
this.serverLocale = Locale.forLanguageTag(Settings.Enabled_Components.DEFAULT_LOCALE);
|
||||||
@ -299,7 +322,8 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
new WE_Anywhere();
|
new WE_Anywhere();
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.error("Incompatible version of WorldEdit, please upgrade: https://builds.enginehub.org/job/worldedit?branch=master");
|
logger.error(
|
||||||
|
"Incompatible version of WorldEdit, please upgrade: https://builds.enginehub.org/job/worldedit?branch=master");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,9 +391,13 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!worldUtil.isWorld(world) && !world.equals("*")) {
|
if (!worldUtil.isWorld(world) && !world.equals("*")) {
|
||||||
logger.warn("`{}` was not properly loaded - {} will now try to load it properly", world, this.pluginName());
|
|
||||||
logger.warn(
|
logger.warn(
|
||||||
" - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml");
|
"`{}` was not properly loaded - {} will now try to load it properly",
|
||||||
|
world,
|
||||||
|
this.pluginName()
|
||||||
|
);
|
||||||
|
logger.warn(
|
||||||
|
" - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml");
|
||||||
logger.warn(" - Your world management plugin may be faulty (or non existent)");
|
logger.warn(" - Your world management plugin may be faulty (or non existent)");
|
||||||
logger.warn(" This message may also be a false positive and could be ignored.");
|
logger.warn(" This message may also be a false positive and could be ignored.");
|
||||||
this.setGenerator(world);
|
this.setGenerator(world);
|
||||||
@ -403,7 +431,9 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
final SQLiteUUIDService sqLiteUUIDService = new SQLiteUUIDService("user_cache.db");
|
final SQLiteUUIDService sqLiteUUIDService = new SQLiteUUIDService("user_cache.db");
|
||||||
|
|
||||||
final SQLiteUUIDService legacyUUIDService;
|
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");
|
legacyUUIDService = new SQLiteUUIDService("usercache.db");
|
||||||
} else {
|
} else {
|
||||||
legacyUUIDService = null;
|
legacyUUIDService = null;
|
||||||
@ -518,7 +548,12 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
this.methodUnloadSetup = true;
|
this.methodUnloadSetup = true;
|
||||||
try {
|
try {
|
||||||
ReflectionUtils.RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
|
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);
|
this.methodUnloadChunk0.setAccessible(true);
|
||||||
} catch (Throwable event) {
|
} catch (Throwable event) {
|
||||||
event.printStackTrace();
|
event.printStackTrace();
|
||||||
@ -549,7 +584,10 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
}
|
}
|
||||||
final Plot plot = area.getOwnedPlot(id);
|
final Plot plot = area.getOwnedPlot(id);
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
if (!plot.getFlag(ServerPlotFlag.class) || PlotSquared.platform().playerManager().getPlayerIfExists(plot.getOwner()) == null) {
|
if (!plot.getFlag(ServerPlotFlag.class) || PlotSquared
|
||||||
|
.platform()
|
||||||
|
.playerManager()
|
||||||
|
.getPlayerIfExists(plot.getOwner()) == null) {
|
||||||
if (world.getKeepSpawnInMemory()) {
|
if (world.getKeepSpawnInMemory()) {
|
||||||
world.setKeepSpawnInMemory(false);
|
world.setKeepSpawnInMemory(false);
|
||||||
return;
|
return;
|
||||||
@ -590,7 +628,10 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startUuidCaching(@Nonnull final SQLiteUUIDService sqLiteUUIDService, @Nonnull final CacheUUIDService cacheUUIDService) {
|
private void startUuidCaching(
|
||||||
|
final @NonNull SQLiteUUIDService sqLiteUUIDService,
|
||||||
|
final @NonNull CacheUUIDService cacheUUIDService
|
||||||
|
) {
|
||||||
// Load all uuids into a big chunky boi queue
|
// Load all uuids into a big chunky boi queue
|
||||||
final Queue<UUID> uuidQueue = new LinkedBlockingQueue<>();
|
final Queue<UUID> uuidQueue = new LinkedBlockingQueue<>();
|
||||||
PlotSquared.get().forEachPlotRaw(plot -> {
|
PlotSquared.get().forEachPlotRaw(plot -> {
|
||||||
@ -656,12 +697,14 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
}, 10, TimeUnit.SECONDS);
|
}, 10, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onDisable() {
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
PlotSquared.get().disable();
|
PlotSquared.get().disable();
|
||||||
Bukkit.getScheduler().cancelTasks(this);
|
Bukkit.getScheduler().cancelTasks(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void shutdown() {
|
@Override
|
||||||
|
public void shutdown() {
|
||||||
this.getServer().getPluginManager().disablePlugin(this);
|
this.getServer().getPluginManager().disablePlugin(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -675,15 +718,18 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public File getDirectory() {
|
@Override
|
||||||
|
public @NonNull File getDirectory() {
|
||||||
return getDataFolder();
|
return getDataFolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public File worldContainer() {
|
@Override
|
||||||
|
public @NonNull File worldContainer() {
|
||||||
return Bukkit.getWorldContainer();
|
return Bukkit.getWorldContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation") private void runEntityTask() {
|
@SuppressWarnings("deprecation")
|
||||||
|
private void runEntityTask() {
|
||||||
TaskManager.runTaskRepeat(() -> this.plotAreaManager.forEachPlotArea(plotArea -> {
|
TaskManager.runTaskRepeat(() -> this.plotAreaManager.forEachPlotArea(plotArea -> {
|
||||||
final World world = Bukkit.getWorld(plotArea.getWorldName());
|
final World world = Bukkit.getWorld(plotArea.getWorldName());
|
||||||
try {
|
try {
|
||||||
@ -766,7 +812,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
case "DRAGON_FIREBALL":
|
case "DRAGON_FIREBALL":
|
||||||
case "DROPPED_ITEM":
|
case "DROPPED_ITEM":
|
||||||
if (Settings.Enabled_Components.KILL_ROAD_ITEMS
|
if (Settings.Enabled_Components.KILL_ROAD_ITEMS
|
||||||
&& plotArea.getOwnedPlotAbs(BukkitUtil.adapt(entity.getLocation())) == null) {
|
&& plotArea.getOwnedPlotAbs(BukkitUtil.adapt(entity.getLocation())) == null) {
|
||||||
entity.remove();
|
entity.remove();
|
||||||
}
|
}
|
||||||
// dropped item
|
// dropped item
|
||||||
@ -794,8 +840,9 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
PlotArea area = pLoc.getPlotArea();
|
PlotArea area = pLoc.getPlotArea();
|
||||||
if (area != null) {
|
if (area != null) {
|
||||||
PlotId currentPlotId = area.getPlotAbs(pLoc).getId();
|
PlotId currentPlotId = area.getPlotAbs(pLoc).getId();
|
||||||
if (!originalPlotId.equals(currentPlotId) && (currentPlotId == null || !area.getPlot(originalPlotId)
|
if (!originalPlotId.equals(currentPlotId) && (currentPlotId == null || !area.getPlot(
|
||||||
.equals(area.getPlot(currentPlotId)))) {
|
originalPlotId)
|
||||||
|
.equals(area.getPlot(currentPlotId)))) {
|
||||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -811,7 +858,10 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
if (area != null) {
|
if (area != null) {
|
||||||
PlotId currentPlotId = area.getPlotAbs(pLoc).getId();
|
PlotId currentPlotId = area.getPlotAbs(pLoc).getId();
|
||||||
if (currentPlotId != null) {
|
if (currentPlotId != null) {
|
||||||
entity.setMetadata("shulkerPlot", new FixedMetadataValue((Plugin) PlotSquared.platform(), currentPlotId));
|
entity.setMetadata(
|
||||||
|
"shulkerPlot",
|
||||||
|
new FixedMetadataValue((Plugin) PlotSquared.platform(), currentPlotId)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -894,10 +944,10 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
if (entity instanceof LivingEntity) {
|
if (entity instanceof LivingEntity) {
|
||||||
LivingEntity livingEntity = (LivingEntity) entity;
|
LivingEntity livingEntity = (LivingEntity) entity;
|
||||||
if ((Settings.Enabled_Components.KILL_OWNED_ROAD_MOBS || !livingEntity.isLeashed())
|
if ((Settings.Enabled_Components.KILL_OWNED_ROAD_MOBS || !livingEntity.isLeashed())
|
||||||
|| !entity.hasMetadata("keep")) {
|
|| !entity.hasMetadata("keep")) {
|
||||||
Entity passenger = entity.getPassenger();
|
Entity passenger = entity.getPassenger();
|
||||||
if ((Settings.Enabled_Components.KILL_OWNED_ROAD_MOBS
|
if ((Settings.Enabled_Components.KILL_OWNED_ROAD_MOBS
|
||||||
|| !(passenger instanceof Player)) && entity.getMetadata("keep").isEmpty()) {
|
|| !(passenger instanceof Player)) && entity.getMetadata("keep").isEmpty()) {
|
||||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -909,7 +959,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
} else {
|
} else {
|
||||||
Entity passenger = entity.getPassenger();
|
Entity passenger = entity.getPassenger();
|
||||||
if ((Settings.Enabled_Components.KILL_OWNED_ROAD_MOBS
|
if ((Settings.Enabled_Components.KILL_OWNED_ROAD_MOBS
|
||||||
|| !(passenger instanceof Player)) && entity.getMetadata("keep").isEmpty()) {
|
|| !(passenger instanceof Player)) && entity.getMetadata("keep").isEmpty()) {
|
||||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -930,7 +980,8 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
}), TaskTime.seconds(1L));
|
}), TaskTime.seconds(1L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nullable public final ChunkGenerator getDefaultWorldGenerator(@Nonnull final String worldName, final String id) {
|
@Override
|
||||||
|
public @Nullable final ChunkGenerator getDefaultWorldGenerator(final @NonNull String worldName, final String id) {
|
||||||
final IndependentPlotGenerator result;
|
final IndependentPlotGenerator result;
|
||||||
if (id != null && id.equalsIgnoreCase("single")) {
|
if (id != null && id.equalsIgnoreCase("single")) {
|
||||||
result = injector().getInstance(SingleWorldGenerator.class);
|
result = injector().getInstance(SingleWorldGenerator.class);
|
||||||
@ -943,7 +994,8 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
return (ChunkGenerator) result.specify(worldName);
|
return (ChunkGenerator) result.specify(worldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nullable public GeneratorWrapper<?> getGenerator(@Nonnull final String world, @Nullable final String name) {
|
@Override
|
||||||
|
public @Nullable GeneratorWrapper<?> getGenerator(final @NonNull String world, final @Nullable String name) {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -955,12 +1007,15 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
}
|
}
|
||||||
return new BukkitPlotGenerator(world, gen, this.plotAreaManager);
|
return new BukkitPlotGenerator(world, gen, this.plotAreaManager);
|
||||||
} else {
|
} else {
|
||||||
return new BukkitPlotGenerator(world, injector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class)),
|
return new BukkitPlotGenerator(world,
|
||||||
this.plotAreaManager);
|
injector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class)),
|
||||||
|
this.plotAreaManager
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void startMetrics() {
|
@Override
|
||||||
|
public void startMetrics() {
|
||||||
if (this.metricsStarted) {
|
if (this.metricsStarted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -977,33 +1032,50 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
}
|
}
|
||||||
for (final PlotArea plotArea : this.plotAreaManager.getAllPlotAreas()) {
|
for (final PlotArea plotArea : this.plotAreaManager.getAllPlotAreas()) {
|
||||||
final Map<String, Integer> terrainTypeMap = map.get(plotArea.getType().name().toLowerCase());
|
final Map<String, Integer> terrainTypeMap = map.get(plotArea.getType().name().toLowerCase());
|
||||||
terrainTypeMap.put(plotArea.getTerrain().name().toLowerCase(), terrainTypeMap.get(plotArea.getTerrain().name().toLowerCase()) + 1);
|
terrainTypeMap.put(
|
||||||
|
plotArea.getTerrain().name().toLowerCase(),
|
||||||
|
terrainTypeMap.get(plotArea.getTerrain().name().toLowerCase()) + 1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return map;
|
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("worlds", () -> Settings.Enabled_Components.WORLDS ? "true" : "false"));
|
metrics.addCustomChart(new Metrics.SimplePie("worlds", () -> Settings.Enabled_Components.WORLDS ? "true" : "false"));
|
||||||
metrics.addCustomChart(new Metrics.SimplePie("economy", () -> Settings.Enabled_Components.ECONOMY ? "true" : "false"));
|
metrics.addCustomChart(new Metrics.SimplePie("economy", () -> Settings.Enabled_Components.ECONOMY ? "true" : "false"));
|
||||||
metrics.addCustomChart(new Metrics.SimplePie("plot_expiry", () -> Settings.Enabled_Components.PLOT_EXPIRY ? "true" : "false"));
|
metrics.addCustomChart(new Metrics.SimplePie(
|
||||||
|
"plot_expiry",
|
||||||
|
() -> Settings.Enabled_Components.PLOT_EXPIRY ? "true" : "false"
|
||||||
|
));
|
||||||
metrics.addCustomChart(new Metrics.SimplePie("database_type", () -> Storage.MySQL.USE ? "MySQL" : "SQLite"));
|
metrics.addCustomChart(new Metrics.SimplePie("database_type", () -> Storage.MySQL.USE ? "MySQL" : "SQLite"));
|
||||||
metrics.addCustomChart(new Metrics.SimplePie("worldedit_implementation",
|
metrics.addCustomChart(new Metrics.SimplePie(
|
||||||
() -> Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null ? "FastAsyncWorldEdit" : "WorldEdit"));
|
"worldedit_implementation",
|
||||||
|
() -> Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null ? "FastAsyncWorldEdit" : "WorldEdit"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void unregister(@Nonnull final PlotPlayer<?> player) {
|
@Override
|
||||||
|
public void unregister(final @NonNull PlotPlayer<?> player) {
|
||||||
PlotSquared.platform().playerManager().removePlayer(player.getUUID());
|
PlotSquared.platform().playerManager().removePlayer(player.getUUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void setGenerator(@Nonnull final String worldName) {
|
@Override
|
||||||
|
public void setGenerator(final @NonNull String worldName) {
|
||||||
World world = BukkitUtil.getWorld(worldName);
|
World world = BukkitUtil.getWorld(worldName);
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
// create world
|
// create world
|
||||||
ConfigurationSection worldConfig = this.worldConfiguration.getConfigurationSection("worlds." + worldName);
|
ConfigurationSection worldConfig = this.worldConfiguration.getConfigurationSection("worlds." + worldName);
|
||||||
String manager = worldConfig.getString("generator.plugin", pluginName());
|
String manager = worldConfig.getString("generator.plugin", pluginName());
|
||||||
PlotAreaBuilder builder =
|
PlotAreaBuilder builder =
|
||||||
PlotAreaBuilder.newBuilder().plotManager(manager).generatorName(worldConfig.getString("generator.init", manager))
|
PlotAreaBuilder.newBuilder().plotManager(manager).generatorName(worldConfig.getString(
|
||||||
.plotAreaType(ConfigurationUtil.getType(worldConfig)).terrainType(ConfigurationUtil.getTerrain(worldConfig))
|
"generator.init",
|
||||||
.settingsNodesWrapper(new SettingsNodesWrapper(new ConfigurationNode[0], null)).worldName(worldName);
|
manager
|
||||||
|
))
|
||||||
|
.plotAreaType(ConfigurationUtil.getType(worldConfig)).terrainType(ConfigurationUtil.getTerrain(
|
||||||
|
worldConfig))
|
||||||
|
.settingsNodesWrapper(new SettingsNodesWrapper(new ConfigurationNode[0], null)).worldName(worldName);
|
||||||
injector().getInstance(SetupUtils.class).setupWorld(builder);
|
injector().getInstance(SetupUtils.class).setupWorld(builder);
|
||||||
world = Bukkit.getWorld(worldName);
|
world = Bukkit.getWorld(worldName);
|
||||||
} else {
|
} else {
|
||||||
@ -1028,41 +1100,50 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public String serverNativePackage() {
|
@Override
|
||||||
|
public @NonNull String serverNativePackage() {
|
||||||
final String name = Bukkit.getServer().getClass().getPackage().getName();
|
final String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
return name.substring(name.lastIndexOf('.') + 1);
|
return name.substring(name.lastIndexOf('.') + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public GeneratorWrapper<?> wrapPlotGenerator(@Nullable final String world, @Nonnull final IndependentPlotGenerator generator) {
|
@Override
|
||||||
|
public @NonNull GeneratorWrapper<?> wrapPlotGenerator(
|
||||||
|
final @Nullable String world,
|
||||||
|
final @NonNull IndependentPlotGenerator generator
|
||||||
|
) {
|
||||||
return new BukkitPlotGenerator(world, generator, this.plotAreaManager);
|
return new BukkitPlotGenerator(world, generator, this.plotAreaManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public String pluginsFormatted() {
|
@Override
|
||||||
|
public @NonNull String pluginsFormatted() {
|
||||||
StringBuilder msg = new StringBuilder();
|
StringBuilder msg = new StringBuilder();
|
||||||
Plugin[] plugins = Bukkit.getServer().getPluginManager().getPlugins();
|
Plugin[] plugins = Bukkit.getServer().getPluginManager().getPlugins();
|
||||||
msg.append("Plugins (").append(plugins.length).append("): \n");
|
msg.append("Plugins (").append(plugins.length).append("): \n");
|
||||||
for (Plugin p : plugins) {
|
for (Plugin p : plugins) {
|
||||||
msg.append(" - ").append(p.getName()).append(":").append("\n")
|
msg.append(" - ").append(p.getName()).append(":").append("\n")
|
||||||
.append(" • Version: ").append(p.getDescription().getVersion()).append("\n")
|
.append(" • Version: ").append(p.getDescription().getVersion()).append("\n")
|
||||||
.append(" • Enabled: ").append(p.isEnabled()).append("\n")
|
.append(" • Enabled: ").append(p.isEnabled()).append("\n")
|
||||||
.append(" • Main: ").append(p.getDescription().getMain()).append("\n")
|
.append(" • Main: ").append(p.getDescription().getMain()).append("\n")
|
||||||
.append(" • Authors: ").append(p.getDescription().getAuthors()).append("\n")
|
.append(" • Authors: ").append(p.getDescription().getAuthors()).append("\n")
|
||||||
.append(" • Load Before: ").append(p.getDescription().getLoadBefore()).append("\n")
|
.append(" • Load Before: ").append(p.getDescription().getLoadBefore()).append("\n")
|
||||||
.append(" • Dependencies: ").append(p.getDescription().getDepend()).append("\n")
|
.append(" • Dependencies: ").append(p.getDescription().getDepend()).append("\n")
|
||||||
.append(" • Soft Dependencies: ").append(p.getDescription().getSoftDepend()).append("\n");
|
.append(" • Soft Dependencies: ").append(p.getDescription().getSoftDepend()).append("\n");
|
||||||
}
|
}
|
||||||
return msg.toString();
|
return msg.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public com.plotsquared.core.location.World<?> getPlatformWorld(@Nonnull final String worldName) {
|
@Override
|
||||||
|
public com.plotsquared.core.location.@NonNull World<?> getPlatformWorld(final @NonNull String worldName) {
|
||||||
return BukkitWorld.of(worldName);
|
return BukkitWorld.of(worldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public Audience consoleAudience() {
|
@Override
|
||||||
|
public @NonNull Audience consoleAudience() {
|
||||||
return BukkitUtil.BUKKIT_AUDIENCES.console();
|
return BukkitUtil.BUKKIT_AUDIENCES.console();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public String pluginName() {
|
@Override
|
||||||
|
public @NonNull String pluginName() {
|
||||||
return this.pluginName;
|
return this.pluginName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1070,30 +1151,39 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
return this.singleWorldListener;
|
return this.singleWorldListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public Injector injector() {
|
@Override
|
||||||
|
public @NonNull Injector injector() {
|
||||||
return this.injector;
|
return this.injector;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull @Override public Locale getLocale() {
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Locale getLocale() {
|
||||||
return this.serverLocale;
|
return this.serverLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void setLocale(@Nonnull final Locale locale) {
|
@Override
|
||||||
|
public void setLocale(final @NonNull Locale locale) {
|
||||||
throw new UnsupportedOperationException("Cannot replace server locale");
|
throw new UnsupportedOperationException("Cannot replace server locale");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public PlatformWorldManager<?> worldManager() {
|
@Override
|
||||||
|
public @NonNull PlatformWorldManager<?> worldManager() {
|
||||||
return injector().getInstance(Key.get(new TypeLiteral<PlatformWorldManager<World>>() {
|
return injector().getInstance(Key.get(new TypeLiteral<PlatformWorldManager<World>>() {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull @SuppressWarnings("ALL") public PlayerManager<? extends PlotPlayer<Player>, ? extends Player> playerManager() {
|
@Override
|
||||||
|
@NonNull
|
||||||
|
@SuppressWarnings("ALL")
|
||||||
|
public PlayerManager<? extends PlotPlayer<Player>, ? extends Player> playerManager() {
|
||||||
return (PlayerManager<BukkitPlayer, Player>) injector().getInstance(PlayerManager.class);
|
return (PlayerManager<BukkitPlayer, Player>) injector().getInstance(PlayerManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void copyCaptionMaps() {
|
@Override
|
||||||
|
public void copyCaptionMaps() {
|
||||||
/* Make this prettier at some point */
|
/* Make this prettier at some point */
|
||||||
final String[] languages = new String[] { "en" };
|
final String[] languages = new String[]{"en"};
|
||||||
for (final String language : languages) {
|
for (final String language : languages) {
|
||||||
if (!new File(new File(this.getDataFolder(), "lang"), String.format("messages_%s.json", language)).exists()) {
|
if (!new File(new File(this.getDataFolder(), "lang"), String.format("messages_%s.json", language)).exists()) {
|
||||||
this.saveResource(String.format("lang/messages_%s.json", language), false);
|
this.saveResource(String.format("lang/messages_%s.json", language), false);
|
||||||
@ -1102,7 +1192,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toLegacyPlatformString(Component component) {
|
public String toLegacyPlatformString(Component component) {
|
||||||
return LegacyComponentSerializer.legacyAmpersand().serialize(component);
|
return LegacyComponentSerializer.legacyAmpersand().serialize(component);
|
||||||
|
@ -30,4 +30,5 @@ class AgeableStats {
|
|||||||
int age;
|
int age;
|
||||||
boolean locked;
|
boolean locked;
|
||||||
boolean adult;
|
boolean adult;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,4 +37,5 @@ class ArmorStandStats {
|
|||||||
boolean noPlate;
|
boolean noPlate;
|
||||||
boolean invisible;
|
boolean invisible;
|
||||||
boolean small;
|
boolean small;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,4 +34,5 @@ class EntityBaseStats {
|
|||||||
double vZ;
|
double vZ;
|
||||||
double vY;
|
double vY;
|
||||||
double vX;
|
double vX;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public abstract class EntityWrapper {
|
public abstract class EntityWrapper {
|
||||||
|
|
||||||
@ -42,7 +41,7 @@ public abstract class EntityWrapper {
|
|||||||
public double y;
|
public double y;
|
||||||
public double z;
|
public double z;
|
||||||
|
|
||||||
EntityWrapper(@Nonnull final Entity entity) {
|
EntityWrapper(final @NonNull Entity entity) {
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this.type = entity.getType();
|
this.type = entity.getType();
|
||||||
|
|
||||||
@ -54,7 +53,9 @@ public abstract class EntityWrapper {
|
|||||||
this.pitch = location.getPitch();
|
this.pitch = location.getPitch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation") @Override public String toString() {
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
return String.format("[%s, x=%s, y=%s, z=%s]", type.getName(), x, y, z);
|
return String.format("[%s, x=%s, y=%s, z=%s]", type.getName(), x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,4 +90,5 @@ public abstract class EntityWrapper {
|
|||||||
public double getZ() {
|
public double getZ() {
|
||||||
return this.z;
|
return this.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,4 +34,5 @@ class HorseStats {
|
|||||||
Horse.Variant variant;
|
Horse.Variant variant;
|
||||||
Horse.Color color;
|
Horse.Color color;
|
||||||
Horse.Style style;
|
Horse.Style style;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -50,4 +50,5 @@ class LivingEntityStats {
|
|||||||
ItemStack chestplate;
|
ItemStack chestplate;
|
||||||
Collection<PotionEffect> potions;
|
Collection<PotionEffect> potions;
|
||||||
ItemStack offHand;
|
ItemStack offHand;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -241,9 +241,9 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
|||||||
case "ARMOR_STAND":
|
case "ARMOR_STAND":
|
||||||
ArmorStand stand = (ArmorStand) entity;
|
ArmorStand stand = (ArmorStand) entity;
|
||||||
this.inventory =
|
this.inventory =
|
||||||
new ItemStack[] {stand.getItemInHand().clone(), stand.getHelmet().clone(),
|
new ItemStack[]{stand.getItemInHand().clone(), stand.getHelmet().clone(),
|
||||||
stand.getChestplate().clone(), stand.getLeggings().clone(),
|
stand.getChestplate().clone(), stand.getLeggings().clone(),
|
||||||
stand.getBoots().clone()};
|
stand.getBoots().clone()};
|
||||||
storeLiving(stand);
|
storeLiving(stand);
|
||||||
this.stand = new ArmorStandStats();
|
this.stand = new ArmorStandStats();
|
||||||
|
|
||||||
@ -336,15 +336,17 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
|||||||
this.dataByte = (byte) 0;
|
this.dataByte = (byte) 0;
|
||||||
}
|
}
|
||||||
storeLiving((LivingEntity) entity);
|
storeLiving((LivingEntity) entity);
|
||||||
// END LIVING //
|
// END LIVING //
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean equals(Object obj) {
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
return this.hash == obj.hashCode();
|
return this.hash == obj.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public int hashCode() {
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
return this.hash;
|
return this.hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,7 +462,8 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
|||||||
this.tamed.tamed = tamed.isTamed();
|
this.tamed.tamed = tamed.isTamed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Entity spawn(World world, int xOffset, int zOffset) {
|
@Override
|
||||||
|
public Entity spawn(World world, int xOffset, int zOffset) {
|
||||||
Location location = new Location(world, this.getX() + xOffset, this.getY(), this.z + zOffset);
|
Location location = new Location(world, this.getX() + xOffset, this.getY(), this.z + zOffset);
|
||||||
location.setYaw(this.yaw);
|
location.setYaw(this.yaw);
|
||||||
location.setPitch(this.pitch);
|
location.setPitch(this.pitch);
|
||||||
@ -647,36 +650,40 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
|||||||
}
|
}
|
||||||
if (this.stand.head[0] != 0 || this.stand.head[1] != 0 || this.stand.head[2] != 0) {
|
if (this.stand.head[0] != 0 || this.stand.head[1] != 0 || this.stand.head[2] != 0) {
|
||||||
EulerAngle pose =
|
EulerAngle pose =
|
||||||
new EulerAngle(this.stand.head[0], this.stand.head[1], this.stand.head[2]);
|
new EulerAngle(this.stand.head[0], this.stand.head[1], this.stand.head[2]);
|
||||||
stand.setHeadPose(pose);
|
stand.setHeadPose(pose);
|
||||||
}
|
}
|
||||||
if (this.stand.body[0] != 0 || this.stand.body[1] != 0 || this.stand.body[2] != 0) {
|
if (this.stand.body[0] != 0 || this.stand.body[1] != 0 || this.stand.body[2] != 0) {
|
||||||
EulerAngle pose =
|
EulerAngle pose =
|
||||||
new EulerAngle(this.stand.body[0], this.stand.body[1], this.stand.body[2]);
|
new EulerAngle(this.stand.body[0], this.stand.body[1], this.stand.body[2]);
|
||||||
stand.setBodyPose(pose);
|
stand.setBodyPose(pose);
|
||||||
}
|
}
|
||||||
if (this.stand.leftLeg[0] != 0 || this.stand.leftLeg[1] != 0
|
if (this.stand.leftLeg[0] != 0 || this.stand.leftLeg[1] != 0
|
||||||
|| this.stand.leftLeg[2] != 0) {
|
|| this.stand.leftLeg[2] != 0) {
|
||||||
EulerAngle pose = new EulerAngle(this.stand.leftLeg[0], this.stand.leftLeg[1],
|
EulerAngle pose = new EulerAngle(this.stand.leftLeg[0], this.stand.leftLeg[1],
|
||||||
this.stand.leftLeg[2]);
|
this.stand.leftLeg[2]
|
||||||
|
);
|
||||||
stand.setLeftLegPose(pose);
|
stand.setLeftLegPose(pose);
|
||||||
}
|
}
|
||||||
if (this.stand.rightLeg[0] != 0 || this.stand.rightLeg[1] != 0
|
if (this.stand.rightLeg[0] != 0 || this.stand.rightLeg[1] != 0
|
||||||
|| this.stand.rightLeg[2] != 0) {
|
|| this.stand.rightLeg[2] != 0) {
|
||||||
EulerAngle pose = new EulerAngle(this.stand.rightLeg[0], this.stand.rightLeg[1],
|
EulerAngle pose = new EulerAngle(this.stand.rightLeg[0], this.stand.rightLeg[1],
|
||||||
this.stand.rightLeg[2]);
|
this.stand.rightLeg[2]
|
||||||
|
);
|
||||||
stand.setRightLegPose(pose);
|
stand.setRightLegPose(pose);
|
||||||
}
|
}
|
||||||
if (this.stand.leftArm[0] != 0 || this.stand.leftArm[1] != 0
|
if (this.stand.leftArm[0] != 0 || this.stand.leftArm[1] != 0
|
||||||
|| this.stand.leftArm[2] != 0) {
|
|| this.stand.leftArm[2] != 0) {
|
||||||
EulerAngle pose = new EulerAngle(this.stand.leftArm[0], this.stand.leftArm[1],
|
EulerAngle pose = new EulerAngle(this.stand.leftArm[0], this.stand.leftArm[1],
|
||||||
this.stand.leftArm[2]);
|
this.stand.leftArm[2]
|
||||||
|
);
|
||||||
stand.setLeftArmPose(pose);
|
stand.setLeftArmPose(pose);
|
||||||
}
|
}
|
||||||
if (this.stand.rightArm[0] != 0 || this.stand.rightArm[1] != 0
|
if (this.stand.rightArm[0] != 0 || this.stand.rightArm[1] != 0
|
||||||
|| this.stand.rightArm[2] != 0) {
|
|| this.stand.rightArm[2] != 0) {
|
||||||
EulerAngle pose = new EulerAngle(this.stand.rightArm[0], this.stand.rightArm[1],
|
EulerAngle pose = new EulerAngle(this.stand.rightArm[0], this.stand.rightArm[1],
|
||||||
this.stand.rightArm[2]);
|
this.stand.rightArm[2]
|
||||||
|
);
|
||||||
stand.setRightArmPose(pose);
|
stand.setRightArmPose(pose);
|
||||||
}
|
}
|
||||||
if (this.stand.invisible) {
|
if (this.stand.invisible) {
|
||||||
|
@ -31,4 +31,5 @@ class TameableStats {
|
|||||||
|
|
||||||
AnimalTamer owner;
|
AnimalTamer owner;
|
||||||
boolean tamed;
|
boolean tamed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,8 @@ public class TeleportEntityWrapper extends EntityWrapper {
|
|||||||
super(entity);
|
super(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Entity spawn(final World world, final int xOffset, final int zOffset) {
|
@Override
|
||||||
|
public Entity spawn(final World world, final int xOffset, final int zOffset) {
|
||||||
if (!getEntity().getLocation().getChunk().equals(oldLocation.getChunk())) {
|
if (!getEntity().getLocation().getChunk().equals(oldLocation.getChunk())) {
|
||||||
final Location oldLocation = this.oldLocation.clone();
|
final Location oldLocation = this.oldLocation.clone();
|
||||||
oldLocation.add(xOffset, 0, xOffset);
|
oldLocation.add(xOffset, 0, xOffset);
|
||||||
@ -58,7 +59,8 @@ public class TeleportEntityWrapper extends EntityWrapper {
|
|||||||
return getEntity();
|
return getEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void saveEntity() {
|
@Override
|
||||||
|
public void saveEntity() {
|
||||||
if (getEntity().hasMetadata("ps-tmp-teleport")) {
|
if (getEntity().hasMetadata("ps-tmp-teleport")) {
|
||||||
this.oldLocation = (Location) this.getEntity().getMetadata("ps-tmp-teleport").get(0);
|
this.oldLocation = (Location) this.getEntity().getMetadata("ps-tmp-teleport").get(0);
|
||||||
} else {
|
} else {
|
||||||
@ -77,11 +79,13 @@ public class TeleportEntityWrapper extends EntityWrapper {
|
|||||||
this.getEntity().setInvulnerable(true);
|
this.getEntity().setInvulnerable(true);
|
||||||
this.fireTicksOld = this.getEntity().getFireTicks();
|
this.fireTicksOld = this.getEntity().getFireTicks();
|
||||||
this.livingTicksOld = this.getEntity().getTicksLived();
|
this.livingTicksOld = this.getEntity().getTicksLived();
|
||||||
this.getEntity().setMetadata("ps-tmp-teleport",
|
this.getEntity().setMetadata(
|
||||||
new FixedMetadataValue(BukkitPlatform.getPlugin(BukkitPlatform.class), oldLocation));
|
"ps-tmp-teleport",
|
||||||
|
new FixedMetadataValue(BukkitPlatform.getPlugin(BukkitPlatform.class), oldLocation)
|
||||||
|
);
|
||||||
final Chunk newChunk = getNewChunk();
|
final Chunk newChunk = getNewChunk();
|
||||||
this.getEntity().teleport(
|
this.getEntity().teleport(
|
||||||
new Location(newChunk.getWorld(), newChunk.getX() << 4, 5000, newChunk.getZ() << 4));
|
new Location(newChunk.getWorld(), newChunk.getX() << 4, 5000, newChunk.getZ() << 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Chunk getNewChunk() {
|
private Chunk getNewChunk() {
|
||||||
@ -115,4 +119,5 @@ public class TeleportEntityWrapper extends EntityWrapper {
|
|||||||
private Chunk getChunkRelative(final Chunk chunk, final int dx, final int dz) {
|
private Chunk getChunkRelative(final Chunk chunk, final int dx, final int dz) {
|
||||||
return chunk.getWorld().getChunkAt(chunk.getX() + dx, chunk.getZ() + dz);
|
return chunk.getWorld().getChunkAt(chunk.getX() + dx, chunk.getZ() + dz);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,8 @@ import com.sk89q.worldedit.bukkit.BukkitWorld;
|
|||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
final class BlockStatePopulator extends BlockPopulator {
|
final class BlockStatePopulator extends BlockPopulator {
|
||||||
@ -47,12 +47,16 @@ final class BlockStatePopulator extends BlockPopulator {
|
|||||||
|
|
||||||
private QueueCoordinator queue;
|
private QueueCoordinator queue;
|
||||||
|
|
||||||
public BlockStatePopulator(@Nonnull final IndependentPlotGenerator plotGenerator, @Nonnull final PlotAreaManager plotAreaManager) {
|
public BlockStatePopulator(
|
||||||
|
final @NonNull IndependentPlotGenerator plotGenerator,
|
||||||
|
final @NonNull PlotAreaManager plotAreaManager
|
||||||
|
) {
|
||||||
this.plotGenerator = plotGenerator;
|
this.plotGenerator = plotGenerator;
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void populate(@Nonnull final World world, @Nonnull final Random random, @Nonnull final Chunk source) {
|
@Override
|
||||||
|
public void populate(final @NonNull World world, final @NonNull Random random, final @NonNull Chunk source) {
|
||||||
if (this.queue == null) {
|
if (this.queue == null) {
|
||||||
this.queue = PlotSquared.platform().globalBlockQueue().getNewQueue(new BukkitWorld(world));
|
this.queue = PlotSquared.platform().globalBlockQueue().getNewQueue(new BukkitWorld(world));
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,8 @@ import com.plotsquared.core.generator.AugmentedUtils;
|
|||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class BukkitAugmentedGenerator extends BlockPopulator {
|
public class BukkitAugmentedGenerator extends BlockPopulator {
|
||||||
@ -51,7 +51,8 @@ public class BukkitAugmentedGenerator extends BlockPopulator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void populate(@Nonnull World world, @Nonnull Random random, @Nonnull Chunk source) {
|
public void populate(@NonNull World world, @NonNull Random random, @NonNull Chunk source) {
|
||||||
AugmentedUtils.generate(source, world.getName(), source.getX(), source.getZ(), null);
|
AugmentedUtils.generate(source, world.getName(), source.getX(), source.getZ(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,30 +41,32 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class BukkitPlotGenerator extends ChunkGenerator
|
public class BukkitPlotGenerator extends ChunkGenerator
|
||||||
implements GeneratorWrapper<ChunkGenerator> {
|
implements GeneratorWrapper<ChunkGenerator> {
|
||||||
|
|
||||||
@SuppressWarnings("unused") public final boolean PAPER_ASYNC_SAFE = true;
|
@SuppressWarnings("unused")
|
||||||
|
public final boolean PAPER_ASYNC_SAFE = true;
|
||||||
|
|
||||||
private final PlotAreaManager plotAreaManager;
|
private final PlotAreaManager plotAreaManager;
|
||||||
private final IndependentPlotGenerator plotGenerator;
|
private final IndependentPlotGenerator plotGenerator;
|
||||||
private final ChunkGenerator platformGenerator;
|
private final ChunkGenerator platformGenerator;
|
||||||
private final boolean full;
|
private final boolean full;
|
||||||
|
private final String levelName;
|
||||||
private List<BlockPopulator> populators;
|
private List<BlockPopulator> populators;
|
||||||
private boolean loaded = false;
|
private boolean loaded = false;
|
||||||
|
|
||||||
private final String levelName;
|
public BukkitPlotGenerator(
|
||||||
|
final @NonNull String name,
|
||||||
public BukkitPlotGenerator(@Nonnull final String name,
|
final @NonNull IndependentPlotGenerator generator,
|
||||||
@Nonnull final IndependentPlotGenerator generator,
|
final @NonNull PlotAreaManager plotAreaManager
|
||||||
@Nonnull final PlotAreaManager plotAreaManager) {
|
) {
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
this.levelName = name;
|
this.levelName = name;
|
||||||
this.plotGenerator = generator;
|
this.plotGenerator = generator;
|
||||||
@ -74,10 +76,10 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
|||||||
this.full = true;
|
this.full = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BukkitPlotGenerator(final String world, final ChunkGenerator cg, @Nonnull final PlotAreaManager plotAreaManager) {
|
public BukkitPlotGenerator(final String world, final ChunkGenerator cg, final @NonNull PlotAreaManager plotAreaManager) {
|
||||||
if (cg instanceof BukkitPlotGenerator) {
|
if (cg instanceof BukkitPlotGenerator) {
|
||||||
throw new IllegalArgumentException("ChunkGenerator: " + cg.getClass().getName()
|
throw new IllegalArgumentException("ChunkGenerator: " + cg.getClass().getName()
|
||||||
+ " is already a BukkitPlotGenerator!");
|
+ " is already a BukkitPlotGenerator!");
|
||||||
}
|
}
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
this.levelName = world;
|
this.levelName = world;
|
||||||
@ -86,23 +88,28 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
|||||||
this.plotGenerator = new DelegatePlotGenerator(cg, world);
|
this.plotGenerator = new DelegatePlotGenerator(cg, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void augment(PlotArea area) {
|
@Override
|
||||||
|
public void augment(PlotArea area) {
|
||||||
BukkitAugmentedGenerator.get(BukkitUtil.getWorld(area.getWorldName()));
|
BukkitAugmentedGenerator.get(BukkitUtil.getWorld(area.getWorldName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean isFull() {
|
@Override
|
||||||
|
public boolean isFull() {
|
||||||
return this.full;
|
return this.full;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public IndependentPlotGenerator getPlotGenerator() {
|
@Override
|
||||||
|
public IndependentPlotGenerator getPlotGenerator() {
|
||||||
return this.plotGenerator;
|
return this.plotGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public ChunkGenerator getPlatformGenerator() {
|
@Override
|
||||||
|
public ChunkGenerator getPlatformGenerator() {
|
||||||
return this.platformGenerator;
|
return this.platformGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public List<BlockPopulator> getDefaultPopulators(@Nonnull World world) {
|
@Override
|
||||||
|
public @NonNull List<BlockPopulator> getDefaultPopulators(@NonNull World world) {
|
||||||
try {
|
try {
|
||||||
if (!this.loaded) {
|
if (!this.loaded) {
|
||||||
String name = world.getName();
|
String name = world.getName();
|
||||||
@ -146,9 +153,11 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
|||||||
return toAdd;
|
return toAdd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull
|
@Override
|
||||||
public ChunkData generateChunkData(@Nonnull World world, @Nonnull Random random, int x, int z,
|
public @NonNull ChunkData generateChunkData(
|
||||||
@Nonnull BiomeGrid biome) {
|
@NonNull World world, @NonNull Random random, int x, int z,
|
||||||
|
@NonNull BiomeGrid biome
|
||||||
|
) {
|
||||||
|
|
||||||
GenChunk result = new GenChunk();
|
GenChunk result = new GenChunk();
|
||||||
if (this.getPlotGenerator() instanceof SingleWorldGenerator) {
|
if (this.getPlotGenerator() instanceof SingleWorldGenerator) {
|
||||||
@ -200,8 +209,8 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
|||||||
PlotArea area = this.plotAreaManager.getPlotArea(world.getName(), null);
|
PlotArea area = this.plotAreaManager.getPlotArea(world.getName(), null);
|
||||||
if (area == null && (area = this.plotAreaManager.getPlotArea(this.levelName, null)) == null) {
|
if (area == null && (area = this.plotAreaManager.getPlotArea(this.levelName, null)) == null) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Cannot regenerate chunk that does not belong to a plot area." + " Location: " + loc
|
"Cannot regenerate chunk that does not belong to a plot area." + " Location: " + loc
|
||||||
+ ", world: " + world);
|
+ ", world: " + world);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.plotGenerator.generateChunk(result, area);
|
this.plotGenerator.generateChunk(result, area);
|
||||||
@ -212,7 +221,8 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
|||||||
ChunkManager.postProcessChunk(loc, result);
|
ChunkManager.postProcessChunk(loc, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean canSpawn(@Nonnull final World world, final int x, final int z) {
|
@Override
|
||||||
|
public boolean canSpawn(final @NonNull World world, final int x, final int z) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +246,8 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String toString() {
|
@Override
|
||||||
|
public String toString() {
|
||||||
if (this.platformGenerator == this) {
|
if (this.platformGenerator == this) {
|
||||||
return this.plotGenerator.getName();
|
return this.plotGenerator.getName();
|
||||||
}
|
}
|
||||||
@ -247,7 +258,8 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean equals(final Object obj) {
|
@Override
|
||||||
|
public boolean equals(final Object obj) {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -257,4 +269,5 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
|||||||
public String getLevelName() {
|
public String getLevelName() {
|
||||||
return this.levelName;
|
return this.levelName;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,8 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
final class DelegatePlotGenerator extends IndependentPlotGenerator {
|
final class DelegatePlotGenerator extends IndependentPlotGenerator {
|
||||||
@ -52,18 +52,22 @@ final class DelegatePlotGenerator extends IndependentPlotGenerator {
|
|||||||
this.world = world;
|
this.world = world;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void initialize(PlotArea area) {
|
@Override
|
||||||
|
public void initialize(PlotArea area) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String getName() {
|
@Override
|
||||||
|
public String getName() {
|
||||||
return this.chunkGenerator.getClass().getName();
|
return this.chunkGenerator.getClass().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
|
@Override
|
||||||
|
public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
|
||||||
return PlotSquared.platform().defaultGenerator().getNewPlotArea(world, id, min, max);
|
return PlotSquared.platform().defaultGenerator().getNewPlotArea(world, id, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void generateChunk(final ScopedQueueCoordinator result, PlotArea settings) {
|
@Override
|
||||||
|
public void generateChunk(final ScopedQueueCoordinator result, PlotArea settings) {
|
||||||
World world = BukkitUtil.getWorld(this.world);
|
World world = BukkitUtil.getWorld(this.world);
|
||||||
Location min = result.getMin();
|
Location min = result.getMin();
|
||||||
int chunkX = min.getX() >> 4;
|
int chunkX = min.getX() >> 4;
|
||||||
@ -71,21 +75,24 @@ final class DelegatePlotGenerator extends IndependentPlotGenerator {
|
|||||||
Random random = new Random(MathMan.pair((short) chunkX, (short) chunkZ));
|
Random random = new Random(MathMan.pair((short) chunkX, (short) chunkZ));
|
||||||
try {
|
try {
|
||||||
ChunkGenerator.BiomeGrid grid = new ChunkGenerator.BiomeGrid() {
|
ChunkGenerator.BiomeGrid grid = new ChunkGenerator.BiomeGrid() {
|
||||||
@Override public void setBiome(int x, int z, @Nonnull Biome biome) {
|
@Override
|
||||||
|
public void setBiome(int x, int z, @NonNull Biome biome) {
|
||||||
result.setBiome(x, z, BukkitAdapter.adapt(biome));
|
result.setBiome(x, z, BukkitAdapter.adapt(biome));
|
||||||
}
|
}
|
||||||
|
|
||||||
//do not annotate with Override until we discontinue support for 1.4.4
|
//do not annotate with Override until we discontinue support for 1.4.4
|
||||||
public void setBiome(int x, int y, int z, @Nonnull Biome biome) {
|
public void setBiome(int x, int y, int z, @NonNull Biome biome) {
|
||||||
result.setBiome(x, z, BukkitAdapter.adapt(biome));
|
result.setBiome(x, z, BukkitAdapter.adapt(biome));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public Biome getBiome(int x, int z) {
|
@Override
|
||||||
|
public @NonNull Biome getBiome(int x, int z) {
|
||||||
return Biome.FOREST;
|
return Biome.FOREST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public @Nonnull Biome getBiome(int x, int y, int z) {
|
@Override
|
||||||
|
public @NonNull Biome getBiome(int x, int y, int z) {
|
||||||
return Biome.FOREST;
|
return Biome.FOREST;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -40,10 +40,11 @@ public class BackupModule extends AbstractModule {
|
|||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + BackupModule.class.getSimpleName());
|
private static final Logger logger = LoggerFactory.getLogger("P2/" + BackupModule.class.getSimpleName());
|
||||||
|
|
||||||
@Override protected void configure() {
|
@Override
|
||||||
|
protected void configure() {
|
||||||
try {
|
try {
|
||||||
install(new FactoryModuleBuilder()
|
install(new FactoryModuleBuilder()
|
||||||
.implement(BackupProfile.class, PlayerBackupProfile.class).build(PlayerBackupProfileFactory.class));
|
.implement(BackupProfile.class, PlayerBackupProfile.class).build(PlayerBackupProfileFactory.class));
|
||||||
bind(BackupManager.class).to(SimpleBackupManager.class);
|
bind(BackupManager.class).to(SimpleBackupManager.class);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
logger.error("Failed to initialize backup manager", e);
|
logger.error("Failed to initialize backup manager", e);
|
||||||
|
@ -29,7 +29,6 @@ import com.google.inject.AbstractModule;
|
|||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||||
import com.google.inject.assistedinject.FactoryProvider;
|
|
||||||
import com.plotsquared.bukkit.BukkitPlatform;
|
import com.plotsquared.bukkit.BukkitPlatform;
|
||||||
import com.plotsquared.bukkit.listener.SingleWorldListener;
|
import com.plotsquared.bukkit.listener.SingleWorldListener;
|
||||||
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
||||||
@ -73,32 +72,33 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
public class BukkitModule extends AbstractModule {
|
public class BukkitModule extends AbstractModule {
|
||||||
|
|
||||||
private final BukkitPlatform bukkitPlatform;
|
private final BukkitPlatform bukkitPlatform;
|
||||||
|
|
||||||
public BukkitModule(@Nonnull final BukkitPlatform bukkitPlatform) {
|
public BukkitModule(final @NonNull BukkitPlatform bukkitPlatform) {
|
||||||
this.bukkitPlatform = bukkitPlatform;
|
this.bukkitPlatform = bukkitPlatform;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void configure() {
|
@Override
|
||||||
|
protected void configure() {
|
||||||
bind(PlayerManager.class).to(BukkitPlayerManager.class);
|
bind(PlayerManager.class).to(BukkitPlayerManager.class);
|
||||||
bind(JavaPlugin.class).toInstance(bukkitPlatform);
|
bind(JavaPlugin.class).toInstance(bukkitPlatform);
|
||||||
bind(PlotPlatform.class).toInstance(bukkitPlatform);
|
bind(PlotPlatform.class).toInstance(bukkitPlatform);
|
||||||
bind(BukkitPlatform.class).toInstance(bukkitPlatform);
|
bind(BukkitPlatform.class).toInstance(bukkitPlatform);
|
||||||
bind(IndependentPlotGenerator.class).annotatedWith(DefaultGenerator.class).to(HybridGen.class);
|
bind(IndependentPlotGenerator.class).annotatedWith(DefaultGenerator.class).to(HybridGen.class);
|
||||||
// Console actor
|
// Console actor
|
||||||
@Nonnull ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
|
@NonNull ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
|
||||||
WorldEditPlugin wePlugin = ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"));
|
WorldEditPlugin wePlugin = ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"));
|
||||||
bind(Actor.class).annotatedWith(ConsoleActor.class).toInstance(wePlugin.wrapCommandSender(console));
|
bind(Actor.class).annotatedWith(ConsoleActor.class).toInstance(wePlugin.wrapCommandSender(console));
|
||||||
bind(InventoryUtil.class).to(BukkitInventoryUtil.class);
|
bind(InventoryUtil.class).to(BukkitInventoryUtil.class);
|
||||||
bind(SetupUtils.class).to(BukkitSetupUtils.class);
|
bind(SetupUtils.class).to(BukkitSetupUtils.class);
|
||||||
bind(WorldUtil.class).to(BukkitUtil.class);
|
bind(WorldUtil.class).to(BukkitUtil.class);
|
||||||
install(new FactoryModuleBuilder().implement(ProgressSubscriber.class, DefaultProgressSubscriber.class).build(ProgressSubscriberFactory.class));
|
install(new FactoryModuleBuilder()
|
||||||
|
.implement(ProgressSubscriber.class, DefaultProgressSubscriber.class)
|
||||||
|
.build(ProgressSubscriberFactory.class));
|
||||||
bind(GlobalBlockQueue.class).toInstance(new GlobalBlockQueue(QueueProvider.of(BukkitQueueCoordinator.class)));
|
bind(GlobalBlockQueue.class).toInstance(new GlobalBlockQueue(QueueProvider.of(BukkitQueueCoordinator.class)));
|
||||||
bind(ChunkManager.class).to(BukkitChunkManager.class);
|
bind(ChunkManager.class).to(BukkitChunkManager.class);
|
||||||
bind(RegionManager.class).to(BukkitRegionManager.class);
|
bind(RegionManager.class).to(BukkitRegionManager.class);
|
||||||
@ -114,11 +114,15 @@ public class BukkitModule extends AbstractModule {
|
|||||||
bind(PlotAreaManager.class).to(DefaultPlotAreaManager.class);
|
bind(PlotAreaManager.class).to(DefaultPlotAreaManager.class);
|
||||||
}
|
}
|
||||||
install(new FactoryModuleBuilder().build(HybridPlotWorldFactory.class));
|
install(new FactoryModuleBuilder().build(HybridPlotWorldFactory.class));
|
||||||
install(new FactoryModuleBuilder().implement(ChunkCoordinator.class, BukkitChunkCoordinator.class).build(ChunkCoordinatorFactory.class));
|
install(new FactoryModuleBuilder()
|
||||||
|
.implement(ChunkCoordinator.class, BukkitChunkCoordinator.class)
|
||||||
|
.build(ChunkCoordinatorFactory.class));
|
||||||
install(new FactoryModuleBuilder().build(ChunkCoordinatorBuilderFactory.class));
|
install(new FactoryModuleBuilder().build(ChunkCoordinatorBuilderFactory.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides @Singleton @Nonnull EconHandler provideEconHandler() {
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
@NonNull EconHandler provideEconHandler() {
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
|
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
|
||||||
try {
|
try {
|
||||||
return new BukkitEconHandler();
|
return new BukkitEconHandler();
|
||||||
|
@ -35,7 +35,9 @@ import org.bukkit.Bukkit;
|
|||||||
|
|
||||||
public class PermissionModule extends AbstractModule {
|
public class PermissionModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides @Singleton PermissionHandler providePermissionHandler() {
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
PermissionHandler providePermissionHandler() {
|
||||||
try {
|
try {
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
|
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
|
||||||
return new VaultPermissionHandler();
|
return new VaultPermissionHandler();
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.bukkit.listener;
|
package com.plotsquared.bukkit.listener;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.plotsquared.core.PlotSquared;
|
import com.plotsquared.core.PlotSquared;
|
||||||
@ -102,9 +103,8 @@ import org.bukkit.event.world.StructureGrowEvent;
|
|||||||
import org.bukkit.material.Directional;
|
import org.bukkit.material.Directional;
|
||||||
import org.bukkit.projectiles.BlockProjectileSource;
|
import org.bukkit.projectiles.BlockProjectileSource;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -116,7 +116,8 @@ public class BlockEventListener implements Listener {
|
|||||||
private final PlotAreaManager plotAreaManager;
|
private final PlotAreaManager plotAreaManager;
|
||||||
private final WorldEdit worldEdit;
|
private final WorldEdit worldEdit;
|
||||||
|
|
||||||
@Inject public BlockEventListener(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final WorldEdit worldEdit) {
|
@Inject
|
||||||
|
public BlockEventListener(final @NonNull PlotAreaManager plotAreaManager, final @NonNull WorldEdit worldEdit) {
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
this.worldEdit = worldEdit;
|
this.worldEdit = worldEdit;
|
||||||
}
|
}
|
||||||
@ -140,7 +141,8 @@ public class BlockEventListener implements Listener {
|
|||||||
}, TaskTime.ticks(3L));
|
}, TaskTime.ticks(3L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onRedstoneEvent(BlockRedstoneEvent event) {
|
@EventHandler
|
||||||
|
public void onRedstoneEvent(BlockRedstoneEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
Location location = BukkitUtil.adapt(block.getLocation());
|
Location location = BukkitUtil.adapt(block.getLocation());
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
@ -281,19 +283,19 @@ public class BlockEventListener implements Listener {
|
|||||||
Plot plot = area.getPlot(location);
|
Plot plot = area.getPlot(location);
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
if ((location.getY() > area.getMaxBuildHeight() || location.getY() < area
|
if ((location.getY() > area.getMaxBuildHeight() || location.getY() < area
|
||||||
.getMinBuildHeight()) && !Permissions
|
.getMinBuildHeight()) && !Permissions
|
||||||
.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_HEIGHT_LIMIT)) {
|
.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_HEIGHT_LIMIT)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("height.height_limit"),
|
TranslatableCaption.of("height.height_limit"),
|
||||||
Template.of("limit", String.valueOf(area.getMaxBuildHeight()))
|
Template.of("limit", String.valueOf(area.getMaxBuildHeight()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_UNOWNED)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_UNOWNED)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_UNOWNED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_UNOWNED))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -303,25 +305,25 @@ public class BlockEventListener implements Listener {
|
|||||||
if (place != null) {
|
if (place != null) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
if (place.contains(
|
if (place.contains(
|
||||||
BlockTypeWrapper.get(BukkitAdapter.asBlockType(block.getType())))) {
|
BlockTypeWrapper.get(BukkitAdapter.asBlockType(block.getType())))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
plot.debug(player.getName() + " could not place " + event.getBlock().getType()
|
plot.debug(player.getName() + " could not place " + event.getBlock().getType()
|
||||||
+ " because of the place flag");
|
+ " because of the place flag");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
} else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -332,19 +334,20 @@ public class BlockEventListener implements Listener {
|
|||||||
if (block.getType().hasGravity()) {
|
if (block.getType().hasGravity()) {
|
||||||
sendBlockChange(block.getLocation(), block.getBlockData());
|
sendBlockChange(block.getLocation(), block.getBlockData());
|
||||||
plot.debug(event.getBlock().getType()
|
plot.debug(event.getBlock().getType()
|
||||||
+ " did not fall because of disable-physics = true");
|
+ " did not fall because of disable-physics = true");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_ROAD)) {
|
} else if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_ROAD)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_ROAD))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_ROAD))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST) public void blockDestroy(BlockBreakEvent event) {
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void blockDestroy(BlockBreakEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Location location = BukkitUtil.adapt(event.getBlock().getLocation());
|
Location location = BukkitUtil.adapt(event.getBlock().getLocation());
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
@ -356,26 +359,26 @@ public class BlockEventListener implements Listener {
|
|||||||
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
|
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
|
||||||
if (event.getBlock().getY() == 0) {
|
if (event.getBlock().getY() == 0) {
|
||||||
if (!Permissions
|
if (!Permissions
|
||||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL)) {
|
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL)) {
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if ((location.getY() > area.getMaxBuildHeight() || location.getY() < area
|
} else if ((location.getY() > area.getMaxBuildHeight() || location.getY() < area
|
||||||
.getMinBuildHeight()) && !Permissions
|
.getMinBuildHeight()) && !Permissions
|
||||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_BUILD_HEIGHT_LIMIT)) {
|
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_BUILD_HEIGHT_LIMIT)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("height.height_limit"),
|
TranslatableCaption.of("height.height_limit"),
|
||||||
Template.of("limit", String.valueOf(area.getMaxBuildHeight()))
|
Template.of("limit", String.valueOf(area.getMaxBuildHeight()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
if (!Permissions
|
if (!Permissions
|
||||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY_UNOWNED, true)) {
|
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY_UNOWNED, true)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -390,19 +393,19 @@ public class BlockEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Permissions
|
if (Permissions
|
||||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY_OTHER)) {
|
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY_OTHER)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_OTHER))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
} else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
||||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_OTHER))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -414,20 +417,21 @@ public class BlockEventListener implements Listener {
|
|||||||
if (Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_ROAD)) {
|
if (Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_ROAD)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.worldEdit!= null && pp.getAttribute("worldedit")) {
|
if (this.worldEdit != null && pp.getAttribute("worldedit")) {
|
||||||
if (player.getInventory().getItemInMainHand().getType() == Material
|
if (player.getInventory().getItemInMainHand().getType() == Material
|
||||||
.getMaterial(this.worldEdit.getConfiguration().wandItem)) {
|
.getMaterial(this.worldEdit.getConfiguration().wandItem)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_ROAD))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_ROAD))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockSpread(BlockSpreadEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBlockSpread(BlockSpreadEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
Location location = BukkitUtil.adapt(block.getLocation());
|
Location location = BukkitUtil.adapt(block.getLocation());
|
||||||
if (location.isPlotRoad()) {
|
if (location.isPlotRoad()) {
|
||||||
@ -474,7 +478,9 @@ public class BlockEventListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onBlockForm(BlockFormEvent event) {
|
public void onBlockForm(BlockFormEvent event) {
|
||||||
if (event instanceof EntityBlockFormEvent) return; // handled below
|
if (event instanceof EntityBlockFormEvent) {
|
||||||
|
return; // handled below
|
||||||
|
}
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
Location location = BukkitUtil.adapt(block.getLocation());
|
Location location = BukkitUtil.adapt(block.getLocation());
|
||||||
if (location.isPlotRoad()) {
|
if (location.isPlotRoad()) {
|
||||||
@ -546,9 +552,11 @@ public class BlockEventListener implements Listener {
|
|||||||
if (allowed) {
|
if (allowed) {
|
||||||
return; // player is not added but forming <flag> is allowed
|
return; // player is not added but forming <flag> is allowed
|
||||||
}
|
}
|
||||||
plot.debug(String.format("%s could not be formed because %s = false (entity is player)",
|
plot.debug(String.format(
|
||||||
|
"%s could not be formed because %s = false (entity is player)",
|
||||||
event.getNewState().getType(),
|
event.getNewState().getType(),
|
||||||
flag == SnowFormFlag.class ? "snow-form" : "ice-form"));
|
flag == SnowFormFlag.class ? "snow-form" : "ice-form"
|
||||||
|
));
|
||||||
event.setCancelled(true); // player is not added and forming <flag> isn't allowed
|
event.setCancelled(true); // player is not added and forming <flag> isn't allowed
|
||||||
}
|
}
|
||||||
return; // event is cancelled if not added and not allowed, otherwise forming <flag> is allowed
|
return; // event is cancelled if not added and not allowed, otherwise forming <flag> is allowed
|
||||||
@ -557,9 +565,11 @@ public class BlockEventListener implements Listener {
|
|||||||
if (allowed) {
|
if (allowed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plot.debug(String.format("%s could not be formed because %s = false (entity is not player)",
|
plot.debug(String.format(
|
||||||
|
"%s could not be formed because %s = false (entity is not player)",
|
||||||
event.getNewState().getType(),
|
event.getNewState().getType(),
|
||||||
flag == SnowFormFlag.class ? "snow-form" : "ice-form"));
|
flag == SnowFormFlag.class ? "snow-form" : "ice-form"
|
||||||
|
));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -592,7 +602,7 @@ public class BlockEventListener implements Listener {
|
|||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
|
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
|
||||||
if (Permissions
|
if (Permissions
|
||||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
|
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -603,13 +613,13 @@ public class BlockEventListener implements Listener {
|
|||||||
List<BlockTypeWrapper> destroy = plot.getFlag(BreakFlag.class);
|
List<BlockTypeWrapper> destroy = plot.getFlag(BreakFlag.class);
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
if (destroy
|
if (destroy
|
||||||
.contains(BlockTypeWrapper.get(BukkitAdapter.asBlockType(block.getType())))
|
.contains(BlockTypeWrapper.get(BukkitAdapter.asBlockType(block.getType())))
|
||||||
|| Permissions
|
|| Permissions
|
||||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY_OTHER)) {
|
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY_OTHER)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plot.debug(player.getName() + " could not break " + block.getType()
|
plot.debug(player.getName() + " could not break " + block.getType()
|
||||||
+ " because it was not in the break flag");
|
+ " because it was not in the break flag");
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -622,7 +632,8 @@ public class BlockEventListener implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onFade(BlockFadeEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onFade(BlockFadeEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
Location location = BukkitUtil.adapt(block.getLocation());
|
Location location = BukkitUtil.adapt(block.getLocation());
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
@ -681,7 +692,8 @@ public class BlockEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onChange(BlockFromToEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onChange(BlockFromToEvent event) {
|
||||||
Block from = event.getBlock();
|
Block from = event.getBlock();
|
||||||
|
|
||||||
// Check liquid flow flag inside of origin plot too
|
// Check liquid flow flag inside of origin plot too
|
||||||
@ -689,7 +701,9 @@ public class BlockEventListener implements Listener {
|
|||||||
final PlotArea fromArea = fLocation.getPlotArea();
|
final PlotArea fromArea = fLocation.getPlotArea();
|
||||||
if (fromArea != null) {
|
if (fromArea != null) {
|
||||||
final Plot plot = fromArea.getOwnedPlot(fLocation);
|
final Plot plot = fromArea.getOwnedPlot(fLocation);
|
||||||
if (plot != null && plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.DISABLED && event.getBlock().isLiquid()) {
|
if (plot != null && plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.DISABLED && event
|
||||||
|
.getBlock()
|
||||||
|
.isLiquid()) {
|
||||||
plot.debug("Liquid could now flow because liquid-flow = disabled");
|
plot.debug("Liquid could now flow because liquid-flow = disabled");
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -737,20 +751,21 @@ public class BlockEventListener implements Listener {
|
|||||||
<-----O-----> x
|
<-----O-----> x
|
||||||
*/
|
*/
|
||||||
if (BukkitUtil.adapt(location.clone().add(-1, 0, 1) /* A */).getPlot() != null
|
if (BukkitUtil.adapt(location.clone().add(-1, 0, 1) /* A */).getPlot() != null
|
||||||
|| BukkitUtil.adapt(location.clone().add(1, 0, 0) /* B */).getPlot() != null
|
|| BukkitUtil.adapt(location.clone().add(1, 0, 0) /* B */).getPlot() != null
|
||||||
|| BukkitUtil.adapt(location.clone().add(1, 0, 1) /* C */).getPlot() != null
|
|| BukkitUtil.adapt(location.clone().add(1, 0, 1) /* C */).getPlot() != null
|
||||||
|| BukkitUtil.adapt(location.clone().add(-1, 0, 0) /* D */).getPlot() != null
|
|| BukkitUtil.adapt(location.clone().add(-1, 0, 0) /* D */).getPlot() != null
|
||||||
|| BukkitUtil.adapt(location.clone().add(1, 0, 0) /* E */).getPlot() != null
|
|| BukkitUtil.adapt(location.clone().add(1, 0, 0) /* E */).getPlot() != null
|
||||||
|| BukkitUtil.adapt(location.clone().add(-1, 0, -1) /* F */).getPlot() != null
|
|| BukkitUtil.adapt(location.clone().add(-1, 0, -1) /* F */).getPlot() != null
|
||||||
|| BukkitUtil.adapt(location.clone().add(0, 0, -1) /* G */).getPlot() != null
|
|| BukkitUtil.adapt(location.clone().add(0, 0, -1) /* G */).getPlot() != null
|
||||||
|| BukkitUtil.adapt(location.clone().add(1, 0, 1) /* H */).getPlot() != null) {
|
|| BukkitUtil.adapt(location.clone().add(1, 0, 1) /* H */).getPlot() != null) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onGrow(BlockGrowEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onGrow(BlockGrowEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
Location location = BukkitUtil.adapt(block.getLocation());
|
Location location = BukkitUtil.adapt(block.getLocation());
|
||||||
if (location.isUnownedPlotArea()) {
|
if (location.isUnownedPlotArea()) {
|
||||||
@ -758,7 +773,8 @@ public class BlockEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
Location location = BukkitUtil.adapt(block.getLocation());
|
Location location = BukkitUtil.adapt(block.getLocation());
|
||||||
BlockFace face = event.getDirection();
|
BlockFace face = event.getDirection();
|
||||||
@ -770,7 +786,9 @@ public class BlockEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
for (Block block1 : event.getBlocks()) {
|
for (Block block1 : event.getBlocks()) {
|
||||||
Location bloc = BukkitUtil.adapt(block1.getLocation());
|
Location bloc = BukkitUtil.adapt(block1.getLocation());
|
||||||
if (bloc.isPlotArea() || bloc.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ()).isPlotArea()) {
|
if (bloc.isPlotArea() || bloc
|
||||||
|
.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())
|
||||||
|
.isPlotArea()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -789,12 +807,15 @@ public class BlockEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
for (Block block1 : event.getBlocks()) {
|
for (Block block1 : event.getBlocks()) {
|
||||||
Location bloc = BukkitUtil.adapt(block1.getLocation());
|
Location bloc = BukkitUtil.adapt(block1.getLocation());
|
||||||
if (!area.contains(bloc.getX(), bloc.getZ()) || !area.contains(bloc.getX() + relative.getBlockX(), bloc.getZ() + relative.getBlockZ())) {
|
if (!area.contains(bloc.getX(), bloc.getZ()) || !area.contains(
|
||||||
|
bloc.getX() + relative.getBlockX(),
|
||||||
|
bloc.getZ() + relative.getBlockZ()
|
||||||
|
)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!plot.equals(area.getOwnedPlot(bloc)) || !plot
|
if (!plot.equals(area.getOwnedPlot(bloc)) || !plot
|
||||||
.equals(area.getOwnedPlot(bloc.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) {
|
.equals(area.getOwnedPlot(bloc.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -807,7 +828,8 @@ public class BlockEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
Location location = BukkitUtil.adapt(block.getLocation());
|
Location location = BukkitUtil.adapt(block.getLocation());
|
||||||
BlockFace face = event.getDirection();
|
BlockFace face = event.getDirection();
|
||||||
@ -819,7 +841,9 @@ public class BlockEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
for (Block block1 : event.getBlocks()) {
|
for (Block block1 : event.getBlocks()) {
|
||||||
Location bloc = BukkitUtil.adapt(block1.getLocation());
|
Location bloc = BukkitUtil.adapt(block1.getLocation());
|
||||||
if (bloc.isPlotArea() || bloc.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ()).isPlotArea()) {
|
if (bloc.isPlotArea() || bloc
|
||||||
|
.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())
|
||||||
|
.isPlotArea()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -833,19 +857,23 @@ public class BlockEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
for (Block block1 : event.getBlocks()) {
|
for (Block block1 : event.getBlocks()) {
|
||||||
Location bloc = BukkitUtil.adapt(block1.getLocation());
|
Location bloc = BukkitUtil.adapt(block1.getLocation());
|
||||||
if (!area.contains(bloc.getX(), bloc.getZ()) || !area.contains(bloc.getX() + relative.getBlockX(), bloc.getZ() + relative.getBlockZ())) {
|
if (!area.contains(bloc.getX(), bloc.getZ()) || !area.contains(
|
||||||
|
bloc.getX() + relative.getBlockX(),
|
||||||
|
bloc.getZ() + relative.getBlockZ()
|
||||||
|
)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!plot.equals(area.getOwnedPlot(bloc)) || !plot
|
if (!plot.equals(area.getOwnedPlot(bloc)) || !plot
|
||||||
.equals(area.getOwnedPlot(bloc.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) {
|
.equals(area.getOwnedPlot(bloc.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockDispense(BlockDispenseEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBlockDispense(BlockDispenseEvent event) {
|
||||||
Material type = event.getItem().getType();
|
Material type = event.getItem().getType();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SHULKER_BOX:
|
case SHULKER_BOX:
|
||||||
@ -891,7 +919,8 @@ public class BlockEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onStructureGrow(StructureGrowEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onStructureGrow(StructureGrowEvent event) {
|
||||||
if (!this.plotAreaManager.hasPlotArea(event.getWorld().getName())) {
|
if (!this.plotAreaManager.hasPlotArea(event.getWorld().getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -947,7 +976,8 @@ public class BlockEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBigBoom(BlockExplodeEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBigBoom(BlockExplodeEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
Location location = BukkitUtil.adapt(block.getLocation());
|
Location location = BukkitUtil.adapt(block.getLocation());
|
||||||
String world = location.getWorldName();
|
String world = location.getWorldName();
|
||||||
@ -975,7 +1005,8 @@ public class BlockEventListener implements Listener {
|
|||||||
event.blockList().removeIf(blox -> !plot.equals(area.getOwnedPlot(BukkitUtil.adapt(blox.getLocation()))));
|
event.blockList().removeIf(blox -> !plot.equals(area.getOwnedPlot(BukkitUtil.adapt(blox.getLocation()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBurn(BlockBurnEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBlockBurn(BlockBurnEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
Location location = BukkitUtil.adapt(block.getLocation());
|
Location location = BukkitUtil.adapt(block.getLocation());
|
||||||
|
|
||||||
@ -1016,24 +1047,24 @@ public class BlockEventListener implements Listener {
|
|||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_ROAD)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_ROAD)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_ROAD))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_ROAD))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
} else if (!plot.hasOwner()) {
|
} else if (!plot.hasOwner()) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_UNOWNED)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_UNOWNED)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_UNOWNED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_UNOWNED))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
} else if (!plot.isAdded(pp.getUUID())) {
|
} else if (!plot.isAdded(pp.getUUID())) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -1061,7 +1092,7 @@ public class BlockEventListener implements Listener {
|
|||||||
location = BukkitUtil.adapt(shooter.getLocation());
|
location = BukkitUtil.adapt(shooter.getLocation());
|
||||||
} else if (fireball.getShooter() instanceof BlockProjectileSource) {
|
} else if (fireball.getShooter() instanceof BlockProjectileSource) {
|
||||||
Block shooter =
|
Block shooter =
|
||||||
((BlockProjectileSource) fireball.getShooter()).getBlock();
|
((BlockProjectileSource) fireball.getShooter()).getBlock();
|
||||||
location = BukkitUtil.adapt(shooter.getLocation());
|
location = BukkitUtil.adapt(shooter.getLocation());
|
||||||
}
|
}
|
||||||
if (location != null && !plot.equals(location.getPlot())) {
|
if (location != null && !plot.equals(location.getPlot())) {
|
||||||
@ -1074,18 +1105,19 @@ public class BlockEventListener implements Listener {
|
|||||||
Block ignitingBlock = event.getIgnitingBlock();
|
Block ignitingBlock = event.getIgnitingBlock();
|
||||||
Plot plotIgnited = BukkitUtil.adapt(ignitingBlock.getLocation()).getPlot();
|
Plot plotIgnited = BukkitUtil.adapt(ignitingBlock.getLocation()).getPlot();
|
||||||
if (igniteCause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL && (
|
if (igniteCause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL && (
|
||||||
!plot.getFlag(BlockIgnitionFlag.class) || plotIgnited == null || !plotIgnited
|
!plot.getFlag(BlockIgnitionFlag.class) || plotIgnited == null || !plotIgnited
|
||||||
.equals(plot)) || (igniteCause == BlockIgniteEvent.IgniteCause.SPREAD
|
.equals(plot)) || (igniteCause == BlockIgniteEvent.IgniteCause.SPREAD
|
||||||
|| igniteCause == BlockIgniteEvent.IgniteCause.LAVA) && (
|
|| igniteCause == BlockIgniteEvent.IgniteCause.LAVA) && (
|
||||||
!plot.getFlag(BlockIgnitionFlag.class) || plotIgnited == null || !plotIgnited
|
!plot.getFlag(BlockIgnitionFlag.class) || plotIgnited == null || !plotIgnited
|
||||||
.equals(plot))) {
|
.equals(plot))) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onLeavesDecay(LeavesDecayEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onLeavesDecay(LeavesDecayEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
Location location = BukkitUtil.adapt(block.getLocation());
|
Location location = BukkitUtil.adapt(block.getLocation());
|
||||||
|
|
||||||
@ -1103,4 +1135,5 @@ public class BlockEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -54,10 +54,10 @@ import org.bukkit.event.entity.CreatureSpawnEvent;
|
|||||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||||
import org.bukkit.event.world.ChunkLoadEvent;
|
import org.bukkit.event.world.ChunkLoadEvent;
|
||||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -76,7 +76,8 @@ public class ChunkListener implements Listener {
|
|||||||
private Chunk lastChunk;
|
private Chunk lastChunk;
|
||||||
private boolean ignoreUnload = false;
|
private boolean ignoreUnload = false;
|
||||||
|
|
||||||
@Inject public ChunkListener(@Nonnull final PlotAreaManager plotAreaManager) {
|
@Inject
|
||||||
|
public ChunkListener(final @NonNull PlotAreaManager plotAreaManager) {
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
if (Settings.Chunk_Processor.AUTO_TRIM) {
|
if (Settings.Chunk_Processor.AUTO_TRIM) {
|
||||||
try {
|
try {
|
||||||
@ -105,11 +106,11 @@ public class ChunkListener implements Listener {
|
|||||||
Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world);
|
Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world);
|
||||||
Object chunkMap = w.getClass().getDeclaredMethod("getPlayerChunkMap").invoke(w);
|
Object chunkMap = w.getClass().getDeclaredMethod("getPlayerChunkMap").invoke(w);
|
||||||
Method methodIsChunkInUse =
|
Method methodIsChunkInUse =
|
||||||
chunkMap.getClass().getDeclaredMethod("isChunkInUse", int.class, int.class);
|
chunkMap.getClass().getDeclaredMethod("isChunkInUse", int.class, int.class);
|
||||||
Chunk[] chunks = world.getLoadedChunks();
|
Chunk[] chunks = world.getLoadedChunks();
|
||||||
for (Chunk chunk : chunks) {
|
for (Chunk chunk : chunks) {
|
||||||
if ((boolean) methodIsChunkInUse
|
if ((boolean) methodIsChunkInUse
|
||||||
.invoke(chunkMap, chunk.getX(), chunk.getZ())) {
|
.invoke(chunkMap, chunk.getX(), chunk.getZ())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int x = chunk.getX();
|
int x = chunk.getX();
|
||||||
@ -179,7 +180,8 @@ public class ChunkListener implements Listener {
|
|||||||
return plot != null && plot.hasOwner();
|
return plot != null && plot.hasOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onChunkUnload(ChunkUnloadEvent event) {
|
@EventHandler
|
||||||
|
public void onChunkUnload(ChunkUnloadEvent event) {
|
||||||
if (ignoreUnload) {
|
if (ignoreUnload) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -197,11 +199,13 @@ public class ChunkListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onChunkLoad(ChunkLoadEvent event) {
|
@EventHandler
|
||||||
|
public void onChunkLoad(ChunkLoadEvent event) {
|
||||||
processChunk(event.getChunk(), false);
|
processChunk(event.getChunk(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST) public void onItemSpawn(ItemSpawnEvent event) {
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onItemSpawn(ItemSpawnEvent event) {
|
||||||
Item entity = event.getEntity();
|
Item entity = event.getEntity();
|
||||||
PaperLib.getChunkAtAsync(event.getLocation()).thenAccept(chunk -> {
|
PaperLib.getChunkAtAsync(event.getLocation()).thenAccept(chunk -> {
|
||||||
if (chunk == this.lastChunk) {
|
if (chunk == this.lastChunk) {
|
||||||
@ -306,10 +310,11 @@ public class ChunkListener implements Listener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0 ; i < (tiles.length - Settings.Chunk_Processor.MAX_TILES); i++) {
|
for (int i = 0; i < (tiles.length - Settings.Chunk_Processor.MAX_TILES); i++) {
|
||||||
tiles[i].getBlock().setType(Material.AIR, false);
|
tiles[i].getBlock().setType(Material.AIR, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.bukkit.listener;
|
package com.plotsquared.bukkit.listener;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.plotsquared.core.PlotSquared;
|
import com.plotsquared.core.PlotSquared;
|
||||||
@ -60,9 +61,8 @@ import org.bukkit.event.vehicle.VehicleCreateEvent;
|
|||||||
import org.bukkit.metadata.FixedMetadataValue;
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
import org.bukkit.metadata.MetadataValue;
|
import org.bukkit.metadata.MetadataValue;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -72,20 +72,28 @@ public class EntityEventListener implements Listener {
|
|||||||
private final PlotAreaManager plotAreaManager;
|
private final PlotAreaManager plotAreaManager;
|
||||||
private float lastRadius;
|
private float lastRadius;
|
||||||
|
|
||||||
@Inject public EntityEventListener(@Nonnull final PlotAreaManager plotAreaManager) {
|
@Inject
|
||||||
|
public EntityEventListener(final @NonNull PlotAreaManager plotAreaManager) {
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST) public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
|
||||||
EntityDamageByEntityEvent eventChange =
|
EntityDamageByEntityEvent eventChange =
|
||||||
new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), EntityDamageEvent.DamageCause.FIRE_TICK, event.getDuration());
|
new EntityDamageByEntityEvent(
|
||||||
|
event.getCombuster(),
|
||||||
|
event.getEntity(),
|
||||||
|
EntityDamageEvent.DamageCause.FIRE_TICK,
|
||||||
|
event.getDuration()
|
||||||
|
);
|
||||||
onEntityDamageByEntityEvent(eventChange);
|
onEntityDamageByEntityEvent(eventChange);
|
||||||
if (eventChange.isCancelled()) {
|
if (eventChange.isCancelled()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST) public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
||||||
Entity damager = event.getDamager();
|
Entity damager = event.getDamager();
|
||||||
Location location = BukkitUtil.adapt(damager.getLocation());
|
Location location = BukkitUtil.adapt(damager.getLocation());
|
||||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||||
@ -115,7 +123,8 @@ public class EntityEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void creatureSpawnEvent(CreatureSpawnEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void creatureSpawnEvent(CreatureSpawnEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
@ -185,7 +194,8 @@ public class EntityEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onEntityFall(EntityChangeBlockEvent event) {
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
|
public void onEntityFall(EntityChangeBlockEvent event) {
|
||||||
if (event.getEntityType() != EntityType.FALLING_BLOCK) {
|
if (event.getEntityType() != EntityType.FALLING_BLOCK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -227,7 +237,8 @@ public class EntityEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH) public void onDamage(EntityDamageEvent event) {
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onDamage(EntityDamageEvent event) {
|
||||||
if (event.getEntityType() != EntityType.PLAYER) {
|
if (event.getEntityType() != EntityType.PLAYER) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -249,7 +260,8 @@ public class EntityEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBigBoom(EntityExplodeEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBigBoom(EntityExplodeEvent event) {
|
||||||
Location location = BukkitUtil.adapt(event.getLocation());
|
Location location = BukkitUtil.adapt(event.getLocation());
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
boolean plotArea = location.isPlotArea();
|
boolean plotArea = location.isPlotArea();
|
||||||
@ -313,11 +325,13 @@ public class EntityEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onPrime(ExplosionPrimeEvent event) {
|
@EventHandler
|
||||||
|
public void onPrime(ExplosionPrimeEvent event) {
|
||||||
this.lastRadius = event.getRadius() + 1;
|
this.lastRadius = event.getRadius() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onVehicleCreate(VehicleCreateEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onVehicleCreate(VehicleCreateEvent event) {
|
||||||
Vehicle entity = event.getVehicle();
|
Vehicle entity = event.getVehicle();
|
||||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
@ -333,4 +347,5 @@ public class EntityEventListener implements Listener {
|
|||||||
entity.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot));
|
entity.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -54,8 +54,8 @@ import org.bukkit.event.world.ChunkLoadEvent;
|
|||||||
import org.bukkit.metadata.FixedMetadataValue;
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
import org.bukkit.metadata.MetadataValue;
|
import org.bukkit.metadata.MetadataValue;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class EntitySpawnListener implements Listener {
|
public class EntitySpawnListener implements Listener {
|
||||||
@ -66,7 +66,7 @@ public class EntitySpawnListener implements Listener {
|
|||||||
private static String areaName = null;
|
private static String areaName = null;
|
||||||
|
|
||||||
public static void testNether(final Entity entity) {
|
public static void testNether(final Entity entity) {
|
||||||
@Nonnull World world = entity.getWorld();
|
@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;
|
return;
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ public class EntitySpawnListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void testCreate(final Entity entity) {
|
public static void testCreate(final Entity entity) {
|
||||||
@Nonnull World world = entity.getWorld();
|
@NonNull World world = entity.getWorld();
|
||||||
if (areaName == world.getName()) {
|
if (areaName == world.getName()) {
|
||||||
} else {
|
} else {
|
||||||
areaName = world.getName();
|
areaName = world.getName();
|
||||||
@ -87,7 +87,7 @@ public class EntitySpawnListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void test(Entity entity) {
|
public static void test(Entity entity) {
|
||||||
@Nonnull World world = entity.getWorld();
|
@NonNull World world = entity.getWorld();
|
||||||
List<MetadataValue> meta = entity.getMetadata(KEY);
|
List<MetadataValue> meta = entity.getMetadata(KEY);
|
||||||
if (meta.isEmpty()) {
|
if (meta.isEmpty()) {
|
||||||
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world.getName())) {
|
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world.getName())) {
|
||||||
@ -122,7 +122,8 @@ 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();
|
Entity entity = event.getEntity();
|
||||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
@ -166,39 +167,47 @@ public class EntitySpawnListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onChunkLoad(ChunkLoadEvent event) {
|
@EventHandler
|
||||||
@Nonnull Chunk chunk = event.getChunk();
|
public void onChunkLoad(ChunkLoadEvent event) {
|
||||||
|
@NonNull Chunk chunk = event.getChunk();
|
||||||
for (final Entity entity : chunk.getEntities()) {
|
for (final Entity entity : chunk.getEntities()) {
|
||||||
testCreate(entity);
|
testCreate(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onVehicle(VehicleUpdateEvent event) {
|
@EventHandler
|
||||||
|
public void onVehicle(VehicleUpdateEvent event) {
|
||||||
testNether(event.getVehicle());
|
testNether(event.getVehicle());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onVehicle(VehicleCreateEvent event) {
|
@EventHandler
|
||||||
|
public void onVehicle(VehicleCreateEvent event) {
|
||||||
testCreate(event.getVehicle());
|
testCreate(event.getVehicle());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onVehicle(VehicleBlockCollisionEvent event) {
|
@EventHandler
|
||||||
|
public void onVehicle(VehicleBlockCollisionEvent event) {
|
||||||
testNether(event.getVehicle());
|
testNether(event.getVehicle());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onTeleport(EntityTeleportEvent event) {
|
@EventHandler
|
||||||
|
public void onTeleport(EntityTeleportEvent event) {
|
||||||
Entity ent = event.getEntity();
|
Entity ent = event.getEntity();
|
||||||
if (ent instanceof Vehicle || ent instanceof ArmorStand) {
|
if (ent instanceof Vehicle || ent instanceof ArmorStand) {
|
||||||
testNether(event.getEntity());
|
testNether(event.getEntity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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());
|
testNether(event.getVehicle());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void spawn(CreatureSpawnEvent event) {
|
@EventHandler
|
||||||
|
public void spawn(CreatureSpawnEvent event) {
|
||||||
if (event.getEntityType() == EntityType.ARMOR_STAND) {
|
if (event.getEntityType() == EntityType.ARMOR_STAND) {
|
||||||
testCreate(event.getEntity());
|
testCreate(event.getEntity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,8 @@ package com.plotsquared.bukkit.listener;
|
|||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.plotsquared.core.permissions.Permission;
|
|
||||||
import com.plotsquared.core.location.Location;
|
import com.plotsquared.core.location.Location;
|
||||||
|
import com.plotsquared.core.permissions.Permission;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import com.plotsquared.core.plot.Plot;
|
import com.plotsquared.core.plot.Plot;
|
||||||
import com.plotsquared.core.plot.flag.implementations.ForcefieldFlag;
|
import com.plotsquared.core.plot.flag.implementations.ForcefieldFlag;
|
||||||
@ -47,10 +47,10 @@ public class ForceFieldListener {
|
|||||||
private static Set<PlotPlayer> getNearbyPlayers(Player player, Plot plot) {
|
private static Set<PlotPlayer> getNearbyPlayers(Player player, Plot plot) {
|
||||||
Set<PlotPlayer> players = new HashSet<>();
|
Set<PlotPlayer> players = new HashSet<>();
|
||||||
for (Player nearPlayer : Iterables
|
for (Player nearPlayer : Iterables
|
||||||
.filter(player.getNearbyEntities(5d, 5d, 5d), Player.class)) {
|
.filter(player.getNearbyEntities(5d, 5d, 5d), Player.class)) {
|
||||||
PlotPlayer plotPlayer;
|
PlotPlayer plotPlayer;
|
||||||
if ((plotPlayer = BukkitUtil.adapt(nearPlayer)) == null || !plot
|
if ((plotPlayer = BukkitUtil.adapt(nearPlayer)) == null || !plot
|
||||||
.equals(plotPlayer.getCurrentPlot())) {
|
.equals(plotPlayer.getCurrentPlot())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!plot.isAdded(plotPlayer.getUUID())) {
|
if (!plot.isAdded(plotPlayer.getUUID())) {
|
||||||
@ -62,10 +62,10 @@ public class ForceFieldListener {
|
|||||||
|
|
||||||
private static PlotPlayer hasNearbyPermitted(Player player, Plot plot) {
|
private static PlotPlayer hasNearbyPermitted(Player player, Plot plot) {
|
||||||
for (Player nearPlayer : Iterables
|
for (Player nearPlayer : Iterables
|
||||||
.filter(player.getNearbyEntities(5d, 5d, 5d), Player.class)) {
|
.filter(player.getNearbyEntities(5d, 5d, 5d), Player.class)) {
|
||||||
PlotPlayer plotPlayer;
|
PlotPlayer plotPlayer;
|
||||||
if ((plotPlayer = BukkitUtil.adapt(nearPlayer)) == null || !plot
|
if ((plotPlayer = BukkitUtil.adapt(nearPlayer)) == null || !plot
|
||||||
.equals(plotPlayer.getCurrentPlot())) {
|
.equals(plotPlayer.getCurrentPlot())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (plot.isAdded(plotPlayer.getUUID())) {
|
if (plot.isAdded(plotPlayer.getUUID())) {
|
||||||
@ -112,9 +112,9 @@ public class ForceFieldListener {
|
|||||||
Set<PlotPlayer> players = getNearbyPlayers(player, plot);
|
Set<PlotPlayer> players = getNearbyPlayers(player, plot);
|
||||||
for (PlotPlayer oPlayer : players) {
|
for (PlotPlayer oPlayer : players) {
|
||||||
if (!Permissions
|
if (!Permissions
|
||||||
.hasPermission(oPlayer, Permission.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
|
.hasPermission(oPlayer, Permission.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
|
||||||
((BukkitPlayer) oPlayer).player
|
((BukkitPlayer) oPlayer).player
|
||||||
.setVelocity(calculateVelocity(plotPlayer, oPlayer));
|
.setVelocity(calculateVelocity(plotPlayer, oPlayer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -123,10 +123,11 @@ public class ForceFieldListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!Permissions
|
if (!Permissions
|
||||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
|
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
|
||||||
player.setVelocity(calculateVelocity(oPlayer, plotPlayer));
|
player.setVelocity(calculateVelocity(oPlayer, plotPlayer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -60,8 +60,8 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
import org.bukkit.projectiles.ProjectileSource;
|
import org.bukkit.projectiles.ProjectileSource;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -77,11 +77,13 @@ public class PaperListener implements Listener {
|
|||||||
private final PlotAreaManager plotAreaManager;
|
private final PlotAreaManager plotAreaManager;
|
||||||
private Chunk lastChunk;
|
private Chunk lastChunk;
|
||||||
|
|
||||||
@Inject public PaperListener(@Nonnull final PlotAreaManager plotAreaManager) {
|
@Inject
|
||||||
|
public PaperListener(final @NonNull PlotAreaManager plotAreaManager) {
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onEntityPathfind(EntityPathfindEvent event) {
|
@EventHandler
|
||||||
|
public void onEntityPathfind(EntityPathfindEvent event) {
|
||||||
if (!Settings.Paper_Components.ENTITY_PATHING) {
|
if (!Settings.Paper_Components.ENTITY_PATHING) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -114,7 +116,8 @@ public class PaperListener implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onEntityPathfind(SlimePathfindEvent event) {
|
@EventHandler
|
||||||
|
public void onEntityPathfind(SlimePathfindEvent event) {
|
||||||
if (!Settings.Paper_Components.ENTITY_PATHING) {
|
if (!Settings.Paper_Components.ENTITY_PATHING) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -155,7 +158,8 @@ public class PaperListener implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onPreCreatureSpawnEvent(PreCreatureSpawnEvent event) {
|
@EventHandler
|
||||||
|
public void onPreCreatureSpawnEvent(PreCreatureSpawnEvent event) {
|
||||||
if (!Settings.Paper_Components.CREATURE_SPAWN) {
|
if (!Settings.Paper_Components.CREATURE_SPAWN) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -269,7 +273,8 @@ public class PaperListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onPreSpawnerSpawnEvent(PreSpawnerSpawnEvent event) {
|
@EventHandler
|
||||||
|
public void onPreSpawnerSpawnEvent(PreSpawnerSpawnEvent event) {
|
||||||
if (Settings.Paper_Components.SPAWNER_SPAWN) {
|
if (Settings.Paper_Components.SPAWNER_SPAWN) {
|
||||||
Location location = BukkitUtil.adapt(event.getSpawnerLocation());
|
Location location = BukkitUtil.adapt(event.getSpawnerLocation());
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
@ -280,7 +285,8 @@ public class PaperListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST) public void onBlockPlace(BlockPlaceEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
if (!Settings.Paper_Components.TILE_ENTITY_CHECK || !Settings.Enabled_Components.CHUNK_PROCESSOR) {
|
if (!Settings.Paper_Components.TILE_ENTITY_CHECK || !Settings.Enabled_Components.CHUNK_PROCESSOR) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -310,7 +316,8 @@ public class PaperListener implements Listener {
|
|||||||
*
|
*
|
||||||
* @param event Paper's PlayerLaunchProjectileEvent
|
* @param event Paper's PlayerLaunchProjectileEvent
|
||||||
*/
|
*/
|
||||||
@EventHandler public void onProjectileLaunch(PlayerLaunchProjectileEvent event) {
|
@EventHandler
|
||||||
|
public void onProjectileLaunch(PlayerLaunchProjectileEvent event) {
|
||||||
if (!Settings.Paper_Components.PLAYER_PROJECTILE) {
|
if (!Settings.Paper_Components.PLAYER_PROJECTILE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -334,7 +341,8 @@ public class PaperListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onAsyncTabCompletion(final AsyncTabCompleteEvent event) {
|
@EventHandler
|
||||||
|
public void onAsyncTabCompletion(final AsyncTabCompleteEvent event) {
|
||||||
if (!Settings.Paper_Components.ASYNC_TAB_COMPLETION) {
|
if (!Settings.Paper_Components.ASYNC_TAB_COMPLETION) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -352,7 +360,7 @@ public class PaperListener implements Listener {
|
|||||||
if (unprocessedArgs.length == 1) {
|
if (unprocessedArgs.length == 1) {
|
||||||
return; // We don't do anything in this case
|
return; // We don't do anything in this case
|
||||||
} else if (!Settings.Enabled_Components.TAB_COMPLETED_ALIASES
|
} else if (!Settings.Enabled_Components.TAB_COMPLETED_ALIASES
|
||||||
.contains(unprocessedArgs[0].toLowerCase(Locale.ENGLISH))) {
|
.contains(unprocessedArgs[0].toLowerCase(Locale.ENGLISH))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final String[] args = new String[unprocessedArgs.length - 1];
|
final String[] args = new String[unprocessedArgs.length - 1];
|
||||||
@ -369,7 +377,8 @@ public class PaperListener implements Listener {
|
|||||||
}
|
}
|
||||||
event.setCompletions(result);
|
event.setCompletions(result);
|
||||||
event.setHandled(true);
|
event.setHandled(true);
|
||||||
} catch (final Exception ignored) {}
|
} catch (final Exception ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -53,24 +53,25 @@ import org.bukkit.block.Skull;
|
|||||||
import org.bukkit.block.Structure;
|
import org.bukkit.block.Structure;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public class PaperListener113 extends PaperListener {
|
public class PaperListener113 extends PaperListener {
|
||||||
|
|
||||||
@Inject public PaperListener113(@Nonnull PlotAreaManager plotAreaManager) {
|
@Inject
|
||||||
|
public PaperListener113(@NonNull PlotAreaManager plotAreaManager) {
|
||||||
super(plotAreaManager);
|
super(plotAreaManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onBlockPlace(BlockPlaceEvent event) {
|
@EventHandler
|
||||||
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
if (!Settings.Paper_Components.TILE_ENTITY_CHECK || !Settings.Enabled_Components.CHUNK_PROCESSOR) {
|
if (!Settings.Paper_Components.TILE_ENTITY_CHECK || !Settings.Enabled_Components.CHUNK_PROCESSOR) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BlockState state = event.getBlock().getState(false);
|
BlockState state = event.getBlock().getState(false);
|
||||||
if (!(state instanceof Banner || state instanceof Beacon || state instanceof Bed || state instanceof CommandBlock
|
if (!(state instanceof Banner || state instanceof Beacon || state instanceof Bed || state instanceof CommandBlock
|
||||||
|| state instanceof Comparator || state instanceof Conduit || state instanceof Container || state instanceof CreatureSpawner
|
|| state instanceof Comparator || state instanceof Conduit || state instanceof Container || state instanceof CreatureSpawner
|
||||||
|| state instanceof DaylightDetector || state instanceof EnchantingTable || state instanceof EnderChest || state instanceof EndGateway
|
|| state instanceof DaylightDetector || state instanceof EnchantingTable || state instanceof EnderChest || state instanceof EndGateway
|
||||||
|| state instanceof Jukebox || state instanceof Sign || state instanceof Skull || state instanceof Structure)) {
|
|| state instanceof Jukebox || state instanceof Sign || state instanceof Skull || state instanceof Structure)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Location location = BukkitUtil.adapt(event.getBlock().getLocation());
|
final Location location = BukkitUtil.adapt(event.getBlock().getLocation());
|
||||||
@ -81,10 +82,13 @@ public class PaperListener113 extends PaperListener {
|
|||||||
final int tileEntityCount = event.getBlock().getChunk().getTileEntities(false).length;
|
final int tileEntityCount = event.getBlock().getChunk().getTileEntities(false).length;
|
||||||
if (tileEntityCount >= Settings.Chunk_Processor.MAX_TILES) {
|
if (tileEntityCount >= Settings.Chunk_Processor.MAX_TILES) {
|
||||||
final PlotPlayer<?> plotPlayer = BukkitUtil.adapt(event.getPlayer());
|
final PlotPlayer<?> plotPlayer = BukkitUtil.adapt(event.getPlayer());
|
||||||
plotPlayer.sendMessage(TranslatableCaption.of("errors.tile_entity_cap_reached"),
|
plotPlayer.sendMessage(
|
||||||
Template.of("amount", String.valueOf(Settings.Chunk_Processor.MAX_TILES)));
|
TranslatableCaption.of("errors.tile_entity_cap_reached"),
|
||||||
|
Template.of("amount", String.valueOf(Settings.Chunk_Processor.MAX_TILES))
|
||||||
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.setBuild(false);
|
event.setBuild(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ package com.plotsquared.bukkit.listener;
|
|||||||
|
|
||||||
import com.destroystokyo.paper.MaterialTags;
|
import com.destroystokyo.paper.MaterialTags;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.inject.Inject;
|
||||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||||
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
@ -144,9 +145,8 @@ import org.bukkit.metadata.FixedMetadataValue;
|
|||||||
import org.bukkit.metadata.MetadataValue;
|
import org.bukkit.metadata.MetadataValue;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -180,16 +180,20 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject public PlayerEventListener(@Nonnull final PlotAreaManager plotAreaManager,
|
@Inject
|
||||||
@Nonnull final EventDispatcher eventDispatcher,
|
public PlayerEventListener(
|
||||||
@Nonnull final WorldEdit worldEdit) {
|
final @NonNull PlotAreaManager plotAreaManager,
|
||||||
|
final @NonNull EventDispatcher eventDispatcher,
|
||||||
|
final @NonNull WorldEdit worldEdit
|
||||||
|
) {
|
||||||
super(eventDispatcher);
|
super(eventDispatcher);
|
||||||
this.eventDispatcher = eventDispatcher;
|
this.eventDispatcher = eventDispatcher;
|
||||||
this.worldEdit = worldEdit;
|
this.worldEdit = worldEdit;
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onVehicleEntityCollision(VehicleEntityCollisionEvent e) {
|
@EventHandler
|
||||||
|
public void onVehicleEntityCollision(VehicleEntityCollisionEvent e) {
|
||||||
if (e.getVehicle().getType() == EntityType.BOAT) {
|
if (e.getVehicle().getType() == EntityType.BOAT) {
|
||||||
Location location = BukkitUtil.adapt(e.getEntity().getLocation());
|
Location location = BukkitUtil.adapt(e.getEntity().getLocation());
|
||||||
if (location.isPlotArea()) {
|
if (location.isPlotArea()) {
|
||||||
@ -236,7 +240,7 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
case "worldedit:up":
|
case "worldedit:up":
|
||||||
case "worldedit:/up":
|
case "worldedit:/up":
|
||||||
if (plot == null || (!plot.isAdded(plotPlayer.getUUID()) && !Permissions
|
if (plot == null || (!plot.isAdded(plotPlayer.getUUID()) && !Permissions
|
||||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_BUILD_OTHER, true))) {
|
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_BUILD_OTHER, true))) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -246,10 +250,10 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> blockedCommands = plot != null ?
|
List<String> blockedCommands = plot != null ?
|
||||||
plot.getFlag(BlockedCmdsFlag.class) :
|
plot.getFlag(BlockedCmdsFlag.class) :
|
||||||
area.getFlag(BlockedCmdsFlag.class);
|
area.getFlag(BlockedCmdsFlag.class);
|
||||||
if (!blockedCommands.isEmpty() && !Permissions
|
if (!blockedCommands.isEmpty() && !Permissions
|
||||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS)) {
|
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS)) {
|
||||||
String part = parts[0];
|
String part = parts[0];
|
||||||
if (parts[0].contains(":")) {
|
if (parts[0].contains(":")) {
|
||||||
part = parts[0].split(":")[1];
|
part = parts[0].split(":")[1];
|
||||||
@ -307,7 +311,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPreLogin(final AsyncPlayerPreLoginEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPreLogin(final AsyncPlayerPreLoginEvent event) {
|
||||||
final UUID uuid;
|
final UUID uuid;
|
||||||
if (Settings.UUID.OFFLINE) {
|
if (Settings.UUID.OFFLINE) {
|
||||||
if (Settings.UUID.FORCE_LOWERCASE) {
|
if (Settings.UUID.FORCE_LOWERCASE) {
|
||||||
@ -346,7 +351,7 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}, TaskTime.seconds(1L));
|
}, TaskTime.seconds(1L));
|
||||||
|
|
||||||
if (pp.hasPermission(Permission.PERMISSION_ADMIN_UPDATE_NOTIFICATION.toString()) && Settings.Enabled_Components.UPDATE_NOTIFICATIONS
|
if (pp.hasPermission(Permission.PERMISSION_ADMIN_UPDATE_NOTIFICATION.toString()) && Settings.Enabled_Components.UPDATE_NOTIFICATIONS
|
||||||
&& PremiumVerification.isPremium() && UpdateUtility.hasUpdate) {
|
&& PremiumVerification.isPremium() && UpdateUtility.hasUpdate) {
|
||||||
Caption boundary = TranslatableCaption.of("update.update_boundary");
|
Caption boundary = TranslatableCaption.of("update.update_boundary");
|
||||||
Caption updateNotification = TranslatableCaption.of("update.update_notification");
|
Caption updateNotification = TranslatableCaption.of("update.update_notification");
|
||||||
Template internalVersion = Template.of("p2version", String.valueOf(UpdateUtility.internalVersion.versionString()));
|
Template internalVersion = Template.of("p2version", String.valueOf(UpdateUtility.internalVersion.versionString()));
|
||||||
@ -358,7 +363,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void playerRespawn(PlayerRespawnEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void playerRespawn(PlayerRespawnEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
PlotPlayer<Player> pp = BukkitUtil.adapt(player);
|
PlotPlayer<Player> pp = BukkitUtil.adapt(player);
|
||||||
this.eventDispatcher.doRespawnTask(pp);
|
this.eventDispatcher.doRespawnTask(pp);
|
||||||
@ -369,7 +375,7 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||||
try (final MetaDataAccess<Plot> lastPlotAccess =
|
try (final MetaDataAccess<Plot> lastPlotAccess =
|
||||||
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
Plot lastPlot = lastPlotAccess.get().orElse(null);
|
Plot lastPlot = lastPlotAccess.get().orElse(null);
|
||||||
org.bukkit.Location to = event.getTo();
|
org.bukkit.Location to = event.getTo();
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
@ -382,7 +388,7 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
lastPlotAccess.remove();
|
lastPlotAccess.remove();
|
||||||
}
|
}
|
||||||
try (final MetaDataAccess<Location> lastLocationAccess =
|
try (final MetaDataAccess<Location> lastLocationAccess =
|
||||||
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
||||||
lastLocationAccess.remove();
|
lastLocationAccess.remove();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -394,26 +400,30 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
// to is identical to the plot's home location, and untrusted-visit is true
|
// to is identical to the plot's home location, and untrusted-visit is true
|
||||||
// i.e. untrusted-visit can override deny-teleport
|
// i.e. untrusted-visit can override deny-teleport
|
||||||
// this is acceptable, because otherwise it wouldn't make sense to have both flags set
|
// this is acceptable, because otherwise it wouldn't make sense to have both flags set
|
||||||
if (!result && !(plot.getFlag(UntrustedVisitFlag.class) && plot.getHomeSynchronous().equals(BukkitUtil.adaptComplete(to)))) {
|
if (!result && !(plot.getFlag(UntrustedVisitFlag.class) && plot
|
||||||
|
.getHomeSynchronous()
|
||||||
|
.equals(BukkitUtil.adaptComplete(to)))) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_ENTRY_DENIED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_ENTRY_DENIED))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);}
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
playerMove(event);
|
playerMove(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void vehicleMove(VehicleMoveEvent event)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
throws IllegalAccessException {
|
public void vehicleMove(VehicleMoveEvent event)
|
||||||
|
throws IllegalAccessException {
|
||||||
final org.bukkit.Location from = event.getFrom();
|
final org.bukkit.Location from = event.getFrom();
|
||||||
final org.bukkit.Location to = event.getTo();
|
final org.bukkit.Location to = event.getTo();
|
||||||
|
|
||||||
int toX, toZ;
|
int toX, toZ;
|
||||||
if ((toX = MathMan.roundInt(to.getX())) != MathMan.roundInt(from.getX()) | (toZ = MathMan.roundInt(to.getZ())) != MathMan
|
if ((toX = MathMan.roundInt(to.getX())) != MathMan.roundInt(from.getX()) | (toZ = MathMan.roundInt(to.getZ())) != MathMan
|
||||||
.roundInt(from.getZ())) {
|
.roundInt(from.getZ())) {
|
||||||
Vehicle vehicle = event.getVehicle();
|
Vehicle vehicle = event.getVehicle();
|
||||||
|
|
||||||
// Check allowed
|
// Check allowed
|
||||||
@ -437,7 +447,9 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
org.bukkit.Location dest;
|
org.bukkit.Location dest;
|
||||||
if (moveTmp.isCancelled()) {
|
if (moveTmp.isCancelled()) {
|
||||||
dest = from;
|
dest = from;
|
||||||
} else if (MathMan.roundInt(moveTmp.getTo().getX()) != toX || MathMan.roundInt(moveTmp.getTo().getZ()) != toZ) {
|
} else if (MathMan.roundInt(moveTmp.getTo().getX()) != toX || MathMan.roundInt(moveTmp
|
||||||
|
.getTo()
|
||||||
|
.getZ()) != toZ) {
|
||||||
dest = to;
|
dest = to;
|
||||||
} else {
|
} else {
|
||||||
dest = null;
|
dest = null;
|
||||||
@ -487,13 +499,13 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
// Set last location
|
// Set last location
|
||||||
Location location = BukkitUtil.adapt(to);
|
Location location = BukkitUtil.adapt(to);
|
||||||
try (final MetaDataAccess<Location> lastLocationAccess =
|
try (final MetaDataAccess<Location> lastLocationAccess =
|
||||||
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
||||||
lastLocationAccess.remove();
|
lastLocationAccess.remove();
|
||||||
}
|
}
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
if (area == null) {
|
if (area == null) {
|
||||||
try (final MetaDataAccess<Plot> lastPlotAccess =
|
try (final MetaDataAccess<Plot> lastPlotAccess =
|
||||||
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
lastPlotAccess.remove();
|
lastPlotAccess.remove();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -501,16 +513,16 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
Plot now = area.getPlot(location);
|
Plot now = area.getPlot(location);
|
||||||
Plot lastPlot;
|
Plot lastPlot;
|
||||||
try (final MetaDataAccess<Plot> lastPlotAccess =
|
try (final MetaDataAccess<Plot> lastPlotAccess =
|
||||||
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
lastPlot = lastPlotAccess.get().orElse(null);
|
lastPlot = lastPlotAccess.get().orElse(null);
|
||||||
}
|
}
|
||||||
if (now == null) {
|
if (now == null) {
|
||||||
try (final MetaDataAccess<Boolean> kickAccess =
|
try (final MetaDataAccess<Boolean> kickAccess =
|
||||||
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
|
||||||
if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !kickAccess.get().orElse(false)) {
|
if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !kickAccess.get().orElse(false)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_EXIT_DENIED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_EXIT_DENIED))
|
||||||
);
|
);
|
||||||
this.tmpTeleport = false;
|
this.tmpTeleport = false;
|
||||||
if (lastPlot.equals(BukkitUtil.adapt(from).getPlot())) {
|
if (lastPlot.equals(BukkitUtil.adapt(from).getPlot())) {
|
||||||
@ -520,14 +532,15 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
this.tmpTeleport = true;
|
this.tmpTeleport = true;
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;}
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (now.equals(lastPlot)) {
|
} else if (now.equals(lastPlot)) {
|
||||||
ForceFieldListener.handleForcefield(player, pp, now);
|
ForceFieldListener.handleForcefield(player, pp, now);
|
||||||
} else if (!plotEntry(pp, now) && this.tmpTeleport) {
|
} else if (!plotEntry(pp, now) && this.tmpTeleport) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_ENTRY_DENIED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_ENTRY_DENIED))
|
||||||
);
|
);
|
||||||
this.tmpTeleport = false;
|
this.tmpTeleport = false;
|
||||||
to.setX(from.getBlockX());
|
to.setX(from.getBlockX());
|
||||||
@ -564,13 +577,13 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
// Set last location
|
// Set last location
|
||||||
Location location = BukkitUtil.adapt(to);
|
Location location = BukkitUtil.adapt(to);
|
||||||
try (final MetaDataAccess<Location> lastLocationAccess =
|
try (final MetaDataAccess<Location> lastLocationAccess =
|
||||||
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
||||||
lastLocationAccess.set(location);
|
lastLocationAccess.set(location);
|
||||||
}
|
}
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
if (area == null) {
|
if (area == null) {
|
||||||
try (final MetaDataAccess<Plot> lastPlotAccess =
|
try (final MetaDataAccess<Plot> lastPlotAccess =
|
||||||
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
lastPlotAccess.remove();
|
lastPlotAccess.remove();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -578,16 +591,16 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
Plot now = area.getPlot(location);
|
Plot now = area.getPlot(location);
|
||||||
Plot lastPlot;
|
Plot lastPlot;
|
||||||
try (final MetaDataAccess<Plot> lastPlotAccess =
|
try (final MetaDataAccess<Plot> lastPlotAccess =
|
||||||
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
lastPlot = lastPlotAccess.get().orElse(null);
|
lastPlot = lastPlotAccess.get().orElse(null);
|
||||||
}
|
}
|
||||||
if (now == null) {
|
if (now == null) {
|
||||||
try (final MetaDataAccess<Boolean> kickAccess =
|
try (final MetaDataAccess<Boolean> kickAccess =
|
||||||
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
|
||||||
if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !kickAccess.get().orElse(false)) {
|
if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !kickAccess.get().orElse(false)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_EXIT_DENIED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_EXIT_DENIED))
|
||||||
);
|
);
|
||||||
this.tmpTeleport = false;
|
this.tmpTeleport = false;
|
||||||
if (lastPlot.equals(BukkitUtil.adapt(from).getPlot())) {
|
if (lastPlot.equals(BukkitUtil.adapt(from).getPlot())) {
|
||||||
@ -597,14 +610,15 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
this.tmpTeleport = true;
|
this.tmpTeleport = true;
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;}
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (now.equals(lastPlot)) {
|
} else if (now.equals(lastPlot)) {
|
||||||
ForceFieldListener.handleForcefield(player, pp, now);
|
ForceFieldListener.handleForcefield(player, pp, now);
|
||||||
} else if (!plotEntry(pp, now) && this.tmpTeleport) {
|
} else if (!plotEntry(pp, now) && this.tmpTeleport) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_ENTRY_DENIED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_ENTRY_DENIED))
|
||||||
);
|
);
|
||||||
this.tmpTeleport = false;
|
this.tmpTeleport = false;
|
||||||
player.teleport(from);
|
player.teleport(from);
|
||||||
@ -632,7 +646,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW) public void onChat(AsyncPlayerChatEvent event) {
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
public void onChat(AsyncPlayerChatEvent event) {
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -648,11 +663,11 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!((plot.getFlag(ChatFlag.class) && area.isPlotChat() && plotPlayer.getAttribute("chat"))
|
if (!((plot.getFlag(ChatFlag.class) && area.isPlotChat() && plotPlayer.getAttribute("chat"))
|
||||||
|| area.isForcingPlotChat())) {
|
|| area.isForcingPlotChat())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (plot.isDenied(plotPlayer.getUUID()) && !Permissions
|
if (plot.isDenied(plotPlayer.getUUID()) && !Permissions
|
||||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_CHAT_BYPASS)) {
|
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_CHAT_BYPASS)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -683,10 +698,15 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
// allowing colour.
|
// allowing colour.
|
||||||
if (plotPlayer.hasPermission("plots.chat.color")) {
|
if (plotPlayer.hasPermission("plots.chat.color")) {
|
||||||
msgTemplate = Template
|
msgTemplate = Template
|
||||||
.of("msg", BukkitUtil.LEGACY_COMPONENT_SERIALIZER.deserialize(ChatColor.translateAlternateColorCodes('&', message)));
|
.of("msg",
|
||||||
|
BukkitUtil.LEGACY_COMPONENT_SERIALIZER.deserialize(ChatColor.translateAlternateColorCodes(
|
||||||
|
'&',
|
||||||
|
message
|
||||||
|
))
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
msgTemplate = Template.of("msg", BukkitUtil.MINI_MESSAGE.deserialize(
|
msgTemplate = Template.of("msg", BukkitUtil.MINI_MESSAGE.deserialize(
|
||||||
ChatColor.stripColor(BukkitUtil.LEGACY_COMPONENT_SERIALIZER.serialize(Component.text(message)))));
|
ChatColor.stripColor(BukkitUtil.LEGACY_COMPONENT_SERIALIZER.serialize(Component.text(message)))));
|
||||||
}
|
}
|
||||||
for (PlotPlayer<?> receiver : plotRecipients) {
|
for (PlotPlayer<?> receiver : plotRecipients) {
|
||||||
receiver.sendMessage(msg, msgTemplate, plotTemplate, senderTemplate);
|
receiver.sendMessage(msg, msgTemplate, plotTemplate, senderTemplate);
|
||||||
@ -711,11 +731,11 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
// Delete last location
|
// Delete last location
|
||||||
Plot plot;
|
Plot plot;
|
||||||
try (final MetaDataAccess<Plot> lastPlotAccess =
|
try (final MetaDataAccess<Plot> lastPlotAccess =
|
||||||
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
plot = lastPlotAccess.remove();
|
plot = lastPlotAccess.remove();
|
||||||
}
|
}
|
||||||
try (final MetaDataAccess<Location> lastLocationAccess =
|
try (final MetaDataAccess<Location> lastLocationAccess =
|
||||||
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
||||||
lastLocationAccess.remove();
|
lastLocationAccess.remove();
|
||||||
}
|
}
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
@ -738,7 +758,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@SuppressWarnings("deprecation")
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
/*if (!event.isLeftClick() || (event.getAction() != InventoryAction.PLACE_ALL) || event
|
/*if (!event.isLeftClick() || (event.getAction() != InventoryAction.PLACE_ALL) || event
|
||||||
.isShiftClick()) {
|
.isShiftClick()) {
|
||||||
@ -746,7 +767,7 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}*/
|
}*/
|
||||||
HumanEntity entity = event.getWhoClicked();
|
HumanEntity entity = event.getWhoClicked();
|
||||||
if (!(entity instanceof Player) || !this.plotAreaManager
|
if (!(entity instanceof Player) || !this.plotAreaManager
|
||||||
.hasPlotArea(entity.getWorld().getName())) {
|
.hasPlotArea(entity.getWorld().getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -778,20 +799,20 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
final Plot plot = pp.getCurrentPlot();
|
final Plot plot = pp.getCurrentPlot();
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
if (plot.getFlag(PreventCreativeCopyFlag.class) && !plot
|
if (plot.getFlag(PreventCreativeCopyFlag.class) && !plot
|
||||||
.isAdded(player.getUniqueId()) && !Permissions
|
.isAdded(player.getUniqueId()) && !Permissions
|
||||||
.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_OTHER)) {
|
.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_OTHER)) {
|
||||||
final ItemStack newStack =
|
final ItemStack newStack =
|
||||||
new ItemStack(newItem.getType(), newItem.getAmount());
|
new ItemStack(newItem.getType(), newItem.getAmount());
|
||||||
event.setCursor(newStack);
|
event.setCursor(newStack);
|
||||||
plot.debug(player.getName()
|
plot.debug(player.getName()
|
||||||
+ " could not creative-copy an item because prevent-creative-copy = true");
|
+ " could not creative-copy an item because prevent-creative-copy = true");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PlotArea area = pp.getPlotAreaAbs();
|
PlotArea area = pp.getPlotAreaAbs();
|
||||||
if (area != null && area.isRoadFlags() && area
|
if (area != null && area.isRoadFlags() && area
|
||||||
.getRoadFlag(PreventCreativeCopyFlag.class)) {
|
.getRoadFlag(PreventCreativeCopyFlag.class)) {
|
||||||
final ItemStack newStack =
|
final ItemStack newStack =
|
||||||
new ItemStack(newItem.getType(), newItem.getAmount());
|
new ItemStack(newItem.getType(), newItem.getAmount());
|
||||||
event.setCursor(newStack);
|
event.setCursor(newStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -852,16 +873,16 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_ROAD)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_ROAD)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_ROAD))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_ROAD))
|
||||||
);
|
);
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
}
|
}
|
||||||
} else if (!plot.hasOwner()) {
|
} else if (!plot.hasOwner()) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_UNOWNED)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_UNOWNED)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_UNOWNED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_UNOWNED))
|
||||||
);
|
);
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
}
|
}
|
||||||
@ -870,8 +891,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
if (!plot.isAdded(uuid)) {
|
if (!plot.isAdded(uuid)) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_OTHER)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_OTHER)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_OTHER))
|
||||||
);
|
);
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
}
|
}
|
||||||
@ -879,14 +900,14 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
if (cancelled) {
|
if (cancelled) {
|
||||||
if ((current.getType() == newItem.getType()) && (current.getDurability() == newItem
|
if ((current.getType() == newItem.getType()) && (current.getDurability() == newItem
|
||||||
.getDurability())) {
|
.getDurability())) {
|
||||||
event.setCursor(
|
event.setCursor(
|
||||||
new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
|
new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event.setCursor(
|
event.setCursor(
|
||||||
new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
|
new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -906,10 +927,10 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
BukkitPlayer pp = BukkitUtil.adapt(e.getPlayer());
|
BukkitPlayer pp = BukkitUtil.adapt(e.getPlayer());
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (!area.isRoadFlags() && !area.getRoadFlag(MiscInteractFlag.class) && !Permissions
|
if (!area.isRoadFlags() && !area.getRoadFlag(MiscInteractFlag.class) && !Permissions
|
||||||
.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_ROAD)) {
|
.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_ROAD)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_ROAD))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_ROAD))
|
||||||
);
|
);
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -917,8 +938,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
||||||
);
|
);
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -927,8 +948,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
|
if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_UNOWNED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_UNOWNED))
|
||||||
);
|
);
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -942,18 +963,19 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_OTHER)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_OTHER)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_OTHER))
|
||||||
);
|
);
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
plot.debug(pp.getName() + " could not interact with " + entity.getType()
|
plot.debug(pp.getName() + " could not interact with " + entity.getType()
|
||||||
+ " because misc-interact = false");
|
+ " because misc-interact = false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW) public void onCancelledInteract(PlayerInteractEvent event) {
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
public void onCancelledInteract(PlayerInteractEvent event) {
|
||||||
if (event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_AIR) {
|
if (event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||||
@ -988,7 +1010,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onInteract(PlayerInteractEvent event) {
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
|
public void onInteract(PlayerInteractEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||||
PlotArea area = pp.getPlotAreaAbs();
|
PlotArea area = pp.getPlotAreaAbs();
|
||||||
@ -1140,7 +1163,7 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
BlockType blockType = BukkitAdapter.asBlockType(block.getType());
|
BlockType blockType = BukkitAdapter.asBlockType(block.getType());
|
||||||
Location location = BukkitUtil.adapt(block.getLocation());
|
Location location = BukkitUtil.adapt(block.getLocation());
|
||||||
if (!PlotSquared.get().getEventDispatcher()
|
if (!PlotSquared.get().getEventDispatcher()
|
||||||
.checkPlayerBlockEvent(pp, eventType, location, blockType, true)) {
|
.checkPlayerBlockEvent(pp, eventType, location, blockType, true)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1156,7 +1179,7 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
block = event.getBlockClicked().getLocation()
|
block = event.getBlockClicked().getLocation()
|
||||||
.add(bf.getModX(), bf.getModY(), bf.getModZ())
|
.add(bf.getModX(), bf.getModY(), bf.getModZ())
|
||||||
.getBlock();
|
.getBlock();
|
||||||
}
|
}
|
||||||
Location location = BukkitUtil.adapt(block.getLocation());
|
Location location = BukkitUtil.adapt(block.getLocation());
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
@ -1170,8 +1193,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_ROAD))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_ROAD))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else if (!plot.hasOwner()) {
|
} else if (!plot.hasOwner()) {
|
||||||
@ -1179,8 +1202,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_UNOWNED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_UNOWNED))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else if (!plot.isAdded(pp.getUUID())) {
|
} else if (!plot.isAdded(pp.getUUID())) {
|
||||||
@ -1195,22 +1218,23 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
} else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST) public void onInventoryClose(InventoryCloseEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onInventoryClose(InventoryCloseEvent event) {
|
||||||
HumanEntity closer = event.getPlayer();
|
HumanEntity closer = event.getPlayer();
|
||||||
if (!(closer instanceof Player)) {
|
if (!(closer instanceof Player)) {
|
||||||
return;
|
return;
|
||||||
@ -1219,7 +1243,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
PlotInventory.removePlotInventoryOpen(BukkitUtil.adapt(player));
|
PlotInventory.removePlotInventoryOpen(BukkitUtil.adapt(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR) public void onLeave(PlayerQuitEvent event) {
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onLeave(PlayerQuitEvent event) {
|
||||||
TaskManager.removeFromTeleportQueue(event.getPlayer().getName());
|
TaskManager.removeFromTeleportQueue(event.getPlayer().getName());
|
||||||
BukkitPlayer pp = BukkitUtil.adapt(event.getPlayer());
|
BukkitPlayer pp = BukkitUtil.adapt(event.getPlayer());
|
||||||
pp.unregister();
|
pp.unregister();
|
||||||
@ -1242,8 +1267,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_ROAD))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_ROAD))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else if (!plot.hasOwner()) {
|
} else if (!plot.hasOwner()) {
|
||||||
@ -1251,8 +1276,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_UNOWNED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_UNOWNED))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else if (!plot.isAdded(plotPlayer.getUUID())) {
|
} else if (!plot.isAdded(plotPlayer.getUUID())) {
|
||||||
@ -1268,15 +1293,15 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
} else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
||||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -1301,8 +1326,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_ROAD)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_ROAD)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_ROAD))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_ROAD))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -1310,8 +1335,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_UNOWNED)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_UNOWNED)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_UNOWNED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_UNOWNED))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -1321,8 +1346,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
if (!plot.getFlag(HangingPlaceFlag.class)) {
|
if (!plot.getFlag(HangingPlaceFlag.class)) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -1351,16 +1376,16 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_ROAD)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_ROAD)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_ROAD))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_ROAD))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
} else if (!plot.hasOwner()) {
|
} else if (!plot.hasOwner()) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_UNOWNED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_UNOWNED))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -1370,12 +1395,12 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_OTHER)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_OTHER)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_OTHER))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
plot.debug(p.getName()
|
plot.debug(p.getName()
|
||||||
+ " could not break hanging entity because hanging-break = false");
|
+ " could not break hanging entity because hanging-break = false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (remover instanceof Projectile) {
|
} else if (remover instanceof Projectile) {
|
||||||
@ -1392,24 +1417,24 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
if (!Permissions
|
if (!Permissions
|
||||||
.hasPermission(player, Permission.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
|
.hasPermission(player, Permission.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_UNOWNED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_UNOWNED))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
} else if (!plot.isAdded(player.getUUID())) {
|
} else if (!plot.isAdded(player.getUUID())) {
|
||||||
if (!plot.getFlag(HangingBreakFlag.class)) {
|
if (!plot.getFlag(HangingBreakFlag.class)) {
|
||||||
if (!Permissions
|
if (!Permissions
|
||||||
.hasPermission(player, Permission.PERMISSION_ADMIN_DESTROY_OTHER)) {
|
.hasPermission(player, Permission.PERMISSION_ADMIN_DESTROY_OTHER)) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_OTHER))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
plot.debug(player.getName()
|
plot.debug(player.getName()
|
||||||
+ " could not break hanging entity because hanging-break = false");
|
+ " could not break hanging entity because hanging-break = false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1433,24 +1458,24 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
if (plot == null && !area.isRoadFlags()) {
|
if (plot == null && !area.isRoadFlags()) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_ROAD)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_ROAD)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_ROAD))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_ROAD))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
} else if (plot != null && !plot.hasOwner()) {
|
} else if (plot != null && !plot.hasOwner()) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_UNOWNED)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_UNOWNED)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_UNOWNED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_UNOWNED))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
} else if ((plot != null && !plot.isAdded(pp.getUUID())) || (plot == null && area
|
} else if ((plot != null && !plot.isAdded(pp.getUUID())) || (plot == null && area
|
||||||
.isRoadFlags())) {
|
.isRoadFlags())) {
|
||||||
final Entity entity = event.getRightClicked();
|
final Entity entity = event.getRightClicked();
|
||||||
final com.sk89q.worldedit.world.entity.EntityType entityType =
|
final com.sk89q.worldedit.world.entity.EntityType entityType =
|
||||||
BukkitAdapter.adapt(entity.getType());
|
BukkitAdapter.adapt(entity.getType());
|
||||||
|
|
||||||
FlagContainer flagContainer;
|
FlagContainer flagContainer;
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
@ -1460,47 +1485,47 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (EntityCategories.HOSTILE.contains(entityType) && flagContainer
|
if (EntityCategories.HOSTILE.contains(entityType) && flagContainer
|
||||||
.getFlag(HostileInteractFlag.class).getValue()) {
|
.getFlag(HostileInteractFlag.class).getValue()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EntityCategories.ANIMAL.contains(entityType) && flagContainer
|
if (EntityCategories.ANIMAL.contains(entityType) && flagContainer
|
||||||
.getFlag(AnimalInteractFlag.class).getValue()) {
|
.getFlag(AnimalInteractFlag.class).getValue()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This actually makes use of the interface, so we don't use the
|
// This actually makes use of the interface, so we don't use the
|
||||||
// category
|
// category
|
||||||
if (entity instanceof Tameable && ((Tameable) entity).isTamed() && flagContainer
|
if (entity instanceof Tameable && ((Tameable) entity).isTamed() && flagContainer
|
||||||
.getFlag(TamedInteractFlag.class).getValue()) {
|
.getFlag(TamedInteractFlag.class).getValue()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EntityCategories.VEHICLE.contains(entityType) && flagContainer
|
if (EntityCategories.VEHICLE.contains(entityType) && flagContainer
|
||||||
.getFlag(VehicleUseFlag.class).getValue()) {
|
.getFlag(VehicleUseFlag.class).getValue()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EntityCategories.PLAYER.contains(entityType) && flagContainer
|
if (EntityCategories.PLAYER.contains(entityType) && flagContainer
|
||||||
.getFlag(PlayerInteractFlag.class).getValue()) {
|
.getFlag(PlayerInteractFlag.class).getValue()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EntityCategories.VILLAGER.contains(entityType) && flagContainer
|
if (EntityCategories.VILLAGER.contains(entityType) && flagContainer
|
||||||
.getFlag(VillagerInteractFlag.class).getValue()) {
|
.getFlag(VillagerInteractFlag.class).getValue()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((EntityCategories.HANGING.contains(entityType) || EntityCategories.OTHER
|
if ((EntityCategories.HANGING.contains(entityType) || EntityCategories.OTHER
|
||||||
.contains(entityType)) && flagContainer.getFlag(MiscInteractFlag.class)
|
.contains(entityType)) && flagContainer.getFlag(MiscInteractFlag.class)
|
||||||
.getValue()) {
|
.getValue()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_OTHER)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_OTHER)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_OTHER))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -1522,8 +1547,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_ROAD)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_ROAD)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_ROAD))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_ROAD))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -1531,8 +1556,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_UNOWNED)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_UNOWNED)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_UNOWNED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_UNOWNED))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -1545,12 +1570,12 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_OTHER)) {
|
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_OTHER)) {
|
||||||
pp.sendMessage(
|
pp.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_OTHER))
|
||||||
);
|
);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
plot.debug(pp.getName()
|
plot.debug(pp.getName()
|
||||||
+ " could not break vehicle because vehicle-break = false");
|
+ " could not break vehicle because vehicle-break = false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1570,31 +1595,32 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)) {
|
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)) {
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_ROAD))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_ROAD))
|
||||||
);
|
);
|
||||||
event.setHatching(false);
|
event.setHatching(false);
|
||||||
}
|
}
|
||||||
} else if (!plot.hasOwner()) {
|
} else if (!plot.hasOwner()) {
|
||||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) {
|
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) {
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED))
|
||||||
);
|
);
|
||||||
event.setHatching(false);
|
event.setHatching(false);
|
||||||
}
|
}
|
||||||
} else if (!plot.isAdded(plotPlayer.getUUID())) {
|
} else if (!plot.isAdded(plotPlayer.getUUID())) {
|
||||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) {
|
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) {
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER))
|
||||||
);
|
);
|
||||||
event.setHatching(false);
|
event.setHatching(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onItemDrop(PlayerDropItemEvent event) {
|
@EventHandler
|
||||||
|
public void onItemDrop(PlayerDropItemEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||||
Location location = pp.getLocation();
|
Location location = pp.getLocation();
|
||||||
@ -1618,7 +1644,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onItemPickup(EntityPickupItemEvent event) {
|
@EventHandler
|
||||||
|
public void onItemPickup(EntityPickupItemEvent event) {
|
||||||
LivingEntity ent = event.getEntity();
|
LivingEntity ent = event.getEntity();
|
||||||
if (ent instanceof Player) {
|
if (ent instanceof Player) {
|
||||||
Player player = (Player) ent;
|
Player player = (Player) ent;
|
||||||
@ -1643,7 +1670,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onDeath(final PlayerDeathEvent event) {
|
@EventHandler
|
||||||
|
public void onDeath(final PlayerDeathEvent event) {
|
||||||
Location location = BukkitUtil.adapt(event.getEntity().getLocation());
|
Location location = BukkitUtil.adapt(event.getEntity().getLocation());
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
if (area == null) {
|
if (area == null) {
|
||||||
@ -1664,9 +1692,11 @@ public class PlayerEventListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onLocaleChange(final PlayerLocaleChangeEvent event) {
|
@EventHandler
|
||||||
|
public void onLocaleChange(final PlayerLocaleChangeEvent event) {
|
||||||
BukkitPlayer player = BukkitUtil.adapt(event.getPlayer());
|
BukkitPlayer player = BukkitUtil.adapt(event.getPlayer());
|
||||||
// we're stripping the country code as we don't want to differ between countries
|
// we're stripping the country code as we don't want to differ between countries
|
||||||
player.setLocale(Locale.forLanguageTag(event.getLocale().substring(0, 2)));
|
player.setLocale(Locale.forLanguageTag(event.getLocale().substring(0, 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.bukkit.listener;
|
package com.plotsquared.bukkit.listener;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.plotsquared.core.location.Location;
|
import com.plotsquared.core.location.Location;
|
||||||
@ -49,20 +50,20 @@ import org.bukkit.event.entity.ProjectileHitEvent;
|
|||||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||||
import org.bukkit.projectiles.BlockProjectileSource;
|
import org.bukkit.projectiles.BlockProjectileSource;
|
||||||
import org.bukkit.projectiles.ProjectileSource;
|
import org.bukkit.projectiles.ProjectileSource;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class ProjectileEventListener implements Listener {
|
public class ProjectileEventListener implements Listener {
|
||||||
|
|
||||||
private final PlotAreaManager plotAreaManager;
|
private final PlotAreaManager plotAreaManager;
|
||||||
|
|
||||||
@Inject public ProjectileEventListener(@Nonnull final PlotAreaManager plotAreaManager) {
|
@Inject
|
||||||
|
public ProjectileEventListener(final @NonNull PlotAreaManager plotAreaManager) {
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPotionSplash(LingeringPotionSplashEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPotionSplash(LingeringPotionSplashEvent event) {
|
||||||
Projectile entity = event.getEntity();
|
Projectile entity = event.getEntity();
|
||||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||||
@ -73,7 +74,8 @@ public class ProjectileEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPotionSplash(PotionSplashEvent event) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPotionSplash(PotionSplashEvent event) {
|
||||||
ThrownPotion damager = event.getPotion();
|
ThrownPotion damager = event.getPotion();
|
||||||
Location location = BukkitUtil.adapt(damager.getLocation());
|
Location location = BukkitUtil.adapt(damager.getLocation());
|
||||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||||
@ -91,7 +93,8 @@ public class ProjectileEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onProjectileLaunch(ProjectileLaunchEvent event) {
|
@EventHandler
|
||||||
|
public void onProjectileLaunch(ProjectileLaunchEvent event) {
|
||||||
Projectile entity = event.getEntity();
|
Projectile entity = event.getEntity();
|
||||||
if (!(entity instanceof ThrownPotion)) {
|
if (!(entity instanceof ThrownPotion)) {
|
||||||
return;
|
return;
|
||||||
@ -112,7 +115,8 @@ public class ProjectileEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"BooleanMethodIsAlwaysInverted", "cos it's not... dum IntelliJ"}) @EventHandler
|
@SuppressWarnings({"BooleanMethodIsAlwaysInverted", "cos it's not... dum IntelliJ"})
|
||||||
|
@EventHandler
|
||||||
public boolean onProjectileHit(ProjectileHitEvent event) {
|
public boolean onProjectileHit(ProjectileHitEvent event) {
|
||||||
Projectile entity = event.getEntity();
|
Projectile entity = event.getEntity();
|
||||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||||
@ -135,7 +139,7 @@ public class ProjectileEventListener implements Listener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (plot.isAdded(pp.getUUID()) || Permissions
|
if (plot.isAdded(pp.getUUID()) || Permissions
|
||||||
.hasPermission(pp, Permission.PERMISSION_PROJECTILE_OTHER)) {
|
.hasPermission(pp, Permission.PERMISSION_PROJECTILE_OTHER)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
entity.remove();
|
entity.remove();
|
||||||
@ -147,7 +151,7 @@ public class ProjectileEventListener implements Listener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Location sLoc =
|
Location sLoc =
|
||||||
BukkitUtil.adapt(((BlockProjectileSource) shooter).getBlock().getLocation());
|
BukkitUtil.adapt(((BlockProjectileSource) shooter).getBlock().getLocation());
|
||||||
if (!area.contains(sLoc.getX(), sLoc.getZ())) {
|
if (!area.contains(sLoc.getX(), sLoc.getZ())) {
|
||||||
entity.remove();
|
entity.remove();
|
||||||
return false;
|
return false;
|
||||||
@ -160,4 +164,5 @@ public class ProjectileEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,21 +35,23 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.server.ServerLoadEvent;
|
import org.bukkit.event.server.ServerLoadEvent;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public class ServerListener implements Listener {
|
public class ServerListener implements Listener {
|
||||||
|
|
||||||
private final BukkitPlatform plugin;
|
private final BukkitPlatform plugin;
|
||||||
|
|
||||||
@Inject public ServerListener(@Nonnull final BukkitPlatform plugin) {
|
@Inject
|
||||||
|
public ServerListener(final @NonNull BukkitPlatform plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler public void onServerLoad(ServerLoadEvent event) {
|
@EventHandler
|
||||||
|
public void onServerLoad(ServerLoadEvent event) {
|
||||||
if (Bukkit.getPluginManager().getPlugin("MVdWPlaceholderAPI") != null && Settings.Enabled_Components.USE_MVDWAPI) {
|
if (Bukkit.getPluginManager().getPlugin("MVdWPlaceholderAPI") != null && Settings.Enabled_Components.USE_MVDWAPI) {
|
||||||
new MVdWPlaceholders(this.plugin, this.plugin.placeholderRegistry());
|
new MVdWPlaceholders(this.plugin, this.plugin.placeholderRegistry());
|
||||||
ConsolePlayer.getConsole().sendMessage(TranslatableCaption.of("placeholder.hooked"));
|
ConsolePlayer.getConsole().sendMessage(TranslatableCaption.of("placeholder.hooked"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,8 @@ public class SingleWorldListener implements Listener {
|
|||||||
// handle(event);
|
// handle(event);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST) public void onChunkLoad(ChunkLoadEvent event) {
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onChunkLoad(ChunkLoadEvent event) {
|
||||||
handle(event);
|
handle(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,4 +126,5 @@ public class SingleWorldListener implements Listener {
|
|||||||
}
|
}
|
||||||
return separator == 1;
|
return separator == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,15 +37,15 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.world.WorldInitEvent;
|
import org.bukkit.event.world.WorldInitEvent;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class WorldEvents implements Listener {
|
public class WorldEvents implements Listener {
|
||||||
|
|
||||||
private final PlotAreaManager plotAreaManager;
|
private final PlotAreaManager plotAreaManager;
|
||||||
|
|
||||||
@Inject public WorldEvents(@Nonnull final PlotAreaManager plotAreaManager) {
|
@Inject
|
||||||
|
public WorldEvents(final @NonNull PlotAreaManager plotAreaManager) {
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,4 +67,5 @@ public class WorldEvents implements Listener {
|
|||||||
PlotSquared.get().loadWorld(name, new BukkitPlotGenerator(name, gen, this.plotAreaManager));
|
PlotSquared.get().loadWorld(name, new BukkitPlotGenerator(name, gen, this.plotAreaManager));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,9 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.WorldCreator;
|
import org.bukkit.WorldCreator;
|
||||||
import org.bukkit.WorldType;
|
import org.bukkit.WorldType;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -45,13 +45,15 @@ import java.util.List;
|
|||||||
* Default Bukkit world manager. It will handle world creation by
|
* Default Bukkit world manager. It will handle world creation by
|
||||||
* registering the generator in bukkit.yml
|
* registering the generator in bukkit.yml
|
||||||
*/
|
*/
|
||||||
@Singleton public class BukkitWorldManager implements PlatformWorldManager<World> {
|
@Singleton
|
||||||
|
public class BukkitWorldManager implements PlatformWorldManager<World> {
|
||||||
|
|
||||||
@Override public void initialize() {
|
@Override
|
||||||
|
public void initialize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nullable
|
@Override
|
||||||
public World handleWorldCreation(@Nonnull String worldName, @Nullable String generator) {
|
public @Nullable World handleWorldCreation(@NonNull String worldName, @Nullable String generator) {
|
||||||
this.setGenerator(worldName, generator);
|
this.setGenerator(worldName, generator);
|
||||||
final WorldCreator wc = new WorldCreator(worldName);
|
final WorldCreator wc = new WorldCreator(worldName);
|
||||||
wc.environment(World.Environment.NORMAL);
|
wc.environment(World.Environment.NORMAL);
|
||||||
@ -62,7 +64,7 @@ import java.util.List;
|
|||||||
return Bukkit.createWorld(wc);
|
return Bukkit.createWorld(wc);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setGenerator(@Nullable final String worldName, @Nullable final String generator) {
|
protected void setGenerator(final @Nullable String worldName, final @Nullable String generator) {
|
||||||
if (generator == null) {
|
if (generator == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -76,11 +78,13 @@ import java.util.List;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String getName() {
|
@Override
|
||||||
|
public String getName() {
|
||||||
return "bukkit";
|
return "bukkit";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Collection<String> getWorlds() {
|
@Override
|
||||||
|
public Collection<String> getWorlds() {
|
||||||
final List<World> worlds = Bukkit.getWorlds();
|
final List<World> worlds = Bukkit.getWorlds();
|
||||||
final List<String> worldNames = new ArrayList<>();
|
final List<String> worldNames = new ArrayList<>();
|
||||||
for (final World world : worlds) {
|
for (final World world : worlds) {
|
||||||
|
@ -27,41 +27,42 @@ package com.plotsquared.bukkit.managers;
|
|||||||
|
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import se.hyperver.hyperverse.Hyperverse;
|
import se.hyperver.hyperverse.Hyperverse;
|
||||||
import se.hyperver.hyperverse.world.WorldConfiguration;
|
import se.hyperver.hyperverse.world.WorldConfiguration;
|
||||||
import se.hyperver.hyperverse.world.WorldConfigurationBuilder;
|
import se.hyperver.hyperverse.world.WorldConfigurationBuilder;
|
||||||
import se.hyperver.hyperverse.world.WorldFeatures;
|
import se.hyperver.hyperverse.world.WorldFeatures;
|
||||||
import se.hyperver.hyperverse.world.WorldType;
|
import se.hyperver.hyperverse.world.WorldType;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hyperverse specific manager that creates worlds
|
* Hyperverse specific manager that creates worlds
|
||||||
* using Hyperverse's API
|
* using Hyperverse's API
|
||||||
*/
|
*/
|
||||||
@Singleton public class HyperverseWorldManager extends BukkitWorldManager {
|
@Singleton
|
||||||
|
public class HyperverseWorldManager extends BukkitWorldManager {
|
||||||
|
|
||||||
@Override @Nullable
|
@Override
|
||||||
public World handleWorldCreation(@Nonnull String worldName, @Nullable String generator) {
|
public @Nullable World handleWorldCreation(@NonNull String worldName, @Nullable String generator) {
|
||||||
// First let Bukkit register the world
|
// First let Bukkit register the world
|
||||||
this.setGenerator(worldName, generator);
|
this.setGenerator(worldName, generator);
|
||||||
// Create the world
|
// Create the world
|
||||||
final WorldConfigurationBuilder worldConfigurationBuilder = WorldConfiguration.builder()
|
final WorldConfigurationBuilder worldConfigurationBuilder = WorldConfiguration.builder()
|
||||||
.setName(worldName).setType(WorldType.OVER_WORLD);
|
.setName(worldName).setType(WorldType.OVER_WORLD);
|
||||||
if (generator != null) {
|
if (generator != null) {
|
||||||
worldConfigurationBuilder.setGenerator(generator).setWorldFeatures(WorldFeatures.FLATLAND);
|
worldConfigurationBuilder.setGenerator(generator).setWorldFeatures(WorldFeatures.FLATLAND);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return Hyperverse.getApi().createWorld(worldConfigurationBuilder.createWorldConfiguration())
|
return Hyperverse.getApi().createWorld(worldConfigurationBuilder.createWorldConfiguration())
|
||||||
.getBukkitWorld();
|
.getBukkitWorld();
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String getName() {
|
@Override
|
||||||
|
public String getName() {
|
||||||
return "bukkit-hyperverse";
|
return "bukkit-hyperverse";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,23 +28,23 @@ package com.plotsquared.bukkit.managers;
|
|||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Multiverse specific manager that informs Multiverse of
|
* Multiverse specific manager that informs Multiverse of
|
||||||
* world creation by executing a console command
|
* world creation by executing a console command
|
||||||
*/
|
*/
|
||||||
@Singleton public class MultiverseWorldManager extends BukkitWorldManager {
|
@Singleton
|
||||||
|
public class MultiverseWorldManager extends BukkitWorldManager {
|
||||||
|
|
||||||
@Override @Nullable
|
@Override
|
||||||
public World handleWorldCreation(@Nonnull final String worldName, @Nullable final String generator) {
|
public @Nullable World handleWorldCreation(final @NonNull String worldName, final @Nullable String generator) {
|
||||||
// First let Bukkit register the world
|
// First let Bukkit register the world
|
||||||
this.setGenerator(worldName, generator);
|
this.setGenerator(worldName, generator);
|
||||||
// Then we send the console command
|
// Then we send the console command
|
||||||
final StringBuilder commandBuilder = new StringBuilder("mv create ")
|
final StringBuilder commandBuilder = new StringBuilder("mv create ")
|
||||||
.append(worldName).append(" normal");
|
.append(worldName).append(" normal");
|
||||||
if (generator != null) {
|
if (generator != null) {
|
||||||
commandBuilder.append(" -g ").append(generator);
|
commandBuilder.append(" -g ").append(generator);
|
||||||
}
|
}
|
||||||
@ -52,7 +52,8 @@ import javax.annotation.Nullable;
|
|||||||
return Bukkit.getWorld(worldName);
|
return Bukkit.getWorld(worldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String getName() {
|
@Override
|
||||||
|
public String getName() {
|
||||||
return "bukkit-multiverse";
|
return "bukkit-multiverse";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,9 +33,9 @@ import com.plotsquared.core.player.ConsolePlayer;
|
|||||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -43,11 +43,15 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class BukkitPermissionHandler implements PermissionHandler {
|
public class BukkitPermissionHandler implements PermissionHandler {
|
||||||
|
|
||||||
@Override public void initialize() {
|
@Override
|
||||||
|
public void initialize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull @Override public Optional<PermissionProfile> getPermissionProfile(
|
@NonNull
|
||||||
@Nonnull PlotPlayer<?> playerPlotPlayer) {
|
@Override
|
||||||
|
public Optional<PermissionProfile> getPermissionProfile(
|
||||||
|
@NonNull PlotPlayer<?> playerPlotPlayer
|
||||||
|
) {
|
||||||
if (playerPlotPlayer instanceof BukkitPlayer) {
|
if (playerPlotPlayer instanceof BukkitPlayer) {
|
||||||
final BukkitPlayer bukkitPlayer = (BukkitPlayer) playerPlotPlayer;
|
final BukkitPlayer bukkitPlayer = (BukkitPlayer) playerPlotPlayer;
|
||||||
return Optional.of(new BukkitPermissionProfile(bukkitPlayer.getPlatformPlayer()));
|
return Optional.of(new BukkitPermissionProfile(bukkitPlayer.getPlatformPlayer()));
|
||||||
@ -57,12 +61,17 @@ public class BukkitPermissionHandler implements PermissionHandler {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull @Override public Optional<PermissionProfile> getPermissionProfile(
|
@NonNull
|
||||||
@Nonnull OfflinePlotPlayer offlinePlotPlayer) {
|
@Override
|
||||||
|
public Optional<PermissionProfile> getPermissionProfile(
|
||||||
|
@NonNull OfflinePlotPlayer offlinePlotPlayer
|
||||||
|
) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull @Override public Set<PermissionHandlerCapability> getCapabilities() {
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Set<PermissionHandlerCapability> getCapabilities() {
|
||||||
return EnumSet.of(PermissionHandlerCapability.ONLINE_PERMISSIONS);
|
return EnumSet.of(PermissionHandlerCapability.ONLINE_PERMISSIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,12 +80,15 @@ public class BukkitPermissionHandler implements PermissionHandler {
|
|||||||
|
|
||||||
private final WeakReference<Player> playerReference;
|
private final WeakReference<Player> playerReference;
|
||||||
|
|
||||||
private BukkitPermissionProfile(@Nonnull final Player player) {
|
private BukkitPermissionProfile(final @NonNull Player player) {
|
||||||
this.playerReference = new WeakReference<>(player);
|
this.playerReference = new WeakReference<>(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean hasPermission(@Nullable final String world,
|
@Override
|
||||||
@Nonnull final String permission) {
|
public boolean hasPermission(
|
||||||
|
final @Nullable String world,
|
||||||
|
final @NonNull String permission
|
||||||
|
) {
|
||||||
final Player player = this.playerReference.get();
|
final Player player = this.playerReference.get();
|
||||||
return player != null && player.hasPermission(permission);
|
return player != null && player.hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,9 @@ import net.milkbowl.vault.permission.Permission;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -48,19 +48,23 @@ public class VaultPermissionHandler implements PermissionHandler {
|
|||||||
|
|
||||||
private Permission permissions;
|
private Permission permissions;
|
||||||
|
|
||||||
@Override public void initialize() {
|
@Override
|
||||||
|
public void initialize() {
|
||||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||||
throw new IllegalStateException("Vault is not present on the server");
|
throw new IllegalStateException("Vault is not present on the server");
|
||||||
}
|
}
|
||||||
RegisteredServiceProvider<Permission> permissionProvider =
|
RegisteredServiceProvider<Permission> permissionProvider =
|
||||||
Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
||||||
if (permissionProvider != null) {
|
if (permissionProvider != null) {
|
||||||
this.permissions = permissionProvider.getProvider();
|
this.permissions = permissionProvider.getProvider();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull @Override public Optional<PermissionProfile> getPermissionProfile(
|
@NonNull
|
||||||
@Nonnull PlotPlayer<?> playerPlotPlayer) {
|
@Override
|
||||||
|
public Optional<PermissionProfile> getPermissionProfile(
|
||||||
|
@NonNull PlotPlayer<?> playerPlotPlayer
|
||||||
|
) {
|
||||||
if (playerPlotPlayer instanceof BukkitPlayer) {
|
if (playerPlotPlayer instanceof BukkitPlayer) {
|
||||||
final BukkitPlayer bukkitPlayer = (BukkitPlayer) playerPlotPlayer;
|
final BukkitPlayer bukkitPlayer = (BukkitPlayer) playerPlotPlayer;
|
||||||
return Optional.of(new VaultPermissionProfile(bukkitPlayer.getPlatformPlayer()));
|
return Optional.of(new VaultPermissionProfile(bukkitPlayer.getPlatformPlayer()));
|
||||||
@ -70,18 +74,25 @@ public class VaultPermissionHandler implements PermissionHandler {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull @Override public Optional<PermissionProfile> getPermissionProfile(
|
@NonNull
|
||||||
@Nonnull OfflinePlotPlayer offlinePlotPlayer) {
|
@Override
|
||||||
|
public Optional<PermissionProfile> getPermissionProfile(
|
||||||
|
@NonNull OfflinePlotPlayer offlinePlotPlayer
|
||||||
|
) {
|
||||||
if (offlinePlotPlayer instanceof BukkitOfflinePlayer) {
|
if (offlinePlotPlayer instanceof BukkitOfflinePlayer) {
|
||||||
return Optional.of(new VaultPermissionProfile(((BukkitOfflinePlayer) offlinePlotPlayer).player));
|
return Optional.of(new VaultPermissionProfile(((BukkitOfflinePlayer) offlinePlotPlayer).player));
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull @Override public Set<PermissionHandlerCapability> getCapabilities() {
|
@NonNull
|
||||||
return EnumSet.of(PermissionHandlerCapability.PER_WORLD_PERMISSIONS,
|
@Override
|
||||||
PermissionHandlerCapability.ONLINE_PERMISSIONS,
|
public Set<PermissionHandlerCapability> getCapabilities() {
|
||||||
PermissionHandlerCapability.OFFLINE_PERMISSIONS);
|
return EnumSet.of(
|
||||||
|
PermissionHandlerCapability.PER_WORLD_PERMISSIONS,
|
||||||
|
PermissionHandlerCapability.ONLINE_PERMISSIONS,
|
||||||
|
PermissionHandlerCapability.OFFLINE_PERMISSIONS
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -89,12 +100,15 @@ public class VaultPermissionHandler implements PermissionHandler {
|
|||||||
|
|
||||||
private final OfflinePlayer offlinePlayer;
|
private final OfflinePlayer offlinePlayer;
|
||||||
|
|
||||||
private VaultPermissionProfile(@Nonnull final OfflinePlayer offlinePlayer) {
|
private VaultPermissionProfile(final @NonNull OfflinePlayer offlinePlayer) {
|
||||||
this.offlinePlayer = offlinePlayer;
|
this.offlinePlayer = offlinePlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean hasPermission(@Nullable final String world,
|
@Override
|
||||||
@Nonnull final String permission) {
|
public boolean hasPermission(
|
||||||
|
final @Nullable String world,
|
||||||
|
final @NonNull String permission
|
||||||
|
) {
|
||||||
if (permissions == null) {
|
if (permissions == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,7 @@ import com.plotsquared.core.util.placeholders.Placeholder;
|
|||||||
import com.plotsquared.core.util.placeholders.PlaceholderRegistry;
|
import com.plotsquared.core.util.placeholders.PlaceholderRegistry;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Placeholder support for MVdWPlaceholderAPI
|
* Placeholder support for MVdWPlaceholderAPI
|
||||||
@ -46,7 +45,10 @@ public class MVdWPlaceholders {
|
|||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
private final PlaceholderRegistry registry;
|
private final PlaceholderRegistry registry;
|
||||||
|
|
||||||
public MVdWPlaceholders(@Nonnull final Plugin plugin, @Nonnull final PlaceholderRegistry registry) {
|
public MVdWPlaceholders(
|
||||||
|
final @NonNull Plugin plugin,
|
||||||
|
final @NonNull PlaceholderRegistry registry
|
||||||
|
) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.registry = registry;
|
this.registry = registry;
|
||||||
for (final Placeholder placeholder : registry.getPlaceholders()) {
|
for (final Placeholder placeholder : registry.getPlaceholders()) {
|
||||||
@ -55,19 +57,24 @@ public class MVdWPlaceholders {
|
|||||||
PlotSquared.get().getEventDispatcher().registerListener(this);
|
PlotSquared.get().getEventDispatcher().registerListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe public void onNewPlaceholder(@Nonnull final PlaceholderRegistry.PlaceholderAddedEvent event) {
|
@Subscribe
|
||||||
|
public void onNewPlaceholder(final PlaceholderRegistry.@NonNull PlaceholderAddedEvent event) {
|
||||||
this.addPlaceholder(event.getPlaceholder());
|
this.addPlaceholder(event.getPlaceholder());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPlaceholder(@Nonnull final Placeholder placeholder) {
|
private void addPlaceholder(final @NonNull Placeholder placeholder) {
|
||||||
PlaceholderAPI.registerPlaceholder(plugin, PREFIX + String.format("%s", placeholder.getKey()), placeholderReplaceEvent -> {
|
PlaceholderAPI.registerPlaceholder(
|
||||||
if (!placeholderReplaceEvent.isOnline() || placeholderReplaceEvent.getPlayer() == null) {
|
plugin,
|
||||||
return "";
|
PREFIX + String.format("%s", placeholder.getKey()),
|
||||||
}
|
placeholderReplaceEvent -> {
|
||||||
final PlotPlayer<Player> player = BukkitUtil.adapt(placeholderReplaceEvent.getPlayer());
|
if (!placeholderReplaceEvent.isOnline() || placeholderReplaceEvent.getPlayer() == null) {
|
||||||
String key = placeholderReplaceEvent.getPlaceholder().substring(PREFIX.length());
|
return "";
|
||||||
return registry.getPlaceholderValue(key, player);
|
}
|
||||||
});
|
final PlotPlayer<Player> player = BukkitUtil.adapt(placeholderReplaceEvent.getPlayer());
|
||||||
|
String key = placeholderReplaceEvent.getPlaceholder().substring(PREFIX.length());
|
||||||
|
return registry.getPlaceholderValue(key, player);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,27 +36,33 @@ public class PAPIPlaceholders extends PlaceholderExpansion {
|
|||||||
public PAPIPlaceholders() {
|
public PAPIPlaceholders() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean persist() {
|
@Override
|
||||||
|
public boolean persist() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean canRegister() {
|
@Override
|
||||||
|
public boolean canRegister() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String getAuthor() {
|
@Override
|
||||||
|
public String getAuthor() {
|
||||||
return "IntellectualSites";
|
return "IntellectualSites";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String getIdentifier() {
|
@Override
|
||||||
|
public String getIdentifier() {
|
||||||
return "plotsquared";
|
return "plotsquared";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String getVersion() {
|
@Override
|
||||||
|
public String getVersion() {
|
||||||
return "3";
|
return "3";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String onPlaceholderRequest(Player p, String identifier) {
|
@Override
|
||||||
|
public String onPlaceholderRequest(Player p, String identifier) {
|
||||||
final PlotPlayer<?> pl = PlotSquared.platform().playerManager().getPlayerIfExists(p.getUniqueId());
|
final PlotPlayer<?> pl = PlotSquared.platform().playerManager().getPlayerIfExists(p.getUniqueId());
|
||||||
|
|
||||||
if (pl == null) {
|
if (pl == null) {
|
||||||
@ -66,18 +72,20 @@ public class PAPIPlaceholders extends PlaceholderExpansion {
|
|||||||
// PAPI specific ones that don't translate well over into other placeholder APIs
|
// PAPI specific ones that don't translate well over into other placeholder APIs
|
||||||
if (identifier.startsWith("has_plot_")) {
|
if (identifier.startsWith("has_plot_")) {
|
||||||
identifier = identifier.substring("has_plot_".length());
|
identifier = identifier.substring("has_plot_".length());
|
||||||
if (identifier.isEmpty())
|
if (identifier.isEmpty()) {
|
||||||
return "";
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
return pl.getPlotCount(identifier) > 0 ?
|
return pl.getPlotCount(identifier) > 0 ?
|
||||||
PlaceholderAPIPlugin.booleanTrue() :
|
PlaceholderAPIPlugin.booleanTrue() :
|
||||||
PlaceholderAPIPlugin.booleanFalse();
|
PlaceholderAPIPlugin.booleanFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (identifier.startsWith("plot_count_")) {
|
if (identifier.startsWith("plot_count_")) {
|
||||||
identifier = identifier.substring("plot_count_".length());
|
identifier = identifier.substring("plot_count_".length());
|
||||||
if (identifier.isEmpty())
|
if (identifier.isEmpty()) {
|
||||||
return "";
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
return String.valueOf(pl.getPlotCount(identifier));
|
return String.valueOf(pl.getPlotCount(identifier));
|
||||||
}
|
}
|
||||||
|
@ -30,12 +30,12 @@ import com.plotsquared.core.configuration.caption.ChatFormatter;
|
|||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public class PlaceholderFormatter implements ChatFormatter {
|
public class PlaceholderFormatter implements ChatFormatter {
|
||||||
|
|
||||||
@Override public void format(@Nonnull final ChatContext context) {
|
@Override
|
||||||
|
public void format(final @NonNull ChatContext context) {
|
||||||
final PlotPlayer<?> recipient = context.getRecipient();
|
final PlotPlayer<?> recipient = context.getRecipient();
|
||||||
if (recipient instanceof BukkitPlayer) {
|
if (recipient instanceof BukkitPlayer) {
|
||||||
if (context.isRawOutput()) {
|
if (context.isRawOutput()) {
|
||||||
|
@ -30,10 +30,9 @@ import com.plotsquared.core.permissions.PermissionHandler;
|
|||||||
import com.plotsquared.core.permissions.PermissionProfile;
|
import com.plotsquared.core.permissions.PermissionProfile;
|
||||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.checkerframework.checker.index.qual.NonNegative;
|
||||||
import javax.annotation.Nonnegative;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -46,30 +45,40 @@ public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
|||||||
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player),
|
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player),
|
||||||
* as it caches player objects.
|
* as it caches player objects.
|
||||||
*
|
*
|
||||||
* @param player Bukkit OfflinePlayer player to convert
|
* @param player Bukkit OfflinePlayer player to convert
|
||||||
* @param permissionHandler Permission Profile to be used
|
* @param permissionHandler Permission Profile to be used
|
||||||
*/
|
*/
|
||||||
public BukkitOfflinePlayer(@Nonnull final OfflinePlayer player, @Nonnull final
|
public BukkitOfflinePlayer(
|
||||||
PermissionHandler permissionHandler) {
|
final @NonNull OfflinePlayer player, final @NonNull
|
||||||
|
PermissionHandler permissionHandler
|
||||||
|
) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.permissionProfile = permissionHandler.getPermissionProfile(this)
|
this.permissionProfile = permissionHandler.getPermissionProfile(this)
|
||||||
.orElse(NullPermissionProfile.INSTANCE);
|
.orElse(NullPermissionProfile.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull @Override public UUID getUUID() {
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public UUID getUUID() {
|
||||||
return this.player.getUniqueId();
|
return this.player.getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnegative public long getLastPlayed() {
|
@Override
|
||||||
|
@NonNegative
|
||||||
|
public long getLastPlayed() {
|
||||||
return this.player.getLastSeen();
|
return this.player.getLastSeen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String getName() {
|
@Override
|
||||||
|
public String getName() {
|
||||||
return this.player.getName();
|
return this.player.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean hasPermission(@Nullable final String world,
|
@Override
|
||||||
@Nonnull final String permission) {
|
public boolean hasPermission(
|
||||||
|
final @Nullable String world,
|
||||||
|
final @NonNull String permission
|
||||||
|
) {
|
||||||
return this.permissionProfile.hasPermission(world, permission);
|
return this.permissionProfile.hasPermission(world, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,10 +28,10 @@ package com.plotsquared.bukkit.player;
|
|||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.plotsquared.core.PlotSquared;
|
import com.plotsquared.core.PlotSquared;
|
||||||
import com.plotsquared.core.permissions.Permission;
|
|
||||||
import com.plotsquared.core.configuration.Settings;
|
import com.plotsquared.core.configuration.Settings;
|
||||||
import com.plotsquared.core.events.TeleportCause;
|
import com.plotsquared.core.events.TeleportCause;
|
||||||
import com.plotsquared.core.location.Location;
|
import com.plotsquared.core.location.Location;
|
||||||
|
import com.plotsquared.core.permissions.Permission;
|
||||||
import com.plotsquared.core.permissions.PermissionHandler;
|
import com.plotsquared.core.permissions.PermissionHandler;
|
||||||
import com.plotsquared.core.player.ConsolePlayer;
|
import com.plotsquared.core.player.ConsolePlayer;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
@ -54,10 +54,9 @@ import org.bukkit.event.EventException;
|
|||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
import org.bukkit.plugin.RegisteredListener;
|
import org.bukkit.plugin.RegisteredListener;
|
||||||
|
import org.checkerframework.checker.index.qual.NonNegative;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnegative;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -73,24 +72,29 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
private static boolean CHECK_EFFECTIVE = true;
|
private static boolean CHECK_EFFECTIVE = true;
|
||||||
public final Player player;
|
public final Player player;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Please do not use this method. Instead use
|
* <p>Please do not use this method. Instead use
|
||||||
* BukkitUtil.getPlayer(Player), as it caches player objects.</p>
|
* BukkitUtil.getPlayer(Player), as it caches player objects.</p>
|
||||||
*
|
*
|
||||||
* @param plotAreaManager PlotAreaManager instance
|
* @param plotAreaManager PlotAreaManager instance
|
||||||
* @param eventDispatcher EventDispatcher instance
|
* @param eventDispatcher EventDispatcher instance
|
||||||
* @param player Bukkit player instance
|
* @param player Bukkit player instance
|
||||||
* @param permissionHandler PermissionHandler instance
|
* @param permissionHandler PermissionHandler instance
|
||||||
*/
|
*/
|
||||||
public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final EventDispatcher eventDispatcher,
|
public BukkitPlayer(
|
||||||
@Nonnull final Player player, @Nonnull final PermissionHandler permissionHandler) {
|
final @NonNull PlotAreaManager plotAreaManager, final @NonNull EventDispatcher eventDispatcher,
|
||||||
|
final @NonNull Player player, final @NonNull PermissionHandler permissionHandler
|
||||||
|
) {
|
||||||
this(plotAreaManager, eventDispatcher, player, false, permissionHandler);
|
this(plotAreaManager, eventDispatcher, player, false, permissionHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final
|
public BukkitPlayer(
|
||||||
EventDispatcher eventDispatcher, @Nonnull final Player player,
|
final @NonNull PlotAreaManager plotAreaManager, final @NonNull
|
||||||
final boolean realPlayer,
|
EventDispatcher eventDispatcher, final @NonNull Player player,
|
||||||
@Nonnull final PermissionHandler permissionHandler) {
|
final boolean realPlayer,
|
||||||
|
final @NonNull PermissionHandler permissionHandler
|
||||||
|
) {
|
||||||
super(plotAreaManager, eventDispatcher, permissionHandler);
|
super(plotAreaManager, eventDispatcher, permissionHandler);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.setupPermissionProfile();
|
this.setupPermissionProfile();
|
||||||
@ -99,32 +103,39 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Actor toActor() {
|
@Override
|
||||||
|
public Actor toActor() {
|
||||||
return BukkitAdapter.adapt(player);
|
return BukkitAdapter.adapt(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Player getPlatformPlayer() {
|
@Override
|
||||||
|
public Player getPlatformPlayer() {
|
||||||
return this.player;
|
return this.player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull @Override public UUID getUUID() {
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public UUID getUUID() {
|
||||||
if (Settings.UUID.OFFLINE) {
|
if (Settings.UUID.OFFLINE) {
|
||||||
if (Settings.UUID.FORCE_LOWERCASE) {
|
if (Settings.UUID.FORCE_LOWERCASE) {
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" +
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" +
|
||||||
getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
||||||
} else {
|
} else {
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" +
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" +
|
||||||
getName()).getBytes(Charsets.UTF_8));
|
getName()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return player.getUniqueId();
|
return player.getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnegative public long getLastPlayed() {
|
@Override
|
||||||
|
@NonNegative
|
||||||
|
public long getLastPlayed() {
|
||||||
return this.player.getLastSeen();
|
return this.player.getLastSeen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean canTeleport(@Nonnull final Location location) {
|
@Override
|
||||||
|
public boolean canTeleport(final @NonNull Location location) {
|
||||||
final org.bukkit.Location to = BukkitUtil.adapt(location);
|
final org.bukkit.Location to = BukkitUtil.adapt(location);
|
||||||
final org.bukkit.Location from = player.getLocation();
|
final org.bukkit.Location from = player.getLocation();
|
||||||
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
|
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
|
||||||
@ -137,7 +148,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callEvent(@Nonnull final Event event) {
|
private void callEvent(final @NonNull Event event) {
|
||||||
final RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners();
|
final RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners();
|
||||||
for (final RegisteredListener listener : listeners) {
|
for (final RegisteredListener listener : listeners) {
|
||||||
if (listener.getPlugin().getName().equals(PlotSquared.platform().pluginName())) {
|
if (listener.getPlugin().getName().equals(PlotSquared.platform().pluginName())) {
|
||||||
@ -151,8 +162,12 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnegative public int hasPermissionRange(@Nonnull final String stub,
|
@Override
|
||||||
@Nonnegative final int range) {
|
@NonNegative
|
||||||
|
public int hasPermissionRange(
|
||||||
|
final @NonNull String stub,
|
||||||
|
@NonNegative final int range
|
||||||
|
) {
|
||||||
if (hasPermission(Permission.PERMISSION_ADMIN.toString())) {
|
if (hasPermission(Permission.PERMISSION_ADMIN.toString())) {
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
@ -213,34 +228,40 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(@Nonnull final Location location, @Nonnull final TeleportCause cause) {
|
public void teleport(final @NonNull Location location, final @NonNull TeleportCause cause) {
|
||||||
if (Math.abs(location.getX()) >= 30000000 || Math.abs(location.getZ()) >= 30000000) {
|
if (Math.abs(location.getX()) >= 30000000 || Math.abs(location.getZ()) >= 30000000) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final org.bukkit.Location bukkitLocation =
|
final org.bukkit.Location bukkitLocation =
|
||||||
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorldName()), location.getX() + 0.5,
|
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorldName()), location.getX() + 0.5,
|
||||||
location.getY(), location.getZ() + 0.5, location.getYaw(), location.getPitch());
|
location.getY(), location.getZ() + 0.5, location.getYaw(), location.getPitch()
|
||||||
|
);
|
||||||
PaperLib.teleportAsync(player, bukkitLocation, getTeleportCause(cause));
|
PaperLib.teleportAsync(player, bukkitLocation, getTeleportCause(cause));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String getName() {
|
@Override
|
||||||
|
public String getName() {
|
||||||
if (this.name == null) {
|
if (this.name == null) {
|
||||||
this.name = this.player.getName();
|
this.name = this.player.getName();
|
||||||
}
|
}
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void setCompassTarget(Location location) {
|
@Override
|
||||||
|
public void setCompassTarget(Location location) {
|
||||||
this.player.setCompassTarget(
|
this.player.setCompassTarget(
|
||||||
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorldName()), location.getX(),
|
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorldName()), location.getX(),
|
||||||
location.getY(), location.getZ()));
|
location.getY(), location.getZ()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Location getLocationFull() {
|
@Override
|
||||||
|
public Location getLocationFull() {
|
||||||
return BukkitUtil.adaptComplete(this.player.getLocation());
|
return BukkitUtil.adaptComplete(this.player.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void setWeather(@Nonnull final PlotWeather weather) {
|
@Override
|
||||||
|
public void setWeather(final @NonNull PlotWeather weather) {
|
||||||
switch (weather) {
|
switch (weather) {
|
||||||
case CLEAR:
|
case CLEAR:
|
||||||
this.player.setPlayerWeather(WeatherType.CLEAR);
|
this.player.setPlayerWeather(WeatherType.CLEAR);
|
||||||
@ -255,7 +276,8 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public com.sk89q.worldedit.world.gamemode.GameMode getGameMode() {
|
@Override
|
||||||
|
public com.sk89q.worldedit.world.gamemode.GameMode getGameMode() {
|
||||||
switch (this.player.getGameMode()) {
|
switch (this.player.getGameMode()) {
|
||||||
case ADVENTURE:
|
case ADVENTURE:
|
||||||
return ADVENTURE;
|
return ADVENTURE;
|
||||||
@ -282,7 +304,8 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void setTime(final long time) {
|
@Override
|
||||||
|
public void setTime(final long time) {
|
||||||
if (time != Long.MAX_VALUE) {
|
if (time != Long.MAX_VALUE) {
|
||||||
this.player.setPlayerTime(time, false);
|
this.player.setPlayerTime(time, false);
|
||||||
} else {
|
} else {
|
||||||
@ -290,48 +313,57 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean getFlight() {
|
@Override
|
||||||
|
public boolean getFlight() {
|
||||||
return player.getAllowFlight();
|
return player.getAllowFlight();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void setFlight(boolean fly) {
|
@Override
|
||||||
|
public void setFlight(boolean fly) {
|
||||||
this.player.setAllowFlight(fly);
|
this.player.setAllowFlight(fly);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void playMusic(@Nonnull final Location location, @Nonnull final ItemType id) {
|
@Override
|
||||||
|
public void playMusic(final @NonNull Location location, final @NonNull ItemType id) {
|
||||||
if (id == ItemTypes.AIR) {
|
if (id == ItemTypes.AIR) {
|
||||||
// Let's just stop all the discs because why not?
|
// Let's just stop all the discs because why not?
|
||||||
for (final Sound sound : Arrays.stream(Sound.values())
|
for (final Sound sound : Arrays.stream(Sound.values())
|
||||||
.filter(sound -> sound.name().contains("DISC")).collect(Collectors.toList())) {
|
.filter(sound -> sound.name().contains("DISC")).collect(Collectors.toList())) {
|
||||||
player.stopSound(sound);
|
player.stopSound(sound);
|
||||||
}
|
}
|
||||||
// this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, Material.AIR);
|
// this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, Material.AIR);
|
||||||
} else {
|
} else {
|
||||||
// this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, id.to(Material.class));
|
// this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, id.to(Material.class));
|
||||||
this.player.playSound(BukkitUtil.adapt(location),
|
this.player.playSound(BukkitUtil.adapt(location),
|
||||||
Sound.valueOf(BukkitAdapter.adapt(id).name()), Float.MAX_VALUE, 1f);
|
Sound.valueOf(BukkitAdapter.adapt(id).name()), Float.MAX_VALUE, 1f
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void kick(final String message) {
|
@Override
|
||||||
|
public void kick(final String message) {
|
||||||
this.player.kickPlayer(message);
|
this.player.kickPlayer(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void stopSpectating() {
|
@Override
|
||||||
|
public void stopSpectating() {
|
||||||
if (getGameMode() == SPECTATOR) {
|
if (getGameMode() == SPECTATOR) {
|
||||||
this.player.setSpectatorTarget(null);
|
this.player.setSpectatorTarget(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean isBanned() {
|
@Override
|
||||||
|
public boolean isBanned() {
|
||||||
return this.player.isBanned();
|
return this.player.isBanned();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public Audience getAudience() {
|
@Override
|
||||||
|
public @NonNull Audience getAudience() {
|
||||||
return BukkitUtil.BUKKIT_AUDIENCES.player(this.player);
|
return BukkitUtil.BUKKIT_AUDIENCES.player(this.player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean canSee(final PlotPlayer<?> other) {
|
@Override
|
||||||
|
public boolean canSee(final PlotPlayer<?> other) {
|
||||||
if (other instanceof ConsolePlayer) {
|
if (other instanceof ConsolePlayer) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -339,7 +371,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerTeleportEvent.TeleportCause getTeleportCause(@Nonnull final TeleportCause cause) {
|
public PlayerTeleportEvent.TeleportCause getTeleportCause(final @NonNull TeleportCause cause) {
|
||||||
switch (cause) {
|
switch (cause) {
|
||||||
case COMMAND:
|
case COMMAND:
|
||||||
return PlayerTeleportEvent.TeleportCause.COMMAND;
|
return PlayerTeleportEvent.TeleportCause.COMMAND;
|
||||||
@ -349,4 +381,5 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
return PlayerTeleportEvent.TeleportCause.UNKNOWN;
|
return PlayerTeleportEvent.TeleportCause.UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,29 +33,35 @@ import com.plotsquared.core.util.EventDispatcher;
|
|||||||
import com.plotsquared.core.util.PlayerManager;
|
import com.plotsquared.core.util.PlayerManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Player manager providing {@link BukkitPlayer Bukkit players}
|
* Player manager providing {@link BukkitPlayer Bukkit players}
|
||||||
*/
|
*/
|
||||||
@Singleton public class BukkitPlayerManager extends PlayerManager<BukkitPlayer, Player> {
|
@Singleton
|
||||||
|
public class BukkitPlayerManager extends PlayerManager<BukkitPlayer, Player> {
|
||||||
|
|
||||||
private final PlotAreaManager plotAreaManager;
|
private final PlotAreaManager plotAreaManager;
|
||||||
private final EventDispatcher eventDispatcher;
|
private final EventDispatcher eventDispatcher;
|
||||||
private final PermissionHandler permissionHandler;
|
private final PermissionHandler permissionHandler;
|
||||||
|
|
||||||
@Inject public BukkitPlayerManager(@Nonnull final PlotAreaManager plotAreaManager,
|
@Inject
|
||||||
@Nonnull final EventDispatcher eventDispatcher,
|
public BukkitPlayerManager(
|
||||||
@Nonnull final PermissionHandler permissionHandler) {
|
final @NonNull PlotAreaManager plotAreaManager,
|
||||||
|
final @NonNull EventDispatcher eventDispatcher,
|
||||||
|
final @NonNull PermissionHandler permissionHandler
|
||||||
|
) {
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
this.eventDispatcher = eventDispatcher;
|
this.eventDispatcher = eventDispatcher;
|
||||||
this.permissionHandler = permissionHandler;
|
this.permissionHandler = permissionHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull @Override public BukkitPlayer getPlayer(@Nonnull final Player object) {
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public BukkitPlayer getPlayer(final @NonNull Player object) {
|
||||||
if (!object.isOnline()) {
|
if (!object.isOnline()) {
|
||||||
throw new NoSuchPlayerException(object.getUniqueId());
|
throw new NoSuchPlayerException(object.getUniqueId());
|
||||||
}
|
}
|
||||||
@ -66,7 +72,8 @@ import java.util.UUID;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public BukkitPlayer createPlayer(@Nonnull final UUID uuid) {
|
@Override
|
||||||
|
public @NonNull BukkitPlayer createPlayer(final @NonNull UUID uuid) {
|
||||||
final Player player = Bukkit.getPlayer(uuid);
|
final Player player = Bukkit.getPlayer(uuid);
|
||||||
if (player == null || !player.isOnline()) {
|
if (player == null || !player.isOnline()) {
|
||||||
throw new NoSuchPlayerException(uuid);
|
throw new NoSuchPlayerException(uuid);
|
||||||
@ -74,14 +81,18 @@ import java.util.UUID;
|
|||||||
return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, player, this.permissionHandler);
|
return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, player, this.permissionHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable @Override public BukkitOfflinePlayer getOfflinePlayer(@Nullable final UUID uuid) {
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public BukkitOfflinePlayer getOfflinePlayer(final @Nullable UUID uuid) {
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid), this.permissionHandler);
|
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid), this.permissionHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull @Override public BukkitOfflinePlayer getOfflinePlayer(@Nonnull final String username) {
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public BukkitOfflinePlayer getOfflinePlayer(final @NonNull String username) {
|
||||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(username), this.permissionHandler);
|
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(username), this.permissionHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,8 +39,8 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -76,15 +76,18 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
|||||||
private final AtomicInteger expectedSize;
|
private final AtomicInteger expectedSize;
|
||||||
private int batchSize;
|
private int batchSize;
|
||||||
|
|
||||||
@Inject private BukkitChunkCoordinator(@Assisted final long maxIterationTime,
|
@Inject
|
||||||
@Assisted final int initialBatchSize,
|
private BukkitChunkCoordinator(
|
||||||
@Assisted @Nonnull final Consumer<BlockVector2> chunkConsumer,
|
@Assisted final long maxIterationTime,
|
||||||
@Assisted @Nonnull final World world,
|
@Assisted final int initialBatchSize,
|
||||||
@Assisted @Nonnull final Collection<BlockVector2> requestedChunks,
|
@Assisted final @NonNull Consumer<BlockVector2> chunkConsumer,
|
||||||
@Assisted @Nonnull final Runnable whenDone,
|
@Assisted final @NonNull World world,
|
||||||
@Assisted @Nonnull final Consumer<Throwable> throwableConsumer,
|
@Assisted final @NonNull Collection<BlockVector2> requestedChunks,
|
||||||
@Assisted final boolean unloadAfter,
|
@Assisted final @NonNull Runnable whenDone,
|
||||||
@Assisted @Nonnull final Collection<ProgressSubscriber> progressSubscribers) {
|
@Assisted final @NonNull Consumer<Throwable> throwableConsumer,
|
||||||
|
@Assisted final boolean unloadAfter,
|
||||||
|
@Assisted final @NonNull Collection<ProgressSubscriber> progressSubscribers
|
||||||
|
) {
|
||||||
this.requestedChunks = new LinkedBlockingQueue<>(requestedChunks);
|
this.requestedChunks = new LinkedBlockingQueue<>(requestedChunks);
|
||||||
this.availableChunks = new LinkedBlockingQueue<>();
|
this.availableChunks = new LinkedBlockingQueue<>();
|
||||||
this.totalSize = requestedChunks.size();
|
this.totalSize = requestedChunks.size();
|
||||||
@ -100,14 +103,16 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
|||||||
this.progressSubscribers.addAll(progressSubscribers);
|
this.progressSubscribers.addAll(progressSubscribers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void start() {
|
@Override
|
||||||
|
public void start() {
|
||||||
// Request initial batch
|
// Request initial batch
|
||||||
this.requestBatch();
|
this.requestBatch();
|
||||||
// Wait until next tick to give the chunks a chance to be loaded
|
// Wait until next tick to give the chunks a chance to be loaded
|
||||||
TaskManager.runTaskLater(() -> TaskManager.runTaskRepeat(this, TaskTime.ticks(1)), TaskTime.ticks(1));
|
TaskManager.runTaskLater(() -> TaskManager.runTaskRepeat(this, TaskTime.ticks(1)), TaskTime.ticks(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void runTask() {
|
@Override
|
||||||
|
public void runTask() {
|
||||||
Chunk chunk = this.availableChunks.poll();
|
Chunk chunk = this.availableChunks.poll();
|
||||||
if (chunk == null) {
|
if (chunk == null) {
|
||||||
return;
|
return;
|
||||||
@ -166,22 +171,24 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
|||||||
BlockVector2 chunk;
|
BlockVector2 chunk;
|
||||||
for (int i = 0; i < this.batchSize && (chunk = this.requestedChunks.poll()) != null; i++) {
|
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
|
// 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) -> {
|
PaperLib
|
||||||
if (throwable != null) {
|
.getChunkAtAsync(this.bukkitWorld, chunk.getX(), chunk.getZ(), true, true)
|
||||||
throwable.printStackTrace();
|
.whenComplete((chunkObject, throwable) -> {
|
||||||
// We want one less because this couldn't be processed
|
if (throwable != null) {
|
||||||
this.expectedSize.decrementAndGet();
|
throwable.printStackTrace();
|
||||||
} else {
|
// We want one less because this couldn't be processed
|
||||||
this.processChunk(chunkObject);
|
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)
|
* 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) {
|
private void processChunk(final @NonNull Chunk chunk) {
|
||||||
if (!chunk.isLoaded()) {
|
if (!chunk.isLoaded()) {
|
||||||
throw new IllegalArgumentException(String.format("Chunk %d;%d is is not loaded", chunk.getX(), chunk.getZ()));
|
throw new IllegalArgumentException(String.format("Chunk %d;%d is is not loaded", chunk.getX(), chunk.getZ()));
|
||||||
}
|
}
|
||||||
@ -192,18 +199,20 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
|||||||
/**
|
/**
|
||||||
* Once a chunk has been used, free it up for unload by removing the plugin ticket
|
* Once a chunk has been used, free it up for unload by removing the plugin ticket
|
||||||
*/
|
*/
|
||||||
private void freeChunk(@Nonnull final Chunk chunk) {
|
private void freeChunk(final @NonNull Chunk chunk) {
|
||||||
if (!chunk.isLoaded()) {
|
if (!chunk.isLoaded()) {
|
||||||
throw new IllegalArgumentException(String.format("Chunk %d;%d is is not loaded", chunk.getX(), chunk.getZ()));
|
throw new IllegalArgumentException(String.format("Chunk %d;%d is is not loaded", chunk.getX(), chunk.getZ()));
|
||||||
}
|
}
|
||||||
chunk.removePluginChunkTicket(this.plugin);
|
chunk.removePluginChunkTicket(this.plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public int getRemainingChunks() {
|
@Override
|
||||||
|
public int getRemainingChunks() {
|
||||||
return this.expectedSize.get();
|
return this.expectedSize.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public int getTotalChunks() {
|
@Override
|
||||||
|
public int getTotalChunks() {
|
||||||
return this.totalSize;
|
return this.totalSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +221,7 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
|||||||
*
|
*
|
||||||
* @param subscriber Subscriber
|
* @param subscriber Subscriber
|
||||||
*/
|
*/
|
||||||
public void subscribeToProgress(@Nonnull final ProgressSubscriber subscriber) {
|
public void subscribeToProgress(final @NonNull ProgressSubscriber subscriber) {
|
||||||
this.progressSubscribers.add(subscriber);
|
this.progressSubscribers.add(subscriber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,8 +54,8 @@ import org.bukkit.Chunk;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.Container;
|
import org.bukkit.block.Container;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@ -65,31 +65,41 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
|||||||
private final SideEffectSet noSideEffectSet;
|
private final SideEffectSet noSideEffectSet;
|
||||||
private final SideEffectSet lightingSideEffectSet;
|
private final SideEffectSet lightingSideEffectSet;
|
||||||
private org.bukkit.World bukkitWorld;
|
private org.bukkit.World bukkitWorld;
|
||||||
@Inject private ChunkCoordinatorBuilderFactory chunkCoordinatorBuilderFactory;
|
@Inject
|
||||||
@Inject private ChunkCoordinatorFactory chunkCoordinatorFactory;
|
private ChunkCoordinatorBuilderFactory chunkCoordinatorBuilderFactory;
|
||||||
|
@Inject
|
||||||
|
private ChunkCoordinatorFactory chunkCoordinatorFactory;
|
||||||
private ChunkCoordinator chunkCoordinator;
|
private ChunkCoordinator chunkCoordinator;
|
||||||
|
|
||||||
@Inject public BukkitQueueCoordinator(@Nonnull World world) {
|
@Inject
|
||||||
|
public BukkitQueueCoordinator(@NonNull World world) {
|
||||||
super(world);
|
super(world);
|
||||||
noSideEffectSet = SideEffectSet.none().with(SideEffect.LIGHTING, SideEffect.State.OFF).with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
|
noSideEffectSet = SideEffectSet.none().with(SideEffect.LIGHTING, SideEffect.State.OFF).with(
|
||||||
|
SideEffect.NEIGHBORS,
|
||||||
|
SideEffect.State.OFF
|
||||||
|
);
|
||||||
lightingSideEffectSet = SideEffectSet.none().with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
|
lightingSideEffectSet = SideEffectSet.none().with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public BlockState getBlock(int x, int y, int z) {
|
@Override
|
||||||
|
public BlockState getBlock(int x, int y, int z) {
|
||||||
Block block = getBukkitWorld().getBlockAt(x, y, z);
|
Block block = getBukkitWorld().getBlockAt(x, y, z);
|
||||||
return BukkitBlockUtil.get(block);
|
return BukkitBlockUtil.get(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void start() {
|
@Override
|
||||||
|
public void start() {
|
||||||
chunkCoordinator.start();
|
chunkCoordinator.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: implement cancellation
|
//TODO: implement cancellation
|
||||||
@Override public void cancel() {
|
@Override
|
||||||
|
public void cancel() {
|
||||||
chunkCoordinator.cancel();
|
chunkCoordinator.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean enqueue() {
|
@Override
|
||||||
|
public boolean enqueue() {
|
||||||
final Clipboard regenClipboard;
|
final Clipboard regenClipboard;
|
||||||
if (isRegen()) {
|
if (isRegen()) {
|
||||||
BlockVector3 start = BlockVector3.at(getRegenStart()[0] << 4, 0, getRegenStart()[1] << 4);
|
BlockVector3 start = BlockVector3.at(getRegenStart()[0] << 4, 0, getRegenStart()[1] << 4);
|
||||||
@ -110,8 +120,8 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
|||||||
consumer = blockVector2 -> {
|
consumer = blockVector2 -> {
|
||||||
LocalChunk localChunk = getBlockChunks().get(blockVector2);
|
LocalChunk localChunk = getBlockChunks().get(blockVector2);
|
||||||
boolean isRegenChunk =
|
boolean isRegenChunk =
|
||||||
regenClipboard != null && blockVector2.getBlockX() > getRegenStart()[0] && blockVector2.getBlockZ() > getRegenStart()[1]
|
regenClipboard != null && blockVector2.getBlockX() > getRegenStart()[0] && blockVector2.getBlockZ() > getRegenStart()[1]
|
||||||
&& blockVector2.getBlockX() < getRegenEnd()[0] && blockVector2.getBlockZ() < getRegenEnd()[1];
|
&& blockVector2.getBlockX() < getRegenEnd()[0] && blockVector2.getBlockZ() < getRegenEnd()[1];
|
||||||
if (isRegenChunk) {
|
if (isRegenChunk) {
|
||||||
for (int layer = 0; layer < 16; layer++) {
|
for (int layer = 0; layer < 16; layer++) {
|
||||||
for (int y = layer << 4; y < 16; y++) {
|
for (int y = layer << 4; y < 16; y++) {
|
||||||
@ -190,16 +200,26 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
|||||||
read.addAll(getReadChunks());
|
read.addAll(getReadChunks());
|
||||||
}
|
}
|
||||||
chunkCoordinator =
|
chunkCoordinator =
|
||||||
chunkCoordinatorBuilderFactory.create(chunkCoordinatorFactory).inWorld(getWorld()).withChunks(getBlockChunks().keySet()).withChunks(read)
|
chunkCoordinatorBuilderFactory
|
||||||
.withInitialBatchSize(3).withMaxIterationTime(40).withThrowableConsumer(Throwable::printStackTrace).withFinalAction(getCompleteTask())
|
.create(chunkCoordinatorFactory)
|
||||||
.withConsumer(consumer).unloadAfter(isUnloadAfter()).withProgressSubscribers(getProgressSubscribers()).build();
|
.inWorld(getWorld())
|
||||||
|
.withChunks(getBlockChunks().keySet())
|
||||||
|
.withChunks(read)
|
||||||
|
.withInitialBatchSize(3)
|
||||||
|
.withMaxIterationTime(40)
|
||||||
|
.withThrowableConsumer(Throwable::printStackTrace)
|
||||||
|
.withFinalAction(getCompleteTask())
|
||||||
|
.withConsumer(consumer)
|
||||||
|
.unloadAfter(isUnloadAfter())
|
||||||
|
.withProgressSubscribers(getProgressSubscribers())
|
||||||
|
.build();
|
||||||
return super.enqueue();
|
return super.enqueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a block to the world. First tries WNA but defaults to normal block setting methods if that fails
|
* 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) {
|
private void setWorldBlock(int x, int y, int z, @NonNull BaseBlock block, @NonNull BlockVector2 blockVector2) {
|
||||||
try {
|
try {
|
||||||
BlockVector3 loc = BlockVector3.at(x, y, z);
|
BlockVector3 loc = BlockVector3.at(x, y, z);
|
||||||
boolean lighting = false;
|
boolean lighting = false;
|
||||||
@ -211,7 +231,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
|||||||
break;
|
break;
|
||||||
case REPLACEMENT:
|
case REPLACEMENT:
|
||||||
lighting = block.getBlockType().getMaterial().getLightValue() > 0
|
lighting = block.getBlockType().getMaterial().getLightValue() > 0
|
||||||
|| getWorld().getBlock(loc).getBlockType().getMaterial().getLightValue() > 0;
|
|| getWorld().getBlock(loc).getBlockType().getMaterial().getLightValue() > 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Can only be "all"
|
// Can only be "all"
|
||||||
|
@ -45,8 +45,9 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||||
import javax.annotation.Nonnull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class GenChunk extends ScopedQueueCoordinator {
|
public class GenChunk extends ScopedQueueCoordinator {
|
||||||
@ -65,7 +66,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
this.biomes = Biome.values();
|
this.biomes = Biome.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable public ChunkData getChunkData() {
|
public @Nullable ChunkData getChunkData() {
|
||||||
return this.chunkData;
|
return this.chunkData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,11 +75,11 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
*
|
*
|
||||||
* @param chunkData Bukkit ChunkData
|
* @param chunkData Bukkit ChunkData
|
||||||
*/
|
*/
|
||||||
public void setChunkData(@Nonnull ChunkData chunkData) {
|
public void setChunkData(@NonNull ChunkData chunkData) {
|
||||||
this.chunkData = chunkData;
|
this.chunkData = chunkData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull public Chunk getChunk() {
|
public @NonNull Chunk getChunk() {
|
||||||
if (chunk == null) {
|
if (chunk == null) {
|
||||||
World worldObj = BukkitUtil.getWorld(world);
|
World worldObj = BukkitUtil.getWorld(world);
|
||||||
if (worldObj != null) {
|
if (worldObj != null) {
|
||||||
@ -93,7 +94,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
*
|
*
|
||||||
* @param chunk Bukkit Chunk
|
* @param chunk Bukkit Chunk
|
||||||
*/
|
*/
|
||||||
public void setChunk(@Nonnull Chunk chunk) {
|
public void setChunk(@NonNull Chunk chunk) {
|
||||||
this.chunk = chunk;
|
this.chunk = chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,14 +104,15 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
*
|
*
|
||||||
* @param wrap P2 ChunkWrapper
|
* @param wrap P2 ChunkWrapper
|
||||||
*/
|
*/
|
||||||
public void setChunk(@Nonnull ChunkWrapper wrap) {
|
public void setChunk(@NonNull ChunkWrapper wrap) {
|
||||||
chunk = null;
|
chunk = null;
|
||||||
world = wrap.world;
|
world = wrap.world;
|
||||||
chunkX = wrap.x;
|
chunkX = wrap.x;
|
||||||
chunkZ = wrap.z;
|
chunkZ = wrap.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void fillBiome(@Nonnull BiomeType biomeType) {
|
@Override
|
||||||
|
public void fillBiome(@NonNull BiomeType biomeType) {
|
||||||
if (biomeGrid == null) {
|
if (biomeGrid == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -124,7 +126,8 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void setCuboid(@Nonnull Location pos1, @Nonnull Location pos2, @Nonnull BlockState block) {
|
@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) {
|
if (result != null && pos1.getX() == 0 && pos1.getZ() == 0 && pos2.getX() == 15 && pos2.getZ() == 15) {
|
||||||
for (int y = pos1.getY(); y <= pos2.getY(); y++) {
|
for (int y = pos1.getY(); y <= pos2.getY(); y++) {
|
||||||
int layer = y >> 4;
|
int layer = y >> 4;
|
||||||
@ -146,20 +149,20 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
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, @Nonnull BiomeType biomeType) {
|
@Override
|
||||||
|
public boolean setBiome(int x, int z, @NonNull BiomeType biomeType) {
|
||||||
return setBiome(x, z, BukkitAdapter.adapt(biomeType));
|
return setBiome(x, z, BukkitAdapter.adapt(biomeType));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the in the whole column of XZ
|
* Set the in the whole column of XZ
|
||||||
*
|
*
|
||||||
* @param x Relative x location within the chunk (0 - 15)
|
* @param x Relative x location within the chunk (0 - 15)
|
||||||
* @param z Relative z location within the chunk (0 - 15)
|
* @param z Relative z location within the chunk (0 - 15)
|
||||||
* @param biome Bukkit biome to set
|
* @param biome Bukkit biome to set
|
||||||
*
|
|
||||||
* @return if successful
|
* @return if successful
|
||||||
*/
|
*/
|
||||||
public boolean setBiome(int x, int z, @Nonnull Biome biome) {
|
public boolean setBiome(int x, int z, @NonNull Biome biome) {
|
||||||
if (this.biomeGrid != null) {
|
if (this.biomeGrid != null) {
|
||||||
for (int y = 0; y < 256; y++) {
|
for (int y = 0; y < 256; y++) {
|
||||||
this.setBiome(x, y, z, biome);
|
this.setBiome(x, y, z, biome);
|
||||||
@ -169,7 +172,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setBiome(int x, int y, int z, @Nonnull Biome biome) {
|
public boolean setBiome(int x, int y, int z, @NonNull Biome biome) {
|
||||||
if (this.biomeGrid != null) {
|
if (this.biomeGrid != null) {
|
||||||
this.biomeGrid.setBiome(x, y, z, biome);
|
this.biomeGrid.setBiome(x, y, z, biome);
|
||||||
return true;
|
return true;
|
||||||
@ -177,11 +180,13 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean setBlock(int x, int y, int z, @Nonnull Pattern pattern) {
|
@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, @Nonnull BlockState id) {
|
@Override
|
||||||
|
public boolean setBlock(int x, int y, int z, @NonNull BlockState id) {
|
||||||
if (this.result == null) {
|
if (this.result == null) {
|
||||||
this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id));
|
this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id));
|
||||||
return true;
|
return true;
|
||||||
@ -191,7 +196,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeCache(final int x, final int y, final int z, @Nonnull final BlockState id) {
|
private void storeCache(final int x, final int y, final int z, final @NonNull BlockState id) {
|
||||||
int i = y >> 4;
|
int i = y >> 4;
|
||||||
BlockState[] v = this.result[i];
|
BlockState[] v = this.result[i];
|
||||||
if (v == null) {
|
if (v == null) {
|
||||||
@ -201,7 +206,8 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
v[j] = id;
|
v[j] = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean setBlock(int x, int y, int z, @Nonnull BaseBlock id) {
|
@Override
|
||||||
|
public boolean setBlock(int x, int y, int z, @NonNull BaseBlock id) {
|
||||||
if (this.result == null) {
|
if (this.result == null) {
|
||||||
this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id));
|
this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id));
|
||||||
return true;
|
return true;
|
||||||
@ -211,7 +217,8 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nullable public BlockState getBlock(int x, int y, int z) {
|
@Override
|
||||||
|
public @Nullable BlockState getBlock(int x, int y, int z) {
|
||||||
int i = y >> 4;
|
int i = y >> 4;
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
return BukkitBlockUtil.get(chunkData.getType(x, y, z));
|
return BukkitBlockUtil.get(chunkData.getType(x, y, z));
|
||||||
@ -232,19 +239,22 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
return chunk == null ? chunkZ : chunk.getZ();
|
return chunk == null ? chunkZ : chunk.getZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public com.sk89q.worldedit.world.World getWorld() {
|
@Override
|
||||||
|
public com.sk89q.worldedit.world.@NonNull World getWorld() {
|
||||||
return chunk == null ? BukkitAdapter.adapt(Bukkit.getWorld(world)) : BukkitAdapter.adapt(chunk.getWorld());
|
return chunk == null ? BukkitAdapter.adapt(Bukkit.getWorld(world)) : BukkitAdapter.adapt(chunk.getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public Location getMax() {
|
@Override
|
||||||
|
public @NonNull Location getMax() {
|
||||||
return Location.at(getWorld().getName(), 15 + (getX() << 4), 255, 15 + (getZ() << 4));
|
return Location.at(getWorld().getName(), 15 + (getX() << 4), 255, 15 + (getZ() << 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public Location getMin() {
|
@Override
|
||||||
|
public @NonNull Location getMin() {
|
||||||
return Location.at(getWorld().getName(), getX() << 4, 0, getZ() << 4);
|
return Location.at(getWorld().getName(), getX() << 4, 0, getZ() << 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull public GenChunk clone() {
|
public @NonNull GenChunk clone() {
|
||||||
GenChunk toReturn = new GenChunk();
|
GenChunk toReturn = new GenChunk();
|
||||||
if (this.result != null) {
|
if (this.result != null) {
|
||||||
for (int i = 0; i < this.result.length; i++) {
|
for (int i = 0; i < this.result.length; i++) {
|
||||||
@ -258,4 +268,5 @@ public class GenChunk extends ScopedQueueCoordinator {
|
|||||||
toReturn.chunkData = this.chunkData;
|
toReturn.chunkData = this.chunkData;
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,15 +32,16 @@ import com.plotsquared.core.queue.QueueCoordinator;
|
|||||||
import com.plotsquared.core.util.SchematicHandler;
|
import com.plotsquared.core.util.SchematicHandler;
|
||||||
import com.plotsquared.core.util.WorldUtil;
|
import com.plotsquared.core.util.WorldUtil;
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schematic Handler.
|
* Schematic Handler.
|
||||||
*/
|
*/
|
||||||
@Singleton public class BukkitSchematicHandler extends SchematicHandler {
|
@Singleton
|
||||||
|
public class BukkitSchematicHandler extends SchematicHandler {
|
||||||
|
|
||||||
@Inject public BukkitSchematicHandler(@Nonnull final WorldUtil worldUtil, @Nonnull ProgressSubscriberFactory subscriberFactory) {
|
@Inject
|
||||||
|
public BukkitSchematicHandler(final @NonNull WorldUtil worldUtil, @NonNull ProgressSubscriberFactory subscriberFactory) {
|
||||||
super(worldUtil, subscriberFactory);
|
super(worldUtil, subscriberFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,4 +49,5 @@ import javax.annotation.Nonnull;
|
|||||||
public boolean restoreTile(QueueCoordinator queue, CompoundTag ct, int x, int y, int 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);
|
return new StateWrapper(ct).restoreTag(queue.getWorld().getName(), x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -66,102 +66,102 @@ public class StateWrapper {
|
|||||||
|
|
||||||
public static String jsonToColourCode(String str) {
|
public static String jsonToColourCode(String str) {
|
||||||
str = str.replace("{\"extra\":", "").replace("],\"text\":\"\"}", "]")
|
str = str.replace("{\"extra\":", "").replace("],\"text\":\"\"}", "]")
|
||||||
.replace("[{\"color\":\"black\",\"text\":\"", "&0")
|
.replace("[{\"color\":\"black\",\"text\":\"", "&0")
|
||||||
.replace("[{\"color\":\"dark_blue\",\"text\":\"", "&1")
|
.replace("[{\"color\":\"dark_blue\",\"text\":\"", "&1")
|
||||||
.replace("[{\"color\":\"dark_green\",\"text\":\"", "&2")
|
.replace("[{\"color\":\"dark_green\",\"text\":\"", "&2")
|
||||||
.replace("[{\"color\":\"dark_aqua\",\"text\":\"", "&3")
|
.replace("[{\"color\":\"dark_aqua\",\"text\":\"", "&3")
|
||||||
.replace("[{\"color\":\"dark_red\",\"text\":\"", "&4")
|
.replace("[{\"color\":\"dark_red\",\"text\":\"", "&4")
|
||||||
.replace("[{\"color\":\"dark_purple\",\"text\":\"", "&5")
|
.replace("[{\"color\":\"dark_purple\",\"text\":\"", "&5")
|
||||||
.replace("[{\"color\":\"gold\",\"text\":\"", "&6")
|
.replace("[{\"color\":\"gold\",\"text\":\"", "&6")
|
||||||
.replace("[{\"color\":\"gray\",\"text\":\"", "&7")
|
.replace("[{\"color\":\"gray\",\"text\":\"", "&7")
|
||||||
.replace("[{\"color\":\"dark_gray\",\"text\":\"", "&8")
|
.replace("[{\"color\":\"dark_gray\",\"text\":\"", "&8")
|
||||||
.replace("[{\"color\":\"blue\",\"text\":\"", "&9")
|
.replace("[{\"color\":\"blue\",\"text\":\"", "&9")
|
||||||
.replace("[{\"color\":\"green\",\"text\":\"", "&a")
|
.replace("[{\"color\":\"green\",\"text\":\"", "&a")
|
||||||
.replace("[{\"color\":\"aqua\",\"text\":\"", "&b")
|
.replace("[{\"color\":\"aqua\",\"text\":\"", "&b")
|
||||||
.replace("[{\"color\":\"red\",\"text\":\"", "&c")
|
.replace("[{\"color\":\"red\",\"text\":\"", "&c")
|
||||||
.replace("[{\"color\":\"light_purple\",\"text\":\"", "&d")
|
.replace("[{\"color\":\"light_purple\",\"text\":\"", "&d")
|
||||||
.replace("[{\"color\":\"yellow\",\"text\":\"", "&e")
|
.replace("[{\"color\":\"yellow\",\"text\":\"", "&e")
|
||||||
.replace("[{\"color\":\"white\",\"text\":\"", "&f")
|
.replace("[{\"color\":\"white\",\"text\":\"", "&f")
|
||||||
.replace("[{\"obfuscated\":true,\"text\":\"", "&k")
|
.replace("[{\"obfuscated\":true,\"text\":\"", "&k")
|
||||||
.replace("[{\"bold\":true,\"text\":\"", "&l")
|
.replace("[{\"bold\":true,\"text\":\"", "&l")
|
||||||
.replace("[{\"strikethrough\":true,\"text\":\"", "&m")
|
.replace("[{\"strikethrough\":true,\"text\":\"", "&m")
|
||||||
.replace("[{\"underlined\":true,\"text\":\"", "&n")
|
.replace("[{\"underlined\":true,\"text\":\"", "&n")
|
||||||
.replace("[{\"italic\":true,\"text\":\"", "&o").replace("[{\"color\":\"black\",", "&0")
|
.replace("[{\"italic\":true,\"text\":\"", "&o").replace("[{\"color\":\"black\",", "&0")
|
||||||
.replace("[{\"color\":\"dark_blue\",", "&1")
|
.replace("[{\"color\":\"dark_blue\",", "&1")
|
||||||
.replace("[{\"color\":\"dark_green\",", "&2")
|
.replace("[{\"color\":\"dark_green\",", "&2")
|
||||||
.replace("[{\"color\":\"dark_aqua\",", "&3").replace("[{\"color\":\"dark_red\",", "&4")
|
.replace("[{\"color\":\"dark_aqua\",", "&3").replace("[{\"color\":\"dark_red\",", "&4")
|
||||||
.replace("[{\"color\":\"dark_purple\",", "&5").replace("[{\"color\":\"gold\",", "&6")
|
.replace("[{\"color\":\"dark_purple\",", "&5").replace("[{\"color\":\"gold\",", "&6")
|
||||||
.replace("[{\"color\":\"gray\",", "&7").replace("[{\"color\":\"dark_gray\",", "&8")
|
.replace("[{\"color\":\"gray\",", "&7").replace("[{\"color\":\"dark_gray\",", "&8")
|
||||||
.replace("[{\"color\":\"blue\",", "&9").replace("[{\"color\":\"green\",", "&a")
|
.replace("[{\"color\":\"blue\",", "&9").replace("[{\"color\":\"green\",", "&a")
|
||||||
.replace("[{\"color\":\"aqua\",", "&b").replace("[{\"color\":\"red\",", "&c")
|
.replace("[{\"color\":\"aqua\",", "&b").replace("[{\"color\":\"red\",", "&c")
|
||||||
.replace("[{\"color\":\"light_purple\",", "&d").replace("[{\"color\":\"yellow\",", "&e")
|
.replace("[{\"color\":\"light_purple\",", "&d").replace("[{\"color\":\"yellow\",", "&e")
|
||||||
.replace("[{\"color\":\"white\",", "&f").replace("[{\"obfuscated\":true,", "&k")
|
.replace("[{\"color\":\"white\",", "&f").replace("[{\"obfuscated\":true,", "&k")
|
||||||
.replace("[{\"bold\":true,", "&l").replace("[{\"strikethrough\":true,", "&m")
|
.replace("[{\"bold\":true,", "&l").replace("[{\"strikethrough\":true,", "&m")
|
||||||
.replace("[{\"underlined\":true,", "&n").replace("[{\"italic\":true,", "&o")
|
.replace("[{\"underlined\":true,", "&n").replace("[{\"italic\":true,", "&o")
|
||||||
.replace("{\"color\":\"black\",\"text\":\"", "&0")
|
.replace("{\"color\":\"black\",\"text\":\"", "&0")
|
||||||
.replace("{\"color\":\"dark_blue\",\"text\":\"", "&1")
|
.replace("{\"color\":\"dark_blue\",\"text\":\"", "&1")
|
||||||
.replace("{\"color\":\"dark_green\",\"text\":\"", "&2")
|
.replace("{\"color\":\"dark_green\",\"text\":\"", "&2")
|
||||||
.replace("{\"color\":\"dark_aqua\",\"text\":\"", "&3")
|
.replace("{\"color\":\"dark_aqua\",\"text\":\"", "&3")
|
||||||
.replace("{\"color\":\"dark_red\",\"text\":\"", "&4")
|
.replace("{\"color\":\"dark_red\",\"text\":\"", "&4")
|
||||||
.replace("{\"color\":\"dark_purple\",\"text\":\"", "&5")
|
.replace("{\"color\":\"dark_purple\",\"text\":\"", "&5")
|
||||||
.replace("{\"color\":\"gold\",\"text\":\"", "&6")
|
.replace("{\"color\":\"gold\",\"text\":\"", "&6")
|
||||||
.replace("{\"color\":\"gray\",\"text\":\"", "&7")
|
.replace("{\"color\":\"gray\",\"text\":\"", "&7")
|
||||||
.replace("{\"color\":\"dark_gray\",\"text\":\"", "&8")
|
.replace("{\"color\":\"dark_gray\",\"text\":\"", "&8")
|
||||||
.replace("{\"color\":\"blue\",\"text\":\"", "&9")
|
.replace("{\"color\":\"blue\",\"text\":\"", "&9")
|
||||||
.replace("{\"color\":\"green\",\"text\":\"", "&a")
|
.replace("{\"color\":\"green\",\"text\":\"", "&a")
|
||||||
.replace("{\"color\":\"aqua\",\"text\":\"", "&b")
|
.replace("{\"color\":\"aqua\",\"text\":\"", "&b")
|
||||||
.replace("{\"color\":\"red\",\"text\":\"", "&c")
|
.replace("{\"color\":\"red\",\"text\":\"", "&c")
|
||||||
.replace("{\"color\":\"light_purple\",\"text\":\"", "&d")
|
.replace("{\"color\":\"light_purple\",\"text\":\"", "&d")
|
||||||
.replace("{\"color\":\"yellow\",\"text\":\"", "&e")
|
.replace("{\"color\":\"yellow\",\"text\":\"", "&e")
|
||||||
.replace("{\"color\":\"white\",\"text\":\"", "&f")
|
.replace("{\"color\":\"white\",\"text\":\"", "&f")
|
||||||
.replace("{\"obfuscated\":true,\"text\":\"", "&k")
|
.replace("{\"obfuscated\":true,\"text\":\"", "&k")
|
||||||
.replace("{\"bold\":true,\"text\":\"", "&l")
|
.replace("{\"bold\":true,\"text\":\"", "&l")
|
||||||
.replace("{\"strikethrough\":true,\"text\":\"", "&m")
|
.replace("{\"strikethrough\":true,\"text\":\"", "&m")
|
||||||
.replace("{\"underlined\":true,\"text\":\"", "&n")
|
.replace("{\"underlined\":true,\"text\":\"", "&n")
|
||||||
.replace("{\"italic\":true,\"text\":\"", "&o").replace("{\"color\":\"black\",", "&0")
|
.replace("{\"italic\":true,\"text\":\"", "&o").replace("{\"color\":\"black\",", "&0")
|
||||||
.replace("{\"color\":\"dark_blue\",", "&1").replace("{\"color\":\"dark_green\",", "&2")
|
.replace("{\"color\":\"dark_blue\",", "&1").replace("{\"color\":\"dark_green\",", "&2")
|
||||||
.replace("{\"color\":\"dark_aqua\",", "&3").replace("{\"color\":\"dark_red\",", "&4")
|
.replace("{\"color\":\"dark_aqua\",", "&3").replace("{\"color\":\"dark_red\",", "&4")
|
||||||
.replace("{\"color\":\"dark_purple\",", "&5").replace("{\"color\":\"gold\",", "&6")
|
.replace("{\"color\":\"dark_purple\",", "&5").replace("{\"color\":\"gold\",", "&6")
|
||||||
.replace("{\"color\":\"gray\",", "&7").replace("{\"color\":\"dark_gray\",", "&8")
|
.replace("{\"color\":\"gray\",", "&7").replace("{\"color\":\"dark_gray\",", "&8")
|
||||||
.replace("{\"color\":\"blue\",", "&9").replace("{\"color\":\"green\",", "&a")
|
.replace("{\"color\":\"blue\",", "&9").replace("{\"color\":\"green\",", "&a")
|
||||||
.replace("{\"color\":\"aqua\",", "&b").replace("{\"color\":\"red\",", "&c")
|
.replace("{\"color\":\"aqua\",", "&b").replace("{\"color\":\"red\",", "&c")
|
||||||
.replace("{\"color\":\"light_purple\",", "&d").replace("{\"color\":\"yellow\",", "&e")
|
.replace("{\"color\":\"light_purple\",", "&d").replace("{\"color\":\"yellow\",", "&e")
|
||||||
.replace("{\"color\":\"white\",", "&f").replace("{\"obfuscated\":true,", "&k")
|
.replace("{\"color\":\"white\",", "&f").replace("{\"obfuscated\":true,", "&k")
|
||||||
.replace("{\"bold\":true,", "&l").replace("{\"strikethrough\":true,", "&m")
|
.replace("{\"bold\":true,", "&l").replace("{\"strikethrough\":true,", "&m")
|
||||||
.replace("{\"underlined\":true,", "&n").replace("{\"italic\":true,", "&o")
|
.replace("{\"underlined\":true,", "&n").replace("{\"italic\":true,", "&o")
|
||||||
.replace("\"color\":\"black\",\"text\":\"", "&0")
|
.replace("\"color\":\"black\",\"text\":\"", "&0")
|
||||||
.replace("\"color\":\"dark_blue\",\"text\":\"", "&1")
|
.replace("\"color\":\"dark_blue\",\"text\":\"", "&1")
|
||||||
.replace("\"color\":\"dark_green\",\"text\":\"", "&2")
|
.replace("\"color\":\"dark_green\",\"text\":\"", "&2")
|
||||||
.replace("\"color\":\"dark_aqua\",\"text\":\"", "&3")
|
.replace("\"color\":\"dark_aqua\",\"text\":\"", "&3")
|
||||||
.replace("\"color\":\"dark_red\",\"text\":\"", "&4")
|
.replace("\"color\":\"dark_red\",\"text\":\"", "&4")
|
||||||
.replace("\"color\":\"dark_purple\",\"text\":\"", "&5")
|
.replace("\"color\":\"dark_purple\",\"text\":\"", "&5")
|
||||||
.replace("\"color\":\"gold\",\"text\":\"", "&6")
|
.replace("\"color\":\"gold\",\"text\":\"", "&6")
|
||||||
.replace("\"color\":\"gray\",\"text\":\"", "&7")
|
.replace("\"color\":\"gray\",\"text\":\"", "&7")
|
||||||
.replace("\"color\":\"dark_gray\",\"text\":\"", "&8")
|
.replace("\"color\":\"dark_gray\",\"text\":\"", "&8")
|
||||||
.replace("\"color\":\"blue\",\"text\":\"", "&9")
|
.replace("\"color\":\"blue\",\"text\":\"", "&9")
|
||||||
.replace("\"color\":\"green\",\"text\":\"", "&a")
|
.replace("\"color\":\"green\",\"text\":\"", "&a")
|
||||||
.replace("\"color\":\"aqua\",\"text\":\"", "&b")
|
.replace("\"color\":\"aqua\",\"text\":\"", "&b")
|
||||||
.replace("\"color\":\"red\",\"text\":\"", "&c")
|
.replace("\"color\":\"red\",\"text\":\"", "&c")
|
||||||
.replace("\"color\":\"light_purple\",\"text\":\"", "&d")
|
.replace("\"color\":\"light_purple\",\"text\":\"", "&d")
|
||||||
.replace("\"color\":\"yellow\",\"text\":\"", "&e")
|
.replace("\"color\":\"yellow\",\"text\":\"", "&e")
|
||||||
.replace("\"color\":\"white\",\"text\":\"", "&f")
|
.replace("\"color\":\"white\",\"text\":\"", "&f")
|
||||||
.replace("\"obfuscated\":true,\"text\":\"", "&k")
|
.replace("\"obfuscated\":true,\"text\":\"", "&k")
|
||||||
.replace("\"bold\":true,\"text\":\"", "&l")
|
.replace("\"bold\":true,\"text\":\"", "&l")
|
||||||
.replace("\"strikethrough\":true,\"text\":\"", "&m")
|
.replace("\"strikethrough\":true,\"text\":\"", "&m")
|
||||||
.replace("\"underlined\":true,\"text\":\"", "&n")
|
.replace("\"underlined\":true,\"text\":\"", "&n")
|
||||||
.replace("\"italic\":true,\"text\":\"", "&o").replace("\"color\":\"black\",", "&0")
|
.replace("\"italic\":true,\"text\":\"", "&o").replace("\"color\":\"black\",", "&0")
|
||||||
.replace("\"color\":\"dark_blue\",", "&1").replace("\"color\":\"dark_green\",", "&2")
|
.replace("\"color\":\"dark_blue\",", "&1").replace("\"color\":\"dark_green\",", "&2")
|
||||||
.replace("\"color\":\"dark_aqua\",", "&3").replace("\"color\":\"dark_red\",", "&4")
|
.replace("\"color\":\"dark_aqua\",", "&3").replace("\"color\":\"dark_red\",", "&4")
|
||||||
.replace("\"color\":\"dark_purple\",", "&5").replace("\"color\":\"gold\",", "&6")
|
.replace("\"color\":\"dark_purple\",", "&5").replace("\"color\":\"gold\",", "&6")
|
||||||
.replace("\"color\":\"gray\",", "&7").replace("\"color\":\"dark_gray\",", "&8")
|
.replace("\"color\":\"gray\",", "&7").replace("\"color\":\"dark_gray\",", "&8")
|
||||||
.replace("\"color\":\"blue\",", "&9").replace("\"color\":\"green\",", "&a")
|
.replace("\"color\":\"blue\",", "&9").replace("\"color\":\"green\",", "&a")
|
||||||
.replace("\"color\":\"aqua\",", "&b").replace("\"color\":\"red\",", "&c")
|
.replace("\"color\":\"aqua\",", "&b").replace("\"color\":\"red\",", "&c")
|
||||||
.replace("\"color\":\"light_purple\",", "&d").replace("\"color\":\"yellow\",", "&e")
|
.replace("\"color\":\"light_purple\",", "&d").replace("\"color\":\"yellow\",", "&e")
|
||||||
.replace("\"color\":\"white\",", "&f").replace("\"obfuscated\":true,", "&k")
|
.replace("\"color\":\"white\",", "&f").replace("\"obfuscated\":true,", "&k")
|
||||||
.replace("\"bold\":true,", "&l").replace("\"strikethrough\":true,", "&m")
|
.replace("\"bold\":true,", "&l").replace("\"strikethrough\":true,", "&m")
|
||||||
.replace("\"underlined\":true,", "&n").replace("\"italic\":true,", "&o")
|
.replace("\"underlined\":true,", "&n").replace("\"italic\":true,", "&o")
|
||||||
.replace("[{\"text\":\"", "&0").replace("{\"text\":\"", "&0").replace("\"},", "")
|
.replace("[{\"text\":\"", "&0").replace("{\"text\":\"", "&0").replace("\"},", "")
|
||||||
.replace("\"}]", "").replace("\"}", "");
|
.replace("\"}]", "").replace("\"}", "");
|
||||||
str = ChatColor.translateAlternateColorCodes('&', str);
|
str = ChatColor.translateAlternateColorCodes('&', str);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
@ -37,11 +37,14 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
public class BukkitChunkManager extends ChunkManager {
|
public class BukkitChunkManager extends ChunkManager {
|
||||||
|
|
||||||
public static boolean isIn(CuboidRegion region, int x, int z) {
|
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
|
return x >= region.getMinimumPoint().getX() && x <= region.getMaximumPoint().getX() && z >= region
|
||||||
.getMaximumPoint().getZ();
|
.getMinimumPoint()
|
||||||
|
.getZ() && z <= region
|
||||||
|
.getMaximumPoint().getZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public CompletableFuture<?> loadChunk(String world, BlockVector2 chunkLoc, boolean force) {
|
@Override
|
||||||
|
public CompletableFuture<?> loadChunk(String world, BlockVector2 chunkLoc, boolean force) {
|
||||||
return PaperLib.getChunkAtAsync(BukkitUtil.getWorld(world), chunkLoc.getX(), chunkLoc.getZ(), force);
|
return PaperLib.getChunkAtAsync(BukkitUtil.getWorld(world), chunkLoc.getX(), chunkLoc.getZ(), force);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,11 +38,17 @@ import org.bukkit.OfflinePlayer;
|
|||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
@Singleton public class BukkitEconHandler extends EconHandler {
|
@Singleton
|
||||||
|
public class BukkitEconHandler extends EconHandler {
|
||||||
|
|
||||||
private Economy econ;
|
private Economy econ;
|
||||||
|
|
||||||
@Override public boolean init() {
|
private static OfflinePlayer getBukkitOfflinePlayer(PlotPlayer<?> plotPlayer) {
|
||||||
|
return ((BukkitPlayer) plotPlayer).player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean init() {
|
||||||
if (this.econ == null) {
|
if (this.econ == null) {
|
||||||
setupEconomy();
|
setupEconomy();
|
||||||
}
|
}
|
||||||
@ -54,13 +60,14 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RegisteredServiceProvider<Economy> economyProvider =
|
RegisteredServiceProvider<Economy> economyProvider =
|
||||||
Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||||
if (economyProvider != null) {
|
if (economyProvider != null) {
|
||||||
this.econ = economyProvider.getProvider();
|
this.econ = economyProvider.getProvider();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public double getMoney(PlotPlayer<?> player) {
|
@Override
|
||||||
|
public double getMoney(PlotPlayer<?> player) {
|
||||||
double bal = super.getMoney(player);
|
double bal = super.getMoney(player);
|
||||||
if (Double.isNaN(bal)) {
|
if (Double.isNaN(bal)) {
|
||||||
return this.econ.getBalance(getBukkitOfflinePlayer(player));
|
return this.econ.getBalance(getBukkitOfflinePlayer(player));
|
||||||
@ -68,15 +75,18 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
return bal;
|
return bal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void withdrawMoney(PlotPlayer<?> player, double amount) {
|
@Override
|
||||||
|
public void withdrawMoney(PlotPlayer<?> player, double amount) {
|
||||||
this.econ.withdrawPlayer(getBukkitOfflinePlayer(player), amount);
|
this.econ.withdrawPlayer(getBukkitOfflinePlayer(player), amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void depositMoney(PlotPlayer<?> player, double amount) {
|
@Override
|
||||||
|
public void depositMoney(PlotPlayer<?> player, double amount) {
|
||||||
this.econ.depositPlayer(getBukkitOfflinePlayer(player), amount);
|
this.econ.depositPlayer(getBukkitOfflinePlayer(player), amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void depositMoney(OfflinePlotPlayer player, double amount) {
|
@Override
|
||||||
|
public void depositMoney(OfflinePlotPlayer player, double amount) {
|
||||||
this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
|
this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,12 +105,9 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public double getBalance(PlotPlayer<?> player) {
|
@Override
|
||||||
|
public double getBalance(PlotPlayer<?> player) {
|
||||||
return this.econ.getBalance(getBukkitOfflinePlayer(player));
|
return this.econ.getBalance(getBukkitOfflinePlayer(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static OfflinePlayer getBukkitOfflinePlayer(PlotPlayer<?> plotPlayer) {
|
|
||||||
return ((BukkitPlayer) plotPlayer).player;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ import java.util.Objects;
|
|||||||
public class BukkitEntityUtil {
|
public class BukkitEntityUtil {
|
||||||
|
|
||||||
public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE =
|
public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE =
|
||||||
new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake");
|
new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake");
|
||||||
|
|
||||||
public static boolean entityDamage(Entity damager, Entity victim) {
|
public static boolean entityDamage(Entity damager, Entity victim) {
|
||||||
return entityDamage(damager, victim, null);
|
return entityDamage(damager, victim, null);
|
||||||
@ -152,7 +152,7 @@ public class BukkitEntityUtil {
|
|||||||
} else { // shooter is not player
|
} else { // shooter is not player
|
||||||
if (shooter instanceof BlockProjectileSource) {
|
if (shooter instanceof BlockProjectileSource) {
|
||||||
Location sLoc = BukkitUtil
|
Location sLoc = BukkitUtil
|
||||||
.adapt(((BlockProjectileSource) shooter).getBlock().getLocation());
|
.adapt(((BlockProjectileSource) shooter).getBlock().getLocation());
|
||||||
dplot = dArea.getPlot(sLoc);
|
dplot = dArea.getPlot(sLoc);
|
||||||
}
|
}
|
||||||
player = null;
|
player = null;
|
||||||
@ -174,13 +174,13 @@ public class BukkitEntityUtil {
|
|||||||
|
|
||||||
if (EntityCategories.HANGING.contains(entityType)) { // hanging
|
if (EntityCategories.HANGING.contains(entityType)) { // hanging
|
||||||
if (plot != null && (plot.getFlag(HangingBreakFlag.class) || plot
|
if (plot != null && (plot.getFlag(HangingBreakFlag.class) || plot
|
||||||
.isAdded(plotPlayer.getUUID()))) {
|
.isAdded(plotPlayer.getUUID()))) {
|
||||||
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
||||||
if (!Permissions
|
if (!Permissions
|
||||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER))
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -189,79 +189,79 @@ public class BukkitEntityUtil {
|
|||||||
}
|
}
|
||||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY + "." + stub)) {
|
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY + "." + stub)) {
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", Permission.PERMISSION_ADMIN_DESTROY + "." + stub)
|
Template.of("node", Permission.PERMISSION_ADMIN_DESTROY + "." + stub)
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (victim.getType() == EntityType.ARMOR_STAND) {
|
} else if (victim.getType() == EntityType.ARMOR_STAND) {
|
||||||
if (plot != null && (plot.getFlag(MiscBreakFlag.class) || plot
|
if (plot != null && (plot.getFlag(MiscBreakFlag.class) || plot
|
||||||
.isAdded(plotPlayer.getUUID()))) {
|
.isAdded(plotPlayer.getUUID()))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY + "." + stub)) {
|
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY + "." + stub)) {
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", Permission.PERMISSION_ADMIN_DESTROY + "." + stub)
|
Template.of("node", Permission.PERMISSION_ADMIN_DESTROY + "." + stub)
|
||||||
);
|
);
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
plot.debug(player.getName()
|
plot.debug(player.getName()
|
||||||
+ " could not break armor stand because misc-break = false");
|
+ " could not break armor stand because misc-break = false");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (EntityCategories.HOSTILE.contains(entityType)) {
|
} else if (EntityCategories.HOSTILE.contains(entityType)) {
|
||||||
if (isPlot) {
|
if (isPlot) {
|
||||||
if (plot.getFlag(HostileAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
if (plot.getFlag(HostileAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
||||||
.isAdded(plotPlayer.getUUID())) {
|
.isAdded(plotPlayer.getUUID())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (roadFlags && (area.getRoadFlag(HostileAttackFlag.class) || area
|
} else if (roadFlags && (area.getRoadFlag(HostileAttackFlag.class) || area
|
||||||
.getFlag(PveFlag.class))) {
|
.getFlag(PveFlag.class))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVE + "." + stub)) {
|
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVE + "." + stub)) {
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", Permission.PERMISSION_ADMIN_PVE + "." + stub)
|
Template.of("node", Permission.PERMISSION_ADMIN_PVE + "." + stub)
|
||||||
);
|
);
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
plot.debug(player.getName() + " could not attack " + entityType
|
plot.debug(player.getName() + " could not attack " + entityType
|
||||||
+ " because pve = false OR hostile-attack = false");
|
+ " because pve = false OR hostile-attack = false");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (EntityCategories.TAMEABLE.contains(entityType)) { // victim is tameable
|
} else if (EntityCategories.TAMEABLE.contains(entityType)) { // victim is tameable
|
||||||
if (isPlot) {
|
if (isPlot) {
|
||||||
if (plot.getFlag(TamedAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
if (plot.getFlag(TamedAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
||||||
.isAdded(plotPlayer.getUUID())) {
|
.isAdded(plotPlayer.getUUID())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (roadFlags && (area.getRoadFlag(TamedAttackFlag.class) || area
|
} else if (roadFlags && (area.getRoadFlag(TamedAttackFlag.class) || area
|
||||||
.getFlag(PveFlag.class))) {
|
.getFlag(PveFlag.class))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVE + "." + stub)) {
|
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVE + "." + stub)) {
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", Permission.PERMISSION_ADMIN_PVE + "." + stub)
|
Template.of("node", Permission.PERMISSION_ADMIN_PVE + "." + stub)
|
||||||
);
|
);
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
plot.debug(player.getName() + " could not attack " + entityType
|
plot.debug(player.getName() + " could not attack " + entityType
|
||||||
+ " because pve = false OR tamed-attack = false");
|
+ " because pve = false OR tamed-attack = false");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (EntityCategories.PLAYER.contains(entityType)) {
|
} else if (EntityCategories.PLAYER.contains(entityType)) {
|
||||||
if (isPlot) {
|
if (isPlot) {
|
||||||
if (!plot.getFlag(PvpFlag.class) && !Permissions
|
if (!plot.getFlag(PvpFlag.class) && !Permissions
|
||||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVP + "." + stub)) {
|
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVP + "." + stub)) {
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", Permission.PERMISSION_ADMIN_PVP + "." + stub)
|
Template.of("node", Permission.PERMISSION_ADMIN_PVP + "." + stub)
|
||||||
);
|
);
|
||||||
plot.debug(player.getName() + " could not attack " + entityType
|
plot.debug(player.getName() + " could not attack " + entityType
|
||||||
+ " because pve = false");
|
+ " because pve = false");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
@ -271,31 +271,31 @@ public class BukkitEntityUtil {
|
|||||||
}
|
}
|
||||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVP + "." + stub)) {
|
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVP + "." + stub)) {
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", Permission.PERMISSION_ADMIN_PVP + "." + stub)
|
Template.of("node", Permission.PERMISSION_ADMIN_PVP + "." + stub)
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (EntityCategories.ANIMAL.contains(entityType)) { // victim is animal
|
} else if (EntityCategories.ANIMAL.contains(entityType)) { // victim is animal
|
||||||
if (isPlot) {
|
if (isPlot) {
|
||||||
if (plot.getFlag(AnimalAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
if (plot.getFlag(AnimalAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
||||||
.isAdded(plotPlayer.getUUID())) {
|
.isAdded(plotPlayer.getUUID())) {
|
||||||
plot.debug(player.getName() + " could not attack " + entityType
|
plot.debug(player.getName() + " could not attack " + entityType
|
||||||
+ " because pve = false OR animal-attack = false");
|
+ " because pve = false OR animal-attack = false");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (roadFlags && (area.getRoadFlag(AnimalAttackFlag.class) || area
|
} else if (roadFlags && (area.getRoadFlag(AnimalAttackFlag.class) || area
|
||||||
.getFlag(PveFlag.class))) {
|
.getFlag(PveFlag.class))) {
|
||||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVE + "." + stub)) {
|
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVE + "." + stub)) {
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", Permission.PERMISSION_ADMIN_PVE + "." + stub)
|
Template.of("node", Permission.PERMISSION_ADMIN_PVE + "." + stub)
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (EntityCategories.VEHICLE
|
} else if (EntityCategories.VEHICLE
|
||||||
.contains(entityType)) { // Vehicles are managed in vehicle destroy event
|
.contains(entityType)) { // Vehicles are managed in vehicle destroy event
|
||||||
return true;
|
return true;
|
||||||
} else { // victim is something else
|
} else { // victim is something else
|
||||||
if (isPlot) {
|
if (isPlot) {
|
||||||
@ -307,25 +307,25 @@ public class BukkitEntityUtil {
|
|||||||
}
|
}
|
||||||
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVE + "." + stub)) {
|
if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PVE + "." + stub)) {
|
||||||
plotPlayer.sendMessage(
|
plotPlayer.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission_event"),
|
TranslatableCaption.of("permission.no_permission_event"),
|
||||||
Template.of("node", Permission.PERMISSION_ADMIN_PVE + "." + stub)
|
Template.of("node", Permission.PERMISSION_ADMIN_PVE + "." + stub)
|
||||||
);
|
);
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
plot.debug(player.getName() + " could not attack " + entityType
|
plot.debug(player.getName() + " could not attack " + entityType
|
||||||
+ " because pve = false");
|
+ " because pve = false");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (dplot != null && (!dplot.equals(vplot) || Objects
|
} else if (dplot != null && (!dplot.equals(vplot) || Objects
|
||||||
.equals(dplot.getOwnerAbs(), vplot.getOwnerAbs()))) {
|
.equals(dplot.getOwnerAbs(), vplot.getOwnerAbs()))) {
|
||||||
return vplot != null && vplot.getFlag(PveFlag.class);
|
return vplot != null && vplot.getFlag(PveFlag.class);
|
||||||
}
|
}
|
||||||
//disable the firework damage. too much of a headache to support at the moment.
|
//disable the firework damage. too much of a headache to support at the moment.
|
||||||
if (vplot != null) {
|
if (vplot != null) {
|
||||||
if (EntityDamageEvent.DamageCause.ENTITY_EXPLOSION == cause
|
if (EntityDamageEvent.DamageCause.ENTITY_EXPLOSION == cause
|
||||||
&& damager.getType() == EntityType.FIREWORK) {
|
&& damager.getType() == EntityType.FIREWORK) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -333,46 +333,50 @@ public class BukkitEntityUtil {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow
|
return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow
|
||||||
&& !(victim instanceof Creature)));
|
&& !(victim instanceof Creature)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkEntity(Entity entity, Plot plot) {
|
public static boolean checkEntity(Entity entity, Plot plot) {
|
||||||
if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot.getArea()
|
if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot.getArea()
|
||||||
.getFlagContainer().getFlagMap().isEmpty()) {
|
.getFlagContainer().getFlagMap().isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final com.sk89q.worldedit.world.entity.EntityType entityType =
|
final com.sk89q.worldedit.world.entity.EntityType entityType =
|
||||||
BukkitAdapter.adapt(entity.getType());
|
BukkitAdapter.adapt(entity.getType());
|
||||||
|
|
||||||
if (EntityCategories.PLAYER.contains(entityType)) {
|
if (EntityCategories.PLAYER.contains(entityType)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EntityCategories.PROJECTILE.contains(entityType) || EntityCategories.OTHER
|
if (EntityCategories.PROJECTILE.contains(entityType) || EntityCategories.OTHER
|
||||||
.contains(entityType) || EntityCategories.HANGING.contains(entityType)) {
|
.contains(entityType) || EntityCategories.HANGING.contains(entityType)) {
|
||||||
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED,
|
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED,
|
||||||
MiscCapFlag.MISC_CAP_UNLIMITED);
|
MiscCapFlag.MISC_CAP_UNLIMITED
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Has to go go before vehicle as horses are both
|
// Has to go go before vehicle as horses are both
|
||||||
// animals and vehicles
|
// animals and vehicles
|
||||||
if (EntityCategories.ANIMAL.contains(entityType) || EntityCategories.VILLAGER
|
if (EntityCategories.ANIMAL.contains(entityType) || EntityCategories.VILLAGER
|
||||||
.contains(entityType) || EntityCategories.TAMEABLE.contains(entityType)) {
|
.contains(entityType) || EntityCategories.TAMEABLE.contains(entityType)) {
|
||||||
return EntityUtil
|
return EntityUtil
|
||||||
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
|
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
|
||||||
AnimalCapFlag.ANIMAL_CAP_UNLIMITED);
|
AnimalCapFlag.ANIMAL_CAP_UNLIMITED
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EntityCategories.HOSTILE.contains(entityType)) {
|
if (EntityCategories.HOSTILE.contains(entityType)) {
|
||||||
return EntityUtil
|
return EntityUtil
|
||||||
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
|
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
|
||||||
HostileCapFlag.HOSTILE_CAP_UNLIMITED);
|
HostileCapFlag.HOSTILE_CAP_UNLIMITED
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EntityCategories.VEHICLE.contains(entityType)) {
|
if (EntityCategories.VEHICLE.contains(entityType)) {
|
||||||
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED,
|
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED,
|
||||||
VehicleCapFlag.VEHICLE_CAP_UNLIMITED);
|
VehicleCapFlag.VEHICLE_CAP_UNLIMITED
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED);
|
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED);
|
||||||
|
@ -47,39 +47,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
@Singleton public class BukkitInventoryUtil extends InventoryUtil {
|
@Singleton
|
||||||
|
public class BukkitInventoryUtil extends InventoryUtil {
|
||||||
@Override public void open(PlotInventory inv) {
|
|
||||||
BukkitPlayer bp = (BukkitPlayer) inv.getPlayer();
|
|
||||||
Inventory inventory = Bukkit.createInventory(null, inv.getLines() * 9,
|
|
||||||
ChatColor.translateAlternateColorCodes('&', inv.getTitle()));
|
|
||||||
PlotItemStack[] items = inv.getItems();
|
|
||||||
for (int i = 0; i < inv.getLines() * 9; i++) {
|
|
||||||
PlotItemStack item = items[i];
|
|
||||||
if (item != null) {
|
|
||||||
inventory.setItem(i, getItem(item));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bp.player.openInventory(inventory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void close(PlotInventory inv) {
|
|
||||||
if (!inv.isOpen()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
BukkitPlayer bp = (BukkitPlayer) inv.getPlayer();
|
|
||||||
bp.player.closeInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void setItem(PlotInventory inv, int index, PlotItemStack item) {
|
|
||||||
BukkitPlayer bp = (BukkitPlayer) inv.getPlayer();
|
|
||||||
InventoryView opened = bp.player.getOpenInventory();
|
|
||||||
if (!inv.isOpen()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
opened.setItem(index, getItem(item));
|
|
||||||
bp.player.updateInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ItemStack getItem(PlotItemStack item) {
|
private static ItemStack getItem(PlotItemStack item) {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
@ -108,6 +77,42 @@ import java.util.stream.IntStream;
|
|||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void open(PlotInventory inv) {
|
||||||
|
BukkitPlayer bp = (BukkitPlayer) inv.getPlayer();
|
||||||
|
Inventory inventory = Bukkit.createInventory(null, inv.getLines() * 9,
|
||||||
|
ChatColor.translateAlternateColorCodes('&', inv.getTitle())
|
||||||
|
);
|
||||||
|
PlotItemStack[] items = inv.getItems();
|
||||||
|
for (int i = 0; i < inv.getLines() * 9; i++) {
|
||||||
|
PlotItemStack item = items[i];
|
||||||
|
if (item != null) {
|
||||||
|
inventory.setItem(i, getItem(item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bp.player.openInventory(inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close(PlotInventory inv) {
|
||||||
|
if (!inv.isOpen()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BukkitPlayer bp = (BukkitPlayer) inv.getPlayer();
|
||||||
|
bp.player.closeInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setItem(PlotInventory inv, int index, PlotItemStack item) {
|
||||||
|
BukkitPlayer bp = (BukkitPlayer) inv.getPlayer();
|
||||||
|
InventoryView opened = bp.player.getOpenInventory();
|
||||||
|
if (!inv.isOpen()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
opened.setItem(index, getItem(item));
|
||||||
|
bp.player.updateInventory();
|
||||||
|
}
|
||||||
|
|
||||||
public PlotItemStack getItem(ItemStack item) {
|
public PlotItemStack getItem(ItemStack item) {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -132,14 +137,16 @@ import java.util.stream.IntStream;
|
|||||||
return new PlotItemStack(id.name(), amount, name, lore);
|
return new PlotItemStack(id.name(), amount, name, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public PlotItemStack[] getItems(PlotPlayer player) {
|
@Override
|
||||||
|
public PlotItemStack[] getItems(PlotPlayer player) {
|
||||||
BukkitPlayer bp = (BukkitPlayer) player;
|
BukkitPlayer bp = (BukkitPlayer) player;
|
||||||
PlayerInventory inv = bp.player.getInventory();
|
PlayerInventory inv = bp.player.getInventory();
|
||||||
return IntStream.range(0, 36).mapToObj(i -> getItem(inv.getItem(i)))
|
return IntStream.range(0, 36).mapToObj(i -> getItem(inv.getItem(i)))
|
||||||
.toArray(PlotItemStack[]::new);
|
.toArray(PlotItemStack[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean isOpen(PlotInventory plotInventory) {
|
@Override
|
||||||
|
public boolean isOpen(PlotInventory plotInventory) {
|
||||||
if (!plotInventory.isOpen()) {
|
if (!plotInventory.isOpen()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -152,4 +159,5 @@ import java.util.stream.IntStream;
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -55,9 +55,9 @@ import org.bukkit.Chunk;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -75,18 +75,27 @@ public class BukkitRegionManager extends RegionManager {
|
|||||||
|
|
||||||
private final GlobalBlockQueue blockQueue;
|
private final GlobalBlockQueue blockQueue;
|
||||||
|
|
||||||
@Inject public BukkitRegionManager(@Nonnull WorldUtil worldUtil, @Nonnull GlobalBlockQueue blockQueue, @Nonnull
|
@Inject
|
||||||
ProgressSubscriberFactory subscriberFactory) {
|
public BukkitRegionManager(
|
||||||
|
@NonNull WorldUtil worldUtil, @NonNull GlobalBlockQueue blockQueue, @NonNull
|
||||||
|
ProgressSubscriberFactory subscriberFactory
|
||||||
|
) {
|
||||||
super(worldUtil, blockQueue, subscriberFactory);
|
super(worldUtil, blockQueue, subscriberFactory);
|
||||||
this.blockQueue = blockQueue;
|
this.blockQueue = blockQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handleClear(@Nonnull Plot plot, @Nullable Runnable whenDone, @Nonnull PlotManager manager, @Nullable PlotPlayer<?> player) {
|
public boolean handleClear(
|
||||||
|
@NonNull Plot plot,
|
||||||
|
@Nullable Runnable whenDone,
|
||||||
|
@NonNull PlotManager manager,
|
||||||
|
@Nullable PlotPlayer<?> player
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public int[] countEntities(@Nonnull Plot plot) {
|
@Override
|
||||||
|
public int[] countEntities(@NonNull Plot plot) {
|
||||||
int[] existing = (int[]) plot.getMeta("EntityCount");
|
int[] existing = (int[]) plot.getMeta("EntityCount");
|
||||||
if (existing != null && (System.currentTimeMillis() - (long) plot.getMeta("EntityCountTime") < 1000)) {
|
if (existing != null && (System.currentTimeMillis() - (long) plot.getMeta("EntityCountTime") < 1000)) {
|
||||||
return existing;
|
return existing;
|
||||||
@ -160,10 +169,13 @@ public class BukkitRegionManager extends RegionManager {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean regenerateRegion(@Nonnull final Location pos1,
|
@Override
|
||||||
@Nonnull final Location pos2,
|
public boolean regenerateRegion(
|
||||||
final boolean ignoreAugment,
|
final @NonNull Location pos1,
|
||||||
@Nullable final Runnable whenDone) {
|
final @NonNull Location pos2,
|
||||||
|
final boolean ignoreAugment,
|
||||||
|
final @Nullable Runnable whenDone
|
||||||
|
) {
|
||||||
final BukkitWorld world = new BukkitWorld((World) pos1.getWorld());
|
final BukkitWorld world = new BukkitWorld((World) pos1.getWorld());
|
||||||
|
|
||||||
final int p1x = pos1.getX();
|
final int p1x = pos1.getX();
|
||||||
@ -251,35 +263,39 @@ public class BukkitRegionManager extends RegionManager {
|
|||||||
}
|
}
|
||||||
CuboidRegion currentPlotClear = RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
CuboidRegion currentPlotClear = RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||||
map.saveEntitiesOut(Bukkit.getWorld(world.getName()).getChunkAt(x, z), currentPlotClear);
|
map.saveEntitiesOut(Bukkit.getWorld(world.getName()).getChunkAt(x, z), currentPlotClear);
|
||||||
AugmentedUtils.bypass(ignoreAugment, () -> ChunkManager.setChunkInPlotArea(null, new RunnableVal<ScopedQueueCoordinator>() {
|
AugmentedUtils.bypass(
|
||||||
@Override public void run(ScopedQueueCoordinator value) {
|
ignoreAugment,
|
||||||
Location min = value.getMin();
|
() -> ChunkManager.setChunkInPlotArea(null, new RunnableVal<ScopedQueueCoordinator>() {
|
||||||
int bx = min.getX();
|
@Override
|
||||||
int bz = min.getZ();
|
public void run(ScopedQueueCoordinator value) {
|
||||||
for (int x1 = 0; x1 < 16; x1++) {
|
Location min = value.getMin();
|
||||||
for (int z1 = 0; z1 < 16; z1++) {
|
int bx = min.getX();
|
||||||
PlotLoc plotLoc = new PlotLoc(bx + x1, bz + z1);
|
int bz = min.getZ();
|
||||||
BaseBlock[] ids = map.allBlocks.get(plotLoc);
|
for (int x1 = 0; x1 < 16; x1++) {
|
||||||
if (ids != null) {
|
for (int z1 = 0; z1 < 16; z1++) {
|
||||||
for (int y = 0; y < Math.min(128, ids.length); y++) {
|
PlotLoc plotLoc = new PlotLoc(bx + x1, bz + z1);
|
||||||
BaseBlock id = ids[y];
|
BaseBlock[] ids = map.allBlocks.get(plotLoc);
|
||||||
if (id != null) {
|
if (ids != null) {
|
||||||
value.setBlock(x1, y, z1, id);
|
for (int y = 0; y < Math.min(128, ids.length); y++) {
|
||||||
} else {
|
BaseBlock id = ids[y];
|
||||||
value.setBlock(x1, y, z1, BlockTypes.AIR.getDefaultState());
|
if (id != null) {
|
||||||
}
|
value.setBlock(x1, y, z1, id);
|
||||||
}
|
} else {
|
||||||
for (int y = Math.min(128, ids.length); y < ids.length; y++) {
|
value.setBlock(x1, y, z1, BlockTypes.AIR.getDefaultState());
|
||||||
BaseBlock id = ids[y];
|
}
|
||||||
if (id != null) {
|
}
|
||||||
value.setBlock(x1, y, z1, id);
|
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.getName(), chunk)
|
||||||
}
|
);
|
||||||
}, world.getName(), chunk));
|
|
||||||
//map.restoreBlocks(worldObj, 0, 0);
|
//map.restoreBlocks(worldObj, 0, 0);
|
||||||
map.restoreEntities(Bukkit.getWorld(world.getName()), 0, 0);
|
map.restoreEntities(Bukkit.getWorld(world.getName()), 0, 0);
|
||||||
});
|
});
|
||||||
@ -289,7 +305,8 @@ public class BukkitRegionManager extends RegionManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void clearAllEntities(@Nonnull Location pos1, @Nonnull Location pos2) {
|
@Override
|
||||||
|
public void clearAllEntities(@NonNull Location pos1, @NonNull Location pos2) {
|
||||||
String world = pos1.getWorldName();
|
String world = pos1.getWorldName();
|
||||||
|
|
||||||
final World bukkitWorld = BukkitUtil.getWorld(world);
|
final World bukkitWorld = BukkitUtil.getWorld(world);
|
||||||
@ -317,16 +334,16 @@ public class BukkitRegionManager extends RegionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void count(int[] count, @Nonnull Entity entity) {
|
private void count(int[] count, @NonNull Entity entity) {
|
||||||
final com.sk89q.worldedit.world.entity.EntityType entityType = BukkitAdapter.adapt(entity.getType());
|
final com.sk89q.worldedit.world.entity.EntityType entityType = BukkitAdapter.adapt(entity.getType());
|
||||||
|
|
||||||
if (EntityCategories.PLAYER.contains(entityType)) {
|
if (EntityCategories.PLAYER.contains(entityType)) {
|
||||||
return;
|
return;
|
||||||
} else if (EntityCategories.PROJECTILE.contains(entityType) || EntityCategories.OTHER.contains(entityType) || EntityCategories.HANGING
|
} else if (EntityCategories.PROJECTILE.contains(entityType) || EntityCategories.OTHER.contains(entityType) || EntityCategories.HANGING
|
||||||
.contains(entityType)) {
|
.contains(entityType)) {
|
||||||
count[CAP_MISC]++;
|
count[CAP_MISC]++;
|
||||||
} else if (EntityCategories.ANIMAL.contains(entityType) || EntityCategories.VILLAGER.contains(entityType) || EntityCategories.TAMEABLE
|
} else if (EntityCategories.ANIMAL.contains(entityType) || EntityCategories.VILLAGER.contains(entityType) || EntityCategories.TAMEABLE
|
||||||
.contains(entityType)) {
|
.contains(entityType)) {
|
||||||
count[CAP_MOB]++;
|
count[CAP_MOB]++;
|
||||||
count[CAP_ANIMAL]++;
|
count[CAP_ANIMAL]++;
|
||||||
} else if (EntityCategories.VEHICLE.contains(entityType)) {
|
} else if (EntityCategories.VEHICLE.contains(entityType)) {
|
||||||
@ -337,4 +354,5 @@ public class BukkitRegionManager extends RegionManager {
|
|||||||
}
|
}
|
||||||
count[CAP_ENTITY]++;
|
count[CAP_ENTITY]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -48,29 +48,34 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Singleton public class BukkitSetupUtils extends SetupUtils {
|
@Singleton
|
||||||
|
public class BukkitSetupUtils extends SetupUtils {
|
||||||
|
|
||||||
private final PlotAreaManager plotAreaManager;
|
private final PlotAreaManager plotAreaManager;
|
||||||
private final YamlConfiguration worldConfiguration;
|
private final YamlConfiguration worldConfiguration;
|
||||||
private final File worldFile;
|
private final File worldFile;
|
||||||
|
|
||||||
@Inject public BukkitSetupUtils(@Nonnull final PlotAreaManager plotAreaManager,
|
@Inject
|
||||||
@WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
|
public BukkitSetupUtils(
|
||||||
@WorldFile @Nonnull final File worldFile) {
|
final @NonNull PlotAreaManager plotAreaManager,
|
||||||
|
@WorldConfig final @NonNull YamlConfiguration worldConfiguration,
|
||||||
|
@WorldFile final @NonNull File worldFile
|
||||||
|
) {
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
this.worldConfiguration = worldConfiguration;
|
this.worldConfiguration = worldConfiguration;
|
||||||
this.worldFile = worldFile;
|
this.worldFile = worldFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void updateGenerators() {
|
@Override
|
||||||
|
public void updateGenerators() {
|
||||||
if (!SetupUtils.generators.isEmpty()) {
|
if (!SetupUtils.generators.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -97,7 +102,8 @@ import java.util.Objects;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void unload(String worldName, boolean save) {
|
@Override
|
||||||
|
public void unload(String worldName, boolean save) {
|
||||||
TaskManager.runTask(() -> {
|
TaskManager.runTask(() -> {
|
||||||
World world = Bukkit.getWorld(worldName);
|
World world = Bukkit.getWorld(worldName);
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
@ -120,7 +126,8 @@ import java.util.Objects;
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String setupWorld(PlotAreaBuilder builder) {
|
@Override
|
||||||
|
public String setupWorld(PlotAreaBuilder builder) {
|
||||||
this.updateGenerators();
|
this.updateGenerators();
|
||||||
ConfigurationNode[] steps = builder.settingsNodesWrapper() == null ?
|
ConfigurationNode[] steps = builder.settingsNodesWrapper() == null ?
|
||||||
new ConfigurationNode[0] : builder.settingsNodesWrapper().getSettingsNodes();
|
new ConfigurationNode[0] : builder.settingsNodesWrapper().getSettingsNodes();
|
||||||
@ -233,7 +240,8 @@ import java.util.Objects;
|
|||||||
return builder.worldName();
|
return builder.worldName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String getGenerator(PlotArea plotArea) {
|
@Override
|
||||||
|
public String getGenerator(PlotArea plotArea) {
|
||||||
if (SetupUtils.generators.isEmpty()) {
|
if (SetupUtils.generators.isEmpty()) {
|
||||||
updateGenerators();
|
updateGenerators();
|
||||||
}
|
}
|
||||||
@ -253,4 +261,5 @@ import java.util.Objects;
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -94,12 +94,12 @@ import org.bukkit.entity.Snowman;
|
|||||||
import org.bukkit.entity.Tameable;
|
import org.bukkit.entity.Tameable;
|
||||||
import org.bukkit.entity.Vehicle;
|
import org.bukkit.entity.Vehicle;
|
||||||
import org.bukkit.entity.WaterMob;
|
import org.bukkit.entity.WaterMob;
|
||||||
|
import org.checkerframework.checker.index.qual.NonNegative;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.annotation.Nonnegative;
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -113,12 +113,10 @@ import java.util.stream.Stream;
|
|||||||
@Singleton
|
@Singleton
|
||||||
public class BukkitUtil extends WorldUtil {
|
public class BukkitUtil extends WorldUtil {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitUtil.class.getSimpleName());
|
|
||||||
|
|
||||||
public static final BukkitAudiences BUKKIT_AUDIENCES = BukkitAudiences.create(BukkitPlatform.getPlugin(BukkitPlatform.class));
|
public static final BukkitAudiences BUKKIT_AUDIENCES = BukkitAudiences.create(BukkitPlatform.getPlugin(BukkitPlatform.class));
|
||||||
public static final LegacyComponentSerializer LEGACY_COMPONENT_SERIALIZER = LegacyComponentSerializer.legacySection();
|
public static final LegacyComponentSerializer LEGACY_COMPONENT_SERIALIZER = LegacyComponentSerializer.legacySection();
|
||||||
public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build();
|
public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build();
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitUtil.class.getSimpleName());
|
||||||
private final Collection<BlockType> tileEntityTypes = new HashSet<>();
|
private final Collection<BlockType> tileEntityTypes = new HashSet<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,7 +125,7 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
* @param player Bukkit player
|
* @param player Bukkit player
|
||||||
* @return PlotSquared player
|
* @return PlotSquared player
|
||||||
*/
|
*/
|
||||||
@Nonnull public static BukkitPlayer adapt(@Nonnull final Player player) {
|
public @NonNull static BukkitPlayer adapt(final @NonNull Player player) {
|
||||||
final PlayerManager<?, ?> playerManager = PlotSquared.platform().playerManager();
|
final PlayerManager<?, ?> playerManager = PlotSquared.platform().playerManager();
|
||||||
return ((BukkitPlayerManager) playerManager).getPlayer(player);
|
return ((BukkitPlayerManager) playerManager).getPlayer(player);
|
||||||
}
|
}
|
||||||
@ -139,10 +137,13 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
* @param location Bukkit location
|
* @param location Bukkit location
|
||||||
* @return PlotSquared location
|
* @return PlotSquared location
|
||||||
*/
|
*/
|
||||||
@Nonnull public static Location adapt(@Nonnull final org.bukkit.Location location) {
|
public @NonNull static Location adapt(final org.bukkit.@NonNull Location location) {
|
||||||
return Location
|
return Location
|
||||||
.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()), MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()),
|
.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()),
|
||||||
MathMan.roundInt(location.getZ()));
|
MathMan.roundInt(location.getX()),
|
||||||
|
MathMan.roundInt(location.getY()),
|
||||||
|
MathMan.roundInt(location.getZ())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -152,10 +153,15 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
* @param location Bukkit location
|
* @param location Bukkit location
|
||||||
* @return PlotSquared location
|
* @return PlotSquared location
|
||||||
*/
|
*/
|
||||||
@Nonnull public static Location adaptComplete(@Nonnull final org.bukkit.Location location) {
|
public @NonNull static Location adaptComplete(final org.bukkit.@NonNull Location location) {
|
||||||
return Location
|
return Location
|
||||||
.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()), MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()),
|
.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()),
|
||||||
MathMan.roundInt(location.getZ()), location.getYaw(), location.getPitch());
|
MathMan.roundInt(location.getX()),
|
||||||
|
MathMan.roundInt(location.getY()),
|
||||||
|
MathMan.roundInt(location.getZ()),
|
||||||
|
location.getYaw(),
|
||||||
|
location.getPitch()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -165,8 +171,13 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
* @param location PlotSquared location
|
* @param location PlotSquared location
|
||||||
* @return Bukkit location
|
* @return Bukkit location
|
||||||
*/
|
*/
|
||||||
@Nonnull public static org.bukkit.Location adapt(@Nonnull final Location location) {
|
public static org.bukkit.@NonNull Location adapt(final @NonNull 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()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -175,20 +186,25 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
* @param string World name
|
* @param string World name
|
||||||
* @return World if it exists, or {@code null}
|
* @return World if it exists, or {@code null}
|
||||||
*/
|
*/
|
||||||
@Nullable public static World getWorld(@Nonnull final String string) {
|
public @Nullable static World getWorld(final @NonNull String string) {
|
||||||
return Bukkit.getWorld(string);
|
return Bukkit.getWorld(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ensureLoaded(@Nonnull final String world, final int x, final int z, @Nonnull final Consumer<Chunk> chunkConsumer) {
|
private static void ensureLoaded(
|
||||||
|
final @NonNull String world,
|
||||||
|
final int x,
|
||||||
|
final int z,
|
||||||
|
final @NonNull Consumer<Chunk> chunkConsumer
|
||||||
|
) {
|
||||||
PaperLib.getChunkAtAsync(Objects.requireNonNull(getWorld(world)), x >> 4, z >> 4, true)
|
PaperLib.getChunkAtAsync(Objects.requireNonNull(getWorld(world)), x >> 4, z >> 4, true)
|
||||||
.thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk));
|
.thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ensureLoaded(@Nonnull final Location location, @Nonnull final Consumer<Chunk> chunkConsumer) {
|
private static void ensureLoaded(final @NonNull Location location, final @NonNull 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(final @NonNull Consumer<T> consumer, final @NonNull T value) {
|
||||||
if (Bukkit.isPrimaryThread()) {
|
if (Bukkit.isPrimaryThread()) {
|
||||||
consumer.accept(value);
|
consumer.accept(value);
|
||||||
} else {
|
} else {
|
||||||
@ -196,7 +212,8 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean isBlockSame(@Nonnull final BlockState block1, @Nonnull final BlockState block2) {
|
@Override
|
||||||
|
public boolean isBlockSame(final @NonNull BlockState block1, final @NonNull BlockState block2) {
|
||||||
if (block1.equals(block2)) {
|
if (block1.equals(block2)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -205,19 +222,23 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
return mat1 == mat2;
|
return mat1 == mat2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean isWorld(@Nonnull final String worldName) {
|
@Override
|
||||||
|
public boolean isWorld(final @NonNull String worldName) {
|
||||||
return getWorld(worldName) != null;
|
return getWorld(worldName) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void getBiome(@Nonnull final String world, final int x, final int z, @Nonnull final Consumer<BiomeType> result) {
|
@Override
|
||||||
|
public void getBiome(final @NonNull String world, final int x, final int z, final @NonNull Consumer<BiomeType> result) {
|
||||||
ensureLoaded(world, x, z, chunk -> result.accept(BukkitAdapter.adapt(getWorld(world).getBiome(x, z))));
|
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
|
||||||
|
public @NonNull BiomeType getBiomeSynchronous(final @NonNull String world, final int x, final int z) {
|
||||||
return BukkitAdapter.adapt(Objects.requireNonNull(getWorld(world)).getBiome(x, 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(final @NonNull String world, final int x, final int z, final @NonNull IntConsumer result) {
|
||||||
ensureLoaded(world, x, z, chunk -> {
|
ensureLoaded(world, x, z, chunk -> {
|
||||||
final World bukkitWorld = Objects.requireNonNull(getWorld(world));
|
final World bukkitWorld = Objects.requireNonNull(getWorld(world));
|
||||||
// Skip top and bottom block
|
// Skip top and bottom block
|
||||||
@ -243,7 +264,9 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnegative public int getHighestBlockSynchronous(@Nonnull final String world, final int x, final int z) {
|
@Override
|
||||||
|
@NonNegative
|
||||||
|
public int getHighestBlockSynchronous(final @NonNull String world, final int x, final int z) {
|
||||||
final World bukkitWorld = Objects.requireNonNull(getWorld(world));
|
final World bukkitWorld = Objects.requireNonNull(getWorld(world));
|
||||||
// Skip top and bottom block
|
// Skip top and bottom block
|
||||||
int air = 1;
|
int air = 1;
|
||||||
@ -265,8 +288,13 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
return bukkitWorld.getMaxHeight() - 1;
|
return bukkitWorld.getMaxHeight() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public String[] getSignSynchronous(@Nonnull final Location location) {
|
@Override
|
||||||
Block block = Objects.requireNonNull(getWorld(location.getWorldName())).getBlockAt(location.getX(), location.getY(), location.getZ());
|
public @NonNull String[] getSignSynchronous(final @NonNull Location location) {
|
||||||
|
Block block = Objects.requireNonNull(getWorld(location.getWorldName())).getBlockAt(
|
||||||
|
location.getX(),
|
||||||
|
location.getY(),
|
||||||
|
location.getZ()
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
return TaskManager.getPlatformImplementation().sync(() -> {
|
return TaskManager.getPlatformImplementation().sync(() -> {
|
||||||
if (block.getState() instanceof Sign) {
|
if (block.getState() instanceof Sign) {
|
||||||
@ -281,28 +309,34 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
return new String[0];
|
return new String[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public Location getSpawn(@Nonnull final String world) {
|
@Override
|
||||||
|
public @NonNull Location getSpawn(final @NonNull String world) {
|
||||||
final org.bukkit.Location temp = getWorld(world).getSpawnLocation();
|
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) {
|
@Override
|
||||||
|
public void setSpawn(final @NonNull Location location) {
|
||||||
final World world = getWorld(location.getWorldName());
|
final World world = getWorld(location.getWorldName());
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
world.setSpawnLocation(location.getX(), location.getY(), location.getZ());
|
world.setSpawnLocation(location.getX(), location.getY(), location.getZ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void saveWorld(@Nonnull final String worldName) {
|
@Override
|
||||||
|
public void saveWorld(final @NonNull String worldName) {
|
||||||
final World world = getWorld(worldName);
|
final World world = getWorld(worldName);
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
world.save();
|
world.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @SuppressWarnings("deprecation")
|
@Override
|
||||||
public void setSign(@Nonnull final Location location, @Nonnull final Caption[] lines,
|
@SuppressWarnings("deprecation")
|
||||||
@Nonnull final Template ... replacements) {
|
public void setSign(
|
||||||
|
final @NonNull Location location, final @NonNull Caption[] lines,
|
||||||
|
final @NonNull Template... replacements
|
||||||
|
) {
|
||||||
ensureLoaded(location.getWorldName(), location.getX(), location.getZ(), chunk -> {
|
ensureLoaded(location.getWorldName(), location.getX(), location.getZ(), chunk -> {
|
||||||
final World world = getWorld(location.getWorldName());
|
final World world = getWorld(location.getWorldName());
|
||||||
final Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ());
|
final Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||||
@ -334,19 +368,25 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
final Sign sign = (Sign) blockstate;
|
final Sign sign = (Sign) blockstate;
|
||||||
for (int i = 0; i < lines.length; i++) {
|
for (int i = 0; i < lines.length; i++) {
|
||||||
sign.setLine(i, LEGACY_COMPONENT_SERIALIZER
|
sign.setLine(i, LEGACY_COMPONENT_SERIALIZER
|
||||||
.serialize(MINI_MESSAGE.parse(lines[i].getComponent(LocaleHolder.console()), replacements)));
|
.serialize(MINI_MESSAGE.parse(lines[i].getComponent(LocaleHolder.console()), replacements)));
|
||||||
}
|
}
|
||||||
sign.update(true);
|
sign.update(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public StringComparison<BlockState>.ComparisonResult getClosestBlock(@Nonnull String name) {
|
@Override
|
||||||
|
public @NonNull StringComparison<BlockState>.ComparisonResult getClosestBlock(@NonNull String name) {
|
||||||
BlockState state = BlockUtil.get(name);
|
BlockState state = BlockUtil.get(name);
|
||||||
return new StringComparison<BlockState>().new ComparisonResult(1, state);
|
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(
|
||||||
|
final @NonNull String worldName,
|
||||||
|
final @NonNull CuboidRegion region,
|
||||||
|
final @NonNull BiomeType biomeType
|
||||||
|
) {
|
||||||
final World world = getWorld(worldName);
|
final World world = getWorld(worldName);
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
logger.warn("An error occurred while setting the biome because the world was null", new RuntimeException());
|
logger.warn("An error occurred while setting the biome because the world was null", new RuntimeException());
|
||||||
@ -362,15 +402,18 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public com.sk89q.worldedit.world.World getWeWorld(@Nonnull final String world) {
|
@Override
|
||||||
|
public com.sk89q.worldedit.world.@NonNull World getWeWorld(final @NonNull String world) {
|
||||||
return new BukkitWorld(Bukkit.getWorld(world));
|
return new BukkitWorld(Bukkit.getWorld(world));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void refreshChunk(int x, int z, String world) {
|
@Override
|
||||||
|
public void refreshChunk(int x, int z, String world) {
|
||||||
Bukkit.getWorld(world).refreshChunk(x, z);
|
Bukkit.getWorld(world).refreshChunk(x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void getBlock(@Nonnull final Location location, @Nonnull final Consumer<BlockState> result) {
|
@Override
|
||||||
|
public void getBlock(final @NonNull Location location, final @NonNull Consumer<BlockState> result) {
|
||||||
ensureLoaded(location, chunk -> {
|
ensureLoaded(location, chunk -> {
|
||||||
final World world = getWorld(location.getWorldName());
|
final World world = getWorld(location.getWorldName());
|
||||||
final Block block = Objects.requireNonNull(world).getBlockAt(location.getX(), location.getY(), location.getZ());
|
final Block block = Objects.requireNonNull(world).getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||||
@ -378,29 +421,37 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public BlockState getBlockSynchronous(@Nonnull final Location location) {
|
@Override
|
||||||
|
public @NonNull BlockState getBlockSynchronous(final @NonNull Location location) {
|
||||||
final World world = getWorld(location.getWorldName());
|
final World world = getWorld(location.getWorldName());
|
||||||
final Block block = Objects.requireNonNull(world).getBlockAt(location.getX(), location.getY(), location.getZ());
|
final Block block = Objects.requireNonNull(world).getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||||
return Objects.requireNonNull(BukkitAdapter.asBlockType(block.getType())).getDefaultState();
|
return Objects.requireNonNull(BukkitAdapter.asBlockType(block.getType())).getDefaultState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnegative public double getHealth(@Nonnull final PlotPlayer player) {
|
@Override
|
||||||
|
@NonNegative
|
||||||
|
public double getHealth(final @NonNull 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) {
|
@Override
|
||||||
|
@NonNegative
|
||||||
|
public int getFoodLevel(final @NonNull 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) {
|
@Override
|
||||||
|
public void setHealth(final @NonNull PlotPlayer<?> player, @NonNegative final double health) {
|
||||||
Objects.requireNonNull(Bukkit.getPlayer(player.getUUID())).setHealth(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(final @NonNull PlotPlayer<?> player, @NonNegative final int foodLevel) {
|
||||||
Bukkit.getPlayer(player.getUUID()).setFoodLevel(foodLevel);
|
Bukkit.getPlayer(player.getUUID()).setFoodLevel(foodLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public Set<com.sk89q.worldedit.world.entity.EntityType> getTypesInCategory(@Nonnull final String category) {
|
@Override
|
||||||
|
public @NonNull Set<com.sk89q.worldedit.world.entity.EntityType> getTypesInCategory(final @NonNull String category) {
|
||||||
final Collection<Class<?>> allowedInterfaces = new HashSet<>();
|
final Collection<Class<?>> allowedInterfaces = new HashSet<>();
|
||||||
switch (category) {
|
switch (category) {
|
||||||
case "animal": {
|
case "animal": {
|
||||||
@ -480,7 +531,8 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public Collection<BlockType> getTileEntityTypes() {
|
@Override
|
||||||
|
public @NonNull Collection<BlockType> getTileEntityTypes() {
|
||||||
if (this.tileEntityTypes.isEmpty()) {
|
if (this.tileEntityTypes.isEmpty()) {
|
||||||
// Categories
|
// Categories
|
||||||
tileEntityTypes.addAll(BlockCategories.BANNERS.getAll());
|
tileEntityTypes.addAll(BlockCategories.BANNERS.getAll());
|
||||||
@ -489,22 +541,59 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
tileEntityTypes.addAll(BlockCategories.FLOWER_POTS.getAll());
|
tileEntityTypes.addAll(BlockCategories.FLOWER_POTS.getAll());
|
||||||
// Individual Types
|
// Individual Types
|
||||||
// Add these from strings
|
// Add these from strings
|
||||||
Stream.of("barrel", "beacon", "beehive", "bee_nest", "bell", "blast_furnace", "brewing_stand", "campfire", "chest", "ender_chest",
|
Stream.of("barrel",
|
||||||
"trapped_chest", "command_block", "end_gateway", "hopper", "jigsaw", "jubekox", "lectern", "note_block", "black_shulker_box",
|
"beacon",
|
||||||
"blue_shulker_box", "brown_shulker_box", "cyan_shulker_box", "gray_shulker_box", "green_shulker_box", "light_blue_shulker_box",
|
"beehive",
|
||||||
"light_gray_shulker_box", "lime_shulker_box", "magenta_shulker_box", "orange_shulker_box", "pink_shulker_box", "purple_shulker_box",
|
"bee_nest",
|
||||||
"red_shulker_box", "shulker_box", "white_shulker_box", "yellow_shulker_box", "smoker", "structure_block", "structure_void")
|
"bell",
|
||||||
.map(BlockTypes::get).filter(Objects::nonNull).forEach(tileEntityTypes::add);
|
"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;
|
return this.tileEntityTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnegative public int getTileEntityCount(@Nonnull final String world, @Nonnull final BlockVector2 chunk) {
|
@Override
|
||||||
|
@NonNegative
|
||||||
|
public int getTileEntityCount(final @NonNull String world, final @NonNull BlockVector2 chunk) {
|
||||||
return Objects.requireNonNull(getWorld(world)).
|
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) {
|
@Override
|
||||||
|
public Set<BlockVector2> getChunkChunks(String world) {
|
||||||
Set<BlockVector2> chunks = super.getChunkChunks(world);
|
Set<BlockVector2> chunks = super.getChunkChunks(world);
|
||||||
if (Bukkit.isPrimaryThread()) {
|
if (Bukkit.isPrimaryThread()) {
|
||||||
for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world)).getLoadedChunks()) {
|
for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world)).getLoadedChunks()) {
|
||||||
|
@ -28,8 +28,8 @@ package com.plotsquared.bukkit.util;
|
|||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.plotsquared.core.location.World;
|
import com.plotsquared.core.location.World;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ public class BukkitWorld implements World<org.bukkit.World> {
|
|||||||
* @param worldName World name
|
* @param worldName World name
|
||||||
* @return World instance
|
* @return World instance
|
||||||
*/
|
*/
|
||||||
@Nonnull public static BukkitWorld of(@Nonnull final String worldName) {
|
public @NonNull static BukkitWorld of(final @NonNull String worldName) {
|
||||||
final org.bukkit.World bukkitWorld = Bukkit.getWorld(worldName);
|
final org.bukkit.World bukkitWorld = Bukkit.getWorld(worldName);
|
||||||
if (bukkitWorld == null) {
|
if (bukkitWorld == null) {
|
||||||
throw new IllegalArgumentException(String.format("There is no world with the name '%s'", worldName));
|
throw new IllegalArgumentException(String.format("There is no world with the name '%s'", worldName));
|
||||||
@ -63,7 +63,7 @@ public class BukkitWorld implements World<org.bukkit.World> {
|
|||||||
* @param world Bukkit world
|
* @param world Bukkit world
|
||||||
* @return World instance
|
* @return World instance
|
||||||
*/
|
*/
|
||||||
@Nonnull public static BukkitWorld of(final org.bukkit.World world) {
|
public @NonNull static BukkitWorld of(final org.bukkit.World world) {
|
||||||
BukkitWorld bukkitWorld = worldMap.get(world.getName());
|
BukkitWorld bukkitWorld = worldMap.get(world.getName());
|
||||||
if (bukkitWorld != null && bukkitWorld.getPlatformWorld().equals(world)) {
|
if (bukkitWorld != null && bukkitWorld.getPlatformWorld().equals(world)) {
|
||||||
return bukkitWorld;
|
return bukkitWorld;
|
||||||
@ -73,11 +73,13 @@ public class BukkitWorld implements World<org.bukkit.World> {
|
|||||||
return bukkitWorld;
|
return bukkitWorld;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public org.bukkit.World getPlatformWorld() {
|
@Override
|
||||||
|
public org.bukkit.World getPlatformWorld() {
|
||||||
return this.world;
|
return this.world;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public String getName() {
|
@Override
|
||||||
|
public @NonNull String getName() {
|
||||||
return this.world.getName();
|
return this.world.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,4 +115,5 @@ public class BukkitWorld implements World<org.bukkit.World> {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "BukkitWorld(world=" + this.world + ")";
|
return "BukkitWorld(world=" + this.world + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -96,8 +96,10 @@ public class ContentMap {
|
|||||||
saveEntitiesIn(chunk, region, 0, 0, false);
|
saveEntitiesIn(chunk, region, 0, 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveEntitiesIn(Chunk chunk, CuboidRegion region, int offsetX, int offsetZ,
|
void saveEntitiesIn(
|
||||||
boolean delete) {
|
Chunk chunk, CuboidRegion region, int offsetX, int offsetZ,
|
||||||
|
boolean delete
|
||||||
|
) {
|
||||||
for (Entity entity : chunk.getEntities()) {
|
for (Entity entity : chunk.getEntities()) {
|
||||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||||
int x = location.getX();
|
int x = location.getX();
|
||||||
@ -143,4 +145,5 @@ public class ContentMap {
|
|||||||
PlotLoc loc = new PlotLoc(x + offsetX, z + offsetZ);
|
PlotLoc loc = new PlotLoc(x + offsetX, z + offsetZ);
|
||||||
this.allBlocks.put(loc, ids);
|
this.allBlocks.put(loc, ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -75,4 +75,5 @@ public class JavaVersionCheck {
|
|||||||
logger.error("************************************************************");
|
logger.error("************************************************************");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -69,9 +69,10 @@ public class SetGenCB {
|
|||||||
}
|
}
|
||||||
if (!set) {
|
if (!set) {
|
||||||
world.getPopulators()
|
world.getPopulators()
|
||||||
.removeIf(blockPopulator -> blockPopulator instanceof BukkitAugmentedGenerator);
|
.removeIf(blockPopulator -> blockPopulator instanceof BukkitAugmentedGenerator);
|
||||||
}
|
}
|
||||||
PlotSquared.get()
|
PlotSquared.get()
|
||||||
.loadWorld(world.getName(), PlotSquared.platform().getGenerator(world.getName(), null));
|
.loadWorld(world.getName(), PlotSquared.platform().getGenerator(world.getName(), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,8 @@ public class UpdateUtility implements Listener {
|
|||||||
public final JavaPlugin javaPlugin;
|
public final JavaPlugin javaPlugin;
|
||||||
private boolean notify = true;
|
private boolean notify = true;
|
||||||
|
|
||||||
@Inject public UpdateUtility(final JavaPlugin javaPlugin) {
|
@Inject
|
||||||
|
public UpdateUtility(final JavaPlugin javaPlugin) {
|
||||||
this.javaPlugin = javaPlugin;
|
this.javaPlugin = javaPlugin;
|
||||||
internalVersion = PlotSquared.get().getVersion();
|
internalVersion = PlotSquared.get().getVersion();
|
||||||
}
|
}
|
||||||
@ -64,12 +65,12 @@ public class UpdateUtility implements Listener {
|
|||||||
task = Bukkit.getScheduler().runTaskTimerAsynchronously(this.javaPlugin, () -> {
|
task = Bukkit.getScheduler().runTaskTimerAsynchronously(this.javaPlugin, () -> {
|
||||||
try {
|
try {
|
||||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(
|
HttpsURLConnection connection = (HttpsURLConnection) new URL(
|
||||||
"https://api.spigotmc.org/simple/0.1/index.php?action=getResource&id=77506")
|
"https://api.spigotmc.org/simple/0.1/index.php?action=getResource&id=77506")
|
||||||
.openConnection();
|
.openConnection();
|
||||||
connection.setRequestMethod("GET");
|
connection.setRequestMethod("GET");
|
||||||
JsonObject result = (new JsonParser())
|
JsonObject result = (new JsonParser())
|
||||||
.parse(new JsonReader(new InputStreamReader(connection.getInputStream())))
|
.parse(new JsonReader(new InputStreamReader(connection.getInputStream())))
|
||||||
.getAsJsonObject();
|
.getAsJsonObject();
|
||||||
spigotVersion = result.get("current_version").getAsString();
|
spigotVersion = result.get("current_version").getAsString();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Unable to check for updates. Error: {}", e.getMessage());
|
logger.error("Unable to check for updates. Error: {}", e.getMessage());
|
||||||
@ -79,7 +80,8 @@ public class UpdateUtility implements Listener {
|
|||||||
if (internalVersion.isLaterVersion(spigotVersion)) {
|
if (internalVersion.isLaterVersion(spigotVersion)) {
|
||||||
logger.info("There appears to be a PlotSquared update available!");
|
logger.info("There appears to be a PlotSquared update available!");
|
||||||
logger.info("You are running version {}, the latest version is {}",
|
logger.info("You are running version {}, the latest version is {}",
|
||||||
internalVersion.versionString(), spigotVersion);
|
internalVersion.versionString(), spigotVersion
|
||||||
|
);
|
||||||
logger.info("https://www.spigotmc.org/resources/77506/updates");
|
logger.info("https://www.spigotmc.org/resources/77506/updates");
|
||||||
hasUpdate = true;
|
hasUpdate = true;
|
||||||
if (Settings.UpdateChecker.NOTIFY_ONCE) {
|
if (Settings.UpdateChecker.NOTIFY_ONCE) {
|
||||||
@ -95,4 +97,5 @@ public class UpdateUtility implements Listener {
|
|||||||
private void cancelTask() {
|
private void cancelTask() {
|
||||||
Bukkit.getScheduler().runTaskLater(javaPlugin, () -> task.cancel(), 20L);
|
Bukkit.getScheduler().runTaskLater(javaPlugin, () -> task.cancel(), 20L);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,21 +27,22 @@ package com.plotsquared.bukkit.util.task;
|
|||||||
|
|
||||||
import com.plotsquared.core.util.task.PlotSquaredTask;
|
import com.plotsquared.core.util.task.PlotSquaredTask;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bukkit implementation of {@link PlotSquaredTask}
|
* Bukkit implementation of {@link PlotSquaredTask}
|
||||||
*/
|
*/
|
||||||
public final class BukkitPlotSquaredTask extends BukkitRunnable implements PlotSquaredTask {
|
public final class BukkitPlotSquaredTask extends BukkitRunnable implements PlotSquaredTask {
|
||||||
|
|
||||||
@Nonnull private final Runnable runnable;
|
@NonNull
|
||||||
|
private final Runnable runnable;
|
||||||
|
|
||||||
public BukkitPlotSquaredTask(@Nonnull final Runnable runnable) {
|
public BukkitPlotSquaredTask(final @NonNull Runnable runnable) {
|
||||||
this.runnable = runnable;
|
this.runnable = runnable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void runTask() {
|
@Override
|
||||||
|
public void runTask() {
|
||||||
this.runnable.run();
|
this.runnable.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,8 +33,8 @@ import com.plotsquared.core.util.task.PlotSquaredTask;
|
|||||||
import com.plotsquared.core.util.task.TaskManager;
|
import com.plotsquared.core.util.task.TaskManager;
|
||||||
import com.plotsquared.core.util.task.TaskTime;
|
import com.plotsquared.core.util.task.TaskTime;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -43,20 +43,26 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* Bukkit implementation of {@link TaskManager} using
|
* Bukkit implementation of {@link TaskManager} using
|
||||||
* by {@link org.bukkit.scheduler.BukkitScheduler} and {@link BukkitPlotSquaredTask}
|
* by {@link org.bukkit.scheduler.BukkitScheduler} and {@link BukkitPlotSquaredTask}
|
||||||
*/
|
*/
|
||||||
@Singleton public class BukkitTaskManager extends TaskManager {
|
@Singleton
|
||||||
|
public class BukkitTaskManager extends TaskManager {
|
||||||
|
|
||||||
private final BukkitPlatform bukkitMain;
|
private final BukkitPlatform bukkitMain;
|
||||||
private final TaskTime.TimeConverter timeConverter;
|
private final TaskTime.TimeConverter timeConverter;
|
||||||
|
|
||||||
@Inject public BukkitTaskManager(@Nonnull final BukkitPlatform bukkitMain,
|
@Inject
|
||||||
@Nonnull final TaskTime.TimeConverter timeConverter) {
|
public BukkitTaskManager(
|
||||||
|
final @NonNull BukkitPlatform bukkitMain,
|
||||||
|
final TaskTime.@NonNull TimeConverter timeConverter
|
||||||
|
) {
|
||||||
this.bukkitMain = bukkitMain;
|
this.bukkitMain = bukkitMain;
|
||||||
this.timeConverter = timeConverter;
|
this.timeConverter = timeConverter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlotSquaredTask taskRepeat(@Nonnull final Runnable runnable,
|
public PlotSquaredTask taskRepeat(
|
||||||
@Nonnull final TaskTime taskTime) {
|
final @NonNull Runnable runnable,
|
||||||
|
final @NonNull TaskTime taskTime
|
||||||
|
) {
|
||||||
final long ticks = this.timeConverter.toTicks(taskTime);
|
final long ticks = this.timeConverter.toTicks(taskTime);
|
||||||
final BukkitPlotSquaredTask bukkitPlotSquaredTask = new BukkitPlotSquaredTask(runnable);
|
final BukkitPlotSquaredTask bukkitPlotSquaredTask = new BukkitPlotSquaredTask(runnable);
|
||||||
bukkitPlotSquaredTask.runTaskTimer(this.bukkitMain, ticks, ticks);
|
bukkitPlotSquaredTask.runTaskTimer(this.bukkitMain, ticks, ticks);
|
||||||
@ -64,15 +70,18 @@ import java.util.concurrent.TimeUnit;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlotSquaredTask taskRepeatAsync(@Nonnull final Runnable runnable,
|
public PlotSquaredTask taskRepeatAsync(
|
||||||
@Nonnull final TaskTime taskTime) {
|
final @NonNull Runnable runnable,
|
||||||
|
final @NonNull TaskTime taskTime
|
||||||
|
) {
|
||||||
final long ticks = this.timeConverter.toTicks(taskTime);
|
final long ticks = this.timeConverter.toTicks(taskTime);
|
||||||
final BukkitPlotSquaredTask bukkitPlotSquaredTask = new BukkitPlotSquaredTask(runnable);
|
final BukkitPlotSquaredTask bukkitPlotSquaredTask = new BukkitPlotSquaredTask(runnable);
|
||||||
bukkitPlotSquaredTask.runTaskTimerAsynchronously(this.bukkitMain, ticks, ticks);
|
bukkitPlotSquaredTask.runTaskTimerAsynchronously(this.bukkitMain, ticks, ticks);
|
||||||
return bukkitPlotSquaredTask;
|
return bukkitPlotSquaredTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void taskAsync(@Nonnull final Runnable runnable) {
|
@Override
|
||||||
|
public void taskAsync(final @NonNull Runnable runnable) {
|
||||||
if (this.bukkitMain.isEnabled()) {
|
if (this.bukkitMain.isEnabled()) {
|
||||||
new BukkitPlotSquaredTask(runnable).runTaskAsynchronously(this.bukkitMain);
|
new BukkitPlotSquaredTask(runnable).runTaskAsynchronously(this.bukkitMain);
|
||||||
} else {
|
} else {
|
||||||
@ -80,29 +89,38 @@ import java.util.concurrent.TimeUnit;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public <T> T sync(@Nonnull final Callable<T> function, final int timeout) throws Exception {
|
@Override
|
||||||
|
public <T> T sync(final @NonNull Callable<T> function, final int timeout) throws Exception {
|
||||||
if (PlotSquared.get().isMainThread(Thread.currentThread())) {
|
if (PlotSquared.get().isMainThread(Thread.currentThread())) {
|
||||||
return function.call();
|
return function.call();
|
||||||
}
|
}
|
||||||
return this.callMethodSync(function).get(timeout, TimeUnit.MILLISECONDS);
|
return this.callMethodSync(function).get(timeout, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public <T> Future<T> callMethodSync(@Nonnull final Callable<T> method) {
|
@Override
|
||||||
|
public <T> Future<T> callMethodSync(final @NonNull Callable<T> method) {
|
||||||
return Bukkit.getScheduler().callSyncMethod(this.bukkitMain, method);
|
return Bukkit.getScheduler().callSyncMethod(this.bukkitMain, method);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void task(@Nonnull final Runnable runnable) {
|
@Override
|
||||||
|
public void task(final @NonNull Runnable runnable) {
|
||||||
new BukkitPlotSquaredTask(runnable).runTask(this.bukkitMain);
|
new BukkitPlotSquaredTask(runnable).runTask(this.bukkitMain);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void taskLater(@Nonnull final Runnable runnable,
|
@Override
|
||||||
@Nonnull final TaskTime taskTime) {
|
public void taskLater(
|
||||||
|
final @NonNull Runnable runnable,
|
||||||
|
final @NonNull TaskTime taskTime
|
||||||
|
) {
|
||||||
final long delay = this.timeConverter.toTicks(taskTime);
|
final long delay = this.timeConverter.toTicks(taskTime);
|
||||||
new BukkitPlotSquaredTask(runnable).runTaskLater(this.bukkitMain, delay);
|
new BukkitPlotSquaredTask(runnable).runTaskLater(this.bukkitMain, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void taskLaterAsync(@Nonnull final Runnable runnable,
|
@Override
|
||||||
@Nonnull final TaskTime taskTime) {
|
public void taskLaterAsync(
|
||||||
|
final @NonNull Runnable runnable,
|
||||||
|
final @NonNull TaskTime taskTime
|
||||||
|
) {
|
||||||
final long delay = this.timeConverter.toTicks(taskTime);
|
final long delay = this.timeConverter.toTicks(taskTime);
|
||||||
new BukkitPlotSquaredTask(runnable).runTaskLaterAsynchronously(this.bukkitMain, delay);
|
new BukkitPlotSquaredTask(runnable).runTaskLaterAsynchronously(this.bukkitMain, delay);
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,7 @@ package com.plotsquared.bukkit.util.task;
|
|||||||
|
|
||||||
import com.plotsquared.core.util.task.TaskTime;
|
import com.plotsquared.core.util.task.TaskTime;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.checkerframework.checker.index.qual.NonNegative;
|
||||||
import javax.annotation.Nonnegative;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Time converter that uses the server MSPT count to convert between
|
* Time converter that uses the server MSPT count to convert between
|
||||||
@ -38,11 +37,13 @@ public final class PaperTimeConverter implements TaskTime.TimeConverter {
|
|||||||
|
|
||||||
private static final long MIN_MS_PER_TICKS = 50L;
|
private static final long MIN_MS_PER_TICKS = 50L;
|
||||||
|
|
||||||
@Override public long msToTicks(@Nonnegative final long ms) {
|
@Override
|
||||||
|
public long msToTicks(@NonNegative final long ms) {
|
||||||
return Math.max(1L, (long) (ms / Math.max(MIN_MS_PER_TICKS, Bukkit.getAverageTickTime())));
|
return Math.max(1L, (long) (ms / Math.max(MIN_MS_PER_TICKS, Bukkit.getAverageTickTime())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public long ticksToMs(@Nonnegative final long ticks) {
|
@Override
|
||||||
|
public long ticksToMs(@NonNegative final long ticks) {
|
||||||
return Math.max(1L, (long) (ticks * Math.max(MIN_MS_PER_TICKS, Bukkit.getAverageTickTime())));
|
return Math.max(1L, (long) (ticks * Math.max(MIN_MS_PER_TICKS, Bukkit.getAverageTickTime())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,8 +26,7 @@
|
|||||||
package com.plotsquared.bukkit.util.task;
|
package com.plotsquared.bukkit.util.task;
|
||||||
|
|
||||||
import com.plotsquared.core.util.task.TaskTime;
|
import com.plotsquared.core.util.task.TaskTime;
|
||||||
|
import org.checkerframework.checker.index.qual.NonNegative;
|
||||||
import javax.annotation.Nonnegative;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Naive time converter that assumes that all ticks are 50 milliseconds
|
* Naive time converter that assumes that all ticks are 50 milliseconds
|
||||||
@ -36,11 +35,13 @@ public final class SpigotTimeConverter implements TaskTime.TimeConverter {
|
|||||||
|
|
||||||
private static final long MS_PER_TICKS = 50L;
|
private static final long MS_PER_TICKS = 50L;
|
||||||
|
|
||||||
@Override public long msToTicks(@Nonnegative final long ms) {
|
@Override
|
||||||
|
public long msToTicks(@NonNegative final long ms) {
|
||||||
return Math.max(1L, ms / MS_PER_TICKS);
|
return Math.max(1L, ms / MS_PER_TICKS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public long ticksToMs(@Nonnegative final long ticks) {
|
@Override
|
||||||
|
public long ticksToMs(@NonNegative final long ticks) {
|
||||||
return Math.max(1L, ticks * MS_PER_TICKS);
|
return Math.max(1L, ticks * MS_PER_TICKS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ import com.earth2me.essentials.Essentials;
|
|||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.plotsquared.core.uuid.UUIDMapping;
|
import com.plotsquared.core.uuid.UUIDMapping;
|
||||||
import com.plotsquared.core.uuid.UUIDService;
|
import com.plotsquared.core.uuid.UUIDService;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -47,11 +47,13 @@ public class EssentialsUUIDService implements UUIDService {
|
|||||||
this.essentials = Essentials.getPlugin(Essentials.class);
|
this.essentials = Essentials.getPlugin(Essentials.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
@Override
|
||||||
|
public @NonNull List<UUIDMapping> getNames(final @NonNull List<UUID> uuids) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull final List<String> usernames) {
|
@Override
|
||||||
|
public @NonNull List<UUIDMapping> getUUIDs(final @NonNull List<String> usernames) {
|
||||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||||
for (final String username : usernames) {
|
for (final String username : usernames) {
|
||||||
try {
|
try {
|
||||||
@ -62,7 +64,8 @@ public class EssentialsUUIDService implements UUIDService {
|
|||||||
mappings.add(new UUIDMapping(uuid, username));
|
mappings.add(new UUIDMapping(uuid, username));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Exception ignored){}
|
} catch (final Exception ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return mappings;
|
return mappings;
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,8 @@ import net.luckperms.api.LuckPerms;
|
|||||||
import net.luckperms.api.model.user.UserManager;
|
import net.luckperms.api.model.user.UserManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -53,21 +53,24 @@ public class LuckPermsUUIDService implements UUIDService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
@Override
|
||||||
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
public @NonNull List<UUIDMapping> getNames(final @NonNull List<UUID> uuids) {
|
||||||
final UserManager userManager = this.luckPerms.getUserManager();
|
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
||||||
for (final UUID uuid : uuids) {
|
final UserManager userManager = this.luckPerms.getUserManager();
|
||||||
try {
|
for (final UUID uuid : uuids) {
|
||||||
final String username = userManager.lookupUsername(uuid).get();
|
try {
|
||||||
if (username != null) {
|
final String username = userManager.lookupUsername(uuid).get();
|
||||||
mappings.add(new UUIDMapping(uuid, username));
|
if (username != null) {
|
||||||
}
|
mappings.add(new UUIDMapping(uuid, username));
|
||||||
} catch (final Exception ignored) {}
|
}
|
||||||
}
|
} catch (final Exception ignored) {
|
||||||
return mappings;
|
}
|
||||||
|
}
|
||||||
|
return mappings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull final List<String> usernames) {
|
@Override
|
||||||
|
public @NonNull List<UUIDMapping> getUUIDs(final @NonNull List<String> usernames) {
|
||||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||||
final UserManager userManager = this.luckPerms.getUserManager();
|
final UserManager userManager = this.luckPerms.getUserManager();
|
||||||
for (final String username : usernames) {
|
for (final String username : usernames) {
|
||||||
@ -76,7 +79,8 @@ public class LuckPermsUUIDService implements UUIDService {
|
|||||||
if (username != null) {
|
if (username != null) {
|
||||||
mappings.add(new UUIDMapping(uuid, username));
|
mappings.add(new UUIDMapping(uuid, username));
|
||||||
}
|
}
|
||||||
} catch (final Exception ignored) {}
|
} catch (final Exception ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return mappings;
|
return mappings;
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,8 @@ import com.plotsquared.core.uuid.UUIDMapping;
|
|||||||
import com.plotsquared.core.uuid.UUIDService;
|
import com.plotsquared.core.uuid.UUIDService;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -43,7 +43,8 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public class OfflinePlayerUUIDService implements UUIDService {
|
public class OfflinePlayerUUIDService implements UUIDService {
|
||||||
|
|
||||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
@Override
|
||||||
|
public @NonNull List<UUIDMapping> getNames(final @NonNull List<UUID> uuids) {
|
||||||
if (Settings.UUID.FORCE_LOWERCASE || Bukkit.getWorlds().isEmpty()) {
|
if (Settings.UUID.FORCE_LOWERCASE || Bukkit.getWorlds().isEmpty()) {
|
||||||
return Collections.emptyList(); // This is useless now
|
return Collections.emptyList(); // This is useless now
|
||||||
}
|
}
|
||||||
@ -54,14 +55,16 @@ public class OfflinePlayerUUIDService implements UUIDService {
|
|||||||
if (offlinePlayer.hasPlayedBefore()) {
|
if (offlinePlayer.hasPlayedBefore()) {
|
||||||
wrappers.add(new UUIDMapping(uuid, offlinePlayer.getName()));
|
wrappers.add(new UUIDMapping(uuid, offlinePlayer.getName()));
|
||||||
}
|
}
|
||||||
} catch (final Exception ignored) {} /* This can be safely ignored. If this happens, it is
|
} catch (final Exception ignored) {
|
||||||
|
} /* This can be safely ignored. If this happens, it is
|
||||||
probably because it's called before the worlds have
|
probably because it's called before the worlds have
|
||||||
been loaded. This is bad, but does not break anything */
|
been loaded. This is bad, but does not break anything */
|
||||||
}
|
}
|
||||||
return wrappers;
|
return wrappers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull final List<String> usernames) {
|
@Override
|
||||||
|
public @NonNull List<UUIDMapping> getUUIDs(final @NonNull List<String> usernames) {
|
||||||
final List<UUIDMapping> wrappers = new ArrayList<>(usernames.size());
|
final List<UUIDMapping> wrappers = new ArrayList<>(usernames.size());
|
||||||
for (final String username : usernames) {
|
for (final String username : usernames) {
|
||||||
if (Settings.UUID.OFFLINE) {
|
if (Settings.UUID.OFFLINE) {
|
||||||
|
@ -29,8 +29,8 @@ import com.destroystokyo.paper.profile.PlayerProfile;
|
|||||||
import com.plotsquared.core.uuid.UUIDMapping;
|
import com.plotsquared.core.uuid.UUIDMapping;
|
||||||
import com.plotsquared.core.uuid.UUIDService;
|
import com.plotsquared.core.uuid.UUIDService;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -40,7 +40,8 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public class PaperUUIDService implements UUIDService {
|
public class PaperUUIDService implements UUIDService {
|
||||||
|
|
||||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
@Override
|
||||||
|
public @NonNull List<UUIDMapping> getNames(final @NonNull List<UUID> uuids) {
|
||||||
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
||||||
for (final UUID uuid : uuids) {
|
for (final UUID uuid : uuids) {
|
||||||
final PlayerProfile playerProfile = Bukkit.createProfile(uuid);
|
final PlayerProfile playerProfile = Bukkit.createProfile(uuid);
|
||||||
@ -51,7 +52,8 @@ public class PaperUUIDService implements UUIDService {
|
|||||||
return mappings;
|
return mappings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull final List<String> usernames) {
|
@Override
|
||||||
|
public @NonNull List<UUIDMapping> getUUIDs(final @NonNull List<String> usernames) {
|
||||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||||
for (final String username : usernames) {
|
for (final String username : usernames) {
|
||||||
final PlayerProfile playerProfile = Bukkit.createProfile(username);
|
final PlayerProfile playerProfile = Bukkit.createProfile(username);
|
||||||
|
@ -30,8 +30,8 @@ import com.plotsquared.core.database.SQLite;
|
|||||||
import com.plotsquared.core.util.FileUtils;
|
import com.plotsquared.core.util.FileUtils;
|
||||||
import com.plotsquared.core.uuid.UUIDMapping;
|
import com.plotsquared.core.uuid.UUIDMapping;
|
||||||
import com.plotsquared.core.uuid.UUIDService;
|
import com.plotsquared.core.uuid.UUIDService;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -51,7 +51,7 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
|||||||
|
|
||||||
public SQLiteUUIDService(final String fileName) {
|
public SQLiteUUIDService(final String fileName) {
|
||||||
this.sqlite =
|
this.sqlite =
|
||||||
new SQLite(FileUtils.getFile(PlotSquared.platform().getDirectory(), fileName));
|
new SQLite(FileUtils.getFile(PlotSquared.platform().getDirectory(), fileName));
|
||||||
try {
|
try {
|
||||||
this.sqlite.openConnection();
|
this.sqlite.openConnection();
|
||||||
} catch (ClassNotFoundException | SQLException e) {
|
} catch (ClassNotFoundException | SQLException e) {
|
||||||
@ -59,7 +59,7 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
|||||||
}
|
}
|
||||||
|
|
||||||
try (PreparedStatement stmt = getConnection().prepareStatement(
|
try (PreparedStatement stmt = getConnection().prepareStatement(
|
||||||
"CREATE TABLE IF NOT EXISTS `usercache` (uuid VARCHAR(32) NOT NULL, username VARCHAR(32) NOT NULL, PRIMARY KEY (uuid))")) {
|
"CREATE TABLE IF NOT EXISTS `usercache` (uuid VARCHAR(32) NOT NULL, username VARCHAR(32) NOT NULL, PRIMARY KEY (uuid))")) {
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -72,10 +72,11 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
@Override
|
||||||
|
public @NonNull List<UUIDMapping> getNames(final @NonNull List<UUID> uuids) {
|
||||||
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
||||||
try (final PreparedStatement statement = getConnection()
|
try (final PreparedStatement statement = getConnection()
|
||||||
.prepareStatement("SELECT `username` FROM `usercache` WHERE `uuid` = ?")) {
|
.prepareStatement("SELECT `username` FROM `usercache` WHERE `uuid` = ?")) {
|
||||||
for (final UUID uuid : uuids) {
|
for (final UUID uuid : uuids) {
|
||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
try (final ResultSet resultSet = statement.executeQuery()) {
|
try (final ResultSet resultSet = statement.executeQuery()) {
|
||||||
@ -90,16 +91,19 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
|||||||
return mappings;
|
return mappings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull List<String> usernames) {
|
@Override
|
||||||
|
public @NonNull List<UUIDMapping> getUUIDs(@NonNull List<String> usernames) {
|
||||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||||
try (final PreparedStatement statement = getConnection()
|
try (final PreparedStatement statement = getConnection()
|
||||||
.prepareStatement("SELECT `uuid` FROM `usercache` WHERE `username` = ?")) {
|
.prepareStatement("SELECT `uuid` FROM `usercache` WHERE `username` = ?")) {
|
||||||
for (final String username : usernames) {
|
for (final String username : usernames) {
|
||||||
statement.setString(1, username);
|
statement.setString(1, username);
|
||||||
try (final ResultSet resultSet = statement.executeQuery()) {
|
try (final ResultSet resultSet = statement.executeQuery()) {
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
mappings.add(new UUIDMapping(UUID.fromString(resultSet.getString("uuid")),
|
mappings.add(new UUIDMapping(
|
||||||
username));
|
UUID.fromString(resultSet.getString("uuid")),
|
||||||
|
username
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,9 +113,10 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
|||||||
return mappings;
|
return mappings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void accept(final List<UUIDMapping> uuidWrappers) {
|
@Override
|
||||||
|
public void accept(final List<UUIDMapping> uuidWrappers) {
|
||||||
try (final PreparedStatement statement = getConnection()
|
try (final PreparedStatement statement = getConnection()
|
||||||
.prepareStatement("INSERT OR REPLACE INTO `usercache` (`uuid`, `username`) VALUES(?, ?)")) {
|
.prepareStatement("INSERT OR REPLACE INTO `usercache` (`uuid`, `username`) VALUES(?, ?)")) {
|
||||||
for (final UUIDMapping mapping : uuidWrappers) {
|
for (final UUIDMapping mapping : uuidWrappers) {
|
||||||
statement.setString(1, mapping.getUuid().toString());
|
statement.setString(1, mapping.getUuid().toString());
|
||||||
statement.setString(2, mapping.getUsername());
|
statement.setString(2, mapping.getUsername());
|
||||||
@ -127,7 +132,7 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
|||||||
*
|
*
|
||||||
* @return All read mappings
|
* @return All read mappings
|
||||||
*/
|
*/
|
||||||
@Nonnull public List<UUIDMapping> getAll() {
|
public @NonNull List<UUIDMapping> getAll() {
|
||||||
final List<UUIDMapping> mappings = new LinkedList<>();
|
final List<UUIDMapping> mappings = new LinkedList<>();
|
||||||
try (final PreparedStatement statement = getConnection().prepareStatement("SELECT * FROM `usercache`")) {
|
try (final PreparedStatement statement = getConnection().prepareStatement("SELECT * FROM `usercache`")) {
|
||||||
try (final ResultSet resultSet = statement.executeQuery()) {
|
try (final ResultSet resultSet = statement.executeQuery()) {
|
||||||
|
@ -32,10 +32,10 @@ import com.plotsquared.core.uuid.UUIDService;
|
|||||||
import com.sk89q.squirrelid.Profile;
|
import com.sk89q.squirrelid.Profile;
|
||||||
import com.sk89q.squirrelid.resolver.HttpRepositoryService;
|
import com.sk89q.squirrelid.resolver.HttpRepositoryService;
|
||||||
import com.sk89q.squirrelid.resolver.ProfileService;
|
import com.sk89q.squirrelid.resolver.ProfileService;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -67,7 +67,8 @@ public class SquirrelIdUUIDService implements UUIDService {
|
|||||||
this.rateLimiter = RateLimiter.create(rateLimit / 600.0D);
|
this.rateLimiter = RateLimiter.create(rateLimit / 600.0D);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
@Override
|
||||||
|
public @NonNull List<UUIDMapping> getNames(final @NonNull List<UUID> uuids) {
|
||||||
final List<UUIDMapping> results = new ArrayList<>(uuids.size());
|
final List<UUIDMapping> results = new ArrayList<>(uuids.size());
|
||||||
this.rateLimiter.acquire(uuids.size());
|
this.rateLimiter.acquire(uuids.size());
|
||||||
try {
|
try {
|
||||||
@ -101,7 +102,8 @@ public class SquirrelIdUUIDService implements UUIDService {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull final List<String> usernames) {
|
@Override
|
||||||
|
public @NonNull List<UUIDMapping> getUUIDs(final @NonNull List<String> usernames) {
|
||||||
final List<UUIDMapping> results = new ArrayList<>(usernames.size());
|
final List<UUIDMapping> results = new ArrayList<>(usernames.size());
|
||||||
this.rateLimiter.acquire(usernames.size());
|
this.rateLimiter.acquire(usernames.size());
|
||||||
try {
|
try {
|
||||||
|
@ -2,7 +2,7 @@ import java.time.format.DateTimeFormatter
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// Expected everywhere.
|
// Expected everywhere.
|
||||||
compileOnlyApi("javax.annotation:javax.annotation-api:1.3.2")
|
compileOnlyApi("org.checkerframework:checker-qual:3.9.0")
|
||||||
|
|
||||||
// Minecraft expectations
|
// Minecraft expectations
|
||||||
compileOnlyApi("com.google.guava:guava:21.0") // Minecraft uses v21.0
|
compileOnlyApi("com.google.guava:guava:21.0") // Minecraft uses v21.0
|
||||||
@ -23,7 +23,6 @@ dependencies {
|
|||||||
exclude("com.google.inject", "guice")
|
exclude("com.google.inject", "guice")
|
||||||
}
|
}
|
||||||
compileOnlyApi("com.google.code.findbugs:annotations:3.0.1")
|
compileOnlyApi("com.google.code.findbugs:annotations:3.0.1")
|
||||||
compileOnlyApi("javax.inject:javax.inject:1")
|
|
||||||
|
|
||||||
// Plugins
|
// Plugins
|
||||||
compileOnlyApi("com.sk89q.worldedit:worldedit-core:7.2.0") {
|
compileOnlyApi("com.sk89q.worldedit:worldedit-core:7.2.0") {
|
||||||
@ -52,9 +51,9 @@ dependencies {
|
|||||||
tasks.processResources {
|
tasks.processResources {
|
||||||
filesMatching("plugin.properties") {
|
filesMatching("plugin.properties") {
|
||||||
expand(
|
expand(
|
||||||
"version" to project.version.toString(),
|
"version" to project.version.toString(),
|
||||||
"commit" to rootProject.grgit.head().abbreviatedId,
|
"commit" to rootProject.grgit.head().abbreviatedId,
|
||||||
"date" to rootProject.grgit.head().dateTime.format(DateTimeFormatter.ofPattern("yy.MM.dd"))
|
"date" to rootProject.grgit.head().dateTime.format(DateTimeFormatter.ofPattern("yy.MM.dd"))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* _____ _ _ _____ _
|
|
||||||
* | __ \| | | | / ____| | |
|
|
||||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
|
||||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
|
||||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
|
||||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
|
||||||
* | |
|
|
||||||
* |_|
|
|
||||||
* PlotSquared plot management system for Minecraft
|
|
||||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package com.plotsquared.core;
|
|
||||||
|
|
||||||
public enum Platform {
|
|
||||||
Bukkit, Sponge, Spigot, Paper
|
|
||||||
|
|
||||||
}
|
|
@ -38,9 +38,9 @@ import com.plotsquared.core.util.EventDispatcher;
|
|||||||
import com.plotsquared.core.util.SchematicHandler;
|
import com.plotsquared.core.util.SchematicHandler;
|
||||||
import com.plotsquared.core.util.query.PlotQuery;
|
import com.plotsquared.core.util.query.PlotQuery;
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -59,7 +59,8 @@ import java.util.UUID;
|
|||||||
*
|
*
|
||||||
* @version 5
|
* @version 5
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"unused", "WeakerAccess"}) public class PlotAPI {
|
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||||
|
public class PlotAPI {
|
||||||
|
|
||||||
public PlotAPI() {
|
public PlotAPI() {
|
||||||
}
|
}
|
||||||
@ -69,7 +70,7 @@ import java.util.UUID;
|
|||||||
*
|
*
|
||||||
* @return all plots
|
* @return all plots
|
||||||
*/
|
*/
|
||||||
public Set<Plot> getAllPlots() {
|
public @NonNull Set<@NonNull Plot> getAllPlots() {
|
||||||
return PlotQuery.newQuery().allPlots().asSet();
|
return PlotQuery.newQuery().allPlots().asSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ import java.util.UUID;
|
|||||||
* @param player Player, whose plots to search for
|
* @param player Player, whose plots to search for
|
||||||
* @return all plots that a player owns
|
* @return all plots that a player owns
|
||||||
*/
|
*/
|
||||||
public Set<Plot> getPlayerPlots(PlotPlayer<?> player) {
|
public @NonNull Set<@NonNull Plot> getPlayerPlots(final @NonNull PlotPlayer<?> player) {
|
||||||
return PlotQuery.newQuery().ownedBy(player).asSet();
|
return PlotQuery.newQuery().ownedBy(player).asSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +90,7 @@ import java.util.UUID;
|
|||||||
* @param plotArea Plot World Object
|
* @param plotArea Plot World Object
|
||||||
* @see PlotSquared#addPlotArea(PlotArea)
|
* @see PlotSquared#addPlotArea(PlotArea)
|
||||||
*/
|
*/
|
||||||
public void addPlotArea(PlotArea plotArea) {
|
public void addPlotArea(final @NonNull PlotArea plotArea) {
|
||||||
PlotSquared.get().addPlotArea(plotArea);
|
PlotSquared.get().addPlotArea(plotArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ import java.util.UUID;
|
|||||||
* @return ChunkManager
|
* @return ChunkManager
|
||||||
* @see ChunkManager
|
* @see ChunkManager
|
||||||
*/
|
*/
|
||||||
public ChunkManager getChunkManager() {
|
public @NonNull ChunkManager getChunkManager() {
|
||||||
return PlotSquared.platform().injector().getInstance(ChunkManager.class);
|
return PlotSquared.platform().injector().getInstance(ChunkManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +116,7 @@ import java.util.UUID;
|
|||||||
*
|
*
|
||||||
* @return GlobalBlockQueue.IMP
|
* @return GlobalBlockQueue.IMP
|
||||||
*/
|
*/
|
||||||
public GlobalBlockQueue getBlockQueue() {
|
public @NonNull GlobalBlockQueue getBlockQueue() {
|
||||||
return PlotSquared.platform().globalBlockQueue();
|
return PlotSquared.platform().globalBlockQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +127,7 @@ import java.util.UUID;
|
|||||||
* @return SchematicHandler
|
* @return SchematicHandler
|
||||||
* @see SchematicHandler
|
* @see SchematicHandler
|
||||||
*/
|
*/
|
||||||
public SchematicHandler getSchematicHandler() {
|
public @NonNull SchematicHandler getSchematicHandler() {
|
||||||
return PlotSquared.platform().injector().getInstance(SchematicHandler.class);
|
return PlotSquared.platform().injector().getInstance(SchematicHandler.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +137,7 @@ import java.util.UUID;
|
|||||||
* @param world The world to check for plot areas
|
* @param world The world to check for plot areas
|
||||||
* @return A set of PlotAreas
|
* @return A set of PlotAreas
|
||||||
*/
|
*/
|
||||||
public Set<PlotArea> getPlotAreas(String world) {
|
public @NonNull Set<@NonNull PlotArea> getPlotAreas(final @Nullable String world) {
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
@ -149,7 +150,9 @@ import java.util.UUID;
|
|||||||
* @param message the message
|
* @param message the message
|
||||||
* @param replacements Variable replacements
|
* @param replacements Variable replacements
|
||||||
*/
|
*/
|
||||||
public void sendConsoleMessage(@Nonnull final String message, final Template... replacements) {
|
public void sendConsoleMessage(
|
||||||
|
final @NonNull String message,
|
||||||
|
final @NonNull Template @NonNull... replacements) {
|
||||||
ConsolePlayer.getConsole().sendMessage(StaticCaption.of(message), replacements);
|
ConsolePlayer.getConsole().sendMessage(StaticCaption.of(message), replacements);
|
||||||
// TODO: Re-implement
|
// TODO: Re-implement
|
||||||
// PlotSquared.log(message);
|
// PlotSquared.log(message);
|
||||||
@ -161,7 +164,10 @@ import java.util.UUID;
|
|||||||
* @param caption the message
|
* @param caption the message
|
||||||
* @param replacements Variable replacements
|
* @param replacements Variable replacements
|
||||||
*/
|
*/
|
||||||
public void sendConsoleMessage(@Nonnull final Caption caption, final Template... replacements) {
|
public void sendConsoleMessage(
|
||||||
|
final @NonNull Caption caption,
|
||||||
|
final @NonNull Template @NonNull... replacements
|
||||||
|
) {
|
||||||
ConsolePlayer.getConsole().sendMessage(caption, replacements);
|
ConsolePlayer.getConsole().sendMessage(caption, replacements);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +177,7 @@ import java.util.UUID;
|
|||||||
* @return PlotSquared Class
|
* @return PlotSquared Class
|
||||||
* @see PlotSquared
|
* @see PlotSquared
|
||||||
*/
|
*/
|
||||||
public PlotSquared getPlotSquared() {
|
public @NonNull PlotSquared getPlotSquared() {
|
||||||
return PlotSquared.get();
|
return PlotSquared.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,12 +185,12 @@ import java.util.UUID;
|
|||||||
* Gets the PlotPlayer for a UUID.
|
* Gets the PlotPlayer for a UUID.
|
||||||
*
|
*
|
||||||
* <p><i>Please note that PlotSquared can be configured to provide
|
* <p><i>Please note that PlotSquared can be configured to provide
|
||||||
* different UUIDs than bukkit</i>
|
* different UUIDs than Bukkit</i>
|
||||||
*
|
*
|
||||||
* @param uuid the uuid of the player to wrap
|
* @param uuid the uuid of the player to wrap
|
||||||
* @return a {@code PlotPlayer}
|
* @return a {@code PlotPlayer}
|
||||||
*/
|
*/
|
||||||
@Nullable public PlotPlayer<?> wrapPlayer(@Nonnull final UUID uuid) {
|
public @Nullable PlotPlayer<?> wrapPlayer(final @NonNull UUID uuid) {
|
||||||
return PlotSquared.platform().playerManager().getPlayerIfExists(uuid);
|
return PlotSquared.platform().playerManager().getPlayerIfExists(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +200,7 @@ import java.util.UUID;
|
|||||||
* @param player the player to wrap
|
* @param player the player to wrap
|
||||||
* @return a {@code PlotPlayer}
|
* @return a {@code PlotPlayer}
|
||||||
*/
|
*/
|
||||||
@Nullable public PlotPlayer<?> wrapPlayer(@Nonnull final String player) {
|
public @Nullable PlotPlayer<?> wrapPlayer(final @NonNull String player) {
|
||||||
return PlotSquared.platform().playerManager().getPlayerIfExists(player);
|
return PlotSquared.platform().playerManager().getPlayerIfExists(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +210,8 @@ import java.util.UUID;
|
|||||||
* @param listener the listener class to register
|
* @param listener the listener class to register
|
||||||
* @see EventDispatcher#registerListener(Object)
|
* @see EventDispatcher#registerListener(Object)
|
||||||
*/
|
*/
|
||||||
public void registerListener(Object listener) {
|
public void registerListener(final @NonNull Object listener) {
|
||||||
PlotSquared.get().getEventDispatcher().registerListener(listener);
|
PlotSquared.get().getEventDispatcher().registerListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -49,9 +49,9 @@ import com.plotsquared.core.util.WorldUtil;
|
|||||||
import com.plotsquared.core.util.placeholders.PlaceholderRegistry;
|
import com.plotsquared.core.util.placeholders.PlaceholderRegistry;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,14 +66,14 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @return the PlotSquared directory
|
* @return the PlotSquared directory
|
||||||
*/
|
*/
|
||||||
@Nonnull File getDirectory();
|
@NonNull File getDirectory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the folder where all world data is stored.
|
* Gets the folder where all world data is stored.
|
||||||
*
|
*
|
||||||
* @return the world folder
|
* @return the world folder
|
||||||
*/
|
*/
|
||||||
@Nonnull File worldContainer();
|
@NonNull File worldContainer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Completely shuts down the plugin.
|
* Completely shuts down the plugin.
|
||||||
@ -85,7 +85,8 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @return Plugin name
|
* @return Plugin name
|
||||||
*/
|
*/
|
||||||
@Nonnull default String pluginName() {
|
@NonNull
|
||||||
|
default String pluginName() {
|
||||||
return "PlotSquared";
|
return "PlotSquared";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,21 +95,21 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @return server version as array of numbers
|
* @return server version as array of numbers
|
||||||
*/
|
*/
|
||||||
@Nonnull int[] serverVersion();
|
int[] serverVersion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the server implementation name and version
|
* Gets the server implementation name and version
|
||||||
*
|
*
|
||||||
* @return server implementation and version as string
|
* @return server implementation and version as string
|
||||||
*/
|
*/
|
||||||
@Nonnull String serverImplementation();
|
@NonNull String serverImplementation();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the native server code package prefix.
|
* Gets the native server code package prefix.
|
||||||
*
|
*
|
||||||
* @return The package prefix
|
* @return The package prefix
|
||||||
*/
|
*/
|
||||||
@Nonnull String serverNativePackage();
|
@NonNull String serverNativePackage();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start Metrics.
|
* Start Metrics.
|
||||||
@ -120,14 +121,14 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @param world The world to set the generator
|
* @param world The world to set the generator
|
||||||
*/
|
*/
|
||||||
void setGenerator(String world);
|
void setGenerator(@NonNull String world);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters a {@link PlotPlayer} from cache e.g. if they have logged off.
|
* Unregisters a {@link PlotPlayer} from cache e.g. if they have logged off.
|
||||||
*
|
*
|
||||||
* @param player the player to remove
|
* @param player the player to remove
|
||||||
*/
|
*/
|
||||||
void unregister(PlotPlayer<?> player);
|
void unregister(@NonNull PlotPlayer<?> player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the generator wrapper for a world (world) and generator (name).
|
* Gets the generator wrapper for a world (world) and generator (name).
|
||||||
@ -136,7 +137,10 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
* @param name The name of the generator
|
* @param name The name of the generator
|
||||||
* @return The generator being used for the provided world
|
* @return The generator being used for the provided world
|
||||||
*/
|
*/
|
||||||
@Nullable GeneratorWrapper<?> getGenerator(@Nonnull String world, @Nullable String name);
|
@Nullable GeneratorWrapper<?> getGenerator(
|
||||||
|
@NonNull String world,
|
||||||
|
@Nullable String name
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a platform generator from a plot generator
|
* Create a platform generator from a plot generator
|
||||||
@ -145,14 +149,17 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
* @param generator Plot generator
|
* @param generator Plot generator
|
||||||
* @return Platform generator wrapper
|
* @return Platform generator wrapper
|
||||||
*/
|
*/
|
||||||
@Nonnull GeneratorWrapper<?> wrapPlotGenerator(@Nonnull String world, @Nonnull IndependentPlotGenerator generator);
|
@NonNull GeneratorWrapper<?> wrapPlotGenerator(
|
||||||
|
@NonNull String world,
|
||||||
|
@NonNull IndependentPlotGenerator generator
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Usually HybridGen
|
* Usually HybridGen
|
||||||
*
|
*
|
||||||
* @return Default implementation generator
|
* @return Default implementation generator
|
||||||
*/
|
*/
|
||||||
@Nonnull default IndependentPlotGenerator defaultGenerator() {
|
default @NonNull IndependentPlotGenerator defaultGenerator() {
|
||||||
return injector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class));
|
return injector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +168,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @return Backup manager
|
* @return Backup manager
|
||||||
*/
|
*/
|
||||||
@Nonnull default BackupManager backupManager() {
|
default @NonNull BackupManager backupManager() {
|
||||||
return injector().getInstance(BackupManager.class);
|
return injector().getInstance(BackupManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +177,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @return World manager
|
* @return World manager
|
||||||
*/
|
*/
|
||||||
@Nonnull default PlatformWorldManager<?> worldManager() {
|
default @NonNull PlatformWorldManager<?> worldManager() {
|
||||||
return injector().getInstance(PlatformWorldManager.class);
|
return injector().getInstance(PlatformWorldManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,8 +186,9 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @return Player manager
|
* @return Player manager
|
||||||
*/
|
*/
|
||||||
@Nonnull default PlayerManager<? extends PlotPlayer<P>, ? extends P> playerManager() {
|
default @NonNull PlayerManager<? extends PlotPlayer<P>, ? extends P> playerManager() {
|
||||||
return injector().getInstance(Key.get(new TypeLiteral<PlayerManager<? extends PlotPlayer<P>, ? extends P>>() {}));
|
return injector().getInstance(Key.get(new TypeLiteral<PlayerManager<? extends PlotPlayer<P>, ? extends P>>() {
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -189,21 +197,21 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
* @param worldName World name
|
* @param worldName World name
|
||||||
* @return Platform world wrapper
|
* @return Platform world wrapper
|
||||||
*/
|
*/
|
||||||
@Nullable World<?> getPlatformWorld(@Nonnull final String worldName);
|
@Nullable World<?> getPlatformWorld(@NonNull String worldName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the {@link com.google.inject.Injector} instance used by PlotSquared
|
* Get the {@link com.google.inject.Injector} instance used by PlotSquared
|
||||||
*
|
*
|
||||||
* @return Injector instance
|
* @return Injector instance
|
||||||
*/
|
*/
|
||||||
@Nonnull Injector injector();
|
@NonNull Injector injector();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the world utility implementation
|
* Get the world utility implementation
|
||||||
*
|
*
|
||||||
* @return World utility
|
* @return World utility
|
||||||
*/
|
*/
|
||||||
@Nonnull default WorldUtil worldUtil() {
|
default @NonNull WorldUtil worldUtil() {
|
||||||
return injector().getInstance(WorldUtil.class);
|
return injector().getInstance(WorldUtil.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +220,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @return Global block queue implementation
|
* @return Global block queue implementation
|
||||||
*/
|
*/
|
||||||
@Nonnull default GlobalBlockQueue globalBlockQueue() {
|
default @NonNull GlobalBlockQueue globalBlockQueue() {
|
||||||
return injector().getInstance(GlobalBlockQueue.class);
|
return injector().getInstance(GlobalBlockQueue.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +229,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @return Hybrid utils
|
* @return Hybrid utils
|
||||||
*/
|
*/
|
||||||
@Nonnull default HybridUtils hybridUtils() {
|
default @NonNull HybridUtils hybridUtils() {
|
||||||
return injector().getInstance(HybridUtils.class);
|
return injector().getInstance(HybridUtils.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,16 +238,16 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @return Setup utils
|
* @return Setup utils
|
||||||
*/
|
*/
|
||||||
@Nonnull default SetupUtils setupUtils() {
|
default @NonNull SetupUtils setupUtils() {
|
||||||
return injector().getInstance(SetupUtils.class);
|
return injector().getInstance(SetupUtils.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the {@link EconHandler} implementation for the platform
|
* Get the {@link EconHandler} implementation for the platform
|
||||||
* *
|
*
|
||||||
* @return Econ handler
|
* @return Econ handler
|
||||||
*/
|
*/
|
||||||
@Nonnull default EconHandler econHandler() {
|
default @NonNull EconHandler econHandler() {
|
||||||
return injector().getInstance(EconHandler.class);
|
return injector().getInstance(EconHandler.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,7 +256,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @return Region manager
|
* @return Region manager
|
||||||
*/
|
*/
|
||||||
@Nonnull default RegionManager regionManager() {
|
default @NonNull RegionManager regionManager() {
|
||||||
return injector().getInstance(RegionManager.class);
|
return injector().getInstance(RegionManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,7 +265,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @return Region manager
|
* @return Region manager
|
||||||
*/
|
*/
|
||||||
@Nonnull default ChunkManager chunkManager() {
|
default @NonNull ChunkManager chunkManager() {
|
||||||
return injector().getInstance(ChunkManager.class);
|
return injector().getInstance(ChunkManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,7 +274,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @return Console audience
|
* @return Console audience
|
||||||
*/
|
*/
|
||||||
@Nonnull Audience consoleAudience();
|
@NonNull Audience consoleAudience();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a formatted string containing all plugins on the server together
|
* Get a formatted string containing all plugins on the server together
|
||||||
@ -274,7 +282,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @return Formatted string
|
* @return Formatted string
|
||||||
*/
|
*/
|
||||||
@Nonnull String pluginsFormatted();
|
@NonNull String pluginsFormatted();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the caption maps
|
* Load the caption maps
|
||||||
@ -286,7 +294,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @return Permission handler
|
* @return Permission handler
|
||||||
*/
|
*/
|
||||||
@Nonnull default PermissionHandler permissionHandler() {
|
default @NonNull PermissionHandler permissionHandler() {
|
||||||
return injector().getInstance(PermissionHandler.class);
|
return injector().getInstance(PermissionHandler.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,7 +303,7 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @return Service pipeline
|
* @return Service pipeline
|
||||||
*/
|
*/
|
||||||
@Nonnull default ServicePipeline servicePipeline() {
|
default @NonNull ServicePipeline servicePipeline() {
|
||||||
return injector().getInstance(ServicePipeline.class);
|
return injector().getInstance(ServicePipeline.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,10 +312,10 @@ public interface PlotPlatform<P> extends LocaleHolder {
|
|||||||
*
|
*
|
||||||
* @return Placeholder registry
|
* @return Placeholder registry
|
||||||
*/
|
*/
|
||||||
@Nonnull default PlaceholderRegistry placeholderRegistry() {
|
default @NonNull PlaceholderRegistry placeholderRegistry() {
|
||||||
return injector().getInstance(PlaceholderRegistry.class);
|
return injector().getInstance(PlaceholderRegistry.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull String toLegacyPlatformString(Component component);
|
@NonNull String toLegacyPlatformString(Component component);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,10 @@ import com.plotsquared.core.configuration.ConfigurationUtil;
|
|||||||
import com.plotsquared.core.configuration.MemorySection;
|
import com.plotsquared.core.configuration.MemorySection;
|
||||||
import com.plotsquared.core.configuration.Settings;
|
import com.plotsquared.core.configuration.Settings;
|
||||||
import com.plotsquared.core.configuration.Storage;
|
import com.plotsquared.core.configuration.Storage;
|
||||||
import com.plotsquared.core.configuration.caption.load.CaptionLoader;
|
|
||||||
import com.plotsquared.core.configuration.caption.CaptionMap;
|
import com.plotsquared.core.configuration.caption.CaptionMap;
|
||||||
import com.plotsquared.core.configuration.caption.DummyCaptionMap;
|
import com.plotsquared.core.configuration.caption.DummyCaptionMap;
|
||||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||||
|
import com.plotsquared.core.configuration.caption.load.CaptionLoader;
|
||||||
import com.plotsquared.core.configuration.caption.load.DefaultCaptionProvider;
|
import com.plotsquared.core.configuration.caption.load.DefaultCaptionProvider;
|
||||||
import com.plotsquared.core.configuration.file.YamlConfiguration;
|
import com.plotsquared.core.configuration.file.YamlConfiguration;
|
||||||
import com.plotsquared.core.configuration.serialization.ConfigurationSerialization;
|
import com.plotsquared.core.configuration.serialization.ConfigurationSerialization;
|
||||||
@ -73,10 +73,12 @@ import com.plotsquared.core.util.task.TaskManager;
|
|||||||
import com.plotsquared.core.uuid.UUIDPipeline;
|
import com.plotsquared.core.uuid.UUIDPipeline;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.math.BlockVector2;
|
import com.sk89q.worldedit.math.BlockVector2;
|
||||||
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@ -120,7 +122,7 @@ import java.util.zip.ZipInputStream;
|
|||||||
public class PlotSquared {
|
public class PlotSquared {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotSquared.class.getSimpleName());
|
private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotSquared.class.getSimpleName());
|
||||||
private static PlotSquared instance;
|
private static @MonotonicNonNull PlotSquared instance;
|
||||||
|
|
||||||
// Implementation
|
// Implementation
|
||||||
private final PlotPlatform<?> platform;
|
private final PlotPlatform<?> platform;
|
||||||
@ -128,9 +130,13 @@ public class PlotSquared {
|
|||||||
private final Thread thread;
|
private final Thread thread;
|
||||||
// UUID pipelines
|
// UUID pipelines
|
||||||
private final UUIDPipeline impromptuUUIDPipeline =
|
private final UUIDPipeline impromptuUUIDPipeline =
|
||||||
new UUIDPipeline(Executors.newCachedThreadPool());
|
new UUIDPipeline(Executors.newCachedThreadPool());
|
||||||
private final UUIDPipeline backgroundUUIDPipeline =
|
private final UUIDPipeline backgroundUUIDPipeline =
|
||||||
new UUIDPipeline(Executors.newSingleThreadExecutor());
|
new UUIDPipeline(Executors.newSingleThreadExecutor());
|
||||||
|
// Localization
|
||||||
|
private final CaptionLoader captionLoader;
|
||||||
|
private final Map<String, CaptionMap> captionMaps = new HashMap<>();
|
||||||
|
public HashMap<String, HashMap<PlotId, Plot>> plots_tmp;
|
||||||
// WorldEdit instance
|
// WorldEdit instance
|
||||||
private WorldEdit worldedit;
|
private WorldEdit worldedit;
|
||||||
private File configFile;
|
private File configFile;
|
||||||
@ -138,11 +144,7 @@ public class PlotSquared {
|
|||||||
private YamlConfiguration worldConfiguration;
|
private YamlConfiguration worldConfiguration;
|
||||||
// Temporary hold the plots/clusters before the worlds load
|
// Temporary hold the plots/clusters before the worlds load
|
||||||
private HashMap<String, Set<PlotCluster>> clustersTmp;
|
private HashMap<String, Set<PlotCluster>> clustersTmp;
|
||||||
public HashMap<String, HashMap<PlotId, Plot>> plots_tmp;
|
|
||||||
private YamlConfiguration config;
|
private YamlConfiguration config;
|
||||||
// Localization
|
|
||||||
private final CaptionLoader captionLoader;
|
|
||||||
private final Map<String, CaptionMap> captionMaps = new HashMap<>();
|
|
||||||
// Platform / Version / Update URL
|
// Platform / Version / Update URL
|
||||||
private PlotVersion version;
|
private PlotVersion version;
|
||||||
// Files and configuration
|
// Files and configuration
|
||||||
@ -157,7 +159,10 @@ public class PlotSquared {
|
|||||||
* @param iPlotMain Implementation of {@link PlotPlatform} used
|
* @param iPlotMain Implementation of {@link PlotPlatform} used
|
||||||
* @param platform The platform being used
|
* @param platform The platform being used
|
||||||
*/
|
*/
|
||||||
public PlotSquared(final PlotPlatform<?> iPlotMain, final String platform) {
|
public PlotSquared(
|
||||||
|
final @NonNull PlotPlatform<?> iPlotMain,
|
||||||
|
final @NonNull String platform
|
||||||
|
) {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
throw new IllegalStateException("Cannot re-initialize the PlotSquared singleton");
|
throw new IllegalStateException("Cannot re-initialize the PlotSquared singleton");
|
||||||
}
|
}
|
||||||
@ -175,10 +180,14 @@ public class PlotSquared {
|
|||||||
//
|
//
|
||||||
ConfigurationSerialization.registerClass(BlockBucket.class, "BlockBucket");
|
ConfigurationSerialization.registerClass(BlockBucket.class, "BlockBucket");
|
||||||
|
|
||||||
this.captionLoader = CaptionLoader.of(Locale.ENGLISH,
|
this.captionLoader = CaptionLoader.of(
|
||||||
|
Locale.ENGLISH,
|
||||||
CaptionLoader.patternExtractor(Pattern.compile("messages_(.*)\\.json")),
|
CaptionLoader.patternExtractor(Pattern.compile("messages_(.*)\\.json")),
|
||||||
DefaultCaptionProvider.forClassLoaderFormatString(this.getClass().getClassLoader(),
|
DefaultCaptionProvider.forClassLoaderFormatString(
|
||||||
"lang/messages_%s.json")); // the path in our jar file
|
this.getClass().getClassLoader(),
|
||||||
|
"lang/messages_%s.json"
|
||||||
|
)
|
||||||
|
); // the path in our jar file
|
||||||
// Load caption map
|
// Load caption map
|
||||||
try {
|
try {
|
||||||
this.loadCaptionMap();
|
this.loadCaptionMap();
|
||||||
@ -194,14 +203,16 @@ public class PlotSquared {
|
|||||||
try {
|
try {
|
||||||
URL logurl = PlotSquared.class.getProtectionDomain().getCodeSource().getLocation();
|
URL logurl = PlotSquared.class.getProtectionDomain().getCodeSource().getLocation();
|
||||||
this.jarFile = new File(
|
this.jarFile = new File(
|
||||||
new URL(logurl.toURI().toString().split("\\!")[0].replaceAll("jar:file", "file"))
|
new URL(logurl.toURI().toString().split("\\!")[0].replaceAll("jar:file", "file"))
|
||||||
.toURI().getPath());
|
.toURI().getPath());
|
||||||
} catch (MalformedURLException | URISyntaxException | SecurityException e) {
|
} catch (MalformedURLException | URISyntaxException | SecurityException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
this.jarFile = new File(this.platform.getDirectory().getParentFile(), "PlotSquared.jar");
|
this.jarFile = new File(this.platform.getDirectory().getParentFile(), "PlotSquared.jar");
|
||||||
if (!this.jarFile.exists()) {
|
if (!this.jarFile.exists()) {
|
||||||
this.jarFile = new File(this.platform.getDirectory().getParentFile(),
|
this.jarFile = new File(
|
||||||
"PlotSquared-" + platform + ".jar");
|
this.platform.getDirectory().getParentFile(),
|
||||||
|
"PlotSquared-" + platform + ".jar"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,6 +245,27 @@ public class PlotSquared {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an instance of PlotSquared.
|
||||||
|
*
|
||||||
|
* @return instance of PlotSquared
|
||||||
|
*/
|
||||||
|
public static @NonNull PlotSquared get() {
|
||||||
|
return PlotSquared.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the platform specific implementation of PlotSquared
|
||||||
|
*
|
||||||
|
* @return Platform implementation
|
||||||
|
*/
|
||||||
|
public static @NonNull PlotPlatform<?> platform() {
|
||||||
|
if (instance != null && instance.platform != null) {
|
||||||
|
return instance.platform;
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Plot platform implementation is missing");
|
||||||
|
}
|
||||||
|
|
||||||
public void loadCaptionMap() throws Exception {
|
public void loadCaptionMap() throws Exception {
|
||||||
this.platform.copyCaptionMaps();
|
this.platform.copyCaptionMaps();
|
||||||
// Setup localization
|
// Setup localization
|
||||||
@ -245,8 +277,10 @@ public class PlotSquared {
|
|||||||
captionMap = this.captionLoader.loadSingle(this.platform.getDirectory().toPath().resolve("lang").resolve(fileName));
|
captionMap = this.captionLoader.loadSingle(this.platform.getDirectory().toPath().resolve("lang").resolve(fileName));
|
||||||
}
|
}
|
||||||
this.captionMaps.put(TranslatableCaption.DEFAULT_NAMESPACE, captionMap);
|
this.captionMaps.put(TranslatableCaption.DEFAULT_NAMESPACE, captionMap);
|
||||||
logger.info("Loaded caption map for namespace 'plotsquared': {}",
|
logger.info(
|
||||||
this.captionMaps.get(TranslatableCaption.DEFAULT_NAMESPACE).getClass().getCanonicalName());
|
"Loaded caption map for namespace 'plotsquared': {}",
|
||||||
|
this.captionMaps.get(TranslatableCaption.DEFAULT_NAMESPACE).getClass().getCanonicalName()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -254,31 +288,10 @@ public class PlotSquared {
|
|||||||
*
|
*
|
||||||
* @return Plot area manager
|
* @return Plot area manager
|
||||||
*/
|
*/
|
||||||
@Nonnull public PlotAreaManager getPlotAreaManager() {
|
public @NonNull PlotAreaManager getPlotAreaManager() {
|
||||||
return this.platform.injector().getInstance(PlotAreaManager.class);
|
return this.platform.injector().getInstance(PlotAreaManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets an instance of PlotSquared.
|
|
||||||
*
|
|
||||||
* @return instance of PlotSquared
|
|
||||||
*/
|
|
||||||
public static PlotSquared get() {
|
|
||||||
return PlotSquared.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the platform specific implementation of PlotSquared
|
|
||||||
*
|
|
||||||
* @return Platform implementation
|
|
||||||
*/
|
|
||||||
@Nonnull public static PlotPlatform<?> platform() {
|
|
||||||
if (instance != null && instance.platform != null) {
|
|
||||||
return instance.platform;
|
|
||||||
}
|
|
||||||
throw new IllegalStateException("Plot platform implementation is missing");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startExpiryTasks() {
|
public void startExpiryTasks() {
|
||||||
if (Settings.Enabled_Components.PLOT_EXPIRY) {
|
if (Settings.Enabled_Components.PLOT_EXPIRY) {
|
||||||
ExpireManager.IMP = new ExpireManager(this.eventDispatcher);
|
ExpireManager.IMP = new ExpireManager(this.eventDispatcher);
|
||||||
@ -290,7 +303,7 @@ public class PlotSquared {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMainThread(Thread thread) {
|
public boolean isMainThread(final @NonNull Thread thread) {
|
||||||
return this.thread == thread;
|
return this.thread == thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,9 +314,12 @@ public class PlotSquared {
|
|||||||
* @param version2 Second version
|
* @param version2 Second version
|
||||||
* @return true if `version` is >= `version2`
|
* @return true if `version` is >= `version2`
|
||||||
*/
|
*/
|
||||||
public boolean checkVersion(int[] version, int... version2) {
|
public boolean checkVersion(
|
||||||
|
final int[] version,
|
||||||
|
final int... version2
|
||||||
|
) {
|
||||||
return version[0] > version2[0] || version[0] == version2[0] && version[1] > version2[1]
|
return version[0] > version2[0] || version[0] == version2[0] && version[1] > version2[1]
|
||||||
|| version[0] == version2[0] && version[1] == version2[1] && version[2] >= version2[2];
|
|| version[0] == version2[0] && version[1] == version2[1] && version[2] >= version2[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -311,7 +327,7 @@ public class PlotSquared {
|
|||||||
*
|
*
|
||||||
* @return current version in config or null
|
* @return current version in config or null
|
||||||
*/
|
*/
|
||||||
public PlotVersion getVersion() {
|
public @NonNull PlotVersion getVersion() {
|
||||||
return this.version;
|
return this.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,7 +338,7 @@ public class PlotSquared {
|
|||||||
*
|
*
|
||||||
* @return the server implementation
|
* @return the server implementation
|
||||||
*/
|
*/
|
||||||
public String getPlatform() {
|
public @NonNull String getPlatform() {
|
||||||
return Settings.PLATFORM;
|
return Settings.PLATFORM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,7 +348,7 @@ public class PlotSquared {
|
|||||||
* @param plotArea the {@code PlotArea} to add.
|
* @param plotArea the {@code PlotArea} to add.
|
||||||
* @see #removePlotArea(PlotArea) To remove the reference
|
* @see #removePlotArea(PlotArea) To remove the reference
|
||||||
*/
|
*/
|
||||||
public void addPlotArea(PlotArea plotArea) {
|
public void addPlotArea(final @NonNull PlotArea plotArea) {
|
||||||
HashMap<PlotId, Plot> plots;
|
HashMap<PlotId, Plot> plots;
|
||||||
if (plots_tmp == null || (plots = plots_tmp.remove(plotArea.toString())) == null) {
|
if (plots_tmp == null || (plots = plots_tmp.remove(plotArea.toString())) == null) {
|
||||||
if (plotArea.getType() == PlotAreaType.PARTIAL) {
|
if (plotArea.getType() == PlotAreaType.PARTIAL) {
|
||||||
@ -358,8 +374,8 @@ public class PlotSquared {
|
|||||||
if (clustersTmp == null || (clusters = clustersTmp.remove(plotArea.toString())) == null) {
|
if (clustersTmp == null || (clusters = clustersTmp.remove(plotArea.toString())) == null) {
|
||||||
if (plotArea.getType() == PlotAreaType.PARTIAL) {
|
if (plotArea.getType() == PlotAreaType.PARTIAL) {
|
||||||
clusters = this.clustersTmp != null ?
|
clusters = this.clustersTmp != null ?
|
||||||
this.clustersTmp.get(plotArea.getWorldName()) :
|
this.clustersTmp.get(plotArea.getWorldName()) :
|
||||||
null;
|
null;
|
||||||
if (clusters != null) {
|
if (clusters != null) {
|
||||||
Iterator<PlotCluster> iterator = clusters.iterator();
|
Iterator<PlotCluster> iterator = clusters.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
@ -382,8 +398,8 @@ public class PlotSquared {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File file = new File(
|
File file = new File(
|
||||||
this.platform.getDirectory() + File.separator + "persistent_regen_data_" + plotArea.getId()
|
this.platform.getDirectory() + File.separator + "persistent_regen_data_" + plotArea.getId()
|
||||||
+ "_" + plotArea.getWorldName());
|
+ "_" + plotArea.getWorldName());
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -397,7 +413,11 @@ public class PlotSquared {
|
|||||||
regionInts.forEach(l -> regions.add(BlockVector2.at(l[0], l[1])));
|
regionInts.forEach(l -> regions.add(BlockVector2.at(l[0], l[1])));
|
||||||
chunkInts.forEach(l -> chunks.add(BlockVector2.at(l[0], l[1])));
|
chunkInts.forEach(l -> chunks.add(BlockVector2.at(l[0], l[1])));
|
||||||
int height = (int) list.get(2);
|
int height = (int) list.get(2);
|
||||||
logger.info("Incomplete road regeneration found. Restarting in world {} with height {}", plotArea.getWorldName(), height);
|
logger.info(
|
||||||
|
"Incomplete road regeneration found. Restarting in world {} with height {}",
|
||||||
|
plotArea.getWorldName(),
|
||||||
|
height
|
||||||
|
);
|
||||||
logger.info(" - Regions: {}", regions.size());
|
logger.info(" - Regions: {}", regions.size());
|
||||||
logger.info(" - Chunks: {}", chunks.size());
|
logger.info(" - Chunks: {}", chunks.size());
|
||||||
HybridUtils.UPDATE = true;
|
HybridUtils.UPDATE = true;
|
||||||
@ -417,12 +437,12 @@ public class PlotSquared {
|
|||||||
*
|
*
|
||||||
* @param area the {@code PlotArea} to remove
|
* @param area the {@code PlotArea} to remove
|
||||||
*/
|
*/
|
||||||
public void removePlotArea(PlotArea area) {
|
public void removePlotArea(final @NonNull PlotArea area) {
|
||||||
getPlotAreaManager().removePlotArea(area);
|
getPlotAreaManager().removePlotArea(area);
|
||||||
setPlotsTmp(area);
|
setPlotsTmp(area);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePlotAreas(@Nonnull final String world) {
|
public void removePlotAreas(final @NonNull String world) {
|
||||||
for (final PlotArea area : this.getPlotAreaManager().getPlotAreasSet(world)) {
|
for (final PlotArea area : this.getPlotAreaManager().getPlotAreasSet(world)) {
|
||||||
if (area.getWorldName().equals(world)) {
|
if (area.getWorldName().equals(world)) {
|
||||||
removePlotArea(area);
|
removePlotArea(area);
|
||||||
@ -430,12 +450,12 @@ public class PlotSquared {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPlotsTmp(PlotArea area) {
|
private void setPlotsTmp(final @NonNull PlotArea area) {
|
||||||
if (this.plots_tmp == null) {
|
if (this.plots_tmp == null) {
|
||||||
this.plots_tmp = new HashMap<>();
|
this.plots_tmp = new HashMap<>();
|
||||||
}
|
}
|
||||||
HashMap<PlotId, Plot> map =
|
HashMap<PlotId, Plot> map =
|
||||||
this.plots_tmp.computeIfAbsent(area.toString(), k -> new HashMap<>());
|
this.plots_tmp.computeIfAbsent(area.toString(), k -> new HashMap<>());
|
||||||
for (Plot plot : area.getPlots()) {
|
for (Plot plot : area.getPlots()) {
|
||||||
map.put(plot.getId(), plot);
|
map.put(plot.getId(), plot);
|
||||||
}
|
}
|
||||||
@ -445,7 +465,7 @@ public class PlotSquared {
|
|||||||
this.clustersTmp.put(area.toString(), area.getClusters());
|
this.clustersTmp.put(area.toString(), area.getClusters());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<PlotCluster> getClusters(@Nonnull final String world) {
|
public Set<PlotCluster> getClusters(final @NonNull String world) {
|
||||||
final Set<PlotCluster> set = new HashSet<>();
|
final Set<PlotCluster> set = new HashSet<>();
|
||||||
for (final PlotArea area : this.getPlotAreaManager().getPlotAreasSet(world)) {
|
for (final PlotArea area : this.getPlotAreaManager().getPlotAreasSet(world)) {
|
||||||
set.addAll(area.getClusters());
|
set.addAll(area.getClusters());
|
||||||
@ -542,7 +562,7 @@ public class PlotSquared {
|
|||||||
*
|
*
|
||||||
* @param input an array of plots to sort
|
* @param input an array of plots to sort
|
||||||
*/
|
*/
|
||||||
private void sortPlotsByHash(Plot[] input) {
|
private void sortPlotsByHash(final @NonNull Plot @NonNull[] input) {
|
||||||
List<Plot>[] bucket = new ArrayList[32];
|
List<Plot>[] bucket = new ArrayList[32];
|
||||||
Arrays.fill(bucket, new ArrayList<>());
|
Arrays.fill(bucket, new ArrayList<>());
|
||||||
boolean maxLength = false;
|
boolean maxLength = false;
|
||||||
@ -567,11 +587,11 @@ public class PlotSquared {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<Plot> sortPlotsByTimestamp(Collection<Plot> plots) {
|
private @NonNull List<Plot> sortPlotsByTimestamp(final @NonNull Collection<Plot> plots) {
|
||||||
int hardMax = 256000;
|
int hardMax = 256000;
|
||||||
int max = 0;
|
int max = 0;
|
||||||
int overflowSize = 0;
|
int overflowSize = 0;
|
||||||
for (Plot plot : plots) {
|
for (final Plot plot : plots) {
|
||||||
int hash = MathMan.getPositiveId(plot.hashCode());
|
int hash = MathMan.getPositiveId(plot.hashCode());
|
||||||
if (hash > max) {
|
if (hash > max) {
|
||||||
if (hash >= hardMax) {
|
if (hash >= hardMax) {
|
||||||
@ -615,10 +635,10 @@ public class PlotSquared {
|
|||||||
/**
|
/**
|
||||||
* Sort plots by creation timestamp.
|
* Sort plots by creation timestamp.
|
||||||
*
|
*
|
||||||
* @param input
|
* @param input Plots to sort
|
||||||
* @return
|
* @return Sorted list
|
||||||
*/
|
*/
|
||||||
private List<Plot> sortPlotsByModified(Collection<Plot> input) {
|
private @NonNull List<Plot> sortPlotsByModified(final @NonNull Collection<Plot> input) {
|
||||||
List<Plot> list;
|
List<Plot> list;
|
||||||
if (input instanceof List) {
|
if (input instanceof List) {
|
||||||
list = (List<Plot>) input;
|
list = (List<Plot>) input;
|
||||||
@ -639,8 +659,11 @@ public class PlotSquared {
|
|||||||
* want default world order
|
* want default world order
|
||||||
* @return ArrayList of plot
|
* @return ArrayList of plot
|
||||||
*/
|
*/
|
||||||
public ArrayList<Plot> sortPlots(Collection<Plot> plots, SortType type,
|
public @NonNull List<Plot> sortPlots(
|
||||||
final PlotArea priorityArea) {
|
final @NonNull Collection<Plot> plots,
|
||||||
|
final @NonNull SortType type,
|
||||||
|
final @Nullable PlotArea priorityArea
|
||||||
|
) {
|
||||||
// group by world
|
// group by world
|
||||||
// sort each
|
// sort each
|
||||||
HashMap<PlotArea, Collection<Plot>> map = new HashMap<>();
|
HashMap<PlotArea, Collection<Plot>> map = new HashMap<>();
|
||||||
@ -698,7 +721,7 @@ public class PlotSquared {
|
|||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlots(@Nonnull final Map<String, HashMap<PlotId, Plot>> plots) {
|
public void setPlots(final @NonNull Map<String, HashMap<PlotId, Plot>> plots) {
|
||||||
if (this.plots_tmp == null) {
|
if (this.plots_tmp == null) {
|
||||||
this.plots_tmp = new HashMap<>();
|
this.plots_tmp = new HashMap<>();
|
||||||
}
|
}
|
||||||
@ -724,7 +747,10 @@ public class PlotSquared {
|
|||||||
* @param callEvent If to call an event about the plot being removed
|
* @param callEvent If to call an event about the plot being removed
|
||||||
* @return true if plot existed | false if it didn't
|
* @return true if plot existed | false if it didn't
|
||||||
*/
|
*/
|
||||||
public boolean removePlot(Plot plot, boolean callEvent) {
|
public boolean removePlot(
|
||||||
|
final @NonNull Plot plot,
|
||||||
|
final boolean callEvent
|
||||||
|
) {
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -761,7 +787,10 @@ public class PlotSquared {
|
|||||||
* @param world the world to load
|
* @param world the world to load
|
||||||
* @param baseGenerator The generator for that world, or null
|
* @param baseGenerator The generator for that world, or null
|
||||||
*/
|
*/
|
||||||
public void loadWorld(String world, GeneratorWrapper<?> baseGenerator) {
|
public void loadWorld(
|
||||||
|
final @NonNull String world,
|
||||||
|
final @Nullable GeneratorWrapper<?> baseGenerator
|
||||||
|
) {
|
||||||
if (world.equals("CheckingPlotSquaredGenerator")) {
|
if (world.equals("CheckingPlotSquaredGenerator")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -790,13 +819,13 @@ public class PlotSquared {
|
|||||||
} else if (worldSection != null) {
|
} else if (worldSection != null) {
|
||||||
String secondaryGeneratorName = worldSection.getString("generator.plugin");
|
String secondaryGeneratorName = worldSection.getString("generator.plugin");
|
||||||
GeneratorWrapper<?> secondaryGenerator =
|
GeneratorWrapper<?> secondaryGenerator =
|
||||||
this.platform.getGenerator(world, secondaryGeneratorName);
|
this.platform.getGenerator(world, secondaryGeneratorName);
|
||||||
if (secondaryGenerator != null && secondaryGenerator.isFull()) {
|
if (secondaryGenerator != null && secondaryGenerator.isFull()) {
|
||||||
plotGenerator = secondaryGenerator.getPlotGenerator();
|
plotGenerator = secondaryGenerator.getPlotGenerator();
|
||||||
} else {
|
} else {
|
||||||
String primaryGeneratorName = worldSection.getString("generator.init");
|
String primaryGeneratorName = worldSection.getString("generator.init");
|
||||||
GeneratorWrapper<?> primaryGenerator =
|
GeneratorWrapper<?> primaryGenerator =
|
||||||
this.platform.getGenerator(world, primaryGeneratorName);
|
this.platform.getGenerator(world, primaryGeneratorName);
|
||||||
if (primaryGenerator != null && primaryGenerator.isFull()) {
|
if (primaryGenerator != null && primaryGenerator.isFull()) {
|
||||||
plotGenerator = primaryGenerator.getPlotGenerator();
|
plotGenerator = primaryGenerator.getPlotGenerator();
|
||||||
} else {
|
} else {
|
||||||
@ -840,7 +869,7 @@ public class PlotSquared {
|
|||||||
String gen_string = worldSection.getString("generator.plugin", platform.pluginName());
|
String gen_string = worldSection.getString("generator.plugin", platform.pluginName());
|
||||||
if (type == PlotAreaType.PARTIAL) {
|
if (type == PlotAreaType.PARTIAL) {
|
||||||
Set<PlotCluster> clusters =
|
Set<PlotCluster> clusters =
|
||||||
this.clustersTmp != null ? this.clustersTmp.get(world) : new HashSet<>();
|
this.clustersTmp != null ? this.clustersTmp.get(world) : new HashSet<>();
|
||||||
if (clusters == null) {
|
if (clusters == null) {
|
||||||
throw new IllegalArgumentException("No cluster exists for world: " + world);
|
throw new IllegalArgumentException("No cluster exists for world: " + world);
|
||||||
}
|
}
|
||||||
@ -858,7 +887,7 @@ public class PlotSquared {
|
|||||||
throw new IllegalArgumentException("Invalid Generator: " + gen_string);
|
throw new IllegalArgumentException("Invalid Generator: " + gen_string);
|
||||||
}
|
}
|
||||||
PlotArea pa =
|
PlotArea pa =
|
||||||
areaGen.getPlotGenerator().getNewPlotArea(world, name, pos1, pos2);
|
areaGen.getPlotGenerator().getNewPlotArea(world, name, pos1, pos2);
|
||||||
pa.saveConfiguration(worldSection);
|
pa.saveConfiguration(worldSection);
|
||||||
pa.loadDefaultConfiguration(worldSection);
|
pa.loadDefaultConfiguration(worldSection);
|
||||||
try {
|
try {
|
||||||
@ -901,22 +930,22 @@ public class PlotSquared {
|
|||||||
}
|
}
|
||||||
if (type == PlotAreaType.AUGMENTED) {
|
if (type == PlotAreaType.AUGMENTED) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Invalid type for multi-area world. Expected `PARTIAL`, got `"
|
"Invalid type for multi-area world. Expected `PARTIAL`, got `"
|
||||||
+ PlotAreaType.AUGMENTED + "`");
|
+ PlotAreaType.AUGMENTED + "`");
|
||||||
}
|
}
|
||||||
for (String areaId : areasSection.getKeys(false)) {
|
for (String areaId : areasSection.getKeys(false)) {
|
||||||
logger.info(" - {}", areaId);
|
logger.info(" - {}", areaId);
|
||||||
String[] split = areaId.split("(?<=[^;-])-");
|
String[] split = areaId.split("(?<=[^;-])-");
|
||||||
if (split.length != 3) {
|
if (split.length != 3) {
|
||||||
throw new IllegalArgumentException("Invalid Area identifier: " + areaId
|
throw new IllegalArgumentException("Invalid Area identifier: " + areaId
|
||||||
+ ". Expected form `<name>-<pos1>-<pos2>`");
|
+ ". Expected form `<name>-<pos1>-<pos2>`");
|
||||||
}
|
}
|
||||||
String name = split[0];
|
String name = split[0];
|
||||||
PlotId pos1 = PlotId.fromString(split[1]);
|
PlotId pos1 = PlotId.fromString(split[1]);
|
||||||
PlotId pos2 = PlotId.fromString(split[2]);
|
PlotId pos2 = PlotId.fromString(split[2]);
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
throw new IllegalArgumentException("Invalid Area identifier: " + areaId
|
throw new IllegalArgumentException("Invalid Area identifier: " + areaId
|
||||||
+ ". Expected form `<name>-<x1;z1>-<x2;z2>`");
|
+ ". Expected form `<name>-<x1;z1>-<x2;z2>`");
|
||||||
}
|
}
|
||||||
final PlotArea existing = this.getPlotAreaManager().getPlotArea(world, name);
|
final PlotArea existing = this.getPlotAreaManager().getPlotArea(world, name);
|
||||||
if (existing != null && name.equals(existing.getId())) {
|
if (existing != null && name.equals(existing.getId())) {
|
||||||
@ -989,18 +1018,23 @@ public class PlotSquared {
|
|||||||
* @param generator the plot generator
|
* @param generator the plot generator
|
||||||
* @return boolean | if valid arguments were provided
|
* @return boolean | if valid arguments were provided
|
||||||
*/
|
*/
|
||||||
public boolean setupPlotWorld(String world, String args, IndependentPlotGenerator generator) {
|
public boolean setupPlotWorld(
|
||||||
|
final @NonNull String world,
|
||||||
|
final @Nullable String args,
|
||||||
|
final @NonNull IndependentPlotGenerator generator
|
||||||
|
) {
|
||||||
if (args != null && !args.isEmpty()) {
|
if (args != null && !args.isEmpty()) {
|
||||||
// save configuration
|
// save configuration
|
||||||
|
|
||||||
final List<String> validArguments = Arrays
|
final List<String> validArguments = Arrays
|
||||||
.asList("s=", "size=", "g=", "gap=", "h=", "height=", "f=", "floor=", "m=", "main=",
|
.asList("s=", "size=", "g=", "gap=", "h=", "height=", "f=", "floor=", "m=", "main=",
|
||||||
"w=", "wall=", "b=", "border=");
|
"w=", "wall=", "b=", "border="
|
||||||
|
);
|
||||||
|
|
||||||
// Calculate the number of expected arguments
|
// Calculate the number of expected arguments
|
||||||
int expected = (int) validArguments.stream()
|
int expected = (int) validArguments.stream()
|
||||||
.filter(validArgument -> args.toLowerCase(Locale.ENGLISH).contains(validArgument))
|
.filter(validArgument -> args.toLowerCase(Locale.ENGLISH).contains(validArgument))
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
String[] split = args.toLowerCase(Locale.ENGLISH).split(",(?![^\\(\\[]*[\\]\\)])");
|
String[] split = args.toLowerCase(Locale.ENGLISH).split(",(?![^\\(\\[]*[\\]\\)])");
|
||||||
|
|
||||||
@ -1035,7 +1069,9 @@ public class PlotSquared {
|
|||||||
split = combinedArgs;
|
split = combinedArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
final HybridPlotWorldFactory hybridPlotWorldFactory = this.platform.injector().getInstance(HybridPlotWorldFactory.class);
|
final HybridPlotWorldFactory hybridPlotWorldFactory = this.platform
|
||||||
|
.injector()
|
||||||
|
.getInstance(HybridPlotWorldFactory.class);
|
||||||
final HybridPlotWorld plotWorld = hybridPlotWorldFactory.create(world, null, generator, null, null);
|
final HybridPlotWorld plotWorld = hybridPlotWorldFactory.create(world, null, generator, null, null);
|
||||||
|
|
||||||
for (String element : split) {
|
for (String element : split) {
|
||||||
@ -1051,42 +1087,60 @@ public class PlotSquared {
|
|||||||
switch (key) {
|
switch (key) {
|
||||||
case "s":
|
case "s":
|
||||||
case "size":
|
case "size":
|
||||||
this.worldConfiguration.set(base + "plot.size",
|
this.worldConfiguration.set(
|
||||||
ConfigurationUtil.INTEGER.parseString(value).shortValue());
|
base + "plot.size",
|
||||||
|
ConfigurationUtil.INTEGER.parseString(value).shortValue()
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "g":
|
case "g":
|
||||||
case "gap":
|
case "gap":
|
||||||
this.worldConfiguration.set(base + "road.width",
|
this.worldConfiguration.set(
|
||||||
ConfigurationUtil.INTEGER.parseString(value).shortValue());
|
base + "road.width",
|
||||||
|
ConfigurationUtil.INTEGER.parseString(value).shortValue()
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "h":
|
case "h":
|
||||||
case "height":
|
case "height":
|
||||||
this.worldConfiguration.set(base + "road.height",
|
this.worldConfiguration.set(
|
||||||
ConfigurationUtil.INTEGER.parseString(value).shortValue());
|
base + "road.height",
|
||||||
this.worldConfiguration.set(base + "plot.height",
|
ConfigurationUtil.INTEGER.parseString(value).shortValue()
|
||||||
ConfigurationUtil.INTEGER.parseString(value).shortValue());
|
);
|
||||||
this.worldConfiguration.set(base + "wall.height",
|
this.worldConfiguration.set(
|
||||||
ConfigurationUtil.INTEGER.parseString(value).shortValue());
|
base + "plot.height",
|
||||||
|
ConfigurationUtil.INTEGER.parseString(value).shortValue()
|
||||||
|
);
|
||||||
|
this.worldConfiguration.set(
|
||||||
|
base + "wall.height",
|
||||||
|
ConfigurationUtil.INTEGER.parseString(value).shortValue()
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "f":
|
case "f":
|
||||||
case "floor":
|
case "floor":
|
||||||
this.worldConfiguration.set(base + "plot.floor",
|
this.worldConfiguration.set(
|
||||||
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString());
|
base + "plot.floor",
|
||||||
|
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString()
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "m":
|
case "m":
|
||||||
case "main":
|
case "main":
|
||||||
this.worldConfiguration.set(base + "plot.filling",
|
this.worldConfiguration.set(
|
||||||
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString());
|
base + "plot.filling",
|
||||||
|
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString()
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "w":
|
case "w":
|
||||||
case "wall":
|
case "wall":
|
||||||
this.worldConfiguration.set(base + "wall.filling",
|
this.worldConfiguration.set(
|
||||||
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString());
|
base + "wall.filling",
|
||||||
|
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString()
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "b":
|
case "b":
|
||||||
case "border":
|
case "border":
|
||||||
this.worldConfiguration.set(base + "wall.block",
|
this.worldConfiguration.set(
|
||||||
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString());
|
base + "wall.block",
|
||||||
|
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString()
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
logger.error("Key not found: {}", element);
|
logger.error("Key not found: {}", element);
|
||||||
@ -1100,7 +1154,7 @@ public class PlotSquared {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ConfigurationSection section =
|
ConfigurationSection section =
|
||||||
this.worldConfiguration.getConfigurationSection("worlds." + world);
|
this.worldConfiguration.getConfigurationSection("worlds." + world);
|
||||||
plotWorld.saveConfiguration(section);
|
plotWorld.saveConfiguration(section);
|
||||||
plotWorld.loadDefaultConfiguration(section);
|
plotWorld.loadDefaultConfiguration(section);
|
||||||
this.worldConfiguration.save(this.worldsFile);
|
this.worldConfiguration.save(this.worldsFile);
|
||||||
@ -1117,7 +1171,10 @@ public class PlotSquared {
|
|||||||
* @param file Name of the file inside PlotSquared.jar
|
* @param file Name of the file inside PlotSquared.jar
|
||||||
* @param folder The output location relative to /plugins/PlotSquared/
|
* @param folder The output location relative to /plugins/PlotSquared/
|
||||||
*/
|
*/
|
||||||
public void copyFile(String file, String folder) {
|
public void copyFile(
|
||||||
|
final @NonNull String file,
|
||||||
|
final @NonNull String folder
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
File output = this.platform.getDirectory();
|
File output = this.platform.getDirectory();
|
||||||
if (!output.exists()) {
|
if (!output.exists()) {
|
||||||
@ -1131,7 +1188,7 @@ public class PlotSquared {
|
|||||||
byte[] buffer = new byte[2048];
|
byte[] buffer = new byte[2048];
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
try (ZipInputStream zis = new ZipInputStream(
|
try (ZipInputStream zis = new ZipInputStream(
|
||||||
new FileInputStream(this.jarFile))) {
|
new FileInputStream(this.jarFile))) {
|
||||||
ZipEntry ze = zis.getNextEntry();
|
ZipEntry ze = zis.getNextEntry();
|
||||||
while (ze != null) {
|
while (ze != null) {
|
||||||
String name = ze.getName();
|
String name = ze.getName();
|
||||||
@ -1194,7 +1251,7 @@ public class PlotSquared {
|
|||||||
*/
|
*/
|
||||||
private void checkRoadRegenPersistence() {
|
private void checkRoadRegenPersistence() {
|
||||||
if (!HybridUtils.UPDATE || !Settings.Enabled_Components.PERSISTENT_ROAD_REGEN || (
|
if (!HybridUtils.UPDATE || !Settings.Enabled_Components.PERSISTENT_ROAD_REGEN || (
|
||||||
HybridUtils.regions.isEmpty() && HybridUtils.chunks.isEmpty())) {
|
HybridUtils.regions.isEmpty() && HybridUtils.chunks.isEmpty())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.info("Road regeneration incomplete. Saving incomplete regions to disk");
|
logger.info("Road regeneration incomplete. Saving incomplete regions to disk");
|
||||||
@ -1203,24 +1260,24 @@ public class PlotSquared {
|
|||||||
ArrayList<int[]> regions = new ArrayList<>();
|
ArrayList<int[]> regions = new ArrayList<>();
|
||||||
ArrayList<int[]> chunks = new ArrayList<>();
|
ArrayList<int[]> chunks = new ArrayList<>();
|
||||||
for (BlockVector2 r : HybridUtils.regions) {
|
for (BlockVector2 r : HybridUtils.regions) {
|
||||||
regions.add(new int[] {r.getBlockX(), r.getBlockZ()});
|
regions.add(new int[]{r.getBlockX(), r.getBlockZ()});
|
||||||
}
|
}
|
||||||
for (BlockVector2 c : HybridUtils.chunks) {
|
for (BlockVector2 c : HybridUtils.chunks) {
|
||||||
chunks.add(new int[] {c.getBlockX(), c.getBlockZ()});
|
chunks.add(new int[]{c.getBlockX(), c.getBlockZ()});
|
||||||
}
|
}
|
||||||
List<Object> list = new ArrayList<>();
|
List<Object> list = new ArrayList<>();
|
||||||
list.add(regions);
|
list.add(regions);
|
||||||
list.add(chunks);
|
list.add(chunks);
|
||||||
list.add(HybridUtils.height);
|
list.add(HybridUtils.height);
|
||||||
File file = new File(
|
File file = new File(
|
||||||
this.platform.getDirectory() + File.separator + "persistent_regen_data_" + HybridUtils.area
|
this.platform.getDirectory() + File.separator + "persistent_regen_data_" + HybridUtils.area
|
||||||
.getId() + "_" + HybridUtils.area.getWorldName());
|
.getId() + "_" + HybridUtils.area.getWorldName());
|
||||||
if (file.exists() && !file.delete()) {
|
if (file.exists() && !file.delete()) {
|
||||||
logger.error("persistent_regene_data file already exists and could not be deleted");
|
logger.error("persistent_regene_data file already exists and could not be deleted");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try (ObjectOutputStream oos = new ObjectOutputStream(
|
try (ObjectOutputStream oos = new ObjectOutputStream(
|
||||||
Files.newOutputStream(file.toPath(), StandardOpenOption.CREATE_NEW))) {
|
Files.newOutputStream(file.toPath(), StandardOpenOption.CREATE_NEW))) {
|
||||||
oos.writeObject(list);
|
oos.writeObject(list);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Error creating persistent_region_data file", e);
|
logger.error("Error creating persistent_region_data file", e);
|
||||||
@ -1238,7 +1295,8 @@ public class PlotSquared {
|
|||||||
Database database;
|
Database database;
|
||||||
if (Storage.MySQL.USE) {
|
if (Storage.MySQL.USE) {
|
||||||
database = new MySQL(Storage.MySQL.HOST, Storage.MySQL.PORT, Storage.MySQL.DATABASE,
|
database = new MySQL(Storage.MySQL.HOST, Storage.MySQL.PORT, Storage.MySQL.DATABASE,
|
||||||
Storage.MySQL.USER, Storage.MySQL.PASSWORD);
|
Storage.MySQL.USER, Storage.MySQL.PASSWORD
|
||||||
|
);
|
||||||
} else if (Storage.SQLite.USE) {
|
} else if (Storage.SQLite.USE) {
|
||||||
File file = FileUtils.getFile(platform.getDirectory(), Storage.SQLite.DB + ".db");
|
File file = FileUtils.getFile(platform.getDirectory(), Storage.SQLite.DB + ".db");
|
||||||
database = new SQLite(file);
|
database = new SQLite(file);
|
||||||
@ -1247,7 +1305,13 @@ public class PlotSquared {
|
|||||||
this.platform.shutdown(); //shutdown used instead of disable because no database is set
|
this.platform.shutdown(); //shutdown used instead of disable because no database is set
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DBFunc.dbManager = new SQLManager(database, Storage.PREFIX, this.eventDispatcher, this.plotListener, this.worldConfiguration);
|
DBFunc.dbManager = new SQLManager(
|
||||||
|
database,
|
||||||
|
Storage.PREFIX,
|
||||||
|
this.eventDispatcher,
|
||||||
|
this.plotListener,
|
||||||
|
this.worldConfiguration
|
||||||
|
);
|
||||||
this.plots_tmp = DBFunc.getPlots();
|
this.plots_tmp = DBFunc.getPlots();
|
||||||
if (getPlotAreaManager() instanceof SinglePlotAreaManager) {
|
if (getPlotAreaManager() instanceof SinglePlotAreaManager) {
|
||||||
SinglePlotArea area = ((SinglePlotAreaManager) getPlotAreaManager()).getArea();
|
SinglePlotArea area = ((SinglePlotAreaManager) getPlotAreaManager()).getArea();
|
||||||
@ -1261,32 +1325,35 @@ public class PlotSquared {
|
|||||||
}
|
}
|
||||||
this.clustersTmp = DBFunc.getClusters();
|
this.clustersTmp = DBFunc.getClusters();
|
||||||
} catch (ClassNotFoundException | SQLException e) {
|
} catch (ClassNotFoundException | SQLException e) {
|
||||||
logger.error("Failed to open database connection ({}). Disabling PlotSquared", Storage.MySQL.USE ? "MySQL" : "SQLite");
|
logger.error(
|
||||||
|
"Failed to open database connection ({}). Disabling PlotSquared",
|
||||||
|
Storage.MySQL.USE ? "MySQL" : "SQLite"
|
||||||
|
);
|
||||||
logger.error("==== Here is an ugly stacktrace, if you are interested in those things ===");
|
logger.error("==== Here is an ugly stacktrace, if you are interested in those things ===");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
logger.error("==== End of stacktrace ====");
|
logger.error("==== End of stacktrace ====");
|
||||||
logger.error("Please go to the {} 'storage.yml' and configure the database correctly",
|
logger.error(
|
||||||
platform.pluginName());
|
"Please go to the {} 'storage.yml' and configure the database correctly",
|
||||||
|
platform.pluginName()
|
||||||
|
);
|
||||||
this.platform.shutdown(); //shutdown used instead of disable because of database error
|
this.platform.shutdown(); //shutdown used instead of disable because of database error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup the default configuration.
|
* Setup the default configuration.
|
||||||
*
|
|
||||||
* @throws IOException if the config failed to save
|
|
||||||
*/
|
*/
|
||||||
public void setupConfig() throws IOException {
|
public void setupConfig() {
|
||||||
String lastVersionString = this.getConfig().getString("version");
|
String lastVersionString = this.getConfig().getString("version");
|
||||||
if (lastVersionString != null) {
|
if (lastVersionString != null) {
|
||||||
String[] split = lastVersionString.split("\\.");
|
String[] split = lastVersionString.split("\\.");
|
||||||
int[] lastVersion = new int[] {Integer.parseInt(split[0]), Integer.parseInt(split[1]),
|
int[] lastVersion = new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]),
|
||||||
Integer.parseInt(split[2])};
|
Integer.parseInt(split[2])};
|
||||||
if (checkVersion(new int[] {3, 4, 0}, lastVersion)) {
|
if (checkVersion(new int[]{3, 4, 0}, lastVersion)) {
|
||||||
Settings.convertLegacy(configFile);
|
Settings.convertLegacy(configFile);
|
||||||
if (getConfig().contains("worlds")) {
|
if (getConfig().contains("worlds")) {
|
||||||
ConfigurationSection worldSection =
|
ConfigurationSection worldSection =
|
||||||
getConfig().getConfigurationSection("worlds");
|
getConfig().getConfigurationSection("worlds");
|
||||||
worldConfiguration.set("worlds", worldSection);
|
worldConfiguration.set("worlds", worldSection);
|
||||||
try {
|
try {
|
||||||
worldConfiguration.save(worldsFile);
|
worldConfiguration.save(worldsFile);
|
||||||
@ -1335,22 +1402,23 @@ public class PlotSquared {
|
|||||||
|
|
||||||
if (this.worldConfiguration.contains("worlds")) {
|
if (this.worldConfiguration.contains("worlds")) {
|
||||||
if (!this.worldConfiguration.contains("configuration_version") || (
|
if (!this.worldConfiguration.contains("configuration_version") || (
|
||||||
!this.worldConfiguration.getString("configuration_version")
|
!this.worldConfiguration.getString("configuration_version")
|
||||||
.equalsIgnoreCase(LegacyConverter.CONFIGURATION_VERSION) && !this.worldConfiguration
|
.equalsIgnoreCase(LegacyConverter.CONFIGURATION_VERSION) && !this.worldConfiguration
|
||||||
.getString("configuration_version").equalsIgnoreCase("v5"))) {
|
.getString("configuration_version").equalsIgnoreCase("v5"))) {
|
||||||
// Conversion needed
|
// Conversion needed
|
||||||
logger.info("A legacy configuration file was detected. Conversion will be attempted.");
|
logger.info("A legacy configuration file was detected. Conversion will be attempted.");
|
||||||
try {
|
try {
|
||||||
com.google.common.io.Files
|
com.google.common.io.Files
|
||||||
.copy(this.worldsFile, new File(folder, "worlds.yml.old"));
|
.copy(this.worldsFile, new File(folder, "worlds.yml.old"));
|
||||||
logger.info("A copy of worlds.yml has been saved in the file worlds.yml.old");
|
logger.info("A copy of worlds.yml has been saved in the file worlds.yml.old");
|
||||||
final ConfigurationSection worlds =
|
final ConfigurationSection worlds =
|
||||||
this.worldConfiguration.getConfigurationSection("worlds");
|
this.worldConfiguration.getConfigurationSection("worlds");
|
||||||
final LegacyConverter converter = new LegacyConverter(worlds);
|
final LegacyConverter converter = new LegacyConverter(worlds);
|
||||||
converter.convert();
|
converter.convert();
|
||||||
this.worldConfiguration.set("worlds", worlds);
|
this.worldConfiguration.set("worlds", worlds);
|
||||||
this.setConfigurationVersion(LegacyConverter.CONFIGURATION_VERSION);
|
this.setConfigurationVersion(LegacyConverter.CONFIGURATION_VERSION);
|
||||||
logger.info("The conversion has finished. PlotSquared will now be disabled and the new configuration file will be used at next startup. Please review the new worlds.yml file. Please note that schematics will not be converted, as we are now using WorldEdit to handle schematics. You need to re-generate the schematics.");
|
logger.info(
|
||||||
|
"The conversion has finished. PlotSquared will now be disabled and the new configuration file will be used at next startup. Please review the new worlds.yml file. Please note that schematics will not be converted, as we are now using WorldEdit to handle schematics. You need to re-generate the schematics.");
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
logger.error("Failed to convert the legacy configuration file. See stack trace for information.", e);
|
logger.error("Failed to convert the legacy configuration file. See stack trace for information.", e);
|
||||||
}
|
}
|
||||||
@ -1387,12 +1455,12 @@ public class PlotSquared {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getConfigurationVersion() {
|
public @NonNull String getConfigurationVersion() {
|
||||||
return this.worldConfiguration.get("configuration_version", LegacyConverter.CONFIGURATION_VERSION)
|
return this.worldConfiguration.get("configuration_version", LegacyConverter.CONFIGURATION_VERSION)
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConfigurationVersion(final String newVersion) throws IOException {
|
public void setConfigurationVersion(final @NonNull String newVersion) throws IOException {
|
||||||
this.worldConfiguration.set("configuration_version", newVersion);
|
this.worldConfiguration.set("configuration_version", newVersion);
|
||||||
this.worldConfiguration.save(this.worldsFile);
|
this.worldConfiguration.save(this.worldsFile);
|
||||||
}
|
}
|
||||||
@ -1418,7 +1486,7 @@ public class PlotSquared {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forEachPlotRaw(Consumer<Plot> consumer) {
|
public void forEachPlotRaw(final @NonNull Consumer<Plot> consumer) {
|
||||||
for (final PlotArea area : this.getPlotAreaManager().getAllPlotAreas()) {
|
for (final PlotArea area : this.getPlotAreaManager().getAllPlotAreas()) {
|
||||||
area.getPlots().forEach(consumer);
|
area.getPlots().forEach(consumer);
|
||||||
}
|
}
|
||||||
@ -1436,8 +1504,10 @@ public class PlotSquared {
|
|||||||
* @param chunkCoordinates Chunk coordinates
|
* @param chunkCoordinates Chunk coordinates
|
||||||
* @return True if the chunk uses non-standard generation, false if not
|
* @return True if the chunk uses non-standard generation, false if not
|
||||||
*/
|
*/
|
||||||
public boolean isNonStandardGeneration(@Nonnull final String world,
|
public boolean isNonStandardGeneration(
|
||||||
@Nonnull final BlockVector2 chunkCoordinates) {
|
final @NonNull String world,
|
||||||
|
final @NonNull BlockVector2 chunkCoordinates
|
||||||
|
) {
|
||||||
final Location location = Location.at(world, chunkCoordinates.getBlockX() << 4, 64, chunkCoordinates.getBlockZ() << 4);
|
final Location location = Location.at(world, chunkCoordinates.getBlockX() << 4, 64, chunkCoordinates.getBlockZ() << 4);
|
||||||
final PlotArea area = getPlotAreaManager().getApplicablePlotArea(location);
|
final PlotArea area = getPlotAreaManager().getApplicablePlotArea(location);
|
||||||
if (area == null) {
|
if (area == null) {
|
||||||
@ -1446,31 +1516,31 @@ public class PlotSquared {
|
|||||||
return area.getTerrain() != PlotAreaTerrainType.NONE;
|
return area.getTerrain() != PlotAreaTerrainType.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public YamlConfiguration getConfig() {
|
public @NonNull YamlConfiguration getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUIDPipeline getImpromptuUUIDPipeline() {
|
public @NonNull UUIDPipeline getImpromptuUUIDPipeline() {
|
||||||
return this.impromptuUUIDPipeline;
|
return this.impromptuUUIDPipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUIDPipeline getBackgroundUUIDPipeline() {
|
public @NonNull UUIDPipeline getBackgroundUUIDPipeline() {
|
||||||
return this.backgroundUUIDPipeline;
|
return this.backgroundUUIDPipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorldEdit getWorldEdit() {
|
public @NonNull WorldEdit getWorldEdit() {
|
||||||
return this.worldedit;
|
return this.worldedit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getConfigFile() {
|
public @NonNull File getConfigFile() {
|
||||||
return this.configFile;
|
return this.configFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getWorldsFile() {
|
public @NonNull File getWorldsFile() {
|
||||||
return this.worldsFile;
|
return this.worldsFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public YamlConfiguration getWorldConfiguration() {
|
public @NonNull YamlConfiguration getWorldConfiguration() {
|
||||||
return this.worldConfiguration;
|
return this.worldConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1482,33 +1552,42 @@ public class PlotSquared {
|
|||||||
* @return Map instance
|
* @return Map instance
|
||||||
* @see #registerCaptionMap(String, CaptionMap) To register a caption map
|
* @see #registerCaptionMap(String, CaptionMap) To register a caption map
|
||||||
*/
|
*/
|
||||||
@Nonnull public CaptionMap getCaptionMap(@Nonnull final String namespace) {
|
public @NonNull CaptionMap getCaptionMap(final @NonNull String namespace) {
|
||||||
return this.captionMaps.computeIfAbsent(namespace.toLowerCase(Locale.ENGLISH),
|
return this.captionMaps.computeIfAbsent(
|
||||||
missingNamespace -> new DummyCaptionMap());
|
namespace.toLowerCase(Locale.ENGLISH),
|
||||||
|
missingNamespace -> new DummyCaptionMap()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a caption map
|
* Register a caption map
|
||||||
*
|
*
|
||||||
* @param namespace Namespace
|
* @param namespace Namespace
|
||||||
* @param captionMap Map instance
|
* @param captionMap Map instance
|
||||||
*/
|
*/
|
||||||
public void registerCaptionMap(@Nonnull final String namespace, @Nonnull final CaptionMap captionMap) {
|
public void registerCaptionMap(
|
||||||
|
final @NonNull String namespace,
|
||||||
|
final @NonNull CaptionMap captionMap
|
||||||
|
) {
|
||||||
if (namespace.equalsIgnoreCase(TranslatableCaption.DEFAULT_NAMESPACE)) {
|
if (namespace.equalsIgnoreCase(TranslatableCaption.DEFAULT_NAMESPACE)) {
|
||||||
throw new IllegalArgumentException("Cannot replace default caption map");
|
throw new IllegalArgumentException("Cannot replace default caption map");
|
||||||
}
|
}
|
||||||
this.captionMaps.put(namespace.toLowerCase(Locale.ENGLISH), captionMap);
|
this.captionMaps.put(namespace.toLowerCase(Locale.ENGLISH), captionMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EventDispatcher getEventDispatcher() {
|
public @NonNull EventDispatcher getEventDispatcher() {
|
||||||
return this.eventDispatcher;
|
return this.eventDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlotListener getPlotListener() {
|
public @NonNull PlotListener getPlotListener() {
|
||||||
return this.plotListener;
|
return this.plotListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum SortType {
|
public enum SortType {
|
||||||
CREATION_DATE, CREATION_DATE_TIMESTAMP, LAST_MODIFIED, DISTANCE_FROM_ORIGIN
|
CREATION_DATE,
|
||||||
|
CREATION_DATE_TIMESTAMP,
|
||||||
|
LAST_MODIFIED,
|
||||||
|
DISTANCE_FROM_ORIGIN
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,13 +25,23 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.core;
|
package com.plotsquared.core;
|
||||||
|
|
||||||
public class PlotVersion {
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
|
public final class PlotVersion {
|
||||||
|
|
||||||
public final int year, month, day, hash;
|
public final int year, month, day, hash;
|
||||||
public final String versionString;
|
public final String versionString;
|
||||||
public final int[] version;
|
public final int[] version;
|
||||||
public final String suffix;
|
public final String suffix;
|
||||||
|
|
||||||
public PlotVersion(int year, int month, int day, int hash, String versionString) {
|
public PlotVersion(
|
||||||
|
final int year,
|
||||||
|
final int month,
|
||||||
|
final int day,
|
||||||
|
final int hash,
|
||||||
|
final String rawVersion
|
||||||
|
) {
|
||||||
|
String versionString = rawVersion;
|
||||||
this.year = year;
|
this.year = year;
|
||||||
this.month = month;
|
this.month = month;
|
||||||
this.day = day;
|
this.day = day;
|
||||||
@ -51,7 +61,12 @@ public class PlotVersion {
|
|||||||
version[2] = verArray.length > 2 ? Integer.parseInt(verArray[2]) : 0;
|
version[2] = verArray.length > 2 ? Integer.parseInt(verArray[2]) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlotVersion(String versionString, String commit, String date) {
|
public PlotVersion(
|
||||||
|
final String rawVersion,
|
||||||
|
final String commit,
|
||||||
|
final String date
|
||||||
|
) {
|
||||||
|
String versionString = rawVersion;
|
||||||
int dash = versionString.indexOf('-');
|
int dash = versionString.indexOf('-');
|
||||||
if (dash != -1) {
|
if (dash != -1) {
|
||||||
suffix = versionString.substring(dash);
|
suffix = versionString.substring(dash);
|
||||||
@ -73,7 +88,11 @@ public class PlotVersion {
|
|||||||
this.day = Integer.parseInt(split1[2]);
|
this.day = Integer.parseInt(split1[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlotVersion tryParse(String versionString, String commit, String date) {
|
public static @NonNull PlotVersion tryParse(
|
||||||
|
final @NonNull String versionString,
|
||||||
|
final @NonNull String commit,
|
||||||
|
final @NonNull String date
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
return new PlotVersion(versionString, commit, date);
|
return new PlotVersion(versionString, commit, date);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -82,7 +101,7 @@ public class PlotVersion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String versionString() {
|
public @NonNull String versionString() {
|
||||||
if (hash == 0 && versionString == null) {
|
if (hash == 0 && versionString == null) {
|
||||||
return "NoVer-SNAPSHOT";
|
return "NoVer-SNAPSHOT";
|
||||||
} else {
|
} else {
|
||||||
@ -90,7 +109,8 @@ public class PlotVersion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String toString() {
|
@Override
|
||||||
|
public String toString() {
|
||||||
if (hash == 0 && versionString == null) {
|
if (hash == 0 && versionString == null) {
|
||||||
return "PlotSquared-NoVer-SNAPSHOT";
|
return "PlotSquared-NoVer-SNAPSHOT";
|
||||||
} else {
|
} else {
|
||||||
@ -104,10 +124,10 @@ public class PlotVersion {
|
|||||||
* @param versionString the version to compare
|
* @param versionString the version to compare
|
||||||
* @return true if the given version is a "later" version
|
* @return true if the given version is a "later" version
|
||||||
*/
|
*/
|
||||||
public boolean isLaterVersion(String versionString) {
|
public boolean isLaterVersion(final @NonNull String versionString) {
|
||||||
int dash = versionString.indexOf('-');
|
int dash = versionString.indexOf('-');
|
||||||
String[] verArray =
|
String[] verArray =
|
||||||
versionString.substring(0, dash == -1 ? versionString.length() : dash).split("\\.");
|
versionString.substring(0, dash == -1 ? versionString.length() : dash).split("\\.");
|
||||||
int one = Integer.parseInt(verArray[0]);
|
int one = Integer.parseInt(verArray[0]);
|
||||||
int two = Integer.parseInt(verArray[1]);
|
int two = Integer.parseInt(verArray[1]);
|
||||||
int three = Integer.parseInt(verArray[2]);
|
int three = Integer.parseInt(verArray[2]);
|
||||||
@ -133,9 +153,8 @@ public class PlotVersion {
|
|||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return verArray[0] == version[0] && verArray[1] == version[1]
|
return verArray[0] == version[0] && verArray[1] == version[1]
|
||||||
&& verArray[2] > version[2];
|
&& verArray[2] > version[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.core.backup;
|
package com.plotsquared.core.backup;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -38,7 +39,8 @@ public class Backup {
|
|||||||
|
|
||||||
private final BackupProfile owner;
|
private final BackupProfile owner;
|
||||||
private final long creationTime;
|
private final long creationTime;
|
||||||
@Nullable private final Path file;
|
@Nullable
|
||||||
|
private final Path file;
|
||||||
|
|
||||||
Backup(final BackupProfile owner, final long creationTime, final Path file) {
|
Backup(final BackupProfile owner, final long creationTime, final Path file) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
@ -67,7 +69,8 @@ public class Backup {
|
|||||||
return this.creationTime;
|
return this.creationTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable public Path getFile() {
|
public @Nullable Path getFile() {
|
||||||
return this.file;
|
return this.file;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,9 +28,9 @@ package com.plotsquared.core.backup;
|
|||||||
import com.plotsquared.core.PlotSquared;
|
import com.plotsquared.core.PlotSquared;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import com.plotsquared.core.plot.Plot;
|
import com.plotsquared.core.plot.Plot;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ public interface BackupManager {
|
|||||||
* @param plot Plot to perform the automatic backup on
|
* @param plot Plot to perform the automatic backup on
|
||||||
* @param whenDone Action that runs when the automatic backup has been completed
|
* @param whenDone Action that runs when the automatic backup has been completed
|
||||||
*/
|
*/
|
||||||
static void backup(@Nullable PlotPlayer player, @Nonnull final Plot plot, @Nonnull Runnable whenDone) {
|
static void backup(@Nullable PlotPlayer player, final @NonNull Plot plot, @NonNull Runnable whenDone) {
|
||||||
Objects.requireNonNull(PlotSquared.platform()).backupManager().automaticBackup(player, plot, whenDone);
|
Objects.requireNonNull(PlotSquared.platform()).backupManager().automaticBackup(player, plot, whenDone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ public interface BackupManager {
|
|||||||
* @param plot Plot to get the backup profile for
|
* @param plot Plot to get the backup profile for
|
||||||
* @return Backup profile
|
* @return Backup profile
|
||||||
*/
|
*/
|
||||||
@Nonnull BackupProfile getProfile(@Nonnull final Plot plot);
|
@NonNull BackupProfile getProfile(final @NonNull Plot plot);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This will perform an automatic backup of the plot iff the plot has an owner,
|
* This will perform an automatic backup of the plot iff the plot has an owner,
|
||||||
@ -67,14 +67,14 @@ public interface BackupManager {
|
|||||||
* @param plot Plot to perform the automatic backup on
|
* @param plot Plot to perform the automatic backup on
|
||||||
* @param whenDone Action that runs when the automatic backup has been completed
|
* @param whenDone Action that runs when the automatic backup has been completed
|
||||||
*/
|
*/
|
||||||
void automaticBackup(@Nullable PlotPlayer player, @Nonnull final Plot plot, @Nonnull Runnable whenDone);
|
void automaticBackup(@Nullable PlotPlayer player, final @NonNull Plot plot, @NonNull Runnable whenDone);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the directory in which backups are stored
|
* Get the directory in which backups are stored
|
||||||
*
|
*
|
||||||
* @return Backup directory path
|
* @return Backup directory path
|
||||||
*/
|
*/
|
||||||
@Nonnull Path getBackupPath();
|
@NonNull Path getBackupPath();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the maximum amount of backups that may be stored for
|
* Get the maximum amount of backups that may be stored for
|
||||||
|
@ -26,9 +26,9 @@
|
|||||||
package com.plotsquared.core.backup;
|
package com.plotsquared.core.backup;
|
||||||
|
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@ -40,7 +40,7 @@ public interface BackupProfile {
|
|||||||
*
|
*
|
||||||
* @return Future that will be completed with available backups
|
* @return Future that will be completed with available backups
|
||||||
*/
|
*/
|
||||||
@Nonnull CompletableFuture<List<Backup>> listBackups();
|
@NonNull CompletableFuture<List<Backup>> listBackups();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all backups stored for this profile
|
* Remove all backups stored for this profile
|
||||||
@ -53,7 +53,7 @@ public interface BackupProfile {
|
|||||||
*
|
*
|
||||||
* @return Folder that contains the backups for this profile
|
* @return Folder that contains the backups for this profile
|
||||||
*/
|
*/
|
||||||
@Nonnull Path getBackupDirectory();
|
@NonNull Path getBackupDirectory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a backup of the plot. If the profile is at the
|
* Create a backup of the plot. If the profile is at the
|
||||||
@ -61,7 +61,7 @@ public interface BackupProfile {
|
|||||||
*
|
*
|
||||||
* @return Future that completes with the created backup.
|
* @return Future that completes with the created backup.
|
||||||
*/
|
*/
|
||||||
@Nonnull CompletableFuture<Backup> createBackup();
|
@NonNull CompletableFuture<Backup> createBackup();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restore a backup
|
* Restore a backup
|
||||||
@ -70,6 +70,6 @@ public interface BackupProfile {
|
|||||||
* @param player The player restoring the backup
|
* @param player The player restoring the backup
|
||||||
* @return Future that completes when the backup has finished
|
* @return Future that completes when the backup has finished
|
||||||
*/
|
*/
|
||||||
@Nonnull CompletableFuture<Void> restoreBackup(@Nonnull final Backup backup, @Nullable PlotPlayer<?> player);
|
@NonNull CompletableFuture<Void> restoreBackup(final @NonNull Backup backup, @Nullable PlotPlayer<?> player);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,35 +29,43 @@ import com.google.inject.Singleton;
|
|||||||
import com.plotsquared.core.PlotSquared;
|
import com.plotsquared.core.PlotSquared;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import com.plotsquared.core.plot.Plot;
|
import com.plotsquared.core.plot.Plot;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Singleton public class NullBackupManager implements BackupManager {
|
@Singleton
|
||||||
|
public class NullBackupManager implements BackupManager {
|
||||||
|
|
||||||
@Override @Nonnull public BackupProfile getProfile(@Nonnull Plot plot) {
|
@Override
|
||||||
|
public @NonNull BackupProfile getProfile(@NonNull Plot plot) {
|
||||||
return new NullBackupProfile();
|
return new NullBackupProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void automaticBackup(@Nullable PlotPlayer plotPlayer,
|
@Override
|
||||||
@Nonnull Plot plot, @Nonnull Runnable whenDone) {
|
public void automaticBackup(
|
||||||
|
@Nullable PlotPlayer plotPlayer,
|
||||||
|
@NonNull Plot plot, @NonNull Runnable whenDone
|
||||||
|
) {
|
||||||
whenDone.run();
|
whenDone.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public Path getBackupPath() {
|
@Override
|
||||||
|
public @NonNull Path getBackupPath() {
|
||||||
return Objects.requireNonNull(PlotSquared.platform()).getDirectory().toPath();
|
return Objects.requireNonNull(PlotSquared.platform()).getDirectory().toPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public int getBackupLimit() {
|
@Override
|
||||||
|
public int getBackupLimit() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean shouldAutomaticallyBackup() {
|
@Override
|
||||||
|
public boolean shouldAutomaticallyBackup() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,9 +26,9 @@
|
|||||||
package com.plotsquared.core.backup;
|
package com.plotsquared.core.backup;
|
||||||
|
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -41,22 +41,27 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
*/
|
*/
|
||||||
public class NullBackupProfile implements BackupProfile {
|
public class NullBackupProfile implements BackupProfile {
|
||||||
|
|
||||||
@Override @Nonnull public CompletableFuture<List<Backup>> listBackups() {
|
@Override
|
||||||
|
public @NonNull CompletableFuture<List<Backup>> listBackups() {
|
||||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void destroy(){
|
@Override
|
||||||
|
public void destroy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public Path getBackupDirectory() {
|
@Override
|
||||||
|
public @NonNull Path getBackupDirectory() {
|
||||||
return new File(".").toPath();
|
return new File(".").toPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public CompletableFuture<Backup> createBackup() {
|
@Override
|
||||||
|
public @NonNull CompletableFuture<Backup> createBackup() {
|
||||||
throw new UnsupportedOperationException("Cannot create backup of an unowned plot");
|
throw new UnsupportedOperationException("Cannot create backup of an unowned plot");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public CompletableFuture<Void> restoreBackup(@Nonnull final Backup backup, @Nullable PlotPlayer<?> player) {
|
@Override
|
||||||
|
public @NonNull CompletableFuture<Void> restoreBackup(final @NonNull Backup backup, @Nullable PlotPlayer<?> player) {
|
||||||
return CompletableFuture.completedFuture(null);
|
return CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +36,9 @@ import com.plotsquared.core.util.SchematicHandler;
|
|||||||
import com.plotsquared.core.util.task.RunnableVal;
|
import com.plotsquared.core.util.task.RunnableVal;
|
||||||
import com.plotsquared.core.util.task.TaskManager;
|
import com.plotsquared.core.util.task.TaskManager;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -64,24 +64,42 @@ public class PlayerBackupProfile implements BackupProfile {
|
|||||||
private final Plot plot;
|
private final Plot plot;
|
||||||
private final BackupManager backupManager;
|
private final BackupManager backupManager;
|
||||||
private final SchematicHandler schematicHandler;
|
private final SchematicHandler schematicHandler;
|
||||||
|
private final Object backupLock = new Object();
|
||||||
@Inject public PlayerBackupProfile(@Assisted @Nonnull final UUID owner, @Assisted @Nonnull final Plot plot,
|
private volatile List<Backup> backupCache;
|
||||||
@Nonnull final BackupManager backupManager, @Nonnull final SchematicHandler schematicHandler) {
|
@Inject
|
||||||
|
public PlayerBackupProfile(
|
||||||
|
@Assisted final @NonNull UUID owner, @Assisted final @NonNull Plot plot,
|
||||||
|
final @NonNull BackupManager backupManager, final @NonNull SchematicHandler schematicHandler
|
||||||
|
) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.plot = plot;
|
this.plot = plot;
|
||||||
this.backupManager = backupManager;
|
this.backupManager = backupManager;
|
||||||
this.schematicHandler = schematicHandler;
|
this.schematicHandler = schematicHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private volatile List<Backup> backupCache;
|
private static boolean isValidFile(final @NonNull Path path) {
|
||||||
private final Object backupLock = new Object();
|
|
||||||
|
|
||||||
private static boolean isValidFile(@Nonnull final Path path) {
|
|
||||||
final String name = path.getFileName().toString();
|
final String name = path.getFileName().toString();
|
||||||
return name.endsWith(".schem") || name.endsWith(".schematic");
|
return name.endsWith(".schem") || name.endsWith(".schematic");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public CompletableFuture<List<Backup>> listBackups() {
|
private static Path resolve(final @NonNull Path parent, final String child) {
|
||||||
|
Path path = parent;
|
||||||
|
try {
|
||||||
|
if (!Files.exists(parent)) {
|
||||||
|
Files.createDirectory(parent);
|
||||||
|
}
|
||||||
|
path = parent.resolve(child);
|
||||||
|
if (!Files.exists(path)) {
|
||||||
|
Files.createDirectory(path);
|
||||||
|
}
|
||||||
|
} catch (final Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull CompletableFuture<List<Backup>> listBackups() {
|
||||||
synchronized (this.backupLock) {
|
synchronized (this.backupLock) {
|
||||||
if (this.backupCache != null) {
|
if (this.backupCache != null) {
|
||||||
return CompletableFuture.completedFuture(backupCache);
|
return CompletableFuture.completedFuture(backupCache);
|
||||||
@ -101,9 +119,9 @@ public class PlayerBackupProfile implements BackupProfile {
|
|||||||
Files.walk(path).filter(PlayerBackupProfile::isValidFile).forEach(file -> {
|
Files.walk(path).filter(PlayerBackupProfile::isValidFile).forEach(file -> {
|
||||||
try {
|
try {
|
||||||
final BasicFileAttributes basicFileAttributes =
|
final BasicFileAttributes basicFileAttributes =
|
||||||
Files.readAttributes(file, BasicFileAttributes.class);
|
Files.readAttributes(file, BasicFileAttributes.class);
|
||||||
backups.add(
|
backups.add(
|
||||||
new Backup(this, basicFileAttributes.creationTime().toMillis(), file));
|
new Backup(this, basicFileAttributes.creationTime().toMillis(), file));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -117,38 +135,26 @@ public class PlayerBackupProfile implements BackupProfile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void destroy() {
|
@Override
|
||||||
|
public void destroy() {
|
||||||
this.listBackups().whenCompleteAsync((backups, error) -> {
|
this.listBackups().whenCompleteAsync((backups, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
}
|
}
|
||||||
backups.forEach(Backup::delete);
|
backups.forEach(Backup::delete);
|
||||||
this.backupCache = null;
|
this.backupCache = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull public Path getBackupDirectory() {
|
public @NonNull Path getBackupDirectory() {
|
||||||
return resolve(resolve(resolve(backupManager.getBackupPath(), Objects.requireNonNull(plot.getArea().toString(), "plot area id")),
|
return resolve(resolve(
|
||||||
Objects.requireNonNull(plot.getId().toDashSeparatedString(), "plot id")), Objects.requireNonNull(owner.toString(), "owner"));
|
resolve(backupManager.getBackupPath(), Objects.requireNonNull(plot.getArea().toString(), "plot area id")),
|
||||||
|
Objects.requireNonNull(plot.getId().toDashSeparatedString(), "plot id")
|
||||||
|
), Objects.requireNonNull(owner.toString(), "owner"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Path resolve(@Nonnull final Path parent, final String child) {
|
@Override
|
||||||
Path path = parent;
|
public @NonNull CompletableFuture<Backup> createBackup() {
|
||||||
try {
|
|
||||||
if (!Files.exists(parent)) {
|
|
||||||
Files.createDirectory(parent);
|
|
||||||
}
|
|
||||||
path = parent.resolve(child);
|
|
||||||
if (!Files.exists(path)) {
|
|
||||||
Files.createDirectory(path);
|
|
||||||
}
|
|
||||||
} catch (final Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override @Nonnull public CompletableFuture<Backup> createBackup() {
|
|
||||||
final CompletableFuture<Backup> future = new CompletableFuture<>();
|
final CompletableFuture<Backup> future = new CompletableFuture<>();
|
||||||
this.listBackups().thenAcceptAsync(backups -> {
|
this.listBackups().thenAcceptAsync(backups -> {
|
||||||
synchronized (this.backupLock) {
|
synchronized (this.backupLock) {
|
||||||
@ -157,8 +163,9 @@ public class PlayerBackupProfile implements BackupProfile {
|
|||||||
}
|
}
|
||||||
final List<Plot> plots = Collections.singletonList(plot);
|
final List<Plot> plots = Collections.singletonList(plot);
|
||||||
final boolean result = this.schematicHandler.exportAll(plots, getBackupDirectory().toFile(),
|
final boolean result = this.schematicHandler.exportAll(plots, getBackupDirectory().toFile(),
|
||||||
"%world%-%id%-" + System.currentTimeMillis(), () ->
|
"%world%-%id%-" + System.currentTimeMillis(), () ->
|
||||||
future.complete(new Backup(this, System.currentTimeMillis(), null)));
|
future.complete(new Backup(this, System.currentTimeMillis(), null))
|
||||||
|
);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
future.completeExceptionally(new RuntimeException("Failed to complete the backup"));
|
future.completeExceptionally(new RuntimeException("Failed to complete the backup"));
|
||||||
}
|
}
|
||||||
@ -168,7 +175,8 @@ public class PlayerBackupProfile implements BackupProfile {
|
|||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public CompletableFuture<Void> restoreBackup(@Nonnull final Backup backup, @Nullable PlotPlayer<?> player) {
|
@Override
|
||||||
|
public @NonNull CompletableFuture<Void> restoreBackup(final @NonNull Backup backup, @Nullable PlotPlayer<?> player) {
|
||||||
final CompletableFuture<Void> future = new CompletableFuture<>();
|
final CompletableFuture<Void> future = new CompletableFuture<>();
|
||||||
if (backup.getFile() == null || !Files.exists(backup.getFile())) {
|
if (backup.getFile() == null || !Files.exists(backup.getFile())) {
|
||||||
future.completeExceptionally(new IllegalArgumentException("The specific backup does not exist"));
|
future.completeExceptionally(new IllegalArgumentException("The specific backup does not exist"));
|
||||||
@ -181,15 +189,19 @@ public class PlayerBackupProfile implements BackupProfile {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (schematic == null) {
|
if (schematic == null) {
|
||||||
future.completeExceptionally(new IllegalArgumentException("The backup is non-existent or not in the correct format"));
|
future.completeExceptionally(new IllegalArgumentException(
|
||||||
|
"The backup is non-existent or not in the correct format"));
|
||||||
} else {
|
} else {
|
||||||
this.schematicHandler.paste(schematic, plot, 0, 1, 0, false, player, new RunnableVal<Boolean>() {
|
this.schematicHandler.paste(schematic, plot, 0, 1, 0, false, player, new RunnableVal<Boolean>() {
|
||||||
@Override public void run(Boolean value) {
|
@Override
|
||||||
|
public void run(Boolean value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
future.complete(null);
|
future.complete(null);
|
||||||
} else {
|
} else {
|
||||||
future.completeExceptionally(new RuntimeException(MINI_MESSAGE.stripTokens(
|
future.completeExceptionally(new RuntimeException(MINI_MESSAGE.stripTokens(
|
||||||
TranslatableCaption.of("schematics.schematic_paste_failed").getComponent(ConsolePlayer.getConsole()))));
|
TranslatableCaption
|
||||||
|
.of("schematics.schematic_paste_failed")
|
||||||
|
.getComponent(ConsolePlayer.getConsole()))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -38,9 +38,9 @@ import com.plotsquared.core.player.PlotPlayer;
|
|||||||
import com.plotsquared.core.plot.Plot;
|
import com.plotsquared.core.plot.Plot;
|
||||||
import com.plotsquared.core.util.task.TaskManager;
|
import com.plotsquared.core.util.task.TaskManager;
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -50,16 +50,18 @@ import java.util.concurrent.TimeUnit;
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Singleton public class SimpleBackupManager implements BackupManager {
|
@Singleton
|
||||||
|
public class SimpleBackupManager implements BackupManager {
|
||||||
|
|
||||||
private final Path backupPath;
|
private final Path backupPath;
|
||||||
private final boolean automaticBackup;
|
private final boolean automaticBackup;
|
||||||
private final int backupLimit;
|
private final int backupLimit;
|
||||||
private final Cache<PlotCacheKey, BackupProfile> backupProfileCache = CacheBuilder.newBuilder()
|
private final Cache<PlotCacheKey, BackupProfile> backupProfileCache = CacheBuilder.newBuilder()
|
||||||
.expireAfterAccess(3, TimeUnit.MINUTES).build();
|
.expireAfterAccess(3, TimeUnit.MINUTES).build();
|
||||||
private final PlayerBackupProfileFactory playerBackupProfileFactory;
|
private final PlayerBackupProfileFactory playerBackupProfileFactory;
|
||||||
|
|
||||||
@Inject public SimpleBackupManager(@Nonnull final PlayerBackupProfileFactory playerBackupProfileFactory) throws Exception {
|
@Inject
|
||||||
|
public SimpleBackupManager(final @NonNull PlayerBackupProfileFactory playerBackupProfileFactory) throws Exception {
|
||||||
this.playerBackupProfileFactory = playerBackupProfileFactory;
|
this.playerBackupProfileFactory = playerBackupProfileFactory;
|
||||||
this.backupPath = Objects.requireNonNull(PlotSquared.platform()).getDirectory().toPath().resolve("backups");
|
this.backupPath = Objects.requireNonNull(PlotSquared.platform()).getDirectory().toPath().resolve("backups");
|
||||||
if (!Files.exists(backupPath)) {
|
if (!Files.exists(backupPath)) {
|
||||||
@ -69,18 +71,24 @@ import java.util.concurrent.TimeUnit;
|
|||||||
this.backupLimit = Settings.Backup.BACKUP_LIMIT;
|
this.backupLimit = Settings.Backup.BACKUP_LIMIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleBackupManager(final Path backupPath, final boolean automaticBackup,
|
public SimpleBackupManager(
|
||||||
final int backupLimit, final PlayerBackupProfileFactory playerBackupProfileFactory) {
|
final Path backupPath, final boolean automaticBackup,
|
||||||
|
final int backupLimit, final PlayerBackupProfileFactory playerBackupProfileFactory
|
||||||
|
) {
|
||||||
this.backupPath = backupPath;
|
this.backupPath = backupPath;
|
||||||
this.automaticBackup = automaticBackup;
|
this.automaticBackup = automaticBackup;
|
||||||
this.backupLimit = backupLimit;
|
this.backupLimit = backupLimit;
|
||||||
this.playerBackupProfileFactory = playerBackupProfileFactory;
|
this.playerBackupProfileFactory = playerBackupProfileFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public BackupProfile getProfile(@Nonnull final Plot plot) {
|
@Override
|
||||||
|
public @NonNull BackupProfile getProfile(final @NonNull Plot plot) {
|
||||||
if (plot.hasOwner()) {
|
if (plot.hasOwner()) {
|
||||||
try {
|
try {
|
||||||
return backupProfileCache.get(new PlotCacheKey(plot), () -> this.playerBackupProfileFactory.create(plot.getOwnerAbs(), plot));
|
return backupProfileCache.get(
|
||||||
|
new PlotCacheKey(plot),
|
||||||
|
() -> this.playerBackupProfileFactory.create(plot.getOwnerAbs(), plot)
|
||||||
|
);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
final BackupProfile profile = this.playerBackupProfileFactory.create(plot.getOwnerAbs(), plot);
|
final BackupProfile profile = this.playerBackupProfileFactory.create(plot.getOwnerAbs(), plot);
|
||||||
this.backupProfileCache.put(new PlotCacheKey(plot), profile);
|
this.backupProfileCache.put(new PlotCacheKey(plot), profile);
|
||||||
@ -90,32 +98,39 @@ import java.util.concurrent.TimeUnit;
|
|||||||
return new NullBackupProfile();
|
return new NullBackupProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void automaticBackup(@Nullable PlotPlayer player, @Nonnull final Plot plot, @Nonnull Runnable whenDone) {
|
@Override
|
||||||
|
public void automaticBackup(@Nullable PlotPlayer player, final @NonNull Plot plot, @NonNull Runnable whenDone) {
|
||||||
final BackupProfile profile;
|
final BackupProfile profile;
|
||||||
if (!this.shouldAutomaticallyBackup() || (profile = getProfile(plot)) instanceof NullBackupProfile) {
|
if (!this.shouldAutomaticallyBackup() || (profile = getProfile(plot)) instanceof NullBackupProfile) {
|
||||||
whenDone.run();
|
whenDone.run();
|
||||||
} else {
|
} else {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.sendMessage(TranslatableCaption.of("backups.backup_automatic_started"), Template.of("plot", String.valueOf(plot.getId())));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("backups.backup_automatic_started"),
|
||||||
|
Template.of("plot", String.valueOf(plot.getId()))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
profile.createBackup().whenComplete((backup, throwable) -> {
|
profile.createBackup().whenComplete((backup, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.sendMessage(TranslatableCaption.of("backups.backup_automatic_failure"),
|
player.sendMessage(
|
||||||
Templates.of("reason", throwable.getMessage()));
|
TranslatableCaption.of("backups.backup_automatic_failure"),
|
||||||
}
|
Templates.of("reason", throwable.getMessage())
|
||||||
throwable.printStackTrace();
|
);
|
||||||
} else {
|
}
|
||||||
if (player != null) {
|
throwable.printStackTrace();
|
||||||
player.sendMessage(TranslatableCaption.of("backups.backup_automatic_finished"));
|
} else {
|
||||||
TaskManager.runTaskAsync(whenDone);
|
if (player != null) {
|
||||||
}
|
player.sendMessage(TranslatableCaption.of("backups.backup_automatic_finished"));
|
||||||
}
|
TaskManager.runTaskAsync(whenDone);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean shouldAutomaticallyBackup() {
|
@Override
|
||||||
|
public boolean shouldAutomaticallyBackup() {
|
||||||
return this.automaticBackup;
|
return this.automaticBackup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +150,8 @@ import java.util.concurrent.TimeUnit;
|
|||||||
this.plot = plot;
|
this.plot = plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean equals(final Object o) {
|
@Override
|
||||||
|
public boolean equals(final Object o) {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -144,13 +160,15 @@ import java.util.concurrent.TimeUnit;
|
|||||||
}
|
}
|
||||||
final PlotCacheKey that = (PlotCacheKey) o;
|
final PlotCacheKey that = (PlotCacheKey) o;
|
||||||
return Objects.equals(plot.getArea(), that.plot.getArea())
|
return Objects.equals(plot.getArea(), that.plot.getArea())
|
||||||
&& Objects.equals(plot.getId(), that.plot.getId())
|
&& Objects.equals(plot.getId(), that.plot.getId())
|
||||||
&& Objects.equals(plot.getOwnerAbs(), that.plot.getOwnerAbs());
|
&& Objects.equals(plot.getOwnerAbs(), that.plot.getOwnerAbs());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public int hashCode() {
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
return Objects.hash(plot.getArea(), plot.getId(), plot.getOwnerAbs());
|
return Objects.hash(plot.getArea(), plot.getId(), plot.getOwnerAbs());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ package com.plotsquared.core.collection;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class ArrayUtil {
|
public class ArrayUtil {
|
||||||
|
|
||||||
public static final <T> T[] concatAll(T[] first, T[]... rest) {
|
public static final <T> T[] concatAll(T[] first, T[]... rest) {
|
||||||
int totalLength = first.length;
|
int totalLength = first.length;
|
||||||
for (T[] array : rest) {
|
for (T[] array : rest) {
|
||||||
@ -41,4 +42,5 @@ public class ArrayUtil {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ public class ByteArrayUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] booleanToBytes(boolean b) {
|
public static byte[] booleanToBytes(boolean b) {
|
||||||
return new byte[] {(byte) (b ? 1 : 0)};
|
return new byte[]{(byte) (b ? 1 : 0)};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import java.util.Map;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class FlatRandomCollection<T> extends RandomCollection<T> {
|
public class FlatRandomCollection<T> extends RandomCollection<T> {
|
||||||
|
|
||||||
private T[] values;
|
private T[] values;
|
||||||
|
|
||||||
public FlatRandomCollection(Map<T, Double> weights, Random random) {
|
public FlatRandomCollection(Map<T, Double> weights, Random random) {
|
||||||
@ -63,7 +64,9 @@ public class FlatRandomCollection<T> extends RandomCollection<T> {
|
|||||||
this.values = (T[]) parsed.toArray();
|
this.values = (T[]) parsed.toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public T next() {
|
@Override
|
||||||
|
public T next() {
|
||||||
return values[random.nextInt(values.length)];
|
return values[random.nextInt(values.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -127,8 +127,9 @@ public class QuadMap<T> {
|
|||||||
if (region.getMinimumPoint().getZ() >= this.z) {
|
if (region.getMinimumPoint().getZ() >= this.z) {
|
||||||
if (this.one == null) {
|
if (this.one == null) {
|
||||||
this.one =
|
this.one =
|
||||||
newInstance(this.newsize, this.x + this.newsize, this.z + this.newsize,
|
newInstance(this.newsize, this.x + this.newsize, this.z + this.newsize,
|
||||||
this.min);
|
this.min
|
||||||
|
);
|
||||||
}
|
}
|
||||||
this.one.add(area);
|
this.one.add(area);
|
||||||
recalculateSkip();
|
recalculateSkip();
|
||||||
@ -136,8 +137,9 @@ public class QuadMap<T> {
|
|||||||
} else if (region.getMaximumPoint().getZ() < this.z) {
|
} else if (region.getMaximumPoint().getZ() < this.z) {
|
||||||
if (this.two == null) {
|
if (this.two == null) {
|
||||||
this.two =
|
this.two =
|
||||||
newInstance(this.newsize, this.x + this.newsize, this.z - this.newsize,
|
newInstance(this.newsize, this.x + this.newsize, this.z - this.newsize,
|
||||||
this.min);
|
this.min
|
||||||
|
);
|
||||||
}
|
}
|
||||||
this.two.add(area);
|
this.two.add(area);
|
||||||
recalculateSkip();
|
recalculateSkip();
|
||||||
@ -147,8 +149,9 @@ public class QuadMap<T> {
|
|||||||
if (region.getMinimumPoint().getZ() >= this.z) {
|
if (region.getMinimumPoint().getZ() >= this.z) {
|
||||||
if (this.four == null) {
|
if (this.four == null) {
|
||||||
this.four =
|
this.four =
|
||||||
newInstance(this.newsize, this.x - this.newsize, this.z + this.newsize,
|
newInstance(this.newsize, this.x - this.newsize, this.z + this.newsize,
|
||||||
this.min);
|
this.min
|
||||||
|
);
|
||||||
}
|
}
|
||||||
this.four.add(area);
|
this.four.add(area);
|
||||||
recalculateSkip();
|
recalculateSkip();
|
||||||
@ -156,8 +159,9 @@ public class QuadMap<T> {
|
|||||||
} else if (region.getMaximumPoint().getZ() < this.z) {
|
} else if (region.getMaximumPoint().getZ() < this.z) {
|
||||||
if (this.three == null) {
|
if (this.three == null) {
|
||||||
this.three =
|
this.three =
|
||||||
newInstance(this.newsize, this.x - this.newsize, this.z - this.newsize,
|
newInstance(this.newsize, this.x - this.newsize, this.z - this.newsize,
|
||||||
this.min);
|
this.min
|
||||||
|
);
|
||||||
}
|
}
|
||||||
this.three.add(area);
|
this.three.add(area);
|
||||||
recalculateSkip();
|
recalculateSkip();
|
||||||
@ -177,7 +181,8 @@ public class QuadMap<T> {
|
|||||||
public QuadMap<T> newInstance(int newsize, int x, int z, int min) {
|
public QuadMap<T> newInstance(int newsize, int x, int z, int min) {
|
||||||
try {
|
try {
|
||||||
return new QuadMap<T>(newsize, x, z, min) {
|
return new QuadMap<T>(newsize, x, z, min) {
|
||||||
@Override public CuboidRegion getRegion(T value) {
|
@Override
|
||||||
|
public CuboidRegion getRegion(T value) {
|
||||||
return QuadMap.this.getRegion(value);
|
return QuadMap.this.getRegion(value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -238,7 +243,7 @@ public class QuadMap<T> {
|
|||||||
|
|
||||||
public void recalculateSkip() {
|
public void recalculateSkip() {
|
||||||
QuadMap<T> map = null;
|
QuadMap<T> map = null;
|
||||||
for (QuadMap<T> current : new QuadMap[] {this.one, this.two, this.three, this.four}) {
|
for (QuadMap<T> current : new QuadMap[]{this.one, this.two, this.three, this.four}) {
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
this.skip = null;
|
this.skip = null;
|
||||||
@ -282,8 +287,8 @@ public class QuadMap<T> {
|
|||||||
|
|
||||||
public boolean intersects(CuboidRegion other) {
|
public boolean intersects(CuboidRegion other) {
|
||||||
return (other.getMinimumPoint().getX() <= this.x + this.size) && (
|
return (other.getMinimumPoint().getX() <= this.x + this.size) && (
|
||||||
other.getMaximumPoint().getX() >= this.x - this.size) && (other.getMinimumPoint().getZ()
|
other.getMaximumPoint().getX() >= this.x - this.size) && (other.getMinimumPoint().getZ()
|
||||||
<= this.z + this.size) && (other.getMaximumPoint().getZ() >= this.z - this.size);
|
<= this.z + this.size) && (other.getMaximumPoint().getZ() >= this.z - this.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T get(int x, int z) {
|
public T get(int x, int z) {
|
||||||
@ -321,4 +326,5 @@ public class QuadMap<T> {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ import java.util.Random;
|
|||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
public abstract class RandomCollection<T> {
|
public abstract class RandomCollection<T> {
|
||||||
|
|
||||||
protected Random random;
|
protected Random random;
|
||||||
|
|
||||||
public RandomCollection(Map<T, Double> weights, Random random) {
|
public RandomCollection(Map<T, Double> weights, Random random) {
|
||||||
@ -55,4 +56,5 @@ public abstract class RandomCollection<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract T next();
|
public abstract T next();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,9 @@ public class SimpleRandomCollection<E> extends RandomCollection<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void add(double weight, E result) {
|
public void add(double weight, E result) {
|
||||||
if (weight <= 0)
|
if (weight <= 0) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
total += weight;
|
total += weight;
|
||||||
map.put(total, result);
|
map.put(total, result);
|
||||||
}
|
}
|
||||||
@ -52,4 +53,5 @@ public class SimpleRandomCollection<E> extends RandomCollection<E> {
|
|||||||
public E next() {
|
public E next() {
|
||||||
return map.ceilingEntry(random.nextDouble()).getValue();
|
return map.ceilingEntry(random.nextDouble()).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,9 @@ package com.plotsquared.core.command;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.plotsquared.core.configuration.Settings;
|
import com.plotsquared.core.configuration.Settings;
|
||||||
import com.plotsquared.core.permissions.Permission;
|
|
||||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||||
import com.plotsquared.core.database.DBFunc;
|
import com.plotsquared.core.database.DBFunc;
|
||||||
|
import com.plotsquared.core.permissions.Permission;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import com.plotsquared.core.plot.Plot;
|
import com.plotsquared.core.plot.Plot;
|
||||||
import com.plotsquared.core.util.EventDispatcher;
|
import com.plotsquared.core.util.EventDispatcher;
|
||||||
@ -39,8 +39,8 @@ import com.plotsquared.core.util.TabCompletions;
|
|||||||
import com.plotsquared.core.util.task.RunnableVal2;
|
import com.plotsquared.core.util.task.RunnableVal2;
|
||||||
import com.plotsquared.core.util.task.RunnableVal3;
|
import com.plotsquared.core.util.task.RunnableVal3;
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -49,66 +49,81 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
@CommandDeclaration(command = "add",
|
@CommandDeclaration(command = "add",
|
||||||
usage = "/plot add <player | *>",
|
usage = "/plot add <player | *>",
|
||||||
category = CommandCategory.SETTINGS,
|
category = CommandCategory.SETTINGS,
|
||||||
permission = "plots.add",
|
permission = "plots.add",
|
||||||
requiredType = RequiredType.PLAYER)
|
requiredType = RequiredType.PLAYER)
|
||||||
public class Add extends Command {
|
public class Add extends Command {
|
||||||
|
|
||||||
private final EventDispatcher eventDispatcher;
|
private final EventDispatcher eventDispatcher;
|
||||||
|
|
||||||
@Inject public Add(@Nonnull final EventDispatcher eventDispatcher) {
|
@Inject
|
||||||
|
public Add(final @NonNull EventDispatcher eventDispatcher) {
|
||||||
super(MainCommand.getInstance(), true);
|
super(MainCommand.getInstance(), true);
|
||||||
this.eventDispatcher = eventDispatcher;
|
this.eventDispatcher = eventDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
|
public CompletableFuture<Boolean> execute(
|
||||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
final PlotPlayer<?> player, String[] args,
|
||||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||||
|
RunnableVal2<Command, CommandResult> whenDone
|
||||||
|
) throws CommandException {
|
||||||
final Plot plot = check(player.getCurrentPlot(), TranslatableCaption.of("errors.not_in_plot"));
|
final Plot plot = check(player.getCurrentPlot(), TranslatableCaption.of("errors.not_in_plot"));
|
||||||
checkTrue(plot.hasOwner(), TranslatableCaption.of("info.plot_unowned"));
|
checkTrue(plot.hasOwner(), TranslatableCaption.of("info.plot_unowned"));
|
||||||
checkTrue(plot.isOwner(player.getUUID()) || Permissions
|
checkTrue(
|
||||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST),
|
plot.isOwner(player.getUUID()) || Permissions
|
||||||
TranslatableCaption.of("permission.no_plot_perms"));
|
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST),
|
||||||
|
TranslatableCaption.of("permission.no_plot_perms")
|
||||||
|
);
|
||||||
checkTrue(args.length == 1, TranslatableCaption.of("commandconfig.command_syntax"),
|
checkTrue(args.length == 1, TranslatableCaption.of("commandconfig.command_syntax"),
|
||||||
Template.of("value", "/plot add <player | *>"));
|
Template.of("value", "/plot add <player | *>")
|
||||||
|
);
|
||||||
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||||
PlayerManager.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
PlayerManager.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
if (throwable instanceof TimeoutException) {
|
if (throwable instanceof TimeoutException) {
|
||||||
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
|
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(TranslatableCaption.of("errors.invalid_player"),
|
player.sendMessage(
|
||||||
Template.of("value", args[0]));
|
TranslatableCaption.of("errors.invalid_player"),
|
||||||
|
Template.of("value", args[0])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
future.completeExceptionally(throwable);
|
future.completeExceptionally(throwable);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
checkTrue(!uuids.isEmpty(), TranslatableCaption.of("errors.invalid_player"),
|
checkTrue(!uuids.isEmpty(), TranslatableCaption.of("errors.invalid_player"),
|
||||||
Template.of("value", args[0]));
|
Template.of("value", args[0])
|
||||||
|
);
|
||||||
Iterator<UUID> iterator = uuids.iterator();
|
Iterator<UUID> iterator = uuids.iterator();
|
||||||
int size = plot.getTrusted().size() + plot.getMembers().size();
|
int size = plot.getTrusted().size() + plot.getMembers().size();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
UUID uuid = iterator.next();
|
UUID uuid = iterator.next();
|
||||||
if (uuid == DBFunc.EVERYONE && !(
|
if (uuid == DBFunc.EVERYONE && !(
|
||||||
Permissions.hasPermission(player, Permission.PERMISSION_TRUST_EVERYONE) || Permissions
|
Permissions.hasPermission(player, Permission.PERMISSION_TRUST_EVERYONE) || Permissions
|
||||||
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
||||||
player.sendMessage(TranslatableCaption.of("errors.invalid_player"),
|
player.sendMessage(
|
||||||
Template.of("value", PlayerManager.getName(uuid)));
|
TranslatableCaption.of("errors.invalid_player"),
|
||||||
|
Template.of("value", PlayerManager.getName(uuid))
|
||||||
|
);
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (plot.isOwner(uuid)) {
|
if (plot.isOwner(uuid)) {
|
||||||
player.sendMessage(TranslatableCaption.of("member.already_added"),
|
player.sendMessage(
|
||||||
Template.of("player", PlayerManager.getName(uuid)));
|
TranslatableCaption.of("member.already_added"),
|
||||||
|
Template.of("player", PlayerManager.getName(uuid))
|
||||||
|
);
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (plot.getMembers().contains(uuid)) {
|
if (plot.getMembers().contains(uuid)) {
|
||||||
player.sendMessage(TranslatableCaption.of("member.already_added"),
|
player.sendMessage(
|
||||||
Template.of("player", PlayerManager.getName(uuid)));
|
TranslatableCaption.of("member.already_added"),
|
||||||
|
Template.of("player", PlayerManager.getName(uuid))
|
||||||
|
);
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -117,7 +132,10 @@ public class Add extends Command {
|
|||||||
checkTrue(!uuids.isEmpty(), null);
|
checkTrue(!uuids.isEmpty(), null);
|
||||||
int maxAddSize = Permissions.hasPermissionRange(player, Permission.PERMISSION_ADD, Settings.Limit.MAX_PLOTS);
|
int maxAddSize = Permissions.hasPermissionRange(player, Permission.PERMISSION_ADD, Settings.Limit.MAX_PLOTS);
|
||||||
if (size > maxAddSize) {
|
if (size > maxAddSize) {
|
||||||
player.sendMessage(TranslatableCaption.of("members.plot_max_members_added"), Template.of("amount", String.valueOf(size - 1)));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("members.plot_max_members_added"),
|
||||||
|
Template.of("amount", String.valueOf(size - 1))
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Success
|
// Success
|
||||||
@ -145,7 +163,8 @@ public class Add extends Command {
|
|||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
|
@Override
|
||||||
|
public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
|
||||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,10 +26,10 @@
|
|||||||
package com.plotsquared.core.command;
|
package com.plotsquared.core.command;
|
||||||
|
|
||||||
import com.plotsquared.core.PlotSquared;
|
import com.plotsquared.core.PlotSquared;
|
||||||
import com.plotsquared.core.permissions.Permission;
|
|
||||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
|
||||||
import com.plotsquared.core.configuration.Settings;
|
import com.plotsquared.core.configuration.Settings;
|
||||||
|
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||||
import com.plotsquared.core.location.Location;
|
import com.plotsquared.core.location.Location;
|
||||||
|
import com.plotsquared.core.permissions.Permission;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import com.plotsquared.core.plot.Plot;
|
import com.plotsquared.core.plot.Plot;
|
||||||
import com.plotsquared.core.util.MathMan;
|
import com.plotsquared.core.util.MathMan;
|
||||||
@ -44,16 +44,20 @@ import java.util.List;
|
|||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
@CommandDeclaration(command = "alias",
|
@CommandDeclaration(command = "alias",
|
||||||
permission = "plots.alias",
|
permission = "plots.alias",
|
||||||
usage = "/plot alias <set | remove> <alias>",
|
usage = "/plot alias <set | remove> <alias>",
|
||||||
aliases = {"setalias", "sa", "name", "rename", "setname", "seta", "nameplot"},
|
aliases = {"setalias", "sa", "name", "rename", "setname", "seta", "nameplot"},
|
||||||
category = CommandCategory.SETTINGS,
|
category = CommandCategory.SETTINGS,
|
||||||
requiredType = RequiredType.PLAYER)
|
requiredType = RequiredType.PLAYER)
|
||||||
public class Alias extends SubCommand {
|
public class Alias extends SubCommand {
|
||||||
private static final Command SET_COMMAND = new Command(null, false, "set", null, RequiredType.NONE, null) {};
|
|
||||||
private static final Command REMOVE_COMMAND = new Command(null, false, "remove", null, RequiredType.NONE, null) {};
|
|
||||||
|
|
||||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
private static final Command SET_COMMAND = new Command(null, false, "set", null, RequiredType.NONE, null) {
|
||||||
|
};
|
||||||
|
private static final Command REMOVE_COMMAND = new Command(null, false, "remove", null, RequiredType.NONE, null) {
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
sendUsage(player);
|
sendUsage(player);
|
||||||
@ -94,8 +98,10 @@ public class Alias extends SubCommand {
|
|||||||
setAlias(player, plot, args[1]);
|
setAlias(player, plot, args[1]);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
player.sendMessage(
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ALIAS_SET)));
|
TranslatableCaption.of("permission.no_permission"),
|
||||||
|
Template.of("node", String.valueOf(Permission.PERMISSION_ALIAS_SET))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -109,8 +115,10 @@ public class Alias extends SubCommand {
|
|||||||
if (permission) {
|
if (permission) {
|
||||||
result = removeAlias(player, plot);
|
result = removeAlias(player, plot);
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
player.sendMessage(
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ALIAS_REMOVE)));
|
TranslatableCaption.of("permission.no_permission"),
|
||||||
|
Template.of("node", String.valueOf(Permission.PERMISSION_ALIAS_REMOVE))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -162,8 +170,10 @@ public class Alias extends SubCommand {
|
|||||||
player.sendMessage(TranslatableCaption.of("alias.alias_is_taken"));
|
player.sendMessage(TranslatableCaption.of("alias.alias_is_taken"));
|
||||||
} else {
|
} else {
|
||||||
plot.setAlias(alias);
|
plot.setAlias(alias);
|
||||||
player.sendMessage(TranslatableCaption.of("alias.alias_set_to"),
|
player.sendMessage(
|
||||||
Template.of("alias", alias));
|
TranslatableCaption.of("alias.alias_set_to"),
|
||||||
|
Template.of("alias", alias)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -171,12 +181,15 @@ public class Alias extends SubCommand {
|
|||||||
|
|
||||||
private boolean removeAlias(PlotPlayer<?> player, Plot plot) {
|
private boolean removeAlias(PlotPlayer<?> player, Plot plot) {
|
||||||
plot.setAlias(null);
|
plot.setAlias(null);
|
||||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
player.sendMessage(
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ALIAS_REMOVE)));
|
TranslatableCaption.of("permission.no_permission"),
|
||||||
|
Template.of("node", String.valueOf(Permission.PERMISSION_ALIAS_REMOVE))
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPermitted(PlotPlayer<?> player, Permission permission) {
|
private boolean isPermitted(PlotPlayer<?> player, Permission permission) {
|
||||||
return Permissions.hasPermission(player, permission);
|
return Permissions.hasPermission(player, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -76,8 +76,8 @@ import com.sk89q.worldedit.math.BlockVector3;
|
|||||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -95,12 +95,12 @@ import java.util.UUID;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@CommandDeclaration(command = "area",
|
@CommandDeclaration(command = "area",
|
||||||
permission = "plots.area",
|
permission = "plots.area",
|
||||||
category = CommandCategory.ADMINISTRATION,
|
category = CommandCategory.ADMINISTRATION,
|
||||||
requiredType = RequiredType.NONE,
|
requiredType = RequiredType.NONE,
|
||||||
aliases = "world",
|
aliases = "world",
|
||||||
usage = "/plot area <create | info | list | tp | regen>",
|
usage = "/plot area <create | info | list | tp | regen>",
|
||||||
confirmation = true)
|
confirmation = true)
|
||||||
public class Area extends SubCommand {
|
public class Area extends SubCommand {
|
||||||
|
|
||||||
private final PlotAreaManager plotAreaManager;
|
private final PlotAreaManager plotAreaManager;
|
||||||
@ -114,14 +114,17 @@ public class Area extends SubCommand {
|
|||||||
|
|
||||||
private final Map<UUID, Map<String, Object>> metaData = new HashMap<>();
|
private final Map<UUID, Map<String, Object>> metaData = new HashMap<>();
|
||||||
|
|
||||||
@Inject public Area(@Nonnull final PlotAreaManager plotAreaManager,
|
@Inject
|
||||||
@WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
|
public Area(
|
||||||
@WorldFile @Nonnull final File worldFile,
|
final @NonNull PlotAreaManager plotAreaManager,
|
||||||
@Nonnull final HybridPlotWorldFactory hybridPlotWorldFactory,
|
@WorldConfig final @NonNull YamlConfiguration worldConfiguration,
|
||||||
@Nonnull final SetupUtils setupUtils,
|
@WorldFile final @NonNull File worldFile,
|
||||||
@Nonnull final WorldUtil worldUtil,
|
final @NonNull HybridPlotWorldFactory hybridPlotWorldFactory,
|
||||||
@Nonnull final RegionManager regionManager,
|
final @NonNull SetupUtils setupUtils,
|
||||||
@Nonnull final GlobalBlockQueue blockQueue) {
|
final @NonNull WorldUtil worldUtil,
|
||||||
|
final @NonNull RegionManager regionManager,
|
||||||
|
final @NonNull GlobalBlockQueue blockQueue
|
||||||
|
) {
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
this.worldConfiguration = worldConfiguration;
|
this.worldConfiguration = worldConfiguration;
|
||||||
this.worldFile = worldFile;
|
this.worldFile = worldFile;
|
||||||
@ -132,7 +135,8 @@ public class Area extends SubCommand {
|
|||||||
this.blockQueue = blockQueue;
|
this.blockQueue = blockQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
@Override
|
||||||
|
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
sendUsage(player);
|
sendUsage(player);
|
||||||
return false;
|
return false;
|
||||||
@ -144,11 +148,17 @@ public class Area extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_CREATE)) {
|
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_CREATE)) {
|
||||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", String.valueOf(Permission.PERMISSION_AREA_CREATE)));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("permission.no_permission"),
|
||||||
|
Template.of("node", String.valueOf(Permission.PERMISSION_AREA_CREATE))
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
player.sendMessage(TranslatableCaption.of("single.single_area_needs_name"), Template.of("command", "/plot area single <name>"));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("single.single_area_needs_name"),
|
||||||
|
Template.of("command", "/plot area single <name>")
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final PlotArea existingArea = this.plotAreaManager.getPlotArea(player.getLocation().getWorldName(), args[1]);
|
final PlotArea existingArea = this.plotAreaManager.getPlotArea(player.getLocation().getWorldName(), args[1]);
|
||||||
@ -174,8 +184,10 @@ public class Area extends SubCommand {
|
|||||||
player.sendMessage(TranslatableCaption.of("single.single_area_not_square"));
|
player.sendMessage(TranslatableCaption.of("single.single_area_not_square"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.plotAreaManager.getPlotAreas(Objects.requireNonNull(playerSelectedRegion.getWorld()).getName(),
|
if (this.plotAreaManager.getPlotAreas(
|
||||||
CuboidRegion.makeCuboid(playerSelectedRegion)).length != 0) {
|
Objects.requireNonNull(playerSelectedRegion.getWorld()).getName(),
|
||||||
|
CuboidRegion.makeCuboid(playerSelectedRegion)
|
||||||
|
).length != 0) {
|
||||||
player.sendMessage(TranslatableCaption.of("single.single_area_overlapping"));
|
player.sendMessage(TranslatableCaption.of("single.single_area_overlapping"));
|
||||||
}
|
}
|
||||||
// Alter the region
|
// Alter the region
|
||||||
@ -183,13 +195,19 @@ public class Area extends SubCommand {
|
|||||||
final BlockVector3 playerSelectionMax = playerSelectedRegion.getMaximumPoint();
|
final BlockVector3 playerSelectionMax = playerSelectedRegion.getMaximumPoint();
|
||||||
// Create a new selection that spans the entire vertical range of the world
|
// Create a new selection that spans the entire vertical range of the world
|
||||||
final CuboidRegion selectedRegion =
|
final CuboidRegion selectedRegion =
|
||||||
new CuboidRegion(playerSelectedRegion.getWorld(), BlockVector3.at(playerSelectionMin.getX(), 0, playerSelectionMin.getZ()),
|
new CuboidRegion(playerSelectedRegion.getWorld(),
|
||||||
BlockVector3.at(playerSelectionMax.getX(), 255, playerSelectionMax.getZ()));
|
BlockVector3.at(playerSelectionMin.getX(), 0, playerSelectionMin.getZ()),
|
||||||
|
BlockVector3.at(playerSelectionMax.getX(), 255, playerSelectionMax.getZ())
|
||||||
|
);
|
||||||
// There's only one plot in the area...
|
// There's only one plot in the area...
|
||||||
final PlotId plotId = PlotId.of(1, 1);
|
final PlotId plotId = PlotId.of(1, 1);
|
||||||
final HybridPlotWorld hybridPlotWorld = this.hybridPlotWorldFactory
|
final HybridPlotWorld hybridPlotWorld = this.hybridPlotWorldFactory
|
||||||
.create(player.getLocation().getWorldName(), args[1], Objects.requireNonNull(PlotSquared.platform()).defaultGenerator(),
|
.create(player.getLocation().getWorldName(),
|
||||||
plotId, plotId);
|
args[1],
|
||||||
|
Objects.requireNonNull(PlotSquared.platform()).defaultGenerator(),
|
||||||
|
plotId,
|
||||||
|
plotId
|
||||||
|
);
|
||||||
// Plot size is the same as the region width
|
// Plot size is the same as the region width
|
||||||
hybridPlotWorld.PLOT_WIDTH = hybridPlotWorld.SIZE = (short) selectedRegion.getWidth();
|
hybridPlotWorld.PLOT_WIDTH = hybridPlotWorld.SIZE = (short) selectedRegion.getWidth();
|
||||||
// We use a schematic generator
|
// We use a schematic generator
|
||||||
@ -204,19 +222,25 @@ public class Area extends SubCommand {
|
|||||||
hybridPlotWorld.PLOT_HEIGHT = hybridPlotWorld.ROAD_HEIGHT = hybridPlotWorld.WALL_HEIGHT = playerSelectionMin.getBlockY();
|
hybridPlotWorld.PLOT_HEIGHT = hybridPlotWorld.ROAD_HEIGHT = hybridPlotWorld.WALL_HEIGHT = playerSelectionMin.getBlockY();
|
||||||
// No sign plz
|
// No sign plz
|
||||||
hybridPlotWorld.setAllowSigns(false);
|
hybridPlotWorld.setAllowSigns(false);
|
||||||
final File parentFile = FileUtils.getFile(PlotSquared.platform().getDirectory(),
|
final File parentFile = FileUtils.getFile(
|
||||||
"schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + hybridPlotWorld.getWorldName() + File.separator
|
PlotSquared.platform().getDirectory(),
|
||||||
+ hybridPlotWorld.getId());
|
"schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + hybridPlotWorld.getWorldName() + File.separator
|
||||||
|
+ hybridPlotWorld.getId()
|
||||||
|
);
|
||||||
if (!parentFile.exists() && !parentFile.mkdirs()) {
|
if (!parentFile.exists() && !parentFile.mkdirs()) {
|
||||||
player.sendMessage(TranslatableCaption.of("single.single_area_could_not_make_directories"));
|
player.sendMessage(TranslatableCaption.of("single.single_area_could_not_make_directories"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final File file = new File(parentFile, "plot.schem");
|
final File file = new File(parentFile, "plot.schem");
|
||||||
try (final ClipboardWriter clipboardWriter = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) {
|
try (final ClipboardWriter clipboardWriter = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(
|
||||||
|
file))) {
|
||||||
final BlockArrayClipboard clipboard = new BlockArrayClipboard(selectedRegion);
|
final BlockArrayClipboard clipboard = new BlockArrayClipboard(selectedRegion);
|
||||||
final EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(selectedRegion.getWorld(), -1);
|
final EditSession editSession = WorldEdit
|
||||||
|
.getInstance()
|
||||||
|
.getEditSessionFactory()
|
||||||
|
.getEditSession(selectedRegion.getWorld(), -1);
|
||||||
final ForwardExtentCopy forwardExtentCopy =
|
final ForwardExtentCopy forwardExtentCopy =
|
||||||
new ForwardExtentCopy(editSession, selectedRegion, clipboard, selectedRegion.getMinimumPoint());
|
new ForwardExtentCopy(editSession, selectedRegion, clipboard, selectedRegion.getMinimumPoint());
|
||||||
forwardExtentCopy.setCopyingBiomes(true);
|
forwardExtentCopy.setCopyingBiomes(true);
|
||||||
forwardExtentCopy.setCopyingEntities(true);
|
forwardExtentCopy.setCopyingEntities(true);
|
||||||
Operations.complete(forwardExtentCopy);
|
Operations.complete(forwardExtentCopy);
|
||||||
@ -238,12 +262,15 @@ public class Area extends SubCommand {
|
|||||||
final BlockVector3 singlePos1 = selectedRegion.getMinimumPoint();
|
final BlockVector3 singlePos1 = selectedRegion.getMinimumPoint();
|
||||||
|
|
||||||
// Now the schematic is saved, which is wonderful!
|
// Now the schematic is saved, which is wonderful!
|
||||||
PlotAreaBuilder singleBuilder = PlotAreaBuilder.ofPlotArea(hybridPlotWorld).plotManager(PlotSquared.platform().pluginName())
|
PlotAreaBuilder singleBuilder = PlotAreaBuilder.ofPlotArea(hybridPlotWorld).plotManager(PlotSquared
|
||||||
.generatorName(PlotSquared.platform().pluginName()).maximumId(plotId).minimumId(plotId);
|
.platform()
|
||||||
|
.pluginName())
|
||||||
|
.generatorName(PlotSquared.platform().pluginName()).maximumId(plotId).minimumId(plotId);
|
||||||
Runnable singleRun = () -> {
|
Runnable singleRun = () -> {
|
||||||
final String path =
|
final String path =
|
||||||
"worlds." + hybridPlotWorld.getWorldName() + ".areas." + hybridPlotWorld.getId() + '-' + singleBuilder.minimumId() + '-'
|
"worlds." + hybridPlotWorld.getWorldName() + ".areas." + hybridPlotWorld.getId() + '-' + singleBuilder
|
||||||
+ singleBuilder.maximumId();
|
.minimumId() + '-'
|
||||||
|
+ singleBuilder.maximumId();
|
||||||
final int offsetX = singlePos1.getX();
|
final int offsetX = singlePos1.getX();
|
||||||
final int offsetZ = singlePos1.getZ();
|
final int offsetZ = singlePos1.getZ();
|
||||||
if (offsetX != 0) {
|
if (offsetX != 0) {
|
||||||
@ -257,7 +284,10 @@ public class Area extends SubCommand {
|
|||||||
PlotSquared.get().loadWorld(world, null);
|
PlotSquared.get().loadWorld(world, null);
|
||||||
player.sendMessage(TranslatableCaption.of("single.single_area_created"));
|
player.sendMessage(TranslatableCaption.of("single.single_area_created"));
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(TranslatableCaption.of("errors.error_create"), Template.of("world", hybridPlotWorld.getWorldName()));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("errors.error_create"),
|
||||||
|
Template.of("world", hybridPlotWorld.getWorldName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
singleRun.run();
|
singleRun.run();
|
||||||
@ -266,43 +296,67 @@ public class Area extends SubCommand {
|
|||||||
case "setup":
|
case "setup":
|
||||||
case "create":
|
case "create":
|
||||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_CREATE)) {
|
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_CREATE)) {
|
||||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", String.valueOf(Permission.PERMISSION_AREA_CREATE)));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("permission.no_permission"),
|
||||||
|
Template.of("node", String.valueOf(Permission.PERMISSION_AREA_CREATE))
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 1:
|
case 1:
|
||||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
|
player.sendMessage(
|
||||||
Templates.of("value", "/plot area create [world[:id]] [<modifier>=<value>]..."));
|
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||||
|
Templates.of("value", "/plot area create [world[:id]] [<modifier>=<value>]...")
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
case 2:
|
case 2:
|
||||||
switch (args[1].toLowerCase()) {
|
switch (args[1].toLowerCase()) {
|
||||||
case "pos1": { // Set position 1
|
case "pos1": { // Set position 1
|
||||||
HybridPlotWorld area = (HybridPlotWorld) metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>())
|
HybridPlotWorld area = (HybridPlotWorld) metaData.computeIfAbsent(
|
||||||
.get("area_create_area");
|
player.getUUID(),
|
||||||
|
missingUUID -> new HashMap<>()
|
||||||
|
)
|
||||||
|
.get("area_create_area");
|
||||||
if (area == null) {
|
if (area == null) {
|
||||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
|
player.sendMessage(
|
||||||
Templates.of("value", "/plot area create [world[:id]] [<modifier>=<value>]..."));
|
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||||
|
Templates.of("value", "/plot area create [world[:id]] [<modifier>=<value>]...")
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Location location = player.getLocation();
|
Location location = player.getLocation();
|
||||||
metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).put("area_pos1", location);
|
metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).put(
|
||||||
player.sendMessage(TranslatableCaption.of("set.set_attribute"), Template.of("attribute", "area_pos1"),
|
"area_pos1",
|
||||||
Template.of("value", location.getX() + "," + location.getZ()));
|
location
|
||||||
player.sendMessage(TranslatableCaption.of("area.set_pos2"), Template.of("command", "/plot area create pos2"));
|
);
|
||||||
|
player.sendMessage(TranslatableCaption.of("set.set_attribute"),
|
||||||
|
Template.of("attribute", "area_pos1"),
|
||||||
|
Template.of("value", location.getX() + "," + location.getZ())
|
||||||
|
);
|
||||||
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("area.set_pos2"),
|
||||||
|
Template.of("command", "/plot area create pos2")
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "pos2": // Set position 2 and finish creation for type=2 (partial)
|
case "pos2": // Set position 2 and finish creation for type=2 (partial)
|
||||||
final HybridPlotWorld area =
|
final HybridPlotWorld area =
|
||||||
(HybridPlotWorld) metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>())
|
(HybridPlotWorld) metaData.computeIfAbsent(
|
||||||
.get("area_create_area");
|
player.getUUID(),
|
||||||
|
missingUUID -> new HashMap<>()
|
||||||
|
)
|
||||||
|
.get("area_create_area");
|
||||||
if (area == null) {
|
if (area == null) {
|
||||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
|
player.sendMessage(
|
||||||
Templates.of("value", "/plot area create [world[:id]] [<modifier>=<value>]..."));
|
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||||
|
Templates.of("value", "/plot area create [world[:id]] [<modifier>=<value>]...")
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Location pos1 = player.getLocation();
|
Location pos1 = player.getLocation();
|
||||||
Location pos2 =
|
Location pos2 =
|
||||||
(Location) metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).get("area_pos1");
|
(Location) metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).get(
|
||||||
|
"area_pos1");
|
||||||
int dx = Math.abs(pos1.getX() - pos2.getX());
|
int dx = Math.abs(pos1.getX() - pos2.getX());
|
||||||
int dz = Math.abs(pos1.getZ() - pos2.getZ());
|
int dz = Math.abs(pos1.getZ() - pos2.getZ());
|
||||||
int numX = Math.max(1, (dx + 1 + area.ROAD_WIDTH + area.SIZE / 2) / area.SIZE);
|
int numX = Math.max(1, (dx + 1 + area.ROAD_WIDTH + area.SIZE / 2) / area.SIZE);
|
||||||
@ -319,16 +373,20 @@ public class Area extends SubCommand {
|
|||||||
final CuboidRegion region = RegionUtil.createRegion(bx, tx, bz, tz);
|
final CuboidRegion region = RegionUtil.createRegion(bx, tx, bz, tz);
|
||||||
final Set<PlotArea> areas = this.plotAreaManager.getPlotAreasSet(area.getWorldName(), region);
|
final Set<PlotArea> areas = this.plotAreaManager.getPlotAreasSet(area.getWorldName(), region);
|
||||||
if (!areas.isEmpty()) {
|
if (!areas.isEmpty()) {
|
||||||
player.sendMessage(TranslatableCaption.of("cluster.cluster_intersection"),
|
player.sendMessage(
|
||||||
Template.of("cluster", areas.iterator().next().toString()));
|
TranslatableCaption.of("cluster.cluster_intersection"),
|
||||||
|
Template.of("cluster", areas.iterator().next().toString())
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotAreaBuilder builder = PlotAreaBuilder.ofPlotArea(area).plotManager(PlotSquared.platform().pluginName())
|
PlotAreaBuilder builder = PlotAreaBuilder.ofPlotArea(area).plotManager(PlotSquared
|
||||||
.generatorName(PlotSquared.platform().pluginName()).minimumId(PlotId.of(1, 1))
|
.platform()
|
||||||
.maximumId(PlotId.of(numX, numZ));
|
.pluginName())
|
||||||
|
.generatorName(PlotSquared.platform().pluginName()).minimumId(PlotId.of(1, 1))
|
||||||
|
.maximumId(PlotId.of(numX, numZ));
|
||||||
final String path =
|
final String path =
|
||||||
"worlds." + area.getWorldName() + ".areas." + area.getId() + '-' + builder.minimumId() + '-' + builder
|
"worlds." + area.getWorldName() + ".areas." + area.getId() + '-' + builder.minimumId() + '-' + builder
|
||||||
.maximumId();
|
.maximumId();
|
||||||
Runnable run = () -> {
|
Runnable run = () -> {
|
||||||
if (offsetX != 0) {
|
if (offsetX != 0) {
|
||||||
this.worldConfiguration.set(path + ".road.offset.x", offsetX);
|
this.worldConfiguration.set(path + ".road.offset.x", offsetX);
|
||||||
@ -343,12 +401,21 @@ public class Area extends SubCommand {
|
|||||||
player.teleport(this.worldUtil.getSpawn(world), TeleportCause.COMMAND);
|
player.teleport(this.worldUtil.getSpawn(world), TeleportCause.COMMAND);
|
||||||
if (area.getTerrain() != PlotAreaTerrainType.ALL) {
|
if (area.getTerrain() != PlotAreaTerrainType.ALL) {
|
||||||
QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(world));
|
QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(world));
|
||||||
queue.setChunkConsumer(chunk -> AugmentedUtils.generate(null, world, chunk.getX(), chunk.getZ(), null));
|
queue.setChunkConsumer(chunk -> AugmentedUtils.generate(
|
||||||
|
null,
|
||||||
|
world,
|
||||||
|
chunk.getX(),
|
||||||
|
chunk.getZ(),
|
||||||
|
null
|
||||||
|
));
|
||||||
queue.addReadChunks(region.getChunks());
|
queue.addReadChunks(region.getChunks());
|
||||||
queue.enqueue();
|
queue.enqueue();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(TranslatableCaption.of("errors.error_create"), Template.of("world", area.getWorldName()));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("errors.error_create"),
|
||||||
|
Template.of("world", area.getWorldName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (hasConfirmation(player)) {
|
if (hasConfirmation(player)) {
|
||||||
@ -369,10 +436,19 @@ public class Area extends SubCommand {
|
|||||||
PlotAreaBuilder builder = PlotAreaBuilder.newBuilder();
|
PlotAreaBuilder builder = PlotAreaBuilder.newBuilder();
|
||||||
builder.worldName(split[0]);
|
builder.worldName(split[0]);
|
||||||
final HybridPlotWorld pa =
|
final HybridPlotWorld pa =
|
||||||
this.hybridPlotWorldFactory.create(builder.worldName(), id, PlotSquared.platform().defaultGenerator(), null, null);
|
this.hybridPlotWorldFactory.create(
|
||||||
|
builder.worldName(),
|
||||||
|
id,
|
||||||
|
PlotSquared.platform().defaultGenerator(),
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
);
|
||||||
PlotArea other = this.plotAreaManager.getPlotArea(pa.getWorldName(), id);
|
PlotArea other = this.plotAreaManager.getPlotArea(pa.getWorldName(), id);
|
||||||
if (other != null && Objects.equals(pa.getId(), other.getId())) {
|
if (other != null && Objects.equals(pa.getId(), other.getId())) {
|
||||||
player.sendMessage(TranslatableCaption.of("setup.setup_world_taken"), Template.of("value", pa.toString()));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("setup.setup_world_taken"),
|
||||||
|
Template.of("value", pa.toString())
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Set<PlotArea> areas = this.plotAreaManager.getPlotAreasSet(pa.getWorldName());
|
Set<PlotArea> areas = this.plotAreaManager.getPlotAreasSet(pa.getWorldName());
|
||||||
@ -384,9 +460,11 @@ public class Area extends SubCommand {
|
|||||||
for (int i = 2; i < args.length; i++) {
|
for (int i = 2; i < args.length; i++) {
|
||||||
String[] pair = args[i].split("=");
|
String[] pair = args[i].split("=");
|
||||||
if (pair.length != 2) {
|
if (pair.length != 2) {
|
||||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"),
|
player.sendMessage(
|
||||||
Template.of("value1,", getCommandString()),
|
TranslatableCaption.of("commandconfig.command_syntax_extended"),
|
||||||
Template.of("value2", " create [world[:id]] [<modifier>=<value>]..."));
|
Template.of("value1,", getCommandString()),
|
||||||
|
Template.of("value2", " create [world[:id]] [<modifier>=<value>]...")
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch (pair[0].toLowerCase()) {
|
switch (pair[0].toLowerCase()) {
|
||||||
@ -425,24 +503,29 @@ public class Area extends SubCommand {
|
|||||||
break;
|
break;
|
||||||
case "terrain":
|
case "terrain":
|
||||||
pa.setTerrain(PlotAreaTerrainType.fromString(pair[1])
|
pa.setTerrain(PlotAreaTerrainType.fromString(pair[1])
|
||||||
.orElseThrow(() -> new IllegalArgumentException(pair[1] + " is not a valid terrain.")));
|
.orElseThrow(() -> new IllegalArgumentException(pair[1] + " is not a valid terrain.")));
|
||||||
builder.terrainType(pa.getTerrain());
|
builder.terrainType(pa.getTerrain());
|
||||||
break;
|
break;
|
||||||
case "type":
|
case "type":
|
||||||
pa.setType(PlotAreaType.fromString(pair[1])
|
pa.setType(PlotAreaType.fromString(pair[1])
|
||||||
.orElseThrow(() -> new IllegalArgumentException(pair[1] + " is not a valid type.")));
|
.orElseThrow(() -> new IllegalArgumentException(pair[1] + " is not a valid type.")));
|
||||||
builder.plotAreaType(pa.getType());
|
builder.plotAreaType(pa.getType());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"),
|
player.sendMessage(
|
||||||
Template.of("value1", getCommandString()),
|
TranslatableCaption.of("commandconfig.command_syntax_extended"),
|
||||||
Template.of("value2", " create [world[:id]] [<modifier>=<value>]..."));
|
Template.of("value1", getCommandString()),
|
||||||
|
Template.of("value2", " create [world[:id]] [<modifier>=<value>]...")
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pa.getType() != PlotAreaType.PARTIAL) {
|
if (pa.getType() != PlotAreaType.PARTIAL) {
|
||||||
if (this.worldUtil.isWorld(pa.getWorldName())) {
|
if (this.worldUtil.isWorld(pa.getWorldName())) {
|
||||||
player.sendMessage(TranslatableCaption.of("setup.setup_world_taken"), Template.of("value", pa.getWorldName()));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("setup.setup_world_taken"),
|
||||||
|
Template.of("value", pa.getWorldName())
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Runnable run = () -> {
|
Runnable run = () -> {
|
||||||
@ -460,7 +543,10 @@ public class Area extends SubCommand {
|
|||||||
player.sendMessage(TranslatableCaption.of("setup.setup_finished"));
|
player.sendMessage(TranslatableCaption.of("setup.setup_finished"));
|
||||||
player.teleport(this.worldUtil.getSpawn(world), TeleportCause.COMMAND);
|
player.teleport(this.worldUtil.getSpawn(world), TeleportCause.COMMAND);
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(TranslatableCaption.of("errors.error_create"), Template.of("world", pa.getWorldName()));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("errors.error_create"),
|
||||||
|
Template.of("world", pa.getWorldName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.worldConfiguration.save(this.worldFile);
|
this.worldConfiguration.save(this.worldFile);
|
||||||
@ -476,9 +562,14 @@ public class Area extends SubCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (pa.getId() == null) {
|
if (pa.getId() == null) {
|
||||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", getUsage()));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||||
|
Template.of("value", getUsage())
|
||||||
|
);
|
||||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"),
|
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"),
|
||||||
Template.of("value1", getCommandString()), Template.of("value2", " create [world[:id]] [<modifier>=<value>]..."));
|
Template.of("value1", getCommandString()),
|
||||||
|
Template.of("value2", " create [world[:id]] [<modifier>=<value>]...")
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.worldUtil.isWorld(pa.getWorldName())) {
|
if (this.worldUtil.isWorld(pa.getWorldName())) {
|
||||||
@ -492,14 +583,20 @@ public class Area extends SubCommand {
|
|||||||
player.teleport(this.worldUtil.getSpawn(pa.getWorldName()), TeleportCause.COMMAND);
|
player.teleport(this.worldUtil.getSpawn(pa.getWorldName()), TeleportCause.COMMAND);
|
||||||
}
|
}
|
||||||
metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).put("area_create_area", pa);
|
metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).put("area_create_area", pa);
|
||||||
player.sendMessage(TranslatableCaption.of("single.get_position"), Template.of("command", getCommandString()));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("single.get_position"),
|
||||||
|
Template.of("command", getCommandString())
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case "i":
|
case "i":
|
||||||
case "info": {
|
case "info": {
|
||||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_INFO)) {
|
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_INFO)) {
|
||||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", String.valueOf(Permission.PERMISSION_AREA_INFO)));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("permission.no_permission"),
|
||||||
|
Template.of("node", String.valueOf(Permission.PERMISSION_AREA_INFO))
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotArea area;
|
PlotArea area;
|
||||||
@ -511,8 +608,10 @@ public class Area extends SubCommand {
|
|||||||
area = this.plotAreaManager.getPlotAreaByString(args[1]);
|
area = this.plotAreaManager.getPlotAreaByString(args[1]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"), Template.of("value1", getCommandString()),
|
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"),
|
||||||
Template.of("value2", " info [area]"));
|
Template.of("value1", getCommandString()),
|
||||||
|
Template.of("value2", " info [area]")
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (area == null) {
|
if (area == null) {
|
||||||
@ -541,7 +640,10 @@ public class Area extends SubCommand {
|
|||||||
percent = claimed == 0 ? 0 : 100d * claimed / Integer.MAX_VALUE;
|
percent = claimed == 0 ? 0 : 100d * claimed / Integer.MAX_VALUE;
|
||||||
region = "N/A";
|
region = "N/A";
|
||||||
}
|
}
|
||||||
Template headerTemplate = Template.of("header", TranslatableCaption.of("info.plot_info_header").getComponent(player));
|
Template headerTemplate = Template.of(
|
||||||
|
"header",
|
||||||
|
TranslatableCaption.of("info.plot_info_header").getComponent(player)
|
||||||
|
);
|
||||||
Template nameTemplate = Template.of("name", name);
|
Template nameTemplate = Template.of("name", name);
|
||||||
Template typeTemplate = Template.of("type", area.getType().name());
|
Template typeTemplate = Template.of("type", area.getType().name());
|
||||||
Template terrainTemplate = Template.of("terrain", area.getTerrain().name());
|
Template terrainTemplate = Template.of("terrain", area.getTerrain().name());
|
||||||
@ -550,15 +652,31 @@ public class Area extends SubCommand {
|
|||||||
Template clustersTemplate = Template.of("clusters", String.valueOf(clusters));
|
Template clustersTemplate = Template.of("clusters", String.valueOf(clusters));
|
||||||
Template regionTemplate = Template.of("region", region);
|
Template regionTemplate = Template.of("region", region);
|
||||||
Template generatorTemplate = Template.of("generator", generator);
|
Template generatorTemplate = Template.of("generator", generator);
|
||||||
Template footerTemplate = Template.of("footer", TranslatableCaption.of("info.plot_info_footer").getComponent(player));
|
Template footerTemplate = Template.of(
|
||||||
player.sendMessage(TranslatableCaption.of("info.area_info_format"), headerTemplate, nameTemplate, typeTemplate, terrainTemplate,
|
"footer",
|
||||||
usageTemplate, claimedTemplate, clustersTemplate, regionTemplate, generatorTemplate, footerTemplate);
|
TranslatableCaption.of("info.plot_info_footer").getComponent(player)
|
||||||
|
);
|
||||||
|
player.sendMessage(TranslatableCaption.of("info.area_info_format"),
|
||||||
|
headerTemplate,
|
||||||
|
nameTemplate,
|
||||||
|
typeTemplate,
|
||||||
|
terrainTemplate,
|
||||||
|
usageTemplate,
|
||||||
|
claimedTemplate,
|
||||||
|
clustersTemplate,
|
||||||
|
regionTemplate,
|
||||||
|
generatorTemplate,
|
||||||
|
footerTemplate
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "l":
|
case "l":
|
||||||
case "list":
|
case "list":
|
||||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_LIST)) {
|
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_LIST)) {
|
||||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", String.valueOf(Permission.PERMISSION_AREA_LIST)));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("permission.no_permission"),
|
||||||
|
Template.of("node", String.valueOf(Permission.PERMISSION_AREA_LIST))
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int page;
|
int page;
|
||||||
@ -572,13 +690,16 @@ public class Area extends SubCommand {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"), Template.of("value1", getCommandString()),
|
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"),
|
||||||
Template.of("value2", " list [#]"));
|
Template.of("value1", getCommandString()),
|
||||||
|
Template.of("value2", " list [#]")
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final List<PlotArea> areas = new ArrayList<>(Arrays.asList(this.plotAreaManager.getAllPlotAreas()));
|
final List<PlotArea> areas = new ArrayList<>(Arrays.asList(this.plotAreaManager.getAllPlotAreas()));
|
||||||
paginate(player, areas, 8, page, new RunnableVal3<Integer, PlotArea, CaptionHolder>() {
|
paginate(player, areas, 8, page, new RunnableVal3<Integer, PlotArea, CaptionHolder>() {
|
||||||
@Override public void run(Integer i, PlotArea area, CaptionHolder caption) {
|
@Override
|
||||||
|
public void run(Integer i, PlotArea area, CaptionHolder caption) {
|
||||||
String name;
|
String name;
|
||||||
double percent;
|
double percent;
|
||||||
int claimed = area.getPlotCount();
|
int claimed = area.getPlotCount();
|
||||||
@ -603,8 +724,13 @@ public class Area extends SubCommand {
|
|||||||
Template regionTemplate = Template.of("region", region);
|
Template regionTemplate = Template.of("region", region);
|
||||||
Template generatorTemplate = Template.of("generator", generator);
|
Template generatorTemplate = Template.of("generator", generator);
|
||||||
String tooltip = MINI_MESSAGE.serialize(MINI_MESSAGE
|
String tooltip = MINI_MESSAGE.serialize(MINI_MESSAGE
|
||||||
.parse(TranslatableCaption.of("info.area_list_tooltip").getComponent(player), claimedTemplate, usageTemplate,
|
.parse(TranslatableCaption.of("info.area_list_tooltip").getComponent(player),
|
||||||
clustersTemplate, regionTemplate, generatorTemplate));
|
claimedTemplate,
|
||||||
|
usageTemplate,
|
||||||
|
clustersTemplate,
|
||||||
|
regionTemplate,
|
||||||
|
generatorTemplate
|
||||||
|
));
|
||||||
Template tooltipTemplate = Template.of("hover_info", tooltip);
|
Template tooltipTemplate = Template.of("hover_info", tooltip);
|
||||||
Template visitcmdTemplate = Template.of("command_tp", "/plot area tp " + area.toString());
|
Template visitcmdTemplate = Template.of("command_tp", "/plot area tp " + area.toString());
|
||||||
Template infocmdTemplate = Template.of("command_info", "/plot area info " + area.toString());
|
Template infocmdTemplate = Template.of("command_info", "/plot area info " + area.toString());
|
||||||
@ -613,8 +739,14 @@ public class Area extends SubCommand {
|
|||||||
Template typeTemplate = Template.of("area_type", area.getType().name());
|
Template typeTemplate = Template.of("area_type", area.getType().name());
|
||||||
Template terrainTemplate = Template.of("area_terrain", area.getTerrain().name());
|
Template terrainTemplate = Template.of("area_terrain", area.getTerrain().name());
|
||||||
caption.set(TranslatableCaption.of("info.area_list_item"));
|
caption.set(TranslatableCaption.of("info.area_list_item"));
|
||||||
caption.setTemplates(tooltipTemplate, visitcmdTemplate, numberTemplate, nameTemplate, typeTemplate, terrainTemplate,
|
caption.setTemplates(tooltipTemplate,
|
||||||
infocmdTemplate);
|
visitcmdTemplate,
|
||||||
|
numberTemplate,
|
||||||
|
nameTemplate,
|
||||||
|
typeTemplate,
|
||||||
|
terrainTemplate,
|
||||||
|
infocmdTemplate
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}, "/plot area list", TranslatableCaption.of("list.area_list_header_paged"));
|
}, "/plot area list", TranslatableCaption.of("list.area_list_header_paged"));
|
||||||
return true;
|
return true;
|
||||||
@ -623,7 +755,10 @@ public class Area extends SubCommand {
|
|||||||
case "reset":
|
case "reset":
|
||||||
case "regenerate": {
|
case "regenerate": {
|
||||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_REGEN)) {
|
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_REGEN)) {
|
||||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", String.valueOf(Permission.PERMISSION_AREA_REGEN)));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("permission.no_permission"),
|
||||||
|
Template.of("node", String.valueOf(Permission.PERMISSION_AREA_REGEN))
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final PlotArea area = player.getApplicablePlotArea();
|
final PlotArea area = player.getApplicablePlotArea();
|
||||||
@ -632,11 +767,20 @@ public class Area extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (area.getType() != PlotAreaType.PARTIAL) {
|
if (area.getType() != PlotAreaType.PARTIAL) {
|
||||||
player.sendMessage(TranslatableCaption.of("single.delete_world_region"), Template.of("world", area.getWorldName()));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("single.delete_world_region"),
|
||||||
|
Template.of("world", area.getWorldName())
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(area.getWorldName()));
|
QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(area.getWorldName()));
|
||||||
queue.setChunkConsumer(chunk -> AugmentedUtils.generate(null, area.getWorldName(), chunk.getX(), chunk.getZ(), null));
|
queue.setChunkConsumer(chunk -> AugmentedUtils.generate(
|
||||||
|
null,
|
||||||
|
area.getWorldName(),
|
||||||
|
chunk.getX(),
|
||||||
|
chunk.getZ(),
|
||||||
|
null
|
||||||
|
));
|
||||||
queue.addReadChunks(area.getRegion().getChunks());
|
queue.addReadChunks(area.getRegion().getChunks());
|
||||||
queue.setCompleteTask(() -> player.sendMessage(TranslatableCaption.of("single.regeneration_complete")));
|
queue.setCompleteTask(() -> player.sendMessage(TranslatableCaption.of("single.regeneration_complete")));
|
||||||
queue.enqueue();
|
queue.enqueue();
|
||||||
@ -648,11 +792,17 @@ public class Area extends SubCommand {
|
|||||||
case "visit":
|
case "visit":
|
||||||
case "tp":
|
case "tp":
|
||||||
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_TP)) {
|
if (!Permissions.hasPermission(player, Permission.PERMISSION_AREA_TP)) {
|
||||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", String.valueOf(Permission.PERMISSION_AREA_TP)));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("permission.no_permission"),
|
||||||
|
Template.of("node", String.valueOf(Permission.PERMISSION_AREA_TP))
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", "/plot area tp [area]"));
|
player.sendMessage(
|
||||||
|
TranslatableCaption.of("commandconfig.command_syntax"),
|
||||||
|
Template.of("value", "/plot area tp [area]")
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotArea area = this.plotAreaManager.getPlotAreaByString(args[1]);
|
PlotArea area = this.plotAreaManager.getPlotAreaByString(args[1]);
|
||||||
@ -671,10 +821,16 @@ public class Area extends SubCommand {
|
|||||||
} else {
|
} else {
|
||||||
CuboidRegion region = area.getRegion();
|
CuboidRegion region = area.getRegion();
|
||||||
center = Location.at(area.getWorldName(),
|
center = Location.at(area.getWorldName(),
|
||||||
region.getMinimumPoint().getX() + (region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) / 2, 0,
|
region.getMinimumPoint().getX() + (region.getMaximumPoint().getX() - region
|
||||||
region.getMinimumPoint().getZ() + (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) / 2);
|
.getMinimumPoint()
|
||||||
|
.getX()) / 2, 0,
|
||||||
|
region.getMinimumPoint().getZ() + (region.getMaximumPoint().getZ() - region
|
||||||
|
.getMinimumPoint()
|
||||||
|
.getZ()) / 2
|
||||||
|
);
|
||||||
this.worldUtil.getHighestBlock(area.getWorldName(), center.getX(), center.getZ(),
|
this.worldUtil.getHighestBlock(area.getWorldName(), center.getX(), center.getZ(),
|
||||||
y -> player.teleport(center.withY(1 + y), TeleportCause.COMMAND));
|
y -> player.teleport(center.withY(1 + y), TeleportCause.COMMAND)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case "delete":
|
case "delete":
|
||||||
@ -685,6 +841,7 @@ public class Area extends SubCommand {
|
|||||||
sendUsage(player);
|
sendUsage(player);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
@ -704,8 +861,17 @@ public class Area extends SubCommand {
|
|||||||
if (Permissions.hasPermission(player, Permission.PERMISSION_AREA_TP)) {
|
if (Permissions.hasPermission(player, Permission.PERMISSION_AREA_TP)) {
|
||||||
completions.add("tp");
|
completions.add("tp");
|
||||||
}
|
}
|
||||||
final List<Command> commands = completions.stream().filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
|
final List<Command> commands = completions.stream().filter(completion -> completion
|
||||||
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.ADMINISTRATION) {
|
.toLowerCase()
|
||||||
|
.startsWith(args[0].toLowerCase()))
|
||||||
|
.map(completion -> new Command(
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
completion,
|
||||||
|
"",
|
||||||
|
RequiredType.NONE,
|
||||||
|
CommandCategory.ADMINISTRATION
|
||||||
|
) {
|
||||||
}).collect(Collectors.toCollection(LinkedList::new));
|
}).collect(Collectors.toCollection(LinkedList::new));
|
||||||
if (Permissions.hasPermission(player, Permission.PERMISSION_AREA) && args[0].length() > 0) {
|
if (Permissions.hasPermission(player, Permission.PERMISSION_AREA) && args[0].length() > 0) {
|
||||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||||
@ -714,4 +880,5 @@ public class Area extends SubCommand {
|
|||||||
}
|
}
|
||||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,8 @@ import com.plotsquared.core.plot.PlotId;
|
|||||||
public abstract class Argument<T> {
|
public abstract class Argument<T> {
|
||||||
|
|
||||||
public static final Argument<Integer> Integer = new Argument<Integer>("int", 16) {
|
public static final Argument<Integer> Integer = new Argument<Integer>("int", 16) {
|
||||||
@Override public Integer parse(String in) {
|
@Override
|
||||||
|
public Integer parse(String in) {
|
||||||
Integer value = null;
|
Integer value = null;
|
||||||
try {
|
try {
|
||||||
value = java.lang.Integer.parseInt(in);
|
value = java.lang.Integer.parseInt(in);
|
||||||
@ -40,35 +41,39 @@ public abstract class Argument<T> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
public static final Argument<Boolean> Boolean = new Argument<Boolean>("boolean", true) {
|
public static final Argument<Boolean> Boolean = new Argument<Boolean>("boolean", true) {
|
||||||
@Override public Boolean parse(String in) {
|
@Override
|
||||||
|
public Boolean parse(String in) {
|
||||||
Boolean value = null;
|
Boolean value = null;
|
||||||
if (in.equalsIgnoreCase("true") || in.equalsIgnoreCase("Yes") || in
|
if (in.equalsIgnoreCase("true") || in.equalsIgnoreCase("Yes") || in
|
||||||
.equalsIgnoreCase("1")) {
|
.equalsIgnoreCase("1")) {
|
||||||
value = true;
|
value = true;
|
||||||
} else if (in.equalsIgnoreCase("false") || in.equalsIgnoreCase("No") || in
|
} else if (in.equalsIgnoreCase("false") || in.equalsIgnoreCase("No") || in
|
||||||
.equalsIgnoreCase("0")) {
|
.equalsIgnoreCase("0")) {
|
||||||
value = false;
|
value = false;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
public static final Argument<String> String = new Argument<String>("String", "Example") {
|
public static final Argument<String> String = new Argument<String>("String", "Example") {
|
||||||
@Override public String parse(String in) {
|
@Override
|
||||||
|
public String parse(String in) {
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
public static final Argument<String> PlayerName =
|
public static final Argument<String> PlayerName =
|
||||||
new Argument<String>("PlayerName", "<player | *>") {
|
new Argument<String>("PlayerName", "<player | *>") {
|
||||||
@Override public String parse(String in) {
|
@Override
|
||||||
return in.length() <= 16 ? in : null;
|
public String parse(String in) {
|
||||||
}
|
return in.length() <= 16 ? in : null;
|
||||||
};
|
}
|
||||||
|
};
|
||||||
public static final Argument<PlotId> PlotID =
|
public static final Argument<PlotId> PlotID =
|
||||||
new Argument<PlotId>("PlotID", PlotId.of(-6, 3)) {
|
new Argument<PlotId>("PlotID", PlotId.of(-6, 3)) {
|
||||||
@Override public PlotId parse(String in) {
|
@Override
|
||||||
return PlotId.fromString(in);
|
public PlotId parse(String in) {
|
||||||
}
|
return PlotId.fromString(in);
|
||||||
};
|
}
|
||||||
|
};
|
||||||
private final String name;
|
private final String name;
|
||||||
private final T example;
|
private final T example;
|
||||||
|
|
||||||
@ -79,7 +84,8 @@ public abstract class Argument<T> {
|
|||||||
|
|
||||||
public abstract T parse(String in);
|
public abstract T parse(String in);
|
||||||
|
|
||||||
@Override public final String toString() {
|
@Override
|
||||||
|
public final String toString() {
|
||||||
return this.getName();
|
return this.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,4 +96,5 @@ public abstract class Argument<T> {
|
|||||||
public final T getExample() {
|
public final T getExample() {
|
||||||
return this.example;
|
return this.example;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -52,20 +52,20 @@ import com.plotsquared.core.util.task.AutoClaimFinishTask;
|
|||||||
import com.plotsquared.core.util.task.RunnableVal;
|
import com.plotsquared.core.util.task.RunnableVal;
|
||||||
import com.plotsquared.core.util.task.TaskManager;
|
import com.plotsquared.core.util.task.TaskManager;
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@CommandDeclaration(command = "auto",
|
@CommandDeclaration(command = "auto",
|
||||||
permission = "plots.auto",
|
permission = "plots.auto",
|
||||||
category = CommandCategory.CLAIMING,
|
category = CommandCategory.CLAIMING,
|
||||||
requiredType = RequiredType.NONE,
|
requiredType = RequiredType.NONE,
|
||||||
aliases = "a",
|
aliases = "a",
|
||||||
usage = "/plot auto [length, width]")
|
usage = "/plot auto [length, width]")
|
||||||
public class Auto extends SubCommand {
|
public class Auto extends SubCommand {
|
||||||
|
|
||||||
private final PlotAreaManager plotAreaManager;
|
private final PlotAreaManager plotAreaManager;
|
||||||
@ -73,10 +73,13 @@ public class Auto extends SubCommand {
|
|||||||
private final EconHandler econHandler;
|
private final EconHandler econHandler;
|
||||||
private final ServicePipeline servicePipeline;
|
private final ServicePipeline servicePipeline;
|
||||||
|
|
||||||
@Inject public Auto(@Nonnull final PlotAreaManager plotAreaManager,
|
@Inject
|
||||||
@Nonnull final EventDispatcher eventDispatcher,
|
public Auto(
|
||||||
@Nonnull final EconHandler econHandler,
|
final @NonNull PlotAreaManager plotAreaManager,
|
||||||
@Nonnull final ServicePipeline servicePipeline) {
|
final @NonNull EventDispatcher eventDispatcher,
|
||||||
|
final @NonNull EconHandler econHandler,
|
||||||
|
final @NonNull ServicePipeline servicePipeline
|
||||||
|
) {
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
this.eventDispatcher = eventDispatcher;
|
this.eventDispatcher = eventDispatcher;
|
||||||
this.econHandler = econHandler;
|
this.econHandler = econHandler;
|
||||||
@ -84,14 +87,18 @@ public class Auto extends SubCommand {
|
|||||||
this.servicePipeline.registerServiceType(TypeToken.of(AutoService.class), new AutoService.DefaultAutoService());
|
this.servicePipeline.registerServiceType(TypeToken.of(AutoService.class), new AutoService.DefaultAutoService());
|
||||||
final AutoService.MultiPlotService multiPlotService = new AutoService.MultiPlotService();
|
final AutoService.MultiPlotService multiPlotService = new AutoService.MultiPlotService();
|
||||||
this.servicePipeline.registerServiceImplementation(AutoService.class, multiPlotService,
|
this.servicePipeline.registerServiceImplementation(AutoService.class, multiPlotService,
|
||||||
Collections.singletonList(multiPlotService));
|
Collections.singletonList(multiPlotService)
|
||||||
|
);
|
||||||
final AutoService.SinglePlotService singlePlotService = new AutoService.SinglePlotService();
|
final AutoService.SinglePlotService singlePlotService = new AutoService.SinglePlotService();
|
||||||
this.servicePipeline.registerServiceImplementation(AutoService.class, singlePlotService,
|
this.servicePipeline.registerServiceImplementation(AutoService.class, singlePlotService,
|
||||||
Collections.singletonList(singlePlotService));
|
Collections.singletonList(singlePlotService)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkAllowedPlots(PlotPlayer player, PlotArea plotarea,
|
public static boolean checkAllowedPlots(
|
||||||
@Nullable Integer allowedPlots, int sizeX, int sizeZ) {
|
PlotPlayer player, PlotArea plotarea,
|
||||||
|
@Nullable Integer allowedPlots, int sizeX, int sizeZ
|
||||||
|
) {
|
||||||
if (allowedPlots == null) {
|
if (allowedPlots == null) {
|
||||||
allowedPlots = player.getAllowedPlots();
|
allowedPlots = player.getAllowedPlots();
|
||||||
}
|
}
|
||||||
@ -104,16 +111,20 @@ public class Auto extends SubCommand {
|
|||||||
int diff = allowedPlots - currentPlots;
|
int diff = allowedPlots - currentPlots;
|
||||||
if (diff - sizeX * sizeZ < 0) {
|
if (diff - sizeX * sizeZ < 0) {
|
||||||
try (final MetaDataAccess<Integer> metaDataAccess = player.accessPersistentMetaData(
|
try (final MetaDataAccess<Integer> metaDataAccess = player.accessPersistentMetaData(
|
||||||
PlayerMetaDataKeys.PERSISTENT_GRANTED_PLOTS)) {
|
PlayerMetaDataKeys.PERSISTENT_GRANTED_PLOTS)) {
|
||||||
if (metaDataAccess.isPresent()) {
|
if (metaDataAccess.isPresent()) {
|
||||||
int grantedPlots = metaDataAccess.get().orElse(0);
|
int grantedPlots = metaDataAccess.get().orElse(0);
|
||||||
if (diff < 0 && grantedPlots < sizeX * sizeZ) {
|
if (diff < 0 && grantedPlots < sizeX * sizeZ) {
|
||||||
player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_plots"),
|
player.sendMessage(
|
||||||
Template.of("amount", String.valueOf(diff + grantedPlots)));
|
TranslatableCaption.of("permission.cant_claim_more_plots"),
|
||||||
|
Template.of("amount", String.valueOf(diff + grantedPlots))
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
} else if (diff >= 0 && grantedPlots + diff < sizeX * sizeZ) {
|
} else if (diff >= 0 && grantedPlots + diff < sizeX * sizeZ) {
|
||||||
player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_plots"),
|
player.sendMessage(
|
||||||
Template.of("amount", String.valueOf(diff + grantedPlots)));
|
TranslatableCaption.of("permission.cant_claim_more_plots"),
|
||||||
|
Template.of("amount", String.valueOf(diff + grantedPlots))
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
int left = grantedPlots + diff < 0 ? 0 : diff - sizeX * sizeZ;
|
int left = grantedPlots + diff < 0 ? 0 : diff - sizeX * sizeZ;
|
||||||
@ -122,13 +133,17 @@ public class Auto extends SubCommand {
|
|||||||
} else {
|
} else {
|
||||||
metaDataAccess.set(left);
|
metaDataAccess.set(left);
|
||||||
}
|
}
|
||||||
player.sendMessage(TranslatableCaption.of("economy.removed_granted_plot"),
|
player.sendMessage(
|
||||||
Template.of("usedGrants", String.valueOf(grantedPlots - left)),
|
TranslatableCaption.of("economy.removed_granted_plot"),
|
||||||
Template.of("remainingGrants", String.valueOf(left)));
|
Template.of("usedGrants", String.valueOf(grantedPlots - left)),
|
||||||
|
Template.of("remainingGrants", String.valueOf(left))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_plots"),
|
player.sendMessage(
|
||||||
Template.of("amount", "0"));
|
TranslatableCaption.of("permission.cant_claim_more_plots"),
|
||||||
|
Template.of("amount", "0")
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,10 +151,12 @@ public class Auto extends SubCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void claimSingle(@Nonnull final PlotPlayer<?> player, @Nonnull final Plot plot,
|
private void claimSingle(
|
||||||
@Nonnull final PlotArea plotArea, @Nullable final String schematic) {
|
final @NonNull PlotPlayer<?> player, final @NonNull Plot plot,
|
||||||
|
final @NonNull PlotArea plotArea, final @Nullable String schematic
|
||||||
|
) {
|
||||||
try (final MetaDataAccess<Boolean> metaDataAccess =
|
try (final MetaDataAccess<Boolean> metaDataAccess =
|
||||||
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_AUTO)) {
|
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_AUTO)) {
|
||||||
metaDataAccess.set(true);
|
metaDataAccess.set(true);
|
||||||
}
|
}
|
||||||
plot.setOwnerAbs(player.getUUID());
|
plot.setOwnerAbs(player.getUUID());
|
||||||
@ -149,11 +166,13 @@ public class Auto extends SubCommand {
|
|||||||
this.value = plot;
|
this.value = plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void run(final Plot plot) {
|
@Override
|
||||||
|
public void run(final Plot plot) {
|
||||||
try {
|
try {
|
||||||
TaskManager.getPlatformImplementation().sync(
|
TaskManager.getPlatformImplementation().sync(
|
||||||
new AutoClaimFinishTask(player, plot, plotArea, schematic,
|
new AutoClaimFinishTask(player, plot, plotArea, schematic,
|
||||||
PlotSquared.get().getEventDispatcher()));
|
PlotSquared.get().getEventDispatcher()
|
||||||
|
));
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -164,12 +183,13 @@ public class Auto extends SubCommand {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
@Override
|
||||||
|
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||||
PlotArea plotarea = player.getApplicablePlotArea();
|
PlotArea plotarea = player.getApplicablePlotArea();
|
||||||
if (plotarea == null) {
|
if (plotarea == null) {
|
||||||
final PermissionHandler permissionHandler = PlotSquared.platform().permissionHandler();
|
final PermissionHandler permissionHandler = PlotSquared.platform().permissionHandler();
|
||||||
if (permissionHandler.hasCapability(
|
if (permissionHandler.hasCapability(
|
||||||
PermissionHandler.PermissionHandlerCapability.PER_WORLD_PERMISSIONS)) {
|
PermissionHandler.PermissionHandlerCapability.PER_WORLD_PERMISSIONS)) {
|
||||||
for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
|
for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
|
||||||
if (player.hasPermission(area.getWorldName(), "plots.auto")) {
|
if (player.hasPermission(area.getWorldName(), "plots.auto")) {
|
||||||
if (plotarea != null) {
|
if (plotarea != null) {
|
||||||
@ -228,11 +248,12 @@ public class Auto extends SubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerAutoPlotEvent event = this.eventDispatcher
|
PlayerAutoPlotEvent event = this.eventDispatcher
|
||||||
.callAuto(player, plotarea, schematic, size_x, size_z);
|
.callAuto(player, plotarea, schematic, size_x, size_z);
|
||||||
if (event.getEventResult() == Result.DENY) {
|
if (event.getEventResult() == Result.DENY) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("events.event_denied"),
|
TranslatableCaption.of("events.event_denied"),
|
||||||
Template.of("value", "Auto claim"));
|
Template.of("value", "Auto claim")
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
boolean force = event.getEventResult() == Result.FORCE;
|
boolean force = event.getEventResult() == Result.FORCE;
|
||||||
@ -240,19 +261,24 @@ public class Auto extends SubCommand {
|
|||||||
size_z = event.getSize_z();
|
size_z = event.getSize_z();
|
||||||
schematic = event.getSchematic();
|
schematic = event.getSchematic();
|
||||||
if (!force && mega && !Permissions.hasPermission(player, Permission.PERMISSION_AUTO_MEGA)) {
|
if (!force && mega && !Permissions.hasPermission(player, Permission.PERMISSION_AUTO_MEGA)) {
|
||||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
player.sendMessage(
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_AUTO_MEGA)));
|
TranslatableCaption.of("permission.no_permission"),
|
||||||
|
Template.of("node", String.valueOf(Permission.PERMISSION_AUTO_MEGA))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (!force && size_x * size_z > Settings.Claim.MAX_AUTO_AREA) {
|
if (!force && size_x * size_z > Settings.Claim.MAX_AUTO_AREA) {
|
||||||
player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_plots_num"),
|
player.sendMessage(
|
||||||
Template.of("amount", String.valueOf(Settings.Claim.MAX_AUTO_AREA)));
|
TranslatableCaption.of("permission.cant_claim_more_plots_num"),
|
||||||
|
Template.of("amount", String.valueOf(Settings.Claim.MAX_AUTO_AREA))
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final int allowed_plots = player.getAllowedPlots();
|
final int allowed_plots = player.getAllowedPlots();
|
||||||
try (final MetaDataAccess<Boolean> metaDataAccess =
|
try (final MetaDataAccess<Boolean> metaDataAccess =
|
||||||
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_AUTO)) {
|
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_AUTO)) {
|
||||||
if (!force && (metaDataAccess.get().orElse(false) || !checkAllowedPlots(player,
|
if (!force && (metaDataAccess.get().orElse(false) || !checkAllowedPlots(player,
|
||||||
plotarea, allowed_plots, size_x, size_z))) {
|
plotarea, allowed_plots, size_x, size_z
|
||||||
|
))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -266,8 +292,11 @@ public class Auto extends SubCommand {
|
|||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!force && !Permissions.hasPermission(player, Permission.PERMISSION_CLAIM_SCHEMATIC.format(schematic)) && !Permissions
|
if (!force && !Permissions.hasPermission(
|
||||||
.hasPermission(player, "plots.admin.command.schematic")) {
|
player,
|
||||||
|
Permission.PERMISSION_CLAIM_SCHEMATIC.format(schematic)
|
||||||
|
) && !Permissions
|
||||||
|
.hasPermission(player, "plots.admin.command.schematic")) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission"),
|
TranslatableCaption.of("permission.no_permission"),
|
||||||
Template.of("node", "plots.claim.%s0")
|
Template.of("node", "plots.claim.%s0")
|
||||||
@ -278,8 +307,8 @@ public class Auto extends SubCommand {
|
|||||||
if (this.econHandler != null && plotarea.useEconomy()) {
|
if (this.econHandler != null && plotarea.useEconomy()) {
|
||||||
PlotExpression costExp = plotarea.getPrices().get("claim");
|
PlotExpression costExp = plotarea.getPrices().get("claim");
|
||||||
double cost = costExp.evaluate(Settings.Limit.GLOBAL ?
|
double cost = costExp.evaluate(Settings.Limit.GLOBAL ?
|
||||||
player.getPlotCount() :
|
player.getPlotCount() :
|
||||||
player.getPlotCount(plotarea.getWorldName()));
|
player.getPlotCount(plotarea.getWorldName()));
|
||||||
cost = (size_x * size_z) * cost;
|
cost = (size_x * size_z) * cost;
|
||||||
if (cost > 0d) {
|
if (cost > 0d) {
|
||||||
if (!force && this.econHandler.getMoney(player) < cost) {
|
if (!force && this.econHandler.getMoney(player) < cost) {
|
||||||
@ -299,9 +328,9 @@ public class Auto extends SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final List<Plot> plots = this.servicePipeline
|
final List<Plot> plots = this.servicePipeline
|
||||||
.pump(new AutoService.AutoQuery(player, null, size_x, size_z, plotarea))
|
.pump(new AutoService.AutoQuery(player, null, size_x, size_z, plotarea))
|
||||||
.through(AutoService.class)
|
.through(AutoService.class)
|
||||||
.getResult();
|
.getResult();
|
||||||
|
|
||||||
if (plots.isEmpty()) {
|
if (plots.isEmpty()) {
|
||||||
player.sendMessage(TranslatableCaption.of("errors.no_free_plots"));
|
player.sendMessage(TranslatableCaption.of("errors.no_free_plots"));
|
||||||
@ -313,12 +342,14 @@ public class Auto extends SubCommand {
|
|||||||
while (plotIterator.hasNext()) {
|
while (plotIterator.hasNext()) {
|
||||||
plotIterator.next().claim(player, !plotIterator.hasNext(), null);
|
plotIterator.next().claim(player, !plotIterator.hasNext(), null);
|
||||||
}
|
}
|
||||||
final PlotAutoMergeEvent mergeEvent = this.eventDispatcher.callAutoMerge(plots.get(0),
|
final PlotAutoMergeEvent mergeEvent = this.eventDispatcher.callAutoMerge(
|
||||||
plots.stream().map(Plot::getId).collect(Collectors.toList()));
|
plots.get(0),
|
||||||
|
plots.stream().map(Plot::getId).collect(Collectors.toList())
|
||||||
|
);
|
||||||
if (!force && mergeEvent.getEventResult() == Result.DENY) {
|
if (!force && mergeEvent.getEventResult() == Result.DENY) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("events.event_denied"),
|
TranslatableCaption.of("events.event_denied"),
|
||||||
Template.of("value", "Auto merge")
|
Template.of("value", "Auto merge")
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -326,4 +357,5 @@ public class Auto extends SubCommand {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,8 @@ import com.plotsquared.core.util.Permissions;
|
|||||||
import com.plotsquared.core.util.task.RunnableVal2;
|
import com.plotsquared.core.util.task.RunnableVal2;
|
||||||
import com.plotsquared.core.util.task.RunnableVal3;
|
import com.plotsquared.core.util.task.RunnableVal3;
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
@ -57,15 +57,16 @@ import java.util.stream.IntStream;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@CommandDeclaration(command = "backup",
|
@CommandDeclaration(command = "backup",
|
||||||
usage = "/plot backup <save | list | load>",
|
usage = "/plot backup <save | list | load>",
|
||||||
category = CommandCategory.SETTINGS,
|
category = CommandCategory.SETTINGS,
|
||||||
requiredType = RequiredType.PLAYER,
|
requiredType = RequiredType.PLAYER,
|
||||||
permission = "plots.backup")
|
permission = "plots.backup")
|
||||||
public final class Backup extends Command {
|
public final class Backup extends Command {
|
||||||
|
|
||||||
private final BackupManager backupManager;
|
private final BackupManager backupManager;
|
||||||
|
|
||||||
@Inject public Backup(@Nonnull final BackupManager backupManager) {
|
@Inject
|
||||||
|
public Backup(final @NonNull BackupManager backupManager) {
|
||||||
super(MainCommand.getInstance(), true);
|
super(MainCommand.getInstance(), true);
|
||||||
this.backupManager = backupManager;
|
this.backupManager = backupManager;
|
||||||
}
|
}
|
||||||
@ -79,22 +80,25 @@ public final class Backup extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
|
public CompletableFuture<Boolean> execute(
|
||||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
PlotPlayer<?> player, String[] args,
|
||||||
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
|
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||||
|
RunnableVal2<Command, CommandResult> whenDone
|
||||||
|
) throws CommandException {
|
||||||
if (args.length == 0 || !Arrays.asList("save", "list", "load")
|
if (args.length == 0 || !Arrays.asList("save", "list", "load")
|
||||||
.contains(args[0].toLowerCase(Locale.ENGLISH))) {
|
.contains(args[0].toLowerCase(Locale.ENGLISH))) {
|
||||||
return CompletableFuture.completedFuture(sendMessage(player));
|
return CompletableFuture.completedFuture(sendMessage(player));
|
||||||
}
|
}
|
||||||
return super.execute(player, args, confirm, whenDone);
|
return super.execute(player, args, confirm, whenDone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Collection<Command> tab(PlotPlayer<?> player, String[] args, boolean space) {
|
@Override
|
||||||
|
public Collection<Command> tab(PlotPlayer<?> player, String[] args, boolean space) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
return Stream.of("save", "list", "load")
|
return Stream.of("save", "list", "load")
|
||||||
.filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH)))
|
.filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH)))
|
||||||
.map(value -> new Command(null, false, value, "", RequiredType.NONE, null) {
|
.map(value -> new Command(null, false, value, "", RequiredType.NONE, null) {
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
} else if (args[0].equalsIgnoreCase("load")) {
|
} else if (args[0].equalsIgnoreCase("load")) {
|
||||||
|
|
||||||
final Plot plot = player.getCurrentPlot();
|
final Plot plot = player.getCurrentPlot();
|
||||||
@ -102,17 +106,18 @@ public final class Backup extends Command {
|
|||||||
final BackupProfile backupProfile = Objects.requireNonNull(this.backupManager.getProfile(plot));
|
final BackupProfile backupProfile = Objects.requireNonNull(this.backupManager.getProfile(plot));
|
||||||
if (backupProfile instanceof PlayerBackupProfile) {
|
if (backupProfile instanceof PlayerBackupProfile) {
|
||||||
final CompletableFuture<List<com.plotsquared.core.backup.Backup>> backupList =
|
final CompletableFuture<List<com.plotsquared.core.backup.Backup>> backupList =
|
||||||
backupProfile.listBackups();
|
backupProfile.listBackups();
|
||||||
if (backupList.isDone()) {
|
if (backupList.isDone()) {
|
||||||
final List<com.plotsquared.core.backup.Backup> backups =
|
final List<com.plotsquared.core.backup.Backup> backups =
|
||||||
backupList.getNow(new ArrayList<>());
|
backupList.getNow(new ArrayList<>());
|
||||||
if (backups.isEmpty()) {
|
if (backups.isEmpty()) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
return IntStream.range(1, 1 + backups.size()).mapToObj(
|
return IntStream.range(1, 1 + backups.size()).mapToObj(
|
||||||
i -> new Command(null, false, Integer.toString(i), "",
|
i -> new Command(null, false, Integer.toString(i), "",
|
||||||
RequiredType.NONE, null) {
|
RequiredType.NONE, null
|
||||||
}).collect(Collectors.toList());
|
) {
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,13 +127,15 @@ public final class Backup extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@CommandDeclaration(command = "save",
|
@CommandDeclaration(command = "save",
|
||||||
usage = "/plot backup save",
|
usage = "/plot backup save",
|
||||||
category = CommandCategory.SETTINGS,
|
category = CommandCategory.SETTINGS,
|
||||||
requiredType = RequiredType.PLAYER,
|
requiredType = RequiredType.PLAYER,
|
||||||
permission = "plots.backup.save")
|
permission = "plots.backup.save")
|
||||||
public void save(final Command command, final PlotPlayer<?> player, final String[] args,
|
public void save(
|
||||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
final Command command, final PlotPlayer<?> player, final String[] args,
|
||||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||||
|
final RunnableVal2<Command, CommandResult> whenDone
|
||||||
|
) {
|
||||||
final Plot plot = player.getCurrentPlot();
|
final Plot plot = player.getCurrentPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
||||||
@ -145,7 +152,7 @@ public final class Backup extends Command {
|
|||||||
Template.of("plot", "generic.generic_merged")
|
Template.of("plot", "generic.generic_merged")
|
||||||
);
|
);
|
||||||
} else if (!plot.isOwner(player.getUUID()) && !Permissions
|
} else if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||||
.hasPermission(player, Permission.PERMISSION_ADMIN_BACKUP_OTHER)) {
|
.hasPermission(player, Permission.PERMISSION_ADMIN_BACKUP_OTHER)) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission"),
|
TranslatableCaption.of("permission.no_permission"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BACKUP_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BACKUP_OTHER))
|
||||||
@ -174,13 +181,15 @@ public final class Backup extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@CommandDeclaration(command = "list",
|
@CommandDeclaration(command = "list",
|
||||||
usage = "/plot backup list",
|
usage = "/plot backup list",
|
||||||
category = CommandCategory.SETTINGS,
|
category = CommandCategory.SETTINGS,
|
||||||
requiredType = RequiredType.PLAYER,
|
requiredType = RequiredType.PLAYER,
|
||||||
permission = "plots.backup.list")
|
permission = "plots.backup.list")
|
||||||
public void list(final Command command, final PlotPlayer<?> player, final String[] args,
|
public void list(
|
||||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
final Command command, final PlotPlayer<?> player, final String[] args,
|
||||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||||
|
final RunnableVal2<Command, CommandResult> whenDone
|
||||||
|
) {
|
||||||
final Plot plot = player.getCurrentPlot();
|
final Plot plot = player.getCurrentPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
||||||
@ -195,7 +204,7 @@ public final class Backup extends Command {
|
|||||||
Template.of("plot", "generic.generic_merged")
|
Template.of("plot", "generic.generic_merged")
|
||||||
);
|
);
|
||||||
} else if (!plot.isOwner(player.getUUID()) && !Permissions
|
} else if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||||
.hasPermission(player, Permission.PERMISSION_ADMIN_BACKUP_OTHER)) {
|
.hasPermission(player, Permission.PERMISSION_ADMIN_BACKUP_OTHER)) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission"),
|
TranslatableCaption.of("permission.no_permission"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BACKUP_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BACKUP_OTHER))
|
||||||
@ -227,7 +236,8 @@ public final class Backup extends Command {
|
|||||||
Template.of("number", Integer.toString(i + 1)),
|
Template.of("number", Integer.toString(i + 1)),
|
||||||
Template.of("value", DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.ofInstant(
|
Template.of("value", DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.ofInstant(
|
||||||
Instant.ofEpochMilli(backups.get(i).getCreationTime()),
|
Instant.ofEpochMilli(backups.get(i).getCreationTime()),
|
||||||
ZoneId.systemDefault())))
|
ZoneId.systemDefault()
|
||||||
|
)))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
@ -240,13 +250,15 @@ public final class Backup extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@CommandDeclaration(command = "load",
|
@CommandDeclaration(command = "load",
|
||||||
usage = "/plot backup load <#>",
|
usage = "/plot backup load <#>",
|
||||||
category = CommandCategory.SETTINGS,
|
category = CommandCategory.SETTINGS,
|
||||||
requiredType = RequiredType.PLAYER,
|
requiredType = RequiredType.PLAYER,
|
||||||
permission = "plots.backup.load")
|
permission = "plots.backup.load")
|
||||||
public void load(final Command command, final PlotPlayer<?> player, final String[] args,
|
public void load(
|
||||||
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
final Command command, final PlotPlayer<?> player, final String[] args,
|
||||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
final RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||||
|
final RunnableVal2<Command, CommandResult> whenDone
|
||||||
|
) {
|
||||||
final Plot plot = player.getCurrentPlot();
|
final Plot plot = player.getCurrentPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
||||||
@ -265,7 +277,7 @@ public final class Backup extends Command {
|
|||||||
Template.of("plot", "generic.generic_merged")
|
Template.of("plot", "generic.generic_merged")
|
||||||
);
|
);
|
||||||
} else if (!plot.isOwner(player.getUUID()) && !Permissions
|
} else if (!plot.isOwner(player.getUUID()) && !Permissions
|
||||||
.hasPermission(player, Permission.PERMISSION_ADMIN_BACKUP_OTHER)) {
|
.hasPermission(player, Permission.PERMISSION_ADMIN_BACKUP_OTHER)) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission"),
|
TranslatableCaption.of("permission.no_permission"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BACKUP_OTHER))
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BACKUP_OTHER))
|
||||||
@ -308,26 +320,27 @@ public final class Backup extends Command {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
final com.plotsquared.core.backup.Backup backup =
|
final com.plotsquared.core.backup.Backup backup =
|
||||||
backups.get(number - 1);
|
backups.get(number - 1);
|
||||||
if (backup == null || backup.getFile() == null || !Files
|
if (backup == null || backup.getFile() == null || !Files
|
||||||
.exists(backup.getFile())) {
|
.exists(backup.getFile())) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("backup_impossible"),
|
TranslatableCaption.of("backup_impossible"),
|
||||||
Template.of("plot", "generic.generic_invalid_choice")
|
Template.of("plot", "generic.generic_invalid_choice")
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
CmdConfirm.addPending(player, "/plot backup load " + number,
|
CmdConfirm.addPending(player, "/plot backup load " + number,
|
||||||
() -> backupProfile.restoreBackup(backup, player)
|
() -> backupProfile.restoreBackup(backup, player)
|
||||||
.whenComplete((n, error) -> {
|
.whenComplete((n, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("backups.backup_load_failure"),
|
TranslatableCaption.of("backups.backup_load_failure"),
|
||||||
Template.of("reason", error.getMessage())
|
Template.of("reason", error.getMessage())
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(TranslatableCaption.of("backups.backup_load_success"));
|
player.sendMessage(TranslatableCaption.of("backups.backup_load_success"));
|
||||||
}
|
}
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,26 +39,32 @@ import java.util.Locale;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@CommandDeclaration(command = "setbiome",
|
@CommandDeclaration(command = "setbiome",
|
||||||
permission = "plots.set.biome",
|
permission = "plots.set.biome",
|
||||||
usage = "/plot biome [biome]",
|
usage = "/plot biome [biome]",
|
||||||
aliases = {"biome", "sb", "setb", "b"},
|
aliases = {"biome", "sb", "setb", "b"},
|
||||||
category = CommandCategory.APPEARANCE,
|
category = CommandCategory.APPEARANCE,
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Biome extends SetCommand {
|
public class Biome extends SetCommand {
|
||||||
|
|
||||||
@Override public boolean set(final PlotPlayer player, final Plot plot, final String value) {
|
@Override
|
||||||
|
public boolean set(final PlotPlayer player, final Plot plot, final String value) {
|
||||||
BiomeType biome = null;
|
BiomeType biome = null;
|
||||||
try {
|
try {
|
||||||
biome = BiomeTypes.get(value.toLowerCase());
|
biome = BiomeTypes.get(value.toLowerCase());
|
||||||
} catch (final Exception ignore) {
|
} catch (final Exception ignore) {
|
||||||
}
|
}
|
||||||
if (biome == null) {
|
if (biome == null) {
|
||||||
String biomes = StringMan.join(BiomeType.REGISTRY.values(),
|
String biomes = StringMan.join(
|
||||||
MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption.of("blocklist.block_list_separator").getComponent(player))));
|
BiomeType.REGISTRY.values(),
|
||||||
|
MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption
|
||||||
|
.of("blocklist.block_list_separator")
|
||||||
|
.getComponent(player)))
|
||||||
|
);
|
||||||
player.sendMessage(TranslatableCaption.of("biome.need_biome"));
|
player.sendMessage(TranslatableCaption.of("biome.need_biome"));
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("commandconfig.subcommand_set_options_header"),
|
TranslatableCaption.of("commandconfig.subcommand_set_options_header"),
|
||||||
Template.of("values", biomes));
|
Template.of("values", biomes)
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plot.getRunning() > 0) {
|
if (plot.getRunning() > 0) {
|
||||||
@ -83,10 +89,10 @@ public class Biome extends SetCommand {
|
|||||||
@Override
|
@Override
|
||||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||||
return SuggestionHelper.getNamespacedRegistrySuggestions(BiomeType.REGISTRY, args[0])
|
return SuggestionHelper.getNamespacedRegistrySuggestions(BiomeType.REGISTRY, args[0])
|
||||||
.map(value -> value.toLowerCase(Locale.ENGLISH).replace("minecraft:", ""))
|
.map(value -> value.toLowerCase(Locale.ENGLISH).replace("minecraft:", ""))
|
||||||
.filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH)))
|
.filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH)))
|
||||||
.map(value -> new Command(null, false, value, "", RequiredType.NONE, null) {
|
.map(value -> new Command(null, false, value, "", RequiredType.NONE, null) {
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,32 +40,37 @@ import com.plotsquared.core.util.EventDispatcher;
|
|||||||
import com.plotsquared.core.util.task.RunnableVal2;
|
import com.plotsquared.core.util.task.RunnableVal2;
|
||||||
import com.plotsquared.core.util.task.RunnableVal3;
|
import com.plotsquared.core.util.task.RunnableVal3;
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@CommandDeclaration(command = "buy",
|
@CommandDeclaration(command = "buy",
|
||||||
usage = "/plot buy",
|
usage = "/plot buy",
|
||||||
permission = "plots.buy",
|
permission = "plots.buy",
|
||||||
category = CommandCategory.CLAIMING,
|
category = CommandCategory.CLAIMING,
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Buy extends Command {
|
public class Buy extends Command {
|
||||||
|
|
||||||
private final EventDispatcher eventDispatcher;
|
private final EventDispatcher eventDispatcher;
|
||||||
private final EconHandler econHandler;
|
private final EconHandler econHandler;
|
||||||
|
|
||||||
@Inject public Buy(@Nonnull final EventDispatcher eventDispatcher,
|
@Inject
|
||||||
@Nonnull final EconHandler econHandler) {
|
public Buy(
|
||||||
|
final @NonNull EventDispatcher eventDispatcher,
|
||||||
|
final @NonNull EconHandler econHandler
|
||||||
|
) {
|
||||||
super(MainCommand.getInstance(), true);
|
super(MainCommand.getInstance(), true);
|
||||||
this.eventDispatcher = eventDispatcher;
|
this.eventDispatcher = eventDispatcher;
|
||||||
this.econHandler = econHandler;
|
this.econHandler = econHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
|
public CompletableFuture<Boolean> execute(
|
||||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
final PlotPlayer<?> player, String[] args,
|
||||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||||
|
final RunnableVal2<Command, CommandResult> whenDone
|
||||||
|
) {
|
||||||
|
|
||||||
PlotArea area = player.getPlotAreaAbs();
|
PlotArea area = player.getPlotAreaAbs();
|
||||||
check(area, TranslatableCaption.of("errors.not_in_plot_world"));
|
check(area, TranslatableCaption.of("errors.not_in_plot_world"));
|
||||||
@ -83,17 +88,21 @@ public class Buy extends Command {
|
|||||||
checkTrue(plot.hasOwner(), TranslatableCaption.of("info.plot_unowned"));
|
checkTrue(plot.hasOwner(), TranslatableCaption.of("info.plot_unowned"));
|
||||||
checkTrue(!plot.isOwner(player.getUUID()), TranslatableCaption.of("economy.cannot_buy_own"));
|
checkTrue(!plot.isOwner(player.getUUID()), TranslatableCaption.of("economy.cannot_buy_own"));
|
||||||
Set<Plot> plots = plot.getConnectedPlots();
|
Set<Plot> plots = plot.getConnectedPlots();
|
||||||
checkTrue(player.getPlotCount() + plots.size() <= player.getAllowedPlots(),
|
checkTrue(
|
||||||
TranslatableCaption.of("permission.cant_claim_more_plots"),
|
player.getPlotCount() + plots.size() <= player.getAllowedPlots(),
|
||||||
Template.of("amount", String.valueOf(player.getAllowedPlots())));
|
TranslatableCaption.of("permission.cant_claim_more_plots"),
|
||||||
|
Template.of("amount", String.valueOf(player.getAllowedPlots()))
|
||||||
|
);
|
||||||
double price = plot.getFlag(PriceFlag.class);
|
double price = plot.getFlag(PriceFlag.class);
|
||||||
if (price <= 0) {
|
if (price <= 0) {
|
||||||
throw new CommandException(TranslatableCaption.of("economy.not_for_sale"));
|
throw new CommandException(TranslatableCaption.of("economy.not_for_sale"));
|
||||||
}
|
}
|
||||||
checkTrue(this.econHandler.getMoney(player) >= price,
|
checkTrue(
|
||||||
|
this.econHandler.getMoney(player) >= price,
|
||||||
TranslatableCaption.of("economy.cannot_afford_plot"),
|
TranslatableCaption.of("economy.cannot_afford_plot"),
|
||||||
Template.of("money", this.econHandler.format(price)),
|
Template.of("money", this.econHandler.format(price)),
|
||||||
Template.of("balance", this.econHandler.format(this.econHandler.getMoney(player))));
|
Template.of("balance", this.econHandler.format(this.econHandler.getMoney(player)))
|
||||||
|
);
|
||||||
this.econHandler.withdrawMoney(player, price);
|
this.econHandler.withdrawMoney(player, price);
|
||||||
// Failure
|
// Failure
|
||||||
// Success
|
// Success
|
||||||
@ -128,4 +137,5 @@ public class Buy extends Command {
|
|||||||
});
|
});
|
||||||
return CompletableFuture.completedFuture(true);
|
return CompletableFuture.completedFuture(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,21 +47,23 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_MONSTER;
|
|||||||
import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
||||||
|
|
||||||
@CommandDeclaration(command = "caps",
|
@CommandDeclaration(command = "caps",
|
||||||
category = CommandCategory.INFO,
|
category = CommandCategory.INFO,
|
||||||
usage = "/plot caps")
|
usage = "/plot caps")
|
||||||
public class Caps extends SubCommand {
|
public class Caps extends SubCommand {
|
||||||
|
|
||||||
@Override public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
|
@Override
|
||||||
|
public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
|
||||||
final Plot plot = player.getCurrentPlot();
|
final Plot plot = player.getCurrentPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plot.isAdded(player.getUUID()) && !Permissions
|
if (!plot.isAdded(player.getUUID()) && !Permissions
|
||||||
.hasPermission(player, Permission.PERMISSION_ADMIN_CAPS_OTHER)) {
|
.hasPermission(player, Permission.PERMISSION_ADMIN_CAPS_OTHER)) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("permission.no_permission"),
|
TranslatableCaption.of("permission.no_permission"),
|
||||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_CAPS_OTHER)));
|
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_CAPS_OTHER))
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plot.getVolume() > Integer.MAX_VALUE) {
|
if (plot.getVolume() > Integer.MAX_VALUE) {
|
||||||
@ -79,9 +81,11 @@ public class Caps extends SubCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends PlotFlag<Integer, T>> void sendFormatted(final Plot plot,
|
private <T extends PlotFlag<Integer, T>> void sendFormatted(
|
||||||
final PlotPlayer<?> player, final Class<T> capFlag, final int[] countedEntities,
|
final Plot plot,
|
||||||
final String name, final int type) {
|
final PlotPlayer<?> player, final Class<T> capFlag, final int[] countedEntities,
|
||||||
|
final String name, final int type
|
||||||
|
) {
|
||||||
final int current = countedEntities[type];
|
final int current = countedEntities[type];
|
||||||
final int max = plot.getFlag(capFlag);
|
final int max = plot.getFlag(capFlag);
|
||||||
final String percentage = String.format("%.1f", 100 * ((float) current / max));
|
final String percentage = String.format("%.1f", 100 * ((float) current / max));
|
||||||
@ -90,6 +94,8 @@ public class Caps extends SubCommand {
|
|||||||
Template.of("cap", name),
|
Template.of("cap", name),
|
||||||
Template.of("current", String.valueOf(current)),
|
Template.of("current", String.valueOf(current)),
|
||||||
Template.of("limit", String.valueOf(max)),
|
Template.of("limit", String.valueOf(max)),
|
||||||
Template.of("percentage", percentage));
|
Template.of("percentage", percentage)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,14 @@ import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
|||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
|
|
||||||
@CommandDeclaration(command = "chat",
|
@CommandDeclaration(command = "chat",
|
||||||
usage = "/plot chat",
|
usage = "/plot chat",
|
||||||
permission = "plots.chat",
|
permission = "plots.chat",
|
||||||
category = CommandCategory.CHAT,
|
category = CommandCategory.CHAT,
|
||||||
requiredType = RequiredType.PLAYER)
|
requiredType = RequiredType.PLAYER)
|
||||||
public class Chat extends SubCommand {
|
public class Chat extends SubCommand {
|
||||||
|
|
||||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
@Override
|
||||||
|
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||||
if (player.getPlotAreaAbs().isForcingPlotChat()) {
|
if (player.getPlotAreaAbs().isForcingPlotChat()) {
|
||||||
player.sendMessage(TranslatableCaption.of("chat.plot_chat_forced"));
|
player.sendMessage(TranslatableCaption.of("chat.plot_chat_forced"));
|
||||||
return true;
|
return true;
|
||||||
@ -43,4 +44,5 @@ public class Chat extends SubCommand {
|
|||||||
MainCommand.getInstance().toggle.chat(this, player, args, null, null);
|
MainCommand.getInstance().toggle.chat(this, player, args, null, null);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user