Skip to content

Commit

Permalink
Add all_materials() function
Browse files Browse the repository at this point in the history
  • Loading branch information
entrypointkr committed Aug 8, 2019
1 parent 231c27d commit 2b28b20
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/Convertor.java
Expand Up @@ -47,6 +47,8 @@ public interface Convertor {

void Startup(CommandHelperPlugin chp);

MCMaterial[] GetMaterialValues();

MCMaterial GetMaterialFromLegacy(String name, int data);

MCMaterial GetMaterialFromLegacy(int id, int data);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/StaticLayer.java
Expand Up @@ -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);
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/com/laytonsmith/core/functions/Minecraft.java
Expand Up @@ -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.";
}
}
}
49 changes: 27 additions & 22 deletions src/main/java/com/laytonsmith/tools/Interpreter.java
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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.");
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/com/laytonsmith/testing/StaticTest.java
Expand Up @@ -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.");
Expand Down

0 comments on commit 2b28b20

Please sign in to comment.