mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 12:06: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:
@ -25,6 +25,8 @@ import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.minecraft.util.commands.CommandsManager;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extension.platform.Preference;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
@ -32,16 +34,14 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class BukkitServerInterface extends ServerInterface {
|
||||
public Server server;
|
||||
public WorldEditPlugin plugin;
|
||||
private CommandRegistration dynamicCommands;
|
||||
private BukkitBiomeTypes biomes;
|
||||
private boolean hookingEvents;
|
||||
|
||||
public BukkitServerInterface(WorldEditPlugin plugin, Server server) {
|
||||
this.plugin = plugin;
|
||||
@ -50,6 +50,10 @@ public class BukkitServerInterface extends ServerInterface {
|
||||
dynamicCommands = new CommandRegistration(plugin);
|
||||
}
|
||||
|
||||
boolean isHookingEvents() {
|
||||
return hookingEvents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int resolveItem(String name) {
|
||||
Material mat = Material.matchMaterial(name);
|
||||
@ -114,6 +118,11 @@ public class BukkitServerInterface extends ServerInterface {
|
||||
dynamicCommands.register(toRegister);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerGameHooks() {
|
||||
hookingEvents = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalConfiguration getConfiguration() {
|
||||
return plugin.getLocalConfiguration();
|
||||
@ -134,6 +143,17 @@ public class BukkitServerInterface extends ServerInterface {
|
||||
return plugin.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Capability, Preference> getCapabilities() {
|
||||
Map<Capability, Preference> capabilities = new EnumMap<Capability, Preference>(Capability.class);
|
||||
capabilities.put(Capability.CONFIGURATION, Preference.NORMAL);
|
||||
capabilities.put(Capability.GAME_HOOKS, Preference.PREFERRED);
|
||||
capabilities.put(Capability.PERMISSIONS, Preference.PREFERRED);
|
||||
capabilities.put(Capability.USER_COMMANDS, Preference.PREFERRED);
|
||||
capabilities.put(Capability.WORLD_EDITING, Preference.PREFER_OTHERS);
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
public void unregisterCommands() {
|
||||
dynamicCommands.unregisterCommands();
|
||||
}
|
||||
|
@ -69,11 +69,19 @@ public class WorldEditListener implements Listener {
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
if (!plugin.getInternalPlatform().isHookingEvents()) {
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getWorldEdit().markExpire(plugin.wrapPlayer(event.getPlayer()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onGamemode(PlayerGameModeChangeEvent event) {
|
||||
if (!plugin.getInternalPlatform().isHookingEvents()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// this will automatically refresh their sesssion, we don't have to do anything
|
||||
WorldEdit.getInstance().getSession(plugin.wrapPlayer(event.getPlayer()));
|
||||
}
|
||||
@ -114,6 +122,10 @@ public class WorldEditListener implements Listener {
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!plugin.getInternalPlatform().isHookingEvents()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.useItemInHand() == Result.DENY) {
|
||||
return;
|
||||
}
|
||||
|
@ -26,13 +26,9 @@ import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
|
||||
import com.sk89q.worldedit.bukkit.selections.CylinderSelection;
|
||||
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
|
||||
import com.sk89q.worldedit.bukkit.selections.Selection;
|
||||
import com.sk89q.worldedit.extension.platform.PlatformRejectionException;
|
||||
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.CylinderRegion;
|
||||
import com.sk89q.worldedit.regions.Polygonal2DRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.*;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -106,21 +102,19 @@ public class WorldEditPlugin extends JavaPlugin {
|
||||
// Setup interfaces
|
||||
server = new BukkitServerInterface(this, getServer());
|
||||
controller = WorldEdit.getInstance();
|
||||
try {
|
||||
controller.getPlatformManager().register(server);
|
||||
api = new WorldEditAPI(this);
|
||||
getServer().getMessenger().registerIncomingPluginChannel(this, CUI_PLUGIN_CHANNEL, new CUIChannelListener(this));
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this, CUI_PLUGIN_CHANNEL);
|
||||
// Now we can register events!
|
||||
getServer().getPluginManager().registerEvents(new WorldEditListener(this), this);
|
||||
controller.getPlatformManager().register(server);
|
||||
api = new WorldEditAPI(this);
|
||||
getServer().getMessenger().registerIncomingPluginChannel(this, CUI_PLUGIN_CHANNEL, new CUIChannelListener(this));
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this, CUI_PLUGIN_CHANNEL);
|
||||
// Now we can register events!
|
||||
getServer().getPluginManager().registerEvents(new WorldEditListener(this), this);
|
||||
|
||||
getServer().getScheduler().runTaskTimerAsynchronously(this,
|
||||
new SessionTimer(controller, getServer()), 120, 120);
|
||||
} catch (PlatformRejectionException e) {
|
||||
throw new RuntimeException(
|
||||
"WorldEdit rejected the Bukkit implementation of WorldEdit! This is strange and should " +
|
||||
"not have happened. Please report this error.", e);
|
||||
}
|
||||
getServer().getScheduler().runTaskTimerAsynchronously(this, new SessionTimer(controller, getServer()), 120, 120);
|
||||
|
||||
// If we are on MCPC+/Cauldron, then Forge will have already loaded
|
||||
// Forge WorldEdit and there's (probably) not going to be any other
|
||||
// platforms to be worried about... at the current time of writing
|
||||
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent());
|
||||
}
|
||||
|
||||
private void copyNmsBlockClasses(File target) {
|
||||
@ -357,6 +351,10 @@ public class WorldEditPlugin extends JavaPlugin {
|
||||
return server;
|
||||
}
|
||||
|
||||
BukkitServerInterface getInternalPlatform() {
|
||||
return server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get WorldEdit.
|
||||
*
|
||||
|
Reference in New Issue
Block a user