From 368a8aeaef8d0fac06e878d42d547d77b50ef482 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 18 May 2013 12:45:30 -0600 Subject: [PATCH 1/6] Disable plugin method --- src/me/pkt77/giants/Giants.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/me/pkt77/giants/Giants.java b/src/me/pkt77/giants/Giants.java index fd742d0..037ea19 100644 --- a/src/me/pkt77/giants/Giants.java +++ b/src/me/pkt77/giants/Giants.java @@ -61,5 +61,11 @@ public void onEnable() { } else { log.info("[Giants] Cannot Find SpoutPlugin: Disabling Spout features."); } + log.info("[Giants] --- Enabled ---"); } -} \ No newline at end of file + + @Override + public void onDisable(){ + log.info("[Giants] --- Disabled ---"); + } +} From 039b6d015440d0d1aa6f08cc8ce9ff9e01316e44 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 18 May 2013 12:47:15 -0600 Subject: [PATCH 2/6] Why use an underscore? --- src/me/pkt77/giants/spout/SpoutListener.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/me/pkt77/giants/spout/SpoutListener.java b/src/me/pkt77/giants/spout/SpoutListener.java index ab4a86c..468101b 100644 --- a/src/me/pkt77/giants/spout/SpoutListener.java +++ b/src/me/pkt77/giants/spout/SpoutListener.java @@ -13,11 +13,11 @@ import org.getspout.spoutapi.material.CustomItem; public class SpoutListener implements Listener { - private Giants _giants; + private Giants giants; public SpoutListener(Giants giants) { - _giants = giants; - _giants.getServer().getPluginManager().registerEvents(this, giants); + this.giants = giants; + this.giants.getServer().getPluginManager().registerEvents(this, giants); } @EventHandler @@ -38,4 +38,4 @@ public void onPlayerInteract(PlayerInteractEvent event) { } } } -} \ No newline at end of file +} From 428d1784362ece84884d37680ee44c8765fec809 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 18 May 2013 12:50:58 -0600 Subject: [PATCH 3/6] Do away with all static methods to make more API-like --- src/me/pkt77/giants/utils/API.java | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/me/pkt77/giants/utils/API.java b/src/me/pkt77/giants/utils/API.java index 533a265..98f4d11 100644 --- a/src/me/pkt77/giants/utils/API.java +++ b/src/me/pkt77/giants/utils/API.java @@ -11,31 +11,35 @@ import org.bukkit.entity.LivingEntity; public class API { - private static Giants _giants; + private static Giants giants; private Commands commands; private static FileHandler fileHandler; + @Deprecated public API(Giants giants) { - _giants = giants; + } + + public void setup(Giants giants){ + this.giants = giants; new Listeners(_giants); commands = new Commands(_giants); - _giants.getCommand("giants").setExecutor(commands); + this.giants.getCommand("giants").setExecutor(commands); fileHandler = new FileHandler(_giants); } - public static boolean isGiant(Entity entity) { + public boolean isGiant(Entity entity) { return entity instanceof Giant; } - public static boolean isGiant(LivingEntity livingEntity) { + public boolean isGiant(LivingEntity livingEntity) { return livingEntity instanceof Giant; } - public static List getGiantSpawnWorlds() { + public List getGiantSpawnWorlds() { return getFileHandler().getPropertyList(Config.CONFIG, "Giants Configuration.Spawn Settings.Worlds"); } - public static FileHandler getFileHandler() { + public FileHandler getFileHandler() { return fileHandler; } -} \ No newline at end of file +} From 684b73391615839c7bb54c9bfd979420d62991c8 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 18 May 2013 11:52:16 -0700 Subject: [PATCH 4/6] Add support in for API --- src/me/pkt77/giants/Giants.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/me/pkt77/giants/Giants.java b/src/me/pkt77/giants/Giants.java index 037ea19..da14233 100644 --- a/src/me/pkt77/giants/Giants.java +++ b/src/me/pkt77/giants/Giants.java @@ -9,6 +9,7 @@ public class Giants extends JavaPlugin { public final Logger log = Logger.getLogger("Minecraft"); + private API api; /* * CHANGE LOG: @@ -53,7 +54,8 @@ public class Giants extends JavaPlugin { @Override public void onEnable() { - new API(this); + api = new API(); + api.setup(this); if (Bukkit.getPluginManager().getPlugin("Spout") != null) { log.info("[Giants] Found SpoutPlugin: Enabling Spout features."); new GiantEgg(this); @@ -68,4 +70,8 @@ public void onEnable() { public void onDisable(){ log.info("[Giants] --- Disabled ---"); } -} + + public API getAPI(){ + return api; + } +} From 99a4399a0aacab29b3c0c8717d3f75dc0301f506 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 18 May 2013 11:54:24 -0700 Subject: [PATCH 5/6] Static methods are not for your convience --- src/me/pkt77/giants/Commands.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/me/pkt77/giants/Commands.java b/src/me/pkt77/giants/Commands.java index 3751e69..193bea7 100644 --- a/src/me/pkt77/giants/Commands.java +++ b/src/me/pkt77/giants/Commands.java @@ -31,13 +31,13 @@ public boolean onCommand(CommandSender sender, Command command, String commandLa if (sender instanceof Player) { player = (Player) sender; if (player.hasPermission("giants.reload")) { - API.getFileHandler().loadConfig(); + _giants.getAPI().getFileHandler().loadConfig(); sender.sendMessage(ChatColor.GREEN + "Giants config file reloaded."); } else { sender.sendMessage(ChatColor.RED + "You do not have permission to use this command"); } } else { - API.getFileHandler().loadConfig(); + _giants.getAPI().getFileHandler().loadConfig(); _giants.log.info("Giants config file reloaded."); } } @@ -45,4 +45,4 @@ public boolean onCommand(CommandSender sender, Command command, String commandLa } return true; } -} \ No newline at end of file +} From 7de874d0a7aba97c72983b39854826ca053f4ac5 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 18 May 2013 12:57:48 -0600 Subject: [PATCH 6/6] Major corrections via new API --- src/me/pkt77/giants/events/Listeners.java | 42 +++++++++++++---------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/me/pkt77/giants/events/Listeners.java b/src/me/pkt77/giants/events/Listeners.java index ff47946..213e49e 100644 --- a/src/me/pkt77/giants/events/Listeners.java +++ b/src/me/pkt77/giants/events/Listeners.java @@ -37,7 +37,7 @@ public Listeners(Giants giants) { @EventHandler public void onGiantSpawn(SpawnEvent event) { - if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Debug Mode").equalsIgnoreCase("true")) { + if (_giants.getAPI().getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Debug Mode").equalsIgnoreCase("true")) { String message = API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Language.Debug Message"); if (message != null) { for (Player player : Bukkit.getServer().getOnlinePlayers()) { @@ -59,7 +59,7 @@ public void GiantSpawnEvent(CreatureSpawnEvent event) { EntityType type = event.getEntityType(); SpawnReason spawnReason = event.getSpawnReason(); - if (!API.getGiantSpawnWorlds().contains(entity.getWorld().getName())) { + if (!_giants.getAPI().getGiantSpawnWorlds().contains(entity.getWorld().getName())) { return; } @@ -99,6 +99,10 @@ public void GiantSpawnEvent(CreatureSpawnEvent event) { if (spawngiant == 1) { SpawnEvent SE = new SpawnEvent(location); Bukkit.getServer().getPluginManager().callEvent(SE); + if (SE.isCancelled()){ + spawngiant = 0; + return; + } } } } @@ -116,7 +120,7 @@ public void GiantHealth(EntityRegainHealthEvent event) { health = 100; } - if (API.isGiant(entity)) { + if (_giants.getAPI().isGiant(entity)) { event.setAmount(health); } } @@ -138,9 +142,9 @@ public void FireAttack(EntityTargetEvent event) { } if ((entity instanceof LivingEntity)) { - if (API.isGiant(entity)) { - if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Fire Attack.Enabled").equalsIgnoreCase("true")) { - if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Sounds.Fire Attack").equalsIgnoreCase("true")) { + if (_giants.getAPI().isGiant(entity)) { + if (_giants.getAPI().getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Fire Attack.Enabled").equalsIgnoreCase("true")) { + if (_giants.getAPI().getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Sounds.Fire Attack").equalsIgnoreCase("true")) { target.getLocation().getWorld().playSound(target.getLocation(), Sound.FIRE, 1, 0); } try { @@ -161,7 +165,7 @@ public void LightningAttack(EntityTargetEvent event) { Entity target = event.getTarget(); if ((entity instanceof LivingEntity)) { - if (API.isGiant(entity)) { + if (_giants.getAPI().isGiant(entity)) { if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Lightning Attack").equalsIgnoreCase("true")) { try { target.getLocation().getWorld().strikeLightning(target.getLocation()); @@ -185,7 +189,7 @@ public void ThrownBoulderAttack(PlayerMoveEvent event) { } for (Entity entity : player.getNearbyEntities(15, 12, 15)) { - if (API.isGiant(entity)) { + if (_giants.getAPI().isGiant(entity)) { if (entity.getNearbyEntities(15, 12, 15).contains(player) && !entity.getNearbyEntities(5, 3, 5).contains(player)) { inRange = true; } @@ -195,7 +199,7 @@ public void ThrownBoulderAttack(PlayerMoveEvent event) { Vector direction = ((LivingEntity) entity).getEyeLocation().getDirection().multiply(2); Fireball fireball = entity.getWorld().spawn(((LivingEntity) entity).getEyeLocation().add(direction.getX(), direction.getY() - 5, direction.getZ()), Fireball.class); fireball.setShooter((LivingEntity) entity); - if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Sounds.Throw Boulder Attack").equalsIgnoreCase("true")) { + if (_giants.getAPI().getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Sounds.Throw Boulder Attack").equalsIgnoreCase("true")) { player.getLocation().getWorld().playSound(player.getLocation(), Sound.GHAST_FIREBALL, 1, 0); } } @@ -208,8 +212,8 @@ public void ThrownBoulderAttack(PlayerMoveEvent event) { @EventHandler public void KickAttack(PlayerMoveEvent event) { Player player = event.getPlayer(); - if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Kick Attack.Enabled").equalsIgnoreCase("true")) { - String config = API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Kick Attack.Kick Height"); + if (v.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Kick Attack.Enabled").equalsIgnoreCase("true")) { + String config = _giants.getAPI().getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Kick Attack.Kick Height"); int height; try { @@ -225,7 +229,7 @@ public void KickAttack(PlayerMoveEvent event) { } if (chance == 50) { for (Entity entity : player.getNearbyEntities(5, 5, 5)) { - if (API.isGiant(entity)) { + if (_giants.getAPI().isGiant(entity)) { if (entity.getNearbyEntities(5, 5, 5).contains(player)) { player.setVelocity(new Vector(0, height, 0)); if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Sounds.Kick Attack").equalsIgnoreCase("true")) { @@ -241,7 +245,7 @@ public void KickAttack(PlayerMoveEvent event) { @EventHandler public void StompAttack(PlayerMoveEvent event) { Player player = event.getPlayer(); - if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Stomp Attack").equalsIgnoreCase("true")) { + if (_giants.getAPI().getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Attack Mechanisms.Stomp Attack").equalsIgnoreCase("true")) { Random pick = new Random(); int chance = 0; for (int counter = 1; counter <= 1; counter++) { @@ -249,7 +253,7 @@ public void StompAttack(PlayerMoveEvent event) { } if (chance == 50) { for (Entity entity : player.getNearbyEntities(3, 2, 3)) { - if (API.isGiant(entity)) { + if (_giants.getAPI().isGiant(entity)) { if (entity.getNearbyEntities(3, 2, 3).contains(player)) { player.getLocation().getWorld().createExplosion(player.getLocation(), 1.0F); } @@ -262,7 +266,7 @@ public void StompAttack(PlayerMoveEvent event) { @EventHandler public void GiantDrops(EntityDeathEvent event) { Entity entity = event.getEntity(); - String string = API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Giant Stats.Experience"); + String string = _giants.getAPI().getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Giant Stats.Experience"); int exp; try { @@ -271,12 +275,12 @@ public void GiantDrops(EntityDeathEvent event) { exp = 5; } - if (API.isGiant(entity)) { - if (API.getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Sounds.Death").equalsIgnoreCase("true")) { + if (_giants.getAPI().isGiant(entity)) { + if (_giants.getAPI().getFileHandler().getProperty(Config.CONFIG, "Giants Configuration.Sounds.Death").equalsIgnoreCase("true")) { entity.getLocation().getWorld().playSound(entity.getLocation(), Sound.ENDERDRAGON_GROWL, 1, 0); } event.setDroppedExp(exp); - List newDrop = API.getFileHandler().getPropertyList(Config.CONFIG, "Giants Configuration.Giant Stats.Drops"); + List newDrop = _giants.getAPI().getFileHandler().getPropertyList(Config.CONFIG, "Giants Configuration.Giant Stats.Drops"); if (newDrop == null || newDrop.contains("") || newDrop.toString().equalsIgnoreCase("[]")) { return; } @@ -342,4 +346,4 @@ public void GiantDrops(EntityDeathEvent event) { event.getDrops().addAll(drops); } } -} \ No newline at end of file +}