mirror of https://github.com/LOOHP/Limbo.git
Added PlayerMoveEvent and PlayerTeleportEvent
This commit is contained in:
parent
5c69de1637
commit
5ec6eaf6e2
2
pom.xml
2
pom.xml
|
|
@ -4,7 +4,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.loohp</groupId>
|
||||
<artifactId>Limbo</artifactId>
|
||||
<version>0.3.4-ALPHA</version>
|
||||
<version>0.3.5-ALPHA</version>
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<resources>
|
||||
|
|
|
|||
|
|
@ -9,17 +9,12 @@ public class PlayerChatEvent extends PlayerEvent implements Cancellable {
|
|||
private boolean cancelled;
|
||||
|
||||
public PlayerChatEvent(Player player, String prefix, String message, boolean cancelled) {
|
||||
this.player = player;
|
||||
super(player);
|
||||
this.prefix = prefix;
|
||||
this.message = message;
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,16 @@ package com.loohp.limbo.Events;
|
|||
|
||||
import com.loohp.limbo.Player.Player;
|
||||
|
||||
public abstract class PlayerEvent extends Event {
|
||||
public class PlayerEvent extends Event {
|
||||
|
||||
protected Player player;
|
||||
private Player player;
|
||||
|
||||
public abstract Player getPlayer();
|
||||
public PlayerEvent(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,7 @@ import com.loohp.limbo.Player.Player;
|
|||
public class PlayerJoinEvent extends PlayerEvent {
|
||||
|
||||
public PlayerJoinEvent(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
super(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
package com.loohp.limbo.Events;
|
||||
|
||||
import com.loohp.limbo.Location.Location;
|
||||
import com.loohp.limbo.Player.Player;
|
||||
|
||||
/**
|
||||
* Holds information for player movement events
|
||||
*/
|
||||
public class PlayerMoveEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private boolean cancel = false;
|
||||
private Location from;
|
||||
private Location to;
|
||||
|
||||
public PlayerMoveEvent(Player player, Location from, Location to) {
|
||||
super(player);
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location this player moved from
|
||||
*
|
||||
* @return Location the player moved from
|
||||
*/
|
||||
public Location getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(Location from) {
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location this player moved to
|
||||
*
|
||||
* @return Location the player moved to
|
||||
*/
|
||||
public Location getTo() {
|
||||
return to;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location that this player will move to
|
||||
*
|
||||
* @param to New Location this player will move to
|
||||
*/
|
||||
public void setTo(Location to) {
|
||||
this.to = to;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,12 +5,7 @@ import com.loohp.limbo.Player.Player;
|
|||
public class PlayerQuitEvent extends PlayerEvent {
|
||||
|
||||
public PlayerQuitEvent(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
super(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package com.loohp.limbo.Events;
|
||||
|
||||
import com.loohp.limbo.Location.Location;
|
||||
import com.loohp.limbo.Player.Player;
|
||||
|
||||
public class PlayerTeleportEvent extends PlayerMoveEvent {
|
||||
|
||||
public PlayerTeleportEvent(Player player, Location from, Location to) {
|
||||
super(player, from, to);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import java.util.UUID;
|
|||
import com.loohp.limbo.Limbo;
|
||||
import com.loohp.limbo.Commands.CommandSender;
|
||||
import com.loohp.limbo.Events.PlayerChatEvent;
|
||||
import com.loohp.limbo.Events.PlayerTeleportEvent;
|
||||
import com.loohp.limbo.Location.Location;
|
||||
import com.loohp.limbo.Server.ClientConnection;
|
||||
import com.loohp.limbo.Server.Packets.PacketPlayOutChat;
|
||||
|
|
@ -92,15 +93,19 @@ public class Player implements CommandSender {
|
|||
}
|
||||
|
||||
public void teleport(Location location) {
|
||||
try {
|
||||
if (!this.location.getWorld().equals(location.getWorld())) {
|
||||
PacketPlayOutRespawn respawn = new PacketPlayOutRespawn(location.getWorld(), Limbo.getInstance().getDimensionRegistry().getCodec(), 0, gamemode, false, false, true);
|
||||
clientConnection.sendPacket(respawn);
|
||||
PlayerTeleportEvent event = Limbo.getInstance().getEventsManager().callEvent(new PlayerTeleportEvent(this, getLocation(), location));
|
||||
if (!event.isCancelled()) {
|
||||
location = event.getTo();
|
||||
try {
|
||||
if (!this.location.getWorld().equals(location.getWorld())) {
|
||||
PacketPlayOutRespawn respawn = new PacketPlayOutRespawn(location.getWorld(), Limbo.getInstance().getDimensionRegistry().getCodec(), 0, gamemode, false, false, true);
|
||||
clientConnection.sendPacket(respawn);
|
||||
}
|
||||
PacketPlayOutPositionAndLook positionLook = new PacketPlayOutPositionAndLook(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch(), 1);
|
||||
clientConnection.sendPacket(positionLook);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
PacketPlayOutPositionAndLook positionLook = new PacketPlayOutPositionAndLook(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch(), 1);
|
||||
clientConnection.sendPacket(positionLook);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import com.loohp.limbo.DeclareCommands;
|
|||
import com.loohp.limbo.Limbo;
|
||||
import com.loohp.limbo.Events.PlayerJoinEvent;
|
||||
import com.loohp.limbo.Events.PlayerLoginEvent;
|
||||
import com.loohp.limbo.Events.PlayerMoveEvent;
|
||||
import com.loohp.limbo.Events.PlayerQuitEvent;
|
||||
import com.loohp.limbo.Events.StatusPingEvent;
|
||||
import com.loohp.limbo.File.ServerProperties;
|
||||
|
|
@ -356,22 +357,49 @@ public class ClientConnection extends Thread {
|
|||
input.skipBytes(size - DataTypeIO.getVarIntLength(packetId));
|
||||
} else if (packetType.equals(PacketPlayInPositionAndLook.class)) {
|
||||
PacketPlayInPositionAndLook pos = new PacketPlayInPositionAndLook(input);
|
||||
player.setLocation(new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ(), pos.getYaw(), pos.getPitch()));
|
||||
Location from = player.getLocation();
|
||||
Location to = new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ(), pos.getYaw(), pos.getPitch());
|
||||
|
||||
PacketPlayOutUpdateViewPosition response = new PacketPlayOutUpdateViewPosition((int) player.getLocation().getX() >> 4, (int) player.getLocation().getZ() >> 4);
|
||||
sendPacket(response);
|
||||
PlayerMoveEvent event = Limbo.getInstance().getEventsManager().callEvent(new PlayerMoveEvent(player, from, to));
|
||||
if (event.isCancelled()) {
|
||||
Location returnTo = event.getFrom();
|
||||
PacketPlayOutPositionAndLook cancel = new PacketPlayOutPositionAndLook(returnTo.getX(), returnTo.getY(), returnTo.getZ(), returnTo.getYaw(), returnTo.getPitch(), 1);
|
||||
sendPacket(cancel);
|
||||
} else {
|
||||
player.setLocation(event.getTo());
|
||||
PacketPlayOutUpdateViewPosition response = new PacketPlayOutUpdateViewPosition((int) player.getLocation().getX() >> 4, (int) player.getLocation().getZ() >> 4);
|
||||
sendPacket(response);
|
||||
}
|
||||
} else if (packetType.equals(PacketPlayInPosition.class)) {
|
||||
PacketPlayInPosition pos = new PacketPlayInPosition(input);
|
||||
player.setLocation(new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ(), player.getLocation().getYaw(), player.getLocation().getPitch()));
|
||||
Location from = player.getLocation();
|
||||
Location to = new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ(), player.getLocation().getYaw(), player.getLocation().getPitch());
|
||||
|
||||
PacketPlayOutUpdateViewPosition response = new PacketPlayOutUpdateViewPosition((int) player.getLocation().getX() >> 4, (int) player.getLocation().getZ() >> 4);
|
||||
sendPacket(response);
|
||||
PlayerMoveEvent event = Limbo.getInstance().getEventsManager().callEvent(new PlayerMoveEvent(player, from, to));
|
||||
if (event.isCancelled()) {
|
||||
Location returnTo = event.getFrom();
|
||||
PacketPlayOutPositionAndLook cancel = new PacketPlayOutPositionAndLook(returnTo.getX(), returnTo.getY(), returnTo.getZ(), returnTo.getYaw(), returnTo.getPitch(), 1);
|
||||
sendPacket(cancel);
|
||||
} else {
|
||||
player.setLocation(event.getTo());
|
||||
PacketPlayOutUpdateViewPosition response = new PacketPlayOutUpdateViewPosition((int) player.getLocation().getX() >> 4, (int) player.getLocation().getZ() >> 4);
|
||||
sendPacket(response);
|
||||
}
|
||||
} else if (packetType.equals(PacketPlayInRotation.class)) {
|
||||
PacketPlayInRotation pos = new PacketPlayInRotation(input);
|
||||
player.setLocation(new Location(player.getWorld(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), pos.getYaw(), pos.getPitch()));
|
||||
Location from = player.getLocation();
|
||||
Location to = new Location(player.getWorld(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), pos.getYaw(), pos.getPitch());
|
||||
|
||||
PacketPlayOutUpdateViewPosition response = new PacketPlayOutUpdateViewPosition((int) player.getLocation().getX() >> 4, (int) player.getLocation().getZ() >> 4);
|
||||
sendPacket(response);
|
||||
PlayerMoveEvent event = Limbo.getInstance().getEventsManager().callEvent(new PlayerMoveEvent(player, from, to));
|
||||
if (event.isCancelled()) {
|
||||
Location returnTo = event.getFrom();
|
||||
PacketPlayOutPositionAndLook cancel = new PacketPlayOutPositionAndLook(returnTo.getX(), returnTo.getY(), returnTo.getZ(), returnTo.getYaw(), returnTo.getPitch(), 1);
|
||||
sendPacket(cancel);
|
||||
} else {
|
||||
player.setLocation(event.getTo());
|
||||
PacketPlayOutUpdateViewPosition response = new PacketPlayOutUpdateViewPosition((int) player.getLocation().getX() >> 4, (int) player.getLocation().getZ() >> 4);
|
||||
sendPacket(response);
|
||||
}
|
||||
} else if (packetType.equals(PacketPlayInKeepAlive.class)) {
|
||||
PacketPlayInKeepAlive alive = new PacketPlayInKeepAlive(input);
|
||||
if (alive.getPayload() != lastKeepAlivePayLoad) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue