SteamWar/BauSystem2.0
Archiviert
12
0
Add Context
Dieser Commit ist enthalten in:
yoyosource 2021-04-21 10:00:47 +02:00
Ursprung d2cc401c61
Commit f14165dc68
6 geänderte Dateien mit 86 neuen und 47 gelöschten Zeilen

Datei anzeigen

@ -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<String, Function<Player, Integer>> 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());
}
}

Datei anzeigen

@ -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<String, Function<Player, Value>> 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);
}
}

Datei anzeigen

@ -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<String, Value> 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<String> allVariables() {
return variables.keySet();
}
}

Datei anzeigen

@ -1,4 +0,0 @@
package de.steamwar.bausystem.features.script.variables;
public class GlobalContext {
}

Datei anzeigen

@ -1,4 +0,0 @@
package de.steamwar.bausystem.features.script.variables;
public class LocalContext {
}

Datei anzeigen

@ -1,9 +0,0 @@
package de.steamwar.bausystem.features.script.variables;
public class VariableReplacement {
public static String variableReplace(String command) {
return command;
}
}