From 4ffb9bce6cb8dda29335842b3c8491fed2a79866 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 16 Aug 2018 23:21:39 +1000 Subject: [PATCH] Various minor Fix image brush Fix some java 9 issues Fix metrics being disabled Fix compile: duplicate method in SimpleBlockMaterial Load as both FastAsyncWorldEdit and WorldEdit --- .../worldedit/bukkit/WorldEditPlugin.java | 83 +++++++++++++++--- .../src/main/resources/DummyFawe.src | Bin 0 -> 1073 bytes .../src/main/resources/plugin.yml | 2 +- .../src/main/java/com/boydti/fawe/Fawe.java | 11 ++- .../java/com/boydti/fawe/config/Settings.java | 6 +- .../boydti/fawe/object/brush/ImageBrush.java | 5 +- .../boydti/fawe/object/mask/SurfaceMask.java | 2 +- .../java/com/boydti/fawe/util/MainUtil.java | 9 +- .../boydti/fawe/util/ReflectionUtils9.java | 4 - .../java/com/sk89q/worldedit/EditSession.java | 54 ------------ .../world/registry/SimpleBlockMaterial.java | 10 --- 11 files changed, 90 insertions(+), 96 deletions(-) create mode 100644 worldedit-bukkit/src/main/resources/DummyFawe.src diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index 5116a02d2..3c40628f0 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -19,13 +19,10 @@ package com.sk89q.worldedit.bukkit; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.bekvon.bukkit.residence.commands.message; -import com.bekvon.bukkit.residence.containers.cmd; import com.boydti.fawe.Fawe; import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.bukkit.adapter.Spigot_v1_13_R1; +import com.boydti.fawe.util.MainUtil; import com.google.common.base.Joiner; import com.sk89q.util.yaml.YAMLProcessor; import com.sk89q.wepif.PermissionsResolverManager; @@ -56,27 +53,27 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPluginLoader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; +import javax.annotation.Nullable; +import java.io.*; import java.lang.reflect.Field; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.jar.JarFile; import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.ZipEntry; -import javax.annotation.Nullable; +import static com.google.common.base.Preconditions.checkNotNull; /** * Plugin for Bukkit. */ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { - private static final Logger log = Logger.getLogger(WorldEditPlugin.class.getCanonicalName()); + private static final Logger log = Logger.getLogger("FastAsyncWorldEdit"); public static final String CUI_PLUGIN_CHANNEL = "worldedit:cui"; private static WorldEditPlugin INSTANCE; @@ -122,11 +119,20 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { } public WorldEditPlugin() { - if (lookupNames != null) lookupNames.putIfAbsent("WorldEdit".toLowerCase(Locale.ENGLISH), this); + init(); } public WorldEditPlugin(JavaPluginLoader loader, PluginDescriptionFile desc, File dataFolder, File jarFile) { - if (lookupNames != null) lookupNames.putIfAbsent("WorldEdit".toLowerCase(Locale.ENGLISH), this); + init(); + } + + private void init() { + if (lookupNames != null) { + lookupNames.putIfAbsent("FastAsyncWorldEdit".toLowerCase(Locale.ENGLISH), this); + lookupNames.putIfAbsent("WorldEdit".toLowerCase(Locale.ENGLISH), this); + rename(); + } + setEnabled(true); } public static String getCuiPluginChannel() { @@ -182,6 +188,55 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { } } + private void rename() { + { + PluginDescriptionFile desc = getDescription(); + if (desc != null) { + desc = new PluginDescriptionFile("FastAsyncWorldEdit", desc.getVersion(), desc.getMain()); + try { + 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(); + } + } + } + { + 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() == 1073) return; + } + MainUtil.copyFile(MainUtil.getJarFile(), "DummyFawe.src", pluginsFolder, "DummyFawe.jar"); + log.log(Level.INFO, "Please restart the server if you have any plugins which depend on FAWE."); + } + } + private void fail(Runnable run, String message) { try { run.run(); diff --git a/worldedit-bukkit/src/main/resources/DummyFawe.src b/worldedit-bukkit/src/main/resources/DummyFawe.src new file mode 100644 index 0000000000000000000000000000000000000000..969870c12381a7fa4cc896cd40b63f204fce15e8 GIT binary patch literal 1073 zcmWIWW@h1HVBp|jkliNW%K!vSAOZ+Df!NnI#8KDN&rP41ApoxM(^diBP4!Igq=5<~ zfmj4tp|7K#r<-eVh@P+8XWuiYeY|z`F7kToYMncCeshq)72^j_A3bG4G7Q~T7NB9t z`MD?-qO0MCs!7VPOex94t5g70XjvFbv;+uf(TPORg6cv6HE;sd$7{FK5&zH)9p;>nyc_ zr!p55f8_inaLGyG#s8TvxZK?DIlp+Nt|uys79)2Gl&*OIgTft%fvJO`Ag44vGf%HF zH|MnX8Q-lz1>QP(g*xlbc=MgtKjm5Ids64&(^I}@&TJ0yICuW4_o?+hnkTP#d+YdL zEk5OW=Jd0tTHqwWeo9;Nm88bUB1WKnj7%cTxKkd`QXmjucq*g&!;c literal 0 HcmV?d00001 diff --git a/worldedit-bukkit/src/main/resources/plugin.yml b/worldedit-bukkit/src/main/resources/plugin.yml index 4bfc02222..ac4873a5b 100644 --- a/worldedit-bukkit/src/main/resources/plugin.yml +++ b/worldedit-bukkit/src/main/resources/plugin.yml @@ -1,4 +1,4 @@ -name: FastAsyncWorldEdit +name: WorldEdit main: com.sk89q.worldedit.bukkit.WorldEditPlugin version: "${internalVersion}" api-version: 1.13 diff --git a/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java b/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java index 6181395ec..8f0338599 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java @@ -12,6 +12,7 @@ import com.boydti.fawe.util.chat.ChatManager; import com.boydti.fawe.util.chat.PlainChatManager; import com.boydti.fawe.util.cui.CUI; import com.boydti.fawe.util.metrics.BStats; +import com.boydti.fawe.wrappers.FakePlayer; import com.sk89q.jnbt.*; import com.sk89q.worldedit.*; import com.sk89q.worldedit.Vector; @@ -179,10 +180,7 @@ public class Fawe { } public static void debugPlain(String s) { - Actor actor = Request.request().getActor(); - if (actor != null) { - actor.print(BBC.color(s)); - } else if (INSTANCE != null) { + if (INSTANCE != null) { INSTANCE.IMP.debug(s); } else { System.out.println(BBC.stripColor(BBC.color(s))); @@ -195,6 +193,11 @@ public class Fawe { * @param s */ public static void debug(Object s) { + Actor actor = Request.request().getActor(); + if (actor != null && actor.isPlayer()) { + actor.print(BBC.color(BBC.PREFIX.original() + " " + s)); + return; + } debugPlain(BBC.PREFIX.original() + " " + s); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/config/Settings.java b/worldedit-core/src/main/java/com/boydti/fawe/config/Settings.java index f5e8c98e9..169df3132 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/config/Settings.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/config/Settings.java @@ -11,9 +11,9 @@ public class Settings extends Config { @Comment("These first 6 aren't configurable") // This is a comment @Final // Indicates that this value isn't configurable - public final String ISSUES = "https://github.com/boy0001/FastAsyncWorldedit/issues"; + public String ISSUES = "https://github.com/boy0001/FastAsyncWorldedit/issues"; @Final - public final String WIKI = "https://github.com/boy0001/FastAsyncWorldedit/wiki/"; + public String WIKI = "https://github.com/boy0001/FastAsyncWorldedit/wiki/"; @Final public String DATE; // These values are set from FAWE before loading @Final @@ -33,7 +33,7 @@ public class Settings extends Config { }) public String UPDATE = "false"; @Comment("Send anonymous usage statistics") - public boolean METRICS = false; + public boolean METRICS = true; @Comment({ "Set true to enable WorldEdit restrictions per region (e.g. PlotSquared or WorldGuard).", "To be allowed to WorldEdit in a region, users need the appropriate", diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ImageBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ImageBrush.java index c04582ab6..39505426a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ImageBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ImageBrush.java @@ -1,6 +1,7 @@ package com.boydti.fawe.object.brush; import com.boydti.fawe.object.collection.SummedColorTable; +import com.boydti.fawe.object.mask.SurfaceMask; import com.boydti.fawe.util.TextureUtil; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; @@ -77,14 +78,14 @@ public class ImageBrush implements Brush { final int cx = position.getBlockX(); final int cy = position.getBlockY(); final int cz = position.getBlockZ(); - final SolidBlockMask solid = new SolidBlockMask(editSession); + final Mask solid = new SurfaceMask(editSession); double scale = Math.max(width, height) / sizeDouble; Location loc = editSession.getPlayer().getPlayer().getLocation(); float yaw = loc.getYaw(); float pitch = loc.getPitch(); - AffineTransform transform = new AffineTransform().rotateY((-yaw) % 360).rotateX(pitch - 90).inverse(); + AffineTransform transform = new AffineTransform().rotateY((-yaw) % 360).rotateX((pitch - 90) % 360).inverse(); RecursiveVisitor visitor = new RecursiveVisitor(new Mask() { private final Vector mutable = new Vector(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java index e2f125065..5330d8ceb 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java @@ -25,4 +25,4 @@ public class SurfaceMask extends AdjacentAnyMask { public boolean test(Vector v) { return !getParentMask().test(v.getBlockX(), v.getBlockY(), v.getBlockZ()) && super.test(v); } -} +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/MainUtil.java b/worldedit-core/src/main/java/com/boydti/fawe/util/MainUtil.java index 1da728bff..0027cf005 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/MainUtil.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/MainUtil.java @@ -668,6 +668,10 @@ public class MainUtil { } public static File copyFile(File jar, String resource, File output) { + return copyFile(jar, resource, output, resource); + } + + public static File copyFile(File jar, String resource, File output, String fileName) { try { if (output == null) { output = Fawe.imp().getDirectory(); @@ -675,11 +679,11 @@ public class MainUtil { if (!output.exists()) { output.mkdirs(); } - File newFile = new File(output, resource); + File newFile = new File(output, fileName); if (newFile.exists()) { return newFile; } - try (InputStream stream = Fawe.imp().getClass().getResourceAsStream(resource.startsWith("/") ? resource : "/" + resource)) { + try (InputStream stream = Fawe.class.getResourceAsStream(resource.startsWith("/") ? resource : "/" + resource)) { byte[] buffer = new byte[2048]; if (stream == null) { try (ZipInputStream zis = new ZipInputStream(new FileInputStream(jar))) { @@ -687,7 +691,6 @@ public class MainUtil { while (ze != null) { String name = ze.getName(); if (name.equals(resource)) { - new File(newFile.getParent()).mkdirs(); try (FileOutputStream fos = new FileOutputStream(newFile)) { int len; while ((len = zis.read(buffer)) > 0) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils9.java b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils9.java index e054de7a3..0270b5f16 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils9.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils9.java @@ -117,12 +117,8 @@ public class ReflectionUtils9 { } try { - System.out.println("Target " + target + " | " + field.getName()); if (target == null) field.set(null, value); else field.set(target, value); - -// FieldAccessor fa = ReflectionFactory.getReflectionFactory().newFieldAccessor(field, false); -// fa.set(target, value); } catch (NoSuchMethodError error) { field.set(target, value); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index b7b70294f..8a250f790 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -2424,7 +2424,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, if (dx2 + dz2 > radiusSq) { continue; } -<<<<<<< HEAD outer: for (int y = maxY; y >= 1; --y) { BlockType type = getBlockType(x, y, z); @@ -2442,29 +2441,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, case JUNGLE_LEAVES: case OAK_LEAVES: case SPRUCE_LEAVES: -======= - - for (int y = world.getMaxY(); y >= 1; --y) { - Vector pt = new Vector(x, y, z); - BlockType id = getBlock(pt).getBlockType(); - - if (id.getMaterial().isAir()) { - continue; - } - - // Ice! - if (id == BlockTypes.WATER) { - if (setBlock(pt, ice)) { - ++affected; - } - break; - } - - // Snow should not cover these blocks - if (id.getMaterial().isTranslucent()) { - // Add snow on leaves - if (!BlockCategories.LEAVES.contains(id)) { ->>>>>>> refs/remotes/sk89q/master break; default: if (type.getMaterial().isTranslucent()) { @@ -2569,7 +2545,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of trees created * @throws MaxChangedBlocksException thrown if too many blocks are changed */ -<<<<<<< HEAD public int makeForest(final Vector basePosition, final int size, final double density, TreeGenerator.TreeType treeType) { try { for (int x = basePosition.getBlockX() - size; x <= (basePosition.getBlockX() + size); ++x) { @@ -2601,35 +2576,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, default: break; } -======= - public int makeForest(Vector basePosition, int size, double density, TreeGenerator.TreeType treeType) throws MaxChangedBlocksException { - int affected = 0; - - for (int x = basePosition.getBlockX() - size; x <= basePosition.getBlockX() - + size; ++x) { - for (int z = basePosition.getBlockZ() - size; z <= basePosition.getBlockZ() - + size; ++z) { - // Don't want to be in the ground - if (!getBlock(new Vector(x, basePosition.getBlockY(), z)).getBlockType().getMaterial().isAir()) { - continue; - } - // The gods don't want a tree here - if (Math.random() >= density) { - continue; - } // def 0.05 - - for (int y = basePosition.getBlockY(); y >= basePosition.getBlockY() - 10; --y) { - // Check if we hit the ground - BlockType t = getBlock(new Vector(x, y, z)).getBlockType(); - if (t == BlockTypes.GRASS_BLOCK || t == BlockTypes.DIRT) { - treeType.generate(this, new Vector(x, y + 1, z)); - ++affected; - break; - } else if (t == BlockTypes.SNOW) { - setBlock(new Vector(x, y, z), BlockTypes.AIR.getDefaultState()); - } else if (!t.getMaterial().isAir()) { // Trees won't grow on this! - break; ->>>>>>> refs/remotes/sk89q/master } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/SimpleBlockMaterial.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/SimpleBlockMaterial.java index 40ff55364..2ba9a820d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/SimpleBlockMaterial.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/SimpleBlockMaterial.java @@ -43,7 +43,6 @@ class SimpleBlockMaterial implements BlockMaterial { private boolean isTranslucent; private boolean hasContainer; private int lightOpacity; - private boolean isAir; private int mapColor; @Override @@ -51,10 +50,6 @@ class SimpleBlockMaterial implements BlockMaterial { return isAir; } - public void setAir(boolean air) { - isAir = air; - } - @Override public int getMapColor() { return mapColor; @@ -73,11 +68,6 @@ class SimpleBlockMaterial implements BlockMaterial { this.lightOpacity = lightOpacity; } - @Override - public boolean isAir() { - return this.isAir; - } - public void setIsAir(boolean isAir) { this.isAir = isAir; }