mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 23:26:45 +01:00
Port weather flag
This commit is contained in:
parent
70e965d5cb
commit
080e3d0788
@ -8,6 +8,7 @@ import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.BlockStateListFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.PlotWeatherFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.types.BlockTypeListFlag;
|
||||
@ -122,7 +123,7 @@ public class FlagCmd extends SubCommand {
|
||||
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_SET_FLAG_OTHER);
|
||||
return false;
|
||||
}
|
||||
PlotFlag<?> flag = null;
|
||||
PlotFlag<?, ?> flag = null;
|
||||
if (args.length > 1) {
|
||||
flag = GlobalFlagContainer.getInstance().getFlagFromString(args[1]);
|
||||
if (flag == null || flag.isReserved()) {
|
||||
@ -254,7 +255,7 @@ public class FlagCmd extends SubCommand {
|
||||
}
|
||||
if (flag == Flags.TIME) {
|
||||
player.setTime(Long.MAX_VALUE);
|
||||
} else if (flag == Flags.WEATHER) {
|
||||
} else if (flag.getClass().isInstance(PlotWeatherFlag.class)) {
|
||||
player.setWeather(PlotWeather.RESET);
|
||||
}
|
||||
MainUtil.sendMessage(player, Captions.FLAG_REMOVED);
|
||||
|
@ -555,6 +555,7 @@ public enum Captions implements Caption {
|
||||
FLAG_DESCRIPTION_DESCRIPTION("Plot description. Supports '&' color codes.", "Flags"),
|
||||
FLAG_DESCRIPTION_GREETING("Message sent to players on plot entry. Supports '&' color codes.", "Flags"),
|
||||
FLAG_DESCRIPTION_FAREWELL("Message sent to players when leaving the plot. Supports '&' color codes.", "Flags"),
|
||||
FLAG_DESCRIPTION_WEATHER("Specifies the weather conditions inside of the plot.", "Flags"),
|
||||
//</editor-fold>
|
||||
//<editor-fold desc="Flag category errors">
|
||||
FLAG_ERROR_BOOLEAN("Flag value must be a boolean (true|false)", "Flags"),
|
||||
|
@ -20,7 +20,6 @@ public final class Flags {
|
||||
public static final BooleanFlag HIDE_INFO = new BooleanFlag("hide-info");
|
||||
public static final BooleanFlag SERVER_PLOT = new BooleanFlag("server-plot");
|
||||
public static final LongFlag TIME = new LongFlag("time");
|
||||
public static final PlotWeatherFlag WEATHER = new PlotWeatherFlag("weather");
|
||||
public static final DoubleFlag PRICE = new DoubleFlag("price") {
|
||||
@Override public Double parseValue(String input) {
|
||||
Double value = super.parseValue(input);
|
||||
|
@ -7,6 +7,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Farew
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GreetingFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlotWeatherFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.UntrustedVisitFlag;
|
||||
import lombok.Getter;
|
||||
|
||||
@ -35,6 +36,7 @@ public final class GlobalFlagContainer extends FlagContainer {
|
||||
this.addFlag(DescriptionFlag.DESCRIPTION_FLAG_EMPTY);
|
||||
this.addFlag(GreetingFlag.GREETING_FLAG_EMPTY);
|
||||
this.addFlag(FarewellFlag.FAREWELL_FLAG_EMPTY);
|
||||
this.addFlag(PlotWeatherFlag.PLOT_WEATHER_FLAG_OFF);
|
||||
}
|
||||
|
||||
@Override public PlotFlag<?, ?> getFlagErased(Class<?> flagClass) {
|
||||
|
@ -0,0 +1,63 @@
|
||||
package com.github.intellectualsites.plotsquared.plot.flags.implementations;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.PlotWeather;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PlotWeatherFlag extends PlotFlag<PlotWeather, PlotWeatherFlag> {
|
||||
|
||||
public static final PlotWeatherFlag PLOT_WEATHER_FLAG_RAIN = new PlotWeatherFlag(PlotWeather.RAIN);
|
||||
public static final PlotWeatherFlag PLOT_WEATHER_FLAG_CLEAR = new PlotWeatherFlag(PlotWeather.CLEAR);
|
||||
public static final PlotWeatherFlag PLOT_WEATHER_FLAG_OFF = new PlotWeatherFlag(PlotWeather.RESET);
|
||||
|
||||
/**
|
||||
* Construct a new flag instance.
|
||||
*
|
||||
* @param value Flag value
|
||||
*/
|
||||
protected PlotWeatherFlag(@NotNull PlotWeather value) {
|
||||
super(value, Captions.FLAG_CATEGORY_WEATHER, Captions.FLAG_DESCRIPTION_WEATHER);
|
||||
}
|
||||
|
||||
@Override public PlotWeatherFlag parse(@NotNull String input) {
|
||||
switch (input.toLowerCase()) {
|
||||
case "rain":
|
||||
case "storm":
|
||||
case "on":
|
||||
case "lightning":
|
||||
case "thunder":
|
||||
return flagOf(PlotWeather.RAIN);
|
||||
case "clear":
|
||||
case "off":
|
||||
case "sun":
|
||||
return flagOf(PlotWeather.CLEAR);
|
||||
default:
|
||||
return flagOf(PlotWeather.RESET);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public PlotWeatherFlag merge(@NotNull PlotWeather newValue) {
|
||||
return flagOf(newValue);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return getValue().toString();
|
||||
}
|
||||
|
||||
@Override public String getExample() {
|
||||
return "storm";
|
||||
}
|
||||
|
||||
@Override protected PlotWeatherFlag flagOf(@NotNull PlotWeather value) {
|
||||
switch (value) {
|
||||
case RAIN:
|
||||
return PLOT_WEATHER_FLAG_RAIN;
|
||||
case CLEAR:
|
||||
return PLOT_WEATHER_FLAG_CLEAR;
|
||||
default:
|
||||
return PLOT_WEATHER_FLAG_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -10,6 +10,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Farew
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GreetingFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlotWeatherFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||
@ -145,8 +146,7 @@ public class PlotListener {
|
||||
}
|
||||
}
|
||||
|
||||
Optional<PlotWeather> weatherFlag = plot.getFlag(Flags.WEATHER);
|
||||
weatherFlag.ifPresent(player::setWeather);
|
||||
player.setWeather(plot.getFlag(PlotWeatherFlag.class));
|
||||
|
||||
ItemType musicFlag = plot.getFlag(MusicFlag.class);
|
||||
if (musicFlag != null) {
|
||||
@ -279,8 +279,9 @@ public class PlotListener {
|
||||
player.setTime(Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
if (plot.getFlag(Flags.WEATHER).isPresent()) {
|
||||
player.setWeather(PlotWeather.CLEAR);
|
||||
final PlotWeather plotWeather = plot.getFlag(PlotWeatherFlag.class);
|
||||
if (plotWeather != PlotWeather.RESET) {
|
||||
player.setWeather(plotWeather);
|
||||
}
|
||||
|
||||
Location lastLoc = player.getMeta("music");
|
||||
|
Loading…
Reference in New Issue
Block a user