QA Pass #2 - Comment WorldManager, optimize searching
This commit is contained in:
parent
b952de856e
commit
9853ef824e
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
@ -28,7 +29,9 @@ import mineplex.game.clans.spawn.Spawn;
|
|||||||
|
|
||||||
public class ClansUtility
|
public class ClansUtility
|
||||||
{
|
{
|
||||||
|
// The maximum number of clans to search before exiting early. Inclusive
|
||||||
private static final int MAX_CLAN_SEARCH = 10;
|
private static final int MAX_CLAN_SEARCH = 10;
|
||||||
|
// The maximum number of players to search before exiting early. Inclusive
|
||||||
private static final int MAX_PLAYER_SEARCH = 10;
|
private static final int MAX_PLAYER_SEARCH = 10;
|
||||||
|
|
||||||
private ClansManager _clansManager;
|
private ClansManager _clansManager;
|
||||||
@ -116,7 +119,7 @@ public class ClansUtility
|
|||||||
public ClanInfo searchClanPlayer(Player caller, String name, boolean inform)
|
public ClanInfo searchClanPlayer(Player caller, String name, boolean inform)
|
||||||
{
|
{
|
||||||
// CLAN
|
// CLAN
|
||||||
LinkedList<ClanInfo> clanMatchList = new LinkedList<ClanInfo>();
|
List<ClanInfo> clanMatchList = new ArrayList<>(MAX_CLAN_SEARCH);
|
||||||
|
|
||||||
for (ClanInfo cur : _clansManager.getClanMap().values())
|
for (ClanInfo cur : _clansManager.getClanMap().values())
|
||||||
{
|
{
|
||||||
@ -129,24 +132,8 @@ public class ClansUtility
|
|||||||
|
|
||||||
if (clanMatchList.size() == 1) return clanMatchList.get(0);
|
if (clanMatchList.size() == 1) return clanMatchList.get(0);
|
||||||
|
|
||||||
// No / Non-Unique
|
|
||||||
String clanMatchString = "";
|
|
||||||
if (clanMatchList.size() <= MAX_CLAN_SEARCH)
|
|
||||||
{
|
|
||||||
if (clanMatchList.size() > 1)
|
|
||||||
{
|
|
||||||
for (ClanInfo cur : clanMatchList)
|
|
||||||
clanMatchString += cur.getName() + " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clanMatchString.length() == 0)
|
|
||||||
{
|
|
||||||
clanMatchString = "None";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PLAYER
|
// PLAYER
|
||||||
LinkedList<ClanInfo> playerMatchList = new LinkedList<ClanInfo>();
|
List<ClanInfo> playerMatchList = new ArrayList<>(MAX_PLAYER_SEARCH);
|
||||||
|
|
||||||
outer: for (ClanInfo clanInfo : _clansManager.getClanMap().values())
|
outer: for (ClanInfo clanInfo : _clansManager.getClanMap().values())
|
||||||
{
|
{
|
||||||
@ -154,7 +141,12 @@ public class ClansUtility
|
|||||||
{
|
{
|
||||||
if (player.getPlayerName().equalsIgnoreCase(name)) return clanInfo;
|
if (player.getPlayerName().equalsIgnoreCase(name)) return clanInfo;
|
||||||
|
|
||||||
if (player.getPlayerName().toLowerCase().contains(name.toLowerCase())) playerMatchList.add(clanInfo);
|
if (player.getPlayerName().toLowerCase().contains(name.toLowerCase()))
|
||||||
|
{
|
||||||
|
playerMatchList.add(clanInfo);
|
||||||
|
// No duplicate results please
|
||||||
|
continue outer;
|
||||||
|
}
|
||||||
|
|
||||||
if (playerMatchList.size() > MAX_PLAYER_SEARCH) break outer;
|
if (playerMatchList.size() > MAX_PLAYER_SEARCH) break outer;
|
||||||
}
|
}
|
||||||
@ -162,22 +154,6 @@ public class ClansUtility
|
|||||||
|
|
||||||
if (playerMatchList.size() == 1) return playerMatchList.get(0);
|
if (playerMatchList.size() == 1) return playerMatchList.get(0);
|
||||||
|
|
||||||
// No / Non-Unique
|
|
||||||
String playerMatchString = "";
|
|
||||||
if (playerMatchList.size() <= MAX_PLAYER_SEARCH)
|
|
||||||
{
|
|
||||||
if (playerMatchList.size() > 1)
|
|
||||||
{
|
|
||||||
for (ClanInfo cur : playerMatchList)
|
|
||||||
playerMatchString += cur.getName() + " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (playerMatchString.length() == 0)
|
|
||||||
{
|
|
||||||
playerMatchString = "None";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inform)
|
if (inform)
|
||||||
{
|
{
|
||||||
UtilPlayer.message(caller, F.main("Clan Search", "" + C.mCount + (clanMatchList.size() + playerMatchList.size()) + C.mBody + " matches for [" + C.mElem + name + C.mBody + "]."));
|
UtilPlayer.message(caller, F.main("Clan Search", "" + C.mCount + (clanMatchList.size() + playerMatchList.size()) + C.mBody + " matches for [" + C.mElem + name + C.mBody + "]."));
|
||||||
@ -186,17 +162,35 @@ public class ClansUtility
|
|||||||
{
|
{
|
||||||
UtilPlayer.message(caller, F.main("Clan Search", "Too many clans matched. Try a more specific search"));
|
UtilPlayer.message(caller, F.main("Clan Search", "Too many clans matched. Try a more specific search"));
|
||||||
}
|
}
|
||||||
|
else if (clanMatchList.size() == 0)
|
||||||
|
{
|
||||||
|
UtilPlayer.message(caller, F.main("Clan Search", "No clans matched. Try a more specific search"));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UtilPlayer.message(caller, F.desc("Matches via Clan", clanMatchString));
|
StringBuilder clanMatchString = new StringBuilder();
|
||||||
|
for (ClanInfo clanInfo : clanMatchList)
|
||||||
|
{
|
||||||
|
clanMatchString.append(clanInfo.getName()).append(" ");
|
||||||
|
}
|
||||||
|
UtilPlayer.message(caller, F.desc("Matches via Clan", clanMatchString.toString()));
|
||||||
}
|
}
|
||||||
if (playerMatchList.size() > MAX_PLAYER_SEARCH)
|
if (playerMatchList.size() > MAX_PLAYER_SEARCH)
|
||||||
{
|
{
|
||||||
UtilPlayer.message(caller, F.main("Clan Search", "Too many players matched. Try a more specific search"));
|
UtilPlayer.message(caller, F.main("Clan Search", "Too many players matched. Try a more specific search"));
|
||||||
}
|
}
|
||||||
|
else if (playerMatchList.size() == 0)
|
||||||
|
{
|
||||||
|
UtilPlayer.message(caller, F.main("Clan Search", "No players matched. Try a more specific search"));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UtilPlayer.message(caller, F.desc("Matches via Player", playerMatchString));
|
StringBuilder playerMatchString = new StringBuilder();
|
||||||
|
for (ClanInfo clanInfo : playerMatchList)
|
||||||
|
{
|
||||||
|
playerMatchString.append(clanInfo.getName()).append(" ");
|
||||||
|
}
|
||||||
|
UtilPlayer.message(caller, F.desc("Matches via Player", playerMatchString.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ public class FinishCommand extends CommandBase<TutorialManager>
|
|||||||
public void Execute(Player caller, String[] args)
|
public void Execute(Player caller, String[] args)
|
||||||
{
|
{
|
||||||
boolean testServer = Plugin.getPlugin().getConfig().getString("serverstatus.group").equalsIgnoreCase("Testing");
|
boolean testServer = Plugin.getPlugin().getConfig().getString("serverstatus.group").equalsIgnoreCase("Testing");
|
||||||
if (CommandCenter.Instance.GetClientManager().hasRank(caller, testServer ? Rank.ALL : Rank.JNR_DEV))
|
if (_commandCenter.GetClientManager().hasRank(caller, testServer ? Rank.ALL : Rank.JNR_DEV))
|
||||||
{
|
{
|
||||||
Plugin.finishTutorial(caller);
|
Plugin.finishTutorial(caller);
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package mineplex.game.clans.tutorial.command;
|
package mineplex.game.clans.tutorial.command;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import mineplex.core.command.CommandBase;
|
|
||||||
import mineplex.core.command.MultiCommandBase;
|
import mineplex.core.command.MultiCommandBase;
|
||||||
import mineplex.core.common.Rank;
|
import mineplex.core.common.Rank;
|
||||||
import mineplex.core.common.util.F;
|
import mineplex.core.common.util.F;
|
||||||
import mineplex.core.common.util.UtilPlayer;
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
import mineplex.game.clans.tutorial.TutorialManager;
|
import mineplex.game.clans.tutorial.TutorialManager;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class TutorialCommand extends MultiCommandBase<TutorialManager>
|
public class TutorialCommand extends MultiCommandBase<TutorialManager>
|
||||||
{
|
{
|
||||||
@ -29,7 +27,7 @@ public class TutorialCommand extends MultiCommandBase<TutorialManager>
|
|||||||
public void Execute(Player caller, String[] args)
|
public void Execute(Player caller, String[] args)
|
||||||
{
|
{
|
||||||
boolean testServer = Plugin.getPlugin().getConfig().getString("serverstatus.group").equalsIgnoreCase("Testing");
|
boolean testServer = Plugin.getPlugin().getConfig().getString("serverstatus.group").equalsIgnoreCase("Testing");
|
||||||
if (CommandCenter.GetClientManager().hasRank(caller, testServer ? Rank.ALL : Rank.JNR_DEV))
|
if (_commandCenter.GetClientManager().hasRank(caller, testServer ? Rank.ALL : Rank.JNR_DEV))
|
||||||
{
|
{
|
||||||
super.Execute(caller, args);
|
super.Execute(caller, args);
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,8 @@ public class WorldManager extends MiniPlugin
|
|||||||
boolean cull = true;
|
boolean cull = true;
|
||||||
for (Player player : players)
|
for (Player player : players)
|
||||||
{
|
{
|
||||||
|
// Using NMS because this is going to be called quite a few times
|
||||||
|
// and each getLocation() call creates a new Location object
|
||||||
if (UtilWorld.distanceSquared(player, entity) <= MIN_RANGE_SQUARED)
|
if (UtilWorld.distanceSquared(player, entity) <= MIN_RANGE_SQUARED)
|
||||||
{
|
{
|
||||||
cull = false;
|
cull = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user