diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java index 2befa960..7541e3ca 100644 --- a/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -5,7 +5,7 @@ import io.lumine.mythic.lib.version.SpigotPlugin; import io.lumine.mythic.utils.plugin.LuminePlugin; import net.Indyuce.mmocore.api.ConfigFile; import net.Indyuce.mmocore.api.PlayerActionBar; -import net.Indyuce.mmocore.api.loot.LootChest; +import net.Indyuce.mmocore.loot.chest.LootChest; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource; import net.Indyuce.mmocore.api.player.social.guilds.Guild; diff --git a/src/main/java/net/Indyuce/mmocore/api/block/BlockInfo.java b/src/main/java/net/Indyuce/mmocore/api/block/BlockInfo.java index 60b8236a..1007354c 100644 --- a/src/main/java/net/Indyuce/mmocore/api/block/BlockInfo.java +++ b/src/main/java/net/Indyuce/mmocore/api/block/BlockInfo.java @@ -5,8 +5,8 @@ import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.condition.type.BlockCondition; import io.lumine.mythic.lib.api.condition.type.MMOCondition; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.droptable.DropTable; -import net.Indyuce.mmocore.api.loot.LootBuilder; +import net.Indyuce.mmocore.loot.droptable.DropTable; +import net.Indyuce.mmocore.loot.LootBuilder; import net.Indyuce.mmocore.api.quest.trigger.Trigger; import org.apache.commons.lang.Validate; import org.bukkit.Location; diff --git a/src/main/java/net/Indyuce/mmocore/api/event/LootChestSpawnEvent.java b/src/main/java/net/Indyuce/mmocore/api/event/LootChestSpawnEvent.java index df5e75c2..757d33d2 100644 --- a/src/main/java/net/Indyuce/mmocore/api/event/LootChestSpawnEvent.java +++ b/src/main/java/net/Indyuce/mmocore/api/event/LootChestSpawnEvent.java @@ -3,8 +3,8 @@ package net.Indyuce.mmocore.api.event; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; -import net.Indyuce.mmocore.api.loot.LootBuilder; -import net.Indyuce.mmocore.api.loot.LootChest; +import net.Indyuce.mmocore.loot.LootBuilder; +import net.Indyuce.mmocore.loot.chest.LootChest; import net.Indyuce.mmocore.api.player.PlayerData; public class LootChestSpawnEvent extends PlayerDataEvent implements Cancellable { diff --git a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java index 0adb3bf1..13e22eef 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java @@ -6,17 +6,17 @@ import org.bukkit.configuration.ConfigurationSection; import net.Indyuce.mmocore.api.block.BlockType; import net.Indyuce.mmocore.api.block.SkullBlockType; import net.Indyuce.mmocore.api.block.VanillaBlockType; -import net.Indyuce.mmocore.api.droptable.condition.BiomeCondition; -import net.Indyuce.mmocore.api.droptable.condition.Condition; -import net.Indyuce.mmocore.api.droptable.condition.LevelCondition; -import net.Indyuce.mmocore.api.droptable.condition.PermissionCondition; -import net.Indyuce.mmocore.api.droptable.condition.WorldCondition; -import net.Indyuce.mmocore.api.droptable.dropitem.DropItem; -import net.Indyuce.mmocore.api.droptable.dropitem.DropTableDropItem; -import net.Indyuce.mmocore.api.droptable.dropitem.GoldDropItem; -import net.Indyuce.mmocore.api.droptable.dropitem.MMDropTableDropItem; -import net.Indyuce.mmocore.api.droptable.dropitem.NoteDropItem; -import net.Indyuce.mmocore.api.droptable.dropitem.VanillaDropItem; +import net.Indyuce.mmocore.loot.droptable.condition.BiomeCondition; +import net.Indyuce.mmocore.loot.droptable.condition.Condition; +import net.Indyuce.mmocore.loot.droptable.condition.LevelCondition; +import net.Indyuce.mmocore.loot.droptable.condition.PermissionCondition; +import net.Indyuce.mmocore.loot.droptable.condition.WorldCondition; +import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem; +import net.Indyuce.mmocore.loot.droptable.dropitem.DropTableDropItem; +import net.Indyuce.mmocore.loot.droptable.dropitem.GoldDropItem; +import net.Indyuce.mmocore.loot.droptable.dropitem.MMDropTableDropItem; +import net.Indyuce.mmocore.loot.droptable.dropitem.NoteDropItem; +import net.Indyuce.mmocore.loot.droptable.dropitem.VanillaDropItem; import net.Indyuce.mmocore.experience.source.BrewPotionExperienceSource; import net.Indyuce.mmocore.experience.source.CraftItemExperienceSource; import net.Indyuce.mmocore.experience.source.EnchantItemExperienceSource; diff --git a/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java b/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java index b1bfebe2..43624dfe 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java @@ -2,8 +2,8 @@ package net.Indyuce.mmocore.api.load; import io.lumine.mythic.lib.api.MMOLineConfig; import net.Indyuce.mmocore.api.block.BlockType; -import net.Indyuce.mmocore.api.droptable.condition.Condition; -import net.Indyuce.mmocore.api.droptable.dropitem.DropItem; +import net.Indyuce.mmocore.loot.droptable.condition.Condition; +import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem; import net.Indyuce.mmocore.experience.provider.ExperienceDispenser; import net.Indyuce.mmocore.experience.source.type.ExperienceSource; import net.Indyuce.mmocore.api.quest.objective.Objective; diff --git a/src/main/java/net/Indyuce/mmocore/api/loot/LootChestRegion.java b/src/main/java/net/Indyuce/mmocore/api/loot/LootChestRegion.java deleted file mode 100644 index 45e0a221..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/loot/LootChestRegion.java +++ /dev/null @@ -1,185 +0,0 @@ -package net.Indyuce.mmocore.api.loot; - -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.event.LootChestSpawnEvent; -import net.Indyuce.mmocore.api.player.PlayerData; -import org.apache.commons.lang.Validate; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Chest; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.util.Vector; - -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Optional; -import java.util.Random; -import java.util.Set; -import java.util.logging.Level; - -public class LootChestRegion { - private final String id; - - private final long chestSpawnPeriod; - private final RegionBounds bounds; - private final ChestAlgorithmOptions algOptions; - private final Set tiers = new LinkedHashSet<>(); - private final BukkitRunnable runnable; - - private static final Random random = new Random(); - - public LootChestRegion(ConfigurationSection config) { - Validate.notNull(config, "Could not load config"); - id = config.getName().toLowerCase().replace("_", "-").replace(" ", "-"); - - bounds = new RegionBounds(config.getConfigurationSection("bounds")); - chestSpawnPeriod = config.getLong("spawn-period", 5 * 60); - algOptions = config.contains("algorithm-options") ? new ChestAlgorithmOptions(config.getConfigurationSection("algorithm-options")) - : ChestAlgorithmOptions.DEFAULT; - - Validate.isTrue(config.isConfigurationSection("tiers"), "Could not find chest tiers"); - for (String key : config.getConfigurationSection("tiers").getKeys(false)) - try { - tiers.add(new ChestTier(config.getConfigurationSection("tiers." + key))); - } catch (IllegalArgumentException exception) { - MMOCore.plugin.getLogger().log(Level.WARNING, - "Could not load tier '" + key + "' from chest region '" + id + "': " + exception.getMessage()); - } - - Validate.isTrue(!tiers.isEmpty(), "Your region must have at least one chest tier"); - - runnable = new LootChestRunnable(this); - } - - public String getId() { - return id; - } - - public Set getTiers() { - return tiers; - } - - public RegionBounds getBounds() { - return bounds; - } - - public long getChestSpawnPeriod() { - return chestSpawnPeriod; - } - - public BukkitRunnable getRunnable() { - return runnable; - } - - public void spawnChest(PlayerData player) { - if(!player.isOnline()) return; - // first randomly determine the chest tier - ChestTier tier = rollTier(); - - // find a random location, 20 trials max - Location location = getRandomLocation(player.getPlayer().getLocation()); - if (location == null) - return; - - LootChest lootChest = new LootChest(tier, this, location.getBlock()); - LootBuilder builder = new LootBuilder(player, tier.rollCapacity(player)); - tier.getDropTable().collect(builder); - - LootChestSpawnEvent event = new LootChestSpawnEvent(player, lootChest, builder); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) - return; - - List slots = new ArrayList<>(); - for (int j = 0; j < 27; j++) - slots.add(j); - - location.getBlock().setType(Material.CHEST); - Chest chest = (Chest) location.getBlock().getState(); - tier.getDropTable().collect(builder).forEach(item -> { - Integer slot = slots.get(random.nextInt(slots.size())); - chest.getInventory().setItem(slot, item); - slots.remove(slot); - }); - - MMOCore.plugin.lootChests.register(lootChest); - } - - // TODO improve - // TODO stat to increase chance to get higher tiers? - public ChestTier rollTier() { - - double s = 0; - for (ChestTier tier : tiers) { - if (random.nextDouble() < tier.chance / (1 - s)) - return tier; - s += tier.chance; - } - - return tiers.stream().findAny().orElse(null); - } - - public Location getRandomLocation(Location center) { - - for (int j = 0; j < algOptions.iterations; j++) { - Location random = tryRandomDirection(center); - if (random != null) - return random; - } - - /* - * no location has been found after the X iterations, return null and - * cancel chest spawning. worst case scenario, should not happen too - * often except if the player is in a really NARROW zone - */ - return null; - } - - public Location tryRandomDirection(Location center) { - - /* - * chooses a random direction and get the block in that direction which - * has the same height as the player - */ - double a = random.nextDouble() * 2 * Math.PI; - Vector dir = new Vector(Math.cos(a), 0, Math.sin(a)) - .multiply(algOptions.minRange + random.nextDouble() * (algOptions.maxRange - algOptions.minRange)); - Location random = center.add(dir); - - /* - * go up and down at the same time till it finds a non-solid block with - * a solid block underneath - */ - for (int h = 0; h <= algOptions.height * 2; h++) { - int z = h % 2 == 0 ? h / 2 : -(h + 1) / 2; // bijective from N to Z - Location checked = random.clone().add(0, z, 0); - if (isSuitable(checked)) - return checked; - } - - return null; - } - - private boolean isSuitable(Location loc) { - return !loc.getBlock().getType().isSolid() && loc.clone().add(0, -1, 0).getBlock().getType().isSolid(); - } - - public static class LootChestRunnable extends BukkitRunnable { - private final LootChestRegion region; - - public LootChestRunnable(LootChestRegion region) { - this.region = region; - - runTaskTimer(MMOCore.plugin, region.getChestSpawnPeriod() * 20, region.getChestSpawnPeriod() * 20); - } - - @Override - public void run() { - Optional found = region.getBounds().getPlayers().filter(PlayerData::canSpawnLootChest).findAny(); - found.ifPresent(region::spawnChest); - } - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 04282429..7d6a96c5 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -79,7 +79,7 @@ public class PlayerData extends OfflinePlayerData { // NON-FINAL player data stuff made public to facilitate field change public int skillGuiDisplayOffset; public SkillCasting skillCasting; - public boolean nocd; + public boolean noCooldown; public CombatRunnable combat; /** @@ -845,7 +845,7 @@ public class PlayerData extends OfflinePlayerData { } // Apply cooldown, mana and stamina costs - if (!nocd) { + if (!noCooldown) { double flatCooldownReduction = Math.max(0, Math.min(1, getStats().getStat(StatType.COOLDOWN_REDUCTION) / 100)); flatCooldownReduction *= flatCooldownReduction > 0 ? skill.getModifier("cooldown", getSkillLevel(skill.getSkill())) * 1000 : 0; diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/NoCooldownCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/NoCooldownCommandTreeNode.java index c7c63019..d573123e 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/NoCooldownCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/NoCooldownCommandTreeNode.java @@ -29,9 +29,9 @@ public class NoCooldownCommandTreeNode extends CommandTreeNode { } PlayerData data = PlayerData.get(player); - data.nocd = !data.nocd; + data.noCooldown = !data.noCooldown; CommandVerbose.verbose(sender, CommandVerbose.CommandType.NOCD, - ChatColor.YELLOW + "NoCD " + (data.nocd ? "enabled" : "disabled") + " for " + player.getName() + "."); + ChatColor.YELLOW + "NoCD " + (data.noCooldown ? "enabled" : "disabled") + " for " + player.getName() + "."); return CommandResult.SUCCESS; } } diff --git a/src/main/java/net/Indyuce/mmocore/comp/region/RegionCondition.java b/src/main/java/net/Indyuce/mmocore/comp/region/RegionCondition.java index 0795d84d..dbe80a15 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/region/RegionCondition.java +++ b/src/main/java/net/Indyuce/mmocore/comp/region/RegionCondition.java @@ -3,8 +3,8 @@ package net.Indyuce.mmocore.comp.region; import java.util.Arrays; import java.util.List; -import net.Indyuce.mmocore.api.droptable.condition.Condition; -import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance; +import net.Indyuce.mmocore.loot.droptable.condition.Condition; +import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; import io.lumine.mythic.lib.api.MMOLineConfig; public class RegionCondition extends Condition { diff --git a/src/main/java/net/Indyuce/mmocore/comp/region/WorldGuardMMOLoader.java b/src/main/java/net/Indyuce/mmocore/comp/region/WorldGuardMMOLoader.java index 5fed85e4..0c771cf7 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/region/WorldGuardMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/comp/region/WorldGuardMMOLoader.java @@ -1,6 +1,6 @@ package net.Indyuce.mmocore.comp.region; -import net.Indyuce.mmocore.api.droptable.condition.Condition; +import net.Indyuce.mmocore.loot.droptable.condition.Condition; import net.Indyuce.mmocore.api.load.MMOLoader; import io.lumine.mythic.lib.api.MMOLineConfig; diff --git a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java index 5fc6a4ee..aa0c8576 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java @@ -6,9 +6,9 @@ import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.block.BlockInfo; import net.Indyuce.mmocore.api.block.BlockInfo.BlockInfoOption; import net.Indyuce.mmocore.api.block.VanillaBlockType; -import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance; +import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; import net.Indyuce.mmocore.api.event.CustomBlockMineEvent; -import net.Indyuce.mmocore.api.loot.LootBuilder; +import net.Indyuce.mmocore.loot.LootBuilder; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.util.MMOCoreUtils; import org.bukkit.*; diff --git a/src/main/java/net/Indyuce/mmocore/listener/LootableChestsListener.java b/src/main/java/net/Indyuce/mmocore/listener/LootableChestsListener.java index bde1ae20..d29553a2 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/LootableChestsListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/LootableChestsListener.java @@ -6,7 +6,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryCloseEvent; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.loot.LootChest; +import net.Indyuce.mmocore.loot.chest.LootChest; public class LootableChestsListener implements Listener { @EventHandler diff --git a/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java b/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java index bfc2f884..28afaff3 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java @@ -2,10 +2,10 @@ package net.Indyuce.mmocore.listener.profession; import io.lumine.mythic.lib.version.VersionSound; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.droptable.dropitem.fishing.FishingDropItem; +import net.Indyuce.mmocore.loot.droptable.dropitem.fishing.FishingDropItem; import net.Indyuce.mmocore.api.event.CustomPlayerFishEvent; import net.Indyuce.mmocore.experience.EXPSource; -import net.Indyuce.mmocore.api.loot.LootBuilder; +import net.Indyuce.mmocore.loot.LootBuilder; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.stats.StatType; import net.Indyuce.mmocore.api.util.MMOCoreUtils; diff --git a/src/main/java/net/Indyuce/mmocore/api/loot/LootBuilder.java b/src/main/java/net/Indyuce/mmocore/loot/LootBuilder.java similarity index 92% rename from src/main/java/net/Indyuce/mmocore/api/loot/LootBuilder.java rename to src/main/java/net/Indyuce/mmocore/loot/LootBuilder.java index 5521e341..b5a5ae7e 100644 --- a/src/main/java/net/Indyuce/mmocore/api/loot/LootBuilder.java +++ b/src/main/java/net/Indyuce/mmocore/loot/LootBuilder.java @@ -1,55 +1,55 @@ -package net.Indyuce.mmocore.api.loot; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.inventory.ItemStack; - -import net.Indyuce.mmocore.api.player.PlayerData; - -public class LootBuilder { - private final PlayerData player; - private final List loot = new ArrayList<>(); - - private double capacity; - - /** - * Used to create loot from a drop table - * - * @param player - * Player looting - * @param capacity - * Capacity is the maximum amount of item weight generated using - * this table. If capacity is set to 10, this table cannot drop - * an item with 5 weight and another with 6 weight at the saeme - * time. - */ - public LootBuilder(PlayerData player, double capacity) { - this.player = player; - this.capacity = capacity; - } - - public PlayerData getEntity() { - return player; - } - - public List getLoot() { - return loot; - } - - public double getCapacity() { - return capacity; - } - - public void addLoot(ItemStack item) { - loot.add(item); - } - - public void addLoot(List items) { - loot.addAll(items); - } - - public void reduceCapacity(double value) { - this.capacity = Math.max(0, capacity - value); - } -} +package net.Indyuce.mmocore.loot; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.inventory.ItemStack; + +import net.Indyuce.mmocore.api.player.PlayerData; + +public class LootBuilder { + private final PlayerData player; + private final List loot = new ArrayList<>(); + + private double capacity; + + /** + * Used to create loot from a drop table + * + * @param player + * Player looting + * @param capacity + * Capacity is the maximum amount of item weight generated using + * this table. If capacity is set to 10, this table cannot drop + * an item with 5 weight and another with 6 weight at the saeme + * time. + */ + public LootBuilder(PlayerData player, double capacity) { + this.player = player; + this.capacity = capacity; + } + + public PlayerData getEntity() { + return player; + } + + public List getLoot() { + return loot; + } + + public double getCapacity() { + return capacity; + } + + public void addLoot(ItemStack item) { + loot.add(item); + } + + public void addLoot(List items) { + loot.addAll(items); + } + + public void reduceCapacity(double value) { + this.capacity = Math.max(0, capacity - value); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/api/loot/ChestAlgorithmOptions.java b/src/main/java/net/Indyuce/mmocore/loot/chest/ChestAlgorithmOptions.java similarity index 95% rename from src/main/java/net/Indyuce/mmocore/api/loot/ChestAlgorithmOptions.java rename to src/main/java/net/Indyuce/mmocore/loot/chest/ChestAlgorithmOptions.java index ab98956e..c7c23b6e 100644 --- a/src/main/java/net/Indyuce/mmocore/api/loot/ChestAlgorithmOptions.java +++ b/src/main/java/net/Indyuce/mmocore/loot/chest/ChestAlgorithmOptions.java @@ -1,50 +1,50 @@ -package net.Indyuce.mmocore.api.loot; - -import org.apache.commons.lang.Validate; -import org.bukkit.configuration.ConfigurationSection; - -public class ChestAlgorithmOptions { - - /* - * min and max range represents the range at which the chest can spawn - * around the player. height is the Z delta in which the chest can spawn, - * relative to the player's altitude - */ - public final double minRange, maxRange, height; - - /* - * maximum amount of trials the algorithm will run in order to find a - * suitable location for a chest around the player. - */ - public final int iterations; - - public static final ChestAlgorithmOptions DEFAULT = new ChestAlgorithmOptions(10, 30, 8, 15); - - /* - * this is purely to let server owners tweak the chest random location - * finder algorithm. - */ - public ChestAlgorithmOptions(ConfigurationSection config) { - Validate.notNull(config, "Config cannot be null"); - - minRange = config.getDouble("min-range", DEFAULT.minRange); - maxRange = config.getDouble("max-range", DEFAULT.maxRange); - height = config.getDouble("height", DEFAULT.height); - iterations = config.getInt("iterations", DEFAULT.iterations); - - Validate.isTrue(minRange < maxRange, "Max range must be greater than min range"); - Validate.isTrue(height > 0, "Height must be strictly positive"); - Validate.isTrue(iterations > 0, "Iterations must be strictly positive"); - } - - /* - * can be used to register loot chest regions with external plugins, and - * used by the default alg options instance - */ - public ChestAlgorithmOptions(double minRange, double maxRange, double height, int iterations) { - this.minRange = minRange; - this.maxRange = maxRange; - this.height = height; - this.iterations = iterations; - } -} +package net.Indyuce.mmocore.loot.chest; + +import org.apache.commons.lang.Validate; +import org.bukkit.configuration.ConfigurationSection; + +public class ChestAlgorithmOptions { + + /* + * min and max range represents the range at which the chest can spawn + * around the player. height is the Z delta in which the chest can spawn, + * relative to the player's altitude + */ + public final double minRange, maxRange, height; + + /* + * maximum amount of trials the algorithm will run in order to find a + * suitable location for a chest around the player. + */ + public final int iterations; + + public static final ChestAlgorithmOptions DEFAULT = new ChestAlgorithmOptions(10, 30, 8, 15); + + /* + * this is purely to let server owners tweak the chest random location + * finder algorithm. + */ + public ChestAlgorithmOptions(ConfigurationSection config) { + Validate.notNull(config, "Config cannot be null"); + + minRange = config.getDouble("min-range", DEFAULT.minRange); + maxRange = config.getDouble("max-range", DEFAULT.maxRange); + height = config.getDouble("height", DEFAULT.height); + iterations = config.getInt("iterations", DEFAULT.iterations); + + Validate.isTrue(minRange < maxRange, "Max range must be greater than min range"); + Validate.isTrue(height > 0, "Height must be strictly positive"); + Validate.isTrue(iterations > 0, "Iterations must be strictly positive"); + } + + /* + * can be used to register loot chest regions with external plugins, and + * used by the default alg options instance + */ + public ChestAlgorithmOptions(double minRange, double maxRange, double height, int iterations) { + this.minRange = minRange; + this.maxRange = maxRange; + this.height = height; + this.iterations = iterations; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/api/loot/ChestTier.java b/src/main/java/net/Indyuce/mmocore/loot/chest/ChestTier.java similarity index 88% rename from src/main/java/net/Indyuce/mmocore/api/loot/ChestTier.java rename to src/main/java/net/Indyuce/mmocore/loot/chest/ChestTier.java index 2d5e2738..770c7986 100644 --- a/src/main/java/net/Indyuce/mmocore/api/loot/ChestTier.java +++ b/src/main/java/net/Indyuce/mmocore/loot/chest/ChestTier.java @@ -1,38 +1,38 @@ -package net.Indyuce.mmocore.api.loot; - -import io.lumine.mythic.lib.api.math.ScalingFormula; -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.droptable.DropTable; -import net.Indyuce.mmocore.api.player.PlayerData; -import org.bukkit.configuration.ConfigurationSection; - -public class ChestTier { - private final TierEffect effect; - private final ScalingFormula capacity; - private final DropTable table; - - public final double chance; - - public ChestTier(ConfigurationSection config) { - effect = config.isConfigurationSection("effect") ? new TierEffect(config.getConfigurationSection("effect")) : null; - capacity = new ScalingFormula(config.get("capacity")); - chance = config.getDouble("chance"); - table = MMOCore.plugin.dropTableManager.loadDropTable(config.get("drops")); - } - - public double rollCapacity(PlayerData player) { - return capacity.calculate(player.getLevel()); - } - - public DropTable getDropTable() { - return table; - } - - public boolean hasEffect() { - return effect != null; - } - - public TierEffect getEffect() { - return effect; - } -} +package net.Indyuce.mmocore.loot.chest; + +import io.lumine.mythic.lib.api.math.ScalingFormula; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.loot.droptable.DropTable; +import net.Indyuce.mmocore.api.player.PlayerData; +import org.bukkit.configuration.ConfigurationSection; + +public class ChestTier { + private final TierEffect effect; + private final ScalingFormula capacity; + private final DropTable table; + + public final double chance; + + public ChestTier(ConfigurationSection config) { + effect = config.isConfigurationSection("effect") ? new TierEffect(config.getConfigurationSection("effect")) : null; + capacity = new ScalingFormula(config.get("capacity")); + chance = config.getDouble("chance"); + table = MMOCore.plugin.dropTableManager.loadDropTable(config.get("drops")); + } + + public double rollCapacity(PlayerData player) { + return capacity.calculate(player.getLevel()); + } + + public DropTable getDropTable() { + return table; + } + + public boolean hasEffect() { + return effect != null; + } + + public TierEffect getEffect() { + return effect; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/api/loot/LootChest.java b/src/main/java/net/Indyuce/mmocore/loot/chest/LootChest.java similarity index 96% rename from src/main/java/net/Indyuce/mmocore/api/loot/LootChest.java rename to src/main/java/net/Indyuce/mmocore/loot/chest/LootChest.java index ce489cdc..b8f2b0bf 100644 --- a/src/main/java/net/Indyuce/mmocore/api/loot/LootChest.java +++ b/src/main/java/net/Indyuce/mmocore/loot/chest/LootChest.java @@ -1,108 +1,108 @@ -package net.Indyuce.mmocore.api.loot; - -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.manager.SoundManager; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Particle; -import org.bukkit.block.Block; -import org.bukkit.block.Chest; -import org.bukkit.block.data.BlockData; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -public class LootChest { - private final ChestTier tier; - private final LootChestRegion region; - private final ReplacedBlock block; - private final BukkitRunnable effectRunnable; - private final long date = System.currentTimeMillis(); - - /** - * Called when a loot chest is placed as a Bukkit block, and used - * to save the data of the block which has been replaced. - *

- * A placed drop chest may only replace non solid blocks like grass - * or levels.. - */ - public LootChest(ChestTier tier, LootChestRegion region, Block block) { - this.tier = tier; - this.region = region; - this.block = new ReplacedBlock(block); - this.effectRunnable = tier.hasEffect() ? tier.getEffect().startNewRunnable(block.getLocation().add(.5, .5, .5)) : null; - } - - public ChestTier getTier() { - return tier; - } - - public ReplacedBlock getBlock() { - return block; - } - - public LootChestRegion getRegion() { - return region; - } - - public boolean hasPlayerNearby() { - for (Player player : block.loc.getWorld().getPlayers()) - if (player.getLocation().distanceSquared(block.loc) < 625) - return true; - return false; - } - - public boolean shouldExpire() { - return System.currentTimeMillis() - date > MMOCore.plugin.configManager.lootChestExpireTime; - } - - /** - * @param player If a player just the chest. It's set to false - * when a loot chest expires or when MMOCore disables. - */ - public void unregister(boolean player) { - - // If a player is responsible of closing the chest, close it with sound - if (player) { - MMOCore.plugin.soundManager.play(block.loc.getBlock(), SoundManager.SoundEvent.CLOSE_LOOT_CHEST); - block.loc.getWorld().spawnParticle(Particle.CRIT, block.loc.clone().add(.5, .5, .5), 16, 0, 0, 0, .5); - MMOCore.plugin.lootChests.unregister(this); - } - - /* - * Must clean block inventory before replacing block otherwise loots fly - * off and accumulate on the ground (+during dev phase) - */ - else - ((Chest) block.loc.getBlock().getState()).getBlockInventory().clear(); - - block.restore(); - if (effectRunnable != null) - effectRunnable.cancel(); - } - - public static class ReplacedBlock { - private final Material material; - private final BlockData data; - private final Location loc; - - public ReplacedBlock(Block block) { - this.material = block.getType(); - this.data = block.getBlockData(); - this.loc = block.getLocation(); - } - - public Location getLocoation() { - return loc; - } - - public boolean matches(Location loc) { - return this.loc.getWorld().equals(loc.getWorld()) && this.loc.getBlockX() == loc.getBlockX() && this.loc.getBlockY() == loc.getBlockY() - && this.loc.getBlockZ() == loc.getBlockZ(); - } - - public void restore() { - loc.getBlock().setType(material); - loc.getBlock().setBlockData(data); - } - } -} +package net.Indyuce.mmocore.loot.chest; + +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.manager.SoundManager; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.block.Block; +import org.bukkit.block.Chest; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +public class LootChest { + private final ChestTier tier; + private final LootChestRegion region; + private final ReplacedBlock block; + private final BukkitRunnable effectRunnable; + private final long date = System.currentTimeMillis(); + + /** + * Called when a loot chest is placed as a Bukkit block, and used + * to save the data of the block which has been replaced. + *

+ * A placed drop chest may only replace non solid blocks like grass + * or levels.. + */ + public LootChest(ChestTier tier, LootChestRegion region, Block block) { + this.tier = tier; + this.region = region; + this.block = new ReplacedBlock(block); + this.effectRunnable = tier.hasEffect() ? tier.getEffect().startNewRunnable(block.getLocation().add(.5, .5, .5)) : null; + } + + public ChestTier getTier() { + return tier; + } + + public ReplacedBlock getBlock() { + return block; + } + + public LootChestRegion getRegion() { + return region; + } + + public boolean hasPlayerNearby() { + for (Player player : block.loc.getWorld().getPlayers()) + if (player.getLocation().distanceSquared(block.loc) < 625) + return true; + return false; + } + + public boolean shouldExpire() { + return System.currentTimeMillis() - date > MMOCore.plugin.configManager.lootChestExpireTime; + } + + /** + * @param player If a player just the chest. It's set to false + * when a loot chest expires or when MMOCore disables. + */ + public void unregister(boolean player) { + + // If a player is responsible of closing the chest, close it with sound + if (player) { + MMOCore.plugin.soundManager.play(block.loc.getBlock(), SoundManager.SoundEvent.CLOSE_LOOT_CHEST); + block.loc.getWorld().spawnParticle(Particle.CRIT, block.loc.clone().add(.5, .5, .5), 16, 0, 0, 0, .5); + MMOCore.plugin.lootChests.unregister(this); + } + + /* + * Must clean block inventory before replacing block otherwise loots fly + * off and accumulate on the ground (+during dev phase) + */ + else + ((Chest) block.loc.getBlock().getState()).getBlockInventory().clear(); + + block.restore(); + if (effectRunnable != null) + effectRunnable.cancel(); + } + + public static class ReplacedBlock { + private final Material material; + private final BlockData data; + private final Location loc; + + public ReplacedBlock(Block block) { + this.material = block.getType(); + this.data = block.getBlockData(); + this.loc = block.getLocation(); + } + + public Location getLocoation() { + return loc; + } + + public boolean matches(Location loc) { + return this.loc.getWorld().equals(loc.getWorld()) && this.loc.getBlockX() == loc.getBlockX() && this.loc.getBlockY() == loc.getBlockY() + && this.loc.getBlockZ() == loc.getBlockZ(); + } + + public void restore() { + loc.getBlock().setType(material); + loc.getBlock().setBlockData(data); + } + } +} diff --git a/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java b/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java new file mode 100644 index 00000000..fa53b31c --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java @@ -0,0 +1,174 @@ +package net.Indyuce.mmocore.loot.chest; + +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.event.LootChestSpawnEvent; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.loot.LootBuilder; +import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Chest; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.util.Vector; + +import java.util.*; +import java.util.logging.Level; + +public class LootChestRegion { + private final String id; + + private final long chestSpawnPeriod; + private final RegionBounds bounds; + private final ChestAlgorithmOptions algOptions; + private final Set tiers = new LinkedHashSet<>(); + private final BukkitRunnable runnable = new BukkitRunnable() { + + @Override + public void run() { + getBounds().getPlayers().filter(PlayerData::canSpawnLootChest).findAny().ifPresent(player -> spawnChest(player)); + } + }; + + private static final Random random = new Random(); + + public LootChestRegion(ConfigurationSection config) { + Validate.notNull(config, "Could not load config"); + id = config.getName().toLowerCase().replace("_", "-").replace(" ", "-"); + + bounds = new RegionBounds(config.getConfigurationSection("bounds")); + chestSpawnPeriod = config.getLong("spawn-period", 5 * 60); + algOptions = config.contains("algorithm-options") ? new ChestAlgorithmOptions(config.getConfigurationSection("algorithm-options")) + : ChestAlgorithmOptions.DEFAULT; + + Validate.isTrue(config.isConfigurationSection("tiers"), "Could not find chest tiers"); + for (String key : config.getConfigurationSection("tiers").getKeys(false)) + try { + tiers.add(new ChestTier(config.getConfigurationSection("tiers." + key))); + } catch (IllegalArgumentException exception) { + MMOCore.plugin.getLogger().log(Level.WARNING, + "Could not load tier '" + key + "' from chest region '" + id + "': " + exception.getMessage()); + } + + Validate.isTrue(!tiers.isEmpty(), "Your region must have at least one chest tier"); + + // Run timer + runnable.runTaskTimer(MMOCore.plugin, chestSpawnPeriod * 20, chestSpawnPeriod * 20); + } + + public String getId() { + return id; + } + + public Set getTiers() { + return tiers; + } + + public RegionBounds getBounds() { + return bounds; + } + + public long getChestSpawnPeriod() { + return chestSpawnPeriod; + } + + public BukkitRunnable getRunnable() { + return runnable; + } + + public void spawnChest(PlayerData player) { + + // Apply chest cooldown + player.applyLootChestCooldown(); + + // First randomly determine the chest tier + ChestTier tier = rollTier(); + + // Find a random location, 20 trials max + Location location = getRandomLocation(player.getPlayer().getLocation()); + if (location == null) + return; + + LootChest lootChest = new LootChest(tier, this, location.getBlock()); + LootBuilder builder = new LootBuilder(player, tier.rollCapacity(player)); + tier.getDropTable().collect(builder); + + LootChestSpawnEvent event = new LootChestSpawnEvent(player, lootChest, builder); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) + return; + + List slots = new ArrayList<>(); + for (int j = 0; j < 27; j++) + slots.add(j); + + location.getBlock().setType(Material.CHEST); + Chest chest = (Chest) location.getBlock().getState(); + tier.getDropTable().collect(builder).forEach(item -> { + Integer slot = slots.get(random.nextInt(slots.size())); + chest.getInventory().setItem(slot, item); + slots.remove(slot); + }); + + MMOCore.plugin.lootChests.register(lootChest); + } + + // TODO stat to increase chance to get higher tiers? + public ChestTier rollTier() { + + double s = 0; + for (ChestTier tier : tiers) { + if (random.nextDouble() < tier.chance / (1 - s)) + return tier; + s += tier.chance; + } + + return tiers.stream().findAny().orElse(null); + } + + public Location getRandomLocation(Location center) { + + for (int j = 0; j < algOptions.iterations; j++) { + Location random = tryRandomDirection(center); + if (random != null) + return random; + } + + /* + * no location has been found after the X iterations, return null and + * cancel chest spawning. worst case scenario, should not happen too + * often except if the player is in a really NARROW zone + */ + return null; + } + + public Location tryRandomDirection(Location center) { + + /* + * chooses a random direction and get the block in that direction which + * has the same height as the player + */ + double a = random.nextDouble() * 2 * Math.PI; + Vector dir = new Vector(Math.cos(a), 0, Math.sin(a)) + .multiply(algOptions.minRange + random.nextDouble() * (algOptions.maxRange - algOptions.minRange)); + Location random = center.add(dir); + + /* + * go up and down at the same time till it finds a non-solid block with + * a solid block underneath + */ + for (int h = 0; h <= algOptions.height * 2; h++) { + int z = h % 2 == 0 ? h / 2 : -(h + 1) / 2; // bijective from N to Z + Location checked = random.clone().add(0, z, 0); + if (isSuitable(checked)) + return checked; + } + + return null; + } + + private boolean isSuitable(Location loc) { + return !loc.getBlock().getType().isSolid() && loc.clone().add(0, -1, 0).getBlock().getType().isSolid(); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/api/loot/RegionBounds.java b/src/main/java/net/Indyuce/mmocore/loot/chest/RegionBounds.java similarity index 94% rename from src/main/java/net/Indyuce/mmocore/api/loot/RegionBounds.java rename to src/main/java/net/Indyuce/mmocore/loot/chest/RegionBounds.java index 3a5cf3f1..1e25507b 100644 --- a/src/main/java/net/Indyuce/mmocore/api/loot/RegionBounds.java +++ b/src/main/java/net/Indyuce/mmocore/loot/chest/RegionBounds.java @@ -1,51 +1,51 @@ -package net.Indyuce.mmocore.api.loot; - -import java.util.stream.Stream; - -import org.apache.commons.lang.Validate; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.entity.Player; - -import net.Indyuce.mmocore.api.player.PlayerData; - -public class RegionBounds { - private final World world; - private final int x1, z1, x2, z2; - - public RegionBounds(ConfigurationSection config) { - Validate.notNull(config, "Could not load config"); - - String name = config.getString("world"); - Validate.notNull(name, "Could not find world name"); - Validate.notNull(world = Bukkit.getWorld(name), "Could not find world " + config.getString("world")); - - x1 = Math.min(config.getInt("x1"), config.getInt("x2")); - x2 = Math.max(config.getInt("x1"), config.getInt("x2")); - - z1 = Math.min(config.getInt("z1"), config.getInt("z2")); - z2 = Math.max(config.getInt("z1"), config.getInt("z2")); - } - - public RegionBounds(Location loc1, Location loc2) { - Validate.isTrue(loc1.getWorld().equals(loc2.getWorld()), "Locations must be in the same world"); - world = loc1.getWorld(); - x1 = Math.min(loc1.getBlockX(), loc2.getBlockX()); - x2 = Math.max(loc1.getBlockX(), loc2.getBlockX()); - - z1 = Math.min(loc1.getBlockZ(), loc2.getBlockZ()); - z2 = Math.max(loc1.getBlockZ(), loc2.getBlockZ()); - } - - public Stream getPlayers() { - return world.getPlayers().stream().filter(this::isInRegion).map(PlayerData::get); - } - - public boolean isInRegion(Player player) { - int x = player.getLocation().getBlockX(); - int z = player.getLocation().getBlockZ(); - return player.getWorld().equals(world) && x1 <= x && x2 >= x && z1 <= z && z2 >= z; - } -} +package net.Indyuce.mmocore.loot.chest; + +import java.util.stream.Stream; + +import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; + +import net.Indyuce.mmocore.api.player.PlayerData; + +public class RegionBounds { + private final World world; + private final int x1, z1, x2, z2; + + public RegionBounds(ConfigurationSection config) { + Validate.notNull(config, "Could not load config"); + + String name = config.getString("world"); + Validate.notNull(name, "Could not find world name"); + Validate.notNull(world = Bukkit.getWorld(name), "Could not find world " + config.getString("world")); + + x1 = Math.min(config.getInt("x1"), config.getInt("x2")); + x2 = Math.max(config.getInt("x1"), config.getInt("x2")); + + z1 = Math.min(config.getInt("z1"), config.getInt("z2")); + z2 = Math.max(config.getInt("z1"), config.getInt("z2")); + } + + public RegionBounds(Location loc1, Location loc2) { + Validate.isTrue(loc1.getWorld().equals(loc2.getWorld()), "Locations must be in the same world"); + world = loc1.getWorld(); + x1 = Math.min(loc1.getBlockX(), loc2.getBlockX()); + x2 = Math.max(loc1.getBlockX(), loc2.getBlockX()); + + z1 = Math.min(loc1.getBlockZ(), loc2.getBlockZ()); + z2 = Math.max(loc1.getBlockZ(), loc2.getBlockZ()); + } + + public Stream getPlayers() { + return world.getPlayers().stream().filter(this::isInRegion).map(PlayerData::get); + } + + public boolean isInRegion(Player player) { + int x = player.getLocation().getBlockX(); + int z = player.getLocation().getBlockZ(); + return player.getWorld().equals(world) && x1 <= x && x2 >= x && z1 <= z && z2 >= z; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/api/loot/TierEffect.java b/src/main/java/net/Indyuce/mmocore/loot/chest/TierEffect.java similarity index 93% rename from src/main/java/net/Indyuce/mmocore/api/loot/TierEffect.java rename to src/main/java/net/Indyuce/mmocore/loot/chest/TierEffect.java index 03cbdd68..fb26bd86 100644 --- a/src/main/java/net/Indyuce/mmocore/api/loot/TierEffect.java +++ b/src/main/java/net/Indyuce/mmocore/loot/chest/TierEffect.java @@ -1,37 +1,37 @@ -package net.Indyuce.mmocore.api.loot; - -import org.apache.commons.lang.Validate; -import org.bukkit.Location; -import org.bukkit.Particle; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.scheduler.BukkitRunnable; - -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.util.math.particle.ChestParticleEffect; - -public class TierEffect { - private final ChestParticleEffect type; - private final Particle particle; - private final int period; - - public TierEffect(ConfigurationSection config) { - Validate.notNull(config, "Could not load tier config"); - type = ChestParticleEffect.valueOf(config.getString("type", "OFFSET").toUpperCase().replace("-", "_").replace(" ", "_")); - particle = Particle.valueOf(config.getString("particle", "FLAME").toUpperCase().replace("-", "_").replace(" ", "_")); - period = Math.max(20, config.getInt("period", 5 * 20)); - } - - public void play(Location loc) { - type.play(loc, particle); - } - - public BukkitRunnable startNewRunnable(Location loc) { - BukkitRunnable runnable = new BukkitRunnable() { - public void run() { - type.play(loc, particle); - } - }; - runnable.runTaskTimer(MMOCore.plugin, 0, period); - return runnable; - } +package net.Indyuce.mmocore.loot.chest; + +import org.apache.commons.lang.Validate; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.scheduler.BukkitRunnable; + +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.util.math.particle.ChestParticleEffect; + +public class TierEffect { + private final ChestParticleEffect type; + private final Particle particle; + private final int period; + + public TierEffect(ConfigurationSection config) { + Validate.notNull(config, "Could not load tier config"); + type = ChestParticleEffect.valueOf(config.getString("type", "OFFSET").toUpperCase().replace("-", "_").replace(" ", "_")); + particle = Particle.valueOf(config.getString("particle", "FLAME").toUpperCase().replace("-", "_").replace(" ", "_")); + period = Math.max(20, config.getInt("period", 5 * 20)); + } + + public void play(Location loc) { + type.play(loc, particle); + } + + public BukkitRunnable startNewRunnable(Location loc) { + BukkitRunnable runnable = new BukkitRunnable() { + public void run() { + type.play(loc, particle); + } + }; + runnable.runTaskTimer(MMOCore.plugin, 0, period); + return runnable; + } } \ No newline at end of file diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/DropTable.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/DropTable.java similarity index 89% rename from src/main/java/net/Indyuce/mmocore/api/droptable/DropTable.java rename to src/main/java/net/Indyuce/mmocore/loot/droptable/DropTable.java index 3d69053f..1cce3177 100644 --- a/src/main/java/net/Indyuce/mmocore/api/droptable/DropTable.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/DropTable.java @@ -1,19 +1,19 @@ -package net.Indyuce.mmocore.api.droptable; +package net.Indyuce.mmocore.loot.droptable; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.logging.Level; +import net.Indyuce.mmocore.loot.droptable.condition.Condition; +import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; +import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem; import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.droptable.condition.Condition; -import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance; -import net.Indyuce.mmocore.api.droptable.dropitem.DropItem; -import net.Indyuce.mmocore.api.loot.LootBuilder; +import net.Indyuce.mmocore.loot.LootBuilder; import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.util.PostLoadObject; diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/condition/BiomeCondition.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/BiomeCondition.java similarity index 91% rename from src/main/java/net/Indyuce/mmocore/api/droptable/condition/BiomeCondition.java rename to src/main/java/net/Indyuce/mmocore/loot/droptable/condition/BiomeCondition.java index aaa47376..7da08703 100644 --- a/src/main/java/net/Indyuce/mmocore/api/droptable/condition/BiomeCondition.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/BiomeCondition.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.api.droptable.condition; +package net.Indyuce.mmocore.loot.droptable.condition; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/condition/Condition.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/Condition.java similarity index 84% rename from src/main/java/net/Indyuce/mmocore/api/droptable/condition/Condition.java rename to src/main/java/net/Indyuce/mmocore/loot/droptable/condition/Condition.java index 1650113a..d1445364 100644 --- a/src/main/java/net/Indyuce/mmocore/api/droptable/condition/Condition.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/Condition.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.api.droptable.condition; +package net.Indyuce.mmocore.loot.droptable.condition; import io.lumine.mythic.lib.api.MMOLineConfig; diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/condition/ConditionInstance.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/ConditionInstance.java similarity index 93% rename from src/main/java/net/Indyuce/mmocore/api/droptable/condition/ConditionInstance.java rename to src/main/java/net/Indyuce/mmocore/loot/droptable/condition/ConditionInstance.java index 92ed9373..937b9475 100644 --- a/src/main/java/net/Indyuce/mmocore/api/droptable/condition/ConditionInstance.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/ConditionInstance.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.api.droptable.condition; +package net.Indyuce.mmocore.loot.droptable.condition; import java.util.List; import java.util.stream.Stream; diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/condition/LevelCondition.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/LevelCondition.java similarity index 93% rename from src/main/java/net/Indyuce/mmocore/api/droptable/condition/LevelCondition.java rename to src/main/java/net/Indyuce/mmocore/loot/droptable/condition/LevelCondition.java index ed694ddd..e3fe2a0d 100644 --- a/src/main/java/net/Indyuce/mmocore/api/droptable/condition/LevelCondition.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/LevelCondition.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.api.droptable.condition; +package net.Indyuce.mmocore.loot.droptable.condition; import net.Indyuce.mmocore.api.player.PlayerData; import io.lumine.mythic.lib.api.MMOLineConfig; diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/condition/PermissionCondition.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/PermissionCondition.java similarity index 90% rename from src/main/java/net/Indyuce/mmocore/api/droptable/condition/PermissionCondition.java rename to src/main/java/net/Indyuce/mmocore/loot/droptable/condition/PermissionCondition.java index 12541234..0d009b44 100644 --- a/src/main/java/net/Indyuce/mmocore/api/droptable/condition/PermissionCondition.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/PermissionCondition.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.api.droptable.condition; +package net.Indyuce.mmocore.loot.droptable.condition; import io.lumine.mythic.lib.api.MMOLineConfig; import org.bukkit.entity.Player; diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/condition/WorldCondition.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/WorldCondition.java similarity index 90% rename from src/main/java/net/Indyuce/mmocore/api/droptable/condition/WorldCondition.java rename to src/main/java/net/Indyuce/mmocore/loot/droptable/condition/WorldCondition.java index 4ff87b19..35e6341d 100644 --- a/src/main/java/net/Indyuce/mmocore/api/droptable/condition/WorldCondition.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/WorldCondition.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.api.droptable.condition; +package net.Indyuce.mmocore.loot.droptable.condition; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/DropItem.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropItem.java similarity index 90% rename from src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/DropItem.java rename to src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropItem.java index 23806894..0872aa7b 100644 --- a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/DropItem.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropItem.java @@ -1,8 +1,8 @@ -package net.Indyuce.mmocore.api.droptable.dropitem; +package net.Indyuce.mmocore.loot.droptable.dropitem; import java.util.Random; -import net.Indyuce.mmocore.api.loot.LootBuilder; +import net.Indyuce.mmocore.loot.LootBuilder; import net.Indyuce.mmocore.api.util.math.formula.RandomAmount; import io.lumine.mythic.lib.api.MMOLineConfig; diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/DropTableDropItem.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropTableDropItem.java similarity index 80% rename from src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/DropTableDropItem.java rename to src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropTableDropItem.java index b0721ff6..02123b38 100644 --- a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/DropTableDropItem.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropTableDropItem.java @@ -1,10 +1,10 @@ -package net.Indyuce.mmocore.api.droptable.dropitem; +package net.Indyuce.mmocore.loot.droptable.dropitem; import io.lumine.mythic.lib.api.MMOLineConfig; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.droptable.DropTable; -import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance; -import net.Indyuce.mmocore.api.loot.LootBuilder; +import net.Indyuce.mmocore.loot.droptable.DropTable; +import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; +import net.Indyuce.mmocore.loot.LootBuilder; import net.Indyuce.mmocore.api.player.PlayerData; import org.apache.commons.lang.Validate; diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/GoldDropItem.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/GoldDropItem.java similarity index 77% rename from src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/GoldDropItem.java rename to src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/GoldDropItem.java index 975435bf..6f79c112 100644 --- a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/GoldDropItem.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/GoldDropItem.java @@ -1,6 +1,6 @@ -package net.Indyuce.mmocore.api.droptable.dropitem; +package net.Indyuce.mmocore.loot.droptable.dropitem; -import net.Indyuce.mmocore.api.loot.LootBuilder; +import net.Indyuce.mmocore.loot.LootBuilder; import net.Indyuce.mmocore.api.util.item.CurrencyItem; import io.lumine.mythic.lib.api.MMOLineConfig; diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/MMDropTableDropItem.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/MMDropTableDropItem.java similarity index 92% rename from src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/MMDropTableDropItem.java rename to src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/MMDropTableDropItem.java index ed5d0f82..2d8d1473 100644 --- a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/MMDropTableDropItem.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/MMDropTableDropItem.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.api.droptable.dropitem; +package net.Indyuce.mmocore.loot.droptable.dropitem; import java.util.NoSuchElementException; @@ -9,7 +9,7 @@ import io.lumine.xikage.mythicmobs.drops.DropMetadata; import io.lumine.xikage.mythicmobs.drops.DropTable; import io.lumine.xikage.mythicmobs.drops.IItemDrop; import io.lumine.xikage.mythicmobs.drops.LootBag; -import net.Indyuce.mmocore.api.loot.LootBuilder; +import net.Indyuce.mmocore.loot.LootBuilder; import io.lumine.mythic.lib.api.MMOLineConfig; public class MMDropTableDropItem extends DropItem { diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/NoteDropItem.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/NoteDropItem.java similarity index 83% rename from src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/NoteDropItem.java rename to src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/NoteDropItem.java index 93107b63..41f45c21 100644 --- a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/NoteDropItem.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/NoteDropItem.java @@ -1,6 +1,6 @@ -package net.Indyuce.mmocore.api.droptable.dropitem; +package net.Indyuce.mmocore.loot.droptable.dropitem; -import net.Indyuce.mmocore.api.loot.LootBuilder; +import net.Indyuce.mmocore.loot.LootBuilder; import net.Indyuce.mmocore.api.util.item.CurrencyItem; import io.lumine.mythic.lib.api.MMOLineConfig; diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/VanillaDropItem.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/VanillaDropItem.java similarity index 84% rename from src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/VanillaDropItem.java rename to src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/VanillaDropItem.java index 3cca4e05..628bb6ed 100644 --- a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/VanillaDropItem.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/VanillaDropItem.java @@ -1,9 +1,9 @@ -package net.Indyuce.mmocore.api.droptable.dropitem; +package net.Indyuce.mmocore.loot.droptable.dropitem; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import net.Indyuce.mmocore.api.loot.LootBuilder; +import net.Indyuce.mmocore.loot.LootBuilder; import io.lumine.mythic.lib.api.MMOLineConfig; public class VanillaDropItem extends DropItem { diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/fishing/FishingDropItem.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/fishing/FishingDropItem.java similarity index 88% rename from src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/fishing/FishingDropItem.java rename to src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/fishing/FishingDropItem.java index 3722f00a..e18c9674 100644 --- a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/fishing/FishingDropItem.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/fishing/FishingDropItem.java @@ -1,11 +1,11 @@ -package net.Indyuce.mmocore.api.droptable.dropitem.fishing; +package net.Indyuce.mmocore.loot.droptable.dropitem.fishing; import org.apache.commons.lang.Validate; import org.bukkit.inventory.ItemStack; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.droptable.dropitem.DropItem; -import net.Indyuce.mmocore.api.loot.LootBuilder; +import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem; +import net.Indyuce.mmocore.loot.LootBuilder; import net.Indyuce.mmocore.api.util.math.formula.RandomAmount; import io.lumine.mythic.lib.api.MMOLineConfig; diff --git a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java index d9be5103..b069c7f1 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java @@ -22,164 +22,163 @@ import java.util.List; import java.util.logging.Level; public class ConfigManager { - public final CommandVerbose commandVerbose = new CommandVerbose(); + public final CommandVerbose commandVerbose = new CommandVerbose(); - public boolean overrideVanillaExp, canCreativeCast, cobbleGeneratorXP, saveDefaultClassInfo; - public double expPartyBuff, regenPartyBuff; - public String partyChatPrefix, noSkillBoundPlaceholder; - public ChatColor staminaFull, staminaHalf, staminaEmpty; - public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown; - public SwapAction normalSwapAction, sneakingSwapAction; + public boolean overrideVanillaExp, canCreativeCast, cobbleGeneratorXP, saveDefaultClassInfo; + public String partyChatPrefix, noSkillBoundPlaceholder; + public ChatColor staminaFull, staminaHalf, staminaEmpty; + public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown; + public SwapAction normalSwapAction, sneakingSwapAction; - private final FileConfiguration messages; - private final boolean chatInput; + private final FileConfiguration messages; + private final boolean chatInput; - /* - * the instance must be created after the other managers since all it does - * is to update them based on the config except for the classes which are - * already loaded based on the config - */ - public ConfigManager() { - // loadDefaultFile("recipes", "brewing.yml"); - // loadDefaultFile("recipes", "furnace.yml"); + /* + * the instance must be created after the other managers since all it does + * is to update them based on the config except for the classes which are + * already loaded based on the config + */ + public ConfigManager() { + // loadDefaultFile("recipes", "brewing.yml"); + // loadDefaultFile("recipes", "furnace.yml"); - if (!new File(MMOCore.plugin.getDataFolder() + "/drop-tables").exists()) - loadDefaultFile("drop-tables", "example-drop-tables.yml"); + if (!new File(MMOCore.plugin.getDataFolder() + "/drop-tables").exists()) + loadDefaultFile("drop-tables", "example-drop-tables.yml"); - if (!new File(MMOCore.plugin.getDataFolder() + "/professions").exists()) { - loadDefaultFile("professions", "alchemy.yml"); - loadDefaultFile("professions", "farming.yml"); - loadDefaultFile("professions", "fishing.yml"); - loadDefaultFile("professions", "mining.yml"); - loadDefaultFile("professions", "smelting.yml"); - loadDefaultFile("professions", "smithing.yml"); - loadDefaultFile("professions", "woodcutting.yml"); - loadDefaultFile("professions", "enchanting.yml"); - } + if (!new File(MMOCore.plugin.getDataFolder() + "/professions").exists()) { + loadDefaultFile("professions", "alchemy.yml"); + loadDefaultFile("professions", "farming.yml"); + loadDefaultFile("professions", "fishing.yml"); + loadDefaultFile("professions", "mining.yml"); + loadDefaultFile("professions", "smelting.yml"); + loadDefaultFile("professions", "smithing.yml"); + loadDefaultFile("professions", "woodcutting.yml"); + loadDefaultFile("professions", "enchanting.yml"); + } - if (!new File(MMOCore.plugin.getDataFolder() + "/quests").exists()) { - loadDefaultFile("quests", "adv-begins.yml"); - loadDefaultFile("quests", "tutorial.yml"); - loadDefaultFile("quests", "fetch-mango.yml"); - } + if (!new File(MMOCore.plugin.getDataFolder() + "/quests").exists()) { + loadDefaultFile("quests", "adv-begins.yml"); + loadDefaultFile("quests", "tutorial.yml"); + loadDefaultFile("quests", "fetch-mango.yml"); + } - if (!new File(MMOCore.plugin.getDataFolder() + "/classes").exists()) { - loadDefaultFile("classes", "arcane-mage.yml"); - loadDefaultFile("classes", "human.yml"); - loadDefaultFile("classes", "mage.yml"); - loadDefaultFile("classes", "marksman.yml"); - loadDefaultFile("classes", "paladin.yml"); - loadDefaultFile("classes", "rogue.yml"); - loadDefaultFile("classes", "warrior.yml"); - } + if (!new File(MMOCore.plugin.getDataFolder() + "/classes").exists()) { + loadDefaultFile("classes", "arcane-mage.yml"); + loadDefaultFile("classes", "human.yml"); + loadDefaultFile("classes", "mage.yml"); + loadDefaultFile("classes", "marksman.yml"); + loadDefaultFile("classes", "paladin.yml"); + loadDefaultFile("classes", "rogue.yml"); + loadDefaultFile("classes", "warrior.yml"); + } - if (!new File(MMOCore.plugin.getDataFolder() + "/expcurves").exists()) { - loadDefaultFile("expcurves", "levels.txt"); - loadDefaultFile("expcurves", "mining.txt"); - } + if (!new File(MMOCore.plugin.getDataFolder() + "/expcurves").exists()) { + loadDefaultFile("expcurves", "levels.txt"); + loadDefaultFile("expcurves", "mining.txt"); + } - loadDefaultFile("attributes.yml"); - loadDefaultFile("items.yml"); - loadDefaultFile("messages.yml"); - loadDefaultFile("stats.yml"); - loadDefaultFile("waypoints.yml"); - loadDefaultFile("restrictions.yml"); - loadDefaultFile("sounds.yml"); - loadDefaultFile("loot-chests.yml"); - loadDefaultFile("commands.yml"); - loadDefaultFile("guilds.yml"); + loadDefaultFile("attributes.yml"); + loadDefaultFile("items.yml"); + loadDefaultFile("messages.yml"); + loadDefaultFile("stats.yml"); + loadDefaultFile("waypoints.yml"); + loadDefaultFile("restrictions.yml"); + loadDefaultFile("sounds.yml"); + loadDefaultFile("loot-chests.yml"); + loadDefaultFile("commands.yml"); + loadDefaultFile("guilds.yml"); - commandVerbose.reload(MMOCore.plugin.getConfig().getConfigurationSection("command-verbose")); + commandVerbose.reload(MMOCore.plugin.getConfig().getConfigurationSection("command-verbose")); - messages = new ConfigFile("messages").getConfig(); - chatInput = MMOCore.plugin.getConfig().getBoolean("use-chat-input"); - partyChatPrefix = MMOCore.plugin.getConfig().getString("party.chat-prefix"); - combatLogTimer = MMOCore.plugin.getConfig().getInt("combat-log.timer") * 1000L; - lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chests.chest-expire-time"), 1) * 1000L; - lootChestPlayerCooldown = MMOCore.plugin.getConfig().getInt("player-cooldown") * 1000L; - noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message(); + messages = new ConfigFile("messages").getConfig(); + chatInput = MMOCore.plugin.getConfig().getBoolean("use-chat-input"); + partyChatPrefix = MMOCore.plugin.getConfig().getString("party.chat-prefix"); + combatLogTimer = MMOCore.plugin.getConfig().getInt("combat-log.timer") * 1000L; + lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chests.chest-expire-time"), 1) * 1000L; + lootChestPlayerCooldown = (long) MMOCore.plugin.getConfig().getDouble("player-cooldown") * 1000L; + noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message(); - staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN); - staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN); - staminaEmpty = getColorOrDefault("stamina-empty", ChatColor.WHITE); + staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN); + staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN); + staminaEmpty = getColorOrDefault("stamina-empty", ChatColor.WHITE); - normalSwapAction = EnumUtils.getIfPresent(SwapAction.class, MMOCore.plugin.getConfig().getString("swap-keybind.normal").toUpperCase()).orElse(SwapAction.VANILLA); - sneakingSwapAction = EnumUtils.getIfPresent(SwapAction.class, MMOCore.plugin.getConfig().getString("swap-keybind.sneaking").toUpperCase()).orElse(SwapAction.VANILLA); - canCreativeCast = MMOCore.plugin.getConfig().getBoolean("can-creative-cast"); - cobbleGeneratorXP = MMOCore.plugin.getConfig().getBoolean("should-cobblestone-generators-give-exp"); - saveDefaultClassInfo = MMOCore.plugin.getConfig().getBoolean("save-default-class-info"); - } + normalSwapAction = EnumUtils.getIfPresent(SwapAction.class, MMOCore.plugin.getConfig().getString("swap-keybind.normal").toUpperCase()).orElse(SwapAction.VANILLA); + sneakingSwapAction = EnumUtils.getIfPresent(SwapAction.class, MMOCore.plugin.getConfig().getString("swap-keybind.sneaking").toUpperCase()).orElse(SwapAction.VANILLA); + canCreativeCast = MMOCore.plugin.getConfig().getBoolean("can-creative-cast"); + cobbleGeneratorXP = MMOCore.plugin.getConfig().getBoolean("should-cobblestone-generators-give-exp"); + saveDefaultClassInfo = MMOCore.plugin.getConfig().getBoolean("save-default-class-info"); + } - private ChatColor getColorOrDefault(String key, ChatColor defaultColor) { - try { - return ChatColor.valueOf(MMOCore.plugin.getConfig().getString("resource-bar-colors." + key).toUpperCase()); - } catch (IllegalArgumentException exception) { - MMOCore.log(Level.WARNING, "Could not read resource bar color from '" + key + "': using default."); - return defaultColor; - } - } + private ChatColor getColorOrDefault(String key, ChatColor defaultColor) { + try { + return ChatColor.valueOf(MMOCore.plugin.getConfig().getString("resource-bar-colors." + key).toUpperCase()); + } catch (IllegalArgumentException exception) { + MMOCore.log(Level.WARNING, "Could not read resource bar color from '" + key + "': using default."); + return defaultColor; + } + } - public PlayerInput newPlayerInput(Player player, InputType type, Consumer output) { - return chatInput ? new ChatInput(player, type, output) : new AnvilGUI(player, type, output); - } + public PlayerInput newPlayerInput(Player player, InputType type, Consumer output) { + return chatInput ? new ChatInput(player, type, output) : new AnvilGUI(player, type, output); + } - public void loadDefaultFile(String name) { - loadDefaultFile("", name); - } + public void loadDefaultFile(String name) { + loadDefaultFile("", name); + } - public void loadDefaultFile(String path, String name) { - String newPath = path.isEmpty() ? "" : "/" + path; - File folder = new File(MMOCore.plugin.getDataFolder() + (newPath)); - if (!folder.exists()) folder.mkdir(); + public void loadDefaultFile(String path, String name) { + String newPath = path.isEmpty() ? "" : "/" + path; + File folder = new File(MMOCore.plugin.getDataFolder() + (newPath)); + if (!folder.exists()) folder.mkdir(); - File file = new File(MMOCore.plugin.getDataFolder() + (newPath), name); - if (!file.exists()) try { - Files.copy(MMOCore.plugin.getResource("default/" + (path.isEmpty() ? "" : path + "/") + name), file.getAbsoluteFile().toPath()); - } catch (IOException e) { - e.printStackTrace(); - } - } + File file = new File(MMOCore.plugin.getDataFolder() + (newPath), name); + if (!file.exists()) try { + Files.copy(MMOCore.plugin.getResource("default/" + (path.isEmpty() ? "" : path + "/") + name), file.getAbsoluteFile().toPath()); + } catch (IOException e) { + e.printStackTrace(); + } + } - public List getMessage(String key) { - return messages.getStringList(key); - } + public List getMessage(String key) { + return messages.getStringList(key); + } - public SimpleMessage getSimpleMessage(String key, String... placeholders) { - String format = messages.getString(key, ""); - for (int j = 0; j < placeholders.length - 1; j += 2) - format = format.replace("{" + placeholders[j] + "}", placeholders[j + 1]); - return new SimpleMessage(MythicLib.plugin.parseColors(format)); - } + public SimpleMessage getSimpleMessage(String key, String... placeholders) { + String format = messages.getString(key, ""); + for (int j = 0; j < placeholders.length - 1; j += 2) + format = format.replace("{" + placeholders[j] + "}", placeholders[j + 1]); + return new SimpleMessage(MythicLib.plugin.parseColors(format)); + } - public static class SimpleMessage { - private final String message; - private final boolean actionbar; - private final boolean hasPlaceholders; + public static class SimpleMessage { + private final String message; + private final boolean actionbar; + private final boolean hasPlaceholders; - public SimpleMessage(String message) { - this.actionbar = message.startsWith("%"); - this.message = actionbar ? message.substring(1) : message; - this.hasPlaceholders = this.message.contains("%"); - } + public SimpleMessage(String message) { + this.actionbar = message.startsWith("%"); + this.message = actionbar ? message.substring(1) : message; + this.hasPlaceholders = this.message.contains("%"); + } - public String message() { - return message; - } + public String message() { + return message; + } - public boolean send(Player player) { - String msg = hasPlaceholders ? MMOCore.plugin.placeholderParser.parse(player, message) : message; + public boolean send(Player player) { + String msg = hasPlaceholders ? MMOCore.plugin.placeholderParser.parse(player, message) : message; - if (!msg.isEmpty()) { - if (actionbar) PlayerData.get(player.getUniqueId()).displayActionBar(msg); - else player.sendMessage(msg); - } - return !msg.isEmpty(); - } - } + if (!msg.isEmpty()) { + if (actionbar) PlayerData.get(player.getUniqueId()).displayActionBar(msg); + else player.sendMessage(msg); + } + return !msg.isEmpty(); + } + } - public enum SwapAction { - VANILLA, - SPELL_CAST, - HOTBAR_SWAP - } + public enum SwapAction { + VANILLA, + SPELL_CAST, + HOTBAR_SWAP + } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java b/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java index 2bb3644d..c39904d9 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java @@ -7,8 +7,8 @@ import net.Indyuce.mmocore.api.block.BlockInfo.RegeneratingBlock; import net.Indyuce.mmocore.api.block.BlockType; import net.Indyuce.mmocore.api.block.SkullBlockType; import net.Indyuce.mmocore.api.block.VanillaBlockType; -import net.Indyuce.mmocore.api.droptable.condition.Condition; -import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance; +import net.Indyuce.mmocore.loot.droptable.condition.Condition; +import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; import net.Indyuce.mmocore.api.util.MMOCoreUtils; import io.lumine.mythic.lib.api.MMOLineConfig; import org.bukkit.Bukkit; diff --git a/src/main/java/net/Indyuce/mmocore/manager/DropTableManager.java b/src/main/java/net/Indyuce/mmocore/manager/DropTableManager.java index f781497e..9bb04f13 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/DropTableManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/DropTableManager.java @@ -14,7 +14,7 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.droptable.DropTable; +import net.Indyuce.mmocore.loot.droptable.DropTable; public class DropTableManager implements MMOManager { private final Map map = new HashMap<>(); diff --git a/src/main/java/net/Indyuce/mmocore/manager/LootChestManager.java b/src/main/java/net/Indyuce/mmocore/manager/LootChestManager.java index 787a8947..2f3ff309 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/LootChestManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/LootChestManager.java @@ -12,8 +12,8 @@ import org.bukkit.configuration.file.FileConfiguration; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.ConfigFile; -import net.Indyuce.mmocore.api.loot.LootChest; -import net.Indyuce.mmocore.api.loot.LootChestRegion; +import net.Indyuce.mmocore.loot.chest.LootChest; +import net.Indyuce.mmocore.loot.chest.LootChestRegion; public class LootChestManager { diff --git a/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java b/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java index 2693dd6e..c25d36ce 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java @@ -11,8 +11,8 @@ import org.bukkit.configuration.ConfigurationSection; import com.google.gson.JsonParseException; import net.Indyuce.mmocore.api.block.BlockType; -import net.Indyuce.mmocore.api.droptable.condition.Condition; -import net.Indyuce.mmocore.api.droptable.dropitem.DropItem; +import net.Indyuce.mmocore.loot.droptable.condition.Condition; +import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem; import net.Indyuce.mmocore.experience.source.type.ExperienceSource; import net.Indyuce.mmocore.api.load.DefaultMMOLoader; import net.Indyuce.mmocore.api.load.MMOLoader; diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java index e297cc93..badb7889 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java @@ -13,9 +13,9 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Entity; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.droptable.condition.Condition; -import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance; -import net.Indyuce.mmocore.api.droptable.dropitem.fishing.FishingDropItem; +import net.Indyuce.mmocore.loot.droptable.condition.Condition; +import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; +import net.Indyuce.mmocore.loot.droptable.dropitem.fishing.FishingDropItem; import net.Indyuce.mmocore.manager.MMOManager; import io.lumine.mythic.lib.api.MMOLineConfig;