Plex-FAWE/src/forge/java/com/sk89q/worldedit/forge/ForgeServerInterface.java

99 lines
3.3 KiB
Java
Raw Normal View History

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-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;
import net.minecraft.item.Item;
2013-02-24 20:16:12 +00:00
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
2013-02-24 20:16:12 +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() {
this.server = FMLCommonHandler.instance().getMinecraftServerInstance();
2013-02-24 20:16:12 +00:00
this.biomes = new ForgeBiomeTypes();
}
public int resolveItem(String name) {
if (name == null) return 0;
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() {
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) {
if (server == null) return;
ServerCommandManager mcMan = (ServerCommandManager) server.getCommandManager();
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
}
}
}