Skip to content
Permalink
Browse files

Add all_materials() function

  • Loading branch information...
EntryPointKR committed Aug 8, 2019
1 parent 231c27d commit 2b28b20f8a8688db9147262da37ed7191ffd2873
@@ -47,6 +47,8 @@

void Startup(CommandHelperPlugin chp);

MCMaterial[] GetMaterialValues();

MCMaterial GetMaterialFromLegacy(String name, int data);

MCMaterial GetMaterialFromLegacy(int id, int data);
@@ -92,6 +92,10 @@ public static MCEnchantment GetEnchantmentByName(String name) {
return convertor.GetEnchantmentByName(name);
}

public static MCMaterial[] GetMaterialValues() {
return convertor.GetMaterialValues();
}

public static MCMaterial GetMaterial(String name) {
return convertor.GetMaterial(name);
}
@@ -68,15 +68,15 @@
import com.laytonsmith.abstraction.enums.MCRecipeType;
import com.laytonsmith.abstraction.enums.MCTone;
import com.laytonsmith.abstraction.enums.MCVersion;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCLegacyMaterial;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCDyeColor;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCEntityType;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCLegacyMaterial;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCPatternShape;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCPotionType;
import com.laytonsmith.annotations.convert;
import com.laytonsmith.commandhelper.CommandHelperPlugin;
import com.laytonsmith.core.MSLog;
import com.laytonsmith.core.LogLevel;
import com.laytonsmith.core.MSLog;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.environments.CommandHelperEnvironment;
@@ -200,6 +200,16 @@ public MCServer GetServer() {
return BukkitMCServer.Get();
}

@Override
public MCMaterial[] GetMaterialValues() {
Material[] mats = Material.values();
MCMaterial[] ret = new MCMaterial[mats.length];
for(int i = 0; i < mats.length; i++) {
ret[i] = new BukkitMCMaterial(mats[i]);
}
return ret;
}

@Override
public MCMaterial GetMaterialFromLegacy(String mat, int data) {
Material m = BukkitMCLegacyMaterial.getMaterial(mat, data);
@@ -1307,4 +1307,53 @@ public Version since() {
}

}

@api
public static class all_materials extends AbstractFunction {
@Override
public Class<? extends CREThrowable>[] thrown() {
return new Class[]{};
}

@Override
public boolean isRestricted() {
return false;
}

@Override
public Boolean runAsync() {
return Boolean.FALSE;
}

@Override
public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
CArray mats = new CArray(t);
for(MCMaterial mat : StaticLayer.GetMaterialValues()) {
if(!mat.getName().startsWith("LEGACY_")) {
mats.push(new CString(mat.getName(), t), t);
}
}
return mats;
}

@Override
public Version since() {
return MSVersion.V3_3_4;
}

@Override
public String getName() {
return "all_materials";
}

@Override
public Integer[] numArgs() {
return new Integer[]{0};
}

@Override
public String docs() {
return "array {} Returns an array of all material names.";
}
}
}
@@ -45,7 +45,10 @@
import com.laytonsmith.abstraction.enums.MCTone;
import com.laytonsmith.annotations.api;
import com.laytonsmith.annotations.convert;
import com.laytonsmith.annotations.seealso;
import com.laytonsmith.annotations.typeof;
import com.laytonsmith.commandhelper.CommandHelperPlugin;
import com.laytonsmith.core.Documentation;
import com.laytonsmith.core.Installer;
import com.laytonsmith.core.LogLevel;
import com.laytonsmith.core.MethodScriptCompiler;
@@ -55,9 +58,13 @@
import com.laytonsmith.core.Prefs;
import com.laytonsmith.core.Profiles;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.compiler.TokenStream;
import com.laytonsmith.core.constructs.CArray;
import com.laytonsmith.core.constructs.CBoolean;
import com.laytonsmith.core.constructs.CClosure;
import com.laytonsmith.core.constructs.CInt;
import com.laytonsmith.core.constructs.CString;
import com.laytonsmith.core.constructs.Construct;
import com.laytonsmith.core.constructs.IVariable;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.constructs.Variable;
@@ -68,58 +75,51 @@
import com.laytonsmith.core.events.EventUtils;
import com.laytonsmith.core.events.drivers.CmdlineEvents;
import com.laytonsmith.core.exceptions.CRE.CREFormatException;
import com.laytonsmith.core.exceptions.CRE.CREIOException;
import com.laytonsmith.core.exceptions.CRE.CREThrowable;
import com.laytonsmith.core.exceptions.CancelCommandException;
import com.laytonsmith.core.exceptions.ConfigCompileException;
import com.laytonsmith.core.exceptions.ConfigCompileGroupException;
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
import com.laytonsmith.core.functions.Cmdline;
import com.laytonsmith.core.functions.Echoes;
import com.laytonsmith.core.functions.ExampleScript;
import com.laytonsmith.core.functions.Function;
import com.laytonsmith.core.functions.FunctionBase;
import com.laytonsmith.core.functions.FunctionList;
import com.laytonsmith.core.profiler.ProfilePoint;
import com.laytonsmith.persistence.DataSourceException;
import com.laytonsmith.tools.docgen.DocGen;
import com.laytonsmith.tools.docgen.DocGenTemplates;
import jline.console.ConsoleReader;
import jline.console.completer.ArgumentCompleter;
import jline.console.completer.StringsCompleter;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.laytonsmith.PureUtilities.TermColors.BLUE;
import static com.laytonsmith.PureUtilities.TermColors.RED;
import static com.laytonsmith.PureUtilities.TermColors.YELLOW;
import static com.laytonsmith.PureUtilities.TermColors.p;
import static com.laytonsmith.PureUtilities.TermColors.pl;
import static com.laytonsmith.PureUtilities.TermColors.reset;
import com.laytonsmith.annotations.seealso;
import com.laytonsmith.annotations.typeof;
import com.laytonsmith.core.Documentation;
import com.laytonsmith.core.compiler.TokenStream;
import com.laytonsmith.core.constructs.CBoolean;
import com.laytonsmith.core.constructs.CInt;
import com.laytonsmith.core.constructs.Construct;
import com.laytonsmith.core.exceptions.CRE.CREIOException;
import com.laytonsmith.core.exceptions.CRE.CREThrowable;
import com.laytonsmith.core.functions.Cmdline;
import com.laytonsmith.core.functions.Echoes;
import com.laytonsmith.core.functions.ExampleScript;
import com.laytonsmith.core.functions.Function;
import com.laytonsmith.tools.docgen.DocGen;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* This is a command line implementation of the in game interpreter mode. This should only be run while the server is
@@ -1201,6 +1201,11 @@ public MCPluginMeta GetPluginMeta() {
throw new UnsupportedOperationException("This method is not supported from a shell.");
}

@Override
public MCMaterial[] GetMaterialValues() {
throw new UnsupportedOperationException("This method is not supported from a shell.");
}

@Override
public MCMaterial GetMaterialFromLegacy(String name, int data) {
throw new UnsupportedOperationException("This method is not supported from a shell.");
@@ -808,6 +808,11 @@ public MCPluginMeta GetPluginMeta() {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public MCMaterial[] GetMaterialValues() {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public MCMaterial GetMaterialFromLegacy(String name, int data) {
throw new UnsupportedOperationException("Not supported yet.");

0 comments on commit 2b28b20

Please sign in to comment.
You can’t perform that action at this time.