Skip to content

Commit

Permalink
some fixes and changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofaa2 committed Jan 6, 2024
1 parent 2517a5d commit 1cb1e46
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 215 deletions.
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/encodings.xml

This file was deleted.

27 changes: 0 additions & 27 deletions .idea/gradle.xml

This file was deleted.

28 changes: 0 additions & 28 deletions .idea/misc.xml

This file was deleted.

124 changes: 0 additions & 124 deletions .idea/uiDesigner.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/me/tofaa/entitylib/meta/EntityMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Component getCustomName() {
}

public void setCustomName(Component value) {
this.metadata.setIndex(offset(OFFSET, 2), EntityDataTypes.COMPONENT, GsonComponentSerializer.gson().serialize(value));
this.metadata.setIndex(offset(OFFSET, 2), EntityDataTypes.ADV_COMPONENT, value);
}

public boolean isCustomNameVisible() {
Expand Down
31 changes: 17 additions & 14 deletions test-plugin/src/main/java/me/tofaa/entitylib/TestEntityCommand.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package me.tofaa.entitylib;

import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import com.github.retrooper.packetevents.protocol.world.Location;
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
import me.tofaa.entitylib.entity.WrapperEntity;
import me.tofaa.entitylib.entity.WrapperEntityEquipment;
import me.tofaa.entitylib.entity.WrapperLivingEntity;
import me.tofaa.entitylib.meta.EntityMeta;
import me.tofaa.entitylib.meta.other.ArmorStandMeta;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.UUID;

public class TestEntityCommand implements CommandExecutor {
Expand All @@ -36,22 +32,29 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
entity.addViewer(player.getUniqueId());
entity.spawn(SpigotConversionUtil.fromBukkitLocation(player.getLocation()));
}
ItemStack held = player.getInventory().getItemInMainHand();
if (!held.getType().isAir()) {
entity.getEquipment().setBoots(SpigotConversionUtil.fromBukkitItemStack(held));
}
equipItems(player);
EntityMeta meta = entity.getMeta();
meta.setOnFire(!meta.isOnFire());
meta.setHasGlowingEffect(!meta.hasGlowingEffect());

meta.setCustomNameVisible(!meta.isCustomNameVisible());
meta.setCustomName(Component.text("test"));

player.sendMessage("on fire: " + meta.isOnFire());
player.sendMessage("glowing: " + meta.hasGlowingEffect());

entity.refresh();
return false;
}

private void equipItems(Player player) {
ItemStack held = player.getInventory().getItemInMainHand();
ItemStack helmet = player.getInventory().getHelmet();
ItemStack chestplate = player.getInventory().getChestplate();
ItemStack leggings = player.getInventory().getLeggings();
ItemStack boots = player.getInventory().getBoots();
WrapperEntityEquipment equipment = entity.getEquipment();

if (helmet != null && !helmet.getType().isAir()) equipment.setHelmet(SpigotConversionUtil.fromBukkitItemStack(helmet));
if (chestplate != null && !chestplate.getType().isAir()) equipment.setChestplate(SpigotConversionUtil.fromBukkitItemStack(chestplate));
if (leggings != null && !leggings.getType().isAir()) equipment.setLeggings(SpigotConversionUtil.fromBukkitItemStack(leggings));
if (boots != null && !boots.getType().isAir()) equipment.setBoots(SpigotConversionUtil.fromBukkitItemStack(boots));
if (!held.getType().isAir()) equipment.setMainHand(SpigotConversionUtil.fromBukkitItemStack(held));
}

}

0 comments on commit 1cb1e46

Please sign in to comment.