mirror of
https://github.com/SunNetservers/Launchpad.git
synced 2024-12-05 01:43:15 +01:00
Fix for #2
In addition to allowing null to clear a value, this change makes sure launchpads store their actual velocities instead of the fallback, allowing value changes to update for all current launchpads. A bug where a double parsing was checking for the wrong exception has been fixed.
This commit is contained in:
parent
11f969a3f8
commit
c6ecd8219b
@ -35,13 +35,12 @@ public class LaunchpadCommand implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Register the modification request
|
||||
ModificationRequest request = null;
|
||||
switch (action) {
|
||||
case ADD, REMOVE -> request = new ModificationRequest(action, null);
|
||||
case VERTICAL_VELOCITY, HORIZONTAL_VELOCITY, FIXED_DIRECTION ->
|
||||
request = new ModificationRequest(action, arguments[1]);
|
||||
case VERTICAL_VELOCITY, HORIZONTAL_VELOCITY, FIXED_DIRECTION -> request = new ModificationRequest(action,
|
||||
arguments[1].equalsIgnoreCase("null") ? null : arguments[1]);
|
||||
case ABORT -> {
|
||||
// Retrieving modification requests also removes them
|
||||
ModificationRequestHandler.getRequests(player.getUniqueId());
|
||||
|
@ -94,7 +94,7 @@ public class LaunchpadBlock {
|
||||
* @param horizontalVelocity <p>The horizontal velocity to set</p>
|
||||
*/
|
||||
public void setHorizontalVelocity(double horizontalVelocity) {
|
||||
this.horizontalVelocity = Math.max(0, horizontalVelocity);
|
||||
this.horizontalVelocity = horizontalVelocity;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,7 +103,7 @@ public class LaunchpadBlock {
|
||||
* @param verticalVelocity <p>The vertical velocity to set</p>
|
||||
*/
|
||||
public void setVerticalVelocity(double verticalVelocity) {
|
||||
this.verticalVelocity = Math.max(0, verticalVelocity);
|
||||
this.verticalVelocity = verticalVelocity;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,11 +114,29 @@ public class LaunchpadBlock {
|
||||
public void setFixedDirection(@Nullable BlockFace fixedDirection) {
|
||||
// Make sure the fixed direction is in the correct plane by multiplying it by the normal vector to the
|
||||
// North x West plane.
|
||||
if (fixedDirection != null && (fixedDirection.getDirection().dot(BlockFace.WEST.getDirection().crossProduct(
|
||||
BlockFace.NORTH.getDirection()))) != 0) {
|
||||
if (fixedDirection != null && ((fixedDirection.getDirection().dot(BlockFace.WEST.getDirection().crossProduct(
|
||||
BlockFace.NORTH.getDirection()))) != 0 || fixedDirection == BlockFace.SELF)) {
|
||||
return;
|
||||
}
|
||||
this.fixedDirection = fixedDirection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the actual horizontal velocity specified for this block, with no fallback
|
||||
*
|
||||
* @return <p>The raw horizontal velocity</p>
|
||||
*/
|
||||
public double getHorizontalVelocityRaw() {
|
||||
return this.horizontalVelocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the actual vertical velocity specified for this block, with no fallback
|
||||
*
|
||||
* @return <p>The raw vertical velocity</p>
|
||||
*/
|
||||
public double getVerticalVelocityRaw() {
|
||||
return this.verticalVelocity;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -96,8 +96,8 @@ public final class LaunchpadBlockHandler {
|
||||
block.getX() + "," + block.getY() + "," + block.getZ();
|
||||
ConfigurationSection launchpadSection = launchpadsSection.createSection(locationString);
|
||||
LaunchpadBlock launchpadBlock = launchpadBlocks.get(block);
|
||||
launchpadSection.set("verticalVelocity", launchpadBlock.getVerticalVelocity());
|
||||
launchpadSection.set("horizontalVelocity", launchpadBlock.getHorizontalVelocity());
|
||||
launchpadSection.set("verticalVelocity", launchpadBlock.getVerticalVelocityRaw());
|
||||
launchpadSection.set("horizontalVelocity", launchpadBlock.getHorizontalVelocityRaw());
|
||||
launchpadSection.set("fixedDirection", launchpadBlock.getFixedDirection() != null ?
|
||||
launchpadBlock.getFixedDirection().name() : null);
|
||||
}
|
||||
|
@ -79,11 +79,13 @@ public enum ModificationAction {
|
||||
* @return <p>True if the argument is valid</p>
|
||||
*/
|
||||
public boolean isValidArgument(String argument) {
|
||||
if (argument.equalsIgnoreCase("null")) {
|
||||
return true;
|
||||
}
|
||||
if (this == ModificationAction.HORIZONTAL_VELOCITY || this == ModificationAction.VERTICAL_VELOCITY) {
|
||||
try {
|
||||
double ignored = Double.parseDouble(argument);
|
||||
return true;
|
||||
} catch (NullPointerException exception) {
|
||||
return Double.parseDouble(argument) >= 0;
|
||||
} catch (NumberFormatException exception) {
|
||||
return false;
|
||||
}
|
||||
} else if (this == ModificationAction.FIXED_DIRECTION) {
|
||||
|
@ -64,16 +64,22 @@ public class LaunchpadModifyListener implements Listener {
|
||||
case VERTICAL_VELOCITY -> {
|
||||
if (request.value() != null) {
|
||||
existingLaunchpad.setVerticalVelocity(Double.parseDouble(request.value()));
|
||||
} else {
|
||||
existingLaunchpad.setVerticalVelocity(-1);
|
||||
}
|
||||
}
|
||||
case HORIZONTAL_VELOCITY -> {
|
||||
if (request.value() != null) {
|
||||
existingLaunchpad.setHorizontalVelocity(Double.parseDouble(request.value()));
|
||||
} else {
|
||||
existingLaunchpad.setHorizontalVelocity(-1);
|
||||
}
|
||||
}
|
||||
case FIXED_DIRECTION -> {
|
||||
if (request.value() != null) {
|
||||
existingLaunchpad.setFixedDirection(BlockFace.valueOf(request.value().toUpperCase()));
|
||||
} else {
|
||||
existingLaunchpad.setFixedDirection(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
launchpad:
|
||||
# A list of all materials used as a launch-pad. Use +PRESSURE_PLATES for all pressure plates, or
|
||||
# A list of all materials automatically enabled as a launch-pad. Use +PRESSURE_PLATES for all pressure plates, or
|
||||
# +WOODEN_PRESSURE_PLATES for all wooden pressure plates.
|
||||
materials:
|
||||
- LIGHT_WEIGHTED_PRESSURE_PLATE # This is the gold pressure plate
|
||||
|
Loading…
Reference in New Issue
Block a user