PlayerUtil experiments and probably fixing the Vault integration failure.

This commit is contained in:
Olof Larsson 2014-05-26 09:30:48 +02:00
parent 25cb50924c
commit 0a281196e6
11 changed files with 461 additions and 315 deletions

View File

@ -15,7 +15,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerKickEvent;
@ -23,7 +22,6 @@ import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
@ -42,7 +40,6 @@ import com.massivecraft.mcore.event.MCoreSenderUnregisterEvent;
import com.massivecraft.mcore.mixin.Mixin;
import com.massivecraft.mcore.store.Coll;
import com.massivecraft.mcore.store.SenderColl;
import com.massivecraft.mcore.util.FlyUtil;
import com.massivecraft.mcore.util.IdUtil;
import com.massivecraft.mcore.util.SmokeUtil;
import com.massivecraft.mcore.util.Txt;
@ -73,45 +70,6 @@ public class EngineMainMCore extends EngineAbstract
MCorePlayerLeaveEvent.player2event.clear();
}
// -------------------------------------------- //
// FLY UTIL & EVENT
// -------------------------------------------- //
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void updateFly(PlayerMoveEvent event)
{
// If a player ...
Player player = event.getPlayer();
// ... moved from one block to another ...
if (event.getFrom().getBlock().equals(event.getTo().getBlock())) return;
// ... and the player is alive ...
if (player.isDead()) return;
// ... trigger a fly update.
FlyUtil.update(player);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void negateNoCheatPlusBug(EntityDamageEvent event)
{
// If a player ...
if ( ! (event.getEntity() instanceof Player)) return;
Player player = (Player)event.getEntity();
// ... is taking fall damage ...
if (event.getCause() != DamageCause.FALL) return;
// ... within 2 seconds of flying ...
Long lastActive = FlyUtil.getLastActive(player);
if (lastActive == null) return;
if (System.currentTimeMillis() - lastActive > 2000) return;
// ... cancel the event.
event.setCancelled(true);
}
// -------------------------------------------- //
// RECIPIENT CHAT
// -------------------------------------------- //

View File

@ -161,8 +161,8 @@ public class MCore extends MPlugin
EngineScheduledTeleport.get().activate();
EngineTeleportMixinCause.get().activate();
EngineWorldNameSet.get().activate();
EngineCommandRegistration.get().activate(); // TODO: Make all engines
PlayerUtil.get().setup();
EngineCommandRegistration.get().activate();
PlayerUtil.get().activate();
// Tasks
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this.collTickTask, 1, 1);

View File

@ -0,0 +1,55 @@
package com.massivecraft.mcore.event;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import com.massivecraft.mcore.util.PlayerUtil;
public class EventMCorePlayerUpdate extends MCoreEvent
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
// -------------------------------------------- //
private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- //
// FIELD
// -------------------------------------------- //
private final Player player;
public Player getPlayer() { return this.player; }
private double maxHealth;
public double getMaxHealth() { return this.maxHealth; }
public void setMaxHealth(double maxHealth) { this.maxHealth = maxHealth; }
private boolean flyAllowed;
public boolean isFlyAllowed() { return this.flyAllowed; }
public void setAllowed(boolean flyAllowed) { this.flyAllowed = flyAllowed; }
private boolean flyActive;
public boolean isFlyActive() { return this.flyActive; }
public void setFlyActive(boolean flyActive) { this.flyActive = flyActive; }
private float flySpeed;
public float getFlySpeed() { return this.flySpeed; }
public void setFlySpeed(float flySpeed) { this.flySpeed = flySpeed; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public EventMCorePlayerUpdate(Player player)
{
this.player = player;
this.maxHealth = PlayerUtil.getMaxHealth(player);
this.flyAllowed = PlayerUtil.isFlyAllowed(player);
this.flyActive = PlayerUtil.isFlyActive(player);
this.flySpeed = PlayerUtil.getFlySpeed(player);
}
}

View File

