Skip to content

Commit

Permalink
Remove object utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsNature committed Sep 16, 2024
1 parent 75ea8f6 commit 7b536dc
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 395 deletions.
11 changes: 2 additions & 9 deletions docs/developers/modules/border.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,7 @@ public void displayBorderExample(Player viewer) {
.setCancelExit(true)
.setCanShrinkOrExpand(false)
.setColor(ProtobufUtil.createColorProto(Color.RED))
.setBounds(ProtobufUtil.createCuboid2DProto(Cuboid2D.builder()
.minX(-50)
.minZ(-50)
.maxX(50)
.maxZ(50)
.build()))
.setBounds(ProtobufUtil.createCuboid2DProto(-50, -50, 50, 50))
.setDurationTicks(1000)
.build();

Expand Down Expand Up @@ -218,9 +213,7 @@ public void displayBorderExample(Player viewer) {
message.addProperty("cancel_exit", true);
message.addProperty("can_shrink_or_expand", false);
message.add("color", JsonUtil.createColorObject(Color.RED));
message.add("bounds", JsonUtil.createCuboid2DObject(
Cuboid2D.builder().minX(-50).minZ(-50).maxX(50).maxZ(50).build()
));
message.add("bounds", JsonUtil.createCuboid2DObject(-50, -50, 50, 50));
message.addProperty("duration_ticks", 1000);

JsonPacketUtil.sendPacket(viewer, message);
Expand Down
22 changes: 4 additions & 18 deletions docs/developers/modules/cooldown.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ public void displayCooldownItemExample(Player viewer) {
DisplayCooldownMessage message = DisplayCooldownMessage.newBuilder()
.setName("enderpearl-cooldown")
.setDuration(ProtobufUtil.createDurationProto(Duration.ofSeconds(15)))
.setIcon(ProtobufUtil.createIconProto(ItemStackIcon.builder()
.itemName("ENDER_PEARL")
.build()))
.setIcon(ProtobufUtil.createItemStackIconProto("ENDER_PEARL", 0, 0))
.build();

ProtobufPacketUtil.sendPacket(viewer, message);
Expand All @@ -137,10 +135,7 @@ public void displayCooldownResourceExample(Player viewer) {
DisplayCooldownMessage message = DisplayCooldownMessage.newBuilder()
.setName("lunar-cooldown")
.setDuration(ProtobufUtil.createDurationProto(Duration.ofSeconds(15)))
.setIcon(ProtobufUtil.createIconProto(SimpleResourceLocationIcon.builder()
.resourceLocation("lunar:logo/logo-200x182.svg")
.size(12)
.build()))
.setIcon(ProtobufUtil.createSimpleResourceLocationIconProto("lunar:logo/logo-200x182.svg", 12))
.build();

ProtobufPacketUtil.sendPacket(viewer, message);
Expand Down Expand Up @@ -180,11 +175,7 @@ public void displayCooldownItemExample(Player viewer) {
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.cooldown.v1.DisplayCooldownMessage");
message.addProperty("name", "enderpearl-cooldown");
message.addProperty("duration", JsonUtil.createDurationObject(Duration.ofSeconds(15)));
message.add("icon", JsonUtil.createIconObject(
ItemStackIcon.builder()
.itemName("ENDER_PEARL")
.build())
);
message.add("icon", JsonUtil.createItemStackIconObject("ENDER_PEARL", 0, 0));

JsonPacketUtil.sendPacket(viewer, message);
}
Expand All @@ -198,12 +189,7 @@ public void displayCooldownResourceExample(Player viewer) {
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.cooldown.v1.DisplayCooldownMessage");
message.addProperty("name", "lunar-cooldown");
message.addProperty("duration", JsonUtil.createDurationObject(Duration.ofSeconds(15)));
message.add("icon", JsonUtil.createIconObject(
SimpleResourceLocationIcon.builder()
.resourceLocation("lunar:logo/logo-200x182.svg")
.size(12)
.build())
);
message.add("icon", JsonUtil.createSimpleResourceLocationIconObject("lunar:logo/logo-200x182.svg", 12));

JsonPacketUtil.sendPacket(viewer, message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@
@Getter
public class ApolloExamplePlugin extends JavaPlugin {

// TODO:
// Available module options

@Getter
private static ApolloExamplePlugin plugin;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.lunarclient.apollo.example.modules.impl.BorderExample;
import com.lunarclient.apollo.example.utilities.JsonPacketUtil;
import com.lunarclient.apollo.example.utilities.JsonUtil;
import com.lunarclient.apollo.example.utilities.objects.cuboid.Cuboid2D;
import java.awt.Color;
import org.bukkit.entity.Player;

Expand All @@ -43,9 +42,7 @@ public void displayBorderExample(Player viewer) {
message.addProperty("cancel_exit", true);
message.addProperty("can_shrink_or_expand", false);
message.add("color", JsonUtil.createColorObject(Color.RED));
message.add("bounds", JsonUtil.createCuboid2DObject(
Cuboid2D.builder().minX(-50).minZ(-50).maxX(50).maxZ(50).build()
));
message.add("bounds", JsonUtil.createCuboid2DObject(-50, -50, 50, 50));
message.addProperty("duration_ticks", 1000);

JsonPacketUtil.sendPacket(viewer, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import com.lunarclient.apollo.example.modules.impl.CooldownExample;
import com.lunarclient.apollo.example.utilities.JsonPacketUtil;
import com.lunarclient.apollo.example.utilities.JsonUtil;
import com.lunarclient.apollo.example.utilities.objects.icon.ItemStackIcon;
import com.lunarclient.apollo.example.utilities.objects.icon.SimpleResourceLocationIcon;
import java.time.Duration;
import org.bukkit.entity.Player;

Expand All @@ -40,11 +38,7 @@ public void displayCooldownItemExample(Player viewer) {
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.cooldown.v1.DisplayCooldownMessage");
message.addProperty("name", "enderpearl-cooldown");
message.addProperty("duration", JsonUtil.createDurationObject(Duration.ofSeconds(15)));
message.add("icon", JsonUtil.createIconObject(
ItemStackIcon.builder()
.itemName("ENDER_PEARL")
.build())
);
message.add("icon", JsonUtil.createItemStackIconObject("ENDER_PEARL", 0, 0));

JsonPacketUtil.sendPacket(viewer, message);
}
Expand All @@ -55,12 +49,7 @@ public void displayCooldownResourceExample(Player viewer) {
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.cooldown.v1.DisplayCooldownMessage");
message.addProperty("name", "lunar-cooldown");
message.addProperty("duration", JsonUtil.createDurationObject(Duration.ofSeconds(15)));
message.add("icon", JsonUtil.createIconObject(
SimpleResourceLocationIcon.builder()
.resourceLocation("lunar:logo/logo-200x182.svg")
.size(12)
.build())
);
message.add("icon", JsonUtil.createSimpleResourceLocationIconObject("lunar:logo/logo-200x182.svg", 12));

JsonPacketUtil.sendPacket(viewer, message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.lunarclient.apollo.example.modules.impl.BorderExample;
import com.lunarclient.apollo.example.utilities.ProtobufPacketUtil;
import com.lunarclient.apollo.example.utilities.ProtobufUtil;
import com.lunarclient.apollo.example.utilities.objects.cuboid.Cuboid2D;
import java.awt.Color;
import org.bukkit.entity.Player;

Expand All @@ -44,12 +43,7 @@ public void displayBorderExample(Player viewer) {
.setCancelExit(true)
.setCanShrinkOrExpand(false)
.setColor(ProtobufUtil.createColorProto(Color.RED))
.setBounds(ProtobufUtil.createCuboid2DProto(Cuboid2D.builder()
.minX(-50)
.minZ(-50)
.maxX(50)
.maxZ(50)
.build()))
.setBounds(ProtobufUtil.createCuboid2DProto(-50, -50, 50, 50))
.setDurationTicks(1000)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import com.lunarclient.apollo.example.modules.impl.CooldownExample;
import com.lunarclient.apollo.example.utilities.ProtobufPacketUtil;
import com.lunarclient.apollo.example.utilities.ProtobufUtil;
import com.lunarclient.apollo.example.utilities.objects.icon.ItemStackIcon;
import com.lunarclient.apollo.example.utilities.objects.icon.SimpleResourceLocationIcon;
import java.time.Duration;
import org.bukkit.entity.Player;

Expand All @@ -41,9 +39,7 @@ public void displayCooldownItemExample(Player viewer) {
DisplayCooldownMessage message = DisplayCooldownMessage.newBuilder()
.setName("enderpearl-cooldown")
.setDuration(ProtobufUtil.createDurationProto(Duration.ofSeconds(15)))
.setIcon(ProtobufUtil.createIconProto(ItemStackIcon.builder()
.itemName("ENDER_PEARL")
.build()))
.setIcon(ProtobufUtil.createItemStackIconProto("ENDER_PEARL", 0, 0))
.build();

ProtobufPacketUtil.sendPacket(viewer, message);
Expand All @@ -54,10 +50,7 @@ public void displayCooldownResourceExample(Player viewer) {
DisplayCooldownMessage message = DisplayCooldownMessage.newBuilder()
.setName("lunar-cooldown")
.setDuration(ProtobufUtil.createDurationProto(Duration.ofSeconds(15)))
.setIcon(ProtobufUtil.createIconProto(SimpleResourceLocationIcon.builder()
.resourceLocation("lunar:logo/logo-200x182.svg")
.size(12)
.build()))
.setIcon(ProtobufUtil.createSimpleResourceLocationIconProto("lunar:logo/logo-200x182.svg", 12))
.build();

ProtobufPacketUtil.sendPacket(viewer, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@
package com.lunarclient.apollo.example.utilities;

import com.google.gson.JsonObject;
import com.lunarclient.apollo.example.utilities.objects.cuboid.Cuboid2D;
import com.lunarclient.apollo.example.utilities.objects.icon.AdvancedResourceLocationIcon;
import com.lunarclient.apollo.example.utilities.objects.icon.Icon;
import com.lunarclient.apollo.example.utilities.objects.icon.ItemStackIcon;
import com.lunarclient.apollo.example.utilities.objects.icon.SimpleResourceLocationIcon;
import java.awt.Color;
import java.time.Duration;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public final class JsonUtil {

Expand Down Expand Up @@ -100,51 +96,54 @@ public static JsonObject createEntityIdObject(@NotNull Entity entity) {
return entityIdObject;
}

public static JsonObject createCuboid2DObject(@NotNull Cuboid2D cuboid2D) {
public static JsonObject createCuboid2DObject(double minX, double minZ, double maxX, double maxZ) {
JsonObject cuboid2DObject = new JsonObject();
cuboid2DObject.addProperty("min_x", cuboid2D.getMinX());
cuboid2DObject.addProperty("min_z", cuboid2D.getMinZ());
cuboid2DObject.addProperty("max_x", cuboid2D.getMaxX());
cuboid2DObject.addProperty("max_z", cuboid2D.getMaxZ());
cuboid2DObject.addProperty("min_x", minX);
cuboid2DObject.addProperty("min_z", minZ);
cuboid2DObject.addProperty("max_x", maxX);
cuboid2DObject.addProperty("max_z", maxZ);
return cuboid2DObject;
}

public static JsonObject createIconObject(@NotNull Icon icon) {
public static JsonObject createItemStackIconObject(@Nullable String itemName, int itemId, int customModelData) {
JsonObject itemIconObject = new JsonObject();
if (itemName != null) {
itemIconObject.addProperty("item_name", itemName);
} else {
itemIconObject.addProperty("item_id", itemId);
}

itemIconObject.addProperty("custom_model_data", customModelData);

JsonObject iconObject = new JsonObject();
iconObject.add("item_stack", itemIconObject);
return iconObject;
}

if (icon instanceof ItemStackIcon) {
ItemStackIcon item = (ItemStackIcon) icon;
String itemName = item.getItemName();

JsonObject itemIconObject = new JsonObject();
if (itemName != null) {
itemIconObject.addProperty("item_name", itemName);
} else {
itemIconObject.addProperty("item_id", item.getItemId());
}

itemIconObject.addProperty("custom_model_data", item.getCustomModelData());
iconObject.add("item_stack", itemIconObject);
} else if (icon instanceof SimpleResourceLocationIcon) {
SimpleResourceLocationIcon simple = (SimpleResourceLocationIcon) icon;

JsonObject simpleIconObject = new JsonObject();
simpleIconObject.addProperty("resource_location", simple.getResourceLocation());
simpleIconObject.addProperty("size", simple.getSize());
iconObject.add("simple_resource_location", simpleIconObject);
} else if (icon instanceof AdvancedResourceLocationIcon) {
AdvancedResourceLocationIcon advanced = (AdvancedResourceLocationIcon) icon;

JsonObject advancedIcon = new JsonObject();
advancedIcon.addProperty("resource_location", advanced.getResourceLocation());
advancedIcon.addProperty("width", advanced.getWidth());
advancedIcon.addProperty("height", advanced.getHeight());
advancedIcon.addProperty("min_u", advanced.getMinU());
advancedIcon.addProperty("max_u", advanced.getMaxU());
advancedIcon.addProperty("min_v", advanced.getMinV());
advancedIcon.addProperty("max_v", advanced.getMaxV());
iconObject.add("advanced_resource_location", advancedIcon);
}
public static JsonObject createSimpleResourceLocationIconObject(String resourceLocation, int size) {
JsonObject simpleIconObject = new JsonObject();
simpleIconObject.addProperty("resource_location", resourceLocation);
simpleIconObject.addProperty("size", size);

JsonObject iconObject = new JsonObject();
iconObject.add("simple_resource_location", simpleIconObject);

return iconObject;
}

public static JsonObject createAdvancedResourceLocationIconObject(String resourceLocation, float width, float height,
float minU, float maxU, float minV, float maxV) {
JsonObject advancedIcon = new JsonObject();
advancedIcon.addProperty("resource_location", resourceLocation);
advancedIcon.addProperty("width", width);
advancedIcon.addProperty("height", height);
advancedIcon.addProperty("min_u", minU);
advancedIcon.addProperty("max_u", maxU);
advancedIcon.addProperty("min_v", minV);
advancedIcon.addProperty("max_v", maxV);

JsonObject iconObject = new JsonObject();
iconObject.add("advanced_resource_location", advancedIcon);

return iconObject;
}
Expand Down
Loading

1 comment on commit 7b536dc

@LunarClientBot
Copy link
Collaborator

@LunarClientBot LunarClientBot commented on 7b536dc Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📄 Documentation Deployment

Status:❌ Failed
Environment:preview
URL:Pending...

Please sign in to comment.