From f20a1002bb600fdd4f434f031ff392889f15dedf Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 10 Jul 2017 16:00:17 +1000 Subject: [PATCH] Fixes language option and Fixes #633 --- .../com/boydti/fawe/bukkit/BukkitMain.java | 24 +++++++++++++++ .../com/boydti/fawe/bukkit/FaweBukkit.java | 23 -------------- .../boydti/fawe/bukkit/v0/BukkitQueue_0.java | 1 + .../fawe/bukkit/v1_12/BukkitChunk_1_12.java | 4 +-- core/src/main/java/com/boydti/fawe/Fawe.java | 9 ++++-- .../de/{messages.yml => message.yml} | 0 .../com/boydti/fawe/bukkit/favs/Favs.java | 25 ++++++++++++---- .../boydti/fawe/bukkit/favs/PatternUtil.java | 30 +++++++++++++++++++ .../command/VoxelVoxelCommand.java | 22 ++------------ 9 files changed, 85 insertions(+), 53 deletions(-) rename core/src/main/resources/de/{messages.yml => message.yml} (100%) create mode 100644 favs/src/main/java/com/boydti/fawe/bukkit/favs/PatternUtil.java diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitMain.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitMain.java index b4a82b5e..bfcd3d92 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitMain.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitMain.java @@ -1,7 +1,12 @@ package com.boydti.fawe.bukkit; import com.boydti.fawe.Fawe; +import java.io.File; +import java.io.FileOutputStream; import java.lang.reflect.Field; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -49,6 +54,25 @@ public class BukkitMain extends JavaPlugin { @Override public void onEnable() { + if (Bukkit.getPluginManager().getPlugin("WorldEdit") == null) { + try { + File output = new File(this.getDataFolder().getParentFile(), "WorldEdit.jar"); + URL worldEditUrl = new URL("https://addons.cursecdn.com/files/2431/372/worldedit-bukkit-6.1.7.2.jar"); + try (ReadableByteChannel rbc = Channels.newChannel(worldEditUrl.openStream())) { + try (FileOutputStream fos = new FileOutputStream(output)) { + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + } + } + Bukkit.getPluginManager().loadPlugin(output); + } catch (Throwable e) { + e.printStackTrace(); + Fawe.debug("====== INSTALL WORLDEDIT ======"); + Fawe.debug("FAWE requires WorldEdit to function correctly"); + Fawe.debug("Info: https://github.com/boy0001/FastAsyncWorldedit/releases/"); + Fawe.debug("==============================="); + return; + } + } FaweBukkit imp = new FaweBukkit(this); } } \ No newline at end of file diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index 8880de75..034c828b 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -36,13 +36,9 @@ import com.sk89q.worldedit.bukkit.EditSessionBlockChangeDelegate; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.world.World; import java.io.File; -import java.io.FileOutputStream; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.net.URL; -import java.nio.channels.Channels; -import java.nio.channels.ReadableByteChannel; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -112,25 +108,6 @@ public class FaweBukkit implements IFawe, Listener { } public void setupInjector() { - if (Bukkit.getPluginManager().getPlugin("WorldEdit") == null) { - try { - File output = new File(getDirectory().getParentFile(), "WorldEdit.jar"); - URL worldEditUrl = new URL("http://builds.enginehub.org/job/worldedit/9819/download/worldedit-bukkit-6.1.8-SNAPSHOT-dist.jar"); - try (ReadableByteChannel rbc = Channels.newChannel(worldEditUrl.openStream())) { - try (FileOutputStream fos = new FileOutputStream(output)) { - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - } - } - Bukkit.getPluginManager().loadPlugin(output); - } catch (Throwable e) { - e.printStackTrace(); - Fawe.debug("====== INSTALL WORLDEDIT ======"); - Fawe.debug("FAWE requires WorldEdit to function correctly"); - Fawe.debug("Info: https://github.com/boy0001/FastAsyncWorldedit/releases/"); - Fawe.debug("==============================="); - return; - } - } Fawe.setupInjector(); // Inject EditSessionBlockChangeDelegate.inject(); diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java index 7897ffe8..c7258cde 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java @@ -176,6 +176,7 @@ public abstract class BukkitQueue_0 extends NMSMa } } } catch (Throwable e) { + setupAdapter = false; Fawe.debug("====== NO NATIVE WORLDEDIT ADAPTER ======"); e.printStackTrace(); Fawe.debug("Try updating WorldEdit: "); diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_12/BukkitChunk_1_12.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_12/BukkitChunk_1_12.java index 0bb45690..0436c7dd 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_12/BukkitChunk_1_12.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_12/BukkitChunk_1_12.java @@ -78,7 +78,7 @@ public class BukkitChunk_1_12 extends CharFaweChunk { } public boolean storeEntity(Entity ent) throws InvocationTargetException, IllegalAccessException { - if (ent instanceof EntityPlayer) { + if (ent instanceof EntityPlayer || BukkitQueue_0.adapter == null) { return false; } int x = ((int) Math.round(ent.locX) & 15); @@ -90,7 +90,7 @@ public class BukkitChunk_1_12 extends CharFaweChunk { if (id != null) { NBTTagCompound tag = new NBTTagCompound(); ent.save(tag); // readEntityIntoTag - CompoundTag nativeTag = (CompoundTag) getParent().methodToNative.invoke(getParent().adapter, tag); + CompoundTag nativeTag = (CompoundTag) BukkitQueue_0.methodToNative.invoke(getParent().adapter, tag); Map map = ReflectionUtils.getMap(nativeTag.getValue()); map.put("Id", new StringTag(id)); setEntity(nativeTag); diff --git a/core/src/main/java/com/boydti/fawe/Fawe.java b/core/src/main/java/com/boydti/fawe/Fawe.java index 9eb4f26a..ce8505ca 100644 --- a/core/src/main/java/com/boydti/fawe/Fawe.java +++ b/core/src/main/java/com/boydti/fawe/Fawe.java @@ -143,6 +143,7 @@ import java.lang.management.MemoryUsage; import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Objects; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; @@ -419,8 +420,8 @@ public class Fawe { } public void setupConfigs() { - MainUtil.copyFile(MainUtil.getJarFile(), "de/messages.yml", null); - MainUtil.copyFile(MainUtil.getJarFile(), "ru/messages.yml", null); + MainUtil.copyFile(MainUtil.getJarFile(), "de/message.yml", null); + MainUtil.copyFile(MainUtil.getJarFile(), "ru/message.yml", null); MainUtil.copyFile(MainUtil.getJarFile(), "ru/commands.yml", null); // Setting up config.yml File file = new File(this.IMP.getDirectory(), "config.yml"); @@ -437,9 +438,11 @@ public class Fawe { } catch (Throwable ignore) {} Settings.IMP.reload(file); // Setting up message.yml - BBC.load(new File(this.IMP.getDirectory(), "message.yml")); + String lang = Objects.toString(Settings.IMP.LANGUAGE); + BBC.load(new File(this.IMP.getDirectory(), (lang.isEmpty() ? "" : lang + File.separator) + "message.yml")); } + public WorldEdit getWorldEdit() { return WorldEdit.getInstance(); } diff --git a/core/src/main/resources/de/messages.yml b/core/src/main/resources/de/message.yml similarity index 100% rename from core/src/main/resources/de/messages.yml rename to core/src/main/resources/de/message.yml diff --git a/favs/src/main/java/com/boydti/fawe/bukkit/favs/Favs.java b/favs/src/main/java/com/boydti/fawe/bukkit/favs/Favs.java index 6a8e2681..2283817b 100644 --- a/favs/src/main/java/com/boydti/fawe/bukkit/favs/Favs.java +++ b/favs/src/main/java/com/boydti/fawe/bukkit/favs/Favs.java @@ -4,6 +4,7 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.bukkit.BukkitCommand; import com.boydti.fawe.object.FaweCommand; import com.boydti.fawe.object.FawePlayer; +import com.boydti.fawe.util.MainUtil; import com.thevoxelbox.voxelsniper.RangeBlockHelper; import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.Sniper; @@ -21,16 +22,30 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; public class Favs extends JavaPlugin { + @Override public void onEnable() { try { if (Bukkit.getPluginManager().getPlugin("VoxelSniper") == null) { try { - File output = new File(this.getDataFolder().getParentFile(), "VoxelSniper.jar"); - URL worldEditUrl = new URL("https://addons-origin.cursecdn.com/files/912/511/VoxelSniper-5.171.0-SNAPSHOT.jar"); - try (ReadableByteChannel rbc = Channels.newChannel(worldEditUrl.openStream())) { - try (FileOutputStream fos = new FileOutputStream(output)) { - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + File thisFile = MainUtil.getJarFile(); + String thisName = thisFile.getName().toLowerCase(); + File output = null; + for (File file : getDataFolder().getParentFile().listFiles()) { + String name = file.getName().toLowerCase(); + if (name.endsWith(".jar") && name.contains("voxelsniper") && !name.contains("fastasyncvoxelsniper")) { + output = file; + System.out.println("File " + file + " | " + thisName); + break; + } + } + if (output == null) { + output = new File(this.getDataFolder().getParentFile(), "VoxelSniper.jar"); + URL worldEditUrl = new URL("https://addons-origin.cursecdn.com/files/912/511/VoxelSniper-5.171.0-SNAPSHOT.jar"); + try (ReadableByteChannel rbc = Channels.newChannel(worldEditUrl.openStream())) { + try (FileOutputStream fos = new FileOutputStream(output)) { + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + } } } Bukkit.getPluginManager().loadPlugin(output); diff --git a/favs/src/main/java/com/boydti/fawe/bukkit/favs/PatternUtil.java b/favs/src/main/java/com/boydti/fawe/bukkit/favs/PatternUtil.java new file mode 100644 index 00000000..81d4e6f9 --- /dev/null +++ b/favs/src/main/java/com/boydti/fawe/bukkit/favs/PatternUtil.java @@ -0,0 +1,30 @@ +package com.boydti.fawe.bukkit.favs; + +import com.boydti.fawe.config.BBC; +import com.boydti.fawe.object.FawePlayer; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.input.InputParseException; +import com.sk89q.worldedit.extension.input.ParserContext; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.thevoxelbox.voxelsniper.SnipeData; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +public class PatternUtil { + public static Pattern parsePattern(Player player, SnipeData snipeData, String arg) { + ParserContext context = new ParserContext(); + FawePlayer fp = FawePlayer.wrap(player); + context.setActor(fp.getPlayer()); + context.setWorld(fp.getWorld()); + context.setSession(fp.getSession()); + try { + Pattern pattern = WorldEdit.getInstance().getPatternFactory().parseFromInput(arg, context); + snipeData.setPattern(pattern, arg); + snipeData.sendMessage(ChatColor.GOLD + "Voxel: " + ChatColor.RED + arg); + return pattern; + } catch (InputParseException e) { + fp.sendMessage(BBC.getPrefix() + e.getMessage()); + return null; + } + } +} diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelVoxelCommand.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelVoxelCommand.java index 86e157c4..0ed7642b 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelVoxelCommand.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/command/VoxelVoxelCommand.java @@ -5,19 +5,12 @@ package com.thevoxelbox.voxelsniper.command; -import com.boydti.fawe.config.BBC; -import com.boydti.fawe.object.FawePlayer; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.extension.input.InputParseException; -import com.sk89q.worldedit.extension.input.ParserContext; -import com.sk89q.worldedit.function.pattern.Pattern; +import com.boydti.fawe.bukkit.favs.PatternUtil; import com.thevoxelbox.voxelsniper.RangeBlockHelper; import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.Sniper; import com.thevoxelbox.voxelsniper.VoxelSniper; import com.thevoxelbox.voxelsniper.api.command.VoxelCommand; -import com.thevoxelbox.voxelsniper.brush.perform.PerformBrush; -import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -59,18 +52,7 @@ public class VoxelVoxelCommand extends VoxelCommand { return true; } } else { - ParserContext context = new ParserContext(); - FawePlayer fp = FawePlayer.wrap(player); - context.setActor(fp.getPlayer()); - context.setWorld(fp.getWorld()); - context.setSession(fp.getSession()); - try { - Pattern pattern = WorldEdit.getInstance().getPatternFactory().parseFromInput(args[0], context); - snipeData.setPattern(pattern, args[0]); - snipeData.sendMessage(ChatColor.GOLD + "Voxel: " + ChatColor.RED + args[0]); - } catch (InputParseException e) { - fp.sendMessage(BBC.getPrefix() + e.getMessage()); - } + PatternUtil.parsePattern(player, snipeData, args[0]); return true; } }