mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-21 20:56:45 +01:00
Add TitleFlag (#3202)
This commit is contained in:
parent
eb2848e5d7
commit
33a79595af
@ -392,6 +392,7 @@ permissions:
|
||||
plots.set.flag.price: true
|
||||
plots.set.flag.no-worldedit: true
|
||||
plots.set.flag.no-worldedit.*: true
|
||||
plots.set.flag.titleflag.*: true
|
||||
plots.permpack.basicinbox:
|
||||
default: false
|
||||
children:
|
||||
|
@ -32,6 +32,7 @@ import com.plotsquared.core.plot.flag.implementations.DescriptionFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.FarewellFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.GreetingFlag;
|
||||
import com.plotsquared.core.plot.flag.types.StringFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.PlotTitleFlag;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
@ -46,10 +47,11 @@ import static com.plotsquared.core.configuration.caption.ComponentTransform.stri
|
||||
public class CaptionUtility {
|
||||
|
||||
// flags which values are parsed by minimessage
|
||||
private static final Set<Class<? extends StringFlag<?>>> MINI_MESSAGE_FLAGS = Set.of(
|
||||
private static final Set<Class<? extends PlotFlag<?, ?>>> MINI_MESSAGE_FLAGS = Set.of(
|
||||
GreetingFlag.class,
|
||||
FarewellFlag.class,
|
||||
DescriptionFlag.class
|
||||
DescriptionFlag.class,
|
||||
PlotTitleFlag.class
|
||||
);
|
||||
|
||||
private static final ComponentTransform CLICK_STRIP_TRANSFORM = nested(
|
||||
|
@ -41,6 +41,7 @@ import com.plotsquared.core.player.PlayerMetaDataKeys;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotTitle;
|
||||
import com.plotsquared.core.plot.PlotWeather;
|
||||
import com.plotsquared.core.plot.comment.CommentManager;
|
||||
import com.plotsquared.core.plot.expiration.ExpireManager;
|
||||
@ -57,6 +58,7 @@ import com.plotsquared.core.plot.flag.implementations.HealFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.MusicFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.NotifyEnterFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.NotifyLeaveFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.PlotTitleFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.TimeFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.TitlesFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.WeatherFlag;
|
||||
@ -161,12 +163,12 @@ public class PlotListener {
|
||||
this.eventDispatcher.callEntry(player, plot);
|
||||
if (plot.hasOwner()) {
|
||||
// This will inherit values from PlotArea
|
||||
final TitlesFlag.TitlesFlagValue titleFlag = plot.getFlag(TitlesFlag.class);
|
||||
final TitlesFlag.TitlesFlagValue titlesFlag = plot.getFlag(TitlesFlag.class);
|
||||
final boolean titles;
|
||||
if (titleFlag == TitlesFlag.TitlesFlagValue.NONE) {
|
||||
if (titlesFlag == TitlesFlag.TitlesFlagValue.NONE) {
|
||||
titles = Settings.Titles.DISPLAY_TITLES;
|
||||
} else {
|
||||
titles = titleFlag == TitlesFlag.TitlesFlagValue.TRUE;
|
||||
titles = titlesFlag == TitlesFlag.TitlesFlagValue.TRUE;
|
||||
}
|
||||
|
||||
String greeting = plot.getFlag(GreetingFlag.class);
|
||||
@ -291,11 +293,20 @@ public class PlotListener {
|
||||
CommentManager.sendTitle(player, plot);
|
||||
|
||||
if (titles && !player.getAttribute("disabletitles")) {
|
||||
if (!TranslatableCaption.of("titles.title_entered_plot").getComponent(ConsolePlayer.getConsole()).isEmpty()
|
||||
|| !TranslatableCaption
|
||||
.of("titles.title_entered_plot_sub")
|
||||
.getComponent(ConsolePlayer.getConsole())
|
||||
.isEmpty()) {
|
||||
String title;
|
||||
String subtitle;
|
||||
PlotTitle titleFlag = plot.getFlag(PlotTitleFlag.class);
|
||||
boolean fromFlag;
|
||||
if (!titleFlag.title().isEmpty() && !titleFlag.subtitle().isEmpty()) {
|
||||
title = titleFlag.title();
|
||||
subtitle = titleFlag.subtitle();
|
||||
fromFlag = true;
|
||||
} else {
|
||||
title = TranslatableCaption.of("titles.title_entered_plot").getComponent(ConsolePlayer.getConsole());
|
||||
subtitle = TranslatableCaption.of("titles.title_entered_plot_sub").getComponent(ConsolePlayer.getConsole());
|
||||
fromFlag = false;
|
||||
}
|
||||
if (!title.isEmpty() && !subtitle.isEmpty()) {
|
||||
TaskManager.runTaskLaterAsync(() -> {
|
||||
Plot lastPlot;
|
||||
try (final MetaDataAccess<Plot> lastPlotAccess =
|
||||
@ -305,8 +316,10 @@ public class PlotListener {
|
||||
if ((lastPlot != null) && plot.getId().equals(lastPlot.getId()) && plot.hasOwner()) {
|
||||
final UUID plotOwner = plot.getOwnerAbs();
|
||||
String owner = PlayerManager.getName(plotOwner, false);
|
||||
Caption header = TranslatableCaption.of("titles.title_entered_plot");
|
||||
Caption subHeader = TranslatableCaption.of("titles.title_entered_plot_sub");
|
||||
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);
|
||||
|
49
Core/src/main/java/com/plotsquared/core/plot/PlotTitle.java
Normal file
49
Core/src/main/java/com/plotsquared/core/plot/PlotTitle.java
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.core.plot;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class PlotTitle {
|
||||
|
||||
private final String title;
|
||||
private final String subtitle;
|
||||
|
||||
public PlotTitle(String title, String subtitle) {
|
||||
Objects.requireNonNull(title);
|
||||
Objects.requireNonNull(subtitle);
|
||||
this.title = title;
|
||||
this.subtitle = subtitle;
|
||||
}
|
||||
|
||||
public String title() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String subtitle() {
|
||||
return subtitle;
|
||||
}
|
||||
}
|
@ -90,6 +90,7 @@ import com.plotsquared.core.plot.flag.implementations.NotifyEnterFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.NotifyLeaveFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.PlaceFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.PlayerInteractFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.PlotTitleFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.PreventCreativeCopyFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.PriceFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.PveFlag;
|
||||
@ -137,9 +138,6 @@ public final class GlobalFlagContainer extends FlagContainer {
|
||||
this.addFlag(ExplosionFlag.EXPLOSION_FALSE);
|
||||
this.addFlag(UntrustedVisitFlag.UNTRUSTED_VISIT_FLAG_TRUE);
|
||||
this.addFlag(DenyExitFlag.DENY_EXIT_FLAG_FALSE);
|
||||
this.addFlag(DescriptionFlag.DESCRIPTION_FLAG_EMPTY);
|
||||
this.addFlag(GreetingFlag.GREETING_FLAG_EMPTY);
|
||||
this.addFlag(FarewellFlag.FAREWELL_FLAG_EMPTY);
|
||||
this.addFlag(AnimalAttackFlag.ANIMAL_ATTACK_FALSE);
|
||||
this.addFlag(AnimalInteractFlag.ANIMAL_INTERACT_FALSE);
|
||||
this.addFlag(BlockBurnFlag.BLOCK_BURN_FALSE);
|
||||
@ -231,6 +229,12 @@ public final class GlobalFlagContainer extends FlagContainer {
|
||||
this.addFlag(KeepFlag.KEEP_FLAG_FALSE);
|
||||
this.addFlag(MusicFlag.MUSIC_FLAG_NONE);
|
||||
|
||||
// String flags
|
||||
this.addFlag(DescriptionFlag.DESCRIPTION_FLAG_EMPTY);
|
||||
this.addFlag(GreetingFlag.GREETING_FLAG_EMPTY);
|
||||
this.addFlag(FarewellFlag.FAREWELL_FLAG_EMPTY);
|
||||
this.addFlag(PlotTitleFlag.TITLE_FLAG_EMPTY);
|
||||
|
||||
// Internal flags
|
||||
this.addFlag(new AnalysisFlag(Collections.emptyList()));
|
||||
this.addFlag(new DoneFlag(""));
|
||||
|
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.core.plot.flag.implementations;
|
||||
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.plot.PlotTitle;
|
||||
import com.plotsquared.core.plot.flag.FlagParseException;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class PlotTitleFlag extends PlotFlag<PlotTitle, PlotTitleFlag> {
|
||||
|
||||
public static final PlotTitleFlag TITLE_FLAG_EMPTY = new PlotTitleFlag(new PlotTitle("", ""));
|
||||
|
||||
/**
|
||||
* Construct a new flag instance.
|
||||
*
|
||||
* @param value Flag value
|
||||
*/
|
||||
protected PlotTitleFlag(PlotTitle value) {
|
||||
super(value, TranslatableCaption.of("flags.flag_category_string"), TranslatableCaption.of("flags.flag_description_title"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotTitleFlag parse(@NonNull String input) throws FlagParseException {
|
||||
if (!input.contains("\"")) {
|
||||
return new PlotTitleFlag(new PlotTitle(input, ""));
|
||||
}
|
||||
input = input.substring(input.indexOf("\""));
|
||||
input = input.substring(0, input.lastIndexOf("\"") + 1);
|
||||
String[] inputs = input.split("\"");
|
||||
PlotTitle value;
|
||||
if (inputs.length == 2) {
|
||||
value = new PlotTitle(inputs[1], "");
|
||||
} else if (inputs.length > 3) {
|
||||
value = new PlotTitle(inputs[1], inputs[3]);
|
||||
} else {
|
||||
throw new FlagParseException(this, input, TranslatableCaption.of("flags.flag_error_title"));
|
||||
}
|
||||
return new PlotTitleFlag(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotTitleFlag merge(@NonNull PlotTitle newValue) {
|
||||
if (getValue().title().isEmpty() && getValue().subtitle().isEmpty()) {
|
||||
return new PlotTitleFlag(newValue);
|
||||
} else if (getValue().subtitle().isEmpty()) {
|
||||
return new PlotTitleFlag(new PlotTitle(getValue().title(), newValue.subtitle()));
|
||||
} else if (getValue().title().isEmpty()) {
|
||||
return new PlotTitleFlag(new PlotTitle(newValue.title(), getValue().subtitle()));
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "\"" + getValue().title() + "\" \"" + getValue().subtitle() + "\"";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValuedPermission() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExample() {
|
||||
return "\"A Title\" \"The subtitle\"";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PlotTitleFlag flagOf(@NonNull PlotTitle value) {
|
||||
return new PlotTitleFlag(value);
|
||||
}
|
||||
|
||||
}
|
@ -585,6 +585,7 @@
|
||||
"flags.flag_description_tamed_interact": "<gray>Set to `true` to allow guests to interact with tamed animals in the plot.</gray>",
|
||||
"flags.flag_description_time": "<gray>Set the time in the plot to a fixed value.</gray>",
|
||||
"flags.flag_description_titles": "<gray>Set to `false` to disable plot titles. Can be set to: `none` (to inherit world settings), `true`, or `false`</gray>",
|
||||
"flags.flag_description_title": "<gray>Set the pop-up title's title and subtitle. Format: /plot flag set title \"A title\" \"The subtitle\"</gray>",
|
||||
"flags.flag_description_use": "<gray>Define a list of materials players should be able to interact with in the plot.</gray>",
|
||||
"flags.flag_description_vehicle_break": "<gray>Set to `true` to allow guests to break vehicles in the plot.</gray>",
|
||||
"flags.flag_description_vehicle_cap": "<gray>Set to an integer value to limit the amount of vehicles on the plot.</gray>",
|
||||
@ -611,6 +612,7 @@
|
||||
"flags.flag_error_invalid_block": "The provided value is not a valid block or block category.",
|
||||
"flags.flag_error_double": "Flag value must be a decimal number.",
|
||||
"flags.flag_error_music": "Flag value must be a valid music disc ID.",
|
||||
"flags.flag_error_title": "Flag value must be in the format </red><grey>\"A title\" \"The subtitle\"</grey><red>.",
|
||||
"flags.area_flags": "<prefix><gray>Area flags: </gray><dark_aqua><flags></dark_aqua>",
|
||||
"flags.road_flags": "<prefix><gray>Road flags: </gray><dark_aqua><flags></dark_aqua>",
|
||||
"commands.description.add": "<gray>Allow a user to build in a plot while the plot owner is online.</gray>",
|
||||
|
Loading…
Reference in New Issue
Block a user