mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-29 16:46:46 +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.mcMMO;
|
||||||
import com.gmail.nossr50.datatypes.party.Party;
|
import com.gmail.nossr50.datatypes.party.Party;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
||||||
import com.gmail.nossr50.party.PartyManager;
|
import com.gmail.nossr50.party.PartyManager;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
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
|
* @return true if the player is in a party, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean inParty(Player player) {
|
public static boolean inParty(Player player) {
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
return UserManager.getPlayer(player).inParty();
|
||||||
|
|
||||||
if (mcMMOPlayer == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mcMMOPlayer.inParty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,6 +11,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
@ -39,9 +40,10 @@ public class KrakenCommand implements TabExecutor {
|
|||||||
return true;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
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.commands.CommandUtils;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
|
|
||||||
@ -45,9 +46,10 @@ public abstract class ToggleCommand implements TabExecutor {
|
|||||||
return true;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import org.bukkit.util.StringUtil;
|
|||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
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) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 1:
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mcMMO.getDatabaseManager().removeUser(args[0])) {
|
if (mcMMO.getDatabaseManager().removeUser(playerName)) {
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", args[0]));
|
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", playerName));
|
||||||
}
|
}
|
||||||
else {
|
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;
|
return true;
|
||||||
|
@ -67,7 +67,7 @@ public abstract class ExperienceCommand implements TabExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String playerName = Misc.getMatchedPlayerName(args[0]);
|
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 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) {
|
if (mcMMOPlayer == null) {
|
||||||
|
@ -8,6 +8,7 @@ import com.gmail.nossr50.mcMMO;
|
|||||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||||
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
@ -56,11 +57,12 @@ public class SkillresetCommand extends ExperienceCommand {
|
|||||||
return true;
|
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 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) {
|
if (mcMMOPlayer == null) {
|
||||||
profile = mcMMO.getDatabaseManager().loadPlayerProfile(args[0], false);
|
profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false);
|
||||||
|
|
||||||
if (CommandUtils.unloadedProfile(sender, profile)) {
|
if (CommandUtils.unloadedProfile(sender, profile)) {
|
||||||
return true;
|
return true;
|
||||||
@ -76,7 +78,7 @@ public class SkillresetCommand extends ExperienceCommand {
|
|||||||
editValues();
|
editValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSenderMessage(sender, args[0]);
|
handleSenderMessage(sender, playerName);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -19,7 +19,7 @@ public class PartyInviteCommand implements CommandExecutor {
|
|||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 2:
|
case 2:
|
||||||
String playerName = Misc.getMatchedPlayerName(args[1]);
|
String playerName = Misc.getMatchedPlayerName(args[1]);
|
||||||
McMMOPlayer mcMMOTarget = UserManager.getPlayerExact(playerName);
|
McMMOPlayer mcMMOTarget = UserManager.getPlayer(playerName);
|
||||||
|
|
||||||
if (!CommandUtils.checkPlayerExistence(sender, playerName, mcMMOTarget)) {
|
if (!CommandUtils.checkPlayerExistence(sender, playerName, mcMMOTarget)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -66,7 +66,7 @@ public class PartyJoinCommand implements CommandExecutor {
|
|||||||
|
|
||||||
private boolean canJoinParty(CommandSender sender, String targetName) {
|
private boolean canJoinParty(CommandSender sender, String targetName) {
|
||||||
targetName = Misc.getMatchedPlayerName(targetName);
|
targetName = Misc.getMatchedPlayerName(targetName);
|
||||||
mcMMOTarget = UserManager.getPlayerExact(targetName);
|
mcMMOTarget = UserManager.getPlayer(targetName);
|
||||||
|
|
||||||
if (!CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) {
|
if (!CommandUtils.checkPlayerExistence(sender, targetName, mcMMOTarget)) {
|
||||||
return false;
|
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;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -139,7 +139,6 @@ public class PtpCommand implements TabExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
target = mcMMOTarget.getPlayer();
|
target = mcMMOTarget.getPlayer();
|
||||||
targetName = target.getName();
|
|
||||||
|
|
||||||
if (player.equals(target)) {
|
if (player.equals(target)) {
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Teleport.Self"));
|
player.sendMessage(LocaleLoader.getString("Party.Teleport.Self"));
|
||||||
|
@ -34,7 +34,7 @@ public class InspectCommand implements TabExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String playerName = Misc.getMatchedPlayerName(args[0]);
|
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 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) {
|
if (mcMMOPlayer == null) {
|
||||||
|
@ -52,7 +52,7 @@ public class McrankCommand implements TabExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String playerName = Misc.getMatchedPlayerName(args[0]);
|
String playerName = Misc.getMatchedPlayerName(args[0]);
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayerExact(playerName);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
|
||||||
|
|
||||||
if (mcMMOPlayer != null) {
|
if (mcMMOPlayer != null) {
|
||||||
playerName = mcMMOPlayer.getPlayer().getName();
|
playerName = mcMMOPlayer.getPlayer().getName();
|
||||||
|
@ -215,10 +215,6 @@ public class EntityListener implements Listener {
|
|||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (mcMMOPlayer == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check for invincibility */
|
/* Check for invincibility */
|
||||||
if (mcMMOPlayer.getGodMode()) {
|
if (mcMMOPlayer.getGodMode()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
@ -82,13 +82,7 @@ public class PlayerListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
UserManager.getPlayer(player).actualizeTeleportATS();
|
||||||
|
|
||||||
if (mcMMOPlayer == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mcMMOPlayer.actualizeTeleportATS();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -167,10 +161,6 @@ public class PlayerListener implements Listener {
|
|||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (mcMMOPlayer == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mcMMOPlayer.checkGodMode();
|
mcMMOPlayer.checkGodMode();
|
||||||
mcMMOPlayer.checkParty();
|
mcMMOPlayer.checkParty();
|
||||||
}
|
}
|
||||||
@ -300,10 +290,6 @@ public class PlayerListener implements Listener {
|
|||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (mcMMOPlayer == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Item drop = event.getItem();
|
Item drop = event.getItem();
|
||||||
ItemStack dropStack = drop.getItemStack();
|
ItemStack dropStack = drop.getItemStack();
|
||||||
|
|
||||||
@ -346,10 +332,6 @@ public class PlayerListener implements Listener {
|
|||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (mcMMOPlayer == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mcMMOPlayer.resetAbilityMode();
|
mcMMOPlayer.resetAbilityMode();
|
||||||
BleedTimerTask.bleedOut(player);
|
BleedTimerTask.bleedOut(player);
|
||||||
mcMMOPlayer.getProfile().save();
|
mcMMOPlayer.getProfile().save();
|
||||||
@ -424,12 +406,6 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
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();
|
MiningManager miningManager = mcMMOPlayer.getMiningManager();
|
||||||
Block block = event.getClickedBlock();
|
Block block = event.getClickedBlock();
|
||||||
ItemStack heldItem = player.getItemInHand();
|
ItemStack heldItem = player.getItemInHand();
|
||||||
@ -521,12 +497,6 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
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();
|
ItemStack heldItem = player.getItemInHand();
|
||||||
|
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
@ -632,12 +602,6 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
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;
|
ChatManager chatManager = null;
|
||||||
|
|
||||||
if (mcMMOPlayer.getPartyChatMode()) {
|
if (mcMMOPlayer.getPartyChatMode()) {
|
||||||
|
@ -63,10 +63,6 @@ public final class PartyManager {
|
|||||||
McMMOPlayer firstMcMMOPlayer = UserManager.getPlayer(firstPlayer);
|
McMMOPlayer firstMcMMOPlayer = UserManager.getPlayer(firstPlayer);
|
||||||
McMMOPlayer secondMcMMOPlayer = UserManager.getPlayer(secondPlayer);
|
McMMOPlayer secondMcMMOPlayer = UserManager.getPlayer(secondPlayer);
|
||||||
|
|
||||||
if (firstMcMMOPlayer == null || secondMcMMOPlayer == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstMcMMOPlayer.getParty() == null || secondMcMMOPlayer.getParty() == null) {
|
if (firstMcMMOPlayer.getParty() == null || secondMcMMOPlayer.getParty() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -514,10 +510,6 @@ public final class PartyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void processPartyLeaving(McMMOPlayer mcMMOPlayer) {
|
private static void processPartyLeaving(McMMOPlayer mcMMOPlayer) {
|
||||||
if (mcMMOPlayer == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mcMMOPlayer.removeParty();
|
mcMMOPlayer.removeParty();
|
||||||
mcMMOPlayer.setPartyChat(false);
|
mcMMOPlayer.setPartyChat(false);
|
||||||
mcMMOPlayer.setItemShareModifier(10);
|
mcMMOPlayer.setItemShareModifier(10);
|
||||||
|
@ -182,23 +182,20 @@ public final class Misc {
|
|||||||
|
|
||||||
public static void profileCleanup(String playerName) {
|
public static void profileCleanup(String playerName) {
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
|
||||||
|
Player player = mcMMOPlayer.getPlayer();
|
||||||
|
McMMOHud spoutHud = mcMMOPlayer.getProfile().getSpoutHud();
|
||||||
|
|
||||||
if (mcMMOPlayer != null) {
|
if (spoutHud != null) {
|
||||||
Player player = mcMMOPlayer.getPlayer();
|
spoutHud.removeWidgets();
|
||||||
McMMOHud spoutHud = mcMMOPlayer.getProfile().getSpoutHud();
|
}
|
||||||
|
|
||||||
if (spoutHud != null) {
|
UserManager.remove(playerName);
|
||||||
spoutHud.removeWidgets();
|
|
||||||
}
|
|
||||||
|
|
||||||
UserManager.remove(playerName);
|
if (player.isOnline()) {
|
||||||
|
UserManager.addUser(player);
|
||||||
|
|
||||||
if (player.isOnline()) {
|
if (mcMMO.isSpoutEnabled()) {
|
||||||
UserManager.addUser(player);
|
SpoutUtils.reloadSpoutPlayer(player);
|
||||||
|
|
||||||
if (mcMMO.isSpoutEnabled()) {
|
|
||||||
SpoutUtils.reloadSpoutPlayer(player);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,16 +270,16 @@ public final class Misc {
|
|||||||
public static List<String> matchPlayer(String partialName) {
|
public static List<String> matchPlayer(String partialName) {
|
||||||
List<String> matchedPlayers = new ArrayList<String>();
|
List<String> matchedPlayers = new ArrayList<String>();
|
||||||
|
|
||||||
for (String iterPlayerName : mcMMO.getDatabaseManager().getStoredUsers()) {
|
for (String playerName : mcMMO.getDatabaseManager().getStoredUsers()) {
|
||||||
if (partialName.equalsIgnoreCase(iterPlayerName)) {
|
if (partialName.equalsIgnoreCase(playerName)) {
|
||||||
// Exact match
|
// Exact match
|
||||||
matchedPlayers.clear();
|
matchedPlayers.clear();
|
||||||
matchedPlayers.add(iterPlayerName);
|
matchedPlayers.add(playerName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (iterPlayerName.toLowerCase().contains(partialName.toLowerCase())) {
|
if (playerName.toLowerCase().contains(partialName.toLowerCase())) {
|
||||||
// Partial match
|
// Partial match
|
||||||
matchedPlayers.add(iterPlayerName);
|
matchedPlayers.add(playerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,6 +298,7 @@ public final class Misc {
|
|||||||
if (matches.size() == 1) {
|
if (matches.size() == 1) {
|
||||||
partialName = matches.get(0);
|
partialName = matches.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return partialName;
|
return partialName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,15 +2,14 @@ package com.gmail.nossr50.util.player;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
import com.gmail.nossr50.util.Misc;
|
|
||||||
|
|
||||||
public final class UserManager {
|
public final class UserManager {
|
||||||
private final static Map<String, McMMOPlayer> players = new HashMap<String, McMMOPlayer>();
|
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
|
* @return the player's McMMOPlayer object
|
||||||
*/
|
*/
|
||||||
public static McMMOPlayer getPlayer(String playerName) {
|
public static McMMOPlayer getPlayer(String playerName) {
|
||||||
List<String> matches = Misc.matchPlayer(playerName);
|
return retrieveMcMMOPlayer(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,6 +87,24 @@ public final class UserManager {
|
|||||||
* @return the player's McMMOPlayer object
|
* @return the player's McMMOPlayer object
|
||||||
*/
|
*/
|
||||||
public static McMMOPlayer getPlayer(OfflinePlayer player) {
|
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) {
|
private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Entity arrow) {
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (mcMMOPlayer == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager();
|
ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager();
|
||||||
|
|
||||||
if (archeryManager.canSkillShot()) {
|
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.
|
* 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;
|
Wolf wolf = (Wolf) damager;
|
||||||
AnimalTamer tamer = wolf.getOwner();
|
AnimalTamer tamer = wolf.getOwner();
|
||||||
|
|
||||||
@ -254,8 +249,7 @@ public final class CombatUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (damager.getType() == EntityType.ARROW) {
|
||||||
if (damager.getType() == EntityType.ARROW) {
|
|
||||||
LivingEntity shooter = ((Arrow) damager).getShooter();
|
LivingEntity shooter = ((Arrow) damager).getShooter();
|
||||||
|
|
||||||
if (shooter != null && shooter instanceof Player && shouldProcessSkill(target, SkillType.ARCHERY)) {
|
if (shooter != null && shooter instanceof Player && shouldProcessSkill(target, SkillType.ARCHERY)) {
|
||||||
@ -317,11 +311,6 @@ public final class CombatUtils {
|
|||||||
|
|
||||||
Player player = (Player) target;
|
Player player = (Player) target;
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (mcMMOPlayer == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager();
|
AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager();
|
||||||
|
|
||||||
if (acrobaticsManager.canDodge(damager)) {
|
if (acrobaticsManager.canDodge(damager)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user