mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-16 22:43:14 +01:00
SPIGOT-7919: Add API to access current player input
By: md_5 <git@md-5.net>
This commit is contained in:
parent
d6c970b00b
commit
cd2a2a27ff
2 changed files with 82 additions and 0 deletions
|
@ -0,0 +1,75 @@
|
|||
package org.bukkit.craftbukkit;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.bukkit.Input;
|
||||
|
||||
public class CraftInput implements Input {
|
||||
|
||||
private final net.minecraft.world.entity.player.Input handle;
|
||||
|
||||
public CraftInput(net.minecraft.world.entity.player.Input handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isForward() {
|
||||
return handle.forward();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBackward() {
|
||||
return handle.backward();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeft() {
|
||||
return handle.left();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRight() {
|
||||
return handle.right();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJump() {
|
||||
return handle.jump();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSneak() {
|
||||
return handle.shift();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSprint() {
|
||||
return handle.sprint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 89 * hash + Objects.hashCode(this.handle);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final CraftInput other = (CraftInput) obj;
|
||||
return Objects.equals(this.handle, other.handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CraftInput{" + handle + '}';
|
||||
}
|
||||
}
|
|
@ -118,6 +118,7 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Input;
|
||||
import org.bukkit.Instrument;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
@ -144,6 +145,7 @@ import org.bukkit.conversations.ConversationAbandonedEvent;
|
|||
import org.bukkit.conversations.ManuallyAbandonedConversationCanceller;
|
||||
import org.bukkit.craftbukkit.CraftEffect;
|
||||
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.CraftInput;
|
||||
import org.bukkit.craftbukkit.CraftOfflinePlayer;
|
||||
import org.bukkit.craftbukkit.CraftParticle;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
|
@ -1193,6 +1195,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|||
return getHandle().getEnderPearls().stream().map((e) -> (EnderPearl) e.getBukkitEntity()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Input getCurrentInput() {
|
||||
return new CraftInput(getHandle().getLastClientInput());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getBedLocation() {
|
||||
Preconditions.checkState(isSleeping(), "Not sleeping");
|
||||
|
|
Loading…
Reference in a new issue