mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-12-28 05:37:44 +01:00
!API stuff for loot chests
This commit is contained in:
parent
9105a8744a
commit
6ae069f651
48
src/main/java/net/Indyuce/mmocore/api/loot/ChestTier.java
Normal file
48
src/main/java/net/Indyuce/mmocore/api/loot/ChestTier.java
Normal file
@ -0,0 +1,48 @@
|
||||
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 net.Indyuce.mmocore.api.util.math.particle.ChestParticleEffect;
|
||||
|
||||
public class ChestTier {
|
||||
private final TierEffect effect;
|
||||
private final int weight;
|
||||
|
||||
public ChestTier(ConfigurationSection config) {
|
||||
effect = config.isConfigurationSection("effect") ? new TierEffect(config.getConfigurationSection("effect"))
|
||||
: null;
|
||||
weight = config.getInt("weight", 1);
|
||||
}
|
||||
|
||||
public int getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public boolean hasEffect() {
|
||||
return effect != null;
|
||||
}
|
||||
|
||||
public TierEffect getEffect() {
|
||||
return effect;
|
||||
}
|
||||
|
||||
public class TierEffect {
|
||||
private final ChestParticleEffect type;
|
||||
private final Particle particle;
|
||||
|
||||
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(" ", "_"));
|
||||
}
|
||||
|
||||
public void play(Location loc) {
|
||||
type.play(loc, particle);
|
||||
}
|
||||
}
|
||||
}
|
45
src/main/java/net/Indyuce/mmocore/api/loot/LootChest.java
Normal file
45
src/main/java/net/Indyuce/mmocore/api/loot/LootChest.java
Normal file
@ -0,0 +1,45 @@
|
||||
package net.Indyuce.mmocore.api.loot;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
public class LootChest {
|
||||
private final LootChestRegion region;
|
||||
|
||||
/*
|
||||
* saves data of block replaced
|
||||
*/
|
||||
private final ReplacedBlock block;
|
||||
|
||||
public LootChest(LootChestRegion region, Block block) {
|
||||
this.region = region;
|
||||
this.block = new ReplacedBlock(block);
|
||||
}
|
||||
|
||||
public ReplacedBlock getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public LootChestRegion getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public 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();
|
||||
loc = block.getLocation();
|
||||
}
|
||||
|
||||
public void restore() {
|
||||
loc.getBlock().setType(material);
|
||||
loc.getBlock().setBlockData(data);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package net.Indyuce.mmocore.api.loot;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
|
||||
public class LootChestRegion {
|
||||
private final String id;
|
||||
|
||||
private final long chestSpawnPeriod;
|
||||
private final RegionBounds bounds;
|
||||
private final Set<ChestTier> tiers = new HashSet<>();
|
||||
|
||||
/*
|
||||
* last time
|
||||
*/
|
||||
|
||||
public LootChestRegion(ConfigurationSection config) {
|
||||
Validate.notNull(config, "Could not load config");
|
||||
id = config.getName();
|
||||
|
||||
bounds = new RegionBounds(config.getConfigurationSection("bounds"));
|
||||
chestSpawnPeriod = config.getInt("spawn-period");
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Set<ChestTier> getTiers() {
|
||||
return tiers;
|
||||
}
|
||||
|
||||
public RegionBounds getBounds() {
|
||||
return bounds;
|
||||
}
|
||||
|
||||
public long getChestSpawnPeriod() {
|
||||
return chestSpawnPeriod;
|
||||
}
|
||||
}
|
53
src/main/java/net/Indyuce/mmocore/api/loot/RegionBounds.java
Normal file
53
src/main/java/net/Indyuce/mmocore/api/loot/RegionBounds.java
Normal file
@ -0,0 +1,53 @@
|
||||
package net.Indyuce.mmocore.api.loot;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
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;
|
||||
|
||||
public class RegionBounds {
|
||||
private final World world;
|
||||
private final int x1, z1, x2, z2;
|
||||
|
||||
private static final Random random = new Random();
|
||||
|
||||
public RegionBounds(ConfigurationSection config) {
|
||||
Validate.notNull(config, "Could not load config");
|
||||
Validate.notNull(world = Bukkit.getWorld(config.getString("world")),
|
||||
"Could not find world " + config.getString("world"));
|
||||
x1 = config.getInt("x1");
|
||||
z1 = config.getInt("z1");
|
||||
|
||||
x2 = config.getInt("x2");
|
||||
z2 = 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 = loc1.getBlockX();
|
||||
z1 = loc1.getBlockZ();
|
||||
|
||||
x2 = loc2.getBlockX();
|
||||
z2 = loc2.getBlockZ();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public Location findChestLocation() {
|
||||
|
||||
Optional<Player> player = world.getPlayers().stream().filter(check -> isInRegion(check)).findAny();
|
||||
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user