Skip to content

Commit

Permalink
add exception to async check for paper's async tab packets
Browse files Browse the repository at this point in the history
also multiple meta improvements
  • Loading branch information
mcmonkey4eva committed Aug 23, 2021
1 parent d1de30c commit c1ea138
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
Expand Up @@ -419,7 +419,7 @@ public static void registerTags() {
// @attribute <MaterialTag.is_solid>
// @returns ElementTag(Boolean)
// @description
// Returns whether the material is a block that is solid (cannot be walked through).
// Returns whether the material is a block that is solid (can be built upon).
// -->
registerTag("is_solid", (attribute, object) -> {
return new ElementTag(object.material.isSolid());
Expand Down
Expand Up @@ -40,11 +40,19 @@ public GiveCommand() {
//
// @Description
// Gives the linked player or inventory items, xp, or money.
//
// Optionally specify a slot to put the items into. If the slot is already filled, the next available slot will be used.
// If the player's inventory is full, the items will be dropped on the ground at the inventory's location.
// If the inventory is full, the items will be dropped on the ground at the inventory's location.
// For player inventories, only the storage contents are valid - to equip armor or an offhand item, use <@link command equip>.
//
// Specifying "unlimit_stack_size" will allow an item to stack up to 64. This is useful for stacking items
// with a max stack size that is less than 64 (for example, most weapon and armor items have a stack size of 1).
// If an economy is registered, specifying money instead of a item will give money to the player's economy.
//
// When giving an item, you can specify any valid inventory as a target. If unspecified, the linked player's inventory will be used.
//
// If an economy is registered, specifying money instead of a item will give money to the linked player's economy.
//
// If 'xp' is specified, this will give experience points to the linked player.
//
// @Tags
// <PlayerTag.money>
Expand Down Expand Up @@ -127,14 +135,21 @@ else if (!scriptEntry.hasObject("slot")
.defaultObject("quantity", new ElementTag(1))
.defaultObject("slot", new ElementTag(1));
Type type = (Type) scriptEntry.getObject("type");
if (type != Type.MONEY && scriptEntry.getObject("inventory") == null) {
scriptEntry.addObject("inventory", Utilities.entryHasPlayer(scriptEntry) ? Utilities.getEntryPlayer(scriptEntry).getInventory() : null);
}
if (!scriptEntry.hasObject("inventory") && type != Type.MONEY) {
throw new InvalidArgumentsException("Must specify an inventory to give to!");
if (type == Type.ITEM) {
if (!scriptEntry.hasObject("items")) {
throw new InvalidArgumentsException("Must specify item/items!");
}
if (!scriptEntry.hasObject("inventory")) {
if (!Utilities.entryHasPlayer(scriptEntry)) {
throw new InvalidArgumentsException("Must specify an inventory to give to!");
}
scriptEntry.addObject("inventory", Utilities.getEntryPlayer(scriptEntry).getInventory());
}
}
if (type == Type.ITEM && scriptEntry.getObject("items") == null) {
throw new InvalidArgumentsException("Must specify item/items!");
else {
if (!Utilities.entryHasPlayer(scriptEntry)) {
throw new InvalidArgumentsException("Must link a player to give money or XP!");
}
}
}

Expand All @@ -151,13 +166,7 @@ public void execute(ScriptEntry scriptEntry) {
items = (List<ItemTag>) items_object;
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(),
ArgumentHelper.debugObj("Type", type.name())
+ (inventory != null ? inventory.debug() : "")
+ quantity.debug()
+ unlimit_stack_size.debug()
+ (items != null ? ArgumentHelper.debugObj("Items", items) : "")
+ slot.debug());
Debug.report(scriptEntry, getName(), ArgumentHelper.debugObj("Type", type.name()), inventory, quantity, unlimit_stack_size, (items != null ? ArgumentHelper.debugObj("Items", items) : ""), slot);
}
switch (type) {
case MONEY:
Expand Down
Expand Up @@ -165,7 +165,9 @@ public void send(Packet<?> packet, GenericFutureListener<? extends Future<? supe
if (NMSHandler.debugPackets) {
Debug.log("Packet: " + packet.getClass().getCanonicalName() + " sent to " + player.getScoreboardName());
}
if (!Bukkit.isPrimaryThread() && !(packet instanceof ClientboundChatPacket)) {
if (!Bukkit.isPrimaryThread()
&& !(packet instanceof ClientboundChatPacket) // Vanilla supports an async chat system, though it's normally disabled, some plugins use this as justification for sending messages async
&& !(packet instanceof ClientboundCommandSuggestionsPacket)) { // Async tab complete is wholly unsupported in Spigot (and will cause an exception), however Paper explicitly adds async support (for unclear reasons), so let it through too
if (Debug.verbose || !hasShownAsyncWarning) {
hasShownAsyncWarning = true;
Debug.echoError("Warning: packet sent off main thread! This is completely unsupported behavior! Denizen network interceptor ignoring packet to avoid crash. Further display of this message requires '/denizen debug -v'. Packet class: "
Expand Down

0 comments on commit c1ea138

Please sign in to comment.