mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 10:14:42 +02:00
Remove construction of fake player entities for offline players.
This commit is contained in:
@ -39,6 +39,8 @@ import com.plotsquared.core.util.SchematicHandler;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -178,10 +180,9 @@ import java.util.UUID;
|
||||
*
|
||||
* @param uuid the uuid of the player to wrap
|
||||
* @return a {@code PlotPlayer}
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*/
|
||||
public PlotPlayer wrapPlayer(UUID uuid) {
|
||||
return PlotPlayer.wrap(uuid);
|
||||
@Nullable public PlotPlayer<?> wrapPlayer(@Nonnull final UUID uuid) {
|
||||
return PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,10 +190,9 @@ import java.util.UUID;
|
||||
*
|
||||
* @param player the player to wrap
|
||||
* @return a {@code PlotPlayer}
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*/
|
||||
public PlotPlayer wrapPlayer(String player) {
|
||||
return PlotPlayer.wrap(player);
|
||||
@Nullable public PlotPlayer<?> wrapPlayer(@Nonnull final String player) {
|
||||
return PlotSquared.platform().getPlayerManager().getPlayerIfExists(player);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,6 +27,7 @@ package com.plotsquared.core;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.plotsquared.core.backup.BackupManager;
|
||||
import com.plotsquared.core.generator.GeneratorWrapper;
|
||||
import com.plotsquared.core.generator.HybridUtils;
|
||||
@ -80,14 +81,6 @@ public interface PlotPlatform<P> extends ILogger {
|
||||
*/
|
||||
File getWorldContainer();
|
||||
|
||||
/**
|
||||
* Wraps a player into a PlotPlayer object.
|
||||
*
|
||||
* @param player The player to convert to a PlotPlayer
|
||||
* @return A PlotPlayer
|
||||
*/
|
||||
@Nullable PlotPlayer<P> wrapPlayer(Object player);
|
||||
|
||||
/**
|
||||
* Completely shuts down the plugin.
|
||||
*/
|
||||
@ -186,7 +179,7 @@ public interface PlotPlatform<P> extends ILogger {
|
||||
* @return Player manager
|
||||
*/
|
||||
@Nonnull default PlayerManager<? extends PlotPlayer<P>, ? extends P> getPlayerManager() {
|
||||
return getInjector().getInstance(PlayerManager.class);
|
||||
return getInjector().getInstance(Key.get(new TypeLiteral<PlayerManager<? extends PlotPlayer<P>, ? extends P>>() {}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,7 +93,7 @@ public class Buy extends Command {
|
||||
|
||||
this.econHandler.depositMoney(PlotSquared.platform().getPlayerManager().getOfflinePlayer(plot.getOwnerAbs()), price);
|
||||
|
||||
PlotPlayer owner = PlotSquared.platform().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs());
|
||||
PlotPlayer<?> owner = PlotSquared.platform().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs());
|
||||
if (owner != null) {
|
||||
Captions.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price);
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ public class PlotListener {
|
||||
++value.count;
|
||||
if (value.count == value.interval) {
|
||||
value.count = 0;
|
||||
PlotPlayer<?> player = PlotPlayer.wrap(entry.getKey());
|
||||
final PlotPlayer<?> player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(entry.getKey());
|
||||
if (player == null) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
@ -114,7 +114,7 @@ public class PlotListener {
|
||||
++value.count;
|
||||
if (value.count == value.interval) {
|
||||
value.count = 0;
|
||||
PlotPlayer<?> player = PlotSquared.platform().getWorldUtil().getPlayer(entry.getKey());
|
||||
final PlotPlayer<?> player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(entry.getKey());
|
||||
if (player == null) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
|
@ -26,6 +26,7 @@
|
||||
package com.plotsquared.core.listener;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
@ -72,7 +73,7 @@ public class WESubscriber {
|
||||
Actor actor = event.getActor();
|
||||
if (actor != null && actor.isPlayer()) {
|
||||
String name = actor.getName();
|
||||
PlotPlayer plotPlayer = PlotPlayer.wrap(name);
|
||||
final PlotPlayer<?> plotPlayer = PlotSquared.platform().getPlayerManager().getPlayerIfExists(name);
|
||||
Set<CuboidRegion> mask;
|
||||
if (plotPlayer == null) {
|
||||
Player player = (Player) actor;
|
||||
|
@ -120,7 +120,7 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
|
||||
}
|
||||
|
||||
@Override public long getLastPlayed() {
|
||||
return 0;
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override public void sendMessage(String message) {
|
||||
@ -132,10 +132,6 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
|
||||
setMeta(META_LOCATION, location);
|
||||
}
|
||||
|
||||
@Override public boolean isOnline() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public String getName() {
|
||||
return "*";
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ package com.plotsquared.core.player;
|
||||
|
||||
import com.plotsquared.core.permissions.PermissionHolder;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface OfflinePlotPlayer extends PermissionHolder {
|
||||
@ -42,16 +43,8 @@ public interface OfflinePlotPlayer extends PermissionHolder {
|
||||
* Gets the time in milliseconds when the player was last seen online.
|
||||
*
|
||||
* @return the time in milliseconds when last online
|
||||
* @deprecated This method may be inconsistent across platforms. The javadoc may be wrong depending on which platform is used.
|
||||
*/
|
||||
@SuppressWarnings("DeprecatedIsStillUsed") @Deprecated long getLastPlayed();
|
||||
|
||||
/**
|
||||
* Checks if this player is online.
|
||||
*
|
||||
* @return {@code true} if this player is online
|
||||
*/
|
||||
boolean isOnline();
|
||||
@Nonnegative long getLastPlayed();
|
||||
|
||||
/**
|
||||
* Gets the name of this player.
|
||||
|
@ -140,20 +140,6 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
|
||||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
* Efficiently wrap a Player, or OfflinePlayer object to get a PlotPlayer (or fetch if it's already cached)<br>
|
||||
* - Accepts sponge/bukkit Player (online)
|
||||
* - Accepts player name (online)
|
||||
* - Accepts UUID
|
||||
* - Accepts bukkit OfflinePlayer (offline)
|
||||
*
|
||||
* @param player Player object to wrap
|
||||
* @return Wrapped player
|
||||
*/
|
||||
public static PlotPlayer<?> wrap(Object player) {
|
||||
return PlotSquared.platform().wrapPlayer(player);
|
||||
}
|
||||
|
||||
@Override public final boolean hasPermission(@Nullable final String world,
|
||||
@Nonnull final String permission) {
|
||||
return this.permissionProfile.hasPermission(world, permission);
|
||||
|
@ -1926,11 +1926,16 @@ public class Plot {
|
||||
DBFunc.createPlotAndSettings(this, () -> {
|
||||
PlotArea plotworld = Plot.this.area;
|
||||
if (notify && plotworld.isAutoMerge()) {
|
||||
PlotPlayer player = this.worldUtil.getPlayer(uuid);
|
||||
final PlotPlayer<?> player = PlotSquared.platform().getPlayerManager()
|
||||
.getPlayerIfExists(uuid);
|
||||
|
||||
PlotMergeEvent event = this.eventDispatcher
|
||||
.callMerge(this, Direction.ALL, Integer.MAX_VALUE, player);
|
||||
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
sendMessage(player, Captions.EVENT_DENIED, "Auto merge on claim");
|
||||
if (player != null) {
|
||||
sendMessage(player, Captions.EVENT_DENIED, "Auto merge on claim");
|
||||
}
|
||||
return;
|
||||
}
|
||||
Plot.this.autoMerge(event.getDir(), event.getMax(), uuid, true);
|
||||
@ -3083,10 +3088,10 @@ public class Plot {
|
||||
if (!TaskManager.removeFromTeleportQueue(name)) {
|
||||
return;
|
||||
}
|
||||
if (player.isOnline()) {
|
||||
try {
|
||||
MainUtil.sendMessage(player, Captions.TELEPORTED_TO_PLOT);
|
||||
player.teleport(location, cause);
|
||||
}
|
||||
} catch (final Exception ignored) {}
|
||||
}, TaskTime.seconds(Settings.Teleport.DELAY));
|
||||
resultConsumer.accept(true);
|
||||
};
|
||||
|
@ -418,13 +418,13 @@ public class ExpireManager {
|
||||
}
|
||||
}
|
||||
for (UUID helper : plot.getTrusted()) {
|
||||
PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper);
|
||||
PlotPlayer<?> player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper);
|
||||
if (player != null) {
|
||||
MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString());
|
||||
}
|
||||
}
|
||||
for (UUID helper : plot.getMembers()) {
|
||||
PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper);
|
||||
PlotPlayer<?> player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper);
|
||||
if (player != null) {
|
||||
MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString());
|
||||
}
|
||||
|
@ -328,14 +328,6 @@ public abstract class WorldUtil {
|
||||
*/
|
||||
public abstract boolean isBlockSame(@Nonnull BlockState block1, @Nonnull BlockState block2);
|
||||
|
||||
/**
|
||||
* Get a player object for the player with the given UUID
|
||||
*
|
||||
* @param uuid Player UUID
|
||||
* @return Player object
|
||||
*/
|
||||
@Nonnull public abstract PlotPlayer<?> getPlayer(@Nonnull UUID uuid);
|
||||
|
||||
/**
|
||||
* Get the player health
|
||||
*
|
||||
|
Reference in New Issue
Block a user