mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-30 04:19:28 +00:00
Continued work; moved more NMS to modules
This commit is contained in:
@@ -102,13 +102,14 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
||||
// Translation setup
|
||||
Translation.setup();
|
||||
|
||||
// ItemHooks
|
||||
ItemHooks.setup();
|
||||
|
||||
// Cosmetics setup
|
||||
Cosmetics.setup();
|
||||
|
||||
// Menus setup
|
||||
Menus.setup();
|
||||
|
||||
// ItemHooks
|
||||
ItemHooks.setup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("apply")) {
|
||||
sender.sendMessage("Applying - Begin");
|
||||
Player player = null;
|
||||
Cosmetic cosmetic;
|
||||
|
||||
@@ -51,6 +52,7 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
|
||||
user.addPlayerCosmetic(cosmetic);
|
||||
user.updateCosmetic(cosmetic.getSlot());
|
||||
sender.sendMessage("Applying - Finish with " + cosmetic.getId());
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("unapply")) {
|
||||
|
||||
@@ -36,7 +36,7 @@ public class CosmeticArmorType extends Cosmetic {
|
||||
}
|
||||
|
||||
public ItemStack getCosmeticItem() {
|
||||
return this.itemStack;
|
||||
return this.itemStack.clone();
|
||||
}
|
||||
|
||||
public EquipmentSlot getEquipSlot() {
|
||||
|
||||
@@ -15,10 +15,13 @@ import org.spongepowered.configurate.serialize.SerializationException;
|
||||
public class CosmeticBackpackType extends Cosmetic {
|
||||
|
||||
private ItemStack backpackItem;
|
||||
ConfigurationNode config;
|
||||
|
||||
public CosmeticBackpackType(String id, ConfigurationNode config) {
|
||||
super(id, config);
|
||||
|
||||
this.config = config;
|
||||
|
||||
this.backpackItem = generateItemStack(config.node("item"));
|
||||
}
|
||||
|
||||
@@ -52,7 +55,11 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
}
|
||||
|
||||
public ItemStack getBackpackItem() {
|
||||
return backpackItem;
|
||||
if (this.backpackItem == null ) {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Backpack item was null for " + getId());
|
||||
this.backpackItem = generateItemStack(config.node("item"));
|
||||
}
|
||||
return this.backpackItem.clone();
|
||||
}
|
||||
|
||||
private ItemStack generateItemStack(ConfigurationNode config) {
|
||||
|
||||
@@ -32,10 +32,10 @@ public class CosmeticBalloonType extends Cosmetic {
|
||||
final Location actual = player.getLocation().clone().add(Settings.getBalloonOffset());
|
||||
|
||||
if (player.getLocation().getWorld() != user.getBalloonEntity().getLocation().getWorld()) {
|
||||
user.getBalloonEntity().getModelEntity().getBukkitLivingEntity().teleport(actual);
|
||||
user.getBalloonEntity().getModelEntity().teleport(actual);
|
||||
}
|
||||
|
||||
user.getBalloonEntity().getModelEntity().moveTo(actual.getX(), actual.getY(), actual.getZ());
|
||||
user.getBalloonEntity().getModelEntity().teleport(actual);
|
||||
|
||||
List<Player> viewer = PlayerUtils.getNearbyPlayers(player);
|
||||
viewer.add(player);
|
||||
|
||||
@@ -2,11 +2,13 @@ package com.hibiscusmc.hmccosmetics.entities;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandler;
|
||||
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;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@@ -17,12 +19,12 @@ public class BalloonEntity {
|
||||
|
||||
private final int balloonID;
|
||||
private final UUID uniqueID;
|
||||
private final MEGEntity modelEntity;
|
||||
private final Entity modelEntity;
|
||||
|
||||
public BalloonEntity(Location location) {
|
||||
this.uniqueID = UUID.randomUUID();
|
||||
this.balloonID = NMSHandlers.getHandler().getNextEntityId();
|
||||
this.modelEntity = new MEGEntity(location.add(Settings.getBalloonOffset()));
|
||||
this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset()));
|
||||
}
|
||||
|
||||
public void spawnModel(final String id) {
|
||||
@@ -31,13 +33,13 @@ public class BalloonEntity {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().warning("Invalid Model Engine Blueprint " + id);
|
||||
return;
|
||||
}
|
||||
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(modelEntity.getBukkitEntity());
|
||||
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(modelEntity);
|
||||
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(id));
|
||||
modeledEntity.addModel(model, false);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
final ModeledEntity entity = ModelEngineAPI.api.getModeledEntity(modelEntity.getUUID());
|
||||
final ModeledEntity entity = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
|
||||
|
||||
if (entity == null) return;
|
||||
|
||||
@@ -50,7 +52,7 @@ public class BalloonEntity {
|
||||
}
|
||||
|
||||
public void addPlayerToModel(final Player player, final String id) {
|
||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUUID());
|
||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
|
||||
if (model == null) {
|
||||
spawnModel(id);
|
||||
return;
|
||||
@@ -59,14 +61,14 @@ public class BalloonEntity {
|
||||
model.showToPlayer(player);
|
||||
}
|
||||
public void removePlayerFromModel(final Player player) {
|
||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUUID());
|
||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
|
||||
|
||||
if (model == null) return;
|
||||
|
||||
model.hideFromPlayer(player);
|
||||
}
|
||||
|
||||
public MEGEntity getModelEntity() {
|
||||
public Entity getModelEntity() {
|
||||
return this.modelEntity;
|
||||
}
|
||||
|
||||
@@ -79,27 +81,23 @@ public class BalloonEntity {
|
||||
}
|
||||
|
||||
public UUID getModelUnqiueId() {
|
||||
return modelEntity.getUUID();
|
||||
return modelEntity.getUniqueId();
|
||||
}
|
||||
|
||||
public int getModelId() {
|
||||
return modelEntity.getId();
|
||||
return modelEntity.getEntityId();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return this.modelEntity.getBukkitEntity().getLocation();
|
||||
}
|
||||
|
||||
public boolean isAlive() {
|
||||
return this.modelEntity.isAlive();
|
||||
return this.modelEntity.getLocation();
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
//this.megEntity.teleportTo(location.getX(), location.getY(), location.getZ());
|
||||
this.modelEntity.getBukkitEntity().teleport(location);
|
||||
this.modelEntity.teleport(location);
|
||||
}
|
||||
|
||||
public void setVelocity(Vector vector) {
|
||||
this.modelEntity.getBukkitEntity().setVelocity(vector);
|
||||
this.modelEntity.setVelocity(vector);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.entities;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.ambient.Bat;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class MEGEntity extends Bat {
|
||||
|
||||
public MEGEntity(Location loc) {
|
||||
super(EntityType.BAT, ((CraftWorld) loc.getWorld()).getHandle());
|
||||
this.setPos(loc.getX(), loc.getY(), loc.getZ());
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Spawned MEGEntity at " + loc);
|
||||
getBukkitLivingEntity().setInvisible(true);
|
||||
getBukkitLivingEntity().setInvulnerable(true); // NOTE - CREATIVE PLAYERS CAN DESTROY IT STILL
|
||||
getBukkitLivingEntity().setAI(false);
|
||||
getBukkitLivingEntity().setGravity(false);
|
||||
getBukkitLivingEntity().setSilent(true);
|
||||
getBukkitLivingEntity().setCollidable(false);
|
||||
persist = false;
|
||||
|
||||
getBukkitEntity().getPersistentDataContainer().set(new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticMob"), PersistentDataType.SHORT, Short.valueOf("1"));
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,10 @@ 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 net.minecraft.network.protocol.Packet;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface NMSHandler {
|
||||
|
||||
@@ -15,10 +17,14 @@ public interface NMSHandler {
|
||||
|
||||
Entity getInvisibleArmorstand(Location loc);
|
||||
|
||||
Entity getMEGEntity(Location loc);
|
||||
|
||||
Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType);
|
||||
|
||||
BalloonEntity spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType);
|
||||
|
||||
void sendPacket(Player player, Packet packet);
|
||||
|
||||
default boolean getSupported () {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -72,9 +72,11 @@ public class CosmeticUser {
|
||||
public void addPlayerCosmetic(Cosmetic cosmetic, Color color) {
|
||||
playerCosmetics.put(cosmetic.getSlot(), cosmetic);
|
||||
if (color != null) colors.put(cosmetic.getSlot(), color);
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("addPlayerCosmetic " + cosmetic.getId());
|
||||
if (cosmetic.getSlot() == CosmeticSlot.BACKPACK) {
|
||||
CosmeticBackpackType backpackType = (CosmeticBackpackType) cosmetic;
|
||||
spawnBackpack(backpackType);
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("addPlayerCosmetic spawnBackpack " + cosmetic.getId());
|
||||
}
|
||||
if (cosmetic.getSlot() == CosmeticSlot.BALLOON) {
|
||||
CosmeticBalloonType balloonType = (CosmeticBalloonType) cosmetic;
|
||||
@@ -129,19 +131,26 @@ public class CosmeticUser {
|
||||
if (cosmetic instanceof CosmeticArmorType) {
|
||||
CosmeticArmorType cosmetic1 = (CosmeticArmorType) cosmetic;
|
||||
item = cosmetic1.getCosmeticItem();
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("GetUserCosemticUser Armor");
|
||||
}
|
||||
if (cosmetic instanceof CosmeticBackpackType) {
|
||||
CosmeticBackpackType cosmetic1 = (CosmeticBackpackType) cosmetic;
|
||||
item = cosmetic1.getBackpackItem();
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("GetUserCosemticUser Backpack");
|
||||
}
|
||||
if (!item.hasItemMeta()) return null;
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
if (itemMeta instanceof LeatherArmorMeta) {
|
||||
if (colors.containsKey(cosmetic.getSlot())) {
|
||||
((LeatherArmorMeta) itemMeta).setColor(colors.get(cosmetic.getSlot()));
|
||||
if (item == null) {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("GetUserCosemticUser Item is null");
|
||||
return null;
|
||||
}
|
||||
if (item.hasItemMeta()) {
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
if (itemMeta instanceof LeatherArmorMeta) {
|
||||
if (colors.containsKey(cosmetic.getSlot())) {
|
||||
((LeatherArmorMeta) itemMeta).setColor(colors.get(cosmetic.getSlot()));
|
||||
}
|
||||
}
|
||||
item.setItemMeta(itemMeta);
|
||||
}
|
||||
item.setItemMeta(itemMeta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -177,6 +186,7 @@ public class CosmeticUser {
|
||||
}
|
||||
|
||||
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("spawnBackpack Bukkit - Start");
|
||||
Player player = Bukkit.getPlayer(getUniqueId());
|
||||
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation());
|
||||
|
||||
@@ -186,6 +196,8 @@ public class CosmeticUser {
|
||||
|
||||
player.addPassenger(invisibleArmorstand);
|
||||
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("spawnBackpack Bukkit - Finish");
|
||||
|
||||
}
|
||||
|
||||
public void spawnBalloon(CosmeticBalloonType cosmeticBalloonType) {
|
||||
|
||||
@@ -174,7 +174,7 @@ public class Wardrobe {
|
||||
|
||||
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||
PacketManager.sendTeleportPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), WardrobeSettings.getWardrobeLocation(), false, viewer);
|
||||
VIEWER.getBalloonEntity().getModelEntity().getBukkitLivingEntity().teleport(WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()));
|
||||
VIEWER.getBalloonEntity().getModelEntity().teleport(WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()));
|
||||
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), NPC_ID, viewer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,14 @@ package com.hibiscusmc.hmccosmetics.util.packets;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerPlayerConnection;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BasePacket {
|
||||
|
||||
public static void sendPacket(Player player, Packet<?> packet) {
|
||||
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
||||
ServerPlayerConnection connection = serverPlayer.connection;
|
||||
connection.send(packet);
|
||||
NMSHandlers.getHandler().sendPacket(player, packet);
|
||||
}
|
||||
|
||||
public static void sendPacket(Player player, PacketContainer packet) {
|
||||
|
||||
Reference in New Issue
Block a user