@ -1,64 +0,0 @@
package com.massivecraft.mcore.event;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import com.massivecraft.mcore.util.FlyUtil;
public class MCorePlayerFlyEvent extends MCoreEvent
{
// -------------------------------------------- //
// CONSTANTS
// -------------------------------------------- //
public final static float DEFAULT_SPEED = 0.1f;
// -------------------------------------------- //
// REQUIRED EVENT CODE
// -------------------------------------------- //
private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- //
// FIELD
// -------------------------------------------- //
private final Player player;
public Player getPlayer() { return this.player; }
private boolean allowed;
public boolean isAllowed() { return this.allowed; }
public void setAllowed(boolean allowed) { this.allowed = allowed; }
private boolean active;
public boolean isActive() { return this.active; }
public void setActive(boolean active) { this.active = active; }
private float speed;
public float getSpeed() { return this.speed; }
public void setSpeed(float speed) { this.speed = speed; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public MCorePlayerFlyEvent(Player player, boolean allowed, boolean active, float speed)
{
this.player = player;
this.allowed = allowed;
this.active = active;
this.speed = speed;
}
public MCorePlayerFlyEvent(Player player)
{
this.player = player;
this.allowed = FlyUtil.isAllowed(player);
this.active = FlyUtil.isActive(player);
this.speed = FlyUtil.getSpeed(player);
}
}

View File

@ -24,6 +24,7 @@ public class Money
if (account == null) return null;
// ... but if something is supplied we must manage to extract an id.
// NOTE: This ID is the name for now, later all money plugins will probably support UUIDs.
String ret = MUtil.extract(String.class, "accountId", account);
if (ret == null) throw new IllegalArgumentException("extraction of accountId from object failed");
return ret;

View File

@ -1,133 +0,0 @@
package com.massivecraft.mcore.util;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import com.massivecraft.mcore.event.MCorePlayerFlyEvent;
public class FlyUtil
{
// -------------------------------------------- //
// CONSTANTS
// -------------------------------------------- //
public final static float DEFAULT_SPEED = 0.1f;
// -------------------------------------------- //
// LAST ALLOWED
// -------------------------------------------- //
public static Map<UUID, Long> idToLastActive = new HashMap<UUID, Long>();
public static Long getLastActive(Player player)
{
return idToLastActive.get(player.getUniqueId());
}
public static void setLastActive(Player player, Long millis)
{
idToLastActive.put(player.getUniqueId(), millis);
}
// -------------------------------------------- //
// UPDATE BY EVENT
// -------------------------------------------- //
public static void update(Player player)
{
MCorePlayerFlyEvent event = new MCorePlayerFlyEvent(player);
event.run();
setAllowed(player, event.isAllowed());
setActive(player, event.isActive());
setSpeed(player, event.getSpeed());
}
public static void reset(Player player)
{
setAllowed(player, player.getGameMode() == GameMode.CREATIVE);
setActive(player, player.getGameMode() == GameMode.CREATIVE);
setSpeed(player, DEFAULT_SPEED);
update(player);
}
// -------------------------------------------- //
// ALLOWED
// -------------------------------------------- //
public static boolean setAllowed(Player player, boolean allowed)
{
// NoChange
if (isAllowed(player) == allowed) return false;
// Apply
player.setFallDistance(0);
player.setAllowFlight(allowed);
player.setFallDistance(0);
// Return
return true;
}
public static boolean isAllowed(Player player)
{
return player.getAllowFlight();
}
// -------------------------------------------- //
// ACTIVE
// -------------------------------------------- //
public static boolean setActive(Player player, boolean active)
{
// Last Active Update
if (active)
{
setLastActive(player, System.currentTimeMillis());
}
// NoChange
if (isActive(player) == active) return false;
// Apply
player.setFallDistance(0);
player.setFlying(active);
player.setFallDistance(0);
// Return
return true;
}
public static boolean isActive(Player player)
{
return player.isFlying();
}
// -------------------------------------------- //
// ACTIVE
// -------------------------------------------- //
public static boolean setSpeed(Player player, float speed)
{
// NoChange
if (getSpeed(player) == speed) return false;
// Apply
player.setFallDistance(0);
player.setFlySpeed(speed);
player.setFallDistance(0);
// Return
return true;
}
public static float getSpeed(Player player)
{
return player.getFlySpeed();
}
}

View File

@ -53,6 +53,7 @@ import com.massivecraft.mcore.util.extractor.ExtractorPlayer;
import com.massivecraft.mcore.util.extractor.ExtractorPlayerName;
import com.massivecraft.mcore.util.extractor.ExtractorSender;
import com.massivecraft.mcore.util.extractor.ExtractorSenderId;
import com.massivecraft.mcore.util.extractor.ExtractorSenderName;
import com.massivecraft.mcore.util.extractor.ExtractorWorld;
import com.massivecraft.mcore.util.extractor.ExtractorWorldName;
@ -696,7 +697,9 @@ public class MUtil
registerExtractor(World.class, "world", ExtractorWorld.get());
registerExtractor(String.class, "worldName", ExtractorWorldName.get());
registerExtractor(String.class, "accountId", ExtractorSenderId.get());
// The accountId extractor is used for the money mixin.
// For now we act on the name instead of the ID since vault needs names.
registerExtractor(String.class, "accountId", ExtractorSenderName.get());
}
}

