Fix threading of community create command and make invite loader run on a LoginProcessor
This commit is contained in:
parent
36f671d944
commit
66c6f66768
@ -25,6 +25,7 @@ import com.google.common.collect.Lists;
|
|||||||
import mineplex.core.Managers;
|
import mineplex.core.Managers;
|
||||||
import mineplex.core.MiniDbClientPlugin;
|
import mineplex.core.MiniDbClientPlugin;
|
||||||
import mineplex.core.account.CoreClientManager;
|
import mineplex.core.account.CoreClientManager;
|
||||||
|
import mineplex.core.account.ILoginProcessor;
|
||||||
import mineplex.core.common.jsonchat.ClickEvent;
|
import mineplex.core.common.jsonchat.ClickEvent;
|
||||||
import mineplex.core.common.jsonchat.JsonMessage;
|
import mineplex.core.common.jsonchat.JsonMessage;
|
||||||
import mineplex.core.common.util.C;
|
import mineplex.core.common.util.C;
|
||||||
@ -105,6 +106,34 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
|
|
||||||
_loadedCommunities = new ConcurrentHashMap<>();
|
_loadedCommunities = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
clientManager.addStoredProcedureLoginProcessor(new ILoginProcessor()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return "community-invite-loader";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processLoginResultSet(String playerName, UUID uuid, int accountId, ResultSet resultSet) throws SQLException
|
||||||
|
{
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
String region = resultSet.getString("region");
|
||||||
|
if ((_us && region.equalsIgnoreCase("US")) || (!_us && region.equalsIgnoreCase("EU")))
|
||||||
|
{
|
||||||
|
CommunityManager.this.Get(uuid).Invites.add(resultSet.getInt("communityId"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getQuery(int accountId, String uuid, String name)
|
||||||
|
{
|
||||||
|
return "SELECT ci.communityId, c.region FROM communityInvites AS ci INNER JOIN communities AS c ON c.id=ci.communityId WHERE accountId=" + accountId + ";";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Bukkit.getScheduler().scheduleAsyncRepeatingTask(plugin, () ->
|
Bukkit.getScheduler().scheduleAsyncRepeatingTask(plugin, () ->
|
||||||
{
|
{
|
||||||
if (_cycling)
|
if (_cycling)
|
||||||
@ -630,7 +659,8 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
{
|
{
|
||||||
if (id == -1)
|
if (id == -1)
|
||||||
{
|
{
|
||||||
sender.sendMessage(F.main(getName(), "Failed to create community " + F.elem(name)));
|
UtilPlayer.message(sender, F.main(getName(), "Failed to create community " + F.elem(name)));
|
||||||
|
runSync(() -> _creating.remove(sender.getUniqueId()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -688,19 +718,11 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void loadInvites(PlayerJoinEvent event)
|
public void loadInvites(PlayerJoinEvent event)
|
||||||
{
|
{
|
||||||
final int accountId = Managers.get(CoreClientManager.class).getAccountId(event.getPlayer());
|
|
||||||
final CommunityMemberData data = Get(event.getPlayer());
|
final CommunityMemberData data = Get(event.getPlayer());
|
||||||
runAsync(() ->
|
if (data.Invites.size() > 0 && Managers.get(PreferencesManager.class).get(event.getPlayer()).isActive(Preference.COMMUNITY_INVITES))
|
||||||
{
|
{
|
||||||
_repo.loadInvites(accountId, data.Invites);
|
UtilPlayer.message(event.getPlayer(), F.main(getName(), "You have been invited to join " + F.elem(data.Invites.size()) + " communities!"));
|
||||||
runSync(() ->
|
}
|
||||||
{
|
|
||||||
if (data.Invites.size() > 0 && Managers.get(PreferencesManager.class).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!"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
|
@ -60,7 +60,7 @@ public class CommunityCreateCommand extends CommandBase<CommunityManager>
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Plugin.handleCreate(caller, accountId, args[0]);
|
Plugin.runSync(() -> Plugin.handleCreate(caller, accountId, args[0]));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user