Skip to content

Commit

Permalink
PlayerTag mech send_server_brand
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 9, 2021
1 parent f0529cf commit c28fdfc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
Expand Up @@ -112,4 +112,8 @@ default void showDebugTestMarker(Player player, Location location, ColorTag colo
default void clearDebugTestMarker(Player player) {
throw new UnsupportedOperationException();
}

default void sendBrand(Player player, String brand) {
throw new UnsupportedOperationException();
}
}
Expand Up @@ -3665,6 +3665,21 @@ else if (bal > goal) {
Depends.bungeeSendPlayer(getPlayerEntity(), mechanism.getValue().asString());
}

// <--[mechanism]
// @object PlayerTag
// @name send_server_brand
// @input ElementTag
// @description
// Sends the player a fake server brand, that will be displayed in the F3 Debug screen.
// -->
if (mechanism.matches("send_server_brand") && mechanism.hasValue()) {
if (!isOnline()) {
Debug.echoError("Cannot use send_server_brand on offline player.");
return;
}
NMSHandler.getPacketHelper().sendBrand(getPlayerEntity(), mechanism.getValue().asString());
}

CoreUtilities.autoPropertyMechanism(this, mechanism);

// Pass along to EntityTag mechanism handler if not already handled.
Expand Down
Expand Up @@ -2047,40 +2047,22 @@ else if (attribute.startsWith("source")) {
event.setReplacedObject(new ElementTag(Bukkit.getServer().getViewDistance()).getObjectAttribute(attribute.fulfill(1)));
return;
}

// <--[tag]
// @attribute <server.entity_is_spawned[<entity>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether an entity is spawned and valid.
// -->
else if (attribute.startsWith("entity_is_spawned")
&& attribute.hasContext(1)) {
Deprecations.isValidTag.warn(attribute.context);
EntityTag ent = EntityTag.valueOf(attribute.getContext(1), new BukkitTagContext(null, null, null, false, null));
event.setReplacedObject(new ElementTag((ent != null && ent.isUnique() && ent.isSpawnedOrValidForTag()) ? "true" : "false")
.getObjectAttribute(attribute.fulfill(1)));
}

// <--[tag]
// @attribute <server.player_is_valid[<player_name>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether a player exists under the specified name.
// -->
else if (attribute.startsWith("player_is_valid")
&& attribute.hasContext(1)) {
Deprecations.isValidTag.warn(attribute.context);
event.setReplacedObject(new ElementTag(PlayerTag.playerNameIsValid(attribute.getContext(1)))
.getObjectAttribute(attribute.fulfill(1)));
}

// <--[tag]
// @attribute <server.npc_is_valid[<npc>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether an NPC exists and is usable.
// -->
else if (attribute.startsWith("npc_is_valid")
&& attribute.hasContext(1)) {
Deprecations.isValidTag.warn(attribute.context);
NPCTag npc = NPCTag.valueOf(attribute.getContext(1), new BukkitTagContext(null, null, null, false, null));
event.setReplacedObject(new ElementTag((npc != null && npc.isValid()))
.getObjectAttribute(attribute.fulfill(1)));
Expand Down
Expand Up @@ -481,6 +481,15 @@ public void clearDebugTestMarker(Player player) {
send(player, packet);
}

@Override
public void sendBrand(Player player, String brand) {
ResourceLocation packetKey = new ResourceLocation("minecraft", "brand");
FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
buf.writeUtf(brand);
ClientboundCustomPayloadPacket packet = new ClientboundCustomPayloadPacket(packetKey, buf);
send(player, packet);
}

public static void send(Player player, Packet packet) {
((CraftPlayer) player).getHandle().connection.send(packet);
}
Expand Down

0 comments on commit c28fdfc

Please sign in to comment.