Ensure mini plugins aren't null
Lookin' at you, chat
This commit is contained in:
parent
3f83ac642a
commit
3786cb480d
@ -27,7 +27,6 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
|||||||
|
|
||||||
import mineplex.core.MiniDbClientPlugin;
|
import mineplex.core.MiniDbClientPlugin;
|
||||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||||
import mineplex.core.account.CoreClientManager;
|
|
||||||
import mineplex.core.account.ILoginProcessor;
|
import mineplex.core.account.ILoginProcessor;
|
||||||
import mineplex.core.account.permissions.Permission;
|
import mineplex.core.account.permissions.Permission;
|
||||||
import mineplex.core.account.permissions.PermissionGroup;
|
import mineplex.core.account.permissions.PermissionGroup;
|
||||||
@ -141,10 +140,40 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
private int _updateCycleCount; // The number of update cycles since we've updated all communities
|
private int _updateCycleCount; // The number of update cycles since we've updated all communities
|
||||||
private volatile boolean _cycling = false;
|
private volatile boolean _cycling = false;
|
||||||
|
|
||||||
private final Chat _chat;
|
private Chat _chat;
|
||||||
private final PreferencesManager _prefManager;
|
private PreferencesManager _prefManager;
|
||||||
private final CoreClientManager _clientManager;
|
private CustomDataManager _customDataManager;
|
||||||
private final CustomDataManager _customDataManager;
|
|
||||||
|
private Chat getChat()
|
||||||
|
{
|
||||||
|
// the mini plugin contract is a lie
|
||||||
|
if (_chat == null)
|
||||||
|
{
|
||||||
|
_chat = require(Chat.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _chat;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PreferencesManager getPrefManager()
|
||||||
|
{
|
||||||
|
if (_prefManager == null)
|
||||||
|
{
|
||||||
|
_prefManager = require(PreferencesManager.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _prefManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CustomDataManager getCustomDataManager()
|
||||||
|
{
|
||||||
|
if (_customDataManager == null)
|
||||||
|
{
|
||||||
|
_customDataManager = require(CustomDataManager.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _customDataManager;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"deprecation", "unchecked"})
|
@SuppressWarnings({"deprecation", "unchecked"})
|
||||||
private CommunityManager()
|
private CommunityManager()
|
||||||
@ -165,10 +194,9 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
|
|
||||||
_chat = require(Chat.class);
|
_chat = require(Chat.class);
|
||||||
_prefManager = require(PreferencesManager.class);
|
_prefManager = require(PreferencesManager.class);
|
||||||
_clientManager = require(CoreClientManager.class);
|
|
||||||
_customDataManager = require(CustomDataManager.class);
|
_customDataManager = require(CustomDataManager.class);
|
||||||
|
|
||||||
_clientManager.addStoredProcedureLoginProcessor(new ILoginProcessor()
|
getClientManager().addStoredProcedureLoginProcessor(new ILoginProcessor()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public String getName()
|
public String getName()
|
||||||
@ -289,11 +317,6 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
PermissionGroup.ADMIN.setPermission(Perm.COMMUNITY_UNINVITE_STAFF_COMMAND, true, true);
|
PermissionGroup.ADMIN.setPermission(Perm.COMMUNITY_UNINVITE_STAFF_COMMAND, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomDataManager getCustomDataManager()
|
|
||||||
{
|
|
||||||
return _customDataManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isNameValid(String communityName)
|
public boolean isNameValid(String communityName)
|
||||||
{
|
{
|
||||||
return VALID_NAME_PATTERN.matcher(communityName).find();
|
return VALID_NAME_PATTERN.matcher(communityName).find();
|
||||||
@ -301,7 +324,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
|
|
||||||
public boolean isNameAllowed(Player caller, String communityName)
|
public boolean isNameAllowed(Player caller, String communityName)
|
||||||
{
|
{
|
||||||
return !_chat.filterMessage(caller, communityName).contains("*");
|
return !getChat().filterMessage(caller, communityName).contains("*");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void communityExists(String name, Consumer<Boolean> result)
|
public void communityExists(String name, Consumer<Boolean> result)
|
||||||
@ -528,7 +551,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
if (!Get(Bukkit.getPlayer(targetUUID)).Invites.contains(community.getId()))
|
if (!Get(Bukkit.getPlayer(targetUUID)).Invites.contains(community.getId()))
|
||||||
{
|
{
|
||||||
Get(Bukkit.getPlayer(targetUUID)).Invites.add(community.getId());
|
Get(Bukkit.getPlayer(targetUUID)).Invites.add(community.getId());
|
||||||
if (_prefManager.get(Bukkit.getPlayer(targetUUID)).isActive(Preference.COMMUNITY_INVITES))
|
if (getPrefManager().get(Bukkit.getPlayer(targetUUID)).isActive(Preference.COMMUNITY_INVITES))
|
||||||
{
|
{
|
||||||
new JsonMessage(F.main(getName(), "You have been invited to join " + F.elem(community.getName()) + " by " + F.name(sender) + "! " + C.cGreen + "Click this message to join!")).click(ClickEvent.RUN_COMMAND, "/community join " + community.getName()).sendToPlayer(Bukkit.getPlayer(targetUUID));
|
new JsonMessage(F.main(getName(), "You have been invited to join " + F.elem(community.getName()) + " by " + F.name(sender) + "! " + C.cGreen + "Click this message to join!")).click(ClickEvent.RUN_COMMAND, "/community join " + community.getName()).sendToPlayer(Bukkit.getPlayer(targetUUID));
|
||||||
}
|
}
|
||||||
@ -553,7 +576,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
if (Bukkit.getPlayer(targetUUID) != null)
|
if (Bukkit.getPlayer(targetUUID) != null)
|
||||||
{
|
{
|
||||||
Get(Bukkit.getPlayer(targetUUID)).Invites.remove(community.getId());
|
Get(Bukkit.getPlayer(targetUUID)).Invites.remove(community.getId());
|
||||||
if (_prefManager.get(Bukkit.getPlayer(targetUUID)).isActive(Preference.COMMUNITY_INVITES) && announce)
|
if (getPrefManager().get(Bukkit.getPlayer(targetUUID)).isActive(Preference.COMMUNITY_INVITES) && announce)
|
||||||
{
|
{
|
||||||
UtilPlayer.message(Bukkit.getPlayer(targetUUID), F.main(getName(), "Your invitation to join " + F.elem(community.getName()) + " has been revoked by " + F.name(sender) + "!"));
|
UtilPlayer.message(Bukkit.getPlayer(targetUUID), F.main(getName(), "Your invitation to join " + F.elem(community.getName()) + " has been revoked by " + F.name(sender) + "!"));
|
||||||
}
|
}
|
||||||
@ -705,7 +728,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
{
|
{
|
||||||
UtilPlayer.message(sender, F.main(getName(), "You have invited " + F.name(target) + " to join " + F.name(community.getName()) + "!"));
|
UtilPlayer.message(sender, F.main(getName(), "You have invited " + F.name(target) + " to join " + F.name(community.getName()) + "!"));
|
||||||
}
|
}
|
||||||
new CommunityInvite(community.getId(), sender.getName(), target, _clientManager.loadUUIDFromDB(target).toString()).publish();
|
new CommunityInvite(community.getId(), sender.getName(), target, getClientManager().loadUUIDFromDB(target).toString()).publish();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -724,7 +747,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
{
|
{
|
||||||
UtilPlayer.message(sender, F.main(getName(), "You have revoked " + F.name(target) + "'s invitation to join " + F.name(community.getName()) + "!"));
|
UtilPlayer.message(sender, F.main(getName(), "You have revoked " + F.name(target) + "'s invitation to join " + F.name(community.getName()) + "!"));
|
||||||
}
|
}
|
||||||
new CommunityUnInvite(community.getId(), sender.getName(), target, _clientManager.loadUUIDFromDB(target).toString(), true).publish();
|
new CommunityUnInvite(community.getId(), sender.getName(), target, getClientManager().loadUUIDFromDB(target).toString(), true).publish();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -735,7 +758,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
|
|
||||||
public void handleRejectInvite(Player sender, int id)
|
public void handleRejectInvite(Player sender, int id)
|
||||||
{
|
{
|
||||||
final String playerName = _clientManager.Get(sender).getName();
|
final String playerName = getClientManager().Get(sender).getName();
|
||||||
runAsync(() ->
|
runAsync(() ->
|
||||||
{
|
{
|
||||||
_repo.deleteInviteToCommunity(id, playerName);
|
_repo.deleteInviteToCommunity(id, playerName);
|
||||||
@ -746,11 +769,11 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
|
|
||||||
public void handleJoinRequest(Player sender, Community community)
|
public void handleJoinRequest(Player sender, Community community)
|
||||||
{
|
{
|
||||||
final int accountId = _clientManager.getAccountId(sender);
|
final int accountId = getClientManager().getAccountId(sender);
|
||||||
|
|
||||||
if (Get(sender).Invites.contains(community.getId()))
|
if (Get(sender).Invites.contains(community.getId()))
|
||||||
{
|
{
|
||||||
String playerName = _clientManager.Get(sender).getName(); //Guarantee real name (important in this instance)
|
String playerName = getClientManager().Get(sender).getName(); //Guarantee real name (important in this instance)
|
||||||
runAsync(() ->
|
runAsync(() ->
|
||||||
{
|
{
|
||||||
_repo.addToCommunity(accountId, community.getId());
|
_repo.addToCommunity(accountId, community.getId());
|
||||||
@ -778,8 +801,8 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
|
|
||||||
public void handleJoin(Player sender, ICommunity community, boolean fromInvite)
|
public void handleJoin(Player sender, ICommunity community, boolean fromInvite)
|
||||||
{
|
{
|
||||||
final int accountId = _clientManager.getAccountId(sender);
|
final int accountId = getClientManager().getAccountId(sender);
|
||||||
final String playerName = _clientManager.Get(sender).getName();
|
final String playerName = getClientManager().Get(sender).getName();
|
||||||
runAsync(() ->
|
runAsync(() ->
|
||||||
{
|
{
|
||||||
_repo.addToCommunity(accountId, community.getId());
|
_repo.addToCommunity(accountId, community.getId());
|
||||||
@ -892,7 +915,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
|
|
||||||
public void handleToggleReadingChat(Player sender, Community community)
|
public void handleToggleReadingChat(Player sender, Community community)
|
||||||
{
|
{
|
||||||
final int accountId = _clientManager.getAccountId(sender);
|
final int accountId = getClientManager().getAccountId(sender);
|
||||||
final boolean reading = !community.getMembers().get(sender.getUniqueId()).ReadingChat;
|
final boolean reading = !community.getMembers().get(sender.getUniqueId()).ReadingChat;
|
||||||
|
|
||||||
runAsync(() ->
|
runAsync(() ->
|
||||||
@ -962,7 +985,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int savedChattingTo = _customDataManager.getData(sender, COMMUNITY_CHAT_KEY);
|
int savedChattingTo = getCustomDataManager().getData(sender, COMMUNITY_CHAT_KEY);
|
||||||
|
|
||||||
if (savedChattingTo != -1)
|
if (savedChattingTo != -1)
|
||||||
{
|
{
|
||||||
@ -1010,7 +1033,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
CommunityMemberData data = Get(player);
|
CommunityMemberData data = Get(player);
|
||||||
|
|
||||||
if (data.Invites.size() > 0 && _prefManager.get(event.getPlayer()).isActive(Preference.COMMUNITY_INVITES))
|
if (data.Invites.size() > 0 && getPrefManager().get(event.getPlayer()).isActive(Preference.COMMUNITY_INVITES))
|
||||||
{
|
{
|
||||||
UtilPlayer.message(event.getPlayer(), F.main(getName(), "You have been invited to join " + F.elem(data.Invites.size()) + " communities!"));
|
UtilPlayer.message(event.getPlayer(), F.main(getName(), "You have been invited to join " + F.elem(data.Invites.size()) + " communities!"));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user