Adding in an event on PS teleportation.
This commit is contained in:
parent
2543fc306e
commit
e07241d4d7
@ -0,0 +1,61 @@
|
||||
package com.massivecraft.mcore.event;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.massivecraft.mcore.PS;
|
||||
|
||||
public class MCorePlayerPSTeleportEvent extends Event implements Cancellable, Runnable
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// REQUIRED EVENT CODE
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
@Override public HandlerList getHandlers() { return handlers; }
|
||||
public static HandlerList getHandlerList() { return handlers; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private boolean cancelled;
|
||||
@Override public boolean isCancelled() { return this.cancelled; }
|
||||
@Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; }
|
||||
|
||||
private final Player player;
|
||||
public Player getPlayer() { return this.player; }
|
||||
|
||||
private final Location from;
|
||||
public Location getFrom() { return this.from; }
|
||||
|
||||
private PS to;
|
||||
public PS getTo() { return this.to; }
|
||||
public void setTo(PS to) { this.to = to; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public MCorePlayerPSTeleportEvent(Player player, Location from, PS to)
|
||||
{
|
||||
this.player = player;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// RUN
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Bukkit.getPluginManager().callEvent(this);
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.massivecraft.mcore.PS;
|
||||
import com.massivecraft.mcore.event.MCorePlayerPSTeleportEvent;
|
||||
import com.massivecraft.mcore.util.SenderUtil;
|
||||
import com.massivecraft.mcore.util.Txt;
|
||||
|
||||
@ -24,7 +25,6 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
|
||||
|
||||
public static void teleportEntity(Entity entity, PS ps) throws TeleporterException
|
||||
{
|
||||
// Use a local clone of the ps to avoid altering original
|
||||
ps = ps.clone();
|
||||
|
||||
// Ensure the ps has a world name
|
||||
@ -58,6 +58,13 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
|
||||
}
|
||||
else
|
||||
{
|
||||
// Run event
|
||||
MCorePlayerPSTeleportEvent event = new MCorePlayerPSTeleportEvent(teleportee, teleportee.getLocation(), destinationPs.clone());
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
if (event.getTo() == null) return;
|
||||
destinationPs = event.getTo().clone();
|
||||
|
||||
teleportEntity(teleportee, destinationPs);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.massivecraft.mcore.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -128,6 +129,22 @@ public class TimeDiffUtil
|
||||
return unitcounts(millis, TimeUnit.getAll());
|
||||
}
|
||||
|
||||
public static LinkedHashMap<TimeUnit, Long> limit(LinkedHashMap<TimeUnit, Long> unitcounts, int limit)
|
||||
{
|
||||
LinkedHashMap<TimeUnit, Long> ret = new LinkedHashMap<TimeUnit, Long>();
|
||||
|
||||
Iterator<Entry<TimeUnit, Long>> iter = unitcounts.entrySet().iterator();
|
||||
int i = 0;
|
||||
while (iter.hasNext() && i < limit)
|
||||
{
|
||||
Entry<TimeUnit, Long> entry = iter.next();
|
||||
ret.put(entry.getKey(), entry.getValue());
|
||||
i++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FORMAT
|
||||
// -------------------------------------------- //
|
||||
|
Loading…
Reference in New Issue
Block a user