Player data things, LPInjector update start
This commit is contained in:
parent
d3ae53cd46
commit
40fe1093e0
8 changed files with 44 additions and 58 deletions
|
@ -180,7 +180,7 @@ public class DiscordPlugin extends ButtonPlugin {
|
|||
|
||||
CommonListeners.register(dc.getEventDispatcher());
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(), this);
|
||||
TBMCCoreAPI.RegisterUserClass(DiscordPlayer.class);
|
||||
TBMCCoreAPI.RegisterUserClass(DiscordPlayer.class, DiscordPlayer::new);
|
||||
ChromaGamerBase.addConverter(sender -> Optional.ofNullable(sender instanceof DiscordSenderBase
|
||||
? ((DiscordSenderBase) sender).getChromaUser() : null));
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
|
@ -42,20 +40,16 @@ public class ConnectCommand extends ICommand2DC {
|
|||
channel.createMessage("The specified Minecraft player cannot be found").subscribe();
|
||||
return true;
|
||||
}
|
||||
try (TBMCPlayer pl = TBMCPlayerBase.getPlayer(p.getUniqueId(), TBMCPlayer.class)) {
|
||||
DiscordPlayer dp = pl.getAs(DiscordPlayer.class);
|
||||
if (dp != null && author.getId().asString().equals(dp.getDiscordID())) {
|
||||
channel.createMessage("You already have this account connected.").subscribe();
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occured while connecting a Discord account!", e, DiscordPlugin.plugin);
|
||||
channel.createMessage("An internal error occured!\n" + e).subscribe();
|
||||
TBMCPlayer pl = TBMCPlayerBase.getPlayer(p.getUniqueId(), TBMCPlayer.class);
|
||||
DiscordPlayer dp = pl.getAs(DiscordPlayer.class);
|
||||
if (dp != null && author.getId().asString().equals(dp.getDiscordID())) {
|
||||
channel.createMessage("You already have this account connected.").subscribe();
|
||||
return true;
|
||||
}
|
||||
WaitingToConnect.put(p.getName(), author.getId().asString());
|
||||
channel.createMessage(
|
||||
"Alright! Now accept the connection in Minecraft from the account " + Minecraftname
|
||||
+ " before the next server restart. You can also adjust the Minecraft name you want to connect to with the same command.").subscribe();
|
||||
+ " before the next server restart. You can also adjust the Minecraft name you want to connect to by running this command again.").subscribe();
|
||||
if (p.isOnline())
|
||||
((Player) p).sendMessage("§bTo connect with the Discord account " + author.getUsername() + "#"
|
||||
+ author.getDiscriminator() + " do /discord accept");
|
||||
|
|
|
@ -2,7 +2,6 @@ package buttondevteam.discordplugin.commands;
|
|||
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
|
@ -67,14 +66,10 @@ public class UserinfoCommand extends ICommand2DC {
|
|||
sender.sendMessage("An error occurred.");
|
||||
return true;
|
||||
}
|
||||
try (DiscordPlayer dp = ChromaGamerBase.getUser(target.getId().asString(), DiscordPlayer.class)) {
|
||||
StringBuilder uinfo = new StringBuilder("User info for ").append(target.getUsername()).append(":\n");
|
||||
uinfo.append(dp.getInfo(InfoTarget.Discord));
|
||||
channel.createMessage(uinfo.toString()).subscribe();
|
||||
} catch (Exception e) {
|
||||
channel.createMessage("An error occured while getting the user!").subscribe();
|
||||
TBMCCoreAPI.SendException("Error while getting info about " + target.getUsername() + "!", e, DiscordPlugin.plugin);
|
||||
}
|
||||
DiscordPlayer dp = ChromaGamerBase.getUser(target.getId().asString(), DiscordPlayer.class);
|
||||
StringBuilder uinfo = new StringBuilder("User info for ").append(target.getUsername()).append(":\n");
|
||||
uinfo.append(dp.getInfo(InfoTarget.Discord));
|
||||
channel.createMessage(uinfo.toString()).subscribe();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,21 +7,21 @@ import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
|
|||
import buttondevteam.discordplugin.util.DPState;
|
||||
import buttondevteam.lib.TBMCCommandPreprocessEvent;
|
||||
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
|
||||
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
|
||||
import discord4j.common.util.Snowflake;
|
||||
import discord4j.core.object.entity.Member;
|
||||
import discord4j.core.object.entity.User;
|
||||
import lombok.val;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class MCListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(TBMCPlayerJoinEvent e) {
|
||||
if (ConnectCommand.WaitingToConnect.containsKey(e.GetPlayer().PlayerName().get())) {
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
if (ConnectCommand.WaitingToConnect.containsKey(e.getPlayer().getName())) {
|
||||
@SuppressWarnings("ConstantConditions") User user = DiscordPlugin.dc
|
||||
.getUserById(Snowflake.of(ConnectCommand.WaitingToConnect.get(e.GetPlayer().PlayerName().get()))).block();
|
||||
.getUserById(Snowflake.of(ConnectCommand.WaitingToConnect.get(e.getPlayer().getName()))).block();
|
||||
if (user == null) return;
|
||||
e.getPlayer().sendMessage("§bTo connect with the Discord account @" + user.getUsername() + "#" + user.getDiscriminator()
|
||||
+ " do /discord accept");
|
||||
|
|
|
@ -5,7 +5,6 @@ import buttondevteam.discordplugin.DiscordPlayer;
|
|||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.discordplugin.commands.Command2DCSender;
|
||||
import buttondevteam.discordplugin.commands.ICommand2DC;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import discord4j.core.object.entity.channel.PrivateChannel;
|
||||
|
@ -36,15 +35,12 @@ public class MCChatCommand extends ICommand2DC {
|
|||
DPUtils.reply(message, channel, "this command can only be issued in a direct message with the bot.").subscribe();
|
||||
return true;
|
||||
}
|
||||
try (final DiscordPlayer user = DiscordPlayer.getUser(author.getId().asString(), DiscordPlayer.class)) {
|
||||
boolean mcchat = !user.isMinecraftChatEnabled();
|
||||
MCChatPrivate.privateMCChat(channel, mcchat, author, user);
|
||||
DPUtils.reply(message, channel, "Minecraft chat " + (mcchat //
|
||||
? "enabled. Use '" + DiscordPlugin.getPrefix() + "mcchat' again to turn it off." //
|
||||
: "disabled.")).subscribe();
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Error while setting mcchat for user " + author.getUsername() + "#" + author.getDiscriminator(), e, module);
|
||||
}
|
||||
final DiscordPlayer user = DiscordPlayer.getUser(author.getId().asString(), DiscordPlayer.class);
|
||||
boolean mcchat = !user.isMinecraftChatEnabled();
|
||||
MCChatPrivate.privateMCChat(channel, mcchat, author, user);
|
||||
DPUtils.reply(message, channel, "Minecraft chat " + (mcchat //
|
||||
? "enabled. Use '" + DiscordPlugin.getPrefix() + "mcchat' again to turn it off." //
|
||||
: "disabled.")).subscribe();
|
||||
return true;
|
||||
} // TODO: Pin channel switching to indicate the current channel
|
||||
|
||||
|
|
|
@ -338,8 +338,8 @@ public class MCChatListener implements Listener {
|
|||
if (dmessage.length() == 0 && event.getMessage().getAttachments().size() == 0
|
||||
&& !isPrivate && event.getMessage().getType() == Message.Type.CHANNEL_PINNED_MESSAGE) {
|
||||
val rtr = clmd != null ? clmd.mcchannel.getRTR(clmd.dcp)
|
||||
: dsender.getChromaUser().channel().get().getRTR(dsender);
|
||||
TBMCChatAPI.SendSystemMessage(clmd != null ? clmd.mcchannel : dsender.getChromaUser().channel().get(), rtr,
|
||||
: dsender.getChromaUser().channel.get().getRTR(dsender);
|
||||
TBMCChatAPI.SendSystemMessage(clmd != null ? clmd.mcchannel : dsender.getChromaUser().channel.get(), rtr,
|
||||
(dsender instanceof Player ? ((Player) dsender).getDisplayName()
|
||||
: dsender.getName()) + " pinned a message on Discord.", TBMCSystemChatEvent.BroadcastTarget.ALL);
|
||||
} else {
|
||||
|
@ -374,7 +374,7 @@ public class MCChatListener implements Listener {
|
|||
}
|
||||
module.log(dsender.getName() + " ran from DC: /" + cmd);
|
||||
if (runCustomCommand(dsender, cmdlowercased)) return true;
|
||||
val channel = clmd == null ? user.channel().get() : clmd.mcchannel;
|
||||
val channel = clmd == null ? user.channel.get() : clmd.mcchannel;
|
||||
val ev = new TBMCCommandPreprocessEvent(dsender, channel, dmessage, clmd == null ? dsender : clmd.dcp);
|
||||
Bukkit.getScheduler().runTask(DiscordPlugin.plugin, //Commands need to be run sync
|
||||
() -> {
|
||||
|
|
|
@ -38,8 +38,6 @@ public class DiscordMCCommand extends ICommand2MC {
|
|||
DiscordPlayer dp = ChromaGamerBase.getUser(did, DiscordPlayer.class);
|
||||
TBMCPlayer mcp = TBMCPlayerBase.getPlayer(player.getUniqueId(), TBMCPlayer.class);
|
||||
dp.connectWith(mcp);
|
||||
dp.save();
|
||||
mcp.save();
|
||||
ConnectCommand.WaitingToConnect.remove(player.getName());
|
||||
MCChatUtils.UnconnectedSenders.remove(did); //Remove all unconnected, will be recreated where needed
|
||||
player.sendMessage("§bAccounts connected.");
|
||||
|
|
|
@ -10,8 +10,10 @@ import me.lucko.luckperms.bukkit.inject.permissible.DummyPermissibleBase;
|
|||
import me.lucko.luckperms.bukkit.inject.permissible.LuckPermsPermissible;
|
||||
import me.lucko.luckperms.bukkit.listeners.BukkitConnectionListener;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.locale.Message;
|
||||
import me.lucko.luckperms.common.locale.TranslationManager;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
@ -92,9 +94,9 @@ public final class LPInjector implements Listener { //Disable login event for Lu
|
|||
|
||||
final DiscordConnectedPlayer player = (DiscordConnectedPlayer) e.getPlayer();
|
||||
|
||||
/*if (plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||
if (plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||
plugin.getLogger().info("Processing login for " + player.getUniqueId() + " - " + player.getName());
|
||||
}*/
|
||||
}
|
||||
|
||||
final User user = plugin.getUserManager().getIfLoaded(player.getUniqueId());
|
||||
|
||||
|
@ -102,7 +104,7 @@ public final class LPInjector implements Listener { //Disable login event for Lu
|
|||
if (user == null) {
|
||||
deniedLogin.add(player.getUniqueId());
|
||||
|
||||
if (!connectionListener.getUniqueConnections().contains(player.getUniqueId())) {
|
||||
if (!plugin.getConnectionListener().getUniqueConnections().contains(player.getUniqueId())) {
|
||||
|
||||
plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getName() +
|
||||
" doesn't have data pre-loaded, they have never been processed during pre-login in this session." +
|
||||
|
@ -111,7 +113,9 @@ public final class LPInjector implements Listener { //Disable login event for Lu
|
|||
try {
|
||||
if ((Boolean) detectedCraftBukkitOfflineMode.get(connectionListener)) {
|
||||
printCraftBukkitOfflineModeError.invoke(connectionListener);
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.LOADING_STATE_ERROR_CB_OFFLINE_MODE.asString(plugin.getLocaleManager()));
|
||||
|
||||
Component reason = TranslationManager.render(Message.LOADING_STATE_ERROR_CB_OFFLINE_MODE.build(), player.getLocale());
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, LegacyComponentSerializer.legacySection().serialize(reason));
|
||||
return;
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException ex) {
|
||||
|
@ -124,32 +128,31 @@ public final class LPInjector implements Listener { //Disable login event for Lu
|
|||
" - denying login.");
|
||||
}
|
||||
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.LOADING_STATE_ERROR.asString(plugin.getLocaleManager()));
|
||||
Component reason = TranslationManager.render(Message.LOADING_STATE_ERROR.build(), player.getLocale());
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, LegacyComponentSerializer.legacySection().serialize(reason));
|
||||
return;
|
||||
}
|
||||
|
||||
// User instance is there, now we can inject our custom Permissible into the player.
|
||||
// Care should be taken at this stage to ensure that async tasks which manipulate bukkit data check that the player is still online.
|
||||
try {
|
||||
// get the existing PermissibleBase held by the player
|
||||
PermissibleBase oldPermissible = player.getPerm();
|
||||
|
||||
// Make a new permissible for the user
|
||||
LuckPermsPermissible lpPermissible = new LuckPermsPermissible(player, user, plugin);
|
||||
LuckPermsPermissible lpPermissible = new LuckPermsPermissible(player, user, this.plugin);
|
||||
|
||||
// Inject into the player
|
||||
inject(player, lpPermissible, oldPermissible);
|
||||
inject(player, lpPermissible);
|
||||
|
||||
} catch (Throwable t) {
|
||||
plugin.getLogger().warn("Exception thrown when setting up permissions for " +
|
||||
player.getUniqueId() + " - " + player.getName() + " - denying login.");
|
||||
t.printStackTrace();
|
||||
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.LOADING_SETUP_ERROR.asString(plugin.getLocaleManager()));
|
||||
//return;
|
||||
Component reason = TranslationManager.render(Message.LOADING_SETUP_ERROR.build(), player.getLocale());
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, LegacyComponentSerializer.legacySection().serialize(reason));
|
||||
return;
|
||||
}
|
||||
|
||||
//this.plugin.getContextManager().signalContextUpdate(player);
|
||||
this.plugin.getContextManager().signalContextUpdate(player);
|
||||
}
|
||||
|
||||
// Wait until the last priority to unload, so plugins can still perform permission checks on this event
|
||||
|
@ -160,14 +163,14 @@ public final class LPInjector implements Listener { //Disable login event for Lu
|
|||
|
||||
final DiscordConnectedPlayer player = (DiscordConnectedPlayer) e.getPlayer();
|
||||
|
||||
connectionListener.handleDisconnect(player.getUniqueId());
|
||||
handleDisconnect(player.getUniqueId());
|
||||
|
||||
// perform unhooking from bukkit objects 1 tick later.
|
||||
// this allows plugins listening after us on MONITOR to still have intact permissions data
|
||||
this.plugin.getBootstrap().getServer().getScheduler().runTaskLaterAsynchronously(this.plugin.getBootstrap(), () -> {
|
||||
this.plugin.getBootstrap().getServer().getScheduler().runTaskLater(this.plugin.getBootstrap(), () -> {
|
||||
// Remove the custom permissible
|
||||
try {
|
||||
uninject(player);
|
||||
uninject(player, true);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue