mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Switch from Class<T> to TypeLiteral, and implement managed meta access for temporary meta
This commit is contained in:
parent
6a63e5bb51
commit
d2f40612f4
@ -38,6 +38,8 @@ import com.plotsquared.core.database.DBFunc;
|
|||||||
import com.plotsquared.core.listener.PlayerBlockEventType;
|
import com.plotsquared.core.listener.PlayerBlockEventType;
|
||||||
import com.plotsquared.core.listener.PlotListener;
|
import com.plotsquared.core.listener.PlotListener;
|
||||||
import com.plotsquared.core.location.Location;
|
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.player.PlotPlayer;
|
||||||
import com.plotsquared.core.plot.Plot;
|
import com.plotsquared.core.plot.Plot;
|
||||||
import com.plotsquared.core.plot.PlotArea;
|
import com.plotsquared.core.plot.PlotArea;
|
||||||
@ -216,13 +218,14 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import org.bukkit.projectiles.BlockProjectileSource;
|
import org.bukkit.projectiles.BlockProjectileSource;
|
||||||
import org.bukkit.projectiles.ProjectileSource;
|
import org.bukkit.projectiles.ProjectileSource;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
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;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -731,7 +734,9 @@ import java.util.regex.Pattern;
|
|||||||
public void onTeleport(PlayerTeleportEvent event) {
|
public void onTeleport(PlayerTeleportEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||||
Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT);
|
try (final MetaDataAccess<Plot> lastPlotAccess =
|
||||||
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
|
Plot lastPlot = lastPlotAccess.get().orElse(null);
|
||||||
org.bukkit.Location to = event.getTo();
|
org.bukkit.Location to = event.getTo();
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
if (to != null) {
|
if (to != null) {
|
||||||
@ -740,9 +745,12 @@ import java.util.regex.Pattern;
|
|||||||
if (area == null) {
|
if (area == null) {
|
||||||
if (lastPlot != null) {
|
if (lastPlot != null) {
|
||||||
plotExit(pp, lastPlot);
|
plotExit(pp, lastPlot);
|
||||||
pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
|
lastPlotAccess.remove();
|
||||||
|
}
|
||||||
|
try (final MetaDataAccess<Location> lastLocationAccess =
|
||||||
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
||||||
|
lastLocationAccess.remove();
|
||||||
}
|
}
|
||||||
pp.deleteMeta(PlotPlayer.META_LOCATION);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Plot plot = area.getPlot(location);
|
Plot plot = area.getPlot(location);
|
||||||
@ -752,14 +760,13 @@ import java.util.regex.Pattern;
|
|||||||
// 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()
|
if (!result && !(plot.getFlag(UntrustedVisitFlag.class) && plot.getHomeSynchronous().equals(BukkitUtil.adaptComplete(to)))) {
|
||||||
.equals(BukkitUtil.adaptComplete(to)))) {
|
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_ENTRY_DENIED);
|
||||||
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
|
|
||||||
Captions.PERMISSION_ADMIN_ENTRY_DENIED);
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
playerMove(event);
|
playerMove(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -847,19 +854,29 @@ import java.util.regex.Pattern;
|
|||||||
}
|
}
|
||||||
// Set last location
|
// Set last location
|
||||||
Location location = BukkitUtil.adapt(to);
|
Location location = BukkitUtil.adapt(to);
|
||||||
pp.setMeta(PlotPlayer.META_LOCATION, location);
|
try (final MetaDataAccess<Location> lastLocationAccess =
|
||||||
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
||||||
|
lastLocationAccess.remove();
|
||||||
|
}
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
if (area == null) {
|
if (area == null) {
|
||||||
pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
|
try (final MetaDataAccess<Plot> lastPlotAccess =
|
||||||
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
|
lastPlotAccess.remove();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Plot now = area.getPlot(location);
|
Plot now = area.getPlot(location);
|
||||||
Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT);
|
Plot lastPlot;
|
||||||
|
try (final MetaDataAccess<Plot> lastPlotAccess =
|
||||||
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
|
lastPlot = lastPlotAccess.get().orElse(null);
|
||||||
|
}
|
||||||
if (now == null) {
|
if (now == null) {
|
||||||
if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !pp
|
try (final MetaDataAccess<Boolean> kickAccess =
|
||||||
.getMeta("kick", false)) {
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
|
||||||
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
|
if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !kickAccess.get().orElse(false)) {
|
||||||
Captions.PERMISSION_ADMIN_EXIT_DENIED);
|
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_EXIT_DENIED);
|
||||||
this.tmpTeleport = false;
|
this.tmpTeleport = false;
|
||||||
if (lastPlot.equals(BukkitUtil.adapt(from).getPlot())) {
|
if (lastPlot.equals(BukkitUtil.adapt(from).getPlot())) {
|
||||||
player.teleport(from);
|
player.teleport(from);
|
||||||
@ -870,6 +887,7 @@ import java.util.regex.Pattern;
|
|||||||
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) {
|
||||||
@ -909,19 +927,29 @@ import java.util.regex.Pattern;
|
|||||||
}
|
}
|
||||||
// Set last location
|
// Set last location
|
||||||
Location location = BukkitUtil.adapt(to);
|
Location location = BukkitUtil.adapt(to);
|
||||||
pp.setMeta(PlotPlayer.META_LOCATION, location);
|
try (final MetaDataAccess<Location> lastLocationAccess =
|
||||||
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
||||||
|
lastLocationAccess.set(location);
|
||||||
|
}
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
if (area == null) {
|
if (area == null) {
|
||||||
pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
|
try (final MetaDataAccess<Plot> lastPlotAccess =
|
||||||
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
|
lastPlotAccess.remove();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Plot now = area.getPlot(location);
|
Plot now = area.getPlot(location);
|
||||||
Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT);
|
Plot lastPlot;
|
||||||
|
try (final MetaDataAccess<Plot> lastPlotAccess =
|
||||||
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
|
lastPlot = lastPlotAccess.get().orElse(null);
|
||||||
|
}
|
||||||
if (now == null) {
|
if (now == null) {
|
||||||
if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !pp
|
try (final MetaDataAccess<Boolean> kickAccess =
|
||||||
.getMeta("kick", false)) {
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
|
||||||
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
|
if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !kickAccess.get().orElse(false)) {
|
||||||
Captions.PERMISSION_ADMIN_EXIT_DENIED);
|
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_EXIT_DENIED);
|
||||||
this.tmpTeleport = false;
|
this.tmpTeleport = false;
|
||||||
if (lastPlot.equals(BukkitUtil.adapt(from).getPlot())) {
|
if (lastPlot.equals(BukkitUtil.adapt(from).getPlot())) {
|
||||||
player.teleport(from);
|
player.teleport(from);
|
||||||
@ -932,6 +960,7 @@ import java.util.regex.Pattern;
|
|||||||
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) {
|
||||||
@ -1155,8 +1184,15 @@ import java.util.regex.Pattern;
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||||
// Delete last location
|
// Delete last location
|
||||||
Plot plot = (Plot) pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
|
Plot plot;
|
||||||
pp.deleteMeta(PlotPlayer.META_LOCATION);
|
try (final MetaDataAccess<Plot> lastPlotAccess =
|
||||||
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
|
plot = lastPlotAccess.remove();
|
||||||
|
}
|
||||||
|
try (final MetaDataAccess<Location> lastLocationAccess =
|
||||||
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
||||||
|
lastLocationAccess.remove();
|
||||||
|
}
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
plotExit(pp, plot);
|
plotExit(pp, plot);
|
||||||
}
|
}
|
||||||
@ -1168,7 +1204,10 @@ import java.util.regex.Pattern;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Settings.Enabled_Components.PERMISSION_CACHE) {
|
if (Settings.Enabled_Components.PERMISSION_CACHE) {
|
||||||
pp.deleteMeta("perm");
|
try (final MetaDataAccess<Map<String, Boolean>> metaDataAccess =
|
||||||
|
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_PERMISSIONS)) {
|
||||||
|
metaDataAccess.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Location location = pp.getLocation();
|
Location location = pp.getLocation();
|
||||||
PlotArea area = location.getPlotArea();
|
PlotArea area = location.getPlotArea();
|
||||||
|
@ -69,12 +69,12 @@ import static com.sk89q.worldedit.world.gamemode.GameModes.SURVIVAL;
|
|||||||
public class BukkitPlayer extends PlotPlayer<Player> {
|
public class BukkitPlayer extends PlotPlayer<Player> {
|
||||||
|
|
||||||
private static boolean CHECK_EFFECTIVE = true;
|
private static boolean CHECK_EFFECTIVE = true;
|
||||||
|
|
||||||
private final EconHandler econHandler;
|
|
||||||
public final Player player;
|
public final Player player;
|
||||||
|
private final EconHandler econHandler;
|
||||||
private boolean offline;
|
private boolean offline;
|
||||||
private String name;
|
private String name;
|
||||||
|
private String lastMessage = "";
|
||||||
|
private long lastMessageTime = 0L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Please do not use this method. Instead use
|
* <p>Please do not use this method. Instead use
|
||||||
@ -234,10 +234,10 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
|
|
||||||
@Override public void sendMessage(String message) {
|
@Override public void sendMessage(String message) {
|
||||||
message = message.replace('\u2010', '%').replace('\u2020', '&').replace('\u2030', '&');
|
message = message.replace('\u2010', '%').replace('\u2020', '&').replace('\u2030', '&');
|
||||||
if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || (
|
if (!StringMan.isEqual(this.lastMessage, message) || (
|
||||||
System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {
|
System.currentTimeMillis() - this.lastMessageTime > 5000)) {
|
||||||
setMeta("lastMessage", message);
|
this.lastMessage = message;
|
||||||
setMeta("lastMessageTime", System.currentTimeMillis());
|
this.lastMessageTime = System.currentTimeMillis();
|
||||||
this.player.sendMessage(message);
|
this.player.sendMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,6 @@ package com.plotsquared.core.command;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.plotsquared.core.PlotSquared;
|
import com.plotsquared.core.PlotSquared;
|
||||||
import com.plotsquared.core.inject.annotations.WorldConfig;
|
|
||||||
import com.plotsquared.core.inject.annotations.WorldFile;
|
|
||||||
import com.plotsquared.core.configuration.Captions;
|
import com.plotsquared.core.configuration.Captions;
|
||||||
import com.plotsquared.core.configuration.ConfigurationSection;
|
import com.plotsquared.core.configuration.ConfigurationSection;
|
||||||
import com.plotsquared.core.configuration.ConfigurationUtil;
|
import com.plotsquared.core.configuration.ConfigurationUtil;
|
||||||
@ -36,6 +34,8 @@ import com.plotsquared.core.configuration.file.YamlConfiguration;
|
|||||||
import com.plotsquared.core.events.TeleportCause;
|
import com.plotsquared.core.events.TeleportCause;
|
||||||
import com.plotsquared.core.generator.AugmentedUtils;
|
import com.plotsquared.core.generator.AugmentedUtils;
|
||||||
import com.plotsquared.core.generator.HybridPlotWorld;
|
import com.plotsquared.core.generator.HybridPlotWorld;
|
||||||
|
import com.plotsquared.core.inject.annotations.WorldConfig;
|
||||||
|
import com.plotsquared.core.inject.annotations.WorldFile;
|
||||||
import com.plotsquared.core.inject.factory.HybridPlotWorldFactory;
|
import com.plotsquared.core.inject.factory.HybridPlotWorldFactory;
|
||||||
import com.plotsquared.core.location.Location;
|
import com.plotsquared.core.location.Location;
|
||||||
import com.plotsquared.core.player.ConsolePlayer;
|
import com.plotsquared.core.player.ConsolePlayer;
|
||||||
@ -72,16 +72,19 @@ import com.sk89q.worldedit.math.BlockVector2;
|
|||||||
import com.sk89q.worldedit.math.BlockVector3;
|
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 javax.annotation.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;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@CommandDeclaration(command = "area",
|
@CommandDeclaration(command = "area",
|
||||||
permission = "plots.area",
|
permission = "plots.area",
|
||||||
@ -101,6 +104,8 @@ public class Area extends SubCommand {
|
|||||||
private final WorldUtil worldUtil;
|
private final WorldUtil worldUtil;
|
||||||
private final RegionManager regionManager;
|
private final RegionManager regionManager;
|
||||||
|
|
||||||
|
private final Map<UUID, Map<String, Object>> metaData = new HashMap<>();
|
||||||
|
|
||||||
@Inject public Area(@Nonnull final PlotAreaManager plotAreaManager,
|
@Inject public Area(@Nonnull final PlotAreaManager plotAreaManager,
|
||||||
@WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
|
@WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
|
||||||
@WorldFile @Nonnull final File worldFile,
|
@WorldFile @Nonnull final File worldFile,
|
||||||
@ -264,14 +269,16 @@ public class Area extends SubCommand {
|
|||||||
case 2:
|
case 2:
|
||||||
switch (args[1].toLowerCase()) {
|
switch (args[1].toLowerCase()) {
|
||||||
case "pos1": { // Set position 1
|
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) {
|
if (area == null) {
|
||||||
Captions.COMMAND_SYNTAX.send(player,
|
Captions.COMMAND_SYNTAX.send(player,
|
||||||
"/plot area create [world[:id]] [<modifier>=<value>]...");
|
"/plot area create [world[:id]] [<modifier>=<value>]...");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Location location = player.getLocation();
|
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",
|
Captions.SET_ATTRIBUTE.send(player, "area_pos1",
|
||||||
location.getX() + "," + location.getZ());
|
location.getX() + "," + location.getZ());
|
||||||
MainUtil.sendMessage(player,
|
MainUtil.sendMessage(player,
|
||||||
@ -280,14 +287,15 @@ public class Area extends SubCommand {
|
|||||||
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 = player.getMeta("area_create_area");
|
final HybridPlotWorld area = (HybridPlotWorld) metaData
|
||||||
|
.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).get("area_create_area");
|
||||||
if (area == null) {
|
if (area == null) {
|
||||||
Captions.COMMAND_SYNTAX.send(player,
|
Captions.COMMAND_SYNTAX.send(player,
|
||||||
"/plot area create [world[:id]] [<modifier>=<value>]...");
|
"/plot area create [world[:id]] [<modifier>=<value>]...");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Location pos1 = player.getLocation();
|
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 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,
|
int numX = Math.max(1,
|
||||||
@ -500,7 +508,7 @@ public class Area extends SubCommand {
|
|||||||
player.teleport(this.worldUtil.getSpawn(pa.getWorldName()),
|
player.teleport(this.worldUtil.getSpawn(pa.getWorldName()),
|
||||||
TeleportCause.COMMAND);
|
TeleportCause.COMMAND);
|
||||||
}
|
}
|
||||||
player.setMeta("area_create_area", pa);
|
metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).put("area_create_area", pa);
|
||||||
MainUtil.sendMessage(player,
|
MainUtil.sendMessage(player,
|
||||||
"$1Go to the first corner and use: $2 " + getCommandString()
|
"$1Go to the first corner and use: $2 " + getCommandString()
|
||||||
+ " create pos1");
|
+ " create pos1");
|
||||||
|
@ -93,7 +93,7 @@ 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.GRANTED_PLOTS)) {
|
PlayerMetaDataKeys.PERSISTENT_GRANTED_PLOTS)) {
|
||||||
if (metaDataAccess.has()) {
|
if (metaDataAccess.has()) {
|
||||||
int grantedPlots = metaDataAccess.get().orElse(0);
|
int grantedPlots = metaDataAccess.get().orElse(0);
|
||||||
if (diff < 0 && grantedPlots < sizeX * sizeZ) {
|
if (diff < 0 && grantedPlots < sizeX * sizeZ) {
|
||||||
@ -149,7 +149,10 @@ public class Auto extends SubCommand {
|
|||||||
*/
|
*/
|
||||||
public static void autoClaimSafe(final PlotPlayer<?> player, final PlotArea area, PlotId start,
|
public static void autoClaimSafe(final PlotPlayer<?> player, final PlotArea area, PlotId start,
|
||||||
final String schematic) {
|
final String schematic) {
|
||||||
player.setMeta(Auto.class.getName(), true);
|
try (final MetaDataAccess<Boolean> metaDataAccess =
|
||||||
|
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_AUTO)) {
|
||||||
|
metaDataAccess.set(true);
|
||||||
|
}
|
||||||
autoClaimFromDatabase(player, area, start, new RunnableVal<Plot>() {
|
autoClaimFromDatabase(player, area, start, new RunnableVal<Plot>() {
|
||||||
@Override public void run(final Plot plot) {
|
@Override public void run(final Plot plot) {
|
||||||
try {
|
try {
|
||||||
@ -253,10 +256,13 @@ public class Auto extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final int allowed_plots = player.getAllowedPlots();
|
final int allowed_plots = player.getAllowedPlots();
|
||||||
if (!force && (player.getMeta(Auto.class.getName(), false) || !checkAllowedPlots(player,
|
try (final MetaDataAccess<Boolean> metaDataAccess =
|
||||||
|
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_AUTO)) {
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (schematic != null && !schematic.isEmpty()) {
|
if (schematic != null && !schematic.isEmpty()) {
|
||||||
if (!plotarea.hasSchematic(schematic)) {
|
if (!plotarea.hasSchematic(schematic)) {
|
||||||
|
@ -89,7 +89,7 @@ public class Claim extends SubCommand {
|
|||||||
|
|
||||||
final PlotArea area = plot.getArea();
|
final PlotArea area = plot.getArea();
|
||||||
|
|
||||||
try (final MetaDataAccess<Integer> metaDataAccess = player.accessPersistentMetaData(PlayerMetaDataKeys.GRANTED_PLOTS)) {
|
try (final MetaDataAccess<Integer> metaDataAccess = player.accessPersistentMetaData(PlayerMetaDataKeys.PERSISTENT_GRANTED_PLOTS)) {
|
||||||
int grants = 0;
|
int grants = 0;
|
||||||
if (currentPlots >= player.getAllowedPlots() && !force) {
|
if (currentPlots >= player.getAllowedPlots() && !force) {
|
||||||
if (metaDataAccess.has()) {
|
if (metaDataAccess.has()) {
|
||||||
|
@ -26,19 +26,29 @@
|
|||||||
package com.plotsquared.core.command;
|
package com.plotsquared.core.command;
|
||||||
|
|
||||||
import com.plotsquared.core.configuration.Captions;
|
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.player.PlotPlayer;
|
||||||
import com.plotsquared.core.util.MainUtil;
|
import com.plotsquared.core.util.MainUtil;
|
||||||
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 javax.annotation.Nullable;
|
||||||
|
|
||||||
public class CmdConfirm {
|
public class CmdConfirm {
|
||||||
|
|
||||||
public static CmdInstance getPending(PlotPlayer<?> player) {
|
@Nullable public static CmdInstance getPending(PlotPlayer<?> player) {
|
||||||
return player.getMeta("cmdConfirm");
|
try (final MetaDataAccess<CmdInstance> metaDataAccess = player.accessTemporaryMetaData(
|
||||||
|
PlayerMetaDataKeys.TEMPORARY_CONFIRM)) {
|
||||||
|
return metaDataAccess.get().orElse(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removePending(PlotPlayer<?> player) {
|
public static void removePending(PlotPlayer<?> player) {
|
||||||
player.deleteMeta("cmdConfirm");
|
try (final MetaDataAccess<CmdInstance> metaDataAccess = player.accessTemporaryMetaData(
|
||||||
|
PlayerMetaDataKeys.TEMPORARY_CONFIRM)) {
|
||||||
|
metaDataAccess.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addPending(final PlotPlayer<?> player, String commandStr,
|
public static void addPending(final PlotPlayer<?> player, String commandStr,
|
||||||
@ -49,7 +59,10 @@ public class CmdConfirm {
|
|||||||
}
|
}
|
||||||
TaskManager.runTaskLater(() -> {
|
TaskManager.runTaskLater(() -> {
|
||||||
CmdInstance cmd = new CmdInstance(runnable);
|
CmdInstance cmd = new CmdInstance(runnable);
|
||||||
player.setMeta("cmdConfirm", cmd);
|
try (final MetaDataAccess<CmdInstance> metaDataAccess = player.accessTemporaryMetaData(
|
||||||
|
PlayerMetaDataKeys.TEMPORARY_CONFIRM)) {
|
||||||
|
metaDataAccess.set(cmd);
|
||||||
|
}
|
||||||
}, TaskTime.ticks(1L));
|
}, TaskTime.ticks(1L));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -409,46 +409,6 @@ public class DebugExec extends SubCommand {
|
|||||||
}
|
}
|
||||||
}, "/plot debugexec list-scripts", "List of scripts");
|
}, "/plot debugexec list-scripts", "List of scripts");
|
||||||
return true;
|
return true;
|
||||||
case "allcmd":
|
|
||||||
if (args.length < 3) {
|
|
||||||
Captions.COMMAND_SYNTAX
|
|
||||||
.send(player, "/plot debugexec allcmd <condition> <command>");
|
|
||||||
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":
|
case "all":
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
Captions.COMMAND_SYNTAX
|
Captions.COMMAND_SYNTAX
|
||||||
|
@ -84,7 +84,7 @@ public class Grant extends Command {
|
|||||||
PlotPlayer<?> pp = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid);
|
PlotPlayer<?> pp = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid);
|
||||||
if (pp != null) {
|
if (pp != null) {
|
||||||
try (final MetaDataAccess<Integer> access = pp.accessPersistentMetaData(
|
try (final MetaDataAccess<Integer> access = pp.accessPersistentMetaData(
|
||||||
PlayerMetaDataKeys.GRANTED_PLOTS)) {
|
PlayerMetaDataKeys.PERSISTENT_GRANTED_PLOTS)) {
|
||||||
if (args[0].equalsIgnoreCase("check")) {
|
if (args[0].equalsIgnoreCase("check")) {
|
||||||
Captions.GRANTED_PLOTS.send(player, access.get().orElse(0));
|
Captions.GRANTED_PLOTS.send(player, access.get().orElse(0));
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,7 +25,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.core.command;
|
package com.plotsquared.core.command;
|
||||||
|
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
import com.plotsquared.core.configuration.Captions;
|
import com.plotsquared.core.configuration.Captions;
|
||||||
|
import com.plotsquared.core.player.MetaDataAccess;
|
||||||
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.comment.CommentInbox;
|
import com.plotsquared.core.plot.comment.CommentInbox;
|
||||||
@ -34,6 +36,7 @@ import com.plotsquared.core.plot.comment.PlotComment;
|
|||||||
import com.plotsquared.core.util.MainUtil;
|
import com.plotsquared.core.util.MainUtil;
|
||||||
import com.plotsquared.core.util.StringMan;
|
import com.plotsquared.core.util.StringMan;
|
||||||
import com.plotsquared.core.util.task.RunnableVal;
|
import com.plotsquared.core.util.task.RunnableVal;
|
||||||
|
import com.plotsquared.core.player.MetaDataKey;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -140,7 +143,10 @@ public class Inbox extends SubCommand {
|
|||||||
StringMan.join(CommentManager.inboxes.keySet(), ", "));
|
StringMan.join(CommentManager.inboxes.keySet(), ", "));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
player.setMeta("inbox:" + inbox.toString(), System.currentTimeMillis());
|
final MetaDataKey<Long> metaDataKey = MetaDataKey.of(String.format("inbox:%s", inbox.toString()), new TypeLiteral<Long>() {});
|
||||||
|
try (final MetaDataAccess<Long> metaDataAccess = player.accessTemporaryMetaData(metaDataKey)) {
|
||||||
|
metaDataAccess.set(System.currentTimeMillis());
|
||||||
|
}
|
||||||
final int page;
|
final int page;
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
switch (args[1].toLowerCase()) {
|
switch (args[1].toLowerCase()) {
|
||||||
|
@ -28,6 +28,8 @@ package com.plotsquared.core.command;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.plotsquared.core.configuration.Captions;
|
import com.plotsquared.core.configuration.Captions;
|
||||||
import com.plotsquared.core.configuration.Settings;
|
import com.plotsquared.core.configuration.Settings;
|
||||||
|
import com.plotsquared.core.player.MetaDataAccess;
|
||||||
|
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
||||||
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.PlotArea;
|
import com.plotsquared.core.plot.PlotArea;
|
||||||
@ -43,6 +45,7 @@ import javax.annotation.Nonnull;
|
|||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandDeclaration(command = "load",
|
@CommandDeclaration(command = "load",
|
||||||
@ -86,9 +89,11 @@ public class Load extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try (final MetaDataAccess<List<String>> metaDataAccess =
|
||||||
|
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_SCHEMATICS)) {
|
||||||
if (args.length != 0) {
|
if (args.length != 0) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
List<String> schematics = player.getMeta("plot_schematics");
|
List<String> schematics = metaDataAccess.get().orElse(null);
|
||||||
if (schematics == null) {
|
if (schematics == null) {
|
||||||
// No schematics found:
|
// No schematics found:
|
||||||
MainUtil.sendMessage(player, Captions.LOAD_NULL);
|
MainUtil.sendMessage(player, Captions.LOAD_NULL);
|
||||||
@ -122,8 +127,8 @@ public class Load extends SubCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PlotArea area = plot.getArea();
|
PlotArea area = plot.getArea();
|
||||||
this.schematicHandler.paste(taskSchematic, plot, 0, area.getMinBuildHeight(), 0, false,
|
this.schematicHandler
|
||||||
new RunnableVal<Boolean>() {
|
.paste(taskSchematic, plot, 0, area.getMinBuildHeight(), 0, false, new RunnableVal<Boolean>() {
|
||||||
@Override public void run(Boolean value) {
|
@Override public void run(Boolean value) {
|
||||||
plot.removeRunning();
|
plot.removeRunning();
|
||||||
if (value) {
|
if (value) {
|
||||||
@ -143,7 +148,7 @@ public class Load extends SubCommand {
|
|||||||
|
|
||||||
// list schematics
|
// list schematics
|
||||||
|
|
||||||
List<String> schematics = player.getMeta("plot_schematics");
|
List<String> schematics = metaDataAccess.get().orElse(null);
|
||||||
if (schematics == null) {
|
if (schematics == null) {
|
||||||
plot.addRunning();
|
plot.addRunning();
|
||||||
TaskManager.runTaskAsync(() -> {
|
TaskManager.runTaskAsync(() -> {
|
||||||
@ -153,17 +158,20 @@ public class Load extends SubCommand {
|
|||||||
MainUtil.sendMessage(player, Captions.LOAD_FAILED);
|
MainUtil.sendMessage(player, Captions.LOAD_FAILED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
player.setMeta("plot_schematics", schematics1);
|
metaDataAccess.set(schematics1);
|
||||||
displaySaves(player);
|
displaySaves(player);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
displaySaves(player);
|
displaySaves(player);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displaySaves(PlotPlayer<?> player) {
|
public void displaySaves(PlotPlayer<?> player) {
|
||||||
List<String> schematics = player.getMeta("plot_schematics");
|
try (final MetaDataAccess<List<String>> metaDataAccess =
|
||||||
|
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_SCHEMATICS)) {
|
||||||
|
List<String> schematics = metaDataAccess.get().orElse(Collections.emptyList());
|
||||||
for (int i = 0; i < Math.min(schematics.size(), 32); i++) {
|
for (int i = 0; i < Math.min(schematics.size(), 32); i++) {
|
||||||
try {
|
try {
|
||||||
String schematic = schematics.get(i).split("\\.")[0];
|
String schematic = schematics.get(i).split("\\.")[0];
|
||||||
@ -171,8 +179,7 @@ public class Load extends SubCommand {
|
|||||||
if (split.length < 5) {
|
if (split.length < 5) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String time =
|
String time = secToTime((System.currentTimeMillis() / 1000) - Long.parseLong(split[0]));
|
||||||
secToTime((System.currentTimeMillis() / 1000) - Long.parseLong(split[0]));
|
|
||||||
String world = split[1];
|
String world = split[1];
|
||||||
PlotId id = PlotId.fromString(split[2] + ';' + split[3]);
|
PlotId id = PlotId.fromString(split[2] + ';' + split[3]);
|
||||||
String size = split[4];
|
String size = split[4];
|
||||||
@ -186,6 +193,7 @@ public class Load extends SubCommand {
|
|||||||
}
|
}
|
||||||
MainUtil.sendMessage(player, Captions.LOAD_LIST);
|
MainUtil.sendMessage(player, Captions.LOAD_LIST);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String secToTime(long time) {
|
public String secToTime(long time) {
|
||||||
StringBuilder toreturn = new StringBuilder();
|
StringBuilder toreturn = new StringBuilder();
|
||||||
|
@ -31,6 +31,8 @@ import com.plotsquared.core.configuration.Captions;
|
|||||||
import com.plotsquared.core.configuration.Settings;
|
import com.plotsquared.core.configuration.Settings;
|
||||||
import com.plotsquared.core.location.Location;
|
import com.plotsquared.core.location.Location;
|
||||||
import com.plotsquared.core.player.ConsolePlayer;
|
import com.plotsquared.core.player.ConsolePlayer;
|
||||||
|
import com.plotsquared.core.player.MetaDataAccess;
|
||||||
|
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
||||||
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.PlotArea;
|
import com.plotsquared.core.plot.PlotArea;
|
||||||
@ -43,6 +45,7 @@ import com.plotsquared.core.util.task.RunnableVal3;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -231,7 +234,11 @@ public class MainCommand extends Command {
|
|||||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||||
RunnableVal2<Command, CommandResult> whenDone) {
|
RunnableVal2<Command, CommandResult> whenDone) {
|
||||||
// Clear perm caching //
|
// Clear perm caching //
|
||||||
player.deleteMeta("perm");
|
try (final MetaDataAccess<Map<String, Boolean>> permAccess = player.accessTemporaryMetaData(
|
||||||
|
PlayerMetaDataKeys.TEMPORARY_PERMISSIONS)) {
|
||||||
|
permAccess.remove();
|
||||||
|
}
|
||||||
|
|
||||||
// Optional command scope //
|
// Optional command scope //
|
||||||
Location location = null;
|
Location location = null;
|
||||||
Plot plot = null;
|
Plot plot = null;
|
||||||
@ -246,12 +253,17 @@ public class MainCommand extends Command {
|
|||||||
Location newLoc = newPlot.getCenterSynchronous();
|
Location newLoc = newPlot.getCenterSynchronous();
|
||||||
if (player.canTeleport(newLoc)) {
|
if (player.canTeleport(newLoc)) {
|
||||||
// Save meta
|
// Save meta
|
||||||
location = player.getMeta(PlotPlayer.META_LOCATION);
|
try (final MetaDataAccess<Location> locationMetaDataAccess
|
||||||
plot = player.getMeta(PlotPlayer.META_LAST_PLOT);
|
= player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
||||||
|
location = locationMetaDataAccess.get().orElse(null);
|
||||||
|
locationMetaDataAccess.set(newLoc);
|
||||||
|
}
|
||||||
|
try (final MetaDataAccess<Plot> plotMetaDataAccess
|
||||||
|
= player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
|
plot = plotMetaDataAccess.get().orElse(null);
|
||||||
|
plotMetaDataAccess.set(newPlot);
|
||||||
|
}
|
||||||
tp = true;
|
tp = true;
|
||||||
// Set loc
|
|
||||||
player.setMeta(PlotPlayer.META_LOCATION, newLoc);
|
|
||||||
player.setMeta(PlotPlayer.META_LAST_PLOT, newPlot);
|
|
||||||
} else {
|
} else {
|
||||||
Captions.BORDER.send(player);
|
Captions.BORDER.send(player);
|
||||||
}
|
}
|
||||||
@ -304,15 +316,21 @@ public class MainCommand extends Command {
|
|||||||
}
|
}
|
||||||
// Reset command scope //
|
// Reset command scope //
|
||||||
if (tp && !(player instanceof ConsolePlayer)) {
|
if (tp && !(player instanceof ConsolePlayer)) {
|
||||||
|
try (final MetaDataAccess<Location> locationMetaDataAccess
|
||||||
|
= player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
player.deleteMeta(PlotPlayer.META_LOCATION);
|
locationMetaDataAccess.remove();
|
||||||
} else {
|
} else {
|
||||||
player.setMeta(PlotPlayer.META_LOCATION, location);
|
locationMetaDataAccess.set(location);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
try (final MetaDataAccess<Plot> plotMetaDataAccess
|
||||||
|
= player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
player.deleteMeta(PlotPlayer.META_LAST_PLOT);
|
plotMetaDataAccess.remove();
|
||||||
} else {
|
} else {
|
||||||
player.setMeta(PlotPlayer.META_LAST_PLOT, plot);
|
plotMetaDataAccess.set(plot);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(true);
|
return CompletableFuture.completedFuture(true);
|
||||||
|
@ -28,6 +28,8 @@ package com.plotsquared.core.command;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.plotsquared.core.configuration.Captions;
|
import com.plotsquared.core.configuration.Captions;
|
||||||
import com.plotsquared.core.location.Location;
|
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.player.PlotPlayer;
|
||||||
import com.plotsquared.core.plot.Plot;
|
import com.plotsquared.core.plot.Plot;
|
||||||
import com.plotsquared.core.plot.PlotId;
|
import com.plotsquared.core.plot.PlotId;
|
||||||
@ -104,9 +106,9 @@ public class Save extends SubCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(player, Captions.SAVE_SUCCESS);
|
MainUtil.sendMessage(player, Captions.SAVE_SUCCESS);
|
||||||
List<String> schematics = player.getMeta("plot_schematics");
|
try (final MetaDataAccess<List<String>> schematicAccess =
|
||||||
if (schematics != null) {
|
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_SCHEMATICS)) {
|
||||||
schematics.add(file + ".schem");
|
schematicAccess.get().ifPresent(schematics -> schematics.add(file + ".schem"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -29,6 +29,8 @@ import com.google.inject.Inject;
|
|||||||
import com.plotsquared.core.PlotSquared;
|
import com.plotsquared.core.PlotSquared;
|
||||||
import com.plotsquared.core.configuration.Captions;
|
import com.plotsquared.core.configuration.Captions;
|
||||||
import com.plotsquared.core.generator.GeneratorWrapper;
|
import com.plotsquared.core.generator.GeneratorWrapper;
|
||||||
|
import com.plotsquared.core.player.MetaDataAccess;
|
||||||
|
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import com.plotsquared.core.setup.SetupProcess;
|
import com.plotsquared.core.setup.SetupProcess;
|
||||||
import com.plotsquared.core.setup.SetupStep;
|
import com.plotsquared.core.setup.SetupStep;
|
||||||
@ -72,14 +74,16 @@ public class Setup extends SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||||
SetupProcess process = player.getMeta("setup");
|
try (final MetaDataAccess<SetupProcess> metaDataAccess =
|
||||||
|
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_SETUP)) {
|
||||||
|
SetupProcess process = metaDataAccess.get().orElse(null);
|
||||||
if (process == null) {
|
if (process == null) {
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
MainUtil.sendMessage(player, Captions.SETUP_NOT_STARTED);
|
MainUtil.sendMessage(player, Captions.SETUP_NOT_STARTED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
process = new SetupProcess();
|
process = new SetupProcess();
|
||||||
player.setMeta("setup", process);
|
metaDataAccess.set(process);
|
||||||
this.setupUtils.updateGenerators();
|
this.setupUtils.updateGenerators();
|
||||||
SetupStep step = process.getCurrentStep();
|
SetupStep step = process.getCurrentStep();
|
||||||
step.announce(player);
|
step.announce(player);
|
||||||
@ -91,7 +95,7 @@ public class Setup extends SubCommand {
|
|||||||
process.back();
|
process.back();
|
||||||
process.getCurrentStep().announce(player);
|
process.getCurrentStep().announce(player);
|
||||||
} else if ("cancel".equalsIgnoreCase(args[0])) {
|
} else if ("cancel".equalsIgnoreCase(args[0])) {
|
||||||
player.deleteMeta("setup");
|
metaDataAccess.remove();
|
||||||
MainUtil.sendMessage(player, Captions.SETUP_CANCELLED);
|
MainUtil.sendMessage(player, Captions.SETUP_CANCELLED);
|
||||||
} else {
|
} else {
|
||||||
process.handleInput(player, args[0]);
|
process.handleInput(player, args[0]);
|
||||||
@ -103,11 +107,15 @@ public class Setup extends SubCommand {
|
|||||||
process.getCurrentStep().announce(player);
|
process.getCurrentStep().announce(player);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
|
@Override public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
|
||||||
SetupProcess process = (SetupProcess) player.getMeta("setup"); // TODO use generics -> auto cast
|
SetupProcess process;
|
||||||
|
try (final MetaDataAccess<SetupProcess> metaDataAccess =
|
||||||
|
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_SETUP)) {
|
||||||
|
process = metaDataAccess.get().orElse(null);
|
||||||
|
}
|
||||||
if (process == null) {
|
if (process == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import com.plotsquared.core.events.PlotFlagRemoveEvent;
|
|||||||
import com.plotsquared.core.events.Result;
|
import com.plotsquared.core.events.Result;
|
||||||
import com.plotsquared.core.location.Location;
|
import com.plotsquared.core.location.Location;
|
||||||
import com.plotsquared.core.player.MetaDataAccess;
|
import com.plotsquared.core.player.MetaDataAccess;
|
||||||
|
import com.plotsquared.core.player.MetaDataKey;
|
||||||
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import com.plotsquared.core.plot.Plot;
|
import com.plotsquared.core.plot.Plot;
|
||||||
@ -136,14 +137,16 @@ public class PlotListener {
|
|||||||
.hasPermission(player, "plots.admin.entry.denied")) {
|
.hasPermission(player, "plots.admin.entry.denied")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Plot last = player.getMeta(PlotPlayer.META_LAST_PLOT);
|
try (final MetaDataAccess<Plot> lastPlot = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
|
Plot last = lastPlot.get().orElse(null);
|
||||||
if ((last != null) && !last.getId().equals(plot.getId())) {
|
if ((last != null) && !last.getId().equals(plot.getId())) {
|
||||||
plotExit(player, last);
|
plotExit(player, last);
|
||||||
}
|
}
|
||||||
if (ExpireManager.IMP != null) {
|
if (ExpireManager.IMP != null) {
|
||||||
ExpireManager.IMP.handleEntry(player, plot);
|
ExpireManager.IMP.handleEntry(player, plot);
|
||||||
}
|
}
|
||||||
player.setMeta(PlotPlayer.META_LAST_PLOT, plot);
|
lastPlot.set(plot);
|
||||||
|
}
|
||||||
this.eventDispatcher.callEntry(player, plot);
|
this.eventDispatcher.callEntry(player, plot);
|
||||||
if (plot.hasOwner()) {
|
if (plot.hasOwner()) {
|
||||||
// This will inherit values from PlotArea
|
// This will inherit values from PlotArea
|
||||||
@ -230,39 +233,47 @@ public class PlotListener {
|
|||||||
player.setWeather(plot.getFlag(WeatherFlag.class));
|
player.setWeather(plot.getFlag(WeatherFlag.class));
|
||||||
|
|
||||||
ItemType musicFlag = plot.getFlag(MusicFlag.class);
|
ItemType musicFlag = plot.getFlag(MusicFlag.class);
|
||||||
|
|
||||||
|
try (final MetaDataAccess<Location> musicMeta =
|
||||||
|
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_MUSIC)) {
|
||||||
if (musicFlag != null) {
|
if (musicFlag != null) {
|
||||||
final String rawId = musicFlag.getId();
|
final String rawId = musicFlag.getId();
|
||||||
if (rawId.contains("disc") || musicFlag == ItemTypes.AIR) {
|
if (rawId.contains("disc") || musicFlag == ItemTypes.AIR) {
|
||||||
Location location = player.getLocation();
|
Location location = player.getLocation();
|
||||||
Location lastLocation = player.getMeta("music");
|
Location lastLocation = musicMeta.get().orElse(null);
|
||||||
if (lastLocation != null) {
|
if (lastLocation != null) {
|
||||||
player.playMusic(lastLocation, musicFlag);
|
player.playMusic(lastLocation, musicFlag);
|
||||||
if (musicFlag == ItemTypes.AIR) {
|
if (musicFlag == ItemTypes.AIR) {
|
||||||
player.deleteMeta("music");
|
musicMeta.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (musicFlag != ItemTypes.AIR) {
|
if (musicFlag != ItemTypes.AIR) {
|
||||||
try {
|
try {
|
||||||
player.setMeta("music", location);
|
musicMeta.set(location);
|
||||||
player.playMusic(location, musicFlag);
|
player.playMusic(location, musicFlag);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Location lastLoc = player.getMeta("music");
|
musicMeta.get().ifPresent(lastLoc -> {
|
||||||
if (lastLoc != null) {
|
musicMeta.remove();
|
||||||
player.deleteMeta("music");
|
|
||||||
player.playMusic(lastLoc, ItemTypes.AIR);
|
player.playMusic(lastLoc, ItemTypes.AIR);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CommentManager.sendTitle(player, plot);
|
CommentManager.sendTitle(player, plot);
|
||||||
|
|
||||||
if (titles && !player.getAttribute("disabletitles")) {
|
if (titles && !player.getAttribute("disabletitles")) {
|
||||||
if (!Captions.TITLE_ENTERED_PLOT.getTranslated().isEmpty()
|
if (!Captions.TITLE_ENTERED_PLOT.getTranslated().isEmpty()
|
||||||
|| !Captions.TITLE_ENTERED_PLOT_SUB.getTranslated().isEmpty()) {
|
|| !Captions.TITLE_ENTERED_PLOT_SUB.getTranslated().isEmpty()) {
|
||||||
TaskManager.runTaskLaterAsync(() -> {
|
TaskManager.runTaskLaterAsync(() -> {
|
||||||
Plot lastPlot = player.getMeta(PlotPlayer.META_LAST_PLOT);
|
Plot lastPlot = null;
|
||||||
|
try (final MetaDataAccess<Plot> lastPlotAccess =
|
||||||
|
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
|
lastPlot = lastPlotAccess.get().orElse(null);
|
||||||
|
}
|
||||||
if ((lastPlot != null) && plot.getId().equals(lastPlot.getId())) {
|
if ((lastPlot != null) && plot.getId().equals(lastPlot.getId())) {
|
||||||
Map<String, String> replacements = new HashMap<>();
|
Map<String, String> replacements = new HashMap<>();
|
||||||
replacements.put("%x%", String.valueOf(lastPlot.getId().getX()));
|
replacements.put("%x%", String.valueOf(lastPlot.getId().getX()));
|
||||||
@ -299,21 +310,25 @@ public class PlotListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean plotExit(final PlotPlayer<?> player, Plot plot) {
|
public boolean plotExit(final PlotPlayer<?> player, Plot plot) {
|
||||||
Object previous = player.deleteMeta(PlotPlayer.META_LAST_PLOT);
|
try (final MetaDataAccess<Plot> lastPlot = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
|
final Plot previous = lastPlot.remove();
|
||||||
this.eventDispatcher.callLeave(player, plot);
|
this.eventDispatcher.callLeave(player, plot);
|
||||||
if (plot.hasOwner()) {
|
if (plot.hasOwner()) {
|
||||||
PlotArea pw = plot.getArea();
|
PlotArea pw = plot.getArea();
|
||||||
if (pw == null) {
|
if (pw == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
try (final MetaDataAccess<Boolean> kickAccess =
|
||||||
|
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
|
||||||
if (plot.getFlag(DenyExitFlag.class) && !Permissions
|
if (plot.getFlag(DenyExitFlag.class) && !Permissions
|
||||||
.hasPermission(player, Captions.PERMISSION_ADMIN_EXIT_DENIED) && !player
|
.hasPermission(player, Captions.PERMISSION_ADMIN_EXIT_DENIED) &&
|
||||||
.getMeta("kick", false)) {
|
!kickAccess.get().orElse(false)) {
|
||||||
if (previous != null) {
|
if (previous != null) {
|
||||||
player.setMeta(PlotPlayer.META_LAST_PLOT, previous);
|
lastPlot.set(previous);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!plot.getFlag(GamemodeFlag.class).equals(GamemodeFlag.DEFAULT) || !plot
|
if (!plot.getFlag(GamemodeFlag.class).equals(GamemodeFlag.DEFAULT) || !plot
|
||||||
.getFlag(GuestGamemodeFlag.class).equals(GamemodeFlag.DEFAULT)) {
|
.getFlag(GuestGamemodeFlag.class).equals(GamemodeFlag.DEFAULT)) {
|
||||||
if (player.getGameMode() != pw.getGameMode()) {
|
if (player.getGameMode() != pw.getGameMode()) {
|
||||||
@ -374,15 +389,18 @@ public class PlotListener {
|
|||||||
player.setWeather(PlotWeather.RESET);
|
player.setWeather(PlotWeather.RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
Location lastLoc = player.getMeta("music");
|
try (final MetaDataAccess<Location> musicAccess =
|
||||||
if (lastLoc != null) {
|
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_MUSIC)) {
|
||||||
player.deleteMeta("music");
|
musicAccess.get().ifPresent(lastLoc -> {
|
||||||
|
musicAccess.remove();
|
||||||
player.playMusic(lastLoc, ItemTypes.AIR);
|
player.playMusic(lastLoc, ItemTypes.AIR);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
feedRunnable.remove(player.getUUID());
|
feedRunnable.remove(player.getUUID());
|
||||||
healRunnable.remove(player.getUUID());
|
healRunnable.remove(player.getUUID());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ import com.plotsquared.core.database.DBFunc;
|
|||||||
import com.plotsquared.core.events.TeleportCause;
|
import com.plotsquared.core.events.TeleportCause;
|
||||||
import com.plotsquared.core.inject.annotations.ConsoleActor;
|
import com.plotsquared.core.inject.annotations.ConsoleActor;
|
||||||
import com.plotsquared.core.location.Location;
|
import com.plotsquared.core.location.Location;
|
||||||
|
import com.plotsquared.core.plot.Plot;
|
||||||
import com.plotsquared.core.plot.PlotArea;
|
import com.plotsquared.core.plot.PlotArea;
|
||||||
import com.plotsquared.core.plot.PlotWeather;
|
import com.plotsquared.core.plot.PlotWeather;
|
||||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||||
@ -134,8 +135,16 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public void teleport(Location location, TeleportCause cause) {
|
@Override public void teleport(Location location, TeleportCause cause) {
|
||||||
setMeta(META_LAST_PLOT, location.getPlot());
|
try (final MetaDataAccess<Plot> lastPlot = accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
setMeta(META_LOCATION, location);
|
if (location.getPlot() == null) {
|
||||||
|
lastPlot.remove();
|
||||||
|
} else {
|
||||||
|
lastPlot.set(location.getPlot());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try (final MetaDataAccess<Location> locationMetaDataAccess = accessPersistentMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
|
||||||
|
locationMetaDataAccess.set(location);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean isOnline() {
|
@Override public boolean isOnline() {
|
||||||
|
@ -28,6 +28,7 @@ package com.plotsquared.core.player;
|
|||||||
import com.plotsquared.core.synchronization.LockRepository;
|
import com.plotsquared.core.synchronization.LockRepository;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,8 +60,10 @@ public abstract class MetaDataAccess<T> implements AutoCloseable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the stored value meta data
|
* Remove the stored value meta data
|
||||||
|
*
|
||||||
|
* @return Old value, or {@link null}
|
||||||
*/
|
*/
|
||||||
public abstract void remove();
|
@Nullable public abstract T remove();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the meta data value
|
* Set the meta data value
|
||||||
|
@ -27,6 +27,7 @@ package com.plotsquared.core.player;
|
|||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
import com.plotsquared.core.synchronization.LockKey;
|
import com.plotsquared.core.synchronization.LockKey;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -44,10 +45,10 @@ public final class MetaDataKey<T> {
|
|||||||
private static final Object keyMetaData = new Object();
|
private static final Object keyMetaData = new Object();
|
||||||
|
|
||||||
private final String key;
|
private final String key;
|
||||||
private final Class<T> type;
|
private final TypeLiteral<T> type;
|
||||||
private final LockKey lockKey;
|
private final LockKey lockKey;
|
||||||
|
|
||||||
private MetaDataKey(@Nonnull final String key, @Nonnull final Class<T> type) {
|
private MetaDataKey(@Nonnull final String key, @Nonnull final TypeLiteral<T> type) {
|
||||||
this.key = Preconditions.checkNotNull(key, "Key may not be null");
|
this.key = Preconditions.checkNotNull(key, "Key may not be null");
|
||||||
this.type = Preconditions.checkNotNull(type, "Type may not be null");
|
this.type = Preconditions.checkNotNull(type, "Type may not be null");
|
||||||
this.lockKey = LockKey.of(this.key);
|
this.lockKey = LockKey.of(this.key);
|
||||||
@ -60,7 +61,7 @@ public final class MetaDataKey<T> {
|
|||||||
* @param <T> Type
|
* @param <T> Type
|
||||||
* @return MetaData key instance
|
* @return MetaData key instance
|
||||||
*/
|
*/
|
||||||
@Nonnull public static <T> MetaDataKey<T> of(@Nonnull final String key, @Nonnull final Class<T> type) {
|
@Nonnull public static <T> MetaDataKey<T> of(@Nonnull final String key, @Nonnull final TypeLiteral<T> type) {
|
||||||
synchronized (keyMetaData) {
|
synchronized (keyMetaData) {
|
||||||
return (MetaDataKey<T>)
|
return (MetaDataKey<T>)
|
||||||
keyMap.computeIfAbsent(key, missingKey -> new MetaDataKey<>(missingKey, type));
|
keyMap.computeIfAbsent(key, missingKey -> new MetaDataKey<>(missingKey, type));
|
||||||
@ -100,7 +101,7 @@ public final class MetaDataKey<T> {
|
|||||||
*
|
*
|
||||||
* @return Meta data type
|
* @return Meta data type
|
||||||
*/
|
*/
|
||||||
@Nonnull public Class<T> getType() {
|
@Nonnull public TypeLiteral<T> getType() {
|
||||||
return this.type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,9 +28,10 @@ package com.plotsquared.core.player;
|
|||||||
import com.plotsquared.core.synchronization.LockRepository;
|
import com.plotsquared.core.synchronization.LockRepository;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public final class PersistentMetaDataAccess<T> extends MetaDataAccess<T> {
|
final class PersistentMetaDataAccess<T> extends MetaDataAccess<T> {
|
||||||
|
|
||||||
PersistentMetaDataAccess(@Nonnull final PlotPlayer<?> player,
|
PersistentMetaDataAccess(@Nonnull final PlotPlayer<?> player,
|
||||||
@Nonnull final MetaDataKey<T> metaDataKey,
|
@Nonnull final MetaDataKey<T> metaDataKey,
|
||||||
@ -42,8 +43,12 @@ public final class PersistentMetaDataAccess<T> extends MetaDataAccess<T> {
|
|||||||
return this.getPlayer().hasPersistentMeta(getMetaDataKey().toString());
|
return this.getPlayer().hasPersistentMeta(getMetaDataKey().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void remove() {
|
@Override @Nullable public T remove() {
|
||||||
this.getPlayer().removePersistentMeta(this.getMetaDataKey().toString());
|
final Object old = this.getPlayer().removePersistentMeta(this.getMetaDataKey().toString());
|
||||||
|
if (old == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (T) old;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void set(@Nonnull T value) {
|
@Override public void set(@Nonnull T value) {
|
||||||
|
@ -25,10 +25,36 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.core.player;
|
package com.plotsquared.core.player;
|
||||||
|
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
import com.plotsquared.core.command.Auto;
|
||||||
|
import com.plotsquared.core.command.CmdInstance;
|
||||||
|
import com.plotsquared.core.location.Location;
|
||||||
|
import com.plotsquared.core.plot.Plot;
|
||||||
|
import com.plotsquared.core.plot.PlotInventory;
|
||||||
|
import com.plotsquared.core.setup.SetupProcess;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public final class PlayerMetaDataKeys {
|
public final class PlayerMetaDataKeys {
|
||||||
|
|
||||||
public static final MetaDataKey<Boolean> PERSISTENT_FLIGHT = MetaDataKey.of("flight", Boolean.class);
|
//@formatter:off
|
||||||
public static final MetaDataKey<Integer> GRANTED_PLOTS = MetaDataKey.of("grantedPlots", Integer.class);
|
public static final MetaDataKey<Boolean> PERSISTENT_FLIGHT = MetaDataKey.of("flight", new TypeLiteral<Boolean>() {});
|
||||||
|
public static final MetaDataKey<Integer> PERSISTENT_GRANTED_PLOTS = MetaDataKey.of("grantedPlots", new TypeLiteral<Integer>() {});
|
||||||
|
|
||||||
|
public static final MetaDataKey<Plot> TEMPORARY_LAST_PLOT = MetaDataKey.of("lastplot", new TypeLiteral<Plot>() {});
|
||||||
|
public static final MetaDataKey<Location> TEMPORARY_MUSIC = MetaDataKey.of("music", new TypeLiteral<Location>() {});
|
||||||
|
public static final MetaDataKey<Boolean> TEMPORARY_KICK = MetaDataKey.of("kick", new TypeLiteral<Boolean>() {});
|
||||||
|
public static final MetaDataKey<SetupProcess> TEMPORARY_SETUP = MetaDataKey.of("setup", new TypeLiteral<SetupProcess>() {});
|
||||||
|
public static final MetaDataKey<PlotInventory> TEMPORARY_INVENTORY = MetaDataKey.of("inventory", new TypeLiteral<PlotInventory>() {});
|
||||||
|
public static final MetaDataKey<Boolean> TEMPORARY_IGNORE_EXPIRE_TASK = MetaDataKey.of("ignoreExpireTask", new TypeLiteral<Boolean>() {});
|
||||||
|
public static final MetaDataKey<Plot> TEMPORARY_WORLD_EDIT_REGION_PLOT = MetaDataKey.of("WorldEditRegionPlot", new TypeLiteral<Plot>() {});
|
||||||
|
public static final MetaDataKey<Boolean> TEMPORARY_AUTO = MetaDataKey.of(Auto.class.getName(), new TypeLiteral<Boolean>() {});
|
||||||
|
public static final MetaDataKey<Map<String, Boolean>> TEMPORARY_PERMISSIONS = MetaDataKey.of("permissions", new TypeLiteral<Map<String, Boolean>>() {});
|
||||||
|
public static final MetaDataKey<List<String>> TEMPORARY_SCHEMATICS = MetaDataKey.of("plot_schematics", new TypeLiteral<List<String>>() {});
|
||||||
|
public static final MetaDataKey<Location> TEMPORARY_LOCATION = MetaDataKey.of("location", new TypeLiteral<Location>() {});
|
||||||
|
public static final MetaDataKey<CmdInstance> TEMPORARY_CONFIRM = MetaDataKey.of("cmdConfirm", new TypeLiteral<CmdInstance>() {});
|
||||||
|
//@formatter:on
|
||||||
|
|
||||||
private PlayerMetaDataKeys() {
|
private PlayerMetaDataKeys() {
|
||||||
}
|
}
|
||||||
|
@ -81,9 +81,6 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
|
|||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotPlayer.class.getSimpleName());
|
private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotPlayer.class.getSimpleName());
|
||||||
|
|
||||||
public static final String META_LAST_PLOT = "lastplot";
|
|
||||||
public static final String META_LOCATION = "location";
|
|
||||||
|
|
||||||
// Used to track debug mode
|
// Used to track debug mode
|
||||||
private static final Set<PlotPlayer<?>> debugModeEnabled = Collections.synchronizedSet(new HashSet<>());
|
private static final Set<PlotPlayer<?>> debugModeEnabled = Collections.synchronizedSet(new HashSet<>());
|
||||||
|
|
||||||
@ -162,7 +159,7 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
|
|||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
public void setMeta(String key, Object value) {
|
void setMeta(String key, Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
deleteMeta(key);
|
deleteMeta(key);
|
||||||
} else {
|
} else {
|
||||||
@ -180,14 +177,14 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
|
|||||||
* @param <T> the object type to return
|
* @param <T> the object type to return
|
||||||
* @return the value assigned to the key or null if it does not exist
|
* @return the value assigned to the key or null if it does not exist
|
||||||
*/
|
*/
|
||||||
public <T> T getMeta(String key) {
|
<T> T getMeta(String key) {
|
||||||
if (this.meta != null) {
|
if (this.meta != null) {
|
||||||
return (T) this.meta.get(key);
|
return (T) this.meta.get(key);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T getMeta(String key, T defaultValue) {
|
<T> T getMeta(String key, T defaultValue) {
|
||||||
T meta = getMeta(key);
|
T meta = getMeta(key);
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
@ -206,7 +203,7 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
|
|||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
*/
|
*/
|
||||||
public Object deleteMeta(String key) {
|
Object deleteMeta(String key) {
|
||||||
return this.meta == null ? null : this.meta.remove(key);
|
return this.meta == null ? null : this.meta.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,11 +222,13 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
|
|||||||
* @return the plot the player is standing on or null if standing on a road or not in a {@link PlotArea}
|
* @return the plot the player is standing on or null if standing on a road or not in a {@link PlotArea}
|
||||||
*/
|
*/
|
||||||
public Plot getCurrentPlot() {
|
public Plot getCurrentPlot() {
|
||||||
Plot value = getMeta(PlotPlayer.META_LAST_PLOT);
|
try (final MetaDataAccess<Plot> lastPlotAccess =
|
||||||
if (value == null && !Settings.Enabled_Components.EVENTS) {
|
this.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
return getLocation().getPlot();
|
if (lastPlotAccess.get().orElse(null) == null && !Settings.Enabled_Components.EVENTS) {
|
||||||
|
return this.getLocation().getPlot();
|
||||||
|
}
|
||||||
|
return lastPlotAccess.get().orElse(null);
|
||||||
}
|
}
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -730,11 +729,12 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
|
|||||||
return this.metaMap.get(key);
|
return this.metaMap.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void removePersistentMeta(String key) {
|
Object removePersistentMeta(String key) {
|
||||||
this.metaMap.remove(key);
|
final Object old = this.metaMap.remove(key);
|
||||||
if (Settings.Enabled_Components.PERSISTENT_META) {
|
if (Settings.Enabled_Components.PERSISTENT_META) {
|
||||||
DBFunc.removePersistentMeta(getUUID(), key);
|
DBFunc.removePersistentMeta(getUUID(), key);
|
||||||
}
|
}
|
||||||
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -756,15 +756,34 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
|
|||||||
return new PersistentMetaDataAccess<>(this, key, this.lockRepository.lock(key.getLockKey()));
|
return new PersistentMetaDataAccess<>(this, key, this.lockRepository.lock(key.getLockKey()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access keyed temporary meta data for this player. This returns a meta data
|
||||||
|
* access instance, that MUST be closed. It is meant to be used with try-with-resources,
|
||||||
|
* like such:
|
||||||
|
* <pre>{@code
|
||||||
|
* try (final MetaDataAccess<Integer> access = player.accessTemporaryMetaData(PlayerMetaKeys.GRANTS)) {
|
||||||
|
* int grants = access.get();
|
||||||
|
* access.set(grants + 1);
|
||||||
|
* }
|
||||||
|
* }</pre>
|
||||||
|
*
|
||||||
|
* @param key Meta data key
|
||||||
|
* @param <T> Meta data type
|
||||||
|
* @return Meta data access. MUST be closed after being used
|
||||||
|
*/
|
||||||
|
@Nonnull public <T> MetaDataAccess<T> accessTemporaryMetaData(@Nonnull final MetaDataKey<T> key) {
|
||||||
|
return new TemporaryMetaDataAccess<>(this, key, this.lockRepository.lock(key.getLockKey()));
|
||||||
|
}
|
||||||
|
|
||||||
<T> void setPersistentMeta(@Nonnull final MetaDataKey<T> key,
|
<T> void setPersistentMeta(@Nonnull final MetaDataKey<T> key,
|
||||||
@Nonnull final T value) {
|
@Nonnull final T value) {
|
||||||
final Object rawValue = value;
|
final Object rawValue = value;
|
||||||
if (key.getType().equals(Integer.class)) {
|
if (key.getType().getRawType().equals(Integer.class)) {
|
||||||
this.setPersistentMeta(key.toString(), Ints.toByteArray((int) rawValue));
|
this.setPersistentMeta(key.toString(), Ints.toByteArray((int) rawValue));
|
||||||
} else if (key.getType().equals(Boolean.class)) {
|
} else if (key.getType().getRawType().equals(Boolean.class)) {
|
||||||
this.setPersistentMeta(key.toString(), ByteArrayUtilities.booleanToBytes((boolean) rawValue));
|
this.setPersistentMeta(key.toString(), ByteArrayUtilities.booleanToBytes((boolean) rawValue));
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException(String.format("Unknown meta data type '%s'", key.getType().getSimpleName()));
|
throw new IllegalArgumentException(String.format("Unknown meta data type '%s'", key.getType().toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -774,12 +793,12 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Object returnValue;
|
final Object returnValue;
|
||||||
if (key.getType().equals(Integer.class)) {
|
if (key.getType().getRawType().equals(Integer.class)) {
|
||||||
returnValue = Ints.fromByteArray(value);
|
returnValue = Ints.fromByteArray(value);
|
||||||
} else if (key.getType().equals(Boolean.class)) {
|
} else if (key.getType().getRawType().equals(Boolean.class)) {
|
||||||
returnValue = ByteArrayUtilities.bytesToBoolean(value);
|
returnValue = ByteArrayUtilities.bytesToBoolean(value);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException(String.format("Unknown meta data type '%s'", key.getType().getSimpleName()));
|
throw new IllegalArgumentException(String.format("Unknown meta data type '%s'", key.getType().toString()));
|
||||||
}
|
}
|
||||||
return (T) returnValue;
|
return (T) returnValue;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* _____ _ _ _____ _
|
||||||
|
* | __ \| | | | / ____| | |
|
||||||
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||||
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||||
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||||
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||||
|
* | |
|
||||||
|
* |_|
|
||||||
|
* PlotSquared plot management system for Minecraft
|
||||||
|
* Copyright (C) 2020 IntellectualSites
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.plotsquared.core.player;
|
||||||
|
|
||||||
|
import com.plotsquared.core.synchronization.LockRepository;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
final class TemporaryMetaDataAccess<T> extends MetaDataAccess<T> {
|
||||||
|
|
||||||
|
TemporaryMetaDataAccess(@Nonnull final PlotPlayer<?> player,
|
||||||
|
@Nonnull final MetaDataKey<T> metaDataKey,
|
||||||
|
@Nonnull final LockRepository.LockAccess lockAccess) {
|
||||||
|
super(player, metaDataKey, lockAccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean has() {
|
||||||
|
return this.getPlayer().getMeta(this.getMetaDataKey().toString()) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override @Nullable public T remove() {
|
||||||
|
final Object old = getPlayer().deleteMeta(this.getMetaDataKey().toString());
|
||||||
|
if (old == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (T) old;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void set(@Nonnull T value) {
|
||||||
|
this.getPlayer().setMeta(this.getMetaDataKey().toString(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull @Override public Optional<T> get() {
|
||||||
|
return Optional.ofNullable(this.getPlayer().getMeta(this.getMetaDataKey().toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -42,6 +42,8 @@ import com.plotsquared.core.inject.annotations.WorldConfig;
|
|||||||
import com.plotsquared.core.location.Direction;
|
import com.plotsquared.core.location.Direction;
|
||||||
import com.plotsquared.core.location.Location;
|
import com.plotsquared.core.location.Location;
|
||||||
import com.plotsquared.core.location.PlotLoc;
|
import com.plotsquared.core.location.PlotLoc;
|
||||||
|
import com.plotsquared.core.player.MetaDataAccess;
|
||||||
|
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import com.plotsquared.core.plot.flag.FlagContainer;
|
import com.plotsquared.core.plot.flag.FlagContainer;
|
||||||
import com.plotsquared.core.plot.flag.FlagParseException;
|
import com.plotsquared.core.plot.flag.FlagParseException;
|
||||||
@ -787,8 +789,11 @@ public abstract class PlotArea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean addPlot(@Nonnull final Plot plot) {
|
public boolean addPlot(@Nonnull final Plot plot) {
|
||||||
for (PlotPlayer pp : plot.getPlayersInPlot()) {
|
for (final PlotPlayer<?> pp : plot.getPlayersInPlot()) {
|
||||||
pp.setMeta(PlotPlayer.META_LAST_PLOT, plot);
|
try (final MetaDataAccess<Plot> metaDataAccess = pp.accessTemporaryMetaData(
|
||||||
|
PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
|
metaDataAccess.set(plot);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return this.plots.put(plot.getId(), plot) == null;
|
return this.plots.put(plot.getId(), plot) == null;
|
||||||
}
|
}
|
||||||
@ -826,8 +831,11 @@ public abstract class PlotArea {
|
|||||||
|
|
||||||
public boolean addPlotIfAbsent(@Nonnull final Plot plot) {
|
public boolean addPlotIfAbsent(@Nonnull final Plot plot) {
|
||||||
if (this.plots.putIfAbsent(plot.getId(), plot) == null) {
|
if (this.plots.putIfAbsent(plot.getId(), plot) == null) {
|
||||||
for (PlotPlayer pp : plot.getPlayersInPlot()) {
|
for (PlotPlayer<?> pp : plot.getPlayersInPlot()) {
|
||||||
pp.setMeta(PlotPlayer.META_LAST_PLOT, plot);
|
try (final MetaDataAccess<Plot> metaDataAccess = pp.accessTemporaryMetaData(
|
||||||
|
PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
|
||||||
|
metaDataAccess.set(plot);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -25,18 +25,19 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.core.plot;
|
package com.plotsquared.core.plot;
|
||||||
|
|
||||||
|
import com.plotsquared.core.player.MetaDataAccess;
|
||||||
|
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import com.plotsquared.core.util.InventoryUtil;
|
import com.plotsquared.core.util.InventoryUtil;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class PlotInventory {
|
public class PlotInventory {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotInventory.class.getSimpleName());
|
private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotInventory.class.getSimpleName());
|
||||||
|
|
||||||
private static final String META_KEY = "inventory";
|
|
||||||
public final PlotPlayer<?> player;
|
public final PlotPlayer<?> player;
|
||||||
public final int size;
|
public final int size;
|
||||||
private final PlotItemStack[] items;
|
private final PlotItemStack[] items;
|
||||||
@ -58,16 +59,25 @@ public class PlotInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static PlotInventory getOpenPlotInventory(@Nonnull final PlotPlayer<?> plotPlayer) {
|
public static PlotInventory getOpenPlotInventory(@Nonnull final PlotPlayer<?> plotPlayer) {
|
||||||
return plotPlayer.getMeta(META_KEY, null);
|
try (final MetaDataAccess<PlotInventory> inventoryAccess = plotPlayer.accessTemporaryMetaData(
|
||||||
|
PlayerMetaDataKeys.TEMPORARY_INVENTORY)) {
|
||||||
|
return inventoryAccess.get().orElse(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setPlotInventoryOpen(@Nonnull final PlotPlayer<?> plotPlayer,
|
public static void setPlotInventoryOpen(@Nonnull final PlotPlayer<?> plotPlayer,
|
||||||
@Nonnull final PlotInventory plotInventory) {
|
@Nonnull final PlotInventory plotInventory) {
|
||||||
plotPlayer.setMeta(META_KEY, plotInventory);
|
try (final MetaDataAccess<PlotInventory> inventoryAccess = plotPlayer.accessTemporaryMetaData(
|
||||||
|
PlayerMetaDataKeys.TEMPORARY_INVENTORY)) {
|
||||||
|
inventoryAccess.set(plotInventory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removePlotInventoryOpen(@Nonnull final PlotPlayer<?>plotPlayer) {
|
public static void removePlotInventoryOpen(@Nonnull final PlotPlayer<?>plotPlayer) {
|
||||||
plotPlayer.deleteMeta(META_KEY);
|
try (final MetaDataAccess<PlotInventory> inventoryAccess = plotPlayer.accessTemporaryMetaData(
|
||||||
|
PlayerMetaDataKeys.TEMPORARY_INVENTORY)) {
|
||||||
|
inventoryAccess.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onClick(int index) {
|
public boolean onClick(int index) {
|
||||||
|
@ -26,8 +26,11 @@
|
|||||||
package com.plotsquared.core.plot.comment;
|
package com.plotsquared.core.plot.comment;
|
||||||
|
|
||||||
import com.google.common.annotations.Beta;
|
import com.google.common.annotations.Beta;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
import com.plotsquared.core.configuration.Captions;
|
import com.plotsquared.core.configuration.Captions;
|
||||||
import com.plotsquared.core.configuration.Settings;
|
import com.plotsquared.core.configuration.Settings;
|
||||||
|
import com.plotsquared.core.player.MetaDataAccess;
|
||||||
|
import com.plotsquared.core.player.MetaDataKey;
|
||||||
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.task.RunnableVal;
|
import com.plotsquared.core.util.task.RunnableVal;
|
||||||
@ -77,7 +80,10 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static long getTimestamp(PlotPlayer<?> player, String inbox) {
|
public static long getTimestamp(PlotPlayer<?> player, String inbox) {
|
||||||
return player.getMeta("inbox:" + inbox, player.getLastPlayed());
|
final MetaDataKey<Long> inboxKey = MetaDataKey.of(String.format("inbox:%s", inbox), new TypeLiteral<Long>() {});
|
||||||
|
try (final MetaDataAccess<Long> inboxAccess = player.accessTemporaryMetaData(inboxKey)) {
|
||||||
|
return inboxAccess.get().orElse(player.getLastPlayed());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addInbox(CommentInbox inbox) {
|
public static void addInbox(CommentInbox inbox) {
|
||||||
|
@ -31,7 +31,9 @@ import com.plotsquared.core.database.DBFunc;
|
|||||||
import com.plotsquared.core.events.PlotFlagAddEvent;
|
import com.plotsquared.core.events.PlotFlagAddEvent;
|
||||||
import com.plotsquared.core.events.PlotUnlinkEvent;
|
import com.plotsquared.core.events.PlotUnlinkEvent;
|
||||||
import com.plotsquared.core.events.Result;
|
import com.plotsquared.core.events.Result;
|
||||||
|
import com.plotsquared.core.player.MetaDataAccess;
|
||||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||||
|
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
||||||
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.PlotArea;
|
import com.plotsquared.core.plot.PlotArea;
|
||||||
@ -137,35 +139,32 @@ public class ExpireManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void confirmExpiry(final PlotPlayer pp) {
|
public void confirmExpiry(final PlotPlayer<?> pp) {
|
||||||
if (pp.getMeta("ignoreExpireTask") != null) {
|
try (final MetaDataAccess<Boolean> metaDataAccess = pp.accessTemporaryMetaData(
|
||||||
|
PlayerMetaDataKeys.TEMPORARY_IGNORE_EXPIRE_TASK)) {
|
||||||
|
if (metaDataAccess.has()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (plotsToDelete != null && !plotsToDelete.isEmpty() && pp
|
if (plotsToDelete != null && !plotsToDelete.isEmpty() && pp.hasPermission("plots.admin.command.autoclear")) {
|
||||||
.hasPermission("plots.admin.command.autoclear")) {
|
|
||||||
final int num = plotsToDelete.size();
|
final int num = plotsToDelete.size();
|
||||||
while (!plotsToDelete.isEmpty()) {
|
while (!plotsToDelete.isEmpty()) {
|
||||||
Iterator<Plot> iter = plotsToDelete.iterator();
|
Iterator<Plot> iter = plotsToDelete.iterator();
|
||||||
final Plot current = iter.next();
|
final Plot current = iter.next();
|
||||||
if (!isExpired(new ArrayDeque<>(tasks), current).isEmpty()) {
|
if (!isExpired(new ArrayDeque<>(tasks), current).isEmpty()) {
|
||||||
TaskManager.runTask(() -> {
|
TaskManager.runTask(() -> {
|
||||||
pp.setMeta("ignoreExpireTask", true);
|
metaDataAccess.set(true);
|
||||||
current.getCenter(pp::teleport);
|
current.getCenter(pp::teleport);
|
||||||
pp.deleteMeta("ignoreExpireTask");
|
metaDataAccess.remove();
|
||||||
PlotMessage msg = new PlotMessage()
|
PlotMessage msg = new PlotMessage().text(
|
||||||
.text(num + " " + (num > 1 ? "plots are" : "plot is") + " expired: ")
|
num + " " + (num > 1 ? "plots are" : "plot is") + " expired: ").color("$1").text(current.toString()).color("$2")
|
||||||
.color("$1").text(current.toString()).color("$2")
|
|
||||||
.command("/plot list expired").tooltip("/plot list expired")
|
.command("/plot list expired").tooltip("/plot list expired")
|
||||||
//.text("\n - ").color("$3").text("Delete all (/plot delete expired)").color("$2").command("/plot delete expired")
|
//.text("\n - ").color("$3").text("Delete all (/plot delete expired)").color("$2").command("/plot delete expired")
|
||||||
.text("\n - ").color("$3").text("Delete this (/plot delete)")
|
.text("\n - ").color("$3").text("Delete this (/plot delete)").color("$2").command("/plot delete").tooltip("/plot delete")
|
||||||
.color("$2").command("/plot delete").tooltip("/plot delete")
|
.text("\n - ").color("$3").text("Remind later (/plot flag set keep 1d)").color("$2")
|
||||||
.text("\n - ").color("$3").text("Remind later (/plot flag set keep 1d)")
|
.command("/plot flag set keep 1d").tooltip("/plot flag set keep 1d")
|
||||||
.color("$2").command("/plot flag set keep 1d").tooltip("/plot flag set keep 1d")
|
.text("\n - ").color("$3").text("Keep this (/plot flag set keep true)").color("$2")
|
||||||
.text("\n - ").color("$3").text("Keep this (/plot flag set keep true)")
|
.command("/plot flag set keep true").tooltip("/plot flag set keep true").text("\n - ").color("$3")
|
||||||
.color("$2").command("/plot flag set keep true")
|
.text("Don't show me this").color("$2").command("/plot toggle clear-confirmation")
|
||||||
.tooltip("/plot flag set keep true").text("\n - ").color("$3")
|
|
||||||
.text("Don't show me this").color("$2")
|
|
||||||
.command("/plot toggle clear-confirmation")
|
|
||||||
.tooltip("/plot toggle clear-confirmation");
|
.tooltip("/plot toggle clear-confirmation");
|
||||||
msg.send(pp);
|
msg.send(pp);
|
||||||
});
|
});
|
||||||
@ -177,6 +176,7 @@ public class ExpireManager {
|
|||||||
plotsToDelete.clear();
|
plotsToDelete.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean cancelTask() {
|
public boolean cancelTask() {
|
||||||
|
@ -30,6 +30,8 @@ import com.plotsquared.core.configuration.Caption;
|
|||||||
import com.plotsquared.core.configuration.Captions;
|
import com.plotsquared.core.configuration.Captions;
|
||||||
import com.plotsquared.core.events.TeleportCause;
|
import com.plotsquared.core.events.TeleportCause;
|
||||||
import com.plotsquared.core.generator.GeneratorWrapper;
|
import com.plotsquared.core.generator.GeneratorWrapper;
|
||||||
|
import com.plotsquared.core.player.MetaDataAccess;
|
||||||
|
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import com.plotsquared.core.plot.PlotArea;
|
import com.plotsquared.core.plot.PlotArea;
|
||||||
import com.plotsquared.core.plot.PlotAreaTerrainType;
|
import com.plotsquared.core.plot.PlotAreaTerrainType;
|
||||||
@ -221,7 +223,10 @@ public enum CommonSetupSteps implements SetupStep {
|
|||||||
MainUtil.sendMessage(plotPlayer, Captions.SETUP_WORLD_APPLY_PLOTSQUARED);
|
MainUtil.sendMessage(plotPlayer, Captions.SETUP_WORLD_APPLY_PLOTSQUARED);
|
||||||
}
|
}
|
||||||
builder.worldName(argument);
|
builder.worldName(argument);
|
||||||
plotPlayer.deleteMeta("setup");
|
try (final MetaDataAccess<SetupProcess> setupAccess = plotPlayer.accessTemporaryMetaData(
|
||||||
|
PlayerMetaDataKeys.TEMPORARY_SETUP)) {
|
||||||
|
setupAccess.remove();
|
||||||
|
}
|
||||||
String world;
|
String world;
|
||||||
if (builder.setupManager() == null) {
|
if (builder.setupManager() == null) {
|
||||||
world = PlotSquared.platform().getInjector().getInstance(SetupUtils.class).setupWorld(builder);
|
world = PlotSquared.platform().getInjector().getInstance(SetupUtils.class).setupWorld(builder);
|
||||||
|
@ -28,9 +28,12 @@ package com.plotsquared.core.util;
|
|||||||
import com.plotsquared.core.command.CommandCaller;
|
import com.plotsquared.core.command.CommandCaller;
|
||||||
import com.plotsquared.core.configuration.Captions;
|
import com.plotsquared.core.configuration.Captions;
|
||||||
import com.plotsquared.core.configuration.Settings;
|
import com.plotsquared.core.configuration.Settings;
|
||||||
|
import com.plotsquared.core.player.MetaDataAccess;
|
||||||
|
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Permissions class handles checking user permissions.<br>
|
* The Permissions class handles checking user permissions.<br>
|
||||||
@ -65,20 +68,22 @@ public class Permissions {
|
|||||||
if (!Settings.Enabled_Components.PERMISSION_CACHE) {
|
if (!Settings.Enabled_Components.PERMISSION_CACHE) {
|
||||||
return hasPermission((CommandCaller) player, permission);
|
return hasPermission((CommandCaller) player, permission);
|
||||||
}
|
}
|
||||||
HashMap<String, Boolean> map = player.getMeta("perm");
|
try (final MetaDataAccess<Map<String, Boolean>> mapAccess =
|
||||||
|
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_PERMISSIONS)) {
|
||||||
|
Map<String, Boolean> map = mapAccess.get().orElse(null);
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
Boolean result = map.get(permission);
|
final Boolean result = map.get(permission);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
map = new HashMap<>();
|
mapAccess.set((map = new HashMap<>()));
|
||||||
player.setMeta("perm", map);
|
|
||||||
}
|
}
|
||||||
boolean result = hasPermission((CommandCaller) player, permission);
|
boolean result = hasPermission((CommandCaller) player, permission);
|
||||||
map.put(permission, result);
|
map.put(permission, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a {@code CommandCaller} has a permission.
|
* Check if a {@code CommandCaller} has a permission.
|
||||||
|
@ -28,6 +28,8 @@ package com.plotsquared.core.util;
|
|||||||
import com.plotsquared.core.PlotSquared;
|
import com.plotsquared.core.PlotSquared;
|
||||||
import com.plotsquared.core.configuration.Settings;
|
import com.plotsquared.core.configuration.Settings;
|
||||||
import com.plotsquared.core.location.Location;
|
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.player.PlotPlayer;
|
||||||
import com.plotsquared.core.plot.Plot;
|
import com.plotsquared.core.plot.Plot;
|
||||||
import com.plotsquared.core.plot.PlotArea;
|
import com.plotsquared.core.plot.PlotArea;
|
||||||
@ -100,8 +102,10 @@ public class WEManager {
|
|||||||
}
|
}
|
||||||
boolean allowMember = player.hasPermission("plots.worldedit.member");
|
boolean allowMember = player.hasPermission("plots.worldedit.member");
|
||||||
Plot plot = player.getCurrentPlot();
|
Plot plot = player.getCurrentPlot();
|
||||||
|
try (final MetaDataAccess<Plot> metaDataAccess =
|
||||||
|
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_WORLD_EDIT_REGION_PLOT)) {
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
plot = player.getMeta("WorldEditRegionPlot");
|
plot = metaDataAccess.get().orElse(null);
|
||||||
}
|
}
|
||||||
if (plot != null && (!Settings.Done.RESTRICT_BUILDING || !DoneFlag.isDone(plot)) && (
|
if (plot != null && (!Settings.Done.RESTRICT_BUILDING || !DoneFlag.isDone(plot)) && (
|
||||||
(allowMember && plot.isAdded(uuid)) || (!allowMember && (plot.isOwner(uuid)) || plot
|
(allowMember && plot.isAdded(uuid)) || (!allowMember && (plot.isOwner(uuid)) || plot
|
||||||
@ -112,7 +116,8 @@ public class WEManager {
|
|||||||
CuboidRegion copy = new CuboidRegion(pos1, pos2);
|
CuboidRegion copy = new CuboidRegion(pos1, pos2);
|
||||||
regions.add(copy);
|
regions.add(copy);
|
||||||
}
|
}
|
||||||
player.setMeta("WorldEditRegionPlot", plot);
|
metaDataAccess.set(plot);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return regions;
|
return regions;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,8 @@ import com.plotsquared.core.configuration.Captions;
|
|||||||
import com.plotsquared.core.events.PlotMergeEvent;
|
import com.plotsquared.core.events.PlotMergeEvent;
|
||||||
import com.plotsquared.core.events.Result;
|
import com.plotsquared.core.events.Result;
|
||||||
import com.plotsquared.core.location.Direction;
|
import com.plotsquared.core.location.Direction;
|
||||||
|
import com.plotsquared.core.player.MetaDataAccess;
|
||||||
|
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
||||||
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.PlotArea;
|
import com.plotsquared.core.plot.PlotArea;
|
||||||
@ -50,7 +52,10 @@ public final class AutoClaimFinishTask implements Callable<Boolean> {
|
|||||||
private final EventDispatcher eventDispatcher;
|
private final EventDispatcher eventDispatcher;
|
||||||
|
|
||||||
@Override public Boolean call() {
|
@Override public Boolean call() {
|
||||||
player.deleteMeta(Auto.class.getName());
|
try (final MetaDataAccess<Boolean> autoAccess
|
||||||
|
= player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_AUTO)) {
|
||||||
|
autoAccess.remove();
|
||||||
|
}
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
sendMessage(player, Captions.NO_FREE_PLOTS);
|
sendMessage(player, Captions.NO_FREE_PLOTS);
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user