Finalize PlotListener

This commit is contained in:
Alexander Söderberg 2020-02-18 14:52:44 +01:00
parent 2fe00ef284
commit e4915407e7
4 changed files with 167 additions and 130 deletions

View File

@ -624,7 +624,7 @@ public enum Captions implements Caption {
FLAG_DESCRIPTION_TAMED_ATTACK("Set to `true` to allow guests to attack tamed animals in the plot.", "Flags"), FLAG_DESCRIPTION_TAMED_ATTACK("Set to `true` to allow guests to attack tamed animals in the plot.", "Flags"),
FLAG_DESCRIPTION_TAMED_INTERACT("Set to `true` to allow guests to interact with tamed animals in the plot.", "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_TIME("Set the time in the plot to a fixed value.", "Flags"),
FLAG_DESCRIPTION_TITLES("Set to `false` to disable plot titles.", "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_USE("Define a list of materials players should be able to interact with in the plot.", "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_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.", "Flags"), FLAG_DESCRIPTION_VEHICLE_CAP("Set to an integer value to limit the amount of vehicles on the plot.", "Flags"),

View File

@ -136,7 +136,6 @@ public final class GlobalFlagContainer extends FlagContainer {
this.addFlag(SoilDryFlag.SOIL_DRY_FALSE); this.addFlag(SoilDryFlag.SOIL_DRY_FALSE);
this.addFlag(TamedAttackFlag.TAMED_ATTACK_FALSE); this.addFlag(TamedAttackFlag.TAMED_ATTACK_FALSE);
this.addFlag(TamedInteractFlag.TAMED_INTERACT_FALSE); this.addFlag(TamedInteractFlag.TAMED_INTERACT_FALSE);
this.addFlag(TitlesFlag.TITLES_TRUE);
this.addFlag(VehicleBreakFlag.VEHICLE_BREAK_FALSE); this.addFlag(VehicleBreakFlag.VEHICLE_BREAK_FALSE);
this.addFlag(VehicleUseFlag.VEHICLE_USE_FALSE); this.addFlag(VehicleUseFlag.VEHICLE_USE_FALSE);
this.addFlag(VillagerInteractFlag.VILLAGER_INTERACT_FALSE); this.addFlag(VillagerInteractFlag.VILLAGER_INTERACT_FALSE);
@ -148,6 +147,7 @@ public final class GlobalFlagContainer extends FlagContainer {
// Enum Flags // Enum Flags
this.addFlag(PlotWeatherFlag.PLOT_WEATHER_FLAG_OFF); this.addFlag(PlotWeatherFlag.PLOT_WEATHER_FLAG_OFF);
this.addFlag(DenyTeleportFlag.DENY_TELEPORT_FLAG_NONE); this.addFlag(DenyTeleportFlag.DENY_TELEPORT_FLAG_NONE);
this.addFlag(TitlesFlag.TITLES_NONE);
// Integer flags // Integer flags
this.addFlag(AnimalCapFlag.ANIMAL_CAP_UNLIMITED); this.addFlag(AnimalCapFlag.ANIMAL_CAP_UNLIMITED);

View File

@ -1,20 +1,72 @@
package com.github.intellectualsites.plotsquared.plot.flags.implementations; package com.github.intellectualsites.plotsquared.plot.flags.implementations;
import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.flags.types.BooleanFlag; import com.github.intellectualsites.plotsquared.plot.flags.FlagParseException;
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class TitlesFlag extends BooleanFlag<TitlesFlag> { import java.util.Arrays;
import java.util.Locale;
public static final TitlesFlag TITLES_TRUE = new TitlesFlag(true); public class TitlesFlag extends PlotFlag<TitlesFlag.TitlesFlagValue, TitlesFlag> {
public static final TitlesFlag TITLES_FALSE = new TitlesFlag(false);
private TitlesFlag(boolean value) { public static final TitlesFlag TITLES_NONE = new TitlesFlag(TitlesFlagValue.NONE);
super(value, Captions.FLAG_DESCRIPTION_TITLES); public static final TitlesFlag TITLES_TRUE = new TitlesFlag(TitlesFlagValue.TRUE);
public static final TitlesFlag TITLES_FALSE = new TitlesFlag(TitlesFlagValue.FALSE);
private TitlesFlag(final TitlesFlagValue value) {
super(value, Captions.FLAG_CATEGORY_ENUM, Captions.FLAG_DESCRIPTION_TITLES);
} }
@Override protected TitlesFlag flagOf(@NotNull Boolean value) { @Override public TitlesFlag parse(@NotNull final String input) throws FlagParseException {
return value ? TITLES_TRUE : TITLES_FALSE; final TitlesFlagValue titlesFlagValue = TitlesFlagValue.fromString(input);
if (titlesFlagValue == null) {
throw new FlagParseException(this, input, Captions.FLAG_ERROR_ENUM,
Arrays.asList("none", "true", "false"));
}
return flagOf(titlesFlagValue);
}
@Override public TitlesFlag merge(@NotNull TitlesFlagValue newValue) {
if (newValue == TitlesFlagValue.TRUE || newValue == TitlesFlagValue.FALSE) {
return flagOf(newValue);
}
return this;
}
@Override public String toString() {
return getValue().name().toLowerCase(Locale.ENGLISH);
}
@Override public String getExample() {
return "true";
}
@Override protected TitlesFlag flagOf(@NotNull TitlesFlagValue value) {
if (value == TitlesFlagValue.TRUE) {
return TITLES_TRUE;
} else if (value == TitlesFlagValue.FALSE) {
return TITLES_FALSE;
}
return TITLES_NONE;
}
public enum TitlesFlagValue {
NONE,
TRUE,
FALSE;
@Nullable public static TitlesFlagValue fromString(final String value) {
if (value.equalsIgnoreCase("true")) {
return TRUE;
} else if (value.equalsIgnoreCase("false")) {
return FALSE;
} else if (value.equalsIgnoreCase("none")) {
return NONE;
}
return null;
}
} }
} }

View File

@ -2,9 +2,6 @@ package com.github.intellectualsites.plotsquared.plot.listener;
import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyExitFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyExitFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FarewellFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.FarewellFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag;
@ -37,7 +34,6 @@ import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.item.ItemTypes;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -59,27 +55,16 @@ public class PlotListener {
player.setMeta(PlotPlayer.META_LAST_PLOT, plot); player.setMeta(PlotPlayer.META_LAST_PLOT, plot);
EventUtil.manager.callEntry(player, plot); EventUtil.manager.callEntry(player, plot);
if (plot.hasOwner()) { if (plot.hasOwner()) {
// This will inherit values from PlotArea
final Collection<PlotFlag<?, ?>> plotFlags = plot.getApplicableFlags(false); final TitlesFlag.TitlesFlagValue titleFlag = plot.getFlag(TitlesFlag.class);
final boolean titles;
boolean titles; if (titleFlag == TitlesFlag.TitlesFlagValue.NONE) {
if (!plot.getArea().DEFAULT_FLAGS.isEmpty()) {
Boolean value = (Boolean) plot.getArea().DEFAULT_FLAGS.get(Flags.TITLES);
titles = value != null ? value : Settings.TITLES;
} else {
titles = Settings.TITLES; titles = Settings.TITLES;
}
String greeting;
if (flags.isEmpty()) {
if (titles) {
greeting = "";
} else { } else {
return true; titles = titleFlag == TitlesFlag.TitlesFlagValue.TRUE;
} }
} else {
titles = titles && plot.getFlag(TitlesFlag.class);
greeting = plot.getFlag(GreetingFlag.class); final String greeting = plot.getFlag(GreetingFlag.class);
if (!greeting.isEmpty()) { if (!greeting.isEmpty()) {
MainUtil MainUtil
.format(Captions.PREFIX_GREETING.getTranslated() + greeting, plot, player, .format(Captions.PREFIX_GREETING.getTranslated() + greeting, plot, player,
@ -180,7 +165,7 @@ public class PlotListener {
} }
} }
CommentManager.sendTitle(player, plot); CommentManager.sendTitle(player, plot);
}
if (titles && !player.getAttribute("disabletitles")) { if (titles && !player.getAttribute("disabletitles")) {
if (!Captions.TITLE_ENTERED_PLOT.getTranslated().isEmpty() if (!Captions.TITLE_ENTERED_PLOT.getTranslated().isEmpty()
|| !Captions.TITLE_ENTERED_PLOT_SUB.getTranslated().isEmpty()) { || !Captions.TITLE_ENTERED_PLOT_SUB.getTranslated().isEmpty()) {