use of com.plotsquared.core.util.PlayerManager in project PlotSquared by IntellectualSites.
the class Owner method set.
@Override
public boolean set(final PlotPlayer<?> player, final Plot plot, String value) {
if (value == null || value.isEmpty()) {
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", "/plot setowner <owner>"));
return false;
}
@Nullable final UUID oldOwner = plot.getOwnerAbs();
Set<Plot> plots = plot.getConnectedPlots();
final Consumer<UUID> uuidConsumer = uuid -> {
if (uuid == null && !value.equalsIgnoreCase("none") && !value.equalsIgnoreCase("null") && !value.equalsIgnoreCase("-")) {
player.sendMessage(TranslatableCaption.of("errors.invalid_player"), Template.of("value", value));
return;
}
PlotChangeOwnerEvent event = this.eventDispatcher.callOwnerChange(player, plot, plot.hasOwner() ? plot.getOwnerAbs() : null, uuid, plot.hasOwner());
if (event.getEventResult() == Result.DENY) {
player.sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Owner change"));
return;
}
uuid = event.getNewOwner();
boolean force = event.getEventResult() == Result.FORCE;
if (uuid == null) {
if (!force && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_SET_OWNER, true)) {
return;
}
PlotUnlinkEvent unlinkEvent = this.eventDispatcher.callUnlink(plot.getArea(), plot, false, false, PlotUnlinkEvent.REASON.NEW_OWNER);
if (unlinkEvent.getEventResult() == Result.DENY) {
player.sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Unlink on owner change"));
return;
}
if (plot.getPlotModificationManager().unlinkPlot(unlinkEvent.isCreateRoad(), unlinkEvent.isCreateRoad())) {
eventDispatcher.callPostUnlink(plot, PlotUnlinkEvent.REASON.NEW_OWNER);
}
Set<Plot> connected = plot.getConnectedPlots();
for (Plot current : connected) {
current.unclaim();
current.getPlotModificationManager().removeSign();
}
eventDispatcher.callPostOwnerChange(player, plot, oldOwner);
player.sendMessage(TranslatableCaption.of("owner.set_owner"));
return;
}
final PlotPlayer<?> other = PlotSquared.platform().playerManager().getPlayerIfExists(uuid);
if (plot.isOwner(uuid)) {
player.sendMessage(TranslatableCaption.of("member.already_owner"), Template.of("player", PlayerManager.resolveName(uuid, false).getComponent(player)));
return;
}
if (!force && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_SET_OWNER)) {
if (other == null) {
player.sendMessage(TranslatableCaption.of("errors.invalid_player_offline"), Template.of("player", PlayerManager.resolveName(uuid).getComponent(player)));
return;
}
int size = plots.size();
int currentPlots = (Settings.Limit.GLOBAL ? other.getPlotCount() : other.getPlotCount(plot.getWorldName())) + size;
try (final MetaDataAccess<Integer> metaDataAccess = player.accessPersistentMetaData(PlayerMetaDataKeys.PERSISTENT_GRANTED_PLOTS)) {
int grants;
if (currentPlots >= other.getAllowedPlots()) {
if (metaDataAccess.isPresent()) {
grants = metaDataAccess.get().orElse(0);
if (grants <= 0) {
metaDataAccess.remove();
player.sendMessage(TranslatableCaption.of("permission.cant_transfer_more_plots"));
return;
}
}
}
}
}
final UUID finalUUID = uuid;
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(uuid, (finalName, throwable) -> {
final boolean removeDenied = plot.isDenied(finalUUID);
Runnable run = () -> {
if (plot.setOwner(finalUUID, player)) {
if (removeDenied) {
plot.removeDenied(finalUUID);
}
plot.getPlotModificationManager().setSign(finalName);
player.sendMessage(TranslatableCaption.of("owner.set_owner"));
eventDispatcher.callPostOwnerChange(player, plot, oldOwner);
if (other != null) {
other.sendMessage(TranslatableCaption.of("owner.now_owner"), Template.of("plot", plot.getArea() + ";" + plot.getId()));
}
} else {
player.sendMessage(TranslatableCaption.of("owner.set_owner_cancelled"));
}
};
if (hasConfirmation(player)) {
CmdConfirm.addPending(player, "/plot setowner " + value, run);
} else {
TaskManager.runTask(run);
}
});
};
if (value.length() == 36) {
try {
uuidConsumer.accept(UUID.fromString(value));
} catch (Exception ignored) {
}
} else {
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(value, (uuid, throwable) -> uuidConsumer.accept(uuid));
}
return true;
}
use of com.plotsquared.core.util.PlayerManager in project PlotSquared by IntellectualSites.
the class PlotListener method plotEntry.
public boolean plotEntry(final PlotPlayer<?> player, final Plot plot) {
if (plot.isDenied(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.entry.denied")) {
player.sendMessage(TranslatableCaption.of("deny.no_enter"), Template.of("plot", plot.toString()));
return false;
}
try (final MetaDataAccess<Plot> lastPlot = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
Plot last = lastPlot.get().orElse(null);
if ((last != null) && !last.getId().equals(plot.getId())) {
plotExit(player, last);
}
if (ExpireManager.IMP != null) {
ExpireManager.IMP.handleEntry(player, plot);
}
lastPlot.set(plot);
}
this.eventDispatcher.callEntry(player, plot);
if (plot.hasOwner()) {
// This will inherit values from PlotArea
final TitlesFlag.TitlesFlagValue titlesFlag = plot.getFlag(TitlesFlag.class);
final boolean titles;
if (titlesFlag == TitlesFlag.TitlesFlagValue.NONE) {
titles = Settings.Titles.DISPLAY_TITLES;
} else {
titles = titlesFlag == TitlesFlag.TitlesFlagValue.TRUE;
}
String greeting = plot.getFlag(GreetingFlag.class);
if (!greeting.isEmpty()) {
if (!Settings.Chat.NOTIFICATION_AS_ACTIONBAR) {
plot.format(StaticCaption.of(greeting), player, false).thenAcceptAsync(player::sendMessage);
} else {
plot.format(StaticCaption.of(greeting), player, false).thenAcceptAsync(player::sendActionBar);
}
}
if (plot.getFlag(NotifyEnterFlag.class)) {
if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) {
for (UUID uuid : plot.getOwners()) {
final PlotPlayer<?> owner = PlotSquared.platform().playerManager().getPlayerIfExists(uuid);
if (owner != null && !owner.getUUID().equals(player.getUUID()) && owner.canSee(player)) {
Caption caption = TranslatableCaption.of("notification.notify_enter");
notifyPlotOwner(player, plot, owner, caption);
}
}
}
}
final FlyFlag.FlyStatus flyStatus = plot.getFlag(FlyFlag.class);
if (!Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_FLIGHT)) {
if (flyStatus != FlyFlag.FlyStatus.DEFAULT) {
boolean flight = player.getFlight();
GameMode gamemode = player.getGameMode();
if (flight != (gamemode == GameModes.CREATIVE || gamemode == GameModes.SPECTATOR)) {
try (final MetaDataAccess<Boolean> metaDataAccess = player.accessPersistentMetaData(PlayerMetaDataKeys.PERSISTENT_FLIGHT)) {
metaDataAccess.set(player.getFlight());
}
}
player.setFlight(flyStatus == FlyFlag.FlyStatus.ENABLED);
}
}
final GameMode gameMode = plot.getFlag(GamemodeFlag.class);
if (!gameMode.equals(GamemodeFlag.DEFAULT)) {
if (player.getGameMode() != gameMode) {
if (!Permissions.hasPermission(player, "plots.gamemode.bypass")) {
player.setGameMode(gameMode);
} else {
player.sendMessage(TranslatableCaption.of("gamemode.gamemode_was_bypassed"), Template.of("gamemode", String.valueOf(gameMode)), Template.of("plot", plot.getId().toString()));
}
}
}
final GameMode guestGameMode = plot.getFlag(GuestGamemodeFlag.class);
if (!guestGameMode.equals(GamemodeFlag.DEFAULT)) {
if (player.getGameMode() != guestGameMode && !plot.isAdded(player.getUUID())) {
if (!Permissions.hasPermission(player, "plots.gamemode.bypass")) {
player.setGameMode(guestGameMode);
} else {
player.sendMessage(TranslatableCaption.of("gamemode.gamemode_was_bypassed"), Template.of("gamemode", String.valueOf(guestGameMode)), Template.of("plot", plot.getId().toString()));
}
}
}
long time = plot.getFlag(TimeFlag.class);
if (time != TimeFlag.TIME_DISABLED.getValue() && !player.getAttribute("disabletime")) {
try {
player.setTime(time);
} catch (Exception ignored) {
PlotFlag<?, ?> plotFlag = GlobalFlagContainer.getInstance().getFlag(TimeFlag.class);
PlotFlagRemoveEvent event = this.eventDispatcher.callFlagRemove(plotFlag, plot);
if (event.getEventResult() != Result.DENY) {
plot.removeFlag(event.getFlag());
}
}
}
player.setWeather(plot.getFlag(WeatherFlag.class));
ItemType musicFlag = plot.getFlag(MusicFlag.class);
try (final MetaDataAccess<Location> musicMeta = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_MUSIC)) {
if (musicFlag != null) {
final String rawId = musicFlag.getId();
if (rawId.contains("disc") || musicFlag == ItemTypes.AIR) {
Location location = player.getLocation();
Location lastLocation = musicMeta.get().orElse(null);
if (lastLocation != null) {
plot.getCenter(center -> player.playMusic(center.add(0, Short.MAX_VALUE, 0), musicFlag));
if (musicFlag == ItemTypes.AIR) {
musicMeta.remove();
}
}
if (musicFlag != ItemTypes.AIR) {
try {
musicMeta.set(location);
plot.getCenter(center -> player.playMusic(center.add(0, Short.MAX_VALUE, 0), musicFlag));
} catch (Exception ignored) {
}
}
}
} else {
musicMeta.get().ifPresent(lastLoc -> {
musicMeta.remove();
player.playMusic(lastLoc, ItemTypes.AIR);
});
}
}
CommentManager.sendTitle(player, plot);
if (titles && !player.getAttribute("disabletitles")) {
String title;
String subtitle;
PlotTitle titleFlag = plot.getFlag(PlotTitleFlag.class);
boolean fromFlag;
if (titleFlag.title() != null && titleFlag.subtitle() != null) {
title = titleFlag.title();
subtitle = titleFlag.subtitle();
fromFlag = true;
} else {
title = "";
subtitle = "";
fromFlag = false;
}
if (fromFlag || !plot.getFlag(ServerPlotFlag.class) || Settings.Titles.DISPLAY_DEFAULT_ON_SERVER_PLOT) {
TaskManager.runTaskLaterAsync(() -> {
Plot lastPlot;
try (final MetaDataAccess<Plot> lastPlotAccess = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
lastPlot = lastPlotAccess.get().orElse(null);
}
if ((lastPlot != null) && plot.getId().equals(lastPlot.getId()) && plot.hasOwner()) {
final UUID plotOwner = plot.getOwnerAbs();
String owner = PlayerManager.resolveName(plotOwner, true).getComponent(player);
Caption header = fromFlag ? StaticCaption.of(title) : TranslatableCaption.of("titles" + ".title_entered_plot");
Caption subHeader = fromFlag ? StaticCaption.of(subtitle) : TranslatableCaption.of("titles" + ".title_entered_plot_sub");
Template plotTemplate = Template.of("plot", lastPlot.getId().toString());
Template worldTemplate = Template.of("world", player.getLocation().getWorldName());
Template ownerTemplate = Template.of("owner", owner);
Template aliasTemplate = Template.of("alias", plot.getAlias());
final Consumer<String> userConsumer = user -> {
if (Settings.Titles.TITLES_AS_ACTIONBAR) {
player.sendActionBar(header, aliasTemplate, plotTemplate, worldTemplate, ownerTemplate);
} else {
player.sendTitle(header, subHeader, aliasTemplate, plotTemplate, worldTemplate, ownerTemplate);
}
};
UUID uuid = plot.getOwner();
if (uuid == null) {
userConsumer.accept("Unknown");
} else if (uuid.equals(DBFunc.SERVER)) {
userConsumer.accept(MINI_MESSAGE.stripTokens(TranslatableCaption.of("info.server").getComponent(player)));
} else {
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(plot.getOwner(), (user, throwable) -> {
if (throwable != null) {
userConsumer.accept("Unknown");
} else {
userConsumer.accept(user);
}
});
}
}
}, TaskTime.seconds(1L));
}
}
TimedFlag.Timed<Integer> feed = plot.getFlag(FeedFlag.class);
if (feed.getInterval() != 0 && feed.getValue() != 0) {
feedRunnable.put(player.getUUID(), new Interval(feed.getInterval(), feed.getValue(), 20));
}
TimedFlag.Timed<Integer> heal = plot.getFlag(HealFlag.class);
if (heal.getInterval() != 0 && heal.getValue() != 0) {
healRunnable.put(player.getUUID(), new Interval(heal.getInterval(), heal.getValue(), 20));
}
return true;
}
return true;
}
Aggregations