Allow rules to manage Scarpet apps (Scarpet Rules) (#519)

by altrisi
This commit is contained in:
altrisi authored and GitHub committed 2020-11-02 21:52:21 -04:00
1 parent 5c76723091
commit b9eee6e58b
12 files changed
+166 -26

No files matched your search

@@ -11,6 +11,7 @@ import carpet.script.value.NBTSerializableValue;
import carpet.script.value.NumericValue;
import carpet.script.value.StringValue;
import carpet.script.value.Value;
import carpet.settings.ParsedRule;
import carpet.utils.Messenger;
import net.minecraft.block.BlockState;
import net.minecraft.entity.EntityType;
@@ -653,6 +654,25 @@ public class CarpetEventServer
);
}
};
public static final Event CARPET_RULE_CHANGES = new Event("carpet_rule_changes", 2, true)
{
@Override
public void onCarpetRuleChanges(ParsedRule<?> rule, ServerCommandSource source)
{
String identifier = rule.settingsManager.getIdentifier();
final String namespace;
if (!identifier.equals("carpet"))
{
namespace = identifier+":";
} else { namespace = "";}
handler.call(
() -> Arrays.asList(
new StringValue(namespace+rule.name),
new StringValue(rule.getAsString())
), () -> source
);
}
};
public static String getLoadEvent(EntityType<? extends Entity> et)
{
@@ -721,6 +741,7 @@ public class CarpetEventServer
public void onWorldEvent(ServerWorld world, BlockPos pos) { }
public void onWorldEventFlag(ServerWorld world, BlockPos pos, int flag) { }
public void onCarpetRuleChanges(ParsedRule<?> rule, ServerCommandSource source) { }
}