From addb99a1f20d31c55a1bfa35916eac7dca682992 Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 28 Jan 2016 21:20:28 -0200 Subject: [PATCH] Few changes, WorldEdit Change Event should now be cancellable. --- src/me/TheBukor/SkStuff/SkStuff.java | 10 ++++----- .../SkStuff/events/EvtWorldEditChange.java | 22 ++++++++++++++----- .../SkStuff/expressions/ExprFileNBT.java | 6 ++--- .../SkStuff/expressions/ExprItemNBT.java | 6 ++--- .../SkStuff/expressions/ExprNBTOf.java | 10 ++++----- .../SkStuff/util/ReflectionUtils.java | 5 +++-- 6 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/me/TheBukor/SkStuff/SkStuff.java b/src/me/TheBukor/SkStuff/SkStuff.java index 43e5b3e..a245baf 100644 --- a/src/me/TheBukor/SkStuff/SkStuff.java +++ b/src/me/TheBukor/SkStuff/SkStuff.java @@ -5,12 +5,12 @@ import java.lang.reflect.InvocationTargetException; import javax.annotation.Nullable; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; +import org.fusesource.jansi.Ansi; import com.sk89q.worldedit.EditSession; @@ -65,7 +65,7 @@ import me.TheBukor.SkStuff.util.ReflectionUtils; public class SkStuff extends JavaPlugin { private int condAmount = 0; private int effAmount = 0; - private boolean evtWE = false; + private int evtAmount = 0; private int exprAmount = 0; private int typeAmount = 0; @@ -116,7 +116,7 @@ public class SkStuff extends JavaPlugin { NBT1 = nbtParserClass.getMethod("parse", String.class).invoke(NBT1, newTags); } catch (Exception ex) { if (ex instanceof InvocationTargetException && ex.getCause().getClass().getName().contains("MojangsonParseException")) { - Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage()); + getLogger().warning(Ansi.ansi().fgBright(Ansi.Color.RED) + "Error when parsing NBT - " + ex.getCause().getMessage() + Ansi.ansi().fgBright(Ansi.Color.DEFAULT)); return; } ex.printStackTrace(); @@ -214,7 +214,7 @@ public class SkStuff extends JavaPlugin { return EvtWorldEditChange.getBlock(); } }, 0); - evtWE = true; + evtAmount += 1; } catch (ClassNotFoundException ex) { Skript.error("Unable to register \"On WorldEdit block change\" event! You will need to upgrade to WorldEdit 6.0"); return; @@ -231,7 +231,7 @@ public class SkStuff extends JavaPlugin { effAmount += 1; exprAmount += 1; } - getLogger().info("Everything ready! Loaded a total of " + condAmount + (condAmount == 1 ? " condition, " : " conditions, ") + effAmount + (effAmount == 1 ? " effect, " : " effects, ") + (evtWE ? "1 event, " : "") + exprAmount + (exprAmount == 1 ? " expression" : " expressions and ") + typeAmount + (typeAmount == 1 ? " type!" : " types!")); + getLogger().info("Everything ready! Loaded a total of " + condAmount + " conditions, " + effAmount + " effects, " + evtAmount + "events, " + exprAmount + " expressions and " + typeAmount + " types!"); } else { getLogger().info("Unable to find Skript or Skript isn't accepting registrations, disabling SkStuff..."); Bukkit.getPluginManager().disablePlugin(this);; diff --git a/src/me/TheBukor/SkStuff/events/EvtWorldEditChange.java b/src/me/TheBukor/SkStuff/events/EvtWorldEditChange.java index 02f04e7..b1fca1e 100644 --- a/src/me/TheBukor/SkStuff/events/EvtWorldEditChange.java +++ b/src/me/TheBukor/SkStuff/events/EvtWorldEditChange.java @@ -2,16 +2,20 @@ package me.TheBukor.SkStuff.events; import org.bukkit.block.Block; import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -public class EvtWorldEditChange extends Event { - static Player player; - static Block block; +public class EvtWorldEditChange extends Event implements Cancellable { + private static Player player; + private static Block block; + private boolean cancelled; + private static final HandlerList handlers = new HandlerList(); public EvtWorldEditChange(Player player, Block block) { EvtWorldEditChange.player = player; EvtWorldEditChange.block = block; + this.cancelled = false; } public static Player getPlayer() { @@ -22,8 +26,6 @@ public class EvtWorldEditChange extends Event { return block; } - private static final HandlerList handlers = new HandlerList(); - public HandlerList getHandlers() { return handlers; } @@ -31,4 +33,14 @@ public class EvtWorldEditChange extends Event { public static HandlerList getHandlerList() { return handlers; } + + @Override + public boolean isCancelled() { + return this.cancelled; + } + + @Override + public void setCancelled(boolean bool) { + this.cancelled = bool; + } } \ No newline at end of file diff --git a/src/me/TheBukor/SkStuff/expressions/ExprFileNBT.java b/src/me/TheBukor/SkStuff/expressions/ExprFileNBT.java index cb3d3dc..3705667 100644 --- a/src/me/TheBukor/SkStuff/expressions/ExprFileNBT.java +++ b/src/me/TheBukor/SkStuff/expressions/ExprFileNBT.java @@ -12,10 +12,10 @@ import java.lang.reflect.InvocationTargetException; import javax.annotation.Nullable; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.event.Event; +import org.fusesource.jansi.Ansi; +import ch.njol.skript.Skript; import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; @@ -104,7 +104,7 @@ public class ExprFileNBT extends SimpleExpression { os.close(); } catch (Exception ex) { if (ex instanceof InvocationTargetException && ex.getCause().getClass().getName().contains("MojangsonParseException")) { - Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage()); + Skript.warning(Ansi.ansi().fgBright(Ansi.Color.RED) + "Error when parsing NBT - " + ex.getCause().getMessage() + Ansi.ansi().fgBright(Ansi.Color.DEFAULT)); return; } ex.printStackTrace(); diff --git a/src/me/TheBukor/SkStuff/expressions/ExprItemNBT.java b/src/me/TheBukor/SkStuff/expressions/ExprItemNBT.java index 583ab1e..b5f2f8c 100644 --- a/src/me/TheBukor/SkStuff/expressions/ExprItemNBT.java +++ b/src/me/TheBukor/SkStuff/expressions/ExprItemNBT.java @@ -4,12 +4,12 @@ import java.lang.reflect.InvocationTargetException; import javax.annotation.Nullable; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.event.Event; import org.bukkit.inventory.ItemStack; +import org.fusesource.jansi.Ansi; +import ch.njol.skript.Skript; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; @@ -72,7 +72,7 @@ public class ExprItemNBT extends SimpleExpression { nmsItem.getClass().getMethod("setTag", nbtClass).invoke(nmsItem, NBT); } catch (Exception ex) { if (ex instanceof InvocationTargetException && ex.getCause().getClass().getName().contains("MojangsonParseException")) { - Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage()); + Skript.warning(Ansi.ansi().fgBright(Ansi.Color.RED) + "Error when parsing NBT - " + ex.getCause().getMessage() + Ansi.ansi().fgBright(Ansi.Color.DEFAULT)); return null; } ex.printStackTrace(); diff --git a/src/me/TheBukor/SkStuff/expressions/ExprNBTOf.java b/src/me/TheBukor/SkStuff/expressions/ExprNBTOf.java index 4c026f9..785babc 100644 --- a/src/me/TheBukor/SkStuff/expressions/ExprNBTOf.java +++ b/src/me/TheBukor/SkStuff/expressions/ExprNBTOf.java @@ -4,14 +4,14 @@ import java.lang.reflect.InvocationTargetException; import javax.annotation.Nullable; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.event.Event; import org.bukkit.inventory.ItemStack; +import org.fusesource.jansi.Ansi; +import ch.njol.skript.Skript; import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; @@ -141,7 +141,7 @@ public class ExprNBTOf extends SimpleExpression { nmsEnt.getClass().getMethod("f", nbtClass).invoke(nmsEnt, NBT); } catch (Exception ex) { if (ex instanceof InvocationTargetException && ex.getCause().getClass().getName().contains("MojangsonParseException")) { - Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage()); + Skript.warning(Ansi.ansi().fgBright(Ansi.Color.RED) + "Error when parsing NBT - " + ex.getCause().getMessage() + Ansi.ansi().fgBright(Ansi.Color.DEFAULT)); return; } ex.printStackTrace(); @@ -193,7 +193,7 @@ public class ExprNBTOf extends SimpleExpression { nmsWorld.getClass().getMethod("notify", nmsPosClass).invoke(nmsWorld, tileEntity.getClass().getMethod("getPosition").invoke(tileEntity)); } catch (Exception ex) { if (ex instanceof InvocationTargetException && ex.getCause().getClass().getName().contains("MojangsonParseException")) { - Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage()); + Skript.warning(Ansi.ansi().fgBright(Ansi.Color.RED) + "Error when parsing NBT - " + ex.getCause().getMessage() + Ansi.ansi().fgBright(Ansi.Color.DEFAULT)); return; } ex.printStackTrace(); @@ -253,7 +253,7 @@ public class ExprNBTOf extends SimpleExpression { ((Slot) slot[0]).setItem((ItemStack) newItem); } catch (Exception ex) { if (ex instanceof InvocationTargetException && ex.getCause().getClass().getName().contains("MojangsonParseException")) { - Bukkit.getConsoleSender().sendMessage("[SkStuff] " + ChatColor.RED + "Error when parsing NBT - " + ex.getCause().getMessage()); + Skript.warning(Ansi.ansi().fgBright(Ansi.Color.RED) + "Error when parsing NBT - " + ex.getCause().getMessage() + Ansi.ansi().fgBright(Ansi.Color.DEFAULT)); return; } ex.printStackTrace(); diff --git a/src/me/TheBukor/SkStuff/util/ReflectionUtils.java b/src/me/TheBukor/SkStuff/util/ReflectionUtils.java index 6d5deaf..fd371cb 100644 --- a/src/me/TheBukor/SkStuff/util/ReflectionUtils.java +++ b/src/me/TheBukor/SkStuff/util/ReflectionUtils.java @@ -1,6 +1,7 @@ package me.TheBukor.SkStuff.util; import org.bukkit.Bukkit; +import org.fusesource.jansi.Ansi; public class ReflectionUtils { @@ -11,7 +12,7 @@ public class ReflectionUtils { try { nmsClass = Class.forName(name); } catch (ClassNotFoundException ex) { - Bukkit.getLogger().warning("Unable to get NMS class! You are probably running an unsupported version"); + Bukkit.getLogger().warning(Ansi.ansi().fgBright(Ansi.Color.RED) + "Unable to get NMS class! You are probably running an unsupported version!" + Ansi.ansi().fgBright(Ansi.Color.DEFAULT)); return null; } return nmsClass; @@ -24,7 +25,7 @@ public class ReflectionUtils { try { obcClass = Class.forName(name); } catch (ClassNotFoundException ex) { - Bukkit.getLogger().warning("Unable to get OBC class! You are probably running an unsupported version"); + Bukkit.getLogger().warning(Ansi.ansi().fgBright(Ansi.Color.RED) + "Unable to get OBC class! You are probably running an unsupported version!" + Ansi.ansi().fgBright(Ansi.Color.DEFAULT)); return null; } return obcClass;