mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 22:16:22 +00:00
Add TeleportBackEvent, Teleport.Type.BACK type, close #180
This commit is contained in:
6 files changed
+69
-13
No files matched your search
@@ -23,7 +23,7 @@ public interface BukkitEventDispatcher extends EventDispatcher {
|
||||
|
||||
@Override
|
||||
default ITeleportEvent getTeleportEvent(@NotNull Teleport teleport) {
|
||||
return new TeleportEvent(teleport);
|
||||
return teleport.getType() == Teleport.Type.BACK ? new TeleportBackEvent(teleport) : new TeleportEvent(teleport);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TeleportBackEvent extends TeleportEvent implements ITeleportBackEvent {
|
||||
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
public TeleportBackEvent(@NotNull Teleport teleport) {
|
||||
super(teleport);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Position getLastPosition() {
|
||||
return (Position) getTeleport().getTarget();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -33,6 +33,7 @@ public class BackCommand extends InGameCommand {
|
||||
.teleporter(executor)
|
||||
.target(lastPosition.get())
|
||||
.economyActions(EconomyHook.Action.BACK_COMMAND)
|
||||
.type(Teleport.Type.BACK)
|
||||
.toTimedTeleport()
|
||||
.execute();
|
||||
} catch (TeleportationException e) {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package net.william278.huskhomes.event;
|
||||
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface ITeleportBackEvent extends ITeleportEvent {
|
||||
|
||||
@NotNull
|
||||
Position getLastPosition();
|
||||
|
||||
}
|
||||
@@ -79,6 +79,26 @@ public class EventListener {
|
||||
private void handleInboundTeleport(@NotNull OnlineUser teleporter) {
|
||||
plugin.getDatabase().getCurrentTeleport(teleporter).ifPresent(teleport -> {
|
||||
if (teleport.getType() == Teleport.Type.RESPAWN) {
|
||||
handleInboundRespawn(teleporter);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
teleporter.teleportLocally((Position) teleport.getTarget(), plugin.getSettings().doAsynchronousTeleports());
|
||||
} catch (TeleportationException e) {
|
||||
e.displayMessage(teleporter, plugin, new String[0]);
|
||||
}
|
||||
plugin.getDatabase().setCurrentTeleport(teleporter, null);
|
||||
teleport.displayTeleportingComplete(teleporter);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an inbound global respawn
|
||||
*
|
||||
* @param teleporter the user to handle the checks for
|
||||
*/
|
||||
private void handleInboundRespawn(@NotNull OnlineUser teleporter) {
|
||||
final Optional<Position> bedPosition = teleporter.getBedSpawnPosition();
|
||||
if (bedPosition.isEmpty()) {
|
||||
plugin.getSpawn().ifPresent(spawn -> {
|
||||
@@ -112,17 +132,6 @@ public class EventListener {
|
||||
}
|
||||
plugin.getDatabase().setCurrentTeleport(teleporter, null);
|
||||
plugin.getDatabase().setRespawnPosition(teleporter, bedPosition.orElse(null));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
teleporter.teleportLocally((Position) teleport.getTarget(), plugin.getSettings().doAsynchronousTeleports());
|
||||
} catch (TeleportationException e) {
|
||||
e.displayMessage(teleporter, plugin, new String[0]);
|
||||
}
|
||||
plugin.getDatabase().setCurrentTeleport(teleporter, null);
|
||||
teleport.displayTeleportingComplete(teleporter);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -184,7 +184,8 @@ public class Teleport {
|
||||
*/
|
||||
public enum Type {
|
||||
TELEPORT(0),
|
||||
RESPAWN(1);
|
||||
RESPAWN(1),
|
||||
BACK(2);
|
||||
|
||||
private final int typeId;
|
||||
|
||||
|
||||
Reference in new issue
Block a user