mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 22:56:45 +01:00
Improvements to mcMMOPlayer lookup.
This commit is contained in:
parent
98c6abad36
commit
50ef8d9610
@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
|
||||
@ -41,13 +40,7 @@ public final class PartyAPI {
|
||||
* @return true if the player is in a party, false otherwise
|
||||
*/
|
||||
public static boolean inParty(Player player) {
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
if (mcMMOPlayer == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return mcMMOPlayer.inParty();
|
||||
return UserManager.getPlayer(player).inParty();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
@ -39,9 +40,10 @@ public class KrakenCommand implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(args[0]);
|
||||
String playerName = Misc.getMatchedPlayerName(args[0]);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
|
||||
|
||||
if (!CommandUtils.checkPlayerExistence(sender, args[0], mcMMOPlayer)) {
|
||||
if (!CommandUtils.checkPlayerExistence(sender, playerName, mcMMOPlayer)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
|
||||
@ -45,9 +46,10 @@ public abstract class ToggleCommand implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
mcMMOPlayer = UserManager.getPlayer(args[0]);
|
||||
String playerName = Misc.getMatchedPlayerName(args[0]);
|
||||
mcMMOPlayer = UserManager.getPlayer(playerName);
|
||||
|
||||
if (!CommandUtils.checkPlayerExistence(sender, args[0], mcMMOPlayer)) {
|
||||
if (!CommandUtils.checkPlayerExistence(sender, playerName, mcMMOPlayer)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.util.StringUtil;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
|
||||
@ -21,15 +22,17 @@ public class McremoveCommand implements TabExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
if (UserManager.getPlayer(args[0]) == null && CommandUtils.unloadedProfile(sender, mcMMO.getDatabaseManager().loadPlayerProfile(args[0], false))) {
|
||||
String playerName = Misc.getMatchedPlayerName(args[0]);
|
||||
|
||||
if (UserManager.getPlayer(playerName) == null && CommandUtils.unloadedProfile(sender, mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mcMMO.getDatabaseManager().removeUser(args[0])) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", args[0]));
|
||||
if (mcMMO.getDatabaseManager().removeUser(playerName)) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", playerName));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(args[0] + " could not be removed from the database."); // Pretty sure this should NEVER happen.
|
||||
sender.sendMessage(playerName + " could not be removed from the database."); // Pretty sure this should NEVER happen.
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -67,7 +67,7 @@ public abstract class ExperienceCommand implements TabExecutor {
|
||||
}
|
||||
|
||||
String playerName = Misc.getMatchedPlayerName(args[0]);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayerExact(playerName);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
|
||||
|
||||
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
|
||||
if (mcMMOPlayer == null) {
|
||||
|
@ -8,6 +8,7 @@ import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
@ -56,11 +57,12 @@ public class SkillresetCommand extends ExperienceCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
mcMMOPlayer = UserManager.getPlayer(args[0]);
|
||||
String playerName = Misc.getMatchedPlayerName(args[0]);
|
||||
mcMMOPlayer = UserManager.getPlayer(playerName);
|
||||
|
||||
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
|
||||
if (mcMMOPlayer == null) {
|
||||
profile = mcMMO.getDatabaseManager().loadPlayerProfile(args[0], false);
|
||||
profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false);
|
||||
|
||||
if (CommandUtils.unloadedProfile(sender, profile)) {
|
||||
return true;
|
||||
@ -76,7 +78,7 @@ public class SkillresetCommand extends ExperienceCommand {
|
||||
editValues();
|
||||
}
|
||||
|
||||
handleSenderMessage(sender, args[0]);
|
||||
handleSenderMessage(sender, playerName);
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
@ -19,7 +19,7 @@ public class PartyInviteCommand implements CommandExecutor {
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
String playerName = Misc.getMatchedPlayerName(args[1]);
|
||||
McMMOPlayer mcMMOTarget = UserManager.getPlayerExact(playerName);
|
||||
McMMOPlayer mcMMOTarget = UserManager.getPlayer(playerName);
|
||||
|
||||
if (!CommandUtils.checkPlayerExistence(sender, playerName, mcMMOTarget)) {
|
||||
return false;
|
||||
|
@ -66,7 +66,7 @@ public class PartyJoinCommand implements CommandExecutor {
|
||||
|
||||
private boolean canJoinParty(CommandSender sender, String targetName) {
|
||||
targetName = Misc.getMatchedPlayerName(targetName);
|
||||
mcMMOTarget = UserManager.getPlayerExact(targetName);
|
||||
mcMMOTarget = UserManager.getPlayer(targetName);
|
||||
|
||||
if (!CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) {
|
||||
return false;
|
||||
|
@ -87,7 +87,7 @@ public class PtpCommand implements TabExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
sendTeleportRequest(sender, player, args[0]);
|
||||
sendTeleportRequest(sender, player, Misc.getMatchedPlayerName(args[0]));
|
||||
return true;
|
||||
|
||||
default:
|
||||
@ -139,7 +139,6 @@ public class PtpCommand implements TabExecutor {
|
||||
}
|
||||
|
||||
target = mcMMOTarget.getPlayer();
|
||||
targetName = target.getName();
|
||||
|
||||
if (player.equals(target)) {
|
||||
player.sendMessage(LocaleLoader.getString("Party.Teleport.Self"));
|
||||
|
@ -34,7 +34,7 @@ public class InspectCommand implements TabExecutor {
|
||||
}
|
||||
|
||||
String playerName = Misc.getMatchedPlayerName(args[0]);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayerExact(playerName);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
|
||||
|
||||
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
|
||||
if (mcMMOPlayer == null) {
|
||||
|
@ -52,7 +52,7 @@ public class McrankCommand implements TabExecutor {
|
||||
}
|
||||
|
||||
String playerName = Misc.getMatchedPlayerName(args[0]);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayerExact(playerName);
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
|
||||
|
||||
if (mcMMOPlayer != null) {
|
||||
playerName = mcMMOPlayer.getPlayer().getName();
|
||||
|
@ -215,10 +215,6 @@ public class EntityListener implements Listener {
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
if (mcMMOPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check for invincibility */
|
||||
if (mcMMOPlayer.getGodMode()) {
|
||||
event.setCancelled(true);
|
||||
|
@ -82,13 +82,7 @@ public class PlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
if (mcMMOPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mcMMOPlayer.actualizeTeleportATS();
|
||||
UserManager.getPlayer(player).actualizeTeleportATS();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,10 +161,6 @@ public class PlayerListener implements Listener {
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
if (mcMMOPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mcMMOPlayer.checkGodMode();
|
||||
mcMMOPlayer.checkParty();
|
||||
}
|
||||
@ -300,10 +290,6 @@ public class PlayerListener implements Listener {
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
if (mcMMOPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Item drop = event.getItem();
|
||||
ItemStack dropStack = drop.getItemStack();
|
||||
|
||||
@ -346,10 +332,6 @@ public class PlayerListener implements Listener {
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
if (mcMMOPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mcMMOPlayer.resetAbilityMode();
|
||||
BleedTimerTask.bleedOut(player);
|
||||
mcMMOPlayer.getProfile().save();
|
||||
@ -424,12 +406,6 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
// TODO: This shouldn't be possible - this is probably a band-aid for a larger issue somewhere else.
|
||||
if (mcMMOPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
MiningManager miningManager = mcMMOPlayer.getMiningManager();
|
||||
Block block = event.getClickedBlock();
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
@ -521,12 +497,6 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
// TODO: This shouldn't be possible - this is probably a band-aid for a larger issue somewhere else.
|
||||
if (mcMMOPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
|
||||
switch (event.getAction()) {
|
||||
@ -632,12 +602,6 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
if (mcMMOPlayer == null) {
|
||||
mcMMO.p.debug(player.getName() + " is currently chatting, but has never logged on to the server.");
|
||||
return;
|
||||
}
|
||||
|
||||
ChatManager chatManager = null;
|
||||
|
||||
if (mcMMOPlayer.getPartyChatMode()) {
|
||||
|
@ -63,10 +63,6 @@ public final class PartyManager {
|
||||
McMMOPlayer firstMcMMOPlayer = UserManager.getPlayer(firstPlayer);
|
||||
McMMOPlayer secondMcMMOPlayer = UserManager.getPlayer(secondPlayer);
|
||||
|
||||
if (firstMcMMOPlayer == null || secondMcMMOPlayer == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (firstMcMMOPlayer.getParty() == null || secondMcMMOPlayer.getParty() == null) {
|
||||
return false;
|
||||
}
|
||||
@ -514,10 +510,6 @@ public final class PartyManager {
|
||||
}
|
||||
|
||||
private static void processPartyLeaving(McMMOPlayer mcMMOPlayer) {
|
||||
if (mcMMOPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mcMMOPlayer.removeParty();
|
||||
mcMMOPlayer.setPartyChat(false);
|
||||
mcMMOPlayer.setItemShareModifier(10);
|
||||
|
@ -182,23 +182,20 @@ public final class Misc {
|
||||
|
||||
public static void profileCleanup(String playerName) {
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
McMMOHud spoutHud = mcMMOPlayer.getProfile().getSpoutHud();
|
||||
|
||||
if (mcMMOPlayer != null) {
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
McMMOHud spoutHud = mcMMOPlayer.getProfile().getSpoutHud();
|
||||
if (spoutHud != null) {
|
||||
spoutHud.removeWidgets();
|
||||
}
|
||||
|
||||
if (spoutHud != null) {
|
||||
spoutHud.removeWidgets();
|
||||
}
|
||||
UserManager.remove(playerName);
|
||||
|
||||
UserManager.remove(playerName);
|
||||
if (player.isOnline()) {
|
||||
UserManager.addUser(player);
|
||||
|
||||
if (player.isOnline()) {
|
||||
UserManager.addUser(player);
|
||||
|
||||
if (mcMMO.isSpoutEnabled()) {
|
||||
SpoutUtils.reloadSpoutPlayer(player);
|
||||
}
|
||||
if (mcMMO.isSpoutEnabled()) {
|
||||
SpoutUtils.reloadSpoutPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -273,16 +270,16 @@ public final class Misc {
|
||||
public static List<String> matchPlayer(String partialName) {
|
||||
List<String> matchedPlayers = new ArrayList<String>();
|
||||
|
||||
for (String iterPlayerName : mcMMO.getDatabaseManager().getStoredUsers()) {
|
||||
if (partialName.equalsIgnoreCase(iterPlayerName)) {
|
||||
for (String playerName : mcMMO.getDatabaseManager().getStoredUsers()) {
|
||||
if (partialName.equalsIgnoreCase(playerName)) {
|
||||
// Exact match
|
||||
matchedPlayers.clear();
|
||||
matchedPlayers.add(iterPlayerName);
|
||||
matchedPlayers.add(playerName);
|
||||
break;
|
||||
}
|
||||
if (iterPlayerName.toLowerCase().contains(partialName.toLowerCase())) {
|
||||
if (playerName.toLowerCase().contains(partialName.toLowerCase())) {
|
||||
// Partial match
|
||||
matchedPlayers.add(iterPlayerName);
|
||||
matchedPlayers.add(playerName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,6 +298,7 @@ public final class Misc {
|
||||
if (matches.size() == 1) {
|
||||
partialName = matches.get(0);
|
||||
}
|
||||
|
||||
return partialName;
|
||||
}
|
||||
|
||||
|
@ -2,15 +2,14 @@ package com.gmail.nossr50.util.player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
|
||||
public final class UserManager {
|
||||
private final static Map<String, McMMOPlayer> players = new HashMap<String, McMMOPlayer>();
|
||||
@ -72,29 +71,13 @@ public final class UserManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the McMMOPlayer of a player by a partial name.
|
||||
* Get the McMMOPlayer of a player by name.
|
||||
*
|
||||
* @param playerName The partial name of the player whose McMMOPlayer to retrieve
|
||||
* @param playerName The name of the player whose McMMOPlayer to retrieve
|
||||
* @return the player's McMMOPlayer object
|
||||
*/
|
||||
public static McMMOPlayer getPlayer(String playerName) {
|
||||
List<String> matches = Misc.matchPlayer(playerName);
|
||||
|
||||
if (matches.size() == 1) {
|
||||
playerName = matches.get(0);
|
||||
}
|
||||
|
||||
return players.get(playerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the McMMOPlayer of a player by the exact name.
|
||||
*
|
||||
* @param playerName The exact name of the player whose McMMOPlayer to retrieve
|
||||
* @return the player's McMMOPlayer object
|
||||
*/
|
||||
public static McMMOPlayer getPlayerExact(String playerName) {
|
||||
return players.get(playerName);
|
||||
return retrieveMcMMOPlayer(playerName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,6 +87,24 @@ public final class UserManager {
|
||||
* @return the player's McMMOPlayer object
|
||||
*/
|
||||
public static McMMOPlayer getPlayer(OfflinePlayer player) {
|
||||
return players.get(player.getName());
|
||||
return retrieveMcMMOPlayer(player.getName());
|
||||
}
|
||||
|
||||
private static McMMOPlayer retrieveMcMMOPlayer(String playerName) {
|
||||
McMMOPlayer mcMMOPlayer = players.get(playerName);
|
||||
|
||||
if (mcMMOPlayer == null) {
|
||||
Player player = mcMMO.p.getServer().getPlayerExact(playerName);
|
||||
|
||||
if (player == null) {
|
||||
mcMMO.p.getLogger().warning("A valid mcMMOPlayer object could not be found for " + playerName + ".");
|
||||
return null;
|
||||
}
|
||||
|
||||
mcMMOPlayer = new McMMOPlayer(player);
|
||||
players.put(playerName, mcMMOPlayer);
|
||||
}
|
||||
|
||||
return mcMMOPlayer;
|
||||
}
|
||||
}
|
||||
|
@ -139,11 +139,6 @@ public final class CombatUtils {
|
||||
|
||||
private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Entity arrow) {
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
if (mcMMOPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager();
|
||||
|
||||
if (archeryManager.canSkillShot()) {
|
||||
@ -242,7 +237,7 @@ public final class CombatUtils {
|
||||
* This will be reverted back to the switch statement once the fix is addressed on their end.
|
||||
*/
|
||||
|
||||
if (damager.getType() == EntityType.WOLF) {
|
||||
else if (damager.getType() == EntityType.WOLF) {
|
||||
Wolf wolf = (Wolf) damager;
|
||||
AnimalTamer tamer = wolf.getOwner();
|
||||
|
||||
@ -254,8 +249,7 @@ public final class CombatUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (damager.getType() == EntityType.ARROW) {
|
||||
else if (damager.getType() == EntityType.ARROW) {
|
||||
LivingEntity shooter = ((Arrow) damager).getShooter();
|
||||
|
||||
if (shooter != null && shooter instanceof Player && shouldProcessSkill(target, SkillType.ARCHERY)) {
|
||||
@ -317,11 +311,6 @@ public final class CombatUtils {
|
||||
|
||||
Player player = (Player) target;
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
if (mcMMOPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager();
|
||||
|
||||
if (acrobaticsManager.canDodge(damager)) {
|
||||
|
Loading…
Reference in New Issue
Block a user