mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-28 03:34:42 +02:00
Start working on the new permission system
This commit is contained in:
@ -25,6 +25,9 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit.player;
|
||||
|
||||
import com.plotsquared.core.permissions.NullPermissionProfile;
|
||||
import com.plotsquared.core.permissions.PermissionHandler;
|
||||
import com.plotsquared.core.permissions.PermissionProfile;
|
||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import javax.annotation.Nonnull;
|
||||
@ -34,6 +37,7 @@ import java.util.UUID;
|
||||
public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
||||
|
||||
public final OfflinePlayer player;
|
||||
private final PermissionProfile permissionProfile;
|
||||
|
||||
/**
|
||||
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player),
|
||||
@ -41,8 +45,11 @@ public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public BukkitOfflinePlayer(OfflinePlayer player) {
|
||||
public BukkitOfflinePlayer(@Nonnull final OfflinePlayer player, @Nonnull final
|
||||
PermissionHandler permissionHandler) {
|
||||
this.player = player;
|
||||
this.permissionProfile = permissionHandler.getPermissionProfile(this)
|
||||
.orElse(NullPermissionProfile.INSTANCE);
|
||||
}
|
||||
|
||||
@Nonnull @Override public UUID getUUID() {
|
||||
@ -60,4 +67,9 @@ public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
||||
@Override public String getName() {
|
||||
return this.player.getName();
|
||||
}
|
||||
|
||||
@Override public boolean hasPermission(@Nonnull final String permission) {
|
||||
return this.permissionProfile.hasPermission(permission);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.events.TeleportCause;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.permissions.PermissionHandler;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.PlotWeather;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
@ -83,19 +84,21 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
* @param player Bukkit player instance
|
||||
*/
|
||||
public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nonnull final Player player, @Nullable final EconHandler econHandler) {
|
||||
this(plotAreaManager, eventDispatcher, player, false, econHandler);
|
||||
@Nonnull final Player player, @Nullable final EconHandler econHandler, @Nonnull final PermissionHandler permissionHandler) {
|
||||
this(plotAreaManager, eventDispatcher, player, false, econHandler, permissionHandler);
|
||||
}
|
||||
|
||||
public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nonnull final Player player, final boolean offline, @Nullable final EconHandler econHandler) {
|
||||
this(plotAreaManager, eventDispatcher, player, offline, true, econHandler);
|
||||
@Nonnull final Player player, final boolean offline, @Nullable final EconHandler econHandler,
|
||||
@Nonnull final PermissionHandler permissionHandler) {
|
||||
this(plotAreaManager, eventDispatcher, player, offline, true, econHandler, permissionHandler);
|
||||
}
|
||||
|
||||
public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final
|
||||
EventDispatcher eventDispatcher, @Nonnull final Player player, final boolean offline,
|
||||
final boolean realPlayer, @Nullable final EconHandler econHandler) {
|
||||
super(plotAreaManager, eventDispatcher, econHandler);
|
||||
final boolean realPlayer, @Nullable final EconHandler econHandler,
|
||||
@Nonnull final PermissionHandler permissionHandler) {
|
||||
super(plotAreaManager, eventDispatcher, econHandler, permissionHandler);
|
||||
this.player = player;
|
||||
this.offline = offline;
|
||||
this.econHandler = econHandler;
|
||||
@ -161,13 +164,6 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean hasPermission(final String permission) {
|
||||
if (this.offline && this.econHandler != null) {
|
||||
return this.econHandler.hasPermission(getName(), permission);
|
||||
}
|
||||
return this.player.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override public int hasPermissionRange(final String stub, final int range) {
|
||||
if (hasPermission(Captions.PERMISSION_ADMIN.getTranslated())) {
|
||||
return Integer.MAX_VALUE;
|
||||
|
@ -27,6 +27,7 @@ package com.plotsquared.bukkit.player;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.plotsquared.core.permissions.PermissionHandler;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.EconHandler;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
@ -46,13 +47,16 @@ import java.util.UUID;
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final EventDispatcher eventDispatcher;
|
||||
private final EconHandler econHandler;
|
||||
private final PermissionHandler permissionHandler;
|
||||
|
||||
@Inject public BukkitPlayerManager(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final EventDispatcher eventDispatcher,
|
||||
@Nullable final EconHandler econHandler) {
|
||||
@Nullable final EconHandler econHandler,
|
||||
@Nonnull final PermissionHandler permissionHandler) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.econHandler = econHandler;
|
||||
this.permissionHandler = permissionHandler;
|
||||
}
|
||||
|
||||
@Nonnull @Override public BukkitPlayer getPlayer(@Nonnull final Player object) {
|
||||
@ -60,7 +64,7 @@ import java.util.UUID;
|
||||
return getPlayer(object.getUniqueId());
|
||||
} catch (final NoSuchPlayerException exception) {
|
||||
return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, object,
|
||||
object.isOnline(), false, this.econHandler);
|
||||
object.isOnline(), false, this.econHandler, this.permissionHandler);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,18 +73,18 @@ import java.util.UUID;
|
||||
if (player == null || !player.isOnline()) {
|
||||
throw new NoSuchPlayerException(uuid);
|
||||
}
|
||||
return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, player, this.econHandler);
|
||||
return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, player, this.econHandler, this.permissionHandler);
|
||||
}
|
||||
|
||||
@Nullable @Override public BukkitOfflinePlayer getOfflinePlayer(@Nullable final UUID uuid) {
|
||||
if (uuid == null) {
|
||||
return null;
|
||||
}
|
||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid));
|
||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid), this.permissionHandler);
|
||||
}
|
||||
|
||||
@Nonnull @Override public BukkitOfflinePlayer getOfflinePlayer(@Nonnull final String username) {
|
||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(username));
|
||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(username), this.permissionHandler);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user