Recoding TeleporterMixin
This commit is contained in:
parent
e07241d4d7
commit
941478c574
@ -5,6 +5,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.permissions.Permissible;
|
||||||
|
|
||||||
import com.massivecraft.mcore.cmd.CmdMcore;
|
import com.massivecraft.mcore.cmd.CmdMcore;
|
||||||
import com.massivecraft.mcore.usys.cmd.CmdUsys;
|
import com.massivecraft.mcore.usys.cmd.CmdUsys;
|
||||||
import com.massivecraft.mcore.util.MUtil;
|
import com.massivecraft.mcore.util.MUtil;
|
||||||
@ -35,6 +37,12 @@ public class Conf extends SimpleConfig
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getTpdelay(Permissible permissible)
|
||||||
|
{
|
||||||
|
if (Permission.NOTPDELAY.has(permissible, false)) return 0;
|
||||||
|
return Math.max(tpdelay, 0);
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// META
|
// META
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -24,6 +24,7 @@ import com.massivecraft.mcore.store.MStore;
|
|||||||
import com.massivecraft.mcore.usys.AspectColl;
|
import com.massivecraft.mcore.usys.AspectColl;
|
||||||
import com.massivecraft.mcore.usys.MultiverseColl;
|
import com.massivecraft.mcore.usys.MultiverseColl;
|
||||||
import com.massivecraft.mcore.usys.cmd.CmdUsys;
|
import com.massivecraft.mcore.usys.cmd.CmdUsys;
|
||||||
|
import com.massivecraft.mcore.util.FirstTeleportUtil;
|
||||||
import com.massivecraft.mcore.util.PlayerUtil;
|
import com.massivecraft.mcore.util.PlayerUtil;
|
||||||
import com.massivecraft.mcore.util.TimeDiffUtil;
|
import com.massivecraft.mcore.util.TimeDiffUtil;
|
||||||
import com.massivecraft.mcore.util.TimeUnit;
|
import com.massivecraft.mcore.util.TimeUnit;
|
||||||
@ -115,6 +116,7 @@ public class MCore extends MPlugin
|
|||||||
// Register events
|
// Register events
|
||||||
InternalListener.get().setup();
|
InternalListener.get().setup();
|
||||||
ScheduledTeleportEngine.get().setup();
|
ScheduledTeleportEngine.get().setup();
|
||||||
|
FirstTeleportUtil.get().setup();
|
||||||
|
|
||||||
// Schedule the collection ticker.
|
// Schedule the collection ticker.
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this.collTickTask, 1, 1);
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this.collTickTask, 1, 1);
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package com.massivecraft.mcore.event;
|
package com.massivecraft.mcore.event;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@ -27,11 +25,11 @@ public class MCorePlayerPSTeleportEvent extends Event implements Cancellable, Ru
|
|||||||
@Override public boolean isCancelled() { return this.cancelled; }
|
@Override public boolean isCancelled() { return this.cancelled; }
|
||||||
@Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; }
|
@Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; }
|
||||||
|
|
||||||
private final Player player;
|
private final String teleporteeId;
|
||||||
public Player getPlayer() { return this.player; }
|
public String getTeleporteeId() { return this.teleporteeId; }
|
||||||
|
|
||||||
private final Location from;
|
private final PS from;
|
||||||
public Location getFrom() { return this.from; }
|
public PS getFrom() { return this.from; }
|
||||||
|
|
||||||
private PS to;
|
private PS to;
|
||||||
public PS getTo() { return this.to; }
|
public PS getTo() { return this.to; }
|
||||||
@ -41,9 +39,9 @@ public class MCorePlayerPSTeleportEvent extends Event implements Cancellable, Ru
|
|||||||
// CONSTRUCT
|
// CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public MCorePlayerPSTeleportEvent(Player player, Location from, PS to)
|
public MCorePlayerPSTeleportEvent(String teleporteeId, PS from, PS to)
|
||||||
{
|
{
|
||||||
this.player = player;
|
this.teleporteeId = teleporteeId;
|
||||||
this.from = from;
|
this.from = from;
|
||||||
this.to = to;
|
this.to = to;
|
||||||
}
|
}
|
||||||
|
@ -296,18 +296,6 @@ public class Mixin
|
|||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, destinationPs, destinationDesc, delayPermissible);
|
getTeleportMixin().teleport(teleportee, destinationPs, destinationDesc, delayPermissible);
|
||||||
}
|
}
|
||||||
public static void teleport(Player teleportee, PS destinationPs, String destinationDesc, Permissible delayPermissible, CommandSender otherSender, String otherPerm) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, destinationPs, destinationDesc, delayPermissible, otherSender, otherPerm);
|
|
||||||
}
|
|
||||||
public static void teleport(Player teleportee, PS destinationPs, String destinationDesc, CommandSender otherSender, String otherPerm) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, destinationPs, destinationDesc, otherSender, otherPerm);
|
|
||||||
}
|
|
||||||
public static void teleport(Player teleportee, PS destinationPs, String destinationDesc, int delaySeconds, CommandSender otherSender, String otherPerm) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, destinationPs, destinationDesc, delaySeconds, otherSender, otherPerm);
|
|
||||||
}
|
|
||||||
public static void teleport(Player teleportee, PS destinationPs, String destinationDesc, int delaySeconds) throws TeleporterException
|
public static void teleport(Player teleportee, PS destinationPs, String destinationDesc, int delaySeconds) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, destinationPs, destinationDesc, delaySeconds);
|
getTeleportMixin().teleport(teleportee, destinationPs, destinationDesc, delaySeconds);
|
||||||
@ -325,18 +313,6 @@ public class Mixin
|
|||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleporteeId, destinationPs, destinationDesc, delayPermissible);
|
getTeleportMixin().teleport(teleporteeId, destinationPs, destinationDesc, delayPermissible);
|
||||||
}
|
}
|
||||||
public static void teleport(String teleporteeId, PS destinationPs, String destinationDesc, Permissible delayPermissible, CommandSender otherSender, String otherPerm) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleporteeId, destinationPs, destinationDesc, delayPermissible, otherSender, otherPerm);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleporteeId, PS destinationPs, String destinationDesc, CommandSender otherSender, String otherPerm) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleporteeId, destinationPs, destinationDesc, otherSender, otherPerm);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleporteeId, PS destinationPs, String destinationDesc, int delaySeconds, CommandSender otherSender, String otherPerm) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleporteeId, destinationPs, destinationDesc, delaySeconds, otherSender, otherPerm);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleporteeId, PS destinationPs, String destinationDesc, int delaySeconds) throws TeleporterException
|
public static void teleport(String teleporteeId, PS destinationPs, String destinationDesc, int delaySeconds) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleporteeId, destinationPs, destinationDesc, delaySeconds);
|
getTeleportMixin().teleport(teleporteeId, destinationPs, destinationDesc, delaySeconds);
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
package com.massivecraft.mcore.mixin;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.massivecraft.mcore.PS;
|
import com.massivecraft.mcore.PS;
|
||||||
|
|
||||||
public class ScheduledTeleport implements Runnable
|
public class ScheduledTeleport implements Runnable
|
||||||
@ -10,8 +8,8 @@ public class ScheduledTeleport implements Runnable
|
|||||||
// FIELDS & RAW-DATA ACCESS
|
// FIELDS & RAW-DATA ACCESS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
private final Player teleportee;
|
private final String teleporteeId;
|
||||||
public Player getTeleportee() { return this.teleportee; }
|
public String getTeleporteeId() { return this.teleporteeId; }
|
||||||
|
|
||||||
private final PS destinationPs;
|
private final PS destinationPs;
|
||||||
public PS getDestinationPs() { return this.destinationPs; }
|
public PS getDestinationPs() { return this.destinationPs; }
|
||||||
@ -31,9 +29,9 @@ public class ScheduledTeleport implements Runnable
|
|||||||
// CONSTRUCT
|
// CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public ScheduledTeleport(Player teleportee, PS destinationPs, String destinationDesc, int delaySeconds)
|
public ScheduledTeleport(String teleporteeId, PS destinationPs, String destinationDesc, int delaySeconds)
|
||||||
{
|
{
|
||||||
this.teleportee = teleportee;
|
this.teleporteeId = teleporteeId;
|
||||||
this.destinationPs = destinationPs;
|
this.destinationPs = destinationPs;
|
||||||
this.destinationDesc = destinationDesc;
|
this.destinationDesc = destinationDesc;
|
||||||
this.delaySeconds = delaySeconds;
|
this.delaySeconds = delaySeconds;
|
||||||
@ -67,14 +65,14 @@ public class ScheduledTeleport implements Runnable
|
|||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
this.unschedule();
|
this.unschedule();
|
||||||
if (!teleportee.isOnline()) return;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Mixin.teleport(this.teleportee, this.destinationPs, this.destinationDesc);
|
Mixin.teleport(this.getTeleporteeId(), this.getDestinationPs(), this.getDestinationDesc());
|
||||||
}
|
}
|
||||||
catch (TeleporterException e)
|
catch (TeleporterException e)
|
||||||
{
|
{
|
||||||
this.teleportee.sendMessage(e.getMessage());
|
Mixin.message(this.getTeleporteeId(), e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -12,6 +11,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
|||||||
|
|
||||||
import com.massivecraft.mcore.MCore;
|
import com.massivecraft.mcore.MCore;
|
||||||
import com.massivecraft.mcore.util.MUtil;
|
import com.massivecraft.mcore.util.MUtil;
|
||||||
|
import com.massivecraft.mcore.util.SenderUtil;
|
||||||
|
|
||||||
public class ScheduledTeleportEngine implements Listener, Runnable
|
public class ScheduledTeleportEngine implements Listener, Runnable
|
||||||
{
|
{
|
||||||
@ -26,19 +26,19 @@ public class ScheduledTeleportEngine implements Listener, Runnable
|
|||||||
// SCHEDULED TELEPORT INDEX
|
// SCHEDULED TELEPORT INDEX
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
protected Map<Player, ScheduledTeleport> teleporteeToScheduledTeleport = new ConcurrentHashMap<Player, ScheduledTeleport>();
|
protected Map<String, ScheduledTeleport> teleporteeIdToScheduledTeleport = new ConcurrentHashMap<String, ScheduledTeleport>();
|
||||||
|
|
||||||
public boolean isScheduled(ScheduledTeleport st)
|
public boolean isScheduled(ScheduledTeleport st)
|
||||||
{
|
{
|
||||||
return this.teleporteeToScheduledTeleport.containsValue(st);
|
return this.teleporteeIdToScheduledTeleport.containsValue(st);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScheduledTeleport schedule(ScheduledTeleport st)
|
public ScheduledTeleport schedule(ScheduledTeleport st)
|
||||||
{
|
{
|
||||||
ScheduledTeleport old = this.teleporteeToScheduledTeleport.get(st.getTeleportee());
|
ScheduledTeleport old = this.teleporteeIdToScheduledTeleport.get(st.getTeleporteeId());
|
||||||
if (old != null) old.unschedule();
|
if (old != null) old.unschedule();
|
||||||
|
|
||||||
this.teleporteeToScheduledTeleport.put(st.getTeleportee(), st);
|
this.teleporteeIdToScheduledTeleport.put(st.getTeleporteeId(), st);
|
||||||
|
|
||||||
st.setDueMillis(System.currentTimeMillis() + st.getDelaySeconds()*1000);
|
st.setDueMillis(System.currentTimeMillis() + st.getDelaySeconds()*1000);
|
||||||
|
|
||||||
@ -47,11 +47,11 @@ public class ScheduledTeleportEngine implements Listener, Runnable
|
|||||||
|
|
||||||
public boolean unschedule(ScheduledTeleport st)
|
public boolean unschedule(ScheduledTeleport st)
|
||||||
{
|
{
|
||||||
ScheduledTeleport old = this.teleporteeToScheduledTeleport.get(st.getTeleportee());
|
ScheduledTeleport old = this.teleporteeIdToScheduledTeleport.get(st.getTeleporteeId());
|
||||||
if (old == null) return false;
|
if (old == null) return false;
|
||||||
if (old != st) return false;
|
if (old != st) return false;
|
||||||
|
|
||||||
return this.teleporteeToScheduledTeleport.remove(st.getTeleportee()) != null;
|
return this.teleporteeIdToScheduledTeleport.remove(st.getTeleporteeId()) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -75,14 +75,14 @@ public class ScheduledTeleportEngine implements Listener, Runnable
|
|||||||
if (MUtil.isSameBlock(event.getFrom(), event.getTo())) return;
|
if (MUtil.isSameBlock(event.getFrom(), event.getTo())) return;
|
||||||
|
|
||||||
// ... and there is a ScheduledTeleport ...
|
// ... and there is a ScheduledTeleport ...
|
||||||
ScheduledTeleport scheduledTeleport = teleporteeToScheduledTeleport.get(event.getPlayer());
|
ScheduledTeleport scheduledTeleport = teleporteeIdToScheduledTeleport.get(SenderUtil.getSenderId(event.getPlayer()));
|
||||||
if (scheduledTeleport == null) return;
|
if (scheduledTeleport == null) return;
|
||||||
|
|
||||||
// ... unschedule it ...
|
// ... unschedule it ...
|
||||||
scheduledTeleport.unschedule();
|
scheduledTeleport.unschedule();
|
||||||
|
|
||||||
// ... and inform the teleportee.
|
// ... and inform the teleportee.
|
||||||
Mixin.msg(scheduledTeleport.getTeleportee(), "<rose>Cancelled <i>teleport to <h>"+scheduledTeleport.getDestinationDesc()+"<i>.");
|
Mixin.msg(scheduledTeleport.getTeleporteeId(), "<rose>Cancelled <i>teleport to <h>"+scheduledTeleport.getDestinationDesc()+"<i>.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -93,7 +93,7 @@ public class ScheduledTeleportEngine implements Listener, Runnable
|
|||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
for (ScheduledTeleport st : teleporteeToScheduledTeleport.values())
|
for (ScheduledTeleport st : teleporteeIdToScheduledTeleport.values())
|
||||||
{
|
{
|
||||||
if (st.isDue(now))
|
if (st.isDue(now))
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
package com.massivecraft.mcore.mixin;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.permissions.Permissible;
|
import org.bukkit.permissions.Permissible;
|
||||||
|
|
||||||
@ -8,12 +7,6 @@ import com.massivecraft.mcore.PS;
|
|||||||
|
|
||||||
public interface TeleportMixin
|
public interface TeleportMixin
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
|
||||||
// MESSAGING
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public void sendPreTeleportMessage(Player teleportee, String destinationDesc, int delaySeconds);
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// PLAYER
|
// PLAYER
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -23,11 +16,6 @@ public interface TeleportMixin
|
|||||||
public void teleport(Player teleportee, PS destinationPs, String destinationDesc) throws TeleporterException;
|
public void teleport(Player teleportee, PS destinationPs, String destinationDesc) throws TeleporterException;
|
||||||
|
|
||||||
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, Permissible delayPermissible) throws TeleporterException;
|
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, Permissible delayPermissible) throws TeleporterException;
|
||||||
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, Permissible delayPermissible, CommandSender otherSender, String otherPerm) throws TeleporterException;
|
|
||||||
|
|
||||||
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, CommandSender otherSender, String otherPerm) throws TeleporterException;
|
|
||||||
|
|
||||||
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, int delaySeconds, CommandSender otherSender, String otherPerm) throws TeleporterException;
|
|
||||||
|
|
||||||
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, int delaySeconds) throws TeleporterException;
|
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, int delaySeconds) throws TeleporterException;
|
||||||
|
|
||||||
@ -40,11 +28,7 @@ public interface TeleportMixin
|
|||||||
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc) throws TeleporterException;
|
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc) throws TeleporterException;
|
||||||
|
|
||||||
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, Permissible delayPermissible) throws TeleporterException;
|
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, Permissible delayPermissible) throws TeleporterException;
|
||||||
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, Permissible delayPermissible, CommandSender otherSender, String otherPerm) throws TeleporterException;
|
|
||||||
|
|
||||||
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, CommandSender otherSender, String otherPerm) throws TeleporterException;
|
|
||||||
|
|
||||||
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, int delaySeconds, CommandSender otherSender, String otherPerm) throws TeleporterException;
|
|
||||||
|
|
||||||
|
// The only one not covered in abstract
|
||||||
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, int delaySeconds) throws TeleporterException;
|
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, int delaySeconds) throws TeleporterException;
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
package com.massivecraft.mcore.mixin;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.permissions.Permissible;
|
import org.bukkit.permissions.Permissible;
|
||||||
|
|
||||||
import com.massivecraft.mcore.Conf;
|
import com.massivecraft.mcore.Conf;
|
||||||
import com.massivecraft.mcore.PS;
|
import com.massivecraft.mcore.PS;
|
||||||
import com.massivecraft.mcore.Permission;
|
|
||||||
import com.massivecraft.mcore.util.PermUtil;
|
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.SenderUtil;
|
||||||
import com.massivecraft.mcore.util.Txt;
|
|
||||||
|
|
||||||
public abstract class TeleportMixinAbstract implements TeleportMixin
|
public abstract class TeleportMixinAbstract implements TeleportMixin
|
||||||
{
|
{
|
||||||
@ -17,29 +13,6 @@ public abstract class TeleportMixinAbstract implements TeleportMixin
|
|||||||
// OVERRIDE
|
// OVERRIDE
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendPreTeleportMessage(Player teleportee, String destinationDesc, int delaySeconds)
|
|
||||||
{
|
|
||||||
if (delaySeconds > 0)
|
|
||||||
{
|
|
||||||
if (destinationDesc != null)
|
|
||||||
{
|
|
||||||
Mixin.msg(teleportee, "<i>Teleporting to <h>"+destinationDesc+" <i>in <h>"+delaySeconds+"s <i>unless you move.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Mixin.msg(teleportee, "<i>Teleporting in <h>"+delaySeconds+"s <i>unless you move.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (destinationDesc != null)
|
|
||||||
{
|
|
||||||
Mixin.msg(teleportee, "<i>Teleporting to <h>"+destinationDesc+"<i>.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(Player teleportee, PS destinationPs) throws TeleporterException
|
public void teleport(Player teleportee, PS destinationPs) throws TeleporterException
|
||||||
{
|
{
|
||||||
@ -55,28 +28,14 @@ public abstract class TeleportMixinAbstract implements TeleportMixin
|
|||||||
@Override
|
@Override
|
||||||
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, Permissible delayPermissible) throws TeleporterException
|
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, Permissible delayPermissible) throws TeleporterException
|
||||||
{
|
{
|
||||||
int delaySeconds = decideDelaySeconds(delayPermissible);
|
int delaySeconds = getTpdelay(delayPermissible);
|
||||||
this.teleport(teleportee, destinationPs, destinationDesc, delaySeconds);
|
this.teleport(teleportee, destinationPs, destinationDesc, delaySeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, Permissible delayPermissible, CommandSender otherSender, String otherPerm) throws TeleporterException
|
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, int delaySeconds) throws TeleporterException
|
||||||
{
|
{
|
||||||
int delaySeconds = decideDelaySeconds(delayPermissible);
|
this.teleport(SenderUtil.getSenderId(teleportee), destinationPs, destinationDesc, delaySeconds);
|
||||||
this.teleport(teleportee, destinationPs, destinationDesc, delaySeconds, otherSender, otherPerm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, CommandSender otherSender, String otherPerm) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, destinationPs, destinationDesc, 0, otherSender, otherPerm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, int delaySeconds, CommandSender otherSender, String otherPerm) throws TeleporterException
|
|
||||||
{
|
|
||||||
otherPermCheck(SenderUtil.getSenderId(teleportee), otherSender, otherPerm);
|
|
||||||
this.teleport(teleportee, destinationPs, destinationDesc, delaySeconds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
@ -96,27 +55,7 @@ public abstract class TeleportMixinAbstract implements TeleportMixin
|
|||||||
@Override
|
@Override
|
||||||
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, Permissible delayPermissible) throws TeleporterException
|
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, Permissible delayPermissible) throws TeleporterException
|
||||||
{
|
{
|
||||||
int delaySeconds = decideDelaySeconds(delayPermissible);
|
int delaySeconds = getTpdelay(delayPermissible);
|
||||||
this.teleport(teleporteeId, destinationPs, destinationDesc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, Permissible delayPermissible, CommandSender otherSender, String otherPerm) throws TeleporterException
|
|
||||||
{
|
|
||||||
int delaySeconds = decideDelaySeconds(delayPermissible);
|
|
||||||
this.teleport(teleporteeId, destinationPs, destinationDesc, delaySeconds, otherSender, otherPerm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, CommandSender otherSender, String otherPerm) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleporteeId, destinationPs, destinationDesc, 0, otherSender, otherPerm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, int delaySeconds, CommandSender otherSender, String otherPerm) throws TeleporterException
|
|
||||||
{
|
|
||||||
otherPermCheck(teleporteeId, otherSender, otherPerm);
|
|
||||||
this.teleport(teleporteeId, destinationPs, destinationDesc, delaySeconds);
|
this.teleport(teleporteeId, destinationPs, destinationDesc, delaySeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,17 +63,12 @@ public abstract class TeleportMixinAbstract implements TeleportMixin
|
|||||||
// UTIL
|
// UTIL
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static int decideDelaySeconds(Permissible delayPermissible)
|
public static int getTpdelay(Permissible delayPermissible)
|
||||||
{
|
{
|
||||||
int ret = Conf.tpdelay;
|
return Conf.getTpdelay(delayPermissible);
|
||||||
if (Permission.NOTPDELAY.has(delayPermissible, false))
|
|
||||||
{
|
|
||||||
ret = 0;
|
|
||||||
}
|
|
||||||
ret = Math.max(ret, 0);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
public static void otherPermCheck(String teleporteeId, CommandSender otherSender, String otherPerm) throws TeleporterException
|
public static void otherPermCheck(String teleporteeId, CommandSender otherSender, String otherPerm) throws TeleporterException
|
||||||
{
|
{
|
||||||
String otherSenderId = SenderUtil.getSenderId(otherSender);
|
String otherSenderId = SenderUtil.getSenderId(otherSender);
|
||||||
@ -147,7 +81,7 @@ public abstract class TeleportMixinAbstract implements TeleportMixin
|
|||||||
{
|
{
|
||||||
if (!SenderUtil.isPlayerId(teleporteeId)) throw new TeleporterException(Txt.parse("<white>%s <b>is not a player.", Mixin.getDisplayName(teleporteeId)));
|
if (!SenderUtil.isPlayerId(teleporteeId)) throw new TeleporterException(Txt.parse("<white>%s <b>is not a player.", Mixin.getDisplayName(teleporteeId)));
|
||||||
if (Mixin.isOffline(teleporteeId)) throw new TeleporterException(Txt.parse("<white>%s <b>is offline.", Mixin.getDisplayName(teleporteeId)));
|
if (Mixin.isOffline(teleporteeId)) throw new TeleporterException(Txt.parse("<white>%s <b>is offline.", Mixin.getDisplayName(teleporteeId)));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,32 +49,50 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(Player teleportee, PS destinationPs, String destinationDesc, int delaySeconds) throws TeleporterException
|
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, int delaySeconds) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.sendPreTeleportMessage(teleportee, destinationDesc, delaySeconds);
|
if (!SenderUtil.isPlayerId(teleporteeId)) throw new TeleporterException(Txt.parse("<white>%s <b>is not a player.", Mixin.getDisplayName(teleporteeId)));
|
||||||
|
|
||||||
if (delaySeconds > 0)
|
if (delaySeconds > 0)
|
||||||
{
|
{
|
||||||
new ScheduledTeleport(teleportee, destinationPs, destinationDesc, delaySeconds).schedule();
|
// With delay
|
||||||
|
if (destinationDesc != null)
|
||||||
|
{
|
||||||
|
Mixin.msg(teleporteeId, "<i>Teleporting to <h>"+destinationDesc+" <i>in <h>"+delaySeconds+"s <i>unless you move.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Mixin.msg(teleporteeId, "<i>Teleporting in <h>"+delaySeconds+"s <i>unless you move.");
|
||||||
|
}
|
||||||
|
|
||||||
|
new ScheduledTeleport(teleporteeId, destinationPs, destinationDesc, delaySeconds).schedule();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Without delay AKA "now"/"at once"
|
||||||
|
|
||||||
// Run event
|
// Run event
|
||||||
MCorePlayerPSTeleportEvent event = new MCorePlayerPSTeleportEvent(teleportee, teleportee.getLocation(), destinationPs.clone());
|
MCorePlayerPSTeleportEvent event = new MCorePlayerPSTeleportEvent(teleporteeId, Mixin.getSenderPs(teleporteeId), destinationPs.clone());
|
||||||
event.run();
|
event.run();
|
||||||
if (event.isCancelled()) return;
|
if (event.isCancelled()) return;
|
||||||
if (event.getTo() == null) return;
|
if (event.getTo() == null) return;
|
||||||
destinationPs = event.getTo().clone();
|
destinationPs = event.getTo().clone();
|
||||||
|
|
||||||
teleportEntity(teleportee, destinationPs);
|
if (destinationDesc != null)
|
||||||
}
|
{
|
||||||
|
Mixin.msg(teleporteeId, "<i>Teleporting to <h>"+destinationDesc+"<i>.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(String teleporteeId, PS destinationPs, String destinationDesc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
validateTeleporteeId(teleporteeId);
|
|
||||||
Player teleportee = SenderUtil.getPlayer(teleporteeId);
|
Player teleportee = SenderUtil.getPlayer(teleporteeId);
|
||||||
this.teleport(teleportee, destinationPs, destinationDesc, delaySeconds);
|
if (teleportee != null)
|
||||||
|
{
|
||||||
|
teleportEntity(teleportee, destinationPs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Mixin.setSenderPs(teleporteeId, destinationPs.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
82
src/com/massivecraft/mcore/util/FirstTeleportUtil.java
Normal file
82
src/com/massivecraft/mcore/util/FirstTeleportUtil.java
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
package com.massivecraft.mcore.util;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
|
||||||
|
import com.massivecraft.mcore.MCore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The first teleport to ever occur for a player happens soon after the player logged in.
|
||||||
|
* This is a system one that should not be cancelled since it happens as the player is assigned their entrance position.
|
||||||
|
* Altering the to-location is possible but altering the world will not matter. Only x, y, z, pitch and yaw are taken into consideration.
|
||||||
|
* This tool can be used to check if a PlayerTeleportEvent is the first one for the player.
|
||||||
|
*/
|
||||||
|
public class FirstTeleportUtil implements Listener
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// INSTANCE & CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private static FirstTeleportUtil i = new FirstTeleportUtil();
|
||||||
|
public static FirstTeleportUtil get() { return i; }
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// STATIC
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private Map<Player, PlayerTeleportEvent> playerToFirstTeleport;
|
||||||
|
|
||||||
|
public static boolean isFirstTeleport(PlayerTeleportEvent event)
|
||||||
|
{
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
PlayerTeleportEvent stored = i.playerToFirstTeleport.get(player);
|
||||||
|
if (stored == null)
|
||||||
|
{
|
||||||
|
i.playerToFirstTeleport.put(player, event);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return stored == event;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// SETUP
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public void setup()
|
||||||
|
{
|
||||||
|
playerToFirstTeleport = new HashMap<Player, PlayerTeleportEvent>();
|
||||||
|
Bukkit.getPluginManager().registerEvents(this, MCore.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// LISTENER
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onPlayerLoginEventMonitor(PlayerLoginEvent event)
|
||||||
|
{
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
this.playerToFirstTeleport.remove(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onPlayerTeleportLowest(PlayerTeleportEvent event)
|
||||||
|
{
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (this.playerToFirstTeleport.containsKey(player)) return;
|
||||||
|
this.playerToFirstTeleport.put(player, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user