Allow for getting groups by their untagged names

This commit is contained in:
Daniel Saukel 2021-02-26 20:14:45 +01:00
parent 42bde96c86
commit bd14fa2202
2 changed files with 28 additions and 3 deletions

View File

@ -136,7 +136,7 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
private Registry<Integer, InstanceWorld> instanceCache = new Registry<>();
private Registry<String, GameRule> gameRuleRegistry = new GameRuleRegistry();
private Registry<String, ExternalMobProvider> externalMobProviderRegistry = new Registry<>();
private Registry<String, PlayerGroup> playerGroupCache = new Registry<>();
private Registry<String, PlayerGroup> playerGroupCache = new PlayerGroupCache();
private Collection<GroupAdapter> groupAdapters = new ArrayList<>();
@Deprecated
@ -177,6 +177,24 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
}
private class PlayerGroupCache extends Registry<String, PlayerGroup> {
@Override
public PlayerGroup get(String key) {
PlayerGroup group = elements.get(key);
if (group != null) {
return group;
}
for (PlayerGroup value : elements.values()) {
if (((DGroup) value).getUntaggedName().equalsIgnoreCase(key)) {
return value;
}
}
return null;
}
}
private boolean loaded, loadingWorld;
private GlobalData globalData;

View File

@ -68,6 +68,7 @@ public class DGroup implements PlayerGroup {
private int id;
private String name;
private String untaggedName;
private GroupSign groupSign;
private Player captain;
private PlayerCollection players = new PlayerCollection();
@ -94,9 +95,10 @@ public class DGroup implements PlayerGroup {
this.plugin = plugin;
dPlayers = plugin.getPlayerCache();
plugin.getGroupCache().add(name, this);
id = counter++;
untaggedName = name;
this.name = name + "#" + id;
plugin.getGroupCache().add(this.name, this);
GroupPlayerJoinEvent event = new GroupPlayerJoinEvent(this, dPlayers.get(player), true);
Bukkit.getPluginManager().callEvent(event);
@ -123,9 +125,10 @@ public class DGroup implements PlayerGroup {
this.plugin = plugin;
dPlayers = plugin.getPlayerCache();
plugin.getGroupCache().add(name, this);
id = counter++;
untaggedName = name;
this.name = name + "#" + id;
plugin.getGroupCache().add(this.name, this);
GroupPlayerJoinEvent event = new GroupPlayerJoinEvent(this, dPlayers.get(captain), true);
Bukkit.getPluginManager().callEvent(event);
@ -169,6 +172,10 @@ public class DGroup implements PlayerGroup {
this.name = name;
}
public String getUntaggedName() {
return untaggedName;
}
public GroupSign getGroupSign() {
return groupSign;
}