2023-04-13 20:13:29 +02:00
|
|
|
package net.knarcraft.minigames.config;
|
2023-04-11 13:25:45 +02:00
|
|
|
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2023-04-11 20:04:04 +02:00
|
|
|
/**
|
2023-04-13 13:24:43 +02:00
|
|
|
* The configuration keeping track of dropper settings
|
2023-04-11 20:04:04 +02:00
|
|
|
*/
|
2023-04-13 13:24:43 +02:00
|
|
|
public class DropperConfiguration extends MiniGameConfiguration {
|
2023-04-11 13:25:45 +02:00
|
|
|
|
2023-04-11 20:04:04 +02:00
|
|
|
private final static String rootNode = "dropper.";
|
2023-04-11 13:25:45 +02:00
|
|
|
|
|
|
|
private double verticalVelocity;
|
|
|
|
private float horizontalVelocity;
|
|
|
|
private int randomlyInvertedTimer;
|
|
|
|
private boolean mustDoGroupedInSequence;
|
|
|
|
private boolean ignoreRecordsUntilGroupBeatenOnce;
|
|
|
|
private boolean mustDoNormalModeFirst;
|
|
|
|
private boolean makePlayersInvisible;
|
|
|
|
private boolean disableHitCollision;
|
2023-04-11 20:04:04 +02:00
|
|
|
private boolean blockSneaking;
|
|
|
|
private boolean blockSprinting;
|
2023-04-11 13:25:45 +02:00
|
|
|
private Set<Material> blockWhitelist;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new dropper configuration
|
|
|
|
*
|
|
|
|
* @param configuration <p>The YAML configuration to use internally</p>
|
|
|
|
*/
|
|
|
|
public DropperConfiguration(FileConfiguration configuration) {
|
2023-04-13 13:24:43 +02:00
|
|
|
super(configuration);
|
2023-04-11 13:25:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the default vertical velocity
|
|
|
|
*
|
|
|
|
* @return <p>The default vertical velocity</p>
|
|
|
|
*/
|
|
|
|
public double getVerticalVelocity() {
|
|
|
|
return this.verticalVelocity;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the default horizontal velocity
|
|
|
|
*
|
|
|
|
* @return <p>The default horizontal velocity</p>
|
|
|
|
*/
|
|
|
|
public float getHorizontalVelocity() {
|
|
|
|
return this.horizontalVelocity;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the number of seconds before the randomly inverted game-mode toggles
|
|
|
|
*
|
|
|
|
* @return <p>Number of seconds before the inversion toggles</p>
|
|
|
|
*/
|
|
|
|
public int getRandomlyInvertedTimer() {
|
|
|
|
return this.randomlyInvertedTimer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets whether grouped arenas must be done in the set sequence
|
|
|
|
*
|
|
|
|
* @return <p>Whether grouped arenas must be done in sequence</p>
|
|
|
|
*/
|
|
|
|
public boolean mustDoGroupedInSequence() {
|
|
|
|
return this.mustDoGroupedInSequence;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets whether the normal/default mode must be beaten before playing another game-mode
|
|
|
|
*
|
|
|
|
* @return <p>Whether the normal game-mode must be beaten first</p>
|
|
|
|
*/
|
|
|
|
public boolean mustDoNormalModeFirst() {
|
|
|
|
return this.mustDoNormalModeFirst;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the types of block which should not trigger a loss
|
|
|
|
*
|
|
|
|
* @return <p>The materials that should not trigger a loss</p>
|
|
|
|
*/
|
|
|
|
public Set<Material> getBlockWhitelist() {
|
|
|
|
return new HashSet<>(this.blockWhitelist);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets whether records should be discarded, unless the player has already beaten all arenas in the group
|
|
|
|
*
|
|
|
|
* @return <p>Whether to ignore records on the first play-through</p>
|
|
|
|
*/
|
|
|
|
public boolean ignoreRecordsUntilGroupBeatenOnce() {
|
|
|
|
return this.ignoreRecordsUntilGroupBeatenOnce;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets whether players should be made invisible while in an arena
|
|
|
|
*
|
|
|
|
* @return <p>Whether players should be made invisible</p>
|
|
|
|
*/
|
|
|
|
public boolean makePlayersInvisible() {
|
|
|
|
return this.makePlayersInvisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets whether entity hit-collision of players in an arena should be disabled
|
|
|
|
*
|
|
|
|
* @return <p>Whether to disable hit collision</p>
|
|
|
|
*/
|
|
|
|
public boolean disableHitCollision() {
|
|
|
|
return this.disableHitCollision;
|
|
|
|
}
|
|
|
|
|
2023-04-11 20:04:04 +02:00
|
|
|
/**
|
|
|
|
* Gets whether players trying to sneak while in a dropper arena to increase their downwards speed should be blocked
|
|
|
|
*
|
|
|
|
* @return <p>Whether to block sneak to speed up</p>
|
|
|
|
*/
|
|
|
|
public boolean blockSneaking() {
|
|
|
|
return blockSneaking;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets whether players trying to sprint to improve their horizontal speed while in a dropper arena should be blocked
|
|
|
|
*
|
|
|
|
* @return <p>Whether to block sprint to speed up</p>
|
|
|
|
*/
|
|
|
|
public boolean blockSprinting() {
|
|
|
|
return this.blockSprinting;
|
|
|
|
}
|
|
|
|
|
2023-04-13 13:24:43 +02:00
|
|
|
@Override
|
2023-04-13 20:13:29 +02:00
|
|
|
protected void load() {
|
2023-04-11 20:04:04 +02:00
|
|
|
this.verticalVelocity = configuration.getDouble(rootNode + "verticalVelocity", 1.0);
|
|
|
|
this.horizontalVelocity = (float) configuration.getDouble(rootNode + "horizontalVelocity", 1.0);
|
|
|
|
this.randomlyInvertedTimer = configuration.getInt(rootNode + "randomlyInvertedTimer", 7);
|
|
|
|
this.mustDoGroupedInSequence = configuration.getBoolean(rootNode + "mustDoGroupedInSequence", true);
|
|
|
|
this.ignoreRecordsUntilGroupBeatenOnce = configuration.getBoolean(rootNode + "ignoreRecordsUntilGroupBeatenOnce", false);
|
|
|
|
this.mustDoNormalModeFirst = configuration.getBoolean(rootNode + "mustDoNormalModeFirst", true);
|
|
|
|
this.makePlayersInvisible = configuration.getBoolean(rootNode + "makePlayersInvisible", false);
|
|
|
|
this.disableHitCollision = configuration.getBoolean(rootNode + "disableHitCollision", true);
|
|
|
|
this.blockSprinting = configuration.getBoolean(rootNode + "blockSprinting", true);
|
|
|
|
this.blockSneaking = configuration.getBoolean(rootNode + "blockSneaking", true);
|
2023-04-13 20:13:29 +02:00
|
|
|
this.blockWhitelist = loadMaterialList(rootNode + "blockWhitelist");
|
2023-04-11 13:55:46 +02:00
|
|
|
sanitizeValues();
|
2023-04-11 13:25:45 +02:00
|
|
|
}
|
|
|
|
|
2023-04-11 13:55:46 +02:00
|
|
|
/**
|
|
|
|
* Sanitizes configuration values to ensure they are within expected bounds
|
|
|
|
*/
|
|
|
|
private void sanitizeValues() {
|
|
|
|
if (this.horizontalVelocity > 1 || this.horizontalVelocity <= 0) {
|
|
|
|
this.horizontalVelocity = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.verticalVelocity <= 0 || this.verticalVelocity > 75) {
|
|
|
|
this.verticalVelocity = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.randomlyInvertedTimer <= 0 || this.randomlyInvertedTimer > 3600) {
|
|
|
|
this.randomlyInvertedTimer = 7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-11 20:04:04 +02:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
StringBuilder builder = new StringBuilder(
|
|
|
|
"Current configuration:" +
|
|
|
|
"\n" + "Vertical velocity: " + verticalVelocity +
|
|
|
|
"\n" + "Horizontal velocity: " + horizontalVelocity +
|
|
|
|
"\n" + "Randomly inverted timer: " + randomlyInvertedTimer +
|
|
|
|
"\n" + "Must do groups in sequence: " + mustDoGroupedInSequence +
|
|
|
|
"\n" + "Ignore records until group beaten once: " + ignoreRecordsUntilGroupBeatenOnce +
|
|
|
|
"\n" + "Must do normal mode first: " + mustDoNormalModeFirst +
|
|
|
|
"\n" + "Make players invisible: " + makePlayersInvisible +
|
|
|
|
"\n" + "Disable hit collision: " + disableHitCollision +
|
|
|
|
"\n" + "Block whitelist: ");
|
|
|
|
for (Material material : blockWhitelist) {
|
|
|
|
builder.append("\n - ").append(material.name());
|
|
|
|
}
|
|
|
|
return builder.toString();
|
|
|
|
}
|
|
|
|
|
2023-04-11 13:25:45 +02:00
|
|
|
}
|