Adds Platform support for WorldEdit CUI

This commit is contained in:
Wyatt Childers 2014-07-06 20:13:27 -04:00
parent ad9b8ce3b1
commit bc92e43be0
5 changed files with 23 additions and 2 deletions

View File

@ -168,6 +168,7 @@ public class BukkitServerInterface extends ServerInterface {
public Map<Capability, Preference> getCapabilities() { public Map<Capability, Preference> getCapabilities() {
Map<Capability, Preference> capabilities = new EnumMap<Capability, Preference>(Capability.class); Map<Capability, Preference> capabilities = new EnumMap<Capability, Preference>(Capability.class);
capabilities.put(Capability.CONFIGURATION, Preference.NORMAL); capabilities.put(Capability.CONFIGURATION, Preference.NORMAL);
capabilities.put(Capability.WORLDEDIT_CUI, Preference.NORMAL);
capabilities.put(Capability.GAME_HOOKS, Preference.PREFERRED); capabilities.put(Capability.GAME_HOOKS, Preference.PREFERRED);
capabilities.put(Capability.PERMISSIONS, Preference.PREFERRED); capabilities.put(Capability.PERMISSIONS, Preference.PREFERRED);
capabilities.put(Capability.USER_COMMANDS, Preference.PREFERRED); capabilities.put(Capability.USER_COMMANDS, Preference.PREFERRED);

View File

@ -205,6 +205,7 @@ class ForgePlatform extends ServerInterface {
public Map<Capability, Preference> getCapabilities() { public Map<Capability, Preference> getCapabilities() {
Map<Capability, Preference> capabilities = new EnumMap<Capability, Preference>(Capability.class); Map<Capability, Preference> capabilities = new EnumMap<Capability, Preference>(Capability.class);
capabilities.put(Capability.CONFIGURATION, Preference.PREFER_OTHERS); capabilities.put(Capability.CONFIGURATION, Preference.PREFER_OTHERS);
capabilities.put(Capability.WORLDEDIT_CUI, Preference.NORMAL);
capabilities.put(Capability.GAME_HOOKS, Preference.NORMAL); capabilities.put(Capability.GAME_HOOKS, Preference.NORMAL);
capabilities.put(Capability.PERMISSIONS, Preference.PREFER_OTHERS); capabilities.put(Capability.PERMISSIONS, Preference.PREFER_OTHERS);
capabilities.put(Capability.USER_COMMANDS, Preference.NORMAL); capabilities.put(Capability.USER_COMMANDS, Preference.NORMAL);

View File

@ -65,6 +65,11 @@ public enum Capability {
*/ */
PERMISSIONS, PERMISSIONS,
/**
* The capability of a platform to dispatch WorldEditCUI events.
*/
WORLDEDIT_CUI,
/** /**
* The capability of a platform to perform modifications to a world. * The capability of a platform to perform modifications to a world.
*/ */

View File

@ -240,7 +240,12 @@ public class PlatformManager {
permActor = player; permActor = player;
} }
return (T) new PlayerProxy(player, permActor, getWorldForEditing(player.getWorld())); Player cuiActor = queryCapability(Capability.WORLDEDIT_CUI).matchPlayer(player);
if (cuiActor == null) {
cuiActor = player;
}
return (T) new PlayerProxy(player, permActor, cuiActor, getWorldForEditing(player.getWorld()));
} else { } else {
return base; return base;
} }

View File

@ -23,6 +23,7 @@ import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector; import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
@ -32,14 +33,17 @@ class PlayerProxy extends AbstractPlayerActor {
private final Player basePlayer; private final Player basePlayer;
private final Actor permActor; private final Actor permActor;
private final Actor cuiActor;
private final World world; private final World world;
PlayerProxy(Player basePlayer, Actor permActor, World world) { PlayerProxy(Player basePlayer, Actor permActor, Actor cuiActor, World world) {
checkNotNull(basePlayer); checkNotNull(basePlayer);
checkNotNull(permActor); checkNotNull(permActor);
checkNotNull(cuiActor);
checkNotNull(world); checkNotNull(world);
this.basePlayer = basePlayer; this.basePlayer = basePlayer;
this.permActor = permActor; this.permActor = permActor;
this.cuiActor = cuiActor;
this.world = world; this.world = world;
} }
@ -122,4 +126,9 @@ class PlayerProxy extends AbstractPlayerActor {
public boolean hasPermission(String perm) { public boolean hasPermission(String perm) {
return permActor.hasPermission(perm); return permActor.hasPermission(perm);
} }
@Override
public void dispatchCUIEvent(CUIEvent event) {
cuiActor.dispatchCUIEvent(event);
}
} }