2020-04-16 04:52:39 +02:00
|
|
|
/*
|
2022-06-15 20:17:17 +02:00
|
|
|
* PlotSquared, a land and world management plugin for Minecraft.
|
|
|
|
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
|
|
|
* Copyright (C) IntellectualSites team and contributors
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +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.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* 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.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-16 04:52:39 +02:00
|
|
|
*/
|
2020-05-19 00:28:52 +02:00
|
|
|
package com.plotsquared.bukkit.player;
|
2014-12-16 05:58:54 +01:00
|
|
|
|
2020-07-10 22:12:37 +02:00
|
|
|
import com.google.inject.Inject;
|
|
|
|
import com.google.inject.Singleton;
|
2020-07-21 14:28:54 +02:00
|
|
|
import com.plotsquared.core.permissions.PermissionHandler;
|
2020-07-10 17:32:07 +02:00
|
|
|
import com.plotsquared.core.plot.world.PlotAreaManager;
|
2020-07-10 18:17:44 +02:00
|
|
|
import com.plotsquared.core.util.EventDispatcher;
|
2020-05-19 00:28:52 +02:00
|
|
|
import com.plotsquared.core.util.PlayerManager;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.entity.Player;
|
2021-01-09 22:28:41 +01:00
|
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
2014-12-16 05:58:54 +01:00
|
|
|
|
2016-03-23 18:16:05 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2020-05-19 00:28:52 +02:00
|
|
|
/**
|
|
|
|
* Player manager providing {@link BukkitPlayer Bukkit players}
|
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
@Singleton
|
|
|
|
public class BukkitPlayerManager extends PlayerManager<BukkitPlayer, Player> {
|
2020-05-27 14:08:48 +02:00
|
|
|
|
2020-07-10 17:32:07 +02:00
|
|
|
private final PlotAreaManager plotAreaManager;
|
2020-07-10 18:17:44 +02:00
|
|
|
private final EventDispatcher eventDispatcher;
|
2020-07-21 14:28:54 +02:00
|
|
|
private final PermissionHandler permissionHandler;
|
2020-07-10 17:32:07 +02:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Inject
|
|
|
|
public BukkitPlayerManager(
|
|
|
|
final @NonNull PlotAreaManager plotAreaManager,
|
|
|
|
final @NonNull EventDispatcher eventDispatcher,
|
|
|
|
final @NonNull PermissionHandler permissionHandler
|
|
|
|
) {
|
2020-07-10 22:12:37 +02:00
|
|
|
this.plotAreaManager = plotAreaManager;
|
|
|
|
this.eventDispatcher = eventDispatcher;
|
2020-07-21 14:28:54 +02:00
|
|
|
this.permissionHandler = permissionHandler;
|
2020-07-10 22:12:37 +02:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@NonNull
|
|
|
|
@Override
|
2023-01-12 10:03:11 +01:00
|
|
|
@SuppressWarnings("deprecation")
|
2021-01-09 22:28:41 +01:00
|
|
|
public BukkitPlayer getPlayer(final @NonNull Player object) {
|
2021-06-22 10:18:48 +02:00
|
|
|
if (object.getUniqueId().version() == 2) { // not a real player
|
|
|
|
return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, object, false, this.permissionHandler);
|
|
|
|
}
|
2020-07-23 12:47:00 +02:00
|
|
|
if (!object.isOnline()) {
|
|
|
|
throw new NoSuchPlayerException(object.getUniqueId());
|
|
|
|
}
|
2021-06-22 10:18:48 +02:00
|
|
|
return getPlayer(object.getUniqueId());
|
2020-05-27 14:08:48 +02:00
|
|
|
}
|
2016-03-23 18:16:05 +01:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
2023-01-12 10:03:11 +01:00
|
|
|
@SuppressWarnings("deprecation")
|
2021-01-09 22:28:41 +01:00
|
|
|
public @NonNull BukkitPlayer createPlayer(final @NonNull UUID uuid) {
|
2020-05-19 00:28:52 +02:00
|
|
|
final Player player = Bukkit.getPlayer(uuid);
|
|
|
|
if (player == null || !player.isOnline()) {
|
|
|
|
throw new NoSuchPlayerException(uuid);
|
|
|
|
}
|
2020-08-23 00:13:00 +02:00
|
|
|
return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, player, this.permissionHandler);
|
2020-05-19 00:28:52 +02:00
|
|
|
}
|
2016-02-10 19:59:51 +01:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public BukkitOfflinePlayer getOfflinePlayer(final @Nullable UUID uuid) {
|
2020-05-19 23:05:36 +02:00
|
|
|
if (uuid == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2020-07-21 14:28:54 +02:00
|
|
|
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid), this.permissionHandler);
|
2020-05-19 23:05:36 +02:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public BukkitOfflinePlayer getOfflinePlayer(final @NonNull String username) {
|
2020-07-21 14:28:54 +02:00
|
|
|
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(username), this.permissionHandler);
|
2020-05-19 23:05:36 +02:00
|
|
|
}
|
|
|
|
|
2014-12-16 05:58:54 +01:00
|
|
|
}
|