mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-21 12:32:29 +00:00
- Fixed crash when using mt command from server console
- Forum command now leads to the new forums - Checked in some missing files from previous commit
This commit is contained in:
1 parent
1b72abb2b4
commit
e644398505
17 files changed
+923
-9
No files matched your search
@@ -5,3 +5,4 @@ run
|
||||
/MineTweaker3-Web/nbproject/private/
|
||||
/MineTweaker3-Web/doc
|
||||
/MineTweaker3-MC164-Main/eclipse
|
||||
/ZenScript-Test
|
||||
@@ -257,7 +257,7 @@ public class MineTweakerImplementationAPI {
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
player.openBrowser("http://www.minecraftforum.net/topic/1886008-164-17x-minetweaker-3-customize-your-minecraft-experience");
|
||||
player.openBrowser("http://minetweaker3.powerofbytes.com/forum");
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ buildscript {
|
||||
|
||||
apply plugin: 'forge'
|
||||
|
||||
version = "1.6.4-3.0.3"
|
||||
version = "1.6.4-3.0.6"
|
||||
//group= "com.yourname.modid" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
archivesBaseName = project.projectDir.name
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.MineTweakerImplementationAPI;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.server.AbstractServer;
|
||||
@@ -22,6 +21,7 @@ import net.minecraft.command.ICommand;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -53,14 +53,18 @@ public class MCServer extends AbstractServer {
|
||||
@Override
|
||||
public boolean isOp(IPlayer player) {
|
||||
return MinecraftServer.getServer().getConfigurationManager().getOps().isEmpty()
|
||||
|| MinecraftServer.getServer().getConfigurationManager().getOps().contains(player.getName());
|
||||
|| MinecraftServer.getServer().getConfigurationManager().getOps().contains(player.getName())
|
||||
|| player == ServerPlayer.INSTANCE;
|
||||
}
|
||||
|
||||
private static IPlayer getPlayer(ICommandSender commandSender) {
|
||||
if (commandSender instanceof EntityPlayer) {
|
||||
return MineTweakerMC.getIPlayer((EntityPlayer) commandSender);
|
||||
} else if (commandSender instanceof DedicatedServer) {
|
||||
return ServerPlayer.INSTANCE;
|
||||
} else {
|
||||
System.out.println("No such player: " + commandSender);
|
||||
System.out.println("Unsupported command sender: " + commandSender);
|
||||
System.out.println("player name: " + commandSender.getCommandSenderName());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.server;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import minetweaker.api.chat.IChatMessage;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ServerPlayer implements IPlayer {
|
||||
public static final ServerPlayer INSTANCE = new ServerPlayer();
|
||||
|
||||
private ServerPlayer() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "server";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Server";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getData() {
|
||||
// TODO: implement
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(IData data) {
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendChat(IChatMessage message) {
|
||||
DedicatedServer.getServer().sendChatToPlayer((ChatMessageComponent) message.getInternal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHotbarSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getHotbarStack(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventorySize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getInventoryStack(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getCurrentItem() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openBrowser(String url) {
|
||||
if (Desktop.isDesktopSupported()) {
|
||||
try {
|
||||
Desktop.getDesktop().browse(URI.create(url));
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(ServerPlayer.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ buildscript {
|
||||
|
||||
apply plugin: 'forge'
|
||||
minecraft{version = "1.7.10-10.13.0.1160"}
|
||||
version = "1.7.10-3.0.3"
|
||||
version = "1.7.10-3.0.6"
|
||||
archivesBaseName = project.projectDir.name
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.command.ICommand;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.server.management.UserListOps;
|
||||
|
||||
/**
|
||||
@@ -52,6 +53,9 @@ public class MCServer extends AbstractServer {
|
||||
|
||||
@Override
|
||||
public boolean isOp(IPlayer player) {
|
||||
if (player == ServerPlayer.INSTANCE)
|
||||
return true;
|
||||
|
||||
UserListOps ops = MinecraftServer.getServer().getConfigurationManager().func_152603_m();
|
||||
if (server.isDedicatedServer()) {
|
||||
return ops.func_152690_d() || ops.func_152700_a(player.getName()) != null;
|
||||
@@ -63,7 +67,11 @@ public class MCServer extends AbstractServer {
|
||||
private static IPlayer getPlayer(ICommandSender commandSender) {
|
||||
if (commandSender instanceof EntityPlayer) {
|
||||
return MineTweakerMC.getIPlayer((EntityPlayer) commandSender);
|
||||
} else if (commandSender instanceof DedicatedServer) {
|
||||
return ServerPlayer.INSTANCE;
|
||||
} else {
|
||||
System.out.println("Unsupported command sender: " + commandSender);
|
||||
System.out.println("player name: " + commandSender.getCommandSenderName());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc1710.server;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import minetweaker.api.chat.IChatMessage;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ServerPlayer implements IPlayer {
|
||||
public static final ServerPlayer INSTANCE = new ServerPlayer();
|
||||
|
||||
private ServerPlayer() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "server";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Server";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getData() {
|
||||
// TODO: implement
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(IData data) {
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendChat(IChatMessage message) {
|
||||
DedicatedServer.getServer().addChatMessage((IChatComponent) message.getInternal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHotbarSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getHotbarStack(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventorySize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getInventoryStack(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getCurrentItem() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openBrowser(String url) {
|
||||
if (Desktop.isDesktopSupported()) {
|
||||
try {
|
||||
Desktop.getDesktop().browse(URI.create(url));
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(ServerPlayer.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ buildscript {
|
||||
|
||||
apply plugin: 'forge'
|
||||
minecraft{version = "1.7.2-10.12.2.1121"}
|
||||
version = "1.7.2-3.0.3"
|
||||
version = "1.7.2-3.0.6"
|
||||
archivesBaseName = project.projectDir.name
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.command.ICommand;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -51,14 +52,19 @@ public class MCServer extends AbstractServer {
|
||||
|
||||
@Override
|
||||
public boolean isOp(IPlayer player) {
|
||||
return MinecraftServer.getServer().getConfigurationManager().getOps().isEmpty()
|
||||
|| MinecraftServer.getServer().getConfigurationManager().getOps().contains(player.getName());
|
||||
return (MinecraftServer.getServer().getConfigurationManager().getOps().isEmpty()
|
||||
|| MinecraftServer.getServer().getConfigurationManager().getOps().contains(player.getName()))
|
||||
|| player == ServerPlayer.INSTANCE;
|
||||
}
|
||||
|
||||
private static IPlayer getPlayer(ICommandSender commandSender) {
|
||||
if (commandSender instanceof EntityPlayer) {
|
||||
return MineTweakerMC.getIPlayer((EntityPlayer) commandSender);
|
||||
} else if (commandSender instanceof DedicatedServer) {
|
||||
return ServerPlayer.INSTANCE;
|
||||
} else {
|
||||
System.out.println("Unsupported command sender: " + commandSender);
|
||||
System.out.println("player name: " + commandSender.getCommandSenderName());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc172.server;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import minetweaker.api.chat.IChatMessage;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ServerPlayer implements IPlayer {
|
||||
public static final ServerPlayer INSTANCE = new ServerPlayer();
|
||||
|
||||
private ServerPlayer() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "server";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Server";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getData() {
|
||||
// TODO: implement
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(IData data) {
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendChat(IChatMessage message) {
|
||||
DedicatedServer.getServer().addChatMessage((IChatComponent) message.getInternal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHotbarSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getHotbarStack(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventorySize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getInventoryStack(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getCurrentItem() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openBrowser(String url) {
|
||||
if (Desktop.isDesktopSupported()) {
|
||||
try {
|
||||
Desktop.getDesktop().browse(URI.create(url));
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(ServerPlayer.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.5 KiB |
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.expression;
|
||||
|
||||
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ExpressionStringContains extends Expression {
|
||||
private final Expression haystack;
|
||||
private final Expression needle;
|
||||
|
||||
public ExpressionStringContains(ZenPosition position, Expression haystack, Expression needle) {
|
||||
super(position);
|
||||
|
||||
this.haystack = haystack;
|
||||
this.needle = needle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZenType getType() {
|
||||
return ZenType.STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(boolean result, IEnvironmentMethod environment) {
|
||||
haystack.compile(result, environment);
|
||||
needle.compile(result, environment);
|
||||
|
||||
if (result) {
|
||||
environment.getOutput().invokeVirtual(String.class, "contains", CharSequence.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.expression;
|
||||
|
||||
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ExpressionStringIndex extends Expression {
|
||||
private final Expression source;
|
||||
private final Expression index;
|
||||
|
||||
public ExpressionStringIndex(ZenPosition position, Expression source, Expression index) {
|
||||
super(position);
|
||||
|
||||
this.source = source;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZenType getType() {
|
||||
return ZenType.STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(boolean result, IEnvironmentMethod environment) {
|
||||
source.compile(result, environment);
|
||||
index.compile(result, environment);
|
||||
|
||||
if (result) {
|
||||
environment.getOutput().dup();
|
||||
environment.getOutput().iConst1();
|
||||
environment.getOutput().iAdd();
|
||||
environment.getOutput().invokeVirtual(String.class, "substring", String.class, int.class, int.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,425 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.util;
|
||||
|
||||
import java.util.Iterator;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
import static stanhebben.zenscript.util.ZenTypeUtil.EMPTY_REGISTRY;
|
||||
import static stanhebben.zenscript.util.ZenTypeUtil.internal;
|
||||
import static stanhebben.zenscript.util.ZenTypeUtil.signature;
|
||||
import stanhebben.zenscript.value.IAny;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class AnyClassWriter {
|
||||
public static final JavaMethod METHOD_NOT = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "not");
|
||||
public static final JavaMethod METHOD_NEG = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "neg");
|
||||
public static final JavaMethod METHOD_ADD = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "add", IAny.class);
|
||||
public static final JavaMethod METHOD_CAT = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "cat", IAny.class);
|
||||
public static final JavaMethod METHOD_SUB = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "sub", IAny.class);
|
||||
public static final JavaMethod METHOD_MUL = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "mul", IAny.class);
|
||||
public static final JavaMethod METHOD_DIV = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "div", IAny.class);
|
||||
public static final JavaMethod METHOD_MOD = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "mod", IAny.class);
|
||||
public static final JavaMethod METHOD_AND = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "and", IAny.class);
|
||||
public static final JavaMethod METHOD_OR = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "or", IAny.class);
|
||||
public static final JavaMethod METHOD_XOR = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "xor", IAny.class);
|
||||
public static final JavaMethod METHOD_RANGE = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "range", IAny.class);
|
||||
public static final JavaMethod METHOD_COMPARETO = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "compareTo", IAny.class);
|
||||
public static final JavaMethod METHOD_CONTAINS = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "contains", IAny.class);
|
||||
public static final JavaMethod METHOD_MEMBERGET = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "memberGet", String.class);
|
||||
public static final JavaMethod METHOD_MEMBERSET = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "memberSet", String.class, IAny.class);
|
||||
public static final JavaMethod METHOD_MEMBERCALL = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "memberCall", String.class, IAny[].class);
|
||||
public static final JavaMethod METHOD_INDEXGET = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "indexGet", IAny.class);
|
||||
public static final JavaMethod METHOD_INDEXSET = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "indexSet", IAny.class, IAny.class);
|
||||
public static final JavaMethod METHOD_CALL = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "call", IAny[].class);
|
||||
public static final JavaMethod METHOD_ASBOOL = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "asBool");
|
||||
public static final JavaMethod METHOD_ASBYTE = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "asByte");
|
||||
public static final JavaMethod METHOD_ASSHORT = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "asShort");
|
||||
public static final JavaMethod METHOD_ASINT = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "asInt");
|
||||
public static final JavaMethod METHOD_ASLONG = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "asLong");
|
||||
public static final JavaMethod METHOD_ASFLOAT = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "asFloat");
|
||||
public static final JavaMethod METHOD_ASDOUBLE = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "asDouble");
|
||||
public static final JavaMethod METHOD_ASSTRING = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "asString");
|
||||
public static final JavaMethod METHOD_AS = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "as", Class.class);
|
||||
public static final JavaMethod METHOD_IS = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "is", Class.class);
|
||||
public static final JavaMethod METHOD_CANCASTIMPLICIT = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "canCastImplicit", Class.class);
|
||||
public static final JavaMethod METHOD_GETNUMBERTYPE = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "getNumberType");
|
||||
public static final JavaMethod METHOD_ITERATORSINGLE = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "iteratorSingle");
|
||||
public static final JavaMethod METHOD_ITERATORMULTI = JavaMethod.get(EMPTY_REGISTRY, IAny.class, "iteratorMulti", int.class);
|
||||
|
||||
private static final String SIG_ANY = "()" + signature(IAny.class);
|
||||
private static final String SIG_ANY_ANY = "(" + signature(IAny.class) + ")" + signature(IAny.class);
|
||||
private static final String SIG_ANY_INT = "(" + signature(IAny.class) + ")I";
|
||||
private static final String SIG_ANY_BOOL = "(" + signature(IAny.class) + ")Z";
|
||||
private static final String SIG_STRING_ANY = "(" + signature(String.class) + ")" + signature(IAny.class);
|
||||
private static final String SIG_STRING_ANY_VOID = "(" + signature(String.class) + signature(IAny.class) + ")V";
|
||||
private static final String SIG_STRING_ANYARRAY_ANY = "(" + signature(String.class) + signature(IAny[].class) + ")" + signature(IAny.class);
|
||||
private static final String SIG_ANY_ANY_VOID = "(" + signature(IAny.class) + signature(IAny.class) + ")V";
|
||||
private static final String SIG_ANYARRAY_ANY = "(" + signature(IAny[].class) + ")" + signature(IAny.class);
|
||||
|
||||
private AnyClassWriter() {}
|
||||
|
||||
public static byte[] construct(IAnyDefinition definition, String name, Type asmType) {
|
||||
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
writer.visit(
|
||||
Opcodes.V1_6,
|
||||
Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL,
|
||||
name,
|
||||
null,
|
||||
internal(Object.class),
|
||||
new String[] { internal(IAny.class) });
|
||||
|
||||
definition.defineMembers(writer);
|
||||
|
||||
MethodOutput outputStaticCanCastImplicit = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC,
|
||||
"rtCanCastImplicit",
|
||||
"(Ljava/lang/Class;)Z",
|
||||
"(Ljava/lang/Class<*>;)Z",
|
||||
null);
|
||||
outputStaticCanCastImplicit.start();
|
||||
definition.defineStaticCanCastImplicit(outputStaticCanCastImplicit);
|
||||
outputStaticCanCastImplicit.end();
|
||||
|
||||
MethodOutput outputStaticAs = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC,
|
||||
"rtAs",
|
||||
"(ILjava/lang/Class;)Ljava/lang/Object;",
|
||||
"(ILjava/lang/Class<*>;)Ljava/lang/Object;",
|
||||
null);
|
||||
outputStaticAs.start();
|
||||
definition.defineStaticAs(outputStaticAs);
|
||||
outputStaticAs.end();
|
||||
|
||||
MethodOutput outputNot = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"not",
|
||||
SIG_ANY,
|
||||
null,
|
||||
null);
|
||||
outputNot.start();
|
||||
definition.defineNot(outputNot);
|
||||
outputNot.end();
|
||||
|
||||
MethodOutput outputNeg = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"neg",
|
||||
SIG_ANY,
|
||||
null,
|
||||
null);
|
||||
outputNeg.start();
|
||||
definition.defineNeg(outputNeg);
|
||||
outputNeg.end();
|
||||
|
||||
MethodOutput outputAdd = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"add",
|
||||
SIG_ANY_ANY,
|
||||
null,
|
||||
null);
|
||||
outputAdd.start();
|
||||
definition.defineAdd(outputAdd);
|
||||
outputAdd.end();
|
||||
|
||||
MethodOutput outputSub = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"sub",
|
||||
SIG_ANY_ANY,
|
||||
null,
|
||||
null);
|
||||
outputSub.start();
|
||||
definition.defineSub(outputSub);
|
||||
outputSub.end();
|
||||
|
||||
MethodOutput outputCat = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"cat",
|
||||
SIG_ANY_ANY,
|
||||
null,
|
||||
null);
|
||||
outputCat.start();
|
||||
definition.defineCat(outputCat);
|
||||
outputCat.end();
|
||||
|
||||
MethodOutput outputMul = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"mul",
|
||||
SIG_ANY_ANY,
|
||||
null,
|
||||
null);
|
||||
outputMul.start();
|
||||
definition.defineMul(outputMul);
|
||||
outputMul.end();
|
||||
|
||||
MethodOutput outputDiv = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"div",
|
||||
SIG_ANY_ANY,
|
||||
null,
|
||||
null);
|
||||
outputDiv.start();
|
||||
definition.defineDiv(outputDiv);
|
||||
outputDiv.end();
|
||||
|
||||
MethodOutput outputMod = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"mod",
|
||||
SIG_ANY_ANY,
|
||||
null,
|
||||
null);
|
||||
outputMod.start();
|
||||
definition.defineMod(outputMod);
|
||||
outputMod.end();
|
||||
|
||||
MethodOutput outputAnd = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"and",
|
||||
SIG_ANY_ANY,
|
||||
null,
|
||||
null);
|
||||
outputAnd.start();
|
||||
definition.defineAnd(outputAnd);
|
||||
outputAnd.end();
|
||||
|
||||
MethodOutput outputOr = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"or",
|
||||
SIG_ANY_ANY,
|
||||
null,
|
||||
null);
|
||||
outputOr.start();
|
||||
definition.defineOr(outputOr);
|
||||
outputOr.end();
|
||||
|
||||
MethodOutput outputXor = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"xor",
|
||||
SIG_ANY_ANY,
|
||||
null,
|
||||
null);
|
||||
outputXor.start();
|
||||
definition.defineXor(outputXor);
|
||||
outputXor.end();
|
||||
|
||||
MethodOutput outputRange = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"range",
|
||||
SIG_ANY_ANY,
|
||||
null,
|
||||
null);
|
||||
outputRange.start();
|
||||
definition.defineRange(outputRange);
|
||||
outputRange.end();
|
||||
|
||||
MethodOutput outputCompare = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"compareTo",
|
||||
SIG_ANY_INT,
|
||||
null,
|
||||
null);
|
||||
outputCompare.start();
|
||||
definition.defineCompareTo(outputCompare);
|
||||
outputCompare.end();
|
||||
|
||||
MethodOutput outputContains = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"contains",
|
||||
SIG_ANY_BOOL,
|
||||
null,
|
||||
null);
|
||||
outputContains.start();
|
||||
definition.defineContains(outputContains);
|
||||
outputContains.end();
|
||||
|
||||
MethodOutput outputMemberGet = new MethodOutput(writer, Opcodes.ACC_PUBLIC, "memberGet", SIG_STRING_ANY, null, null);
|
||||
outputMemberGet.start();
|
||||
definition.defineMemberGet(outputMemberGet);
|
||||
outputMemberGet.end();
|
||||
|
||||
MethodOutput outputMemberSet = new MethodOutput(writer, Opcodes.ACC_PUBLIC, "memberSet", SIG_STRING_ANY_VOID, null, null);
|
||||
outputMemberSet.start();
|
||||
definition.defineMemberSet(outputMemberSet);
|
||||
outputMemberSet.end();
|
||||
|
||||
MethodOutput outputMemberCall = new MethodOutput(writer, Opcodes.ACC_PUBLIC, "memberCall", SIG_STRING_ANYARRAY_ANY, null, null);
|
||||
outputMemberCall.start();
|
||||
definition.defineMemberCall(outputMemberCall);
|
||||
outputMemberCall.end();
|
||||
|
||||
MethodOutput outputIndexGet = new MethodOutput(writer, Opcodes.ACC_PUBLIC, "indexGet", SIG_ANY_ANY, null, null);
|
||||
outputIndexGet.start();
|
||||
definition.defineIndexGet(outputIndexGet);
|
||||
outputIndexGet.end();
|
||||
|
||||
MethodOutput outputIndexSet = new MethodOutput(writer, Opcodes.ACC_PUBLIC, "indexSet", SIG_ANY_ANY_VOID, null, null);
|
||||
outputIndexSet.start();
|
||||
definition.defineIndexSet(outputIndexSet);
|
||||
outputIndexSet.end();
|
||||
|
||||
MethodOutput outputCall = new MethodOutput(writer, Opcodes.ACC_PUBLIC, "call", SIG_ANYARRAY_ANY, null, null);
|
||||
outputCall.start();
|
||||
definition.defineCall(outputCall);
|
||||
outputCall.end();
|
||||
|
||||
MethodOutput outputAsBool = new MethodOutput(writer, Opcodes.ACC_PUBLIC, "asBool", "()Z", null, null);
|
||||
outputAsBool.start();
|
||||
definition.defineAsBool(outputAsBool);
|
||||
outputAsBool.end();
|
||||
|
||||
MethodOutput outputAsByte = new MethodOutput(writer, Opcodes.ACC_PUBLIC, "asByte", "()B", null, null);
|
||||
outputAsByte.start();
|
||||
definition.defineAsByte(outputAsByte);
|
||||
outputAsByte.end();
|
||||
|
||||
MethodOutput outputAsShort = new MethodOutput(writer, Opcodes.ACC_PUBLIC, "asShort", "()S", null, null);
|
||||
outputAsShort.start();
|
||||
definition.defineAsShort(outputAsShort);
|
||||
outputAsShort.end();
|
||||
|
||||
MethodOutput outputAsInt = new MethodOutput(writer, Opcodes.ACC_PUBLIC, "asInt", "()I", null, null);
|
||||
outputAsInt.start();
|
||||
definition.defineAsInt(outputAsInt);
|
||||
outputAsInt.end();
|
||||
|
||||
MethodOutput outputAsLong = new MethodOutput(writer, Opcodes.ACC_PUBLIC, "asLong", "()J", null, null);
|
||||
outputAsLong.start();
|
||||
definition.defineAsLong(outputAsLong);
|
||||
outputAsLong.end();
|
||||
|
||||
MethodOutput outputAsFloat = new MethodOutput(writer, Opcodes.ACC_PUBLIC, "asFloat", "()F", null, null);
|
||||
outputAsFloat.start();
|
||||
definition.defineAsFloat(outputAsFloat);
|
||||
outputAsFloat.end();
|
||||
|
||||
MethodOutput outputAsDouble = new MethodOutput(writer, Opcodes.ACC_PUBLIC, "asDouble", "()D", null, null);
|
||||
outputAsDouble.start();
|
||||
definition.defineAsDouble(outputAsDouble);
|
||||
outputAsDouble.end();
|
||||
|
||||
MethodOutput outputAsString = new MethodOutput(writer, Opcodes.ACC_PUBLIC, "asString", "()Ljava/lang/String;", null, null);
|
||||
outputAsString.start();
|
||||
definition.defineAsString(outputAsString);
|
||||
outputAsString.end();
|
||||
|
||||
MethodOutput outputAs = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"as",
|
||||
"(Ljava/lang/Class;)" + signature(IAny.class),
|
||||
"<T:Ljava/lang/Object;>(Ljava/lang/Class<TT;>;)TT;",
|
||||
null);
|
||||
outputAs.start();
|
||||
definition.defineAs(outputAs);
|
||||
outputAs.end();
|
||||
|
||||
MethodOutput outputIs = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"is",
|
||||
"(Ljava/lang/Class;)Z",
|
||||
"(Ljava/lang/Class<*>;)Z",
|
||||
null);
|
||||
outputIs.start();
|
||||
definition.defineIs(outputIs);
|
||||
outputIs.end();
|
||||
|
||||
MethodOutput outputCanCastImplicit = new MethodOutput(writer, Opcodes.ACC_PUBLIC, "canCastImplicit", "(" + signature(Class.class) + ")Z", "(Ljava/lang/Class<*>;)Z", null);
|
||||
outputCanCastImplicit.start();
|
||||
outputCanCastImplicit.loadObject(1);
|
||||
outputCanCastImplicit.invokeStatic(name, "rtCanCastImplicit", "(Ljava/lang/Class;)Z");
|
||||
outputCanCastImplicit.returnInt();
|
||||
outputCanCastImplicit.end();
|
||||
|
||||
MethodOutput outputGetNumberType = new MethodOutput(writer, Opcodes.ACC_PUBLIC, "getNumberType", "()I", null, null);
|
||||
outputGetNumberType.start();
|
||||
definition.defineGetNumberType(outputGetNumberType);
|
||||
outputGetNumberType.end();
|
||||
|
||||
MethodOutput outputIteratorSingle = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"iteratorSingle",
|
||||
"()" + signature(Iterator.class),
|
||||
"()Ljava/util/Iterator<Lstanhebben/zenscript/value/IAny;>;",
|
||||
null);
|
||||
outputIteratorSingle.start();
|
||||
definition.defineIteratorSingle(outputIteratorSingle);
|
||||
outputIteratorSingle.end();
|
||||
|
||||
MethodOutput outputIteratorMulti = new MethodOutput(
|
||||
writer,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
"iteratorMulti",
|
||||
"(I)Ljava/util/Iterator;",
|
||||
"(I)Ljava/util/Iterator<[Lstanhebben/zenscript/value/IAny;>;",
|
||||
null);
|
||||
outputIteratorMulti.start();
|
||||
definition.defineIteratorMulti(outputIteratorMulti);
|
||||
outputIteratorMulti.end();
|
||||
|
||||
writer.visitEnd();
|
||||
return writer.toByteArray();
|
||||
}
|
||||
|
||||
public static void throwUnsupportedException(MethodOutput output, String fromType, String operation) {
|
||||
// throw new UnsupportedOperationException(fromType + " does not support the " + operation + " operator");
|
||||
output.newObject(UnsupportedOperationException.class);
|
||||
output.dup();
|
||||
output.constant(fromType + " does not support the " + operation + " operator");
|
||||
output.construct(UnsupportedOperationException.class, String.class);
|
||||
output.aThrow();
|
||||
}
|
||||
|
||||
public static void throwCastException(MethodOutput output, String fromType, String toType) {
|
||||
// throw new ClassCastException("Cannot cast " + fromType + " to " + [local:Class].getName())
|
||||
output.newObject(ClassCastException.class);
|
||||
output.dup();
|
||||
output.constant("Cannot cast " + fromType + " to " + toType);
|
||||
output.construct(ClassCastException.class, String.class);
|
||||
output.aThrow();
|
||||
}
|
||||
|
||||
public static void throwCastException(MethodOutput output, String fromType, int local) {
|
||||
// throw new ClassCastException("Cannot cast " + fromType + " to " + [local:Class].getName())
|
||||
output.newObject(ClassCastException.class);
|
||||
output.dup();
|
||||
|
||||
output.newObject(StringBuilder.class);
|
||||
output.dup();
|
||||
output.construct(StringBuilder.class);
|
||||
output.constant("Cannot cast " + fromType + " to ");
|
||||
output.invokeVirtual(StringBuilder.class, "append", StringBuilder.class, String.class);
|
||||
output.loadObject(local);
|
||||
output.invokeVirtual(Class.class, "getName", String.class);
|
||||
output.invokeVirtual(StringBuilder.class, "append", StringBuilder.class, String.class);
|
||||
output.invokeVirtual(StringBuilder.class, "toString", String.class);
|
||||
|
||||
output.construct(ClassCastException.class, String.class);
|
||||
output.aThrow();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.util;
|
||||
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public interface IAnyDefinition {
|
||||
public void defineMembers(ClassVisitor output);
|
||||
|
||||
public void defineStaticCanCastImplicit(MethodOutput output);
|
||||
|
||||
public void defineStaticAs(MethodOutput output);
|
||||
|
||||
public void defineNot(MethodOutput output);
|
||||
|
||||
public void defineNeg(MethodOutput output);
|
||||
|
||||
public void defineAdd(MethodOutput output);
|
||||
|
||||
public void defineSub(MethodOutput output);
|
||||
|
||||
public void defineCat(MethodOutput output);
|
||||
|
||||
public void defineMul(MethodOutput output);
|
||||
|
||||
public void defineDiv(MethodOutput output);
|
||||
|
||||
public void defineMod(MethodOutput output);
|
||||
|
||||
public void defineAnd(MethodOutput output);
|
||||
|
||||
public void defineOr(MethodOutput output);
|
||||
|
||||
public void defineXor(MethodOutput output);
|
||||
|
||||
public void defineRange(MethodOutput output);
|
||||
|
||||
public void defineCompareTo(MethodOutput output);
|
||||
|
||||
public void defineContains(MethodOutput output);
|
||||
|
||||
public void defineMemberGet(MethodOutput output);
|
||||
|
||||
public void defineMemberSet(MethodOutput output);
|
||||
|
||||
public void defineMemberCall(MethodOutput output);
|
||||
|
||||
public void defineIndexGet(MethodOutput output);
|
||||
|
||||
public void defineIndexSet(MethodOutput output);
|
||||
|
||||
public void defineCall(MethodOutput output);
|
||||
|
||||
public void defineAsBool(MethodOutput output);
|
||||
|
||||
public void defineAsByte(MethodOutput output);
|
||||
|
||||
public void defineAsShort(MethodOutput output);
|
||||
|
||||
public void defineAsInt(MethodOutput output);
|
||||
|
||||
public void defineAsLong(MethodOutput output);
|
||||
|
||||
public void defineAsFloat(MethodOutput output);
|
||||
|
||||
public void defineAsDouble(MethodOutput output);
|
||||
|
||||
public void defineAsString(MethodOutput output);
|
||||
|
||||
public void defineAs(MethodOutput output);
|
||||
|
||||
public void defineIs(MethodOutput output);
|
||||
|
||||
public void defineGetNumberType(MethodOutput output);
|
||||
|
||||
public void defineIteratorSingle(MethodOutput output);
|
||||
|
||||
public void defineIteratorMulti(MethodOutput output);
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.value.builtin.expansion;
|
||||
|
||||
import stanhebben.zenscript.value.IAny;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public interface IByteExpansion {
|
||||
public IAny member(byte value, String member);
|
||||
}
|
||||
Reference in new issue
Block a user