mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 15:16:45 +01:00
Finalize PlotListener
This commit is contained in:
parent
2fe00ef284
commit
e4915407e7
@ -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_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.", "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_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"),
|
||||
|
@ -136,7 +136,6 @@ public final class GlobalFlagContainer extends FlagContainer {
|
||||
this.addFlag(SoilDryFlag.SOIL_DRY_FALSE);
|
||||
this.addFlag(TamedAttackFlag.TAMED_ATTACK_FALSE);
|
||||
this.addFlag(TamedInteractFlag.TAMED_INTERACT_FALSE);
|
||||
this.addFlag(TitlesFlag.TITLES_TRUE);
|
||||
this.addFlag(VehicleBreakFlag.VEHICLE_BREAK_FALSE);
|
||||
this.addFlag(VehicleUseFlag.VEHICLE_USE_FALSE);
|
||||
this.addFlag(VillagerInteractFlag.VILLAGER_INTERACT_FALSE);
|
||||
@ -148,6 +147,7 @@ public final class GlobalFlagContainer extends FlagContainer {
|
||||
// Enum Flags
|
||||
this.addFlag(PlotWeatherFlag.PLOT_WEATHER_FLAG_OFF);
|
||||
this.addFlag(DenyTeleportFlag.DENY_TELEPORT_FLAG_NONE);
|
||||
this.addFlag(TitlesFlag.TITLES_NONE);
|
||||
|
||||
// Integer flags
|
||||
this.addFlag(AnimalCapFlag.ANIMAL_CAP_UNLIMITED);
|
||||
|
@ -1,20 +1,72 @@
|
||||
package com.github.intellectualsites.plotsquared.plot.flags.implementations;
|
||||
|
||||
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.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 static final TitlesFlag TITLES_FALSE = new TitlesFlag(false);
|
||||
public class TitlesFlag extends PlotFlag<TitlesFlag.TitlesFlagValue, TitlesFlag> {
|
||||
|
||||
private TitlesFlag(boolean value) {
|
||||
super(value, Captions.FLAG_DESCRIPTION_TITLES);
|
||||
public static final TitlesFlag TITLES_NONE = new TitlesFlag(TitlesFlagValue.NONE);
|
||||
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) {
|
||||
return value ? TITLES_TRUE : TITLES_FALSE;
|
||||
@Override public TitlesFlag parse(@NotNull final String input) throws FlagParseException {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.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.FarewellFlag;
|
||||
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.ItemTypes;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -59,27 +55,16 @@ public class PlotListener {
|
||||
player.setMeta(PlotPlayer.META_LAST_PLOT, plot);
|
||||
EventUtil.manager.callEntry(player, plot);
|
||||
if (plot.hasOwner()) {
|
||||
|
||||
final Collection<PlotFlag<?, ?>> plotFlags = plot.getApplicableFlags(false);
|
||||
|
||||
boolean titles;
|
||||
if (!plot.getArea().DEFAULT_FLAGS.isEmpty()) {
|
||||
Boolean value = (Boolean) plot.getArea().DEFAULT_FLAGS.get(Flags.TITLES);
|
||||
titles = value != null ? value : Settings.TITLES;
|
||||
} else {
|
||||
// This will inherit values from PlotArea
|
||||
final TitlesFlag.TitlesFlagValue titleFlag = plot.getFlag(TitlesFlag.class);
|
||||
final boolean titles;
|
||||
if (titleFlag == TitlesFlag.TitlesFlagValue.NONE) {
|
||||
titles = Settings.TITLES;
|
||||
}
|
||||
String greeting;
|
||||
if (flags.isEmpty()) {
|
||||
if (titles) {
|
||||
greeting = "";
|
||||
} 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()) {
|
||||
MainUtil
|
||||
.format(Captions.PREFIX_GREETING.getTranslated() + greeting, plot, player,
|
||||
@ -180,7 +165,7 @@ public class PlotListener {
|
||||
}
|
||||
}
|
||||
CommentManager.sendTitle(player, plot);
|
||||
}
|
||||
|
||||
if (titles && !player.getAttribute("disabletitles")) {
|
||||
if (!Captions.TITLE_ENTERED_PLOT.getTranslated().isEmpty()
|
||||
|| !Captions.TITLE_ENTERED_PLOT_SUB.getTranslated().isEmpty()) {
|
||||
|
Loading…
Reference in New Issue
Block a user