2013-02-24 20:16:12 +00:00
|
|
|
package com.sk89q.worldedit.forge;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2013-02-25 06:22:05 +00:00
|
|
|
|
2013-02-24 20:16:12 +00:00
|
|
|
import net.minecraft.command.CommandBase;
|
|
|
|
import net.minecraft.command.ICommandSender;
|
|
|
|
import net.minecraft.command.ServerCommandManager;
|
|
|
|
import net.minecraft.entity.EntityList;
|
2013-09-29 13:30:06 +00:00
|
|
|
import net.minecraft.item.Item;
|
2013-02-24 20:16:12 +00:00
|
|
|
import net.minecraft.server.MinecraftServer;
|
|
|
|
import net.minecraft.world.WorldServer;
|
2013-09-29 13:30:06 +00:00
|
|
|
import net.minecraftforge.common.DimensionManager;
|
2013-02-24 20:16:12 +00:00
|
|
|
|
2013-02-25 06:22:05 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Command;
|
|
|
|
import com.sk89q.worldedit.BiomeTypes;
|
|
|
|
import com.sk89q.worldedit.LocalWorld;
|
|
|
|
import com.sk89q.worldedit.ServerInterface;
|
|
|
|
|
|
|
|
import cpw.mods.fml.common.FMLCommonHandler;
|
|
|
|
|
2013-02-24 20:16:12 +00:00
|
|
|
public class ForgeServerInterface extends ServerInterface {
|
|
|
|
private MinecraftServer server;
|
|
|
|
private ForgeBiomeTypes biomes;
|
|
|
|
|
|
|
|
public ForgeServerInterface() {
|
2013-02-25 06:22:05 +00:00
|
|
|
this.server = FMLCommonHandler.instance().getMinecraftServerInstance();
|
2013-02-24 20:16:12 +00:00
|
|
|
this.biomes = new ForgeBiomeTypes();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int resolveItem(String name) {
|
2014-04-04 21:11:48 +00:00
|
|
|
if (name == null) return 0;
|
2013-09-29 13:30:06 +00:00
|
|
|
for (Item item : Item.itemsList) {
|
|
|
|
if (item == null) continue;
|
|
|
|
if (item.getUnlocalizedName() == null) continue;
|
|
|
|
if (item.getUnlocalizedName().startsWith("item.")) {
|
|
|
|
if (item.getUnlocalizedName().equalsIgnoreCase("item." + name)) return item.itemID;
|
|
|
|
}
|
|
|
|
if (item.getUnlocalizedName().startsWith("tile.")) {
|
|
|
|
if (item.getUnlocalizedName().equalsIgnoreCase("tile." + name)) return item.itemID;
|
|
|
|
}
|
|
|
|
if (item.getUnlocalizedName().equalsIgnoreCase(name)) return item.itemID;
|
|
|
|
}
|
2013-02-24 20:16:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isValidMobType(String type) {
|
|
|
|
return EntityList.stringToClassMapping.containsKey(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reload() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public BiomeTypes getBiomes() {
|
|
|
|
return this.biomes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int schedule(long delay, long period, Runnable task) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<LocalWorld> getWorlds() {
|
2013-09-29 13:30:06 +00:00
|
|
|
List<WorldServer> worlds = Arrays.asList(DimensionManager.getWorlds());
|
|
|
|
List<LocalWorld> ret = new ArrayList<LocalWorld>(worlds.size());
|
2013-02-24 20:16:12 +00:00
|
|
|
for (WorldServer world : worlds) {
|
|
|
|
ret.add(new ForgeWorld(world));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCommandRegistration(List<Command> commands) {
|
2013-02-25 06:22:05 +00:00
|
|
|
if (server == null) return;
|
|
|
|
ServerCommandManager mcMan = (ServerCommandManager) server.getCommandManager();
|
2013-09-29 13:30:06 +00:00
|
|
|
for (final Command cmd : commands) {
|
|
|
|
mcMan.registerCommand(new CommandBase() {
|
|
|
|
@Override
|
|
|
|
public String getCommandName() {
|
|
|
|
return cmd.aliases()[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getCommandAliases() {
|
|
|
|
return Arrays.asList(cmd.aliases());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void processCommand(ICommandSender var1, String[] var2) {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getCommandUsage(ICommandSender icommandsender) {
|
|
|
|
return "/" + cmd.aliases()[0] + " " + cmd.usage();
|
|
|
|
}
|
|
|
|
});
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-29 13:30:06 +00:00
|
|
|
}
|