mirror of
https://github.com/SunNetservers/Launchpad.git
synced 2025-03-31 08:46:29 +02: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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Register the modification request
|
// Register the modification request
|
||||||
ModificationRequest request = null;
|
ModificationRequest request = null;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ADD, REMOVE -> request = new ModificationRequest(action, null);
|
case ADD, REMOVE -> request = new ModificationRequest(action, null);
|
||||||
case VERTICAL_VELOCITY, HORIZONTAL_VELOCITY, FIXED_DIRECTION ->
|
case VERTICAL_VELOCITY, HORIZONTAL_VELOCITY, FIXED_DIRECTION -> request = new ModificationRequest(action,
|
||||||
request = new ModificationRequest(action, arguments[1]);
|
arguments[1].equalsIgnoreCase("null") ? null : arguments[1]);
|
||||||
case ABORT -> {
|
case ABORT -> {
|
||||||
// Retrieving modification requests also removes them
|
// Retrieving modification requests also removes them
|
||||||
ModificationRequestHandler.getRequests(player.getUniqueId());
|
ModificationRequestHandler.getRequests(player.getUniqueId());
|
||||||
|
@ -94,7 +94,7 @@ public class LaunchpadBlock {
|
|||||||
* @param horizontalVelocity <p>The horizontal velocity to set</p>
|
* @param horizontalVelocity <p>The horizontal velocity to set</p>
|
||||||
*/
|
*/
|
||||||
public void setHorizontalVelocity(double horizontalVelocity) {
|
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>
|
* @param verticalVelocity <p>The vertical velocity to set</p>
|
||||||
*/
|
*/
|
||||||
public void setVerticalVelocity(double verticalVelocity) {
|
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) {
|
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
|
// Make sure the fixed direction is in the correct plane by multiplying it by the normal vector to the
|
||||||
// North x West plane.
|
// North x West plane.
|
||||||
if (fixedDirection != null && (fixedDirection.getDirection().dot(BlockFace.WEST.getDirection().crossProduct(
|
if (fixedDirection != null && ((fixedDirection.getDirection().dot(BlockFace.WEST.getDirection().crossProduct(
|
||||||
BlockFace.NORTH.getDirection()))) != 0) {
|
BlockFace.NORTH.getDirection()))) != 0 || fixedDirection == BlockFace.SELF)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.fixedDirection = fixedDirection;
|
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();
|
block.getX() + "," + block.getY() + "," + block.getZ();
|
||||||
ConfigurationSection launchpadSection = launchpadsSection.createSection(locationString);
|
ConfigurationSection launchpadSection = launchpadsSection.createSection(locationString);
|
||||||
LaunchpadBlock launchpadBlock = launchpadBlocks.get(block);
|
LaunchpadBlock launchpadBlock = launchpadBlocks.get(block);
|
||||||
launchpadSection.set("verticalVelocity", launchpadBlock.getVerticalVelocity());
|
launchpadSection.set("verticalVelocity", launchpadBlock.getVerticalVelocityRaw());
|
||||||
launchpadSection.set("horizontalVelocity", launchpadBlock.getHorizontalVelocity());
|
launchpadSection.set("horizontalVelocity", launchpadBlock.getHorizontalVelocityRaw());
|
||||||
launchpadSection.set("fixedDirection", launchpadBlock.getFixedDirection() != null ?
|
launchpadSection.set("fixedDirection", launchpadBlock.getFixedDirection() != null ?
|
||||||
launchpadBlock.getFixedDirection().name() : null);
|
launchpadBlock.getFixedDirection().name() : null);
|
||||||
}
|
}
|
||||||
|
@ -79,11 +79,13 @@ public enum ModificationAction {
|
|||||||
* @return <p>True if the argument is valid</p>
|
* @return <p>True if the argument is valid</p>
|
||||||
*/
|
*/
|
||||||
public boolean isValidArgument(String argument) {
|
public boolean isValidArgument(String argument) {
|
||||||
|
if (argument.equalsIgnoreCase("null")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (this == ModificationAction.HORIZONTAL_VELOCITY || this == ModificationAction.VERTICAL_VELOCITY) {
|
if (this == ModificationAction.HORIZONTAL_VELOCITY || this == ModificationAction.VERTICAL_VELOCITY) {
|
||||||
try {
|
try {
|
||||||
double ignored = Double.parseDouble(argument);
|
return Double.parseDouble(argument) >= 0;
|
||||||
return true;
|
} catch (NumberFormatException exception) {
|
||||||
} catch (NullPointerException exception) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (this == ModificationAction.FIXED_DIRECTION) {
|
} else if (this == ModificationAction.FIXED_DIRECTION) {
|
||||||
|
@ -64,16 +64,22 @@ public class LaunchpadModifyListener implements Listener {
|
|||||||
case VERTICAL_VELOCITY -> {
|
case VERTICAL_VELOCITY -> {
|
||||||
if (request.value() != null) {
|
if (request.value() != null) {
|
||||||
existingLaunchpad.setVerticalVelocity(Double.parseDouble(request.value()));
|
existingLaunchpad.setVerticalVelocity(Double.parseDouble(request.value()));
|
||||||
|
} else {
|
||||||
|
existingLaunchpad.setVerticalVelocity(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case HORIZONTAL_VELOCITY -> {
|
case HORIZONTAL_VELOCITY -> {
|
||||||
if (request.value() != null) {
|
if (request.value() != null) {
|
||||||
existingLaunchpad.setHorizontalVelocity(Double.parseDouble(request.value()));
|
existingLaunchpad.setHorizontalVelocity(Double.parseDouble(request.value()));
|
||||||
|
} else {
|
||||||
|
existingLaunchpad.setHorizontalVelocity(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case FIXED_DIRECTION -> {
|
case FIXED_DIRECTION -> {
|
||||||
if (request.value() != null) {
|
if (request.value() != null) {
|
||||||
existingLaunchpad.setFixedDirection(BlockFace.valueOf(request.value().toUpperCase()));
|
existingLaunchpad.setFixedDirection(BlockFace.valueOf(request.value().toUpperCase()));
|
||||||
|
} else {
|
||||||
|
existingLaunchpad.setFixedDirection(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
launchpad:
|
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.
|
# +WOODEN_PRESSURE_PLATES for all wooden pressure plates.
|
||||||
materials:
|
materials:
|
||||||
- LIGHT_WEIGHTED_PRESSURE_PLATE # This is the gold pressure plate
|
- LIGHT_WEIGHTED_PRESSURE_PLATE # This is the gold pressure plate
|
||||||
|
Loading…
x
Reference in New Issue
Block a user