Load without throwing errors without WorldEdit

It's just functional enough to print a message saying it won't function
without WorldEdit
This commit is contained in:
Jesse Boyd 2016-11-30 18:45:30 +11:00
parent 1a3aff28dc
commit 90e0ab574d
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
25 changed files with 161 additions and 82 deletions

View File

@ -61,6 +61,7 @@ public class FaweBukkit implements IFawe, Listener {
this.plugin = plugin;
try {
Fawe.set(this);
setupInjector();
if (Bukkit.getVersion().contains("git-Spigot")) {
debug("====== USE PAPER SPIGOT ======");
debug("DOWNLOAD: https://ci.destroystokyo.com/job/PaperSpigot/");
@ -79,8 +80,19 @@ public class FaweBukkit implements IFawe, Listener {
new ChunkListener();
}
});
// Inject
EditSessionBlockChangeDelegate.inject();
}
public void setupInjector() {
if (Bukkit.getPluginManager().getPlugin("WorldEdit") != null) {
Fawe.get().setupInjector();
// Inject
EditSessionBlockChangeDelegate.inject();
} else {
Fawe.debug("====== INSTALL WORLDEDIT ======");
Fawe.debug("FAWE requires WorldEdit to function correctly");
Fawe.debug("Info: https://github.com/boy0001/FastAsyncWorldedit/releases/");
Fawe.debug("===============================");
}
}
@Override
@ -377,4 +389,4 @@ public class FaweBukkit implements IFawe, Listener {
}
return ((BlocksHubBukkit) blocksHubPlugin).getApi();
}
}
}

View File

@ -223,30 +223,21 @@ public class Fawe {
this.IMP.startMetrics();
}
this.setupCommands();
/*
* Instance independent stuff
*/
this.setupMemoryListener();
// Delayed setup
// Delayed event setup
TaskManager.IMP.later(new Runnable() {
@Override
public void run() {
try {
WEManager.IMP.managers.addAll(Fawe.this.IMP.getMaskManagers());
WEManager.IMP.managers.add(new PlotSquaredFeature());
Fawe.debug("Plugin 'PlotSquared' found. Using it now.");
} catch (Throwable e) {}
Fawe.this.worldedit = WorldEdit.getInstance();
// Events
Fawe.this.setupEvents();
Fawe.this.IMP.setupVault();
}
}, 0);
/*
* Instance independent stuff
*/
this.setupInjector();
this.setupMemoryListener();
// Update
// Delayed updating
TaskManager.IMP.async(new Runnable() {
@Override
public void run() {
@ -311,23 +302,6 @@ public class Fawe {
Settings.save(file);
// Setting up message.yml
BBC.load(new File(this.IMP.getDirectory(), "message.yml"));
// Setting up commands.yml
Commands.load(new File(this.IMP.getDirectory(), "commands.yml"));
// Block rotation
try {
BundledBlockData.getInstance().loadFromResource();
} catch (IOException e) {
MainUtil.handleError(e);
}
File jar = MainUtil.getJarFile();
File extraBlocks = MainUtil.copyFile(jar, "extrablocks.json", null);
if (extraBlocks != null && extraBlocks.exists()) {
try {
BundledBlockData.getInstance().add(extraBlocks.toURI().toURL(), true);
} catch (Throwable ignore) {
Fawe.debug("Invalid format: extrablocks.json");
}
}
}
private WorldEdit worldedit;
@ -339,13 +313,28 @@ public class Fawe {
return this.worldedit;
}
private void setupInjector() {
public void setupInjector() {
/*
* Modify the sessions
* - EditSession supports custom queue and a lot of optimizations
* - LocalSession supports VirtualPlayers and undo on disk
*/
try {
// Delayed worldedit setup
TaskManager.IMP.later(new Runnable() {
@Override
public void run() {
try {
WEManager.IMP.managers.addAll(Fawe.this.IMP.getMaskManagers());
WEManager.IMP.managers.add(new PlotSquaredFeature());
Fawe.debug("Plugin 'PlotSquared' found. Using it now.");
} catch (Throwable e) {}
Fawe.this.worldedit = WorldEdit.getInstance();
Fawe.this.setupEvents();
}
}, 0);
// Setting up commands.yml
Commands.load(new File(this.IMP.getDirectory(), "commands.yml"));
EditSession.inject(); // Custom block placer + optimizations
EditSessionEvent.inject(); // Add EditSession to event (API)
LocalSession.inject(); // Add remember order / queue flushing / Optimizations for disk
@ -422,6 +411,20 @@ public class Fawe {
// BlockData
BlockData.inject(); // Temporary fix for 1.9.4
BundledBlockData.inject(); // Add custom rotation
try {
BundledBlockData.getInstance().loadFromResource();
} catch (IOException e) {
MainUtil.handleError(e);
}
File jar = MainUtil.getJarFile();
File extraBlocks = MainUtil.copyFile(jar, "extrablocks.json", null);
if (extraBlocks != null && extraBlocks.exists()) {
try {
BundledBlockData.getInstance().add(extraBlocks.toURI().toURL(), true);
} catch (Throwable ignore) {
Fawe.debug("Invalid format: extrablocks.json");
}
}
// NBT
NBTInputStream.inject(); // Add actual streaming + Optimizations + New methods
NBTOutputStream.inject(); // New methods

View File

@ -69,7 +69,7 @@ public class AnvilCommands {
}
}
});
BBC.VISITOR_BLOCK.send(player, count.longValue());
player.print(BBC.VISITOR_BLOCK.format(count.longValue()));
}
@Command(
@ -114,7 +114,7 @@ public class AnvilCommands {
}
}
});
BBC.VISITOR_BLOCK.send(player, count.longValue());
player.print(BBC.VISITOR_BLOCK.format(count.longValue()));
}
@Command(
@ -189,7 +189,7 @@ public class AnvilCommands {
};
}
queue.filterWorld(filter);
BBC.SELECTION_COUNT.send(player, count.longValue());
player.print(BBC.SELECTION_COUNT.format(count.longValue()));
}
}

