2020-04-16 04:52:39 +02:00
|
|
|
/*
|
|
|
|
* _____ _ _ _____ _
|
|
|
|
* | __ \| | | | / ____| | |
|
|
|
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
|
|
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
|
|
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
|
|
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
|
|
|
* | |
|
|
|
|
* |_|
|
|
|
|
* PlotSquared plot management system for Minecraft
|
2022-01-02 22:22:19 +01:00
|
|
|
* Copyright (C) 2014 - 2022 IntellectualSites
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
|
|
|
* 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
|
2020-08-15 14:59:29 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-16 04:52:39 +02:00
|
|
|
*/
|
2020-04-11 02:19:18 +02:00
|
|
|
package com.plotsquared.bukkit.player;
|
2015-02-21 13:52:50 +01:00
|
|
|
|
2020-07-21 14:28:54 +02:00
|
|
|
import com.plotsquared.core.permissions.NullPermissionProfile;
|
|
|
|
import com.plotsquared.core.permissions.PermissionHandler;
|
|
|
|
import com.plotsquared.core.permissions.PermissionProfile;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.player.OfflinePlotPlayer;
|
2015-02-21 13:52:50 +01:00
|
|
|
import org.bukkit.OfflinePlayer;
|
2021-01-09 22:28:41 +01:00
|
|
|
import org.checkerframework.checker.index.qual.NonNegative;
|
|
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
2015-02-21 13:52:50 +01:00
|
|
|
|
2016-03-23 02:41:37 +01:00
|
|
|
import java.util.UUID;
|
2015-07-27 19:50:04 +02:00
|
|
|
|
2015-09-13 06:04:31 +02:00
|
|
|
public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
2016-03-23 18:09:13 +01:00
|
|
|
|
2015-02-23 02:32:27 +01:00
|
|
|
public final OfflinePlayer player;
|
2020-07-21 14:28:54 +02:00
|
|
|
private final PermissionProfile permissionProfile;
|
2016-03-23 18:09:13 +01:00
|
|
|
|
2015-02-21 13:52:50 +01:00
|
|
|
/**
|
2016-06-01 22:50:35 +02:00
|
|
|
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player),
|
|
|
|
* as it caches player objects.
|
2020-08-16 12:34:08 +02:00
|
|
|
*
|
2021-01-09 22:28:41 +01:00
|
|
|
* @param player Bukkit OfflinePlayer player to convert
|
2020-08-16 12:34:08 +02:00
|
|
|
* @param permissionHandler Permission Profile to be used
|
2015-02-21 13:52:50 +01:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public BukkitOfflinePlayer(
|
|
|
|
final @NonNull OfflinePlayer player, final @NonNull
|
|
|
|
PermissionHandler permissionHandler
|
|
|
|
) {
|
2015-02-21 13:52:50 +01:00
|
|
|
this.player = player;
|
2020-07-21 14:28:54 +02:00
|
|
|
this.permissionProfile = permissionHandler.getPermissionProfile(this)
|
2021-01-09 22:28:41 +01:00
|
|
|
.orElse(NullPermissionProfile.INSTANCE);
|
2015-02-21 13:52:50 +01:00
|
|
|
}
|
2016-03-23 18:09:13 +01:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public UUID getUUID() {
|
2016-03-23 02:41:37 +01:00
|
|
|
return this.player.getUniqueId();
|
2015-02-21 13:52:50 +01:00
|
|
|
}
|
2016-03-23 18:09:13 +01:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
@NonNegative
|
|
|
|
public long getLastPlayed() {
|
2020-07-23 12:47:00 +02:00
|
|
|
return this.player.getLastSeen();
|
2015-02-21 13:52:50 +01:00
|
|
|
}
|
2016-03-23 18:09:13 +01:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public String getName() {
|
2016-03-23 02:41:37 +01:00
|
|
|
return this.player.getName();
|
2015-02-21 13:52:50 +01:00
|
|
|
}
|
2020-07-21 14:28:54 +02:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public boolean hasPermission(
|
|
|
|
final @Nullable String world,
|
|
|
|
final @NonNull String permission
|
|
|
|
) {
|
2020-07-22 12:35:48 +02:00
|
|
|
return this.permissionProfile.hasPermission(world, permission);
|
2020-07-21 14:28:54 +02:00
|
|
|
}
|
|
|
|
|
2021-08-14 15:13:01 +02:00
|
|
|
@Override
|
|
|
|
public boolean hasKeyedPermission(
|
|
|
|
final @Nullable String world,
|
|
|
|
final @NonNull String stub,
|
|
|
|
final @NonNull String key
|
|
|
|
) {
|
2021-08-18 11:58:18 +02:00
|
|
|
return this.permissionProfile.hasPermission(world, stub + "." + key) || this.permissionProfile.hasPermission(
|
|
|
|
world,
|
|
|
|
stub + ".*"
|
|
|
|
);
|
2021-08-14 15:13:01 +02:00
|
|
|
}
|
|
|
|
|
2015-02-21 13:52:50 +01:00
|
|
|
}
|