mirror of
https://github.com/SparklyPower/SparklyPaper.git
synced 2025-12-29 11:59:06 +00:00
Update to Paper 1.21.4 (post hard fork™️ edition)
This commit is contained in:
2
sparklypaper-api/src/main/java/ForkFile.java
Normal file
2
sparklypaper-api/src/main/java/ForkFile.java
Normal file
@@ -0,0 +1,2 @@
|
||||
public class ForkFile {
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package net.sparklypower.sparklypaper.event.entity;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.entity.EntityEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Called when a entity releases a bow, before the projectile is spawned
|
||||
* <p>
|
||||
* Compared to EntityShootBowEvent, this event is called before the projectile is spawned, before the force check is done, and before the bow release sound is played.
|
||||
* <p>
|
||||
* Currently this event is only called for players! To be more specific, it is only called for HumanEntity!!
|
||||
*/
|
||||
public class PreEntityShootBowEvent extends EntityEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final ItemStack bow;
|
||||
private final EquipmentSlot hand;
|
||||
private final float force;
|
||||
private boolean cancelled;
|
||||
|
||||
public PreEntityShootBowEvent(@NotNull final HumanEntity shooter, @Nullable final ItemStack bow, @NotNull final EquipmentSlot hand, final float force) {
|
||||
super(shooter);
|
||||
this.bow = bow;
|
||||
this.hand = hand;
|
||||
this.force = force;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bow ItemStack used to fire the arrow.
|
||||
*
|
||||
* @return the bow involved in this event
|
||||
*/
|
||||
@Nullable
|
||||
public ItemStack getBow() {
|
||||
return bow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hand from which the bow was shot.
|
||||
*
|
||||
* @return the hand
|
||||
*/
|
||||
@NotNull
|
||||
public EquipmentSlot getHand() {
|
||||
return hand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the force the arrow was launched with
|
||||
*
|
||||
* @return bow shooting force, up to 1.0
|
||||
*/
|
||||
public float getForce() {
|
||||
return force;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package net.sparklypower.sparklypaper.event.inventory;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Called when the recipe of an Item is completed inside a crafting matrix.
|
||||
*
|
||||
* This is an alternate version of [org.bukkit.event.inventory.CraftItemEvent], where this one is called for player crafting items and crafters.
|
||||
*/
|
||||
public class CraftItemRecipeEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Recipe recipe;
|
||||
private final ItemStack @Nullable [] matrix;
|
||||
private ItemStack result;
|
||||
private boolean isCancelled = false;
|
||||
|
||||
public CraftItemRecipeEvent(@NotNull ItemStack @Nullable [] matrix, @NotNull Recipe recipe, @Nullable ItemStack result) {
|
||||
this.matrix = matrix;
|
||||
this.recipe = recipe;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public void setResult(@Nullable ItemStack result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A copy of the current recipe on the crafting matrix.
|
||||
*/
|
||||
@NotNull
|
||||
public Recipe getRecipe() {
|
||||
return recipe;
|
||||
}
|
||||
|
||||
public @Nullable ItemStack[] getCraftingMatrix() {
|
||||
return matrix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return isCancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.isCancelled = cancel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
package net.sparklypower.sparklypaper.event.player;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Raised when a player moves a controllable vehicle. Controllable vehicles are vehicles that the client can control, such as boats, horses, striders, pigs, etc.
|
||||
* <p>
|
||||
* Minecarts are NOT affected by this event!
|
||||
*/
|
||||
public class PlayerMoveControllableVehicleEvent extends PlayerEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancel = false;
|
||||
private final Vehicle vehicle;
|
||||
private Location from;
|
||||
private Location to;
|
||||
|
||||
public PlayerMoveControllableVehicleEvent(@NotNull final Player player, @NotNull final Vehicle vehicle, @NotNull final Location from, @NotNull final Location to) {
|
||||
super(player);
|
||||
|
||||
this.vehicle = vehicle;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the previous position.
|
||||
*
|
||||
* @return Old position.
|
||||
*/
|
||||
@NotNull
|
||||
public Location getFrom() {
|
||||
return from.clone(); // Paper - clone to avoid changes
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location to mark as where the player moved from
|
||||
*
|
||||
* @param from New location to mark as the players previous location
|
||||
*/
|
||||
public void setFrom(@NotNull Location from) {
|
||||
validateLocation(from, this.from);
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next position.
|
||||
*
|
||||
* @return New position.
|
||||
*/
|
||||
@NotNull
|
||||
public Location getTo() {
|
||||
return to.clone(); // Paper - clone to avoid changes
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location that this player will move to
|
||||
*
|
||||
* @param to New Location this player will move to
|
||||
*/
|
||||
public void setTo(@NotNull Location to) {
|
||||
validateLocation(to, this.to);
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the vehicle.
|
||||
*
|
||||
* @return the vehicle
|
||||
*/
|
||||
@NotNull
|
||||
public final Entity getVehicle() {
|
||||
return vehicle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cancellation state of this event. A cancelled event will not
|
||||
* be executed in the server, but will still pass to other plugins
|
||||
* <p>
|
||||
* If a move or teleport event is cancelled, the vehicle and player will be moved or
|
||||
* teleported back to the Location as defined by getFrom(). This will not
|
||||
* fire an event
|
||||
*
|
||||
* @return true if this event is cancelled
|
||||
*/
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event. A cancelled event will not
|
||||
* be executed in the server, but will still pass to other plugins
|
||||
* <p>
|
||||
* If a move or teleport event is cancelled, the vehicle and player will be moved or
|
||||
* teleported back to the Location as defined by getFrom(). This will not
|
||||
* fire an event
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
private void validateLocation(@NotNull Location loc, @NotNull Location originalLoc) {
|
||||
Preconditions.checkArgument(loc != null, "Cannot use null location!");
|
||||
Preconditions.checkArgument(loc.getWorld() != null, "Cannot use null location with null world!");
|
||||
Preconditions.checkArgument(loc.getWorld() != originalLoc, "New location should be in the original world!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package net.sparklypower.sparklypaper.event.player;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Called after the server attempts to move the player, but before the PlayerMoveEvent is called.
|
||||
* <p>
|
||||
* In contrast to PlayerMoveEvent, this event happens on every movement instead of being throttled like PlayerMoveEvent,
|
||||
* and this event exposes the player's onGround/horizontalCollision status, allowing plugins to manipulate it.
|
||||
*/
|
||||
public class PlayerPreMoveEvent extends PlayerEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Location from;
|
||||
private final Location to;
|
||||
private boolean onGround;
|
||||
private boolean horizontalCollision;
|
||||
private boolean resetFallDistance;
|
||||
|
||||
public PlayerPreMoveEvent(@NotNull final Player player, @NotNull final Location from, @Nullable final Location to, boolean onGround, boolean horizontalCollision, boolean resetFallDistance) {
|
||||
super(player);
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.onGround = onGround;
|
||||
this.horizontalCollision = horizontalCollision;
|
||||
this.resetFallDistance = resetFallDistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location this player moved from
|
||||
*
|
||||
* @return Location the player moved from
|
||||
*/
|
||||
@NotNull
|
||||
public Location getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location this player moved to
|
||||
*
|
||||
* @return Location the player moved to
|
||||
*/
|
||||
@NotNull // Paper
|
||||
public Location getTo() {
|
||||
return to;
|
||||
}
|
||||
|
||||
// Paper start - PlayerMoveEvent improvements
|
||||
/**
|
||||
* Check if the player has changed position (even within the same block) in the event
|
||||
*
|
||||
* @return whether the player has changed position or not
|
||||
*/
|
||||
public boolean hasChangedPosition() {
|
||||
return hasExplicitlyChangedPosition() || !from.getWorld().equals(to.getWorld());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has changed position (even within the same block) in the event, disregarding a possible world change
|
||||
*
|
||||
* @return whether the player has changed position or not
|
||||
*/
|
||||
public boolean hasExplicitlyChangedPosition() {
|
||||
return from.getX() != to.getX() || from.getY() != to.getY() || from.getZ() != to.getZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has moved to a new block in the event
|
||||
*
|
||||
* @return whether the player has moved to a new block or not
|
||||
*/
|
||||
public boolean hasChangedBlock() {
|
||||
return hasExplicitlyChangedBlock() || !from.getWorld().equals(to.getWorld());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has moved to a new block in the event, disregarding a possible world change
|
||||
*
|
||||
* @return whether the player has moved to a new block or not
|
||||
*/
|
||||
public boolean hasExplicitlyChangedBlock() {
|
||||
return from.getBlockX() != to.getBlockX() || from.getBlockY() != to.getBlockY() || from.getBlockZ() != to.getBlockZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has changed orientation in the event
|
||||
*
|
||||
* @return whether the player has changed orientation or not
|
||||
*/
|
||||
public boolean hasChangedOrientation() {
|
||||
return from.getPitch() != to.getPitch() || from.getYaw() != to.getYaw();
|
||||
}
|
||||
// Paper end
|
||||
|
||||
/**
|
||||
* Gets if the client said that they are on ground, keep in mind that this value is controlled by the client, so it can
|
||||
* be spoofed by malicious clients or be out of sync.
|
||||
*
|
||||
* @return if the client said that the is on ground
|
||||
*/
|
||||
public boolean isOnGround() {
|
||||
return onGround;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the player should be on ground.
|
||||
*
|
||||
* @param onGround true if the player should be on ground
|
||||
*/
|
||||
public void setOnGround(boolean onGround) {
|
||||
this.onGround = onGround;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the client said that they are horizontally colliding, keep in mind that this value is controlled by the client, so it can
|
||||
* be spoofed by malicious clients or be out of sync.
|
||||
*
|
||||
* @return if the player is horizontally colliding on a block
|
||||
*/
|
||||
public boolean isHorizontalCollision() {
|
||||
return horizontalCollision;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the player should be horizontally colliding on a block.
|
||||
*
|
||||
* @param horizontalCollision true if the player should be colliding horizontally be on ground
|
||||
*/
|
||||
public void setHorizontalCollision(boolean horizontalCollision) {
|
||||
this.horizontalCollision = horizontalCollision;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the player's fall distance should be reset. By default, the fall distance is reset every time the player moves upwards on the y axis.
|
||||
*
|
||||
* @return if the fall distance should be reset
|
||||
*/
|
||||
public boolean isResetFallDistance() {
|
||||
return resetFallDistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the player's fall distance should be reset.
|
||||
*
|
||||
* @param resetFallDistance true if the player fall distance should be reset
|
||||
*/
|
||||
public void setResetFallDistance(boolean resetFallDistance) {
|
||||
this.resetFallDistance = resetFallDistance;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user