mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-30 20:39:13 +00:00
Continued work with moving NMS to a module
This commit is contained in:
@@ -33,21 +33,21 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
return;
|
||||
}
|
||||
|
||||
if (loc.getWorld() != user.getBackpackEntity().getBukkitLivingEntity().getWorld()) {
|
||||
user.getBackpackEntity().getBukkitLivingEntity().teleport(loc);
|
||||
if (loc.getWorld() != user.getBackpackEntity().getWorld()) {
|
||||
user.getBackpackEntity().teleport(loc);
|
||||
}
|
||||
|
||||
user.getBackpackEntity().moveTo(loc.getX(), loc.getY(), loc.getZ());
|
||||
user.getBackpackEntity().teleport(loc);
|
||||
|
||||
if (player.getPassengers().isEmpty()) {
|
||||
//HMCCosmeticsPlugin.getInstance().getLogger().info("No passengers");
|
||||
user.getBackpackEntity().getBukkitLivingEntity().teleport(loc);
|
||||
player.addPassenger(user.getBackpackEntity().getBukkitEntity());
|
||||
user.getBackpackEntity().teleport(loc);
|
||||
player.addPassenger(user.getBackpackEntity());
|
||||
} else {
|
||||
//HMCCosmeticsPlugin.getInstance().getLogger().info("Passengers: " + player.getPassengers());
|
||||
}
|
||||
|
||||
user.getBackpackEntity().getBukkitLivingEntity().setRotation(loc.getYaw(), loc.getPitch());
|
||||
user.getBackpackEntity().setRotation(loc.getYaw(), loc.getPitch());
|
||||
user.showBackpack();
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.entities;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import com.ticxo.modelengine.api.ModelEngineAPI;
|
||||
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||
import com.ticxo.modelengine.api.model.ModeledEntity;
|
||||
@@ -21,7 +22,7 @@ public class BalloonEntity {
|
||||
|
||||
public BalloonEntity(Location location) {
|
||||
this.uniqueID = UUID.randomUUID();
|
||||
this.balloonID = Entity.nextEntityId();
|
||||
this.balloonID = NMSHandlers.getHandler().getNextEntityId();
|
||||
this.modelEntity = new MEGEntity(location.add(Settings.getBalloonOffset()));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.entities;
|
||||
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
|
||||
public class InvisibleArmorstand extends ArmorStand {
|
||||
|
||||
public InvisibleArmorstand(Level world, double x, double y, double z) {
|
||||
super(world, x, y, z);
|
||||
}
|
||||
|
||||
public InvisibleArmorstand(Location loc) {
|
||||
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
|
||||
this.setPos(loc.getX(), loc.getY(), loc.getZ());
|
||||
setInvisible(true);
|
||||
setInvulnerable(true);
|
||||
setMarker(true);
|
||||
getBukkitLivingEntity().setCollidable(false);
|
||||
persist = false;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.hibiscusmc.hmccosmetics.listener;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.database.Database;
|
||||
import com.hibiscusmc.hmccosmetics.entities.InvisibleArmorstand;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
@@ -25,8 +25,8 @@ public class PlayerConnectionListener implements Listener {
|
||||
if (user == null) { // Remove any passengers if a user failed to initialize. Bugs can cause this to happen
|
||||
if (!event.getPlayer().getPassengers().isEmpty()) {
|
||||
for (Entity entity : event.getPlayer().getPassengers()) {
|
||||
if (entity instanceof InvisibleArmorstand) {
|
||||
((InvisibleArmorstand) entity).setHealth(0);
|
||||
if (entity.getType() == EntityType.ARMOR_STAND) {
|
||||
entity.remove();
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class PlayerGameListener implements Listener {
|
||||
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||
user.hideBackpack();
|
||||
|
||||
user.getBackpackEntity().getBukkitLivingEntity().teleport(event.getTo());
|
||||
user.getBackpackEntity().teleport(event.getTo());
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
user.showBackpack();
|
||||
|
||||
@@ -1,9 +1,24 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.entities.BalloonEntity;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public interface NMSHandler {
|
||||
|
||||
int getNextEntityId();
|
||||
|
||||
Entity getEntity(int entityId);
|
||||
|
||||
Entity getInvisibleArmorstand(Location loc);
|
||||
|
||||
Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType);
|
||||
|
||||
BalloonEntity spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType);
|
||||
|
||||
default boolean getSupported () {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.entities.BalloonEntity;
|
||||
import com.hibiscusmc.hmccosmetics.entities.InvisibleArmorstand;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandler;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
@@ -18,8 +19,7 @@ import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@@ -35,7 +35,7 @@ public class CosmeticUser {
|
||||
private UUID uniqueId;
|
||||
private HashMap<CosmeticSlot, Cosmetic> playerCosmetics = new HashMap<>();
|
||||
private Wardrobe wardrobe;
|
||||
private InvisibleArmorstand invisibleArmorstand;
|
||||
private ArmorStand invisibleArmorstand;
|
||||
private BalloonEntity balloonEntity;
|
||||
|
||||
// Cosmetic Settings/Toggles
|
||||
@@ -60,10 +60,10 @@ public class CosmeticUser {
|
||||
}
|
||||
|
||||
public int getArmorstandId() {
|
||||
return invisibleArmorstand.getId();
|
||||
return invisibleArmorstand.getEntityId();
|
||||
}
|
||||
|
||||
public InvisibleArmorstand getBackpackEntity() {
|
||||
public Entity getBackpackEntity() {
|
||||
return this.invisibleArmorstand;
|
||||
}
|
||||
public BalloonEntity getBalloonEntity() {
|
||||
@@ -186,38 +186,19 @@ public class CosmeticUser {
|
||||
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation());
|
||||
|
||||
if (this.invisibleArmorstand != null) return;
|
||||
this.invisibleArmorstand = new InvisibleArmorstand(player.getLocation());
|
||||
|
||||
ItemStack item = getUserCosmeticItem(cosmeticBackpackType);
|
||||
this.invisibleArmorstand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(this, cosmeticBackpackType);
|
||||
|
||||
invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item));
|
||||
((CraftWorld) player.getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
|
||||
//PacketManager.armorStandMetaPacket(invisibleArmorstand.getBukkitEntity(), sentTo);
|
||||
//PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo);
|
||||
|
||||
player.addPassenger(invisibleArmorstand.getBukkitEntity());
|
||||
player.addPassenger(invisibleArmorstand);
|
||||
|
||||
}
|
||||
|
||||
public void spawnBalloon(CosmeticBalloonType cosmeticBalloonType) {
|
||||
Player player = Bukkit.getPlayer(getUniqueId());
|
||||
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation());
|
||||
Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset());
|
||||
|
||||
if (this.balloonEntity != null) return;
|
||||
BalloonEntity balloonEntity1 = new BalloonEntity(player.getLocation());
|
||||
|
||||
((CraftWorld) player.getWorld()).getHandle().addFreshEntity(balloonEntity1.getModelEntity(), CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
|
||||
balloonEntity1.spawnModel(cosmeticBalloonType.getModelName());
|
||||
balloonEntity1.addPlayerToModel(player, cosmeticBalloonType.getModelName());
|
||||
|
||||
PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getPufferfishBalloonId(), EntityType.PUFFERFISH, balloonEntity1.getPufferfishBalloonUniqueId(), sentTo);
|
||||
PacketManager.sendInvisibilityPacket(balloonEntity1.getPufferfishBalloonId(), sentTo);
|
||||
PacketManager.sendLeashPacket(balloonEntity1.getPufferfishBalloonId(), player.getEntityId(), sentTo);
|
||||
|
||||
this.balloonEntity = balloonEntity1;
|
||||
this.balloonEntity = NMSHandlers.getHandler().spawnBalloon(this, cosmeticBalloonType);
|
||||
}
|
||||
|
||||
public void despawnBalloon() {
|
||||
@@ -233,8 +214,9 @@ public class CosmeticUser {
|
||||
public void despawnBackpack() {
|
||||
Player player = Bukkit.getPlayer(getUniqueId());
|
||||
if (invisibleArmorstand == null) return;
|
||||
invisibleArmorstand.getBukkitLivingEntity().setHealth(0);
|
||||
invisibleArmorstand.remove(net.minecraft.world.entity.Entity.RemovalReason.DISCARDED);
|
||||
invisibleArmorstand.setHealth(0);
|
||||
invisibleArmorstand.remove();
|
||||
//invisibleArmorstand.remove(net.minecraft.world.entity.Entity.RemovalReason.DISCARDED);
|
||||
this.invisibleArmorstand = null;
|
||||
}
|
||||
|
||||
@@ -274,8 +256,8 @@ public class CosmeticUser {
|
||||
if (hideBackpack == true) return;
|
||||
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||
//CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK);
|
||||
getPlayer().removePassenger(invisibleArmorstand.getBukkitEntity());
|
||||
invisibleArmorstand.getBukkitLivingEntity().getEquipment().clear();
|
||||
getPlayer().removePassenger(invisibleArmorstand);
|
||||
invisibleArmorstand.getEquipment().clear();
|
||||
hideBackpack = true;
|
||||
}
|
||||
}
|
||||
@@ -284,9 +266,9 @@ public class CosmeticUser {
|
||||
if (hideBackpack == false) return;
|
||||
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK);
|
||||
getPlayer().addPassenger(invisibleArmorstand.getBukkitEntity());
|
||||
getPlayer().addPassenger(invisibleArmorstand);
|
||||
ItemStack item = getUserCosmeticItem(cosmeticBackpackType);
|
||||
invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item));
|
||||
invisibleArmorstand.getEquipment().setHelmet(item);
|
||||
hideBackpack = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
@@ -31,8 +32,8 @@ public class Wardrobe {
|
||||
private boolean active;
|
||||
|
||||
public Wardrobe(CosmeticUser user) {
|
||||
NPC_ID = Entity.nextEntityId();
|
||||
ARMORSTAND_ID = Entity.nextEntityId();
|
||||
NPC_ID = NMSHandlers.getHandler().getNextEntityId();
|
||||
ARMORSTAND_ID = NMSHandlers.getHandler().getNextEntityId();
|
||||
WARDROBE_UUID = UUID.randomUUID();
|
||||
VIEWER = user;
|
||||
}
|
||||
@@ -78,7 +79,7 @@ public class Wardrobe {
|
||||
// Misc
|
||||
|
||||
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||
PacketManager.ridingMountPacket(NPC_ID, VIEWER.getBackpackEntity().getId(), viewer);
|
||||
PacketManager.ridingMountPacket(NPC_ID, VIEWER.getBackpackEntity().getEntityId(), viewer);
|
||||
}
|
||||
|
||||
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||
@@ -120,7 +121,7 @@ public class Wardrobe {
|
||||
VIEWER.showPlayer();
|
||||
|
||||
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||
PacketManager.ridingMountPacket(player.getEntityId(), VIEWER.getBackpackEntity().getId(), viewer);
|
||||
PacketManager.ridingMountPacket(player.getEntityId(), VIEWER.getBackpackEntity().getEntityId(), viewer);
|
||||
}
|
||||
|
||||
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||
@@ -168,8 +169,8 @@ public class Wardrobe {
|
||||
|
||||
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||
PacketManager.sendTeleportPacket(VIEWER.getArmorstandId(), location, false, viewer);
|
||||
PacketManager.ridingMountPacket(NPC_ID, VIEWER.getBackpackEntity().getId(), viewer);
|
||||
VIEWER.getBackpackEntity().getBukkitEntity().setRotation(nextyaw, 0);
|
||||
PacketManager.ridingMountPacket(NPC_ID, VIEWER.getBackpackEntity().getEntityId(), viewer);
|
||||
VIEWER.getBackpackEntity().setRotation(nextyaw, 0);
|
||||
}
|
||||
|
||||
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package com.hibiscusmc.hmccosmetics.util;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import org.bukkit.Bukkit;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ServerUtils {
|
||||
|
||||
@@ -22,19 +19,7 @@ public class ServerUtils {
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static org.bukkit.entity.Entity getEntity(int entityId) {
|
||||
net.minecraft.world.entity.Entity entity = getNMSEntity(entityId);
|
||||
if (entity == null) return null;
|
||||
return entity.getBukkitEntity();
|
||||
}
|
||||
@Nullable
|
||||
public static net.minecraft.world.entity.Entity getNMSEntity(int entityId) {
|
||||
for (ServerLevel world : ((CraftServer) Bukkit.getServer()).getHandle().getServer().getAllLevels()) {
|
||||
net.minecraft.world.entity.Entity entity = world.getEntity(entityId);
|
||||
if (entity == null) return null;
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
return NMSHandlers.getHandler().getEntity(entityId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user