diff --git a/Bukkit/src/main/resources/plugin.yml b/Bukkit/src/main/resources/plugin.yml index 8b2cfd094..dc7a6045e 100644 --- a/Bukkit/src/main/resources/plugin.yml +++ b/Bukkit/src/main/resources/plugin.yml @@ -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: diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionUtility.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionUtility.java index 93f4275b1..28ff8b7b6 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionUtility.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionUtility.java @@ -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>> MINI_MESSAGE_FLAGS = Set.of( + private static final Set>> MINI_MESSAGE_FLAGS = Set.of( GreetingFlag.class, FarewellFlag.class, - DescriptionFlag.class + DescriptionFlag.class, + PlotTitleFlag.class ); private static final ComponentTransform CLICK_STRIP_TRANSFORM = nested( diff --git a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java index 13679d6d4..807a289c6 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java @@ -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 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); diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotTitle.java b/Core/src/main/java/com/plotsquared/core/plot/PlotTitle.java new file mode 100644 index 000000000..41b0d4002 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotTitle.java @@ -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 . + */ +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; + } +} diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java b/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java index e50a05331..34b97f6d0 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java @@ -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("")); diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/PlotTitleFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/PlotTitleFlag.java new file mode 100644 index 000000000..0d3a86a60 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/PlotTitleFlag.java @@ -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 . + */ +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 { + + 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); + } + +} diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 88fb57aee..9bf458c05 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -585,6 +585,7 @@ "flags.flag_description_tamed_interact": "Set to `true` to allow guests to interact with tamed animals in the plot.", "flags.flag_description_time": "Set the time in the plot to a fixed value.", "flags.flag_description_titles": "Set to `false` to disable plot titles. Can be set to: `none` (to inherit world settings), `true`, or `false`", + "flags.flag_description_title": "Set the pop-up title's title and subtitle. Format: /plot flag set title \"A title\" \"The subtitle\"", "flags.flag_description_use": "Define a list of materials players should be able to interact with in the plot.", "flags.flag_description_vehicle_break": "Set to `true` to allow guests to break vehicles in the plot.", "flags.flag_description_vehicle_cap": "Set to an integer value to limit the amount of vehicles on the plot.", @@ -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 \"A title\" \"The subtitle\".", "flags.area_flags": "Area flags: ", "flags.road_flags": "Road flags: ", "commands.description.add": "Allow a user to build in a plot while the plot owner is online.",