diff --git a/libs/HiPlugin.jar b/libs/HiPlugin.jar index 483191e..d1ae3e0 100644 Binary files a/libs/HiPlugin.jar and b/libs/HiPlugin.jar differ diff --git a/src/main/java/top/whitecola/coteleport/commands/Back.java b/src/main/java/top/whitecola/coteleport/commands/Back.java index b3fa2bd..d14c761 100644 --- a/src/main/java/top/whitecola/coteleport/commands/Back.java +++ b/src/main/java/top/whitecola/coteleport/commands/Back.java @@ -5,13 +5,12 @@ import org.bukkit.entity.Player; import top.whitecola.annotations.ItsACommand; import top.whitecola.commandhandler.ICommand; -import top.whitecola.coteleport.CoTeleport; +import top.whitecola.coteleport.handler.PlayerBackHandler; +import top.whitecola.coteleport.utils.HandlerFactory; import top.whitecola.coteleport.wrapper.BackRequest; -import top.whitecola.coteleport.utils.PlayerUtils; import java.util.Arrays; import java.util.List; -import java.util.Vector; @ItsACommand(CommandNmae = "back",premission = "ct.back") public class Back implements ICommand { @@ -22,15 +21,10 @@ public boolean onCommand(CommandSender commandSender, Command command, String s, Player fromP = (Player) commandSender; - Vector backRequests = CoTeleport.instance.getPlayerBackHandler().getBackRequests(); - if(backRequests==null) - return false; - - for(BackRequest backRequest : backRequests){ - if(PlayerUtils.isSamePlayer(backRequest.getFrom(),fromP)){ - backRequest.accept(); - return true; - } + BackRequest backRequest; + if((backRequest = HandlerFactory.getHandler(PlayerBackHandler.class).getBackRequestByPlayer(fromP))!=null){ + backRequest.accept(); + return true; } fromP.sendMessage("§4上一个地点已过期或不存在,无法传送。"); diff --git a/src/main/java/top/whitecola/coteleport/effects/AbstractTeleporting.java b/src/main/java/top/whitecola/coteleport/effects/AbstractTeleporting.java new file mode 100644 index 0000000..87d9927 --- /dev/null +++ b/src/main/java/top/whitecola/coteleport/effects/AbstractTeleporting.java @@ -0,0 +1,27 @@ +package top.whitecola.coteleport.effects; + +import de.slikey.effectlib.effect.CircleEffect; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import top.whitecola.coteleport.wrapper.AbstractRequest; +import top.whitecola.coteleport.wrapper.PlayerNoticer; + +public abstract class AbstractTeleporting { + + public void teleportToSomeplace(Entity entity, Location to){ + + } + + + public Thread tpaRequestHandle(AbstractRequest request, PlayerNoticer noticer){ + + return null; + } + + public static CircleEffect playTeleportingParticle(Location location){ + + return null; + } + + +} diff --git a/src/main/java/top/whitecola/coteleport/effects/Teleporting.java b/src/main/java/top/whitecola/coteleport/effects/Teleporting.java new file mode 100644 index 0000000..df9cbfd --- /dev/null +++ b/src/main/java/top/whitecola/coteleport/effects/Teleporting.java @@ -0,0 +1,19 @@ +package top.whitecola.coteleport.effects; + +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import top.whitecola.coteleport.wrapper.AbstractRequest; +import top.whitecola.coteleport.wrapper.PlayerNoticer; + +public class Teleporting extends AbstractTeleporting{ + @Override + public void teleportToSomeplace(Entity entity, Location to) { + super.teleportToSomeplace(entity, to); + } + + + @Override + public Thread tpaRequestHandle(AbstractRequest request, PlayerNoticer noticer) { + return super.tpaRequestHandle(request, noticer); + } +} diff --git a/src/main/java/top/whitecola/coteleport/listeners/PlayerListener.java b/src/main/java/top/whitecola/coteleport/listeners/PlayerListener.java index 5dcaaf2..756d9f9 100644 --- a/src/main/java/top/whitecola/coteleport/listeners/PlayerListener.java +++ b/src/main/java/top/whitecola/coteleport/listeners/PlayerListener.java @@ -21,11 +21,15 @@ public void playerMoveListener(PlayerMoveEvent e){ if(e.getFrom().getBlockX()==e.getTo().getBlockX() && e.getFrom().getBlockY()==e.getTo().getBlockY()&& e.getFrom().getBlockZ()==e.getTo().getBlockZ()){ return; } - PlayerRequest playerRequest = HandlerFactory.getHandler(PlayerTeleportEventHandler.class).getPlayerRequestByFrom(e.getPlayer()); - if(playerRequest==null) + + AbstractRequest request = HandlerFactory.getHandler(PlayerTeleportEventHandler.class).getPlayerRequestByFrom(e.getPlayer()); + if(request==null && (request = HandlerFactory.getHandler(PlayerBackHandler.class).getBackRequestByPlayer(e.getPlayer()))==null) return; - if(playerRequest.getThread()==null) + if(request.getThread()==null) + return; + + if(request.getTime()==-2 || request.getTime()==-1) return; e.setCancelled(true); @@ -39,7 +43,6 @@ public void PlayerShiftEvent(PlayerToggleSneakEvent e){ if(request==null && (request = HandlerFactory.getHandler(PlayerBackHandler.class).getBackRequestByPlayer(e.getPlayer()))==null) return; - if(request.getThread()==null) return; @@ -57,10 +60,12 @@ public void onPlayerQuitEvent(PlayerQuitEvent e){ } - BackRequest backRequest = CoTeleport.instance.getPlayerBackHandler().getBackRequestByPlayer(e.getPlayer()); + BackRequest backRequest = HandlerFactory.getHandler(PlayerBackHandler.class).getBackRequestByPlayer(e.getPlayer()); if(backRequest!=null){ backRequest.cancel(); + backRequest.addRequestOrRemoving(); } + return; } diff --git a/src/main/java/top/whitecola/coteleport/utils/TeleportUtils.java b/src/main/java/top/whitecola/coteleport/utils/TeleportUtils.java index c43f926..9f0a10a 100644 --- a/src/main/java/top/whitecola/coteleport/utils/TeleportUtils.java +++ b/src/main/java/top/whitecola/coteleport/utils/TeleportUtils.java @@ -10,6 +10,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import top.whitecola.coteleport.CoTeleport; +import top.whitecola.coteleport.handler.PlayerBackHandler; import top.whitecola.coteleport.handler.PlayerTeleportEventHandler; import top.whitecola.coteleport.wrapper.AbstractRequest; import top.whitecola.coteleport.wrapper.PlayerNoticer; @@ -45,6 +46,13 @@ public static Thread tpaRequestHandle(AbstractRequest request, PlayerNoticer not if((request.getTime()!=-2)&&(System.currentTimeMillis()-request.getTime())>=3000){ request.setTime(-1); + teleportPlace(request.getFrom(), request.getTolcation()); + + noticer.getP1().spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("§a§l传送完成!")); + + if(noticer.getP2()!=null){ + noticer.getP2().spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("§a§l传送完成!")); + } break; } @@ -55,23 +63,15 @@ public static Thread tpaRequestHandle(AbstractRequest request, PlayerNoticer not noticer.getP1().spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("§a§l即将传送,期间无法移动。按 SHIFT 以取消传送。")); try { - Thread.sleep(1000); + Thread.sleep(10); } catch (InterruptedException e) { return; } } - teleportPlace(request.getFrom(), request.getTolcation()); - - noticer.getP1().spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("§a§l传送完成!")); - - if(noticer.getP2()!=null){ - noticer.getP2().spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("§a§l传送完成!")); - } - - request.setTime(-1); HandlerFactory.getHandler(PlayerTeleportEventHandler.class).getRequests().remove(request); + HandlerFactory.getHandler(PlayerBackHandler.class).getBackRequests().remove(request); return; } diff --git a/src/main/java/top/whitecola/coteleport/wrapper/AbstractRequest.java b/src/main/java/top/whitecola/coteleport/wrapper/AbstractRequest.java index be0c2ca..37b7f5f 100644 --- a/src/main/java/top/whitecola/coteleport/wrapper/AbstractRequest.java +++ b/src/main/java/top/whitecola/coteleport/wrapper/AbstractRequest.java @@ -38,8 +38,13 @@ public void deny() { @Override public void cancel() { setTime(-2); - thread.interrupt(); - addRequestOrRemoving(); + if(thread!=null) + thread.interrupt(); + + if(!(this instanceof BackRequest)) + addRequestOrRemoving(); + + thread = null; } @Override @@ -90,7 +95,7 @@ public void setThread(Thread thread) { this.thread = thread; } - private void addRequestOrRemoving(){ + public void addRequestOrRemoving(){ if(this instanceof PlayerRequest) { if(getThread()==null && time!=-2){ HandlerFactory.getHandler(PlayerTeleportEventHandler.class).addRequest(this);