mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 10:36:10 +01:00
Catch exception from protocollib
This commit is contained in:
parent
d94cd006ec
commit
aa61f6b88c
@ -4,6 +4,7 @@ import java.util.Set;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
@ -11,6 +12,7 @@ import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
@ -36,8 +38,14 @@ public class ProtocolLibListener {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
Entity entity = manager.getEntityFromID(event.getPlayer().getWorld(),
|
||||
packet.getIntegers().getValues().get(0));
|
||||
Entity entity = null;
|
||||
try {
|
||||
entity = manager.getEntityFromID(event.getPlayer().getWorld(),
|
||||
packet.getIntegers().getValues().get(0));
|
||||
} catch (FieldAccessException ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(entity instanceof NPCHolder))
|
||||
return;
|
||||
|
||||
@ -50,16 +58,16 @@ public class ProtocolLibListener {
|
||||
if (session == null || !session.isActive())
|
||||
return;
|
||||
|
||||
if (event.getPacketType() == Server.ENTITY_HEAD_ROTATION) {
|
||||
PacketType type = event.getPacketType();
|
||||
if (type == Server.ENTITY_HEAD_ROTATION) {
|
||||
packet.getBytes().write(0, degToByte(session.getHeadYaw()));
|
||||
} else if (event.getPacketType() == Server.ENTITY_LOOK) {
|
||||
} else if (type == Server.ENTITY_LOOK) {
|
||||
packet.getBytes().write(0, degToByte(session.getBodyYaw()));
|
||||
packet.getBytes().write(1, degToByte(session.getPitch()));
|
||||
} else if (event.getPacketType() == Server.ENTITY_MOVE_LOOK
|
||||
|| event.getPacketType() == Server.REL_ENTITY_MOVE_LOOK) {
|
||||
} else if (type == Server.ENTITY_MOVE_LOOK || type == Server.REL_ENTITY_MOVE_LOOK) {
|
||||
packet.getBytes().write(0, degToByte(session.getBodyYaw()));
|
||||
packet.getBytes().write(1, degToByte(session.getPitch()));
|
||||
} else if (event.getPacketType() == Server.POSITION) {
|
||||
} else if (type == Server.POSITION) {
|
||||
Set<PlayerTeleportFlag> rel = getFlagsModifier(packet).read(0);
|
||||
rel.remove(PlayerTeleportFlag.ZYAW);
|
||||
rel.remove(PlayerTeleportFlag.ZPITCH);
|
||||
|
@ -183,11 +183,6 @@ public class ScoreboardTrait extends Trait {
|
||||
NMS.setTeamNameTagVisible(team, nameVisibility);
|
||||
}
|
||||
|
||||
if (npc.data().has(NPC.GLOWING_COLOR_METADATA)) {
|
||||
color = ChatColor.valueOf(npc.data().get(NPC.GLOWING_COLOR_METADATA));
|
||||
npc.data().remove(NPC.GLOWING_COLOR_METADATA);
|
||||
}
|
||||
|
||||
if (color != null) {
|
||||
if (SUPPORT_GLOWING_COLOR && Util.getMinecraftRevision().contains("1_12_R1")) {
|
||||
SUPPORT_GLOWING_COLOR = false;
|
||||
@ -201,6 +196,7 @@ public class ScoreboardTrait extends Trait {
|
||||
changed = true;
|
||||
}
|
||||
} catch (NoSuchMethodError err) {
|
||||
err.printStackTrace();
|
||||
SUPPORT_GLOWING_COLOR = false;
|
||||
}
|
||||
} else {
|
||||
|
@ -49,7 +49,21 @@ public class TextBasePrompt extends StringPrompt {
|
||||
} else {
|
||||
text.remove(index);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("delay")) {
|
||||
} else if (input.equalsIgnoreCase("page")) {
|
||||
try {
|
||||
int page = Integer.parseInt(parts[1]);
|
||||
if (!text.hasPage(page)) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_PAGE);
|
||||
}
|
||||
context.setSessionData("page", page);
|
||||
} catch (NumberFormatException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_PAGE);
|
||||
}
|
||||
}
|
||||
|
||||
Messaging.send(sender, getPromptText(context));
|
||||
|
||||
if (input.equalsIgnoreCase("delay")) {
|
||||
try {
|
||||
int delay = Integer.parseInt(parts[1]);
|
||||
text.setDelay(delay);
|
||||
@ -84,22 +98,11 @@ public class TextBasePrompt extends StringPrompt {
|
||||
} else {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_MISSING_ITEM_PATTERN);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("page")) {
|
||||
try {
|
||||
int page = Integer.parseInt(parts[1]);
|
||||
if (!text.hasPage(page)) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_PAGE);
|
||||
}
|
||||
context.setSessionData("page", page);
|
||||
} catch (NumberFormatException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_PAGE);
|
||||
}
|
||||
} else {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_EDIT_TYPE);
|
||||
return this;
|
||||
}
|
||||
|
||||
Messaging.send(sender, getPromptText(context));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user