Skip to content

Commit

Permalink
Various cleanups - meta, event matchers, stray debug, network impl
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 30, 2021
1 parent d5bf4fc commit 7180246
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 28 deletions.
Expand Up @@ -308,7 +308,10 @@ public boolean couldMatchBlock(String text, Function<Material, Boolean> requirem
if (mat == null || !mat.getMaterial().isBlock()) {
return false;
}
return true;
if (mat.getMaterial().isBlock() && (requirement == null || requirement.apply(mat.getMaterial()))) {
return true;
}
return false;
}
if (isAdvancedMatchable(text)) {
MatchHelper matcher = createMatcher(text);
Expand Down
Expand Up @@ -48,7 +48,7 @@ public boolean couldMatch(ScriptPath path) {
if (!path.eventLower.contains("collides with")) {
return false;
}
if (!couldMatchVehicle(path.eventArgLowerAt(0))) {
if (!exactMatchesVehicle(path.eventArgLowerAt(0))) {
return false;
}
if (!couldMatchBlock(path.eventArgLowerAt(3))) {
Expand Down
Expand Up @@ -63,7 +63,7 @@ public boolean couldMatch(ScriptPath path) {
if (!couldMatchEntity(path.eventArgLowerAt(3))) {
return false;
}
if (!couldMatchVehicle(path.eventArgLowerAt(0))) {
if (!exactMatchesVehicle(path.eventArgLowerAt(0))) {
return false;
}
return true;
Expand Down
Expand Up @@ -43,7 +43,7 @@ public boolean couldMatch(ScriptPath path) {
if (!path.eventArgLowerAt(1).equals("created")) {
return false;
}
if (!couldMatchVehicle(path.eventArgLowerAt(0))) {
if (!exactMatchesVehicle(path.eventArgLowerAt(0))) {
return false;
}
return true;
Expand Down
Expand Up @@ -63,7 +63,7 @@ public boolean couldMatch(ScriptPath path) {
if (path.eventArgLowerAt(3).equals("by")) {
return false;
}
if (!couldMatchVehicle(path.eventArgLowerAt(0)) && !couldMatchVehicle(path.eventArgLowerAt(2))) {
if (!exactMatchesVehicle(path.eventArgLowerAt(0)) && !exactMatchesVehicle(path.eventArgLowerAt(2))) {
return false;
}
if (!couldMatchEntity(path.eventArgLowerAt(0))) {
Expand Down
Expand Up @@ -56,12 +56,12 @@ public boolean couldMatch(ScriptPath path) {
if (!couldMatchEntity(path.eventArgLowerAt(0))) {
return false;
}
if (!couldMatchVehicle(path.eventArgLowerAt(2))) {
if (!exactMatchesVehicle(path.eventArgLowerAt(2))) {
return false;
}
}
else if (cmd.equals("destroyed")) {
if (!couldMatchVehicle(path.eventArgLowerAt(0))) {
if (!exactMatchesVehicle(path.eventArgLowerAt(0))) {
return false;
}
}
Expand Down
Expand Up @@ -47,7 +47,7 @@ public boolean couldMatch(ScriptPath path) {
if (!path.eventArgLowerAt(1).equals("moves")) {
return false;
}
if (!couldMatchVehicle(path.eventArgLowerAt(0))) {
if (!exactMatchesVehicle(path.eventArgLowerAt(0))) {
return false;
}
return true;
Expand Down
Expand Up @@ -3860,7 +3860,6 @@ else if (getBukkitEntity() instanceof Creeper) {
NMSHandler.getPlayerHelper().setAttackCooldown((Player) getLivingEntity(), mechanism.getValue().asType(DurationTag.class, mechanism.context).getTicksAsInt());
}

Debug.log("Attempt mech: " + mechanism.getName());
// <--[mechanism]
// @object EntityTag
// @name fallingblock_type
Expand All @@ -3876,7 +3875,6 @@ else if (getBukkitEntity() instanceof Creeper) {
return;
}
NMSHandler.getEntityHelper().setFallingBlockType((FallingBlock) getBukkitEntity(), mechanism.valueAsType(MaterialTag.class).getModernData());
Debug.log("Type set: " + ((FallingBlock) getBukkitEntity()).getBlockData());
}


Expand Down
Expand Up @@ -369,10 +369,10 @@ public String getPrefix() {
@Override
public String debuggable() {
if (npc.getOwningRegistry() == CitizensAPI.getNPCRegistry()) {
return "n@" + npc.getId() + "<GR> (" + getName() + ")";
return "n@" + npc.getId() + "<GR> (" + getName() + "<GR>)";
}
else {
return "n@" + npc.getId() + "<G>," + npc.getOwningRegistry().getName() + "<GR> (" + getName() + ")";
return "n@" + npc.getId() + "<G>," + npc.getOwningRegistry().getName() + "<GR> (" + getName() + "<GR>)";
}
}

Expand Down
Expand Up @@ -64,7 +64,7 @@ public ExecuteCommand() {
// - execute as_server "save-all"
//
// @Usage
// Use to make the linked (non-op) player execute a command that normally only ops can use.
// Use to make the linked (non-op) player execute a command that normally only ops can use. Generally avoid ever doing this.
// - execute as_op "staffsay hi"
// -->

Expand Down
@@ -1,6 +1,6 @@
package com.denizenscript.denizen.scripts.containers.core;

import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizen.objects.InventoryTag;
import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizencore.objects.ArgumentHelper;
Expand Down Expand Up @@ -47,7 +47,7 @@ public class InventoryScriptContainer extends ScriptContainer {
// type: inventory
//
// # Must be a valid inventory type.
// # Valid inventory types: BREWING, CHEST, DISPENSER, ENCHANTING, ENDER_CHEST, HOPPER, PLAYER, WORKBENCH
// # Valid inventory types: BREWING, CHEST, DISPENSER, ENCHANTING, ENDER_CHEST, HOPPER, WORKBENCH
// # | All inventory scripts MUST have this key!
// inventory: inventory type
//
Expand Down Expand Up @@ -117,35 +117,39 @@ public InventoryTag getInventoryFrom(TagContext context) {
type = InventoryType.valueOf(getString("inventory").toUpperCase());
}
catch (IllegalArgumentException ex) {
Debug.echoError("Invalid inventory type specified. Assuming \"CHEST\" (" + ex.getMessage() + ")");
Debug.echoError(this, "Invalid inventory type specified. Assuming \"CHEST\" (" + ex.getMessage() + ")");
}
}
else {
Debug.echoError("Inventory script '" + getName() + "' does not specify an inventory type. Assuming \"CHEST\".");
Debug.echoError(this, "Inventory script '" + getName() + "' does not specify an inventory type. Assuming \"CHEST\".");
}
if (type == InventoryType.PLAYER) {
Debug.echoError(this, "Inventory type 'player' is not valid for inventory scripts - defaulting to 'CHEST'.");
type = InventoryType.CHEST;
}
int size = 0;
if (contains("size")) {
if (type != InventoryType.CHEST) {
Debug.echoError("You can only set the size of chest inventories!");
Debug.echoError(this, "You can only set the size of chest inventories!");
}
else {
String sizeText = TagManager.tag(getString("size"), context);
if (!ArgumentHelper.matchesInteger(sizeText)) {
Debug.echoError("Inventory script '" + getName() + "' has invalid (not-a-number) size value.");
Debug.echoError(this, "Invalid (not-a-number) size value.");
}
else {
size = Integer.parseInt(sizeText);
}
if (size == 0) {
Debug.echoError("Inventory size can't be 0. Assuming default of inventory type...");
Debug.echoError(this, "Inventory size can't be 0. Assuming default of inventory type...");
}
if (size % 9 != 0) {
size = (int) Math.ceil(size / 9.0) * 9;
Debug.echoError("Inventory size must be a multiple of 9! Rounding up to " + size + "...");
Debug.echoError(this, "Inventory size must be a multiple of 9! Rounding up to " + size + "...");
}
if (size < 0) {
size = size * -1;
Debug.echoError("Inventory size must be a positive number! Inverting to " + size + "...");
Debug.echoError(this, "Inventory size must be a positive number! Inverting to " + size + "...");
}
}
}
Expand Down Expand Up @@ -181,8 +185,7 @@ public InventoryTag getInventoryFrom(TagContext context) {
continue;
}
if (!items.startsWith("[") || !items.endsWith("]")) {
Debug.echoError("Inventory script \"" + getName() + "\" has an invalid slots line: ["
+ items + "]... Ignoring it");
Debug.echoError(this, "Invalid slots line: [" + items + "]... Ignoring it");
continue;
}
String[] itemsInLine = items.substring(1, items.length() - 1).split("\\[?\\]?\\s+\\[", -1);
Expand All @@ -195,7 +198,7 @@ public InventoryTag getInventoryFrom(TagContext context) {
if (contains("definitions." + item)) {
ItemTag def = ItemTag.valueOf(TagManager.tag(getString("definitions." + item), context), context);
if (def == null) {
Debug.echoError("Invalid definition '" + item + "' in inventory script '" + getName() + "'" + "... Ignoring it and assuming 'AIR'");
Debug.echoError(this, "Invalid definition '" + item + "'... Ignoring it and assuming 'AIR'");
finalItems[itemsAdded] = new ItemStack(Material.AIR);
}
else {
Expand All @@ -207,14 +210,14 @@ public InventoryTag getInventoryFrom(TagContext context) {
ItemTag itemTag = ItemTag.valueOf(item, context);
if (itemTag == null) {
finalItems[itemsAdded] = new ItemStack(Material.AIR);
Debug.echoError("Inventory script '" + getName() + "' has an invalid slot item: [" + item + "]... ignoring it and assuming 'AIR'");
Debug.echoError(this, "Invalid slot item: [" + item + "]... ignoring it and assuming 'AIR'");
}
else {
finalItems[itemsAdded] = itemTag.getItemStack();
}
}
catch (Exception ex) {
Debug.echoError("Inventory script '" + getName() + "' has an invalid slot item: [" + item + "]...");
Debug.echoError(this, "Invalid slot item: [" + item + "]...");
Debug.echoError(ex);
}
}
Expand Down Expand Up @@ -257,7 +260,7 @@ public InventoryTag getInventoryFrom(TagContext context) {
}
}
catch (Exception e) {
Debug.echoError("Woah! An exception has been called with this inventory script!");
Debug.echoError(this, "Woah! An exception has been called while building this inventory script!");
Debug.echoError(e);
inventory = null;
}
Expand Down
Expand Up @@ -2,6 +2,8 @@

import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
Expand Down Expand Up @@ -111,6 +113,11 @@ public void send(Packet<?> packet) {
oldListener.send(packet);
}

@Override
public void send(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
oldListener.send(packet, genericfuturelistener);
}

public void handlePacketIn(Packet<ServerGamePacketListener> packet) {
denizenNetworkManager.packetsReceived++;
if (NMSHandler.debugPackets) {
Expand Down
Expand Up @@ -98,6 +98,16 @@ public static void setNetworkManager(Player player) {
setNetworkManager(playerConnection, new DenizenNetworkManagerImpl(entityPlayer, playerConnection.connection));
}

@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
oldManager.channelRegistered(ctx);
}

@Override
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
oldManager.channelUnregistered(ctx);
}

@Override
public void channelActive(ChannelHandlerContext channelhandlercontext) throws Exception {
oldManager.channelActive(channelhandlercontext);
Expand All @@ -113,6 +123,21 @@ public void channelInactive(ChannelHandlerContext channelhandlercontext) {
oldManager.channelInactive(channelhandlercontext);
}

@Override
public boolean isSharable() {
return oldManager.isSharable();
}

@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
oldManager.handlerAdded(ctx);
}

@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
oldManager.handlerRemoved(ctx);
}

@Override
public void exceptionCaught(ChannelHandlerContext channelhandlercontext, Throwable throwable) {
oldManager.exceptionCaught(channelhandlercontext, throwable);
Expand Down Expand Up @@ -976,11 +1001,26 @@ public boolean isMemoryConnection() {
return oldManager.isMemoryConnection();
}

@Override
public PacketFlow getReceiving() {
return oldManager.getReceiving();
}

@Override
public PacketFlow getSending() {
return oldManager.getSending();
}

@Override
public void setEncryptionKey(Cipher cipher, Cipher cipher1) {
oldManager.setEncryptionKey(cipher, cipher1);
}

@Override
public boolean isEncrypted() {
return oldManager.isEncrypted();
}

@Override
public boolean isConnected() {
return oldManager.isConnected();
Expand Down Expand Up @@ -1021,6 +1061,11 @@ public float getAverageReceivedPackets() {
return oldManager.getAverageReceivedPackets();
}

@Override
public float getAverageSentPackets() {
return oldManager.getAverageSentPackets();
}

@Override
public SocketAddress getRawAddress() {
return oldManager.getRawAddress();
Expand Down Expand Up @@ -1067,4 +1112,29 @@ private static void setNetworkManager(ServerGamePacketListenerImpl playerConnect
Debug.echoError(ex);
}
}

@Override
public boolean acceptInboundMessage(Object msg) throws Exception {
return oldManager.acceptInboundMessage(msg);
}

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
oldManager.channelRead(ctx, msg);
}

@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
oldManager.channelReadComplete(ctx);
}

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
oldManager.userEventTriggered(ctx, evt);
}

@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
oldManager.channelWritabilityChanged(ctx);
}
}

0 comments on commit 7180246

Please sign in to comment.