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

149 lines
5.0 KiB
Java
Raw Normal View History

2014-04-04 22:03:18 +00:00
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2013-02-24 20:16:12 +00:00
package com.sk89q.worldedit.forge;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.worldedit.BiomeTypes;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
import cpw.mods.fml.common.FMLCommonHandler;
2013-02-24 20:16:12 +00:00
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommand;
2013-02-24 20:16:12 +00:00
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 java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
2013-02-24 20:16:12 +00:00
public class ForgeServerInterface extends ServerInterface {
private final WorldEditMod mod;
private final MinecraftServer server;
private final ForgeBiomeTypes biomes;
2013-02-24 20:16:12 +00:00
public ForgeServerInterface(WorldEditMod mod) {
this.mod = mod;
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();
}
@Override
public int compareTo(Object o) {
if (o instanceof ICommand) {
return super.compareTo((ICommand) o);
} else {
return -1;
}
}
});
2013-02-24 20:16:12 +00:00
}
}
@Override
public LocalConfiguration getConfiguration() {
return mod.getConfig();
}
@Override
public String getVersion() {
return mod.getInternalVersion();
}
@Override
public String getPlatformName() {
return "Forge-Official";
}
@Override
public String getPlatformVersion() {
return mod.getInternalVersion();
}
2014-04-04 22:03:18 +00:00
}