mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-12 12:33:54 +00:00
Merge remote-tracking branch 'upstream/master' into merge
This commit is contained in:
@ -57,8 +57,10 @@ public class CUIChannelHandler implements RawDataListener {
|
||||
return;
|
||||
}
|
||||
|
||||
session.handleCUIInitializationMessage(new String(data.readBytes(data.available()), StandardCharsets.UTF_8));
|
||||
session.describeCUI(SpongeWorldEdit.inst().wrapPlayer(player));
|
||||
final SpongePlayer actor = SpongeWorldEdit.inst().wrapPlayer(player);
|
||||
session.handleCUIInitializationMessage(new String(data.readBytes(data.available()), StandardCharsets.UTF_8),
|
||||
actor);
|
||||
session.describeCUI(actor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,50 +19,52 @@
|
||||
|
||||
package com.sk89q.worldedit.sponge;
|
||||
|
||||
import com.sk89q.worldedit.util.command.CommandMapping;
|
||||
import com.sk89q.worldedit.command.util.PermissionCondition;
|
||||
import org.enginehub.piston.Command;
|
||||
import org.spongepowered.api.command.CommandCallable;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.text.Text;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.sk89q.worldedit.sponge.SpongeTextAdapter.convert;
|
||||
|
||||
public abstract class CommandAdapter implements CommandCallable {
|
||||
private CommandMapping command;
|
||||
private Command command;
|
||||
|
||||
protected CommandAdapter(CommandMapping command) {
|
||||
protected CommandAdapter(Command command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandSource source) {
|
||||
for (String perm : command.getDescription().getPermissions()) {
|
||||
if (!source.hasPermission(perm)) {
|
||||
return false;
|
||||
Set<String> permissions = command.getCondition().as(PermissionCondition.class)
|
||||
.map(PermissionCondition::getPermissions)
|
||||
.orElseGet(Collections::emptySet);
|
||||
for (String perm : permissions) {
|
||||
if (source.hasPermission(perm)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Text> getShortDescription(CommandSource source) {
|
||||
String description = command.getDescription().getDescription();
|
||||
if (description != null && !description.isEmpty()) {
|
||||
return Optional.of(Text.of(description));
|
||||
}
|
||||
return Optional.empty();
|
||||
return Optional.of(command.getDescription())
|
||||
.map(SpongeTextAdapter::convert);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Text> getHelp(CommandSource source) {
|
||||
String help = command.getDescription().getHelp();
|
||||
if (help != null && !help.isEmpty()) {
|
||||
return Optional.of(Text.of(help));
|
||||
}
|
||||
return Optional.empty();
|
||||
return Optional.of(command.getFullHelp())
|
||||
.map(SpongeTextAdapter::convert);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getUsage(CommandSource source) {
|
||||
return Text.of(command.getDescription().getUsage());
|
||||
return convert(command.getUsage());
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,9 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
||||
import com.sk89q.worldedit.session.SessionKey;
|
||||
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
||||
import com.sk89q.worldedit.util.formatting.WorldEditText;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.adapter.spongeapi.TextAdapter;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.text.Text;
|
||||
@ -89,6 +92,11 @@ public class SpongeCommandSender implements Actor {
|
||||
sendColorized(msg, TextColors.RED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(Component component) {
|
||||
TextAdapter.sendComponent(sender, WorldEditText.format(component));
|
||||
}
|
||||
|
||||
private void sendColorized(String msg, TextColor formatting) {
|
||||
for (String part : msg.split("\n")) {
|
||||
sender.sendMessage(Text.of(formatting, TextSerializers.LEGACY_FORMATTING_CODE.deserialize(part)));
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.sponge;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.event.platform.CommandEvent;
|
||||
@ -28,11 +29,12 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extension.platform.MultiUserPlatform;
|
||||
import com.sk89q.worldedit.extension.platform.Preference;
|
||||
import com.sk89q.worldedit.internal.command.CommandUtil;
|
||||
import com.sk89q.worldedit.sponge.config.SpongeConfiguration;
|
||||
import com.sk89q.worldedit.util.command.CommandMapping;
|
||||
import com.sk89q.worldedit.util.command.Dispatcher;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.registry.Registries;
|
||||
import org.enginehub.piston.Command;
|
||||
import org.enginehub.piston.CommandManager;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.command.CommandException;
|
||||
import org.spongepowered.api.command.CommandResult;
|
||||
@ -41,6 +43,7 @@ import org.spongepowered.api.entity.EntityType;
|
||||
import org.spongepowered.api.scheduler.Task;
|
||||
import org.spongepowered.api.world.Location;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
@ -48,7 +51,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
class SpongePlatform extends AbstractPlatform implements MultiUserPlatform {
|
||||
|
||||
@ -68,6 +71,12 @@ class SpongePlatform extends AbstractPlatform implements MultiUserPlatform {
|
||||
return SpongeRegistries.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDataVersion() {
|
||||
// TODO add to adapter - org.spongepowered.common.data.util.DataUtil#MINECRAFT_DATA_VERSION
|
||||
return 1631;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidMobType(String type) {
|
||||
return Sponge.getRegistry().getType(EntityType.class, type).isPresent();
|
||||
@ -122,24 +131,26 @@ class SpongePlatform extends AbstractPlatform implements MultiUserPlatform {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCommands(Dispatcher dispatcher) {
|
||||
for (CommandMapping command : dispatcher.getCommands()) {
|
||||
public void registerCommands(CommandManager manager) {
|
||||
for (Command command : manager.getAllCommands().collect(toList())) {
|
||||
CommandAdapter adapter = new CommandAdapter(command) {
|
||||
@Override
|
||||
public CommandResult process(CommandSource source, String arguments) throws org.spongepowered.api.command.CommandException {
|
||||
CommandEvent weEvent = new CommandEvent(SpongeWorldEdit.inst().wrapCommandSource(source), command.getPrimaryAlias() + " " + arguments);
|
||||
CommandEvent weEvent = new CommandEvent(SpongeWorldEdit.inst().wrapCommandSource(source), command.getName() + " " + arguments);
|
||||
WorldEdit.getInstance().getEventBus().post(weEvent);
|
||||
return weEvent.isCancelled() ? CommandResult.success() : CommandResult.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<org.spongepowered.api.world.World> targetPosition) throws CommandException {
|
||||
CommandSuggestionEvent weEvent = new CommandSuggestionEvent(SpongeWorldEdit.inst().wrapCommandSource(source), command.getPrimaryAlias() + " " + arguments);
|
||||
CommandSuggestionEvent weEvent = new CommandSuggestionEvent(SpongeWorldEdit.inst().wrapCommandSource(source), command.getName() + " " + arguments);
|
||||
WorldEdit.getInstance().getEventBus().post(weEvent);
|
||||
return weEvent.getSuggestions();
|
||||
return CommandUtil.fixSuggestions(arguments, weEvent.getSuggestions());
|
||||
}
|
||||
};
|
||||
Sponge.getCommandManager().register(SpongeWorldEdit.inst(), adapter, command.getAllAliases());
|
||||
ImmutableList.Builder<String> aliases = ImmutableList.builder();
|
||||
aliases.add(command.getName()).addAll(command.getAliases());
|
||||
Sponge.getCommandManager().register(SpongeWorldEdit.inst(), adapter, aliases.build());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,12 +31,15 @@ import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.session.SessionKey;
|
||||
import com.sk89q.worldedit.util.HandSide;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.formatting.WorldEditText;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.adapter.spongeapi.TextAdapter;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.gamemode.GameMode;
|
||||
import com.sk89q.worldedit.world.gamemode.GameModes;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.data.key.Keys;
|
||||
import org.spongepowered.api.data.type.HandTypes;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.item.ItemType;
|
||||
@ -149,6 +152,11 @@ public class SpongePlayer extends AbstractPlayerActor {
|
||||
sendColorized(msg, TextColors.RED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(Component component) {
|
||||
TextAdapter.sendComponent(player, WorldEditText.format(component));
|
||||
}
|
||||
|
||||
private void sendColorized(String msg, TextColor formatting) {
|
||||
for (String part : msg.split("\n")) {
|
||||
this.player.sendMessage(Text.of(formatting, TextSerializers.FORMATTING_CODE.deserialize(part)));
|
||||
@ -196,6 +204,16 @@ public class SpongePlayer extends AbstractPlayerActor {
|
||||
gameMode.getId()).get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedToFly() {
|
||||
return player.get(Keys.CAN_FLY).orElse(super.isAllowedToFly());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlying(boolean flying) {
|
||||
player.offer(Keys.IS_FLYING, flying);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
|
||||
org.spongepowered.api.world.Location<World> loc = player.getWorld().getLocation(pos.getX(), pos.getY(), pos.getZ());
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.sponge;
|
||||
|
||||
import com.sk89q.worldedit.util.formatting.WorldEditText;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
|
||||
public class SpongeTextAdapter {
|
||||
|
||||
public static Text convert(Component component) {
|
||||
component = WorldEditText.format(component);
|
||||
return TextSerializers.JSON.deserialize(GsonComponentSerializer.INSTANCE.serialize(component));
|
||||
}
|
||||
|
||||
private SpongeTextAdapter() {
|
||||
}
|
||||
}
|
@ -57,8 +57,10 @@ import org.spongepowered.api.world.World;
|
||||
import org.spongepowered.api.world.weather.Weather;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -116,6 +118,17 @@ public abstract class SpongeWorld extends AbstractWorld {
|
||||
return getWorld().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return getName().replace(" ", "_").toLowerCase(Locale.ROOT) +
|
||||
getWorld().getDimension().getType().getName().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getStoragePath() {
|
||||
return getWorld().getDirectory();
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
protected BlockState getBlockState(BlockStateHolder<?> block) {
|
||||
if (block instanceof com.sk89q.worldedit.world.block.BlockState) {
|
||||
|
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.sponge;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldedit.internal.anvil.ChunkDeleter.DELCHUNKS_FILE_NAME;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@ -29,6 +30,7 @@ import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.internal.anvil.ChunkDeleter;
|
||||
import com.sk89q.worldedit.sponge.adapter.AdapterLoadException;
|
||||
import com.sk89q.worldedit.sponge.adapter.SpongeImplAdapter;
|
||||
import com.sk89q.worldedit.sponge.adapter.SpongeImplLoader;
|
||||
@ -51,6 +53,7 @@ import org.spongepowered.api.event.game.state.GamePostInitializationEvent;
|
||||
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
|
||||
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
|
||||
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
|
||||
import org.spongepowered.api.event.item.inventory.InteractItemEvent;
|
||||
import org.spongepowered.api.item.ItemType;
|
||||
import org.spongepowered.api.item.inventory.ItemStack;
|
||||
import org.spongepowered.api.plugin.Plugin;
|
||||
@ -61,6 +64,8 @@ import org.spongepowered.api.world.World;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -133,6 +138,11 @@ public class SpongeWorldEdit {
|
||||
WorldEdit.getInstance().getPlatformManager().unregister(platform);
|
||||
}
|
||||
|
||||
final Path delChunks = workingDir.toPath().resolve(DELCHUNKS_FILE_NAME);
|
||||
if (Files.exists(delChunks)) {
|
||||
ChunkDeleter.runFromFile(delChunks, true);
|
||||
}
|
||||
|
||||
this.platform = new SpongePlatform(this);
|
||||
this.provider = new SpongePermissionsProvider();
|
||||
|
||||
@ -202,6 +212,22 @@ public class SpongeWorldEdit {
|
||||
return this.spongeAdapter;
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onPlayerItemInteract(InteractItemEvent.Secondary event, @Root Player spongePlayer) {
|
||||
if (platform == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!platform.isHookingEvents()) return; // We have to be told to catch these events
|
||||
|
||||
WorldEdit we = WorldEdit.getInstance();
|
||||
|
||||
SpongePlayer player = wrapPlayer(spongePlayer);
|
||||
if (we.handleRightClick(player)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onPlayerInteract(InteractBlockEvent event, @Root Player spongePlayer) {
|
||||
if (platform == null) {
|
||||
@ -242,26 +268,20 @@ public class SpongeWorldEdit {
|
||||
}
|
||||
}
|
||||
} else if (event instanceof InteractBlockEvent.Secondary) {
|
||||
if (interactedType != BlockTypes.AIR) {
|
||||
if (!optLoc.isPresent()) {
|
||||
return;
|
||||
}
|
||||
if (!optLoc.isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location<World> loc = optLoc.get();
|
||||
com.sk89q.worldedit.util.Location pos = new com.sk89q.worldedit.util.Location(
|
||||
world, loc.getX(), loc.getY(), loc.getZ());
|
||||
Location<World> loc = optLoc.get();
|
||||
com.sk89q.worldedit.util.Location pos = new com.sk89q.worldedit.util.Location(
|
||||
world, loc.getX(), loc.getY(), loc.getZ());
|
||||
|
||||
if (we.handleBlockRightClick(player, pos)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (we.handleBlockRightClick(player, pos)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (we.handleRightClick(player)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
if (we.handleRightClick(player)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (we.handleRightClick(player)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import com.sk89q.worldedit.util.Location;
|
||||
import org.spongepowered.api.entity.Entity;
|
||||
import org.spongepowered.api.item.inventory.ItemStack;
|
||||
import org.spongepowered.api.world.World;
|
||||
import org.spongepowered.api.world.biome.BiomeType;
|
||||
|
||||
/**
|
||||
* An interface for various things that can't be done through the Sponge API.
|
||||
|
@ -128,5 +128,7 @@ public class ConfigurateConfiguration extends LocalConfiguration {
|
||||
|
||||
String type = node.getNode("shell-save-type").getString("").trim();
|
||||
shellSaveType = type.equals("") ? null : type;
|
||||
|
||||
extendedYLimit = node.getNode("compat", "extended-y-limit").getBoolean(false);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user