use of me.superckl.api.superscript.script.command.ScriptCommandListing in project BiomeTweaker by superckl.
the class ScriptObject method handleCall.
public void handleCall(final String call, final ScriptContext context, final ScriptHandler handler) throws Exception {
String command;
try {
command = ScriptParser.getCommandCalled(call);
} catch (final IllegalArgumentException e) {
APIInfo.log.error("Failed to parse command call: " + call + " @ " + context + ". Reason: " + e.getMessage());
return;
}
if (!this.validCommands.containsKey(command)) {
APIInfo.log.error("Failed to find meaning in command " + call + " @ " + context + ". Reason: No commands found with that name.");
return;
}
final ScriptCommandListing listing = this.validCommands.get(command);
String[] args = CollectionHelper.trimAll(ScriptParser.parseArguments(call));
args = this.modifyArguments(args, handler);
Pair<Constructor<? extends ScriptCommand>, Object[]> pair = ScriptParser.findConstructor(listing, args, handler);
if (pair != null) {
pair = this.modifyConstructorPair(pair, args, handler);
final ScriptCommand sCommand = pair.getKey().newInstance(pair.getValue());
sCommand.setContext(context);
sCommand.setScriptHandler(handler);
if (listing.isPerformInst())
sCommand.perform();
else
this.addCommand(sCommand);
return;
}
APIInfo.log.error("Failed to parse arguments for command " + call + " @ " + context + ". Reason: No constructors found with matching arguments.");
}
use of me.superckl.api.superscript.script.command.ScriptCommandListing in project BiomeTweaker by superckl.
the class CommonProxy method setupScripts.
@Override
public void setupScripts(final ASMDataTable table) {
// Ensure BTParamterTypes registers its defaults
BTParameterTypes.BLOCKSTATE_BUILDER.getTypeClass();
LogHelper.debug("Discovering @AutoRegister script commands...");
final Map<Class<? extends ScriptObject>, Map<String, ScriptCommandListing>> listings = new HashMap<>();
final Set<ASMData> datas = table.getAll(AutoRegister.class.getCanonicalName());
final Set<ASMData> groupedDatas = table.getAll(AutoRegisters.class.getCanonicalName());
final Set<ASMData> allData = new HashSet<>(datas);
for (final ASMData data : groupedDatas) {
final List<Map<String, Object>> anns = WarningHelper.uncheckedCast(data.getAnnotationInfo().get("value"));
anns.forEach(l -> allData.add(new ASMData(data.getCandidate(), AutoRegister.class.getCanonicalName(), data.getClassName(), data.getObjectName(), l)));
}
final Set<String> examinedClasses = new HashSet<>();
for (final ASMData data : allData) try {
if (examinedClasses.contains(data.getClassName()))
continue;
final Class<?> asmClass = Class.forName(data.getClassName());
final Class<? extends ScriptCommand> scriptClass = asmClass.asSubclass(ScriptCommand.class);
final AutoRegister[] classAnns = scriptClass.getAnnotationsByType(AutoRegister.class);
final Constructor<?>[] cons = scriptClass.getConstructors();
for (final Constructor<?> con : cons) {
if (con.isAnnotationPresent(RegisterExempt.class))
continue;
final AutoRegister[] methodAnns = con.getAnnotationsByType(AutoRegister.class);
if (classAnns.length == 0 && methodAnns.length == 0)
continue;
AutoRegister[] annsToUse;
if (methodAnns.length != 0)
annsToUse = methodAnns;
else
annsToUse = classAnns;
final Class<?>[] cTypes = con.getParameterTypes();
final ParameterWrapper<?>[] pTypes = new ParameterWrapper[cTypes.length];
for (final ParameterOverride override : con.getAnnotationsByType(ParameterOverride.class)) pTypes[override.parameterIndex()] = ParameterTypes.getExceptionWrapper(override.exceptionKey());
for (int i = 0; i < cTypes.length; i++) {
if (pTypes[i] != null)
continue;
final ParameterType<?> type = ParameterTypes.getDefaultType(cTypes[i]);
if (type == null)
throw new IllegalStateException("No parameter type found for parameter " + cTypes[i].getCanonicalName());
pTypes[i] = type.getSimpleWrapper();
}
for (final AutoRegister ann : annsToUse) for (final Class<? extends ScriptObject> clazz : ann.classes()) {
if (!listings.containsKey(clazz))
listings.put(clazz, new HashMap<>());
final Map<String, ScriptCommandListing> map = listings.get(clazz);
if (!map.containsKey(ann.name()))
map.put(ann.name(), new ScriptCommandListing());
final ScriptCommandListing listing = map.get(ann.name());
listing.addEntry(Lists.newArrayList(pTypes), WarningHelper.uncheckedCast(con));
}
}
examinedClasses.add(data.getClassName());
} catch (final Exception e) {
LogHelper.error("Failed to auto-register a script command " + data.getAnnotationInfo().toString());
e.printStackTrace();
}
for (final Entry<Class<? extends ScriptObject>, Map<String, ScriptCommandListing>> entry : listings.entrySet()) {
LogHelper.debug("Registering " + entry.getValue().size() + " commands to " + entry.getKey().getSimpleName());
ScriptCommandRegistry.INSTANCE.registerClassListing(entry.getKey(), entry.getValue());
}
ScriptHandler.registerStaticObject("Tweaker", TweakerScriptObject.class);
try {
ConstructorListing<ScriptObject> listing = new ConstructorListing<>();
listing.addEntry(Lists.newArrayList(BTParameterTypes.BASIC_BIOMES_PACKAGE.getVarArgsWrapper()), BiomesScriptObject.class.getDeclaredConstructor());
ScriptParser.registerValidObjectInst("forBiomes", listing);
listing = new ConstructorListing<>();
listing.addEntry(Lists.newArrayList(BTParameterTypes.TYPE_BIOMES_PACKAGE.getSpecialWrapper()), BiomesScriptObject.class.getDeclaredConstructor());
ScriptParser.registerValidObjectInst("forBiomesOfTypes", listing);
listing = new ConstructorListing<>();
listing.addEntry(Lists.newArrayList(BTParameterTypes.ALL_BIOMES_PACKAGE.getSpecialWrapper()), BiomesScriptObject.class.getDeclaredConstructor());
ScriptParser.registerValidObjectInst("forAllBiomes", listing);
listing = new ConstructorListing<>();
listing.addEntry(Lists.newArrayList(BTParameterTypes.ALL_BUT_BIOMES_PACKAGE.getSpecialWrapper()), BiomesScriptObject.class.getDeclaredConstructor());
ScriptParser.registerValidObjectInst("forAllBiomesExcept", listing);
listing = new ConstructorListing<>();
listing.addEntry(Lists.newArrayList(BTParameterTypes.INTERSECT_BIOMES_PACKAGE.getSpecialWrapper()), BiomesScriptObject.class.getDeclaredConstructor());
ScriptParser.registerValidObjectInst("intersectionOf", listing);
listing = new ConstructorListing<>();
listing.addEntry(Lists.newArrayList(BTParameterTypes.SUBTRACT_BIOMES_PACKAGE.getSpecialWrapper()), BiomesScriptObject.class.getDeclaredConstructor());
ScriptParser.registerValidObjectInst("subtractFrom", listing);
listing = new ConstructorListing<>();
listing.addEntry(Lists.newArrayList(BTParameterTypes.PROPERTY_RANGE_PACKAGE.getSpecialWrapper()), BiomesScriptObject.class.getDeclaredConstructor());
ScriptParser.registerValidObjectInst("forBiomesWithPropertyRange", listing);
listing = new ConstructorListing<>();
listing.addEntry(new ArrayList<>(), OreDecorationScriptObject.class.getDeclaredConstructor());
ScriptParser.registerValidObjectInst("newOreDecoration", listing);
listing = new ConstructorListing<>();
listing.addEntry(new ArrayList<>(), TreesDecorationScriptObject.class.getDeclaredConstructor());
ScriptParser.registerValidObjectInst("newTreeDecoration", listing);
listing = new ConstructorListing<>();
listing.addEntry(new ArrayList<>(), ClusterDecorationScriptObject.class.getDeclaredConstructor());
ScriptParser.registerValidObjectInst("newClusterDecoration", listing);
listing = new ConstructorListing<>();
listing.addEntry(new ArrayList<>(), SplotchDecorationScriptObject.class.getDeclaredConstructor());
ScriptParser.registerValidObjectInst("newSplotchDecoration", listing);
listing = new ConstructorListing<>();
listing.addEntry(Lists.newArrayList(ParameterTypes.STRING.getSimpleWrapper()), BasicBlockStateScriptObject.class.getDeclaredConstructor());
ScriptParser.registerValidObjectInst("forBlock", listing);
listing = new ConstructorListing<>();
listing.addEntry(new ArrayList<>(), BlockReplacementScriptObject.class.getDeclaredConstructor());
ScriptParser.registerValidObjectInst("newBlockReplacement", listing);
} catch (final Exception e2) {
LogHelper.error("Failed to populate object listings! Some tweaks may not be applied.");
e2.printStackTrace();
}
}
use of me.superckl.api.superscript.script.command.ScriptCommandListing in project BiomeTweaker by superckl.
the class BOPIntegrationModule method preInit.
@Override
public void preInit() {
try {
LogHelper.info("Registering BOP script commands...");
// TweakerObject
ScriptCommandListing listing = new ScriptCommandListing();
listing.addEntry(Lists.newArrayList(ParameterTypes.STRING.getSimpleWrapper()), ScriptCommandRemoveBOPWorldType.class.getDeclaredConstructor(String.class));
ScriptCommandRegistry.INSTANCE.registerListing("removeExcludedBOPWorldType", listing, TweakerScriptObject.class);
ScriptCommandRegistry.INSTANCE.registerListing("removeExcludedBOPWorldType", listing, BiomesScriptObject.class);
listing = new ScriptCommandListing();
listing.addEntry(Lists.newArrayList(ParameterTypes.STRING.getSimpleWrapper()), ScriptCommandAddBOPWorldType.class.getDeclaredConstructor(String.class));
ScriptCommandRegistry.INSTANCE.registerListing("addExcludedBOPWorldType", listing, TweakerScriptObject.class);
ScriptCommandRegistry.INSTANCE.registerListing("addExcludedBOPWorldType", listing, BiomesScriptObject.class);
listing = new ScriptCommandListing();
listing.addEntry(Lists.newArrayList(BTParameterTypes.BASIC_BIOMES_PACKAGE.getSimpleWrapper(), ParameterTypes.STRING.getSimpleWrapper(), ParameterTypes.NON_NEG_INTEGER.getSimpleWrapper()), ScriptCommandAddToGenerationBOP.class.getDeclaredConstructor(BiomePackage.class, String.class, Integer.TYPE));
ScriptCommandRegistry.INSTANCE.registerListing("addToGenerationBOP", listing, TweakerScriptObject.class);
ScriptCommandRegistry.INSTANCE.registerListing("addToGenerationBOP", listing, BiomesScriptObject.class);
listing = new ScriptCommandListing();
listing.addEntry(Lists.newArrayList(BTParameterTypes.BASIC_BIOMES_PACKAGE.getSimpleWrapper()), ScriptCommandRemoveBOP.class.getDeclaredConstructor(BiomePackage.class));
listing.addEntry(Lists.newArrayList(BTParameterTypes.BASIC_BIOMES_PACKAGE.getSimpleWrapper(), ParameterTypes.STRING_ARRAY.getSpecialWrapper()), ScriptCommandRemoveBOP.class.getDeclaredConstructor(BiomePackage.class, String[].class));
ScriptCommandRegistry.INSTANCE.registerListing("removeBOP", listing, TweakerScriptObject.class);
ScriptCommandRegistry.INSTANCE.registerListing("removeBOP", listing, BiomesScriptObject.class);
listing = new ScriptCommandListing();
listing.addEntry(Lists.newArrayList(BTParameterTypes.BASIC_BIOMES_PACKAGE.getSimpleWrapper(), ParameterTypes.STRING_ARRAY.getSpecialWrapper()), ScriptCommandRemoveGeneratorBOP.class.getDeclaredConstructor(BiomePackage.class, String[].class));
ScriptCommandRegistry.INSTANCE.registerListing("removeGeneratorBOP", listing, TweakerScriptObject.class);
ScriptCommandRegistry.INSTANCE.registerListing("removeGeneratorBOP", listing, BiomesScriptObject.class);
listing = new ScriptCommandListing();
listing.addEntry(Lists.newArrayList(BTParameterTypes.BASIC_BIOMES_PACKAGE.getSimpleWrapper(), BTParameterTypes.BASIC_BIOMES_PACKAGE.getSimpleWrapper()), ScriptCommandAddSubBiomeBOP.class.getDeclaredConstructor(BiomePackage.class, BiomePackage.class));
ScriptCommandRegistry.INSTANCE.registerListing("addSubBiomeBOP", listing, TweakerScriptObject.class);
ScriptCommandRegistry.INSTANCE.registerListing("addSubBiomeBOP", listing, BiomesScriptObject.class);
listing = new ScriptCommandListing();
listing.addEntry(Lists.newArrayList(BTParameterTypes.BASIC_BIOMES_PACKAGE.getSimpleWrapper(), BTParameterTypes.BASIC_BIOMES_PACKAGE.getSimpleWrapper()), ScriptCommandRemoveSubBiomeBOP.class.getDeclaredConstructor(BiomePackage.class, BiomePackage.class));
ScriptCommandRegistry.INSTANCE.registerListing("removeSubBiomeBOP", listing, TweakerScriptObject.class);
ScriptCommandRegistry.INSTANCE.registerListing("removeSubBiomeBOP", listing, BiomesScriptObject.class);
listing = new ScriptCommandListing();
listing.addEntry(Lists.newArrayList(BTParameterTypes.BASIC_BIOMES_PACKAGE.getSimpleWrapper(), ParameterTypes.NON_NEG_INTEGER.getSimpleWrapper()), ScriptCommandAddIslandBiomeBOP.class.getDeclaredConstructor(BiomePackage.class, Integer.TYPE));
ScriptCommandRegistry.INSTANCE.registerListing("addToIslandBOP", listing, TweakerScriptObject.class);
ScriptCommandRegistry.INSTANCE.registerListing("addToIslandBOP", listing, BiomesScriptObject.class);
listing = new ScriptCommandListing();
listing.addEntry(Lists.newArrayList(BTParameterTypes.BASIC_BIOMES_PACKAGE.getSimpleWrapper()), ScriptCommandRemoveIslandBiomeBOP.class.getDeclaredConstructor(BiomePackage.class));
ScriptCommandRegistry.INSTANCE.registerListing("removeIslandBOP", listing, TweakerScriptObject.class);
ScriptCommandRegistry.INSTANCE.registerListing("removeIslandBOP", listing, BiomesScriptObject.class);
} catch (final Exception e) {
LogHelper.error("Failed to register BOP script commands! Some commands may not work properly!");
e.printStackTrace();
}
}
Aggregations