Minecraft 1.7.9 support and UUID oriented.
This commit is contained in:
parent
9fdf1b1235
commit
6b2332c162
@ -11,6 +11,7 @@ permissions:
|
|||||||
# -------------------------------------------- #
|
# -------------------------------------------- #
|
||||||
# cmd
|
# cmd
|
||||||
mcore.basecommand: {description: use the MCore base command, default: false}
|
mcore.basecommand: {description: use the MCore base command, default: false}
|
||||||
|
mcore.test: {description: run developer test, default: false}
|
||||||
mcore.id: {description: see the server id, default: false}
|
mcore.id: {description: see the server id, default: false}
|
||||||
mcore.version: {description: diplay plugin version, default: false}
|
mcore.version: {description: diplay plugin version, default: false}
|
||||||
mcore.hearsound: {description: hear a sound, default: false}
|
mcore.hearsound: {description: hear a sound, default: false}
|
||||||
@ -43,6 +44,7 @@ permissions:
|
|||||||
default: false
|
default: false
|
||||||
children:
|
children:
|
||||||
mcore.basecommand: true
|
mcore.basecommand: true
|
||||||
|
mcore.test: true
|
||||||
mcore.id: true
|
mcore.id: true
|
||||||
mcore.version: true
|
mcore.version: true
|
||||||
mcore.hearsound: true
|
mcore.hearsound: true
|
||||||
|
@ -6,9 +6,9 @@ import java.util.Map;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Server;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.SimpleCommandMap;
|
import org.bukkit.command.SimpleCommandMap;
|
||||||
import org.bukkit.craftbukkit.v1_7_R3.CraftServer;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.massivecraft.mcore.cmd.MCommand;
|
import com.massivecraft.mcore.cmd.MCommand;
|
||||||
@ -103,14 +103,10 @@ public class EngineCommandRegistration extends EngineAbstract
|
|||||||
// GETTERS
|
// GETTERS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static CraftServer getCraftServer()
|
|
||||||
{
|
|
||||||
return (CraftServer)Bukkit.getServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SimpleCommandMap getSimpleCommandMap()
|
public static SimpleCommandMap getSimpleCommandMap()
|
||||||
{
|
{
|
||||||
return getCraftServer().getCommandMap();
|
Server server = Bukkit.getServer();
|
||||||
|
return (SimpleCommandMap) get(server.getClass(), "commandMap", server);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -15,6 +15,7 @@ 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.entity.EntityDamageByBlockEvent;
|
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerKickEvent;
|
import org.bukkit.event.player.PlayerKickEvent;
|
||||||
@ -22,6 +23,7 @@ import org.bukkit.event.player.PlayerLoginEvent;
|
|||||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||||
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
@ -40,7 +42,8 @@ import com.massivecraft.mcore.event.MCoreSenderUnregisterEvent;
|
|||||||
import com.massivecraft.mcore.mixin.Mixin;
|
import com.massivecraft.mcore.mixin.Mixin;
|
||||||
import com.massivecraft.mcore.store.Coll;
|
import com.massivecraft.mcore.store.Coll;
|
||||||
import com.massivecraft.mcore.store.SenderColl;
|
import com.massivecraft.mcore.store.SenderColl;
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.FlyUtil;
|
||||||
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
import com.massivecraft.mcore.util.SmokeUtil;
|
import com.massivecraft.mcore.util.SmokeUtil;
|
||||||
import com.massivecraft.mcore.util.Txt;
|
import com.massivecraft.mcore.util.Txt;
|
||||||
|
|
||||||
@ -70,6 +73,45 @@ public class EngineMainMCore extends EngineAbstract
|
|||||||
MCorePlayerLeaveEvent.player2event.clear();
|
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
|
// RECIPIENT CHAT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -147,14 +189,14 @@ public class EngineMainMCore extends EngineAbstract
|
|||||||
Set<String> current = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
Set<String> current = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||||
current.addAll(event.getTabCompletions());
|
current.addAll(event.getTabCompletions());
|
||||||
|
|
||||||
// Add ids of all online senders that match and isn't added yet.
|
// Add names of all online senders that match and isn't added yet.
|
||||||
for (String senderId : Mixin.getOnlineSenderIds())
|
for (String senderName : IdUtil.getOnlineNames())
|
||||||
{
|
{
|
||||||
if (!senderId.toLowerCase().startsWith(tokenlc)) continue;
|
if (!senderName.toLowerCase().startsWith(tokenlc)) continue;
|
||||||
if (current.contains(senderId)) continue;
|
if (current.contains(senderName)) continue;
|
||||||
if (!Mixin.canSee(watcher, senderId)) continue;
|
if (!Mixin.canSee(watcher, senderName)) continue;
|
||||||
|
|
||||||
event.getTabCompletions().add(senderId);
|
event.getTabCompletions().add(senderName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,52 +271,54 @@ public class EngineMainMCore extends EngineAbstract
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// PLAYER AND SENDER REFERENCES
|
// PLAYER AND SENDER REFERENCES
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
// Note: For now we update both names and ids.
|
||||||
|
// That way collections in plugins that haven't yet undergone update will still work.
|
||||||
|
|
||||||
|
public static void setSenderReferences(CommandSender sender, CommandSender reference)
|
||||||
|
{
|
||||||
|
String id = IdUtil.getId(sender);
|
||||||
|
if (id != null)
|
||||||
|
{
|
||||||
|
SenderColl.setSenderReferences(id, reference);
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = IdUtil.getName(sender);
|
||||||
|
if (name != null)
|
||||||
|
{
|
||||||
|
SenderColl.setSenderReferences(name, reference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void senderReferencesLoginLowest(PlayerLoginEvent event)
|
public void setSenderReferencesLoginLowest(PlayerLoginEvent event)
|
||||||
{
|
{
|
||||||
String id = SenderUtil.getSenderId(event.getPlayer());
|
setSenderReferences(event.getPlayer(), event.getPlayer());
|
||||||
CommandSender sender = event.getPlayer();
|
|
||||||
|
|
||||||
SenderColl.setSenderRefferences(id, sender);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void senderReferencesLoginMonitor(PlayerLoginEvent event)
|
public void setSenderReferencesLoginMonitor(PlayerLoginEvent event)
|
||||||
{
|
{
|
||||||
if (event.getResult() == Result.ALLOWED) return;
|
if (event.getResult() == Result.ALLOWED) return;
|
||||||
|
|
||||||
String id = SenderUtil.getSenderId(event.getPlayer());
|
setSenderReferences(event.getPlayer(), null);
|
||||||
CommandSender sender = null;
|
|
||||||
|
|
||||||
SenderColl.setSenderRefferences(id, sender);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void senderReferencesQuitMonitor(PlayerQuitEvent event)
|
public void setSenderReferencesQuitMonitor(PlayerQuitEvent event)
|
||||||
{
|
{
|
||||||
String id = SenderUtil.getSenderId(event.getPlayer());
|
setSenderReferences(event.getPlayer(), null);
|
||||||
CommandSender sender = null;
|
|
||||||
|
|
||||||
SenderColl.setSenderRefferences(id, sender);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void senderReferencesRegisterMonitor(MCoreSenderRegisterEvent event)
|
public void setSenderReferencesRegisterMonitor(MCoreSenderRegisterEvent event)
|
||||||
{
|
{
|
||||||
String id = SenderUtil.getSenderId(event.getSender());
|
setSenderReferences(event.getSender(), event.getSender());
|
||||||
CommandSender sender = event.getSender();
|
|
||||||
|
|
||||||
SenderColl.setSenderRefferences(id, sender);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void senderReferencesUnregisterMonitor(MCoreSenderUnregisterEvent event)
|
public void setSenderReferencesUnregisterMonitor(MCoreSenderUnregisterEvent event)
|
||||||
{
|
{
|
||||||
String id = SenderUtil.getSenderId(event.getSender());
|
setSenderReferences(event.getSender(), null);
|
||||||
CommandSender sender = null;
|
|
||||||
|
|
||||||
SenderColl.setSenderRefferences(id, sender);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -372,12 +416,15 @@ public class EngineMainMCore extends EngineAbstract
|
|||||||
|
|
||||||
public void syncAllForPlayer(Player player)
|
public void syncAllForPlayer(Player player)
|
||||||
{
|
{
|
||||||
|
// TODO: For now we sync them both!
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
|
String playerId = player.getUniqueId().toString();
|
||||||
for (Coll<?> coll : Coll.getInstances())
|
for (Coll<?> coll : Coll.getInstances())
|
||||||
{
|
{
|
||||||
if (!(coll instanceof SenderColl)) continue;
|
if (!(coll instanceof SenderColl)) continue;
|
||||||
SenderColl<?> pcoll = (SenderColl<?>)coll;
|
SenderColl<?> pcoll = (SenderColl<?>)coll;
|
||||||
pcoll.syncId(playerName);
|
pcoll.syncId(playerName);
|
||||||
|
pcoll.syncId(playerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.massivecraft.mcore;
|
package com.massivecraft.mcore;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -19,19 +19,21 @@ import com.massivecraft.mcore.adapter.ModdedEnumTypeAdapter;
|
|||||||
import com.massivecraft.mcore.adapter.ObjectIdAdapter;
|
import com.massivecraft.mcore.adapter.ObjectIdAdapter;
|
||||||
import com.massivecraft.mcore.adapter.PlayerInventoryAdapter;
|
import com.massivecraft.mcore.adapter.PlayerInventoryAdapter;
|
||||||
import com.massivecraft.mcore.adapter.UUIDAdapter;
|
import com.massivecraft.mcore.adapter.UUIDAdapter;
|
||||||
|
import com.massivecraft.mcore.event.MCoreUuidUpdateEvent;
|
||||||
|
import com.massivecraft.mcore.fetcher.Fetcher;
|
||||||
|
import com.massivecraft.mcore.fetcher.IdAndName;
|
||||||
import com.massivecraft.mcore.integration.protocollib.ProtocolLibFeatures;
|
import com.massivecraft.mcore.integration.protocollib.ProtocolLibFeatures;
|
||||||
import com.massivecraft.mcore.integration.vault.VaultFeatures;
|
import com.massivecraft.mcore.integration.vault.VaultFeatures;
|
||||||
import com.massivecraft.mcore.mcorecmd.CmdMCore;
|
import com.massivecraft.mcore.mcorecmd.CmdMCore;
|
||||||
import com.massivecraft.mcore.mcorecmd.CmdMCoreMStore;
|
import com.massivecraft.mcore.mcorecmd.CmdMCoreMStore;
|
||||||
import com.massivecraft.mcore.mcorecmd.CmdMCoreUsys;
|
import com.massivecraft.mcore.mcorecmd.CmdMCoreUsys;
|
||||||
import com.massivecraft.mcore.mixin.SenderIdMixinDefault;
|
|
||||||
import com.massivecraft.mcore.mixin.EngineTeleportMixinCause;
|
import com.massivecraft.mcore.mixin.EngineTeleportMixinCause;
|
||||||
import com.massivecraft.mcore.ps.PS;
|
import com.massivecraft.mcore.ps.PS;
|
||||||
import com.massivecraft.mcore.ps.PSAdapter;
|
import com.massivecraft.mcore.ps.PSAdapter;
|
||||||
import com.massivecraft.mcore.store.Coll;
|
import com.massivecraft.mcore.store.Coll;
|
||||||
import com.massivecraft.mcore.store.ExamineThread;
|
import com.massivecraft.mcore.store.ExamineThread;
|
||||||
import com.massivecraft.mcore.teleport.EngineScheduledTeleport;
|
import com.massivecraft.mcore.teleport.EngineScheduledTeleport;
|
||||||
import com.massivecraft.mcore.util.MUtil;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
import com.massivecraft.mcore.util.PlayerUtil;
|
import com.massivecraft.mcore.util.PlayerUtil;
|
||||||
import com.massivecraft.mcore.util.Txt;
|
import com.massivecraft.mcore.util.Txt;
|
||||||
import com.massivecraft.mcore.xlib.bson.types.ObjectId;
|
import com.massivecraft.mcore.xlib.bson.types.ObjectId;
|
||||||
@ -120,9 +122,20 @@ public class MCore extends MPlugin
|
|||||||
// OVERRIDE
|
// OVERRIDE
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public boolean doderp = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
doderp = true;
|
||||||
|
}
|
||||||
|
}, 20);
|
||||||
|
|
||||||
// This is safe since all plugins using Persist should bukkit-depend this plugin.
|
// This is safe since all plugins using Persist should bukkit-depend this plugin.
|
||||||
// Note this one must be before preEnable. dooh.
|
// Note this one must be before preEnable. dooh.
|
||||||
// TODO: Create something like "deinit all" (perhaps a forloop) to readd this.
|
// TODO: Create something like "deinit all" (perhaps a forloop) to readd this.
|
||||||
@ -140,8 +153,8 @@ public class MCore extends MPlugin
|
|||||||
// Setup the default database
|
// Setup the default database
|
||||||
//db = MStore.getDb(ConfServer.dburi);
|
//db = MStore.getDb(ConfServer.dburi);
|
||||||
|
|
||||||
// Setup PlayerUtil and it's events
|
// Setup IdUtil
|
||||||
SenderIdMixinDefault.get().setup();
|
IdUtil.setup();
|
||||||
|
|
||||||
// Register events
|
// Register events
|
||||||
EngineMainMCore.get().activate();
|
EngineMainMCore.get().activate();
|
||||||
@ -158,7 +171,6 @@ public class MCore extends MPlugin
|
|||||||
MultiverseColl.get().init();
|
MultiverseColl.get().init();
|
||||||
AspectColl.get().init();
|
AspectColl.get().init();
|
||||||
MCoreConfColl.get().init();
|
MCoreConfColl.get().init();
|
||||||
MCoreMPlayerColl.get().init();
|
|
||||||
|
|
||||||
// Register commands
|
// Register commands
|
||||||
this.outerCmdMCore = new CmdMCore() { public List<String> getAliases() { return MCoreConf.get().aliasesOuterMCore; } };
|
this.outerCmdMCore = new CmdMCore() { public List<String> getAliases() { return MCoreConf.get().aliasesOuterMCore; } };
|
||||||
@ -180,18 +192,32 @@ public class MCore extends MPlugin
|
|||||||
TaskDeleteFiles.get().run();
|
TaskDeleteFiles.get().run();
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, TaskDeleteFiles.get());
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this, TaskDeleteFiles.get());
|
||||||
|
|
||||||
//test();
|
// test();
|
||||||
|
|
||||||
// Schedule fetch all
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
PlayerUtil.fetchAllIds();
|
log(Txt.parse("<a>============================================"));
|
||||||
|
log(Txt.parse("<i>We are preparing for Mojangs switch to UUIDs."));
|
||||||
|
log(Txt.parse("<i>Learn more at: <aqua>https://forums.bukkit.org/threads/psa-the-switch-to-uuids-potential-plugin-server-breakage.250915/"));
|
||||||
|
|
||||||
|
// TODO: NOTE!!! IMPORTANT EVEN LATER!
|
||||||
|
IdUtil.loadDatas();
|
||||||
|
|
||||||
|
log(Txt.parse("<i>Now updating database for plugins that are ready ..."));
|
||||||
|
|
||||||
|
MCoreUuidUpdateEvent event = new MCoreUuidUpdateEvent();
|
||||||
|
event.run();
|
||||||
|
|
||||||
|
log(Txt.parse("<g> ... done!"));
|
||||||
|
log(Txt.parse("<i>(database saving will now commence which might lock the server for a while)"));
|
||||||
|
log(Txt.parse("<a>============================================"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
this.postEnable();
|
this.postEnable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,16 +230,59 @@ public class MCore extends MPlugin
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// whatever you feel like
|
// whatever you feel like
|
||||||
for (int i = 0; i <= 1; i++)
|
List<Object> objects = new ArrayList<Object>();
|
||||||
|
|
||||||
|
//objects.add("Cayorion");
|
||||||
|
objects.add("a2cce16b-9494-45ff-b5ff-0362ca687d4e");
|
||||||
|
|
||||||
|
//objects.add("a2cce16b-9494-45ff-b5ff-0362ca687d4a");
|
||||||
|
|
||||||
|
objects.add("hnnn");
|
||||||
|
objects.add("hnnnbsarc");
|
||||||
|
|
||||||
|
objects.add("NOT EVEN LEGIT");
|
||||||
|
|
||||||
|
objects.add("MonMarty");
|
||||||
|
objects.add("Thortuna");
|
||||||
|
objects.add("yendor46");
|
||||||
|
objects.add("Gethelp");
|
||||||
|
objects.add("Th3_Drunk_Monk");
|
||||||
|
objects.add("Ryciera");
|
||||||
|
objects.add("Jamescl");
|
||||||
|
objects.add("spectec");
|
||||||
|
objects.add("Tom1804");
|
||||||
|
objects.add("imboring56");
|
||||||
|
objects.add("BigBellyBuddah");
|
||||||
|
objects.add("MrHappyTinkles");
|
||||||
|
objects.add("BabaManga");
|
||||||
|
objects.add("_Omnomivore_");
|
||||||
|
objects.add("Cielian");
|
||||||
|
objects.add("BboyMVB");
|
||||||
|
objects.add("MrWackeo");
|
||||||
|
objects.add("Kellock93");
|
||||||
|
objects.add("Feykronos");
|
||||||
|
objects.add("Unluvable");
|
||||||
|
objects.add("DanyWood");
|
||||||
|
objects.add("jadex224");
|
||||||
|
objects.add("MinecraftSpartan");
|
||||||
|
objects.add("ravenwolfthorn");
|
||||||
|
objects.add("ELtongo");
|
||||||
|
objects.add("Azas");
|
||||||
|
objects.add("TazeHD");
|
||||||
|
objects.add("BillyA835");
|
||||||
|
objects.add("duhsigil");
|
||||||
|
objects.add("Sahrotaar");
|
||||||
|
objects.add("Alj23");
|
||||||
|
|
||||||
|
Set<IdAndName> idAndNames = Fetcher.fetch(objects);
|
||||||
|
|
||||||
|
// Map<String, UUID> map = PlayerUtil.getPlayerIds(MUtil.list("Cayorion", "MonMarty", "Thortuna", "yendor46", "Gethelp", "Th3_Drunk_Monk", "Ryciera", "Jamescl", "spectec", "Tom1804", "imboring56", "BigBellyBuddah", "MrHappyTinkles", "BabaManga", "_Omnomivore_", "Cielian", "BboyMVB", "MrWackeo", "Kellock93", "Feykronos", "Unluvable", "DanyWood", "jadex224", "MinecraftSpartan", "ravenwolfthorn", "ELtongo", "Azas", "TazeHD", "BillyA835", "duhsigil", "Sahrotaar", "Alj23"));
|
||||||
|
|
||||||
|
for (IdAndName idAndName: idAndNames)
|
||||||
{
|
{
|
||||||
Map<String, UUID> map = PlayerUtil.getPlayerIds(MUtil.list("Cayorion", "MonMarty", "Thortuna", "yendor46", "Gethelp", "Th3_Drunk_Monk", "Ryciera", "Jamescl", "spectec", "Tom1804", "imboring56", "BigBellyBuddah", "MrHappyTinkles", "BabaManga", "_Omnomivore_", "Cielian", "BboyMVB", "MrWackeo", "Kellock93", "Feykronos", "Unluvable", "DanyWood", "jadex224", "MinecraftSpartan", "ravenwolfthorn", "ELtongo", "Azas", "TazeHD", "BillyA835", "duhsigil", "Sahrotaar", "Alj23"));
|
String name = idAndName.getName();
|
||||||
for (Entry<String, UUID> entry : map.entrySet())
|
UUID id = idAndName.getId();
|
||||||
{
|
log(Txt.parse("<k>%s <v>%s", name, id));
|
||||||
String playerName = entry.getKey();
|
|
||||||
UUID playerId = entry.getValue();
|
|
||||||
log(Txt.parse("<k>%s <v>%s", playerName, playerId.toString()));
|
|
||||||
}
|
|
||||||
log("===========================");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -232,6 +301,7 @@ public class MCore extends MPlugin
|
|||||||
super.onDisable();
|
super.onDisable();
|
||||||
ExamineThread.get().interrupt();
|
ExamineThread.get().interrupt();
|
||||||
TaskDeleteFiles.get().run();
|
TaskDeleteFiles.get().run();
|
||||||
|
IdUtil.saveCachefileDatas();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
package com.massivecraft.mcore;
|
|
||||||
|
|
||||||
import com.massivecraft.mcore.store.Entity;
|
|
||||||
|
|
||||||
public class MCoreMPlayer extends Entity<MCoreMPlayer>
|
|
||||||
{
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// META
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static MCoreMPlayer get(Object oid)
|
|
||||||
{
|
|
||||||
return MCoreMPlayerColl.get().get(oid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MCoreMPlayer get(Object oid, boolean creative)
|
|
||||||
{
|
|
||||||
return MCoreMPlayerColl.get().get(oid, creative);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// OVERRIDE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MCoreMPlayer load(MCoreMPlayer that)
|
|
||||||
{
|
|
||||||
this.name = that.name;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDefault()
|
|
||||||
{
|
|
||||||
if (this.name != null) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// FIELDS
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
private String name = null;
|
|
||||||
public String getName() { return this.name; }
|
|
||||||
public void setName(String name)
|
|
||||||
{
|
|
||||||
this.name = name;
|
|
||||||
if (!this.attached()) return;
|
|
||||||
MCoreMPlayerColl.get().getIndexName().update(this, name);
|
|
||||||
this.changed();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,91 +0,0 @@
|
|||||||
package com.massivecraft.mcore;
|
|
||||||
|
|
||||||
import java.util.TreeMap;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.massivecraft.mcore.store.Coll;
|
|
||||||
import com.massivecraft.mcore.store.IndexUniqueField;
|
|
||||||
import com.massivecraft.mcore.store.MStore;
|
|
||||||
import com.massivecraft.mcore.util.MUtil;
|
|
||||||
|
|
||||||
public class MCoreMPlayerColl extends Coll<MCoreMPlayer>
|
|
||||||
{
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// INSTANCE & CONSTRUCT
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
private static MCoreMPlayerColl i = new MCoreMPlayerColl();
|
|
||||||
public static MCoreMPlayerColl get() { return i; }
|
|
||||||
public MCoreMPlayerColl()
|
|
||||||
{
|
|
||||||
super("mcore_mplayer", MCoreMPlayer.class, MStore.getDb(), MCore.get(), false, false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// FIELD
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
private IndexUniqueField<String, MCoreMPlayer> indexName = new IndexUniqueField<String, MCoreMPlayer>(new TreeMap<String, MCoreMPlayer>(String.CASE_INSENSITIVE_ORDER));
|
|
||||||
public IndexUniqueField<String, MCoreMPlayer> getIndexName() { return this.indexName; }
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// OVERRIDE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postAttach(MCoreMPlayer entity, String id)
|
|
||||||
{
|
|
||||||
super.postAttach(entity, id);
|
|
||||||
this.getIndexName().update(entity, entity.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postDetach(MCoreMPlayer entity, String id)
|
|
||||||
{
|
|
||||||
super.postDetach(entity, id);
|
|
||||||
this.getIndexName().removeObject(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String fixId(Object oid)
|
|
||||||
{
|
|
||||||
if (oid == null) return null;
|
|
||||||
|
|
||||||
if (oid instanceof MCoreMPlayer)
|
|
||||||
{
|
|
||||||
return this.entity2id.get(oid);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oid instanceof String)
|
|
||||||
{
|
|
||||||
String string = (String)oid;
|
|
||||||
string = string.toLowerCase();
|
|
||||||
|
|
||||||
// Handle Player Name
|
|
||||||
if (MUtil.isValidPlayerName(string))
|
|
||||||
{
|
|
||||||
MCoreMPlayer mplayer = this.getIndexName().getObject(string);
|
|
||||||
if (mplayer != null) return mplayer.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oid instanceof UUID)
|
|
||||||
{
|
|
||||||
UUID uuid = (UUID)oid;
|
|
||||||
return uuid.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oid instanceof Player)
|
|
||||||
{
|
|
||||||
Player player = (Player)oid;
|
|
||||||
return player.getUniqueId().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -11,6 +11,7 @@ public enum MCorePerm
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
BASECOMMAND("basecommand"),
|
BASECOMMAND("basecommand"),
|
||||||
|
TEST("test"),
|
||||||
ID("id"),
|
ID("id"),
|
||||||
VERSION("version"),
|
VERSION("version"),
|
||||||
HEARSOUND("hearsound"),
|
HEARSOUND("hearsound"),
|
||||||
|
@ -450,34 +450,34 @@ public class MCommand
|
|||||||
|
|
||||||
public boolean sendMessage(String message)
|
public boolean sendMessage(String message)
|
||||||
{
|
{
|
||||||
return Mixin.message(this.sender, message);
|
return Mixin.messageOne(this.sender, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean sendMessage(String... messages)
|
public boolean sendMessage(String... messages)
|
||||||
{
|
{
|
||||||
return Mixin.message(this.sender, messages);
|
return Mixin.messageOne(this.sender, messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean sendMessage(Collection<String> messages)
|
public boolean sendMessage(Collection<String> messages)
|
||||||
{
|
{
|
||||||
return Mixin.message(this.sender, messages);
|
return Mixin.messageOne(this.sender, messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CONVENIENCE MSG
|
// CONVENIENCE MSG
|
||||||
|
|
||||||
public boolean msg(String msg)
|
public boolean msg(String msg)
|
||||||
{
|
{
|
||||||
return Mixin.msg(this.sender, msg);
|
return Mixin.msgOne(this.sender, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean msg(String msg, Object... args)
|
public boolean msg(String msg, Object... args)
|
||||||
{
|
{
|
||||||
return Mixin.msg(this.sender, msg, args);
|
return Mixin.msgOne(this.sender, msg, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean msg(Collection<String> msgs)
|
public boolean msg(Collection<String> msgs)
|
||||||
{
|
{
|
||||||
return Mixin.msg(this.sender, msgs);
|
return Mixin.msgOne(this.sender, msgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -10,6 +10,7 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import com.massivecraft.mcore.mixin.Mixin;
|
import com.massivecraft.mcore.mixin.Mixin;
|
||||||
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
import com.massivecraft.mcore.util.Txt;
|
import com.massivecraft.mcore.util.Txt;
|
||||||
|
|
||||||
public class MCoreBukkitCommand extends Command
|
public class MCoreBukkitCommand extends Command
|
||||||
@ -83,12 +84,12 @@ public class MCoreBukkitCommand extends Command
|
|||||||
|
|
||||||
String tokenlc = args[args.length - 1].toLowerCase();
|
String tokenlc = args[args.length - 1].toLowerCase();
|
||||||
|
|
||||||
// Add ids of all online senders that match and isn't added yet.
|
// Add names of all online senders that match and isn't added yet.
|
||||||
for (String senderId : Mixin.getOnlineSenderIds())
|
for (String senderName : IdUtil.getOnlineNames())
|
||||||
{
|
{
|
||||||
if (!senderId.toLowerCase().startsWith(tokenlc)) continue;
|
if (!senderName.toLowerCase().startsWith(tokenlc)) continue;
|
||||||
if (!Mixin.canSee(sender, senderId)) continue;
|
if (!Mixin.canSee(sender, senderName)) continue;
|
||||||
ret.add(senderId);
|
ret.add(senderName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ArrayList<String>(ret);
|
return new ArrayList<String>(ret);
|
||||||
|
@ -4,7 +4,7 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import com.massivecraft.mcore.store.SenderIdSource;
|
import com.massivecraft.mcore.store.SenderIdSource;
|
||||||
import com.massivecraft.mcore.store.SenderIdSourceMixinAllSenderIds;
|
import com.massivecraft.mcore.store.SenderIdSourceMixinAllSenderIds;
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public class ARPlayer extends ARSenderIdAbstractPredsource<Player>
|
public class ARPlayer extends ARSenderIdAbstractPredsource<Player>
|
||||||
{
|
{
|
||||||
@ -40,7 +40,7 @@ public class ARPlayer extends ARSenderIdAbstractPredsource<Player>
|
|||||||
@Override
|
@Override
|
||||||
public Player getResultForSenderId(String senderId)
|
public Player getResultForSenderId(String senderId)
|
||||||
{
|
{
|
||||||
return SenderUtil.getPlayer(senderId);
|
return IdUtil.getPlayer(senderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
|
|
||||||
import com.massivecraft.mcore.store.SenderIdSource;
|
import com.massivecraft.mcore.store.SenderIdSource;
|
||||||
import com.massivecraft.mcore.store.SenderIdSourceMixinAllSenderIds;
|
import com.massivecraft.mcore.store.SenderIdSourceMixinAllSenderIds;
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public class ARSender extends ARSenderIdAbstractPredsource<CommandSender>
|
public class ARSender extends ARSenderIdAbstractPredsource<CommandSender>
|
||||||
{
|
{
|
||||||
@ -20,12 +20,12 @@ public class ARSender extends ARSenderIdAbstractPredsource<CommandSender>
|
|||||||
|
|
||||||
public static ARSender getFull(SenderIdSource source)
|
public static ARSender getFull(SenderIdSource source)
|
||||||
{
|
{
|
||||||
return new ARSender(source, "sender", ArgPredictateStringEqualsLC.get());
|
return new ARSender(source, "player", ArgPredictateStringEqualsLC.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ARSender getStart(SenderIdSource source)
|
public static ARSender getStart(SenderIdSource source)
|
||||||
{
|
{
|
||||||
return new ARSender(source, "sender", ArgPredictateStringStartsLC.get());
|
return new ARSender(source, "player", ArgPredictateStringStartsLC.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ARSender(SenderIdSource source, String typename, ArgPredictate<String> argPredictate)
|
private ARSender(SenderIdSource source, String typename, ArgPredictate<String> argPredictate)
|
||||||
@ -40,7 +40,7 @@ public class ARSender extends ARSenderIdAbstractPredsource<CommandSender>
|
|||||||
@Override
|
@Override
|
||||||
public CommandSender getResultForSenderId(String senderId)
|
public CommandSender getResultForSenderId(String senderId)
|
||||||
{
|
{
|
||||||
return SenderUtil.getSender(senderId);
|
return IdUtil.getSender(senderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.massivecraft.mcore.cmd.arg;
|
|||||||
import com.massivecraft.mcore.store.SenderColl;
|
import com.massivecraft.mcore.store.SenderColl;
|
||||||
import com.massivecraft.mcore.store.SenderEntity;
|
import com.massivecraft.mcore.store.SenderEntity;
|
||||||
import com.massivecraft.mcore.store.SenderIdSource;
|
import com.massivecraft.mcore.store.SenderIdSource;
|
||||||
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public class ARSenderEntity<T extends SenderEntity<T>> extends ARSenderIdAbstractPredsource<T>
|
public class ARSenderEntity<T extends SenderEntity<T>> extends ARSenderIdAbstractPredsource<T>
|
||||||
{
|
{
|
||||||
@ -57,6 +58,12 @@ public class ARSenderEntity<T extends SenderEntity<T>> extends ARSenderIdAbstrac
|
|||||||
@Override
|
@Override
|
||||||
public T getResultForSenderId(String senderId)
|
public T getResultForSenderId(String senderId)
|
||||||
{
|
{
|
||||||
|
if (senderId == null) return null;
|
||||||
|
|
||||||
|
// Convert names to ids so we can handle both
|
||||||
|
String betterId = IdUtil.getId(senderId);
|
||||||
|
if (betterId != null) return this.coll.get(betterId);
|
||||||
|
|
||||||
return this.coll.get(senderId);
|
return this.coll.get(senderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package com.massivecraft.mcore.cmd.arg;
|
|||||||
|
|
||||||
import com.massivecraft.mcore.store.SenderIdSource;
|
import com.massivecraft.mcore.store.SenderIdSource;
|
||||||
import com.massivecraft.mcore.store.SenderIdSourceMixinAllSenderIds;
|
import com.massivecraft.mcore.store.SenderIdSourceMixinAllSenderIds;
|
||||||
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public class ARSenderId extends ARSenderIdAbstractPredsource<String>
|
public class ARSenderId extends ARSenderIdAbstractPredsource<String>
|
||||||
{
|
{
|
||||||
@ -37,6 +38,12 @@ public class ARSenderId extends ARSenderIdAbstractPredsource<String>
|
|||||||
@Override
|
@Override
|
||||||
public String getResultForSenderId(String senderId)
|
public String getResultForSenderId(String senderId)
|
||||||
{
|
{
|
||||||
|
if (senderId == null) return null;
|
||||||
|
|
||||||
|
// Convert names to ids so we can handle both
|
||||||
|
String betterId = IdUtil.getId(senderId);
|
||||||
|
if (betterId != null) return betterId;
|
||||||
|
|
||||||
return senderId;
|
return senderId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import java.util.Collection;
|
|||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import com.massivecraft.mcore.mixin.Mixin;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
import com.massivecraft.mcore.util.Txt;
|
import com.massivecraft.mcore.util.Txt;
|
||||||
|
|
||||||
public abstract class ARSenderIdAbstract<T> extends ArgReaderAbstract<T>
|
public abstract class ARSenderIdAbstract<T> extends ArgReaderAbstract<T>
|
||||||
@ -50,13 +50,13 @@ public abstract class ARSenderIdAbstract<T> extends ArgReaderAbstract<T>
|
|||||||
else if (senderIds.contains(arg))
|
else if (senderIds.contains(arg))
|
||||||
{
|
{
|
||||||
// Exact match
|
// Exact match
|
||||||
String senderId = Mixin.tryFix(arg);
|
String senderId = IdUtil.getName(arg);
|
||||||
ret.setResult(this.getResultForSenderId(senderId));
|
ret.setResult(this.getResultForSenderId(senderId));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Ambigious!
|
// Ambigious!
|
||||||
ret.getErrors().add("<b>Online "+this.getTypename()+" matching \"<h>"+arg+"<b>\" is ambigious.");
|
ret.getErrors().add("<b>"+this.getTypename()+" matching \"<h>"+arg+"<b>\" is ambigious.");
|
||||||
if (senderIds.size() >= MAX_COUNT)
|
if (senderIds.size() >= MAX_COUNT)
|
||||||
{
|
{
|
||||||
// To many to list
|
// To many to list
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.massivecraft.mcore.cmd.req;
|
package com.massivecraft.mcore.cmd.req;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.massivecraft.mcore.Lang;
|
import com.massivecraft.mcore.Lang;
|
||||||
import com.massivecraft.mcore.cmd.MCommand;
|
import com.massivecraft.mcore.cmd.MCommand;
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
|
||||||
|
|
||||||
public class ReqIsPlayer extends ReqAbstract
|
public class ReqIsPlayer extends ReqAbstract
|
||||||
{
|
{
|
||||||
@ -24,7 +24,7 @@ public class ReqIsPlayer extends ReqAbstract
|
|||||||
@Override
|
@Override
|
||||||
public boolean apply(CommandSender sender, MCommand command)
|
public boolean apply(CommandSender sender, MCommand command)
|
||||||
{
|
{
|
||||||
return SenderUtil.isPlayer(sender);
|
return sender instanceof Player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,7 +4,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
|
|
||||||
import com.massivecraft.mcore.cmd.MCommand;
|
import com.massivecraft.mcore.cmd.MCommand;
|
||||||
import com.massivecraft.mcore.mixin.Mixin;
|
import com.massivecraft.mcore.mixin.Mixin;
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
import com.massivecraft.mcore.util.Txt;
|
import com.massivecraft.mcore.util.Txt;
|
||||||
|
|
||||||
public class ReqIsntCertainSender extends ReqAbstract
|
public class ReqIsntCertainSender extends ReqAbstract
|
||||||
@ -15,11 +15,8 @@ public class ReqIsntCertainSender extends ReqAbstract
|
|||||||
// INSTANCE & CONSTRUCT
|
// INSTANCE & CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static ReqIsntCertainSender get(CommandSender sender) { return new ReqIsntCertainSender(sender); }
|
public static ReqIsntCertainSender get(Object senderObject) { return new ReqIsntCertainSender(senderObject); }
|
||||||
public ReqIsntCertainSender(CommandSender sender) { this.senderId = SenderUtil.getSenderId(sender); }
|
public ReqIsntCertainSender(Object senderObject) { this.senderId = IdUtil.getId(senderObject); }
|
||||||
|
|
||||||
public static ReqIsntCertainSender get(String senderId) { return new ReqIsntCertainSender(senderId); }
|
|
||||||
public ReqIsntCertainSender(String senderId) { this.senderId = senderId; }
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// FIELDS
|
// FIELDS
|
||||||
@ -35,7 +32,7 @@ public class ReqIsntCertainSender extends ReqAbstract
|
|||||||
@Override
|
@Override
|
||||||
public boolean apply(CommandSender sender, MCommand command)
|
public boolean apply(CommandSender sender, MCommand command)
|
||||||
{
|
{
|
||||||
return !this.getSenderId().equalsIgnoreCase(SenderUtil.getSenderId(sender));
|
return !this.getSenderId().equalsIgnoreCase(IdUtil.getId(sender));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.massivecraft.mcore.cmd.req;
|
package com.massivecraft.mcore.cmd.req;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.massivecraft.mcore.Lang;
|
import com.massivecraft.mcore.Lang;
|
||||||
import com.massivecraft.mcore.cmd.MCommand;
|
import com.massivecraft.mcore.cmd.MCommand;
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
|
||||||
|
|
||||||
public class ReqIsntPlayer extends ReqAbstract
|
public class ReqIsntPlayer extends ReqAbstract
|
||||||
{
|
{
|
||||||
@ -24,7 +24,7 @@ public class ReqIsntPlayer extends ReqAbstract
|
|||||||
@Override
|
@Override
|
||||||
public boolean apply(CommandSender sender, MCommand command)
|
public boolean apply(CommandSender sender, MCommand command)
|
||||||
{
|
{
|
||||||
return !SenderUtil.isPlayer(sender);
|
return ! (sender instanceof Player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
64
src/com/massivecraft/mcore/event/MCorePlayerFlyEvent.java
Normal file
64
src/com/massivecraft/mcore/event/MCorePlayerFlyEvent.java
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,9 @@ package com.massivecraft.mcore.event;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
public class MCoreSenderRegisterEvent extends MCoreSenderEvent
|
import com.massivecraft.mcore.util.IdData;
|
||||||
|
|
||||||
|
public class MCoreSenderRegisterEvent extends MCoreSenderRegistryEvent
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// REQUIRED EVENT CODE
|
// REQUIRED EVENT CODE
|
||||||
@ -17,9 +19,9 @@ public class MCoreSenderRegisterEvent extends MCoreSenderEvent
|
|||||||
// CONSTRUCT
|
// CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public MCoreSenderRegisterEvent(CommandSender sender)
|
public MCoreSenderRegisterEvent(CommandSender sender, IdData data)
|
||||||
{
|
{
|
||||||
super(sender);
|
super(sender, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,9 @@ package com.massivecraft.mcore.event;
|
|||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public abstract class MCoreSenderEvent extends MCoreEvent
|
import com.massivecraft.mcore.util.IdData;
|
||||||
|
|
||||||
|
public abstract class MCoreSenderRegistryEvent extends MCoreEvent
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// FIELDS
|
// FIELDS
|
||||||
@ -11,13 +13,17 @@ public abstract class MCoreSenderEvent extends MCoreEvent
|
|||||||
private final CommandSender sender;
|
private final CommandSender sender;
|
||||||
public CommandSender getSender() { return this.sender; }
|
public CommandSender getSender() { return this.sender; }
|
||||||
|
|
||||||
|
private final IdData data;
|
||||||
|
public IdData getData() { return this.data; }
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CONSTRUCT
|
// CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public MCoreSenderEvent(CommandSender sender)
|
public MCoreSenderRegistryEvent(CommandSender sender, IdData data)
|
||||||
{
|
{
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -3,7 +3,9 @@ package com.massivecraft.mcore.event;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
public class MCoreSenderUnregisterEvent extends MCoreSenderEvent
|
import com.massivecraft.mcore.util.IdData;
|
||||||
|
|
||||||
|
public class MCoreSenderUnregisterEvent extends MCoreSenderRegistryEvent
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// REQUIRED EVENT CODE
|
// REQUIRED EVENT CODE
|
||||||
@ -17,9 +19,9 @@ public class MCoreSenderUnregisterEvent extends MCoreSenderEvent
|
|||||||
// CONSTRUCT
|
// CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public MCoreSenderUnregisterEvent(CommandSender sender)
|
public MCoreSenderUnregisterEvent(CommandSender sender, IdData data)
|
||||||
{
|
{
|
||||||
super(sender);
|
super(sender, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
15
src/com/massivecraft/mcore/event/MCoreUuidUpdateEvent.java
Normal file
15
src/com/massivecraft/mcore/event/MCoreUuidUpdateEvent.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package com.massivecraft.mcore.event;
|
||||||
|
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class MCoreUuidUpdateEvent extends MCoreEvent
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// REQUIRED EVENT CODE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
@Override public HandlerList getHandlers() { return handlers; }
|
||||||
|
public static HandlerList getHandlerList() { return handlers; }
|
||||||
|
|
||||||
|
}
|
117
src/com/massivecraft/mcore/fetcher/Fetcher.java
Normal file
117
src/com/massivecraft/mcore/fetcher/Fetcher.java
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
package com.massivecraft.mcore.fetcher;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
import com.massivecraft.mcore.util.MUtil;
|
||||||
|
|
||||||
|
public class Fetcher implements Callable<Set<IdAndName>>
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTANTS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static final ExecutorService ES = Executors.newFixedThreadPool(100);
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// FIELDS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private final Collection<Object> objects;
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public Fetcher(Collection<Object> objects)
|
||||||
|
{
|
||||||
|
this.objects = objects;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// OVERRIDE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<IdAndName> call() throws Exception
|
||||||
|
{
|
||||||
|
return fetch(this.objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// STATIC
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static Set<IdAndName> fetch(Collection<? extends Object> objects) throws Exception
|
||||||
|
{
|
||||||
|
// Separate names and ids
|
||||||
|
final Set<String> names = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||||
|
final Set<UUID> ids = new HashSet<UUID>();
|
||||||
|
for (Object object : objects)
|
||||||
|
{
|
||||||
|
if (object instanceof UUID)
|
||||||
|
{
|
||||||
|
UUID id = (UUID)object;
|
||||||
|
ids.add(id);
|
||||||
|
}
|
||||||
|
else if (object instanceof String)
|
||||||
|
{
|
||||||
|
String string = (String)object;
|
||||||
|
if (MUtil.isValidPlayerName(string))
|
||||||
|
{
|
||||||
|
names.add(string);
|
||||||
|
}
|
||||||
|
else if (MUtil.isValidUUID(string))
|
||||||
|
{
|
||||||
|
ids.add(UUID.fromString(string));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Tasks
|
||||||
|
Callable<Set<IdAndName>> taskName = new Callable<Set<IdAndName>>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Set<IdAndName> call() throws Exception
|
||||||
|
{
|
||||||
|
return new HashSet<IdAndName>(new FetcherByName(names).call().values());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Callable<Set<IdAndName>> taskId = new Callable<Set<IdAndName>>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Set<IdAndName> call() throws Exception
|
||||||
|
{
|
||||||
|
return new HashSet<IdAndName>(new FetcherById(ids).call().values());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
final List<Callable<Set<IdAndName>>> tasks = new ArrayList<Callable<Set<IdAndName>>>();
|
||||||
|
tasks.add(taskName);
|
||||||
|
tasks.add(taskId);
|
||||||
|
|
||||||
|
// Invoke All Tasks
|
||||||
|
List<Future<Set<IdAndName>>> futures = ES.invokeAll(tasks);
|
||||||
|
|
||||||
|
// Merge Return Value
|
||||||
|
Set<IdAndName> ret = new HashSet<IdAndName>();
|
||||||
|
for (Future<Set<IdAndName>> future : futures)
|
||||||
|
{
|
||||||
|
Set<IdAndName> set = future.get();
|
||||||
|
ret.addAll(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
75
src/com/massivecraft/mcore/fetcher/FetcherById.java
Normal file
75
src/com/massivecraft/mcore/fetcher/FetcherById.java
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package com.massivecraft.mcore.fetcher;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
public class FetcherById implements Callable<Map<Object, IdAndName>>
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTANTS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static final ExecutorService ES = Executors.newFixedThreadPool(100);
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// FIELDS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private final Collection<UUID> ids;
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public FetcherById(Collection<UUID> ids)
|
||||||
|
{
|
||||||
|
this.ids = ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// OVERRIDE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Object, IdAndName> call() throws Exception
|
||||||
|
{
|
||||||
|
return fetch(this.ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// STATIC
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static Map<Object, IdAndName> fetch(Collection<UUID> ids) throws Exception
|
||||||
|
{
|
||||||
|
// Create Tasks
|
||||||
|
final List<Callable<Map<UUID, IdAndName>>> tasks = new ArrayList<Callable<Map<UUID, IdAndName>>>();
|
||||||
|
for (UUID id : ids)
|
||||||
|
{
|
||||||
|
tasks.add(new FetcherByIdSingle(Arrays.asList(id)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invoke All Tasks
|
||||||
|
List<Future<Map<UUID, IdAndName>>> futures = ES.invokeAll(tasks);
|
||||||
|
|
||||||
|
// Merge Return Value
|
||||||
|
Map<Object, IdAndName> ret = new HashMap<Object, IdAndName>();
|
||||||
|
for (Future<Map<UUID, IdAndName>> future : futures)
|
||||||
|
{
|
||||||
|
Map<UUID, IdAndName> map = future.get();
|
||||||
|
ret.putAll(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
107
src/com/massivecraft/mcore/fetcher/FetcherByIdSingle.java
Normal file
107
src/com/massivecraft/mcore/fetcher/FetcherByIdSingle.java
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
package com.massivecraft.mcore.fetcher;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.parser.JSONParser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Many thanks to evilmidget38!
|
||||||
|
* This utility class is based on his work.
|
||||||
|
* http://forums.bukkit.org/threads/player-name-uuid-fetcher.250926/
|
||||||
|
*/
|
||||||
|
public class FetcherByIdSingle implements Callable<Map<UUID, IdAndName>>
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTANTS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public final static String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
||||||
|
public final static String KEY_NAME = "name";
|
||||||
|
public final static String KEY_CAUSE = "cause";
|
||||||
|
public final static String KEY_ERROR_MESSAGE = "errorMessage";
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// FIELDS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private final Collection<UUID> ids;
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public FetcherByIdSingle(Collection<UUID> ids)
|
||||||
|
{
|
||||||
|
this.ids = ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// OVERRIDE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<UUID, IdAndName> call() throws Exception
|
||||||
|
{
|
||||||
|
return fetch(this.ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// STATIC
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static Map<UUID, IdAndName> fetch(Collection<UUID> ids) throws Exception
|
||||||
|
{
|
||||||
|
Map<UUID, IdAndName> ret = new HashMap<UUID, IdAndName>();
|
||||||
|
JSONParser jsonParser = new JSONParser();
|
||||||
|
|
||||||
|
for (UUID id : ids)
|
||||||
|
{
|
||||||
|
HttpURLConnection connection = createConnection(id);
|
||||||
|
InputStream inputStream = connection.getInputStream();
|
||||||
|
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
|
||||||
|
|
||||||
|
JSONObject response = (JSONObject) jsonParser.parse(inputStreamReader);
|
||||||
|
|
||||||
|
inputStreamReader.close();
|
||||||
|
inputStream.close();
|
||||||
|
connection.disconnect();
|
||||||
|
|
||||||
|
String name = (String) response.get(KEY_NAME);
|
||||||
|
// if (name == null) continue;
|
||||||
|
// No... we want to add null values as well.
|
||||||
|
|
||||||
|
String cause = (String) response.get(KEY_CAUSE);
|
||||||
|
if (cause != null && cause.length() > 0)
|
||||||
|
{
|
||||||
|
String errorMessage = (String) response.get(KEY_ERROR_MESSAGE);
|
||||||
|
throw new IllegalStateException(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.put(id, new IdAndName(id, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HttpURLConnection createConnection(UUID id) throws Exception
|
||||||
|
{
|
||||||
|
URL url = new URL(PROFILE_URL + id.toString().replace("-", ""));
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setConnectTimeout(15000);
|
||||||
|
connection.setReadTimeout(15000);
|
||||||
|
connection.setUseCaches(false);
|
||||||
|
connection.setDoInput(true);
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,39 +6,33 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
/**
|
public class FetcherByName implements Callable<Map<String, IdAndName>>
|
||||||
* Many thanks to evilmidget38!
|
|
||||||
* This utility class is based on his work.
|
|
||||||
* http://forums.bukkit.org/threads/player-name-uuid-fetcher.250926/
|
|
||||||
*/
|
|
||||||
public class FetcherPlayerIdMojang implements Callable<Map<String, UUID>>
|
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CONSTANTS
|
// CONSTANTS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static final int BATCH_SIZE = FetcherPlayerIdMojangSingle.MAX_PAGE_SIZE;
|
public static final ExecutorService ES = Executors.newFixedThreadPool(100);
|
||||||
public static final ExecutorService ES = Executors.newCachedThreadPool();
|
public static final int BATCH_SIZE = FetcherByNameSingle.PROFILES_PER_REQUEST;
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// FIELDS
|
// FIELDS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
private final Collection<String> playerNames;
|
private final Collection<String> names;
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CONSTRUCT
|
// CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public FetcherPlayerIdMojang(Collection<String> playerNames)
|
public FetcherByName(Collection<String> names)
|
||||||
{
|
{
|
||||||
this.playerNames = playerNames;
|
this.names = names;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -46,41 +40,40 @@ public class FetcherPlayerIdMojang implements Callable<Map<String, UUID>>
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, UUID> call() throws Exception
|
public Map<String, IdAndName> call() throws Exception
|
||||||
{
|
{
|
||||||
return fetch(this.playerNames);
|
return fetch(this.names);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// STATIC
|
// STATIC
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static Map<String, UUID> fetch(Collection<String> playerNames) throws Exception
|
public static Map<String, IdAndName> fetch(Collection<String> names) throws Exception
|
||||||
{
|
{
|
||||||
// Create batches
|
// Create batches
|
||||||
List<List<String>> batches = new ArrayList<List<String>>();
|
List<List<String>> batches = new ArrayList<List<String>>();
|
||||||
playerNames = new ArrayList<String>(playerNames);
|
names = new ArrayList<String>(names);
|
||||||
while (playerNames.size() > 0)
|
while (names.size() > 0)
|
||||||
{
|
{
|
||||||
List<String> batch = take(playerNames, BATCH_SIZE);
|
List<String> batch = take(names, BATCH_SIZE);
|
||||||
batches.add(batch);
|
batches.add(batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Tasks
|
// Create Tasks
|
||||||
final List<Callable<Map<String, UUID>>> tasks = new ArrayList<Callable<Map<String, UUID>>>();
|
final List<Callable<Map<String, IdAndName>>> tasks = new ArrayList<Callable<Map<String, IdAndName>>>();
|
||||||
for (List<String> batch : batches)
|
for (List<String> batch : batches)
|
||||||
{
|
{
|
||||||
tasks.add(new FetcherPlayerIdMojangSingle(batch));
|
tasks.add(new FetcherByNameSingle(batch));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invoke All Tasks
|
// Invoke All Tasks
|
||||||
List<Future<Map<String, UUID>>> futures = ES.invokeAll(tasks);
|
List<Future<Map<String, IdAndName>>> futures = ES.invokeAll(tasks);
|
||||||
|
|
||||||
// Merge Return Value
|
// Merge Return Value
|
||||||
Map<String, UUID> ret = new TreeMap<String, UUID> (String.CASE_INSENSITIVE_ORDER);
|
Map<String, IdAndName> ret = new TreeMap<String, IdAndName> (String.CASE_INSENSITIVE_ORDER);
|
||||||
for (Future<Map<String, UUID>> future : futures)
|
for (Future<Map<String, IdAndName>> future : futures)
|
||||||
{
|
{
|
||||||
|
|
||||||
ret.putAll(future.get());
|
ret.putAll(future.get());
|
||||||
}
|
}
|
||||||
|
|
178
src/com/massivecraft/mcore/fetcher/FetcherByNameSingle.java
Normal file
178
src/com/massivecraft/mcore/fetcher/FetcherByNameSingle.java
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
package com.massivecraft.mcore.fetcher;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.parser.JSONParser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Many thanks to evilmidget38!
|
||||||
|
* This utility class is based on his work.
|
||||||
|
* http://forums.bukkit.org/threads/player-name-uuid-fetcher.250926/
|
||||||
|
*/
|
||||||
|
public class FetcherByNameSingle implements Callable<Map<String, IdAndName>>
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTANTS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public final static int PROFILES_PER_REQUEST = 100;
|
||||||
|
public final static String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
||||||
|
|
||||||
|
public final static String KEY_ID = "id";
|
||||||
|
public final static String KEY_NAME = "name";
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// FIELDS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private final Collection<String> names;
|
||||||
|
private final boolean rateLimiting;
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public FetcherByNameSingle(Collection<String> names)
|
||||||
|
{
|
||||||
|
this(names, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FetcherByNameSingle(Collection<String> names, boolean rateLimiting)
|
||||||
|
{
|
||||||
|
this.names = names;
|
||||||
|
this.rateLimiting = rateLimiting;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// OVERRIDE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, IdAndName> call() throws Exception
|
||||||
|
{
|
||||||
|
return fetch(this.names, this.rateLimiting);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// STATIC
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static Map<String, IdAndName> fetch(Collection<String> namesCollection) throws Exception
|
||||||
|
{
|
||||||
|
return fetch(namesCollection, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, IdAndName> fetch(Collection<String> namesCollection, boolean rateLimiting) throws Exception
|
||||||
|
{
|
||||||
|
List<String> names = new ArrayList<String>(namesCollection);
|
||||||
|
Map<String, IdAndName> ret = new TreeMap<String, IdAndName>(String.CASE_INSENSITIVE_ORDER);
|
||||||
|
JSONParser jsonParser = new JSONParser();
|
||||||
|
|
||||||
|
int requests = (int) Math.ceil(names.size() / (double) PROFILES_PER_REQUEST);
|
||||||
|
for (int i = 0; i < requests; i++)
|
||||||
|
{
|
||||||
|
HttpURLConnection connection = createConnection();
|
||||||
|
String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
|
||||||
|
writeBody(connection, body);
|
||||||
|
InputStream inputStream = connection.getInputStream();
|
||||||
|
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
|
||||||
|
|
||||||
|
JSONArray array = (JSONArray) jsonParser.parse(inputStreamReader);
|
||||||
|
|
||||||
|
inputStreamReader.close();
|
||||||
|
inputStream.close();
|
||||||
|
connection.disconnect();
|
||||||
|
|
||||||
|
for (Object profile : array)
|
||||||
|
{
|
||||||
|
JSONObject jsonProfile = (JSONObject) profile;
|
||||||
|
String id = (String) jsonProfile.get(KEY_ID);
|
||||||
|
String name = (String) jsonProfile.get(KEY_NAME);
|
||||||
|
UUID uuid = getUUID(id);
|
||||||
|
ret.put(name, new IdAndName(uuid, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rateLimiting && i != requests - 1)
|
||||||
|
{
|
||||||
|
Thread.sleep(100L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String name : names)
|
||||||
|
{
|
||||||
|
IdAndName idAndName = ret.get(name);
|
||||||
|
if (idAndName == null) idAndName = new IdAndName(null, name);
|
||||||
|
ret.put(name, idAndName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void writeBody(HttpURLConnection connection, String body) throws Exception
|
||||||
|
{
|
||||||
|
OutputStream stream = connection.getOutputStream();
|
||||||
|
stream.write(body.getBytes());
|
||||||
|
stream.flush();
|
||||||
|
stream.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HttpURLConnection createConnection() throws Exception
|
||||||
|
{
|
||||||
|
URL url = new URL(PROFILE_URL);
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
connection.setRequestProperty("Content-Type", "application/json");
|
||||||
|
connection.setConnectTimeout(15000);
|
||||||
|
connection.setReadTimeout(15000);
|
||||||
|
connection.setUseCaches(false);
|
||||||
|
connection.setDoInput(true);
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static UUID getUUID(String id)
|
||||||
|
{
|
||||||
|
return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" +id.substring(20, 32));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] toBytes(UUID uuid)
|
||||||
|
{
|
||||||
|
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
|
||||||
|
byteBuffer.putLong(uuid.getMostSignificantBits());
|
||||||
|
byteBuffer.putLong(uuid.getLeastSignificantBits());
|
||||||
|
return byteBuffer.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UUID fromBytes(byte[] array)
|
||||||
|
{
|
||||||
|
if (array.length != 16)
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Illegal byte array length: " + array.length);
|
||||||
|
}
|
||||||
|
ByteBuffer byteBuffer = ByteBuffer.wrap(array);
|
||||||
|
long mostSignificant = byteBuffer.getLong();
|
||||||
|
long leastSignificant = byteBuffer.getLong();
|
||||||
|
return new UUID(mostSignificant, leastSignificant);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IdAndName get(String name) throws Exception
|
||||||
|
{
|
||||||
|
return fetch(Arrays.asList(name)).get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,94 +0,0 @@
|
|||||||
package com.massivecraft.mcore.fetcher;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
|
|
||||||
import com.massivecraft.mcore.MCoreMPlayer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Many thanks to evilmidget38!
|
|
||||||
* This utility class is based on his work.
|
|
||||||
* http://forums.bukkit.org/threads/player-name-uuid-fetcher.250926/
|
|
||||||
*/
|
|
||||||
public class FetcherPlayerIdCached implements Callable<Map<String, UUID>>
|
|
||||||
{
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// FIELDS
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
private final Collection<String> playerNames;
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// CONSTRUCT
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public FetcherPlayerIdCached(Collection<String> playerNames)
|
|
||||||
{
|
|
||||||
this.playerNames = playerNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// OVERRIDE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, UUID> call() throws Exception
|
|
||||||
{
|
|
||||||
return fetch(this.playerNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// STATIC
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static Map<String, UUID> fetch(Collection<String> playerNames) throws Exception
|
|
||||||
{
|
|
||||||
Map<String, UUID> ret = new TreeMap<String, UUID>(String.CASE_INSENSITIVE_ORDER);
|
|
||||||
List<String> playerNamesCopy = new ArrayList<String>(playerNames);
|
|
||||||
|
|
||||||
// Use Cache
|
|
||||||
Iterator<String> iter = playerNamesCopy.iterator();
|
|
||||||
while (iter.hasNext())
|
|
||||||
{
|
|
||||||
String playerName = iter.next();
|
|
||||||
MCoreMPlayer mplayer = MCoreMPlayer.get(playerName);
|
|
||||||
if (mplayer == null) continue;
|
|
||||||
ret.put(mplayer.getName(), UUID.fromString(mplayer.getId()));
|
|
||||||
iter.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use Mojang API for the rest
|
|
||||||
if (playerNamesCopy.size() > 0)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Map<String, UUID> mojangApiResult = FetcherPlayerIdMojang.fetch(playerNamesCopy);
|
|
||||||
// Add to the cache
|
|
||||||
for (Entry<String, UUID> entry : mojangApiResult.entrySet())
|
|
||||||
{
|
|
||||||
String name = entry.getKey();
|
|
||||||
UUID id = entry.getValue();
|
|
||||||
MCoreMPlayer mplayer = MCoreMPlayer.get(id, true);
|
|
||||||
mplayer.setName(name);
|
|
||||||
}
|
|
||||||
// Add to the return value
|
|
||||||
ret.putAll(mojangApiResult);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,143 +0,0 @@
|
|||||||
package com.massivecraft.mcore.fetcher;
|
|
||||||
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
|
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.JSONValue;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Many thanks to evilmidget38!
|
|
||||||
* This utility class is based on his work.
|
|
||||||
* http://forums.bukkit.org/threads/player-name-uuid-fetcher.250926/
|
|
||||||
*/
|
|
||||||
public class FetcherPlayerIdMojangSingle implements Callable<Map<String, UUID>>
|
|
||||||
{
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// CONSTANTS
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public final static String URL_BASE = "https://api.mojang.com/profiles/page/";
|
|
||||||
public final static int MAX_PAGES = 100;
|
|
||||||
|
|
||||||
// The maximum amount of profiles returned per page.
|
|
||||||
// Mojang might change this value.
|
|
||||||
// Thus we can not fully depend on it.
|
|
||||||
public final static int MAX_PAGE_SIZE = 50;
|
|
||||||
|
|
||||||
public final static String KEY_PROFILES = "profiles";
|
|
||||||
public final static String KEY_SIZE = "size";
|
|
||||||
public final static String KEY_ID = "id";
|
|
||||||
public final static String KEY_NAME = "name";
|
|
||||||
public final static String KEY_AGENT = "agent";
|
|
||||||
public final static String VALUGE_AGENT = "minecraft";
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// FIELDS
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
private final Collection<String> playerNames;
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// CONSTRUCT
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public FetcherPlayerIdMojangSingle(Collection<String> playerNames)
|
|
||||||
{
|
|
||||||
this.playerNames = playerNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// OVERRIDE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, UUID> call() throws Exception
|
|
||||||
{
|
|
||||||
return fetch(this.playerNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// STATIC
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static Map<String, UUID> fetch(Collection<String> playerNames) throws Exception
|
|
||||||
{
|
|
||||||
Map<String, UUID> ret = new TreeMap<String, UUID>(String.CASE_INSENSITIVE_ORDER);
|
|
||||||
JSONParser jsonParser = new JSONParser();
|
|
||||||
String body = createBody(playerNames);
|
|
||||||
for (int i = 1; i < MAX_PAGES; i++)
|
|
||||||
{
|
|
||||||
// If the return object has as many entries as player names requested we must have gotten all the info.
|
|
||||||
// This will often help us avoid the extra useless last call of a page with 0 entries.
|
|
||||||
if (ret.size() == playerNames.size()) break;
|
|
||||||
|
|
||||||
HttpURLConnection connection = createConnection(i);
|
|
||||||
writeBody(connection, body);
|
|
||||||
JSONObject jsonObject = (JSONObject) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
|
||||||
JSONArray profiles = (JSONArray) jsonObject.get(KEY_PROFILES);
|
|
||||||
int size = ((Number) jsonObject.get(KEY_SIZE)).intValue();
|
|
||||||
|
|
||||||
// If the page is empty we are done
|
|
||||||
if (size == 0) break;
|
|
||||||
|
|
||||||
for (Object profile : profiles)
|
|
||||||
{
|
|
||||||
JSONObject jsonProfile = (JSONObject) profile;
|
|
||||||
String id = (String) jsonProfile.get(KEY_ID);
|
|
||||||
String name = (String) jsonProfile.get(KEY_NAME);
|
|
||||||
UUID uuid = UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32));
|
|
||||||
ret.put(name, uuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static HttpURLConnection createConnection(int page) throws Exception
|
|
||||||
{
|
|
||||||
URL url = new URL(URL_BASE + page);
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setRequestMethod("POST");
|
|
||||||
connection.setRequestProperty("Content-Type", "application/json");
|
|
||||||
connection.setConnectTimeout(15000);
|
|
||||||
connection.setReadTimeout(15000);
|
|
||||||
connection.setUseCaches(false);
|
|
||||||
connection.setDoInput(true);
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static String createBody(Collection<String> playerNames)
|
|
||||||
{
|
|
||||||
List<JSONObject> lookups = new ArrayList<JSONObject>();
|
|
||||||
for (String playerName : playerNames)
|
|
||||||
{
|
|
||||||
JSONObject obj = new JSONObject();
|
|
||||||
obj.put(KEY_NAME, playerName);
|
|
||||||
obj.put(KEY_AGENT, VALUGE_AGENT);
|
|
||||||
lookups.add(obj);
|
|
||||||
}
|
|
||||||
return JSONValue.toJSONString(lookups);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void writeBody(HttpURLConnection connection, String body) throws Exception
|
|
||||||
{
|
|
||||||
DataOutputStream writer = new DataOutputStream(connection.getOutputStream());
|
|
||||||
writer.write(body.getBytes());
|
|
||||||
writer.flush();
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,93 +0,0 @@
|
|||||||
package com.massivecraft.mcore.fetcher;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import com.massivecraft.mcore.MCoreMPlayer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Many thanks to evilmidget38!
|
|
||||||
* This utility class is based on his work.
|
|
||||||
* http://forums.bukkit.org/threads/player-name-uuid-fetcher.250926/
|
|
||||||
*/
|
|
||||||
public class FetcherPlayerNameCached implements Callable<Map<UUID, String>>
|
|
||||||
{
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// FIELDS
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
private final Collection<UUID> playerIds;
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// CONSTRUCT
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public FetcherPlayerNameCached(Collection<UUID> playerIds)
|
|
||||||
{
|
|
||||||
this.playerIds = playerIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// OVERRIDE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<UUID, String> call() throws Exception
|
|
||||||
{
|
|
||||||
return fetch(this.playerIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// STATIC
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static Map<UUID, String> fetch(Collection<UUID> playerIds) throws Exception
|
|
||||||
{
|
|
||||||
Map<UUID, String> ret = new HashMap<UUID, String>();
|
|
||||||
List<UUID> playerIdsCopy = new ArrayList<UUID>(playerIds);
|
|
||||||
|
|
||||||
// Use Cache
|
|
||||||
Iterator<UUID> iter = playerIdsCopy.iterator();
|
|
||||||
while (iter.hasNext())
|
|
||||||
{
|
|
||||||
UUID playerId = iter.next();
|
|
||||||
MCoreMPlayer mplayer = MCoreMPlayer.get(playerId);
|
|
||||||
if (mplayer == null) continue;
|
|
||||||
ret.put(playerId, mplayer.getName());
|
|
||||||
iter.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use Mojang API for the rest
|
|
||||||
if (playerIdsCopy.size() > 0)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Map<UUID, String> mojangApiResult = FetcherPlayerNameMojang.fetch(playerIdsCopy);
|
|
||||||
// Add to the cache
|
|
||||||
for (Entry<UUID, String> entry : mojangApiResult.entrySet())
|
|
||||||
{
|
|
||||||
UUID id = entry.getKey();
|
|
||||||
String name = entry.getValue();
|
|
||||||
MCoreMPlayer mplayer = MCoreMPlayer.get(id, true);
|
|
||||||
mplayer.setName(name);
|
|
||||||
}
|
|
||||||
// Add to the return value
|
|
||||||
ret.putAll(mojangApiResult);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,81 +0,0 @@
|
|||||||
package com.massivecraft.mcore.fetcher;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.Future;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Many thanks to evilmidget38!
|
|
||||||
* This utility class is based on his work.
|
|
||||||
* http://forums.bukkit.org/threads/player-name-uuid-fetcher.250926/
|
|
||||||
*/
|
|
||||||
public class FetcherPlayerNameMojang implements Callable<Map<UUID, String>>
|
|
||||||
{
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// CONSTANTS
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static final ExecutorService ES = Executors.newCachedThreadPool();
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// FIELDS
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
private final Collection<UUID> playerIds;
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// CONSTRUCT
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public FetcherPlayerNameMojang(Collection<UUID> playerIds)
|
|
||||||
{
|
|
||||||
this.playerIds = playerIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// OVERRIDE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<UUID, String> call() throws Exception
|
|
||||||
{
|
|
||||||
return fetch(this.playerIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// STATIC
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static Map<UUID, String> fetch(Collection<UUID> playerIds) throws Exception
|
|
||||||
{
|
|
||||||
// Create Tasks
|
|
||||||
final List<Callable<Entry<UUID, String>>> tasks = new ArrayList<Callable<Entry<UUID, String>>>();
|
|
||||||
for (UUID playerId : playerIds)
|
|
||||||
{
|
|
||||||
tasks.add(new FetcherPlayerNameMojangSingle(playerId));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Invoke All Tasks
|
|
||||||
List<Future<Entry<UUID, String>>> futures = ES.invokeAll(tasks);
|
|
||||||
|
|
||||||
// Merge Return Value
|
|
||||||
Map<UUID, String> ret = new HashMap<UUID, String>();
|
|
||||||
for (Future<Entry<UUID, String>> future : futures)
|
|
||||||
{
|
|
||||||
Entry<UUID, String> entry = future.get();
|
|
||||||
if (entry == null) continue;
|
|
||||||
ret.put(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
package com.massivecraft.mcore.fetcher;
|
|
||||||
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.AbstractMap.SimpleEntry;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Many thanks to evilmidget38!
|
|
||||||
* This utility class is based on his work.
|
|
||||||
* http://forums.bukkit.org/threads/player-name-uuid-fetcher.250926/
|
|
||||||
*/
|
|
||||||
public class FetcherPlayerNameMojangSingle implements Callable<Entry<UUID, String>>
|
|
||||||
{
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// CONSTANTS
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public final static String URL_BASE = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
|
||||||
public final static String KEY_NAME = "name";
|
|
||||||
public final static String KEY_CAUSE = "cause";
|
|
||||||
public final static String KEY_ERROR_MESSAGE = "errorMessage";
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// FIELDS
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
private final UUID playerId;
|
|
||||||
public UUID getPlayerId() { return this.playerId; }
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// CONSTRUCT
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public FetcherPlayerNameMojangSingle(UUID playerId)
|
|
||||||
{
|
|
||||||
this.playerId = playerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// OVERRIDE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Entry<UUID, String> call() throws Exception
|
|
||||||
{
|
|
||||||
String playerName = fetch(this.playerId);
|
|
||||||
if (playerName == null) return null;
|
|
||||||
return new SimpleEntry<UUID, String>(this.playerId, playerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// STATIC
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static String fetch(UUID playerId) throws Exception
|
|
||||||
{
|
|
||||||
JSONParser jsonParser = new JSONParser();
|
|
||||||
HttpURLConnection connection = createConnection(playerId);
|
|
||||||
JSONObject response = (JSONObject) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
|
||||||
String name = (String) response.get(KEY_NAME);
|
|
||||||
if (name == null) return null;
|
|
||||||
String cause = (String) response.get(KEY_CAUSE);
|
|
||||||
if (cause != null && cause.length() > 0)
|
|
||||||
{
|
|
||||||
String errorMessage = (String) response.get(KEY_ERROR_MESSAGE);
|
|
||||||
throw new IllegalStateException(errorMessage);
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static HttpURLConnection createConnection(UUID playerId) throws Exception
|
|
||||||
{
|
|
||||||
URL url = new URL(URL_BASE + playerId.toString().replace("-", ""));
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setConnectTimeout(15000);
|
|
||||||
connection.setReadTimeout(15000);
|
|
||||||
connection.setUseCaches(false);
|
|
||||||
connection.setDoInput(true);
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
66
src/com/massivecraft/mcore/fetcher/IdAndName.java
Normal file
66
src/com/massivecraft/mcore/fetcher/IdAndName.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package com.massivecraft.mcore.fetcher;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class IdAndName
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// FIELDS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private UUID id;
|
||||||
|
public UUID getId() { return this.id; }
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
public String getName() { return this.name; }
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public IdAndName(UUID id, String name)
|
||||||
|
{
|
||||||
|
if (id == null && name == null)
|
||||||
|
{
|
||||||
|
throw new NullPointerException("one of id and name can be null but not both!");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// HASH CODE & EQUALS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||||
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj)
|
||||||
|
{
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (obj == null) return false;
|
||||||
|
if (!(obj instanceof IdAndName)) return false;
|
||||||
|
IdAndName other = (IdAndName) obj;
|
||||||
|
if (id == null)
|
||||||
|
{
|
||||||
|
if (other.id != null) return false;
|
||||||
|
}
|
||||||
|
else if (!id.equals(other.id)) return false;
|
||||||
|
if (name == null)
|
||||||
|
{
|
||||||
|
if (other.name != null) return false;
|
||||||
|
}
|
||||||
|
else if (!name.equals(other.name)) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -15,6 +15,7 @@ public class CmdMCore extends MCommand
|
|||||||
public CmdMCoreUsys cmdMCoreUsys = new CmdMCoreUsys();
|
public CmdMCoreUsys cmdMCoreUsys = new CmdMCoreUsys();
|
||||||
public CmdMCoreMStore cmdMCoreMStore = new CmdMCoreMStore();
|
public CmdMCoreMStore cmdMCoreMStore = new CmdMCoreMStore();
|
||||||
public CmdMCoreId cmdMCoreId = new CmdMCoreId();
|
public CmdMCoreId cmdMCoreId = new CmdMCoreId();
|
||||||
|
public CmdMCoreTest cmdMCoreTest = new CmdMCoreTest();
|
||||||
public CmdMCoreHearsound cmdMCoreHearsound = new CmdMCoreHearsound();
|
public CmdMCoreHearsound cmdMCoreHearsound = new CmdMCoreHearsound();
|
||||||
public VersionCommand cmdMCoreVersion = new VersionCommand(MCore.get(), MCorePerm.VERSION.node, "v", "version");
|
public VersionCommand cmdMCoreVersion = new VersionCommand(MCore.get(), MCorePerm.VERSION.node, "v", "version");
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ public class CmdMCore extends MCommand
|
|||||||
this.addSubCommand(this.cmdMCoreUsys);
|
this.addSubCommand(this.cmdMCoreUsys);
|
||||||
this.addSubCommand(this.cmdMCoreMStore);
|
this.addSubCommand(this.cmdMCoreMStore);
|
||||||
this.addSubCommand(this.cmdMCoreId);
|
this.addSubCommand(this.cmdMCoreId);
|
||||||
|
this.addSubCommand(this.cmdMCoreTest);
|
||||||
this.addSubCommand(this.cmdMCoreHearsound);
|
this.addSubCommand(this.cmdMCoreHearsound);
|
||||||
this.addSubCommand(this.cmdMCoreVersion);
|
this.addSubCommand(this.cmdMCoreVersion);
|
||||||
|
|
||||||
|
37
src/com/massivecraft/mcore/mcorecmd/CmdMCoreTest.java
Normal file
37
src/com/massivecraft/mcore/mcorecmd/CmdMCoreTest.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package com.massivecraft.mcore.mcorecmd;
|
||||||
|
|
||||||
|
import com.massivecraft.mcore.MCorePerm;
|
||||||
|
import com.massivecraft.mcore.cmd.MCommand;
|
||||||
|
import com.massivecraft.mcore.cmd.VisibilityMode;
|
||||||
|
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||||
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
|
public class CmdMCoreTest extends MCommand
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public CmdMCoreTest()
|
||||||
|
{
|
||||||
|
// Aliases
|
||||||
|
this.addAliases("test");
|
||||||
|
|
||||||
|
// Requirements
|
||||||
|
this.addRequirements(ReqHasPerm.get(MCorePerm.TEST.node));
|
||||||
|
|
||||||
|
// VisibilityMode
|
||||||
|
this.setVisibilityMode(VisibilityMode.SECRET);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// OVERRIDE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void perform()
|
||||||
|
{
|
||||||
|
IdUtil.isOnline(IdUtil.CONSOLE_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,13 +1,8 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
package com.massivecraft.mcore.mixin;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import com.massivecraft.mcore.store.SenderEntity;
|
|
||||||
|
|
||||||
public interface CommandMixin
|
public interface CommandMixin
|
||||||
{
|
{
|
||||||
public boolean dispatchCommand(CommandSender sender, String commandLine);
|
public boolean dispatchCommand(Object senderObject, String commandLine);
|
||||||
public boolean dispatchCommand(SenderEntity<?> sender, String commandLine);
|
public boolean dispatchCommand(Object presentObject, Object senderObject, String commandLine); // This one is non-abstract
|
||||||
public boolean dispatchCommand(String senderId, String commandLine);
|
|
||||||
public boolean dispatchCommand(String presentId, String senderId, String commandLine); // This one is non-abstract
|
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,10 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
package com.massivecraft.mcore.mixin;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import com.massivecraft.mcore.store.SenderEntity;
|
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
|
||||||
|
|
||||||
public abstract class CommandMixinAbstract implements CommandMixin
|
public abstract class CommandMixinAbstract implements CommandMixin
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchCommand(CommandSender sender, String commandLine)
|
public boolean dispatchCommand(Object senderObject, String commandLine)
|
||||||
{
|
{
|
||||||
return this.dispatchCommand(SenderUtil.getSenderId(sender), SenderUtil.getSenderId(sender), commandLine);
|
return this.dispatchCommand(senderObject, senderObject, commandLine);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean dispatchCommand(SenderEntity<?> sender, String commandLine)
|
|
||||||
{
|
|
||||||
return this.dispatchCommand(sender.getId(), sender.getId(), commandLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean dispatchCommand(String senderId, String commandLine)
|
|
||||||
{
|
|
||||||
return this.dispatchCommand(senderId, senderId, commandLine);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package com.massivecraft.mcore.mixin;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public class CommandMixinDefault extends CommandMixinAbstract
|
public class CommandMixinDefault extends CommandMixinAbstract
|
||||||
{
|
{
|
||||||
@ -19,14 +19,14 @@ public class CommandMixinDefault extends CommandMixinAbstract
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchCommand(String presentId, String senderId, String commandLine)
|
public boolean dispatchCommand(Object presentObject, Object senderObject, String commandLine)
|
||||||
{
|
{
|
||||||
// Additional enforced presence
|
// Additional enforced presence
|
||||||
CommandSender present = SenderUtil.getSender(presentId);
|
CommandSender present = IdUtil.getSender(presentObject);
|
||||||
if (present == null) return false;
|
if (present == null) return false;
|
||||||
|
|
||||||
// We must then of course have the presence of the sender
|
// We must then of course have the presence of the sender
|
||||||
CommandSender sender = SenderUtil.getSender(senderId);
|
CommandSender sender = IdUtil.getSender(senderObject);
|
||||||
if (sender == null) return false;
|
if (sender == null) return false;
|
||||||
|
|
||||||
// Great! Let's do it!
|
// Great! Let's do it!
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
package com.massivecraft.mcore.mixin;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
public interface DisplayNameMixin
|
public interface DisplayNameMixin
|
||||||
{
|
{
|
||||||
public String getDisplayName(String senderId);
|
public String getDisplayName(Object senderObject);
|
||||||
public void setDisplayName(String senderId, String displayName);
|
public void setDisplayName(Object senderObject, String displayName);
|
||||||
public String getDisplayName(CommandSender sender);
|
|
||||||
public void setDisplayName(CommandSender sender, String displayName);
|
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,6 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
package com.massivecraft.mcore.mixin;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
|
||||||
|
|
||||||
public abstract class DisplayNameMixinAbstract implements DisplayNameMixin
|
public abstract class DisplayNameMixinAbstract implements DisplayNameMixin
|
||||||
{
|
{
|
||||||
@Override
|
|
||||||
public String getDisplayName(CommandSender sender)
|
|
||||||
{
|
|
||||||
return this.getDisplayName(SenderUtil.getSenderId(sender));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDisplayName(CommandSender sender, String displayName)
|
|
||||||
{
|
|
||||||
this.setDisplayName(SenderUtil.getSenderId(sender), displayName);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ import java.util.TreeMap;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public class DisplayNameMixinDefault extends DisplayNameMixinAbstract
|
public class DisplayNameMixinDefault extends DisplayNameMixinAbstract
|
||||||
{
|
{
|
||||||
@ -30,27 +30,34 @@ public class DisplayNameMixinDefault extends DisplayNameMixinAbstract
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName(String senderId)
|
public String getDisplayName(Object senderObject)
|
||||||
{
|
{
|
||||||
|
String senderId = IdUtil.getId(senderObject);
|
||||||
if (senderId == null) return null;
|
if (senderId == null) return null;
|
||||||
|
|
||||||
// Try Our Map
|
// Our Map
|
||||||
String ret = this.idToDisplayName.get(senderId);
|
String ret = this.idToDisplayName.get(senderId);
|
||||||
|
|
||||||
// Try Bukkit
|
// Bukkit
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
{
|
{
|
||||||
Player player = SenderUtil.getPlayer(senderId);
|
Player player = IdUtil.getPlayer(senderObject);
|
||||||
if (player != null)
|
if (player != null)
|
||||||
{
|
{
|
||||||
ret = player.getDisplayName();
|
ret = player.getDisplayName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try Fixed Id
|
// Fixed Name
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
{
|
{
|
||||||
ret = Mixin.tryFix(senderId);
|
ret = IdUtil.getName(senderObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Id Fallback
|
||||||
|
if (ret == null)
|
||||||
|
{
|
||||||
|
ret = senderId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure Colored
|
// Ensure Colored
|
||||||
@ -63,8 +70,11 @@ public class DisplayNameMixinDefault extends DisplayNameMixinAbstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDisplayName(String senderId, String displayName)
|
public void setDisplayName(Object senderObject, String displayName)
|
||||||
{
|
{
|
||||||
|
String senderId = IdUtil.getId(senderObject);
|
||||||
|
if (senderId == null) return;
|
||||||
|
|
||||||
if (displayName == null)
|
if (displayName == null)
|
||||||
{
|
{
|
||||||
this.idToDisplayName.remove(senderId);
|
this.idToDisplayName.remove(senderId);
|
||||||
@ -74,9 +84,9 @@ public class DisplayNameMixinDefault extends DisplayNameMixinAbstract
|
|||||||
this.idToDisplayName.put(senderId, displayName);
|
this.idToDisplayName.put(senderId, displayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = SenderUtil.getPlayer(senderId);
|
Player player = IdUtil.getPlayer(senderObject);
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
player.setDisplayName(this.getDisplayName(senderId));
|
player.setDisplayName(this.getDisplayName(senderObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,12 +1,7 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
package com.massivecraft.mcore.mixin;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
public interface KickMixin
|
public interface KickMixin
|
||||||
{
|
{
|
||||||
public boolean kick(CommandSender sender);
|
public boolean kick(Object senderObject);
|
||||||
public boolean kick(String senderId);
|
public boolean kick(Object senderObject, String message);
|
||||||
|
|
||||||
public boolean kick(CommandSender sender, String message);
|
|
||||||
public boolean kick(String senderId, String message);
|
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,10 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
package com.massivecraft.mcore.mixin;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
public abstract class KickMixinAbstract implements KickMixin
|
public abstract class KickMixinAbstract implements KickMixin
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean kick(CommandSender sender)
|
public boolean kick(Object senderObject)
|
||||||
{
|
{
|
||||||
return this.kick(sender, null);
|
return this.kick(senderObject, null);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean kick(String senderId)
|
|
||||||
{
|
|
||||||
return this.kick(senderId, null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
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 com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public class KickMixinDefault extends KickMixinAbstract
|
public class KickMixinDefault extends KickMixinAbstract
|
||||||
{
|
{
|
||||||
@ -19,18 +18,9 @@ public class KickMixinDefault extends KickMixinAbstract
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean kick(CommandSender sender, String message)
|
public boolean kick(Object senderObject, String message)
|
||||||
{
|
{
|
||||||
Player player = SenderUtil.getAsPlayer(sender);
|
Player player = IdUtil.getPlayer(senderObject);
|
||||||
if (player == null) return false;
|
|
||||||
player.kickPlayer(message);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean kick(String senderId, String message)
|
|
||||||
{
|
|
||||||
Player player = SenderUtil.getPlayer(senderId);
|
|
||||||
if (player == null) return false;
|
if (player == null) return false;
|
||||||
player.kickPlayer(message);
|
player.kickPlayer(message);
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
package com.massivecraft.mcore.mixin;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
public interface ListNameMixin
|
public interface ListNameMixin
|
||||||
{
|
{
|
||||||
public String getListName(String senderId);
|
public String getListName(Object senderObject);
|
||||||
public void setListName(String senderId, String listName);
|
public void setListName(Object senderObject, String listName);
|
||||||
public String getListName(CommandSender sender);
|
|
||||||
public void setListName(CommandSender sender, String listName);
|
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,6 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
package com.massivecraft.mcore.mixin;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
|
||||||
|
|
||||||
public abstract class ListNameMixinAbstract implements ListNameMixin
|
public abstract class ListNameMixinAbstract implements ListNameMixin
|
||||||
{
|
{
|
||||||
@Override
|
|
||||||
public String getListName(CommandSender sender)
|
|
||||||
{
|
|
||||||
return this.getListName(SenderUtil.getSenderId(sender));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setListName(CommandSender sender, String listName)
|
|
||||||
{
|
|
||||||
this.setListName(SenderUtil.getSenderId(sender), listName);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ import java.util.TreeMap;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public class ListNameMixinDefault extends ListNameMixinAbstract
|
public class ListNameMixinDefault extends ListNameMixinAbstract
|
||||||
{
|
{
|
||||||
@ -30,27 +30,34 @@ public class ListNameMixinDefault extends ListNameMixinAbstract
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getListName(String senderId)
|
public String getListName(Object senderObject)
|
||||||
{
|
{
|
||||||
|
String senderId = IdUtil.getId(senderObject);
|
||||||
if (senderId == null) return null;
|
if (senderId == null) return null;
|
||||||
|
|
||||||
// Try Our Map
|
// Our Map
|
||||||
String ret = this.idToListName.get(senderId);
|
String ret = this.idToListName.get(senderId);
|
||||||
|
|
||||||
// Try Bukkit
|
// Bukkit
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
{
|
{
|
||||||
Player player = SenderUtil.getPlayer(senderId);
|
Player player = IdUtil.getPlayer(senderObject);
|
||||||
if (player != null)
|
if (player != null)
|
||||||
{
|
{
|
||||||
ret = player.getPlayerListName();
|
ret = player.getPlayerListName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try Fixed Id
|
// Fixed Name
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
{
|
{
|
||||||
ret = Mixin.tryFix(senderId);
|
ret = IdUtil.getName(senderObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Id Fallback
|
||||||
|
if (ret == null)
|
||||||
|
{
|
||||||
|
ret = senderId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure Colored
|
// Ensure Colored
|
||||||
@ -63,8 +70,11 @@ public class ListNameMixinDefault extends ListNameMixinAbstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setListName(String senderId, String listName)
|
public void setListName(Object senderObject, String listName)
|
||||||
{
|
{
|
||||||
|
String senderId = IdUtil.getId(senderObject);
|
||||||
|
if (senderId == null) return;
|
||||||
|
|
||||||
if (listName == null)
|
if (listName == null)
|
||||||
{
|
{
|
||||||
this.idToListName.remove(senderId);
|
this.idToListName.remove(senderId);
|
||||||
@ -74,9 +84,9 @@ public class ListNameMixinDefault extends ListNameMixinAbstract
|
|||||||
this.idToListName.put(senderId, listName);
|
this.idToListName.put(senderId, listName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = SenderUtil.getPlayer(senderId);
|
Player player = IdUtil.getPlayer(senderObject);
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
player.setPlayerListName(this.getListName(senderId));
|
player.setPlayerListName(this.getListName(senderObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -13,46 +13,37 @@ public interface MessageMixin
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
// All
|
// All
|
||||||
public boolean message(String message);
|
public boolean messageAll(String message);
|
||||||
public boolean message(String... messages);
|
public boolean messageAll(String... messages);
|
||||||
public boolean message(Collection<String> messages);
|
public boolean messageAll(Collection<String> messages);
|
||||||
|
|
||||||
// Predictate
|
// Predictate
|
||||||
public boolean message(Predictate<CommandSender> predictate, String message);
|
public boolean messagePredictate(Predictate<CommandSender> predictate, String message);
|
||||||
public boolean message(Predictate<CommandSender> predictate, String... messages);
|
public boolean messagePredictate(Predictate<CommandSender> predictate, String... messages);
|
||||||
public boolean message(Predictate<CommandSender> predictate, Collection<String> messages);
|
public boolean messagePredictate(Predictate<CommandSender> predictate, Collection<String> messages);
|
||||||
|
|
||||||
// One
|
// One
|
||||||
public boolean message(CommandSender sendee, String message);
|
public boolean messageOne(Object sendeeObject, String message);
|
||||||
public boolean message(CommandSender sendee, String... messages);
|
public boolean messageOne(Object sendeeObject, String... messages);
|
||||||
public boolean message(CommandSender sendee, Collection<String> messages);
|
public boolean messageOne(Object sendeeObject, Collection<String> messages);
|
||||||
|
|
||||||
// One by id
|
|
||||||
public boolean message(String sendeeId, String message);
|
|
||||||
public boolean message(String sendeeId, String... messages);
|
|
||||||
public boolean message(String sendeeId, Collection<String> messages);
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// PARSE MESSAGE
|
// PARSE MESSAGE
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
// All
|
// All
|
||||||
public boolean msg(String msg);
|
public boolean msgAll(String msg);
|
||||||
public boolean msg(String msg, Object... args);
|
public boolean msgAll(String msg, Object... args);
|
||||||
public boolean msg(Collection<String> msgs);
|
public boolean msgAll(Collection<String> msgs);
|
||||||
|
|
||||||
// Predictate
|
// Predictate
|
||||||
public boolean msg(Predictate<CommandSender> predictate, String msg);
|
public boolean msgPredictate(Predictate<CommandSender> predictate, String msg);
|
||||||
public boolean msg(Predictate<CommandSender> predictate, String msg, Object... args);
|
public boolean msgPredictate(Predictate<CommandSender> predictate, String msg, Object... args);
|
||||||
public boolean msg(Predictate<CommandSender> predictate, Collection<String> msgs);
|
public boolean msgPredictate(Predictate<CommandSender> predictate, Collection<String> msgs);
|
||||||
|
|
||||||
// One
|
// One
|
||||||
public boolean msg(CommandSender sendee, String msg);
|
public boolean msgOne(Object sendeeObject, String msg);
|
||||||
public boolean msg(CommandSender sendee, String msg, Object... args);
|
public boolean msgOne(Object sendeeObject, String msg, Object... args);
|
||||||
public boolean msg(CommandSender sendee, Collection<String> msgs);
|
public boolean msgOne(Object sendeeObject, Collection<String> msgs);
|
||||||
|
|
||||||
// One by id
|
|
||||||
public boolean msg(String sendeeId, String msg);
|
|
||||||
public boolean msg(String sendeeId, String msg, Object... args);
|
|
||||||
public boolean msg(String sendeeId, Collection<String> msgs);
|
|
||||||
}
|
}
|
||||||
|
@ -17,54 +17,41 @@ public abstract class MessageMixinAbstract implements MessageMixin
|
|||||||
|
|
||||||
// All
|
// All
|
||||||
@Override
|
@Override
|
||||||
public boolean message(String message)
|
public boolean messageAll(String message)
|
||||||
{
|
{
|
||||||
return this.message(MUtil.list(message));
|
return this.messageAll(MUtil.list(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean message(String... messages)
|
public boolean messageAll(String... messages)
|
||||||
{
|
{
|
||||||
return this.message(Arrays.asList(messages));
|
return this.messageAll(Arrays.asList(messages));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Predictate
|
// Predictate
|
||||||
@Override
|
@Override
|
||||||
public boolean message(Predictate<CommandSender> predictate, String message)
|
public boolean messagePredictate(Predictate<CommandSender> predictate, String message)
|
||||||
{
|
{
|
||||||
return this.message(predictate, MUtil.list(message));
|
return this.messagePredictate(predictate, MUtil.list(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean message(Predictate<CommandSender> predictate, String... messages)
|
public boolean messagePredictate(Predictate<CommandSender> predictate, String... messages)
|
||||||
{
|
{
|
||||||
return this.message(predictate, Arrays.asList(messages));
|
return this.messagePredictate(predictate, Arrays.asList(messages));
|
||||||
}
|
}
|
||||||
|
|
||||||
// One
|
// One
|
||||||
@Override
|
@Override
|
||||||
public boolean message(CommandSender sendee, String message)
|
public boolean messageOne(Object sendeeObject, String message)
|
||||||
{
|
{
|
||||||
return this.message(sendee, MUtil.list(message));
|
return this.messageOne(sendeeObject, MUtil.list(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean message(CommandSender sendee, String... messages)
|
public boolean messageOne(Object sendeeObject, String... messages)
|
||||||
{
|
{
|
||||||
return this.message(sendee, Arrays.asList(messages));
|
return this.messageOne(sendeeObject, Arrays.asList(messages));
|
||||||
}
|
|
||||||
|
|
||||||
// One by id
|
|
||||||
@Override
|
|
||||||
public boolean message(String sendeeId, String message)
|
|
||||||
{
|
|
||||||
return this.message(sendeeId, MUtil.list(message));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean message(String sendeeId, String... messages)
|
|
||||||
{
|
|
||||||
return this.message(sendeeId, Arrays.asList(messages));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -74,78 +61,59 @@ public abstract class MessageMixinAbstract implements MessageMixin
|
|||||||
|
|
||||||
// All
|
// All
|
||||||
@Override
|
@Override
|
||||||
public boolean msg(String msg)
|
public boolean msgAll(String msg)
|
||||||
{
|
{
|
||||||
return this.message(Txt.parse(msg));
|
return this.messageAll(Txt.parse(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean msg(String msg, Object... args)
|
public boolean msgAll(String msg, Object... args)
|
||||||
{
|
{
|
||||||
return this.message(Txt.parse(msg, args));
|
return this.messageAll(Txt.parse(msg, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean msg(Collection<String> msgs)
|
public boolean msgAll(Collection<String> msgs)
|
||||||
{
|
{
|
||||||
return this.message(Txt.parse(msgs));
|
return this.messageAll(Txt.parse(msgs));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Predictate
|
// Predictate
|
||||||
@Override
|
@Override
|
||||||
public boolean msg(Predictate<CommandSender> predictate, String msg)
|
public boolean msgPredictate(Predictate<CommandSender> predictate, String msg)
|
||||||
{
|
{
|
||||||
return this.message(predictate, Txt.parse(msg));
|
return this.messagePredictate(predictate, Txt.parse(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean msg(Predictate<CommandSender> predictate, String msg, Object... args)
|
public boolean msgPredictate(Predictate<CommandSender> predictate, String msg, Object... args)
|
||||||
{
|
{
|
||||||
return this.message(predictate, Txt.parse(msg, args));
|
return this.messagePredictate(predictate, Txt.parse(msg, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean msg(Predictate<CommandSender> predictate, Collection<String> msgs)
|
public boolean msgPredictate(Predictate<CommandSender> predictate, Collection<String> msgs)
|
||||||
{
|
{
|
||||||
return this.message(predictate, Txt.parse(msgs));
|
return this.messagePredictate(predictate, Txt.parse(msgs));
|
||||||
}
|
}
|
||||||
|
|
||||||
// One
|
// One
|
||||||
@Override
|
@Override
|
||||||
public boolean msg(CommandSender sendee, String msg)
|
public boolean msgOne(Object sendeeObject, String msg)
|
||||||
{
|
{
|
||||||
return this.message(sendee, Txt.parse(msg));
|
return this.messageOne(sendeeObject, Txt.parse(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean msg(CommandSender sendee, String msg, Object... args)
|
public boolean msgOne(Object sendeeObject, String msg, Object... args)
|
||||||
{
|
{
|
||||||
return this.message(sendee, Txt.parse(msg, args));
|
return this.messageOne(sendeeObject, Txt.parse(msg, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean msg(CommandSender sendee, Collection<String> msgs)
|
public boolean msgOne(Object sendeeObject, Collection<String> msgs)
|
||||||
{
|
{
|
||||||
return this.message(sendee, Txt.parse(msgs));
|
return this.messageOne(sendeeObject, Txt.parse(msgs));
|
||||||
}
|
|
||||||
|
|
||||||
// One by id
|
|
||||||
@Override
|
|
||||||
public boolean msg(String sendeeId, String msg)
|
|
||||||
{
|
|
||||||
return this.message(sendeeId, Txt.parse(msg));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean msg(String sendeeId, String msg, Object... args)
|
|
||||||
{
|
|
||||||
return this.message(sendeeId, Txt.parse(msg, args));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean msg(String sendeeId, Collection<String> msgs)
|
|
||||||
{
|
|
||||||
return this.message(sendeeId, Txt.parse(msgs));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import java.util.Collection;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import com.massivecraft.mcore.Predictate;
|
import com.massivecraft.mcore.Predictate;
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public class MessageMixinDefault extends MessageMixinAbstract
|
public class MessageMixinDefault extends MessageMixinAbstract
|
||||||
{
|
{
|
||||||
@ -21,44 +21,37 @@ public class MessageMixinDefault extends MessageMixinAbstract
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean message(Collection<String> messages)
|
public boolean messageAll(Collection<String> messages)
|
||||||
{
|
{
|
||||||
if (messages == null) return false;
|
if (messages == null) return false;
|
||||||
for (CommandSender sender : SenderUtil.getOnlineSenders())
|
for (CommandSender sender : IdUtil.getOnlineSenders())
|
||||||
{
|
{
|
||||||
this.message(sender, messages);
|
this.messageOne(sender, messages);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean message(Predictate<CommandSender> predictate, Collection<String> messages)
|
public boolean messagePredictate(Predictate<CommandSender> predictate, Collection<String> messages)
|
||||||
{
|
{
|
||||||
if (predictate == null) return false;
|
if (predictate == null) return false;
|
||||||
if (messages == null) return false;
|
if (messages == null) return false;
|
||||||
for (CommandSender sender : SenderUtil.getOnlineSenders())
|
for (CommandSender sender : IdUtil.getOnlineSenders())
|
||||||
{
|
{
|
||||||
if (!predictate.apply(sender)) continue;
|
if (!predictate.apply(sender)) continue;
|
||||||
this.message(sender, messages);
|
this.messageOne(sender, messages);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean message(CommandSender sendee, Collection<String> messages)
|
public boolean messageOne(Object sendeeObject, Collection<String> messages)
|
||||||
{
|
{
|
||||||
|
CommandSender sendee = IdUtil.getSender(sendeeObject);
|
||||||
if (sendee == null) return false;
|
if (sendee == null) return false;
|
||||||
if (messages == null) return false;
|
if (messages == null) return false;
|
||||||
sendee.sendMessage(messages.toArray(new String[0]));
|
sendee.sendMessage(messages.toArray(new String[0]));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean message(String sendeeId, Collection<String> messages)
|
|
||||||
{
|
|
||||||
if (sendeeId == null) return false;
|
|
||||||
if (messages == null) return false;
|
|
||||||
return this.message(SenderUtil.getSender(sendeeId), messages);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package com.massivecraft.mcore.mixin;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -46,10 +45,6 @@ public class Mixin
|
|||||||
public static VisibilityMixin getVisibilityMixin() { return visibilityMixin; }
|
public static VisibilityMixin getVisibilityMixin() { return visibilityMixin; }
|
||||||
public static void setVisibilityMixin(VisibilityMixin val) { visibilityMixin = val; }
|
public static void setVisibilityMixin(VisibilityMixin val) { visibilityMixin = val; }
|
||||||
|
|
||||||
private static SenderIdMixin senderIdMixin = SenderIdMixinDefault.get();
|
|
||||||
public static SenderIdMixin getSenderIdMixin() { return senderIdMixin; }
|
|
||||||
public static void setSenderIdMixin(SenderIdMixin val) { senderIdMixin = val; }
|
|
||||||
|
|
||||||
private static TeleportMixin teleportMixin = TeleportMixinDefault.get();
|
private static TeleportMixin teleportMixin = TeleportMixinDefault.get();
|
||||||
public static TeleportMixin getTeleportMixin() { return teleportMixin; }
|
public static TeleportMixin getTeleportMixin() { return teleportMixin; }
|
||||||
public static void setTeleportMixin(TeleportMixin val) { teleportMixin = val; }
|
public static void setTeleportMixin(TeleportMixin val) { teleportMixin = val; }
|
||||||
@ -128,24 +123,14 @@ public class Mixin
|
|||||||
// STATIC EXPOSE: DISPLAY NAME
|
// STATIC EXPOSE: DISPLAY NAME
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static String getDisplayName(String senderId)
|
public static String getDisplayName(Object senderObject)
|
||||||
{
|
{
|
||||||
return getDisplayNameMixin().getDisplayName(senderId);
|
return getDisplayNameMixin().getDisplayName(senderObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setDisplayName(String senderId, String displayName)
|
public static void setDisplayName(Object senderObject, String displayName)
|
||||||
{
|
{
|
||||||
getDisplayNameMixin().setDisplayName(senderId, displayName);
|
getDisplayNameMixin().setDisplayName(senderObject, displayName);
|
||||||
}
|
|
||||||
|
|
||||||
public static String getDisplayName(CommandSender sender)
|
|
||||||
{
|
|
||||||
return getDisplayNameMixin().getDisplayName(sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setDisplayName(CommandSender sender, String displayName)
|
|
||||||
{
|
|
||||||
getDisplayNameMixin().setDisplayName(sender, displayName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -176,103 +161,48 @@ public class Mixin
|
|||||||
// STATIC EXPOSE: SENDER PS
|
// STATIC EXPOSE: SENDER PS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static PS getSenderPs(String senderId)
|
public static PS getSenderPs(Object senderObject)
|
||||||
{
|
{
|
||||||
return getSenderPsMixin().getSenderPs(senderId);
|
return getSenderPsMixin().getSenderPs(senderObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setSenderPs(String senderId, PS ps)
|
public static void setSenderPs(Object senderObject, PS ps)
|
||||||
{
|
{
|
||||||
getSenderPsMixin().setSenderPs(senderId, ps);
|
getSenderPsMixin().setSenderPs(senderObject, ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// STATIC EXPOSE: PLAYED
|
// STATIC EXPOSE: PLAYED
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static boolean isOnline(String senderId)
|
public static boolean isOnline(Object senderObject)
|
||||||
{
|
{
|
||||||
return getPlayedMixin().isOnline(senderId);
|
return getPlayedMixin().isOnline(senderObject);
|
||||||
}
|
}
|
||||||
public static boolean isOffline(String senderId)
|
public static boolean isOffline(Object senderObject)
|
||||||
{
|
{
|
||||||
return getPlayedMixin().isOffline(senderId);
|
return getPlayedMixin().isOffline(senderObject);
|
||||||
}
|
}
|
||||||
public static Long getLastPlayed(String senderId)
|
public static Long getLastPlayed(Object senderObject)
|
||||||
{
|
{
|
||||||
return getPlayedMixin().getLastPlayed(senderId);
|
return getPlayedMixin().getLastPlayed(senderObject);
|
||||||
}
|
}
|
||||||
public static Long getFirstPlayed(String senderId)
|
public static Long getFirstPlayed(Object senderObject)
|
||||||
{
|
{
|
||||||
return getPlayedMixin().getFirstPlayed(senderId);
|
return getPlayedMixin().getFirstPlayed(senderObject);
|
||||||
}
|
}
|
||||||
public static boolean hasPlayedBefore(String senderId)
|
public static boolean hasPlayedBefore(Object senderObject)
|
||||||
{
|
{
|
||||||
return getPlayedMixin().hasPlayedBefore(senderId);
|
return getPlayedMixin().hasPlayedBefore(senderObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// STATIC EXPOSE: VISIBILITY
|
// STATIC EXPOSE: VISIBILITY
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static boolean canSee(String watcherId, String watcheeId)
|
public static boolean canSee(Object watcherObject, Object watcheeObject)
|
||||||
{
|
{
|
||||||
return getVisibilityMixin().canSee(watcherId, watcheeId);
|
return getVisibilityMixin().canSee(watcherObject, watcheeObject);
|
||||||
}
|
|
||||||
public static boolean canSee(CommandSender watcher, String watcheeId)
|
|
||||||
{
|
|
||||||
return getVisibilityMixin().canSee(watcher, watcheeId);
|
|
||||||
}
|
|
||||||
public static boolean canSee(String watcherId, CommandSender watchee)
|
|
||||||
{
|
|
||||||
return getVisibilityMixin().canSee(watcherId, watchee);
|
|
||||||
}
|
|
||||||
public static boolean canSee(CommandSender watcher, CommandSender watchee)
|
|
||||||
{
|
|
||||||
return getVisibilityMixin().canSee(watcher, watchee);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// STATIC EXPOSE: SENDER ID
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static String reqFix(String senderId)
|
|
||||||
{
|
|
||||||
return getSenderIdMixin().reqFix(senderId);
|
|
||||||
}
|
|
||||||
public static String tryFix(String senderId)
|
|
||||||
{
|
|
||||||
return getSenderIdMixin().tryFix(senderId);
|
|
||||||
}
|
|
||||||
public static boolean canFix(String senderId)
|
|
||||||
{
|
|
||||||
return getSenderIdMixin().canFix(senderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<String> getAllSenderIds()
|
|
||||||
{
|
|
||||||
return getSenderIdMixin().getAllSenderIds();
|
|
||||||
}
|
|
||||||
public static Set<String> getOnlineSenderIds()
|
|
||||||
{
|
|
||||||
return getSenderIdMixin().getOnlineSenderIds();
|
|
||||||
}
|
|
||||||
public static Set<String> getOfflineSenderIds()
|
|
||||||
{
|
|
||||||
return getSenderIdMixin().getOfflineSenderIds();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<String> getAllPlayerIds()
|
|
||||||
{
|
|
||||||
return getSenderIdMixin().getAllPlayerIds();
|
|
||||||
}
|
|
||||||
public static Set<String> getOnlinePlayerIds()
|
|
||||||
{
|
|
||||||
return getSenderIdMixin().getOnlinePlayerIds();
|
|
||||||
}
|
|
||||||
public static Set<String> getOfflinePlayerIds()
|
|
||||||
{
|
|
||||||
return getSenderIdMixin().getOfflinePlayerIds();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -284,274 +214,94 @@ public class Mixin
|
|||||||
return getTeleportMixin().isCausedByMixin(event);
|
return getTeleportMixin().isCausedByMixin(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandSender & PS
|
// PS
|
||||||
public static void teleport(CommandSender teleportee, PS to) throws TeleporterException
|
public static void teleport(Object teleporteeObject, PS to) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to);
|
getTeleportMixin().teleport(teleporteeObject, to);
|
||||||
}
|
}
|
||||||
public static void teleport(CommandSender teleportee, PS to, String desc) throws TeleporterException
|
public static void teleport(Object teleporteeObject, PS to, String desc) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to, desc);
|
getTeleportMixin().teleport(teleporteeObject, to, desc);
|
||||||
}
|
}
|
||||||
public static void teleport(CommandSender teleportee, PS to, String desc, Permissible delayPermissible) throws TeleporterException
|
public static void teleport(Object teleporteeObject, PS to, String desc, Permissible delayPermissible) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delayPermissible);
|
getTeleportMixin().teleport(teleporteeObject, to, desc, delayPermissible);
|
||||||
}
|
}
|
||||||
public static void teleport(CommandSender teleportee, PS to, String desc, int delaySeconds) throws TeleporterException
|
public static void teleport(Object teleporteeObject, PS to, String desc, int delaySeconds) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delaySeconds);
|
getTeleportMixin().teleport(teleporteeObject, to, desc, delaySeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandSender & CommandSender
|
// CommandSender
|
||||||
public static void teleport(CommandSender teleportee, CommandSender to) throws TeleporterException
|
public static void teleport(Object teleporteeObject, CommandSender to) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to);
|
getTeleportMixin().teleport(teleporteeObject, to);
|
||||||
}
|
}
|
||||||
public static void teleport(CommandSender teleportee, CommandSender to, String desc) throws TeleporterException
|
public static void teleport(Object teleporteeObject, CommandSender to, String desc) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to, desc);
|
getTeleportMixin().teleport(teleporteeObject, to, desc);
|
||||||
}
|
}
|
||||||
public static void teleport(CommandSender teleportee, CommandSender to, String desc, Permissible delayPermissible) throws TeleporterException
|
public static void teleport(Object teleporteeObject, CommandSender to, String desc, Permissible delayPermissible) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delayPermissible);
|
getTeleportMixin().teleport(teleporteeObject, to, desc, delayPermissible);
|
||||||
}
|
}
|
||||||
public static void teleport(CommandSender teleportee, CommandSender to, String desc, int delaySeconds) throws TeleporterException
|
public static void teleport(Object teleporteeObject, CommandSender to, String desc, int delaySeconds) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delaySeconds);
|
getTeleportMixin().teleport(teleporteeObject, to, desc, delaySeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandSender & SenderEntity
|
// SenderEntity
|
||||||
public static void teleport(CommandSender teleportee, SenderEntity<?> to) throws TeleporterException
|
public static void teleport(Object teleporteeObject, SenderEntity<?> to) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to);
|
getTeleportMixin().teleport(teleporteeObject, to);
|
||||||
}
|
}
|
||||||
public static void teleport(CommandSender teleportee, SenderEntity<?> to, String desc) throws TeleporterException
|
public static void teleport(Object teleporteeObject, SenderEntity<?> to, String desc) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to, desc);
|
getTeleportMixin().teleport(teleporteeObject, to, desc);
|
||||||
}
|
}
|
||||||
public static void teleport(CommandSender teleportee, SenderEntity<?> to, String desc, Permissible delayPermissible) throws TeleporterException
|
public static void teleport(Object teleporteeObject, SenderEntity<?> to, String desc, Permissible delayPermissible) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delayPermissible);
|
getTeleportMixin().teleport(teleporteeObject, to, desc, delayPermissible);
|
||||||
}
|
}
|
||||||
public static void teleport(CommandSender teleportee, SenderEntity<?> to, String desc, int delaySeconds) throws TeleporterException
|
public static void teleport(Object teleporteeObject, SenderEntity<?> to, String desc, int delaySeconds) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delaySeconds);
|
getTeleportMixin().teleport(teleporteeObject, to, desc, delaySeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandSender & String
|
// String
|
||||||
public static void teleport(CommandSender teleportee, String to) throws TeleporterException
|
public static void teleport(Object teleporteeObject, String to) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to);
|
getTeleportMixin().teleport(teleporteeObject, to);
|
||||||
}
|
}
|
||||||
public static void teleport(CommandSender teleportee, String to, String desc) throws TeleporterException
|
public static void teleport(Object teleporteeObject, String to, String desc) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to, desc);
|
getTeleportMixin().teleport(teleporteeObject, to, desc);
|
||||||
}
|
}
|
||||||
public static void teleport(CommandSender teleportee, String to, String desc, Permissible delayPermissible) throws TeleporterException
|
public static void teleport(Object teleporteeObject, String to, String desc, Permissible delayPermissible) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delayPermissible);
|
getTeleportMixin().teleport(teleporteeObject, to, desc, delayPermissible);
|
||||||
}
|
}
|
||||||
public static void teleport(CommandSender teleportee, String to, String desc, int delaySeconds) throws TeleporterException
|
public static void teleport(Object teleporteeObject, String to, String desc, int delaySeconds) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delaySeconds);
|
getTeleportMixin().teleport(teleporteeObject, to, desc, delaySeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandSender & PSGetter
|
// PSGetter
|
||||||
public static void teleport(CommandSender teleportee, PSGetter to) throws TeleporterException
|
public static void teleport(Object teleporteeObject, PSGetter to) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to);
|
getTeleportMixin().teleport(teleporteeObject, to);
|
||||||
}
|
}
|
||||||
public static void teleport(CommandSender teleportee, PSGetter to, String desc) throws TeleporterException
|
public static void teleport(Object teleporteeObject, PSGetter to, String desc) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to, desc);
|
getTeleportMixin().teleport(teleporteeObject, to, desc);
|
||||||
}
|
}
|
||||||
public static void teleport(CommandSender teleportee, PSGetter to, String desc, Permissible delayPermissible) throws TeleporterException
|
public static void teleport(Object teleporteeObject, PSGetter to, String desc, Permissible delayPermissible) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delayPermissible);
|
getTeleportMixin().teleport(teleporteeObject, to, desc, delayPermissible);
|
||||||
}
|
}
|
||||||
public static void teleport(CommandSender teleportee, PSGetter to, String desc, int delaySeconds) throws TeleporterException
|
public static void teleport(Object teleporteeObject, PSGetter to, String desc, int delaySeconds) throws TeleporterException
|
||||||
{
|
{
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delaySeconds);
|
getTeleportMixin().teleport(teleporteeObject, to, desc, delaySeconds);
|
||||||
}
|
|
||||||
|
|
||||||
// SenderEntity & PS
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, PS to) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to);
|
|
||||||
}
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, PS to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc);
|
|
||||||
}
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, PS to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delayPermissible);
|
|
||||||
}
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, PS to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// SenderEntity & CommandSender
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, CommandSender to) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to);
|
|
||||||
}
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, CommandSender to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc);
|
|
||||||
}
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, CommandSender to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delayPermissible);
|
|
||||||
}
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, CommandSender to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// SenderEntity & SenderEntity
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, SenderEntity<?> to) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to);
|
|
||||||
}
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, SenderEntity<?> to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc);
|
|
||||||
}
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, SenderEntity<?> to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delayPermissible);
|
|
||||||
}
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, SenderEntity<?> to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// SenderEntity & String
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, String to) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to);
|
|
||||||
}
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, String to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc);
|
|
||||||
}
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, String to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delayPermissible);
|
|
||||||
}
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, String to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// SenderEntity & PSGetter
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, PSGetter to) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to);
|
|
||||||
}
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, PSGetter to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc);
|
|
||||||
}
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, PSGetter to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delayPermissible);
|
|
||||||
}
|
|
||||||
public static void teleport(SenderEntity<?> teleportee, PSGetter to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// String & PS
|
|
||||||
public static void teleport(String teleportee, PS to) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleportee, PS to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleportee, PS to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delayPermissible);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleportee, PS to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// String & CommandSender
|
|
||||||
public static void teleport(String teleportee, CommandSender to) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleportee, CommandSender to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleportee, CommandSender to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delayPermissible);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleportee, CommandSender to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// String & SenderEntity
|
|
||||||
public static void teleport(String teleportee, SenderEntity<?> to) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleportee, SenderEntity<?> to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleportee, SenderEntity<?> to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delayPermissible);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleportee, SenderEntity<?> to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// String & String
|
|
||||||
public static void teleport(String teleportee, String to) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleportee, String to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleportee, String to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delayPermissible);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleportee, String to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// String & PSGetter
|
|
||||||
public static void teleport(String teleportee, PSGetter to) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleportee, PSGetter to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleportee, PSGetter to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delayPermissible);
|
|
||||||
}
|
|
||||||
public static void teleport(String teleportee, PSGetter to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
getTeleportMixin().teleport(teleportee, to, desc, delaySeconds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -559,137 +309,101 @@ public class Mixin
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
// All
|
// All
|
||||||
public static boolean message(String message)
|
public static boolean messageAll(String message)
|
||||||
{
|
{
|
||||||
return getMessageMixin().message(message);
|
return getMessageMixin().messageAll(message);
|
||||||
}
|
}
|
||||||
public static boolean message(String... messages)
|
public static boolean messageAll(String... messages)
|
||||||
{
|
{
|
||||||
return getMessageMixin().message(messages);
|
return getMessageMixin().messageAll(messages);
|
||||||
}
|
}
|
||||||
public static boolean message(Collection<String> messages)
|
public static boolean messageAll(Collection<String> messages)
|
||||||
{
|
{
|
||||||
return getMessageMixin().message(messages);
|
return getMessageMixin().messageAll(messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Predictate
|
// Predictate
|
||||||
public static boolean message(Predictate<CommandSender> predictate, String message)
|
public static boolean messagePredictate(Predictate<CommandSender> predictate, String message)
|
||||||
{
|
{
|
||||||
return getMessageMixin().message(predictate, message);
|
return getMessageMixin().messagePredictate(predictate, message);
|
||||||
}
|
}
|
||||||
public static boolean message(Predictate<CommandSender> predictate, String... messages)
|
public static boolean messagePredictate(Predictate<CommandSender> predictate, String... messages)
|
||||||
{
|
{
|
||||||
return getMessageMixin().message(predictate, messages);
|
return getMessageMixin().messagePredictate(predictate, messages);
|
||||||
}
|
}
|
||||||
public static boolean message(Predictate<CommandSender> predictate, Collection<String> messages)
|
public static boolean messagePredictate(Predictate<CommandSender> predictate, Collection<String> messages)
|
||||||
{
|
{
|
||||||
return getMessageMixin().message(predictate, messages);
|
return getMessageMixin().messagePredictate(predictate, messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
// One
|
// One
|
||||||
public static boolean message(CommandSender sender, String message)
|
public static boolean messageOne(Object senderObject, String message)
|
||||||
{
|
{
|
||||||
return getMessageMixin().message(sender, message);
|
return getMessageMixin().messageOne(senderObject, message);
|
||||||
}
|
}
|
||||||
public static boolean message(CommandSender sender, String... messages)
|
public static boolean messageOne(Object senderObject, String... messages)
|
||||||
{
|
{
|
||||||
return getMessageMixin().message(sender, messages);
|
return getMessageMixin().messageOne(senderObject, messages);
|
||||||
}
|
}
|
||||||
public static boolean message(CommandSender sender, Collection<String> messages)
|
public static boolean messageOne(Object senderObject, Collection<String> messages)
|
||||||
{
|
{
|
||||||
return getMessageMixin().message(sender, messages);
|
return getMessageMixin().messageOne(senderObject, messages);
|
||||||
}
|
|
||||||
|
|
||||||
// One by id
|
|
||||||
public static boolean message(String senderId, String message)
|
|
||||||
{
|
|
||||||
return getMessageMixin().message(senderId, message);
|
|
||||||
}
|
|
||||||
public static boolean message(String senderId, String... messages)
|
|
||||||
{
|
|
||||||
return getMessageMixin().message(senderId, messages);
|
|
||||||
}
|
|
||||||
public static boolean message(String senderId, Collection<String> messages)
|
|
||||||
{
|
|
||||||
return getMessageMixin().message(senderId, messages);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// All
|
// All
|
||||||
public static boolean msg(String msg)
|
public static boolean msgAll(String msg)
|
||||||
{
|
{
|
||||||
return getMessageMixin().msg(msg);
|
return getMessageMixin().msgAll(msg);
|
||||||
}
|
}
|
||||||
public static boolean msg(String msg, Object... args)
|
public static boolean msgAll(String msg, Object... args)
|
||||||
{
|
{
|
||||||
return getMessageMixin().msg(msg, args);
|
return getMessageMixin().msgAll(msg, args);
|
||||||
}
|
}
|
||||||
public static boolean msg(Collection<String> msgs)
|
public static boolean msgAll(Collection<String> msgs)
|
||||||
{
|
{
|
||||||
return getMessageMixin().msg(msgs);
|
return getMessageMixin().msgAll(msgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Predictate
|
// Predictate
|
||||||
public static boolean msg(Predictate<CommandSender> predictate, String msg)
|
public static boolean msgPredictate(Predictate<CommandSender> predictate, String msg)
|
||||||
{
|
{
|
||||||
return getMessageMixin().msg(predictate, msg);
|
return getMessageMixin().msgPredictate(predictate, msg);
|
||||||
}
|
}
|
||||||
public static boolean msg(Predictate<CommandSender> predictate, String msg, Object... args)
|
public static boolean msgPredictate(Predictate<CommandSender> predictate, String msg, Object... args)
|
||||||
{
|
{
|
||||||
return getMessageMixin().msg(predictate, msg, args);
|
return getMessageMixin().msgPredictate(predictate, msg, args);
|
||||||
}
|
}
|
||||||
public static boolean msg(Predictate<CommandSender> predictate, Collection<String> msgs)
|
public static boolean msgPredictate(Predictate<CommandSender> predictate, Collection<String> msgs)
|
||||||
{
|
{
|
||||||
return getMessageMixin().msg(predictate, msgs);
|
return getMessageMixin().msgPredictate(predictate, msgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// One
|
// One
|
||||||
public static boolean msg(CommandSender sender, String msg)
|
public static boolean msgOne(Object senderObject, String msg)
|
||||||
{
|
{
|
||||||
return getMessageMixin().msg(sender, msg);
|
return getMessageMixin().msgOne(senderObject, msg);
|
||||||
}
|
}
|
||||||
public static boolean msg(CommandSender sender, String msg, Object... args)
|
public static boolean msgOne(Object senderObject, String msg, Object... args)
|
||||||
{
|
{
|
||||||
return getMessageMixin().msg(sender, msg, args);
|
return getMessageMixin().msgOne(senderObject, msg, args);
|
||||||
}
|
}
|
||||||
public static boolean msg(CommandSender sender, Collection<String> msgs)
|
public static boolean msgOne(Object senderObject, Collection<String> msgs)
|
||||||
{
|
{
|
||||||
return getMessageMixin().msg(sender, msgs);
|
return getMessageMixin().msgOne(senderObject, msgs);
|
||||||
}
|
|
||||||
|
|
||||||
// One by id
|
|
||||||
public static boolean msg(String senderId, String msg)
|
|
||||||
{
|
|
||||||
return getMessageMixin().msg(senderId, msg);
|
|
||||||
}
|
|
||||||
public static boolean msg(String senderId, String msg, Object... args)
|
|
||||||
{
|
|
||||||
return getMessageMixin().msg(senderId, msg, args);
|
|
||||||
}
|
|
||||||
public static boolean msg(String senderId, Collection<String> msgs)
|
|
||||||
{
|
|
||||||
return getMessageMixin().msg(senderId, msgs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// STATIC EXPOSE: KICK
|
// STATIC EXPOSE: KICK
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static boolean kick(CommandSender sender)
|
public static boolean kick(Object senderObject)
|
||||||
{
|
{
|
||||||
return getKickMixin().kick(sender);
|
return getKickMixin().kick(senderObject);
|
||||||
}
|
|
||||||
public static boolean kick(String senderId)
|
|
||||||
{
|
|
||||||
return getKickMixin().kick(senderId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean kick(CommandSender sender, String message)
|
public static boolean kick(Object senderObject, String message)
|
||||||
{
|
{
|
||||||
return getKickMixin().kick(sender, message);
|
return getKickMixin().kick(senderObject, message);
|
||||||
}
|
|
||||||
public static boolean kick(String senderId, String message)
|
|
||||||
{
|
|
||||||
return getKickMixin().kick(senderId, message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -710,24 +424,14 @@ public class Mixin
|
|||||||
// STATIC EXPOSE: COMMAND
|
// STATIC EXPOSE: COMMAND
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static boolean dispatchCommand(CommandSender sender, String commandLine)
|
public static boolean dispatchCommand(Object senderObject, String commandLine)
|
||||||
{
|
{
|
||||||
return getCommandMixin().dispatchCommand(sender, commandLine);
|
return getCommandMixin().dispatchCommand(senderObject, commandLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean dispatchCommand(SenderEntity<?> sender, String commandLine)
|
public static boolean dispatchCommand(Object presentObject, Object senderObject, String commandLine)
|
||||||
{
|
{
|
||||||
return getCommandMixin().dispatchCommand(sender, commandLine);
|
return getCommandMixin().dispatchCommand(presentObject, senderObject, commandLine);
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean dispatchCommand(String senderId, String commandLine)
|
|
||||||
{
|
|
||||||
return getCommandMixin().dispatchCommand(senderId, commandLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean dispatchCommand(String presentId, String senderId, String commandLine)
|
|
||||||
{
|
|
||||||
return getCommandMixin().dispatchCommand(presentId, senderId, commandLine);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@ package com.massivecraft.mcore.mixin;
|
|||||||
|
|
||||||
public interface PlayedMixin
|
public interface PlayedMixin
|
||||||
{
|
{
|
||||||
public boolean isOnline(String senderId);
|
public boolean isOnline(Object senderObject);
|
||||||
public boolean isOffline(String senderId);
|
public boolean isOffline(Object senderObject);
|
||||||
public Long getFirstPlayed(String senderId);
|
public Long getFirstPlayed(Object senderObject);
|
||||||
public Long getLastPlayed(String senderId);
|
public Long getLastPlayed(Object senderObject);
|
||||||
public boolean hasPlayedBefore(String senderId);
|
public boolean hasPlayedBefore(Object senderObject);
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,25 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
package com.massivecraft.mcore.mixin;
|
||||||
|
|
||||||
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public abstract class PlayedMixinAbstract implements PlayedMixin
|
public abstract class PlayedMixinAbstract implements PlayedMixin
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOffline(String senderId)
|
public boolean isOnline(Object senderObject)
|
||||||
{
|
{
|
||||||
return !this.isOnline(senderId);
|
return IdUtil.isOnline(senderObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPlayedBefore(String senderId)
|
public boolean isOffline(Object senderObject)
|
||||||
{
|
{
|
||||||
Long firstPlayed = this.getFirstPlayed(senderId);
|
return !this.isOnline(senderObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPlayedBefore(Object senderObject)
|
||||||
|
{
|
||||||
|
Long firstPlayed = this.getFirstPlayed(senderObject);
|
||||||
return firstPlayed != null && firstPlayed != 0;
|
return firstPlayed != null && firstPlayed != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
package com.massivecraft.mcore.mixin;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
||||||
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public class PlayedMixinDefault extends PlayedMixinAbstract
|
public class PlayedMixinDefault extends PlayedMixinAbstract
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -17,29 +21,34 @@ public class PlayedMixinDefault extends PlayedMixinAbstract
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOnline(String senderId)
|
public Long getFirstPlayed(Object senderObject)
|
||||||
{
|
{
|
||||||
if (senderId == null) return false;
|
UUID uuid = IdUtil.getUuid(senderObject);
|
||||||
return Mixin.getOnlineSenderIds().contains(senderId);
|
if (uuid == null) return null;
|
||||||
}
|
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
|
||||||
|
if (offlinePlayer == null) return null;
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long getFirstPlayed(String senderId)
|
|
||||||
{
|
|
||||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(senderId);
|
|
||||||
Long ret = offlinePlayer.getFirstPlayed();
|
Long ret = offlinePlayer.getFirstPlayed();
|
||||||
if (ret == 0) ret = null;
|
if (ret == 0) ret = null;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getLastPlayed(String senderId)
|
public Long getLastPlayed(Object senderObject)
|
||||||
{
|
{
|
||||||
if (this.isOnline(senderId)) return System.currentTimeMillis();
|
//if (this.isOnline(senderObject)) return System.currentTimeMillis();
|
||||||
|
// We do in fact NOT want this commented out behavior
|
||||||
|
// It's important we can check the previous played time on join!
|
||||||
|
|
||||||
|
UUID uuid = IdUtil.getUuid(senderObject);
|
||||||
|
if (uuid == null) return null;
|
||||||
|
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
|
||||||
|
if (offlinePlayer == null) return null;
|
||||||
|
|
||||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(senderId);
|
|
||||||
Long ret = offlinePlayer.getLastPlayed();
|
Long ret = offlinePlayer.getLastPlayed();
|
||||||
if (ret == 0) ret = null;
|
if (ret == 0) ret = null;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public interface SenderIdMixin
|
|
||||||
{
|
|
||||||
// Q: What do you mean "fix" a senderId?
|
|
||||||
// A: A senderId is case insensitive. However a certain caseing may be the best looking one. Player do for example have an optimal caseing.
|
|
||||||
public String reqFix(String senderId);
|
|
||||||
public String tryFix(String senderId);
|
|
||||||
public boolean canFix(String senderId);
|
|
||||||
|
|
||||||
// These may be unmodifiable. Don't expect them to be changeable.
|
|
||||||
public Set<String> getAllSenderIds();
|
|
||||||
public Set<String> getOnlineSenderIds();
|
|
||||||
public Set<String> getOfflineSenderIds();
|
|
||||||
|
|
||||||
public Set<String> getAllPlayerIds();
|
|
||||||
public Set<String> getOnlinePlayerIds();
|
|
||||||
public Set<String> getOfflinePlayerIds();
|
|
||||||
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
|
||||||
|
|
||||||
public abstract class SenderIdMixinAbstract implements SenderIdMixin
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public String tryFix(String senderId)
|
|
||||||
{
|
|
||||||
String ret = this.reqFix(senderId);
|
|
||||||
if (ret != null) return ret;
|
|
||||||
return senderId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canFix(String senderId)
|
|
||||||
{
|
|
||||||
return this.reqFix(senderId) != null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,232 +0,0 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ConcurrentSkipListMap;
|
|
||||||
import java.util.concurrent.ConcurrentSkipListSet;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
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.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
|
||||||
|
|
||||||
import com.massivecraft.mcore.MCore;
|
|
||||||
import com.massivecraft.mcore.event.MCorePlayerLeaveEvent;
|
|
||||||
import com.massivecraft.mcore.event.MCoreSenderRegisterEvent;
|
|
||||||
import com.massivecraft.mcore.event.MCoreSenderUnregisterEvent;
|
|
||||||
import com.massivecraft.mcore.util.PlayerUtil;
|
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
|
||||||
import com.massivecraft.mcore.util.Txt;
|
|
||||||
|
|
||||||
public class SenderIdMixinDefault extends SenderIdMixinAbstract implements Listener
|
|
||||||
{
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// INSTANCE & CONSTRUCT
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
private static SenderIdMixinDefault i = new SenderIdMixinDefault();
|
|
||||||
public static SenderIdMixinDefault get() { return i; }
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// SETUP
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public void setup()
|
|
||||||
{
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
|
|
||||||
// Create new empty sets
|
|
||||||
this.allSenderIds = new ConcurrentSkipListMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
|
||||||
this.onlineSenderIds = new ConcurrentSkipListSet<String>(String.CASE_INSENSITIVE_ORDER);
|
|
||||||
this.offlineSenderIds = new ConcurrentSkipListSet<String>(String.CASE_INSENSITIVE_ORDER);
|
|
||||||
|
|
||||||
this.allPlayerIds = new ConcurrentSkipListSet<String>(String.CASE_INSENSITIVE_ORDER);
|
|
||||||
this.onlinePlayerIds = new ConcurrentSkipListSet<String>(String.CASE_INSENSITIVE_ORDER);
|
|
||||||
this.offlinePlayerIds = new ConcurrentSkipListSet<String>(String.CASE_INSENSITIVE_ORDER);
|
|
||||||
|
|
||||||
// Add online players
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers())
|
|
||||||
{
|
|
||||||
String id = player.getName();
|
|
||||||
|
|
||||||
this.allSenderIds.put(id, id);
|
|
||||||
this.allPlayerIds.add(id);
|
|
||||||
|
|
||||||
this.onlineSenderIds.add(id);
|
|
||||||
this.onlinePlayerIds.add(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add offline players
|
|
||||||
for (String id : PlayerUtil.getDirectoryPlayerNames())
|
|
||||||
{
|
|
||||||
// Check if this player was added already since it's online
|
|
||||||
if (this.onlinePlayerIds.contains(id)) continue;
|
|
||||||
|
|
||||||
this.allSenderIds.put(id, id);
|
|
||||||
this.allPlayerIds.add(id);
|
|
||||||
|
|
||||||
this.offlineSenderIds.add(id);
|
|
||||||
this.offlinePlayerIds.add(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add command senders
|
|
||||||
for (String id : SenderUtil.getIdToSender().keySet())
|
|
||||||
{
|
|
||||||
this.allSenderIds.put(id, id);
|
|
||||||
this.onlineSenderIds.add(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(this, MCore.get());
|
|
||||||
|
|
||||||
long end = System.currentTimeMillis();
|
|
||||||
MCore.get().log(Txt.parse("<i>Setup of SenderIdMixinDefault took <h>%d<i>ms.", end-start));
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// FIELDS
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
// The first field is a map since we use it for the "try" methods.
|
|
||||||
protected Map<String, String> allSenderIds;
|
|
||||||
protected Set<String> onlineSenderIds;
|
|
||||||
protected Set<String> offlineSenderIds;
|
|
||||||
|
|
||||||
protected Set<String> allPlayerIds;
|
|
||||||
protected Set<String> onlinePlayerIds;
|
|
||||||
protected Set<String> offlinePlayerIds;
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// UTIL
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
protected void onOnlineChanged(CommandSender sender, boolean isOnline)
|
|
||||||
{
|
|
||||||
boolean isPlayer = SenderUtil.isPlayer(sender);
|
|
||||||
String id = SenderUtil.getSenderId(sender);
|
|
||||||
|
|
||||||
this.allSenderIds.put(id, id);
|
|
||||||
if (isPlayer)
|
|
||||||
{
|
|
||||||
this.allPlayerIds.add(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isOnline)
|
|
||||||
{
|
|
||||||
this.onlineSenderIds.add(id);
|
|
||||||
this.offlineSenderIds.remove(id);
|
|
||||||
if (isPlayer)
|
|
||||||
{
|
|
||||||
this.onlinePlayerIds.add(id);
|
|
||||||
this.offlinePlayerIds.remove(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.offlineSenderIds.add(id);
|
|
||||||
this.onlineSenderIds.remove(id);
|
|
||||||
if (isPlayer)
|
|
||||||
{
|
|
||||||
this.offlinePlayerIds.add(id);
|
|
||||||
this.onlinePlayerIds.remove(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// LISTENER
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
// We don't care if it's cancelled or not.
|
|
||||||
// We just wan't to make sure this id is known of and can be "fixed" asap.
|
|
||||||
// Online or not? We just use the mixin to get the actuall value.
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public void playerLoginLowest(PlayerLoginEvent event)
|
|
||||||
{
|
|
||||||
boolean isOnline = Mixin.isOnline(SenderUtil.getSenderId(event.getPlayer()));
|
|
||||||
this.onOnlineChanged(event.getPlayer(), isOnline);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Can't be cancelled
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public void playerJoinLowest(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
this.onOnlineChanged(event.getPlayer(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Can't be cancelled
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public void senderRegisterLowest(MCoreSenderRegisterEvent event)
|
|
||||||
{
|
|
||||||
this.onOnlineChanged(event.getSender(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Can't be cancelled
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void playerLeaveMonitor(MCorePlayerLeaveEvent event)
|
|
||||||
{
|
|
||||||
this.onOnlineChanged(event.getPlayer(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Can't be cancelled
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void senderUnregisterLowest(MCoreSenderUnregisterEvent event)
|
|
||||||
{
|
|
||||||
this.onOnlineChanged(event.getSender(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// OVERRIDE: FIX
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String reqFix(String senderId)
|
|
||||||
{
|
|
||||||
return this.allSenderIds.get(senderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// OVERRIDE: SETS
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getAllSenderIds()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableSet(this.allSenderIds.keySet());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getOnlineSenderIds()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableSet(this.onlineSenderIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getOfflineSenderIds()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableSet(this.offlineSenderIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getAllPlayerIds()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableSet(this.allPlayerIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getOnlinePlayerIds()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableSet(this.onlinePlayerIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getOfflinePlayerIds()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableSet(this.offlinePlayerIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -4,6 +4,6 @@ import com.massivecraft.mcore.ps.PS;
|
|||||||
|
|
||||||
public interface SenderPsMixin
|
public interface SenderPsMixin
|
||||||
{
|
{
|
||||||
public PS getSenderPs(String senderId);
|
public PS getSenderPs(Object senderObject);
|
||||||
public void setSenderPs(String senderId, PS ps);
|
public void setSenderPs(Object senderObject, PS ps);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package com.massivecraft.mcore.mixin;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.massivecraft.mcore.ps.PS;
|
import com.massivecraft.mcore.ps.PS;
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public class SenderPsMixinDefault extends SenderPsMixinAbstract
|
public class SenderPsMixinDefault extends SenderPsMixinAbstract
|
||||||
{
|
{
|
||||||
@ -19,15 +19,15 @@ public class SenderPsMixinDefault extends SenderPsMixinAbstract
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PS getSenderPs(String senderId)
|
public PS getSenderPs(Object senderObject)
|
||||||
{
|
{
|
||||||
Player player = SenderUtil.getPlayer(senderId);
|
Player player = IdUtil.getPlayer(senderObject);
|
||||||
if (player == null) return null;
|
if (player == null) return null;
|
||||||
return PS.valueOf(player.getLocation());
|
return PS.valueOf(player.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSenderPs(String senderId, PS ps)
|
public void setSenderPs(Object senderObject, PS ps)
|
||||||
{
|
{
|
||||||
// Bukkit does not support setting the physical state for offline players for now.
|
// Bukkit does not support setting the physical state for offline players for now.
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,6 @@ public interface TeleportMixin
|
|||||||
public boolean isCausedByMixin(PlayerTeleportEvent event);
|
public boolean isCausedByMixin(PlayerTeleportEvent event);
|
||||||
|
|
||||||
// PERMUTATION
|
// PERMUTATION
|
||||||
//
|
|
||||||
// # teleportee
|
|
||||||
// CommandSender
|
|
||||||
// SenderEntity
|
|
||||||
// String
|
|
||||||
//
|
|
||||||
// # to
|
// # to
|
||||||
// PS
|
// PS
|
||||||
// CommandSender
|
// CommandSender
|
||||||
@ -34,108 +28,34 @@ public interface TeleportMixin
|
|||||||
// COMMAND SENDER
|
// COMMAND SENDER
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
// CommandSender & PS
|
// PS
|
||||||
public void teleport(CommandSender teleportee, PS to) throws TeleporterException;
|
public void teleport(Object teleporteeObject, PS to) throws TeleporterException;
|
||||||
public void teleport(CommandSender teleportee, PS to, String desc) throws TeleporterException;
|
public void teleport(Object teleporteeObject, PS to, String desc) throws TeleporterException;
|
||||||
public void teleport(CommandSender teleportee, PS to, String desc, Permissible delayPermissible) throws TeleporterException;
|
public void teleport(Object teleporteeObject, PS to, String desc, Permissible delayPermissible) throws TeleporterException;
|
||||||
public void teleport(CommandSender teleportee, PS to, String desc, int delaySeconds) throws TeleporterException;
|
public void teleport(Object teleporteeObject, PS to, String desc, int delaySeconds) throws TeleporterException;
|
||||||
|
|
||||||
// CommandSender & CommandSender
|
// CommandSender
|
||||||
public void teleport(CommandSender teleportee, CommandSender to) throws TeleporterException;
|
public void teleport(Object teleporteeObject, CommandSender to) throws TeleporterException;
|
||||||
public void teleport(CommandSender teleportee, CommandSender to, String desc) throws TeleporterException;
|
public void teleport(Object teleporteeObject, CommandSender to, String desc) throws TeleporterException;
|
||||||
public void teleport(CommandSender teleportee, CommandSender to, String desc, Permissible delayPermissible) throws TeleporterException;
|
public void teleport(Object teleporteeObject, CommandSender to, String desc, Permissible delayPermissible) throws TeleporterException;
|
||||||
public void teleport(CommandSender teleportee, CommandSender to, String desc, int delaySeconds) throws TeleporterException;
|
public void teleport(Object teleporteeObject, CommandSender to, String desc, int delaySeconds) throws TeleporterException;
|
||||||
|
|
||||||
// CommandSender & SenderEntity
|
// SenderEntity
|
||||||
public void teleport(CommandSender teleportee, SenderEntity<?> to) throws TeleporterException;
|
public void teleport(Object teleporteeObject, SenderEntity<?> to) throws TeleporterException;
|
||||||
public void teleport(CommandSender teleportee, SenderEntity<?> to, String desc) throws TeleporterException;
|
public void teleport(Object teleporteeObject, SenderEntity<?> to, String desc) throws TeleporterException;
|
||||||
public void teleport(CommandSender teleportee, SenderEntity<?> to, String desc, Permissible delayPermissible) throws TeleporterException;
|
public void teleport(Object teleporteeObject, SenderEntity<?> to, String desc, Permissible delayPermissible) throws TeleporterException;
|
||||||
public void teleport(CommandSender teleportee, SenderEntity<?> to, String desc, int delaySeconds) throws TeleporterException;
|
public void teleport(Object teleporteeObject, SenderEntity<?> to, String desc, int delaySeconds) throws TeleporterException;
|
||||||
|
|
||||||
// CommandSender & String
|
// String
|
||||||
public void teleport(CommandSender teleportee, String to) throws TeleporterException;
|
public void teleport(Object teleporteeObject, String to) throws TeleporterException;
|
||||||
public void teleport(CommandSender teleportee, String to, String desc) throws TeleporterException;
|
public void teleport(Object teleporteeObject, String to, String desc) throws TeleporterException;
|
||||||
public void teleport(CommandSender teleportee, String to, String desc, Permissible delayPermissible) throws TeleporterException;
|
public void teleport(Object teleporteeObject, String to, String desc, Permissible delayPermissible) throws TeleporterException;
|
||||||
public void teleport(CommandSender teleportee, String to, String desc, int delaySeconds) throws TeleporterException;
|
public void teleport(Object teleporteeObject, String to, String desc, int delaySeconds) throws TeleporterException;
|
||||||
|
|
||||||
// CommandSender & PSGetter
|
// PSGetter
|
||||||
public void teleport(CommandSender teleportee, PSGetter to) throws TeleporterException;
|
public void teleport(Object teleporteeObject, PSGetter to) throws TeleporterException;
|
||||||
public void teleport(CommandSender teleportee, PSGetter to, String desc) throws TeleporterException;
|
public void teleport(Object teleporteeObject, PSGetter to, String desc) throws TeleporterException;
|
||||||
public void teleport(CommandSender teleportee, PSGetter to, String desc, Permissible delayPermissible) throws TeleporterException;
|
public void teleport(Object teleporteeObject, PSGetter to, String desc, Permissible delayPermissible) throws TeleporterException;
|
||||||
public void teleport(CommandSender teleportee, PSGetter to, String desc, int delaySeconds) throws TeleporterException;
|
public void teleport(Object teleporteeObject, PSGetter to, String desc, int delaySeconds) throws TeleporterException;
|
||||||
|
|
||||||
//// SenderEntity
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// SENDER ENTITY
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
// SenderEntity & PS
|
|
||||||
public void teleport(SenderEntity<?> teleportee, PS to) throws TeleporterException;
|
|
||||||
public void teleport(SenderEntity<?> teleportee, PS to, String desc) throws TeleporterException;
|
|
||||||
public void teleport(SenderEntity<?> teleportee, PS to, String desc, Permissible delayPermissible) throws TeleporterException;
|
|
||||||
public void teleport(SenderEntity<?> teleportee, PS to, String desc, int delaySeconds) throws TeleporterException;
|
|
||||||
|
|
||||||
// SenderEntity & CommandSender
|
|
||||||
public void teleport(SenderEntity<?> teleportee, CommandSender to) throws TeleporterException;
|
|
||||||
public void teleport(SenderEntity<?> teleportee, CommandSender to, String desc) throws TeleporterException;
|
|
||||||
public void teleport(SenderEntity<?> teleportee, CommandSender to, String desc, Permissible delayPermissible) throws TeleporterException;
|
|
||||||
public void teleport(SenderEntity<?> teleportee, CommandSender to, String desc, int delaySeconds) throws TeleporterException;
|
|
||||||
|
|
||||||
// SenderEntity & SenderEntity
|
|
||||||
public void teleport(SenderEntity<?> teleportee, SenderEntity<?> to) throws TeleporterException;
|
|
||||||
public void teleport(SenderEntity<?> teleportee, SenderEntity<?> to, String desc) throws TeleporterException;
|
|
||||||
public void teleport(SenderEntity<?> teleportee, SenderEntity<?> to, String desc, Permissible delayPermissible) throws TeleporterException;
|
|
||||||
public void teleport(SenderEntity<?> teleportee, SenderEntity<?> to, String desc, int delaySeconds) throws TeleporterException;
|
|
||||||
|
|
||||||
// SenderEntity & String
|
|
||||||
public void teleport(SenderEntity<?> teleportee, String to) throws TeleporterException;
|
|
||||||
public void teleport(SenderEntity<?> teleportee, String to, String desc) throws TeleporterException;
|
|
||||||
public void teleport(SenderEntity<?> teleportee, String to, String desc, Permissible delayPermissible) throws TeleporterException;
|
|
||||||
public void teleport(SenderEntity<?> teleportee, String to, String desc, int delaySeconds) throws TeleporterException;
|
|
||||||
|
|
||||||
// SenderEntity & PSGetter
|
|
||||||
public void teleport(SenderEntity<?> teleportee, PSGetter to) throws TeleporterException;
|
|
||||||
public void teleport(SenderEntity<?> teleportee, PSGetter to, String desc) throws TeleporterException;
|
|
||||||
public void teleport(SenderEntity<?> teleportee, PSGetter to, String desc, Permissible delayPermissible) throws TeleporterException;
|
|
||||||
public void teleport(SenderEntity<?> teleportee, PSGetter to, String desc, int delaySeconds) throws TeleporterException;
|
|
||||||
|
|
||||||
//// String
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// STRING
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
// String & PS
|
|
||||||
public void teleport(String teleportee, PS to) throws TeleporterException;
|
|
||||||
public void teleport(String teleportee, PS to, String desc) throws TeleporterException;
|
|
||||||
public void teleport(String teleportee, PS to, String desc, Permissible delayPermissible) throws TeleporterException;
|
|
||||||
public void teleport(String teleportee, PS to, String desc, int delaySeconds) throws TeleporterException;
|
|
||||||
|
|
||||||
// String & CommandSender
|
|
||||||
public void teleport(String teleportee, CommandSender to) throws TeleporterException;
|
|
||||||
public void teleport(String teleportee, CommandSender to, String desc) throws TeleporterException;
|
|
||||||
public void teleport(String teleportee, CommandSender to, String desc, Permissible delayPermissible) throws TeleporterException;
|
|
||||||
public void teleport(String teleportee, CommandSender to, String desc, int delaySeconds) throws TeleporterException;
|
|
||||||
|
|
||||||
// String & SenderEntity
|
|
||||||
public void teleport(String teleportee, SenderEntity<?> to) throws TeleporterException;
|
|
||||||
public void teleport(String teleportee, SenderEntity<?> to, String desc) throws TeleporterException;
|
|
||||||
public void teleport(String teleportee, SenderEntity<?> to, String desc, Permissible delayPermissible) throws TeleporterException;
|
|
||||||
public void teleport(String teleportee, SenderEntity<?> to, String desc, int delaySeconds) throws TeleporterException;
|
|
||||||
|
|
||||||
// String & String
|
|
||||||
public void teleport(String teleportee, String to) throws TeleporterException;
|
|
||||||
public void teleport(String teleportee, String to, String desc) throws TeleporterException;
|
|
||||||
public void teleport(String teleportee, String to, String desc, Permissible delayPermissible) throws TeleporterException;
|
|
||||||
public void teleport(String teleportee, String to, String desc, int delaySeconds) throws TeleporterException;
|
|
||||||
|
|
||||||
// String & PSGetter
|
|
||||||
public void teleport(String teleportee, PSGetter to) throws TeleporterException;
|
|
||||||
public void teleport(String teleportee, PSGetter to, String desc) throws TeleporterException;
|
|
||||||
public void teleport(String teleportee, PSGetter to, String desc, Permissible delayPermissible) throws TeleporterException;
|
|
||||||
public void teleport(String teleportee, PSGetter to, String desc, int delaySeconds) throws TeleporterException;
|
|
||||||
// This very last method is is the core logic.
|
|
||||||
// Everything else is implemented in the abstract.
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import com.massivecraft.mcore.store.SenderEntity;
|
|||||||
import com.massivecraft.mcore.teleport.PSGetter;
|
import com.massivecraft.mcore.teleport.PSGetter;
|
||||||
import com.massivecraft.mcore.teleport.PSGetterPS;
|
import com.massivecraft.mcore.teleport.PSGetterPS;
|
||||||
import com.massivecraft.mcore.teleport.PSGetterPlayer;
|
import com.massivecraft.mcore.teleport.PSGetterPlayer;
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
|
||||||
|
|
||||||
public abstract class TeleportMixinAbstract implements TeleportMixin
|
public abstract class TeleportMixinAbstract implements TeleportMixin
|
||||||
{
|
{
|
||||||
@ -34,384 +33,132 @@ public abstract class TeleportMixinAbstract implements TeleportMixin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// COMMAND SENDER
|
// SENDER OBJECT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
// CommandSender & PS
|
// PS
|
||||||
@Override
|
@Override
|
||||||
public void teleport(CommandSender teleportee, PS to) throws TeleporterException
|
public void teleport(Object teleportee, PS to) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, to, null);
|
this.teleport(teleportee, to, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(CommandSender teleportee, PS to, String desc) throws TeleporterException
|
public void teleport(Object teleportee, PS to, String desc) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, to, desc, 0);
|
this.teleport(teleportee, to, desc, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(CommandSender teleportee, PS to, String desc, Permissible delayPermissible) throws TeleporterException
|
public void teleport(Object teleportee, PS to, String desc, Permissible delayPermissible) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(CommandSender teleportee, PS to, String desc, int delaySeconds) throws TeleporterException
|
public void teleport(Object teleportee, PS to, String desc, int delaySeconds) throws TeleporterException
|
||||||
{
|
|
||||||
this.teleport(SenderUtil.getSenderId(teleportee), to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// CommandSender & CommandSender
|
|
||||||
@Override
|
|
||||||
public void teleport(CommandSender teleportee, CommandSender to) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(CommandSender teleportee, CommandSender to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(CommandSender teleportee, CommandSender to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(CommandSender teleportee, CommandSender to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(SenderUtil.getSenderId(teleportee), to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// CommandSender & SenderEntity
|
|
||||||
@Override
|
|
||||||
public void teleport(CommandSender teleportee, SenderEntity<?> to) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(CommandSender teleportee, SenderEntity<?> to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(CommandSender teleportee, SenderEntity<?> to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(CommandSender teleportee, SenderEntity<?> to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(SenderUtil.getSenderId(teleportee), to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// CommandSender & String
|
|
||||||
@Override
|
|
||||||
public void teleport(CommandSender teleportee, String to) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(CommandSender teleportee, String to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(CommandSender teleportee, String to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(CommandSender teleportee, String to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(SenderUtil.getSenderId(teleportee), to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// CommandSender & PSGetter
|
|
||||||
@Override
|
|
||||||
public void teleport(CommandSender teleportee, PSGetter to) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(CommandSender teleportee, PSGetter to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(CommandSender teleportee, PSGetter to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(CommandSender teleportee, PSGetter to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(SenderUtil.getSenderId(teleportee), to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// SENDER ENTITY
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
// SenderEntity & PS
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, PS to) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, PS to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, PS to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, PS to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee.getId(), to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// SenderEntity & CommandSender
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, CommandSender to) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, CommandSender to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, CommandSender to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, CommandSender to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee.getId(), to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// SenderEntity & SenderEntity
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, SenderEntity<?> to) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, SenderEntity<?> to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, SenderEntity<?> to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, SenderEntity<?> to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee.getId(), to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// SenderEntity & String
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, String to) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, String to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, String to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, String to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee.getId(), to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// SenderEntity & PSGetter
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, PSGetter to) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, PSGetter to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, PSGetter to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(SenderEntity<?> teleportee, PSGetter to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee.getId(), to, desc, delaySeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// STRING
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
// String & PS
|
|
||||||
@Override
|
|
||||||
public void teleport(String teleportee, PS to) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(String teleportee, PS to, String desc) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(String teleportee, PS to, String desc, Permissible delayPermissible) throws TeleporterException
|
|
||||||
{
|
|
||||||
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void teleport(String teleportee, PS to, String desc, int delaySeconds) throws TeleporterException
|
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, PSGetterPS.valueOf(to), desc, delaySeconds);
|
this.teleport(teleportee, PSGetterPS.valueOf(to), desc, delaySeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// String & CommandSender
|
// CommandSender
|
||||||
@Override
|
@Override
|
||||||
public void teleport(String teleportee, CommandSender to) throws TeleporterException
|
public void teleport(Object teleportee, CommandSender to) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, to, null);
|
this.teleport(teleportee, to, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(String teleportee, CommandSender to, String desc) throws TeleporterException
|
public void teleport(Object teleportee, CommandSender to, String desc) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, to, desc, 0);
|
this.teleport(teleportee, to, desc, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(String teleportee, CommandSender to, String desc, Permissible delayPermissible) throws TeleporterException
|
public void teleport(Object teleportee, CommandSender to, String desc, Permissible delayPermissible) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(String teleportee, CommandSender to, String desc, int delaySeconds) throws TeleporterException
|
public void teleport(Object teleportee, CommandSender to, String desc, int delaySeconds) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, PSGetterPlayer.valueOf(to), desc, delaySeconds);
|
this.teleport(teleportee, PSGetterPlayer.valueOf(to), desc, delaySeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// String & SenderEntity
|
// SenderEntity
|
||||||
@Override
|
@Override
|
||||||
public void teleport(String teleportee, SenderEntity<?> to) throws TeleporterException
|
public void teleport(Object teleportee, SenderEntity<?> to) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, to, null);
|
this.teleport(teleportee, to, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(String teleportee, SenderEntity<?> to, String desc) throws TeleporterException
|
public void teleport(Object teleportee, SenderEntity<?> to, String desc) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, to, desc, 0);
|
this.teleport(teleportee, to, desc, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(String teleportee, SenderEntity<?> to, String desc, Permissible delayPermissible) throws TeleporterException
|
public void teleport(Object teleportee, SenderEntity<?> to, String desc, Permissible delayPermissible) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(String teleportee, SenderEntity<?> to, String desc, int delaySeconds) throws TeleporterException
|
public void teleport(Object teleportee, SenderEntity<?> to, String desc, int delaySeconds) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, PSGetterPlayer.valueOf(to), desc, delaySeconds);
|
this.teleport(teleportee, PSGetterPlayer.valueOf(to), desc, delaySeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// String & String
|
// String
|
||||||
@Override
|
@Override
|
||||||
public void teleport(String teleportee, String to) throws TeleporterException
|
public void teleport(Object teleportee, String to) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, to, null);
|
this.teleport(teleportee, to, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(String teleportee, String to, String desc) throws TeleporterException
|
public void teleport(Object teleportee, String to, String desc) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, to, desc, 0);
|
this.teleport(teleportee, to, desc, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(String teleportee, String to, String desc, Permissible delayPermissible) throws TeleporterException
|
public void teleport(Object teleportee, String to, String desc, Permissible delayPermissible) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(String teleportee, String to, String desc, int delaySeconds) throws TeleporterException
|
public void teleport(Object teleportee, String to, String desc, int delaySeconds) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, PSGetterPlayer.valueOf(to), desc, delaySeconds);
|
this.teleport(teleportee, PSGetterPlayer.valueOf(to), desc, delaySeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// String & PSGetter
|
// PSGetter
|
||||||
@Override
|
@Override
|
||||||
public void teleport(String teleportee, PSGetter to) throws TeleporterException
|
public void teleport(Object teleportee, PSGetter to) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, to, null);
|
this.teleport(teleportee, to, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(String teleportee, PSGetter to, String desc) throws TeleporterException
|
public void teleport(Object teleportee, PSGetter to, String desc) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, to, desc, 0);
|
this.teleport(teleportee, to, desc, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(String teleportee, PSGetter to, String desc, Permissible delayPermissible) throws TeleporterException
|
public void teleport(Object teleportee, PSGetter to, String desc, Permissible delayPermissible) throws TeleporterException
|
||||||
{
|
{
|
||||||
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To implement!
|
||||||
|
/*@Override
|
||||||
|
public void teleport(Object teleportee, PSGetter to, String desc, int delaySeconds) throws TeleporterException
|
||||||
|
{
|
||||||
|
//this.teleport(teleportee, to, desc, delaySeconds);
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import com.massivecraft.mcore.event.MCorePlayerPSTeleportEvent;
|
|||||||
import com.massivecraft.mcore.ps.PS;
|
import com.massivecraft.mcore.ps.PS;
|
||||||
import com.massivecraft.mcore.teleport.PSGetter;
|
import com.massivecraft.mcore.teleport.PSGetter;
|
||||||
import com.massivecraft.mcore.teleport.ScheduledTeleport;
|
import com.massivecraft.mcore.teleport.ScheduledTeleport;
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
import com.massivecraft.mcore.util.Txt;
|
import com.massivecraft.mcore.util.Txt;
|
||||||
|
|
||||||
public class TeleportMixinDefault extends TeleportMixinAbstract
|
public class TeleportMixinDefault extends TeleportMixinAbstract
|
||||||
@ -71,20 +71,21 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(String teleporteeId, PSGetter toGetter, String desc, int delaySeconds) throws TeleporterException
|
public void teleport(Object teleporteeObject, PSGetter toGetter, String desc, int delaySeconds) throws TeleporterException
|
||||||
{
|
{
|
||||||
if (!SenderUtil.isPlayerId(teleporteeId)) throw new TeleporterException(Txt.parse("<white>%s <b>is not a player.", Mixin.getDisplayName(teleporteeId)));
|
String teleporteeId = IdUtil.getId(teleporteeObject);
|
||||||
|
if (!IdUtil.isPlayerId(teleporteeId)) throw new TeleporterException(Txt.parse("<white>%s <b>is not a player.", Mixin.getDisplayName(teleporteeId)));
|
||||||
|
|
||||||
if (delaySeconds > 0)
|
if (delaySeconds > 0)
|
||||||
{
|
{
|
||||||
// With delay
|
// With delay
|
||||||
if (desc != null)
|
if (desc != null)
|
||||||
{
|
{
|
||||||
Mixin.msg(teleporteeId, "<i>Teleporting to <h>"+desc+" <i>in <h>"+delaySeconds+"s <i>unless you move.");
|
Mixin.msgOne(teleporteeId, "<i>Teleporting to <h>"+desc+" <i>in <h>"+delaySeconds+"s <i>unless you move.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Mixin.msg(teleporteeId, "<i>Teleporting in <h>"+delaySeconds+"s <i>unless you move.");
|
Mixin.msgOne(teleporteeId, "<i>Teleporting in <h>"+delaySeconds+"s <i>unless you move.");
|
||||||
}
|
}
|
||||||
|
|
||||||
new ScheduledTeleport(teleporteeId, toGetter, desc, delaySeconds).schedule();
|
new ScheduledTeleport(teleporteeId, toGetter, desc, delaySeconds).schedule();
|
||||||
@ -106,10 +107,10 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
|
|||||||
|
|
||||||
if (desc != null)
|
if (desc != null)
|
||||||
{
|
{
|
||||||
Mixin.msg(teleporteeId, "<i>Teleporting to <h>"+desc+"<i>.");
|
Mixin.msgOne(teleporteeId, "<i>Teleporting to <h>"+desc+"<i>.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Player teleportee = SenderUtil.getPlayer(teleporteeId);
|
Player teleportee = IdUtil.getPlayer(teleporteeId);
|
||||||
if (teleportee != null)
|
if (teleportee != null)
|
||||||
{
|
{
|
||||||
teleportPlayer(teleportee, to);
|
teleportPlayer(teleportee, to);
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
package com.massivecraft.mcore.mixin;
|
package com.massivecraft.mcore.mixin;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
public interface VisibilityMixin
|
public interface VisibilityMixin
|
||||||
{
|
{
|
||||||
public boolean canSee(String watcherId, String watcheeId);
|
public boolean canSee(Object watcherObject, Object watcheeObject);
|
||||||
public boolean canSee(CommandSender watcher, String watcheeId);
|
|
||||||
public boolean canSee(String watcherId, CommandSender watchee);
|
|
||||||
public boolean canSee(CommandSender watcher, CommandSender watchee);
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
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 com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public class VisibilityMixinDefault extends VisibilityMixinAbstract
|
public class VisibilityMixinDefault extends VisibilityMixinAbstract
|
||||||
{
|
{
|
||||||
@ -19,28 +18,10 @@ public class VisibilityMixinDefault extends VisibilityMixinAbstract
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canSee(String watcherId, String watcheeId)
|
public boolean canSee(Object watcherObject, Object watcheeObject)
|
||||||
{
|
{
|
||||||
return this.canSee(SenderUtil.getSender(watcherId), SenderUtil.getSender(watcheeId));
|
Player pwatcher = IdUtil.getPlayer(watcherObject);
|
||||||
}
|
Player pwatchee = IdUtil.getPlayer(watcheeObject);
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canSee(CommandSender watcher, String watcheeId)
|
|
||||||
{
|
|
||||||
return this.canSee(watcher, SenderUtil.getSender(watcheeId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canSee(String watcherId, CommandSender watchee)
|
|
||||||
{
|
|
||||||
return this.canSee(SenderUtil.getSender(watcherId), watchee);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canSee(CommandSender watcher, CommandSender watchee)
|
|
||||||
{
|
|
||||||
Player pwatcher = SenderUtil.getAsPlayer(watcher);
|
|
||||||
Player pwatchee = SenderUtil.getAsPlayer(watchee);
|
|
||||||
|
|
||||||
if (pwatcher == null) return true;
|
if (pwatcher == null) return true;
|
||||||
if (pwatchee == null) return true;
|
if (pwatchee == null) return true;
|
||||||
|
@ -93,7 +93,7 @@ public class WorldMixinDefault extends WorldMixinAbstract
|
|||||||
{
|
{
|
||||||
if (verbooseChange || verbooseSame)
|
if (verbooseChange || verbooseSame)
|
||||||
{
|
{
|
||||||
Mixin.msg(sender, "<b>Unknown world <h>%s<b>.", worldId);
|
Mixin.msgOne(sender, "<b>Unknown world <h>%s<b>.", worldId);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ public class WorldMixinDefault extends WorldMixinAbstract
|
|||||||
{
|
{
|
||||||
if (verbooseSame)
|
if (verbooseSame)
|
||||||
{
|
{
|
||||||
Mixin.msg(sender, "<i>Spawn location is already <h>%s <i>for <h>%s<i>.", currentFormatted, worldDisplayName);
|
Mixin.msgOne(sender, "<i>Spawn location is already <h>%s <i>for <h>%s<i>.", currentFormatted, worldDisplayName);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ public class WorldMixinDefault extends WorldMixinAbstract
|
|||||||
// Report
|
// Report
|
||||||
if (verbooseChange)
|
if (verbooseChange)
|
||||||
{
|
{
|
||||||
Mixin.msg(sender, "<i>Changing spawn location from <h>%s <i>to <h>%s <i>for <h>%s<i>.", currentFormatted, goalFormatted, worldDisplayName);
|
Mixin.msgOne(sender, "<i>Changing spawn location from <h>%s <i>to <h>%s <i>for <h>%s<i>.", currentFormatted, goalFormatted, worldDisplayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set it
|
// Set it
|
||||||
|
@ -6,11 +6,11 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.permissions.PermissibleBase;
|
import org.bukkit.permissions.PermissibleBase;
|
||||||
|
|
||||||
import com.massivecraft.mcore.MCore;
|
import com.massivecraft.mcore.MCore;
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public class BasicCommandSender extends PermissibleBase implements CommandSender
|
public class BasicCommandSender extends PermissibleBase implements CommandSender
|
||||||
{
|
{
|
||||||
private final String name;
|
public final String name;
|
||||||
|
|
||||||
public BasicCommandSender(String name, boolean op, boolean opChangeable)
|
public BasicCommandSender(String name, boolean op, boolean opChangeable)
|
||||||
{
|
{
|
||||||
@ -55,7 +55,7 @@ public class BasicCommandSender extends PermissibleBase implements CommandSender
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean register()
|
public void register()
|
||||||
{
|
{
|
||||||
final BasicCommandSender ME = this;
|
final BasicCommandSender ME = this;
|
||||||
|
|
||||||
@ -70,17 +70,17 @@ public class BasicCommandSender extends PermissibleBase implements CommandSender
|
|||||||
});
|
});
|
||||||
|
|
||||||
// and register now
|
// and register now
|
||||||
return this.registerImmediately();
|
registerImmediately();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean registerImmediately()
|
public void registerImmediately()
|
||||||
{
|
{
|
||||||
return SenderUtil.register(this);
|
IdUtil.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean unregister()
|
public void unregister()
|
||||||
{
|
{
|
||||||
return SenderUtil.unregister(this);
|
IdUtil.unregister(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -327,7 +327,7 @@ public class Coll<E> implements CollInterface<E>
|
|||||||
if (entity instanceof Entity)
|
if (entity instanceof Entity)
|
||||||
{
|
{
|
||||||
((Entity)entity).setColl(this);
|
((Entity)entity).setColl(this);
|
||||||
((Entity)entity).setid(id);
|
((Entity)entity).setId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach
|
// Attach
|
||||||
@ -497,7 +497,7 @@ public class Coll<E> implements CollInterface<E>
|
|||||||
if (entity instanceof Entity)
|
if (entity instanceof Entity)
|
||||||
{
|
{
|
||||||
((Entity)entity).setColl(null);
|
((Entity)entity).setColl(null);
|
||||||
((Entity)entity).setid(null);
|
((Entity)entity).setId(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
@ -742,6 +742,14 @@ public class Coll<E> implements CollInterface<E>
|
|||||||
@Override
|
@Override
|
||||||
public void syncSuspects()
|
public void syncSuspects()
|
||||||
{
|
{
|
||||||
|
/*if (MCore.get().doderp)
|
||||||
|
{
|
||||||
|
if (this.changedIds.size() > 0)
|
||||||
|
{
|
||||||
|
System.out.println("Coll " + this.getName() + " had suspects " + Txt.implode(this.changedIds, " "));
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
for (String id : this.changedIds)
|
for (String id : this.changedIds)
|
||||||
{
|
{
|
||||||
this.syncId(id);
|
this.syncId(id);
|
||||||
|
@ -25,7 +25,7 @@ public abstract class Entity<E extends Entity<E>> implements Comparable<E>
|
|||||||
public Coll<E> getColl() { return this.coll; }
|
public Coll<E> getColl() { return this.coll; }
|
||||||
|
|
||||||
protected transient String id;
|
protected transient String id;
|
||||||
protected void setid(String id) { this.id = id; }
|
protected void setId(String id) { this.id = id; }
|
||||||
public String getId() { return this.id; }
|
public String getId() { return this.id; }
|
||||||
|
|
||||||
public String getUniverse()
|
public String getUniverse()
|
||||||
|
@ -9,8 +9,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.massivecraft.mcore.Predictate;
|
import com.massivecraft.mcore.Predictate;
|
||||||
import com.massivecraft.mcore.mixin.Mixin;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
import com.massivecraft.mcore.util.MUtil;
|
|
||||||
|
|
||||||
public class SenderColl<E extends SenderEntity<E>> extends Coll<E> implements SenderIdSource
|
public class SenderColl<E extends SenderEntity<E>> extends Coll<E> implements SenderIdSource
|
||||||
{
|
{
|
||||||
@ -41,52 +40,54 @@ public class SenderColl<E extends SenderEntity<E>> extends Coll<E> implements Se
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// EXTRAS
|
// OVERRIDE: Coll
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public List<String> getFixedIds()
|
|
||||||
{
|
|
||||||
List<String> ret = new ArrayList<String>();
|
|
||||||
for (String senderId : this.getIds())
|
|
||||||
{
|
|
||||||
ret.add(Mixin.tryFix(senderId));
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<Collection<String>> getSenderIdCollections()
|
|
||||||
{
|
|
||||||
List<Collection<String>> ret = new ArrayList<Collection<String>>();
|
|
||||||
ret.add(this.getFixedIds());
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String fixId(Object oid)
|
public String fixId(Object oid)
|
||||||
{
|
{
|
||||||
if (oid == null) return null;
|
if (oid == null) return null;
|
||||||
|
|
||||||
String ret = null;
|
|
||||||
if (oid instanceof String)
|
if (oid instanceof String)
|
||||||
{
|
{
|
||||||
ret = (String)oid;
|
String ret = (String)oid;
|
||||||
}
|
return this.isLowercasing() ? ret.toLowerCase() : ret;
|
||||||
else if (oid.getClass() == this.entityClass)
|
|
||||||
{
|
|
||||||
ret = this.entity2id.get(oid);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret = MUtil.extract(String.class, "senderId", oid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == null) return null;
|
if (oid.getClass() == this.entityClass)
|
||||||
|
{
|
||||||
|
return fixId(this.entity2id.get(oid));
|
||||||
|
}
|
||||||
|
|
||||||
return this.isLowercasing() ? ret.toLowerCase() : ret;
|
return fixId(IdUtil.getId(oid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// OVERRIDE: SenderIdSource
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Collection<String>> getSenderIdCollections()
|
||||||
|
{
|
||||||
|
List<Collection<String>> ret = new ArrayList<Collection<String>>();
|
||||||
|
ret.add(this.getIds());
|
||||||
|
|
||||||
|
List<String> names = new ArrayList<String>();
|
||||||
|
for (String id : this.getIds())
|
||||||
|
{
|
||||||
|
String name = IdUtil.getName(id);
|
||||||
|
if (name == null) continue;
|
||||||
|
names.add(name);
|
||||||
|
}
|
||||||
|
ret.add(names);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// EXTRAS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public Collection<E> getAllOnline()
|
public Collection<E> getAllOnline()
|
||||||
{
|
{
|
||||||
return this.getAll(new Predictate<E>()
|
return this.getAll(new Predictate<E>()
|
||||||
@ -110,10 +111,10 @@ public class SenderColl<E extends SenderEntity<E>> extends Coll<E> implements Se
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// SENDER REFFERENCE MANAGEMENT
|
// SENDER REFERENCE MANAGEMENT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
protected void setSenderRefference(String senderId, CommandSender sender)
|
protected void setSenderReference(String senderId, CommandSender sender)
|
||||||
{
|
{
|
||||||
E senderEntity = this.get(senderId, false);
|
E senderEntity = this.get(senderId, false);
|
||||||
if (senderEntity == null) return;
|
if (senderEntity == null) return;
|
||||||
@ -121,19 +122,20 @@ public class SenderColl<E extends SenderEntity<E>> extends Coll<E> implements Se
|
|||||||
senderEntity.senderInitiated = true;
|
senderEntity.senderInitiated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setSenderRefferences(String senderId, CommandSender sender)
|
public static void setSenderReferences(String senderId, CommandSender sender)
|
||||||
{
|
{
|
||||||
for (Coll<?> coll : Coll.getInstances())
|
for (Coll<?> coll : Coll.getInstances())
|
||||||
{
|
{
|
||||||
if (!(coll instanceof SenderColl)) continue;
|
if (!(coll instanceof SenderColl)) continue;
|
||||||
SenderColl<?> senderColl = (SenderColl<?>)coll;
|
SenderColl<?> senderColl = (SenderColl<?>)coll;
|
||||||
senderColl.setSenderRefference(senderId, sender);
|
senderColl.setSenderReference(senderId, sender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// ARGUMENT READERS
|
// ARGUMENT READERS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
// TODO: Why were these removed?
|
||||||
|
|
||||||
/*public ArgReader<E> getARFullAny()
|
/*public ArgReader<E> getARFullAny()
|
||||||
{
|
{
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
package com.massivecraft.mcore.store;
|
package com.massivecraft.mcore.store;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.command.BlockCommandSender;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.command.RemoteConsoleCommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.massivecraft.mcore.mixin.Mixin;
|
import com.massivecraft.mcore.mixin.Mixin;
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E>
|
public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E>
|
||||||
{
|
{
|
||||||
@ -18,6 +17,8 @@ public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E>
|
|||||||
// FIELDS
|
// FIELDS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
// TODO: With the new IdUtil containing a built in index ;
|
||||||
|
// TODO: ; Do we even need this local-cache?
|
||||||
// We keep a reference to the sender to provide fast "reverse lookup".
|
// We keep a reference to the sender to provide fast "reverse lookup".
|
||||||
// The sender reference is initiated here and is kept updated using the InternalListener
|
// The sender reference is initiated here and is kept updated using the InternalListener
|
||||||
protected transient CommandSender sender = null;
|
protected transient CommandSender sender = null;
|
||||||
@ -26,19 +27,20 @@ public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E>
|
|||||||
{
|
{
|
||||||
if ( ! this.senderInitiated)
|
if ( ! this.senderInitiated)
|
||||||
{
|
{
|
||||||
this.sender = SenderUtil.getSender(this.getId());
|
this.sender = IdUtil.getSender(this.getId());
|
||||||
this.senderInitiated = true;
|
this.senderInitiated = true;
|
||||||
}
|
}
|
||||||
return this.sender;
|
return this.sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
public String getName()
|
||||||
// FIXED ID
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public String getFixedId()
|
|
||||||
{
|
{
|
||||||
return Mixin.tryFix(this.getId());
|
return IdUtil.getName(this.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getUuid()
|
||||||
|
{
|
||||||
|
return IdUtil.getUuid(this.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -57,48 +59,26 @@ public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E>
|
|||||||
|
|
||||||
// IS
|
// IS
|
||||||
|
|
||||||
public boolean isSender()
|
|
||||||
{
|
|
||||||
return SenderUtil.isSenderId(this.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPlayer()
|
public boolean isPlayer()
|
||||||
{
|
{
|
||||||
return SenderUtil.isPlayerId(this.getId());
|
return IdUtil.isPlayerId(this.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isConsole()
|
public boolean isConsole()
|
||||||
{
|
{
|
||||||
return SenderUtil.isConsoleId(this.getId());
|
return IdUtil.isConsoleId(this.getId());
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRcon()
|
|
||||||
{
|
|
||||||
return SenderUtil.isRconId(this.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET
|
// GET
|
||||||
|
|
||||||
// TODO: Usage of sender instead of id here is cheating but is good performance-wise so it can be ok.
|
|
||||||
|
|
||||||
public Player getPlayer()
|
public Player getPlayer()
|
||||||
{
|
{
|
||||||
return SenderUtil.getAsPlayer(this.getSender());
|
return IdUtil.getAsPlayer(this.getSender());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConsoleCommandSender getConsole()
|
public ConsoleCommandSender getConsole()
|
||||||
{
|
{
|
||||||
return SenderUtil.getAsConsole(this.getSender());
|
return IdUtil.getAsConsole(this.getSender());
|
||||||
}
|
|
||||||
|
|
||||||
public RemoteConsoleCommandSender getRcon()
|
|
||||||
{
|
|
||||||
return SenderUtil.getAsRcon(this.getSender());
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlockCommandSender getBlock()
|
|
||||||
{
|
|
||||||
return SenderUtil.getAsBlock(this.getSender());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ONLINE / OFFLINE
|
// ONLINE / OFFLINE
|
||||||
@ -141,46 +121,46 @@ public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E>
|
|||||||
|
|
||||||
public boolean sendMessage(String message)
|
public boolean sendMessage(String message)
|
||||||
{
|
{
|
||||||
return Mixin.message(this.getId(), message);
|
return Mixin.messageOne(this.getId(), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean sendMessage(String... messages)
|
public boolean sendMessage(String... messages)
|
||||||
{
|
{
|
||||||
return Mixin.message(this.getId(), messages);
|
return Mixin.messageOne(this.getId(), messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean sendMessage(Collection<String> messages)
|
public boolean sendMessage(Collection<String> messages)
|
||||||
{
|
{
|
||||||
return Mixin.message(this.getId(), messages);
|
return Mixin.messageOne(this.getId(), messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CONVENIENCE MSG
|
// CONVENIENCE MSG
|
||||||
|
|
||||||
public boolean msg(String msg)
|
public boolean msg(String msg)
|
||||||
{
|
{
|
||||||
return Mixin.msg(this.getId(), msg);
|
return Mixin.msgOne(this.getId(), msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean msg(String msg, Object... args)
|
public boolean msg(String msg, Object... args)
|
||||||
{
|
{
|
||||||
return Mixin.msg(this.getId(), msg, args);
|
return Mixin.msgOne(this.getId(), msg, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean msg(Collection<String> msgs)
|
public boolean msg(Collection<String> msgs)
|
||||||
{
|
{
|
||||||
return Mixin.msg(this.getId(), msgs);
|
return Mixin.msgOne(this.getId(), msgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CONVENIENCE GAME-MODE
|
// CONVENIENCE GAME-MODE
|
||||||
|
|
||||||
public GameMode getGameMode(GameMode def)
|
public GameMode getGameMode(GameMode def)
|
||||||
{
|
{
|
||||||
return SenderUtil.getGameMode(this.getId(), def);
|
return IdUtil.getGameMode(this.getId(), def);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGameMode(GameMode gm, boolean def)
|
public boolean isGameMode(GameMode gm, boolean def)
|
||||||
{
|
{
|
||||||
return SenderUtil.isGameMode(this.getId(), gm, def);
|
return IdUtil.isGameMode(this.getId(), gm, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
package com.massivecraft.mcore.store;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.massivecraft.mcore.mixin.Mixin;
|
|
||||||
|
|
||||||
public class SenderIdSourceMixinAllPlayerIds implements SenderIdSource
|
|
||||||
{
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// INSTANCE & CONSTRUCT
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
private static SenderIdSourceMixinAllPlayerIds i = new SenderIdSourceMixinAllPlayerIds();
|
|
||||||
public static SenderIdSourceMixinAllPlayerIds get() { return i; }
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// OVERRIDE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<Collection<String>> getSenderIdCollections()
|
|
||||||
{
|
|
||||||
List<Collection<String>> ret = new ArrayList<Collection<String>>();
|
|
||||||
ret.add(Mixin.getAllPlayerIds());
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -4,7 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.massivecraft.mcore.mixin.Mixin;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public class SenderIdSourceMixinAllSenderIds implements SenderIdSource
|
public class SenderIdSourceMixinAllSenderIds implements SenderIdSource
|
||||||
{
|
{
|
||||||
@ -23,7 +23,8 @@ public class SenderIdSourceMixinAllSenderIds implements SenderIdSource
|
|||||||
public Collection<Collection<String>> getSenderIdCollections()
|
public Collection<Collection<String>> getSenderIdCollections()
|
||||||
{
|
{
|
||||||
List<Collection<String>> ret = new ArrayList<Collection<String>>();
|
List<Collection<String>> ret = new ArrayList<Collection<String>>();
|
||||||
ret.add(Mixin.getAllSenderIds());
|
ret.add(IdUtil.getAllNames());
|
||||||
|
ret.add(IdUtil.getAllIds());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
package com.massivecraft.mcore.store;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.massivecraft.mcore.mixin.Mixin;
|
|
||||||
|
|
||||||
public class SenderIdSourceMixinOnlinePlayerIds implements SenderIdSource
|
|
||||||
{
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// INSTANCE & CONSTRUCT
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
private static SenderIdSourceMixinOnlinePlayerIds i = new SenderIdSourceMixinOnlinePlayerIds();
|
|
||||||
public static SenderIdSourceMixinOnlinePlayerIds get() { return i; }
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// OVERRIDE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<Collection<String>> getSenderIdCollections()
|
|
||||||
{
|
|
||||||
List<Collection<String>> ret = new ArrayList<Collection<String>>();
|
|
||||||
ret.add(Mixin.getOnlinePlayerIds());
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package com.massivecraft.mcore.store;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.massivecraft.mcore.mixin.Mixin;
|
|
||||||
|
|
||||||
public class SenderIdSourceMixinOnlineSenderIds implements SenderIdSource
|
|
||||||
{
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// INSTANCE & CONSTRUCT
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
private static SenderIdSourceMixinOnlineSenderIds i = new SenderIdSourceMixinOnlineSenderIds();
|
|
||||||
public static SenderIdSourceMixinOnlineSenderIds get() { return i; }
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// OVERRIDE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<Collection<String>> getSenderIdCollections()
|
|
||||||
{
|
|
||||||
List<Collection<String>> ret = new ArrayList<Collection<String>>();
|
|
||||||
ret.add(Mixin.getOnlineSenderIds());
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -11,8 +11,8 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import com.massivecraft.mcore.EngineAbstract;
|
import com.massivecraft.mcore.EngineAbstract;
|
||||||
import com.massivecraft.mcore.MCore;
|
import com.massivecraft.mcore.MCore;
|
||||||
import com.massivecraft.mcore.mixin.Mixin;
|
import com.massivecraft.mcore.mixin.Mixin;
|
||||||
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
import com.massivecraft.mcore.util.MUtil;
|
import com.massivecraft.mcore.util.MUtil;
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
|
||||||
|
|
||||||
public class EngineScheduledTeleport extends EngineAbstract
|
public class EngineScheduledTeleport extends EngineAbstract
|
||||||
{
|
{
|
||||||
@ -95,14 +95,14 @@ public class EngineScheduledTeleport extends EngineAbstract
|
|||||||
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 = teleporteeIdToScheduledTeleport.get(SenderUtil.getSenderId(event.getPlayer()));
|
ScheduledTeleport scheduledTeleport = teleporteeIdToScheduledTeleport.get(IdUtil.getId(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.getTeleporteeId(), "<rose>Cancelled <i>teleport to <h>"+scheduledTeleport.getDestinationDesc()+"<i>.");
|
Mixin.msgOne(scheduledTeleport.getTeleporteeId(), "<rose>Cancelled <i>teleport to <h>"+scheduledTeleport.getDestinationDesc()+"<i>.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import com.massivecraft.mcore.mixin.Mixin;
|
import com.massivecraft.mcore.mixin.Mixin;
|
||||||
import com.massivecraft.mcore.ps.PS;
|
import com.massivecraft.mcore.ps.PS;
|
||||||
import com.massivecraft.mcore.store.SenderEntity;
|
import com.massivecraft.mcore.store.SenderEntity;
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
|
|
||||||
public final class PSGetterPlayer extends PSGetterAbstract
|
public final class PSGetterPlayer extends PSGetterAbstract
|
||||||
{
|
{
|
||||||
@ -33,7 +33,7 @@ public final class PSGetterPlayer extends PSGetterAbstract
|
|||||||
|
|
||||||
public static PSGetterPlayer valueOf(CommandSender player)
|
public static PSGetterPlayer valueOf(CommandSender player)
|
||||||
{
|
{
|
||||||
return new PSGetterPlayer(SenderUtil.getSenderId(player));
|
return new PSGetterPlayer(IdUtil.getId(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PSGetterPlayer valueOf(SenderEntity<?> playerEntity)
|
public static PSGetterPlayer valueOf(SenderEntity<?> playerEntity)
|
||||||
|
@ -73,7 +73,7 @@ public class ScheduledTeleport implements Runnable
|
|||||||
}
|
}
|
||||||
catch (TeleporterException e)
|
catch (TeleporterException e)
|
||||||
{
|
{
|
||||||
Mixin.message(this.getTeleporteeId(), e.getMessage());
|
Mixin.messageOne(this.getTeleporteeId(), e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
133
src/com/massivecraft/mcore/util/FlyUtil.java
Normal file
133
src/com/massivecraft/mcore/util/FlyUtil.java
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
78
src/com/massivecraft/mcore/util/IdData.java
Normal file
78
src/com/massivecraft/mcore/util/IdData.java
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
package com.massivecraft.mcore.util;
|
||||||
|
|
||||||
|
public class IdData
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// FIELDS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
public String getId() { return this.id; }
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
public String getName() { return this.name; }
|
||||||
|
|
||||||
|
private long millis;
|
||||||
|
public long getMillis() { return this.millis; }
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
// It's always good to have a no-arg constructor
|
||||||
|
public IdData()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public IdData(String id, String name)
|
||||||
|
{
|
||||||
|
this(id, name, System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
public IdData(String id, String name, long millis)
|
||||||
|
{
|
||||||
|
if (id == null && name == null) throw new NullPointerException("Either id or name must be set. They can't both be null!");
|
||||||
|
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.millis = millis;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// HASH CODE & EQUALS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||||
|
result = prime * result + (int) (millis ^ (millis >>> 32));
|
||||||
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj)
|
||||||
|
{
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (obj == null) return false;
|
||||||
|
if (!(obj instanceof IdData)) return false;
|
||||||
|
IdData other = (IdData) obj;
|
||||||
|
if (id == null)
|
||||||
|
{
|
||||||
|
if (other.id != null) return false;
|
||||||
|
}
|
||||||
|
else if (!id.equals(other.id)) return false;
|
||||||
|
if (millis != other.millis) return false;
|
||||||
|
if (name == null)
|
||||||
|
{
|
||||||
|
if (other.name != null) return false;
|
||||||
|
}
|
||||||
|
else if (!name.equals(other.name)) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
106
src/com/massivecraft/mcore/util/IdUpdateUtil.java
Normal file
106
src/com/massivecraft/mcore/util/IdUpdateUtil.java
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
package com.massivecraft.mcore.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.massivecraft.mcore.MCore;
|
||||||
|
import com.massivecraft.mcore.store.Coll;
|
||||||
|
import com.massivecraft.mcore.store.Entity;
|
||||||
|
|
||||||
|
public class IdUpdateUtil
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// SINGLE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static String update(String string, boolean force)
|
||||||
|
{
|
||||||
|
if (string == null) return null;
|
||||||
|
|
||||||
|
String ret = IdUtil.getId(string);
|
||||||
|
if (ret != null) return ret;
|
||||||
|
|
||||||
|
if (!force) return string;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// COLL
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static void update(Collection<String> from, Collection<String> to, boolean force)
|
||||||
|
{
|
||||||
|
for (String string : from)
|
||||||
|
{
|
||||||
|
string = update(string, force);
|
||||||
|
if (string == null) continue;
|
||||||
|
to.add(string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> update(List<String> strings, boolean force)
|
||||||
|
{
|
||||||
|
List<String> ret = new ArrayList<String>();
|
||||||
|
update(strings, ret, force);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<String> update(Set<String> strings, boolean force)
|
||||||
|
{
|
||||||
|
Set<String> ret = new LinkedHashSet<String>();
|
||||||
|
update(strings, ret, force);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// COLL
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static <E extends Entity<E>> void update(Coll<E> coll)
|
||||||
|
{
|
||||||
|
update(coll, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <E extends Entity<E>> void update(Coll<E> coll, boolean force)
|
||||||
|
{
|
||||||
|
long pre = System.currentTimeMillis();
|
||||||
|
MCore.get().log(Txt.parse("<i>Pre update <h>%s<i>.", coll.getName()));
|
||||||
|
|
||||||
|
int countTotal = coll.getAll().size();
|
||||||
|
int countUpdate = 0;
|
||||||
|
for (E entity : coll.getAll())
|
||||||
|
{
|
||||||
|
if (update(coll, entity, force)) countUpdate++;
|
||||||
|
}
|
||||||
|
|
||||||
|
long post = System.currentTimeMillis();
|
||||||
|
long delta = post - pre;
|
||||||
|
MCore.get().log(Txt.parse("<i>Post update <h>%s<i>. Took <h>%dms<i>. <h>%d/%d <i>changed.", coll.getName(), delta, countUpdate, countTotal));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <E extends Entity<E>> boolean update(Coll<E> coll, E entity, boolean force)
|
||||||
|
{
|
||||||
|
// Before and After
|
||||||
|
String before = coll.getId(entity);
|
||||||
|
if (before == null) return false;
|
||||||
|
String after = update(before, force);
|
||||||
|
if (after == null && !force) return false;
|
||||||
|
|
||||||
|
// NoChange
|
||||||
|
if (MUtil.equals(before, after)) return false;
|
||||||
|
|
||||||
|
// Apply
|
||||||
|
coll.detachEntity(entity);
|
||||||
|
if (after == null) return true;
|
||||||
|
coll.attach(entity, after);
|
||||||
|
coll.syncId(after);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
1083
src/com/massivecraft/mcore/util/IdUtil.java
Normal file
1083
src/com/massivecraft/mcore/util/IdUtil.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -251,6 +251,50 @@ public class InventoryUtil
|
|||||||
return (PlayerInventory)cloneInventory((Inventory)inventory);
|
return (PlayerInventory)cloneInventory((Inventory)inventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// EQUALS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static boolean equals(ItemStack one, ItemStack two)
|
||||||
|
{
|
||||||
|
if (isNothing(one)) return isNothing(two);
|
||||||
|
if (isNothing(two)) return false;
|
||||||
|
return one.equals(two);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean equals(ItemStack[] one, ItemStack[] two)
|
||||||
|
{
|
||||||
|
if (one == null) return two == null;
|
||||||
|
if (two == null) return false;
|
||||||
|
if (one.length != two.length) return false;
|
||||||
|
for (int i = 0; i < one.length; i++)
|
||||||
|
{
|
||||||
|
if (!equals(one[i], two[i])) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean equals(Inventory one, Inventory two)
|
||||||
|
{
|
||||||
|
if (one == null) return two == null;
|
||||||
|
if (two == null) return false;
|
||||||
|
if (!equals(one.getContents(), two.getContents())) return false;
|
||||||
|
if (one instanceof PlayerInventory)
|
||||||
|
{
|
||||||
|
PlayerInventory pone = (PlayerInventory)one;
|
||||||
|
if (two instanceof PlayerInventory)
|
||||||
|
{
|
||||||
|
PlayerInventory ptwo = (PlayerInventory)two;
|
||||||
|
return equals(pone.getArmorContents(), ptwo.getArmorContents());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// SET CONTENT
|
// SET CONTENT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.massivecraft.mcore.util;
|
package com.massivecraft.mcore.util;
|
||||||
|
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -12,6 +14,7 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -70,12 +73,30 @@ public class MUtil
|
|||||||
// IS VALID UUID
|
// IS VALID UUID
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
// The regex for a valid UUID in string form
|
|
||||||
public final static Pattern uuidPattern = Pattern.compile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$");
|
|
||||||
|
|
||||||
public static boolean isValidUUID(String string)
|
public static boolean isValidUUID(String string)
|
||||||
{
|
{
|
||||||
return uuidPattern.matcher(string).matches();
|
if (string == null) return false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
UUID.fromString(string);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// STACK TRACE STRING
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static String getStackTraceString()
|
||||||
|
{
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
new Throwable().printStackTrace(pw);
|
||||||
|
return sw.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -488,7 +509,7 @@ public class MUtil
|
|||||||
public static boolean equals(Object herp, Object derp)
|
public static boolean equals(Object herp, Object derp)
|
||||||
{
|
{
|
||||||
if (herp == null) return derp == null;
|
if (herp == null) return derp == null;
|
||||||
if (derp == null) return herp == null;
|
if (derp == null) return false;
|
||||||
return herp.equals(derp);
|
return herp.equals(derp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -634,7 +655,7 @@ public class MUtil
|
|||||||
registerExtractor(World.class, "world", ExtractorWorld.get());
|
registerExtractor(World.class, "world", ExtractorWorld.get());
|
||||||
registerExtractor(String.class, "worldName", ExtractorWorldName.get());
|
registerExtractor(String.class, "worldName", ExtractorWorldName.get());
|
||||||
|
|
||||||
registerExtractor(String.class, "accountId", ExtractorPlayerName.get());
|
registerExtractor(String.class, "accountId", ExtractorSenderId.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,47 +1,20 @@
|
|||||||
package com.massivecraft.mcore.util;
|
package com.massivecraft.mcore.util;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeMap;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.ConcurrentSkipListSet;
|
import java.util.concurrent.ConcurrentSkipListSet;
|
||||||
|
|
||||||
import net.minecraft.server.v1_7_R3.DedicatedServer;
|
|
||||||
import net.minecraft.server.v1_7_R3.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_7_R3.NBTCompressedStreamTools;
|
|
||||||
import net.minecraft.server.v1_7_R3.NBTTagCompound;
|
|
||||||
import net.minecraft.server.v1_7_R3.PacketPlayOutUpdateHealth;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_7_R3.CraftServer;
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
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;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import com.massivecraft.mcore.MCore;
|
import com.massivecraft.mcore.MCore;
|
||||||
import com.massivecraft.mcore.MCoreMPlayer;
|
|
||||||
import com.massivecraft.mcore.fetcher.FetcherPlayerIdCached;
|
|
||||||
import com.massivecraft.mcore.fetcher.FetcherPlayerNameCached;
|
|
||||||
import com.massivecraft.mcore.mixin.Mixin;
|
|
||||||
import com.massivecraft.mcore.store.Coll;
|
|
||||||
import com.massivecraft.mcore.store.SenderColl;
|
|
||||||
|
|
||||||
public class PlayerUtil implements Listener
|
public class PlayerUtil implements Listener
|
||||||
{
|
{
|
||||||
@ -156,251 +129,14 @@ public class PlayerUtil implements Listener
|
|||||||
*/
|
*/
|
||||||
public static void sendHealthFoodUpdatePacket(Player player)
|
public static void sendHealthFoodUpdatePacket(Player player)
|
||||||
{
|
{
|
||||||
|
// No need for nms anymore.
|
||||||
|
// We can trigger this packet through the use of this bukkit api method:
|
||||||
|
player.setHealthScaled(player.isHealthScaled());
|
||||||
|
/*
|
||||||
CraftPlayer cplayer = (CraftPlayer)player;
|
CraftPlayer cplayer = (CraftPlayer)player;
|
||||||
EntityPlayer eplayer = cplayer.getHandle();
|
EntityPlayer eplayer = cplayer.getHandle();
|
||||||
eplayer.playerConnection.sendPacket(new PacketPlayOutUpdateHealth(cplayer.getScaledHealth(), eplayer.getFoodData().a(), eplayer.getFoodData().e()));
|
eplayer.playerConnection.sendPacket(new PacketPlayOutUpdateHealth(cplayer.getScaledHealth(), eplayer.getFoodData().a(), eplayer.getFoodData().e()));
|
||||||
}
|
*/
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// PLAYER DIRECTORIES
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// Getting the player directories even when the server just started.
|
|
||||||
// We also supply ways to pull player names or UUIDs.
|
|
||||||
|
|
||||||
public static File getDirectoryBaseworld()
|
|
||||||
{
|
|
||||||
CraftServer cserver = (CraftServer)Bukkit.getServer();
|
|
||||||
DedicatedServer dserver = (DedicatedServer)cserver.getServer();
|
|
||||||
String levelName = dserver.propertyManager.getString("level-name", "world");
|
|
||||||
return new File(Bukkit.getWorldContainer(), levelName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File getDirectoryPlayerdata()
|
|
||||||
{
|
|
||||||
// after 1.7.8
|
|
||||||
// a2cce16b-9494-45ff-b5ff-0362ca687d4e.dat (the uuid)
|
|
||||||
return new File(getDirectoryBaseworld(), "playerdata");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<UUID> getDirectoryPlayerIds()
|
|
||||||
{
|
|
||||||
List<UUID> ret = new ArrayList<UUID>();
|
|
||||||
|
|
||||||
// Get the directory
|
|
||||||
File directory = getDirectoryPlayerdata();
|
|
||||||
|
|
||||||
// List the files in the directory
|
|
||||||
File[] files = directory.listFiles();
|
|
||||||
|
|
||||||
// The directory may not exist
|
|
||||||
if (files == null) return ret;
|
|
||||||
|
|
||||||
// Populate by removing .dat
|
|
||||||
for (File file : files)
|
|
||||||
{
|
|
||||||
String filename = file.getName();
|
|
||||||
|
|
||||||
// Ensure it's actually a .dat player filefile
|
|
||||||
if (!filename.toLowerCase().endsWith(".dat")) continue;
|
|
||||||
|
|
||||||
String uuid = filename.substring(0, filename.length()-4);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ret.add(UUID.fromString(uuid));
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getDirectoryPlayerNames()
|
|
||||||
{
|
|
||||||
List<String> ret = new ArrayList<String>();
|
|
||||||
|
|
||||||
// Get the directory
|
|
||||||
File directory = getDirectoryPlayerdata();
|
|
||||||
|
|
||||||
// List the files in the directory
|
|
||||||
File[] files = directory.listFiles();
|
|
||||||
|
|
||||||
// The directory may not exist
|
|
||||||
if (files == null) return ret;
|
|
||||||
|
|
||||||
// For each file
|
|
||||||
for (File file : files)
|
|
||||||
{
|
|
||||||
NBTTagCompound compound = loadTagCompound(file);
|
|
||||||
if (compound == null) continue;
|
|
||||||
|
|
||||||
if (!compound.hasKey("bukkit")) continue;
|
|
||||||
NBTTagCompound bukkit = compound.getCompound("bukkit");
|
|
||||||
if (bukkit == null) continue;
|
|
||||||
|
|
||||||
if (!bukkit.hasKey("lastKnownName")) continue;
|
|
||||||
String lastKnownName = bukkit.getString("lastKnownName");
|
|
||||||
if (lastKnownName == null) continue;
|
|
||||||
|
|
||||||
ret.add(lastKnownName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static NBTTagCompound loadTagCompound(File file)
|
|
||||||
{
|
|
||||||
if (!file.exists()) return null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return NBTCompressedStreamTools.a((InputStream) (new FileInputStream(file)));
|
|
||||||
}
|
|
||||||
catch (FileNotFoundException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// PLAYER ID <---> PLAYER NAME
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
// Update Cache on Login
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public void playerIdPlayerName(PlayerLoginEvent event)
|
|
||||||
{
|
|
||||||
final String playerName = event.getPlayer().getName();
|
|
||||||
final UUID playerId = event.getPlayer().getUniqueId();
|
|
||||||
MCoreMPlayer mplayer = MCoreMPlayer.get(playerId, true);
|
|
||||||
mplayer.setName(playerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, UUID> getPlayerIds(Collection<String> playerNames)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return FetcherPlayerIdCached.fetch(playerNames);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
return new TreeMap<String, UUID>(String.CASE_INSENSITIVE_ORDER);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static UUID getPlayerId(String playerName)
|
|
||||||
{
|
|
||||||
List<String> playerNames = Collections.singletonList(playerName);
|
|
||||||
Map<String, UUID> map = getPlayerIds(playerNames);
|
|
||||||
return map.get(playerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<UUID, String> getPlayerNames(Collection<UUID> playerIds)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return FetcherPlayerNameCached.fetch(playerIds);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
return new HashMap<UUID, String>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static String getPlayerName(UUID playerId)
|
|
||||||
{
|
|
||||||
List<UUID> playerIds = Collections.singletonList(playerId);
|
|
||||||
Map<UUID, String> map = getPlayerNames(playerIds);
|
|
||||||
return map.get(playerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// PLAYER ID <---> PLAYER NAME: FETCH ALL
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static void fetchAllIds()
|
|
||||||
{
|
|
||||||
// --- Starting Information ---
|
|
||||||
MCore.get().log(Txt.parse("<a>============================================"));
|
|
||||||
MCore.get().log(Txt.parse("<i>We are preparing for Mojangs switch to UUIDs."));
|
|
||||||
MCore.get().log(Txt.parse("<i>Learn more at: <aqua>https://forums.bukkit.org/threads/psa-the-switch-to-uuids-potential-plugin-server-breakage.250915/"));
|
|
||||||
MCore.get().log(Txt.parse("<i>Now fetching and caching UUID for all player names on this server!"));
|
|
||||||
MCore.get().log(Txt.parse("<i>The mstore collection \"<h>mcore_mplayer<i>\" will contain the cached information."));
|
|
||||||
|
|
||||||
// --- Find Player Names ---
|
|
||||||
// Here we build a set containing all player names we know of!
|
|
||||||
Set<String> playerNames = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
|
||||||
|
|
||||||
// All from mixin
|
|
||||||
playerNames.addAll(Mixin.getAllPlayerIds());
|
|
||||||
|
|
||||||
// All from sender colls
|
|
||||||
for (Coll<?> coll : Coll.getInstances())
|
|
||||||
{
|
|
||||||
if (!(coll instanceof SenderColl<?>)) continue;
|
|
||||||
playerNames.addAll(coll.getIds());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only valid player names
|
|
||||||
Iterator<String> iter = playerNames.iterator();
|
|
||||||
while (iter.hasNext())
|
|
||||||
{
|
|
||||||
String playerName =iter.next();
|
|
||||||
if (MUtil.isValidPlayerName(playerName)) continue;
|
|
||||||
iter.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Report: Player Names Found
|
|
||||||
MCore.get().log(Txt.parse("<k>Player Names Found: <v>%d", playerNames.size()));
|
|
||||||
|
|
||||||
// --- Remove Cached ---
|
|
||||||
// Here we remove what we already have cached.
|
|
||||||
iter = playerNames.iterator();
|
|
||||||
int cached = 0;
|
|
||||||
while (iter.hasNext())
|
|
||||||
{
|
|
||||||
String playerName = iter.next();
|
|
||||||
MCoreMPlayer mplayer = MCoreMPlayer.get(playerName);
|
|
||||||
if (mplayer == null) continue;
|
|
||||||
if (mplayer.getName() == null) continue;
|
|
||||||
cached++;
|
|
||||||
iter.remove();
|
|
||||||
}
|
|
||||||
MCore.get().log(Txt.parse("<k>Player Names Cached: <v>%d", cached));
|
|
||||||
MCore.get().log(Txt.parse("<k>Player Names Remaining: <v>%d", playerNames.size()));
|
|
||||||
|
|
||||||
// --- Fetch ---
|
|
||||||
// Here we fetch the remaining player names.
|
|
||||||
// We fetch them through the cached fetcher.
|
|
||||||
// This way we will use the mojang fetcher but also cache the result for the future.
|
|
||||||
|
|
||||||
MCore.get().log(Txt.parse("<i>Now fetching the remaining players from Mojang API ..."));
|
|
||||||
|
|
||||||
getPlayerIds(playerNames);
|
|
||||||
|
|
||||||
MCore.get().log(Txt.parse("<g> ... done!"));
|
|
||||||
MCore.get().log(Txt.parse("<i>(database saving will now commence which might lock the server for a while)"));
|
|
||||||
MCore.get().log(Txt.parse("<a>============================================"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> List<T> take(Collection<T> coll, int count)
|
|
||||||
{
|
|
||||||
List<T> ret = new ArrayList<T>();
|
|
||||||
|
|
||||||
Iterator<T> iter = coll.iterator();
|
|
||||||
int i = 0;
|
|
||||||
while (iter.hasNext() && i < count)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
ret.add(iter.next());
|
|
||||||
iter.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,315 +0,0 @@
|
|||||||
package com.massivecraft.mcore.util;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import net.minecraft.server.v1_7_R3.MinecraftServer;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.GameMode;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.command.BlockCommandSender;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
|
||||||
import org.bukkit.command.RemoteConsoleCommandSender;
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R3.CraftServer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.massivecraft.mcore.MCore;
|
|
||||||
import com.massivecraft.mcore.event.MCoreSenderRegisterEvent;
|
|
||||||
import com.massivecraft.mcore.event.MCoreSenderUnregisterEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We add an ID <--> CommandSender lookup feature.
|
|
||||||
* Each player has an id which is the UUID of the player.
|
|
||||||
* Players are retrievable by id using Bukkit.getPlayer().
|
|
||||||
* Other command senders have no true id. We make it so they have.
|
|
||||||
* Non-player-sender-ids always start with and ampersand (@). This is to avoid clashes with regular player names.
|
|
||||||
* The id is simply "@"+CommandSender.getName()
|
|
||||||
* Non standard CommandSenders must be manually registered to the util using the register method.
|
|
||||||
*/
|
|
||||||
public class SenderUtil
|
|
||||||
{
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// CONSTANTS
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
// The id prefix
|
|
||||||
public final static String IDPREFIX = "@";
|
|
||||||
|
|
||||||
// Ids for standard-non-players
|
|
||||||
public final static String ID_CONSOLE = IDPREFIX+"console";
|
|
||||||
public final static String ID_RCON = IDPREFIX+"rcon";
|
|
||||||
|
|
||||||
// Names for standard-non-players
|
|
||||||
public final static String VANILLA_CONSOLE_NAME = "CONSOLE";
|
|
||||||
public final static String VANILLA_RCON_NAME = "Rcon";
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// REGISTRY
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
protected static Map<String, CommandSender> idToSender = new TreeMap<String, CommandSender>(String.CASE_INSENSITIVE_ORDER);
|
|
||||||
|
|
||||||
public static synchronized boolean register(CommandSender sender)
|
|
||||||
{
|
|
||||||
if (sender == null) return false;
|
|
||||||
String id = getSenderId(sender);
|
|
||||||
idToSender.put(id, sender);
|
|
||||||
new MCoreSenderRegisterEvent(sender).run();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized boolean unregister(CommandSender sender)
|
|
||||||
{
|
|
||||||
boolean ret = (idToSender.remove(getSenderId(sender)) != null);
|
|
||||||
if (ret)
|
|
||||||
{
|
|
||||||
new MCoreSenderUnregisterEvent(sender).run();
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, CommandSender> getIdToSender()
|
|
||||||
{
|
|
||||||
return Collections.unmodifiableMap(idToSender);
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
// Since the console and rcon initially does not exist we schedule the register for these senders.
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(MCore.get(), new Runnable()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
register(getConsole());
|
|
||||||
register(getRcon());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// ID TYPE CHECKING
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static boolean isSenderId(Object o)
|
|
||||||
{
|
|
||||||
return o instanceof String || o instanceof UUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isPlayerId(Object o)
|
|
||||||
{
|
|
||||||
if (o instanceof UUID) return true;
|
|
||||||
if (!(o instanceof String)) return false;
|
|
||||||
String string = (String)o;
|
|
||||||
return MUtil.isValidPlayerName(string) || MUtil.isValidUUID(string);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isConsoleId(Object o)
|
|
||||||
{
|
|
||||||
return ID_CONSOLE.equals(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isRconId(Object o)
|
|
||||||
{
|
|
||||||
return ID_RCON.equals(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// SENDER/OBJECT TYPE CHECKING
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static boolean isSender(Object o)
|
|
||||||
{
|
|
||||||
return o instanceof CommandSender;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isPlayer(Object o)
|
|
||||||
{
|
|
||||||
return o instanceof Player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isBlock(Object o)
|
|
||||||
{
|
|
||||||
return o instanceof BlockCommandSender;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isConsole(Object o)
|
|
||||||
{
|
|
||||||
if (!(o instanceof ConsoleCommandSender)) return false;
|
|
||||||
if (!VANILLA_CONSOLE_NAME.equals(((CommandSender)o).getName())) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isRcon(Object o)
|
|
||||||
{
|
|
||||||
if (!(o instanceof RemoteConsoleCommandSender)) return false;
|
|
||||||
if (!VANILLA_RCON_NAME.equals(((CommandSender)o).getName())) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isNonplayer(Object o)
|
|
||||||
{
|
|
||||||
if (!isSender(o)) return false;
|
|
||||||
if (isPlayer(o)) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// GET ID
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
// TODO: Returns outdated value (name instead of ID)
|
|
||||||
public static String getSenderId(Object o)
|
|
||||||
{
|
|
||||||
if (!isSender(o)) return null;
|
|
||||||
if (isPlayer(o)) return ((CommandSender)o).getName();
|
|
||||||
if (isConsole(o)) return ID_CONSOLE;
|
|
||||||
if (isRcon(o)) return ID_RCON;
|
|
||||||
return ((CommandSender)o).getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// GET SENDER
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
// ACTUALL LOGIC
|
|
||||||
|
|
||||||
// Note: Handles both player id and name.
|
|
||||||
public static synchronized CommandSender getSender(String senderId)
|
|
||||||
{
|
|
||||||
if (senderId == null) return null;
|
|
||||||
|
|
||||||
if (MUtil.isValidPlayerName(senderId))
|
|
||||||
{
|
|
||||||
return Bukkit.getPlayerExact(senderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MUtil.isValidUUID(senderId))
|
|
||||||
{
|
|
||||||
UUID uuid = UUID.fromString(senderId);
|
|
||||||
return Bukkit.getPlayer(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
return idToSender.get(senderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ID STUFF
|
|
||||||
|
|
||||||
public static Player getPlayer(String senderId)
|
|
||||||
{
|
|
||||||
return getAsPlayer(getSender(senderId));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConsoleCommandSender getConsole(String senderId)
|
|
||||||
{
|
|
||||||
return getAsConsole(getSender(senderId));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RemoteConsoleCommandSender getRcon(String senderId)
|
|
||||||
{
|
|
||||||
return getAsRcon(getSender(senderId));
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARCHAL STUFF
|
|
||||||
|
|
||||||
public static CommandSender getAsSender(Object o)
|
|
||||||
{
|
|
||||||
if (!isSender(o)) return null;
|
|
||||||
return (CommandSender) o;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Player getAsPlayer(Object o)
|
|
||||||
{
|
|
||||||
if (!isPlayer(o)) return null;
|
|
||||||
return (Player) o;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BlockCommandSender getAsBlock(Object o)
|
|
||||||
{
|
|
||||||
if (!isBlock(o)) return null;
|
|
||||||
return (BlockCommandSender) o;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConsoleCommandSender getAsConsole(Object o)
|
|
||||||
{
|
|
||||||
if (!isConsole(o)) return null;
|
|
||||||
return (ConsoleCommandSender) o;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RemoteConsoleCommandSender getAsRcon(Object o)
|
|
||||||
{
|
|
||||||
if (!isRcon(o)) return null;
|
|
||||||
return (RemoteConsoleCommandSender) o;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// GET STANDARD-NON-PLAYERS
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static ConsoleCommandSender getConsole()
|
|
||||||
{
|
|
||||||
return Bukkit.getConsoleSender();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RemoteConsoleCommandSender getRcon()
|
|
||||||
{
|
|
||||||
Server server = Bukkit.getServer();
|
|
||||||
CraftServer craftServer = (CraftServer)server;
|
|
||||||
MinecraftServer minecraftServer = craftServer.getServer();
|
|
||||||
return minecraftServer.remoteConsole;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// GET ALL ONLINE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static List<CommandSender> getOnlineSenders()
|
|
||||||
{
|
|
||||||
List<CommandSender> ret = new ArrayList<CommandSender>(Arrays.asList(Bukkit.getOnlinePlayers()));
|
|
||||||
for (Entry<String, CommandSender> entry : idToSender.entrySet())
|
|
||||||
{
|
|
||||||
String id = entry.getKey();
|
|
||||||
CommandSender sender = entry.getValue();
|
|
||||||
if (isPlayerId(id)) continue;
|
|
||||||
ret.add(sender);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// CONVENIENCE GAME-MODE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static GameMode getGameMode(String senderId, GameMode def)
|
|
||||||
{
|
|
||||||
Player player = getPlayer(senderId);
|
|
||||||
if (player == null) return def;
|
|
||||||
return player.getGameMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isGameMode(String senderId, GameMode gm, boolean def)
|
|
||||||
{
|
|
||||||
Player player = getPlayer(senderId);
|
|
||||||
if (player == null) return def;
|
|
||||||
return player.getGameMode() == gm;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GameMode getGameMode(CommandSender sender, GameMode def)
|
|
||||||
{
|
|
||||||
return getGameMode(getSenderId(sender), def);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isGameMode(CommandSender sender, GameMode gm, boolean def)
|
|
||||||
{
|
|
||||||
return isGameMode(getSenderId(sender), gm, def);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -26,8 +26,7 @@ import org.bukkit.event.vehicle.VehicleEvent;
|
|||||||
import org.bukkit.event.vehicle.VehicleExitEvent;
|
import org.bukkit.event.vehicle.VehicleExitEvent;
|
||||||
|
|
||||||
import com.massivecraft.mcore.ps.PS;
|
import com.massivecraft.mcore.ps.PS;
|
||||||
import com.massivecraft.mcore.store.SenderEntity;
|
import com.massivecraft.mcore.util.IdUtil;
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
|
||||||
|
|
||||||
public class ExtractorLogic
|
public class ExtractorLogic
|
||||||
{
|
{
|
||||||
@ -35,7 +34,7 @@ public class ExtractorLogic
|
|||||||
// SENDER
|
// SENDER
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static CommandSender sender(String o) { return SenderUtil.getSender(o); }
|
public static CommandSender sender(String o) { return IdUtil.getSender(o); }
|
||||||
|
|
||||||
public static CommandSender sender(PlayerEvent o) { return o.getPlayer(); }
|
public static CommandSender sender(PlayerEvent o) { return o.getPlayer(); }
|
||||||
public static CommandSender sender(BlockBreakEvent o) { return o.getPlayer(); }
|
public static CommandSender sender(BlockBreakEvent o) { return o.getPlayer(); }
|
||||||
@ -94,11 +93,14 @@ public class ExtractorLogic
|
|||||||
public static String senderIdFromObject(Object o)
|
public static String senderIdFromObject(Object o)
|
||||||
{
|
{
|
||||||
if (o == null) return null;
|
if (o == null) return null;
|
||||||
if (o instanceof String) return (String)o;
|
|
||||||
if (o instanceof SenderEntity) return ((SenderEntity<?>)o).getId();
|
String id = IdUtil.getId(o);
|
||||||
|
if (id != null) return id;
|
||||||
|
|
||||||
CommandSender sender = senderFromObject(o);
|
CommandSender sender = senderFromObject(o);
|
||||||
if (sender == null) return null;
|
if (sender == null) return null;
|
||||||
return SenderUtil.getSenderId(sender);
|
|
||||||
|
return IdUtil.getId(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
Loading…
Reference in New Issue
Block a user