Skip to content

Commit

Permalink
world.gamerule_map, server.gamerules
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 3, 2021
1 parent 8f422d1 commit 8ab2599
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 8 deletions.
Expand Up @@ -768,7 +768,7 @@ public boolean tryMaterial(MaterialTag mat, String comparedto) {
}
}
MatchHelper matcher = createMatcher(comparedto);
if (matcher.doesMatch(mat.realName())) {
if (matcher.doesMatch(mat.name())) {
return true;
}
else if (matcher.doesMatch(mat.identifyNoIdentifier())) {
Expand Down
Expand Up @@ -750,7 +750,7 @@ else if (container != null) {
}

public String formattedName() {
String id = CoreUtilities.toLowerCase(getMaterial().realName()).replace('_', ' ');
String id = CoreUtilities.toLowerCase(getMaterial().name()).replace('_', ' ');
if (id.equals("air")) {
return "nothing";
}
Expand Down
Expand Up @@ -209,10 +209,6 @@ public String toString() {
return identify();
}

public String realName() {
return CoreUtilities.toLowerCase(material.name());
}

@Override
public ObjectTag setPrefix(String prefix) {
if (prefix != null) {
Expand Down
Expand Up @@ -7,6 +7,7 @@
import com.denizenscript.denizencore.objects.core.DurationTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.core.MapTag;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.tags.ObjectTagProcessor;
import com.denizenscript.denizencore.tags.TagContext;
Expand Down Expand Up @@ -744,10 +745,31 @@ else if (time >= 12500) {
// Note that the name is case-sensitive... so "doFireTick" is correct, but "dofiretick" is not.
// -->
registerTag("gamerule", (attribute, object) -> {
if (!attribute.hasContext(1)) {
attribute.echoError("The tag 'worldtag.gamerule[...]' must have an input value.");
return null;
}
GameRule rule = GameRule.getByName(attribute.getContext(1));
Object result = object.getWorld().getGameRuleValue(rule);
return new ElementTag(result == null ? "null" : result.toString());
});

// <--[tag]
// @attribute <WorldTag.gamerule_map>
// @returns MapTag
// @description
// Returns a map of all the current values of all gamerules in the world.
// -->
registerTag("gamerule_map", (attribute, object) -> {
MapTag map = new MapTag();
for (GameRule rule : GameRule.values()) {
Object result = object.getWorld().getGameRuleValue(rule);
if (result != null) {
map.putObject(rule.getName(), new ElementTag(result.toString()));
}
}
return map;
});
}

public static ObjectTagProcessor<WorldTag> tagProcessor = new ObjectTagProcessor<>();
Expand Down
Expand Up @@ -139,7 +139,7 @@ public void adjust(Mechanism mechanism) {
if ((mechanism.matches("age") || mechanism.matches("plant_growth")) && mechanism.requireInteger()) {
int age = mechanism.getValue().asInt();
if (age < 0 || age > getMax()) {
mechanism.echoError("Age value '" + age + "' is not valid. Must be between 0 and " + getMax() + " for material '" + material.realName() + "'.");
mechanism.echoError("Age value '" + age + "' is not valid. Must be between 0 and " + getMax() + " for material '" + material.name() + "'.");
return;
}
if (isTurtleEgg()) {
Expand Down
Expand Up @@ -193,7 +193,7 @@ public void adjust(Mechanism mechanism) {
if (mechanism.matches("level") && mechanism.requireInteger()) {
int level = mechanism.getValue().asInt();
if (level < getMin() || level > getMax()) {
mechanism.echoError("Level value '" + level + "' is not valid. Must be between " + getMin() + " and " + getMax() + " for material '" + material.realName() + "'.");
mechanism.echoError("Level value '" + level + "' is not valid. Must be between " + getMin() + " and " + getMax() + " for material '" + material.name() + "'.");
return;
}
setCurrent(level);
Expand Down
Expand Up @@ -491,6 +491,21 @@ else if (recipe instanceof CookingRecipe<?>) {
return;
}

// <--[tag]
// @attribute <server.gamerules>
// @Plugin Citizens
// @returns ListTag
// @description
// Returns a list of all available gamerules on the server.
// -->
if (attribute.startsWith("gamerules")) {
ListTag allGameRules = new ListTag();
for (GameRule rule : GameRule.values()) {
allGameRules.add(rule.getName());
}
event.setReplacedObject(allGameRules.getObjectAttribute(attribute.fulfill(1)));
}

// <--[tag]
// @attribute <server.traits>
// @Plugin Citizens
Expand Down

0 comments on commit 8ab2599

Please sign in to comment.