diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle
index 1bf48750c..3d0059159 100644
--- a/Bukkit/build.gradle
+++ b/Bukkit/build.gradle
@@ -106,6 +106,8 @@ shadowJar {
include(dependency("javax.annotation:javax-annotation-api"))
include(dependency('org.apache.logging.log4j:log4j-slf4j-impl'))
include(dependency('org.slf4j:slf4j-api'))
+ include(dependency('javax.inject:javax.inject:1'))
+ include(dependency('aopalliance:aopalliance:1.0'))
}
relocate('net.kyori.text', 'com.plotsquared.formatting.text')
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java
index 06981b095..ea5f45430 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java
@@ -34,6 +34,7 @@ import com.google.inject.TypeLiteral;
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
import com.plotsquared.bukkit.inject.BackupModule;
import com.plotsquared.bukkit.inject.BukkitModule;
+import com.plotsquared.bukkit.inject.PermissionModule;
import com.plotsquared.bukkit.inject.WorldManagerModule;
import com.plotsquared.bukkit.listener.ChunkListener;
import com.plotsquared.bukkit.listener.EntitySpawnListener;
@@ -103,7 +104,6 @@ import com.plotsquared.core.util.ConsoleColors;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.FileUtils;
-import com.plotsquared.core.util.PermHandler;
import com.plotsquared.core.util.PlatformWorldManager;
import com.plotsquared.core.util.PlayerManager;
import com.plotsquared.core.util.PremiumVerification;
@@ -123,7 +123,6 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
-import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Entity;
@@ -184,7 +183,6 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
private boolean methodUnloadSetup = false;
private boolean metricsStarted;
private EconHandler econ;
- private PermHandler perm;
@Getter private Injector injector;
@@ -249,9 +247,11 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
// We create the injector after PlotSquared has been initialized, so that we have access
// to generated instances and settings
- this.injector = Guice
- .createInjector(Stage.PRODUCTION, new WorldManagerModule(), new PlotSquaredModule(),
- new BukkitModule(this), new BackupModule());
+ this.injector = Guice.createInjector(Stage.PRODUCTION, new PermissionModule(),
+ new WorldManagerModule(),
+ new PlotSquaredModule(),
+ new BukkitModule(this),
+ new BackupModule());
this.injector.injectMembers(this);
if (PremiumVerification.isPremium() && Settings.Enabled_Components.UPDATE_NOTIFICATIONS) {
@@ -344,10 +344,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
// Economy
if (Settings.Enabled_Components.ECONOMY) {
TaskManager.runTask(() -> {
- final PermHandler permHandler = getInjector().getInstance(PermHandler.class);
- if (permHandler != null) {
- permHandler.init();
- }
+ this.getPermissionHandler().initialize();
final EconHandler econHandler = getInjector().getInstance(EconHandler.class);
if (econHandler != null) {
econHandler.init();
@@ -589,7 +586,8 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
}
final Plot plot = area.getOwnedPlot(id);
if (plot != null) {
- if (!plot.getFlag(ServerPlotFlag.class) || PlotPlayer.wrap(plot.getOwner()) == null) {
+ if (!plot.getFlag(ServerPlotFlag.class) || PlotSquared.platform().getPlayerManager()
+ .getPlayerIfExists(plot.getOwner()) == null) {
if (world.getKeepSpawnInMemory()) {
world.setKeepSpawnInMemory(false);
return;
@@ -1104,39 +1102,6 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
}
}
- /**
- * Attempt to retrieve a {@link PlotPlayer} from a player identifier.
- * This method accepts:
- * - {@link Player} objects,
- * - {@link OfflinePlayer} objects,
- * - {@link String} usernames for online players, and
- * - {@link UUID} UUIDs for online players
- *
- * In the case of offline players, a fake {@link Player} instance will be created.
- * This is a rather expensive operation, and should be avoided if possible.
- *
- * @param player The player to convert to a PlotPlayer
- * @return The plot player instance that corresponds to the identifier, or null
- * if no such player object could be created
- */
- @Override @Nullable public PlotPlayer wrapPlayer(final Object player) {
- if (player instanceof Player) {
- return BukkitUtil.adapt((Player) player);
- }
- if (player instanceof OfflinePlayer) {
- return BukkitUtil.adapt((OfflinePlayer) player);
- }
- if (player instanceof String) {
- return (PlotPlayer) PlotSquared.platform().getPlayerManager()
- .getPlayerIfExists((String) player);
- }
- if (player instanceof UUID) {
- return (PlotPlayer) PlotSquared.platform().getPlayerManager()
- .getPlayerIfExists((UUID) player);
- }
- return null;
- }
-
@Override public String getNMSPackage() {
final String name = Bukkit.getServer().getClass().getPackage().getName();
return name.substring(name.lastIndexOf('.') + 1);
@@ -1173,8 +1138,9 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
return getInjector().getInstance(Key.get(new TypeLiteral>() {}));
}
- @Override @Nonnull public PlayerManager extends PlotPlayer, ? extends Player> getPlayerManager() {
- return getInjector().getInstance(Key.get(new TypeLiteral>() {}));
+ @Override @Nonnull @SuppressWarnings("ALL")
+ public PlayerManager extends PlotPlayer, ? extends Player> getPlayerManager() {
+ return (PlayerManager) getInjector().getInstance(PlayerManager.class);
}
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java
index 17afd5a1b..db2e311a0 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java
@@ -26,8 +26,9 @@
package com.plotsquared.bukkit.inject;
import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
import com.google.inject.assistedinject.FactoryModuleBuilder;
-import com.google.inject.util.Providers;
import com.plotsquared.bukkit.BukkitPlatform;
import com.plotsquared.bukkit.player.BukkitPlayerManager;
import com.plotsquared.bukkit.queue.BukkitChunkCoordinator;
@@ -36,7 +37,6 @@ import com.plotsquared.bukkit.schematic.BukkitSchematicHandler;
import com.plotsquared.bukkit.util.BukkitChunkManager;
import com.plotsquared.bukkit.util.BukkitEconHandler;
import com.plotsquared.bukkit.util.BukkitInventoryUtil;
-import com.plotsquared.bukkit.util.BukkitPermHandler;
import com.plotsquared.bukkit.util.BukkitRegionManager;
import com.plotsquared.bukkit.util.BukkitSetupUtils;
import com.plotsquared.bukkit.util.BukkitUtil;
@@ -58,7 +58,6 @@ import com.plotsquared.core.queue.QueueProvider;
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.InventoryUtil;
-import com.plotsquared.core.util.PermHandler;
import com.plotsquared.core.util.PlayerManager;
import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.SchematicHandler;
@@ -72,6 +71,7 @@ import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
@RequiredArgsConstructor
public class BukkitModule extends AbstractModule {
@@ -98,7 +98,6 @@ public class BukkitModule extends AbstractModule {
bind(ChunkManager.class).to(BukkitChunkManager.class);
bind(RegionManager.class).to(BukkitRegionManager.class);
bind(SchematicHandler.class).to(BukkitSchematicHandler.class);
- this.setupVault();
if (Settings.Enabled_Components.WORLDS) {
bind(PlotAreaManager.class).to(SinglePlotAreaManager.class);
} else {
@@ -111,26 +110,14 @@ public class BukkitModule extends AbstractModule {
install(new FactoryModuleBuilder().build(ChunkCoordinatorBuilderFactory.class));
}
- private void setupVault() {
+ @Provides @Singleton @Nullable EconHandler provideEconHandler() {
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
- BukkitPermHandler bukkitPermHandler = null;
try {
- bukkitPermHandler = new BukkitPermHandler();
- bind(PermHandler.class).toInstance(bukkitPermHandler);
+ return new BukkitEconHandler();
} catch (final Exception ignored) {
- bind(PermHandler.class).toProvider(Providers.of(null));
}
- try {
- final BukkitEconHandler bukkitEconHandler =
- new BukkitEconHandler(bukkitPermHandler);
- bind(EconHandler.class).toInstance(bukkitEconHandler);
- } catch (final Exception ignored) {
- bind(EconHandler.class).toProvider(Providers.of(null));
- }
- } else {
- bind(PermHandler.class).toProvider(Providers.of(null));
- bind(EconHandler.class).toProvider(Providers.of(null));
}
+ return null;
}
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/PermissionModule.java
similarity index 57%
rename from Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/inject/PermissionModule.java
index 8987e3527..de42d884a 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/PermissionModule.java
@@ -23,38 +23,26 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package com.plotsquared.bukkit.util;
+package com.plotsquared.bukkit.inject;
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
import com.google.inject.Singleton;
-import com.plotsquared.core.util.PermHandler;
-import net.milkbowl.vault.permission.Permission;
+import com.plotsquared.bukkit.permissions.BukkitPermissionHandler;
+import com.plotsquared.bukkit.permissions.VaultPermissionHandler;
+import com.plotsquared.core.permissions.PermissionHandler;
import org.bukkit.Bukkit;
-import org.bukkit.plugin.RegisteredServiceProvider;
-@Singleton public class BukkitPermHandler extends PermHandler {
+public class PermissionModule extends AbstractModule {
- private Permission perms;
-
- @Override
- public boolean init() {
- if (this.perms == null) {
- setupPermissions();
+ @Provides @Singleton PermissionHandler providePermissionHandler() {
+ try {
+ if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
+ return new VaultPermissionHandler();
+ }
+ } catch (final Exception ignored) {
}
- return this.perms != null;
+ return new BukkitPermissionHandler();
}
- private void setupPermissions() {
- if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
- return;
- }
- RegisteredServiceProvider permissionProvider =
- Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
- if (permissionProvider != null) {
- this.perms = permissionProvider.getProvider();
- }
- }
-
- @Override public boolean hasPermission(String world, String player, String perm) {
- return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm);
- }
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java
index f334e055b..0e783067c 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java
@@ -38,6 +38,8 @@ import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.listener.PlayerBlockEventType;
import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.location.Location;
+import com.plotsquared.core.player.MetaDataAccess;
+import com.plotsquared.core.player.PlayerMetaDataKeys;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
@@ -216,8 +218,8 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;
-import javax.annotation.Nonnull;
+import javax.annotation.Nonnull;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashSet;
@@ -731,32 +733,36 @@ import java.util.regex.Pattern;
public void onTeleport(PlayerTeleportEvent event) {
Player player = event.getPlayer();
BukkitPlayer pp = BukkitUtil.adapt(player);
- Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT);
- org.bukkit.Location to = event.getTo();
- //noinspection ConstantConditions
- if (to != null) {
- Location location = BukkitUtil.adapt(to);
- PlotArea area = location.getPlotArea();
- if (area == null) {
- if (lastPlot != null) {
- plotExit(pp, lastPlot);
- pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
+ try (final MetaDataAccess lastPlotAccess =
+ pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
+ Plot lastPlot = lastPlotAccess.get().orElse(null);
+ org.bukkit.Location to = event.getTo();
+ //noinspection ConstantConditions
+ if (to != null) {
+ Location location = BukkitUtil.adapt(to);
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ if (lastPlot != null) {
+ plotExit(pp, lastPlot);
+ lastPlotAccess.remove();
+ }
+ try (final MetaDataAccess lastLocationAccess =
+ pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
+ lastLocationAccess.remove();
+ }
+ return;
}
- pp.deleteMeta(PlotPlayer.META_LOCATION);
- return;
- }
- Plot plot = area.getPlot(location);
- if (plot != null) {
- final boolean result = DenyTeleportFlag.allowsTeleport(pp, plot);
- // there is one possibility to still allow teleportation:
- // to is identical to the plot's home location, and untrusted-visit is true
- // i.e. untrusted-visit can override deny-teleport
- // 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)))) {
- MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
- Captions.PERMISSION_ADMIN_ENTRY_DENIED);
- event.setCancelled(true);
+ Plot plot = area.getPlot(location);
+ if (plot != null) {
+ final boolean result = DenyTeleportFlag.allowsTeleport(pp, plot);
+ // there is one possibility to still allow teleportation:
+ // to is identical to the plot's home location, and untrusted-visit is true
+ // i.e. untrusted-visit can override deny-teleport
+ // 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)))) {
+ MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_ENTRY_DENIED);
+ event.setCancelled(true);
+ }
}
}
}
@@ -847,28 +853,39 @@ import java.util.regex.Pattern;
}
// Set last location
Location location = BukkitUtil.adapt(to);
- pp.setMeta(PlotPlayer.META_LOCATION, location);
+ try (final MetaDataAccess lastLocationAccess =
+ pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
+ lastLocationAccess.remove();
+ }
PlotArea area = location.getPlotArea();
if (area == null) {
- pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
+ try (final MetaDataAccess lastPlotAccess =
+ pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
+ lastPlotAccess.remove();
+ }
return;
}
Plot now = area.getPlot(location);
- Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT);
+ Plot lastPlot;
+ try (final MetaDataAccess lastPlotAccess =
+ pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
+ lastPlot = lastPlotAccess.get().orElse(null);
+ }
if (now == null) {
- if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !pp
- .getMeta("kick", false)) {
- MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
- Captions.PERMISSION_ADMIN_EXIT_DENIED);
- this.tmpTeleport = false;
- if (lastPlot.equals(BukkitUtil.adapt(from).getPlot())) {
- player.teleport(from);
- } else {
- player.teleport(player.getWorld().getSpawnLocation());
+ try (final MetaDataAccess kickAccess =
+ pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
+ if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !kickAccess.get().orElse(false)) {
+ MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_EXIT_DENIED);
+ this.tmpTeleport = false;
+ if (lastPlot.equals(BukkitUtil.adapt(from).getPlot())) {
+ player.teleport(from);
+ } else {
+ player.teleport(player.getWorld().getSpawnLocation());
+ }
+ this.tmpTeleport = true;
+ event.setCancelled(true);
+ return;
}
- this.tmpTeleport = true;
- event.setCancelled(true);
- return;
}
} else if (now.equals(lastPlot)) {
ForceFieldListener.handleForcefield(player, pp, now);
@@ -909,28 +926,39 @@ import java.util.regex.Pattern;
}
// Set last location
Location location = BukkitUtil.adapt(to);
- pp.setMeta(PlotPlayer.META_LOCATION, location);
+ try (final MetaDataAccess lastLocationAccess =
+ pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
+ lastLocationAccess.set(location);
+ }
PlotArea area = location.getPlotArea();
if (area == null) {
- pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
+ try (final MetaDataAccess lastPlotAccess =
+ pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
+ lastPlotAccess.remove();
+ }
return;
}
Plot now = area.getPlot(location);
- Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT);
+ Plot lastPlot;
+ try (final MetaDataAccess lastPlotAccess =
+ pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
+ lastPlot = lastPlotAccess.get().orElse(null);
+ }
if (now == null) {
- if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !pp
- .getMeta("kick", false)) {
- MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
- Captions.PERMISSION_ADMIN_EXIT_DENIED);
- this.tmpTeleport = false;
- if (lastPlot.equals(BukkitUtil.adapt(from).getPlot())) {
- player.teleport(from);
- } else {
- player.teleport(player.getWorld().getSpawnLocation());
+ try (final MetaDataAccess kickAccess =
+ pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
+ if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !kickAccess.get().orElse(false)) {
+ MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_EXIT_DENIED);
+ this.tmpTeleport = false;
+ if (lastPlot.equals(BukkitUtil.adapt(from).getPlot())) {
+ player.teleport(from);
+ } else {
+ player.teleport(player.getWorld().getSpawnLocation());
+ }
+ this.tmpTeleport = true;
+ event.setCancelled(true);
+ return;
}
- this.tmpTeleport = true;
- event.setCancelled(true);
- return;
}
} else if (now.equals(lastPlot)) {
ForceFieldListener.handleForcefield(player, pp, now);
@@ -1155,8 +1183,15 @@ import java.util.regex.Pattern;
Player player = event.getPlayer();
BukkitPlayer pp = BukkitUtil.adapt(player);
// Delete last location
- Plot plot = (Plot) pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
- pp.deleteMeta(PlotPlayer.META_LOCATION);
+ Plot plot;
+ try (final MetaDataAccess lastPlotAccess =
+ pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
+ plot = lastPlotAccess.remove();
+ }
+ try (final MetaDataAccess lastLocationAccess =
+ pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
+ lastLocationAccess.remove();
+ }
if (plot != null) {
plotExit(pp, plot);
}
@@ -1167,9 +1202,6 @@ import java.util.regex.Pattern;
}
}
}
- if (Settings.Enabled_Components.PERMISSION_CACHE) {
- pp.deleteMeta("perm");
- }
Location location = pp.getLocation();
PlotArea area = location.getPlotArea();
if (location.isPlotArea()) {
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/permissions/BukkitPermissionHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/permissions/BukkitPermissionHandler.java
new file mode 100644
index 000000000..6aca7ea62
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/permissions/BukkitPermissionHandler.java
@@ -0,0 +1,86 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * PlotSquared plot management system for Minecraft
+ * Copyright (C) 2020 IntellectualSites
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package com.plotsquared.bukkit.permissions;
+
+import com.plotsquared.bukkit.player.BukkitPlayer;
+import com.plotsquared.core.permissions.ConsolePermissionProfile;
+import com.plotsquared.core.permissions.PermissionHandler;
+import com.plotsquared.core.permissions.PermissionProfile;
+import com.plotsquared.core.player.ConsolePlayer;
+import com.plotsquared.core.player.OfflinePlotPlayer;
+import com.plotsquared.core.player.PlotPlayer;
+import org.bukkit.entity.Player;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.lang.ref.WeakReference;
+import java.util.EnumSet;
+import java.util.Optional;
+import java.util.Set;
+
+public class BukkitPermissionHandler implements PermissionHandler {
+
+ @Override public void initialize() {
+ }
+
+ @Nonnull @Override public Optional getPermissionProfile(
+ @Nonnull PlotPlayer> playerPlotPlayer) {
+ if (playerPlotPlayer instanceof BukkitPlayer) {
+ final BukkitPlayer bukkitPlayer = (BukkitPlayer) playerPlotPlayer;
+ return Optional.of(new BukkitPermissionProfile(bukkitPlayer.getPlatformPlayer()));
+ } else if (playerPlotPlayer instanceof ConsolePlayer) {
+ return Optional.of(ConsolePermissionProfile.INSTANCE);
+ }
+ return Optional.empty();
+ }
+
+ @Nonnull @Override public Optional getPermissionProfile(
+ @Nonnull OfflinePlotPlayer offlinePlotPlayer) {
+ return Optional.empty();
+ }
+
+ @Nonnull @Override public Set getCapabilities() {
+ return EnumSet.of(PermissionHandlerCapability.ONLINE_PERMISSIONS);
+ }
+
+
+ private static final class BukkitPermissionProfile implements PermissionProfile {
+
+ private final WeakReference playerReference;
+
+ private BukkitPermissionProfile(@Nonnull final Player player) {
+ this.playerReference = new WeakReference<>(player);
+ }
+
+ @Override public boolean hasPermission(@Nullable final String world,
+ @Nonnull final String permission) {
+ final Player player = this.playerReference.get();
+ return player != null && player.hasPermission(permission);
+ }
+
+ }
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/permissions/VaultPermissionHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/permissions/VaultPermissionHandler.java
new file mode 100644
index 000000000..b7b08a49f
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/permissions/VaultPermissionHandler.java
@@ -0,0 +1,109 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * PlotSquared plot management system for Minecraft
+ * Copyright (C) 2020 IntellectualSites
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package com.plotsquared.bukkit.permissions;
+
+import com.plotsquared.bukkit.player.BukkitOfflinePlayer;
+import com.plotsquared.bukkit.player.BukkitPlayer;
+import com.plotsquared.core.permissions.ConsolePermissionProfile;
+import com.plotsquared.core.permissions.PermissionHandler;
+import com.plotsquared.core.permissions.PermissionProfile;
+import com.plotsquared.core.player.ConsolePlayer;
+import com.plotsquared.core.player.OfflinePlotPlayer;
+import com.plotsquared.core.player.PlotPlayer;
+import net.milkbowl.vault.permission.Permission;
+import org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.plugin.RegisteredServiceProvider;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.EnumSet;
+import java.util.Optional;
+import java.util.Set;
+
+public class VaultPermissionHandler implements PermissionHandler {
+
+ private Permission permissions;
+
+ @Override public void initialize() {
+ if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
+ throw new IllegalStateException("Vault is not present on the server");
+ }
+ RegisteredServiceProvider permissionProvider =
+ Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
+ if (permissionProvider != null) {
+ this.permissions = permissionProvider.getProvider();
+ }
+ }
+
+ @Nonnull @Override public Optional getPermissionProfile(
+ @Nonnull PlotPlayer> playerPlotPlayer) {
+ if (playerPlotPlayer instanceof BukkitPlayer) {
+ final BukkitPlayer bukkitPlayer = (BukkitPlayer) playerPlotPlayer;
+ return Optional.of(new VaultPermissionProfile(bukkitPlayer.getPlatformPlayer()));
+ } else if (playerPlotPlayer instanceof ConsolePlayer) {
+ return Optional.of(ConsolePermissionProfile.INSTANCE);
+ }
+ return Optional.empty();
+ }
+
+ @Nonnull @Override public Optional getPermissionProfile(
+ @Nonnull OfflinePlotPlayer offlinePlotPlayer) {
+ if (offlinePlotPlayer instanceof BukkitOfflinePlayer) {
+ return Optional.of(new VaultPermissionProfile(((BukkitOfflinePlayer) offlinePlotPlayer).player));
+ }
+ return Optional.empty();
+ }
+
+ @Nonnull @Override public Set getCapabilities() {
+ return EnumSet.of(PermissionHandlerCapability.PER_WORLD_PERMISSIONS,
+ PermissionHandlerCapability.ONLINE_PERMISSIONS,
+ PermissionHandlerCapability.OFFLINE_PERMISSIONS);
+ }
+
+
+ private final class VaultPermissionProfile implements PermissionProfile {
+
+ private final OfflinePlayer offlinePlayer;
+
+ private VaultPermissionProfile(@Nonnull final OfflinePlayer offlinePlayer) {
+ this.offlinePlayer = offlinePlayer;
+ }
+
+ @Override public boolean hasPermission(@Nullable final String world,
+ @Nonnull final String permission) {
+ if (permissions == null) {
+ return false;
+ }
+ if (world == null && offlinePlayer instanceof BukkitPlayer) {
+ return permissions.playerHas(((BukkitPlayer) offlinePlayer).getPlatformPlayer(), permission);
+ }
+ return permissions.playerHas(world, offlinePlayer, permission);
+ }
+
+ }
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitOfflinePlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitOfflinePlayer.java
index 3aa5d12c3..799fbf2b1 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitOfflinePlayer.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitOfflinePlayer.java
@@ -25,39 +25,49 @@
*/
package com.plotsquared.bukkit.player;
+import com.plotsquared.core.permissions.NullPermissionProfile;
+import com.plotsquared.core.permissions.PermissionHandler;
+import com.plotsquared.core.permissions.PermissionProfile;
import com.plotsquared.core.player.OfflinePlotPlayer;
import org.bukkit.OfflinePlayer;
+
+import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.UUID;
public class BukkitOfflinePlayer implements OfflinePlotPlayer {
public final OfflinePlayer player;
+ private final PermissionProfile permissionProfile;
/**
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player),
* as it caches player objects.
- *
- * @param player
*/
- public BukkitOfflinePlayer(OfflinePlayer player) {
+ public BukkitOfflinePlayer(@Nonnull final OfflinePlayer player, @Nonnull final
+ PermissionHandler permissionHandler) {
this.player = player;
+ this.permissionProfile = permissionHandler.getPermissionProfile(this)
+ .orElse(NullPermissionProfile.INSTANCE);
}
@Nonnull @Override public UUID getUUID() {
return this.player.getUniqueId();
}
- @Override public long getLastPlayed() {
- return this.player.getLastPlayed();
- }
-
- @Override public boolean isOnline() {
- return this.player.isOnline();
+ @Override @Nonnegative public long getLastPlayed() {
+ return this.player.getLastSeen();
}
@Override public String getName() {
return this.player.getName();
}
+
+ @Override public boolean hasPermission(@Nullable final String world,
+ @Nonnull final String permission) {
+ return this.permissionProfile.hasPermission(world, permission);
+ }
+
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java
index 15d9bacf8..9d9d7e4cb 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java
@@ -32,6 +32,7 @@ import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.location.Location;
+import com.plotsquared.core.permissions.PermissionHandler;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotWeather;
import com.plotsquared.core.plot.world.PlotAreaManager;
@@ -53,6 +54,8 @@ import org.bukkit.event.EventException;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.RegisteredListener;
+
+import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -69,13 +72,11 @@ import static com.sk89q.worldedit.world.gamemode.GameModes.SURVIVAL;
public class BukkitPlayer extends PlotPlayer {
private static boolean CHECK_EFFECTIVE = true;
-
- private final EconHandler econHandler;
public final Player player;
- private boolean offline;
+ private final EconHandler econHandler;
private String name;
-
-
+ private String lastMessage = "";
+ private long lastMessageTime = 0L;
/**
* Please do not use this method. Instead use
* BukkitUtil.getPlayer(Player), as it caches player objects.
@@ -83,21 +84,16 @@ public class BukkitPlayer extends PlotPlayer {
* @param player Bukkit player instance
*/
public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final EventDispatcher eventDispatcher,
- @Nonnull final Player player, @Nullable final EconHandler econHandler) {
- this(plotAreaManager, eventDispatcher, player, false, econHandler);
- }
-
- public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final EventDispatcher eventDispatcher,
- @Nonnull final Player player, final boolean offline, @Nullable final EconHandler econHandler) {
- this(plotAreaManager, eventDispatcher, player, offline, true, econHandler);
+ @Nonnull final Player player, @Nullable final EconHandler econHandler, @Nonnull final PermissionHandler permissionHandler) {
+ this(plotAreaManager, eventDispatcher, player, false, econHandler, permissionHandler);
}
public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final
- EventDispatcher eventDispatcher, @Nonnull final Player player, final boolean offline,
- final boolean realPlayer, @Nullable final EconHandler econHandler) {
- super(plotAreaManager, eventDispatcher, econHandler);
+ EventDispatcher eventDispatcher, @Nonnull final Player player,
+ final boolean realPlayer, @Nullable final EconHandler econHandler,
+ @Nonnull final PermissionHandler permissionHandler) {
+ super(plotAreaManager, eventDispatcher, econHandler, permissionHandler);
this.player = player;
- this.offline = offline;
this.econHandler = econHandler;
if (realPlayer) {
super.populatePersistentMetaMap();
@@ -125,8 +121,8 @@ public class BukkitPlayer extends PlotPlayer {
return player.getUniqueId();
}
- @Override public long getLastPlayed() {
- return this.player.getLastPlayed();
+ @Override @Nonnegative public long getLastPlayed() {
+ return this.player.getLastSeen();
}
@Override public boolean canTeleport(@Nonnull final Location location) {
@@ -161,14 +157,8 @@ public class BukkitPlayer extends PlotPlayer {
}
}
- @Override public boolean hasPermission(final String permission) {
- if (this.offline && this.econHandler != null) {
- return this.econHandler.hasPermission(getName(), permission);
- }
- return this.player.hasPermission(permission);
- }
-
- @Override public int hasPermissionRange(final String stub, final int range) {
+ @Override @Nonnegative public int hasPermissionRange(@Nonnull final String stub,
+ @Nonnegative final int range) {
if (hasPermission(Captions.PERMISSION_ADMIN.getTranslated())) {
return Integer.MAX_VALUE;
}
@@ -228,16 +218,12 @@ public class BukkitPlayer extends PlotPlayer {
return max;
}
- @Override public boolean isPermissionSet(final String permission) {
- return this.player.isPermissionSet(permission);
- }
-
@Override public void sendMessage(String message) {
message = message.replace('\u2010', '%').replace('\u2020', '&').replace('\u2030', '&');
- if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || (
- System.currentTimeMillis() - this.getMeta("lastMessageTime") > 5000)) {
- setMeta("lastMessage", message);
- setMeta("lastMessageTime", System.currentTimeMillis());
+ if (!StringMan.isEqual(this.lastMessage, message) || (
+ System.currentTimeMillis() - this.lastMessageTime > 5000)) {
+ this.lastMessage = message;
+ this.lastMessageTime = System.currentTimeMillis();
this.player.sendMessage(message);
}
}
@@ -260,10 +246,6 @@ public class BukkitPlayer extends PlotPlayer {
return this.name;
}
- @Override public boolean isOnline() {
- return !this.offline && this.player.isOnline();
- }
-
@Override public void setCompassTarget(Location location) {
this.player.setCompassTarget(
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorldName()), location.getX(),
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java
index 7238709e3..78af765a2 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java
@@ -27,6 +27,7 @@ package com.plotsquared.bukkit.player;
import com.google.inject.Inject;
import com.google.inject.Singleton;
+import com.plotsquared.core.permissions.PermissionHandler;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.EventDispatcher;
@@ -46,21 +47,26 @@ import java.util.UUID;
private final PlotAreaManager plotAreaManager;
private final EventDispatcher eventDispatcher;
private final EconHandler econHandler;
+ private final PermissionHandler permissionHandler;
@Inject public BukkitPlayerManager(@Nonnull final PlotAreaManager plotAreaManager,
@Nonnull final EventDispatcher eventDispatcher,
- @Nullable final EconHandler econHandler) {
+ @Nullable final EconHandler econHandler,
+ @Nonnull final PermissionHandler permissionHandler) {
this.plotAreaManager = plotAreaManager;
this.eventDispatcher = eventDispatcher;
this.econHandler = econHandler;
+ this.permissionHandler = permissionHandler;
}
@Nonnull @Override public BukkitPlayer getPlayer(@Nonnull final Player object) {
+ if (!object.isOnline()) {
+ throw new NoSuchPlayerException(object.getUniqueId());
+ }
try {
return getPlayer(object.getUniqueId());
} catch (final NoSuchPlayerException exception) {
- return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, object,
- object.isOnline(), false, this.econHandler);
+ return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, object, false, this.econHandler, this.permissionHandler);
}
}
@@ -69,18 +75,18 @@ import java.util.UUID;
if (player == null || !player.isOnline()) {
throw new NoSuchPlayerException(uuid);
}
- return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, player, this.econHandler);
+ return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, player, this.econHandler, this.permissionHandler);
}
@Nullable @Override public BukkitOfflinePlayer getOfflinePlayer(@Nullable final UUID uuid) {
if (uuid == null) {
return null;
}
- return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid));
+ return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid), this.permissionHandler);
}
@Nonnull @Override public BukkitOfflinePlayer getOfflinePlayer(@Nonnull final String username) {
- return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(username));
+ return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(username), this.permissionHandler);
}
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java
index c7356c13b..470fbbfbb 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java
@@ -25,31 +25,21 @@
*/
package com.plotsquared.bukkit.util;
-import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.plotsquared.bukkit.player.BukkitOfflinePlayer;
import com.plotsquared.bukkit.player.BukkitPlayer;
import com.plotsquared.core.player.OfflinePlotPlayer;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.EconHandler;
-import com.plotsquared.core.util.PermHandler;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
-import javax.annotation.Nullable;
@Singleton public class BukkitEconHandler extends EconHandler {
private Economy econ;
- private final PermHandler permHandler;
-
- @Inject public BukkitEconHandler(@Nullable final PermHandler permHandler) {
- this.permHandler = permHandler;
- }
-
- @Override
- public boolean init() {
+ @Override public boolean init() {
if (this.econ == null) {
setupEconomy();
}
@@ -87,17 +77,6 @@ import javax.annotation.Nullable;
this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
}
- /**
- * @deprecated Use {@link PermHandler#hasPermission(String, String, String)} instead
- */
- @Deprecated @Override public boolean hasPermission(String world, String player, String perm) {
- if (this.permHandler != null) {
- return this.permHandler.hasPermission(world, player, perm);
- } else {
- return false;
- }
- }
-
@Override public double getBalance(PlotPlayer> player) {
return this.econ.getBalance(player.getName());
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java
index 659b6a7d7..790b322de 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java
@@ -51,7 +51,6 @@ import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
-import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
@@ -113,25 +112,6 @@ public class BukkitUtil extends WorldUtil {
LoggerFactory.getLogger("P2/" + BukkitUtil.class.getSimpleName());
private final Collection tileEntityTypes = new HashSet<>();
- /**
- * Get a {@link PlotPlayer} from an {@link OfflinePlayer}. If the player is
- * online, it returns a complete player. If the player is offline, it creates
- * a fake player
- *
- * @param op Offline player
- * @return Plot player instance
- */
- @Nonnull public static PlotPlayer adapt(@Nonnull final OfflinePlayer op) {
- if (op.isOnline()) {
- return adapt(Objects.requireNonNull(op.getPlayer()));
- }
- final Player player = OfflinePlayerUtil.loadPlayer(op);
- player.loadData();
- return new BukkitPlayer(PlotSquared.get().getPlotAreaManager(),
- PlotSquared.get().getEventDispatcher(), player, true,
- PlotSquared.platform().getEconHandler());
- }
-
/**
* Turn a Bukkit {@link Player} into a PlotSquared {@link PlotPlayer}
*
@@ -213,20 +193,8 @@ public class BukkitUtil extends WorldUtil {
}
}
- /**
- * Gets the PlotPlayer for a UUID. The PlotPlayer is usually cached and
- * will provide useful functions relating to players.
- *
- * @param uuid the uuid to wrap
- * @return a {@code PlotPlayer}
- * @see PlotPlayer#wrap(Object)
- */
- @Override @Nonnull public PlotPlayer> getPlayer(@Nonnull final UUID uuid) {
- return PlotPlayer.wrap(Bukkit.getOfflinePlayer(uuid));
- }
-
- @Override
- public boolean isBlockSame(@Nonnull final BlockState block1, @Nonnull final BlockState block2) {
+ @Override public boolean isBlockSame(@Nonnull final BlockState block1,
+ @Nonnull final BlockState block2) {
if (block1.equals(block2)) {
return true;
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/OfflinePlayerUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/OfflinePlayerUtil.java
deleted file mode 100644
index 41ae4dedd..000000000
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/OfflinePlayerUtil.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * _____ _ _ _____ _
- * | __ \| | | | / ____| | |
- * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
- * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
- * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
- * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
- * | |
- * |_|
- * PlotSquared plot management system for Minecraft
- * Copyright (C) 2020 IntellectualSites
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package com.plotsquared.bukkit.util;
-
-import org.bukkit.Bukkit;
-import org.bukkit.OfflinePlayer;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.Player;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.UUID;
-
-import static com.plotsquared.core.util.ReflectionUtils.callConstructor;
-import static com.plotsquared.core.util.ReflectionUtils.callMethod;
-import static com.plotsquared.core.util.ReflectionUtils.getCbClass;
-import static com.plotsquared.core.util.ReflectionUtils.getField;
-import static com.plotsquared.core.util.ReflectionUtils.getNmsClass;
-import static com.plotsquared.core.util.ReflectionUtils.getUtilClass;
-import static com.plotsquared.core.util.ReflectionUtils.makeConstructor;
-import static com.plotsquared.core.util.ReflectionUtils.makeField;
-import static com.plotsquared.core.util.ReflectionUtils.makeMethod;
-
-public class OfflinePlayerUtil {
-
- public static Player loadPlayer(OfflinePlayer player) {
- if (player == null) {
- return null;
- }
- if (player instanceof Player) {
- return (Player) player;
- }
- return loadPlayer(player.getUniqueId(), player.getName());
- }
-
- private static Player loadPlayer(UUID id, String name) {
- Object server = getMinecraftServer();
- Object interactManager = newPlayerInteractManager();
- Object worldServer = getWorldServer();
- Object profile = newGameProfile(id, name);
- Class> entityPlayerClass = getNmsClass("EntityPlayer");
- Constructor entityPlayerConstructor =
- makeConstructor(entityPlayerClass, getNmsClass("MinecraftServer"),
- getNmsClass("WorldServer"), getUtilClass("com.mojang.authlib.GameProfile"),
- getNmsClass("PlayerInteractManager"));
- Object entityPlayer =
- callConstructor(entityPlayerConstructor, server, worldServer, profile, interactManager);
- return (Player) getBukkitEntity(entityPlayer);
- }
-
- private static Object newGameProfile(UUID id, String name) {
- Class> gameProfileClass = getUtilClass("com.mojang.authlib.GameProfile");
- if (gameProfileClass == null) { //Before uuids
- return name;
- }
- Constructor gameProfileConstructor =
- makeConstructor(gameProfileClass, UUID.class, String.class);
- if (gameProfileConstructor == null) { //Version has string constructor
- gameProfileConstructor = makeConstructor(gameProfileClass, String.class, String.class);
- return callConstructor(gameProfileConstructor, id.toString(), name);
- } else { //Version has uuid constructor
- return callConstructor(gameProfileConstructor, id, name);
- }
- }
-
- private static Object newPlayerInteractManager() {
- Object worldServer = getWorldServer();
- Class> playerInteractClass = getNmsClass("PlayerInteractManager");
- Class> worldClass = getNmsClass("World");
- Constructor> c = makeConstructor(playerInteractClass, worldClass);
- if (c == null) {
- c = makeConstructor(playerInteractClass, getNmsClass("WorldServer"));
- }
- return callConstructor(c, worldServer);
- }
-
- public static Object getWorldServerNew() {
- Object server = getMinecraftServer();
- Class> minecraftServerClass = getNmsClass("MinecraftServer");
- Class> dimensionManager = getNmsClass("DimensionManager");
- Object overworld = getField(makeField(dimensionManager, "OVERWORLD"), null);
- Method getWorldServer =
- makeMethod(minecraftServerClass, "getWorldServer", dimensionManager);
- return callMethod(getWorldServer, server, overworld);
- }
-
- private static Object getWorldServer() {
- Object server = getMinecraftServer();
- Class> minecraftServerClass = getNmsClass("MinecraftServer");
- Method getWorldServer = makeMethod(minecraftServerClass, "getWorldServer", int.class);
- Object o;
- try {
- o = callMethod(getWorldServer, server, 0);
- } catch (final RuntimeException e) {
- o = getWorldServerNew();
- }
- return o;
- }
-
- //NMS Utils
-
- private static Object getMinecraftServer() {
- return callMethod(makeMethod(getCbClass("CraftServer"), "getServer"), Bukkit.getServer());
- }
-
- private static Entity getBukkitEntity(Object o) {
- Method getBukkitEntity = makeMethod(o.getClass(), "getBukkitEntity");
- return callMethod(getBukkitEntity, o);
- }
-}
diff --git a/Core/build.gradle b/Core/build.gradle
index 9743bc080..bd0fa55f0 100644
--- a/Core/build.gradle
+++ b/Core/build.gradle
@@ -20,6 +20,8 @@ dependencies {
compile("com.google.inject:guice:4.2.3")
compile("com.google.inject.extensions:guice-assistedinject:4.2.3")
compile group: 'com.google.code.findbugs', name: 'annotations', version: '3.0.1'
+ compile group: 'javax.inject', name: 'javax.inject', version: '1'
+ compile group: 'aopalliance', name: 'aopalliance', version: '1.0'
// logging
implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")
}
diff --git a/Core/pom.xml b/Core/pom.xml
index 272b95508..1c6963679 100644
--- a/Core/pom.xml
+++ b/Core/pom.xml
@@ -36,6 +36,18 @@
3.0.1
compile
+
+ javax.inject
+ javax.inject
+ 1
+ compile
+
+
+ aopalliance
+ aopalliance
+ 1.0
+ compile
+
org.projectlombok
lombok
diff --git a/Core/src/main/java/com/plotsquared/core/PlotAPI.java b/Core/src/main/java/com/plotsquared/core/PlotAPI.java
index 9a83aae5e..1450a3f4e 100644
--- a/Core/src/main/java/com/plotsquared/core/PlotAPI.java
+++ b/Core/src/main/java/com/plotsquared/core/PlotAPI.java
@@ -39,6 +39,8 @@ import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.query.PlotQuery;
import lombok.NoArgsConstructor;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Set;
import java.util.UUID;
@@ -178,10 +180,9 @@ import java.util.UUID;
*
* @param uuid the uuid of the player to wrap
* @return a {@code PlotPlayer}
- * @see PlotPlayer#wrap(Object)
*/
- public PlotPlayer wrapPlayer(UUID uuid) {
- return PlotPlayer.wrap(uuid);
+ @Nullable public PlotPlayer> wrapPlayer(@Nonnull final UUID uuid) {
+ return PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid);
}
/**
@@ -189,10 +190,9 @@ import java.util.UUID;
*
* @param player the player to wrap
* @return a {@code PlotPlayer}
- * @see PlotPlayer#wrap(Object)
*/
- public PlotPlayer wrapPlayer(String player) {
- return PlotPlayer.wrap(player);
+ @Nullable public PlotPlayer> wrapPlayer(@Nonnull final String player) {
+ return PlotSquared.platform().getPlayerManager().getPlayerIfExists(player);
}
/**
diff --git a/Core/src/main/java/com/plotsquared/core/PlotPlatform.java b/Core/src/main/java/com/plotsquared/core/PlotPlatform.java
index dc3136372..51f5ff6e1 100644
--- a/Core/src/main/java/com/plotsquared/core/PlotPlatform.java
+++ b/Core/src/main/java/com/plotsquared/core/PlotPlatform.java
@@ -27,12 +27,14 @@ package com.plotsquared.core;
import com.google.inject.Injector;
import com.google.inject.Key;
+import com.google.inject.TypeLiteral;
import com.plotsquared.core.backup.BackupManager;
import com.plotsquared.core.generator.GeneratorWrapper;
import com.plotsquared.core.generator.HybridUtils;
import com.plotsquared.core.generator.IndependentPlotGenerator;
import com.plotsquared.core.inject.annotations.DefaultGenerator;
import com.plotsquared.core.location.World;
+import com.plotsquared.core.permissions.PermissionHandler;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.util.ChatManager;
@@ -79,14 +81,6 @@ public interface PlotPlatform extends ILogger {
*/
File getWorldContainer();
- /**
- * Wraps a player into a PlotPlayer object.
- *
- * @param player The player to convert to a PlotPlayer
- * @return A PlotPlayer
- */
- @Nullable PlotPlayer
wrapPlayer(Object player);
-
/**
* Completely shuts down the plugin.
*/
@@ -185,7 +179,7 @@ public interface PlotPlatform
extends ILogger {
* @return Player manager
*/
@Nonnull default PlayerManager extends PlotPlayer
, ? extends P> getPlayerManager() {
- return getInjector().getInstance(PlayerManager.class);
+ return getInjector().getInstance(Key.get(new TypeLiteral, ? extends P>>() {}));
}
/**
@@ -266,4 +260,13 @@ public interface PlotPlatform extends ILogger {
return getInjector().getInstance(ChunkManager.class);
}
+ /**
+ * Get the {@link PermissionHandler} implementation for the platform
+ *
+ * @return Permission handler
+ */
+ @Nonnull default PermissionHandler getPermissionHandler() {
+ return getInjector().getInstance(PermissionHandler.class);
+ }
+
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Area.java b/Core/src/main/java/com/plotsquared/core/command/Area.java
index 5003b3b14..29a9f1551 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Area.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Area.java
@@ -79,9 +79,12 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.UUID;
@CommandDeclaration(command = "area",
permission = "plots.area",
@@ -102,6 +105,8 @@ public class Area extends SubCommand {
private final RegionManager regionManager;
private final GlobalBlockQueue blockQueue;
+ private final Map> metaData = new HashMap<>();
+
@Inject public Area(@Nonnull final PlotAreaManager plotAreaManager,
@WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
@WorldFile @Nonnull final File worldFile,
@@ -282,14 +287,16 @@ public class Area extends SubCommand {
case 2:
switch (args[1].toLowerCase()) {
case "pos1": { // Set position 1
- HybridPlotWorld area = player.getMeta("area_create_area");
+ HybridPlotWorld area = (HybridPlotWorld) metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>())
+ .get("area_create_area");
if (area == null) {
Captions.COMMAND_SYNTAX.send(player,
"/plot area create [world[:id]] [=]...");
return false;
}
Location location = player.getLocation();
- player.setMeta("area_pos1", location);
+ metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>())
+ .put("area_pos1", location);
Captions.SET_ATTRIBUTE.send(player, "area_pos1",
location.getX() + "," + location.getZ());
MainUtil.sendMessage(player,
@@ -298,14 +305,15 @@ public class Area extends SubCommand {
return true;
}
case "pos2": // Set position 2 and finish creation for type=2 (partial)
- final HybridPlotWorld area = player.getMeta("area_create_area");
+ final HybridPlotWorld area = (HybridPlotWorld) metaData
+ .computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).get("area_create_area");
if (area == null) {
Captions.COMMAND_SYNTAX.send(player,
"/plot area create [world[:id]] [=]...");
return false;
}
Location pos1 = player.getLocation();
- Location pos2 = player.getMeta("area_pos1");
+ Location pos2 = (Location) metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).get("area_pos1");
int dx = Math.abs(pos1.getX() - pos2.getX());
int dz = Math.abs(pos1.getZ() - pos2.getZ());
int numX = Math.max(1,
@@ -521,7 +529,7 @@ public class Area extends SubCommand {
player.teleport(this.worldUtil.getSpawn(pa.getWorldName()),
TeleportCause.COMMAND);
}
- player.setMeta("area_create_area", pa);
+ metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).put("area_create_area", pa);
MainUtil.sendMessage(player,
"$1Go to the first corner and use: $2 " + getCommandString()
+ " create pos1");
diff --git a/Core/src/main/java/com/plotsquared/core/command/Auto.java b/Core/src/main/java/com/plotsquared/core/command/Auto.java
index ea6a6cf6c..63b361304 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Auto.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Auto.java
@@ -26,7 +26,6 @@
package com.plotsquared.core.command;
import com.google.common.collect.Lists;
-import com.google.common.primitives.Ints;
import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.CaptionUtility;
@@ -37,6 +36,9 @@ import com.plotsquared.core.events.PlayerAutoPlotEvent;
import com.plotsquared.core.events.PlotAutoMergeEvent;
import com.plotsquared.core.events.Result;
import com.plotsquared.core.events.TeleportCause;
+import com.plotsquared.core.player.MetaDataAccess;
+import com.plotsquared.core.player.PlayerMetaDataKeys;
+import com.plotsquared.core.permissions.PermissionHandler;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
@@ -91,27 +93,29 @@ public class Auto extends SubCommand {
}
int diff = allowedPlots - currentPlots;
if (diff - sizeX * sizeZ < 0) {
- if (player.hasPersistentMeta("grantedPlots")) {
- int grantedPlots = Ints.fromByteArray(player.getPersistentMeta("grantedPlots"));
- if (diff < 0 && grantedPlots < sizeX * sizeZ) {
- MainUtil.sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS);
- return false;
- } else if (diff >= 0 && grantedPlots + diff < sizeX * sizeZ) {
- MainUtil.sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS);
- return false;
- } else {
- int left = grantedPlots + diff < 0 ? 0 : diff - sizeX * sizeZ;
- if (left == 0) {
- player.removePersistentMeta("grantedPlots");
+ try (final MetaDataAccess metaDataAccess = player.accessPersistentMetaData(
+ PlayerMetaDataKeys.PERSISTENT_GRANTED_PLOTS)) {
+ if (metaDataAccess.isPresent()) {
+ int grantedPlots = metaDataAccess.get().orElse(0);
+ if (diff < 0 && grantedPlots < sizeX * sizeZ) {
+ MainUtil.sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS);
+ return false;
+ } else if (diff >= 0 && grantedPlots + diff < sizeX * sizeZ) {
+ MainUtil.sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS);
+ return false;
} else {
- player.setPersistentMeta("grantedPlots", Ints.toByteArray(left));
+ int left = grantedPlots + diff < 0 ? 0 : diff - sizeX * sizeZ;
+ if (left == 0) {
+ metaDataAccess.remove();
+ } else {
+ metaDataAccess.set(left);
+ }
+ MainUtil.sendMessage(player, Captions.REMOVED_GRANTED_PLOT, "" + (grantedPlots - left), "" + left);
}
- MainUtil.sendMessage(player, Captions.REMOVED_GRANTED_PLOT,
- "" + (grantedPlots - left), "" + left);
+ } else {
+ MainUtil.sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS);
+ return false;
}
- } else {
- MainUtil.sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS);
- return false;
}
}
return true;
@@ -146,7 +150,10 @@ public class Auto extends SubCommand {
*/
public static void autoClaimSafe(final PlotPlayer> player, final PlotArea area, PlotId start,
final String schematic) {
- player.setMeta(Auto.class.getName(), true);
+ try (final MetaDataAccess metaDataAccess =
+ player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_AUTO)) {
+ metaDataAccess.set(true);
+ }
autoClaimFromDatabase(player, area, start, new RunnableVal() {
@Override public void run(final Plot plot) {
try {
@@ -175,9 +182,11 @@ public class Auto extends SubCommand {
@Override public boolean onCommand(final PlotPlayer> player, String[] args) {
PlotArea plotarea = player.getApplicablePlotArea();
if (plotarea == null) {
- if (this.econHandler != null) {
- for (PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
- if (this.econHandler.hasPermission(area.getWorldName(), player.getName(), "plots.auto")) {
+ final PermissionHandler permissionHandler = PlotSquared.platform().getPermissionHandler();
+ if (permissionHandler.hasCapability(
+ PermissionHandler.PermissionHandlerCapability.PER_WORLD_PERMISSIONS)) {
+ for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
+ if (player.hasPermission(area.getWorldName(), "plots.auto")) {
if (plotarea != null) {
plotarea = null;
break;
@@ -250,9 +259,12 @@ public class Auto extends SubCommand {
return false;
}
final int allowed_plots = player.getAllowedPlots();
- if (!force && (player.getMeta(Auto.class.getName(), false) || !checkAllowedPlots(player,
- plotarea, allowed_plots, size_x, size_z))) {
- return false;
+ try (final MetaDataAccess metaDataAccess =
+ player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_AUTO)) {
+ if (!force && (metaDataAccess.get().orElse(false) || !checkAllowedPlots(player,
+ plotarea, allowed_plots, size_x, size_z))) {
+ return false;
+ }
}
if (schematic != null && !schematic.isEmpty()) {
diff --git a/Core/src/main/java/com/plotsquared/core/command/Buy.java b/Core/src/main/java/com/plotsquared/core/command/Buy.java
index 88f4dd4af..8fe688834 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Buy.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Buy.java
@@ -93,7 +93,7 @@ public class Buy extends Command {
this.econHandler.depositMoney(PlotSquared.platform().getPlayerManager().getOfflinePlayer(plot.getOwnerAbs()), price);
- PlotPlayer owner = PlotSquared.platform().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs());
+ PlotPlayer> owner = PlotSquared.platform().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs());
if (owner != null) {
Captions.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price);
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Claim.java b/Core/src/main/java/com/plotsquared/core/command/Claim.java
index bb3ae02c3..d2285e7ba 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Claim.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Claim.java
@@ -25,7 +25,6 @@
*/
package com.plotsquared.core.command;
-import com.google.common.primitives.Ints;
import com.google.inject.Inject;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
@@ -36,6 +35,8 @@ import com.plotsquared.core.events.PlotMergeEvent;
import com.plotsquared.core.events.Result;
import com.plotsquared.core.location.Direction;
import com.plotsquared.core.location.Location;
+import com.plotsquared.core.player.MetaDataAccess;
+import com.plotsquared.core.player.PlayerMetaDataKeys;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
@@ -85,54 +86,57 @@ public class Claim extends SubCommand {
int currentPlots = Settings.Limit.GLOBAL ?
player.getPlotCount() :
player.getPlotCount(location.getWorldName());
- int grants = 0;
- if (currentPlots >= player.getAllowedPlots() && !force) {
- if (player.hasPersistentMeta("grantedPlots")) {
- grants = Ints.fromByteArray(player.getPersistentMeta("grantedPlots"));
- if (grants <= 0) {
- player.removePersistentMeta("grantedPlots");
+
+ final PlotArea area = plot.getArea();
+
+ try (final MetaDataAccess metaDataAccess = player.accessPersistentMetaData(PlayerMetaDataKeys.PERSISTENT_GRANTED_PLOTS)) {
+ int grants = 0;
+ if (currentPlots >= player.getAllowedPlots() && !force) {
+ if (metaDataAccess.isPresent()) {
+ grants = metaDataAccess.get().orElse(0);
+ if (grants <= 0) {
+ metaDataAccess.remove();
+ return sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS);
+ }
+ } else {
return sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS);
}
- } else {
- return sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS);
}
- }
- if (!plot.canClaim(player)) {
- return sendMessage(player, Captions.PLOT_IS_CLAIMED);
- }
- final PlotArea area = plot.getArea();
- if (schematic != null && !schematic.isEmpty()) {
- if (area.isSchematicClaimSpecify()) {
- if (!area.hasSchematic(schematic)) {
- return sendMessage(player, Captions.SCHEMATIC_INVALID,
- "non-existent: " + schematic);
- }
- if (!Permissions.hasPermission(player, CaptionUtility
- .format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic))
- && !Permissions
- .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_SCHEMATIC) && !force) {
- return sendMessage(player, Captions.NO_SCHEMATIC_PERMISSION, schematic);
+
+ if (!plot.canClaim(player)) {
+ return sendMessage(player, Captions.PLOT_IS_CLAIMED);
+ }
+ if (schematic != null && !schematic.isEmpty()) {
+ if (area.isSchematicClaimSpecify()) {
+ if (!area.hasSchematic(schematic)) {
+ return sendMessage(player, Captions.SCHEMATIC_INVALID, "non-existent: " + schematic);
+ }
+ if (!Permissions.hasPermission(player, CaptionUtility.format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(),
+ schematic)) && !Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_SCHEMATIC)
+ && !force) {
+ return sendMessage(player, Captions.NO_SCHEMATIC_PERMISSION, schematic);
+ }
}
}
- }
- if ((this.econHandler != null) && area.useEconomy() && !force) {
- Expression costExr = area.getPrices().get("claim");
- double cost = costExr.evaluate((double) currentPlots);
- if (cost > 0d) {
- if (this.econHandler.getMoney(player) < cost) {
- return sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost);
+ if ((this.econHandler != null) && area.useEconomy() && !force) {
+ Expression costExr = area.getPrices().get("claim");
+ double cost = costExr.evaluate((double) currentPlots);
+ if (cost > 0d) {
+ if (this.econHandler.getMoney(player) < cost) {
+ return sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost);
+ }
+ this.econHandler.withdrawMoney(player, cost);
+ sendMessage(player, Captions.REMOVED_BALANCE, cost + "");
}
- this.econHandler.withdrawMoney(player, cost);
- sendMessage(player, Captions.REMOVED_BALANCE, cost + "");
}
- }
- if (grants > 0) {
- if (grants == 1) {
- player.removePersistentMeta("grantedPlots");
- } else {
- player.setPersistentMeta("grantedPlots", Ints.toByteArray(grants - 1));
+ if (grants > 0) {
+ if (grants == 1) {
+ metaDataAccess.remove();
+ } else {
+ metaDataAccess.set(grants - 1);
+ }
+ sendMessage(player, Captions.REMOVED_GRANTED_PLOT, "1", (grants - 1));
}
- sendMessage(player, Captions.REMOVED_GRANTED_PLOT, "1", (grants - 1));
}
int border = area.getBorder();
if (border != Integer.MAX_VALUE && plot.getDistanceFromOrigin() > border && !force) {
diff --git a/Core/src/main/java/com/plotsquared/core/command/CmdConfirm.java b/Core/src/main/java/com/plotsquared/core/command/CmdConfirm.java
index c8aee497c..412cff610 100644
--- a/Core/src/main/java/com/plotsquared/core/command/CmdConfirm.java
+++ b/Core/src/main/java/com/plotsquared/core/command/CmdConfirm.java
@@ -26,19 +26,29 @@
package com.plotsquared.core.command;
import com.plotsquared.core.configuration.Captions;
+import com.plotsquared.core.player.MetaDataAccess;
+import com.plotsquared.core.player.PlayerMetaDataKeys;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.task.TaskTime;
+import javax.annotation.Nullable;
+
public class CmdConfirm {
- public static CmdInstance getPending(PlotPlayer> player) {
- return player.getMeta("cmdConfirm");
+ @Nullable public static CmdInstance getPending(PlotPlayer> player) {
+ try (final MetaDataAccess metaDataAccess = player.accessTemporaryMetaData(
+ PlayerMetaDataKeys.TEMPORARY_CONFIRM)) {
+ return metaDataAccess.get().orElse(null);
+ }
}
public static void removePending(PlotPlayer> player) {
- player.deleteMeta("cmdConfirm");
+ try (final MetaDataAccess metaDataAccess = player.accessTemporaryMetaData(
+ PlayerMetaDataKeys.TEMPORARY_CONFIRM)) {
+ metaDataAccess.remove();
+ }
}
public static void addPending(final PlotPlayer> player, String commandStr,
@@ -49,7 +59,10 @@ public class CmdConfirm {
}
TaskManager.runTaskLater(() -> {
CmdInstance cmd = new CmdInstance(runnable);
- player.setMeta("cmdConfirm", cmd);
+ try (final MetaDataAccess metaDataAccess = player.accessTemporaryMetaData(
+ PlayerMetaDataKeys.TEMPORARY_CONFIRM)) {
+ metaDataAccess.set(cmd);
+ }
}, TaskTime.ticks(1L));
}
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Command.java b/Core/src/main/java/com/plotsquared/core/command/Command.java
index a0dbe9079..60512dd5a 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Command.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Command.java
@@ -35,6 +35,7 @@ import com.plotsquared.core.util.StringComparison;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
+import com.plotsquared.core.permissions.PermissionHolder;
import lombok.SneakyThrows;
import javax.annotation.Nonnull;
@@ -158,7 +159,7 @@ public abstract class Command {
return this.allCommands;
}
- public boolean hasConfirmation(CommandCaller player) {
+ public boolean hasConfirmation(PermissionHolder player) {
return this.confirmation && !player.hasPermission(getPermission() + ".confirm.bypass");
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/CommandCaller.java b/Core/src/main/java/com/plotsquared/core/command/CommandCaller.java
index b26eed517..f7a6c6885 100644
--- a/Core/src/main/java/com/plotsquared/core/command/CommandCaller.java
+++ b/Core/src/main/java/com/plotsquared/core/command/CommandCaller.java
@@ -34,14 +34,6 @@ public interface CommandCaller {
*/
void sendMessage(String message);
- /**
- * Check the player's permissions. Will be cached if permission caching is enabled.
- *
- * @param permission the name of the permission
- */
- boolean hasPermission(String permission);
-
- boolean isPermissionSet(String permission);
-
RequiredType getSuperCaller();
+
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java
index 598baf510..bc39a8f3e 100644
--- a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java
+++ b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java
@@ -409,46 +409,6 @@ public class DebugExec extends SubCommand {
}
}, "/plot debugexec list-scripts", "List of scripts");
return true;
- case "allcmd":
- if (args.length < 3) {
- Captions.COMMAND_SYNTAX
- .send(player, "/plot debugexec allcmd ");
- return false;
- }
- long start = System.currentTimeMillis();
- Command cmd = MainCommand.getInstance().getCommand(args[3]);
- String[] params = Arrays.copyOfRange(args, 4, args.length);
- if ("true".equals(args[1])) {
- Location location = player.getMeta(PlotPlayer.META_LOCATION);
- Plot plot = player.getMeta(PlotPlayer.META_LAST_PLOT);
- for (Plot current : PlotSquared.get().getBasePlots()) {
- player.setMeta(PlotPlayer.META_LOCATION, current.getBottomAbs());
- player.setMeta(PlotPlayer.META_LAST_PLOT, current);
- cmd.execute(player, params, null, null);
- }
- if (location == null) {
- player.deleteMeta(PlotPlayer.META_LOCATION);
- } else {
- player.setMeta(PlotPlayer.META_LOCATION, location);
- }
- if (plot == null) {
- player.deleteMeta(PlotPlayer.META_LAST_PLOT);
- } else {
- player.setMeta(PlotPlayer.META_LAST_PLOT, plot);
- }
- player.sendMessage("&c> " + (System.currentTimeMillis() - start));
- return true;
- }
- init();
- this.scope.put("_2", params);
- this.scope.put("_3", cmd);
- script =
- "_1=PS.getBasePlots().iterator();while(_1.hasNext()){plot=_1.next();if("
- + args[1]
- + "){PlotPlayer.setMeta(\"location\",plot.getBottomAbs());PlotPlayer.setMeta(\"lastplot\",plot);_3.onCommand"
- + "(PlotPlayer,_2)}}";
-
- break;
case "all":
if (args.length < 3) {
Captions.COMMAND_SYNTAX
diff --git a/Core/src/main/java/com/plotsquared/core/command/Grant.java b/Core/src/main/java/com/plotsquared/core/command/Grant.java
index ab1ef00d4..a45905522 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Grant.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Grant.java
@@ -30,6 +30,8 @@ import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.database.DBFunc;
+import com.plotsquared.core.player.MetaDataAccess;
+import com.plotsquared.core.player.PlayerMetaDataKeys;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
@@ -42,7 +44,6 @@ import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;
-import java.util.function.Consumer;
@CommandDeclaration(command = "grant",
category = CommandCategory.CLAIMING,
@@ -80,41 +81,40 @@ public class Grant extends Command {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER);
} else {
final UUID uuid = uuids.toArray(new UUID[0])[0];
- final Consumer result = array -> {
- if (arg0.equals("check")) { // check
- int granted;
- if (array == null) {
- granted = 0;
- } else {
- granted = Ints.fromByteArray(array);
- }
- Captions.GRANTED_PLOTS.send(player, granted);
- } else { // add
- int amount;
- if (array == null) {
- amount = 1;
- } else {
- amount = 1 + Ints.fromByteArray(array);
- }
- boolean replace = array != null;
- String key = "grantedPlots";
- byte[] rawData = Ints.toByteArray(amount);
-
- PlotPlayer online = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid);
- if (online != null) {
- online.setPersistentMeta(key, rawData);
- } else {
- DBFunc.addPersistentMeta(uuid, key, rawData, replace);
- }
- }
- };
PlotPlayer> pp = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid);
if (pp != null) {
- result.accept(player.getPersistentMeta("grantedPlots"));
+ try (final MetaDataAccess access = pp.accessPersistentMetaData(
+ PlayerMetaDataKeys.PERSISTENT_GRANTED_PLOTS)) {
+ if (args[0].equalsIgnoreCase("check")) {
+ Captions.GRANTED_PLOTS.send(player, access.get().orElse(0));
+ } else {
+ access.set(access.get().orElse(0) + 1);
+ }
+ }
} else {
DBFunc.getPersistentMeta(uuid, new RunnableVal