View File

@ -3,6 +3,8 @@ package com.massivecraft.mcore.util;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Bukkit;
public class PeriodUtil
{
// -------------------------------------------- //
@ -30,6 +32,31 @@ public class PeriodUtil
}
}
// -------------------------------------------- //
// TICKS STORE
// -------------------------------------------- //
private static Map<Object, Long> objectToTicks = new HashMap<Object, Long>();
public static long getTicks(Object object)
{
Long ret = objectToTicks.get(object);
if (ret == null) ret = 0L;
return ret;
}
public static void setTicks(Object object, Long ticks)
{
if (ticks == null || ticks == 0)
{
objectToTicks.remove(object);
}
else
{
objectToTicks.put(object, ticks);
}
}
// -------------------------------------------- //
// RANDOM SIMPLE
// -------------------------------------------- //
@ -51,11 +78,18 @@ public class PeriodUtil
public static boolean isNewPeriod(Object object, long length, long now)
{
// If the ticks are the same we are fine!
long currentTicks = Bukkit.getWorlds().get(0).getTime();
long lastTicks = getTicks(object);
if (currentTicks == lastTicks) return true;
// Otherwise period must be new!
long currentPeriod = getPeriod(length, now);
long lastPeriod = getLastPeriod(object, length);
if (currentPeriod == lastPeriod) return false;
// And then we log data
setTicks(object, currentTicks);
setMillis(object, now);
return true;

View File

@ -7,19 +7,26 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentSkipListSet;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.Plugin;
import com.massivecraft.mcore.EngineAbstract;
import com.massivecraft.mcore.MCore;
import com.massivecraft.mcore.event.EventMCorePlayerUpdate;
import com.massivecraft.mcore.event.MCoreAfterPlayerRespawnEvent;
import com.massivecraft.mcore.event.MCoreAfterPlayerTeleportEvent;
public class PlayerUtil implements Listener
public class PlayerUtil extends EngineAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -29,38 +36,72 @@ public class PlayerUtil implements Listener
public static PlayerUtil get() { return i; }
// -------------------------------------------- //
// FIELDS
// OVERRIDE
// -------------------------------------------- //
private static Set<String> joinedPlayerNames = new ConcurrentSkipListSet<String>(String.CASE_INSENSITIVE_ORDER);
private static Map<UUID, PlayerDeathEvent> idToDeath = new HashMap<UUID, PlayerDeathEvent>();
private static Map<UUID, Long> idToLastMoveMillis = new HashMap<UUID, Long>();
// -------------------------------------------- //
// SETUP
// -------------------------------------------- //
public void setup()
@Override
public void activate()
{
super.activate();
idToDeath.clear();
joinedPlayerNames.clear();
joinedPlayerIds.clear();
for (Player player : Bukkit.getOnlinePlayers())
{
joinedPlayerNames.add(player.getName());
joinedPlayerIds.add(player.getUniqueId());
}
idToLastMoveMillis.clear();
}
@Override
public Plugin getPlugin()
{
return MCore.get();
}
// -------------------------------------------- //
// IS JOINED
// -------------------------------------------- //
private static Set<UUID> joinedPlayerIds = new ConcurrentSkipListSet<UUID>();
@EventHandler(priority = EventPriority.MONITOR)
public void isJoined(PlayerJoinEvent event)
{
final UUID id = event.getPlayer().getUniqueId();
Bukkit.getScheduler().scheduleSyncDelayedTask(MCore.get(), new Runnable()
{
@Override
public void run()
{
joinedPlayerIds.add(id);
}
});
}
@EventHandler(priority = EventPriority.MONITOR)
public void isJoined(PlayerQuitEvent event)
{
final UUID id = event.getPlayer().getUniqueId();
joinedPlayerIds.remove(id);
}
public static boolean isJoined(Player player)
{
if (player == null) throw new NullPointerException("player was null");
final UUID id = player.getUniqueId();
return joinedPlayerIds.contains(id);
Bukkit.getPluginManager().registerEvents(this, MCore.get());
}
// -------------------------------------------- //
// LAST MOVE & STAND STILL (MILLIS)
// -------------------------------------------- //
private static Map<UUID, Long> idToLastMoveMillis = new HashMap<UUID, Long>();
public static void setLastMoveMillis(Player player, long millis)
{
if (player == null) return;
@ -72,6 +113,25 @@ public class PlayerUtil implements Listener
setLastMoveMillis(player, System.currentTimeMillis());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void setLastMoveMillis(PlayerMoveEvent event)
{
if (MUtil.isSameBlock(event)) return;
setLastMoveMillis(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void setLastMoveMillis(PlayerJoinEvent event)
{
setLastMoveMillis(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void setLastMoveMillis(PlayerChangedWorldEvent event)
{
setLastMoveMillis(event.getPlayer());
}
public static long getLastMoveMillis(Player player)
{
if (player == null) return 0;
@ -94,31 +154,14 @@ public class PlayerUtil implements Listener
return ret;
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void setLastMoveMillis(PlayerMoveEvent event)
{
if (MUtil.isSameBlock(event)) return;
setLastMoveMillis(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void setLastMoveMillis(PlayerJoinEvent event)
{
setLastMoveMillis(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void setLastMoveMillis(PlayerChangedWorldEvent event)
{
setLastMoveMillis(event.getPlayer());
}
// -------------------------------------------- //
// IS DUPLICATE DEATH EVENT
// -------------------------------------------- //
// Some times when players die the PlayerDeathEvent is fired twice.
// We want to ignore the extra calls.
private static Map<UUID, PlayerDeathEvent> idToDeath = new HashMap<UUID, PlayerDeathEvent>();
public static boolean isDuplicateDeathEvent(PlayerDeathEvent event)
{
// Prepare the lowercase name ...
@ -152,37 +195,6 @@ public class PlayerUtil implements Listener
isDuplicateDeathEvent(event);
}
// -------------------------------------------- //
// IS JOINED
// -------------------------------------------- //
@EventHandler(priority = EventPriority.MONITOR)
public void joinMonitor(PlayerJoinEvent event)
{
final String playerName = event.getPlayer().getName();
Bukkit.getScheduler().scheduleSyncDelayedTask(MCore.get(), new Runnable()
{
@Override
public void run()
{
joinedPlayerNames.add(playerName);
}
});
}
@EventHandler(priority = EventPriority.MONITOR)
public void quitMonitor(PlayerQuitEvent event)
{
final String playerName = event.getPlayer().getName();
joinedPlayerNames.remove(playerName);
}
public static boolean isJoined(Player player)
{
if (player == null) throw new NullPointerException("player was null");
return joinedPlayerNames.contains(player.getName());
}
// -------------------------------------------- //
// PACKET
// -------------------------------------------- //
@ -202,4 +214,245 @@ public class PlayerUtil implements Listener
*/
}
// -------------------------------------------- //
// SETTINGS BY EVENT
// -------------------------------------------- //
public static void update(Player player)
{
EventMCorePlayerUpdate event = new EventMCorePlayerUpdate(player);
event.run();
setMaxHealth(player, event.getMaxHealth());
setFlyAllowed(player, event.isFlyAllowed());
setFlyActive(player, event.isFlyActive());
setFlySpeed(player, event.getFlySpeed());
}
public static void reset(Player player)
{
setMaxHealth(player, getMaxHealthDefault(player));
setFlyAllowed(player, isFlyAllowedDefault(player));
setFlyActive(player, isFlyActiveDefault(player));
setFlySpeed(player, getFlySpeedDefault(player));
update(player);
}
// Can't be cancelled
@EventHandler(priority = EventPriority.LOWEST)
public void reset(PlayerJoinEvent event)
{
// If we have a player ...
Player player = event.getPlayer();
// ... and the player is alive ...
if (player.isDead()) return;
// ... trigger.
reset(player);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void update(MCoreAfterPlayerTeleportEvent event)
{
// If we have a player ...
Player player = event.getPlayer();
// ... and the player is alive ...
if (player.isDead()) return;
// ... trigger.
update(player);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void update(MCoreAfterPlayerRespawnEvent event)
{
// If we have a player ...
Player player = event.getPlayer();
// ... and the player is alive ...
if (player.isDead()) return;
// ... trigger.
update(player);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void update(PlayerChangedWorldEvent event)
{
// If we have a player ...
Player player = event.getPlayer();
// ... and the player is alive ...
if (player.isDead()) return;
// ... trigger.
update(player);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void update(PlayerMoveEvent event)
{
// If we have a player ...
Player player = event.getPlayer();
// ... and the player is alive ...
if (player.isDead()) return;
// ... and the player moved from one block to another ...
if (event.getFrom().getBlock().equals(event.getTo().getBlock())) return;
// ... trigger.
update(player);
}
// -------------------------------------------- //
// MAX HEALTH
// -------------------------------------------- //
public static boolean setMaxHealth(Player player, double maxHealth)
{
// NoChange
if (getMaxHealth(player) == maxHealth) return false;
// Apply
player.setMaxHealth(maxHealth);
// Return
return true;
}
public static double getMaxHealth(Player player)
{
return player.getMaxHealth();
}
public static double getMaxHealthDefault(Player player)
{
return 20D;
}
// -------------------------------------------- //
// FLY: ALLOWED
// -------------------------------------------- //
public static boolean setFlyAllowed(Player player, boolean allowed)
{
// NoChange
if (isFlyAllowed(player) == allowed) return false;
// Apply
player.setFallDistance(0);
player.setAllowFlight(allowed);
player.setFallDistance(0);
// Return
return true;
}
public static boolean isFlyAllowed(Player player)
{
return player.getAllowFlight();
}
public static boolean isFlyAllowedDefault(Player player)
{
return player.getGameMode() == GameMode.CREATIVE;
}
// -------------------------------------------- //
// FLY: ACTIVE
// -------------------------------------------- //
public static Map<UUID, Long> idToLastFlyActive = new HashMap<UUID, Long>();
public static Long getLastFlyActive(Player player)
{
return idToLastFlyActive.get(player.getUniqueId());
}
public static void setLastFlyActive(Player player, Long millis)
{
idToLastFlyActive.put(player.getUniqueId(), millis);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void negateNoCheatPlusBug(EntityDamageEvent event)
{
// If a player ...
if ( ! (event.getEntity() instanceof Player)) return;
Player player = (Player)event.getEntity();
// ... is taking fall damage ...
if (event.getCause() != DamageCause.FALL) return;
// ... within 2 seconds of flying ...
Long lastActive = getLastFlyActive(player);
if (lastActive == null) return;
if (System.currentTimeMillis() - lastActive > 2000) return;
// ... cancel the event.
event.setCancelled(true);
}
public static boolean setFlyActive(Player player, boolean active)
{
// Last Active Update
if (active)
{
setLastFlyActive(player, System.currentTimeMillis());
}
// NoChange
if (isFlyActive(player) == active) return false;
// Apply
player.setFallDistance(0);
player.setFlying(active);
player.setFallDistance(0);
// Return
return true;
}
public static boolean isFlyActive(Player player)
{
return player.isFlying();
}
public static boolean isFlyActiveDefault(Player player)
{
return player.getGameMode() == GameMode.CREATIVE;
}
// -------------------------------------------- //
// FLY: SPEED
// -------------------------------------------- //
public final static float DEFAULT_FLY_SPEED = 0.1f;
public static boolean setFlySpeed(Player player, float speed)
{
// NoChange
if (getFlySpeed(player) == speed) return false;
// Apply
player.setFallDistance(0);
player.setFlySpeed(speed);
player.setFallDistance(0);
// Return
return true;
}
public static float getFlySpeed(Player player)
{
return player.getFlySpeed();
}
public static float getFlySpeedDefault(Player player)
{
return DEFAULT_FLY_SPEED;
}
}

View File

@ -86,6 +86,17 @@ public class ExtractorLogic
return null;
}
// -------------------------------------------- //
// PLAYER
// -------------------------------------------- //
public static Player playerFromObject(Object o)
{
CommandSender sender = senderFromObject(o);
if (sender instanceof Player) return (Player)sender;
return null;
}
// -------------------------------------------- //
// SENDER ID
// -------------------------------------------- //
@ -104,14 +115,20 @@ public class ExtractorLogic
}
// -------------------------------------------- //
// PLAYER
// SENDER NAME
// -------------------------------------------- //
public static Player playerFromObject(Object o)
public static String senderNameFromObject(Object o)
{
if (o == null) return null;
String name = IdUtil.getName(o);
if (name != null) return name;
CommandSender sender = senderFromObject(o);
if (sender instanceof Player) return (Player)sender;
return null;
if (sender == null) return null;
return IdUtil.getName(sender);
}
// -------------------------------------------- //
@ -120,7 +137,7 @@ public class ExtractorLogic
public static String playerNameFromObject(Object o)
{
String senderId = senderIdFromObject(o);
String senderId = senderNameFromObject(o);
//if (SenderUtil.isPlayerId(senderId)) return senderId;
//return null;
return senderId;

View File

@ -0,0 +1,22 @@
package com.massivecraft.mcore.util.extractor;
public class ExtractorSenderName implements Extractor
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static ExtractorSenderName i = new ExtractorSenderName();
public static ExtractorSenderName get() { return i; }
// -------------------------------------------- //
// OVERRIDE: EXTRACTOR
// -------------------------------------------- //
@Override
public Object extract(Object o)
{
return ExtractorLogic.senderNameFromObject(o);
}
}