mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-14 10:35:50 +01:00
Merge pull request #2886 from IntellectualSites/features/v6/permissions
Permission system fixup
This commit is contained in:
commit
0ea862b572
@ -106,6 +106,8 @@ shadowJar {
|
|||||||
include(dependency("javax.annotation:javax-annotation-api"))
|
include(dependency("javax.annotation:javax-annotation-api"))
|
||||||
include(dependency('org.apache.logging.log4j:log4j-slf4j-impl'))
|
include(dependency('org.apache.logging.log4j:log4j-slf4j-impl'))
|
||||||
include(dependency('org.slf4j:slf4j-api'))
|
include(dependency('org.slf4j:slf4j-api'))
|
||||||
|
include(dependency('javax.inject:javax.inject:1'))
|
||||||
|
include(dependency('aopalliance:aopalliance:1.0'))
|
||||||
}
|
}
|
||||||
|
|
||||||
relocate('net.kyori.text', 'com.plotsquared.formatting.text')
|
relocate('net.kyori.text', 'com.plotsquared.formatting.text')
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.papermc</groupId>
|
<groupId>io.papermc</groupId>
|
||||||
<artifactId>paperlib</artifactId>
|
<artifactId>paperlib</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.0.4</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -34,6 +34,7 @@ import com.google.inject.TypeLiteral;
|
|||||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||||
import com.plotsquared.bukkit.inject.BackupModule;
|
import com.plotsquared.bukkit.inject.BackupModule;
|
||||||
import com.plotsquared.bukkit.inject.BukkitModule;
|
import com.plotsquared.bukkit.inject.BukkitModule;
|
||||||
|
import com.plotsquared.bukkit.inject.PermissionModule;
|
||||||
import com.plotsquared.bukkit.inject.WorldManagerModule;
|
import com.plotsquared.bukkit.inject.WorldManagerModule;
|
||||||
import com.plotsquared.bukkit.listener.ChunkListener;
|
import com.plotsquared.bukkit.listener.ChunkListener;
|
||||||
import com.plotsquared.bukkit.listener.EntitySpawnListener;
|
import com.plotsquared.bukkit.listener.EntitySpawnListener;
|
||||||
@ -104,7 +105,6 @@ import com.plotsquared.core.util.ConsoleColors;
|
|||||||
import com.plotsquared.core.util.EconHandler;
|
import com.plotsquared.core.util.EconHandler;
|
||||||
import com.plotsquared.core.util.EventDispatcher;
|
import com.plotsquared.core.util.EventDispatcher;
|
||||||
import com.plotsquared.core.util.FileUtils;
|
import com.plotsquared.core.util.FileUtils;
|
||||||
import com.plotsquared.core.util.PermHandler;
|
|
||||||
import com.plotsquared.core.util.PlatformWorldManager;
|
import com.plotsquared.core.util.PlatformWorldManager;
|
||||||
import com.plotsquared.core.util.PlayerManager;
|
import com.plotsquared.core.util.PlayerManager;
|
||||||
import com.plotsquared.core.util.PremiumVerification;
|
import com.plotsquared.core.util.PremiumVerification;
|
||||||
@ -124,7 +124,6 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -183,7 +182,6 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
|||||||
private boolean methodUnloadSetup = false;
|
private boolean methodUnloadSetup = false;
|
||||||
private boolean metricsStarted;
|
private boolean metricsStarted;
|
||||||
private EconHandler econ;
|
private EconHandler econ;
|
||||||
private PermHandler perm;
|
|
||||||
|
|
||||||
@Getter private Injector injector;
|
@Getter private Injector injector;
|
||||||
|
|
||||||
@ -248,8 +246,11 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
|||||||
|
|
||||||
// We create the injector after PlotSquared has been initialized, so that we have access
|
// We create the injector after PlotSquared has been initialized, so that we have access
|
||||||
// to generated instances and settings
|
// to generated instances and settings
|
||||||
this.injector = Guice.createInjector(Stage.PRODUCTION, new WorldManagerModule(), new PlotSquaredModule(),
|
this.injector = Guice.createInjector(Stage.PRODUCTION, new PermissionModule(),
|
||||||
new BukkitModule(this), new BackupModule());
|
new WorldManagerModule(),
|
||||||
|
new PlotSquaredModule(),
|
||||||
|
new BukkitModule(this),
|
||||||
|
new BackupModule());
|
||||||
this.injector.injectMembers(this);
|
this.injector.injectMembers(this);
|
||||||
|
|
||||||
if (PremiumVerification.isPremium() && Settings.Enabled_Components.UPDATE_NOTIFICATIONS) {
|
if (PremiumVerification.isPremium() && Settings.Enabled_Components.UPDATE_NOTIFICATIONS) {
|
||||||
@ -339,10 +340,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
|||||||
// Economy
|
// Economy
|
||||||
if (Settings.Enabled_Components.ECONOMY) {
|
if (Settings.Enabled_Components.ECONOMY) {
|
||||||
TaskManager.runTask(() -> {
|
TaskManager.runTask(() -> {
|
||||||
final PermHandler permHandler = getInjector().getInstance(PermHandler.class);
|
this.getPermissionHandler().initialize();
|
||||||
if (permHandler != null) {
|
|
||||||
permHandler.init();
|
|
||||||
}
|
|
||||||
final EconHandler econHandler = getInjector().getInstance(EconHandler.class);
|
final EconHandler econHandler = getInjector().getInstance(EconHandler.class);
|
||||||
if (econHandler != null) {
|
if (econHandler != null) {
|
||||||
econHandler.init();
|
econHandler.init();
|
||||||
@ -574,7 +572,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
|||||||
}
|
}
|
||||||
final Plot plot = area.getOwnedPlot(id);
|
final Plot plot = area.getOwnedPlot(id);
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
if (!plot.getFlag(ServerPlotFlag.class) || PlotPlayer.wrap(plot.getOwner()) == null) {
|
if (!plot.getFlag(ServerPlotFlag.class) || PlotSquared.platform().getPlayerManager()
|
||||||
|
.getPlayerIfExists(plot.getOwner()) == null) {
|
||||||
if (world.getKeepSpawnInMemory()) {
|
if (world.getKeepSpawnInMemory()) {
|
||||||
world.setKeepSpawnInMemory(false);
|
world.setKeepSpawnInMemory(false);
|
||||||
return;
|
return;
|
||||||
@ -1082,39 +1081,6 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempt to retrieve a {@link PlotPlayer} from a player identifier.
|
|
||||||
* This method accepts:
|
|
||||||
* - {@link Player} objects,
|
|
||||||
* - {@link OfflinePlayer} objects,
|
|
||||||
* - {@link String} usernames for online players, and
|
|
||||||
* - {@link UUID} UUIDs for online players
|
|
||||||
* <p>
|
|
||||||
* In the case of offline players, a fake {@link Player} instance will be created.
|
|
||||||
* This is a rather expensive operation, and should be avoided if possible.
|
|
||||||
*
|
|
||||||
* @param player The player to convert to a PlotPlayer
|
|
||||||
* @return The plot player instance that corresponds to the identifier, or null
|
|
||||||
* if no such player object could be created
|
|
||||||
*/
|
|
||||||
@Override @Nullable public PlotPlayer<Player> wrapPlayer(final Object player) {
|
|
||||||
if (player instanceof Player) {
|
|
||||||
return BukkitUtil.adapt((Player) player);
|
|
||||||
}
|
|
||||||
if (player instanceof OfflinePlayer) {
|
|
||||||
return BukkitUtil.adapt((OfflinePlayer) player);
|
|
||||||
}
|
|
||||||
if (player instanceof String) {
|
|
||||||
return (PlotPlayer<Player>) PlotSquared.platform().getPlayerManager()
|
|
||||||
.getPlayerIfExists((String) player);
|
|
||||||
}
|
|
||||||
if (player instanceof UUID) {
|
|
||||||
return (PlotPlayer<Player>) PlotSquared.platform().getPlayerManager()
|
|
||||||
.getPlayerIfExists((UUID) player);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public String getNMSPackage() {
|
@Override public String getNMSPackage() {
|
||||||
final String name = Bukkit.getServer().getClass().getPackage().getName();
|
final String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
return name.substring(name.lastIndexOf('.') + 1);
|
return name.substring(name.lastIndexOf('.') + 1);
|
||||||
@ -1151,8 +1117,9 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
|||||||
return getInjector().getInstance(Key.get(new TypeLiteral<PlatformWorldManager<World>>() {}));
|
return getInjector().getInstance(Key.get(new TypeLiteral<PlatformWorldManager<World>>() {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Nonnull public PlayerManager<? extends PlotPlayer<Player>, ? extends Player> getPlayerManager() {
|
@Override @Nonnull @SuppressWarnings("ALL")
|
||||||
return getInjector().getInstance(Key.get(new TypeLiteral<PlayerManager<BukkitPlayer, Player>>() {}));
|
public PlayerManager<? extends PlotPlayer<Player>, ? extends Player> getPlayerManager() {
|
||||||
|
return (PlayerManager<BukkitPlayer, Player>) getInjector().getInstance(PlayerManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ import com.google.inject.AbstractModule;
|
|||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||||
import com.google.inject.util.Providers;
|
|
||||||
import com.plotsquared.bukkit.BukkitPlatform;
|
import com.plotsquared.bukkit.BukkitPlatform;
|
||||||
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
||||||
import com.plotsquared.bukkit.queue.BukkitLocalQueue;
|
import com.plotsquared.bukkit.queue.BukkitLocalQueue;
|
||||||
@ -37,12 +36,9 @@ import com.plotsquared.bukkit.schematic.BukkitSchematicHandler;
|
|||||||
import com.plotsquared.bukkit.util.BukkitChunkManager;
|
import com.plotsquared.bukkit.util.BukkitChunkManager;
|
||||||
import com.plotsquared.bukkit.util.BukkitEconHandler;
|
import com.plotsquared.bukkit.util.BukkitEconHandler;
|
||||||
import com.plotsquared.bukkit.util.BukkitInventoryUtil;
|
import com.plotsquared.bukkit.util.BukkitInventoryUtil;
|
||||||
import com.plotsquared.bukkit.util.BukkitPermHandler;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitRegionManager;
|
import com.plotsquared.bukkit.util.BukkitRegionManager;
|
||||||
import com.plotsquared.bukkit.util.BukkitSetupUtils;
|
import com.plotsquared.bukkit.util.BukkitSetupUtils;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.plotsquared.bukkit.util.task.PaperTimeConverter;
|
|
||||||
import com.plotsquared.bukkit.util.task.SpigotTimeConverter;
|
|
||||||
import com.plotsquared.core.PlotPlatform;
|
import com.plotsquared.core.PlotPlatform;
|
||||||
import com.plotsquared.core.configuration.Settings;
|
import com.plotsquared.core.configuration.Settings;
|
||||||
import com.plotsquared.core.generator.HybridGen;
|
import com.plotsquared.core.generator.HybridGen;
|
||||||
@ -58,7 +54,6 @@ import com.plotsquared.core.queue.QueueProvider;
|
|||||||
import com.plotsquared.core.util.ChunkManager;
|
import com.plotsquared.core.util.ChunkManager;
|
||||||
import com.plotsquared.core.util.EconHandler;
|
import com.plotsquared.core.util.EconHandler;
|
||||||
import com.plotsquared.core.util.InventoryUtil;
|
import com.plotsquared.core.util.InventoryUtil;
|
||||||
import com.plotsquared.core.util.PermHandler;
|
|
||||||
import com.plotsquared.core.util.PlayerManager;
|
import com.plotsquared.core.util.PlayerManager;
|
||||||
import com.plotsquared.core.util.RegionManager;
|
import com.plotsquared.core.util.RegionManager;
|
||||||
import com.plotsquared.core.util.SchematicHandler;
|
import com.plotsquared.core.util.SchematicHandler;
|
||||||
@ -70,7 +65,9 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@RequiredArgsConstructor public class BukkitModule extends AbstractModule {
|
@RequiredArgsConstructor public class BukkitModule extends AbstractModule {
|
||||||
|
|
||||||
@ -93,7 +90,6 @@ import javax.annotation.Nonnull;
|
|||||||
bind(ChunkManager.class).to(BukkitChunkManager.class);
|
bind(ChunkManager.class).to(BukkitChunkManager.class);
|
||||||
bind(RegionManager.class).to(BukkitRegionManager.class);
|
bind(RegionManager.class).to(BukkitRegionManager.class);
|
||||||
bind(SchematicHandler.class).to(BukkitSchematicHandler.class);
|
bind(SchematicHandler.class).to(BukkitSchematicHandler.class);
|
||||||
this.setupVault();
|
|
||||||
if (Settings.Enabled_Components.WORLDS) {
|
if (Settings.Enabled_Components.WORLDS) {
|
||||||
bind(PlotAreaManager.class).to(SinglePlotAreaManager.class);
|
bind(PlotAreaManager.class).to(SinglePlotAreaManager.class);
|
||||||
} else {
|
} else {
|
||||||
@ -102,25 +98,14 @@ import javax.annotation.Nonnull;
|
|||||||
install(new FactoryModuleBuilder().build(HybridPlotWorldFactory.class));
|
install(new FactoryModuleBuilder().build(HybridPlotWorldFactory.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupVault() {
|
@Provides @Singleton @Nullable EconHandler provideEconHandler() {
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
|
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
|
||||||
BukkitPermHandler bukkitPermHandler = null;
|
|
||||||
try {
|
try {
|
||||||
bukkitPermHandler = new BukkitPermHandler();
|
return new BukkitEconHandler();
|
||||||
bind(PermHandler.class).toInstance(bukkitPermHandler);
|
|
||||||
} catch (final Exception ignored) {
|
} catch (final Exception ignored) {
|
||||||
bind(PermHandler.class).toProvider(Providers.of(null));
|
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
final BukkitEconHandler bukkitEconHandler = new BukkitEconHandler(bukkitPermHandler);
|
|
||||||
bind(EconHandler.class).toInstance(bukkitEconHandler);
|
|
||||||
} catch (final Exception ignored) {
|
|
||||||
bind(EconHandler.class).toProvider(Providers.of(null));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
bind(PermHandler.class).toProvider(Providers.of(null));
|
|
||||||
bind(EconHandler.class).toProvider(Providers.of(null));
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,38 +23,26 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package com.plotsquared.bukkit.util;
|
package com.plotsquared.bukkit.inject;
|
||||||
|
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import com.plotsquared.core.util.PermHandler;
|
import com.plotsquared.bukkit.permissions.BukkitPermissionHandler;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import com.plotsquared.bukkit.permissions.VaultPermissionHandler;
|
||||||
|
import com.plotsquared.core.permissions.PermissionHandler;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
||||||
|
|
||||||
@Singleton public class BukkitPermHandler extends PermHandler {
|
public class PermissionModule extends AbstractModule {
|
||||||
|
|
||||||
private Permission perms;
|
@Provides @Singleton PermissionHandler providePermissionHandler() {
|
||||||
|
try {
|
||||||
@Override
|
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
|
||||||
public boolean init() {
|
return new VaultPermissionHandler();
|
||||||
if (this.perms == null) {
|
}
|
||||||
setupPermissions();
|
} catch (final Exception ignored) {
|
||||||
}
|
}
|
||||||
return this.perms != null;
|
return new BukkitPermissionHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupPermissions() {
|
|
||||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
RegisteredServiceProvider<Permission> permissionProvider =
|
|
||||||
Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
|
||||||
if (permissionProvider != null) {
|
|
||||||
this.perms = permissionProvider.getProvider();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public boolean hasPermission(String world, String player, String perm) {
|
|
||||||
return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* _____ _ _ _____ _
|
||||||
|
* | __ \| | | | / ____| | |
|
||||||
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||||
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||||
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||||
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||||
|
* | |
|
||||||
|
* |_|
|
||||||
|
* PlotSquared plot management system for Minecraft
|
||||||
|
* Copyright (C) 2020 IntellectualSites
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.plotsquared.bukkit.permissions;
|
||||||
|
|
||||||
|
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||||
|
import com.plotsquared.core.permissions.ConsolePermissionProfile;
|
||||||
|
import com.plotsquared.core.permissions.PermissionHandler;
|
||||||
|
import com.plotsquared.core.permissions.PermissionProfile;
|
||||||
|
import com.plotsquared.core.player.ConsolePlayer;
|
||||||
|
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||||
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class BukkitPermissionHandler implements PermissionHandler {
|
||||||
|
|
||||||
|
@Override public void initialize() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull @Override public Optional<PermissionProfile> getPermissionProfile(
|
||||||
|
@Nonnull PlotPlayer<?> playerPlotPlayer) {
|
||||||
|
if (playerPlotPlayer instanceof BukkitPlayer) {
|
||||||
|
final BukkitPlayer bukkitPlayer = (BukkitPlayer) playerPlotPlayer;
|
||||||
|
return Optional.of(new BukkitPermissionProfile(bukkitPlayer.getPlatformPlayer()));
|
||||||
|
} else if (playerPlotPlayer instanceof ConsolePlayer) {
|
||||||
|
return Optional.of(ConsolePermissionProfile.INSTANCE);
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull @Override public Optional<PermissionProfile> getPermissionProfile(
|
||||||
|
@Nonnull OfflinePlotPlayer offlinePlotPlayer) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull @Override public Set<PermissionHandlerCapability> getCapabilities() {
|
||||||
|
return EnumSet.of(PermissionHandlerCapability.ONLINE_PERMISSIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static final class BukkitPermissionProfile implements PermissionProfile {
|
||||||
|
|
||||||
|
private final WeakReference<Player> playerReference;
|
||||||
|
|
||||||
|
private BukkitPermissionProfile(@Nonnull final Player player) {
|
||||||
|
this.playerReference = new WeakReference<>(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean hasPermission(@Nullable final String world,
|
||||||
|
@Nonnull final String permission) {
|
||||||
|
final Player player = this.playerReference.get();
|
||||||
|
return player != null && player.hasPermission(permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* _____ _ _ _____ _
|
||||||
|
* | __ \| | | | / ____| | |
|
||||||
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||||
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||||
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||||
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||||
|
* | |
|
||||||
|
* |_|
|
||||||
|
* PlotSquared plot management system for Minecraft
|
||||||
|
* Copyright (C) 2020 IntellectualSites
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.plotsquared.bukkit.permissions;
|
||||||
|
|
||||||
|
import com.plotsquared.bukkit.player.BukkitOfflinePlayer;
|
||||||
|
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||||
|
import com.plotsquared.core.permissions.ConsolePermissionProfile;
|
||||||
|
import com.plotsquared.core.permissions.PermissionHandler;
|
||||||
|
import com.plotsquared.core.permissions.PermissionProfile;
|
||||||
|
import com.plotsquared.core.player.ConsolePlayer;
|
||||||
|
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||||
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class VaultPermissionHandler implements PermissionHandler {
|
||||||
|
|
||||||
|
private Permission permissions;
|
||||||
|
|
||||||
|
@Override public void initialize() {
|
||||||
|
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||||
|
throw new IllegalStateException("Vault is not present on the server");
|
||||||
|
}
|
||||||
|
RegisteredServiceProvider<Permission> permissionProvider =
|
||||||
|
Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
||||||
|
if (permissionProvider != null) {
|
||||||
|
this.permissions = permissionProvider.getProvider();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull @Override public Optional<PermissionProfile> getPermissionProfile(
|
||||||
|
@Nonnull PlotPlayer<?> playerPlotPlayer) {
|
||||||
|
if (playerPlotPlayer instanceof BukkitPlayer) {
|
||||||
|
final BukkitPlayer bukkitPlayer = (BukkitPlayer) playerPlotPlayer;
|
||||||
|
return Optional.of(new VaultPermissionProfile(bukkitPlayer.getPlatformPlayer()));
|
||||||
|
} else if (playerPlotPlayer instanceof ConsolePlayer) {
|
||||||
|
return Optional.of(ConsolePermissionProfile.INSTANCE);
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull @Override public Optional<PermissionProfile> getPermissionProfile(
|
||||||
|
@Nonnull OfflinePlotPlayer offlinePlotPlayer) {
|
||||||
|
if (offlinePlotPlayer instanceof BukkitOfflinePlayer) {
|
||||||
|
return Optional.of(new VaultPermissionProfile(((BukkitOfflinePlayer) offlinePlotPlayer).player));
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull @Override public Set<PermissionHandlerCapability> getCapabilities() {
|
||||||
|
return EnumSet.of(PermissionHandlerCapability.PER_WORLD_PERMISSIONS,
|
||||||
|
PermissionHandlerCapability.ONLINE_PERMISSIONS,
|
||||||
|
PermissionHandlerCapability.OFFLINE_PERMISSIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private final class VaultPermissionProfile implements PermissionProfile {
|
||||||
|
|
||||||
|
private final OfflinePlayer offlinePlayer;
|
||||||
|
|
||||||
|
private VaultPermissionProfile(@Nonnull final OfflinePlayer offlinePlayer) {
|
||||||
|
this.offlinePlayer = offlinePlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean hasPermission(@Nullable final String world,
|
||||||
|
@Nonnull final String permission) {
|
||||||
|
if (permissions == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (world == null && offlinePlayer instanceof BukkitPlayer) {
|
||||||
|
return permissions.playerHas(((BukkitPlayer) offlinePlayer).getPlatformPlayer(), permission);
|
||||||
|
}
|
||||||
|
return permissions.playerHas(world, offlinePlayer, permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -25,39 +25,49 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.bukkit.player;
|
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 com.plotsquared.core.player.OfflinePlotPlayer;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnegative;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
||||||
|
|
||||||
public final OfflinePlayer player;
|
public final OfflinePlayer player;
|
||||||
|
private final PermissionProfile permissionProfile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player),
|
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player),
|
||||||
* as it caches player objects.
|
* as it caches player objects.
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
*/
|
*/
|
||||||
public BukkitOfflinePlayer(OfflinePlayer player) {
|
public BukkitOfflinePlayer(@Nonnull final OfflinePlayer player, @Nonnull final
|
||||||
|
PermissionHandler permissionHandler) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
this.permissionProfile = permissionHandler.getPermissionProfile(this)
|
||||||
|
.orElse(NullPermissionProfile.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull @Override public UUID getUUID() {
|
@Nonnull @Override public UUID getUUID() {
|
||||||
return this.player.getUniqueId();
|
return this.player.getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public long getLastPlayed() {
|
@Override @Nonnegative public long getLastPlayed() {
|
||||||
return this.player.getLastPlayed();
|
return this.player.getLastSeen();
|
||||||
}
|
|
||||||
|
|
||||||
@Override public boolean isOnline() {
|
|
||||||
return this.player.isOnline();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String getName() {
|
@Override public String getName() {
|
||||||
return this.player.getName();
|
return this.player.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public boolean hasPermission(@Nullable final String world,
|
||||||
|
@Nonnull final String permission) {
|
||||||
|
return this.permissionProfile.hasPermission(world, permission);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import com.plotsquared.core.configuration.Captions;
|
|||||||
import com.plotsquared.core.configuration.Settings;
|
import com.plotsquared.core.configuration.Settings;
|
||||||
import com.plotsquared.core.events.TeleportCause;
|
import com.plotsquared.core.events.TeleportCause;
|
||||||
import com.plotsquared.core.location.Location;
|
import com.plotsquared.core.location.Location;
|
||||||
|
import com.plotsquared.core.permissions.PermissionHandler;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
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;
|
||||||
@ -53,6 +54,8 @@ import org.bukkit.event.EventException;
|
|||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
import org.bukkit.plugin.RegisteredListener;
|
import org.bukkit.plugin.RegisteredListener;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnegative;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@ -71,11 +74,9 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
private static boolean CHECK_EFFECTIVE = true;
|
private static boolean CHECK_EFFECTIVE = true;
|
||||||
public final Player player;
|
public final Player player;
|
||||||
private final EconHandler econHandler;
|
private final EconHandler econHandler;
|
||||||
private boolean offline;
|
|
||||||
private String name;
|
private String name;
|
||||||
private String lastMessage = "";
|
private String lastMessage = "";
|
||||||
private long lastMessageTime = 0L;
|
private long lastMessageTime = 0L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Please do not use this method. Instead use
|
* <p>Please do not use this method. Instead use
|
||||||
* BukkitUtil.getPlayer(Player), as it caches player objects.</p>
|
* BukkitUtil.getPlayer(Player), as it caches player objects.</p>
|
||||||
@ -83,21 +84,16 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
* @param player Bukkit player instance
|
* @param player Bukkit player instance
|
||||||
*/
|
*/
|
||||||
public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final EventDispatcher eventDispatcher,
|
public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final EventDispatcher eventDispatcher,
|
||||||
@Nonnull final Player player, @Nullable final EconHandler econHandler) {
|
@Nonnull final Player player, @Nullable final EconHandler econHandler, @Nonnull final PermissionHandler permissionHandler) {
|
||||||
this(plotAreaManager, eventDispatcher, player, false, econHandler);
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final
|
public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final
|
||||||
EventDispatcher eventDispatcher, @Nonnull final Player player, final boolean offline,
|
EventDispatcher eventDispatcher, @Nonnull final Player player,
|
||||||
final boolean realPlayer, @Nullable final EconHandler econHandler) {
|
final boolean realPlayer, @Nullable final EconHandler econHandler,
|
||||||
super(plotAreaManager, eventDispatcher, econHandler);
|
@Nonnull final PermissionHandler permissionHandler) {
|
||||||
|
super(plotAreaManager, eventDispatcher, econHandler, permissionHandler);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.offline = offline;
|
|
||||||
this.econHandler = econHandler;
|
this.econHandler = econHandler;
|
||||||
if (realPlayer) {
|
if (realPlayer) {
|
||||||
super.populatePersistentMetaMap();
|
super.populatePersistentMetaMap();
|
||||||
@ -125,8 +121,8 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
return player.getUniqueId();
|
return player.getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public long getLastPlayed() {
|
@Override @Nonnegative public long getLastPlayed() {
|
||||||
return this.player.getLastPlayed();
|
return this.player.getLastSeen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean canTeleport(@Nonnull final Location location) {
|
@Override public boolean canTeleport(@Nonnull final Location location) {
|
||||||
@ -161,14 +157,8 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean hasPermission(final String permission) {
|
@Override @Nonnegative public int hasPermissionRange(@Nonnull final String stub,
|
||||||
if (this.offline && this.econHandler != null) {
|
@Nonnegative final int range) {
|
||||||
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())) {
|
if (hasPermission(Captions.PERMISSION_ADMIN.getTranslated())) {
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
@ -228,10 +218,6 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean isPermissionSet(final String permission) {
|
|
||||||
return this.player.isPermissionSet(permission);
|
|
||||||
}
|
|
||||||
|
|
||||||
@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.lastMessage, message) || (
|
if (!StringMan.isEqual(this.lastMessage, message) || (
|
||||||
@ -260,10 +246,6 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean isOnline() {
|
|
||||||
return !this.offline && this.player.isOnline();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void setCompassTarget(Location location) {
|
@Override public void setCompassTarget(Location location) {
|
||||||
this.player.setCompassTarget(
|
this.player.setCompassTarget(
|
||||||
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorldName()), location.getX(),
|
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorldName()), location.getX(),
|
||||||
|
@ -27,6 +27,7 @@ package com.plotsquared.bukkit.player;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
import com.plotsquared.core.permissions.PermissionHandler;
|
||||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||||
import com.plotsquared.core.util.EconHandler;
|
import com.plotsquared.core.util.EconHandler;
|
||||||
import com.plotsquared.core.util.EventDispatcher;
|
import com.plotsquared.core.util.EventDispatcher;
|
||||||
@ -46,21 +47,26 @@ import java.util.UUID;
|
|||||||
private final PlotAreaManager plotAreaManager;
|
private final PlotAreaManager plotAreaManager;
|
||||||
private final EventDispatcher eventDispatcher;
|
private final EventDispatcher eventDispatcher;
|
||||||
private final EconHandler econHandler;
|
private final EconHandler econHandler;
|
||||||
|
private final PermissionHandler permissionHandler;
|
||||||
|
|
||||||
@Inject public BukkitPlayerManager(@Nonnull final PlotAreaManager plotAreaManager,
|
@Inject public BukkitPlayerManager(@Nonnull final PlotAreaManager plotAreaManager,
|
||||||
@Nonnull final EventDispatcher eventDispatcher,
|
@Nonnull final EventDispatcher eventDispatcher,
|
||||||
@Nullable final EconHandler econHandler) {
|
@Nullable final EconHandler econHandler,
|
||||||
|
@Nonnull final PermissionHandler permissionHandler) {
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
this.eventDispatcher = eventDispatcher;
|
this.eventDispatcher = eventDispatcher;
|
||||||
this.econHandler = econHandler;
|
this.econHandler = econHandler;
|
||||||
|
this.permissionHandler = permissionHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull @Override public BukkitPlayer getPlayer(@Nonnull final Player object) {
|
@Nonnull @Override public BukkitPlayer getPlayer(@Nonnull final Player object) {
|
||||||
|
if (!object.isOnline()) {
|
||||||
|
throw new NoSuchPlayerException(object.getUniqueId());
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return getPlayer(object.getUniqueId());
|
return getPlayer(object.getUniqueId());
|
||||||
} catch (final NoSuchPlayerException exception) {
|
} catch (final NoSuchPlayerException exception) {
|
||||||
return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, object,
|
return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, object, false, this.econHandler, this.permissionHandler);
|
||||||
object.isOnline(), false, this.econHandler);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,18 +75,18 @@ import java.util.UUID;
|
|||||||
if (player == null || !player.isOnline()) {
|
if (player == null || !player.isOnline()) {
|
||||||
throw new NoSuchPlayerException(uuid);
|
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) {
|
@Nullable @Override public BukkitOfflinePlayer getOfflinePlayer(@Nullable final UUID uuid) {
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
return 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) {
|
@Nonnull @Override public BukkitOfflinePlayer getOfflinePlayer(@Nonnull final String username) {
|
||||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(username));
|
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(username), this.permissionHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,31 +25,21 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.bukkit.util;
|
package com.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import com.plotsquared.bukkit.player.BukkitOfflinePlayer;
|
import com.plotsquared.bukkit.player.BukkitOfflinePlayer;
|
||||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import com.plotsquared.core.util.EconHandler;
|
import com.plotsquared.core.util.EconHandler;
|
||||||
import com.plotsquared.core.util.PermHandler;
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
@Singleton public class BukkitEconHandler extends EconHandler {
|
@Singleton public class BukkitEconHandler extends EconHandler {
|
||||||
|
|
||||||
private Economy econ;
|
private Economy econ;
|
||||||
|
|
||||||
private final PermHandler permHandler;
|
@Override public boolean init() {
|
||||||
|
|
||||||
@Inject public BukkitEconHandler(@Nullable final PermHandler permHandler) {
|
|
||||||
this.permHandler = permHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean init() {
|
|
||||||
if (this.econ == null) {
|
if (this.econ == null) {
|
||||||
setupEconomy();
|
setupEconomy();
|
||||||
}
|
}
|
||||||
@ -87,17 +77,6 @@ import javax.annotation.Nullable;
|
|||||||
this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
|
this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link PermHandler#hasPermission(String, String, String)} instead
|
|
||||||
*/
|
|
||||||
@Deprecated @Override public boolean hasPermission(String world, String player, String perm) {
|
|
||||||
if (this.permHandler != null) {
|
|
||||||
return this.permHandler.hasPermission(world, player, perm);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public double getBalance(PlotPlayer<?> player) {
|
@Override public double getBalance(PlotPlayer<?> player) {
|
||||||
return this.econ.getBalance(player.getName());
|
return this.econ.getBalance(player.getName());
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,6 @@ import io.papermc.lib.PaperLib;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -101,7 +100,6 @@ import java.util.Collection;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.IntConsumer;
|
import java.util.function.IntConsumer;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@ -116,24 +114,6 @@ import java.util.stream.Stream;
|
|||||||
super(regionManager);
|
super(regionManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a {@link PlotPlayer} from an {@link OfflinePlayer}. If the player is
|
|
||||||
* online, it returns a complete player. If the player is offline, it creates
|
|
||||||
* a fake player
|
|
||||||
*
|
|
||||||
* @param op Offline player
|
|
||||||
* @return Plot player instance
|
|
||||||
*/
|
|
||||||
@Nonnull public static PlotPlayer<Player> adapt(@Nonnull final OfflinePlayer op) {
|
|
||||||
if (op.isOnline()) {
|
|
||||||
return adapt(Objects.requireNonNull(op.getPlayer()));
|
|
||||||
}
|
|
||||||
final Player player = OfflinePlayerUtil.loadPlayer(op);
|
|
||||||
player.loadData();
|
|
||||||
return new BukkitPlayer(PlotSquared.get().getPlotAreaManager(),
|
|
||||||
PlotSquared.get().getEventDispatcher(), player, true, PlotSquared.platform().getEconHandler());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turn a Bukkit {@link Player} into a PlotSquared {@link PlotPlayer}
|
* Turn a Bukkit {@link Player} into a PlotSquared {@link PlotPlayer}
|
||||||
*
|
*
|
||||||
@ -214,18 +194,6 @@ import java.util.stream.Stream;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the PlotPlayer for a UUID. The PlotPlayer is usually cached and
|
|
||||||
* will provide useful functions relating to players.
|
|
||||||
*
|
|
||||||
* @param uuid the uuid to wrap
|
|
||||||
* @return a {@code PlotPlayer}
|
|
||||||
* @see PlotPlayer#wrap(Object)
|
|
||||||
*/
|
|
||||||
@Override @Nonnull public PlotPlayer<?> getPlayer(@Nonnull final UUID uuid) {
|
|
||||||
return PlotPlayer.wrap(Bukkit.getOfflinePlayer(uuid));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public boolean isBlockSame(@Nonnull final BlockState block1,
|
@Override public boolean isBlockSame(@Nonnull final BlockState block1,
|
||||||
@Nonnull final BlockState block2) {
|
@Nonnull final BlockState block2) {
|
||||||
if (block1.equals(block2)) {
|
if (block1.equals(block2)) {
|
||||||
|
@ -1,133 +0,0 @@
|
|||||||
/*
|
|
||||||
* _____ _ _ _____ _
|
|
||||||
* | __ \| | | | / ____| | |
|
|
||||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
|
||||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
|
||||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
|
||||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
|
||||||
* | |
|
|
||||||
* |_|
|
|
||||||
* PlotSquared plot management system for Minecraft
|
|
||||||
* Copyright (C) 2020 IntellectualSites
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package com.plotsquared.bukkit.util;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static com.plotsquared.core.util.ReflectionUtils.callConstructor;
|
|
||||||
import static com.plotsquared.core.util.ReflectionUtils.callMethod;
|
|
||||||
import static com.plotsquared.core.util.ReflectionUtils.getCbClass;
|
|
||||||
import static com.plotsquared.core.util.ReflectionUtils.getField;
|
|
||||||
import static com.plotsquared.core.util.ReflectionUtils.getNmsClass;
|
|
||||||
import static com.plotsquared.core.util.ReflectionUtils.getUtilClass;
|
|
||||||
import static com.plotsquared.core.util.ReflectionUtils.makeConstructor;
|
|
||||||
import static com.plotsquared.core.util.ReflectionUtils.makeField;
|
|
||||||
import static com.plotsquared.core.util.ReflectionUtils.makeMethod;
|
|
||||||
|
|
||||||
public class OfflinePlayerUtil {
|
|
||||||
|
|
||||||
public static Player loadPlayer(OfflinePlayer player) {
|
|
||||||
if (player == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (player instanceof Player) {
|
|
||||||
return (Player) player;
|
|
||||||
}
|
|
||||||
return loadPlayer(player.getUniqueId(), player.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Player loadPlayer(UUID id, String name) {
|
|
||||||
Object server = getMinecraftServer();
|
|
||||||
Object interactManager = newPlayerInteractManager();
|
|
||||||
Object worldServer = getWorldServer();
|
|
||||||
Object profile = newGameProfile(id, name);
|
|
||||||
Class<?> entityPlayerClass = getNmsClass("EntityPlayer");
|
|
||||||
Constructor entityPlayerConstructor =
|
|
||||||
makeConstructor(entityPlayerClass, getNmsClass("MinecraftServer"),
|
|
||||||
getNmsClass("WorldServer"), getUtilClass("com.mojang.authlib.GameProfile"),
|
|
||||||
getNmsClass("PlayerInteractManager"));
|
|
||||||
Object entityPlayer =
|
|
||||||
callConstructor(entityPlayerConstructor, server, worldServer, profile, interactManager);
|
|
||||||
return (Player) getBukkitEntity(entityPlayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Object newGameProfile(UUID id, String name) {
|
|
||||||
Class<?> gameProfileClass = getUtilClass("com.mojang.authlib.GameProfile");
|
|
||||||
if (gameProfileClass == null) { //Before uuids
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
Constructor gameProfileConstructor =
|
|
||||||
makeConstructor(gameProfileClass, UUID.class, String.class);
|
|
||||||
if (gameProfileConstructor == null) { //Version has string constructor
|
|
||||||
gameProfileConstructor = makeConstructor(gameProfileClass, String.class, String.class);
|
|
||||||
return callConstructor(gameProfileConstructor, id.toString(), name);
|
|
||||||
} else { //Version has uuid constructor
|
|
||||||
return callConstructor(gameProfileConstructor, id, name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Object newPlayerInteractManager() {
|
|
||||||
Object worldServer = getWorldServer();
|
|
||||||
Class<?> playerInteractClass = getNmsClass("PlayerInteractManager");
|
|
||||||
Class<?> worldClass = getNmsClass("World");
|
|
||||||
Constructor<?> c = makeConstructor(playerInteractClass, worldClass);
|
|
||||||
if (c == null) {
|
|
||||||
c = makeConstructor(playerInteractClass, getNmsClass("WorldServer"));
|
|
||||||
}
|
|
||||||
return callConstructor(c, worldServer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Object getWorldServerNew() {
|
|
||||||
Object server = getMinecraftServer();
|
|
||||||
Class<?> minecraftServerClass = getNmsClass("MinecraftServer");
|
|
||||||
Class<?> dimensionManager = getNmsClass("DimensionManager");
|
|
||||||
Object overworld = getField(makeField(dimensionManager, "OVERWORLD"), null);
|
|
||||||
Method getWorldServer =
|
|
||||||
makeMethod(minecraftServerClass, "getWorldServer", dimensionManager);
|
|
||||||
return callMethod(getWorldServer, server, overworld);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Object getWorldServer() {
|
|
||||||
Object server = getMinecraftServer();
|
|
||||||
Class<?> minecraftServerClass = getNmsClass("MinecraftServer");
|
|
||||||
Method getWorldServer = makeMethod(minecraftServerClass, "getWorldServer", int.class);
|
|
||||||
Object o;
|
|
||||||
try {
|
|
||||||
o = callMethod(getWorldServer, server, 0);
|
|
||||||
} catch (final RuntimeException e) {
|
|
||||||
o = getWorldServerNew();
|
|
||||||
}
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
//NMS Utils
|
|
||||||
|
|
||||||
private static Object getMinecraftServer() {
|
|
||||||
return callMethod(makeMethod(getCbClass("CraftServer"), "getServer"), Bukkit.getServer());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Entity getBukkitEntity(Object o) {
|
|
||||||
Method getBukkitEntity = makeMethod(o.getClass(), "getBukkitEntity");
|
|
||||||
return callMethod(getBukkitEntity, o);
|
|
||||||
}
|
|
||||||
}
|
|
@ -20,6 +20,8 @@ dependencies {
|
|||||||
compile("com.google.inject:guice:4.2.3")
|
compile("com.google.inject:guice:4.2.3")
|
||||||
compile("com.google.inject.extensions:guice-assistedinject:4.2.3")
|
compile("com.google.inject.extensions:guice-assistedinject:4.2.3")
|
||||||
compile group: 'com.google.code.findbugs', name: 'annotations', version: '3.0.1'
|
compile group: 'com.google.code.findbugs', name: 'annotations', version: '3.0.1'
|
||||||
|
compile group: 'javax.inject', name: 'javax.inject', version: '1'
|
||||||
|
compile group: 'aopalliance', name: 'aopalliance', version: '1.0'
|
||||||
// logging
|
// logging
|
||||||
implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")
|
implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")
|
||||||
}
|
}
|
||||||
|
12
Core/pom.xml
12
Core/pom.xml
@ -36,6 +36,18 @@
|
|||||||
<version>3.0.1</version>
|
<version>3.0.1</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.inject</groupId>
|
||||||
|
<artifactId>javax.inject</artifactId>
|
||||||
|
<version>1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>aopalliance</groupId>
|
||||||
|
<artifactId>aopalliance</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
@ -39,6 +39,8 @@ import com.plotsquared.core.util.SchematicHandler;
|
|||||||
import com.plotsquared.core.util.query.PlotQuery;
|
import com.plotsquared.core.util.query.PlotQuery;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -178,10 +180,9 @@ import java.util.UUID;
|
|||||||
*
|
*
|
||||||
* @param uuid the uuid of the player to wrap
|
* @param uuid the uuid of the player to wrap
|
||||||
* @return a {@code PlotPlayer}
|
* @return a {@code PlotPlayer}
|
||||||
* @see PlotPlayer#wrap(Object)
|
|
||||||
*/
|
*/
|
||||||
public PlotPlayer wrapPlayer(UUID uuid) {
|
@Nullable public PlotPlayer<?> wrapPlayer(@Nonnull final UUID uuid) {
|
||||||
return PlotPlayer.wrap(uuid);
|
return PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -189,10 +190,9 @@ import java.util.UUID;
|
|||||||
*
|
*
|
||||||
* @param player the player to wrap
|
* @param player the player to wrap
|
||||||
* @return a {@code PlotPlayer}
|
* @return a {@code PlotPlayer}
|
||||||
* @see PlotPlayer#wrap(Object)
|
|
||||||
*/
|
*/
|
||||||
public PlotPlayer wrapPlayer(String player) {
|
@Nullable public PlotPlayer<?> wrapPlayer(@Nonnull final String player) {
|
||||||
return PlotPlayer.wrap(player);
|
return PlotSquared.platform().getPlayerManager().getPlayerIfExists(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,12 +27,14 @@ package com.plotsquared.core;
|
|||||||
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
import com.plotsquared.core.backup.BackupManager;
|
import com.plotsquared.core.backup.BackupManager;
|
||||||
import com.plotsquared.core.generator.GeneratorWrapper;
|
import com.plotsquared.core.generator.GeneratorWrapper;
|
||||||
import com.plotsquared.core.generator.HybridUtils;
|
import com.plotsquared.core.generator.HybridUtils;
|
||||||
import com.plotsquared.core.generator.IndependentPlotGenerator;
|
import com.plotsquared.core.generator.IndependentPlotGenerator;
|
||||||
import com.plotsquared.core.inject.annotations.DefaultGenerator;
|
import com.plotsquared.core.inject.annotations.DefaultGenerator;
|
||||||
import com.plotsquared.core.location.World;
|
import com.plotsquared.core.location.World;
|
||||||
|
import com.plotsquared.core.permissions.PermissionHandler;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import com.plotsquared.core.queue.GlobalBlockQueue;
|
import com.plotsquared.core.queue.GlobalBlockQueue;
|
||||||
import com.plotsquared.core.util.ChatManager;
|
import com.plotsquared.core.util.ChatManager;
|
||||||
@ -79,14 +81,6 @@ public interface PlotPlatform<P> extends ILogger {
|
|||||||
*/
|
*/
|
||||||
File getWorldContainer();
|
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.
|
* Completely shuts down the plugin.
|
||||||
*/
|
*/
|
||||||
@ -185,7 +179,7 @@ public interface PlotPlatform<P> extends ILogger {
|
|||||||
* @return Player manager
|
* @return Player manager
|
||||||
*/
|
*/
|
||||||
@Nonnull default PlayerManager<? extends PlotPlayer<P>, ? extends P> getPlayerManager() {
|
@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>>() {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -266,4 +260,13 @@ public interface PlotPlatform<P> extends ILogger {
|
|||||||
return getInjector().getInstance(ChunkManager.class);
|
return getInjector().getInstance(ChunkManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@link PermissionHandler} implementation for the platform
|
||||||
|
*
|
||||||
|
* @return Permission handler
|
||||||
|
*/
|
||||||
|
@Nonnull default PermissionHandler getPermissionHandler() {
|
||||||
|
return getInjector().getInstance(PermissionHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ import com.plotsquared.core.events.Result;
|
|||||||
import com.plotsquared.core.events.TeleportCause;
|
import com.plotsquared.core.events.TeleportCause;
|
||||||
import com.plotsquared.core.player.MetaDataAccess;
|
import com.plotsquared.core.player.MetaDataAccess;
|
||||||
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
||||||
|
import com.plotsquared.core.permissions.PermissionHandler;
|
||||||
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;
|
||||||
@ -181,9 +182,11 @@ public class Auto extends SubCommand {
|
|||||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||||
PlotArea plotarea = player.getApplicablePlotArea();
|
PlotArea plotarea = player.getApplicablePlotArea();
|
||||||
if (plotarea == null) {
|
if (plotarea == null) {
|
||||||
if (this.econHandler != null) {
|
final PermissionHandler permissionHandler = PlotSquared.platform().getPermissionHandler();
|
||||||
for (PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
|
if (permissionHandler.hasCapability(
|
||||||
if (this.econHandler.hasPermission(area.getWorldName(), player.getName(), "plots.auto")) {
|
PermissionHandler.PermissionHandlerCapability.PER_WORLD_PERMISSIONS)) {
|
||||||
|
for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
|
||||||
|
if (player.hasPermission(area.getWorldName(), "plots.auto")) {
|
||||||
if (plotarea != null) {
|
if (plotarea != null) {
|
||||||
plotarea = null;
|
plotarea = null;
|
||||||
break;
|
break;
|
||||||
|
@ -93,7 +93,7 @@ public class Buy extends Command {
|
|||||||
|
|
||||||
this.econHandler.depositMoney(PlotSquared.platform().getPlayerManager().getOfflinePlayer(plot.getOwnerAbs()), price);
|
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) {
|
if (owner != null) {
|
||||||
Captions.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price);
|
Captions.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price);
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ import com.plotsquared.core.util.StringComparison;
|
|||||||
import com.plotsquared.core.util.StringMan;
|
import com.plotsquared.core.util.StringMan;
|
||||||
import com.plotsquared.core.util.task.RunnableVal2;
|
import com.plotsquared.core.util.task.RunnableVal2;
|
||||||
import com.plotsquared.core.util.task.RunnableVal3;
|
import com.plotsquared.core.util.task.RunnableVal3;
|
||||||
|
import com.plotsquared.core.permissions.PermissionHolder;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@ -158,7 +159,7 @@ public abstract class Command {
|
|||||||
return this.allCommands;
|
return this.allCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasConfirmation(CommandCaller player) {
|
public boolean hasConfirmation(PermissionHolder player) {
|
||||||
return this.confirmation && !player.hasPermission(getPermission() + ".confirm.bypass");
|
return this.confirmation && !player.hasPermission(getPermission() + ".confirm.bypass");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,14 +34,6 @@ public interface CommandCaller {
|
|||||||
*/
|
*/
|
||||||
void sendMessage(String message);
|
void sendMessage(String message);
|
||||||
|
|
||||||
/**
|
|
||||||
* Check the player's permissions. <i>Will be cached if permission caching is enabled.</i>
|
|
||||||
*
|
|
||||||
* @param permission the name of the permission
|
|
||||||
*/
|
|
||||||
boolean hasPermission(String permission);
|
|
||||||
|
|
||||||
boolean isPermissionSet(String permission);
|
|
||||||
|
|
||||||
RequiredType getSuperCaller();
|
RequiredType getSuperCaller();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ public class PlotListener {
|
|||||||
++value.count;
|
++value.count;
|
||||||
if (value.count == value.interval) {
|
if (value.count == value.interval) {
|
||||||
value.count = 0;
|
value.count = 0;
|
||||||
PlotPlayer<?> player = PlotPlayer.wrap(entry.getKey());
|
final PlotPlayer<?> player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(entry.getKey());
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
@ -117,7 +117,7 @@ public class PlotListener {
|
|||||||
++value.count;
|
++value.count;
|
||||||
if (value.count == value.interval) {
|
if (value.count == value.interval) {
|
||||||
value.count = 0;
|
value.count = 0;
|
||||||
PlotPlayer<?> player = PlotSquared.platform().getWorldUtil().getPlayer(entry.getKey());
|
final PlotPlayer<?> player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(entry.getKey());
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
package com.plotsquared.core.listener;
|
package com.plotsquared.core.listener;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.plotsquared.core.PlotSquared;
|
||||||
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.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
@ -72,7 +73,7 @@ public class WESubscriber {
|
|||||||
Actor actor = event.getActor();
|
Actor actor = event.getActor();
|
||||||
if (actor != null && actor.isPlayer()) {
|
if (actor != null && actor.isPlayer()) {
|
||||||
String name = actor.getName();
|
String name = actor.getName();
|
||||||
PlotPlayer plotPlayer = PlotPlayer.wrap(name);
|
final PlotPlayer<?> plotPlayer = PlotSquared.platform().getPlayerManager().getPlayerIfExists(name);
|
||||||
Set<CuboidRegion> mask;
|
Set<CuboidRegion> mask;
|
||||||
if (plotPlayer == null) {
|
if (plotPlayer == null) {
|
||||||
Player player = (Player) actor;
|
Player player = (Player) actor;
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* _____ _ _ _____ _
|
||||||
|
* | __ \| | | | / ____| | |
|
||||||
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||||
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||||
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||||
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||||
|
* | |
|
||||||
|
* |_|
|
||||||
|
* 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.permissions;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public enum ConsolePermissionProfile implements PermissionProfile {
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
@Override public boolean hasPermission(@Nullable final String world,
|
||||||
|
@Nonnull final String permission) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -23,15 +23,17 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package com.plotsquared.core.util;
|
package com.plotsquared.core.permissions;
|
||||||
|
|
||||||
public abstract class PermHandler {
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public abstract boolean init();
|
public enum NullPermissionProfile implements PermissionProfile {
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
public abstract boolean hasPermission(String world, String player, String perm);
|
@Override public boolean hasPermission(@Nullable final String world,
|
||||||
|
@Nonnull final String permission) {
|
||||||
public boolean hasPermission(String player, String perm) {
|
return false;
|
||||||
return hasPermission(null, player, perm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* _____ _ _ _____ _
|
||||||
|
* | __ \| | | | / ____| | |
|
||||||
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||||
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||||
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||||
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||||
|
* | |
|
||||||
|
* |_|
|
||||||
|
* 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.permissions;
|
||||||
|
|
||||||
|
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||||
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permission handler
|
||||||
|
*/
|
||||||
|
public interface PermissionHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the permission handler
|
||||||
|
*/
|
||||||
|
void initialize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to construct a permission profile for a plot player
|
||||||
|
*
|
||||||
|
* @param playerPlotPlayer Plot player
|
||||||
|
* @return Permission profile, if one was able to be constructed
|
||||||
|
*/
|
||||||
|
@Nonnull Optional<PermissionProfile> getPermissionProfile(
|
||||||
|
@Nonnull PlotPlayer<?> playerPlotPlayer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to construct a permission profile for an offline plot player
|
||||||
|
*
|
||||||
|
* @param offlinePlotPlayer Offline player
|
||||||
|
* @return Permission profile, if one was able to be constructed
|
||||||
|
*/
|
||||||
|
@Nonnull Optional<PermissionProfile> getPermissionProfile(
|
||||||
|
@Nonnull OfflinePlotPlayer offlinePlotPlayer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all capabilities that the permission handler has
|
||||||
|
*
|
||||||
|
* @return Immutable set of capabilities
|
||||||
|
*/
|
||||||
|
@Nonnull Set<PermissionHandlerCapability> getCapabilities();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether or not the permission handler has a given capability
|
||||||
|
*
|
||||||
|
* @param capability Capability
|
||||||
|
* @return {@code true} if the handler has the capability, else {@code false}
|
||||||
|
*/
|
||||||
|
default boolean hasCapability(@Nonnull final PermissionHandlerCapability capability) {
|
||||||
|
return this.getCapabilities().contains(capability);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permission handler capabilities
|
||||||
|
*/
|
||||||
|
enum PermissionHandlerCapability {
|
||||||
|
/**
|
||||||
|
* The ability to check for online (player) permissions
|
||||||
|
*/
|
||||||
|
ONLINE_PERMISSIONS,
|
||||||
|
/**
|
||||||
|
* The ability to check for offline (player) permissions
|
||||||
|
*/
|
||||||
|
OFFLINE_PERMISSIONS,
|
||||||
|
/**
|
||||||
|
* Per world permissions
|
||||||
|
*/
|
||||||
|
PER_WORLD_PERMISSIONS
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* _____ _ _ _____ _
|
||||||
|
* | __ \| | | | / ____| | |
|
||||||
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||||
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||||
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||||
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||||
|
* | |
|
||||||
|
* |_|
|
||||||
|
* 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.permissions;
|
||||||
|
|
||||||
|
import com.plotsquared.core.configuration.Captions;
|
||||||
|
import com.plotsquared.core.configuration.Settings;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnegative;
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Any object which can hold permissions
|
||||||
|
*/
|
||||||
|
public interface PermissionHolder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the owner of the profile has a given (global) permission
|
||||||
|
*
|
||||||
|
* @param permission Permission
|
||||||
|
* @return {@code true} if the owner has the given permission, else {@code false}
|
||||||
|
*/
|
||||||
|
default boolean hasPermission(@Nonnull final String permission) {
|
||||||
|
return hasPermission(null ,permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the the highest permission a PlotPlayer has within a specified range.<br>
|
||||||
|
* - Excessively high values will lag<br>
|
||||||
|
* - The default range that is checked is {@link Settings.Limit#MAX_PLOTS}<br>
|
||||||
|
*
|
||||||
|
* @param stub The permission stub to check e.g. for `plots.plot.#` the stub is `plots.plot`
|
||||||
|
* @param range The range to check
|
||||||
|
* @return The highest permission they have within that range
|
||||||
|
*/
|
||||||
|
@Nonnegative default int hasPermissionRange(@Nonnull final String stub,
|
||||||
|
@Nonnegative final int range) {
|
||||||
|
if (hasPermission(Captions.PERMISSION_ADMIN.getTranslated())) {
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
String[] nodes = stub.split("\\.");
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for (int i = 0; i < (nodes.length - 1); i++) {
|
||||||
|
builder.append(nodes[i]).append(".");
|
||||||
|
if (!stub.equals(builder + Captions.PERMISSION_STAR.getTranslated())) {
|
||||||
|
if (hasPermission(builder + Captions.PERMISSION_STAR.getTranslated())) {
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasPermission(stub + ".*")) {
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
for (int i = range; i > 0; i--) {
|
||||||
|
if (hasPermission(stub + "." + i)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the owner of the profile has a given permission
|
||||||
|
*
|
||||||
|
* @param world World name
|
||||||
|
* @param permission Permission
|
||||||
|
* @return {@code true} if the owner has the given permission, else {@code false}
|
||||||
|
*/
|
||||||
|
boolean hasPermission(@Nullable String world, @Nonnull String permission);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* _____ _ _ _____ _
|
||||||
|
* | __ \| | | | / ____| | |
|
||||||
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||||
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||||
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||||
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||||
|
* | |
|
||||||
|
* |_|
|
||||||
|
* 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.permissions;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A permission profile that can be used to check for permissions
|
||||||
|
*/
|
||||||
|
public interface PermissionProfile {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the owner of the profile has a given (global) permission
|
||||||
|
*
|
||||||
|
* @param permission Permission
|
||||||
|
* @return {@code true} if the owner has the given permission, else {@code false}
|
||||||
|
*/
|
||||||
|
default boolean hasPermission(@Nonnull final String permission) {
|
||||||
|
return hasPermission(null ,permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the owner of the profile has a given permission
|
||||||
|
*
|
||||||
|
* @param world World name
|
||||||
|
* @param permission Permission
|
||||||
|
* @return {@code true} if the owner has the given permission, else {@code false}
|
||||||
|
*/
|
||||||
|
boolean hasPermission(@Nullable final String world, @Nonnull String permission);
|
||||||
|
|
||||||
|
}
|
@ -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.permissions.PermissionHandler;
|
||||||
import com.plotsquared.core.plot.Plot;
|
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;
|
||||||
@ -48,6 +49,8 @@ import javax.annotation.Nullable;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ConsolePlayer extends PlotPlayer<Actor> {
|
public class ConsolePlayer extends PlotPlayer<Actor> {
|
||||||
@ -60,8 +63,9 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
|
|||||||
@Inject private ConsolePlayer(@Nonnull final PlotAreaManager plotAreaManager,
|
@Inject private ConsolePlayer(@Nonnull final PlotAreaManager plotAreaManager,
|
||||||
@Nonnull final EventDispatcher eventDispatcher,
|
@Nonnull final EventDispatcher eventDispatcher,
|
||||||
@ConsoleActor @Nonnull final Actor actor,
|
@ConsoleActor @Nonnull final Actor actor,
|
||||||
@Nullable final EconHandler econHandler) {
|
@Nullable final EconHandler econHandler,
|
||||||
super(plotAreaManager, eventDispatcher, econHandler);
|
@Nonnull final PermissionHandler permissionHandler) {
|
||||||
|
super(plotAreaManager, eventDispatcher, econHandler, permissionHandler);
|
||||||
this.actor = actor;
|
this.actor = actor;
|
||||||
final PlotArea[] areas = plotAreaManager.getAllPlotAreas();
|
final PlotArea[] areas = plotAreaManager.getAllPlotAreas();
|
||||||
final PlotArea area;
|
final PlotArea area;
|
||||||
@ -119,15 +123,7 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public long getLastPlayed() {
|
@Override public long getLastPlayed() {
|
||||||
return 0;
|
return System.currentTimeMillis();
|
||||||
}
|
|
||||||
|
|
||||||
@Override public boolean hasPermission(String permission) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public boolean isPermissionSet(String permission) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void sendMessage(String message) {
|
@Override public void sendMessage(String message) {
|
||||||
@ -147,10 +143,6 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean isOnline() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public String getName() {
|
@Override public String getName() {
|
||||||
return "*";
|
return "*";
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,12 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.core.player;
|
package com.plotsquared.core.player;
|
||||||
|
|
||||||
|
import com.plotsquared.core.permissions.PermissionHolder;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnegative;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface OfflinePlotPlayer {
|
public interface OfflinePlotPlayer extends PermissionHolder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@code UUID} of this player
|
* Gets the {@code UUID} of this player
|
||||||
@ -40,16 +43,8 @@ public interface OfflinePlotPlayer {
|
|||||||
* Gets the time in milliseconds when the player was last seen online.
|
* Gets the time in milliseconds when the player was last seen online.
|
||||||
*
|
*
|
||||||
* @return the time in milliseconds when last 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();
|
@Nonnegative long getLastPlayed();
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if this player is online.
|
|
||||||
*
|
|
||||||
* @return {@code true} if this player is online
|
|
||||||
*/
|
|
||||||
boolean isOnline();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name of this player.
|
* Gets the name of this player.
|
||||||
@ -57,4 +52,5 @@ public interface OfflinePlotPlayer {
|
|||||||
* @return the player name
|
* @return the player name
|
||||||
*/
|
*/
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,9 @@ import com.plotsquared.core.configuration.Settings;
|
|||||||
import com.plotsquared.core.database.DBFunc;
|
import com.plotsquared.core.database.DBFunc;
|
||||||
import com.plotsquared.core.events.TeleportCause;
|
import com.plotsquared.core.events.TeleportCause;
|
||||||
import com.plotsquared.core.location.Location;
|
import com.plotsquared.core.location.Location;
|
||||||
|
import com.plotsquared.core.permissions.NullPermissionProfile;
|
||||||
|
import com.plotsquared.core.permissions.PermissionHandler;
|
||||||
|
import com.plotsquared.core.permissions.PermissionProfile;
|
||||||
import com.plotsquared.core.plot.Plot;
|
import com.plotsquared.core.plot.Plot;
|
||||||
import com.plotsquared.core.plot.PlotArea;
|
import com.plotsquared.core.plot.PlotArea;
|
||||||
import com.plotsquared.core.plot.PlotCluster;
|
import com.plotsquared.core.plot.PlotCluster;
|
||||||
@ -97,11 +100,15 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
|
|||||||
private final PlotAreaManager plotAreaManager;
|
private final PlotAreaManager plotAreaManager;
|
||||||
private final EventDispatcher eventDispatcher;
|
private final EventDispatcher eventDispatcher;
|
||||||
private final EconHandler econHandler;
|
private final EconHandler econHandler;
|
||||||
|
private final PermissionProfile permissionProfile;
|
||||||
|
|
||||||
public PlotPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final EventDispatcher eventDispatcher, @Nullable final EconHandler econHandler) {
|
public PlotPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final EventDispatcher eventDispatcher, @Nullable final EconHandler econHandler,
|
||||||
|
@Nonnull final PermissionHandler permissionHandler) {
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
this.eventDispatcher = eventDispatcher;
|
this.eventDispatcher = eventDispatcher;
|
||||||
this.econHandler = econHandler;
|
this.econHandler = econHandler;
|
||||||
|
this.permissionProfile = permissionHandler.getPermissionProfile(this).orElse(
|
||||||
|
NullPermissionProfile.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> PlotPlayer<T> from(@Nonnull final T object) {
|
public static <T> PlotPlayer<T> from(@Nonnull final T object) {
|
||||||
@ -135,18 +142,9 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
|
|||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override public final boolean hasPermission(@Nullable final String world,
|
||||||
* Efficiently wrap a Player, or OfflinePlayer object to get a PlotPlayer (or fetch if it's already cached)<br>
|
@Nonnull final String permission) {
|
||||||
* - Accepts sponge/bukkit Player (online)
|
return this.permissionProfile.hasPermission(world, permission);
|
||||||
* - 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Actor toActor();
|
public abstract Actor toActor();
|
||||||
@ -250,31 +248,6 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
|
|||||||
return Permissions.hasPermissionRange(this, "plots.cluster", Settings.Limit.MAX_PLOTS);
|
return Permissions.hasPermissionRange(this, "plots.cluster", Settings.Limit.MAX_PLOTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hasPermissionRange(String stub, int range) {
|
|
||||||
if (hasPermission(Captions.PERMISSION_ADMIN.getTranslated())) {
|
|
||||||
return Integer.MAX_VALUE;
|
|
||||||
}
|
|
||||||
String[] nodes = stub.split("\\.");
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
for (int i = 0; i < (nodes.length - 1); i++) {
|
|
||||||
builder.append(nodes[i]).append(".");
|
|
||||||
if (!stub.equals(builder + Captions.PERMISSION_STAR.getTranslated())) {
|
|
||||||
if (hasPermission(builder + Captions.PERMISSION_STAR.getTranslated())) {
|
|
||||||
return Integer.MAX_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hasPermission(stub + ".*")) {
|
|
||||||
return Integer.MAX_VALUE;
|
|
||||||
}
|
|
||||||
for (int i = range; i > 0; i--) {
|
|
||||||
if (hasPermission(stub + "." + i)) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of plots this player owns.
|
* Get the number of plots this player owns.
|
||||||
*
|
*
|
||||||
|
@ -1926,11 +1926,16 @@ public class Plot {
|
|||||||
DBFunc.createPlotAndSettings(this, () -> {
|
DBFunc.createPlotAndSettings(this, () -> {
|
||||||
PlotArea plotworld = Plot.this.area;
|
PlotArea plotworld = Plot.this.area;
|
||||||
if (notify && plotworld.isAutoMerge()) {
|
if (notify && plotworld.isAutoMerge()) {
|
||||||
PlotPlayer player = this.worldUtil.getPlayer(uuid);
|
final PlotPlayer<?> player = PlotSquared.platform().getPlayerManager()
|
||||||
|
.getPlayerIfExists(uuid);
|
||||||
|
|
||||||
PlotMergeEvent event = this.eventDispatcher
|
PlotMergeEvent event = this.eventDispatcher
|
||||||
.callMerge(this, Direction.ALL, Integer.MAX_VALUE, player);
|
.callMerge(this, Direction.ALL, Integer.MAX_VALUE, player);
|
||||||
|
|
||||||
if (event.getEventResult() == Result.DENY) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
Plot.this.autoMerge(event.getDir(), event.getMax(), uuid, true);
|
Plot.this.autoMerge(event.getDir(), event.getMax(), uuid, true);
|
||||||
@ -3083,10 +3088,10 @@ public class Plot {
|
|||||||
if (!TaskManager.removeFromTeleportQueue(name)) {
|
if (!TaskManager.removeFromTeleportQueue(name)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (player.isOnline()) {
|
try {
|
||||||
MainUtil.sendMessage(player, Captions.TELEPORTED_TO_PLOT);
|
MainUtil.sendMessage(player, Captions.TELEPORTED_TO_PLOT);
|
||||||
player.teleport(location, cause);
|
player.teleport(location, cause);
|
||||||
}
|
} catch (final Exception ignored) {}
|
||||||
}, TaskTime.seconds(Settings.Teleport.DELAY));
|
}, TaskTime.seconds(Settings.Teleport.DELAY));
|
||||||
resultConsumer.accept(true);
|
resultConsumer.accept(true);
|
||||||
};
|
};
|
||||||
|
@ -418,13 +418,13 @@ public class ExpireManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (UUID helper : plot.getTrusted()) {
|
for (UUID helper : plot.getTrusted()) {
|
||||||
PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper);
|
PlotPlayer<?> player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString());
|
MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (UUID helper : plot.getMembers()) {
|
for (UUID helper : plot.getMembers()) {
|
||||||
PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper);
|
PlotPlayer<?> player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString());
|
MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString());
|
||||||
}
|
}
|
||||||
|
@ -48,16 +48,4 @@ public abstract class EconHandler {
|
|||||||
|
|
||||||
public abstract void depositMoney(OfflinePlotPlayer player, double amount);
|
public abstract void depositMoney(OfflinePlotPlayer player, double amount);
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link PermHandler#hasPermission(String, String, String)} instead
|
|
||||||
*/
|
|
||||||
@Deprecated public abstract boolean hasPermission(String world, String player, String perm);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link PermHandler#hasPermission(String, String)} instead
|
|
||||||
*/
|
|
||||||
@Deprecated public boolean hasPermission(String player, String perm) {
|
|
||||||
return hasPermission(null, player, perm);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,15 +25,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.core.util;
|
package com.plotsquared.core.util;
|
||||||
|
|
||||||
import com.plotsquared.core.command.CommandCaller;
|
import com.plotsquared.core.configuration.Caption;
|
||||||
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.permissions.PermissionHolder;
|
||||||
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Permissions class handles checking user permissions.<br>
|
* The Permissions class handles checking user permissions.<br>
|
||||||
@ -42,80 +40,28 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class Permissions {
|
public class Permissions {
|
||||||
|
|
||||||
public static boolean hasPermission(PlotPlayer player, Captions caption, boolean notify) {
|
public static boolean hasPermission(PlotPlayer<?> player, Captions caption, boolean notify) {
|
||||||
return hasPermission(player, caption.getTranslated(), notify);
|
return hasPermission(player, caption.getTranslated(), notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a player has a permission (Captions class helps keep track of permissions).
|
* Check if the owner of the profile has a given (global) permission
|
||||||
*
|
*
|
||||||
* @param player
|
* @param permission Permission
|
||||||
* @param caption
|
* @return {@code true} if the owner has the given permission, else {@code false}
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static boolean hasPermission(PlotPlayer player, Captions caption) {
|
public static boolean hasPermission(@Nonnull final PermissionHolder caller, @Nonnull final Caption permission) {
|
||||||
return hasPermission(player, caption.getTranslated());
|
return caller.hasPermission(permission.getTranslated());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a {@link PlotPlayer} has a permission.
|
* Check if the owner of the profile has a given (global) permission
|
||||||
*
|
*
|
||||||
* @param player
|
* @param permission Permission
|
||||||
* @param permission
|
* @return {@code true} if the owner has the given permission, else {@code false}
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static boolean hasPermission(PlotPlayer<?> player, String permission) {
|
public static boolean hasPermission(@Nonnull final PermissionHolder caller, @Nonnull final String permission) {
|
||||||
if (!Settings.Enabled_Components.PERMISSION_CACHE) {
|
return caller.hasPermission(permission);
|
||||||
return hasPermission((CommandCaller) player, permission);
|
|
||||||
}
|
|
||||||
try (final MetaDataAccess<Map<String, Boolean>> mapAccess =
|
|
||||||
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_PERMISSIONS)) {
|
|
||||||
Map<String, Boolean> map = mapAccess.get().orElse(null);
|
|
||||||
if (map != null) {
|
|
||||||
final Boolean result = map.get(permission);
|
|
||||||
if (result != null) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mapAccess.set((map = new HashMap<>()));
|
|
||||||
}
|
|
||||||
boolean result = hasPermission((CommandCaller) player, permission);
|
|
||||||
map.put(permission, result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a {@code CommandCaller} has a permission.
|
|
||||||
*
|
|
||||||
* @param caller
|
|
||||||
* @param permission
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static boolean hasPermission(CommandCaller caller, String permission) {
|
|
||||||
if (caller.hasPermission(permission)) {
|
|
||||||
return true;
|
|
||||||
} else if (caller.isPermissionSet(permission)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (caller.hasPermission(Captions.PERMISSION_ADMIN.getTranslated())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
permission = permission.toLowerCase().replaceAll("^[^a-z|0-9|\\.|_|-]", "");
|
|
||||||
String[] nodes = permission.split("\\.");
|
|
||||||
StringBuilder n = new StringBuilder();
|
|
||||||
for (int i = 0; i <= (nodes.length - 1); i++) {
|
|
||||||
n.append(nodes[i] + ".");
|
|
||||||
String combined = n + Captions.PERMISSION_STAR.getTranslated();
|
|
||||||
if (!permission.equals(combined)) {
|
|
||||||
if (caller.hasPermission(combined)) {
|
|
||||||
return true;
|
|
||||||
} else if (caller.isPermissionSet(combined)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,7 +72,7 @@ public class Permissions {
|
|||||||
* @param notify
|
* @param notify
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean hasPermission(PlotPlayer player, String permission, boolean notify) {
|
public static boolean hasPermission(PlotPlayer<?> player, String permission, boolean notify) {
|
||||||
if (!hasPermission(player, permission)) {
|
if (!hasPermission(player, permission)) {
|
||||||
if (notify) {
|
if (notify) {
|
||||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION_EVENT, permission);
|
MainUtil.sendMessage(player, Captions.NO_PERMISSION_EVENT, permission);
|
||||||
@ -136,7 +82,7 @@ public class Permissions {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int hasPermissionRange(PlotPlayer player, Captions perm, int range) {
|
public static int hasPermissionRange(PlotPlayer<?> player, Captions perm, int range) {
|
||||||
return hasPermissionRange(player, perm.getTranslated(), range);
|
return hasPermissionRange(player, perm.getTranslated(), range);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,12 +91,12 @@ public class Permissions {
|
|||||||
* - Excessively high values will lag<br>
|
* - Excessively high values will lag<br>
|
||||||
* - The default range that is checked is {@link Settings.Limit#MAX_PLOTS}<br>
|
* - The default range that is checked is {@link Settings.Limit#MAX_PLOTS}<br>
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player Player to check for
|
||||||
* @param stub The permission stub to check e.g. for `plots.plot.#` the stub is `plots.plot`
|
* @param stub The permission stub to check e.g. for `plots.plot.#` the stub is `plots.plot`
|
||||||
* @param range The range to check
|
* @param range The range to check
|
||||||
* @return The highest permission they have within that range
|
* @return The highest permission they have within that range
|
||||||
*/
|
*/
|
||||||
public static int hasPermissionRange(PlotPlayer player, String stub, int range) {
|
public static int hasPermissionRange(PlotPlayer<?> player, String stub, int range) {
|
||||||
return player.hasPermissionRange(stub, range);
|
return player.hasPermissionRange(stub, range);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a plot player from a platform player object. This method requires
|
* Get a plot player from a platform player object. This method requires
|
||||||
* that the caller actually knows that the player exists.
|
* that the caller actually knows that the player exists and is online.
|
||||||
* <p>
|
* <p>
|
||||||
* The method will throw an exception if there is no such
|
* The method will throw an exception if there is no such
|
||||||
* player online.
|
* player online.
|
||||||
|
@ -328,14 +328,6 @@ public abstract class WorldUtil {
|
|||||||
*/
|
*/
|
||||||
public abstract boolean isBlockSame(@Nonnull BlockState block1, @Nonnull BlockState block2);
|
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
|
* Get the player health
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user