mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
Added support for platforms to declare capabilities.
Platforms can declare certain capabilities and a suggested preference for the platform for each capability. WorldEdit can then choose the best platform for a given capability. Examples of capabilities include providing configuration, registering game hooks/events, performing changes to the world, or checking permissions/authorization.
This commit is contained in:
@ -23,6 +23,8 @@ import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.worldedit.BiomeTypes;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.ServerInterface;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extension.platform.Preference;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommand;
|
||||
@ -34,21 +36,26 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
class ForgePlatform extends ServerInterface {
|
||||
|
||||
private final ForgeWorldEdit mod;
|
||||
private final MinecraftServer server;
|
||||
private final ForgeBiomeTypes biomes;
|
||||
private boolean hookingEvents = false;
|
||||
|
||||
public ForgePlatform(ForgeWorldEdit mod) {
|
||||
ForgePlatform(ForgeWorldEdit mod) {
|
||||
this.mod = mod;
|
||||
this.server = FMLCommonHandler.instance().getMinecraftServerInstance();
|
||||
this.biomes = new ForgeBiomeTypes();
|
||||
}
|
||||
|
||||
boolean isHookingEvents() {
|
||||
return hookingEvents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int resolveItem(String name) {
|
||||
if (name == null) return 0;
|
||||
for (Item item : Item.itemsList) {
|
||||
@ -65,21 +72,26 @@ class ForgePlatform extends ServerInterface {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidMobType(String type) {
|
||||
return EntityList.stringToClassMapping.containsKey(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeTypes getBiomes() {
|
||||
return this.biomes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int schedule(long delay, long period, Runnable task) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends com.sk89q.worldedit.world.World> getWorlds() {
|
||||
List<WorldServer> worlds = Arrays.asList(DimensionManager.getWorlds());
|
||||
List<com.sk89q.worldedit.world.World> ret = new ArrayList<com.sk89q.worldedit.world.World>(worlds.size());
|
||||
@ -125,6 +137,12 @@ class ForgePlatform extends ServerInterface {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerGameHooks() {
|
||||
// We registered the events already anyway, so we just 'turn them on'
|
||||
hookingEvents = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalConfiguration getConfiguration() {
|
||||
return mod.getConfig();
|
||||
@ -144,4 +162,16 @@ class ForgePlatform extends ServerInterface {
|
||||
public String getPlatformVersion() {
|
||||
return mod.getInternalVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Capability, Preference> getCapabilities() {
|
||||
Map<Capability, Preference> capabilities = new EnumMap<Capability, Preference>(Capability.class);
|
||||
capabilities.put(Capability.CONFIGURATION, Preference.PREFER_OTHERS);
|
||||
capabilities.put(Capability.GAME_HOOKS, Preference.NORMAL);
|
||||
capabilities.put(Capability.PERMISSIONS, Preference.PREFER_OTHERS);
|
||||
capabilities.put(Capability.USER_COMMANDS, Preference.NORMAL);
|
||||
capabilities.put(Capability.WORLD_EDITING, Preference.PREFERRED);
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ import com.google.common.io.Closer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldVector;
|
||||
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.extension.platform.PlatformRejectionException;
|
||||
import com.sk89q.worldedit.internal.LocalWorldAdapter;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
@ -103,11 +103,8 @@ public class ForgeWorldEdit {
|
||||
}
|
||||
|
||||
this.platform = new ForgePlatform(this);
|
||||
try {
|
||||
WorldEdit.getInstance().getPlatformManager().register(platform);
|
||||
} catch (PlatformRejectionException e) {
|
||||
throw new RuntimeException("Failed to register with WorldEdit", e);
|
||||
}
|
||||
|
||||
WorldEdit.getInstance().getPlatformManager().register(platform);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -115,6 +112,11 @@ public class ForgeWorldEdit {
|
||||
WorldEdit.getInstance().getPlatformManager().unregister(platform);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void serverStarted(FMLServerStartedEvent event) {
|
||||
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent());
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onCommandEvent(CommandEvent event) {
|
||||
if ((event.sender instanceof EntityPlayerMP)) {
|
||||
@ -128,6 +130,8 @@ public class ForgeWorldEdit {
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!platform.isHookingEvents()) return; // We have to be told to catch these events
|
||||
|
||||
if (event.useItem == Result.DENY || event.entity.worldObj.isRemote) return;
|
||||
|
||||
WorldEdit we = WorldEdit.getInstance();
|
||||
|
Reference in New Issue
Block a user