diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/BrewPotionExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/BrewPotionExperienceSource.java index 6e09b771..81599307 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/BrewPotionExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/source/BrewPotionExperienceSource.java @@ -36,18 +36,16 @@ public class BrewPotionExperienceSource extends ExperienceSource { @Override public boolean matches(PlayerData player, PotionMeta meta) { - return hasRightClass(player) && (types.isEmpty() || new ArrayList<>(types).stream().filter(type -> meta.getBasePotionData().getType() == type).count() > 0); + return hasRightClass(player) + && (types.isEmpty() || new ArrayList<>(types).stream().filter(type -> meta.getBasePotionData().getType() == type).count() > 0); } @Override public ExperienceManager newManager() { return new ExperienceManager() { - @EventHandler(priority = EventPriority.HIGH) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void a(BrewEvent event) { - if (event.isCancelled()) - return; - Optional playerOpt = getNearbyPlayer(event.getBlock().getLocation(), 10); if (!playerOpt.isPresent()) return; diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/CraftItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/CraftItemExperienceSource.java index 78db80b3..fa7c085a 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/CraftItemExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/source/CraftItemExperienceSource.java @@ -14,7 +14,7 @@ import net.mmogroup.mmolib.api.MMOLineConfig; public class CraftItemExperienceSource extends SpecificExperienceSource { public final Material material; - + public CraftItemExperienceSource(Profession profession, MMOLineConfig config) { super(profession, config); @@ -26,15 +26,12 @@ public class CraftItemExperienceSource extends SpecificExperienceSource newManager() { return new ExperienceManager() { - @EventHandler(priority = EventPriority.HIGH) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void a(CraftItemEvent event) { - if (event.isCancelled()) - return; - PlayerData data = PlayerData.get((Player) event.getWhoClicked()); for (CraftItemExperienceSource source : getSources()) if (source.matches(data, event.getInventory().getResult().getType())) - source.giveExperience(data, event.getInventory().getLocation()); + source.giveExperience(data, event.getInventory().getResult().getAmount(), event.getInventory().getLocation()); } }; } diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/EnchantItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/EnchantItemExperienceSource.java index 80050b83..a2ea6081 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/EnchantItemExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/source/EnchantItemExperienceSource.java @@ -35,16 +35,13 @@ public class EnchantItemExperienceSource extends ExperienceSource { public boolean matches(PlayerData player, Void v) { return hasRightClass(player); } - + @Override public ExperienceManager newManager() { return new ExperienceManager() { - @EventHandler(priority = EventPriority.HIGH) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void a(EnchantItemEvent event) { - if (event.isCancelled()) - return; - PlayerData player = PlayerData.get(event.getEnchanter()); for (EnchantItemExperienceSource source : getSources()) if (source.matches(player, null)) { diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/FishItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/FishItemExperienceSource.java index 38654bde..2b328d24 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/FishItemExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/source/FishItemExperienceSource.java @@ -28,9 +28,9 @@ public class FishItemExperienceSource extends SpecificExperienceSource newManager() { return new ExperienceManager() { - @EventHandler(priority = EventPriority.HIGH) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void a(PlayerFishEvent event) { - if (!event.isCancelled() && event.getState() == State.CAUGHT_FISH) { + if (event.getState() == State.CAUGHT_FISH) { ItemStack caught = ((Item) event.getCaught()).getItemStack(); if (caught.hasItemMeta()) return; @@ -38,7 +38,7 @@ public class FishItemExperienceSource extends SpecificExperienceSource { @Override public ExperienceManager newManager() { return new ExperienceManager() { - @EventHandler(priority = EventPriority.MONITOR) + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void a(EntityKillEntityEvent event) { Bukkit.getScheduler().runTaskLater(MMOCore.plugin, new Runnable() { @Override public void run() { - if (!event.getTarget().isDead()) return; - if (event.getEntity() instanceof Player && !event.getEntity().hasMetadata("NPC")) { - if(event.getTarget().hasMetadata("spawner_spawned")) return; + if (event.getTarget().isDead() && event.getEntity() instanceof Player && !event.getEntity().hasMetadata("NPC") + && !event.getTarget().hasMetadata("spawner_spawned")) { PlayerData data = PlayerData.get((Player) event.getEntity()); for (KillMobExperienceSource source : getSources()) if (source.matches(data, event.getTarget())) - source.giveExperience(data, event.getTarget().getLocation()); + source.giveExperience(data, 1, event.getTarget().getLocation()); } } }, 2); diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/MineBlockExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/MineBlockExperienceSource.java index 55c7ef4a..908cfe2d 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/MineBlockExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/source/MineBlockExperienceSource.java @@ -12,8 +12,8 @@ import net.Indyuce.mmocore.api.experience.Profession; import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.manager.profession.ExperienceManager; -import net.mmogroup.mmolib.api.MMOLineConfig; import net.mmogroup.mmolib.MMOLib; +import net.mmogroup.mmolib.api.MMOLineConfig; public class MineBlockExperienceSource extends SpecificExperienceSource { public final Material material; @@ -35,14 +35,14 @@ public class MineBlockExperienceSource extends SpecificExperienceSource newManager() { return new ExperienceManager() { - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void a(BlockBreakEvent event) { - if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.SURVIVAL) + if (event.getPlayer().getGameMode() != GameMode.SURVIVAL) return; + PlayerData data = PlayerData.get(event.getPlayer()); - - for (MineBlockExperienceSource source : getSources()) - { + + for (MineBlockExperienceSource source : getSources()) { if (source.silkTouch && hasSilkTouch(event.getPlayer().getInventory().getItemInMainHand())) continue; if (source.crop && !MMOLib.plugin.getVersion().getWrapper().isCropFullyGrown(event.getBlock())) @@ -51,7 +51,7 @@ public class MineBlockExperienceSource extends SpecificExperienceSource newManager() { return new ExperienceManager() { - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void a(BlockPlaceEvent event) { - if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.SURVIVAL) + if (event.getPlayer().getGameMode() != GameMode.SURVIVAL) return; + PlayerData data = PlayerData.get(event.getPlayer()); - - for (PlaceBlockExperienceSource source : getSources()) { + + for (PlaceBlockExperienceSource source : getSources()) if (source.matches(data, event.getBlock().getType())) - source.giveExperience(data, event.getBlock().getLocation()); - } + source.giveExperience(data, 1, event.getBlock().getLocation()); } }; } diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/RepairItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/RepairItemExperienceSource.java index f41a303a..d98d306a 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/RepairItemExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/source/RepairItemExperienceSource.java @@ -39,28 +39,29 @@ public class RepairItemExperienceSource extends ExperienceSource { public ExperienceManager newManager() { return new ExperienceManager() { - @EventHandler(priority = EventPriority.HIGH) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void a(InventoryClickEvent event) { - if (!event.isCancelled() && event.getInventory() != null && event.getInventory().getType() == InventoryType.ANVIL && event.getSlot() == 2) { + if (event.getInventory() != null && event.getInventory().getType() == InventoryType.ANVIL && event.getSlot() == 2) { ItemStack item = event.getCurrentItem(); PlayerData data = PlayerData.get((Player) event.getWhoClicked()); - + for (RepairItemExperienceSource source : getSources()) if (source.matches(data, item)) { - - if(!(event.getInventory() instanceof AnvilInventory)) + + if (!(event.getInventory() instanceof AnvilInventory)) return; - - if(((AnvilInventory) event.getInventory()).getRepairCost() > - ((Player) event.getWhoClicked()).getLevel()) return; - + + if (((AnvilInventory) event.getInventory()).getRepairCost() > ((Player) event.getWhoClicked()).getLevel()) + return; + /* * make sure the items can actually be repaired * before getting the amount of durability repaired */ ItemStack old = event.getInventory().getItem(0); - if (old == null || old.getType() == Material.AIR) return; + if (old == null || old.getType() == Material.AIR) + return; if (old.getType().getMaxDurability() < 30 || item.getType().getMaxDurability() < 10) return; @@ -72,7 +73,8 @@ public class RepairItemExperienceSource extends ExperienceSource { * was repaired, substract damage from old item * durability. */ - double exp = MMOCore.plugin.smithingManager.getBaseExperience(item.getType()) * Math.max(0, ((Damageable) old.getItemMeta()).getDamage() - ((Damageable) item.getItemMeta()).getDamage()) / 100; + double exp = MMOCore.plugin.smithingManager.getBaseExperience(item.getType()) + * Math.max(0, ((Damageable) old.getItemMeta()).getDamage() - ((Damageable) item.getItemMeta()).getDamage()) / 100; giveExperience(data, (int) exp, null); } } diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/SmeltItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/SmeltItemExperienceSource.java index ff74f34e..d570c10c 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/SmeltItemExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/source/SmeltItemExperienceSource.java @@ -30,35 +30,33 @@ public class SmeltItemExperienceSource extends SpecificExperienceSource newManager() { return new ExperienceManager() { - @EventHandler(priority = EventPriority.HIGH) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void a(BlockCookEvent event) { - if (!event.isCancelled()) { - Optional player = getNearestPlayer(event.getBlock().getLocation(), 10); - if (!player.isPresent()) - return; + Optional player = getNearestPlayer(event.getBlock().getLocation(), 10); + if (!player.isPresent()) + return; - ItemStack caught = event.getResult(); - if (caught.hasItemMeta()) - return; + ItemStack caught = event.getResult(); + if (caught.hasItemMeta()) + return; - PlayerData data = PlayerData.get(player.get()); - for (SmeltItemExperienceSource source : getSources()) - if (source.matches(data, caught)) - source.giveExperience(data, event.getBlock().getLocation()); - } + PlayerData data = PlayerData.get(player.get()); + for (SmeltItemExperienceSource source : getSources()) + if (source.matches(data, caught)) + source.giveExperience(data, 1, event.getBlock().getLocation()); } }; } private Optional getNearestPlayer(Location loc, double d) { final double d2 = d * d; - final Player[] nearby = loc.getWorld().getPlayers().stream() - .filter(player -> player.getLocation().distanceSquared(loc) < d2).toArray(Player[]::new); + final Player[] nearby = loc.getWorld().getPlayers().stream().filter(player -> player.getLocation().distanceSquared(loc) < d2) + .toArray(Player[]::new); Player selected = null; double lastDist = d2; - for(Player p : nearby) { + for (Player p : nearby) { double currDist = p.getLocation().distance(loc); - if(currDist < lastDist) { + if (currDist < lastDist) { lastDist = currDist; selected = p; } diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/type/ExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/type/ExperienceSource.java index 39d1d93b..26469223 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/type/ExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/source/type/ExperienceSource.java @@ -25,6 +25,7 @@ public abstract class ExperienceSource { this.profess = profess; } + // TODO remove setter public void setClass(PlayerClass profess) { this.profess = profess; } diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/type/SpecificExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/type/SpecificExperienceSource.java index d28fa934..ce2e741c 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/type/SpecificExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/source/type/SpecificExperienceSource.java @@ -10,9 +10,10 @@ import net.mmogroup.mmolib.api.MMOLineConfig; public abstract class SpecificExperienceSource extends ExperienceSource { private final RandomAmount amount; - /* - * not all experience sources have to specify a random experience amount e.g - * ENCHANT and ALCHEMY experience depend on the enchanted item. + /** + * Used to register experience sources with SPECIFIC experience outputs. + * Other experience sources like ENCHANT have their exp output depend on the + * enchanted item. ALCHEMY exp outputs depend on the potion crafted */ public SpecificExperienceSource(Profession profession, MMOLineConfig config) { super(profession); @@ -29,7 +30,18 @@ public abstract class SpecificExperienceSource extends ExperienceSource { return amount.calculateInt(); } - public void giveExperience(PlayerData player, Location loc) { - giveExperience(player, rollAmount(), loc); + /** + * Used when a player needs to gain experience after performing the action + * corresponding to this exp source + * + * @param multiplier + * Used by the CraftItem experience source, multiplies the exp + * earned by a certain factor. When crafting an item, the + * multiplier is equal to the amount of items crafted + * @param loc + * Location used to display the exp hologram + */ + public void giveExperience(PlayerData player, int multiplier, Location loc) { + giveExperience(player, rollAmount() * multiplier, loc); } } diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/KillMythicFactionExperienceSource.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/KillMythicFactionExperienceSource.java index 09f3beda..d68afcca 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/KillMythicFactionExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/KillMythicFactionExperienceSource.java @@ -37,7 +37,7 @@ public class KillMythicFactionExperienceSource extends SpecificExperienceSource< PlayerData data = PlayerData.get((Player) event.getKiller()); for (KillMythicFactionExperienceSource source : getSources()) if (source.matches(data, event.getMob().getFaction())) - source.giveExperience(data, event.getEntity().getLocation()); + source.giveExperience(data, 1, event.getEntity().getLocation()); } }, 2); } diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/KillMythicMobExperienceSource.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/KillMythicMobExperienceSource.java index 36fb8149..67b40591 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/KillMythicMobExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/KillMythicMobExperienceSource.java @@ -36,7 +36,7 @@ public class KillMythicMobExperienceSource extends SpecificExperienceSource