-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to disable nested parkour commands
Added ability to affect vehicles with ParkourKit (WIP) Added ability to return items achieved while on Course (WIP) Fixed decimal rewarddelay not working
- Loading branch information
Showing
12 changed files
with
236 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
src/main/java/io/github/a5h73y/parkour/listener/move/VehicleMoveListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package io.github.a5h73y.parkour.listener.move; | ||
|
||
import static io.github.a5h73y.parkour.listener.move.ParkourBlockListener.BLOCK_FACES; | ||
|
||
import io.github.a5h73y.parkour.Parkour; | ||
import io.github.a5h73y.parkour.other.AbstractPluginReceiver; | ||
import io.github.a5h73y.parkour.type.kit.ParkourKit; | ||
import io.github.a5h73y.parkour.type.kit.ParkourKitAction; | ||
import io.github.a5h73y.parkour.type.player.session.ParkourSession; | ||
import io.github.a5h73y.parkour.utility.MaterialUtils; | ||
import io.github.a5h73y.parkour.utility.PlayerUtils; | ||
import org.bukkit.Material; | ||
import org.bukkit.block.BlockFace; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.entity.Vehicle; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.vehicle.VehicleMoveEvent; | ||
import org.bukkit.potion.PotionEffectType; | ||
import org.bukkit.util.Vector; | ||
|
||
public class VehicleMoveListener extends AbstractPluginReceiver implements Listener { | ||
|
||
public VehicleMoveListener(final Parkour parkour) { | ||
super(parkour); | ||
} | ||
|
||
/** | ||
* Handle Player Move. | ||
* While the Player is moving on a Course, handle any actions that should be performed. | ||
* | ||
* @param event VehicleMoveEvent | ||
*/ | ||
@EventHandler | ||
public void onVehicleMove(VehicleMoveEvent event) { | ||
if (!(event.getVehicle().getPassenger() instanceof Player)) { | ||
return; | ||
} | ||
|
||
Player player = (Player) event.getVehicle().getPassenger(); | ||
|
||
if (!parkour.getParkourSessionManager().isPlaying(player)) { | ||
return; | ||
} | ||
|
||
ParkourSession session = parkour.getParkourSessionManager().getParkourSession(player); | ||
ParkourKit parkourKit = session.getCourse().getParkourKit(); | ||
|
||
if (parkourKit == null) { | ||
return; | ||
} | ||
|
||
if (parkour.getParkourConfig().isAttemptLessChecks() | ||
&& MaterialUtils.sameBlockLocations(event.getFrom(), event.getTo())) { | ||
return; | ||
} | ||
|
||
Material belowMaterial = event.getVehicle().getLocation().getBlock().getRelative(BlockFace.DOWN).getType(); | ||
ParkourKitAction kitAction = parkourKit.getAction(belowMaterial); | ||
|
||
if (kitAction != null) { | ||
performBelowAction(player, event.getVehicle(), kitAction); | ||
} else { | ||
performWallAction(player, event.getVehicle(), parkourKit); | ||
} | ||
} | ||
|
||
private void performBelowAction(Player player, Vehicle vehicle, ParkourKitAction kitAction) { | ||
Vector velocity = vehicle.getVelocity(); | ||
switch (kitAction.getActionType()) { | ||
case FINISH: | ||
parkour.getPlayerManager().finishCourse(player); | ||
break; | ||
|
||
case DEATH: | ||
parkour.getPlayerManager().playerDie(player); | ||
break; | ||
|
||
case LAUNCH: | ||
// player.sendMessage(String.valueOf(velocity.getY())); | ||
// TODO why is this so temperamental | ||
velocity.setY(velocity.getY() + 5); | ||
break; | ||
|
||
case BOUNCE: | ||
if (!player.hasPotionEffect(PotionEffectType.JUMP)) { | ||
PlayerUtils.applyPotionEffect(PotionEffectType.JUMP, kitAction.getDuration(), | ||
(int) kitAction.getStrength(), player); | ||
} | ||
break; | ||
|
||
case SPEED: | ||
if (!player.hasPotionEffect(PotionEffectType.SPEED)) { | ||
PlayerUtils.applyPotionEffect(PotionEffectType.SPEED, kitAction.getDuration(), | ||
(int) kitAction.getStrength(), player); | ||
} | ||
break; | ||
|
||
case POTION: | ||
PotionEffectType effect = PotionEffectType.getByName(kitAction.getEffect()); | ||
if (effect != null) { | ||
PlayerUtils.applyPotionEffect(effect, kitAction.getDuration(), | ||
(int) kitAction.getStrength(), player); | ||
} | ||
break; | ||
|
||
case NORUN: | ||
player.setSprinting(false); | ||
break; | ||
|
||
case NOPOTION: | ||
PlayerUtils.removeAllPotionEffects(player); | ||
player.setFireTicks(0); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
vehicle.setVelocity(velocity); | ||
} | ||
|
||
private void performWallAction(Player player, Vehicle vehicle, ParkourKit parkourKit) { | ||
for (BlockFace blockFace : BLOCK_FACES) { | ||
Material material = player.getLocation().getBlock().getRelative(blockFace).getType(); | ||
ParkourKitAction kitAction = parkourKit.getAction(material); | ||
|
||
if (kitAction != null) { | ||
switch (kitAction.getActionType()) { | ||
case CLIMB: | ||
vehicle.setVelocity(new Vector(0, kitAction.getStrength(), 0)); | ||
break; | ||
|
||
case REPULSE: | ||
double strength = kitAction.getStrength(); | ||
double x = blockFace == BlockFace.NORTH || blockFace == BlockFace.SOUTH ? 0 | ||
: blockFace == BlockFace.EAST ? -strength : strength; | ||
double z = blockFace == BlockFace.EAST || blockFace == BlockFace.WEST ? 0 | ||
: blockFace == BlockFace.NORTH ? strength : -strength; | ||
|
||
vehicle.setVelocity(new Vector(x, 0.3, z)); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.