Remove CUI and other cleaning

This commit is contained in:
MattBDev
2019-06-06 18:39:51 -04:00
parent b42553116c
commit 229182aa63
28 changed files with 574 additions and 2653 deletions

View File

@ -25,7 +25,6 @@ import com.boydti.fawe.bukkit.util.BukkitTaskMan;
import com.boydti.fawe.bukkit.util.ItemUtil;
import com.boydti.fawe.bukkit.util.VaultUtil;
import com.boydti.fawe.bukkit.util.cui.CUIListener;
import com.boydti.fawe.bukkit.util.cui.StructureCUI;
import com.boydti.fawe.bukkit.util.image.BukkitImageViewer;
import com.boydti.fawe.bukkit.v0.BukkitQueue_0;
import com.boydti.fawe.bukkit.v0.BukkitQueue_All;
@ -41,7 +40,6 @@ import com.boydti.fawe.regions.FaweMaskManager;
import com.boydti.fawe.util.Jars;
import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.util.cui.CUI;
import com.boydti.fawe.util.image.ImageViewer;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.world.World;
@ -64,7 +62,6 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
public class FaweBukkit implements IFawe, Listener {
@ -149,32 +146,6 @@ public class FaweBukkit implements IFawe, Listener {
});
}
@Override
public CUI getCUI(FawePlayer player) {
if (Settings.IMP.EXPERIMENTAL.VANILLA_CUI) {
if (listeningCui && cuiListener == null) return null;
listeningCui = true;
if (cuiListener == null) {
Plugin protocolLib = Bukkit.getPluginManager().getPlugin("ProtocolLib");
if (protocolLib != null && protocolLib.isEnabled()) {
cuiListener = new CUIListener(plugin);
} else {
return null;
}
}
return new StructureCUI(player);
}
return null;
}
@Override
public void registerPacketListener() {
PluginManager manager = Bukkit.getPluginManager();
if (packetListener == null && manager.getPlugin("ProtocolLib") != null) {
packetListener = new CFIPacketListener(plugin);
}
}
@Override
public synchronized ImageViewer getImageViewer(FawePlayer fp) {
if (listeningImages && imageListener == null) return null;

View File

@ -69,6 +69,7 @@ public class StructureCUI extends CUI {
private int viewDistance() {
Player player = this.<Player>getPlayer().parent;
//todo replace with PaperLib.isPaper()
if (Bukkit.getVersion().contains("paper")) {
return player.getViewDistance();
} else {

View File

@ -56,8 +56,8 @@ import org.bukkit.inventory.ItemStack;
* Adapts between Bukkit and WorldEdit equivalent objects.
*/
public enum BukkitAdapter {
INSTANCE
;
INSTANCE;
private final IBukkitAdapter adapter;
BukkitAdapter() {
@ -73,14 +73,36 @@ public enum BukkitAdapter {
return INSTANCE.adapter;
}
/**
* Checks equality between a WorldEdit BlockType and a Bukkit Material
*
* @param blockType The WorldEdit BlockType
* @param type The Bukkit Material
* @return If they are equal
*/
public static boolean equals(BlockType blockType, Material type) {
return getAdapter().equals(blockType, type);
}
/**
* Convert any WorldEdit world into an equivalent wrapped Bukkit world.
*
* <p>If a matching world cannot be found, a {@link RuntimeException}
* will be thrown.</p>
*
* @param world the world
* @return a wrapped Bukkit world
*/
public static BukkitWorld asBukkitWorld(World world) {
return getAdapter().asBukkitWorld(world);
}
/**
* Create a WorldEdit world from a Bukkit world.
*
* @param world the Bukkit world
* @return a WorldEdit world
*/
public static World adapt(org.bukkit.World world) {
return getAdapter().adapt(world);
}
@ -89,23 +111,48 @@ public enum BukkitAdapter {
return getAdapter().adapt(world);
}
/**
* Create a WorldEdit location from a Bukkit location.
*
* @param location the Bukkit location
* @return a WorldEdit location
*/
public static Location adapt(org.bukkit.Location location) {
checkNotNull(location);
return getAdapter().adapt(location);
}
/**
* Create a Bukkit location from a WorldEdit location.
*
* @param location the WorldEdit location
* @return a Bukkit location
*/
public static org.bukkit.Location adapt(Location location) {
checkNotNull(location);
return getAdapter().adapt(location);
}
public static org.bukkit.Location adapt(org.bukkit.World world, Vector3 position) {
return getAdapter().adapt(world, position);
}
public static org.bukkit.Location adapt(org.bukkit.World world, BlockVector3 position) {
checkNotNull(world);
checkNotNull(position);
return getAdapter().adapt(world, position);
}
/**
* Create a Bukkit location from a WorldEdit location with a Bukkit world.
*
* @param world the Bukkit world
* @param location the WorldEdit location
* @return a Bukkit location
*/
public static org.bukkit.Location adapt(org.bukkit.World world, Location location) {
checkNotNull(world);
checkNotNull(location);
return getAdapter().adapt(world, location);
}
@ -113,23 +160,58 @@ public enum BukkitAdapter {
return getAdapter().asVector(location);
}
/**
* Create a WorldEdit Vector from a Bukkit location.
*
* @param location The Bukkit location
* @return a WorldEdit vector
*/
public static BlockVector3 asBlockVector(org.bukkit.Location location) {
checkNotNull(location);
return getAdapter().asBlockVector(location);
}
/**
* Create a WorldEdit entity from a Bukkit entity.
*
* @param entity the Bukkit entity
* @return a WorldEdit entity
*/
public static Entity adapt(org.bukkit.entity.Entity entity) {
checkNotNull(entity);
return getAdapter().adapt(entity);
}
/**
* Create a Bukkit Material form a WorldEdit ItemType
*
* @param itemType The WorldEdit ItemType
* @return The Bukkit Material
*/
public static Material adapt(ItemType itemType) {
checkNotNull(itemType);
return getAdapter().adapt(itemType);
}
/**
* Create a Bukkit Material form a WorldEdit BlockType
*
* @param blockType The WorldEdit BlockType
* @return The Bukkit Material
*/
public static Material adapt(BlockType blockType) {
checkNotNull(blockType);
return getAdapter().adapt(blockType);
}
/**
* Create a WorldEdit GameMode from a Bukkit one.
*
* @param gameMode Bukkit GameMode
* @return WorldEdit GameMode
*/
public static GameMode adapt(org.bukkit.GameMode gameMode) {
checkNotNull(gameMode);
return getAdapter().adapt(gameMode);
}
@ -161,15 +243,37 @@ public enum BukkitAdapter {
return getAdapter().adapt(entityType);
}
/**
* Converts a Material to a BlockType
*
* @param material The material
* @return The blocktype
*/
public static BlockType asBlockType(Material material) {
checkNotNull(material);
return getAdapter().asBlockType(material);
}
/**
* Converts a Material to a ItemType
*
* @param material The material
* @return The itemtype
*/
public static ItemType asItemType(Material material) {
checkNotNull(material);
return getAdapter().asItemType(material);
}
/**
* Create a WorldEdit BlockState from a Bukkit BlockData
*
* @param blockData The Bukkit BlockData
* @return The WorldEdit BlockState
*/
public static BlockState adapt(BlockData blockData) {
checkNotNull(blockData);
return getAdapter().adapt(blockData);
}
@ -183,7 +287,8 @@ public enum BukkitAdapter {
* @param block The WorldEdit BlockStateHolder
* @return The Bukkit BlockData
*/
public static <B extends BlockStateHolder<B>> BlockData adapt(B block) {
public static BlockData adapt(BlockStateHolder block) {
checkNotNull(block);
return getAdapter().adapt(block);
}
@ -191,15 +296,40 @@ public enum BukkitAdapter {
return getAdapter().getBlockData(combinedId);
}
public static BlockState asBlockState(ItemStack itemStack) {
return getAdapter().asBlockState(itemStack);
/**
* Create a WorldEdit BlockState from a Bukkit ItemStack
*
* @param itemStack The Bukkit ItemStack
* @return The WorldEdit BlockState
*/
public static BlockState asBlockState(ItemStack itemStack) throws WorldEditException {
checkNotNull(itemStack);
if (itemStack.getType().isBlock()) {
return getAdapter().asBlockState(itemStack);
} else {
throw new NotABlockException();
}
}
/**
* Create a WorldEdit BaseItemStack from a Bukkit ItemStack
*
* @param itemStack The Bukkit ItemStack
* @return The WorldEdit BaseItemStack
*/
public static BaseItemStack adapt(ItemStack itemStack) {
checkNotNull(itemStack);
return getAdapter().adapt(itemStack);
}
/**
* Create a Bukkit ItemStack from a WorldEdit BaseItemStack
*
* @param item The WorldEdit BaseItemStack
* @return The Bukkit ItemStack
*/
public static ItemStack adapt(BaseItemStack item) {
checkNotNull(item);
return getAdapter().adapt(item);
}

View File

@ -109,8 +109,8 @@ public class BukkitPlayer extends AbstractPlayerActor {
if (itemStack.getType().getId().equalsIgnoreCase(WorldEdit.getInstance().getConfiguration().wandItem)) {
inv.remove(newItem);
}
final ItemStack item = player.getItemInHand();
player.setItemInHand(newItem);
final ItemStack item = player.getInventory().getItemInMainHand();
player.getInventory().setItemInMainHand(newItem);
HashMap<Integer, ItemStack> overflow = inv.addItem(item);
if (!overflow.isEmpty()) {
TaskManager.IMP.sync(new RunnableVal<Object>() {
@ -216,7 +216,7 @@ public class BukkitPlayer extends AbstractPlayerActor {
if (params.length > 0) {
send = send + "|" + StringUtil.joinString(params, "|");
}
player.sendPluginMessage(plugin, WorldEditPlugin.getCuiPluginChannel(), send.getBytes(CUIChannelListener.UTF_8_CHARSET));
player.sendPluginMessage(plugin, WorldEditPlugin.CUI_PLUGIN_CHANNEL, send.getBytes(CUIChannelListener.UTF_8_CHARSET));
}
public Player getPlayer() {
@ -305,7 +305,7 @@ public class BukkitPlayer extends AbstractPlayerActor {
}
@Override
public void sendFakeBlock(BlockVector3 pos, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
Location loc = new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ());
if (block == null) {
player.sendBlockChange(loc, player.getWorld().getBlockAt(loc).getBlockData());

View File

@ -100,7 +100,7 @@ public class BukkitServerInterface implements MultiUserPlatform {
return player;
} else {
org.bukkit.entity.Player bukkitPlayer = server.getPlayerExact(player.getName());
return bukkitPlayer != null ? plugin.wrapPlayer(bukkitPlayer) : null;
return bukkitPlayer != null ? WorldEditPlugin.getInstance().wrapPlayer(bukkitPlayer) : null;
}
}
@ -119,7 +119,7 @@ public class BukkitServerInterface implements MultiUserPlatform {
public void registerCommands(Dispatcher dispatcher) {
List<CommandInfo> toRegister = new ArrayList<>();
BukkitCommandInspector inspector = new BukkitCommandInspector(plugin, dispatcher);
for (CommandMapping command : dispatcher.getCommands()) {
Description description = command.getDescription();
List<String> permissions = description.getPermissions();
@ -177,7 +177,7 @@ public class BukkitServerInterface implements MultiUserPlatform {
public Collection<Actor> getConnectedUsers() {
List<Actor> users = new ArrayList<>();
for (org.bukkit.entity.Player player : Bukkit.getServer().getOnlinePlayers()) {
users.add(plugin.wrapPlayer(player));
users.add(WorldEditPlugin.getInstance().wrapPlayer(player));
}
return users;
}

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.bukkit;
import com.bekvon.bukkit.residence.commands.message;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.bukkit.adapter.v1_13_1.Spigot_v1_13_R2;
@ -34,47 +33,35 @@ import com.sk89q.worldedit.bukkit.adapter.AdapterLoadException;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplLoader;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
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.extent.inventory.BlockBag;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockCategory;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.FuzzyBlockState;
import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.item.ItemCategory;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Biome;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.java.JavaPluginLoader;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
@ -111,7 +98,7 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
lookupNamesField.setAccessible(true);
List<Plugin> plugins = (List<Plugin>) pluginsField.get(manager);
lookupNames = (Map<String, Plugin>) lookupNamesField.get(manager);
pluginsField.set(manager, plugins = new ArrayList<Plugin>(plugins) {
pluginsField.set(manager, new ArrayList<Plugin>(plugins) {
@Override
public boolean add(Plugin plugin) {
if (plugin.getName().startsWith("AsyncWorldEdit")) {
@ -126,7 +113,7 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
});
lookupNamesField.set(manager, lookupNames = new ConcurrentHashMap<String, Plugin>(lookupNames) {
@Override
public Plugin put(String key, Plugin plugin) {
public Plugin put(@NotNull String key, @NotNull Plugin plugin) {
if (plugin.getName().startsWith("AsyncWorldEdit") || plugin.getName().startsWith("BetterShutdown")) {
return null;
}
@ -157,15 +144,11 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
setEnabled(true);
}
public static String getCuiPluginChannel() {
return CUI_PLUGIN_CHANNEL;
}
@Override
public void onLoad() {
if (INSTANCE != null) return;
rename();
this.INSTANCE = this;
INSTANCE = this;
FaweBukkit imp = new FaweBukkit(this);
//noinspection ResultOfMethodCallIgnored
@ -190,6 +173,7 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
if (INSTANCE != null) return;
onLoad();
setupTags(); // these have to be done post-world since they rely on MC registries. the other ones just use Bukkit enums
//TODO: FAWE -- This needs to be moved to onLoad()
setupRegistries();
WorldEdit.getInstance().loadMappings();
@ -226,28 +210,30 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
}
// Block & Item
for (Material material : Material.values()) {
// if (material.isBlock() && !material.isLegacy()) {
// BlockType.REGISTRY.register(material.getKey().toString(), new BlockType(material.getKey().toString(), blockState -> {
// // TODO Use something way less hacky than this.
// ParserContext context = new ParserContext();
// context.setPreferringWildcard(true);
// context.setTryLegacy(false);
// context.setRestricted(false);
// try {
// FuzzyBlockState state = (FuzzyBlockState) WorldEdit.getInstance().getBlockFactory().parseFromInput(
// BukkitAdapter.adapt(blockState.getBlockType()).createBlockData().getAsString(), context
// ).toImmutableState();
// BlockState defaultState = blockState.getBlockType().getAllStates().get(0);
// for (Map.Entry<Property<?>, Object> propertyObjectEntry : state.getStates().entrySet()) {
// defaultState = defaultState.with((Property) propertyObjectEntry.getKey(), propertyObjectEntry.getValue());
// }
// return defaultState;
// } catch (InputParseException e) {
// e.printStackTrace();
// return blockState;
// }
// }));
// }
/*
if (material.isBlock() && !material.isLegacy()) {
BlockType.REGISTRY.register(material.getKey().toString(), new BlockType(material.getKey().toString(), blockState -> {
// TODO Use something way less hacky than this.
ParserContext context = new ParserContext();
context.setPreferringWildcard(true);
context.setTryLegacy(false);
context.setRestricted(false);
try {
FuzzyBlockState state = (FuzzyBlockState) WorldEdit.getInstance().getBlockFactory().parseFromInput(
BukkitAdapter.adapt(blockState.getBlockType()).createBlockData().getAsString(), context
).toImmutableState();
BlockState defaultState = blockState.getBlockType().getAllStates().get(0);
for (Map.Entry<Property<?>, Object> propertyObjectEntry : state.getStates().entrySet()) {
defaultState = defaultState.with((Property) propertyObjectEntry.getKey(), propertyObjectEntry.getValue());
}
return defaultState;
} catch (InputParseException e) {
e.printStackTrace();
return blockState;
}
}));
}
*/
if (material.isItem() && !material.isLegacy()) {
ItemType.REGISTRY.register(material.getKey().toString(), new ItemType(material.getKey().toString()));
}
@ -276,63 +262,30 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
}
private void rename() {
// {
// PluginDescriptionFile desc = getDescription();
// if (desc != null) {
// try {
// Field nameField = PluginDescriptionFile.class.getDeclaredField("name");
// nameField.setAccessible(true);
// nameField.set(desc, "FastAsyncWorldEdit");
// Field descriptionField = JavaPlugin.class.getDeclaredField("description");
// descriptionField.setAccessible(true);
// descriptionField.set(this, desc);
// } catch (Throwable ignore) {
// ignore.printStackTrace();
// }
// }
// }
{
File dir = getDataFolder();
if (dir != null) {
dir = new File(dir.getParentFile(), "FastAsyncWorldEdit");
try {
Field descriptionField = JavaPlugin.class.getDeclaredField("dataFolder");
descriptionField.setAccessible(true);
descriptionField.set(this, dir);
} catch (Throwable ignore) {
ignore.printStackTrace();
}
}
File dir = getDataFolder();
dir = new File(dir.getParentFile(), "FastAsyncWorldEdit");
try {
Field descriptionField = JavaPlugin.class.getDeclaredField("dataFolder");
descriptionField.setAccessible(true);
descriptionField.set(this, dir);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
// {
// Logger logger = getLogger();
// if (logger != null) {
// try {
// Field nameField = Logger.class.getDeclaredField("name");
// nameField.setAccessible(true);
// nameField.set(logger, "FastAsyncWorldEdit");
// } catch (Throwable ignore) {
// ignore.printStackTrace();
// }
// }
// }
{
File pluginsFolder = MainUtil.getJarFile().getParentFile();
for (File file : pluginsFolder.listFiles()) {
if (file.length() == 1988) return;
}
Plugin plugin = Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit");
File dummy = MainUtil.copyFile(MainUtil.getJarFile(), "DummyFawe.src", pluginsFolder, "DummyFawe.jar");
if (dummy != null && dummy.exists() && plugin == this) {
try {
Bukkit.getPluginManager().loadPlugin(dummy);
} catch (Throwable e) {
e.printStackTrace();
}
getLogger().info("Please restart the server if you have any plugins which depend on FAWE.");
} else if (dummy == null) {
MainUtil.copyFile(MainUtil.getJarFile(), "DummyFawe.src", pluginsFolder, "update" + File.separator + "DummyFawe.jar");
File pluginsFolder = MainUtil.getJarFile().getParentFile();
for (File file : pluginsFolder.listFiles()) {
if (file.length() == 1988) return;
}
Plugin plugin = Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit");
File dummy = MainUtil.copyFile(MainUtil.getJarFile(), "DummyFawe.src", pluginsFolder, "DummyFawe.jar");
if (dummy != null && dummy.exists() && plugin == this) {
try {
Bukkit.getPluginManager().loadPlugin(dummy);
} catch (Throwable e) {
e.printStackTrace();
}
getLogger().info("Please restart the server if you have any plugins which depend on FAWE.");
} else if (dummy == null) {
MainUtil.copyFile(MainUtil.getJarFile(), "DummyFawe.src", pluginsFolder, "update" + File.separator + "DummyFawe.jar");
}
}
@ -470,20 +423,20 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
return true;
}
// @Deprecated Using Async tab complete (rather than main thread)
// @Override
// public List<String> onTabComplete(CommandSender sender, Command cmd, String commandLabel, String[] args) {
// // Add the command to the array because the underlying command handling
// // code of WorldEdit expects it
// String[] split = new String[args.length + 1];
// System.arraycopy(args, 0, split, 1, args.length);
// split[0] = cmd.getName();
//
// CommandSuggestionEvent event = new CommandSuggestionEvent(wrapCommandSender(sender), Joiner.on(" ").join(split));
// getWorldEdit().getEventBus().post(event);
//
// return event.getSuggestions();
// }
/*
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String commandLabel, String[] args) {
// Add the command to the array because the underlying command handling
// code of WorldEdit expects it
String[] split = new String[args.length + 1];
System.arraycopy(args, 0, split, 1, args.length);
split[0] = cmd.getName();
CommandSuggestionEvent event = new CommandSuggestionEvent(wrapCommandSender(sender), Joiner.on(" ").join(split));
getWorldEdit().getEventBus().post(event);
return event.getSuggestions();
}
*/
/**
* Gets the session for the player.