Permalink
Browse files

Merge pull request #420 from sk89q/server-side-cui

Added a server side version of WorldEditCUI with limited functionality
  • Loading branch information...
me4502 committed Aug 20, 2018
2 parents 7b83f97 + 0f8cc99 commit d3b3d57041f2b9711a4b830e9860ea72f45ef682
Showing with 411 additions and 29 deletions.
  1. +21 −0 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java
  2. +1 −1 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java
  3. +20 −0 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java
  4. BIN worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_13_R1.class
  5. +1 −0 worldedit-bukkit/src/main/resources/defaults/config.yml
  6. +1 −0 worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java
  7. +64 −0 worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java
  8. +36 −0 worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java
  9. +14 −0 worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java
  10. +4 −0 worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java
  11. +6 −0 worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java
  12. +156 −0 worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java
  13. +38 −26 worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java
  14. +1 −0 worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java
  15. +1 −0 worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java
  16. +22 −0 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java
  17. +3 −1 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java
  18. +18 −0 worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java
  19. +3 −1 worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java
  20. +1 −0 worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/config/ConfigurateConfiguration.java
@@ -22,6 +22,7 @@
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.entity.BaseEntity;
@@ -31,6 +32,8 @@
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import org.bukkit.Bukkit;
@@ -239,4 +242,22 @@ public boolean isPersistent() {
}
@Override
public void sendFakeBlock(Vector pos, BlockStateHolder block) {
Location loc = new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ());
if (block == null) {
player.sendBlockChange(loc, player.getWorld().getBlockAt(loc).getBlockData());
} else {
player.sendBlockChange(loc, BukkitAdapter.adapt(block));
if (block instanceof BaseBlock && ((BaseBlock) block).hasNbtData()) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
adapter.sendFakeNBT(player, pos, ((BaseBlock) block).getNbtData());
if (block.getBlockType() == BlockTypes.STRUCTURE_BLOCK) {
adapter.sendFakeOP(player);
}
}
}
}
}
}
@@ -150,7 +150,7 @@ private void loadAdapter() {
@Override
public void onDisable() {
WorldEdit worldEdit = WorldEdit.getInstance();
worldEdit.getSessionManager().clear();
worldEdit.getSessionManager().unload();
worldEdit.getPlatformManager().unregister(server);
if (config != null) {
config.unload();
@@ -19,6 +19,8 @@
package com.sk89q.worldedit.bukkit.adapter;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.registry.state.Property;
@@ -27,6 +29,7 @@
import org.bukkit.Location;
import org.bukkit.block.Biome;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.Map;
@@ -101,4 +104,21 @@
* @return The properties map
*/
Map<String, ? extends Property> getProperties(BlockType blockType);
/**
* Send the given NBT data to the player.
*
* @param player The player
* @param pos The position
* @param nbtData The NBT Data
*/
void sendFakeNBT(Player player, Vector pos, CompoundTag nbtData);
/**
* Make the client think it has operator status.
* This does not give them any operator capabilities.
*
* @param player The player
*/
void sendFakeOP(Player player);
}
@@ -143,3 +143,4 @@ no-double-slash: false
no-op-permissions: false
debug: false
show-help-on-first-use: true
server-side-cui: true
@@ -134,6 +134,7 @@
public int butcherDefaultRadius = -1;
public int butcherMaxRadius = -1;
public boolean allowSymlinks = false;
public boolean serverSideCUI = true;
/**
* Load the configuration.
@@ -25,6 +25,8 @@
import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.utils.Span;
import com.sk89q.jchronic.utils.Time;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.command.tool.BlockTool;
import com.sk89q.worldedit.command.tool.BrushTool;
import com.sk89q.worldedit.command.tool.InvalidToolBindException;
@@ -37,13 +39,15 @@
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.internal.cui.CUIRegion;
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
import com.sk89q.worldedit.internal.cui.ServerCUIHandler;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.regions.selector.RegionSelectorType;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.snapshot.Snapshot;
@@ -87,10 +91,12 @@
private transient boolean fastMode = false;
private transient Mask mask;
private transient TimeZone timezone = TimeZone.getDefault();
private transient Vector cuiTemporaryBlock;
// Saved properties
private String lastScript;
private RegionSelectorType defaultSelector;
private boolean useServerCUI = false; // Save this to not annoy players.
/**
* Construct the object.
@@ -612,6 +618,59 @@ public void setLastScript(@Nullable String lastScript) {
public void tellVersion(Actor player) {
}
public boolean shouldUseServerCUI() {
return this.useServerCUI;
}
public void setUseServerCUI(boolean useServerCUI) {
this.useServerCUI = useServerCUI;
setDirty();
}
/**
* Update server-side WorldEdit CUI.
*
* @param actor The player
*/
public void updateServerCUI(Actor actor) {
if (!actor.isPlayer()) {
return; // This is for players only.
}
if (!config.serverSideCUI) {
return; // Disabled in config.
}
Player player = (Player) actor;
if (!useServerCUI || hasCUISupport) {
if (cuiTemporaryBlock != null) {
player.sendFakeBlock(cuiTemporaryBlock, null);
cuiTemporaryBlock = null;
}
return; // If it's not enabled, ignore this.
}
// Remove the old block.
if (cuiTemporaryBlock != null) {
player.sendFakeBlock(cuiTemporaryBlock, null);
cuiTemporaryBlock = null;
}
BaseBlock block = ServerCUIHandler.createStructureBlock(player);
if (block != null) {
// If it's null, we don't need to do anything. The old was already removed.
Map<String, Tag> tags = block.getNbtData().getValue();
cuiTemporaryBlock = new Vector(
((IntTag) tags.get("x")).getValue(),
((IntTag) tags.get("y")).getValue(),
((IntTag) tags.get("z")).getValue()
);
player.sendFakeBlock(cuiTemporaryBlock, block);
}
}
/**
* Dispatch a CUI event but only if the actor has CUI support.
*
@@ -624,6 +683,8 @@ public void dispatchCUIEvent(Actor actor, CUIEvent event) {
if (hasCUISupport) {
actor.dispatchCUIEvent(event);
} else if (useServerCUI) {
updateServerCUI(actor);
}
}
@@ -647,6 +708,9 @@ public void dispatchCUISelection(Actor actor) {
checkNotNull(actor);
if (!hasCUISupport) {
if (useServerCUI) {
updateServerCUI(actor);
}
return;
}
@@ -31,6 +31,7 @@
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.DisallowedUsageException;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.util.command.parametric.Optional;
@@ -114,6 +115,41 @@ public void fast(Player player, LocalSession session, EditSession editSession, C
}
}
@Command(
aliases = { "/drawsel" },
usage = "[on|off]",
desc = "Toggle drawing the current selection",
min = 0,
max = 1
)
@CommandPermissions("worldedit.drawsel")
public void drawSelection(Player player, LocalSession session, CommandContext args) throws WorldEditException {
if (!WorldEdit.getInstance().getConfiguration().serverSideCUI) {
throw new DisallowedUsageException("This functionality is disabled in the configuration!");
}
String newState = args.getString(0, null);
if (session.shouldUseServerCUI()) {
if ("on".equals(newState)) {
player.printError("Server CUI already enabled.");
return;
}
session.setUseServerCUI(false);
session.updateServerCUI(player);
player.print("Server CUI disabled.");
} else {
if ("off".equals(newState)) {
player.printError("Server CUI already disabled.");
return;
}
session.setUseServerCUI(true);
session.updateServerCUI(player);
player.print("Server CUI enabled. This only supports cuboid regions, with a maximum size of 32x32x32.");
}
}
@Command(
aliases = { "/gmask", "gmask" },
usage = "[mask]",
@@ -29,8 +29,11 @@
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.gamemode.GameMode;
import javax.annotation.Nullable;
/**
* Represents a player
*/
@@ -262,4 +265,15 @@
*/
void setPosition(Vector pos);
/**
* Sends a fake block to the client.
*
* <p>
* This block isn't real.
* </p>
*
* @param pos The position of the block
* @param block The block to send, null to reset
*/
void sendFakeBlock(Vector pos, @Nullable BlockStateHolder block);
}
@@ -498,4 +498,8 @@ public boolean remove() {
return false;
}
@Override
public void sendFakeBlock(Vector pos, BlockStateHolder block) {
}
}
@@ -31,6 +31,7 @@
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.gamemode.GameMode;
import java.util.UUID;
@@ -155,4 +156,9 @@ public GameMode getGameMode() {
public void setGameMode(GameMode gameMode) {
basePlayer.setGameMode(gameMode);
}
@Override
public void sendFakeBlock(Vector pos, BlockStateHolder block) {
basePlayer.sendFakeBlock(pos, block);
}
}
Oops, something went wrong.

0 comments on commit d3b3d57

Please sign in to comment.