forked from Upstream/mmocore
refactor, fixed an issue with loot chests cooldown
This commit is contained in:
parent
8c95245ffb
commit
a574a67a3b
@ -5,7 +5,7 @@ import io.lumine.mythic.lib.version.SpigotPlugin;
|
|||||||
import io.lumine.mythic.utils.plugin.LuminePlugin;
|
import io.lumine.mythic.utils.plugin.LuminePlugin;
|
||||||
import net.Indyuce.mmocore.api.ConfigFile;
|
import net.Indyuce.mmocore.api.ConfigFile;
|
||||||
import net.Indyuce.mmocore.api.PlayerActionBar;
|
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.PlayerData;
|
||||||
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
||||||
import net.Indyuce.mmocore.api.player.social.guilds.Guild;
|
import net.Indyuce.mmocore.api.player.social.guilds.Guild;
|
||||||
|
@ -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.BlockCondition;
|
||||||
import io.lumine.mythic.lib.api.condition.type.MMOCondition;
|
import io.lumine.mythic.lib.api.condition.type.MMOCondition;
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.droptable.DropTable;
|
import net.Indyuce.mmocore.loot.droptable.DropTable;
|
||||||
import net.Indyuce.mmocore.api.loot.LootBuilder;
|
import net.Indyuce.mmocore.loot.LootBuilder;
|
||||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -3,8 +3,8 @@ package net.Indyuce.mmocore.api.event;
|
|||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.api.loot.LootBuilder;
|
import net.Indyuce.mmocore.loot.LootBuilder;
|
||||||
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.PlayerData;
|
||||||
|
|
||||||
public class LootChestSpawnEvent extends PlayerDataEvent implements Cancellable {
|
public class LootChestSpawnEvent extends PlayerDataEvent implements Cancellable {
|
||||||
|
@ -6,17 +6,17 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||||||
import net.Indyuce.mmocore.api.block.BlockType;
|
import net.Indyuce.mmocore.api.block.BlockType;
|
||||||
import net.Indyuce.mmocore.api.block.SkullBlockType;
|
import net.Indyuce.mmocore.api.block.SkullBlockType;
|
||||||
import net.Indyuce.mmocore.api.block.VanillaBlockType;
|
import net.Indyuce.mmocore.api.block.VanillaBlockType;
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.BiomeCondition;
|
import net.Indyuce.mmocore.loot.droptable.condition.BiomeCondition;
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
import net.Indyuce.mmocore.loot.droptable.condition.Condition;
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.LevelCondition;
|
import net.Indyuce.mmocore.loot.droptable.condition.LevelCondition;
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.PermissionCondition;
|
import net.Indyuce.mmocore.loot.droptable.condition.PermissionCondition;
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.WorldCondition;
|
import net.Indyuce.mmocore.loot.droptable.condition.WorldCondition;
|
||||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
|
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
|
||||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropTableDropItem;
|
import net.Indyuce.mmocore.loot.droptable.dropitem.DropTableDropItem;
|
||||||
import net.Indyuce.mmocore.api.droptable.dropitem.GoldDropItem;
|
import net.Indyuce.mmocore.loot.droptable.dropitem.GoldDropItem;
|
||||||
import net.Indyuce.mmocore.api.droptable.dropitem.MMDropTableDropItem;
|
import net.Indyuce.mmocore.loot.droptable.dropitem.MMDropTableDropItem;
|
||||||
import net.Indyuce.mmocore.api.droptable.dropitem.NoteDropItem;
|
import net.Indyuce.mmocore.loot.droptable.dropitem.NoteDropItem;
|
||||||
import net.Indyuce.mmocore.api.droptable.dropitem.VanillaDropItem;
|
import net.Indyuce.mmocore.loot.droptable.dropitem.VanillaDropItem;
|
||||||
import net.Indyuce.mmocore.experience.source.BrewPotionExperienceSource;
|
import net.Indyuce.mmocore.experience.source.BrewPotionExperienceSource;
|
||||||
import net.Indyuce.mmocore.experience.source.CraftItemExperienceSource;
|
import net.Indyuce.mmocore.experience.source.CraftItemExperienceSource;
|
||||||
import net.Indyuce.mmocore.experience.source.EnchantItemExperienceSource;
|
import net.Indyuce.mmocore.experience.source.EnchantItemExperienceSource;
|
||||||
|
@ -2,8 +2,8 @@ package net.Indyuce.mmocore.api.load;
|
|||||||
|
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
import net.Indyuce.mmocore.api.block.BlockType;
|
import net.Indyuce.mmocore.api.block.BlockType;
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
import net.Indyuce.mmocore.loot.droptable.condition.Condition;
|
||||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
|
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
|
||||||
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
|
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
|
||||||
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
|
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
|
||||||
import net.Indyuce.mmocore.api.quest.objective.Objective;
|
import net.Indyuce.mmocore.api.quest.objective.Objective;
|
||||||
|
@ -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<ChestTier> 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<ChestTier> 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<Integer> 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<PlayerData> found = region.getBounds().getPlayers().filter(PlayerData::canSpawnLootChest).findAny();
|
|
||||||
found.ifPresent(region::spawnChest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -79,7 +79,7 @@ public class PlayerData extends OfflinePlayerData {
|
|||||||
// NON-FINAL player data stuff made public to facilitate field change
|
// NON-FINAL player data stuff made public to facilitate field change
|
||||||
public int skillGuiDisplayOffset;
|
public int skillGuiDisplayOffset;
|
||||||
public SkillCasting skillCasting;
|
public SkillCasting skillCasting;
|
||||||
public boolean nocd;
|
public boolean noCooldown;
|
||||||
public CombatRunnable combat;
|
public CombatRunnable combat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -845,7 +845,7 @@ public class PlayerData extends OfflinePlayerData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply cooldown, mana and stamina costs
|
// Apply cooldown, mana and stamina costs
|
||||||
if (!nocd) {
|
if (!noCooldown) {
|
||||||
double flatCooldownReduction = Math.max(0, Math.min(1, getStats().getStat(StatType.COOLDOWN_REDUCTION) / 100));
|
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;
|
flatCooldownReduction *= flatCooldownReduction > 0 ? skill.getModifier("cooldown", getSkillLevel(skill.getSkill())) * 1000 : 0;
|
||||||
|
|
||||||
|
@ -29,9 +29,9 @@ public class NoCooldownCommandTreeNode extends CommandTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PlayerData data = PlayerData.get(player);
|
PlayerData data = PlayerData.get(player);
|
||||||
data.nocd = !data.nocd;
|
data.noCooldown = !data.noCooldown;
|
||||||
CommandVerbose.verbose(sender, CommandVerbose.CommandType.NOCD,
|
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;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ package net.Indyuce.mmocore.comp.region;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
import net.Indyuce.mmocore.loot.droptable.condition.Condition;
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
|
import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance;
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
|
||||||
public class RegionCondition extends Condition {
|
public class RegionCondition extends Condition {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package net.Indyuce.mmocore.comp.region;
|
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 net.Indyuce.mmocore.api.load.MMOLoader;
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
|
||||||
|
@ -6,9 +6,9 @@ import net.Indyuce.mmocore.MMOCore;
|
|||||||
import net.Indyuce.mmocore.api.block.BlockInfo;
|
import net.Indyuce.mmocore.api.block.BlockInfo;
|
||||||
import net.Indyuce.mmocore.api.block.BlockInfo.BlockInfoOption;
|
import net.Indyuce.mmocore.api.block.BlockInfo.BlockInfoOption;
|
||||||
import net.Indyuce.mmocore.api.block.VanillaBlockType;
|
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.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.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
|
@ -6,7 +6,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.loot.LootChest;
|
import net.Indyuce.mmocore.loot.chest.LootChest;
|
||||||
|
|
||||||
public class LootableChestsListener implements Listener {
|
public class LootableChestsListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -2,10 +2,10 @@ package net.Indyuce.mmocore.listener.profession;
|
|||||||
|
|
||||||
import io.lumine.mythic.lib.version.VersionSound;
|
import io.lumine.mythic.lib.version.VersionSound;
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
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.api.event.CustomPlayerFishEvent;
|
||||||
import net.Indyuce.mmocore.experience.EXPSource;
|
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.PlayerData;
|
||||||
import net.Indyuce.mmocore.api.player.stats.StatType;
|
import net.Indyuce.mmocore.api.player.stats.StatType;
|
||||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package net.Indyuce.mmocore.api.loot;
|
package net.Indyuce.mmocore.loot;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -1,4 +1,4 @@
|
|||||||
package net.Indyuce.mmocore.api.loot;
|
package net.Indyuce.mmocore.loot.chest;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
@ -1,8 +1,8 @@
|
|||||||
package net.Indyuce.mmocore.api.loot;
|
package net.Indyuce.mmocore.loot.chest;
|
||||||
|
|
||||||
import io.lumine.mythic.lib.api.math.ScalingFormula;
|
import io.lumine.mythic.lib.api.math.ScalingFormula;
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.droptable.DropTable;
|
import net.Indyuce.mmocore.loot.droptable.DropTable;
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package net.Indyuce.mmocore.api.loot;
|
package net.Indyuce.mmocore.loot.chest;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.manager.SoundManager;
|
import net.Indyuce.mmocore.manager.SoundManager;
|
@ -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<ChestTier> 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<ChestTier> 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<Integer> 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();
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package net.Indyuce.mmocore.api.loot;
|
package net.Indyuce.mmocore.loot.chest;
|
||||||
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package net.Indyuce.mmocore.api.loot;
|
package net.Indyuce.mmocore.loot.chest;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
@ -1,19 +1,19 @@
|
|||||||
package net.Indyuce.mmocore.api.droptable;
|
package net.Indyuce.mmocore.loot.droptable;
|
||||||
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
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.apache.commons.lang.Validate;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
import net.Indyuce.mmocore.loot.LootBuilder;
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
|
|
||||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
|
|
||||||
import net.Indyuce.mmocore.api.loot.LootBuilder;
|
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
import io.lumine.mythic.lib.api.util.PostLoadObject;
|
import io.lumine.mythic.lib.api.util.PostLoadObject;
|
||||||
|
|
@ -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.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -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 io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
|
@ -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.List;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
@ -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 net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
@ -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 io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -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.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -1,8 +1,8 @@
|
|||||||
package net.Indyuce.mmocore.api.droptable.dropitem;
|
package net.Indyuce.mmocore.loot.droptable.dropitem;
|
||||||
|
|
||||||
import java.util.Random;
|
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 net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
|
@ -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 io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.droptable.DropTable;
|
import net.Indyuce.mmocore.loot.droptable.DropTable;
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
|
import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance;
|
||||||
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.PlayerData;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
|
|
@ -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 net.Indyuce.mmocore.api.util.item.CurrencyItem;
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package net.Indyuce.mmocore.api.droptable.dropitem;
|
package net.Indyuce.mmocore.loot.droptable.dropitem;
|
||||||
|
|
||||||
import java.util.NoSuchElementException;
|
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.DropTable;
|
||||||
import io.lumine.xikage.mythicmobs.drops.IItemDrop;
|
import io.lumine.xikage.mythicmobs.drops.IItemDrop;
|
||||||
import io.lumine.xikage.mythicmobs.drops.LootBag;
|
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;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
|
||||||
public class MMDropTableDropItem extends DropItem {
|
public class MMDropTableDropItem extends DropItem {
|
@ -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 net.Indyuce.mmocore.api.util.item.CurrencyItem;
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
|
@ -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.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
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;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
|
||||||
public class VanillaDropItem extends DropItem {
|
public class VanillaDropItem extends DropItem {
|
@ -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.apache.commons.lang.Validate;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
|
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
|
||||||
import net.Indyuce.mmocore.api.loot.LootBuilder;
|
import net.Indyuce.mmocore.loot.LootBuilder;
|
||||||
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
|
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
|
@ -22,164 +22,163 @@ import java.util.List;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class ConfigManager {
|
public class ConfigManager {
|
||||||
public final CommandVerbose commandVerbose = new CommandVerbose();
|
public final CommandVerbose commandVerbose = new CommandVerbose();
|
||||||
|
|
||||||
public boolean overrideVanillaExp, canCreativeCast, cobbleGeneratorXP, saveDefaultClassInfo;
|
public boolean overrideVanillaExp, canCreativeCast, cobbleGeneratorXP, saveDefaultClassInfo;
|
||||||
public double expPartyBuff, regenPartyBuff;
|
public String partyChatPrefix, noSkillBoundPlaceholder;
|
||||||
public String partyChatPrefix, noSkillBoundPlaceholder;
|
public ChatColor staminaFull, staminaHalf, staminaEmpty;
|
||||||
public ChatColor staminaFull, staminaHalf, staminaEmpty;
|
public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown;
|
||||||
public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown;
|
public SwapAction normalSwapAction, sneakingSwapAction;
|
||||||
public SwapAction normalSwapAction, sneakingSwapAction;
|
|
||||||
|
|
||||||
private final FileConfiguration messages;
|
private final FileConfiguration messages;
|
||||||
private final boolean chatInput;
|
private final boolean chatInput;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the instance must be created after the other managers since all it does
|
* 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
|
* is to update them based on the config except for the classes which are
|
||||||
* already loaded based on the config
|
* already loaded based on the config
|
||||||
*/
|
*/
|
||||||
public ConfigManager() {
|
public ConfigManager() {
|
||||||
// loadDefaultFile("recipes", "brewing.yml");
|
// loadDefaultFile("recipes", "brewing.yml");
|
||||||
// loadDefaultFile("recipes", "furnace.yml");
|
// loadDefaultFile("recipes", "furnace.yml");
|
||||||
|
|
||||||
if (!new File(MMOCore.plugin.getDataFolder() + "/drop-tables").exists())
|
if (!new File(MMOCore.plugin.getDataFolder() + "/drop-tables").exists())
|
||||||
loadDefaultFile("drop-tables", "example-drop-tables.yml");
|
loadDefaultFile("drop-tables", "example-drop-tables.yml");
|
||||||
|
|
||||||
if (!new File(MMOCore.plugin.getDataFolder() + "/professions").exists()) {
|
if (!new File(MMOCore.plugin.getDataFolder() + "/professions").exists()) {
|
||||||
loadDefaultFile("professions", "alchemy.yml");
|
loadDefaultFile("professions", "alchemy.yml");
|
||||||
loadDefaultFile("professions", "farming.yml");
|
loadDefaultFile("professions", "farming.yml");
|
||||||
loadDefaultFile("professions", "fishing.yml");
|
loadDefaultFile("professions", "fishing.yml");
|
||||||
loadDefaultFile("professions", "mining.yml");
|
loadDefaultFile("professions", "mining.yml");
|
||||||
loadDefaultFile("professions", "smelting.yml");
|
loadDefaultFile("professions", "smelting.yml");
|
||||||
loadDefaultFile("professions", "smithing.yml");
|
loadDefaultFile("professions", "smithing.yml");
|
||||||
loadDefaultFile("professions", "woodcutting.yml");
|
loadDefaultFile("professions", "woodcutting.yml");
|
||||||
loadDefaultFile("professions", "enchanting.yml");
|
loadDefaultFile("professions", "enchanting.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!new File(MMOCore.plugin.getDataFolder() + "/quests").exists()) {
|
if (!new File(MMOCore.plugin.getDataFolder() + "/quests").exists()) {
|
||||||
loadDefaultFile("quests", "adv-begins.yml");
|
loadDefaultFile("quests", "adv-begins.yml");
|
||||||
loadDefaultFile("quests", "tutorial.yml");
|
loadDefaultFile("quests", "tutorial.yml");
|
||||||
loadDefaultFile("quests", "fetch-mango.yml");
|
loadDefaultFile("quests", "fetch-mango.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!new File(MMOCore.plugin.getDataFolder() + "/classes").exists()) {
|
if (!new File(MMOCore.plugin.getDataFolder() + "/classes").exists()) {
|
||||||
loadDefaultFile("classes", "arcane-mage.yml");
|
loadDefaultFile("classes", "arcane-mage.yml");
|
||||||
loadDefaultFile("classes", "human.yml");
|
loadDefaultFile("classes", "human.yml");
|
||||||
loadDefaultFile("classes", "mage.yml");
|
loadDefaultFile("classes", "mage.yml");
|
||||||
loadDefaultFile("classes", "marksman.yml");
|
loadDefaultFile("classes", "marksman.yml");
|
||||||
loadDefaultFile("classes", "paladin.yml");
|
loadDefaultFile("classes", "paladin.yml");
|
||||||
loadDefaultFile("classes", "rogue.yml");
|
loadDefaultFile("classes", "rogue.yml");
|
||||||
loadDefaultFile("classes", "warrior.yml");
|
loadDefaultFile("classes", "warrior.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!new File(MMOCore.plugin.getDataFolder() + "/expcurves").exists()) {
|
if (!new File(MMOCore.plugin.getDataFolder() + "/expcurves").exists()) {
|
||||||
loadDefaultFile("expcurves", "levels.txt");
|
loadDefaultFile("expcurves", "levels.txt");
|
||||||
loadDefaultFile("expcurves", "mining.txt");
|
loadDefaultFile("expcurves", "mining.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
loadDefaultFile("attributes.yml");
|
loadDefaultFile("attributes.yml");
|
||||||
loadDefaultFile("items.yml");
|
loadDefaultFile("items.yml");
|
||||||
loadDefaultFile("messages.yml");
|
loadDefaultFile("messages.yml");
|
||||||
loadDefaultFile("stats.yml");
|
loadDefaultFile("stats.yml");
|
||||||
loadDefaultFile("waypoints.yml");
|
loadDefaultFile("waypoints.yml");
|
||||||
loadDefaultFile("restrictions.yml");
|
loadDefaultFile("restrictions.yml");
|
||||||
loadDefaultFile("sounds.yml");
|
loadDefaultFile("sounds.yml");
|
||||||
loadDefaultFile("loot-chests.yml");
|
loadDefaultFile("loot-chests.yml");
|
||||||
loadDefaultFile("commands.yml");
|
loadDefaultFile("commands.yml");
|
||||||
loadDefaultFile("guilds.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();
|
messages = new ConfigFile("messages").getConfig();
|
||||||
chatInput = MMOCore.plugin.getConfig().getBoolean("use-chat-input");
|
chatInput = MMOCore.plugin.getConfig().getBoolean("use-chat-input");
|
||||||
partyChatPrefix = MMOCore.plugin.getConfig().getString("party.chat-prefix");
|
partyChatPrefix = MMOCore.plugin.getConfig().getString("party.chat-prefix");
|
||||||
combatLogTimer = MMOCore.plugin.getConfig().getInt("combat-log.timer") * 1000L;
|
combatLogTimer = MMOCore.plugin.getConfig().getInt("combat-log.timer") * 1000L;
|
||||||
lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chests.chest-expire-time"), 1) * 1000L;
|
lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chests.chest-expire-time"), 1) * 1000L;
|
||||||
lootChestPlayerCooldown = MMOCore.plugin.getConfig().getInt("player-cooldown") * 1000L;
|
lootChestPlayerCooldown = (long) MMOCore.plugin.getConfig().getDouble("player-cooldown") * 1000L;
|
||||||
noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message();
|
noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message();
|
||||||
|
|
||||||
staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN);
|
staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN);
|
||||||
staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN);
|
staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN);
|
||||||
staminaEmpty = getColorOrDefault("stamina-empty", ChatColor.WHITE);
|
staminaEmpty = getColorOrDefault("stamina-empty", ChatColor.WHITE);
|
||||||
|
|
||||||
normalSwapAction = EnumUtils.getIfPresent(SwapAction.class, MMOCore.plugin.getConfig().getString("swap-keybind.normal").toUpperCase()).orElse(SwapAction.VANILLA);
|
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);
|
sneakingSwapAction = EnumUtils.getIfPresent(SwapAction.class, MMOCore.plugin.getConfig().getString("swap-keybind.sneaking").toUpperCase()).orElse(SwapAction.VANILLA);
|
||||||
canCreativeCast = MMOCore.plugin.getConfig().getBoolean("can-creative-cast");
|
canCreativeCast = MMOCore.plugin.getConfig().getBoolean("can-creative-cast");
|
||||||
cobbleGeneratorXP = MMOCore.plugin.getConfig().getBoolean("should-cobblestone-generators-give-exp");
|
cobbleGeneratorXP = MMOCore.plugin.getConfig().getBoolean("should-cobblestone-generators-give-exp");
|
||||||
saveDefaultClassInfo = MMOCore.plugin.getConfig().getBoolean("save-default-class-info");
|
saveDefaultClassInfo = MMOCore.plugin.getConfig().getBoolean("save-default-class-info");
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChatColor getColorOrDefault(String key, ChatColor defaultColor) {
|
private ChatColor getColorOrDefault(String key, ChatColor defaultColor) {
|
||||||
try {
|
try {
|
||||||
return ChatColor.valueOf(MMOCore.plugin.getConfig().getString("resource-bar-colors." + key).toUpperCase());
|
return ChatColor.valueOf(MMOCore.plugin.getConfig().getString("resource-bar-colors." + key).toUpperCase());
|
||||||
} catch (IllegalArgumentException exception) {
|
} catch (IllegalArgumentException exception) {
|
||||||
MMOCore.log(Level.WARNING, "Could not read resource bar color from '" + key + "': using default.");
|
MMOCore.log(Level.WARNING, "Could not read resource bar color from '" + key + "': using default.");
|
||||||
return defaultColor;
|
return defaultColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerInput newPlayerInput(Player player, InputType type, Consumer<String> output) {
|
public PlayerInput newPlayerInput(Player player, InputType type, Consumer<String> output) {
|
||||||
return chatInput ? new ChatInput(player, type, output) : new AnvilGUI(player, type, output);
|
return chatInput ? new ChatInput(player, type, output) : new AnvilGUI(player, type, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadDefaultFile(String name) {
|
public void loadDefaultFile(String name) {
|
||||||
loadDefaultFile("", name);
|
loadDefaultFile("", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadDefaultFile(String path, String name) {
|
public void loadDefaultFile(String path, String name) {
|
||||||
String newPath = path.isEmpty() ? "" : "/" + path;
|
String newPath = path.isEmpty() ? "" : "/" + path;
|
||||||
File folder = new File(MMOCore.plugin.getDataFolder() + (newPath));
|
File folder = new File(MMOCore.plugin.getDataFolder() + (newPath));
|
||||||
if (!folder.exists()) folder.mkdir();
|
if (!folder.exists()) folder.mkdir();
|
||||||
|
|
||||||
File file = new File(MMOCore.plugin.getDataFolder() + (newPath), name);
|
File file = new File(MMOCore.plugin.getDataFolder() + (newPath), name);
|
||||||
if (!file.exists()) try {
|
if (!file.exists()) try {
|
||||||
Files.copy(MMOCore.plugin.getResource("default/" + (path.isEmpty() ? "" : path + "/") + name), file.getAbsoluteFile().toPath());
|
Files.copy(MMOCore.plugin.getResource("default/" + (path.isEmpty() ? "" : path + "/") + name), file.getAbsoluteFile().toPath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getMessage(String key) {
|
public List<String> getMessage(String key) {
|
||||||
return messages.getStringList(key);
|
return messages.getStringList(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleMessage getSimpleMessage(String key, String... placeholders) {
|
public SimpleMessage getSimpleMessage(String key, String... placeholders) {
|
||||||
String format = messages.getString(key, "");
|
String format = messages.getString(key, "");
|
||||||
for (int j = 0; j < placeholders.length - 1; j += 2)
|
for (int j = 0; j < placeholders.length - 1; j += 2)
|
||||||
format = format.replace("{" + placeholders[j] + "}", placeholders[j + 1]);
|
format = format.replace("{" + placeholders[j] + "}", placeholders[j + 1]);
|
||||||
return new SimpleMessage(MythicLib.plugin.parseColors(format));
|
return new SimpleMessage(MythicLib.plugin.parseColors(format));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SimpleMessage {
|
public static class SimpleMessage {
|
||||||
private final String message;
|
private final String message;
|
||||||
private final boolean actionbar;
|
private final boolean actionbar;
|
||||||
private final boolean hasPlaceholders;
|
private final boolean hasPlaceholders;
|
||||||
|
|
||||||
public SimpleMessage(String message) {
|
public SimpleMessage(String message) {
|
||||||
this.actionbar = message.startsWith("%");
|
this.actionbar = message.startsWith("%");
|
||||||
this.message = actionbar ? message.substring(1) : message;
|
this.message = actionbar ? message.substring(1) : message;
|
||||||
this.hasPlaceholders = this.message.contains("%");
|
this.hasPlaceholders = this.message.contains("%");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String message() {
|
public String message() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean send(Player player) {
|
public boolean send(Player player) {
|
||||||
String msg = hasPlaceholders ? MMOCore.plugin.placeholderParser.parse(player, message) : message;
|
String msg = hasPlaceholders ? MMOCore.plugin.placeholderParser.parse(player, message) : message;
|
||||||
|
|
||||||
if (!msg.isEmpty()) {
|
if (!msg.isEmpty()) {
|
||||||
if (actionbar) PlayerData.get(player.getUniqueId()).displayActionBar(msg);
|
if (actionbar) PlayerData.get(player.getUniqueId()).displayActionBar(msg);
|
||||||
else player.sendMessage(msg);
|
else player.sendMessage(msg);
|
||||||
}
|
}
|
||||||
return !msg.isEmpty();
|
return !msg.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum SwapAction {
|
public enum SwapAction {
|
||||||
VANILLA,
|
VANILLA,
|
||||||
SPELL_CAST,
|
SPELL_CAST,
|
||||||
HOTBAR_SWAP
|
HOTBAR_SWAP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.BlockType;
|
||||||
import net.Indyuce.mmocore.api.block.SkullBlockType;
|
import net.Indyuce.mmocore.api.block.SkullBlockType;
|
||||||
import net.Indyuce.mmocore.api.block.VanillaBlockType;
|
import net.Indyuce.mmocore.api.block.VanillaBlockType;
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
import net.Indyuce.mmocore.loot.droptable.condition.Condition;
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
|
import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance;
|
||||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -14,7 +14,7 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.droptable.DropTable;
|
import net.Indyuce.mmocore.loot.droptable.DropTable;
|
||||||
|
|
||||||
public class DropTableManager implements MMOManager {
|
public class DropTableManager implements MMOManager {
|
||||||
private final Map<String, DropTable> map = new HashMap<>();
|
private final Map<String, DropTable> map = new HashMap<>();
|
||||||
|
@ -12,8 +12,8 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.ConfigFile;
|
import net.Indyuce.mmocore.api.ConfigFile;
|
||||||
import net.Indyuce.mmocore.api.loot.LootChest;
|
import net.Indyuce.mmocore.loot.chest.LootChest;
|
||||||
import net.Indyuce.mmocore.api.loot.LootChestRegion;
|
import net.Indyuce.mmocore.loot.chest.LootChestRegion;
|
||||||
|
|
||||||
public class LootChestManager {
|
public class LootChestManager {
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.api.block.BlockType;
|
import net.Indyuce.mmocore.api.block.BlockType;
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
import net.Indyuce.mmocore.loot.droptable.condition.Condition;
|
||||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
|
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
|
||||||
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
|
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
|
||||||
import net.Indyuce.mmocore.api.load.DefaultMMOLoader;
|
import net.Indyuce.mmocore.api.load.DefaultMMOLoader;
|
||||||
import net.Indyuce.mmocore.api.load.MMOLoader;
|
import net.Indyuce.mmocore.api.load.MMOLoader;
|
||||||
|
@ -13,9 +13,9 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
import net.Indyuce.mmocore.loot.droptable.condition.Condition;
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
|
import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance;
|
||||||
import net.Indyuce.mmocore.api.droptable.dropitem.fishing.FishingDropItem;
|
import net.Indyuce.mmocore.loot.droptable.dropitem.fishing.FishingDropItem;
|
||||||
import net.Indyuce.mmocore.manager.MMOManager;
|
import net.Indyuce.mmocore.manager.MMOManager;
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user