diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/ConstantContext.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/ConstantContext.java deleted file mode 100644 index bbf9d39e..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/ConstantContext.java +++ /dev/null @@ -1,30 +0,0 @@ -package de.steamwar.bausystem.features.script.variables; - -import de.steamwar.bausystem.features.tracer.record.RecordStateMachine; -import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.region.flags.Flag; -import de.steamwar.bausystem.region.flags.flagvalues.FireMode; -import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; -import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; -import org.bukkit.entity.Player; - -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -public class ConstantContext { - - private static final Map> CONSTANTS = new HashMap<>(); - - static { - CONSTANTS.put("trace", player -> RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0); - CONSTANTS.put("autotrace", player -> RecordStateMachine.getRecordStatus().isAutoTrace() ? 1 : 0); - CONSTANTS.put("tnt", player -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) != TNTMode.DENY ? 1 : 0); - CONSTANTS.put("freeze", player -> Region.getRegion(player.getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE ? 1 : 0); - CONSTANTS.put("fire", player -> Region.getRegion(player.getLocation()).getPlain(Flag.FIRE, FireMode.class) == FireMode.ALLOW ? 1 : 0); - CONSTANTS.put("x", player -> player.getLocation().getBlockX()); - CONSTANTS.put("y", player -> player.getLocation().getBlockY()); - CONSTANTS.put("z", player -> player.getLocation().getBlockZ()); - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java new file mode 100644 index 00000000..df39368a --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java @@ -0,0 +1,56 @@ +package de.steamwar.bausystem.features.script.variables; + +import de.steamwar.bausystem.features.tracer.record.RecordStateMachine; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.FireMode; +import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; +import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; +import lombok.experimental.UtilityClass; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +@UtilityClass +public class Constants { + + private final Map> CONSTANTS = new HashMap<>(); + + static { + CONSTANTS.put("trace", player -> { + return new Value.BooleanValue(RecordStateMachine.getRecordStatus().isTracing()); + }); + CONSTANTS.put("autotrace", player -> { + return new Value.BooleanValue(RecordStateMachine.getRecordStatus().isAutoTrace()); + }); + CONSTANTS.put("tnt", player -> { + return new Value.BooleanValue(Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) != TNTMode.DENY); + }); + CONSTANTS.put("freeze", player -> { + return new Value.BooleanValue(Region.getRegion(player.getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE); + }); + CONSTANTS.put("fire", player -> { + return new Value.BooleanValue(Region.getRegion(player.getLocation()).getPlain(Flag.FIRE, FireMode.class) == FireMode.ALLOW); + }); + CONSTANTS.put("x", player -> { + return new Value.LongValue(player.getLocation().getBlockX()); + }); + CONSTANTS.put("y", player -> { + return new Value.LongValue(player.getLocation().getBlockY()); + }); + CONSTANTS.put("z", player -> { + return new Value.LongValue(player.getLocation().getBlockZ()); + }); + } + + public boolean isConstant(String variableName) { + return CONSTANTS.containsKey(variableName); + } + + public Value getConstant(String variableName, Player player) { + return CONSTANTS.get(variableName).apply(player); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Context.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Context.java new file mode 100644 index 00000000..8b0c94d0 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Context.java @@ -0,0 +1,30 @@ +package de.steamwar.bausystem.features.script.variables; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class Context { + + private Map variables = new HashMap<>(); + + public void putValue(String variableName, Value value) { + variables.put(variableName, value); + } + + public void removeValue(String variableName) { + variables.remove(variableName); + } + + public boolean hasValue(String variableName) { + return variables.containsKey(variableName); + } + + public Value getValue(String variableName) { + return variables.get(variableName); + } + + public Set allVariables() { + return variables.keySet(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/GlobalContext.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/GlobalContext.java deleted file mode 100644 index 4ad4e85e..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/GlobalContext.java +++ /dev/null @@ -1,4 +0,0 @@ -package de.steamwar.bausystem.features.script.variables; - -public class GlobalContext { -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/LocalContext.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/LocalContext.java deleted file mode 100644 index 832ed849..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/LocalContext.java +++ /dev/null @@ -1,4 +0,0 @@ -package de.steamwar.bausystem.features.script.variables; - -public class LocalContext { -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/VariableReplacement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/VariableReplacement.java deleted file mode 100644 index 96f606a7..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/VariableReplacement.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.steamwar.bausystem.features.script.variables; - -public class VariableReplacement { - - public static String variableReplace(String command) { - return command; - } - -}