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;
|
|
|
|
|
2014-04-06 02:33:05 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Command;
|
|
|
|
import com.sk89q.worldedit.BiomeTypes;
|
2014-04-05 03:53:58 +00:00
|
|
|
import com.sk89q.worldedit.LocalConfiguration;
|
2014-04-06 02:33:05 +00:00
|
|
|
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;
|
2014-04-06 02:33:05 +00:00
|
|
|
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;
|
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
|
|
|
|
2014-04-06 02:33:05 +00:00
|
|
|
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
|
|
|
public class ForgeServerInterface extends ServerInterface {
|
2014-04-05 03:53:58 +00:00
|
|
|
private final WorldEditMod mod;
|
|
|
|
private final MinecraftServer server;
|
|
|
|
private final ForgeBiomeTypes biomes;
|
2013-02-24 20:16:12 +00:00
|
|
|
|
2014-04-05 03:53:58 +00:00
|
|
|
public ForgeServerInterface(WorldEditMod mod) {
|
|
|
|
this.mod = mod;
|
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();
|
|
|
|
}
|
2014-04-06 02:33:05 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compareTo(Object o) {
|
|
|
|
if (o instanceof ICommand) {
|
|
|
|
return super.compareTo((ICommand) o);
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2013-09-29 13:30:06 +00:00
|
|
|
});
|
2013-02-24 20:16:12 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-05 03:53:58 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public LocalConfiguration getConfiguration() {
|
|
|
|
return mod.getConfig();
|
|
|
|
}
|
2014-04-06 06:27:10 +00:00
|
|
|
|
|
|
|
@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
|
|
|
}
|