mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-21 12:32:29 +00:00
Tons of changes:
- Added interface to game, client and server - Added transformations - Made ingredient conditions more practical to use, no longer requires imports - Started implementation of event handling - Moved commands and logic to the common API code - Added common interface to MineTweaker recipes - Added string methods - Moved the logger from static value to static getter - Fixed crashes on dedicated servers - Fixed bracket resolution for <id:meta> values in 1.6.4 - Fixed scripts not being sent to multiplayer clients in 1.6.4
This commit is contained in:
1 parent
7f6235f30d
commit
115593efa5
131 files changed
+3215
-1930
No files matched your search
@@ -7,6 +7,7 @@
|
||||
package minetweaker;
|
||||
|
||||
import minetweaker.api.chat.IChatMessage;
|
||||
import minetweaker.api.item.IItemDefinition;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -14,4 +15,8 @@ import minetweaker.api.chat.IChatMessage;
|
||||
*/
|
||||
public interface IPlatformFunctions {
|
||||
public IChatMessage getMessage(String message);
|
||||
|
||||
public void distributeScripts(byte[] data);
|
||||
|
||||
public IItemDefinition getItemDefinition(int id);
|
||||
}
|
||||
@@ -11,15 +11,18 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import minetweaker.annotations.BracketHandler;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.client.IClient;
|
||||
import minetweaker.api.event.IEventManager;
|
||||
import minetweaker.api.game.IGame;
|
||||
import minetweaker.api.mods.ILoadedMods;
|
||||
import minetweaker.runtime.IMineTweaker;
|
||||
import minetweaker.runtime.ITweaker;
|
||||
import minetweaker.runtime.ILogger;
|
||||
import minetweaker.runtime.Tweaker;
|
||||
import minetweaker.runtime.MTTweaker;
|
||||
import minetweaker.api.recipes.IRecipeManager;
|
||||
import minetweaker.api.oredict.IOreDict;
|
||||
import minetweaker.api.recipes.IFurnaceManager;
|
||||
import minetweaker.api.resource.IResourceManager;
|
||||
import minetweaker.api.server.IServer;
|
||||
import minetweaker.runtime.GlobalRegistry;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
@@ -57,12 +60,13 @@ public class MineTweakerAPI {
|
||||
registerClass(cls);
|
||||
}
|
||||
|
||||
registerGlobalSymbol("logger", getJavaStaticFieldSymbol(MineTweakerAPI.class, "logger"));
|
||||
registerGlobalSymbol("logger", getJavaStaticGetterSymbol(MineTweakerAPI.class, "getLogger"));
|
||||
registerGlobalSymbol("tweaker", getJavaStaticFieldSymbol(MineTweakerAPI.class, "tweaker"));
|
||||
registerGlobalSymbol("recipes", getJavaStaticFieldSymbol(MineTweakerAPI.class, "recipes"));
|
||||
registerGlobalSymbol("furnace", getJavaStaticFieldSymbol(MineTweakerAPI.class, "furnace"));
|
||||
registerGlobalSymbol("oreDict", getJavaStaticFieldSymbol(MineTweakerAPI.class, "oreDict"));
|
||||
registerGlobalSymbol("events", getJavaStaticFieldSymbol(MineTweakerAPI.class, "events"));
|
||||
registerGlobalSymbol("server", getJavaStaticFieldSymbol(MineTweakerAPI.class, "server"));
|
||||
}
|
||||
|
||||
private MineTweakerAPI() {}
|
||||
@@ -71,13 +75,17 @@ public class MineTweakerAPI {
|
||||
* The Tweaker is where you apply undoable actions. Any kind of action that
|
||||
* reloads with the scripts should always be submitted to the tweaker.
|
||||
*/
|
||||
public static final IMineTweaker tweaker = new Tweaker();
|
||||
public static final ITweaker tweaker = new MTTweaker();
|
||||
|
||||
/**
|
||||
* The logger can be used to write logging messages to the client. Error and
|
||||
* warning messages should be relayed to admins for further handling.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static ILogger logger = null;
|
||||
public static final ILogger getLogger() {
|
||||
return MineTweakerImplementationAPI.logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access point to the ore dictionary.
|
||||
@@ -97,7 +105,22 @@ public class MineTweakerAPI {
|
||||
/**
|
||||
* Access point to the events manager.
|
||||
*/
|
||||
public static IEventManager events = null;
|
||||
public static final IEventManager events = MineTweakerImplementationAPI.events;
|
||||
|
||||
/**
|
||||
* Access point to the server, if any.
|
||||
*/
|
||||
public static IServer server = null;
|
||||
|
||||
/**
|
||||
* Access point to the client, if any.
|
||||
*/
|
||||
public static IClient client = null;
|
||||
|
||||
/**
|
||||
* Access point to general game data, such as items.
|
||||
*/
|
||||
public static IGame game = null;
|
||||
|
||||
/**
|
||||
* Access point to mods list.
|
||||
@@ -110,11 +133,6 @@ public class MineTweakerAPI {
|
||||
*/
|
||||
public static IResourceManager resources = null;
|
||||
|
||||
/**
|
||||
* Access point to general platform functions.
|
||||
*/
|
||||
public static IPlatformFunctions platform = null;
|
||||
|
||||
/**
|
||||
* Register a class registry class. Such class must have (at least) a public
|
||||
* static method called "getClasses" with accepts a List of classes and which
|
||||
|
||||
@@ -0,0 +1,432 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import minetweaker.api.logger.MTLogger;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import static minetweaker.MineTweakerAPI.server;
|
||||
import minetweaker.api.event.IPlayerLoggedInEventHandler;
|
||||
import minetweaker.api.event.IPlayerLoggedOutEventHandler;
|
||||
import minetweaker.api.event.MTEventManager;
|
||||
import minetweaker.api.event.PlayerLoggedInEvent;
|
||||
import minetweaker.api.event.PlayerLoggedOutEvent;
|
||||
import minetweaker.api.item.IItemDefinition;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.liquid.ILiquidDefinition;
|
||||
import minetweaker.api.mods.IMod;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.server.ICommandFunction;
|
||||
import minetweaker.api.server.ICommandValidator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MineTweakerImplementationAPI {
|
||||
private static final Map<String, MineTweakerCommand> minetweakerCommands;
|
||||
private static final Comparator<IItemDefinition> ITEM_COMPARATOR = new ItemComparator();
|
||||
private static final Comparator<ILiquidDefinition> LIQUID_COMPARATOR = new LiquidComparator();
|
||||
private static final ListenPlayerLoggedIn LISTEN_LOGIN = new ListenPlayerLoggedIn();
|
||||
private static final ListenPlayerLoggedOut LISTEN_LOGOUT = new ListenPlayerLoggedOut();
|
||||
|
||||
static {
|
||||
minetweakerCommands = new HashMap<String, MineTweakerCommand>();
|
||||
|
||||
minetweakerCommands.put("reload", new MineTweakerCommand(
|
||||
"reload",
|
||||
new String[] {
|
||||
"/minetweaker reload",
|
||||
" Reloads all scripts"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
reload();
|
||||
player.sendChat(platform.getMessage("Scripts reloaded"));
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("names", new MineTweakerCommand(
|
||||
"names",
|
||||
new String[] {
|
||||
"/minetweaker names",
|
||||
" Outputs a list of all item names in the game to the minetweaker log"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
List<IItemDefinition> items = MineTweakerAPI.game.getItems();
|
||||
Collections.sort(items, ITEM_COMPARATOR);
|
||||
for (IItemDefinition item : items) {
|
||||
String displayName = "";
|
||||
|
||||
try {
|
||||
displayName = " -- " + item.makeStack(0).getDisplayName();
|
||||
} catch (Exception ex) {
|
||||
// some mods (such as buildcraft) may throw exceptions when calling
|
||||
// getDisplayName on an item stack that doesn't contain valid NBT data
|
||||
}
|
||||
|
||||
MineTweakerAPI.getLogger().logCommand("<" + item.getId() + ">" + displayName);
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
player.sendChat(platform.getMessage("List generated; see minetweaker.log in your minecraft dir"));
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("liquids", new MineTweakerCommand(
|
||||
"liquids",
|
||||
new String[] {
|
||||
"/minetweaker liquids",
|
||||
" Outputs a list of all liquid names in the game to the minetweaker log"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
List<ILiquidDefinition> liquids = MineTweakerAPI.game.getLiquids();
|
||||
System.out.println("Liquids: " + liquids.size());
|
||||
Collections.sort(liquids, LIQUID_COMPARATOR);
|
||||
for (ILiquidDefinition liquid : liquids) {
|
||||
System.out.println("Liquid " + liquid.getName());
|
||||
MineTweakerAPI.getLogger().logCommand("<" + liquid.getName() + "> -- " + liquid.getDisplayName());
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
player.sendChat(platform.getMessage("List generated; see minetweaker.log in your minecraft dir"));
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("inventory", new MineTweakerCommand(
|
||||
"inventory",
|
||||
new String[] {
|
||||
"/minetweaker inventory",
|
||||
" Lists all items in your inventory"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
for (int i = 0; i < player.getInventorySize(); i++) {
|
||||
IItemStack stack = player.getInventoryStack(i);
|
||||
if (stack != null) {
|
||||
player.sendChat(platform.getMessage(stack.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("hand", new MineTweakerCommand(
|
||||
"hand",
|
||||
new String[] {
|
||||
"/minetweaker hand",
|
||||
" Outputs the name of the item in your hand"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
IItemStack hand = player.getCurrentItem();
|
||||
if (hand != null) {
|
||||
player.sendChat(platform.getMessage(hand.toString()));
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("oredict", new MineTweakerCommand(
|
||||
"oredict",
|
||||
new String[] {
|
||||
"/minetweaker oredict",
|
||||
" Outputs all ore dictionary entries in the game to the minetweaker log",
|
||||
"/minetweaker oredict <name>",
|
||||
" Outputs all items in the given ore dictionary entry to the minetweaker log"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
if (arguments.length > 0) {
|
||||
String entryName = arguments[0];
|
||||
IOreDictEntry entry = MineTweakerAPI.oreDict.get(entryName);
|
||||
if (entry.isEmpty()) {
|
||||
player.sendChat(platform.getMessage("Entry doesn't exist"));
|
||||
return;
|
||||
} else {
|
||||
MineTweakerAPI.getLogger().logCommand("Ore entries for " + entryName + ":");
|
||||
for (IItemStack ore : entry.getItems()) {
|
||||
MineTweakerAPI.getLogger().logCommand(" " + ore);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (IOreDictEntry entry : MineTweakerAPI.oreDict.getEntries()) {
|
||||
if (!entry.isEmpty()) {
|
||||
MineTweakerAPI.getLogger().logCommand("Ore entries for <ore:" + entry.getName() + "> :");
|
||||
for (IItemStack ore : entry.getItems()) {
|
||||
MineTweakerAPI.getLogger().logCommand(" " + ore);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
player.sendChat(platform.getMessage("List generated; see minetweaker.log in your minecraft dir"));
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("mods", new MineTweakerCommand(
|
||||
"mods",
|
||||
new String[] {
|
||||
"/minetweaker mods",
|
||||
" Outputs all active mod IDs and versions in the game"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
MineTweakerAPI.getLogger().logCommand("Mods list:");
|
||||
for (IMod mod : MineTweakerAPI.loadedMods) {
|
||||
String message = mod.getId() + " - " + mod.getName() + " - " + mod.getVersion();
|
||||
player.sendChat(platform.getMessage(message));
|
||||
MineTweakerAPI.getLogger().logCommand("Mod: " + message);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("name", new MineTweakerCommand(
|
||||
"name",
|
||||
new String[] {
|
||||
"/minetweaker name <id>",
|
||||
" Outputs the name for the given item ID",
|
||||
},
|
||||
new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
if (arguments.length < 1) {
|
||||
player.sendChat(platform.getMessage("missing id parameter"));
|
||||
} else {
|
||||
try {
|
||||
int id = Integer.parseInt(arguments[0]);
|
||||
IItemDefinition definition = platform.getItemDefinition(id);
|
||||
if (definition == null) {
|
||||
player.sendChat(platform.getMessage("no such item"));
|
||||
} else {
|
||||
StringBuilder description = new StringBuilder();
|
||||
description.append('<');
|
||||
description.append(definition.getId());
|
||||
description.append('>');
|
||||
player.sendChat(platform.getMessage(description.toString()));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
MineTweakerAPI.getLogger().logCommand("ID must be an integer");
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("wiki", new MineTweakerCommand(
|
||||
"wiki",
|
||||
new String[] {
|
||||
"/minetweaker wiki",
|
||||
" Opens your browser with the wiki"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
player.openBrowser("http://minetweaker3.powerofbytes.com/wiki/");
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("bugs", new MineTweakerCommand(
|
||||
"bugs",
|
||||
new String[] {
|
||||
"/minetweaker bugs",
|
||||
" Opens your browser with the GitHub bug tracker"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
player.openBrowser("https://github.com/stanhebben/MineTweaker3/issues");
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("forum", new MineTweakerCommand(
|
||||
"forum",
|
||||
new String[] {
|
||||
"/minetweaker forum",
|
||||
" Opens your browser with the forum"
|
||||
}, 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");
|
||||
}
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Access point to the event handler implementation.
|
||||
*/
|
||||
public static final MTEventManager events = new MTEventManager();
|
||||
|
||||
public static final MTLogger logger = new MTLogger();
|
||||
|
||||
/**
|
||||
* Access point to general platform functions.
|
||||
*/
|
||||
public static IPlatformFunctions platform = null;
|
||||
|
||||
public static void onServerStart() {
|
||||
reload();
|
||||
}
|
||||
|
||||
public static void onServerStop() {
|
||||
|
||||
}
|
||||
|
||||
public static void reload() {
|
||||
logger.clear();
|
||||
events.clear();
|
||||
|
||||
if (MineTweakerAPI.server != null) {
|
||||
events.onPlayerLoggedIn(LISTEN_LOGIN);
|
||||
events.onPlayerLoggedOut(LISTEN_LOGOUT);
|
||||
}
|
||||
|
||||
MineTweakerAPI.tweaker.rollback();
|
||||
|
||||
if (MineTweakerAPI.server != null) {
|
||||
server.addCommand("minetweaker", "", new String[] { "mt" }, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
if (arguments.length == 0) {
|
||||
player.sendChat(platform.getMessage("Please provide a command. Use /mt help for more info."));
|
||||
} else if (arguments[0].equals("help")) {
|
||||
String[] keys = minetweakerCommands.keySet().toArray(new String[minetweakerCommands.size()]);
|
||||
Arrays.sort(keys);
|
||||
for (String key : keys) {
|
||||
for (String helpMessage : minetweakerCommands.get(key).description) {
|
||||
player.sendChat(platform.getMessage(helpMessage));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MineTweakerCommand command = minetweakerCommands.get(arguments[0]);
|
||||
if (command == null) {
|
||||
player.sendChat(platform.getMessage("No such minetweaker command available"));
|
||||
} else {
|
||||
command.function.execute(Arrays.copyOfRange(arguments, 1, arguments.length), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, new ICommandValidator() {
|
||||
@Override
|
||||
public boolean canExecute(IPlayer player) {
|
||||
return server.isOp(player);
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
MineTweakerAPI.tweaker.load();
|
||||
|
||||
if (MineTweakerAPI.server != null) {
|
||||
platform.distributeScripts(MineTweakerAPI.tweaker.getScriptData());
|
||||
}
|
||||
}
|
||||
|
||||
public static void addMineTweakerCommand(String name, String[] description, ICommandFunction function) {
|
||||
MineTweakerAPI.tweaker.apply(new AddMineTweakerCommandAction(new MineTweakerCommand(name, description, function)));
|
||||
}
|
||||
|
||||
public static void callMineTweakerCommand(String[] arguments, IPlayer player) {
|
||||
if (minetweakerCommands.containsKey(arguments[0])) {
|
||||
minetweakerCommands.get(arguments[0]).function.execute(
|
||||
Arrays.copyOfRange(arguments, 1, arguments.length),
|
||||
player);
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<String> getMineTweakerCommands() {
|
||||
return minetweakerCommands.keySet();
|
||||
}
|
||||
|
||||
public static String[] getMineTweakerCommandDescription(String command) {
|
||||
return minetweakerCommands.get(command).description;
|
||||
}
|
||||
|
||||
private static class AddMineTweakerCommandAction implements IUndoableAction {
|
||||
private final MineTweakerCommand command;
|
||||
|
||||
public AddMineTweakerCommandAction(MineTweakerCommand command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
minetweakerCommands.put(command.name, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
minetweakerCommands.remove(command.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding minetweaker command " + command.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing minetweaker command " + command.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class MineTweakerCommand {
|
||||
private final String name;
|
||||
private final String[] description;
|
||||
private final ICommandFunction function;
|
||||
|
||||
public MineTweakerCommand(String name, String[] description, ICommandFunction function) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.function = function;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ItemComparator implements Comparator<IItemDefinition> {
|
||||
@Override
|
||||
public int compare(IItemDefinition o1, IItemDefinition o2) {
|
||||
return o1.getId().compareTo(o2.getId());
|
||||
}
|
||||
}
|
||||
|
||||
private static class LiquidComparator implements Comparator<ILiquidDefinition> {
|
||||
@Override
|
||||
public int compare(ILiquidDefinition o1, ILiquidDefinition o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ListenPlayerLoggedIn implements IPlayerLoggedInEventHandler {
|
||||
@Override
|
||||
public void handle(PlayerLoggedInEvent event) {
|
||||
if (MineTweakerAPI.server != null && MineTweakerAPI.server.isOp(event.getPlayer())) {
|
||||
logger.addPlayer(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ListenPlayerLoggedOut implements IPlayerLoggedOutEventHandler {
|
||||
@Override
|
||||
public void handle(PlayerLoggedOutEvent event) {
|
||||
logger.removePlayer(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -4,9 +4,9 @@
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.world;
|
||||
package minetweaker.api.client;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
@@ -14,8 +14,8 @@ import stanhebben.zenscript.annotations.ZenGetter;
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.world.IGame")
|
||||
public interface IGame {
|
||||
@ZenGetter("dimensions")
|
||||
public List<IDimension> getDimensions();
|
||||
@ZenClass("minetweaker.api.IClient")
|
||||
public interface IClient {
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer();
|
||||
}
|
||||
@@ -203,6 +203,10 @@ public class DataMap implements IData {
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
if (data instanceof DataString) {
|
||||
return this.data.containsKey(data.asString());
|
||||
}
|
||||
|
||||
Map<String, IData> dataMap = data.asMap();
|
||||
for (Map.Entry<String, IData> dataEntry : dataMap.entrySet()) {
|
||||
if (!this.data.containsKey(dataEntry.getKey())) {
|
||||
|
||||
+24
-1
@@ -12,7 +12,30 @@ import minetweaker.util.EventList;
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class AbstractEventManager implements IEventManager {
|
||||
public class MTEventManager implements IEventManager {
|
||||
public void clear() {
|
||||
elPlayerCrafted.clear();
|
||||
elPlayerSmelted.clear();
|
||||
elPlayerChangedDimension.clear();
|
||||
elPlayerLoggedIn.clear();
|
||||
elPlayerLoggedOut.clear();
|
||||
elPlayerRespawn.clear();
|
||||
elPlayerAttackEntity.clear();
|
||||
elPlayerBonemeal.clear();
|
||||
elPlayerInteractEntity.clear();
|
||||
elPlayerPickup.clear();
|
||||
elPlayerPickupItem.clear();
|
||||
elPlayerFillBucket.clear();
|
||||
elPlayerDeathDrops.clear();
|
||||
elPlayerInteract.clear();
|
||||
elPlayerOpenContainer.clear();
|
||||
elPlayerPickupXp.clear();
|
||||
elPlayerSleepInBed.clear();
|
||||
elPlayerUseHoe.clear();
|
||||
elPlayerUseItemStart.clear();
|
||||
elPlayerUseItemTick.clear();
|
||||
}
|
||||
|
||||
// ##########################
|
||||
// ### PlayerCraftedEvent ###
|
||||
// ##########################
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.api.game;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.api.item.IItemDefinition;
|
||||
import minetweaker.api.liquid.ILiquidDefinition;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.game.IGame")
|
||||
public interface IGame {
|
||||
@ZenGetter("items")
|
||||
public List<IItemDefinition> getItems();
|
||||
|
||||
@ZenGetter("liquids")
|
||||
public List<ILiquidDefinition> getLiquids();
|
||||
}
|
||||
@@ -115,6 +115,9 @@ public interface IIngredient {
|
||||
@ZenMethod
|
||||
public IItemStack applyTransform(IItemStack item);
|
||||
|
||||
@ZenGetter("hasTransformations")
|
||||
public boolean hasTransformers();
|
||||
|
||||
/**
|
||||
* Gets the internal item backing this ingredient.
|
||||
*
|
||||
|
||||
@@ -6,7 +6,11 @@
|
||||
|
||||
package minetweaker.api.item;
|
||||
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.ZenSetter;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -14,5 +18,12 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IItemDefinition")
|
||||
public interface IItemDefinition {
|
||||
@ZenGetter("id")
|
||||
public String getId();
|
||||
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
|
||||
@ZenMethod
|
||||
public IItemStack makeStack(@Optional int meta);
|
||||
}
|
||||
@@ -70,6 +70,11 @@ public class IngredientAny implements IIngredient {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return INTERNAL_ANY;
|
||||
|
||||
@@ -89,6 +89,11 @@ public class IngredientAnyAdvanced implements IIngredient {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return IngredientAny.INTERNAL_ANY;
|
||||
|
||||
+28
-23
@@ -7,8 +7,7 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.data.IData;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
@@ -18,104 +17,110 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.Condition")
|
||||
public class Condition {
|
||||
@ZenExpansion("minetweaker.item.IIngredient")
|
||||
public class IngredientCondition {
|
||||
/**
|
||||
* Requires the item to be damaged. A damage value of 1 is enough.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @return damaged condition
|
||||
*/
|
||||
@ZenGetter
|
||||
public static IItemCondition damaged() {
|
||||
return new IItemCondition() {
|
||||
@ZenMethod
|
||||
public static IIngredient onlyDamaged(IIngredient ingredient) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() > 0;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item to be damaged with at least a specified amount.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param minDamage minimum damage
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemCondition damageAtLeast(final int minDamage) {
|
||||
return new IItemCondition() {
|
||||
public static IIngredient onlyDamageAtLeast(IIngredient ingredient, final int minDamage) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() >= minDamage;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item to be damaged with at most a specified amount. An
|
||||
* undamaged item is accepted.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param maxDamage maximum damage
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemCondition damageAtMost(final int maxDamage) {
|
||||
return new IItemCondition() {
|
||||
public static IIngredient onlyDamageAtMost(IIngredient ingredient, final int maxDamage) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() <= maxDamage;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item damage value to be between two values.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param minDamage minimum damage
|
||||
* @param maxDamage maximum damage
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemCondition damageBetween(final int minDamage, final int maxDamage) {
|
||||
return new IItemCondition() {
|
||||
public static IIngredient onlyDamageBetween(IIngredient ingredient, final int minDamage, final int maxDamage) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() >= minDamage && stack.getDamage() <= maxDamage;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item to contain at least the given tags. It is OK for the
|
||||
* item to contain more data, as remaining data is ignored.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param data required data
|
||||
* @return data condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemCondition data(final IData data) {
|
||||
return new IItemCondition() {
|
||||
public static IIngredient onlyWithTag(IIngredient ingredient, final IData data) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getTag() != null && stack.getTag().contains(data);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the input stack to contain at least the given number of items.
|
||||
* Used in combination with stack consuming recipes.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param amount required stack size
|
||||
* @return stack size condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemCondition stack(final int amount) {
|
||||
return new IItemCondition() {
|
||||
public static IIngredient onlyStack(IIngredient ingredient, final int amount) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getAmount() >= amount;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class IngredientItem implements IIngredient {
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
if (!item.matches(item)) return false;
|
||||
if (!this.item.matches(item)) return false;
|
||||
|
||||
for (IItemCondition condition : conditions) {
|
||||
if (!condition.matches(item)) return false;
|
||||
@@ -95,6 +95,11 @@ public class IngredientItem implements IIngredient {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return item.getInternal();
|
||||
|
||||
@@ -75,4 +75,9 @@ public class IngredientStack implements IIngredient {
|
||||
public Object getInternal() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return ingredient.hasTransformers();
|
||||
}
|
||||
}
|
||||
+26
-23
@@ -6,49 +6,51 @@
|
||||
|
||||
package minetweaker.api.item;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.item.Transform")
|
||||
public class Transform {
|
||||
@ZenExpansion("minetweaker.item.IIngredient")
|
||||
public class IngredientTransform {
|
||||
/**
|
||||
* Makes the item reusable. Prevents consumption of the item upon crafting.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @return reuse transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemTransformer reuse() {
|
||||
return new IItemTransformer() {
|
||||
public static IIngredient reuse(IIngredient ingredient) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item) {
|
||||
return item.withAmount(item.getAmount() + 1);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Damages the item. Also makes the item reusable. Will damage the item
|
||||
* for 1 point upon crafting and consume it when broken.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @return damage transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemTransformer damage() {
|
||||
return new IItemTransformer() {
|
||||
public static IIngredient transformDamage(IIngredient ingredient) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item) {
|
||||
int newDamage = item.getDamage() + 1;
|
||||
if (newDamage >= item.getMaxDamage()) {
|
||||
return item.withAmount(item.getAmount() - 1).withDamage(0);
|
||||
return item.withAmount(item.getAmount()).withDamage(0);
|
||||
} else {
|
||||
return item.withDamage(newDamage);
|
||||
return item.withAmount(item.getAmount() + 1).withDamage(newDamage);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,12 +59,13 @@ public class Transform {
|
||||
* set the proper condition such that an almost-broken item becomes
|
||||
* invalid for crafting.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param damage damage to be applied
|
||||
* @return damage transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemTransformer damage(final int damage) {
|
||||
return new IItemTransformer() {
|
||||
public static IIngredient transformDamage(IIngredient ingredient, final int damage) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item) {
|
||||
int newDamage = item.getDamage() + damage;
|
||||
@@ -72,26 +75,25 @@ public class Transform {
|
||||
return item.withDamage(newDamage);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the item to be replaced upon crafting. Can be used, for instance,
|
||||
* to return empty bottles or buckets.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param withItem replacement item
|
||||
* @return replacement transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemTransformer replaceWith(IItemStack withItem) {
|
||||
final IItemStack result = withItem.withAmount(withItem.getAmount() + 1);
|
||||
|
||||
return new IItemTransformer() {
|
||||
public static IIngredient transformReplace(IIngredient ingredient, final IItemStack withItem) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item) {
|
||||
return result;
|
||||
return withItem.withAmount(withItem.getAmount() + 1);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,16 +101,17 @@ public class Transform {
|
||||
* a minimum stack size too, as otherwise smaller stacks would still be
|
||||
* accepted for input.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param amount consumption amount
|
||||
* @return consuming transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemTransformer consume(final int amount) {
|
||||
return new IItemTransformer() {
|
||||
public static IIngredient transformConsume(IIngredient ingredient, final int amount) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item) {
|
||||
return item.withAmount(Math.max(item.getAmount() - amount, 0) + 1);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.api.logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
import minetweaker.runtime.ILogger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class FileLogger implements ILogger {
|
||||
private final Writer writer;
|
||||
|
||||
public FileLogger(File output) {
|
||||
try {
|
||||
writer = new OutputStreamWriter(new FileOutputStream(output), "utf-8");
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
throw new RuntimeException("What the heck?");
|
||||
} catch (FileNotFoundException ex) {
|
||||
throw new RuntimeException("File not found");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
try {
|
||||
writer.write("COMMAND: " + message + "\n");
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
try {
|
||||
writer.write("INFO: " + message + "\n");
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarning(String message) {
|
||||
try {
|
||||
writer.write("WARNING: " + message + "\n");
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
try {
|
||||
writer.write("ERROR: " + message + "\n");
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.api.logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.MineTweakerImplementationAPI;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.runtime.ILogger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MTLogger implements ILogger {
|
||||
private final List<ILogger> loggers = new ArrayList<ILogger>();
|
||||
private final List<IPlayer> players = new ArrayList<IPlayer>();
|
||||
private final List<String> unprocessed = new ArrayList<String>();
|
||||
|
||||
public void addLogger(ILogger logger) {
|
||||
loggers.add(logger);
|
||||
}
|
||||
|
||||
public void removeLogger(ILogger logger) {
|
||||
loggers.remove(logger);
|
||||
}
|
||||
|
||||
public void addPlayer(IPlayer player) {
|
||||
players.add(player);
|
||||
|
||||
if (!unprocessed.isEmpty()) {
|
||||
for (String message : unprocessed) {
|
||||
player.sendChat(MineTweakerImplementationAPI.platform.getMessage(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayer(IPlayer player) {
|
||||
players.remove(player);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
unprocessed.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logCommand(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logInfo(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarning(String message) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logWarning(message);
|
||||
}
|
||||
|
||||
String message2 = "WARNING: " + message;
|
||||
|
||||
if (players.isEmpty()) {
|
||||
unprocessed.add(message2);
|
||||
} else {
|
||||
for (IPlayer player : players) {
|
||||
player.sendChat(MineTweakerImplementationAPI.platform.getMessage(message2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logError(message);
|
||||
}
|
||||
|
||||
String message2 = "ERROR: " + message;
|
||||
|
||||
if (players.isEmpty()) {
|
||||
unprocessed.add(message2);
|
||||
} else {
|
||||
for (IPlayer player : players) {
|
||||
player.sendChat(MineTweakerImplementationAPI.platform.getMessage(message2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,9 @@
|
||||
|
||||
package minetweaker.api.oredict;
|
||||
|
||||
import java.util.List;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMemberGetter;
|
||||
|
||||
/**
|
||||
@@ -17,4 +19,7 @@ import stanhebben.zenscript.annotations.ZenMemberGetter;
|
||||
public interface IOreDict {
|
||||
@ZenMemberGetter
|
||||
public IOreDictEntry get(String name);
|
||||
|
||||
@ZenGetter("entries")
|
||||
public List<IOreDictEntry> getEntries();
|
||||
}
|
||||
@@ -18,6 +18,9 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
*/
|
||||
@ZenClass("minetweaker.oredict.IOreDictEntry")
|
||||
public interface IOreDictEntry extends IIngredient {
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
|
||||
@ZenGetter("empty")
|
||||
public boolean isEmpty();
|
||||
|
||||
|
||||
@@ -95,6 +95,11 @@ public class IngredientOreDict implements IIngredient {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return entry.getInternal();
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
|
||||
package minetweaker.api.player;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.api.chat.IChatMessage;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
@@ -18,6 +20,9 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
*/
|
||||
@ZenClass("minetweaker.player.IPlayer")
|
||||
public interface IPlayer {
|
||||
@ZenGetter("id")
|
||||
public String getId();
|
||||
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
|
||||
@@ -29,4 +34,21 @@ public interface IPlayer {
|
||||
|
||||
@ZenMethod
|
||||
public void sendChat(IChatMessage message);
|
||||
|
||||
@ZenGetter("hotbarSize")
|
||||
public int getHotbarSize();
|
||||
|
||||
@ZenMethod
|
||||
public IItemStack getHotbarStack(int i);
|
||||
|
||||
@ZenGetter("inventorySize")
|
||||
public int getInventorySize();
|
||||
|
||||
@ZenMethod
|
||||
public IItemStack getInventoryStack(int i);
|
||||
|
||||
@ZenGetter("currentItem")
|
||||
public IItemStack getCurrentItem();
|
||||
|
||||
public void openBrowser(String url);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.api.recipes;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IDimension;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class CraftingInfo implements ICraftingInfo {
|
||||
private final ICraftingInventory inventory;
|
||||
private final IDimension dimension;
|
||||
|
||||
public CraftingInfo(ICraftingInventory inventory, IDimension dimension) {
|
||||
this.inventory = inventory;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingInventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayer getPlayer() {
|
||||
return inventory.getPlayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDimension getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.api.recipes;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.ICraftingInfo")
|
||||
public interface ICraftingInfo {
|
||||
@ZenGetter("inventory")
|
||||
public ICraftingInventory getInventory();
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer();
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension();
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.ICraftingRecipe")
|
||||
public interface ICraftingRecipe {
|
||||
public boolean matches(ICraftingInventory inventory);
|
||||
|
||||
public IItemStack getCraftingResult(ICraftingInventory inventory);
|
||||
|
||||
public boolean hasTransformers();
|
||||
|
||||
public void applyTransformers(ICraftingInventory inventory);
|
||||
}
|
||||
@@ -16,5 +16,5 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IRecipeFunction")
|
||||
public interface IRecipeFunction {
|
||||
public IItemStack process(IItemStack output, Map<String, IItemStack> inputs, ICraftingInventory inventory);
|
||||
public IItemStack process(IItemStack output, Map<String, IItemStack> inputs, ICraftingInfo craftingInfo);
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import minetweaker.api.item.IItemStack;
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapedRecipe {
|
||||
public class ShapedRecipe implements ICraftingRecipe {
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final byte[] posx;
|
||||
@@ -93,6 +93,7 @@ public class ShapedRecipe {
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ICraftingInventory inventory) {
|
||||
if (inventory.getStackCount() != ingredients.length) {
|
||||
return false;
|
||||
@@ -129,6 +130,7 @@ public class ShapedRecipe {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getCraftingResult(ICraftingInventory inventory) {
|
||||
IItemStack[] stacks = new IItemStack[ingredients.length];
|
||||
|
||||
@@ -165,6 +167,54 @@ public class ShapedRecipe {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
for (IIngredient ingredient : ingredients) {
|
||||
if (ingredient.hasTransformers()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTransformers(ICraftingInventory inventory) {
|
||||
IItemStack[] stacks = new IItemStack[ingredients.length];
|
||||
|
||||
for (int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
|
||||
if (item == null) continue out;
|
||||
|
||||
if (!ingredients[k].matches(item)) continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
doRecipeTransformers(inventory, stacks, i, j, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (mirrored) {
|
||||
for (int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(inventory.getWidth() - (posx[k] + i) - 1, posy[k] + j);
|
||||
if (item == null) continue out;
|
||||
|
||||
if (!ingredients[k].matches(item)) continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
doRecipeTransformers(inventory, stacks, i, j, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IItemStack doRecipe(
|
||||
ICraftingInventory inventory,
|
||||
IItemStack[] stacks,
|
||||
@@ -181,7 +231,8 @@ public class ShapedRecipe {
|
||||
}
|
||||
}
|
||||
|
||||
output = function.process(output, tagged, inventory);
|
||||
// TODO: supply dimension
|
||||
output = function.process(output, tagged, new CraftingInfo(inventory, null));
|
||||
System.out.println("Ouput: " + output);
|
||||
}
|
||||
|
||||
@@ -189,6 +240,31 @@ public class ShapedRecipe {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*for (int i = 0; i < ingredients.length; i++) {
|
||||
IItemStack transformed = ingredients[i].applyTransform(stacks[i]);
|
||||
if (transformed != stacks[i]) {
|
||||
if (mirrored) {
|
||||
inventory.setStack(
|
||||
inventory.getWidth() - (offx + posx[i]) - 1,
|
||||
offy + posy[i],
|
||||
transformed);
|
||||
} else {
|
||||
inventory.setStack(
|
||||
offx + posx[i],
|
||||
offy + posy[i],
|
||||
transformed);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private void doRecipeTransformers(
|
||||
ICraftingInventory inventory,
|
||||
IItemStack[] stacks,
|
||||
int offx, int offy,
|
||||
boolean mirrored) {
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
IItemStack transformed = ingredients[i].applyTransform(stacks[i]);
|
||||
if (transformed != stacks[i]) {
|
||||
@@ -205,7 +281,5 @@ public class ShapedRecipe {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import minetweaker.api.item.IItemStack;
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapelessRecipe {
|
||||
public class ShapelessRecipe implements ICraftingRecipe {
|
||||
private final IItemStack output;
|
||||
private final IRecipeFunction function;
|
||||
private final IIngredient[] ingredients;
|
||||
@@ -38,10 +38,12 @@ public class ShapelessRecipe {
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ICraftingInventory inventory) {
|
||||
return matchShapeless(ingredients, inventory) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getCraftingResult(ICraftingInventory inventory) {
|
||||
RecipeMatching matching = matchShapeless(ingredients, inventory);
|
||||
|
||||
@@ -54,13 +56,20 @@ public class ShapelessRecipe {
|
||||
}
|
||||
}
|
||||
|
||||
actualOutput = function.process(actualOutput, map, inventory);
|
||||
actualOutput = function.process(actualOutput, map, new CraftingInfo(inventory, null));
|
||||
}
|
||||
|
||||
if (actualOutput == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return actualOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTransformers(ICraftingInventory inventory) {
|
||||
RecipeMatching matching = matchShapeless(ingredients, inventory);
|
||||
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
IIngredient ingredient = ingredients[i];
|
||||
IItemStack transformed = ingredient.applyTransform(matching.inputs[i]);
|
||||
@@ -68,8 +77,6 @@ public class ShapelessRecipe {
|
||||
inventory.setStack(matching.indices[i], transformed);
|
||||
}
|
||||
}
|
||||
|
||||
return actualOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,6 +123,17 @@ public class ShapelessRecipe {
|
||||
return new RecipeMatching(matched, indices);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
for (IIngredient ingredient : ingredients) {
|
||||
if (ingredient.hasTransformers()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static class RecipeMatching {
|
||||
public final IItemStack[] inputs;
|
||||
public final int[] indices;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.api.server;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.server.CommandValidators")
|
||||
public class CommandValidators {
|
||||
public static final ICommandValidator ISOP = new ICommandValidator() {
|
||||
@Override
|
||||
public boolean canExecute(IPlayer player) {
|
||||
return MineTweakerAPI.server.isOp(player);
|
||||
}
|
||||
};
|
||||
|
||||
@ZenGetter
|
||||
public static ICommandValidator isOp() {
|
||||
return ISOP;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.api.server;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.server.ICommandFunction")
|
||||
public interface ICommandFunction {
|
||||
public void execute(String[] arguments, IPlayer player);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.api.server;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.server.ICommandTabCompletion")
|
||||
public interface ICommandTabCompletion {
|
||||
public String[] getTabCompletionOptions(String[] command, IPlayer player);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.api.server;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.server.ICommandValidator")
|
||||
public interface ICommandValidator {
|
||||
public boolean canExecute(IPlayer player);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.api.server;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.server.IServer")
|
||||
public interface IServer {
|
||||
@ZenMethod
|
||||
public void addCommand(
|
||||
String name,
|
||||
String usage,
|
||||
String[] aliases,
|
||||
ICommandFunction function,
|
||||
@Optional ICommandValidator validator,
|
||||
@Optional ICommandTabCompletion completion);
|
||||
|
||||
@ZenMethod
|
||||
public void removeCommand(String name);
|
||||
|
||||
@ZenMethod
|
||||
public void addMineTweakerCommand(String name, String[] usage, ICommandFunction function);
|
||||
|
||||
@ZenMethod
|
||||
public boolean isOp(IPlayer player);
|
||||
}
|
||||
@@ -6,12 +6,16 @@
|
||||
|
||||
package minetweaker.expand;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.MineTweakerImplementationAPI;
|
||||
import minetweaker.api.chat.IChatMessage;
|
||||
import minetweaker.api.data.DataString;
|
||||
import minetweaker.api.data.IData;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenCaster;
|
||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -26,6 +30,46 @@ public class ExpandString {
|
||||
|
||||
@ZenCaster
|
||||
public static IChatMessage asChatMessage(String value) {
|
||||
return MineTweakerAPI.platform.getMessage(value);
|
||||
return MineTweakerImplementationAPI.platform.getMessage(value);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static List<String> split(String value, String separator, @Optional int maximum) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
int minIndex = 0;
|
||||
int numSplits = 0;
|
||||
|
||||
while (minIndex + separator.length() <= value.length()) {
|
||||
int index = value.indexOf(separator, minIndex);
|
||||
if (index < 0) break;
|
||||
result.add(value.substring(minIndex, index));
|
||||
minIndex = index + separator.length();
|
||||
|
||||
numSplits++;
|
||||
if (maximum > 0 && numSplits >= maximum) break;
|
||||
}
|
||||
|
||||
result.add(value.substring(minIndex));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static int indexOf(String value, String needle) {
|
||||
return value.indexOf(needle);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static int indexOf(String value, String needle, int fromIndex) {
|
||||
return value.indexOf(needle, fromIndex);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static int lastIndexOf(String value, String needle) {
|
||||
return value.lastIndexOf(needle);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static int lastIndexOf(String value, String needle, int fromIndex) {
|
||||
return value.lastIndexOf(value, fromIndex);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,6 @@ public class GlobalFunctions {
|
||||
private GlobalFunctions() {}
|
||||
|
||||
public static void print(String message) {
|
||||
MineTweakerAPI.logger.logInfo(message);
|
||||
MineTweakerAPI.getLogger().logInfo(message);
|
||||
}
|
||||
}
|
||||
@@ -142,12 +142,20 @@ public class GlobalRegistry {
|
||||
private static class MyErrorLogger implements IZenErrorLogger {
|
||||
@Override
|
||||
public void error(ZenPosition position, String message) {
|
||||
MineTweakerAPI.logger.logError(position.toString() + ": " + message);
|
||||
if (position == null) {
|
||||
MineTweakerAPI.getLogger().logError("system: " + message);
|
||||
} else {
|
||||
MineTweakerAPI.getLogger().logError(position + ": " + message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(ZenPosition position, String message) {
|
||||
MineTweakerAPI.logger.logWarning(position.toString() + ": " + message);
|
||||
if (position == null) {
|
||||
MineTweakerAPI.getLogger().logWarning("system: " + message);
|
||||
} else {
|
||||
MineTweakerAPI.getLogger().logWarning(position + ": " + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,12 +259,12 @@ public class GlobalRegistry {
|
||||
|
||||
@Override
|
||||
public void error(ZenPosition position, String message) {
|
||||
MineTweakerAPI.logger.logError(position.toString() + " > " + message);
|
||||
MineTweakerAPI.getLogger().logError(position.toString() + " > " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(ZenPosition position, String message) {
|
||||
MineTweakerAPI.logger.logWarning(position.toString() + " > " + message);
|
||||
MineTweakerAPI.getLogger().logWarning(position.toString() + " > " + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -6,7 +6,6 @@
|
||||
|
||||
package minetweaker.runtime;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.List;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
@@ -18,7 +17,7 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.IMineTweaker")
|
||||
public interface IMineTweaker {
|
||||
public interface ITweaker {
|
||||
/**
|
||||
* Executes a specified MineTweaker action. Will print a log message and
|
||||
* adds the action to the undo list.
|
||||
+13
-10
@@ -35,7 +35,7 @@ import stanhebben.zenscript.parser.ParseException;
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class Tweaker implements IMineTweaker {
|
||||
public class MTTweaker implements ITweaker {
|
||||
private final List<IUndoableAction> actions = new ArrayList<IUndoableAction>();
|
||||
private final Set<IUndoableAction> wereStuck = new LinkedHashSet<IUndoableAction>();
|
||||
private final Map<Object, IUndoableAction> stuckOverridable = new HashMap<Object, IUndoableAction>();
|
||||
@@ -45,7 +45,7 @@ public class Tweaker implements IMineTweaker {
|
||||
|
||||
@Override
|
||||
public void apply(IUndoableAction action) {
|
||||
MineTweakerAPI.logger.logInfo(action.describe());
|
||||
MineTweakerAPI.getLogger().logInfo(action.describe());
|
||||
|
||||
Object overrideKey = action.getOverrideKey();
|
||||
if (wereStuck.contains(action)) {
|
||||
@@ -76,10 +76,10 @@ public class Tweaker implements IMineTweaker {
|
||||
for (int i = actions.size() - 1; i >= 0; i--) {
|
||||
IUndoableAction action = actions.get(i);
|
||||
if (action.canUndo()) {
|
||||
MineTweakerAPI.logger.logInfo(action.describeUndo());
|
||||
MineTweakerAPI.getLogger().logInfo(action.describeUndo());
|
||||
action.undo();
|
||||
} else {
|
||||
MineTweakerAPI.logger.logInfo("[Stuck] " + action.describe());
|
||||
MineTweakerAPI.getLogger().logInfo("[Stuck] " + action.describe());
|
||||
stuck.add(0, action);
|
||||
wereStuck.add(action);
|
||||
|
||||
@@ -100,6 +100,8 @@ public class Tweaker implements IMineTweaker {
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
System.out.println("Loading scripts");
|
||||
|
||||
scriptData = ScriptProviderMemory.collect(scriptProvider);
|
||||
Set<String> executed = new HashSet<String>();
|
||||
|
||||
@@ -127,11 +129,12 @@ public class Tweaker implements IMineTweaker {
|
||||
ZenParsedFile pfile = new ZenParsedFile(filename, className, parser, environmentGlobal);
|
||||
files.add(pfile);
|
||||
} catch (IOException ex) {
|
||||
MineTweakerAPI.logger.logError("Could not load script " + script.getName() + ": " + ex.getMessage());
|
||||
MineTweakerAPI.getLogger().logError("Could not load script " + script.getName() + ": " + ex.getMessage());
|
||||
} catch (ParseException ex) {
|
||||
MineTweakerAPI.logger.logError("Error parsing " + ex.getFile() + ":" + ex.getLine() + " -- " + ex.getExplanation());
|
||||
//ex.printStackTrace();
|
||||
MineTweakerAPI.getLogger().logError("Error parsing " + ex.getFile().getFileName() + ":" + ex.getLine() + " -- " + ex.getExplanation());
|
||||
} catch (Exception ex) {
|
||||
MineTweakerAPI.logger.logError("Error loading " + script.getName() + ": " + ex.toString());
|
||||
MineTweakerAPI.getLogger().logError("Error loading " + script.getName() + ": " + ex.toString());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -151,16 +154,16 @@ public class Tweaker implements IMineTweaker {
|
||||
ZenModule module = new ZenModule(classes, MineTweakerAPI.class.getClassLoader());
|
||||
module.getMain().run();
|
||||
} catch (Exception ex) {
|
||||
MineTweakerAPI.logger.logError("Error executing " + script.getGroupName() + ": " + ex.getMessage());
|
||||
MineTweakerAPI.getLogger().logError("Error executing " + script.getGroupName() + ": " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wereStuck.size() > 0) {
|
||||
MineTweakerAPI.logger.logWarning(Integer.toString(wereStuck.size()) + " modifications were stuck");
|
||||
MineTweakerAPI.getLogger().logWarning(Integer.toString(wereStuck.size()) + " modifications were stuck");
|
||||
for (IUndoableAction action : wereStuck) {
|
||||
MineTweakerAPI.logger.logInfo("Stuck: " + action.describe());
|
||||
MineTweakerAPI.getLogger().logInfo("Stuck: " + action.describe());
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
-10
@@ -23,22 +23,26 @@ public class ScriptProviderDirectory implements IScriptProvider {
|
||||
private final File directory;
|
||||
|
||||
public ScriptProviderDirectory(File directory) {
|
||||
if (directory == null) throw new IllegalArgumentException("directory cannot be null");
|
||||
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IScriptIterator> getScripts() {
|
||||
List<IScriptIterator> scripts = new ArrayList<IScriptIterator>();
|
||||
for (File file : directory.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
scripts.add(new ScriptIteratorDirectory(file));
|
||||
} else if (file.getName().endsWith(".zs")) {
|
||||
scripts.add(new ScriptIteratorSingle(file));
|
||||
} else if (file.getName().endsWith(".zip")) {
|
||||
try {
|
||||
scripts.add(new ScriptIteratorZip(file));
|
||||
} catch (IOException ex) {
|
||||
MineTweakerAPI.logger.logError("Could not load " + file.getName() + ": " + ex.getMessage());
|
||||
if (directory.exists()) {
|
||||
for (File file : directory.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
scripts.add(new ScriptIteratorDirectory(file));
|
||||
} else if (file.getName().endsWith(".zs")) {
|
||||
scripts.add(new ScriptIteratorSingle(file));
|
||||
} else if (file.getName().endsWith(".zip")) {
|
||||
try {
|
||||
scripts.add(new ScriptIteratorZip(file));
|
||||
} catch (IOException ex) {
|
||||
MineTweakerAPI.getLogger().logError("Could not load " + file.getName() + ": " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -63,7 +63,7 @@ public class ScriptProviderMemory implements IScriptProvider {
|
||||
|
||||
deflater.close();
|
||||
} catch (IOException ex) {
|
||||
MineTweakerAPI.logger.logError("Could not collect scripts: " + ex.getMessage());
|
||||
MineTweakerAPI.getLogger().logError("Could not collect scripts: " + ex.getMessage());
|
||||
}
|
||||
return output.toByteArray();
|
||||
}
|
||||
@@ -96,7 +96,7 @@ public class ScriptProviderMemory implements IScriptProvider {
|
||||
|
||||
inflaterData.close();
|
||||
} catch (IOException ex) {
|
||||
MineTweakerAPI.logger.logError("Could not load transmitted scripts: " + ex.getMessage());
|
||||
MineTweakerAPI.getLogger().logError("Could not load transmitted scripts: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,10 @@ public class EventList<T> {
|
||||
private EventNode first = null;
|
||||
private EventNode last = null;
|
||||
|
||||
public void clear() {
|
||||
first = last = null;
|
||||
}
|
||||
|
||||
public IEventHandle add(IEventHandler<T> handler) {
|
||||
EventNode node = new EventNode(handler, last, null);
|
||||
|
||||
|
||||
Reference in new issue
Block a user