This commit is contained in:
Indyuce 2021-08-25 13:34:04 +02:00
parent a574a67a3b
commit 408703b4f4
2 changed files with 41 additions and 42 deletions

View File

@ -5,46 +5,46 @@ 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;
/**
* 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;
/**
* 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);
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");
/**
* 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);
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");
}
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;
}
/**
* 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;
}
}

View File

@ -56,8 +56,11 @@ public class LootChest {
}
/**
* @param player If a player just the chest. It's set to false
* when a loot chest expires or when MMOCore disables.
* @param player If a player triggered the unregistration of that chest by
* opening and then closing it for the first time. It's set
* to false when a loot chest expires or when MMOCore disables.
* <p>
* When no player is closing the chest, its content should be lost
*/
public void unregister(boolean player) {
@ -91,10 +94,6 @@ public class LootChest {
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();