mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-12-02 13:33:47 +01:00
Port gamemode flags
This commit is contained in:
parent
3df7d3cde9
commit
bf889fc07c
@ -627,6 +627,8 @@ public enum Captions implements Caption {
|
|||||||
FLAG_DESCRIPTION_VILLAGER_INTERACT("Set to `true` to allow guests to interact with villagers in the plot.", "Flags"),
|
FLAG_DESCRIPTION_VILLAGER_INTERACT("Set to `true` to allow guests to interact with villagers in the plot.", "Flags"),
|
||||||
FLAG_DESCRIPTION_VINE_GROW("Set to `true` to allow vines to grow within the plot.", "Flags"),
|
FLAG_DESCRIPTION_VINE_GROW("Set to `true` to allow vines to grow within the plot.", "Flags"),
|
||||||
FLAG_DESCRIPTION_DENY_TELEPORT("Deny a certain group from teleporting to the plot. Available groups: members, nonmembers, trusted, nontrusted, nonowners", "Flags"),
|
FLAG_DESCRIPTION_DENY_TELEPORT("Deny a certain group from teleporting to the plot. Available groups: members, nonmembers, trusted, nontrusted, nonowners", "Flags"),
|
||||||
|
FLAG_DESCRIPTION_GAMEMODE("Determines the gamemode in the plot.", "Flags"),
|
||||||
|
FLAG_DESCRIPTION_GUEST_GAMEMODE("Determines the guest gamemode in the plot.", "Flags"),
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
//<editor-fold desc="Flag category errors">
|
//<editor-fold desc="Flag category errors">
|
||||||
FLAG_ERROR_BOOLEAN("Flag value must be a boolean (true|false)", "Flags"),
|
FLAG_ERROR_BOOLEAN("Flag value must be a boolean (true|false)", "Flags"),
|
||||||
|
@ -6,8 +6,6 @@ import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
|||||||
|
|
||||||
public final class Flags {
|
public final class Flags {
|
||||||
|
|
||||||
public static final GameModeFlag GAMEMODE = new GameModeFlag("gamemode");
|
|
||||||
public static final GameModeFlag GUEST_GAMEMODE = new GameModeFlag("guest-gamemode");
|
|
||||||
public static final LongFlag TIME = new LongFlag("time");
|
public static final LongFlag TIME = new LongFlag("time");
|
||||||
public static final StringListFlag BLOCKED_CMDS = new StringListFlag("blocked-cmds");
|
public static final StringListFlag BLOCKED_CMDS = new StringListFlag("blocked-cmds");
|
||||||
public static final BlockStateListFlag USE = new BlockStateListFlag("use");
|
public static final BlockStateListFlag USE = new BlockStateListFlag("use");
|
||||||
|
@ -19,8 +19,10 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Farew
|
|||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FeedFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FeedFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ForcefieldFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ForcefieldFlag;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GamemodeFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GrassGrowFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GrassGrowFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GreetingFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GreetingFlag;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GuestGamemodeFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HangingBreakFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HangingBreakFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HangingPlaceFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HangingPlaceFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HealFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HealFlag;
|
||||||
@ -156,6 +158,10 @@ public final class GlobalFlagContainer extends FlagContainer {
|
|||||||
// Double flags
|
// Double flags
|
||||||
this.addFlag(PriceFlag.PRICE_NOT_BUYABLE);
|
this.addFlag(PriceFlag.PRICE_NOT_BUYABLE);
|
||||||
|
|
||||||
|
// Misc
|
||||||
|
this.addFlag(GamemodeFlag.GAMEMODE_FLAG_DEFAULT);
|
||||||
|
this.addFlag(GuestGamemodeFlag.GUEST_GAMEMODE_FLAG_DEFAULT);
|
||||||
|
|
||||||
// Internal flags
|
// Internal flags
|
||||||
this.addFlag(new AnalysisFlag(Collections.emptyList()));
|
this.addFlag(new AnalysisFlag(Collections.emptyList()));
|
||||||
this.addFlag(new DoneFlag(""));
|
this.addFlag(new DoneFlag(""));
|
||||||
|
@ -0,0 +1,82 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.plot.flags.implementations;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flags.FlagParseException;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||||
|
import com.sk89q.worldedit.world.gamemode.GameMode;
|
||||||
|
import com.sk89q.worldedit.world.gamemode.GameModes;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class GamemodeFlag extends PlotFlag<GameMode, GamemodeFlag> {
|
||||||
|
|
||||||
|
public static final GameMode DEFAULT = new GameMode("default");
|
||||||
|
static {
|
||||||
|
GameModes.register(DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final GamemodeFlag GAMEMODE_FLAG_CREATIVE = new GamemodeFlag(GameModes.CREATIVE);
|
||||||
|
public static final GamemodeFlag GAMEMODE_FLAG_ADVENTURE = new GamemodeFlag(GameModes.ADVENTURE);
|
||||||
|
public static final GamemodeFlag GAMEMODE_FLAG_SPECTATOR = new GamemodeFlag(GameModes.SPECTATOR);
|
||||||
|
public static final GamemodeFlag GAMEMODE_FLAG_SURVIVAL = new GamemodeFlag(GameModes.SURVIVAL);
|
||||||
|
public static final GamemodeFlag GAMEMODE_FLAG_DEFAULT = new GamemodeFlag(DEFAULT);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new flag instance.
|
||||||
|
*
|
||||||
|
* @param value Flag value
|
||||||
|
*/
|
||||||
|
protected GamemodeFlag(@NotNull GameMode value) {
|
||||||
|
super(value, Captions.FLAG_CATEGORY_GAMEMODE, Captions.FLAG_DESCRIPTION_GAMEMODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public GamemodeFlag parse(@NotNull String input) throws FlagParseException {
|
||||||
|
switch (input) {
|
||||||
|
case "creative":
|
||||||
|
case "c":
|
||||||
|
case "1":
|
||||||
|
return flagOf(GameModes.CREATIVE);
|
||||||
|
case "adventure":
|
||||||
|
case "a":
|
||||||
|
case "2":
|
||||||
|
return flagOf(GameModes.ADVENTURE);
|
||||||
|
case "spectator":
|
||||||
|
case "sp":
|
||||||
|
case "3":
|
||||||
|
return flagOf(GameModes.SPECTATOR);
|
||||||
|
case "survival":
|
||||||
|
case "s":
|
||||||
|
case "0":
|
||||||
|
return flagOf(GameModes.SURVIVAL);
|
||||||
|
default:
|
||||||
|
return flagOf(DEFAULT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public GamemodeFlag merge(@NotNull GameMode newValue) {
|
||||||
|
return flagOf(newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String toString() {
|
||||||
|
return getValue().getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getExample() {
|
||||||
|
return "survival";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected GamemodeFlag flagOf(@NotNull GameMode value) {
|
||||||
|
switch (value.getId()) {
|
||||||
|
case "creative":
|
||||||
|
return GAMEMODE_FLAG_CREATIVE;
|
||||||
|
case "adventure":
|
||||||
|
return GAMEMODE_FLAG_ADVENTURE;
|
||||||
|
case "spectator":
|
||||||
|
return GAMEMODE_FLAG_SPECTATOR;
|
||||||
|
case "survival":
|
||||||
|
return GAMEMODE_FLAG_SURVIVAL;
|
||||||
|
default:
|
||||||
|
return GAMEMODE_FLAG_DEFAULT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.plot.flags.implementations;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flags.FlagParseException;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||||
|
import com.sk89q.worldedit.world.gamemode.GameMode;
|
||||||
|
import com.sk89q.worldedit.world.gamemode.GameModes;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class GuestGamemodeFlag extends PlotFlag<GameMode, GuestGamemodeFlag> {
|
||||||
|
|
||||||
|
public static final GuestGamemodeFlag GUEST_GAMEMODE_FLAG_CREATIVE = new GuestGamemodeFlag(GameModes.CREATIVE);
|
||||||
|
public static final GuestGamemodeFlag GUEST_GAMEMODE_FLAG_ADVENTURE = new GuestGamemodeFlag(GameModes.ADVENTURE);
|
||||||
|
public static final GuestGamemodeFlag GUEST_GAMEMODE_FLAG_SPECTATOR = new GuestGamemodeFlag(GameModes.SPECTATOR);
|
||||||
|
public static final GuestGamemodeFlag GUEST_GAMEMODE_FLAG_SURVIVAL = new GuestGamemodeFlag(GameModes.SURVIVAL);
|
||||||
|
public static final GuestGamemodeFlag GUEST_GAMEMODE_FLAG_DEFAULT = new GuestGamemodeFlag(GamemodeFlag.DEFAULT);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new flag instance.
|
||||||
|
*
|
||||||
|
* @param value Flag value
|
||||||
|
*/
|
||||||
|
protected GuestGamemodeFlag(@NotNull GameMode value) {
|
||||||
|
super(value, Captions.FLAG_CATEGORY_GAMEMODE, Captions.FLAG_DESCRIPTION_GUEST_GAMEMODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public GuestGamemodeFlag parse(@NotNull String input) throws FlagParseException {
|
||||||
|
switch (input) {
|
||||||
|
case "creative":
|
||||||
|
case "c":
|
||||||
|
case "1":
|
||||||
|
return flagOf(GameModes.CREATIVE);
|
||||||
|
case "adventure":
|
||||||
|
case "a":
|
||||||
|
case "2":
|
||||||
|
return flagOf(GameModes.ADVENTURE);
|
||||||
|
case "spectator":
|
||||||
|
case "sp":
|
||||||
|
case "3":
|
||||||
|
return flagOf(GameModes.SPECTATOR);
|
||||||
|
case "survival":
|
||||||
|
case "s":
|
||||||
|
case "0":
|
||||||
|
return flagOf(GameModes.SURVIVAL);
|
||||||
|
default:
|
||||||
|
return flagOf(GamemodeFlag.DEFAULT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public GuestGamemodeFlag merge(@NotNull GameMode newValue) {
|
||||||
|
return flagOf(newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String toString() {
|
||||||
|
return getValue().getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getExample() {
|
||||||
|
return "survival";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected GuestGamemodeFlag flagOf(@NotNull GameMode value) {
|
||||||
|
switch (value.getId()) {
|
||||||
|
case "creative":
|
||||||
|
return GUEST_GAMEMODE_FLAG_CREATIVE;
|
||||||
|
case "adventure":
|
||||||
|
return GUEST_GAMEMODE_FLAG_ADVENTURE;
|
||||||
|
case "spectator":
|
||||||
|
return GUEST_GAMEMODE_FLAG_SPECTATOR;
|
||||||
|
case "survival":
|
||||||
|
return GUEST_GAMEMODE_FLAG_SURVIVAL;
|
||||||
|
default:
|
||||||
|
return GUEST_GAMEMODE_FLAG_DEFAULT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -8,7 +8,9 @@ import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
|||||||
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;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GamemodeFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GreetingFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GreetingFlag;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GuestGamemodeFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.NotifyEnterFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.NotifyEnterFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.NotifyLeaveFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.NotifyLeaveFlag;
|
||||||
@ -29,7 +31,6 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan;
|
|||||||
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
|
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.world.ItemUtil;
|
|
||||||
import com.sk89q.worldedit.world.gamemode.GameMode;
|
import com.sk89q.worldedit.world.gamemode.GameMode;
|
||||||
import com.sk89q.worldedit.world.gamemode.GameModes;
|
import com.sk89q.worldedit.world.gamemode.GameModes;
|
||||||
import com.sk89q.worldedit.world.item.ItemType;
|
import com.sk89q.worldedit.world.item.ItemType;
|
||||||
@ -112,33 +113,35 @@ public class PlotListener {
|
|||||||
player.setFlight(true);
|
player.setFlight(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<GameMode> gamemodeFlag = plot.getFlag(Flags.GAMEMODE);
|
final GameMode gameMode = plot.getFlag(GamemodeFlag.class);
|
||||||
if (gamemodeFlag.isPresent()) {
|
if (!gameMode.equals(GamemodeFlag.DEFAULT)) {
|
||||||
if (player.getGameMode() != gamemodeFlag.get()) {
|
if (player.getGameMode() != gameMode) {
|
||||||
if (!Permissions.hasPermission(player, "plots.gamemode.bypass")) {
|
if (!Permissions.hasPermission(player, "plots.gamemode.bypass")) {
|
||||||
player.setGameMode(gamemodeFlag.get());
|
player.setGameMode(gameMode);
|
||||||
} else {
|
} else {
|
||||||
MainUtil.sendMessage(player, StringMan
|
MainUtil.sendMessage(player, StringMan
|
||||||
.replaceAll(Captions.GAMEMODE_WAS_BYPASSED.getTranslated(),
|
.replaceAll(Captions.GAMEMODE_WAS_BYPASSED.getTranslated(),
|
||||||
"{plot}",
|
"{plot}",
|
||||||
plot.getId(), "{gamemode}", gamemodeFlag.get()));
|
plot.getId(), "{gamemode}", gameMode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Optional<GameMode> guestGamemodeFlag = plot.getFlag(Flags.GUEST_GAMEMODE);
|
|
||||||
if (guestGamemodeFlag.isPresent()) {
|
final GameMode guestGameMode = plot.getFlag(GuestGamemodeFlag.class);
|
||||||
if (player.getGameMode() != guestGamemodeFlag.get() && !plot
|
if (!guestGameMode.equals(GamemodeFlag.DEFAULT)) {
|
||||||
|
if (player.getGameMode() != guestGameMode && !plot
|
||||||
.isAdded(player.getUUID())) {
|
.isAdded(player.getUUID())) {
|
||||||
if (!Permissions.hasPermission(player, "plots.gamemode.bypass")) {
|
if (!Permissions.hasPermission(player, "plots.gamemode.bypass")) {
|
||||||
player.setGameMode(guestGamemodeFlag.get());
|
player.setGameMode(guestGameMode);
|
||||||
} else {
|
} else {
|
||||||
MainUtil.sendMessage(player, StringMan
|
MainUtil.sendMessage(player, StringMan
|
||||||
.replaceAll(Captions.GAMEMODE_WAS_BYPASSED.getTranslated(),
|
.replaceAll(Captions.GAMEMODE_WAS_BYPASSED.getTranslated(),
|
||||||
"{plot}",
|
"{plot}",
|
||||||
plot.getId(), "{gamemode}", guestGamemodeFlag.get()));
|
plot.getId(), "{gamemode}", guestGameMode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Long> timeFlag = plot.getFlag(Flags.TIME);
|
Optional<Long> timeFlag = plot.getFlag(Flags.TIME);
|
||||||
if (timeFlag.isPresent() && !player.getAttribute("disabletime")) {
|
if (timeFlag.isPresent() && !player.getAttribute("disabletime")) {
|
||||||
try {
|
try {
|
||||||
@ -225,8 +228,8 @@ public class PlotListener {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plot.getFlag(Flags.GAMEMODE).isPresent() || plot.getFlag(Flags.GUEST_GAMEMODE)
|
if (!plot.getFlag(GamemodeFlag.class).equals(GamemodeFlag.DEFAULT) ||
|
||||||
.isPresent()) {
|
!plot.getFlag(GuestGamemodeFlag.class).equals(GamemodeFlag.DEFAULT)) {
|
||||||
if (player.getGameMode() != pw.GAMEMODE) {
|
if (player.getGameMode() != pw.GAMEMODE) {
|
||||||
if (!Permissions.hasPermission(player, "plots.gamemode.bypass")) {
|
if (!Permissions.hasPermission(player, "plots.gamemode.bypass")) {
|
||||||
player.setGameMode(pw.GAMEMODE);
|
player.setGameMode(pw.GAMEMODE);
|
||||||
|
Loading…
Reference in New Issue
Block a user