add more debug information to the injection handler
This commit is contained in:
parent
bc4fcc0091
commit
49dec7d115
7 changed files with 39 additions and 13 deletions
|
@ -1,9 +1,9 @@
|
|||
package io.github.znetworkw.znpcservers.commands;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import io.github.znetworkw.znpcservers.commands.exception.CommandException;
|
||||
import io.github.znetworkw.znpcservers.commands.exception.CommandExecuteException;
|
||||
import io.github.znetworkw.znpcservers.commands.exception.CommandPermissionException;
|
||||
import io.github.znetworkw.znpcservers.exception.CommandException;
|
||||
import io.github.znetworkw.znpcservers.exception.CommandExecuteException;
|
||||
import io.github.znetworkw.znpcservers.exception.CommandPermissionException;
|
||||
import io.github.znetworkw.znpcservers.reflection.Reflections;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package io.github.znetworkw.znpcservers.commands;
|
||||
|
||||
import io.github.znetworkw.znpcservers.commands.exception.CommandException;
|
||||
import io.github.znetworkw.znpcservers.commands.exception.CommandExecuteException;
|
||||
import io.github.znetworkw.znpcservers.commands.exception.CommandPermissionException;
|
||||
import io.github.znetworkw.znpcservers.exception.CommandException;
|
||||
import io.github.znetworkw.znpcservers.exception.CommandExecuteException;
|
||||
import io.github.znetworkw.znpcservers.exception.CommandPermissionException;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package io.github.znetworkw.znpcservers.exception;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ChannelRegistrationException extends Throwable {
|
||||
private final Throwable throwable;
|
||||
private final List<String> channelNames;
|
||||
|
||||
public ChannelRegistrationException(Throwable t, List<String> channelNames) {
|
||||
this.throwable = t;
|
||||
this.channelNames = new ImmutableList.Builder<String>().addAll(channelNames).build();
|
||||
}
|
||||
|
||||
public Throwable getThrowable() {
|
||||
return throwable;
|
||||
}
|
||||
|
||||
public List<String> getChannelNames() {
|
||||
return channelNames;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package io.github.znetworkw.znpcservers.commands.exception;
|
||||
package io.github.znetworkw.znpcservers.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package io.github.znetworkw.znpcservers.commands.exception;
|
||||
package io.github.znetworkw.znpcservers.exception;
|
||||
|
||||
public class CommandExecuteException extends CommandException {
|
||||
public CommandExecuteException(String message, Throwable cause) {
|
|
@ -1,4 +1,4 @@
|
|||
package io.github.znetworkw.znpcservers.commands.exception;
|
||||
package io.github.znetworkw.znpcservers.exception;
|
||||
|
||||
public class CommandPermissionException extends CommandException {
|
||||
public CommandPermissionException(String message) {
|
|
@ -1,6 +1,7 @@
|
|||
package io.github.znetworkw.znpcservers.user;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import io.github.znetworkw.znpcservers.exception.ChannelRegistrationException;
|
||||
import io.github.znetworkw.znpcservers.npc.NPC;
|
||||
import io.github.znetworkw.znpcservers.npc.NPCAction;
|
||||
import io.github.znetworkw.znpcservers.npc.event.ClickType;
|
||||
|
@ -59,7 +60,7 @@ public class ZUser {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
Exception ex = user.tryRegisterChannel();
|
||||
ChannelRegistrationException ex = user.tryRegisterChannel();
|
||||
Player player = user.toPlayer();
|
||||
if (player == null) {
|
||||
tries--;
|
||||
|
@ -75,20 +76,22 @@ public class ZUser {
|
|||
ChatColor.WHITE + "Couldn't inject interaction detector to channel\n" +
|
||||
ChatColor.WHITE + "Please report this at https://github.com/Pyrbu/ZNPCsPlus");
|
||||
ZNPCsPlus.LOGGER.severe("Couldn't inject interaction detector to channel for player " + player.getName() + " (" + player.getUniqueId() + ")");
|
||||
ZNPCsPlus.LOGGER.severe("Channel names: " + ex.getChannelNames());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Exception tryRegisterChannel() {
|
||||
private ChannelRegistrationException tryRegisterChannel() {
|
||||
Channel channel = null;
|
||||
try {
|
||||
Channel channel = (Channel) Reflections.CHANNEL_FIELD.get().get(Reflections.NETWORK_MANAGER_FIELD.get().get(this.playerConnection));
|
||||
channel = (Channel) Reflections.CHANNEL_FIELD.get().get(Reflections.NETWORK_MANAGER_FIELD.get().get(this.playerConnection));
|
||||
if (channel.pipeline().names().contains("npc_interact")) channel.pipeline().remove("npc_interact");
|
||||
channel.pipeline().addAfter("decoder", "npc_interact", new ZNPCSocketDecoder());
|
||||
return null;
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException("illegal access exception while trying to register npc_interact channel");
|
||||
} catch (NoSuchElementException e) {
|
||||
return e;
|
||||
return new ChannelRegistrationException(e, channel == null ? List.of() : channel.pipeline().names());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue