From d4152a08121d819d925b2130ff9e43a2bfe90d97 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 14 Aug 2013 06:29:31 +0300 Subject: [PATCH] Replace all tabs in Denizen with spaces. Rename Move back into Shoot after talking to aufdemrand about it. Remove some unused imports. --- .../aufdemrand/denizen/CommandHandler.java | 120 +- .../java/net/aufdemrand/denizen/Denizen.java | 2 +- .../java/net/aufdemrand/denizen/Settings.java | 250 ++-- .../denizen/events/ExhaustedNPCEvent.java | 2 +- .../events/ScriptEntryExecuteEvent.java | 24 +- .../denizen/events/ScriptFailEvent.java | 90 +- .../denizen/events/ScriptFinishEvent.java | 86 +- .../exceptions/CommandExecutionException.java | 24 +- .../exceptions/InvalidArgumentsException.java | 24 +- .../exceptions/RequirementCheckException.java | 24 +- .../ScriptEntryCreationException.java | 24 +- .../aufdemrand/denizen/flags/FlagManager.java | 4 +- .../denizen/listeners/AbstractListener.java | 284 ++-- .../listeners/AbstractListenerType.java | 98 +- .../denizen/listeners/ListenerRegistry.java | 152 +- .../listeners/core/BlockListenerInstance.java | 416 +++--- .../listeners/core/BlockListenerType.java | 12 +- .../core/ItemDropListenerInstance.java | 456 +++--- .../listeners/core/ItemDropListenerType.java | 16 +- .../listeners/core/ItemListenerInstance.java | 376 ++--- .../listeners/core/ItemListenerType.java | 12 +- .../listeners/core/KillListenerType.java | 8 +- .../core/TravelListenerInstance.java | 6 +- .../listeners/core/TravelListenerType.java | 10 +- .../denizen/npc/traits/AssignmentTrait.java | 2 +- .../denizen/npc/traits/CreatorTrait.java | 40 +- .../denizen/npc/traits/FishingTrait.java | 196 +-- .../denizen/npc/traits/HealthTrait.java | 2 +- .../denizen/npc/traits/InvisibleTrait.java | 2 +- .../denizen/npc/traits/NameplateTrait.java | 249 ++-- .../denizen/npc/traits/NicknameTrait.java | 50 +- .../denizen/npc/traits/ParticlesTrait.java | 338 ++--- .../denizen/npc/traits/SittingTrait.java | 188 +-- .../denizen/npc/traits/SleepingTrait.java | 180 +-- .../denizen/npc/traits/SneakingTrait.java | 94 +- .../denizen/npc/traits/TriggerTrait.java | 2 +- .../net/aufdemrand/denizen/objects/aH.java | 30 +- .../aufdemrand/denizen/objects/dColor.java | 138 +- .../aufdemrand/denizen/objects/dEntity.java | 78 +- .../denizen/objects/dInventory.java | 428 +++--- .../net/aufdemrand/denizen/objects/dItem.java | 196 +-- .../net/aufdemrand/denizen/objects/dList.java | 104 +- .../aufdemrand/denizen/objects/dLocation.java | 118 +- .../aufdemrand/denizen/objects/dMaterial.java | 138 +- .../net/aufdemrand/denizen/objects/dNPC.java | 2 +- .../aufdemrand/denizen/objects/dScript.java | 6 +- .../aufdemrand/denizen/objects/dWorld.java | 12 +- .../denizen/scripts/ScriptHelper.java | 3 +- .../scripts/commands/AbstractCommand.java | 200 +-- .../scripts/commands/CommandExecuter.java | 22 +- .../scripts/commands/CommandRegistry.java | 266 ++-- .../commands/core/CooldownCommand.java | 16 +- .../scripts/commands/core/FailCommand.java | 126 +- .../scripts/commands/core/FinishCommand.java | 60 +- .../scripts/commands/core/IfCommand.java | 16 +- .../scripts/commands/core/QueueCommand.java | 2 +- .../scripts/commands/core/RandomCommand.java | 148 +- .../scripts/commands/core/RuntaskCommand.java | 2 +- .../commands/core/_templateCommand.java | 64 +- .../commands/entity/AnimateCommand.java | 93 +- .../commands/entity/AttackCommand.java | 92 +- .../scripts/commands/entity/BurnCommand.java | 32 +- .../scripts/commands/entity/CastCommand.java | 49 +- .../scripts/commands/entity/FlyCommand.java | 258 ++-- .../scripts/commands/entity/HeadCommand.java | 56 +- .../scripts/commands/entity/HealCommand.java | 43 +- .../commands/entity/HealthCommand.java | 12 +- .../scripts/commands/entity/HurtCommand.java | 6 +- .../commands/entity/InvisibleCommand.java | 50 +- .../scripts/commands/entity/LookCommand.java | 152 +- .../scripts/commands/entity/MountCommand.java | 90 +- .../scripts/commands/entity/MoveCommand.java | 243 ---- .../commands/entity/NameplateCommand.java | 22 +- .../commands/entity/RemoveCommand.java | 161 +-- .../scripts/commands/entity/ShootCommand.java | 228 +-- .../scripts/commands/entity/SpawnCommand.java | 87 +- .../commands/entity/TeleportCommand.java | 59 +- .../scripts/commands/item/EnchantCommand.java | 20 +- .../scripts/commands/item/EquipCommand.java | 210 +-- .../scripts/commands/item/GiveCommand.java | 2 +- .../commands/item/InventoryCommand.java | 204 +-- .../scripts/commands/item/ScribeCommand.java | 12 +- .../scripts/commands/item/TakeCommand.java | 4 +- .../scripts/commands/npc/AnchorCommand.java | 8 +- .../scripts/commands/npc/EngageCommand.java | 34 +- .../scripts/commands/npc/FishCommand.java | 116 +- .../commands/npc/LookcloseCommand.java | 74 +- .../scripts/commands/npc/PauseCommand.java | 156 +- .../scripts/commands/npc/PoseCommand.java | 31 +- .../scripts/commands/npc/SitCommand.java | 86 +- .../scripts/commands/npc/StandCommand.java | 60 +- .../scripts/commands/npc/TriggerCommand.java | 40 +- .../commands/player/CompassCommand.java | 12 +- .../commands/player/ExperienceCommand.java | 18 +- .../scripts/commands/player/GroupCommand.java | 8 +- .../commands/player/ListenCommand.java | 60 +- .../commands/player/NarrateCommand.java | 8 +- .../commands/player/PermissionCommand.java | 18 +- .../commands/server/AnnounceCommand.java | 10 +- .../commands/server/ExecuteCommand.java | 82 +- .../commands/world/AnimateChestCommand.java | 110 +- .../commands/world/CopyBlockCommand.java | 20 +- .../commands/world/FireworkCommand.java | 86 +- .../scripts/commands/world/MidiCommand.java | 100 +- .../commands/world/ModifyBlockCommand.java | 220 +-- .../commands/world/PlayEffectCommand.java | 90 +- .../commands/world/PlaySoundCommand.java | 68 +- .../scripts/commands/world/SignCommand.java | 48 +- .../scripts/commands/world/StrikeCommand.java | 18 +- .../scripts/commands/world/SwitchCommand.java | 70 +- .../scripts/commands/world/TimeCommand.java | 20 +- .../scripts/commands/world/ViewerCommand.java | 300 ++-- .../commands/world/WeatherCommand.java | 77 +- .../containers/core/BookScriptContainer.java | 12 +- .../containers/core/ItemScriptContainer.java | 78 +- .../containers/core/ItemScriptHelper.java | 174 +-- .../containers/core/TaskScriptContainer.java | 18 +- .../containers/core/WorldScriptHelper.java | 1266 ++++++++--------- .../requirements/AbstractRequirement.java | 92 +- .../requirements/RequirementChecker.java | 2 +- .../requirements/RequirementRegistry.java | 64 +- .../core/EnchantedRequirement.java | 52 +- .../requirements/core/FlaggedRequirement.java | 64 +- .../requirements/core/HoldingRequirement.java | 46 +- .../requirements/core/InGroupRequirement.java | 104 +- .../requirements/core/ItemRequirement.java | 24 +- .../requirements/core/LiquidRequirement.java | 44 +- .../requirements/core/MoneyRequirement.java | 48 +- .../requirements/core/OpRequirement.java | 8 +- .../requirements/core/OwnerRequirement.java | 4 +- .../requirements/core/OxygenRequirement.java | 4 +- .../core/PermissionRequirement.java | 94 +- .../requirements/core/PoweredRequirement.java | 38 +- .../core/ProcedureRequirement.java | 2 +- .../requirements/core/RainyRequirement.java | 10 +- .../core/SneakingRequirement.java | 14 +- .../requirements/core/StormRequirement.java | 6 +- .../requirements/core/SunnyRequirement.java | 2 +- .../requirements/core/TimeRequirement.java | 50 +- .../core/WorldGuardRegionRequirement.java | 84 +- .../scripts/triggers/AbstractTrigger.java | 68 +- .../scripts/triggers/core/ChatTrigger.java | 5 +- .../triggers/core/ProximityTrigger.java | 4 +- .../denizen/tags/core/AnchorTags.java | 38 +- .../denizen/tags/core/ConstantTags.java | 28 +- .../denizen/tags/core/ContextTags.java | 3 +- .../denizen/tags/core/FlagTags.java | 10 +- .../denizen/tags/core/LocationTags.java | 4 +- .../tags/core/NotableLocationTags.java | 18 +- .../tags/core/SpecialCharacterTags.java | 4 +- .../denizen/tags/core/UtilTags.java | 28 +- .../denizen/tags/core/_templateTag.java | 20 +- .../denizen/utilities/Conversion.java | 18 +- .../denizen/utilities/DenizenAPI.java | 6 +- .../denizen/utilities/ParticleEffect.java | 22 +- .../denizen/utilities/RuntimeCompiler.java | 6 +- .../denizen/utilities/ScriptRepo.java | 192 +-- .../denizen/utilities/Utilities.java | 90 +- .../denizen/utilities/debugging/dB.java | 370 ++--- .../denizen/utilities/depends/Depends.java | 28 +- .../depends/WorldGuardUtilities.java | 138 +- .../denizen/utilities/entity/Position.java | 64 +- .../denizen/utilities/entity/Rotation.java | 36 +- .../inventory/InventoryMenuItem.java | 2 +- .../javaluator/AbstractEvaluator.java | 750 +++++----- .../javaluator/AbstractVariableSet.java | 10 +- .../utilities/javaluator/BracketPair.java | 72 +- .../utilities/javaluator/Constant.java | 30 +- .../utilities/javaluator/DoubleEvaluator.java | 508 +++---- .../utilities/javaluator/Function.java | 90 +- .../utilities/javaluator/Operator.java | 184 +-- .../utilities/javaluator/Parameters.java | 322 ++--- .../javaluator/StaticVariableSet.java | 40 +- .../denizen/utilities/javaluator/Token.java | 224 +-- .../utilities/javaluator/Tokenizer.java | 182 +-- .../denizen/utilities/midi/MidiUtil.java | 174 +-- .../utilities/midi/NoteBlockReceiver.java | 162 +-- .../denizen/utilities/midi/ToneUtil.java | 44 +- .../utilities/nbt/MapOfEnchantments.java | 58 +- .../utilities/packets/PacketHelper.java | 24 +- .../packets/handler/NameplateHandler.java | 114 +- 181 files changed, 8300 insertions(+), 8565 deletions(-) delete mode 100644 src/main/java/net/aufdemrand/denizen/scripts/commands/entity/MoveCommand.java diff --git a/src/main/java/net/aufdemrand/denizen/CommandHandler.java b/src/main/java/net/aufdemrand/denizen/CommandHandler.java index 53c5242e21..def237ab30 100644 --- a/src/main/java/net/aufdemrand/denizen/CommandHandler.java +++ b/src/main/java/net/aufdemrand/denizen/CommandHandler.java @@ -202,16 +202,16 @@ public void assignment(CommandContext args, CommandSender sender, NPC npc) throw AssignmentTrait trait = npc.getTrait(AssignmentTrait.class); if (args.hasValueFlag("set")) { - String script = args.getFlag("set").replace("\"", ""); - + String script = args.getFlag("set").replace("\"", ""); + if (trait.setAssignment(script, dPlayer.mirrorBukkitPlayer(player))) if (trait.hasAssignment()) Messaging.send(sender, ChatColor.YELLOW + npc.getName() + "'s assignment is now: '" + trait.getAssignment().getName() + "'."); else Messaging.send(sender, ChatColor.YELLOW + npc.getName() + "'s assignment was not able to be set."); else if (ScriptRegistry.containsScript(script)) - Messaging.send(sender, ChatColor.RED + "A script with that name exists, but it is not an assignment script!"); + Messaging.send(sender, ChatColor.RED + "A script with that name exists, but it is not an assignment script!"); else - Messaging.send(sender, ChatColor.RED + "Invalid assignment! Has the script sucessfully loaded, or has it been mispelled?"); + Messaging.send(sender, ChatColor.RED + "Invalid assignment! Has the script sucessfully loaded, or has it been mispelled?"); return; } else if (args.hasFlag('r')) { @@ -353,12 +353,12 @@ public void nameplate(CommandContext args, CommandSender sender, NPC npc) throws min = 1, max = 3, permission = "npc.sit") @Requirements(selected = true, ownership = true) public void sitting(CommandContext args, CommandSender sender, NPC npc) throws CommandException { - if (npc.getBukkitEntity().getType() != EntityType.PLAYER) { - Messaging.send(sender, ChatColor.RED + npc.getName() + " needs to be a Player type NPC to sit!"); - return; - } - - if (!npc.hasTrait(SittingTrait.class)) npc.addTrait(SittingTrait.class); + if (npc.getBukkitEntity().getType() != EntityType.PLAYER) { + Messaging.send(sender, ChatColor.RED + npc.getName() + " needs to be a Player type NPC to sit!"); + return; + } + + if (!npc.hasTrait(SittingTrait.class)) npc.addTrait(SittingTrait.class); SittingTrait trait = npc.getTrait(SittingTrait.class); if (trait.isSitting()) { @@ -366,7 +366,7 @@ public void sitting(CommandContext args, CommandSender sender, NPC npc) throws C return; } if (args.hasFlag('c')) { - trait.sit(args.getSenderTargetBlockLocation()); + trait.sit(args.getSenderTargetBlockLocation()); } else if (args.hasValueFlag("location")) { String[] argsArray = args.getFlag("location").split(","); if (argsArray.length != 4) { @@ -396,33 +396,33 @@ public void sitting(CommandContext args, CommandSender sender, NPC npc) throws C @Requirements(selected = true, ownership = true) public void standing(CommandContext args, CommandSender sender, NPC npc) throws CommandException { - if (npc.hasTrait(SittingTrait.class)) { - SittingTrait trait = npc.getTrait(SittingTrait.class); - if (!trait.isSitting()) { + if (npc.hasTrait(SittingTrait.class)) { + SittingTrait trait = npc.getTrait(SittingTrait.class); + if (!trait.isSitting()) { npc.removeTrait(SittingTrait.class); Messaging.send(sender, ChatColor.RED + npc.getName() + " is already standing!"); return; } - trait.stand(); + trait.stand(); npc.removeTrait(SittingTrait.class); - } else if (npc.hasTrait(SneakingTrait.class)) { - SneakingTrait trait = npc.getTrait(SneakingTrait.class); - if (!trait.isSneaking()) { + } else if (npc.hasTrait(SneakingTrait.class)) { + SneakingTrait trait = npc.getTrait(SneakingTrait.class); + if (!trait.isSneaking()) { npc.removeTrait(SittingTrait.class); Messaging.send(sender, ChatColor.RED + npc.getName() + " is already standing!"); return; } - trait.stand(); + trait.stand(); npc.removeTrait(SneakingTrait.class); - } + } } /* - * Sleep - */ + * Sleep + */ @Command( aliases = { "npc" }, usage = "sleep (--location x,y,z,world) (--anchor anchor_name)", desc = "Makes the NPC sleep.", modifiers = { "sleep" }, @@ -479,8 +479,8 @@ public void wakingup(CommandContext args, CommandSender sender, NPC npc) throws } /* - * Fish - */ + * Fish + */ @Command( aliases = { "npc" }, usage = "fish (--location x,y,z,world) (--anchor anchor_name) (-c)", desc = "Makes the NPC fish, casting at the given location.", flags = "c, f", modifiers = { "fish" }, @@ -496,15 +496,15 @@ public void startFishing(CommandContext args, CommandSender sender, NPC npc) thr } if (args.hasFlag('c')) { - trait.startFishing(args.getSenderTargetBlockLocation()); + trait.startFishing(args.getSenderTargetBlockLocation()); } if (args.hasFlag('f')) { - trait.setCatchFish(true); + trait.setCatchFish(true); } if (args.hasValueFlag("percent")) { - trait.setCatchPercent(args.getFlagInteger("percent")); + trait.setCatchPercent(args.getFlagInteger("percent")); } if (args.hasValueFlag("location")) { @@ -559,37 +559,37 @@ public void stopFishing(CommandContext args, CommandSender sender, NPC npc) thro public void playEffect(CommandContext args, CommandSender sender, NPC npc) throws CommandException { if (!npc.hasTrait(ParticlesTrait.class)) npc.addTrait(ParticlesTrait.class); ParticlesTrait trait = npc.getTrait(ParticlesTrait.class); - + if (args.hasValueFlag("delay")) { - trait.setWait(args.getFlagInteger("delay")); + trait.setWait(args.getFlagInteger("delay")); } if (args.hasFlag('d')) { - trait.setDense(true); + trait.setDense(true); } - if (args.hasValueFlag("play")) { - String name = args.getFlag("play"); - if (!npc.hasTrait(ParticlesTrait.class)) npc.addTrait(ParticlesTrait.class); - - if (name.equalsIgnoreCase("none")) { - trait.setEffect("NONE"); - } else if (name.equalsIgnoreCase("flame")) { - trait.setEffect("FLAME"); - } else if (name.equalsIgnoreCase("ender")) { - trait.setEffect("ENDER"); - } else if (name.equalsIgnoreCase("smoke")) { - trait.setEffect("SMOKE"); - } else if (name.equalsIgnoreCase("potbreak")) { - trait.setEffect("POTBREAK"); - } else if (name.equalsIgnoreCase("potion")) { - trait.setEffect("POTION"); - } else if (name.equalsIgnoreCase("heart")) { - trait.setEffect("HEART"); - } else if (name.equalsIgnoreCase("explosion")) { - trait.setEffect("EXPLOSION"); - } else Messaging.send(sender, ChatColor.RED + "Not a valid effect name!"); - + if (args.hasValueFlag("play")) { + String name = args.getFlag("play"); + if (!npc.hasTrait(ParticlesTrait.class)) npc.addTrait(ParticlesTrait.class); + + if (name.equalsIgnoreCase("none")) { + trait.setEffect("NONE"); + } else if (name.equalsIgnoreCase("flame")) { + trait.setEffect("FLAME"); + } else if (name.equalsIgnoreCase("ender")) { + trait.setEffect("ENDER"); + } else if (name.equalsIgnoreCase("smoke")) { + trait.setEffect("SMOKE"); + } else if (name.equalsIgnoreCase("potbreak")) { + trait.setEffect("POTBREAK"); + } else if (name.equalsIgnoreCase("potion")) { + trait.setEffect("POTION"); + } else if (name.equalsIgnoreCase("heart")) { + trait.setEffect("HEART"); + } else if (name.equalsIgnoreCase("explosion")) { + trait.setEffect("EXPLOSION"); + } else Messaging.send(sender, ChatColor.RED + "Not a valid effect name!"); + } else Messaging.send(sender, ChatColor.RED + "Please specify an effect name!"); } @@ -603,12 +603,12 @@ public void playEffect(CommandContext args, CommandSender sender, NPC npc) throw min = 1, max = 3, permission = "npc.sneak") @Requirements(selected = true, ownership = true) public void sneaking(CommandContext args, CommandSender sender, NPC npc) throws CommandException { - if (npc.getBukkitEntity().getType() != EntityType.PLAYER) { - Messaging.send(sender, ChatColor.RED + npc.getName() + " needs to be a Player type NPC to sneak!"); - return; - } - - if (!npc.hasTrait(SneakingTrait.class)) npc.addTrait(SneakingTrait.class); + if (npc.getBukkitEntity().getType() != EntityType.PLAYER) { + Messaging.send(sender, ChatColor.RED + npc.getName() + " needs to be a Player type NPC to sneak!"); + return; + } + + if (!npc.hasTrait(SneakingTrait.class)) npc.addTrait(SneakingTrait.class); SneakingTrait trait = npc.getTrait(SneakingTrait.class); if (trait.isSneaking()) { @@ -975,7 +975,7 @@ public void text(CommandContext args, CommandSender sender, NPC npc) throws Comm // before that, so it needs to be high min = 2, max = 20, permission = "notable.basic") public void addnotable(CommandContext args, CommandSender sender, NPC npc) throws CommandException { - + new dLocation(((Player) sender).getLocation()).rememberAs(args.getString(1)); Messaging.send(sender, "Created new notable called " + (args.getString(1))); } @@ -986,7 +986,7 @@ public void addnotable(CommandContext args, CommandSender sender, NPC npc) throw min = 1, max = 1, permission = "notable.basic") public void listnotable(CommandContext args, CommandSender sender, NPC npc) throws CommandException { - Messaging.send(sender, dLocation.uniqueObjects.toString()); + Messaging.send(sender, dLocation.uniqueObjects.toString()); } } diff --git a/src/main/java/net/aufdemrand/denizen/Denizen.java b/src/main/java/net/aufdemrand/denizen/Denizen.java index b5b9516817..68574b62a9 100644 --- a/src/main/java/net/aufdemrand/denizen/Denizen.java +++ b/src/main/java/net/aufdemrand/denizen/Denizen.java @@ -124,7 +124,7 @@ public NotableManager notableManager() { public Depends depends = new Depends(); /* - * Sets up Denizen on start of the craftbukkit server. + * Sets up Denizen on start of the craftbukkit server. */ @Override diff --git a/src/main/java/net/aufdemrand/denizen/Settings.java b/src/main/java/net/aufdemrand/denizen/Settings.java index 1e22e91859..89002de661 100644 --- a/src/main/java/net/aufdemrand/denizen/Settings.java +++ b/src/main/java/net/aufdemrand/denizen/Settings.java @@ -5,172 +5,172 @@ public class Settings { - /* - - # Whether Denizen should display debug in the console + /* + + # Whether Denizen should display debug in the console - */ - - public static boolean ShowDebug() { - return DenizenAPI.getCurrentInstance().getConfig() + */ + + public static boolean ShowDebug() { + return DenizenAPI.getCurrentInstance().getConfig() .getBoolean("Debug.Show", false); - } + } public static int ConsoleWidth() { return DenizenAPI.getCurrentInstance().getConfig() .getInt("Debug.Console Width", 60); } - - /* + + /* - # Sets the default speed between execution of commands in queues + # Sets the default speed between execution of commands in queues - */ + */ - public static String ScriptQueueSpeed() { - String delay = DenizenAPI.getCurrentInstance().getConfig() + public static String ScriptQueueSpeed() { + String delay = DenizenAPI.getCurrentInstance().getConfig() .getString("Scripts.Queue Speed", "0.5s"); - - // Check for users setting delay to 0, which will in turn lock up the server - try { if (Double.valueOf(delay) < 1) delay = "1t"; } + + // Check for users setting delay to 0, which will in turn lock up the server + try { if (Double.valueOf(delay) < 1) delay = "1t"; } catch (Exception e) { delay = "0.5s"; } - - return delay; - } - - /* - - # Whether scripts in subfolders of the scripts folder should be loaded - - */ - + + return delay; + } + + /* + + # Whether scripts in subfolders of the scripts folder should be loaded + + */ + public static boolean LoadScriptsInSubfolders() { return DenizenAPI.getCurrentInstance().getConfig() .getBoolean("Scripts.Load Scripts in Subfolders", true); } - - /* - - # Whether the Health trait should be enabled by default + + /* + + # Whether the Health trait should be enabled by default - */ - - public static boolean HealthTraitEnabledByDefault() { - return DenizenAPI.getCurrentInstance().getConfig() + */ + + public static boolean HealthTraitEnabledByDefault() { + return DenizenAPI.getCurrentInstance().getConfig() .getBoolean("Traits.Health.Enabled", false); - } - - /* - - # Whether NPCs with the Health trait should respawn after being killed - - */ - - public static boolean HealthTraitRespawnEnabled() { - return DenizenAPI.getCurrentInstance().getConfig() + } + + /* + + # Whether NPCs with the Health trait should respawn after being killed + + */ + + public static boolean HealthTraitRespawnEnabled() { + return DenizenAPI.getCurrentInstance().getConfig() .getBoolean("Traits.Health.Respawn.Enabled", true); - } - - /* - - # Whether NPCs with the Health trait should have a death animation - - */ - - public static boolean HealthTraitAnimatedDeathEnabled() { - return DenizenAPI.getCurrentInstance().getConfig() + } + + /* + + # Whether NPCs with the Health trait should have a death animation + + */ + + public static boolean HealthTraitAnimatedDeathEnabled() { + return DenizenAPI.getCurrentInstance().getConfig() .getBoolean("Traits.Health.Animated Death.Enabled", true); - } - - /* - - # How long it should take for NPCs with the Health trait to respawn - - */ - - public static String HealthTraitRespawnDelay() { - return DenizenAPI.getCurrentInstance().getConfig() + } + + /* + + # How long it should take for NPCs with the Health trait to respawn + + */ + + public static String HealthTraitRespawnDelay() { + return DenizenAPI.getCurrentInstance().getConfig() .getString("Traits.Health.Respawn.Delay", "10s"); - } - - /* - - # Whether a certain trigger is enabled by default or not + } + + /* + + # Whether a certain trigger is enabled by default or not - */ - - public static boolean TriggerEnabled(String triggerName) { - return DenizenAPI.getCurrentInstance().getConfig() + */ + + public static boolean TriggerEnabled(String triggerName) { + return DenizenAPI.getCurrentInstance().getConfig() .getBoolean("Triggers." + String.valueOf(triggerName.charAt(0)).toUpperCase() + triggerName.substring(1).toLowerCase() + ".Enabled", true); - } - - /* - - # Default duration of cooldown set to Denizens for when a trigger is - # triggered. Not all triggers may use this, it is optional! + } + + /* + + # Default duration of cooldown set to Denizens for when a trigger is + # triggered. Not all triggers may use this, it is optional! - */ - - public static double TriggerDefaultCooldown(String triggerName) { - return Duration.valueOf(DenizenAPI.getCurrentInstance().getConfig() + */ + + public static double TriggerDefaultCooldown(String triggerName) { + return Duration.valueOf(DenizenAPI.getCurrentInstance().getConfig() .getString("Triggers." + String.valueOf(triggerName.charAt(0)).toUpperCase() + triggerName.substring(1).toLowerCase() + ".Cooldown", "5s")).getSeconds(); - } - - /* + } + + /* - # This set of nodes defines ranges for different types of - # interact-script triggers. Not all triggers use a range, - # as it may not be applicable to the trigger. + # This set of nodes defines ranges for different types of + # interact-script triggers. Not all triggers use a range, + # as it may not be applicable to the trigger. - */ + */ - public static double TriggerDefaultRange(String triggerName) { - return DenizenAPI.getCurrentInstance().getConfig() + public static double TriggerDefaultRange(String triggerName) { + return DenizenAPI.getCurrentInstance().getConfig() .getDouble("Triggers." + String.valueOf(triggerName.charAt(0)).toUpperCase() + triggerName.substring(1).toLowerCase() + ".Range", -1); - } + } /* - # This set of nodes defines cooldown-types for different types of - # interact-script triggers. + # This set of nodes defines cooldown-types for different types of + # interact-script triggers. - */ + */ public static String TriggerDefaultCooldownType(String triggerName) { return DenizenAPI.getCurrentInstance().getConfig() .getString("Triggers." + String.valueOf(triggerName.charAt(0)).toUpperCase() + triggerName.substring(1).toLowerCase() + ".Cooldown Type", "Player"); } - /* - - # If the damage trigger is disabled on an NPC, and the NPC is not - # vulnerable, both the right and left clicks can be used to activate - # the click trigger. Default setting in versions 0.8+ is 'false', - # but it's worth noting that in previous versions this was by - # default 'true'. - # - # Select true if you would like invulnerable NPCs to use both right - # and left clicks to activate the click trigger. - - */ - - public static boolean ClickTriggerAllowsLeftClick() { - return DenizenAPI.getCurrentInstance().getConfig() + /* + + # If the damage trigger is disabled on an NPC, and the NPC is not + # vulnerable, both the right and left clicks can be used to activate + # the click trigger. Default setting in versions 0.8+ is 'false', + # but it's worth noting that in previous versions this was by + # default 'true'. + # + # Select true if you would like invulnerable NPCs to use both right + # and left clicks to activate the click trigger. + + */ + + public static boolean ClickTriggerAllowsLeftClick() { + return DenizenAPI.getCurrentInstance().getConfig() .getBoolean("Triggers.Click.Allows Left Click", false); - } - - /* - - # Default engage timeout. When NPCs are set to ENGAGE, this is - # the default timeout that they will auto-DISENGAGE if not otherwise - # specified. (Default, 150 seconds) - - */ - - public static String EngageTimeoutInSeconds() { - return DenizenAPI.getCurrentInstance().getConfig() + } + + /* + + # Default engage timeout. When NPCs are set to ENGAGE, this is + # the default timeout that they will auto-DISENGAGE if not otherwise + # specified. (Default, 150 seconds) + + */ + + public static String EngageTimeoutInSeconds() { + return DenizenAPI.getCurrentInstance().getConfig() .getString("Commands.Engage.Timeout", "150s"); - } + } /* diff --git a/src/main/java/net/aufdemrand/denizen/events/ExhaustedNPCEvent.java b/src/main/java/net/aufdemrand/denizen/events/ExhaustedNPCEvent.java index 8184013af4..650f6a331f 100644 --- a/src/main/java/net/aufdemrand/denizen/events/ExhaustedNPCEvent.java +++ b/src/main/java/net/aufdemrand/denizen/events/ExhaustedNPCEvent.java @@ -19,7 +19,7 @@ public class ExhaustedNPCEvent extends NPCEvent implements Cancellable { private boolean cancelled = false; public ExhaustedNPCEvent(NPC npc) { - super(npc); + super(npc); } public HandlerList getHandlers() { diff --git a/src/main/java/net/aufdemrand/denizen/events/ScriptEntryExecuteEvent.java b/src/main/java/net/aufdemrand/denizen/events/ScriptEntryExecuteEvent.java index 451e6f5a58..708bb2d53b 100644 --- a/src/main/java/net/aufdemrand/denizen/events/ScriptEntryExecuteEvent.java +++ b/src/main/java/net/aufdemrand/denizen/events/ScriptEntryExecuteEvent.java @@ -18,8 +18,8 @@ public ScriptEntryExecuteEvent(ScriptEntry scriptEntry) { } public void alterScriptEntry(ScriptEntry scriptEntry) { - this.scriptEntry = scriptEntry; - altered = true; + this.scriptEntry = scriptEntry; + altered = true; } public HandlerList getHandlers() { @@ -31,21 +31,21 @@ public static HandlerList getHandlerList() { } public ScriptEntry getScriptEntry() { - return scriptEntry; + return scriptEntry; } public boolean isAltered() { - return altered; + return altered; } @Override - public boolean isCancelled() { - return cancelled; - } - - @Override - public void setCancelled(boolean arg0) { - cancelled = arg0; - } + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean arg0) { + cancelled = arg0; + } } \ No newline at end of file diff --git a/src/main/java/net/aufdemrand/denizen/events/ScriptFailEvent.java b/src/main/java/net/aufdemrand/denizen/events/ScriptFailEvent.java index 3f80a5459e..54a779cd06 100644 --- a/src/main/java/net/aufdemrand/denizen/events/ScriptFailEvent.java +++ b/src/main/java/net/aufdemrand/denizen/events/ScriptFailEvent.java @@ -1,46 +1,46 @@ -package net.aufdemrand.denizen.events; - -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - - -/** - * Bukkit event for when a dScript FAIL command is executed. - * - * @author Jeremy Schroeder - * - */ - -public class ScriptFailEvent extends Event { - - private static final HandlerList handlers = new HandlerList(); - private String playerName; - private String scriptName; - private int count; - - public ScriptFailEvent(String playerName, String scriptName, int count) { - this.scriptName = scriptName; - this.playerName = playerName; - this.count = count; - } - - public int getCount() { - return count; - } - - public String getScriptName() { - return scriptName; - } - - public String getPlayerName() { - return playerName; - } - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } +package net.aufdemrand.denizen.events; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + + +/** + * Bukkit event for when a dScript FAIL command is executed. + * + * @author Jeremy Schroeder + * + */ + +public class ScriptFailEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + private String playerName; + private String scriptName; + private int count; + + public ScriptFailEvent(String playerName, String scriptName, int count) { + this.scriptName = scriptName; + this.playerName = playerName; + this.count = count; + } + + public int getCount() { + return count; + } + + public String getScriptName() { + return scriptName; + } + + public String getPlayerName() { + return playerName; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } } \ No newline at end of file diff --git a/src/main/java/net/aufdemrand/denizen/events/ScriptFinishEvent.java b/src/main/java/net/aufdemrand/denizen/events/ScriptFinishEvent.java index 08b79ef14e..92157b4441 100644 --- a/src/main/java/net/aufdemrand/denizen/events/ScriptFinishEvent.java +++ b/src/main/java/net/aufdemrand/denizen/events/ScriptFinishEvent.java @@ -1,44 +1,44 @@ -package net.aufdemrand.denizen.events; - -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - - -/** - * Bukkit event for when a dScript FINISH command is executed. - * - * @author Jeremy Schroeder - * - */ -public class ScriptFinishEvent extends Event { - private static final HandlerList handlers = new HandlerList(); - private String playerName; - private String scriptName; - private int count; - - public ScriptFinishEvent(String playerName, String theScript, int count) { - this.scriptName = theScript; - this.playerName = playerName; - this.count = count; - } - - public int getCount() { - return count; - } - - public String getScriptName() { - return scriptName; - } - - public String getPlayerName() { - return playerName; - } - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } +package net.aufdemrand.denizen.events; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + + +/** + * Bukkit event for when a dScript FINISH command is executed. + * + * @author Jeremy Schroeder + * + */ +public class ScriptFinishEvent extends Event { + private static final HandlerList handlers = new HandlerList(); + private String playerName; + private String scriptName; + private int count; + + public ScriptFinishEvent(String playerName, String theScript, int count) { + this.scriptName = theScript; + this.playerName = playerName; + this.count = count; + } + + public int getCount() { + return count; + } + + public String getScriptName() { + return scriptName; + } + + public String getPlayerName() { + return playerName; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } } \ No newline at end of file diff --git a/src/main/java/net/aufdemrand/denizen/exceptions/CommandExecutionException.java b/src/main/java/net/aufdemrand/denizen/exceptions/CommandExecutionException.java index 41f2c26557..478751dd92 100644 --- a/src/main/java/net/aufdemrand/denizen/exceptions/CommandExecutionException.java +++ b/src/main/java/net/aufdemrand/denizen/exceptions/CommandExecutionException.java @@ -4,17 +4,17 @@ public class CommandExecutionException extends Exception { - private static final long serialVersionUID = 3159123423457792068L; + private static final long serialVersionUID = 3159123423457792068L; - public CommandExecutionException(String msg) { - super(msg); - } - - public CommandExecutionException(Messages msg, String arg) { - super(String.format(msg.toString(), arg)); - } - - public CommandExecutionException(Messages msg) { - super(msg.toString()); - } + public CommandExecutionException(String msg) { + super(msg); + } + + public CommandExecutionException(Messages msg, String arg) { + super(String.format(msg.toString(), arg)); + } + + public CommandExecutionException(Messages msg) { + super(msg.toString()); + } } diff --git a/src/main/java/net/aufdemrand/denizen/exceptions/InvalidArgumentsException.java b/src/main/java/net/aufdemrand/denizen/exceptions/InvalidArgumentsException.java index a481f6ad12..7a6ced25bc 100644 --- a/src/main/java/net/aufdemrand/denizen/exceptions/InvalidArgumentsException.java +++ b/src/main/java/net/aufdemrand/denizen/exceptions/InvalidArgumentsException.java @@ -4,17 +4,17 @@ public class InvalidArgumentsException extends Exception { - private static final long serialVersionUID = 3159108944857792068L; + private static final long serialVersionUID = 3159108944857792068L; - public InvalidArgumentsException(String msg) { - super(msg); - } - - public InvalidArgumentsException(Messages msg, String arg) { - super(String.format(msg.toString(), arg)); - } - - public InvalidArgumentsException(Messages msg) { - super(msg.toString()); - } + public InvalidArgumentsException(String msg) { + super(msg); + } + + public InvalidArgumentsException(Messages msg, String arg) { + super(String.format(msg.toString(), arg)); + } + + public InvalidArgumentsException(Messages msg) { + super(msg.toString()); + } } diff --git a/src/main/java/net/aufdemrand/denizen/exceptions/RequirementCheckException.java b/src/main/java/net/aufdemrand/denizen/exceptions/RequirementCheckException.java index 7701a849de..f1f0b7341a 100644 --- a/src/main/java/net/aufdemrand/denizen/exceptions/RequirementCheckException.java +++ b/src/main/java/net/aufdemrand/denizen/exceptions/RequirementCheckException.java @@ -4,17 +4,17 @@ public class RequirementCheckException extends Exception { - private static final long serialVersionUID = 3159123423217792068L; + private static final long serialVersionUID = 3159123423217792068L; - public RequirementCheckException(String msg) { - super(msg); - } - - public RequirementCheckException(Messages msg, String arg) { - super(String.format(msg.toString(), arg)); - } - - public RequirementCheckException(Messages msg) { - super(msg.toString()); - } + public RequirementCheckException(String msg) { + super(msg); + } + + public RequirementCheckException(Messages msg, String arg) { + super(String.format(msg.toString(), arg)); + } + + public RequirementCheckException(Messages msg) { + super(msg.toString()); + } } diff --git a/src/main/java/net/aufdemrand/denizen/exceptions/ScriptEntryCreationException.java b/src/main/java/net/aufdemrand/denizen/exceptions/ScriptEntryCreationException.java index e569dee934..d2fc448a5a 100644 --- a/src/main/java/net/aufdemrand/denizen/exceptions/ScriptEntryCreationException.java +++ b/src/main/java/net/aufdemrand/denizen/exceptions/ScriptEntryCreationException.java @@ -4,17 +4,17 @@ public class ScriptEntryCreationException extends Exception { - private static final long serialVersionUID = 315955523457792068L; + private static final long serialVersionUID = 315955523457792068L; - public ScriptEntryCreationException(String msg) { - super(msg); - } - - public ScriptEntryCreationException(Messages msg, String arg) { - super(String.format(msg.toString(), arg)); - } - - public ScriptEntryCreationException(Messages msg) { - super(msg.toString()); - } + public ScriptEntryCreationException(String msg) { + super(msg); + } + + public ScriptEntryCreationException(Messages msg, String arg) { + super(String.format(msg.toString(), arg)); + } + + public ScriptEntryCreationException(Messages msg) { + super(msg.toString()); + } } diff --git a/src/main/java/net/aufdemrand/denizen/flags/FlagManager.java b/src/main/java/net/aufdemrand/denizen/flags/FlagManager.java index 846d018698..f793b8f814 100644 --- a/src/main/java/net/aufdemrand/denizen/flags/FlagManager.java +++ b/src/main/java/net/aufdemrand/denizen/flags/FlagManager.java @@ -274,8 +274,8 @@ public int split(Object obj) { if (split.length > 0) { for (String val : split) - if (val.length() > 0) - value.values.add(val); + if (val.length() > 0) + value.values.add(val); save(); rebuild(); diff --git a/src/main/java/net/aufdemrand/denizen/listeners/AbstractListener.java b/src/main/java/net/aufdemrand/denizen/listeners/AbstractListener.java index d6fa57f0c3..f045480b3f 100644 --- a/src/main/java/net/aufdemrand/denizen/listeners/AbstractListener.java +++ b/src/main/java/net/aufdemrand/denizen/listeners/AbstractListener.java @@ -16,170 +16,170 @@ public abstract class AbstractListener { - protected Denizen denizen; + protected Denizen denizen; - protected String type; - public String id; - protected dPlayer player; - protected dScript scriptName; + protected String type; + public String id; + protected dPlayer player; + protected dScript scriptName; protected dNPC npc; - protected Map savable = new HashMap(); + protected Map savable = new HashMap(); - public AbstractListener() { - this.denizen = (Denizen) Bukkit.getServer().getPluginManager().getPlugin("Denizen"); - } + public AbstractListener() { + this.denizen = (Denizen) Bukkit.getServer().getPluginManager().getPlugin("Denizen"); + } - public void build(dPlayer player, + public void build(dPlayer player, String listenerId, String listenerType, List args, dScript finishScript, dNPC npc) { - this.player = player; - this.id = listenerId; - this.type = listenerType; - this.scriptName = finishScript; + this.player = player; + this.id = listenerId; + this.type = listenerType; + this.scriptName = finishScript; this.npc = npc; - onBuild(args); - save(); - constructed(); - } - - public void cancel() { - onCancel(); - denizen.getListenerRegistry().cancel(player, id); - deconstructed(); - } - - public abstract void constructed(); - - public abstract void deconstructed(); - - public void finish() { - onFinish(); - denizen.getListenerRegistry().finish(player, npc, id, scriptName); - deconstructed(); - } - - /** - * Gets an Object that was store()d away. - * - * @param key - * the name (key) of the Object requested - * @return the Object associated with the key - * - */ - public Object get(String key) { - return denizen.getSaves().get("Listeners." + player.getName() + "." + id + "." + key); - } - - public String getListenerId() { - return id != null ? id : ""; - } - - public String getListenerType() { - return type != null ? type : ""; - } - - public void load(dPlayer player, dNPC npc, String id, String listenerType) { - this.player = player; - this.id = id; - this.type = listenerType; - this.scriptName = dScript.valueOf((String) get("Finish Script")); + onBuild(args); + save(); + constructed(); + } + + public void cancel() { + onCancel(); + denizen.getListenerRegistry().cancel(player, id); + deconstructed(); + } + + public abstract void constructed(); + + public abstract void deconstructed(); + + public void finish() { + onFinish(); + denizen.getListenerRegistry().finish(player, npc, id, scriptName); + deconstructed(); + } + + /** + * Gets an Object that was store()d away. + * + * @param key + * the name (key) of the Object requested + * @return the Object associated with the key + * + */ + public Object get(String key) { + return denizen.getSaves().get("Listeners." + player.getName() + "." + id + "." + key); + } + + public String getListenerId() { + return id != null ? id : ""; + } + + public String getListenerType() { + return type != null ? type : ""; + } + + public void load(dPlayer player, dNPC npc, String id, String listenerType) { + this.player = player; + this.id = id; + this.type = listenerType; + this.scriptName = dScript.valueOf((String) get("Finish Script")); this.npc = npc; - try { onLoad(); } catch (Exception e) { dB.echoError("Problem loading saved listener '" + id + "' for " + player.getName() + "!"); } - constructed(); - } - - /** - * Method to handle building a new quest listener List of arguments. - * Most likely called from a LISTEN dScript command. The player and id fields - * are non-null at this point. - * - * @param args - * a list of dScript arguments - * - */ - public abstract void onBuild(List args); - - public abstract void onCancel(); - - public abstract void onFinish(); - - /** - * Called when a Player logs on if an instance of this quest listener was saved - * with progress. Any variables that were saved with the store(stringKey, object) method - * should be called and restored. - * - */ - public abstract void onLoad(); - - /** - * When a Player logs off, the quest listener's progress is stored to saves.yml. - * This method should use the store(stringKey, object) method to save the fields needed to - * successfully reload the current state of this quest listener when the onLoad() - * method is called. The fields for player, type, and id are done automatically. - * - */ - public abstract void onSave(); - - /** - * Sums up the current status of a this AbstractListenerInstance in a way that would be - * useful by itself to a Player or Console administrator. - * - * Called by the '/denizen listener --report id' bukkit command. - * - * This should include all applicable variables when reporting. Suggested format would - * follow suit with core Listeners. For example: - * - * return player.getName() + " currently has quest listener '" + id - * + "' active and must kill " + Arrays.toString(targets.toArray()) - * + " '" + type.name() + "'(s). Current progress '" + currentKills - * + "/" + quantity + "'."; - * - * Output: - * aufdemrand currently has quest listener 'example_quest' active and must kill - * '[ZOMBIE, SKELETON] ENTITY'(s). Current progress '10/15'. - * - * Note: This is not intended to be a 'Quest Log' for a Player, rather is used when - * administrators/server operators are checking up on this Listener. Ideally, - * that kind of information should be handled with the use of replaceable tags. - * - * @return a 'formatted' String that contains current progress - * - */ - public abstract String report(); - - public void save() { - denizen.getSaves().set("Listeners." + player.getName() + "." + id + try { onLoad(); } catch (Exception e) { dB.echoError("Problem loading saved listener '" + id + "' for " + player.getName() + "!"); } + constructed(); + } + + /** + * Method to handle building a new quest listener List of arguments. + * Most likely called from a LISTEN dScript command. The player and id fields + * are non-null at this point. + * + * @param args + * a list of dScript arguments + * + */ + public abstract void onBuild(List args); + + public abstract void onCancel(); + + public abstract void onFinish(); + + /** + * Called when a Player logs on if an instance of this quest listener was saved + * with progress. Any variables that were saved with the store(stringKey, object) method + * should be called and restored. + * + */ + public abstract void onLoad(); + + /** + * When a Player logs off, the quest listener's progress is stored to saves.yml. + * This method should use the store(stringKey, object) method to save the fields needed to + * successfully reload the current state of this quest listener when the onLoad() + * method is called. The fields for player, type, and id are done automatically. + * + */ + public abstract void onSave(); + + /** + * Sums up the current status of a this AbstractListenerInstance in a way that would be + * useful by itself to a Player or Console administrator. + * + * Called by the '/denizen listener --report id' bukkit command. + * + * This should include all applicable variables when reporting. Suggested format would + * follow suit with core Listeners. For example: + * + * return player.getName() + " currently has quest listener '" + id + * + "' active and must kill " + Arrays.toString(targets.toArray()) + * + " '" + type.name() + "'(s). Current progress '" + currentKills + * + "/" + quantity + "'."; + * + * Output: + * aufdemrand currently has quest listener 'example_quest' active and must kill + * '[ZOMBIE, SKELETON] ENTITY'(s). Current progress '10/15'. + * + * Note: This is not intended to be a 'Quest Log' for a Player, rather is used when + * administrators/server operators are checking up on this Listener. Ideally, + * that kind of information should be handled with the use of replaceable tags. + * + * @return a 'formatted' String that contains current progress + * + */ + public abstract String report(); + + public void save() { + denizen.getSaves().set("Listeners." + player.getName() + "." + id + ".Listener Type", type); - denizen.getSaves().set("Listeners." + player.getName() + "." + id + denizen.getSaves().set("Listeners." + player.getName() + "." + id + ".Finish Script", scriptName.toString()); - if (npc != null) denizen.getSaves().set("Listeners." + player.getName() + "." + if (npc != null) denizen.getSaves().set("Listeners." + player.getName() + "." + id + ".Linked NPCID", npc.getId()); onSave(); try { - if (!savable.isEmpty()) - for (Entry entry : savable.entrySet()) - denizen.getSaves().set("Listeners." + player.getName() + "." + id + "." + entry.getKey(), entry.getValue()); - } catch (Exception e) { - dB.echoError("Problem saving listener '" + id + "' for " + player.getName() + "!"); - } + if (!savable.isEmpty()) + for (Entry entry : savable.entrySet()) + denizen.getSaves().set("Listeners." + player.getName() + "." + id + "." + entry.getKey(), entry.getValue()); + } catch (Exception e) { + dB.echoError("Problem saving listener '" + id + "' for " + player.getName() + "!"); + } deconstructed(); - } - - /** - * Stores a field away for retrieving later. Should be used in the onSave() method. - * - */ - public void store(String key, Object object) { - savable.put(key, object); - } + } + + /** + * Stores a field away for retrieving later. Should be used in the onSave() method. + * + */ + public void store(String key, Object object) { + savable.put(key, object); + } } diff --git a/src/main/java/net/aufdemrand/denizen/listeners/AbstractListenerType.java b/src/main/java/net/aufdemrand/denizen/listeners/AbstractListenerType.java index 2bcc69d07d..a9bb363e67 100644 --- a/src/main/java/net/aufdemrand/denizen/listeners/AbstractListenerType.java +++ b/src/main/java/net/aufdemrand/denizen/listeners/AbstractListenerType.java @@ -12,60 +12,60 @@ public abstract class AbstractListenerType implements RegistrationableInstance { Denizen denizen; - String name; - Class instanceClass; - - @Override - public AbstractListenerType activate() { - this.denizen = (Denizen) Bukkit.getServer().getPluginManager().getPlugin("Denizen"); - return this; - } + String name; + Class instanceClass; + + @Override + public AbstractListenerType activate() { + this.denizen = (Denizen) Bukkit.getServer().getPluginManager().getPlugin("Denizen"); + return this; + } - @Override - public AbstractListenerType as(String type) { - name = type.toUpperCase(); - denizen.getListenerRegistry() + @Override + public AbstractListenerType as(String type) { + name = type.toUpperCase(); + denizen.getListenerRegistry() .register(this.name, this); - onEnable(); - return this; - } + onEnable(); + return this; + } - public AbstractListener createInstance(dPlayer player, String listenerId) { - try { - denizen.getListenerRegistry().addListenerFor(player, instanceClass.newInstance(), listenerId); - return denizen.getListenerRegistry().getListenerFor(player, listenerId); - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } + public AbstractListener createInstance(dPlayer player, String listenerId) { + try { + denizen.getListenerRegistry().addListenerFor(player, instanceClass.newInstance(), listenerId); + return denizen.getListenerRegistry().getListenerFor(player, listenerId); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } - @Override - public String getName() { - return this.name; - } - - /** - * Part of the Plugin disable sequence. - * - * Can be '@Override'n by a Listener which requires a method when bukkit sends a - * onDisable() to Denizen. (ie. Server shuts down or restarts) - * - */ - public void onDisable() { - - } - - public AbstractListenerType withClass(Class listenerInstanceClass) { - this.instanceClass = listenerInstanceClass; - return null; - } + @Override + public String getName() { + return this.name; + } + + /** + * Part of the Plugin disable sequence. + * + * Can be '@Override'n by a Listener which requires a method when bukkit sends a + * onDisable() to Denizen. (ie. Server shuts down or restarts) + * + */ + public void onDisable() { + + } + + public AbstractListenerType withClass(Class listenerInstanceClass) { + this.instanceClass = listenerInstanceClass; + return null; + } - + } diff --git a/src/main/java/net/aufdemrand/denizen/listeners/ListenerRegistry.java b/src/main/java/net/aufdemrand/denizen/listeners/ListenerRegistry.java index f9409bbcc5..b2e43fabbb 100644 --- a/src/main/java/net/aufdemrand/denizen/listeners/ListenerRegistry.java +++ b/src/main/java/net/aufdemrand/denizen/listeners/ListenerRegistry.java @@ -39,7 +39,7 @@ public class ListenerRegistry implements dRegistry, Listener { - // + // // Keeps track of active listeners. Keyed by player name. // Value contains name of the listener, and the instance // associated. @@ -64,20 +64,20 @@ public class ListenerRegistry implements dRegistry, Listener { * @param instance the listener instance * @param id the id of the listener instance */ - public void addListenerFor(dPlayer player, + public void addListenerFor(dPlayer player, AbstractListener instance, String id) { if (player == null || id == null) return; // Get current instances Map playerListeners; - if (listeners.containsKey(player.getName())) - playerListeners = listeners.get(player.getName()); + if (listeners.containsKey(player.getName())) + playerListeners = listeners.get(player.getName()); else playerListeners = new HashMap(); // Insert instance into hash-map - playerListeners.put(id.toLowerCase(), instance); + playerListeners.put(id.toLowerCase(), instance); listeners.put(player.getName(), playerListeners); - } + } /** @@ -109,14 +109,14 @@ public void removeListenerFor(dPlayer player, String id) { * @param player the dPlayer * @param id */ - public void cancel(dPlayer player, String id) { + public void cancel(dPlayer player, String id) { if (player == null || id == null) return; // Removes listener - removeListenerFor(player, id); + removeListenerFor(player, id); // Fires bukkit event Bukkit.getPluginManager() .callEvent(new ListenerCancelEvent(player, id)); - } + } /** @@ -192,75 +192,75 @@ public void registerCoreMembers() { .registerEvents(this, DenizenAPI.getCurrentInstance()); } - @Override - public void disableCoreMembers() { - // Note: This runs a onDisable() for each AbstractListenerType, NOT each - // AbstractListener, which should be fine considering in-progress - // AbstractListeners deconstruct automatically based on PlayerLogoutEvent - // which is also run on a server disable or restart. - for (RegistrationableInstance member : types.values()) - try { - member.onDisable(); - } catch (Exception e) { - dB.echoError("Unable to disable '" + member.getClass().getName() + "'!"); - if (dB.showStackTraces) e.printStackTrace(); - } - } - - @Override - public T get(Class clazz) { - if (types.containsValue(clazz)) { - for (RegistrationableInstance ri : types.values()) - if (ri.getClass() == clazz) - return (T) clazz.cast(ri); - } - return null; - } - - @Override - public AbstractListenerType get(String listenerType) { - if (types.containsKey(listenerType.toUpperCase())) return types.get(listenerType.toUpperCase()); - return null; - } - - @Override - public Map list() { - return types; - } - - - - - - @EventHandler - public void playerJoin(PlayerJoinEvent event) { + @Override + public void disableCoreMembers() { + // Note: This runs a onDisable() for each AbstractListenerType, NOT each + // AbstractListener, which should be fine considering in-progress + // AbstractListeners deconstruct automatically based on PlayerLogoutEvent + // which is also run on a server disable or restart. + for (RegistrationableInstance member : types.values()) + try { + member.onDisable(); + } catch (Exception e) { + dB.echoError("Unable to disable '" + member.getClass().getName() + "'!"); + if (dB.showStackTraces) e.printStackTrace(); + } + } + + @Override + public T get(Class clazz) { + if (types.containsValue(clazz)) { + for (RegistrationableInstance ri : types.values()) + if (ri.getClass() == clazz) + return (T) clazz.cast(ri); + } + return null; + } + + @Override + public AbstractListenerType get(String listenerType) { + if (types.containsKey(listenerType.toUpperCase())) return types.get(listenerType.toUpperCase()); + return null; + } + + @Override + public Map list() { + return types; + } + + + + + + @EventHandler + public void playerJoin(PlayerJoinEvent event) { Denizen denizen = DenizenAPI.getCurrentInstance(); - // Any saves quest listeners in progress? - if (!denizen.getSaves().contains("Listeners." + event.getPlayer().getName())) return; - Set inProgress = denizen.getSaves().getConfigurationSection("Listeners." + event.getPlayer().getName()).getKeys(false); - // If empty, no quest listeners to load. - if (inProgress.isEmpty()) return; - - String path = "Listeners." + event.getPlayer().getName() + "."; - - // If not empty, let's do the loading process for each. - for (String listenerId : inProgress) { - // People tend to worry when they see long-ass stacktraces.. let's catch them. - try { - String type = denizen.getSaves().getString(path + listenerId + ".Listener Type"); - dNPC npc = null; - if (denizen.getSaves().contains(path + listenerId + ".Linked NPCID")) - npc = DenizenAPI.getDenizenNPC(CitizensAPI.getNPCRegistry().getById(denizen.getSaves().getInt(path + listenerId + ".Linked NPCID"))); + // Any saves quest listeners in progress? + if (!denizen.getSaves().contains("Listeners." + event.getPlayer().getName())) return; + Set inProgress = denizen.getSaves().getConfigurationSection("Listeners." + event.getPlayer().getName()).getKeys(false); + // If empty, no quest listeners to load. + if (inProgress.isEmpty()) return; + + String path = "Listeners." + event.getPlayer().getName() + "."; + + // If not empty, let's do the loading process for each. + for (String listenerId : inProgress) { + // People tend to worry when they see long-ass stacktraces.. let's catch them. + try { + String type = denizen.getSaves().getString(path + listenerId + ".Listener Type"); + dNPC npc = null; + if (denizen.getSaves().contains(path + listenerId + ".Linked NPCID")) + npc = DenizenAPI.getDenizenNPC(CitizensAPI.getNPCRegistry().getById(denizen.getSaves().getInt(path + listenerId + ".Linked NPCID"))); if (get(type) == null) return; - dB.log(event.getPlayer().getName() + " has a LISTENER in progress. Loading '" + listenerId + "'."); - get(type).createInstance(dPlayer.mirrorBukkitPlayer(event.getPlayer()), listenerId).load(dPlayer.mirrorBukkitPlayer(event.getPlayer()), npc, listenerId, type); - } catch (Exception e) { - dB.log(event.getPlayer() + " has a saved listener named '" + listenerId + "' that may be corrupt. Skipping for now, but perhaps check the contents of your saves.yml for problems?"); - } - } - } + dB.log(event.getPlayer().getName() + " has a LISTENER in progress. Loading '" + listenerId + "'."); + get(type).createInstance(dPlayer.mirrorBukkitPlayer(event.getPlayer()), listenerId).load(dPlayer.mirrorBukkitPlayer(event.getPlayer()), npc, listenerId, type); + } catch (Exception e) { + dB.log(event.getPlayer() + " has a saved listener named '" + listenerId + "' that may be corrupt. Skipping for now, but perhaps check the contents of your saves.yml for problems?"); + } + } + } public void deconstructPlayer(dPlayer player ) { @@ -285,8 +285,8 @@ public void deconstructPlayer(dPlayer player ) { } - @EventHandler - public void playerQuit(PlayerQuitEvent event) { + @EventHandler + public void playerQuit(PlayerQuitEvent event) { deconstructPlayer(dPlayer.mirrorBukkitPlayer(event.getPlayer())); } diff --git a/src/main/java/net/aufdemrand/denizen/listeners/core/BlockListenerInstance.java b/src/main/java/net/aufdemrand/denizen/listeners/core/BlockListenerInstance.java index 34c74b6416..155eef8819 100644 --- a/src/main/java/net/aufdemrand/denizen/listeners/core/BlockListenerInstance.java +++ b/src/main/java/net/aufdemrand/denizen/listeners/core/BlockListenerInstance.java @@ -24,225 +24,225 @@ public class BlockListenerInstance extends AbstractListener implements Listener { - BlockType type; - List blocks = new ArrayList(); - Integer quantity = 1; - String region = null; + BlockType type; + List blocks = new ArrayList(); + Integer quantity = 1; + String region = null; - Integer currentBlocks = 0; + Integer currentBlocks = 0; - @Override - public void onBuild(List args) { + @Override + public void onBuild(List args) { // // for (String arg : args) { -// if (aH.matchesValueArg("TYPE", arg, ArgumentType.Custom)) { -// try { -// this.type = BlockType.valueOf(aH.getStringFrom(arg).toUpperCase()); -// dB.echoDebug(Messages.DEBUG_SET_TYPE, this.type.name()); -// } catch (Exception e) { dB.echoError("Invalid BlockType!"); } -// } +// if (aH.matchesValueArg("TYPE", arg, ArgumentType.Custom)) { +// try { +// this.type = BlockType.valueOf(aH.getStringFrom(arg).toUpperCase()); +// dB.echoDebug(Messages.DEBUG_SET_TYPE, this.type.name()); +// } catch (Exception e) { dB.echoError("Invalid BlockType!"); } +// } // -// else if (aH.matchesQuantity(arg)) { -// quantity = aH.getIntegerFrom(arg); -// dB.echoDebug(Messages.DEBUG_SET_QUANTITY, String.valueOf(quantity)); -// } +// else if (aH.matchesQuantity(arg)) { +// quantity = aH.getIntegerFrom(arg); +// dB.echoDebug(Messages.DEBUG_SET_QUANTITY, String.valueOf(quantity)); +// } // -// else if (aH.matchesArg("BLOCKS, BLOCK", arg)){ -// blocks = aH.getListFrom(arg.toUpperCase()); -// dB.echoDebug("...set BLOCK(S): " + Arrays.toString(blocks.toArray())); -// } +// else if (aH.matchesArg("BLOCKS, BLOCK", arg)){ +// blocks = aH.getListFrom(arg.toUpperCase()); +// dB.echoDebug("...set BLOCK(S): " + Arrays.toString(blocks.toArray())); +// } // -// else if (aH.matchesValueArg("REGION", arg, ArgumentType.Custom)) { -// region = aH.getStringFrom(arg); -// dB.echoDebug("...set REGION."); -// } -// } +// else if (aH.matchesValueArg("REGION", arg, ArgumentType.Custom)) { +// region = aH.getStringFrom(arg); +// dB.echoDebug("...set REGION."); +// } +// } // -// if (blocks.isEmpty()) { -// dB.echoError("Missing BLOCK(S) argument!"); -// cancel(); -// return; -// } +// if (blocks.isEmpty()) { +// dB.echoError("Missing BLOCK(S) argument!"); +// cancel(); +// return; +// } // -// if (type == null) { -// dB.echoError("Missing TYPE argument! Valid: BUILD, COLLECT, BREAK"); -// cancel(); +// if (type == null) { +// dB.echoError("Missing TYPE argument! Valid: BUILD, COLLECT, BREAK"); +// cancel(); // } - } - - @Override - public void onSave() { - store("Type", type.name()); - store("Blocks", this.blocks); - store("Quantity", this.quantity); - store("Current Blocks", this.currentBlocks); - store("Region", region); - } - - @SuppressWarnings("unchecked") - @Override - public void onLoad() { - type = BlockType.valueOf(((String) get("Type"))); - blocks = (List) get("Blocks"); - quantity = (Integer) get("Quantity"); - currentBlocks = (Integer) get("Current Blocks"); - region = (String) get("Region"); - } - - @Override - public void onFinish() { - // nothing to do here - } - - @Override - public void onCancel() { - // nothing to do here - } - - @Override - public String report() { - // TODO Format a report output - return null; - } - - @Override - public void constructed() { - denizen.getServer().getPluginManager().registerEvents(this, denizen); - } - - @Override - public void deconstructed() { - BlockBreakEvent.getHandlerList().unregister(this); - PlayerPickupItemEvent.getHandlerList().unregister(this); - BlockPlaceEvent.getHandlerList().unregister(this); - } - - public void check() { - // Check current block count vs. required count; finish() if necessary. - if (currentBlocks >= quantity) { - finish(); - } - } - - List blocksBroken = new ArrayList(); - @EventHandler - public void listenBreak(BlockBreakEvent event) { - if (type == BlockType.BREAK) { - if (event.getPlayer() == player.getPlayerEntity()) { - - if (region != null) - if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; - - if (blocks.contains(event.getBlock().getType().toString()) - || blocks.contains(String.valueOf(event.getBlock().getTypeId()))) { - - if (blocksBroken.contains(event.getBlock().getLocation())) - return; - else blocksBroken.add(event.getBlock().getLocation()); - - currentBlocks++; - dB.echoDebug(ChatColor.YELLOW + "// " + player.getName() + " broke a " + event.getBlock().getType().toString() + "."); - check(); - } - } - } - } - - - List itemsCollected = new ArrayList(); - @EventHandler - public void listenCollect(PlayerPickupItemEvent event) { - if (type == BlockType.COLLECT) { - if (event.getPlayer() == player.getPlayerEntity()) { - - if (region != null) - if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; - - if (blocks.contains(event.getItem().getItemStack().getType().toString()) - || blocks.contains(String.valueOf(event.getItem().getItemStack().getTypeId()))) { - - if (itemsCollected.contains(event.getItem().getEntityId())) - return; - else itemsCollected.add(event.getItem().getEntityId()); - - currentBlocks = currentBlocks + event.getItem().getItemStack().getAmount(); - dB.echoDebug(ChatColor.YELLOW + "// " + player.getName() + " collected a " + event.getItem().getItemStack().getType().toString() + "."); - check(); - - } - } - } - } - - @EventHandler - public void listenBucket(PlayerBucketFillEvent event) { - if (type == BlockType.COLLECT) { - if (event.getPlayer() == player.getPlayerEntity()) { - - if (region != null) - if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; - - if (blocks.contains(event.getBucket().name().toUpperCase()) - || blocks.contains(String.valueOf(event.getBucket().name().toUpperCase()))) { - currentBlocks++; - dB.echoDebug(ChatColor.YELLOW + "// " + player.getName() + " collected a " + event.getBucket().name().toString() + "."); - check(); - } - } - } - } - - List blocksPlaced = new ArrayList(); - @EventHandler - public void listenPlace(BlockPlaceEvent event) { - if (type == BlockType.BUILD) { - if (event.getPlayer() == player.getPlayerEntity()) { - - if (region != null) - if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; - - if (blocks.contains(event.getBlock().getType().toString()) - || blocks.contains(String.valueOf(event.getBlock().getTypeId()))) { - - if (blocksPlaced.contains(event.getBlock().getLocation())) - return; - else blocksPlaced.add(event.getBlock().getLocation()); - - currentBlocks++; - dB.echoDebug(ChatColor.YELLOW + "// " + player.getName() + " placed a " + event.getBlock().getType().toString() + "."); - check(); - } - } - } - } - - @EventHandler + } + + @Override + public void onSave() { + store("Type", type.name()); + store("Blocks", this.blocks); + store("Quantity", this.quantity); + store("Current Blocks", this.currentBlocks); + store("Region", region); + } + + @SuppressWarnings("unchecked") + @Override + public void onLoad() { + type = BlockType.valueOf(((String) get("Type"))); + blocks = (List) get("Blocks"); + quantity = (Integer) get("Quantity"); + currentBlocks = (Integer) get("Current Blocks"); + region = (String) get("Region"); + } + + @Override + public void onFinish() { + // nothing to do here + } + + @Override + public void onCancel() { + // nothing to do here + } + + @Override + public String report() { + // TODO Format a report output + return null; + } + + @Override + public void constructed() { + denizen.getServer().getPluginManager().registerEvents(this, denizen); + } + + @Override + public void deconstructed() { + BlockBreakEvent.getHandlerList().unregister(this); + PlayerPickupItemEvent.getHandlerList().unregister(this); + BlockPlaceEvent.getHandlerList().unregister(this); + } + + public void check() { + // Check current block count vs. required count; finish() if necessary. + if (currentBlocks >= quantity) { + finish(); + } + } + + List blocksBroken = new ArrayList(); + @EventHandler + public void listenBreak(BlockBreakEvent event) { + if (type == BlockType.BREAK) { + if (event.getPlayer() == player.getPlayerEntity()) { + + if (region != null) + if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; + + if (blocks.contains(event.getBlock().getType().toString()) + || blocks.contains(String.valueOf(event.getBlock().getTypeId()))) { + + if (blocksBroken.contains(event.getBlock().getLocation())) + return; + else blocksBroken.add(event.getBlock().getLocation()); + + currentBlocks++; + dB.echoDebug(ChatColor.YELLOW + "// " + player.getName() + " broke a " + event.getBlock().getType().toString() + "."); + check(); + } + } + } + } + + + List itemsCollected = new ArrayList(); + @EventHandler + public void listenCollect(PlayerPickupItemEvent event) { + if (type == BlockType.COLLECT) { + if (event.getPlayer() == player.getPlayerEntity()) { + + if (region != null) + if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; + + if (blocks.contains(event.getItem().getItemStack().getType().toString()) + || blocks.contains(String.valueOf(event.getItem().getItemStack().getTypeId()))) { + + if (itemsCollected.contains(event.getItem().getEntityId())) + return; + else itemsCollected.add(event.getItem().getEntityId()); + + currentBlocks = currentBlocks + event.getItem().getItemStack().getAmount(); + dB.echoDebug(ChatColor.YELLOW + "// " + player.getName() + " collected a " + event.getItem().getItemStack().getType().toString() + "."); + check(); + + } + } + } + } + + @EventHandler + public void listenBucket(PlayerBucketFillEvent event) { + if (type == BlockType.COLLECT) { + if (event.getPlayer() == player.getPlayerEntity()) { + + if (region != null) + if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; + + if (blocks.contains(event.getBucket().name().toUpperCase()) + || blocks.contains(String.valueOf(event.getBucket().name().toUpperCase()))) { + currentBlocks++; + dB.echoDebug(ChatColor.YELLOW + "// " + player.getName() + " collected a " + event.getBucket().name().toString() + "."); + check(); + } + } + } + } + + List blocksPlaced = new ArrayList(); + @EventHandler + public void listenPlace(BlockPlaceEvent event) { + if (type == BlockType.BUILD) { + if (event.getPlayer() == player.getPlayerEntity()) { + + if (region != null) + if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; + + if (blocks.contains(event.getBlock().getType().toString()) + || blocks.contains(String.valueOf(event.getBlock().getTypeId()))) { + + if (blocksPlaced.contains(event.getBlock().getLocation())) + return; + else blocksPlaced.add(event.getBlock().getLocation()); + + currentBlocks++; + dB.echoDebug(ChatColor.YELLOW + "// " + player.getName() + " placed a " + event.getBlock().getType().toString() + "."); + check(); + } + } + } + } + + @EventHandler public void listenTag(ReplaceableTagEvent event) { - - if (!event.matches("LISTENER")) return; - if (!event.getType().equalsIgnoreCase(id)) return; - - if (event.getValue().equalsIgnoreCase("region")) { - event.setReplaced(region); - } - - else if (event.getValue().equalsIgnoreCase("required")) { - event.setReplaced(quantity.toString()); - } - - else if (event.getValue().equalsIgnoreCase("currentblocks")) { - event.setReplaced(currentBlocks.toString()); - } - - else if (event.getValue().equalsIgnoreCase("blocks")) { - String blockList = ""; - for (String curTar : blocks){ - blockList = blockList + curTar + ", "; - blockList = blockList.substring(0, blockList.length() - 1); - } - event.setReplaced(blockList); - } - } + + if (!event.matches("LISTENER")) return; + if (!event.getType().equalsIgnoreCase(id)) return; + + if (event.getValue().equalsIgnoreCase("region")) { + event.setReplaced(region); + } + + else if (event.getValue().equalsIgnoreCase("required")) { + event.setReplaced(quantity.toString()); + } + + else if (event.getValue().equalsIgnoreCase("currentblocks")) { + event.setReplaced(currentBlocks.toString()); + } + + else if (event.getValue().equalsIgnoreCase("blocks")) { + String blockList = ""; + for (String curTar : blocks){ + blockList = blockList + curTar + ", "; + blockList = blockList.substring(0, blockList.length() - 1); + } + event.setReplaced(blockList); + } + } } diff --git a/src/main/java/net/aufdemrand/denizen/listeners/core/BlockListenerType.java b/src/main/java/net/aufdemrand/denizen/listeners/core/BlockListenerType.java index 2806e5451c..5510afe03c 100644 --- a/src/main/java/net/aufdemrand/denizen/listeners/core/BlockListenerType.java +++ b/src/main/java/net/aufdemrand/denizen/listeners/core/BlockListenerType.java @@ -4,10 +4,10 @@ public class BlockListenerType extends AbstractListenerType{ - enum BlockType { BUILD, COLLECT, BREAK } - - @Override - public void onEnable() { - //nothing to do here - } + enum BlockType { BUILD, COLLECT, BREAK } + + @Override + public void onEnable() { + //nothing to do here + } } diff --git a/src/main/java/net/aufdemrand/denizen/listeners/core/ItemDropListenerInstance.java b/src/main/java/net/aufdemrand/denizen/listeners/core/ItemDropListenerInstance.java index 8bd4cf5a11..e43d1861e6 100644 --- a/src/main/java/net/aufdemrand/denizen/listeners/core/ItemDropListenerInstance.java +++ b/src/main/java/net/aufdemrand/denizen/listeners/core/ItemDropListenerInstance.java @@ -21,254 +21,254 @@ import net.aufdemrand.denizen.utilities.depends.WorldGuardUtilities; public class ItemDropListenerInstance extends AbstractListener implements Listener { - - ItemDropType type = null; - - ItemStack item = null; - Location location = null; - Material block = null; - EntityType mob = null; - - String dropper = null; - String region = null; - - Integer radius = 5; - Integer dropRate = 100; - Integer quantity = 1; - Integer qtyDropped = 0; - - @Override - public void constructed() { - denizen.getServer().getPluginManager().registerEvents(this, denizen); - - } + + ItemDropType type = null; + + ItemStack item = null; + Location location = null; + Material block = null; + EntityType mob = null; + + String dropper = null; + String region = null; + + Integer radius = 5; + Integer dropRate = 100; + Integer quantity = 1; + Integer qtyDropped = 0; + + @Override + public void constructed() { + denizen.getServer().getPluginManager().registerEvents(this, denizen); + + } - @Override - public void deconstructed() { - EntityDeathEvent.getHandlerList().unregister(this); - - } + @Override + public void deconstructed() { + EntityDeathEvent.getHandlerList().unregister(this); + + } - @Override - public void onBuild(List args) { -// for (String arg : args) { -// if (aH.matchesValueArg("TYPE", arg, ArgumentType.Custom)) { -// try { -// type = ItemDropType.valueOf(aH.getStringFrom(arg).toUpperCase()); -// dB.echoDebug("...type set to: " + type.name()); -// continue; -// } catch (Exception e) { dB.echoDebug("...type " + aH.getStringFrom(arg) + " is not valid."); } + @Override + public void onBuild(List args) { +// for (String arg : args) { +// if (aH.matchesValueArg("TYPE", arg, ArgumentType.Custom)) { +// try { +// type = ItemDropType.valueOf(aH.getStringFrom(arg).toUpperCase()); +// dB.echoDebug("...type set to: " + type.name()); +// continue; +// } catch (Exception e) { dB.echoDebug("...type " + aH.getStringFrom(arg) + " is not valid."); } // -// } else if (aH.matchesItem(arg)) { -// item = aH.getItemFrom(arg).getItemStack(); -// dB.echoDebug("...item set to: " + item); -// continue; +// } else if (aH.matchesItem(arg)) { +// item = aH.getItemFrom(arg).getItemStack(); +// dB.echoDebug("...item set to: " + item); +// continue; // -// } else if (aH.matchesValueArg("REGION", arg, ArgumentType.Custom)) { -// region = aH.getStringFrom(arg); -// dB.echoDebug("...region set to: " + region); -// continue; +// } else if (aH.matchesValueArg("REGION", arg, ArgumentType.Custom)) { +// region = aH.getStringFrom(arg); +// dB.echoDebug("...region set to: " + region); +// continue; // -// } else if (aH.matchesLocation(arg)) { -// location = aH.getLocationFrom(arg); -// dB.echoDebug("...location set to: " + location); -// continue; +// } else if (aH.matchesLocation(arg)) { +// location = aH.getLocationFrom(arg); +// dB.echoDebug("...location set to: " + location); +// continue; // -// } else if (aH.matchesValueArg("RADIUS", arg, ArgumentType.Integer)) { -// radius = aH.getIntegerFrom(arg); -// dB.echoDebug("...radius set to: " + radius); -// continue; +// } else if (aH.matchesValueArg("RADIUS", arg, ArgumentType.Integer)) { +// radius = aH.getIntegerFrom(arg); +// dB.echoDebug("...radius set to: " + radius); +// continue; // -// } else if (aH.matchesValueArg("DROPRATE", arg, ArgumentType.Integer)) { -// dropRate = aH.getIntegerFrom(arg); -// dB.echoDebug("...drop rate set to: " + dropRate + "/100"); -// continue; +// } else if (aH.matchesValueArg("DROPRATE", arg, ArgumentType.Integer)) { +// dropRate = aH.getIntegerFrom(arg); +// dB.echoDebug("...drop rate set to: " + dropRate + "/100"); +// continue; // -// } else if (aH.matchesValueArg("DROPSFROM", arg, ArgumentType.Custom)) { -// dropper = aH.getStringFrom(arg); -// dB.echoDebug("...dropper set to: " + dropper); -// continue; +// } else if (aH.matchesValueArg("DROPSFROM", arg, ArgumentType.Custom)) { +// dropper = aH.getStringFrom(arg); +// dB.echoDebug("...dropper set to: " + dropper); +// continue; // -// } else if (aH.matchesQuantity(arg)) { -// quantity = aH.getIntegerFrom(arg); -// dB.echoDebug("...required set to: " + quantity); -// continue; -// } -// } +// } else if (aH.matchesQuantity(arg)) { +// quantity = aH.getIntegerFrom(arg); +// dB.echoDebug("...required set to: " + quantity); +// continue; +// } +// } // -// if (item == null) { -// dB.echoDebug("...item could not be set"); -// cancel(); -// } +// if (item == null) { +// dB.echoDebug("...item could not be set"); +// cancel(); +// } // -// switch (type) { +// switch (type) { // -// case BLOCKPLACE: +// case BLOCKPLACE: // -// case BLOCKBREAK: -// try { -// block = Material.valueOf(dropper); -// dB.echoDebug("...DROPSFROM material set"); -// } catch (Exception e) { dB.echoDebug("...DROPSFROM is not a valid material"); } -// break; +// case BLOCKBREAK: +// try { +// block = Material.valueOf(dropper); +// dB.echoDebug("...DROPSFROM material set"); +// } catch (Exception e) { dB.echoDebug("...DROPSFROM is not a valid material"); } +// break; // -// case MOBKILL: -// if (aH.matchesEntityType("entity:" + dropper)) { -// mob = EntityType.valueOf(dropper.toUpperCase()); -// dB.echoDebug("...mob selected from DROPSFROM"); -// } else dB.echoDebug("...could not select mob from DROPSFROM"); -// break; +// case MOBKILL: +// if (aH.matchesEntityType("entity:" + dropper)) { +// mob = EntityType.valueOf(dropper.toUpperCase()); +// dB.echoDebug("...mob selected from DROPSFROM"); +// } else dB.echoDebug("...could not select mob from DROPSFROM"); +// break; // -// default: -// dB.echoDebug("...error setting type"); -// cancel(); -// break; +// default: +// dB.echoDebug("...error setting type"); +// cancel(); +// break; // -// } - } +// } + } - @Override - public void onCancel() { - // nothing to do here - - } + @Override + public void onCancel() { + // nothing to do here + + } - @Override - public void onFinish() { - // nothing to do here - - } + @Override + public void onFinish() { + // nothing to do here + + } - @Override - public void onLoad() { - type = ItemDropType.valueOf((String) get("type")); - item = (ItemStack) get("item"); - location = (Location) get("location"); - block = (Material) get("block"); - mob = (EntityType) get("mob"); - dropper = (String) get("dropper"); - region = (String) get("region"); - radius = (Integer) get("radius"); - dropRate = (Integer) get("dropRate"); - quantity = (Integer) get("required"); - qtyDropped = (Integer) get("qtyDropped"); - //r = (Random) get("r"); - - } + @Override + public void onLoad() { + type = ItemDropType.valueOf((String) get("type")); + item = (ItemStack) get("item"); + location = (Location) get("location"); + block = (Material) get("block"); + mob = (EntityType) get("mob"); + dropper = (String) get("dropper"); + region = (String) get("region"); + radius = (Integer) get("radius"); + dropRate = (Integer) get("dropRate"); + quantity = (Integer) get("required"); + qtyDropped = (Integer) get("qtyDropped"); + //r = (Random) get("r"); + + } - @Override - public void onSave() { - store("type", type); - store("item", item); - store("lcoation",location ); - store("block", block); - store("mob", mob); - store("dropper", dropper); - store("region", region); - store("radius", radius); - store("dropRate", dropRate); - store("required", quantity); - store("qtyDropped", qtyDropped); - //store("r", r); - } + @Override + public void onSave() { + store("type", type); + store("item", item); + store("lcoation",location ); + store("block", block); + store("mob", mob); + store("dropper", dropper); + store("region", region); + store("radius", radius); + store("dropRate", dropRate); + store("required", quantity); + store("qtyDropped", qtyDropped); + //store("r", r); + } - @Override - public String report() { - switch (type) { - case BLOCKBREAK: - break; - case BLOCKPLACE: - break; - case MOBKILL: - break; - default: - break; - } - return null; - } - - @EventHandler - public void mobKilled(EntityDeathEvent event) { - if (type != ItemDropType.MOBKILL) return; - dB.echoDebug("...checking kill"); - if (event.getEntity().getKiller() != player.getPlayerEntity()) return; - dB.echoDebug("...killed by player"); - if (event.getEntity().getType() != mob) return; - dB.echoDebug("...proper mob"); - if (location != null) { - if (location.distance(player.getPlayerEntity().getLocation()) > radius ) return; - } - dB.echoDebug("...within range"); - if (region != null) { - if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; - } - dB.echoDebug("...within region"); - - dB.echoDebug("...trying to drop item"); - if (Utilities.getRandom().nextInt(101) < dropRate) { - dB.echoDebug("...item should drop now"); - event.getEntity().getWorld().dropItem(event.getEntity().getLocation(), item); - qtyDropped++; - dB.echoDebug("...item dropped"); - check(); - } - } - - @EventHandler - public void blockMined(BlockBreakEvent event) { - if (type != ItemDropType.BLOCKBREAK) return; - dB.echoDebug("...checking blockbreakevent"); - if (event.getPlayer() != player.getPlayerEntity()) return; - dB.echoDebug("...mined by player"); - if (event.getBlock().getType() != block) return; - dB.echoDebug("...proper block mined"); - if (location != null) { - if (location.distance(player.getPlayerEntity().getLocation()) > radius ) return; - } - dB.echoDebug("...within range"); - if (region != null) { - if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; - } - dB.echoDebug("...within region"); - - if (Utilities.getRandom().nextInt(101) < dropRate) { - event.getBlock().getWorld().dropItem(event.getBlock().getLocation(), item); - qtyDropped++; - dB.echoDebug("...item dropped"); - check(); - } - } - - @EventHandler - public void blockPlaced(BlockPlaceEvent event) { - if (type != ItemDropType.BLOCKPLACE) return; - dB.echoDebug("...checking blockplaceevent"); - if (event.getPlayer() != player.getPlayerEntity()) return; - dB.echoDebug("...placed by player"); - if (event.getBlock().getType() != block) return; - dB.echoDebug("...proper block placed"); - if (location != null) { - if (location.distance(player.getPlayerEntity().getLocation()) > radius ) return; - } - dB.echoDebug("...within range"); - if (region != null) { - if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; - } - dB.echoDebug("...within region"); - - if (Utilities.getRandom().nextInt(101) < dropRate) { - event.getBlock().getWorld().dropItem(event.getBlock().getLocation(), item); - qtyDropped++; - dB.echoDebug("...item dropped"); - check(); - } - } - - private void check() { - dB.echoDebug(qtyDropped + "/" + quantity + " dropped"); - if (quantity == qtyDropped) { - finish(); - } - } + @Override + public String report() { + switch (type) { + case BLOCKBREAK: + break; + case BLOCKPLACE: + break; + case MOBKILL: + break; + default: + break; + } + return null; + } + + @EventHandler + public void mobKilled(EntityDeathEvent event) { + if (type != ItemDropType.MOBKILL) return; + dB.echoDebug("...checking kill"); + if (event.getEntity().getKiller() != player.getPlayerEntity()) return; + dB.echoDebug("...killed by player"); + if (event.getEntity().getType() != mob) return; + dB.echoDebug("...proper mob"); + if (location != null) { + if (location.distance(player.getPlayerEntity().getLocation()) > radius ) return; + } + dB.echoDebug("...within range"); + if (region != null) { + if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; + } + dB.echoDebug("...within region"); + + dB.echoDebug("...trying to drop item"); + if (Utilities.getRandom().nextInt(101) < dropRate) { + dB.echoDebug("...item should drop now"); + event.getEntity().getWorld().dropItem(event.getEntity().getLocation(), item); + qtyDropped++; + dB.echoDebug("...item dropped"); + check(); + } + } + + @EventHandler + public void blockMined(BlockBreakEvent event) { + if (type != ItemDropType.BLOCKBREAK) return; + dB.echoDebug("...checking blockbreakevent"); + if (event.getPlayer() != player.getPlayerEntity()) return; + dB.echoDebug("...mined by player"); + if (event.getBlock().getType() != block) return; + dB.echoDebug("...proper block mined"); + if (location != null) { + if (location.distance(player.getPlayerEntity().getLocation()) > radius ) return; + } + dB.echoDebug("...within range"); + if (region != null) { + if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; + } + dB.echoDebug("...within region"); + + if (Utilities.getRandom().nextInt(101) < dropRate) { + event.getBlock().getWorld().dropItem(event.getBlock().getLocation(), item); + qtyDropped++; + dB.echoDebug("...item dropped"); + check(); + } + } + + @EventHandler + public void blockPlaced(BlockPlaceEvent event) { + if (type != ItemDropType.BLOCKPLACE) return; + dB.echoDebug("...checking blockplaceevent"); + if (event.getPlayer() != player.getPlayerEntity()) return; + dB.echoDebug("...placed by player"); + if (event.getBlock().getType() != block) return; + dB.echoDebug("...proper block placed"); + if (location != null) { + if (location.distance(player.getPlayerEntity().getLocation()) > radius ) return; + } + dB.echoDebug("...within range"); + if (region != null) { + if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; + } + dB.echoDebug("...within region"); + + if (Utilities.getRandom().nextInt(101) < dropRate) { + event.getBlock().getWorld().dropItem(event.getBlock().getLocation(), item); + qtyDropped++; + dB.echoDebug("...item dropped"); + check(); + } + } + + private void check() { + dB.echoDebug(qtyDropped + "/" + quantity + " dropped"); + if (quantity == qtyDropped) { + finish(); + } + } } diff --git a/src/main/java/net/aufdemrand/denizen/listeners/core/ItemDropListenerType.java b/src/main/java/net/aufdemrand/denizen/listeners/core/ItemDropListenerType.java index ab08c47e7a..291d16a2dd 100644 --- a/src/main/java/net/aufdemrand/denizen/listeners/core/ItemDropListenerType.java +++ b/src/main/java/net/aufdemrand/denizen/listeners/core/ItemDropListenerType.java @@ -3,13 +3,13 @@ import net.aufdemrand.denizen.listeners.AbstractListenerType; public class ItemDropListenerType extends AbstractListenerType { - - enum ItemDropType { MOBKILL, BLOCKBREAK, BLOCKPLACE } - - @Override - public void onEnable() { - // TODO Auto-generated method stub - - } + + enum ItemDropType { MOBKILL, BLOCKBREAK, BLOCKPLACE } + + @Override + public void onEnable() { + // TODO Auto-generated method stub + + } } diff --git a/src/main/java/net/aufdemrand/denizen/listeners/core/ItemListenerInstance.java b/src/main/java/net/aufdemrand/denizen/listeners/core/ItemListenerInstance.java index c6e653f973..823ba6c75d 100644 --- a/src/main/java/net/aufdemrand/denizen/listeners/core/ItemListenerInstance.java +++ b/src/main/java/net/aufdemrand/denizen/listeners/core/ItemListenerInstance.java @@ -26,203 +26,203 @@ public class ItemListenerInstance extends AbstractListener implements Listener { - ItemType type = null; - List items = new ArrayList(); - int quantity = 0; - int currentItems = 0; - Server server = Bukkit.getServer();; - String region = null; - - @Override - public void onBuild(List args) { -// for (String arg : args) { -// if (aH.matchesValueArg ("TYPE", arg, ArgumentType.Custom)) { -// try { -// this.type = ItemType.valueOf(aH.getStringFrom(arg).toUpperCase()); -// dB.echoDebug(Messages.DEBUG_SET_TYPE, this.type.name()); -// } catch (Exception e) { dB.echoError("Invalid ItemType!"); } -// } + ItemType type = null; + List items = new ArrayList(); + int quantity = 0; + int currentItems = 0; + Server server = Bukkit.getServer();; + String region = null; + + @Override + public void onBuild(List args) { +// for (String arg : args) { +// if (aH.matchesValueArg ("TYPE", arg, ArgumentType.Custom)) { +// try { +// this.type = ItemType.valueOf(aH.getStringFrom(arg).toUpperCase()); +// dB.echoDebug(Messages.DEBUG_SET_TYPE, this.type.name()); +// } catch (Exception e) { dB.echoError("Invalid ItemType!"); } +// } // -// else if (aH.matchesQuantity(arg)) { -// this.quantity = aH.getIntegerFrom(arg); -// dB.echoDebug(Messages.DEBUG_SET_QUANTITY, String.valueOf(quantity)); -// } +// else if (aH.matchesQuantity(arg)) { +// this.quantity = aH.getIntegerFrom(arg); +// dB.echoDebug(Messages.DEBUG_SET_QUANTITY, String.valueOf(quantity)); +// } // -// else if (aH.matchesValueArg("ITEMS, ITEM", arg, ArgumentType.Custom)) { -// for (String thisItem : aH.getListFrom(arg.toUpperCase())) -// if (server.getRecipesFor(new ItemStack(Material.matchMaterial(thisItem))) != null) { -// items.add(thisItem); -// } else dB.echoError("..." + thisItem + " is not a craftable item"); -// dB.echoDebug("...set ITEMS.: " + Arrays.toString(items.toArray())); -// } else if (aH.matchesValueArg("REGION", arg, ArgumentType.String)) { -// region = aH.getStringFrom(arg); -// dB.echoDebug("...region set: " + region); -// } -// } +// else if (aH.matchesValueArg("ITEMS, ITEM", arg, ArgumentType.Custom)) { +// for (String thisItem : aH.getListFrom(arg.toUpperCase())) +// if (server.getRecipesFor(new ItemStack(Material.matchMaterial(thisItem))) != null) { +// items.add(thisItem); +// } else dB.echoError("..." + thisItem + " is not a craftable item"); +// dB.echoDebug("...set ITEMS.: " + Arrays.toString(items.toArray())); +// } else if (aH.matchesValueArg("REGION", arg, ArgumentType.String)) { +// region = aH.getStringFrom(arg); +// dB.echoDebug("...region set: " + region); +// } +// } // -// if (items.isEmpty() && !type.name().equalsIgnoreCase("FISH")) { -// dB.echoError("Missing ITEMS argument!"); -// cancel(); -// } +// if (items.isEmpty() && !type.name().equalsIgnoreCase("FISH")) { +// dB.echoError("Missing ITEMS argument!"); +// cancel(); +// } // -// if (type == null) { -// dB.echoError("Missing TYPE argument! Valid: CRAFT, SMELT, FISH"); -// cancel(); -// } - } - - public void increment(String object, int amount) - { - currentItems = currentItems + amount; - dB.echoDebug(ChatColor.YELLOW + "// " + player.getName() + " " + - type.toString().toLowerCase() + "ed " + amount + " " + object + "."); - check(); - } - - @EventHandler - public void listenItem(InventoryClickEvent event) - { - // Proceed if the slot clicked is a RESULT slot and the player is the right one - if (event.getSlotType().toString() == "RESULT" - && event.getWhoClicked() == player.getPlayerEntity()) - { - // Put the type of this inventory in a string and check if it matches the - // listener's type - String inventoryType = event.getInventory().getType().toString(); +// if (type == null) { +// dB.echoError("Missing TYPE argument! Valid: CRAFT, SMELT, FISH"); +// cancel(); +// } + } + + public void increment(String object, int amount) + { + currentItems = currentItems + amount; + dB.echoDebug(ChatColor.YELLOW + "// " + player.getName() + " " + + type.toString().toLowerCase() + "ed " + amount + " " + object + "."); + check(); + } + + @EventHandler + public void listenItem(InventoryClickEvent event) + { + // Proceed if the slot clicked is a RESULT slot and the player is the right one + if (event.getSlotType().toString() == "RESULT" + && event.getWhoClicked() == player.getPlayerEntity()) + { + // Put the type of this inventory in a string and check if it matches the + // listener's type + String inventoryType = event.getInventory().getType().toString(); if ((type == ItemType.CRAFT && (inventoryType == "CRAFTING" || inventoryType == "WORKBENCH")) || (type == ItemType.SMELT && inventoryType == "FURNACE")) { - if (region != null) - if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; - - // Get the item in the result slot as an ItemStack - final ItemStack item = new ItemStack(event.getCurrentItem()); - + if (region != null) + if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; + + // Get the item in the result slot as an ItemStack + final ItemStack item = new ItemStack(event.getCurrentItem()); + //if item isn't a required item, then return if (!items.contains(item.getType().toString()) - && !items.contains(item.getTypeId())) + && !items.contains(item.getTypeId())) return; - - if (event.isShiftClick()) - { - // Save the quantity of items of this type that the player had - // before the event took place - final int initialQty = new dInventory(player.getPlayerEntity().getInventory()).count(item, false); - - // Run a task 1 tick later, after the event has occurred, and - // see how many items of this type the player has then in the - // inventory - Bukkit.getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(), - new Runnable() - { - @Override - public void run() - { - int newQty = new dInventory(player.getPlayerEntity().getInventory()).count(item, false); - int difference = newQty - initialQty; - - // If any items were obtained (i.e. if shift click was - // used with the player's inventory not being full), - // increase the number of current items - if (difference > 0) - { - increment(item.getType().toString(), difference); - } - - } - }, 1); - } - else - { - // If shift click was not used, simply increase the current items - // by the quantity of the item in the result slot - increment(item.getType().toString(), item.getAmount()); - } - - } - } - } - - @EventHandler - public void listenFish(PlayerFishEvent event) - { - if (type == ItemType.FISH) - { - if (event.getPlayer() == player.getPlayerEntity()) - { - - if (region != null) - if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; - - if (event.getState().toString() == "CAUGHT_FISH") - { - increment("FISH", 1); - } - } - } - } - - @Override - public void onSave() { - try { - store("Type", type.name()); - store("Items", this.items); - store("Quantity Needed", this.quantity); - store("Quantity Done", this.currentItems); - store("Region", region); - } catch (Exception e) { - dB.echoError("Unable to save ITEM listener for '%s'!", player.getName()); - } - } - - @SuppressWarnings("unchecked") - @Override - public void onLoad() { - try { - type = ItemType.valueOf((String) get("Type")); - items = (List) (get("Items")); - quantity = (Integer) get("Quantity Needed"); - currentItems = (Integer) get("Quantity Done"); - region = (String) get("Region"); - } catch (Exception e) { - dB.echoError("Unable to load ITEM listener for '%s'!", player.getName()); - cancel(); - } - } - - @Override - public void onFinish() { - - } - - public void check() { - if (currentItems >= quantity) { - InventoryClickEvent.getHandlerList().unregister(this); - PlayerFishEvent.getHandlerList().unregister(this); - finish(); - } - } - - @Override - public void onCancel() { - - } - - @Override - public String report() { - return player.getName() + " current has quest listener '" + id - + "' active and must " + type.name() + " " + Arrays.toString(items.toArray()) - + " '(s). Current progress '" + currentItems + "/" + quantity + "'."; - } - - @Override - public void constructed() { - denizen.getServer().getPluginManager().registerEvents(this, denizen); - } - - @Override - public void deconstructed() { - InventoryClickEvent.getHandlerList().unregister(this); - } + + if (event.isShiftClick()) + { + // Save the quantity of items of this type that the player had + // before the event took place + final int initialQty = new dInventory(player.getPlayerEntity().getInventory()).count(item, false); + + // Run a task 1 tick later, after the event has occurred, and + // see how many items of this type the player has then in the + // inventory + Bukkit.getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(), + new Runnable() + { + @Override + public void run() + { + int newQty = new dInventory(player.getPlayerEntity().getInventory()).count(item, false); + int difference = newQty - initialQty; + + // If any items were obtained (i.e. if shift click was + // used with the player's inventory not being full), + // increase the number of current items + if (difference > 0) + { + increment(item.getType().toString(), difference); + } + + } + }, 1); + } + else + { + // If shift click was not used, simply increase the current items + // by the quantity of the item in the result slot + increment(item.getType().toString(), item.getAmount()); + } + + } + } + } + + @EventHandler + public void listenFish(PlayerFishEvent event) + { + if (type == ItemType.FISH) + { + if (event.getPlayer() == player.getPlayerEntity()) + { + + if (region != null) + if (!WorldGuardUtilities.inRegion(player.getPlayerEntity().getLocation(), region)) return; + + if (event.getState().toString() == "CAUGHT_FISH") + { + increment("FISH", 1); + } + } + } + } + + @Override + public void onSave() { + try { + store("Type", type.name()); + store("Items", this.items); + store("Quantity Needed", this.quantity); + store("Quantity Done", this.currentItems); + store("Region", region); + } catch (Exception e) { + dB.echoError("Unable to save ITEM listener for '%s'!", player.getName()); + } + } + + @SuppressWarnings("unchecked") + @Override + public void onLoad() { + try { + type = ItemType.valueOf((String) get("Type")); + items = (List) (get("Items")); + quantity = (Integer) get("Quantity Needed"); + currentItems = (Integer) get("Quantity Done"); + region = (String) get("Region"); + } catch (Exception e) { + dB.echoError("Unable to load ITEM listener for '%s'!", player.getName()); + cancel(); + } + } + + @Override + public void onFinish() { + + } + + public void check() { + if (currentItems >= quantity) { + InventoryClickEvent.getHandlerList().unregister(this); + PlayerFishEvent.getHandlerList().unregister(this); + finish(); + } + } + + @Override + public void onCancel() { + + } + + @Override + public String report() { + return player.getName() + " current has quest listener '" + id + + "' active and must " + type.name() + " " + Arrays.toString(items.toArray()) + + " '(s). Current progress '" + currentItems + "/" + quantity + "'."; + } + + @Override + public void constructed() { + denizen.getServer().getPluginManager().registerEvents(this, denizen); + } + + @Override + public void deconstructed() { + InventoryClickEvent.getHandlerList().unregister(this); + } } diff --git a/src/main/java/net/aufdemrand/denizen/listeners/core/ItemListenerType.java b/src/main/java/net/aufdemrand/denizen/listeners/core/ItemListenerType.java index 363f1431ba..ac0b0d1b5c 100644 --- a/src/main/java/net/aufdemrand/denizen/listeners/core/ItemListenerType.java +++ b/src/main/java/net/aufdemrand/denizen/listeners/core/ItemListenerType.java @@ -4,10 +4,10 @@ public class ItemListenerType extends AbstractListenerType { - public enum ItemType { CRAFT, SMELT, FISH } - - @Override - public void onEnable() { - - } + public enum ItemType { CRAFT, SMELT, FISH } + + @Override + public void onEnable() { + + } } diff --git a/src/main/java/net/aufdemrand/denizen/listeners/core/KillListenerType.java b/src/main/java/net/aufdemrand/denizen/listeners/core/KillListenerType.java index 066d4d9f93..094e609605 100644 --- a/src/main/java/net/aufdemrand/denizen/listeners/core/KillListenerType.java +++ b/src/main/java/net/aufdemrand/denizen/listeners/core/KillListenerType.java @@ -4,9 +4,9 @@ public class KillListenerType extends AbstractListenerType { - @Override - public void onEnable() { - // Nothing to do here. - } + @Override + public void onEnable() { + // Nothing to do here. + } } diff --git a/src/main/java/net/aufdemrand/denizen/listeners/core/TravelListenerInstance.java b/src/main/java/net/aufdemrand/denizen/listeners/core/TravelListenerInstance.java index feccde9f05..eb4327c73e 100644 --- a/src/main/java/net/aufdemrand/denizen/listeners/core/TravelListenerInstance.java +++ b/src/main/java/net/aufdemrand/denizen/listeners/core/TravelListenerInstance.java @@ -12,9 +12,7 @@ import net.aufdemrand.denizen.listeners.AbstractListener; import net.aufdemrand.denizen.objects.aH; -import net.aufdemrand.denizen.objects.aH.ArgumentType; import net.aufdemrand.denizen.utilities.debugging.dB; -import net.citizensnpcs.api.CitizensAPI; /** @@ -45,7 +43,7 @@ enum TravelType { DISTANCE, TOLOCATION, TONPC, TOCUBOID } // // The type of Travel // - private TravelType type; + private TravelType type; // // End point criteria @@ -164,7 +162,7 @@ public String report() { * This method will be called every time a player moves in the game. It's * used to determine if a player has satisfied a certain travel goal. * - * @param event The player movement event. + * @param event The player movement event. */ @EventHandler public void walking(PlayerMoveEvent event) { diff --git a/src/main/java/net/aufdemrand/denizen/listeners/core/TravelListenerType.java b/src/main/java/net/aufdemrand/denizen/listeners/core/TravelListenerType.java index 1280ba3f1f..5eb0d2260d 100644 --- a/src/main/java/net/aufdemrand/denizen/listeners/core/TravelListenerType.java +++ b/src/main/java/net/aufdemrand/denizen/listeners/core/TravelListenerType.java @@ -3,10 +3,10 @@ import net.aufdemrand.denizen.listeners.AbstractListenerType; public class TravelListenerType extends AbstractListenerType { - - @Override - public void onEnable() { - // nothing to do here - } + + @Override + public void onEnable() { + // nothing to do here + } } diff --git a/src/main/java/net/aufdemrand/denizen/npc/traits/AssignmentTrait.java b/src/main/java/net/aufdemrand/denizen/npc/traits/AssignmentTrait.java index 7a72b12654..58e0887f17 100644 --- a/src/main/java/net/aufdemrand/denizen/npc/traits/AssignmentTrait.java +++ b/src/main/java/net/aufdemrand/denizen/npc/traits/AssignmentTrait.java @@ -195,7 +195,7 @@ public void onHit(EntityDamageByEntityEvent event) { if (event.getEntity() instanceof LivingEntity) { if (((LivingEntity) event.getEntity()).getHealth() - event.getDamage() <= 0) { DenizenAPI.getDenizenNPC(npc).action("kill", player); - DenizenAPI.getDenizenNPC(npc).action("kill of " + event.getEntityType().name(), player); + DenizenAPI.getDenizenNPC(npc).action("kill of " + event.getEntityType().name(), player); } } diff --git a/src/main/java/net/aufdemrand/denizen/npc/traits/CreatorTrait.java b/src/main/java/net/aufdemrand/denizen/npc/traits/CreatorTrait.java index 6284e99261..4e6c9a931f 100644 --- a/src/main/java/net/aufdemrand/denizen/npc/traits/CreatorTrait.java +++ b/src/main/java/net/aufdemrand/denizen/npc/traits/CreatorTrait.java @@ -7,25 +7,25 @@ import net.citizensnpcs.api.trait.trait.Owner; public class CreatorTrait extends Trait { - - String creator = null; - List created = new ArrayList(); - - @Override - public void onAttach() { - creator = npc.getTrait(Owner.class).getOwner(); - } - - public String getCreator() { - return creator; - } - - public List getCreated() { - return created; - } - - protected CreatorTrait() { - super("Creator"); - } + + String creator = null; + List created = new ArrayList(); + + @Override + public void onAttach() { + creator = npc.getTrait(Owner.class).getOwner(); + } + + public String getCreator() { + return creator; + } + + public List getCreated() { + return created; + } + + protected CreatorTrait() { + super("Creator"); + } } diff --git a/src/main/java/net/aufdemrand/denizen/npc/traits/FishingTrait.java b/src/main/java/net/aufdemrand/denizen/npc/traits/FishingTrait.java index 55c67f4f94..c75c4410f4 100644 --- a/src/main/java/net/aufdemrand/denizen/npc/traits/FishingTrait.java +++ b/src/main/java/net/aufdemrand/denizen/npc/traits/FishingTrait.java @@ -25,57 +25,57 @@ public class FishingTrait extends Trait { - @Persist("fishing") + @Persist("fishing") private boolean fishing = false; - @Persist("catch fish") + @Persist("catch fish") private boolean catchFish = false; - - @Persist("fishing spot") - private Location fishingLocation = null; - - ArrayList available = new ArrayList(); - EntityHuman eh = null; - WorldServer nmsworld = null; - Location fishingSpot = null; - EntityFishingHook fishHook = null; - EntityItem fish = null; - - @Persist("catch chance") - int catchPercent = 65; - - int reelCount = 100; - int castCount = 0; - - @Override - public void run() { - reelCount++; - castCount++; - - if(fish != null) - if(fish.getBukkitEntity().getLocation().distance(npc.getBukkitEntity().getLocation())<3) { - try{ - fish.getBukkitEntity().remove(); - } catch(Exception e) { } - } - - if(reelCount == 400) { - reel(); - reelCount = 0; - castCount = 325; - } - - if(castCount == 400) { - cast(); - castCount = 0; - } - } - - @Override - public void onSpawn() { - eh = ((CraftPlayer) npc.getBukkitEntity()).getHandle(); - nmsworld = ((CraftWorld) npc.getBukkitEntity().getWorld()).getHandle(); - } - + + @Persist("fishing spot") + private Location fishingLocation = null; + + ArrayList available = new ArrayList(); + EntityHuman eh = null; + WorldServer nmsworld = null; + Location fishingSpot = null; + EntityFishingHook fishHook = null; + EntityItem fish = null; + + @Persist("catch chance") + int catchPercent = 65; + + int reelCount = 100; + int castCount = 0; + + @Override + public void run() { + reelCount++; + castCount++; + + if(fish != null) + if(fish.getBukkitEntity().getLocation().distance(npc.getBukkitEntity().getLocation())<3) { + try{ + fish.getBukkitEntity().remove(); + } catch(Exception e) { } + } + + if(reelCount == 400) { + reel(); + reelCount = 0; + castCount = 325; + } + + if(castCount == 400) { + cast(); + castCount = 0; + } + } + + @Override + public void onSpawn() { + eh = ((CraftPlayer) npc.getBukkitEntity()).getHandle(); + nmsworld = ((CraftWorld) npc.getBukkitEntity().getWorld()).getHandle(); + } + /** * Makes the NPC fish at the specified location * @@ -102,24 +102,24 @@ public void stopFishing() { fishing = false; } - /** - * Makes the NPC fish in the nearest water - * - * TODO Needs logic for handling that. - */ - public void startFishing() { - fishing = true; - fishingLocation = npc.getBukkitEntity().getLocation(); - return; - } - - private void cast() { - DenizenAPI.getDenizenNPC(npc).action("cast fishing rod", null); - - if(fishingLocation == null) { - dB.echoError("Fishing location not found!"); - return; - } + /** + * Makes the NPC fish in the nearest water + * + * TODO Needs logic for handling that. + */ + public void startFishing() { + fishing = true; + fishingLocation = npc.getBukkitEntity().getLocation(); + return; + } + + private void cast() { + DenizenAPI.getDenizenNPC(npc).action("cast fishing rod", null); + + if(fishingLocation == null) { + dB.echoError("Fishing location not found!"); + return; + } double v = 34; double g = 20; @@ -158,12 +158,12 @@ private void cast() { theHook.setShooter(npc.getBukkitEntity()); theHook.setVelocity(victor); - PlayerAnimation.ARM_SWING.play((Player) npc.getBukkitEntity()); + PlayerAnimation.ARM_SWING.play((Player) npc.getBukkitEntity()); } - - private void reel() { - DenizenAPI.getDenizenNPC(npc).action("reel in fishing rod", null); - + + private void reel() { + DenizenAPI.getDenizenNPC(npc).action("reel in fishing rod", null); + int chance = (int)(Math.random()*100); try{ @@ -189,30 +189,30 @@ private void reel() { } PlayerAnimation.ARM_SWING.play((Player) npc.getBukkitEntity()); - } - - /** - * Checks if the NPC is currently fishing - * - * @return boolean - */ - public boolean isFishing() { - return fishing; - } - - /** - * Gets the location the NPC is casting to - * Returns null if the NPC isn't fishing - * - * @return Location - */ - public Location getFishingLocation() { - return fishingLocation; - } - - public FishingTrait() { - super("fishing"); - } + } + + /** + * Checks if the NPC is currently fishing + * + * @return boolean + */ + public boolean isFishing() { + return fishing; + } + + /** + * Gets the location the NPC is casting to + * Returns null if the NPC isn't fishing + * + * @return Location + */ + public Location getFishingLocation() { + return fishingLocation; + } + + public FishingTrait() { + super("fishing"); + } public static Double launchAngle(Location from, Location to, double v, double elev, double g){ Vector victor = from.clone().subtract(to).toVector(); @@ -245,11 +245,11 @@ public static Vector normalizeVector(Vector victor){ } public void setCatchFish(Boolean catchFish) { - this.catchFish = catchFish; + this.catchFish = catchFish; } public void setCatchPercent(int catchPercent) { - this.catchPercent = catchPercent; + this.catchPercent = catchPercent; } } diff --git a/src/main/java/net/aufdemrand/denizen/npc/traits/HealthTrait.java b/src/main/java/net/aufdemrand/denizen/npc/traits/HealthTrait.java index 4b17ddd12d..4dcd1fddad 100644 --- a/src/main/java/net/aufdemrand/denizen/npc/traits/HealthTrait.java +++ b/src/main/java/net/aufdemrand/denizen/npc/traits/HealthTrait.java @@ -255,7 +255,7 @@ else if (event instanceof EntityDamageByBlockEvent) // return null. Uncomment it once the bug is fixed. // DenizenAPI.getDenizenNPC(npc).action("death by " + - // ((EntityDamageByBlockEvent) event).getDamager().getType().name(), null); + // ((EntityDamageByBlockEvent) event).getDamager().getType().name(), null); } DenizenAPI.getDenizenNPC(npc).action("death", player); diff --git a/src/main/java/net/aufdemrand/denizen/npc/traits/InvisibleTrait.java b/src/main/java/net/aufdemrand/denizen/npc/traits/InvisibleTrait.java index 4f3a4eac00..289e8dadf1 100644 --- a/src/main/java/net/aufdemrand/denizen/npc/traits/InvisibleTrait.java +++ b/src/main/java/net/aufdemrand/denizen/npc/traits/InvisibleTrait.java @@ -21,7 +21,7 @@ public InvisibleTrait() { } public void setInvisible(boolean invisible) { - + this.invisible = invisible; if (invisible) setInvisible(); else if (npc.isSpawned()) diff --git a/src/main/java/net/aufdemrand/denizen/npc/traits/NameplateTrait.java b/src/main/java/net/aufdemrand/denizen/npc/traits/NameplateTrait.java index bcf96b9af4..4bb90f6b60 100644 --- a/src/main/java/net/aufdemrand/denizen/npc/traits/NameplateTrait.java +++ b/src/main/java/net/aufdemrand/denizen/npc/traits/NameplateTrait.java @@ -1,10 +1,8 @@ package net.aufdemrand.denizen.npc.traits; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import net.aufdemrand.denizen.utilities.DenizenAPI; @@ -12,7 +10,6 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.persistence.Persist; import net.citizensnpcs.api.trait.Trait; -import net.citizensnpcs.api.util.DataKey; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -36,17 +33,17 @@ * including the color codes!

*/ public class NameplateTrait extends Trait implements Listener { - private final static String DEFAULT_KEY = "_default_"; + private final static String DEFAULT_KEY = "_default_"; @Persist("text") private String text = null; @Persist(value="colors", collectionType=ConcurrentHashMap.class) - private Map colors = new ConcurrentHashMap(8, 0.9f, 1); + private Map colors = new ConcurrentHashMap(8, 0.9f, 1); - public NameplateTrait() { - super("nameplate"); - } + public NameplateTrait() { + super("nameplate"); + } @Override public void onSpawn() { @@ -62,9 +59,9 @@ public void run() { }, 2); } - if(getColor() != null ) { - refreshTag( getNPC() ); - } + if(getColor() != null ) { + refreshTag( getNPC() ); + } } @Override @@ -74,123 +71,123 @@ public void onDespawn() { } public void setColor(ChatColor color) { - this.setColor(color, DEFAULT_KEY); + this.setColor(color, DEFAULT_KEY); } - public void setColor(ChatColor color, String player) { - this.colors.put(player, color.name()); - refreshTag( getNPC() ); - } - - /** - * Returns the {@link ChatColor} prefixed to the nameplate - * - * @return The stored {@link ChatColor} - */ - public ChatColor getColor() { - try { + public void setColor(ChatColor color, String player) { + this.colors.put(player, color.name()); + refreshTag( getNPC() ); + } + + /** + * Returns the {@link ChatColor} prefixed to the nameplate + * + * @return The stored {@link ChatColor} + */ + public ChatColor getColor() { + try { return ChatColor.valueOf(colors.get(DEFAULT_KEY)); } catch (Exception e) { return ChatColor.YELLOW; } - } - - /** - * Returns the {@link ChatColor} prefixed to the nameplate for a specific - * player. - * - * @param player The player name - * @return The stored {@link ChatColor} for the specific player - */ - public ChatColor getColor(String player) { - if(!colors.containsKey(player)) return getColor(); - else return ChatColor.valueOf(colors.get(player)); - } - - /** - * Returns true if a color has been set - * - * @return True if set, otherwise false - */ - public boolean hasColor() { - return getColor() != null; - } - - /** - * Returns true if a color has been set for this player - * - * @param player The player name to check - * @return True if set, otherwise false - */ - public boolean hasColor(String player) { - return getColor(player) != null; - } - - /** - * Retrieve the trimmed nameplate including the set color (max. 16 chars). - * - * @return The trimmed nameplate including color - */ - public String getTrimmedTag() { - return getTrimmedTag(DEFAULT_KEY); - } - - /** - * Retrieve the trimmed nameplate including the set color (max. 16 chars) for - * the specific player. - * - * @param player The player name - * @return The trimmed nameplate including color - */ - public String getTrimmedTag(String player) { - String tag = getNPC().getName(); - ChatColor c = getColor(player); - - if(c != null) tag = c + tag; - if(tag.length() > 16) tag = tag.substring(0, 16); - - return tag; - } - - public void refreshTag(NPC npc) { - if( Depends.protocolManager == null || !npc.isSpawned() ) return; - - int maxDistance = Bukkit.getServer().getViewDistance() * 16; - List viewers = new ArrayList(); - - for (Player p : getPlayersInRadius(npc, maxDistance)) { - if( p.getEntityId() == npc.getBukkitEntity().getEntityId() ) continue; - - viewers.add(p); - } - - refreshTag(npc, viewers); - } - - private void refreshTag(NPC npc, List players) { - Entity npcEntity = npc.getBukkitEntity(); - - if(npcEntity != null) { - Depends.protocolManager.updateEntity(npcEntity, players); - } - } - - private List getPlayersInRadius( NPC npc, int distance ) { - List players = new ArrayList(); - int dSquared = distance * distance; - - Location loc = npc.getBukkitEntity().getLocation(); - World world = npc.getBukkitEntity().getWorld(); - - for ( Player p : Bukkit.getServer().getOnlinePlayers()) { - if( p.getWorld() != world) continue; - - if( p.getLocation().distanceSquared(loc) <= dSquared) { - players.add(p); - } - } - - return players; - } - - - + } + + /** + * Returns the {@link ChatColor} prefixed to the nameplate for a specific + * player. + * + * @param player The player name + * @return The stored {@link ChatColor} for the specific player + */ + public ChatColor getColor(String player) { + if(!colors.containsKey(player)) return getColor(); + else return ChatColor.valueOf(colors.get(player)); + } + + /** + * Returns true if a color has been set + * + * @return True if set, otherwise false + */ + public boolean hasColor() { + return getColor() != null; + } + + /** + * Returns true if a color has been set for this player + * + * @param player The player name to check + * @return True if set, otherwise false + */ + public boolean hasColor(String player) { + return getColor(player) != null; + } + + /** + * Retrieve the trimmed nameplate including the set color (max. 16 chars). + * + * @return The trimmed nameplate including color + */ + public String getTrimmedTag() { + return getTrimmedTag(DEFAULT_KEY); + } + + /** + * Retrieve the trimmed nameplate including the set color (max. 16 chars) for + * the specific player. + * + * @param player The player name + * @return The trimmed nameplate including color + */ + public String getTrimmedTag(String player) { + String tag = getNPC().getName(); + ChatColor c = getColor(player); + + if(c != null) tag = c + tag; + if(tag.length() > 16) tag = tag.substring(0, 16); + + return tag; + } + + public void refreshTag(NPC npc) { + if( Depends.protocolManager == null || !npc.isSpawned() ) return; + + int maxDistance = Bukkit.getServer().getViewDistance() * 16; + List viewers = new ArrayList(); + + for (Player p : getPlayersInRadius(npc, maxDistance)) { + if( p.getEntityId() == npc.getBukkitEntity().getEntityId() ) continue; + + viewers.add(p); + } + + refreshTag(npc, viewers); + } + + private void refreshTag(NPC npc, List players) { + Entity npcEntity = npc.getBukkitEntity(); + + if(npcEntity != null) { + Depends.protocolManager.updateEntity(npcEntity, players); + } + } + + private List getPlayersInRadius( NPC npc, int distance ) { + List players = new ArrayList(); + int dSquared = distance * distance; + + Location loc = npc.getBukkitEntity().getLocation(); + World world = npc.getBukkitEntity().getWorld(); + + for ( Player p : Bukkit.getServer().getOnlinePlayers()) { + if( p.getWorld() != world) continue; + + if( p.getLocation().distanceSquared(loc) <= dSquared) { + players.add(p); + } + } + + return players; + } + + + } diff --git a/src/main/java/net/aufdemrand/denizen/npc/traits/NicknameTrait.java b/src/main/java/net/aufdemrand/denizen/npc/traits/NicknameTrait.java index 72eb145647..a380e66336 100644 --- a/src/main/java/net/aufdemrand/denizen/npc/traits/NicknameTrait.java +++ b/src/main/java/net/aufdemrand/denizen/npc/traits/NicknameTrait.java @@ -25,12 +25,12 @@ */ public class NicknameTrait extends Trait implements Listener { - @Persist("") + @Persist("") private String nickname = null; - public NicknameTrait() { - super("nickname"); - } + public NicknameTrait() { + super("nickname"); + } /** * Sets the nickname of this NPC. When setting, dScript TAGS @@ -39,9 +39,9 @@ public NicknameTrait() { * @param nickName the new nickname for this NPC * */ - public void setNickname(String nickName) { - this.nickname = nickName; - } + public void setNickname(String nickName) { + this.nickname = nickName; + } /** * Gets the current nickname of this NPC. This may include color codes. @@ -51,37 +51,37 @@ public void setNickname(String nickName) { * @return the nickname for this NPC * */ - public String getNickname() { - if (nickname == null || nickname.equals("")) return npc.getName(); + public String getNickname() { + if (nickname == null || nickname.equals("")) return npc.getName(); else return DenizenAPI.getCurrentInstance().tagManager() .tag(null, DenizenAPI.getDenizenNPC(npc), nickname, false); } - - /** - * Gets the current nickname of this NPC and strips out all text colors. - * To get the colored nickname use {@link #getNickname()}. - * - * @return The uncolored nickname for this NPC - */ - public String getUncoloredNickname() { - return ChatColor.stripColor( getNickname() ); - } + + /** + * Gets the current nickname of this NPC and strips out all text colors. + * To get the colored nickname use {@link #getNickname()}. + * + * @return The uncolored nickname for this NPC + */ + public String getUncoloredNickname() { + return ChatColor.stripColor( getNickname() ); + } /** * Removes the current nickname from the NPC. * */ - public void removeNickname() { - nickname = null; - } + public void removeNickname() { + nickname = null; + } /** * Checks if the NPC has a nickname set. * * @return true if NPC has a nickname */ - public boolean hasNickname() { - return (nickname != null); - } + public boolean hasNickname() { + return (nickname != null); + } } diff --git a/src/main/java/net/aufdemrand/denizen/npc/traits/ParticlesTrait.java b/src/main/java/net/aufdemrand/denizen/npc/traits/ParticlesTrait.java index 5f6471ed0e..26101f51be 100644 --- a/src/main/java/net/aufdemrand/denizen/npc/traits/ParticlesTrait.java +++ b/src/main/java/net/aufdemrand/denizen/npc/traits/ParticlesTrait.java @@ -14,180 +14,180 @@ import org.bukkit.entity.Wolf; public class ParticlesTrait extends Trait { - - public enum EffectType { NONE, SMOKE, FLAME, ENDER, POTBREAK, HEART, POTION, EXPLOSION } - - //DataWatcher dw; - //EntityLiving el; - - Denizen denizen = DenizenAPI.getCurrentInstance(); - World world; - - @Persist("effect type") - EffectType effectType = EffectType.NONE; - - @Persist("particle delay") - int wait = 10; - - @Persist("dense") - Boolean dense = false; - - int counter = 0; - //int c = 0; - int tempcounter = 0; - - @Override - public void run() { - if (world == null) { - return; - } - - if (effectType == null) { - effectType = EffectType.NONE; - } - - if (tempcounter > 20) { - dB.log("current effect: " + effectType.name()); - } - counter++; - - switch (effectType) { - case NONE: - break; - case FLAME: - if (counter > wait) { - playFlameEffect(); - //dB.log("playing flame"); - counter = 0; - } - break; - case ENDER: - if (counter > wait) { - playEnderEffect(); - //dB.log("playing ender"); - counter = 0; - } - case SMOKE: - if (counter > wait) { - playSmokeEffect(); - //dB.log("playing smoke"); - counter = 0; - } - case POTBREAK: - if (counter > wait) { - playPotionBreakEffect(); - //dB.log("playing potion break"); - counter = 0; - } - break; - case POTION: - /* + + public enum EffectType { NONE, SMOKE, FLAME, ENDER, POTBREAK, HEART, POTION, EXPLOSION } + + //DataWatcher dw; + //EntityLiving el; + + Denizen denizen = DenizenAPI.getCurrentInstance(); + World world; + + @Persist("effect type") + EffectType effectType = EffectType.NONE; + + @Persist("particle delay") + int wait = 10; + + @Persist("dense") + Boolean dense = false; + + int counter = 0; + //int c = 0; + int tempcounter = 0; + + @Override + public void run() { + if (world == null) { + return; + } + + if (effectType == null) { + effectType = EffectType.NONE; + } + + if (tempcounter > 20) { + dB.log("current effect: " + effectType.name()); + } + counter++; + + switch (effectType) { + case NONE: + break; + case FLAME: + if (counter > wait) { + playFlameEffect(); + //dB.log("playing flame"); + counter = 0; + } + break; + case ENDER: + if (counter > wait) { + playEnderEffect(); + //dB.log("playing ender"); + counter = 0; + } + case SMOKE: + if (counter > wait) { + playSmokeEffect(); + //dB.log("playing smoke"); + counter = 0; + } + case POTBREAK: + if (counter > wait) { + playPotionBreakEffect(); + //dB.log("playing potion break"); + counter = 0; + } + break; + case POTION: + /* if (!el.effects.isEmpty()) { c = net.minecraft.server.v1_6_R2.PotionBrewer.a(el.effects.values()); } dw.watch(8, Integer.valueOf(c)); */ - break; - case HEART: - if (counter > wait) { - //dB.log("...playing heart effect"); - playHeartEffect(); - counter = 0; - } - break; - case EXPLOSION: - if (counter > wait) { - //dB.log("...playing explosion effect"); - playExplosionEffect(); - counter = 0; - } - break; - } - - - } - - @Override - public void onSpawn() { - //el = ((CraftLivingEntity)npc.getBukkitEntity()).getHandle(); - //dw = el.getDataWatcher(); - world = npc.getBukkitEntity().getWorld(); - } - - public void playFlameEffect() { - Location location = npc.getBukkitEntity().getLocation(); - world.playEffect(location, Effect.MOBSPAWNER_FLAMES, 0); - if (dense) world.playEffect(location.add(0, 1, 0), Effect.MOBSPAWNER_FLAMES, 0); - } - - public void playEnderEffect() { - Location location = npc.getBukkitEntity().getLocation(); - world.playEffect(location, Effect.ENDER_SIGNAL, 0); - if (dense) world.playEffect(location.add(0, 1, 0), Effect.ENDER_SIGNAL, 0); - } - - public void playPotionEffect() { - //dw.watch(8, Integer.valueOf(2)); - } - - public void playPotionBreakEffect() { - Location location = npc.getBukkitEntity().getLocation(); - world.playEffect(location, Effect.POTION_BREAK, 0); - if (dense) world.playEffect(location.add(0, 1, 0), Effect.POTION_BREAK, 0); - } - - public void playHeartEffect() { - Location location = npc.getBukkitEntity().getLocation(); - Wolf tempWolf = (Wolf) world.spawn(location, Wolf.class); - ((CraftWolf) tempWolf).getHandle().setInvisible(true); - tempWolf.playEffect(EntityEffect.WOLF_HEARTS); - if (dense) tempWolf.playEffect(EntityEffect.WOLF_HEARTS); - tempWolf.remove(); - } - - public void playSmokeEffect() { - Location location = npc.getBukkitEntity().getLocation(); - world.playEffect(location, Effect.SMOKE, 0); - world.playEffect(location, Effect.SMOKE, 1); - world.playEffect(location, Effect.SMOKE, 2); - world.playEffect(location, Effect.SMOKE, 3); - world.playEffect(location, Effect.SMOKE, 4); - world.playEffect(location, Effect.SMOKE, 5); - world.playEffect(location, Effect.SMOKE, 6); - world.playEffect(location, Effect.SMOKE, 7); - world.playEffect(location, Effect.SMOKE, 8); - if (dense) { - world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 0); - world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 1); - world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 2); - world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 3); - world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 4); - world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 5); - world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 6); - world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 7); - world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 8); - } - } + break; + case HEART: + if (counter > wait) { + //dB.log("...playing heart effect"); + playHeartEffect(); + counter = 0; + } + break; + case EXPLOSION: + if (counter > wait) { + //dB.log("...playing explosion effect"); + playExplosionEffect(); + counter = 0; + } + break; + } + + + } + + @Override + public void onSpawn() { + //el = ((CraftLivingEntity)npc.getBukkitEntity()).getHandle(); + //dw = el.getDataWatcher(); + world = npc.getBukkitEntity().getWorld(); + } + + public void playFlameEffect() { + Location location = npc.getBukkitEntity().getLocation(); + world.playEffect(location, Effect.MOBSPAWNER_FLAMES, 0); + if (dense) world.playEffect(location.add(0, 1, 0), Effect.MOBSPAWNER_FLAMES, 0); + } + + public void playEnderEffect() { + Location location = npc.getBukkitEntity().getLocation(); + world.playEffect(location, Effect.ENDER_SIGNAL, 0); + if (dense) world.playEffect(location.add(0, 1, 0), Effect.ENDER_SIGNAL, 0); + } + + public void playPotionEffect() { + //dw.watch(8, Integer.valueOf(2)); + } + + public void playPotionBreakEffect() { + Location location = npc.getBukkitEntity().getLocation(); + world.playEffect(location, Effect.POTION_BREAK, 0); + if (dense) world.playEffect(location.add(0, 1, 0), Effect.POTION_BREAK, 0); + } + + public void playHeartEffect() { + Location location = npc.getBukkitEntity().getLocation(); + Wolf tempWolf = (Wolf) world.spawn(location, Wolf.class); + ((CraftWolf) tempWolf).getHandle().setInvisible(true); + tempWolf.playEffect(EntityEffect.WOLF_HEARTS); + if (dense) tempWolf.playEffect(EntityEffect.WOLF_HEARTS); + tempWolf.remove(); + } + + public void playSmokeEffect() { + Location location = npc.getBukkitEntity().getLocation(); + world.playEffect(location, Effect.SMOKE, 0); + world.playEffect(location, Effect.SMOKE, 1); + world.playEffect(location, Effect.SMOKE, 2); + world.playEffect(location, Effect.SMOKE, 3); + world.playEffect(location, Effect.SMOKE, 4); + world.playEffect(location, Effect.SMOKE, 5); + world.playEffect(location, Effect.SMOKE, 6); + world.playEffect(location, Effect.SMOKE, 7); + world.playEffect(location, Effect.SMOKE, 8); + if (dense) { + world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 0); + world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 1); + world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 2); + world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 3); + world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 4); + world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 5); + world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 6); + world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 7); + world.playEffect(location.add(0, 1, 0), Effect.SMOKE, 8); + } + } - public void playExplosionEffect() { - Location location = npc.getBukkitEntity().getLocation(); - world.createExplosion(location, 0); - } - - public void setEffect(String effectType) { - this.effectType = EffectType.valueOf(effectType.toUpperCase()); - } - - public void setWait(Integer ticks) { - wait = ticks; - } - - public ParticlesTrait() { - super("particles"); - } - - public void setDense (Boolean dense) { - this.dense = dense; - } + public void playExplosionEffect() { + Location location = npc.getBukkitEntity().getLocation(); + world.createExplosion(location, 0); + } + + public void setEffect(String effectType) { + this.effectType = EffectType.valueOf(effectType.toUpperCase()); + } + + public void setWait(Integer ticks) { + wait = ticks; + } + + public ParticlesTrait() { + super("particles"); + } + + public void setDense (Boolean dense) { + this.dense = dense; + } } diff --git a/src/main/java/net/aufdemrand/denizen/npc/traits/SittingTrait.java b/src/main/java/net/aufdemrand/denizen/npc/traits/SittingTrait.java index bc798f2716..fa83e4d539 100644 --- a/src/main/java/net/aufdemrand/denizen/npc/traits/SittingTrait.java +++ b/src/main/java/net/aufdemrand/denizen/npc/traits/SittingTrait.java @@ -16,101 +16,101 @@ import org.bukkit.event.block.BlockBreakEvent; public class SittingTrait extends Trait implements Listener { - - @Persist("sitting") + + @Persist("sitting") private boolean sitting = false; - - @Persist("chair location") - private Location chairLocation = null; - - EntityHuman eh = null; - - @Override - public void run() { - if (eh == null || chairLocation == null) return; - if (!Utilities.checkLocation(npc.getBukkitEntity(), chairLocation, 1)) stand(); - } - - @Override - public void onSpawn() { - eh = ((CraftPlayer) npc.getBukkitEntity()).getHandle(); - if (sitting) sit(); - } - - /** - * Makes the NPC sit - */ - public void sit() { - DenizenAPI.getDenizenNPC(npc).action("sit", null); + + @Persist("chair location") + private Location chairLocation = null; + + EntityHuman eh = null; + + @Override + public void run() { + if (eh == null || chairLocation == null) return; + if (!Utilities.checkLocation(npc.getBukkitEntity(), chairLocation, 1)) stand(); + } + + @Override + public void onSpawn() { + eh = ((CraftPlayer) npc.getBukkitEntity()).getHandle(); + if (sitting) sit(); + } + + /** + * Makes the NPC sit + */ + public void sit() { + DenizenAPI.getDenizenNPC(npc).action("sit", null); - if (npc.getBukkitEntity().getType() != EntityType.PLAYER) { - return; - } + if (npc.getBukkitEntity().getType() != EntityType.PLAYER) { + return; + } - ((EntityPlayer) eh).getDataWatcher().watch(0, Byte.valueOf((byte) 0x04)); + ((EntityPlayer) eh).getDataWatcher().watch(0, Byte.valueOf((byte) 0x04)); - sitting = true; - chairLocation = npc.getBukkitEntity().getLocation(); - return; - } - - /** - * Makes the NPC sit a the specified location - * - * @param location - */ - public void sit(Location location) { - DenizenAPI.getDenizenNPC(npc).action("sit", null); + sitting = true; + chairLocation = npc.getBukkitEntity().getLocation(); + return; + } + + /** + * Makes the NPC sit a the specified location + * + * @param location + */ + public void sit(Location location) { + DenizenAPI.getDenizenNPC(npc).action("sit", null); - if (npc.getBukkitEntity().getType() != EntityType.PLAYER) { - return; - } - - /* - * Teleport NPC to the location before - * sending the sit packet to the clients. - */ - eh.getBukkitEntity().teleport(location.add(0.5, 0, 0.5)); - dB.echoDebug("...NPC moved to chair"); - - ((EntityPlayer) eh).getDataWatcher().watch(0, Byte.valueOf((byte) 0x04)); - - sitting = true; - chairLocation = location; - } - - /** - * Makes the NPC stand - */ - public void stand() { - DenizenAPI.getDenizenNPC(npc).action("stand", null); + if (npc.getBukkitEntity().getType() != EntityType.PLAYER) { + return; + } + + /* + * Teleport NPC to the location before + * sending the sit packet to the clients. + */ + eh.getBukkitEntity().teleport(location.add(0.5, 0, 0.5)); + dB.echoDebug("...NPC moved to chair"); + + ((EntityPlayer) eh).getDataWatcher().watch(0, Byte.valueOf((byte) 0x04)); + + sitting = true; + chairLocation = location; + } + + /** + * Makes the NPC stand + */ + public void stand() { + DenizenAPI.getDenizenNPC(npc).action("stand", null); - - ((EntityPlayer) eh).getDataWatcher().watch(0, Byte.valueOf((byte) 0x00)); - - chairLocation = null; - sitting = false; - } - - /** - * Checks if the NPC is currently sitting - * - * @return boolean - */ - public boolean isSitting() { - return sitting; - } - - /** - * Gets the chair the NPC is sitting on - * Returns null if the NPC isnt sitting - * - * @return Location - */ - public Location getChair() { - return chairLocation; - } - + + ((EntityPlayer) eh).getDataWatcher().watch(0, Byte.valueOf((byte) 0x00)); + + chairLocation = null; + sitting = false; + } + + /** + * Checks if the NPC is currently sitting + * + * @return boolean + */ + public boolean isSitting() { + return sitting; + } + + /** + * Gets the chair the NPC is sitting on + * Returns null if the NPC isnt sitting + * + * @return Location + */ + public Location getChair() { + return chairLocation; + } + /** * If someone tries to break the poor @@ -119,14 +119,14 @@ public Location getChair() { */ @EventHandler(ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { - if (chairLocation == null) return; + if (chairLocation == null) return; if (event.getBlock().getLocation().equals(chairLocation)) { event.setCancelled(true); } } - - public SittingTrait() { - super("sitting"); - } + + public SittingTrait() { + super("sitting"); + } } diff --git a/src/main/java/net/aufdemrand/denizen/npc/traits/SleepingTrait.java b/src/main/java/net/aufdemrand/denizen/npc/traits/SleepingTrait.java index 909f00cb94..a03af68ccc 100644 --- a/src/main/java/net/aufdemrand/denizen/npc/traits/SleepingTrait.java +++ b/src/main/java/net/aufdemrand/denizen/npc/traits/SleepingTrait.java @@ -12,92 +12,92 @@ public class SleepingTrait extends Trait { - @Persist("sleeping") + @Persist("sleeping") private boolean sleeping = false; - - @Persist("bed location") - private Location bedLocation = null; - - @Override - public void run() { - if (npc == null || bedLocation == null) return; - - //if (npc.getBukkitEntity().getPassenger() == null && sitting) eh.mount(eh); - - if (!Utilities.checkLocation(npc.getBukkitEntity(), bedLocation, 1)) wakeUp(); - } - - /** - * Makes the NPC sleep - */ - public void toSleep() { - if (sleeping == true) { - return; - } - - PlayerAnimation.SLEEP.play((Player) npc.getBukkitEntity()); - - sleeping = true; - bedLocation = npc.getBukkitEntity().getLocation(); - return; - } - - /** - * Makes the NPC sleep a the specified location - * - * @param location - */ - public void toSleep(Location location) { - if (sleeping == true) { - return; - } - - /* - * Teleport NPC to the location before - * playing sleep animation. - */ - //TODO Adjust the .add() - npc.getBukkitEntity().teleport(location.add(0.5, 0, 0.5)); - - PlayerAnimation.SLEEP.play((Player) npc.getBukkitEntity()); - - sleeping = true; - bedLocation = location; - } - - /** - * Makes the NPC wake up - */ - public void wakeUp() { - if (sleeping == false) { - return; - } - - PlayerAnimation.STOP_SLEEPING.play((Player) npc.getBukkitEntity()); - - bedLocation = null; - sleeping = false; - } - - /** - * Checks if the NPC is currently sleeping - * - * @return boolean - */ - public boolean isSleeping() { - return sleeping; - } - - /** - * Gets the bed the NPC is sleeping on - * Returns null if the NPC isnt sleeping - * - * @return Location - */ - public Location getBed() { - return bedLocation; - } - + + @Persist("bed location") + private Location bedLocation = null; + + @Override + public void run() { + if (npc == null || bedLocation == null) return; + + //if (npc.getBukkitEntity().getPassenger() == null && sitting) eh.mount(eh); + + if (!Utilities.checkLocation(npc.getBukkitEntity(), bedLocation, 1)) wakeUp(); + } + + /** + * Makes the NPC sleep + */ + public void toSleep() { + if (sleeping == true) { + return; + } + + PlayerAnimation.SLEEP.play((Player) npc.getBukkitEntity()); + + sleeping = true; + bedLocation = npc.getBukkitEntity().getLocation(); + return; + } + + /** + * Makes the NPC sleep a the specified location + * + * @param location + */ + public void toSleep(Location location) { + if (sleeping == true) { + return; + } + + /* + * Teleport NPC to the location before + * playing sleep animation. + */ + //TODO Adjust the .add() + npc.getBukkitEntity().teleport(location.add(0.5, 0, 0.5)); + + PlayerAnimation.SLEEP.play((Player) npc.getBukkitEntity()); + + sleeping = true; + bedLocation = location; + } + + /** + * Makes the NPC wake up + */ + public void wakeUp() { + if (sleeping == false) { + return; + } + + PlayerAnimation.STOP_SLEEPING.play((Player) npc.getBukkitEntity()); + + bedLocation = null; + sleeping = false; + } + + /** + * Checks if the NPC is currently sleeping + * + * @return boolean + */ + public boolean isSleeping() { + return sleeping; + } + + /** + * Gets the bed the NPC is sleeping on + * Returns null if the NPC isnt sleeping + * + * @return Location + */ + public Location getBed() { + return bedLocation; + } + /** * If someone tries to break the poor @@ -106,14 +106,14 @@ public Location getBed() { */ @EventHandler(ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { - if (bedLocation == null) return; + if (bedLocation == null) return; if (event.getBlock().getLocation().equals(bedLocation)) { event.setCancelled(true); } } - - public SleepingTrait() { - super("sleeping"); - } + + public SleepingTrait() { + super("sleeping"); + } } diff --git a/src/main/java/net/aufdemrand/denizen/npc/traits/SneakingTrait.java b/src/main/java/net/aufdemrand/denizen/npc/traits/SneakingTrait.java index 5a6c3c32ad..b67dbc17c0 100644 --- a/src/main/java/net/aufdemrand/denizen/npc/traits/SneakingTrait.java +++ b/src/main/java/net/aufdemrand/denizen/npc/traits/SneakingTrait.java @@ -11,56 +11,56 @@ import org.bukkit.event.Listener; public class SneakingTrait extends Trait implements Listener { - - @Persist("sneaking") + + @Persist("sneaking") private boolean sneaking = false; - - EntityHuman eh = null; - - @Override - public void onSpawn() { - eh = ((CraftPlayer) npc.getBukkitEntity()).getHandle(); - if (sneaking) sneak(); - } - - /**x - * Makes the NPC sneak - */ - public void sneak() { - DenizenAPI.getDenizenNPC(npc).action("sneak", null); + + EntityHuman eh = null; + + @Override + public void onSpawn() { + eh = ((CraftPlayer) npc.getBukkitEntity()).getHandle(); + if (sneaking) sneak(); + } + + /**x + * Makes the NPC sneak + */ + public void sneak() { + DenizenAPI.getDenizenNPC(npc).action("sneak", null); - if (npc.getBukkitEntity().getType() != EntityType.PLAYER) { - return; - } + if (npc.getBukkitEntity().getType() != EntityType.PLAYER) { + return; + } - ((EntityPlayer) eh).getDataWatcher().watch(0, Byte.valueOf((byte) 0x02)); + ((EntityPlayer) eh).getDataWatcher().watch(0, Byte.valueOf((byte) 0x02)); - sneaking = true; - return; - } - - /** - * Makes the NPC stand - */ - public void stand() { - DenizenAPI.getDenizenNPC(npc).action("stand", null); - - ((EntityPlayer) eh).getDataWatcher().watch(0, Byte.valueOf((byte) 0x00)); - - sneaking = false; - } - - /** - * Checks if the NPC is currently sneaking - * - * @return boolean - */ - public boolean isSneaking() { - return sneaking; - } - - public SneakingTrait() { - super("sneaking"); - } + sneaking = true; + return; + } + + /** + * Makes the NPC stand + */ + public void stand() { + DenizenAPI.getDenizenNPC(npc).action("stand", null); + + ((EntityPlayer) eh).getDataWatcher().watch(0, Byte.valueOf((byte) 0x00)); + + sneaking = false; + } + + /** + * Checks if the NPC is currently sneaking + * + * @return boolean + */ + public boolean isSneaking() { + return sneaking; + } + + public SneakingTrait() { + super("sneaking"); + } } diff --git a/src/main/java/net/aufdemrand/denizen/npc/traits/TriggerTrait.java b/src/main/java/net/aufdemrand/denizen/npc/traits/TriggerTrait.java index 9494215712..dbfbb88cfb 100644 --- a/src/main/java/net/aufdemrand/denizen/npc/traits/TriggerTrait.java +++ b/src/main/java/net/aufdemrand/denizen/npc/traits/TriggerTrait.java @@ -58,7 +58,7 @@ public void onSpawn() { * @return */ public String toggleTrigger(String triggerName, boolean toggle) { - if (enabled.containsKey(triggerName.toUpperCase())) { + if (enabled.containsKey(triggerName.toUpperCase())) { enabled.put(triggerName.toUpperCase(), toggle); return triggerName + " trigger is now " + (toggle ? "enabled." : "disabled."); } diff --git a/src/main/java/net/aufdemrand/denizen/objects/aH.java b/src/main/java/net/aufdemrand/denizen/objects/aH.java index 10c2b97bdb..62477c191d 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/aH.java +++ b/src/main/java/net/aufdemrand/denizen/objects/aH.java @@ -65,7 +65,7 @@ public Argument(String string) { } public static Argument valueOf(String string) { - return new Argument(string); + return new Argument(string); } public boolean hasPrefix() { @@ -73,8 +73,8 @@ public boolean hasPrefix() { } public Argument getPrefix() { - if (prefix == null) - return null; + if (prefix == null) + return null; return valueOf(prefix); } @@ -164,13 +164,13 @@ public boolean matchesArgumentType(Class dClass) { // Check if this argument matches a dList of a certain dObject public boolean matchesArgumentList(Class dClass) { - dList list = new dList(this.getValue()); - - if (list.filter(dClass) != null) { - return true; - } - - return false; + dList list = new dList(this.getValue()); + + if (list.filter(dClass) != null) { + return true; + } + + return false; } public Element asElement() { @@ -188,7 +188,7 @@ public T asType(Class clazz) { // dB.log("Created: " + clazz.cast(arg).debug()); if (arg != null) { - return (T) clazz.cast(arg).setPrefix(prefix); + return (T) clazz.cast(arg).setPrefix(prefix); } } catch (IllegalAccessException e) { @@ -333,7 +333,7 @@ public static boolean matchesArg(String names, String string_arg) { * 1 try {
* 2 hardness = Hardness.valueOf(aH.getStringFrom(arg).toUpperCase());
* 3 } catch (Exception e) {
- * 4 dB.echoError("Invalid HARDNESS!")
+ * 4 dB.echoError("Invalid HARDNESS!")
* 5 }
* * @@ -516,7 +516,7 @@ public static String getStringFrom(String arg) { @Deprecated public static Duration getDurationFrom(String arg) { - arg = arg.toLowerCase().replace("duration:", "").replace("delay:", ""); + arg = arg.toLowerCase().replace("duration:", "").replace("delay:", ""); return Duration.valueOf(arg); } @@ -526,7 +526,7 @@ public static boolean matchesDouble(String arg) { @Deprecated public static boolean matchesDuration(String arg) { - arg = arg.toLowerCase().replace("duration:", "").replace("delay:", ""); + arg = arg.toLowerCase().replace("duration:", "").replace("delay:", ""); return Duration.matches(arg); } @@ -555,7 +555,7 @@ public static boolean matchesItem(String arg) { @Deprecated public static boolean matchesContext(String arg) { if (arg.toUpperCase().startsWith("CONTEXT:") || - arg.toUpperCase().startsWith("DEFINE:")) return true; + arg.toUpperCase().startsWith("DEFINE:")) return true; // TODO: Other matches____ do some actual checks, should this?. return false; } diff --git a/src/main/java/net/aufdemrand/denizen/objects/dColor.java b/src/main/java/net/aufdemrand/denizen/objects/dColor.java index a6df4ba8a5..2421469aac 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dColor.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dColor.java @@ -30,33 +30,33 @@ public static dColor valueOf(String string) { string = string.toUpperCase().replace("CO@", ""); - if (string.matches("RANDOM")) { - - // Get a color using random RGB values - return new dColor(Utilities.getRandom().nextInt(256), + if (string.matches("RANDOM")) { + + // Get a color using random RGB values + return new dColor(Utilities.getRandom().nextInt(256), Utilities.getRandom().nextInt(256), Utilities.getRandom().nextInt(256)); - } + } - Matcher m = rgbPattern.matcher(string); + Matcher m = rgbPattern.matcher(string); - if (m.matches()) - return new dColor(aH.getIntegerFrom(m.group(1)), + if (m.matches()) + return new dColor(aH.getIntegerFrom(m.group(1)), aH.getIntegerFrom(m.group(2)), aH.getIntegerFrom(m.group(3))); - - Field colorField = null; - - try { - colorField = Color.class.getField(string.toUpperCase()); - } catch (SecurityException e1) { - dB.echoError("Security exception getting color field!"); - } catch (NoSuchFieldException e1) { - dB.echoError("No such color field!"); - } - - if (colorField != null) - return new dColor(colorField); + + Field colorField = null; + + try { + colorField = Color.class.getField(string.toUpperCase()); + } catch (SecurityException e1) { + dB.echoError("Security exception getting color field!"); + } catch (NoSuchFieldException e1) { + dB.echoError("No such color field!"); + } + + if (colorField != null) + return new dColor(colorField); // No match return null; @@ -73,17 +73,17 @@ public static boolean matches(String arg) { arg = arg.toUpperCase().replace("CO@", ""); - if (arg.toUpperCase().matches("RANDOM")) - return true; - - Matcher m = rgbPattern.matcher(arg); - - if (m.matches()) - return true; - - for (Field field : Color.class.getFields()) - if (arg.toUpperCase().matches(field.getName())) return true; - + if (arg.toUpperCase().matches("RANDOM")) + return true; + + Matcher m = rgbPattern.matcher(arg); + + if (m.matches()) + return true; + + for (Field field : Color.class.getFields()) + if (arg.toUpperCase().matches(field.getName())) return true; + return false; } @@ -98,12 +98,12 @@ public dColor(int red, int green, int blue) { public dColor(Field field) { try { - color = (Color) field.get(null); - } catch (IllegalArgumentException e) { - dB.echoError("Illegal argument for color!"); - } catch (IllegalAccessException e) { - dB.echoError("Illegal access for color!"); - } + color = (Color) field.get(null); + } catch (IllegalArgumentException e) { + dB.echoError("Illegal argument for color!"); + } catch (IllegalAccessException e) { + dB.echoError("Illegal access for color!"); + } } public dColor(Color color) { @@ -125,41 +125,41 @@ public Color getColor() { String prefix = "color"; - @Override - public String getPrefix() { - return prefix; - } + @Override + public String getPrefix() { + return prefix; + } - @Override - public String debug() { + @Override + public String debug() { return (prefix + "='" + identify() + "' "); - } - - @Override - public boolean isUnique() { - return false; - } - - @Override - public String getType() { - return "Color"; - } - - @Override - public String identify() { - return "co@" + getColor().getRed() + "," + getColor().getGreen() + "," + getColor().getBlue(); - } - - @Override - public dObject setPrefix(String prefix) { - if (prefix != null) + } + + @Override + public boolean isUnique() { + return false; + } + + @Override + public String getType() { + return "Color"; + } + + @Override + public String identify() { + return "co@" + getColor().getRed() + "," + getColor().getGreen() + "," + getColor().getBlue(); + } + + @Override + public dObject setPrefix(String prefix) { + if (prefix != null) this.prefix = prefix; return this; - } + } - @Override - public String getAttribute(Attribute attribute) { - return new Element(identify()).getAttribute(attribute); - } + @Override + public String getAttribute(Attribute attribute) { + return new Element(identify()).getAttribute(attribute); + } } diff --git a/src/main/java/net/aufdemrand/denizen/objects/dEntity.java b/src/main/java/net/aufdemrand/denizen/objects/dEntity.java index 25ea588142..ea78236f0f 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dEntity.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dEntity.java @@ -27,6 +27,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Ocelot; import org.bukkit.entity.Pig; +import org.bukkit.entity.PigZombie; import org.bukkit.entity.Player; import org.bukkit.entity.Sheep; import org.bukkit.entity.Skeleton; @@ -223,7 +224,7 @@ else if (isSaved(m.group(2))) for (EntityType type : EntityType.values()) { if (type.name().equalsIgnoreCase(m.group(1))) - // Construct a new 'vanilla' unspawned dEntity + // Construct a new 'vanilla' unspawned dEntity return new dEntity(type, data1, data2); } } @@ -393,7 +394,7 @@ public boolean isGeneric() { public dLocation getLocation() { if (!isGeneric()) { - return new dLocation(getBukkitEntity().getLocation()); + return new dLocation(getBukkitEntity().getLocation()); } return null; @@ -407,14 +408,13 @@ public dLocation getLocation() { public dLocation getEyeLocation() { - if (isLivingEntity()) { - return new dLocation(getLivingEntity().getEyeLocation()); + if (!isGeneric() && isLivingEntity()) { + return new dLocation(getLivingEntity().getEyeLocation()); } return null; } - - + public void spawnAt(Location location) { // If the entity is already spawned, teleport it. if (entity != null && isUnique()) entity.teleport(location); @@ -440,9 +440,9 @@ public void spawnAt(Location location) { org.bukkit.entity.Entity ent = null; if (entity_type.name().matches("PLAYER")) { - - NPC npc = CitizensAPI.getNPCRegistry().createNPC(EntityType.PLAYER, data1); - npc.spawn(location); + + NPC npc = CitizensAPI.getNPCRegistry().createNPC(EntityType.PLAYER, data1); + npc.spawn(location); } else if (entity_type.name().matches("FALLING_BLOCK")) { @@ -482,7 +482,28 @@ else if (entity_type.name().matches("FALLING_BLOCK")) { ent = location.getWorld().spawnFallingBlock(location, material, materialData); entity = ent; } + else if (entity_type.name().matches("PIG_ZOMBIE")) { + + // Give pig zombies golden swords by default, unless data2 specifies + // a different weapon + if (dItem.matches(data2) == false) { + data2 = "gold_sword"; + } + + ((PigZombie) entity).getEquipment() + .setItemInHand(dItem.valueOf(data2).getItemStack()); + } + else if (entity_type.name().matches("SKELETON")) { + + // Give skeletons bows by default, unless data2 specifies + // a different weapon + if (dItem.matches(data2) == false) { + data2 = "bow"; + } + ((Skeleton) entity).getEquipment() + .setItemInHand(dItem.valueOf(data2).getItemStack()); + } else { ent = location.getWorld().spawnEntity(location, entity_type); @@ -529,15 +550,6 @@ else if (ent instanceof Sheep) { // Allow setting of skeleton types and their weapons else if (ent instanceof Skeleton) { setSubtype("org.bukkit.entity.Skeleton", "org.bukkit.entity.Skeleton$SkeletonType", "setSkeletonType", data1); - - // Give skeletons bows by default, unless data2 specifies - // a different weapon - if (dItem.matches(data2) == false) { - data2 = "bow"; - } - - ((Skeleton) entity).getEquipment() - .setItemInHand(dItem.valueOf(data2).getItemStack()); } // Allow setting of slime sizes else if (ent instanceof Slime && aH.matchesInteger(data1)) { @@ -590,10 +602,10 @@ public dEntity rememberAs(String id) { } public void teleport(Location location) { - if (isNPC()) - getNPC().teleport(location, TeleportCause.PLUGIN); - else - this.getBukkitEntity().teleport(location); + if (isNPC()) + getNPC().teleport(location, TeleportCause.PLUGIN); + else + this.getBukkitEntity().teleport(location); } /** @@ -605,13 +617,13 @@ public void teleport(Location location) { public void target(LivingEntity target) { - // If the target is not null, cast it to an NMS EntityLiving - // as well for one of the two methods below - EntityLiving nmsTarget = target != null ? ((CraftLivingEntity) target).getHandle() - : null; - - ((CraftCreature) entity).getHandle(). - setGoalTarget(nmsTarget); + // If the target is not null, cast it to an NMS EntityLiving + // as well for one of the two methods below + EntityLiving nmsTarget = target != null ? ((CraftLivingEntity) target).getHandle() + : null; + + ((CraftCreature) entity).getHandle(). + setGoalTarget(nmsTarget); ((CraftCreature) entity).getHandle(). setGoalTarget(((CraftLivingEntity) target).getHandle()); @@ -1025,11 +1037,11 @@ else if ((float) getLivingEntity().getHealth() / maxHealth < 1) // returns false. // --> if (attribute.startsWith("has_effect")) { - Boolean returnElement = false; + Boolean returnElement = false; if (attribute.hasContext(1)) - for (org.bukkit.potion.PotionEffect effect : getLivingEntity().getActivePotionEffects()) - if (effect.getType().equals(org.bukkit.potion.PotionType.valueOf(attribute.getContext(1)))) - returnElement = true; + for (org.bukkit.potion.PotionEffect effect : getLivingEntity().getActivePotionEffects()) + if (effect.getType().equals(org.bukkit.potion.PotionType.valueOf(attribute.getContext(1)))) + returnElement = true; else if (!getLivingEntity().getActivePotionEffects().isEmpty()) returnElement = true; return new Element(returnElement).getAttribute(attribute.fulfill(1)); } diff --git a/src/main/java/net/aufdemrand/denizen/objects/dInventory.java b/src/main/java/net/aufdemrand/denizen/objects/dInventory.java index 0c49bfbac0..0a512af822 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dInventory.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dInventory.java @@ -57,8 +57,8 @@ public dInventory(Inventory inventory) { } public dInventory(InventoryType type) { - - inventory = Bukkit.getServer().createInventory(null, type); + + inventory = Bukkit.getServer().createInventory(null, type); } public dInventory(InventoryHolder holder) { @@ -70,17 +70,17 @@ public dInventory(Player player) { } public dInventory(BlockState state) { - - if (state instanceof InventoryHolder) { - this.inventory = ((InventoryHolder) state).getInventory(); - } + + if (state instanceof InventoryHolder) { + this.inventory = ((InventoryHolder) state).getInventory(); + } } public dInventory(LivingEntity entity) { - - if (entity instanceof InventoryHolder) { - this.inventory = ((InventoryHolder) entity).getInventory(); - } + + if (entity instanceof InventoryHolder) { + this.inventory = ((InventoryHolder) entity).getInventory(); + } } @@ -106,15 +106,15 @@ public Inventory getInventory() { */ public dInventory add(ItemStack[] items) { - - if (inventory == null || items == null) return this; - - for (ItemStack item : items) { - - if (item != null) inventory.addItem(item); - } - - return this; + + if (inventory == null || items == null) return this; + + for (ItemStack item : items) { + + if (item != null) inventory.addItem(item); + } + + return this; } /** @@ -123,39 +123,39 @@ public dInventory add(ItemStack[] items) { * * @param item The item (can be null) * @param stacks Whether stacks should be counted - * instead of item quantities + * instead of item quantities * @return The number of stacks or quantity of items * */ public int count(ItemStack item, boolean stacks) { - if (inventory == null) return 0; - - int qty = 0; - - for (ItemStack invStack : inventory) - { - // If ItemStacks are empty here, they are null - if (invStack != null) - { - // If item is null, include all items in the - // inventory - - if (item == null || invStack.isSimilar(item)) { - - // If stacks is true, only count the number - // of stacks - // - // Otherwise, count the quantities of stacks - - if (stacks == true) qty++; - else qty = qty + invStack.getAmount(); - } - } - } - - return qty; + if (inventory == null) return 0; + + int qty = 0; + + for (ItemStack invStack : inventory) + { + // If ItemStacks are empty here, they are null + if (invStack != null) + { + // If item is null, include all items in the + // inventory + + if (item == null || invStack.isSimilar(item)) { + + // If stacks is true, only count the number + // of stacks + // + // Otherwise, count the quantities of stacks + + if (stacks == true) qty++; + else qty = qty + invStack.getAmount(); + } + } + } + + return qty; } /** @@ -168,37 +168,37 @@ public int count(ItemStack item, boolean stacks) */ public dInventory keep(ItemStack[] items) { - - if (inventory == null || items == null) return this; - - for (ItemStack invStack : inventory) { - - if (invStack != null) { - - boolean keep = false; - - // See if the item array contains - // this inventory item - for (ItemStack item : items) { - - if (invStack.isSimilar(item)) { - - keep = true; - break; - } - } - - // If the item array did not contain - // this inventory item, remove it - // from the inventory - if (keep == false) { - - this.remove(invStack); - } - } - } - - return this; + + if (inventory == null || items == null) return this; + + for (ItemStack invStack : inventory) { + + if (invStack != null) { + + boolean keep = false; + + // See if the item array contains + // this inventory item + for (ItemStack item : items) { + + if (invStack.isSimilar(item)) { + + keep = true; + break; + } + } + + // If the item array did not contain + // this inventory item, remove it + // from the inventory + if (keep == false) { + + this.remove(invStack); + } + } + } + + return this; } /** @@ -212,19 +212,19 @@ public dInventory keep(ItemStack[] items) { */ public dInventory exclude(ItemStack[] items) { - - if (inventory == null || items == null) return this; - - int oldCount = this.count(null, false); - int newCount = -1; - - while (oldCount != newCount) { - - oldCount = newCount; - newCount = this.remove(items).count(null, false); - } - - return this; + + if (inventory == null || items == null) return this; + + int oldCount = this.count(null, false); + int newCount = -1; + + while (oldCount != newCount) { + + oldCount = newCount; + newCount = this.remove(items).count(null, false); + } + + return this; } /** @@ -238,19 +238,19 @@ public dInventory exclude(ItemStack[] items) { */ public dInventory fill(ItemStack[] items) { - - if (inventory == null || items == null) return this; - - int oldCount = this.count(null, false); - int newCount = -1; - - while (oldCount != newCount) { - - oldCount = newCount; - newCount = this.add(items).count(null, false); - } - - return this; + + if (inventory == null || items == null) return this; + + int oldCount = this.count(null, false); + int newCount = -1; + + while (oldCount != newCount) { + + oldCount = newCount; + newCount = this.add(items).count(null, false); + } + + return this; } /** @@ -262,22 +262,22 @@ public dInventory fill(ItemStack[] items) { */ public dLocation getLocation() { - - if (inventory != null) { - - InventoryHolder holder = inventory.getHolder(); - - if (holder instanceof BlockState) { - - return new dLocation(((BlockState) holder).getLocation()); - } - else if (holder instanceof Player) { - - return new dLocation(((Player) holder).getLocation()); - } - } - - return null; + + if (inventory != null) { + + InventoryHolder holder = inventory.getHolder(); + + if (holder instanceof BlockState) { + + return new dLocation(((BlockState) holder).getLocation()); + } + else if (holder instanceof Player) { + + return new dLocation(((Player) holder).getLocation()); + } + } + + return null; } /** @@ -290,15 +290,15 @@ else if (holder instanceof Player) { */ public dInventory remove(ItemStack[] items) { - - if (inventory == null || items == null) return this; - - for (ItemStack item : items) { - - if (item != null) inventory.removeItem(item); - } - - return this; + + if (inventory == null || items == null) return this; + + for (ItemStack item : items) { + + if (item != null) inventory.removeItem(item); + } + + return this; } /** @@ -314,47 +314,47 @@ public dInventory remove(ItemStack[] items) { */ public dInventory removeBook(ItemStack book) { - - if (inventory == null || book == null) return this; - - // We have to manually keep track of the quantity - // we are removing, because we are not relying on - // Bukkit methods to find matching itemStacks - int qty = book.getAmount(); - - // Store the book's meta information in a variable - BookMeta bookMeta = (BookMeta) book.getItemMeta(); - - for (ItemStack invStack : inventory) { + + if (inventory == null || book == null) return this; + + // We have to manually keep track of the quantity + // we are removing, because we are not relying on + // Bukkit methods to find matching itemStacks + int qty = book.getAmount(); + + // Store the book's meta information in a variable + BookMeta bookMeta = (BookMeta) book.getItemMeta(); + + for (ItemStack invStack : inventory) { - if (qty == 0) break; - - if (invStack != null && invStack.getItemMeta() instanceof BookMeta) { - - BookMeta invMeta = (BookMeta) invStack.getItemMeta(); - - if (invMeta.getAuthor().equalsIgnoreCase(bookMeta.getAuthor()) - && invMeta.getTitle().equalsIgnoreCase(bookMeta.getTitle())) { + if (qty == 0) break; + + if (invStack != null && invStack.getItemMeta() instanceof BookMeta) { + + BookMeta invMeta = (BookMeta) invStack.getItemMeta(); + + if (invMeta.getAuthor().equalsIgnoreCase(bookMeta.getAuthor()) + && invMeta.getTitle().equalsIgnoreCase(bookMeta.getTitle())) { - // Make sure we don't remove more books than we - // need to - if (qty - invStack.getAmount() < 0) { - - invStack.setAmount((qty - invStack.getAmount()) * -1); - } - else { - - inventory.removeItem(invStack); - - // Update the quantity we still have to remove - qty = qty - invStack.getAmount(); - } - } - } - - } - - return this; + // Make sure we don't remove more books than we + // need to + if (qty - invStack.getAmount() < 0) { + + invStack.setAmount((qty - invStack.getAmount()) * -1); + } + else { + + inventory.removeItem(invStack); + + // Update the quantity we still have to remove + qty = qty - invStack.getAmount(); + } + } + } + + } + + return this; } /** @@ -366,46 +366,46 @@ public dInventory removeBook(ItemStack book) { */ public void replace(dInventory destination) { - - if (inventory == null || destination == null) return; - - // If the destination is smaller than our current inventory, - // add as many items as possible - - if (destination.getSize() < this.getSize()) { + + if (inventory == null || destination == null) return; + + // If the destination is smaller than our current inventory, + // add as many items as possible + + if (destination.getSize() < this.getSize()) { - destination.clear(); - destination.add(this.getContents()); - } - else { - - destination.setContents(this.getContents()); - } + destination.clear(); + destination.add(this.getContents()); + } + else { + + destination.setContents(this.getContents()); + } } public void clear() { - if (inventory != null) inventory.clear(); + if (inventory != null) inventory.clear(); } public ItemStack[] getContents() { - if (inventory != null) return inventory.getContents(); - else return new ItemStack[0]; + if (inventory != null) return inventory.getContents(); + else return new ItemStack[0]; } public InventoryType getInventoryType() { - return inventory.getType(); + return inventory.getType(); } public int getSize() { - return inventory.getSize(); + return inventory.getSize(); } public void remove(ItemStack item) { - inventory.remove(item); + inventory.remove(item); } public void setContents(ItemStack[] contents) { - inventory.setContents(contents); + inventory.setContents(contents); } @@ -457,28 +457,28 @@ public String getAttribute(Attribute attribute) { if (attribute.startsWith("contains")) { if (attribute.hasContext(1) && dItem.matches(attribute.getContext(1))) { - - int qty = 1; - - if (attribute.getAttribute(2).startsWith("qty") && - attribute.hasContext(2) && - aH.matchesInteger(attribute.getContext(2))) { - - qty = attribute.getIntContext(2); - } - - return new Element(getInventory().containsAtLeast - (dItem.valueOf(attribute.getContext(1)).getItemStack(), qty)) - .getAttribute(attribute.fulfill(qty == 1 ? 1 : 2)); + + int qty = 1; + + if (attribute.getAttribute(2).startsWith("qty") && + attribute.hasContext(2) && + aH.matchesInteger(attribute.getContext(2))) { + + qty = attribute.getIntContext(2); + } + + return new Element(getInventory().containsAtLeast + (dItem.valueOf(attribute.getContext(1)).getItemStack(), qty)) + .getAttribute(attribute.fulfill(qty == 1 ? 1 : 2)); } } // Get the location of this inventory's holder if (attribute.startsWith("location")) { - - return new dLocation(getLocation()) - .getAttribute(attribute.fulfill(1)); + + return new dLocation(getLocation()) + .getAttribute(attribute.fulfill(1)); } // Get the combined quantity of itemstacks that match an item if @@ -487,12 +487,12 @@ public String getAttribute(Attribute attribute) { if (attribute.startsWith("qty")) if (attribute.hasContext(1) && dItem.matches(attribute.getContext(1))) - return new Element(String.valueOf(count - (dItem.valueOf(attribute.getContext(1)).getItemStack(), false))) - .getAttribute(attribute.fulfill(1)); + return new Element(String.valueOf(count + (dItem.valueOf(attribute.getContext(1)).getItemStack(), false))) + .getAttribute(attribute.fulfill(1)); else - return new Element(String.valueOf(count(null, false))) - .getAttribute(attribute.fulfill(1)); + return new Element(String.valueOf(count(null, false))) + .getAttribute(attribute.fulfill(1)); // Return the number of slots in the inventory @@ -505,12 +505,12 @@ public String getAttribute(Attribute attribute) { if (attribute.startsWith("stacks")) if (attribute.hasContext(1) && dItem.matches(attribute.getContext(1))) - return new Element(String.valueOf(count - (dItem.valueOf(attribute.getContext(1)).getItemStack(), true))) - .getAttribute(attribute.fulfill(1)); + return new Element(String.valueOf(count + (dItem.valueOf(attribute.getContext(1)).getItemStack(), true))) + .getAttribute(attribute.fulfill(1)); else - return new Element(String.valueOf(count(null, true))) - .getAttribute(attribute.fulfill(1)); + return new Element(String.valueOf(count(null, true))) + .getAttribute(attribute.fulfill(1)); // Return the type of the inventory (e.g. "PLAYER", "CRAFTING") diff --git a/src/main/java/net/aufdemrand/denizen/objects/dItem.java b/src/main/java/net/aufdemrand/denizen/objects/dItem.java index a2f809549d..13539ba8ab 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dItem.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dItem.java @@ -23,19 +23,19 @@ public class dItem implements dObject { - // An item pattern with the following groups: - // - // 1) An optional item: prefix. - // 2) Word characters (letters and digits) and - // spaces that specify the name or ID of the item - // 3) Digits that specify the special data value - // of the item - // 4) Digits between [] brackets that specify the - // quantity of the item - + // An item pattern with the following groups: + // + // 1) An optional item: prefix. + // 2) Word characters (letters and digits) and + // spaces that specify the name or ID of the item + // 3) Digits that specify the special data value + // of the item + // 4) Digits between [] brackets that specify the + // quantity of the item + final static Pattern itemPattern = - Pattern.compile("(?:item:)?([\\w ]+)[:,]?(\\d+)?\\[?(\\d+)?\\]?", - Pattern.CASE_INSENSITIVE); + Pattern.compile("(?:item:)?([\\w ]+)[:,]?(\\d+)?\\[?(\\d+)?\\]?", + Pattern.CASE_INSENSITIVE); ///////////////////// // STATIC METHODS @@ -78,7 +78,7 @@ public static void remove(String id) { //////////////// public static dItem valueOf(String string) { - return valueOf(string, null, null); + return valueOf(string, null, null); } /** @@ -113,10 +113,10 @@ public static dItem valueOf(String string, dPlayer player, dNPC npc) { stack = new dItem(((Item) entity).getItemStack()); if (m.group(3) != null) { - stack.setAmount(Integer.valueOf(m.group(3))); + stack.setAmount(Integer.valueOf(m.group(3))); } - return stack; + return stack; } } } @@ -132,10 +132,10 @@ public static dItem valueOf(String string, dPlayer player, dNPC npc) { stack = getSaved(m.group(2)); if (m.group(3) != null) { - stack.setAmount(Integer.valueOf(m.group(3))); + stack.setAmount(Integer.valueOf(m.group(3))); } - return stack; + return stack; } string = string.replace("i@", ""); @@ -143,63 +143,63 @@ public static dItem valueOf(String string, dPlayer player, dNPC npc) { m = itemPattern.matcher(string); if (m.matches()) { - - try { - + + try { + /////// // Match item and book script custom items - + if (ScriptRegistry.containsScript(m.group(1), ItemScriptContainer.class)) { // Get item from script stack = ScriptRegistry.getScriptContainerAs - (m.group(1), ItemScriptContainer.class).getItemFrom(player, npc); + (m.group(1), ItemScriptContainer.class).getItemFrom(player, npc); } else if (ScriptRegistry.containsScript(m.group(1), BookScriptContainer.class)) { - // Get book from script + // Get book from script stack = ScriptRegistry.getScriptContainerAs - (m.group(1), BookScriptContainer.class).getBookFrom(player, npc); + (m.group(1), BookScriptContainer.class).getBookFrom(player, npc); } if (stack != null) { - - if (m.group(3) != null) { - stack.setAmount(Integer.valueOf(m.group(3))); + + if (m.group(3) != null) { + stack.setAmount(Integer.valueOf(m.group(3))); } - return stack; + return stack; } - } - catch (Exception e) { + } + catch (Exception e) { // Just a catch, might be a regular item... - } - - + } + + /////// // Match Bukkit/Minecraft standard items format - - try { - String material = m.group(1).toUpperCase(); + + try { + String material = m.group(1).toUpperCase(); - if (aH.matchesInteger(material)) { - stack = new dItem(Integer.valueOf(material)); - } - else { - stack = new dItem(Material.valueOf(material)); - } + if (aH.matchesInteger(material)) { + stack = new dItem(Integer.valueOf(material)); + } + else { + stack = new dItem(Material.valueOf(material)); + } - if (m.group(2) != null) { - stack.setDurability(Short.valueOf(m.group(2))); - } - if (m.group(3) != null) { - stack.setAmount(Integer.valueOf(m.group(3))); - } + if (m.group(2) != null) { + stack.setDurability(Short.valueOf(m.group(2))); + } + if (m.group(3) != null) { + stack.setAmount(Integer.valueOf(m.group(3))); + } - return stack; - } - catch (Exception e) { + return stack; + } + catch (Exception e) { if (!string.equalsIgnoreCase("none")) - dB.log("Does not match a valid item ID or material: " + string); - } + dB.log("Does not match a valid item ID or material: " + string); + } } if (!nope) dB.log("valueOf dItem returning null: " + string); @@ -356,16 +356,16 @@ public int comparesTo(ItemStack item) { * */ public boolean containsLore(String prefix) { - - if (getItemStack().hasItemMeta() && getItemStack().getItemMeta().hasLore()) { - for (String itemLore : getItemStack().getItemMeta().getLore()) { - if (itemLore.startsWith(prefix)) { - return true; - } - } - } - - return false; + + if (getItemStack().hasItemMeta() && getItemStack().getItemMeta().hasLore()) { + for (String itemLore : getItemStack().getItemMeta().getLore()) { + if (itemLore.startsWith(prefix)) { + return true; + } + } + } + + return false; } /** @@ -377,14 +377,14 @@ public boolean containsLore(String prefix) { * */ public String getLore(String prefix) { - - for (String itemLore : getItemStack().getItemMeta().getLore()) { - if (itemLore.startsWith(prefix)) { - return itemLore.substring(prefix.length()); - } - } - - return ""; + + for (String itemLore : getItemStack().getItemMeta().getLore()) { + if (itemLore.startsWith(prefix)) { + return itemLore.substring(prefix.length()); + } + } + + return ""; } /** @@ -395,15 +395,15 @@ public String getLore(String prefix) { * */ public boolean isItemscript() { - - if (containsLore("§0id:")) { - return true; - } - return false; + + if (containsLore("§0id:")) { + return true; + } + return false; } public String getMaterial() { - return getItemStack().getType().name().toLowerCase(); + return getItemStack().getType().name().toLowerCase(); } public void setAmount(int value) { @@ -488,19 +488,19 @@ public String debug() { @Override public String identify() { // If saved item, return that - if (getItemStack() == null) return null; - - if (getItemStack().getTypeId() != 0) { - - if (isSaved(this)) { - return "i@" + getSaved(this); - } - - // If not a saved item, but is a custom item, return the script id - else if (isItemscript()) { - return "i@" + getLore("§0id:"); - } - } + if (getItemStack() == null) return null; + + if (getItemStack().getTypeId() != 0) { + + if (isSaved(this)) { + return "i@" + getSaved(this); + } + + // If not a saved item, but is a custom item, return the script id + else if (isItemscript()) { + return "i@" + getLore("§0id:"); + } + } // Else, return the material name and data return getItemStack().getType().name().toLowerCase() @@ -623,14 +623,14 @@ public String getAttribute(Attribute attribute) { // Return all lore except for lore that holds item script ID if (attribute.startsWith("lore")) { if (getItemStack().hasItemMeta() && getItemStack().getItemMeta().hasLore()) { - - List loreList = new ArrayList(); - - for (String itemLore : getItemStack().getItemMeta().getLore()) { - if (!itemLore.startsWith("§0id:")) { - loreList.add(itemLore); - } - } + + List loreList = new ArrayList(); + + for (String itemLore : getItemStack().getItemMeta().getLore()) { + if (!itemLore.startsWith("§0id:")) { + loreList.add(itemLore); + } + } return new dList(loreList).getAttribute(attribute.fulfill(1)); } else return new dList("").getAttribute(attribute.fulfill(1)); diff --git a/src/main/java/net/aufdemrand/denizen/objects/dList.java b/src/main/java/net/aufdemrand/denizen/objects/dList.java index 71ca49c0a5..28168c13c8 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dList.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dList.java @@ -5,9 +5,7 @@ import net.aufdemrand.denizen.utilities.DenizenAPI; import net.aufdemrand.denizen.utilities.debugging.dB; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.entity.Entity; import java.util.ArrayList; import java.util.Arrays; @@ -21,7 +19,7 @@ public class dList extends ArrayList implements dObject { final static Pattern flag_by_id = Pattern.compile("(fl\\[((?:p@|n@)(.+?))\\]@|fl@)(.+)", Pattern.CASE_INSENSITIVE); - + @ObjectFetcher("li, fl") public static dList valueOf(String string) { if (string == null) return null; @@ -49,7 +47,7 @@ public static dList valueOf(String string) { return new dList(flag_manager.getPlayerFlag(m.group(3), m.group(4))); } else if (m.group(2).toLowerCase().startsWith("n@")) { - if (FlagManager.npcHasFlag(dNPC.valueOf(m.group(3)), m.group(4))) + if (FlagManager.npcHasFlag(dNPC.valueOf(m.group(3)), m.group(4))) return new dList(flag_manager.getNPCFlag(Integer.valueOf(m.group(3)), m.group(4))); } @@ -66,7 +64,7 @@ public static dList valueOf(String string) { public static boolean matches(String arg) { - Matcher m; + Matcher m; m = flag_by_id.matcher(arg); if (m.matches()) return true; @@ -98,9 +96,9 @@ public dList(List items) { } public dList(List items, String prefix) { - for (String element : items) { - add(prefix + element); - } + for (String element : items) { + add(prefix + element); + } } public dList(FlagManager.Flag flag) { @@ -151,42 +149,42 @@ public String getType() { } public String[] toArray() { - - List list = new ArrayList(); - - for (String string : this) { - list.add(string); - } - - return list.toArray(new String[list.size()]); + + List list = new ArrayList(); + + for (String string : this) { + list.add(string); + } + + return list.toArray(new String[list.size()]); } // Return a list that includes only elements belonging to a certain class public List filter(Class dClass) { - List results = new ArrayList(); - - for (String element : this) { - - try { - if ((Boolean) dClass.getMethod("matches", String.class).invoke(null, element)) { - - dObject object = (dObject) dClass.getMethod("valueOf", String.class).invoke(null, element); - - // Only add the object if it is not null, thus filtering useless - // list items - - if (object != null) { - results.add(object); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - if (results.size() > 0) return results; - else return null; + List results = new ArrayList(); + + for (String element : this) { + + try { + if ((Boolean) dClass.getMethod("matches", String.class).invoke(null, element)) { + + dObject object = (dObject) dClass.getMethod("valueOf", String.class).invoke(null, element); + + // Only add the object if it is not null, thus filtering useless + // list items + + if (object != null) { + results.add(object); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + if (results.size() > 0) return results; + else return null; } @Override @@ -293,22 +291,22 @@ public String getAttribute(Attribute attribute) { } if (attribute.startsWith("last")) { - return new Element(get(size() - 1)).getAttribute(attribute.fulfill(1)); + return new Element(get(size() - 1)).getAttribute(attribute.fulfill(1)); } if (attribute.startsWith("contains")) { - if (attribute.hasContext(1)) { - boolean state = false; - - for (String element : this) { - if (element.equalsIgnoreCase(attribute.getContext(1))) { - state = true; - break; - } - } - - return new Element(state).getAttribute(attribute.fulfill(1)); - } + if (attribute.hasContext(1)) { + boolean state = false; + + for (String element : this) { + if (element.equalsIgnoreCase(attribute.getContext(1))) { + state = true; + break; + } + } + + return new Element(state).getAttribute(attribute.fulfill(1)); + } } if (attribute.startsWith("prefix")) @@ -347,7 +345,7 @@ public String getAttribute(Attribute attribute) { // --> if (attribute.startsWith("random")) { if (!this.isEmpty()) - return new Element(this.get(new Random().nextInt(this.size()))) + return new Element(this.get(new Random().nextInt(this.size()))) .getAttribute(attribute.fulfill(1)); } diff --git a/src/main/java/net/aufdemrand/denizen/objects/dLocation.java b/src/main/java/net/aufdemrand/denizen/objects/dLocation.java index de4aaf9e4c..13176ad463 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dLocation.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dLocation.java @@ -24,7 +24,7 @@ public class dLocation extends org.bukkit.Location implements dObject { - // This pattern correctly reads both 0.9 and 0.8 notables + // This pattern correctly reads both 0.9 and 0.8 notables final static Pattern notablePattern = Pattern.compile("(\\w+)[;,]((-?\\d+\\.?\\d*,){3,5}\\w+)", Pattern.CASE_INSENSITIVE); @@ -85,14 +85,14 @@ public static void remove(String id) { * Called on server startup or /denizen reload locations. Should probably not be called manually. */ public static void _recallLocations() { - - + + List loclist = DenizenAPI.getCurrentInstance().getSaves().getStringList("dScript.Locations"); uniqueObjects.clear(); for (String location : loclist) { - Matcher m = notablePattern.matcher(location); + Matcher m = notablePattern.matcher(location); if (m.matches()) { - String id = m.group(1); + String id = m.group(1); dLocation loc = valueOf(m.group(2)); uniqueObjects.put(id, loc); } @@ -210,11 +210,11 @@ public static boolean matches(String string) { * @param location the Bukkit Location to reference */ public dLocation(Location location) { - // Just save the yaw and pitch as they are; don't check if they are - // higher than 0, because Minecraft yaws are weird and can have - // negative values + // Just save the yaw and pitch as they are; don't check if they are + // higher than 0, because Minecraft yaws are weird and can have + // negative values super(location.getWorld(), location.getX(), location.getY(), location.getZ(), - location.getYaw(), location.getPitch()); + location.getYaw(), location.getPitch()); } /** @@ -482,14 +482,14 @@ public int compare(dLocation loc1, dLocation loc2) { // Returns a dList of players within a radius. // --> else if (attribute.startsWith("players") - && attribute.getAttribute(2).startsWith("within") - && attribute.hasContext(2)) { + && attribute.getAttribute(2).startsWith("within") + && attribute.hasContext(2)) { ArrayList found = new ArrayList(); - int radius = aH.matchesInteger(attribute.getContext(2)) ? attribute.getIntContext(2) : 10; + int radius = aH.matchesInteger(attribute.getContext(2)) ? attribute.getIntContext(2) : 10; attribute.fulfill(2); for (Player player : Bukkit.getOnlinePlayers()) - if (Utilities.checkLocation(this, player.getLocation(), radius)) - found.add(new dPlayer(player)); + if (Utilities.checkLocation(this, player.getLocation(), radius)) + found.add(new dPlayer(player)); Collections.sort(found, new Comparator() { @Override @@ -509,10 +509,10 @@ else if (attribute.startsWith("entities") && attribute.getAttribute(2).startsWith("within") && attribute.hasContext(2)) { ArrayList found = new ArrayList(); - int radius = aH.matchesInteger(attribute.getContext(2)) ? attribute.getIntContext(2) : 10; + int radius = aH.matchesInteger(attribute.getContext(2)) ? attribute.getIntContext(2) : 10; attribute.fulfill(2); for (Entity entity : getWorld().getEntities()) - if (Utilities.checkLocation(this, entity.getLocation(), radius)) + if (Utilities.checkLocation(this, entity.getLocation(), radius)) found.add(new dEntity(entity)); Collections.sort(found, new Comparator() { @@ -568,10 +568,10 @@ public int compare(dEntity ent1, dEntity ent2) { // at the location. // --> if (attribute.startsWith("direction")) { - // Get the cardinal direction from this location to another + // Get the cardinal direction from this location to another if (attribute.hasContext(1) && dLocation.matches(attribute.getContext(1))) { - // Subtract this location's vector from the other location's vector, - // not the other way around + // Subtract this location's vector from the other location's vector, + // not the other way around return new Element(Rotation.getCardinal(Rotation.getYaw (dLocation.valueOf(attribute.getContext(1)).toVector().subtract(this.toVector()) .normalize()))) @@ -579,8 +579,8 @@ public int compare(dEntity ent1, dEntity ent2) { } // Get a cardinal direction from this location's yaw else { - return new Element(Rotation.getCardinal(getYaw())) - .getAttribute(attribute.fulfill(1)); + return new Element(Rotation.getCardinal(getYaw())) + .getAttribute(attribute.fulfill(1)); } } @@ -598,7 +598,7 @@ public int compare(dEntity ent1, dEntity ent2) { // --> if (attribute.getAttribute(2).startsWith("horizontal")) { - // <-- + // <-- // ].horizontal.multiworld> -> Element(Number) // Returns the horizontal distance between 2 multiworld locations. // --> @@ -619,8 +619,8 @@ else if (this.getWorld() == toLocation.getWorld()) // Returns the vertical distance between 2 locations. // --> else if (attribute.getAttribute(2).startsWith("vertical")) { - - // <-- + + // <-- // ].vertical.multiworld> -> Element(Number) // Returns the vertical distance between 2 multiworld locations. // --> @@ -716,7 +716,7 @@ else return new Element(String.valueOf(this.distance(toLocation))) // --> if (attribute.startsWith("yaw.raw")) { return new Element(String.valueOf - (getYaw())).getAttribute(attribute.fulfill(2)); + (getYaw())).getAttribute(attribute.fulfill(2)); } // <-- @@ -725,7 +725,7 @@ else return new Element(String.valueOf(this.distance(toLocation))) // --> if (attribute.startsWith("yaw")) { return new Element(String.valueOf - (Rotation.normalizeYaw(getYaw()))).getAttribute(attribute.fulfill(1)); + (Rotation.normalizeYaw(getYaw()))).getAttribute(attribute.fulfill(1)); } // <-- @@ -734,39 +734,39 @@ else return new Element(String.valueOf(this.distance(toLocation))) // entity or location. Otherwise, returns false. // --> if (attribute.startsWith("facing")) { - if (attribute.hasContext(1)) { - - // The default number of degrees if there is no degrees attribute - int degrees = 45; - - // The attribute to fulfill from - int attributePos = 1; - + if (attribute.hasContext(1)) { + + // The default number of degrees if there is no degrees attribute + int degrees = 45; + + // The attribute to fulfill from + int attributePos = 1; + // <-- // ].degrees[X]> -> Element(Boolean) // Returns true if the location's yaw is facing another // entity or location, within a specified degree range. - // Otherwise, returns false. + // Otherwise, returns false. // --> - if (attribute.getAttribute(2).startsWith("degrees") && - attribute.hasContext(2) && - aH.matchesInteger(attribute.getContext(2))) { - - degrees = attribute.getIntContext(2); - attributePos++; - } - - if (dLocation.matches(attribute.getContext(1))) { - return new Element(Rotation.isFacingLocation - (this, dLocation.valueOf(attribute.getContext(1)), degrees)) - .getAttribute(attribute.fulfill(attributePos)); - } - else if (dEntity.matches(attribute.getContext(1))) { - return new Element(Rotation.isFacingLocation - (this, dEntity.valueOf(attribute.getContext(1)) - .getBukkitEntity().getLocation(), degrees)) - .getAttribute(attribute.fulfill(attributePos)); - } + if (attribute.getAttribute(2).startsWith("degrees") && + attribute.hasContext(2) && + aH.matchesInteger(attribute.getContext(2))) { + + degrees = attribute.getIntContext(2); + attributePos++; + } + + if (dLocation.matches(attribute.getContext(1))) { + return new Element(Rotation.isFacingLocation + (this, dLocation.valueOf(attribute.getContext(1)), degrees)) + .getAttribute(attribute.fulfill(attributePos)); + } + else if (dEntity.matches(attribute.getContext(1))) { + return new Element(Rotation.isFacingLocation + (this, dEntity.valueOf(attribute.getContext(1)) + .getBukkitEntity().getLocation(), degrees)) + .getAttribute(attribute.fulfill(attributePos)); + } } } @@ -793,16 +793,16 @@ else if (dEntity.matches(attribute.getContext(1))) { // Check if the player is in the specified region if (attribute.hasContext(1)) { - String region = attribute.getContext(1); + String region = attribute.getContext(1); - return new Element(String.valueOf(WorldGuardUtilities.inRegion(this, region))) - .getAttribute(attribute.fulfill(1)); + return new Element(String.valueOf(WorldGuardUtilities.inRegion(this, region))) + .getAttribute(attribute.fulfill(1)); } // Check if the player is in any region else { - return new Element(String.valueOf(WorldGuardUtilities.inRegion(this))) - .getAttribute(attribute.fulfill(1)); + return new Element(String.valueOf(WorldGuardUtilities.inRegion(this))) + .getAttribute(attribute.fulfill(1)); } } diff --git a/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java b/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java index 278be91f5d..a47091c9e8 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java @@ -12,7 +12,7 @@ public class dMaterial implements dObject { final static Pattern materialPattern = Pattern.compile("(?:m@)?(\\w+):?(\\d+)?", Pattern.CASE_INSENSITIVE); - + ////////////////// // OBJECT FETCHER //////////////// @@ -27,40 +27,40 @@ public class dMaterial implements dObject { @ObjectFetcher("m") public static dMaterial valueOf(String string) { - if (string.toLowerCase().matches("random") + if (string.toLowerCase().matches("random") || string.toLowerCase().matches("m@random")) { - - // Get a random material - return new dMaterial(Material.values()[Utilities.getRandom().nextInt(Material.values().length)]); - } - - Matcher m = materialPattern.matcher(string); - - if (m.matches()) { - + + // Get a random material + return new dMaterial(Material.values()[Utilities.getRandom().nextInt(Material.values().length)]); + } + + Matcher m = materialPattern.matcher(string); + + if (m.matches()) { + int data = -1; - - if (m.group(2) != null) { - - data = aH.getIntegerFrom(m.group(2)); - } - - if (aH.matchesInteger(m.group(1))) { - - return new dMaterial(aH.getIntegerFrom(m.group(1)), data); - } - else { - - for (Material material : Material.values()) { - - if (material.name().equalsIgnoreCase(m.group(1))) { - - return new dMaterial(material, data); - } - } - } - } - + + if (m.group(2) != null) { + + data = aH.getIntegerFrom(m.group(2)); + } + + if (aH.matchesInteger(m.group(1))) { + + return new dMaterial(aH.getIntegerFrom(m.group(1)), data); + } + else { + + for (Material material : Material.values()) { + + if (material.name().equalsIgnoreCase(m.group(1))) { + + return new dMaterial(material, data); + } + } + } + } + // No match return null; } @@ -74,14 +74,14 @@ public static dMaterial valueOf(String string) { */ public static boolean matches(String arg) { - if (arg.toUpperCase().matches("RANDOM")) - return true; - - Matcher m = materialPattern.matcher(arg); - - if (m.matches()) - return true; - + if (arg.toUpperCase().matches("RANDOM")) + return true; + + Matcher m = materialPattern.matcher(arg); + + if (m.matches()) + return true; + return false; } @@ -142,47 +142,47 @@ public MaterialData getMaterialData() { String prefix = "material"; - @Override - public String getPrefix() { - return prefix; - } + @Override + public String getPrefix() { + return prefix; + } - @Override - public String debug() { - return (prefix + "='" + identify() + "' "); - } + @Override + public String debug() { + return (prefix + "='" + identify() + "' "); + } - @Override - public boolean isUnique() { - return false; - } + @Override + public boolean isUnique() { + return false; + } - @Override - public String getType() { - return "Material"; - } + @Override + public String getType() { + return "Material"; + } - @Override - public String identify() { - return "m@" + material.name(); - } + @Override + public String identify() { + return "m@" + material.name(); + } @Override public String toString() { return identify(); } - @Override - public dObject setPrefix(String prefix) { - if (prefix != null) + @Override + public dObject setPrefix(String prefix) { + if (prefix != null) this.prefix = prefix; return this; - } + } - @Override - public String getAttribute(Attribute attribute) { + @Override + public String getAttribute(Attribute attribute) { - return new Element(identify()).getAttribute(attribute); - } + return new Element(identify()).getAttribute(attribute); + } } diff --git a/src/main/java/net/aufdemrand/denizen/objects/dNPC.java b/src/main/java/net/aufdemrand/denizen/objects/dNPC.java index fc4d0133cd..9e9791e730 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dNPC.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dNPC.java @@ -143,7 +143,7 @@ public InteractScriptContainer getInteractScriptQuietly(dPlayer player, Class if (attribute.startsWith("time.period")) { - - long time = getWorld().getTime(); - String period; - - if (time >= 23000) period = "dawn"; + + long time = getWorld().getTime(); + String period; + + if (time >= 23000) period = "dawn"; else if (time >= 13500) period = "night"; else if (time >= 12500) period = "dusk"; else period = "day"; - + return new Element(period).getAttribute(attribute.fulfill(2)); } diff --git a/src/main/java/net/aufdemrand/denizen/scripts/ScriptHelper.java b/src/main/java/net/aufdemrand/denizen/scripts/ScriptHelper.java index 1aa446c246..9f8f1119a0 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/ScriptHelper.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/ScriptHelper.java @@ -5,7 +5,6 @@ import net.aufdemrand.denizen.utilities.debugging.dB; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -98,7 +97,7 @@ private static String _concatenateCoreScripts() { try { yaml = YamlConfiguration.loadConfiguration(f); - String saved = yaml.saveToString(); + String saved = yaml.saveToString(); if (yaml != null && saved.length() > 0) sb.append(saved + "\r\n"); else { diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/AbstractCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/AbstractCommand.java index b3653e170f..df2cfed480 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/AbstractCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/AbstractCommand.java @@ -10,14 +10,14 @@ public abstract class AbstractCommand implements RegistrationableInstance { - /** - * Contains required options for a Command in a single class for the - * ability to add optional options in the future. - * - * {@see withOptions} for information on using CommandOptions with this command. - * - */ - public class CommandOptions { + /** + * Contains required options for a Command in a single class for the + * ability to add optional options in the future. + * + * {@see withOptions} for information on using CommandOptions with this command. + * + */ + public class CommandOptions { public String USAGE_HINT; public int REQUIRED_ARGS; @@ -26,116 +26,116 @@ public CommandOptions(String usageHint, int numberOfRequiredArgs) { this.REQUIRED_ARGS = numberOfRequiredArgs; } } - - public Denizen denizen; - + + public Denizen denizen; + protected String name; public CommandOptions commandOptions; - @Override - public AbstractCommand activate() { - this.denizen = (Denizen) Bukkit.getPluginManager().getPlugin("Denizen"); - return this; - } + @Override + public AbstractCommand activate() { + this.denizen = (Denizen) Bukkit.getPluginManager().getPlugin("Denizen"); + return this; + } - @Override - public AbstractCommand as(String commandName) { - // Register command with Registry with a Name - name = commandName.toUpperCase(); - denizen.getCommandRegistry().register(this.name, this); - onEnable(); - return this; - } - + @Override + public AbstractCommand as(String commandName) { + // Register command with Registry with a Name + name = commandName.toUpperCase(); + denizen.getCommandRegistry().register(this.name, this); + onEnable(); + return this; + } + public abstract void execute(ScriptEntry scriptEntry) throws CommandExecutionException; @Override - public String getName() { - return name; - } - + public String getName() { + return name; + } + /** * Returns the {@link CommandOptions} specified at startup. * * @return commandOptions * */ - public CommandOptions getOptions() { + public CommandOptions getOptions() { return commandOptions; } - - /** - * Returns USAGE_HINT specified in the {@link CommandOptions}, if specified. - * - * @return USAGE_HINT if specified, otherwise "No usage defined! See documentation for more information!" - * - */ - public String getUsageHint() { - return !commandOptions.USAGE_HINT.equals("") ? commandOptions.USAGE_HINT : "No usage defined! See documentation for more information!"; - } - - /** - * Part of the Plugin disable sequence. - * - * Can be '@Override'n by a Command which requires a method when bukkit sends a - * onDisable() to Denizen. (ie. Server shuts down or restarts) - * - */ - public void onDisable() { - - } + + /** + * Returns USAGE_HINT specified in the {@link CommandOptions}, if specified. + * + * @return USAGE_HINT if specified, otherwise "No usage defined! See documentation for more information!" + * + */ + public String getUsageHint() { + return !commandOptions.USAGE_HINT.equals("") ? commandOptions.USAGE_HINT : "No usage defined! See documentation for more information!"; + } + + /** + * Part of the Plugin disable sequence. + * + * Can be '@Override'n by a Command which requires a method when bukkit sends a + * onDisable() to Denizen. (ie. Server shuts down or restarts) + * + */ + public void onDisable() { + + } - /** - * Part of the Plugin enable sequence. This is called when the command is - * instanced by the CommandRegistry, which is generally on a server startup. - * - * Can be '@Override'n by a Command which requires a method when starting, such - * as registering as a Bukkit Listener. - * - */ - public void onEnable() { - - } - - /** - * Called by the CommandExecuter before the execute() method is called. Arguments - * should be iterated through and checked before continuing to execute(). Note that - * PLAYER:player_name and NPCID:# arguments are parsed automatically by the Executer - * and should not be handled by this Command otherwise. Their output is stored in the - * attached {@link ScriptEntry} and can be retrieved with scriptEntry.getPlayer(), - * scriptEntry.getOfflinePlayer() (if the player specified is not online), and - * scriptEntry.getNPC(). Remember that any of these have a possibility of being null - * and should be handled accordingly if required by this Command. - * - * @param scriptEntry - * The {@link ScriptEntry}, which contains run-time context that may - * be utilized by this Command. - * @throws InvalidArgumentsException - * Will halt execution of this Command and hint usage to the console to avoid - * unwanted behavior due to missing information. - * - */ - public abstract void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException; - - /** - * Creates a new {@link CommandOptions} for this command. - * - * @param usageHint - * A String representation of the suggested usage format of this command. - * Typically []'s represent required arguments and ()'s represent optional arguments. - * Example from SWITCH command: [LOCATION:x,y,z,world] (STATE:ON|OFF|TOGGLE) (DURATION:#) - * @param numberOfRequiredArgs - * The minimum number of required arguments needed to ensure proper functionality. The - * Executer will not parseArgs() for this command if this number is not met. - * @return - * The newly created CommandOptions object for the possibility of setting other - * criteria, though currently none exists. - * - */ - public CommandOptions withOptions(String usageHint, int numberOfRequiredArgs) { + /** + * Part of the Plugin enable sequence. This is called when the command is + * instanced by the CommandRegistry, which is generally on a server startup. + * + * Can be '@Override'n by a Command which requires a method when starting, such + * as registering as a Bukkit Listener. + * + */ + public void onEnable() { + + } + + /** + * Called by the CommandExecuter before the execute() method is called. Arguments + * should be iterated through and checked before continuing to execute(). Note that + * PLAYER:player_name and NPCID:# arguments are parsed automatically by the Executer + * and should not be handled by this Command otherwise. Their output is stored in the + * attached {@link ScriptEntry} and can be retrieved with scriptEntry.getPlayer(), + * scriptEntry.getOfflinePlayer() (if the player specified is not online), and + * scriptEntry.getNPC(). Remember that any of these have a possibility of being null + * and should be handled accordingly if required by this Command. + * + * @param scriptEntry + * The {@link ScriptEntry}, which contains run-time context that may + * be utilized by this Command. + * @throws InvalidArgumentsException + * Will halt execution of this Command and hint usage to the console to avoid + * unwanted behavior due to missing information. + * + */ + public abstract void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException; + + /** + * Creates a new {@link CommandOptions} for this command. + * + * @param usageHint + * A String representation of the suggested usage format of this command. + * Typically []'s represent required arguments and ()'s represent optional arguments. + * Example from SWITCH command: [LOCATION:x,y,z,world] (STATE:ON|OFF|TOGGLE) (DURATION:#) + * @param numberOfRequiredArgs + * The minimum number of required arguments needed to ensure proper functionality. The + * Executer will not parseArgs() for this command if this number is not met. + * @return + * The newly created CommandOptions object for the possibility of setting other + * criteria, though currently none exists. + * + */ + public CommandOptions withOptions(String usageHint, int numberOfRequiredArgs) { this.commandOptions = new CommandOptions(usageHint, numberOfRequiredArgs); return commandOptions; } - + } diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandExecuter.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandExecuter.java index 1f6bf81ff3..ba043e164e 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandExecuter.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandExecuter.java @@ -28,9 +28,9 @@ public CommandExecuter(Denizen denizen) { plugin = denizen; } - /* - * Executes a command defined in scriptEntry - */ + /* + * Executes a command defined in scriptEntry + */ public boolean execute(ScriptEntry scriptEntry) { @@ -72,13 +72,13 @@ public boolean execute(ScriptEntry scriptEntry) { if (scriptEntry.has_tags) scriptEntry.setArguments(TagManager.fillArguments(scriptEntry.getArguments(), scriptEntry, true)); // Replace tags - /* If using NPCID:# or PLAYER:Name arguments, these need to be changed out immediately because... - * 1) Denizen/Player flags need the desired NPC/PLAYER before parseArgs's getFilledArguments() so that - * the Player/Denizen flags will read from the correct Object. If using PLAYER or NPCID arguments, - * the desired Objects are obviously not the same objects that were sent with the ScriptEntry. - * 2) These arguments should be valid for EVERY ScriptCommand, so why not just take care of it - * here, instead of requiring each command to take care of the argument. - */ + /* If using NPCID:# or PLAYER:Name arguments, these need to be changed out immediately because... + * 1) Denizen/Player flags need the desired NPC/PLAYER before parseArgs's getFilledArguments() so that + * the Player/Denizen flags will read from the correct Object. If using PLAYER or NPCID arguments, + * the desired Objects are obviously not the same objects that were sent with the ScriptEntry. + * 2) These arguments should be valid for EVERY ScriptCommand, so why not just take care of it + * here, instead of requiring each command to take care of the argument. + */ List newArgs = new ArrayList(); @@ -135,7 +135,7 @@ else if (aH.matchesValueArg("npcid, npc", arg, aH.ArgumentType.String)) { // Parse the rest of the arguments for execution. command.parseArgs(scriptEntry); - } catch (InvalidArgumentsException e) { + } catch (InvalidArgumentsException e) { keepGoing = false; // Give usage hint if InvalidArgumentsException was called. diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java index a60edd659a..96395d2b30 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java @@ -19,71 +19,71 @@ public class CommandRegistry implements dRegistry { - public Denizen denizen; - - public CommandRegistry(Denizen denizen) { - this.denizen = denizen; - } - - private Map instances = new HashMap(); - private Map, String> classes = new HashMap, String>(); - - @Override - public boolean register(String commandName, RegistrationableInstance commandInstance) { - this.instances.put(commandName.toUpperCase(), (AbstractCommand) commandInstance); - this.classes.put(((AbstractCommand) commandInstance).getClass(), commandName.toUpperCase()); - return true; - } - - @Override - public Map list() { - return instances; - } - - @Override - public AbstractCommand get(String commandName) { - if (instances.containsKey(commandName.toUpperCase())) return instances.get(commandName.toUpperCase()); - else return null; - } - - @Override - public T get(Class clazz) { - if (classes.containsKey(clazz)) return (T) clazz.cast(instances.get(classes.get(clazz))); - else return null; - } - - @Override - public void registerCoreMembers() { + public Denizen denizen; + + public CommandRegistry(Denizen denizen) { + this.denizen = denizen; + } + + private Map instances = new HashMap(); + private Map, String> classes = new HashMap, String>(); + + @Override + public boolean register(String commandName, RegistrationableInstance commandInstance) { + this.instances.put(commandName.toUpperCase(), (AbstractCommand) commandInstance); + this.classes.put(((AbstractCommand) commandInstance).getClass(), commandName.toUpperCase()); + return true; + } + + @Override + public Map list() { + return instances; + } + + @Override + public AbstractCommand get(String commandName) { + if (instances.containsKey(commandName.toUpperCase())) return instances.get(commandName.toUpperCase()); + else return null; + } + + @Override + public T get(Class clazz) { + if (classes.containsKey(clazz)) return (T) clazz.cast(instances.get(classes.get(clazz))); + else return null; + } + + @Override + public void registerCoreMembers() { registerCoreMember(AnchorCommand.class, "ANCHOR", "anchor [id:] [assume/add/remove/walkto/walknear] (range:<#>)", 2); - + registerCoreMember(AnimateCommand.class, - "ANIMATE", "animate [|...] [animation:]", 1); + "ANIMATE", "animate [|...] [animation:]", 1); registerCoreMember(AnimateChestCommand.class, - "ANIMATECHEST", "animatechest [] ({open}/close) (sound:{true}/false)", 1); - - registerCoreMember(AnnounceCommand.class, - "ANNOUNCE", "announce [\"\"] (to_ops) (to_flagged:)", 1); + "ANIMATECHEST", "animatechest [] ({open}/close) (sound:{true}/false)", 1); + + registerCoreMember(AnnounceCommand.class, + "ANNOUNCE", "announce [\"\"] (to_ops) (to_flagged:)", 1); registerCoreMember(AssignmentCommand.class, - "ASSIGNMENT", "assignment [{set}/remove] (script:)", 1); - + "ASSIGNMENT", "assignment [{set}/remove] (script:)", 1); + registerCoreMember(AttackCommand.class, - "ATTACK", "attack (cancel) (|...) (target:)", 0); + "ATTACK", "attack (cancel) (|...) (target:)", 0); registerCoreMember(BreakCommand.class, "BREAK", "break [] (entity:) (radius:<#.#>)", 1); registerCoreMember(BurnCommand.class, - "BURN", "burn [|...] (duration:)", 1); + "BURN", "burn [|...] (duration:)", 1); registerCoreMember(CastCommand.class, - "CAST, POTION", "cast [] (remove) (duration:) (power:<#>) (|...)", 1); + "CAST, POTION", "cast [] (remove) (duration:) (power:<#>) (|...)", 1); registerCoreMember(ChatCommand.class, - "CHAT", "chat [\"\"] (targets:|...)", 1); + "CHAT", "chat [\"\"] (targets:|...)", 1); registerCoreMember(ChunkLoadCommand.class, "CHUNKLOAD", "chunkload ({add}/remove/removeall) [] (duration:)", 1); @@ -92,7 +92,7 @@ public void registerCoreMembers() { "COMPASS", "compass []", 1); registerCoreMember(CooldownCommand.class, - "COOLDOWN", "cooldown (duration:) (global) (script:)", 1); + "COOLDOWN", "cooldown (duration:) (global) (script:)", 1); registerCoreMember(CopyBlockCommand.class, "COPYBLOCK", "copyblock [location:] [to:]", 1); @@ -104,148 +104,145 @@ public void registerCoreMembers() { "DEFINE", "define [] []", 2); registerCoreMember(DetermineCommand.class, - "DETERMINE", "determine []", 1); + "DETERMINE", "determine []", 1); registerCoreMember(DisengageCommand.class, - "DISENGAGE", "disengage", 0); + "DISENGAGE", "disengage", 0); registerCoreMember(DisplayItemCommand.class, "DISPLAYITEM", "displayitem (remove) [] [] (duration:)", 2); registerCoreMember(DropCommand.class, - "DROP", "drop [//] [] (qty:<#>)", 1); - + "DROP", "drop [//] [] (qty:<#>)", 1); + registerCoreMember(EngageCommand.class, - "ENGAGE", "engage (duration:)", 0); + "ENGAGE", "engage (duration:)", 0); registerCoreMember(EngraveCommand.class, - "ENGRAVE", "engrave (set/remove)", 0); + "ENGRAVE", "engrave (set/remove)", 0); registerCoreMember(EquipCommand.class, - "EQUIP", "equip (hand:) (head:) (chest:) (legs:) (boots:)", 1); + "EQUIP", "equip (hand:) (head:) (chest:) (legs:) (boots:)", 1); registerCoreMember(ExecuteCommand.class, - "EXECUTE", "execute [as_player/as_op/as_npc/as_server] []", 2); + "EXECUTE", "execute [as_player/as_op/as_npc/as_server] []", 2); registerCoreMember(ExperienceCommand.class, "EXPERIENCE", "experience [{set}/give/take] (level) [<#>]", 2); registerCoreMember(ExplodeCommand.class, - "EXPLODE", "explode (power:<#.#>) () (fire) (breakblocks)", 0); + "EXPLODE", "explode (power:<#.#>) () (fire) (breakblocks)", 0); registerCoreMember(FailCommand.class, - "FAIL", "fail (script:)", 0); + "FAIL", "fail (script:)", 0); registerCoreMember(FeedCommand.class, - "FEED", "feed (amt:<#>) (target:|...)", 0); + "FEED", "feed (amt:<#>) (target:|...)", 0); registerCoreMember(FinishCommand.class, - "FINISH", "finish (script:)", 0); + "FINISH", "finish (script:)", 0); registerCoreMember(FireworkCommand.class, - "FIREWORK", "firework () (power:<#>) (type:/random) (primary:|...) (fade:|...) (flicker) (trail)", 0); + "FIREWORK", "firework () (power:<#>) (type:/random) (primary:|...) (fade:|...) (flicker) (trail)", 0); registerCoreMember(FishCommand.class, - "FISH", "fish (catchfish) (stop) () (catchpercent:<#>)", 1); + "FISH", "fish (catchfish) (stop) () (catchpercent:<#>)", 1); registerCoreMember(FlagCommand.class, - "FLAG", "flag ({player}/npc/global) [([<#>])](:)[:] (duration:)", 1); + "FLAG", "flag ({player}/npc/global) [([<#>])](:)[:] (duration:)", 1); registerCoreMember(FlyCommand.class, - "FLY", "fly (cancel) [|...] (origin:) (destinations:|...) (speed:<#.#>)", 1); + "FLY", "fly (cancel) [|...] (origin:) (destinations:|...) (speed:<#.#>)", 1); registerCoreMember(FollowCommand.class, - "FOLLOW", "follow (stop) (lead:<#.#>)", 0); - + "FOLLOW", "follow (stop) (lead:<#.#>)", 0); + registerCoreMember(ForEachCommand.class, - "FOREACH", "foreach [location:|...] [