View File

@ -7,8 +7,9 @@ import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.RunnableVal3;
import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.StringMan;
import com.sk89q.worldedit.extension.platform.Actor;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
@ -102,6 +103,7 @@ public enum BBC {
BRUSH_SPLINE_SECONDARY("Created spline", "WorldEdit.Brush"),
BRUSH_BLEND_BALL("Blend ball brush equipped (%s0).", "WorldEdit.Brush"),
BRUSH_ERODE("Erode brush equipped (%s0).", "WorldEdit.Brush"),
BRUSH_RECURSIVE("Recursive brush equipped (%s0).", "WorldEdit.Brush"),
BRUSH_PASTE_NONE("Nothing to paste", "WorldEdit.Brush"),
BRUSH_SIZE("Brush size set", "WorldEdit.Brush"),
BRUSH_RANGE("Brush size set", "WorldEdit.Brush"),
@ -276,6 +278,10 @@ public enum BBC {
this(d, true, cat.toLowerCase());
}
public String f(final Object... args) {
return format(args);
}
public String format(final Object... args) {
String m = this.s;
for (int i = args.length - 1; i >= 0; i--) {
@ -387,14 +393,23 @@ public enum BBC {
return this.cat;
}
public void send(Actor actor, final Object... args) {
public void send(Object actor, final Object... args) {
if (isEmpty()) {
return;
}
if (actor == null) {
Fawe.debug(this.format(args));
} else {
actor.print((PREFIX.isEmpty() ? "" : PREFIX.s() + " ") + this.format(args));
try {
Method method = actor.getClass().getDeclaredMethod("print", String.class);
method.invoke(actor, (PREFIX.isEmpty() ? "" : PREFIX.s() + " ") + this.format(args));
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}

View File

@ -74,7 +74,7 @@ public class CopyPastaBrush implements DoubleActionBrush {
ClipboardHolder holder = new ClipboardHolder(clipboard, editSession.getWorld().getWorldData());
session.setClipboard(holder);
int blocks = builder.size();
BBC.COMMAND_COPY.send(player, blocks);
player.print(BBC.COMMAND_COPY.format(blocks));
return;
}
case PRIMARY: {
@ -90,7 +90,7 @@ public class CopyPastaBrush implements DoubleActionBrush {
.build();
Operations.completeLegacy(operation);
} catch (EmptyClipboardException e) {
BBC.BRUSH_PASTE_NONE.send(player);
player.print(BBC.BRUSH_PASTE_NONE.s());
}
}
}

View File

@ -59,11 +59,11 @@ public class InspectBrush extends BrushTool implements DoubleActionTraceTool {
public boolean perform(final Player player, LocalSession session, boolean rightClick) {
if (!session.isToolControlEnabled() || !player.hasPermission("worldedit.tool.inspect")) {
BBC.NO_PERM.send(player, "worldedit.tool.inspect");
player.print(BBC.NO_PERM.f("worldedit.tool.inspect"));
return false;
}
if (!Settings.HISTORY.USE_DATABASE) {
BBC.SETTING_DISABLE.send(player, "history.use-database");
player.print(BBC.SETTING_DISABLE.f("history.use-database"));
return false;
}
WorldVector target = getTarget(player, rightClick);

View File

@ -68,12 +68,12 @@ public class SplineBrush implements DoubleActionBrush {
numSplines = points.size();
}
this.positionSets.add(points);
BBC.BRUSH_SPLINE_PRIMARY.send(player);
player.print(BBC.BRUSH_SPLINE_PRIMARY.s());
break;
}
case SECONDARY: {
if (positionSets.size() < 2) {
BBC.BRUSH_SPLINE_SECONDARY_ERROR.send(player);
player.print(BBC.BRUSH_SPLINE_SECONDARY_ERROR.s());
return;
}
List<Vector> centroids = new ArrayList<>();
@ -112,7 +112,7 @@ public class SplineBrush implements DoubleActionBrush {
}
editSession.drawSpline(Patterns.wrap(pattern), currentSpline, 0, 0, 0, 10, 0, true);
}
BBC.BRUSH_SPLINE_SECONDARY.send(player);
player.print(BBC.BRUSH_SPLINE_SECONDARY.s());
positionSets.clear();
numSplines = 0;
break;

View File

@ -39,4 +39,4 @@ public class Updater {
}
} catch (Throwable ignore) {}
}
}
}

View File

@ -100,7 +100,7 @@ public class BrushCommands {
BrushTool tool = session.getBrushTool(player.getItemInHand());
tool.setSize(radius);
tool.setBrush(new BlendBall(), "worldedit.brush.blendball");
BBC.BRUSH_SPHERE.send(player, radius);
player.print(BBC.BRUSH_BLEND_BALL.f(radius));
}
@Command(
@ -117,7 +117,7 @@ public class BrushCommands {
DoubleActionBrushTool tool = session.getDoubleActionBrushTool(player.getItemInHand());
tool.setSize(radius);
tool.setBrush(new ErodeBrush(), "worldedit.brush.erode");
BBC.BRUSH_SPHERE.send(player, radius);
player.print(BBC.BRUSH_ERODE.f(radius));
}
@Command(
@ -137,7 +137,7 @@ public class BrushCommands {
tool.setBrush(new RecurseBrush(tool, depthFirst), "worldedit.brush.recursive");
tool.setMask(new IdMask(editSession));
tool.setFill(fill);
BBC.BRUSH_SPHERE.send(player, radius);
player.print(BBC.BRUSH_RECURSIVE.f(radius));
}
@Command(
@ -160,7 +160,7 @@ public class BrushCommands {
tool.setFill(fill);
tool.setSize(radius);
tool.setBrush(new LineBrush(shell, select, flat), "worldedit.brush.line");
BBC.BRUSH_LINE.send(player, radius);
player.print(BBC.BRUSH_LINE.f(radius));
}
@Command(
@ -178,7 +178,7 @@ public class BrushCommands {
tool.setFill(fill);
tool.setSize(radius);
tool.setBrush(new SplineBrush(player, session, tool), "worldedit.brush.spline");
BBC.BRUSH_SPLINE.send(player, radius);
player.print(BBC.BRUSH_SPLINE.f(radius));
}
@Command(
@ -205,7 +205,7 @@ public class BrushCommands {
} else {
tool.setBrush(new SphereBrush(), "worldedit.brush.sphere");
}
BBC.BRUSH_SPHERE.send(player, radius);
player.print(BBC.BRUSH_SPHERE.f(radius));
}
@Command(
@ -234,7 +234,7 @@ public class BrushCommands {
} else {
tool.setBrush(new CylinderBrush(height), "worldedit.brush.cylinder");
}
BBC.BRUSH_CYLINDER.send(player, radius, height);
player.print(BBC.BRUSH_SPHERE.f(radius, height));
}
@Command(
@ -261,7 +261,7 @@ public class BrushCommands {
BrushTool tool = session.getBrushTool(player.getItemInHand());
tool.setBrush(new ClipboardBrush(holder, ignoreAir, usingOrigin), "worldedit.brush.clipboard");
BBC.BRUSH_CLIPBOARD.send(player);
player.print(BBC.BRUSH_CLIPBOARD.s());
}
@Command(
@ -289,7 +289,7 @@ public class BrushCommands {
tool.setSize(radius);
tool.setBrush(new SmoothBrush(iterations, naturalBlocksOnly), "worldedit.brush.smooth");
BBC.BRUSH_SMOOTH.send(player, radius, iterations, (naturalBlocksOnly ? "natural blocks only" : "any block"));
player.print(BBC.BRUSH_SMOOTH.f(radius, iterations, (naturalBlocksOnly ? "natural blocks only" : "any block")));
}
@Command(
@ -310,6 +310,7 @@ public class BrushCommands {
tool.setMask(new BlockMask(editSession, new BaseBlock(BlockID.FIRE)));
tool.setBrush(new SphereBrush(), "worldedit.brush.ex");
BBC.BRUSH_EXTINGUISHER.send(player, radius);
player.print(BBC.BRUSH_EXTINGUISHER.f(radius));
}
@Command(
@ -331,7 +332,7 @@ public class BrushCommands {
BrushTool tool = session.getBrushTool(player.getItemInHand());
tool.setSize(radius);
tool.setBrush(new GravityBrush(fromMaxY, tool), "worldedit.brush.gravity");
BBC.BRUSH_GRAVITY.send(player, radius);
player.print(BBC.BRUSH_GRAVITY.f(radius));
}
@Command(
@ -355,7 +356,7 @@ public class BrushCommands {
} catch (EmptyClipboardException ignore) {
tool.setBrush(new HeightBrush(file, rotation, yscale, tool, null), "worldedit.brush.height");
}
BBC.BRUSH_HEIGHT.send(player, radius);
player.print(BBC.BRUSH_HEIGHT.f(radius));
}
@Command(
@ -374,7 +375,7 @@ public class BrushCommands {
DoubleActionBrushTool tool = session.getDoubleActionBrushTool(player.getItemInHand());
tool.setSize(radius);
tool.setBrush(new CopyPastaBrush(player, session, tool), "worldedit.brush.copy");
BBC.BRUSH_COPY.send(player, radius);
player.print(BBC.BRUSH_COPY.f(radius));
}
@Command(
@ -391,7 +392,7 @@ public class BrushCommands {
BrushTool tool = session.getBrushTool(player.getItemInHand());
String cmd = args.getJoinedStrings(1);
tool.setBrush(new CommandBrush(player, tool, cmd, radius), "worldedit.brush.copy");
BBC.BRUSH_COMMAND.send(player, cmd);
player.print(BBC.BRUSH_COMMAND.f(cmd));
}
@Command(
@ -436,7 +437,7 @@ public class BrushCommands {
BrushTool tool = session.getBrushTool(player.getItemInHand());
tool.setSize(radius);
tool.setBrush(new ButcherBrush(flags), "worldedit.brush.butcher");
BBC.BRUSH_BUTCHER.send(player, radius);
player.print(BBC.BRUSH_BUTCHER.f(radius));
}
public static Class<?> inject() {

View File

@ -6,7 +6,11 @@ import com.boydti.fawe.object.extent.TransformExtent;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.ItemType;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.ParserContext;
@ -14,6 +18,7 @@ import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.util.command.parametric.Optional;
import static com.google.common.base.Preconditions.checkNotNull;
/**

View File

@ -43,21 +43,18 @@ public class ToolUtilCommands {
String newState = args.getString(0, null);
if (session.hasSuperPickAxe()) {
if ("on".equals(newState)) {
player.printError("Super pick axe already enabled.");
BBC.SUPERPICKAXE_ENABLED.send(player);
return;
}
session.disableSuperPickAxe();
player.print("Super pick axe disabled.");
BBC.SUPERPICKAXE_DISABLED.send(player);
} else {
if ("off".equals(newState)) {
player.printError("Super pick axe already disabled.");
BBC.SUPERPICKAXE_DISABLED.send(player);
return;
}
session.enableSuperPickAxe();
player.print("Super pick axe enabled.");
BBC.SUPERPICKAXE_ENABLED.send(player);
}

View File

@ -1,6 +1,8 @@
package com.sk89q.worldedit.command.tool;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.entity.Player;

View File

@ -19,7 +19,10 @@
package com.sk89q.worldedit.command.tool;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldVectorFace;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.entity.Player;

View File

@ -26,9 +26,9 @@ import com.sk89q.worldedit.event.Event;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.EditSession.Stage;

View File

@ -43,11 +43,21 @@ public class FaweForge implements IFawe {
this.mod = mod;
try {
Fawe.set(this);
setupInjector();
} catch (InstanceAlreadyExistsException e) {
MainUtil.handleError(e);
}
}
public void setupInjector() {
try {
Fawe.get().setupInjector();
com.sk89q.worldedit.forge.ForgePlayer.inject();
} catch (Throwable e) {
Fawe.debug("Failed to inject WorldEdit classes.");
}
}
@Override
public void debug(String s) {
logger.debug(s);

View File

@ -30,8 +30,6 @@ public class ForgeMain {
MinecraftForge.EVENT_BUS.register(this);
FMLCommonHandler.instance().bus().register(this);
this.IMP = new FaweForge(this, event.getModLog(), event.getModMetadata(), directory);
com.sk89q.worldedit.forge.ForgePlayer.inject();
}
@Mod.EventHandler

View File

@ -43,11 +43,21 @@ public class FaweForge implements IFawe {
this.mod = mod;
try {
Fawe.set(this);
setupInjector();
} catch (InstanceAlreadyExistsException e) {
MainUtil.handleError(e);
}
}
public void setupInjector() {
try {
Fawe.get().setupInjector();
com.sk89q.worldedit.forge.ForgePlayer.inject();
} catch (Throwable e) {
Fawe.debug("Failed to inject WorldEdit classes.");
}
}
@Override
public void debug(String s) {
logger.debug(s);

View File

@ -29,8 +29,6 @@ public class ForgeMain {
MinecraftForge.EVENT_BUS.register(this);
FMLCommonHandler.instance().bus().register(this);
this.IMP = new FaweForge(this, event.getModLog(), event.getModMetadata(), directory);
com.sk89q.worldedit.forge.ForgePlayer.inject();
}
@Mod.EventHandler

View File

@ -43,11 +43,21 @@ public class FaweForge implements IFawe {
this.mod = mod;
try {
Fawe.set(this);
setupInjector();
} catch (InstanceAlreadyExistsException e) {
MainUtil.handleError(e);
}
}
public void setupInjector() {
try {
Fawe.get().setupInjector();
com.sk89q.worldedit.forge.ForgePlayer.inject();
} catch (Throwable e) {
Fawe.debug("Failed to inject WorldEdit classes.");
}
}
@Override
public void debug(String s) {
logger.error(s);

View File

@ -31,8 +31,6 @@ public class ForgeMain {
MinecraftForge.EVENT_BUS.register(this);
FMLCommonHandler.instance().bus().register(this);
this.IMP = new FaweForge(this, event.getModLog(), event.getModMetadata(), directory);
com.sk89q.worldedit.forge.ForgePlayer.inject();
}
@Mod.EventHandler

View File

@ -43,11 +43,21 @@ public class FaweForge implements IFawe {
this.mod = mod;
try {
Fawe.set(this);
setupInjector();
} catch (InstanceAlreadyExistsException e) {
MainUtil.handleError(e);
}
}
public void setupInjector() {
try {
Fawe.get().setupInjector();
com.sk89q.worldedit.forge.ForgePlayer.inject();
} catch (Throwable e) {
Fawe.debug("Failed to inject WorldEdit classes.");
}
}
@Override
public void debug(String s) {
logger.debug(s);

View File

@ -31,8 +31,6 @@ public class ForgeMain {
MinecraftForge.EVENT_BUS.register(this);
FMLCommonHandler.instance().bus().register(this);
this.IMP = new FaweForge(this, event.getModLog(), event.getModMetadata(), directory);
com.sk89q.worldedit.forge.ForgePlayer.inject();
}
@Mod.EventHandler

View File

@ -43,11 +43,21 @@ public class FaweForge implements IFawe {
this.mod = mod;
try {
Fawe.set(this);
setupInjector();
} catch (InstanceAlreadyExistsException e) {
MainUtil.handleError(e);
}
}
public void setupInjector() {
try {
Fawe.get().setupInjector();
com.sk89q.worldedit.forge.ForgePlayer.inject();
} catch (Throwable e) {
Fawe.debug("Failed to inject WorldEdit classes.");
}
}
@Override
public void debug(String s) {
logger.debug(s);

View File

@ -30,8 +30,6 @@ public class ForgeMain {
MinecraftForge.EVENT_BUS.register(this);
FMLCommonHandler.instance().bus().register(this);
this.IMP = new FaweForge(this, event.getModLog(), event.getModMetadata(), directory);
com.sk89q.worldedit.forge.ForgePlayer.inject();
}
@Mod.EventHandler

View File

@ -75,6 +75,7 @@ public class NukkitWorldEdit extends PluginBase {
public void onEnable() {
try {
Fawe.set(new FaweNukkit(this));
Fawe.get().setupInjector();
Settings.HISTORY.COMBINE_STAGES = false;
logger = Logger.getLogger(NukkitWorldEdit.class.getCanonicalName());
createDefaultConfiguration("config-basic.yml");