9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-20 15:39:16 +00:00

Compare commits

..

29 Commits

Author SHA1 Message Date
lucian929
66c5fd86c5 Update default configurations for 2.1.0 2023-01-27 17:47:40 -05:00
LoJoSho
80eb333b39 fixed offhand item not immidently apply 2023-01-27 10:02:46 -06:00
LoJoSho
8b2b771a9b Fixes offhand cosmetics not appearing if applied via menus 2023-01-26 18:15:20 -06:00
LoJoSho
7873b3fe04 removed certain debug messages 2023-01-26 18:01:46 -06:00
LoJoSho
9854e77bf5 Ballons item now dye correctly 2023-01-26 16:24:21 -06:00
LoJoSho
cad78636d0 Version bump (2.1.0) 2023-01-25 17:10:27 -06:00
LoJoSho
14d256feed Add 1.17 NMS Support 2023-01-25 17:08:09 -06:00
LoJoSho
53163feb60 Add ability for lock names and lore #45 2023-01-24 19:23:03 -06:00
LoJoSho
caf168d29d Invisibility now hides cosmetics 2023-01-24 18:31:21 -06:00
LoJoSho
2a7686e6b7 particle fix 2023-01-24 18:17:00 -06:00
LoJoSho
5309c37902 Add particle action 2023-01-22 19:04:42 -06:00
LoJoSho
ea1b87c128 dyable balloons if no parts selected 2023-01-21 18:12:57 -06:00
LoJoSho
9d92ed0dda Add dyable parts to balloons 2023-01-21 18:06:25 -06:00
LoJoSho
e24d5697e7 Fixed issue with windows packet not preserving held item 2023-01-21 10:41:40 -06:00
LoJoSho
8c59b27302 Add color for bossbar in config 2023-01-20 20:03:52 -06:00
LoJoSho
df3544726d Add 1.18.2 Support 2023-01-20 17:31:25 -06:00
LoJoSho
27af0a6085 Add Equip and Unequip actions 2023-01-20 17:10:17 -06:00
LoJoSho
1db96c38d9 Add hidden reason to internal code 2023-01-20 17:03:44 -06:00
LoJoSho
d9b92d5336 Add sound action #43 2023-01-20 16:24:11 -06:00
LoJoSho
0905071dd2 Balloon rework for items as balloons 2023-01-20 16:08:28 -06:00
LoJoSho
1804e4691b version bump (2.0.3) 2023-01-19 17:10:06 -06:00
LoJoSho
223f8bdb9c invalid menus now do not disable plugin on startup 2023-01-19 15:03:01 -06:00
LoJoSho
c757752038 invalid cosmetics now do not disable plugin on startup 2023-01-19 14:59:03 -06:00
LoJoSho
243644301a debug message now ignore only info and message null check 2023-01-19 14:58:19 -06:00
LoJoSho
652b20c148 move dependencies to all projects 2023-01-19 14:39:04 -06:00
LoJoSho
6c3ffbb71e fix ItemAdder hook being error after invalid item 2023-01-16 20:18:13 -06:00
LoJoSho
fb6e5abb8b Backpack don't produce sounds 2023-01-16 19:53:29 -06:00
LoJoSho
f546500f1e Wardrobe internal improvements 2023-01-16 19:51:32 -06:00
LoJoSho
044528188d Fix for external entities showing in wardrobe to others 2023-01-16 18:49:50 -06:00
44 changed files with 1327 additions and 166 deletions

View File

@@ -9,7 +9,7 @@ plugins {
} }
group = "com.hibiscusmc" group = "com.hibiscusmc"
version = "2.0.2" version = "2.1.0"
allprojects { allprojects {
apply(plugin = "java") apply(plugin = "java")
@@ -54,29 +54,33 @@ allprojects {
// UpdateChecker // UpdateChecker
maven("https://hub.jeff-media.com/nexus/repository/jeff-media-public/") maven("https://hub.jeff-media.com/nexus/repository/jeff-media-public/")
// ParticleHelper
maven("https://repo.bytecode.space/repository/maven-public/")
} }
dependencies { dependencies {
compileOnly("com.mojang:authlib:1.5.25")
compileOnly("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT")
compileOnly("org.jetbrains:annotations:23.0.0")
compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0-SNAPSHOT")
compileOnly("me.clip:placeholderapi:2.11.1")
compileOnly("com.ticxo.modelengine:api:R3.0.1")
compileOnly("com.github.oraxen:oraxen:-SNAPSHOT")
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5")
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
compileOnly("it.unimi.dsi:fastutil:8.5.11")
} }
} }
dependencies { dependencies {
implementation(project(path = ":common")) implementation(project(path = ":common"))
implementation(project(path = ":v1_17_R1", configuration = "reobf"))
implementation(project(path = ":v1_18_R2", configuration = "reobf"))
implementation(project(path = ":v1_19_R1", configuration = "reobf")) implementation(project(path = ":v1_19_R1", configuration = "reobf"))
implementation(project(path = ":v1_19_R2", configuration = "reobf")) implementation(project(path = ":v1_19_R2", configuration = "reobf"))
//implementation(files("v1_19_R1/build/libs/1_19_R1-unspecified.jar"))
compileOnly("com.mojang:authlib:1.5.25")
compileOnly("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT")
compileOnly("org.jetbrains:annotations:23.0.0")
compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0-SNAPSHOT")
compileOnly("me.clip:placeholderapi:2.11.1")
compileOnly("com.ticxo.modelengine:api:R3.0.1")
compileOnly("com.github.oraxen:oraxen:-SNAPSHOT")
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5")
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
compileOnly("it.unimi.dsi:fastutil:8.5.11")
//compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT") //compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT")
implementation("net.kyori:adventure-api:4.11.0") implementation("net.kyori:adventure-api:4.11.0")
@@ -86,6 +90,7 @@ dependencies {
implementation("org.spongepowered:configurate-yaml:4.1.2") implementation("org.spongepowered:configurate-yaml:4.1.2")
implementation("org.bstats:bstats-bukkit:3.0.0") implementation("org.bstats:bstats-bukkit:3.0.0")
implementation("com.jeff_media:SpigotUpdateChecker:3.0.0") implementation("com.jeff_media:SpigotUpdateChecker:3.0.0")
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
} }
tasks { tasks {
@@ -109,6 +114,8 @@ tasks {
} }
shadowJar { shadowJar {
dependsOn(":v1_17_R1:reobfJar")
dependsOn(":v1_18_R2:reobfJar")
dependsOn(":v1_19_R1:reobfJar") dependsOn(":v1_19_R1:reobfJar")
dependsOn(":v1_19_R2:reobfJar") dependsOn(":v1_19_R2:reobfJar")
mergeServiceFiles() mergeServiceFiles()
@@ -121,6 +128,7 @@ tasks {
relocate("com.zaxxer.hikaricp", "com.hisbiscusmc.hmccosmetics.hikaricp") relocate("com.zaxxer.hikaricp", "com.hisbiscusmc.hmccosmetics.hikaricp")
relocate("com.j256.ormlite", "com.hisbiscusmc.hmccosmetics.ormlite") relocate("com.j256.ormlite", "com.hisbiscusmc.hmccosmetics.ormlite")
relocate("com.jeff_media.updatechecker", "com.hisbiscusmc.hmccosmetics.updatechecker") relocate("com.jeff_media.updatechecker", "com.hisbiscusmc.hmccosmetics.updatechecker")
relocate("com.woen1212055.particlehelper", "com.hisbiscusmc.hmccosmetics.particlehelper")
archiveFileName.set("HMCCosmeticsRemapped-${project.version}.jar") archiveFileName.set("HMCCosmeticsRemapped-${project.version}.jar")
dependencies { dependencies {
@@ -145,7 +153,7 @@ tasks {
bukkit { bukkit {
load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD
main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin" main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin"
apiVersion = "1.19" apiVersion = "1.16"
authors = listOf("LoJoSho") authors = listOf("LoJoSho")
depend = listOf("ProtocolLib", "PlaceholderAPI") depend = listOf("ProtocolLib", "PlaceholderAPI")
softDepend = listOf("ModelEngine", "Oraxen", "ItemsAdder", "HMCColor", "WorldGuard", "MythicMobs") softDepend = listOf("ModelEngine", "Oraxen", "ItemsAdder", "HMCColor", "WorldGuard", "MythicMobs")

View File

@@ -24,6 +24,7 @@ dependencies {
implementation("org.spongepowered:configurate-yaml:4.1.2") implementation("org.spongepowered:configurate-yaml:4.1.2")
implementation("org.bstats:bstats-bukkit:3.0.0") implementation("org.bstats:bstats-bukkit:3.0.0")
implementation("com.jeff_media:SpigotUpdateChecker:3.0.0") implementation("com.jeff_media:SpigotUpdateChecker:3.0.0")
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
} }
java { java {

View File

@@ -8,10 +8,12 @@ import org.bukkit.event.HandlerList;
public class PlayerCosmeticHideEvent extends Event implements Cancellable { public class PlayerCosmeticHideEvent extends Event implements Cancellable {
private CosmeticUser user; private CosmeticUser user;
private CosmeticUser.HiddenReason reason;
private boolean isCancelled; private boolean isCancelled;
public PlayerCosmeticHideEvent(CosmeticUser user) { public PlayerCosmeticHideEvent(CosmeticUser user, CosmeticUser.HiddenReason reason) {
this.user = user; this.user = user;
this.reason = reason;
this.isCancelled = false; this.isCancelled = false;
} }
@@ -39,4 +41,7 @@ public class PlayerCosmeticHideEvent extends Event implements Cancellable {
public CosmeticUser getUser() { public CosmeticUser getUser() {
return user; return user;
} }
public CosmeticUser.HiddenReason getReason() {
return reason;
}
} }

View File

@@ -326,9 +326,8 @@ public class CosmeticCommand implements CommandExecutor {
} }
CosmeticUser user = CosmeticUsers.getUser(player); CosmeticUser user = CosmeticUsers.getUser(player);
MessagesUtil.sendMessage(sender, "hide-cosmetic"); MessagesUtil.sendMessage(sender, "hide-cosmetic");
user.hideCosmetics(); user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
return true; return true;
} }
case ("show") -> { case ("show") -> {

View File

@@ -2,11 +2,13 @@ package com.hibiscusmc.hmccosmetics.cosmetic;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.apache.commons.lang3.EnumUtils;
import org.spongepowered.configurate.CommentedConfigurationNode; import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.ConfigurateException; import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.ConfigurationNode;
@@ -14,6 +16,7 @@ import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import java.io.File; import java.io.File;
import java.util.Set; import java.util.Set;
import java.util.logging.Level;
public class Cosmetics { public class Cosmetics {
@@ -78,23 +81,27 @@ public class Cosmetics {
private static void setupCosmetics(CommentedConfigurationNode config) { private static void setupCosmetics(CommentedConfigurationNode config) {
for (ConfigurationNode cosmeticConfig : config.childrenMap().values()) { for (ConfigurationNode cosmeticConfig : config.childrenMap().values()) {
String id = cosmeticConfig.key().toString(); try {
MessagesUtil.sendDebugMessages("Attempting to add " + id); String id = cosmeticConfig.key().toString();
switch (CosmeticSlot.valueOf(cosmeticConfig.node("slot").getString())) { MessagesUtil.sendDebugMessages("Attempting to add " + id);
case BALLOON -> { ConfigurationNode slotNode = cosmeticConfig.node("slot");
new CosmeticBalloonType(id, cosmeticConfig); if (slotNode.virtual()) {
MessagesUtil.sendDebugMessages("Unable to create " + id + " because there is no slot defined!", Level.WARNING);
continue;
} }
case BACKPACK -> { if (!EnumUtils.isValidEnum(CosmeticSlot.class, slotNode.getString())) {
new CosmeticBackpackType(id, cosmeticConfig); MessagesUtil.sendDebugMessages("Unable to create " + id + " because " + slotNode.getString() + " is not a valid slot!", Level.WARNING);
continue;
} }
case MAINHAND -> { switch (CosmeticSlot.valueOf(cosmeticConfig.node("slot").getString())) {
new CosmeticMainhandType(id, cosmeticConfig); case BALLOON -> new CosmeticBalloonType(id, cosmeticConfig);
} case BACKPACK -> new CosmeticBackpackType(id, cosmeticConfig);
default -> { case MAINHAND -> new CosmeticMainhandType(id, cosmeticConfig);
new CosmeticArmorType(id, cosmeticConfig); default -> new CosmeticArmorType(id, cosmeticConfig);
} }
} catch (Exception e) {
if (Settings.isDebugEnabled()) e.printStackTrace();
} }
//new Cosmetic(id, cosmeticConfig);
} }
} }
} }

View File

@@ -23,6 +23,8 @@ public class CosmeticBackpackType extends Cosmetic {
Player player = Bukkit.getPlayer(user.getUniqueId()); Player player = Bukkit.getPlayer(user.getUniqueId());
Location loc = player.getLocation().clone(); Location loc = player.getLocation().clone();
if (user.isInWardrobe()) return;
if (loc.getWorld() != user.getBackpackEntity().getWorld()) { if (loc.getWorld() != user.getBackpackEntity().getWorld()) {
user.getBackpackEntity().teleport(loc); user.getBackpackEntity().teleport(loc);
} }

View File

@@ -5,22 +5,45 @@ import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.entities.BalloonEntity; import com.hibiscusmc.hmccosmetics.entities.BalloonEntity;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import org.apache.commons.lang3.EnumUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
import java.util.HashMap;
import java.util.List; import java.util.List;
public class CosmeticBalloonType extends Cosmetic { public class CosmeticBalloonType extends Cosmetic {
private String modelName; private String modelName;
private List<String> dyableParts;
//private HashMap<Animations, String> animationBalloons;
public CosmeticBalloonType(String id, ConfigurationNode config) { public CosmeticBalloonType(String id, ConfigurationNode config) {
super(id, config); super(id, config);
String modelId = config.node("model").getString(); String modelId = config.node("model").getString();
try {
if (!config.node("dyable-parts").virtual()) dyableParts = config.node("dyable-parts").getList(String.class);
/*
if (!config.node("animations").virtual()) {
for (ConfigurationNode animationNode : config.node("animations").childrenMap().values()) {
if (EnumUtils.isValidEnum(Animations.class, animationNode.key().toString().toUpperCase())) continue;
animationBalloons.put(Animations.valueOf(animationNode.key().toString().toUpperCase()), animationNode.getString());
}
}
*/
} catch (SerializationException e) {
// Seriously?
throw new RuntimeException(e);
}
this.modelName = modelId; this.modelName = modelId;
} }
@@ -43,9 +66,9 @@ public class CosmeticBalloonType extends Cosmetic {
return; return;
} }
Vector velocity = newLocation.clone().toVector().subtract(currentLocation.clone().toVector()); Vector velocity = newLocation.toVector().subtract(currentLocation.toVector());
balloonEntity.setVelocity(velocity.multiply(1.1));
balloonEntity.setLocation(newLocation); balloonEntity.setLocation(newLocation);
balloonEntity.setVelocity(velocity);
PacketManager.sendTeleportPacket(balloonEntity.getPufferfishBalloonId(), newLocation, false, viewer); PacketManager.sendTeleportPacket(balloonEntity.getPufferfishBalloonId(), newLocation, false, viewer);
if (!user.getHidden()) PacketManager.sendLeashPacket(balloonEntity.getPufferfishBalloonId(), player.getEntityId(), viewer); if (!user.getHidden()) PacketManager.sendLeashPacket(balloonEntity.getPufferfishBalloonId(), player.getEntityId(), viewer);
@@ -54,4 +77,21 @@ public class CosmeticBalloonType extends Cosmetic {
public String getModelName() { public String getModelName() {
return this.modelName; return this.modelName;
} }
public List<String> getDyableParts() {
return dyableParts;
}
public boolean isDyablePart(String name) {
// If player does not define parts, dye whole model
if (dyableParts == null) return true;
if (dyableParts.isEmpty()) return true;
return dyableParts.contains(name);
}
/*
public String getAnimation(Animations animation) {
return animationBalloons.get(animation);
}
*/
} }

View File

@@ -1,13 +1,16 @@
package com.hibiscusmc.hmccosmetics.entities; package com.hibiscusmc.hmccosmetics.entities;
import com.hibiscusmc.hmccosmetics.config.Settings; import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers; import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.ticxo.modelengine.api.ModelEngineAPI; import com.ticxo.modelengine.api.ModelEngineAPI;
import com.ticxo.modelengine.api.model.ActiveModel; import com.ticxo.modelengine.api.model.ActiveModel;
import com.ticxo.modelengine.api.model.ModeledEntity; import com.ticxo.modelengine.api.model.ModeledEntity;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@@ -15,13 +18,12 @@ import org.bukkit.util.Vector;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
// This includes the Pufferfish (The Pufferfish that's what the player leashes to) and the model (MEGEntity)
public class BalloonEntity { public class BalloonEntity {
private BalloonType balloonType;
private final int balloonID; private final int balloonID;
private final UUID uniqueID; private final UUID uniqueID;
private final Entity modelEntity; private final ArmorStand modelEntity;
private ModeledEntity modeledEntity;
public BalloonEntity(Location location) { public BalloonEntity(Location location) {
this.uniqueID = UUID.randomUUID(); this.uniqueID = UUID.randomUUID();
@@ -29,62 +31,95 @@ public class BalloonEntity {
this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset())); this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset()));
} }
public void spawnModel(final String id, Color color) { public void spawnModel(CosmeticBalloonType cosmeticBalloonType, Color color) {
// redo this
if (cosmeticBalloonType.getModelName() != null) {
balloonType = BalloonType.MODELENGINE;
} else {
if (cosmeticBalloonType.getItem() != null) {
balloonType = BalloonType.ITEM;
} else {
balloonType = BalloonType.NONE;
}
}
MessagesUtil.sendDebugMessages("balloontype is " + balloonType);
MessagesUtil.sendDebugMessages("Attempting Spawning for " + id); if (balloonType == BalloonType.MODELENGINE) {
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(id) == null) { String id = cosmeticBalloonType.getModelName();
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + id, Level.SEVERE); MessagesUtil.sendDebugMessages("Attempting Spawning for " + id);
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(id) == null) {
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + id, Level.SEVERE);
return;
}
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(modelEntity);
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(id));
model.setCanHurt(false);
modeledEntity.addModel(model, false);
if (color != null) {
modeledEntity.getModels().forEach((d, singleModel) -> {
if (cosmeticBalloonType.isDyablePart(d)) {
singleModel.getRendererHandler().setColor(color);
singleModel.getRendererHandler().update();
}
});
}
return; return;
} }
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(modelEntity); if (balloonType == BalloonType.ITEM) {
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(id)); modelEntity.getEquipment().setHelmet(cosmeticBalloonType.getItem());
model.setCanHurt(false);
modeledEntity.addModel(model, false);
if (color != null) {
modeledEntity.getModels().forEach((d, singleModel) -> {
singleModel.getRendererHandler().setColor(color);
singleModel.getRendererHandler().update();
});
} }
this.modeledEntity = modeledEntity;
} }
public void remove() { public void remove() {
final ModeledEntity entity = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId()); if (balloonType == BalloonType.MODELENGINE) {
final ModeledEntity entity = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
if (entity == null) return; if (entity == null) return;
for (final Player player : entity.getRangeManager().getPlayerInRange()) { for (final Player player : entity.getRangeManager().getPlayerInRange()) {
entity.hideFromPlayer(player); entity.hideFromPlayer(player);
}
entity.destroy();
} }
//ModelEngineAPI.removeModeledEntity(megEntity.getUniqueId());
entity.destroy();
modelEntity.remove(); modelEntity.remove();
} }
public void addPlayerToModel(final Player player, final String id) { public void addPlayerToModel(final CosmeticUser user, final CosmeticBalloonType cosmeticBalloonType) {
addPlayerToModel(player, id, null); addPlayerToModel(user, cosmeticBalloonType, null);
} }
public void addPlayerToModel(final Player player, final String id, Color color) { public void addPlayerToModel(final CosmeticUser user, final CosmeticBalloonType cosmeticBalloonType, Color color) {
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId()); if (balloonType == BalloonType.MODELENGINE) {
if (model == null) { final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
spawnModel(id, color); if (model == null) {
MessagesUtil.sendDebugMessages("model is null"); spawnModel(cosmeticBalloonType, color);
MessagesUtil.sendDebugMessages("model is null");
return;
}
//if (model.getRangeManager().getPlayerInRange().contains(player)) return;
model.showToPlayer(user.getPlayer());
MessagesUtil.sendDebugMessages("Show to player");
return; return;
} }
//if (model.getRangeManager().getPlayerInRange().contains(player)) return; if (balloonType == BalloonType.ITEM) {
model.showToPlayer(player); modelEntity.getEquipment().setHelmet(user.getUserCosmeticItem(cosmeticBalloonType));
MessagesUtil.sendDebugMessages("Show to player"); }
} }
public void removePlayerFromModel(final Player player) { public void removePlayerFromModel(final Player player) {
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId()); if (balloonType == BalloonType.MODELENGINE) {
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
if (model == null) return; if (model == null) return;
model.hideFromPlayer(player); model.hideFromPlayer(player);
MessagesUtil.sendDebugMessages("Hidden from player"); MessagesUtil.sendDebugMessages("Hidden from player");
return;
}
if (balloonType == BalloonType.ITEM) {
modelEntity.getEquipment().clear();
return;
}
} }
public Entity getModelEntity() { public Entity getModelEntity() {
@@ -118,4 +153,10 @@ public class BalloonEntity {
public void setVelocity(Vector vector) { public void setVelocity(Vector vector) {
this.getModelEntity().setVelocity(vector); this.getModelEntity().setVelocity(vector);
} }
public enum BalloonType {
MODELENGINE,
ITEM,
NONE
}
} }

View File

@@ -7,6 +7,7 @@ import com.hibiscusmc.hmccosmetics.gui.type.Type;
import com.hibiscusmc.hmccosmetics.gui.type.Types; import com.hibiscusmc.hmccosmetics.gui.type.Types;
import com.hibiscusmc.hmccosmetics.hooks.PAPIHook; import com.hibiscusmc.hmccosmetics.hooks.PAPIHook;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.misc.Adventure; import com.hibiscusmc.hmccosmetics.util.misc.Adventure;
import com.hibiscusmc.hmccosmetics.util.misc.Placeholder; import com.hibiscusmc.hmccosmetics.util.misc.Placeholder;
@@ -137,8 +138,6 @@ public class Menu {
MessagesUtil.sendDebugMessages("something went wrong! " + item); MessagesUtil.sendDebugMessages("something went wrong! " + item);
continue; continue;
} }
ItemStack originalItem = item.clone();
item = updateLore(player, item);
Type type = null; Type type = null;
@@ -147,6 +146,9 @@ public class Menu {
if (Types.isType(typeId)) type = Types.getType(typeId); if (Types.isType(typeId)) type = Types.getType(typeId);
} }
ItemStack originalItem = item.clone();
item = updateLore(user, item, type, config);
GuiItem guiItem = ItemBuilder.from(item).asGuiItem(); GuiItem guiItem = ItemBuilder.from(item).asGuiItem();
Type finalType = type; Type finalType = type;
@@ -155,7 +157,7 @@ public class Menu {
if (finalType != null) finalType.run(user, config, clickType); if (finalType != null) finalType.run(user, config, clickType);
for (int i : slots) { for (int i : slots) {
gui.updateItem(i, updateLore(player, originalItem.clone())); gui.updateItem(i, updateLore(user, originalItem.clone(), finalType, config));
MessagesUtil.sendDebugMessages("Updated slot " + i); MessagesUtil.sendDebugMessages("Updated slot " + i);
} }
}); });
@@ -190,21 +192,9 @@ public class Menu {
return slots; return slots;
} }
private ItemStack updateLore(Player player, ItemStack itemStack) { private ItemStack updateLore(CosmeticUser user, ItemStack itemStack, Type type, ConfigurationNode config) {
if (itemStack.hasItemMeta()) { if (itemStack.hasItemMeta()) {
List<String> processedLore = new ArrayList<>(); itemStack.setItemMeta(type.setLore(user, config, itemStack.getItemMeta()));
if (PAPIHook.isPAPIEnabled()) {
if (itemStack.getItemMeta().hasLore()) {
for (String loreLine : itemStack.getItemMeta().getLore()) {
processedLore.add(PlaceholderAPI.setPlaceholders(player, loreLine));
}
}
}
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setLore(processedLore);
itemStack.setItemMeta(itemMeta);
} }
return itemStack; return itemStack;
} }

View File

@@ -1,6 +1,7 @@
package com.hibiscusmc.hmccosmetics.gui; package com.hibiscusmc.hmccosmetics.gui;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.spongepowered.configurate.CommentedConfigurationNode; import org.spongepowered.configurate.CommentedConfigurationNode;
@@ -12,6 +13,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.logging.Level;
public class Menus { public class Menus {
@@ -67,7 +69,12 @@ public class Menus {
} catch (ConfigurateException e) { } catch (ConfigurateException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
new Menu(FilenameUtils.removeExtension(child.getName()), root); try {
new Menu(FilenameUtils.removeExtension(child.getName()), root);
} catch (Exception e) {
MessagesUtil.sendDebugMessages("Unable to create menu in " + child, Level.WARNING);
if (Settings.isDebugEnabled()) e.printStackTrace();
}
} }
} }
} }

View File

@@ -18,6 +18,10 @@ public class Actions {
private static ActionPlayerCommand ACTION_CONSOLE_COMMAND = new ActionPlayerCommand(); private static ActionPlayerCommand ACTION_CONSOLE_COMMAND = new ActionPlayerCommand();
private static ActionConsoleCommand ACTION_PLAYER_COMMAND = new ActionConsoleCommand(); private static ActionConsoleCommand ACTION_PLAYER_COMMAND = new ActionConsoleCommand();
private static ActionCloseMenu ACTION_EXIT_MENU = new ActionCloseMenu(); private static ActionCloseMenu ACTION_EXIT_MENU = new ActionCloseMenu();
private static ActionSound ACTION_SOUND = new ActionSound();
private static ActionEquip ACTION_EQUIP = new ActionEquip();
private static ActionUnequip ACTION_UNEQUIP = new ActionUnequip();
private static ActionParticle ACTION_PARTICLE = new ActionParticle();
public static Action getAction(String id) { public static Action getAction(String id) {

View File

@@ -0,0 +1,22 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
public class ActionEquip extends Action {
public ActionEquip() {
super("equip");
}
@Override
public void run(CosmeticUser user, String raw) {
Cosmetic cosmetic = Cosmetics.getCosmetic(raw);
if (cosmetic == null) {
return;
}
user.addPlayerCosmetic(cosmetic);
}
}

View File

@@ -0,0 +1,49 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.owen1212055.particlehelper.api.particle.Particle;
import com.owen1212055.particlehelper.api.particle.types.BlockDataParticle;
import com.owen1212055.particlehelper.api.particle.types.DestinationParticle;
import com.owen1212055.particlehelper.api.particle.types.velocity.VelocityParticle;
import com.owen1212055.particlehelper.api.particle.types.vibration.VibrationParticle;
import com.owen1212055.particlehelper.api.type.Particles;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
public class ActionParticle extends Action {
public ActionParticle() {
super("particle");
}
@Override
public void run(CosmeticUser user, String raw) {
String[] rawString = raw.split(" ");
var particleType = Particles.fromKey(NamespacedKey.minecraft(rawString[0].toLowerCase()));
if (particleType == null) {
MessagesUtil.sendDebugMessages("The particle " + rawString[0] + " does not exist!");
return;
}
boolean multi = false;
if (particleType.multi() != null) {
multi = true; // Should work?
}
var particle = multi ? particleType.multi() : particleType.single();
if (particle instanceof DestinationParticle || particle instanceof BlockDataParticle
|| particle instanceof VibrationParticle || particle instanceof VelocityParticle) {
MessagesUtil.sendDebugMessages("The particle " + rawString[0] + " is not supported by this action!");
return;
}
particle = ServerUtils.addParticleValues(particle, rawString);
Location location = user.getPlayer().getLocation();
for (Player player : PacketManager.getViewers(location)) {
particle.compile().send(player, location);
}
}
}

View File

@@ -0,0 +1,35 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.bukkit.entity.Player;
import java.util.logging.Level;
public class ActionSound extends Action {
// [SOUND] minecraft:test 1 1
public ActionSound() {
super("sound");
}
@Override
public void run(CosmeticUser user, String raw) {
Player player = user.getPlayer();
String[] processedString = raw.split(" ");
String soundName = processedString[0];
float volume = 1;
float pitch = 1;
if (processedString.length > 2) {
volume = Float.valueOf(processedString[1]);
pitch = Float.valueOf(processedString[2]);
}
MessagesUtil.sendDebugMessages("Attempting to play " + soundName, Level.WARNING);
player.playSound(player.getLocation(), soundName, volume, pitch);
}
}

View File

@@ -0,0 +1,22 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.apache.commons.lang3.EnumUtils;
public class ActionUnequip extends Action {
public ActionUnequip() {
super("unequip");
}
@Override
public void run(CosmeticUser user, String raw) {
if (!EnumUtils.isValidEnum(CosmeticSlot.class, raw)) {
return;
}
CosmeticSlot slot = CosmeticSlot.valueOf(raw);
user.removeCosmeticSlot(slot);
}
}

View File

@@ -42,7 +42,10 @@ public class DyeMenu {
//user.removeCosmeticSlot(cosmetic); //user.removeCosmeticSlot(cosmetic);
user.addPlayerCosmetic(cosmetic, color); user.addPlayerCosmetic(cosmetic, color);
player.setItemOnCursor(new ItemStack(Material.AIR)); player.setItemOnCursor(new ItemStack(Material.AIR));
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), player::closeInventory, 2); Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
player.closeInventory();
user.updateCosmetic(cosmetic.getSlot());
}, 2);
} else event.setCancelled(true); } else event.setCancelled(true);
}); });

View File

@@ -1,18 +1,28 @@
package com.hibiscusmc.hmccosmetics.gui.type.types; package com.hibiscusmc.hmccosmetics.gui.type.types;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
import com.hibiscusmc.hmccosmetics.gui.action.Actions; import com.hibiscusmc.hmccosmetics.gui.action.Actions;
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu; import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
import com.hibiscusmc.hmccosmetics.gui.type.Type; import com.hibiscusmc.hmccosmetics.gui.type.Type;
import com.hibiscusmc.hmccosmetics.hooks.PAPIHook;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.misc.StringUtils;
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.meta.ItemMeta;
import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException; import org.spongepowered.configurate.serialize.SerializationException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class TypeCosmetic extends Type { public class TypeCosmetic extends Type {
@@ -70,7 +80,73 @@ public class TypeCosmetic extends Type {
} catch (SerializationException e) { } catch (SerializationException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
// Fixes issue with offhand cosmetics not appearing. Yes, I know this is dumb
Runnable run = () -> user.updateCosmetic(cosmetic.getSlot());
if (cosmetic instanceof CosmeticArmorType) {
if (((CosmeticArmorType) cosmetic).getEquipSlot().equals(EquipmentSlot.OFF_HAND)) {
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, 1);
return;
}
}
run.run();
}
user.updateCosmetic(cosmetic.getSlot()); @Override
public ItemMeta setLore(CosmeticUser user, ConfigurationNode config, ItemMeta itemMeta) {
List<String> processedLore = new ArrayList<>();
if (config.node("cosmetic").virtual()) return processLoreLines(user, itemMeta);;
String cosmeticName = config.node("cosmetic").getString();
Cosmetic cosmetic = Cosmetics.getCosmetic(cosmeticName);
if (cosmetic == null) {
return processLoreLines(user, itemMeta);
}
if (user.canEquipCosmetic(cosmetic)) {
return processLoreLines(user, itemMeta);
} else {
ConfigurationNode itemConfig = config.node("item");
if (itemConfig.virtual()) return itemMeta;
if (itemConfig.node("locked-name").virtual() && itemConfig.node("locked-name").virtual()) {
return processLoreLines(user, itemMeta);
}
try {
itemMeta.getLore().clear();
List<String> lockedLore = Utils.replaceIfNull(itemConfig.node("locked-lore").getList(String.class),
new ArrayList<String>()).
stream().map(StringUtils::parseStringToString).collect(Collectors.toList());
if (PAPIHook.isPAPIEnabled()) {
String lockedName = StringUtils.parseStringToString(Utils.replaceIfNull(itemConfig.node("locked-name").getString(), ""));
itemMeta.setDisplayName(PlaceholderAPI.setPlaceholders(user.getPlayer(), lockedName));
if (itemMeta.hasLore()) {
for (String loreLine : lockedLore) {
processedLore.add(PlaceholderAPI.setPlaceholders(user.getPlayer(), loreLine));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
itemMeta.setLore(processedLore);
return itemMeta;
}
private ItemMeta processLoreLines(CosmeticUser user, ItemMeta itemMeta) {
List<String> processedLore = new ArrayList<>();
if (PAPIHook.isPAPIEnabled()) {
if (itemMeta.hasLore()) {
for (String loreLine : itemMeta.getLore()) {
processedLore.add(PlaceholderAPI.setPlaceholders(user.getPlayer(), loreLine));
}
}
}
itemMeta.setLore(processedLore);
return itemMeta;
} }
} }

View File

@@ -2,8 +2,11 @@ package com.hibiscusmc.hmccosmetics.gui.type.types;
import com.hibiscusmc.hmccosmetics.gui.action.Actions; import com.hibiscusmc.hmccosmetics.gui.action.Actions;
import com.hibiscusmc.hmccosmetics.gui.type.Type; import com.hibiscusmc.hmccosmetics.gui.type.Type;
import com.hibiscusmc.hmccosmetics.hooks.PAPIHook;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.meta.ItemMeta;
import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException; import org.spongepowered.configurate.serialize.SerializationException;
@@ -48,6 +51,21 @@ public class TypeEmpty extends Type {
} }
} }
@Override
public ItemMeta setLore(CosmeticUser user, ConfigurationNode config, ItemMeta itemMeta) {
List<String> processedLore = new ArrayList<>();
if (PAPIHook.isPAPIEnabled()) {
if (itemMeta.hasLore()) {
for (String loreLine : itemMeta.getLore()) {
processedLore.add(PlaceholderAPI.setPlaceholders(user.getPlayer(), loreLine));
}
}
}
return itemMeta;
}
// That's it! Now, add it as a static in another one of your classes (such as your main class) and you are good to go. // That's it! Now, add it as a static in another one of your classes (such as your main class) and you are good to go.
// If you need help with that, check the Types class. // If you need help with that, check the Types class.
} }

View File

@@ -21,7 +21,9 @@ public class ItemAdderHook extends ItemHook implements Listener {
@Override @Override
public ItemStack get(String itemid) { public ItemStack get(String itemid) {
if (enabled) { if (enabled) {
return CustomStack.getInstance(itemid).getItemStack(); CustomStack stack = CustomStack.getInstance(itemid);
if (stack == null) return null;
return stack.getItemStack();
} else { } else {
return new ItemStack(Material.AIR); return new ItemStack(Material.AIR);
} }

View File

@@ -30,7 +30,7 @@ public class WGListener implements Listener {
} }
for (ProtectedRegion protectedRegion : set.getRegions()) { for (ProtectedRegion protectedRegion : set.getRegions()) {
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) { if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
user.hideCosmetics(); user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
return; return;
} }
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) { if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {

View File

@@ -24,10 +24,12 @@ import org.bukkit.Color;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
@@ -35,6 +37,7 @@ import org.bukkit.event.player.*;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -196,6 +199,23 @@ public class PlayerGameListener implements Listener {
}, 2); }, 2);
} }
@EventHandler
public void playerInvisibility(EntityPotionEffectEvent event) {
if (event.isCancelled()) return;
if (!event.getModifiedType().equals(PotionEffectType.INVISIBILITY)) return;
if (!event.getEntityType().equals(EntityType.PLAYER)) return;
Player player = (Player) event.getEntity();
CosmeticUser user = CosmeticUsers.getUser(player);
if (event.getAction().equals(EntityPotionEffectEvent.Action.ADDED)) {
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
return;
}
if (event.getAction().equals(EntityPotionEffectEvent.Action.CLEARED) || event.getAction().equals(EntityPotionEffectEvent.Action.REMOVED)) {
user.showCosmetics();
return;
}
}
@EventHandler @EventHandler
public void onMainHandSwitch(PlayerItemHeldEvent event) { public void onMainHandSwitch(PlayerItemHeldEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer()); CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
@@ -278,6 +298,7 @@ public class PlayerGameListener implements Listener {
} }
} }
packet.getItemListModifier().write(0, slotData); packet.getItemListModifier().write(0, slotData);
packet.getItemModifier().write(0, event.getPacket().getItemModifier().read(0));
event.setPacket(packet); event.setPacket(packet);
MessagesUtil.sendDebugMessages("Menu Fired, updated cosmetics " + " on slotdata " + windowID + " with " + slotData.size()); MessagesUtil.sendDebugMessages("Menu Fired, updated cosmetics " + " on slotdata " + windowID + " with " + slotData.size());
/* /*
@@ -298,13 +319,11 @@ public class PlayerGameListener implements Listener {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) { ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) {
@Override @Override
public void onPacketSending(PacketEvent event) { public void onPacketSending(PacketEvent event) {
MessagesUtil.sendDebugMessages("equipment packet is activated");
Player player = event.getPlayer(); // Player that's sent Player player = event.getPlayer(); // Player that's sent
int entityID = event.getPacket().getIntegers().read(0); int entityID = event.getPacket().getIntegers().read(0);
// User // User
CosmeticUser user = CosmeticUsers.getUser(entityID); CosmeticUser user = CosmeticUsers.getUser(entityID);
if (user == null) { if (user == null) {
MessagesUtil.sendDebugMessages("equipment packet is activated - user null");
return; return;
} }

View File

@@ -6,6 +6,7 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.entities.BalloonEntity; import com.hibiscusmc.hmccosmetics.entities.BalloonEntity;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@@ -20,7 +21,7 @@ public interface NMSHandler {
Entity getInvisibleArmorstand(Location loc); Entity getInvisibleArmorstand(Location loc);
Entity getMEGEntity(Location loc); ArmorStand getMEGEntity(Location loc);
Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType); Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType);

View File

@@ -8,7 +8,7 @@ import java.util.logging.Level;
public class NMSHandlers { public class NMSHandlers {
private static final String[] SUPPORTED_VERSION = new String[]{"v1_19_R1", "v1_19_R2"}; private static final String[] SUPPORTED_VERSION = new String[]{"v1_17_R1", "v1_18_R2", "v1_19_R1", "v1_19_R2"};
private static NMSHandler handler; private static NMSHandler handler;
private static String version; private static String version;

View File

@@ -42,6 +42,7 @@ public class CosmeticUser {
// Cosmetic Settings/Toggles // Cosmetic Settings/Toggles
private boolean hideBackpack; private boolean hideBackpack;
private boolean hideCosmetics; private boolean hideCosmetics;
private HiddenReason hiddenReason;
private HashMap<CosmeticSlot, Color> colors = new HashMap<>(); private HashMap<CosmeticSlot, Color> colors = new HashMap<>();
public CosmeticUser() { public CosmeticUser() {
@@ -246,9 +247,25 @@ public class CosmeticUser {
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
if (!getWardrobe().getWardrobeStatus().equals(Wardrobe.WardrobeStatus.RUNNING)) return;
wardrobe.end(); getWardrobe().setWardrobeStatus(Wardrobe.WardrobeStatus.STOPPING);
wardrobe = null;
if (WardrobeSettings.isEnabledTransition()) {
MessagesUtil.sendTitle(
getPlayer(),
WardrobeSettings.getTransitionText(),
WardrobeSettings.getTransitionFadeIn(),
WardrobeSettings.getTransitionStay(),
WardrobeSettings.getTransitionFadeOut()
);
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
wardrobe.end();
wardrobe = null;
}, WardrobeSettings.getTransitionDelay());
} else {
}
} }
public boolean isInWardrobe() { public boolean isInWardrobe() {
@@ -306,6 +323,20 @@ public class CosmeticUser {
this.invisibleArmorstand = null; this.invisibleArmorstand = null;
} }
public void respawnBackpack() {
if (!hasCosmeticInSlot(CosmeticSlot.BACKPACK)) return;
final Cosmetic cosmetic = getCosmetic(CosmeticSlot.BACKPACK);
despawnBackpack();
spawnBackpack((CosmeticBackpackType) cosmetic);
}
public void respawnBalloon() {
if (!hasCosmeticInSlot(CosmeticSlot.BALLOON)) return;
final Cosmetic cosmetic = getCosmetic(CosmeticSlot.BALLOON);
despawnBalloon();
spawnBalloon((CosmeticBalloonType) cosmetic);
}
public void removeArmor(CosmeticSlot slot) { public void removeArmor(CosmeticSlot slot) {
PacketManager.equipmentSlotUpdate(getPlayer().getEntityId(), this, slot, PlayerUtils.getNearbyPlayers(getPlayer())); PacketManager.equipmentSlotUpdate(getPlayer().getEntityId(), this, slot, PlayerUtils.getNearbyPlayers(getPlayer()));
} }
@@ -370,15 +401,16 @@ public class CosmeticUser {
} }
} }
public void hideCosmetics() { public void hideCosmetics(HiddenReason reason) {
if (hideCosmetics == true) return; if (hideCosmetics == true) return;
PlayerCosmeticHideEvent event = new PlayerCosmeticHideEvent(this); PlayerCosmeticHideEvent event = new PlayerCosmeticHideEvent(this, reason);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
hideCosmetics = true; hideCosmetics = true;
hiddenReason = reason;
if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) { if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
getBalloonEntity().removePlayerFromModel(getPlayer()); getBalloonEntity().removePlayerFromModel(getPlayer());
List<Player> viewer = PlayerUtils.getNearbyPlayers(getPlayer()); List<Player> viewer = PlayerUtils.getNearbyPlayers(getPlayer());
@@ -399,10 +431,12 @@ public class CosmeticUser {
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
hideCosmetics = false; hideCosmetics = false;
hiddenReason = HiddenReason.NONE;
if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) { if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
CosmeticBalloonType balloonType = (CosmeticBalloonType) getCosmetic(CosmeticSlot.BALLOON); CosmeticBalloonType balloonType = (CosmeticBalloonType) getCosmetic(CosmeticSlot.BALLOON);
getBalloonEntity().addPlayerToModel(getPlayer(), balloonType.getModelName()); getBalloonEntity().addPlayerToModel(this, balloonType);
List<Player> viewer = PlayerUtils.getNearbyPlayers(getPlayer()); List<Player> viewer = PlayerUtils.getNearbyPlayers(getPlayer());
PacketManager.sendLeashPacket(getBalloonEntity().getPufferfishBalloonId(), getPlayer().getEntityId(), viewer); PacketManager.sendLeashPacket(getBalloonEntity().getPufferfishBalloonId(), getPlayer().getEntityId(), viewer);
} }
@@ -418,4 +452,14 @@ public class CosmeticUser {
public boolean getHidden() { public boolean getHidden() {
return this.hideCosmetics; return this.hideCosmetics;
} }
public HiddenReason getHiddenReason() {
return hiddenReason;
}
public enum HiddenReason {
NONE,
WORLDGUARD,
PLUGIN
}
} }

View File

@@ -39,15 +39,18 @@ public class Wardrobe {
private Location exitLocation; private Location exitLocation;
private BossBar bossBar; private BossBar bossBar;
private boolean active; private boolean active;
private WardrobeStatus wardrobeStatus;
public Wardrobe(CosmeticUser user) { public Wardrobe(CosmeticUser user) {
NPC_ID = NMSHandlers.getHandler().getNextEntityId(); NPC_ID = NMSHandlers.getHandler().getNextEntityId();
ARMORSTAND_ID = NMSHandlers.getHandler().getNextEntityId(); ARMORSTAND_ID = NMSHandlers.getHandler().getNextEntityId();
WARDROBE_UUID = UUID.randomUUID(); WARDROBE_UUID = UUID.randomUUID();
VIEWER = user; VIEWER = user;
wardrobeStatus = WardrobeStatus.SETUP;
} }
public void start() { public void start() {
setWardrobeStatus(WardrobeStatus.STARTING);
Player player = VIEWER.getPlayer(); Player player = VIEWER.getPlayer();
this.originalGamemode = player.getGameMode(); this.originalGamemode = player.getGameMode();
@@ -62,6 +65,8 @@ public class Wardrobe {
VIEWER.hidePlayer(); VIEWER.hidePlayer();
List<Player> viewer = List.of(player); List<Player> viewer = List.of(player);
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
outsideViewers.remove(player);
MessagesUtil.sendMessage(player, "opened-wardrobe"); MessagesUtil.sendMessage(player, "opened-wardrobe");
@@ -119,6 +124,7 @@ public class Wardrobe {
this.active = true; this.active = true;
update(); update();
setWardrobeStatus(WardrobeStatus.RUNNING);
}; };
@@ -138,9 +144,12 @@ public class Wardrobe {
} }
public void end() { public void end() {
setWardrobeStatus(WardrobeStatus.STOPPING);
Player player = VIEWER.getPlayer(); Player player = VIEWER.getPlayer();
List<Player> viewer = List.of(player); List<Player> viewer = List.of(player);
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
outsideViewers.remove(player);
MessagesUtil.sendMessage(player, "closed-wardrobe"); MessagesUtil.sendMessage(player, "closed-wardrobe");
@@ -164,11 +173,13 @@ public class Wardrobe {
VIEWER.showPlayer(); VIEWER.showPlayer();
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
PacketManager.ridingMountPacket(player.getEntityId(), VIEWER.getBackpackEntity().getEntityId(), viewer); VIEWER.respawnBackpack();
//PacketManager.ridingMountPacket(player.getEntityId(), VIEWER.getBackpackEntity().getEntityId(), viewer);
} }
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) { if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), viewer); VIEWER.respawnBalloon();
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), viewer);
} }
if (exitLocation == null) { if (exitLocation == null) {
@@ -189,19 +200,7 @@ public class Wardrobe {
VIEWER.updateCosmetic(); VIEWER.updateCosmetic();
}; };
run.run();
if (WardrobeSettings.isEnabledTransition()) {
MessagesUtil.sendTitle(
VIEWER.getPlayer(),
WardrobeSettings.getTransitionText(),
WardrobeSettings.getTransitionFadeIn(),
WardrobeSettings.getTransitionStay(),
WardrobeSettings.getTransitionFadeOut()
);
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, WardrobeSettings.getTransitionDelay());
} else {
run.run();
}
} }
public void update() { public void update() {
@@ -217,13 +216,15 @@ public class Wardrobe {
} }
MessagesUtil.sendDebugMessages("Update "); MessagesUtil.sendDebugMessages("Update ");
List<Player> viewer = List.of(VIEWER.getPlayer()); List<Player> viewer = List.of(VIEWER.getPlayer());
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
outsideViewers.remove(VIEWER.getPlayer());
Location location = WardrobeSettings.getWardrobeLocation().clone(); Location location = WardrobeSettings.getWardrobeLocation().clone();
int yaw = data.get(); int yaw = data.get();
location.setYaw(yaw); location.setYaw(yaw);
PacketManager.sendLookPacket(NPC_ID, location, viewer); PacketManager.sendLookPacket(NPC_ID, location, viewer);
//VIEWER.updateCosmetic(); VIEWER.hidePlayer();
int rotationSpeed = WardrobeSettings.getRotationSpeed(); int rotationSpeed = WardrobeSettings.getRotationSpeed();
location.setYaw(getNextYaw(yaw - 30, rotationSpeed)); location.setYaw(getNextYaw(yaw - 30, rotationSpeed));
PacketManager.sendRotationPacket(NPC_ID, location, true, viewer); PacketManager.sendRotationPacket(NPC_ID, location, true, viewer);
@@ -238,11 +239,14 @@ public class Wardrobe {
PacketManager.sendTeleportPacket(VIEWER.getArmorstandId(), location, false, viewer); PacketManager.sendTeleportPacket(VIEWER.getArmorstandId(), location, false, viewer);
PacketManager.ridingMountPacket(NPC_ID, VIEWER.getBackpackEntity().getEntityId(), viewer); PacketManager.ridingMountPacket(NPC_ID, VIEWER.getBackpackEntity().getEntityId(), viewer);
VIEWER.getBackpackEntity().setRotation(nextyaw, 0); VIEWER.getBackpackEntity().setRotation(nextyaw, 0);
PacketManager.sendEntityDestroyPacket(VIEWER.getArmorstandId(), outsideViewers);
} }
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) { if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
PacketManager.sendTeleportPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()), false, viewer); PacketManager.sendTeleportPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()), false, viewer);
VIEWER.getBalloonEntity().getModelEntity().teleport(WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset())); VIEWER.getBalloonEntity().getModelEntity().teleport(WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()));
PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), -1, outsideViewers);
PacketManager.sendEntityDestroyPacket(VIEWER.getBalloonEntity().getModelId(), outsideViewers);
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), NPC_ID, viewer); // Pufferfish goes away for some reason? //PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), NPC_ID, viewer); // Pufferfish goes away for some reason?
} }
@@ -267,4 +271,19 @@ public class Wardrobe {
public int getArmorstandId() { public int getArmorstandId() {
return ARMORSTAND_ID; return ARMORSTAND_ID;
} }
public WardrobeStatus getWardrobeStatus() {
return wardrobeStatus;
}
public void setWardrobeStatus(WardrobeStatus status) {
this.wardrobeStatus = status;
}
public enum WardrobeStatus {
SETUP,
STARTING,
RUNNING,
STOPPING,
}
} }

View File

@@ -47,6 +47,7 @@ public class MessagesUtil {
public static void sendMessage(CommandSender sender, String key) { public static void sendMessage(CommandSender sender, String key) {
Component finalMessage = processString(null, key); Component finalMessage = processString(null, key);
if (finalMessage == null) return;
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).sender(sender); Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).sender(sender);
target.sendMessage(finalMessage); target.sendMessage(finalMessage);
@@ -130,7 +131,7 @@ public class MessagesUtil {
} }
public static void sendDebugMessages(String message, Level level) { public static void sendDebugMessages(String message, Level level) {
if (!Settings.isDebugEnabled() && level != Level.SEVERE) return; if (!Settings.isDebugEnabled() && level == Level.INFO) return;
HMCCosmeticsPlugin.getInstance().getLogger().log(level, message); HMCCosmeticsPlugin.getInstance().getLogger().log(level, message);
} }
} }

View File

@@ -1,8 +1,18 @@
package com.hibiscusmc.hmccosmetics.util; package com.hibiscusmc.hmccosmetics.util;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers; import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.owen1212055.particlehelper.api.particle.MultiParticle;
import com.owen1212055.particlehelper.api.particle.Particle;
import com.owen1212055.particlehelper.api.particle.types.*;
import com.owen1212055.particlehelper.api.particle.types.dust.transition.TransitionDustParticle;
import com.owen1212055.particlehelper.api.particle.types.note.MultiNoteParticle;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material;
import org.jetbrains.annotations.Nullable;
import java.math.BigInteger;
import java.util.Arrays;
public class ServerUtils { public class ServerUtils {
@@ -36,4 +46,84 @@ public class ServerUtils {
return null; return null;
} }
} }
// particle amount offsetxyz
// Ex. HEART 10 0.1 0.1 0.1
public static Particle addParticleValues(Particle particle, String[] split) {
var counter = 1;
if (particle instanceof MultiParticle multiParticle) {
multiParticle.setCount(getBigInteger(split[counter]).intValue());
counter++;
multiParticle.setXOffset(getBigInteger(split[counter]).floatValue());
counter++;
multiParticle.setYOffset(getBigInteger(split[counter]).floatValue());
counter++;
multiParticle.setZOffset(getBigInteger(split[counter]).floatValue());
counter++;
if (multiParticle instanceof MultiNoteParticle multiNoteParticle) {
multiNoteParticle.setColorMultplier(getBigInteger(split[counter]).intValue());
counter++;
}
}
if (particle instanceof ColorableParticle colorableParticle && colorFromString(split[counter]) != null) {
colorableParticle.setColor(colorFromString(split[counter]));
counter++;
}
if (particle instanceof TransitionDustParticle transitionDustParticle && colorFromString(split[counter]) != null) {
transitionDustParticle.setFadeColor(colorFromString(split[counter]));
counter++;
}
if (particle instanceof MaterialParticle materialParticle && Material.getMaterial(split[counter]) != null) {
materialParticle.setMaterial(Material.getMaterial(split[counter]));
counter++;
}
if (particle instanceof SpeedModifiableParticle speedModifiableParticle) {
speedModifiableParticle.setSpeed(getBigInteger(split[counter]).floatValue());
counter++;
}
if (particle instanceof DelayableParticle delayableParticle) {
delayableParticle.setDelay(getBigInteger(split[counter]).intValue());
counter++;
}
if (particle instanceof SizeableParticle sizeableParticle) {
sizeableParticle.setSize(getBigInteger(split[counter]).floatValue());
counter++;
}
if (particle instanceof RollableParticle rollableParticle) {
rollableParticle.setRoll(getBigInteger(split[counter]).floatValue());
}
return particle;
}
private static BigInteger getBigInteger(String string) {
try {
return new BigInteger(string);
} catch (Exception e) {
return BigInteger.valueOf(1);
}
}
/**
* Parse a color from a string.
* Formats: #RRGGBB; R,G,B
*
* @param color The string
* @return The color, if the string can't be parsed, null is returned
*/
public static Color colorFromString(@Nullable String color) {
if (color == null) {
return null;
}
try {
var decodedColor = java.awt.Color.decode(color.startsWith("#") ? color : "#" + color);
return Color.fromRGB(decodedColor.getRed(), decodedColor.getGreen(), decodedColor.getBlue());
} catch (NumberFormatException invalidHex) {
try {
var rgbValues = Arrays.stream(color.split(",")).map(Integer::parseInt).toArray(Integer[]::new);
return Color.fromRGB(rgbValues[0], rgbValues[1], rgbValues[2]);
} catch (Exception invalidRgb) {
return null;
}
}
}
} }

View File

@@ -32,7 +32,7 @@ cosmetic-settings:
y: 3 y: 3
z: 0.5 z: 0.5
dye-menu: dye-menu:
title: "<white>" title: "§f"
wardrobe: wardrobe:
# spawn static wardrobe if in this radius of wardrobe-location # spawn static wardrobe if in this radius of wardrobe-location
static-radius: 10 static-radius: 10
@@ -48,6 +48,7 @@ wardrobe:
text: "Left-Click to open the menu!" text: "Left-Click to open the menu!"
progress: 1.0 # Goes between 0.0 -> 1.0 progress: 1.0 # Goes between 0.0 -> 1.0
overlay: PROGRESS overlay: PROGRESS
color: BLUE
transition: transition:
enabled: true enabled: true
text: "<black>" text: "<black>"

View File

@@ -1,9 +1,9 @@
title: "<white>" title: "<white>"
rows: 5 rows: 6
items: items:
beanie: beanie:
slots: slots:
- 1 - 0
item: item:
material: hmccosmetics:beanie material: hmccosmetics:beanie
lore: lore:
@@ -14,7 +14,7 @@ items:
cosmetic: beanie cosmetic: beanie
backpack: backpack:
slots: slots:
- 2 - 1
item: item:
material: hmccosmetics:backpack material: hmccosmetics:backpack
lore: lore:
@@ -25,7 +25,7 @@ items:
cosmetic: backpack cosmetic: backpack
future_wings: future_wings:
slots: slots:
- 3 - 2
item: item:
material: hmccosmetics:future_wings material: hmccosmetics:future_wings
lore: lore:
@@ -36,7 +36,7 @@ items:
cosmetic: future_wings cosmetic: future_wings
lantern_cosmetic: lantern_cosmetic:
slots: slots:
- 4 - 3
item: item:
material: hmccosmetics:lantern_cosmetic material: hmccosmetics:lantern_cosmetic
lore: lore:
@@ -47,7 +47,7 @@ items:
cosmetic: lantern_cosmetic cosmetic: lantern_cosmetic
baseball_hat: baseball_hat:
slots: slots:
- 5 - 4
item: item:
material: hmccosmetics:baseball_hat material: hmccosmetics:baseball_hat
lore: lore:
@@ -58,7 +58,7 @@ items:
cosmetic: baseball_hat cosmetic: baseball_hat
frog_hat: frog_hat:
slots: slots:
- 6 - 5
item: item:
material: hmccosmetics:frog_hat material: hmccosmetics:frog_hat
lore: lore:
@@ -69,7 +69,7 @@ items:
cosmetic: frog_hat cosmetic: frog_hat
jetpack: jetpack:
slots: slots:
- 7 - 6
item: item:
material: hmccosmetics:jetpack material: hmccosmetics:jetpack
lore: lore:
@@ -80,7 +80,7 @@ items:
cosmetic: jetpack cosmetic: jetpack
hammer: hammer:
slots: slots:
- 10 - 7
item: item:
material: hmccosmetics:hammer material: hmccosmetics:hammer
lore: lore:
@@ -91,7 +91,7 @@ items:
cosmetic: hammer cosmetic: hammer
chestplate: chestplate:
slots: slots:
- 11 - 8
item: item:
material: hmccosmetics:chestplate material: hmccosmetics:chestplate
lore: lore:
@@ -102,7 +102,7 @@ items:
cosmetic: chestplate cosmetic: chestplate
pants: pants:
slots: slots:
- 12 - 9
item: item:
material: hmccosmetics:pants material: hmccosmetics:pants
lore: lore:
@@ -113,7 +113,7 @@ items:
cosmetic: pants cosmetic: pants
boots: boots:
slots: slots:
- 13 - 10
item: item:
material: hmccosmetics:boots material: hmccosmetics:boots
lore: lore:
@@ -124,7 +124,7 @@ items:
cosmetic: boots cosmetic: boots
kite: kite:
slots: slots:
- 14 - 11
item: item:
material: hmccosmetics:kite material: hmccosmetics:kite
lore: lore:

View File

@@ -7,6 +7,8 @@ pluginManagement {
rootProject.name = "HMCCosmetics" rootProject.name = "HMCCosmetics"
include( include(
"common", "common",
"v1_17_R1",
"v1_18_R2",
"v1_19_R1", "v1_19_R1",
"v1_19_R2" "v1_19_R2"
) )

27
v1_17_R1/build.gradle.kts Normal file
View File

@@ -0,0 +1,27 @@
plugins {
id("java")
id("io.papermc.paperweight.userdev") version "1.3.8"
}
dependencies {
paperDevBundle("1.17.1-R0.1-SNAPSHOT")
implementation(project(":common"))
}
tasks {
build {
dependsOn(reobfJar)
}
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(17)
}
javadoc {
options.encoding = Charsets.UTF_8.name()
}
processResources {
filteringCharset = Charsets.UTF_8.name()
}
}

View File

@@ -0,0 +1,24 @@
package com.hibiscusmc.hmccosmetics.nms.v1_17_R1;
import net.minecraft.world.entity.decoration.ArmorStand;
import net.minecraft.world.level.Level;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_17_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);
setSilent(true);
getBukkitLivingEntity().setCollidable(false);
persist = false;
}
}

View File

@@ -0,0 +1,31 @@
package com.hibiscusmc.hmccosmetics.nms.v1_17_R1;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.decoration.ArmorStand;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
import org.bukkit.persistence.PersistentDataType;
public class MEGEntity extends ArmorStand {
public MEGEntity(Location loc) {
super(EntityType.ARMOR_STAND, ((CraftWorld) loc.getWorld()).getHandle());
this.setPos(loc.getX(), loc.getY(), loc.getZ());
MessagesUtil.sendDebugMessages("Spawned MEGEntity at " + loc);
setInvisible(true);
setNoGravity(true);
setSilent(true);
setInvulnerable(true);
setSmall(true);
setMarker(true);
persist = false;
getBukkitEntity().getPersistentDataContainer().set(new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticMob"), PersistentDataType.SHORT, Short.valueOf("1"));
((CraftWorld) loc.getWorld()).getHandle().addFreshEntity(this);
}
}

View File

@@ -0,0 +1,240 @@
package com.hibiscusmc.hmccosmetics.nms.v1_17_R1;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
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.cosmetic.types.CosmeticMainhandType;
import com.hibiscusmc.hmccosmetics.entities.BalloonEntity;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.mojang.datafixers.util.Pair;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerPlayerConnection;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.scores.PlayerTeam;
import net.minecraft.world.scores.Team;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_17_R1.CraftEquipmentSlot;
import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_17_R1.scoreboard.CraftScoreboard;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Collections;
import java.util.List;
public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override
public int getNextEntityId() {
return Entity.nextEntityId();
}
@Override
public org.bukkit.entity.Entity getEntity(int entityId) {
net.minecraft.world.entity.Entity entity = getNMSEntity(entityId);
if (entity == null) return null;
return entity.getBukkitEntity();
}
private 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;
}
@Override
public org.bukkit.entity.Entity getInvisibleArmorstand(Location loc) {
InvisibleArmorstand invisibleArmorstand = new InvisibleArmorstand(loc);
return invisibleArmorstand.getBukkitEntity();
}
@Override
public ArmorStand getMEGEntity(Location loc) {
return (ArmorStand) new MEGEntity(loc).getBukkitEntity();
}
@Override
public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) {
InvisibleArmorstand invisibleArmorstand = new InvisibleArmorstand(user.getPlayer().getLocation());
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item));
((CraftWorld) user.getPlayer().getWorld()).getHandle().addFreshEntity(invisibleArmorstand);
MessagesUtil.sendDebugMessages("spawnBackpack NMS");
return invisibleArmorstand.getBukkitLivingEntity();
//PacketManager.armorStandMetaPacket(invisibleArmorstand.getBukkitEntity(), sentTo);
//PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo);
}
@Override
public BalloonEntity spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) {
Player player = user.getPlayer();
Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset());
BalloonEntity balloonEntity1 = new BalloonEntity(user.getPlayer().getLocation());
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation());
balloonEntity1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset()));
balloonEntity1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
balloonEntity1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getPufferfishBalloonId(), EntityType.PUFFERFISH, balloonEntity1.getPufferfishBalloonUniqueId(), sentTo);
PacketManager.sendInvisibilityPacket(balloonEntity1.getPufferfishBalloonId(), sentTo);
PacketManager.sendLeashPacket(balloonEntity1.getPufferfishBalloonId(), player.getEntityId(), sentTo);
return balloonEntity1;
}
@Override
public void equipmentSlotUpdate(
int entityId,
CosmeticUser user,
CosmeticSlot cosmeticSlot,
List<Player> sendTo
) {
EquipmentSlot nmsSlot = null;
net.minecraft.world.item.ItemStack nmsItem = null;
if (!(user.getCosmetic(cosmeticSlot) instanceof CosmeticArmorType)) {
if (user.getCosmetic(cosmeticSlot) instanceof CosmeticMainhandType) {
CosmeticMainhandType cosmeticMainhandType = (CosmeticMainhandType) user.getCosmetic(CosmeticSlot.MAINHAND);
nmsItem = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticMainhandType));
} else {
nmsItem = CraftItemStack.asNMSCopy(user.getPlayer().getInventory().getItem(InventoryUtils.getEquipmentSlot(cosmeticSlot)));
}
nmsSlot = CraftEquipmentSlot.getNMS(InventoryUtils.getEquipmentSlot(cosmeticSlot));
if (nmsSlot == null) return;
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
for (Player p : sendTo) sendPacket(p, packet);
return;
}
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(cosmeticSlot);
// Converting EquipmentSlot and ItemStack to NMS ones.
nmsSlot = CraftEquipmentSlot.getNMS(cosmeticArmor.getEquipSlot());
nmsItem = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticArmor));
if (nmsSlot == null) return;
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
for (Player p : sendTo) sendPacket(p, packet);
}
@Override
public void equipmentSlotUpdate(
int entityId,
org.bukkit.inventory.EquipmentSlot slot,
ItemStack item,
List<Player> sendTo
) {
EquipmentSlot nmsSlot = null;
net.minecraft.world.item.ItemStack nmsItem = null;
// Converting EquipmentSlot and ItemStack to NMS ones.
nmsSlot = CraftEquipmentSlot.getNMS(slot);
nmsItem = CraftItemStack.asNMSCopy(item);
if (nmsSlot == null) return;
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
for (Player p : sendTo) sendPacket(p, packet);
}
@Override
public void slotUpdate(
Player player,
int slot
) {
int index = 0;
ServerPlayer player1 = ((CraftPlayer) player).getHandle();
if (index < Inventory.getSelectionSize()) {
index += 36;
} else if (index > 39) {
index += 5; // Off hand
} else if (index > 35) {
index = 8 - (index - 36);
}
ItemStack item = player.getInventory().getItem(slot);
Packet packet = new ClientboundContainerSetSlotPacket(player1.inventoryMenu.containerId, player1.inventoryMenu.incrementStateId(), index, CraftItemStack.asNMSCopy(item));
sendPacket(player, packet);
}
public void hideNPCName(Player player, String NPCName) {
//Creating the team
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), NPCName);
//Setting name visibility
team.setNameTagVisibility(Team.Visibility.NEVER);
//Remove the Team (i assume so if it exists)
ClientboundSetPlayerTeamPacket removeTeamPacket = ClientboundSetPlayerTeamPacket.createRemovePacket(team);
sendPacket(player, removeTeamPacket);
//Creating the Team
ClientboundSetPlayerTeamPacket createTeamPacket = ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, true);
sendPacket(player, createTeamPacket);
//Adding players to the team (You have to use the NPC's name, and add it to a list)
ClientboundSetPlayerTeamPacket createPlayerTeamPacket = ClientboundSetPlayerTeamPacket.createPlayerPacket(team, NPCName, ClientboundSetPlayerTeamPacket.Action.ADD);
sendPacket(player, createPlayerTeamPacket);
}
public void sendPacket(Player player, Packet packet) {
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
ServerPlayerConnection connection = serverPlayer.connection;
connection.send(packet);
}
@Override
public boolean getSupported() {
return true;
}
}

27
v1_18_R2/build.gradle.kts Normal file
View File

@@ -0,0 +1,27 @@
plugins {
id("java")
id("io.papermc.paperweight.userdev") version "1.3.8"
}
dependencies {
paperDevBundle("1.18.2-R0.1-SNAPSHOT")
implementation(project(":common"))
}
tasks {
build {
dependsOn(reobfJar)
}
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(17)
}
javadoc {
options.encoding = Charsets.UTF_8.name()
}
processResources {
filteringCharset = Charsets.UTF_8.name()
}
}

View File

@@ -0,0 +1,24 @@
package com.hibiscusmc.hmccosmetics.nms.v1_18_R2;
import net.minecraft.world.entity.decoration.ArmorStand;
import net.minecraft.world.level.Level;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_18_R2.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);
setSilent(true);
getBukkitLivingEntity().setCollidable(false);
persist = false;
}
}

View File

@@ -0,0 +1,31 @@
package com.hibiscusmc.hmccosmetics.nms.v1_18_R2;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.decoration.ArmorStand;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
import org.bukkit.persistence.PersistentDataType;
public class MEGEntity extends ArmorStand {
public MEGEntity(Location loc) {
super(EntityType.ARMOR_STAND, ((CraftWorld) loc.getWorld()).getHandle());
this.setPos(loc.getX(), loc.getY(), loc.getZ());
MessagesUtil.sendDebugMessages("Spawned MEGEntity at " + loc);
setInvisible(true);
setNoGravity(true);
setSilent(true);
setInvulnerable(true);
setSmall(true);
setMarker(true);
persist = false;
getBukkitEntity().getPersistentDataContainer().set(new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticMob"), PersistentDataType.SHORT, Short.valueOf("1"));
((CraftWorld) loc.getWorld()).getHandle().addFreshEntity(this);
}
}

View File

@@ -0,0 +1,244 @@
package com.hibiscusmc.hmccosmetics.nms.v1_18_R2;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
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.cosmetic.types.CosmeticMainhandType;
import com.hibiscusmc.hmccosmetics.entities.BalloonEntity;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.mojang.datafixers.util.Pair;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerPlayerConnection;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.scores.PlayerTeam;
import net.minecraft.world.scores.Team;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_18_R2.CraftEquipmentSlot;
import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_18_R2.scoreboard.CraftScoreboard;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override
public int getNextEntityId() {
return Entity.nextEntityId();
}
@Override
public org.bukkit.entity.Entity getEntity(int entityId) {
net.minecraft.world.entity.Entity entity = getNMSEntity(entityId);
if (entity == null) return null;
return entity.getBukkitEntity();
}
private 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;
}
@Override
public org.bukkit.entity.Entity getInvisibleArmorstand(Location loc) {
InvisibleArmorstand invisibleArmorstand = new InvisibleArmorstand(loc);
return invisibleArmorstand.getBukkitEntity();
}
@Override
public ArmorStand getMEGEntity(Location loc) {
return (ArmorStand) new MEGEntity(loc).getBukkitEntity();
}
@Override
public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) {
InvisibleArmorstand invisibleArmorstand = new InvisibleArmorstand(user.getPlayer().getLocation());
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item));
((CraftWorld) user.getPlayer().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM);
MessagesUtil.sendDebugMessages("spawnBackpack NMS");
return invisibleArmorstand.getBukkitLivingEntity();
//PacketManager.armorStandMetaPacket(invisibleArmorstand.getBukkitEntity(), sentTo);
//PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo);
}
@Override
public BalloonEntity spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) {
Player player = user.getPlayer();
Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset());
BalloonEntity balloonEntity1 = new BalloonEntity(user.getPlayer().getLocation());
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation());
balloonEntity1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset()));
balloonEntity1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
balloonEntity1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getPufferfishBalloonId(), EntityType.PUFFERFISH, balloonEntity1.getPufferfishBalloonUniqueId(), sentTo);
PacketManager.sendInvisibilityPacket(balloonEntity1.getPufferfishBalloonId(), sentTo);
PacketManager.sendLeashPacket(balloonEntity1.getPufferfishBalloonId(), player.getEntityId(), sentTo);
return balloonEntity1;
}
@Override
public void equipmentSlotUpdate(
int entityId,
CosmeticUser user,
CosmeticSlot cosmeticSlot,
List<Player> sendTo
) {
EquipmentSlot nmsSlot = null;
net.minecraft.world.item.ItemStack nmsItem = null;
if (!(user.getCosmetic(cosmeticSlot) instanceof CosmeticArmorType)) {
if (user.getCosmetic(cosmeticSlot) instanceof CosmeticMainhandType) {
CosmeticMainhandType cosmeticMainhandType = (CosmeticMainhandType) user.getCosmetic(CosmeticSlot.MAINHAND);
nmsItem = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticMainhandType));
} else {
nmsItem = CraftItemStack.asNMSCopy(user.getPlayer().getInventory().getItem(InventoryUtils.getEquipmentSlot(cosmeticSlot)));
}
nmsSlot = CraftEquipmentSlot.getNMS(InventoryUtils.getEquipmentSlot(cosmeticSlot));
if (nmsSlot == null) return;
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
for (Player p : sendTo) sendPacket(p, packet);
return;
}
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(cosmeticSlot);
// Converting EquipmentSlot and ItemStack to NMS ones.
nmsSlot = CraftEquipmentSlot.getNMS(cosmeticArmor.getEquipSlot());
nmsItem = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticArmor));
if (nmsSlot == null) return;
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
for (Player p : sendTo) sendPacket(p, packet);
}
@Override
public void equipmentSlotUpdate(
int entityId,
org.bukkit.inventory.EquipmentSlot slot,
ItemStack item,
List<Player> sendTo
) {
EquipmentSlot nmsSlot = null;
net.minecraft.world.item.ItemStack nmsItem = null;
// Converting EquipmentSlot and ItemStack to NMS ones.
nmsSlot = CraftEquipmentSlot.getNMS(slot);
nmsItem = CraftItemStack.asNMSCopy(item);
if (nmsSlot == null) return;
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
for (Player p : sendTo) sendPacket(p, packet);
}
@Override
public void slotUpdate(
Player player,
int slot
) {
int index = 0;
ServerPlayer player1 = ((CraftPlayer) player).getHandle();
if (index < Inventory.getSelectionSize()) {
index += 36;
} else if (index > 39) {
index += 5; // Off hand
} else if (index > 35) {
index = 8 - (index - 36);
}
ItemStack item = player.getInventory().getItem(slot);
Packet packet = new ClientboundContainerSetSlotPacket(player1.inventoryMenu.containerId, player1.inventoryMenu.incrementStateId(), index, CraftItemStack.asNMSCopy(item));
sendPacket(player, packet);
}
public void hideNPCName(Player player, String NPCName) {
//Creating the team
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), NPCName);
//Setting name visibility
team.setNameTagVisibility(Team.Visibility.NEVER);
//Remove the Team (i assume so if it exists)
ClientboundSetPlayerTeamPacket removeTeamPacket = ClientboundSetPlayerTeamPacket.createRemovePacket(team);
sendPacket(player, removeTeamPacket);
//Creating the Team
ClientboundSetPlayerTeamPacket createTeamPacket = ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, true);
sendPacket(player, createTeamPacket);
//Adding players to the team (You have to use the NPC's name, and add it to a list)
ClientboundSetPlayerTeamPacket createPlayerTeamPacket = ClientboundSetPlayerTeamPacket.createMultiplePlayerPacket(team, new ArrayList<String>() {{
add(NPCName);
}}, ClientboundSetPlayerTeamPacket.Action.ADD);
sendPacket(player, createPlayerTeamPacket);
}
public void sendPacket(Player player, Packet packet) {
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
ServerPlayerConnection connection = serverPlayer.connection;
connection.send(packet);
}
@Override
public boolean getSupported() {
return true;
}
}

View File

@@ -17,6 +17,7 @@ public class InvisibleArmorstand extends ArmorStand {
setInvisible(true); setInvisible(true);
setInvulnerable(true); setInvulnerable(true);
setMarker(true); setMarker(true);
setSilent(true);
getBukkitLivingEntity().setCollidable(false); getBukkitLivingEntity().setCollidable(false);
persist = false; persist = false;
} }

View File

@@ -3,26 +3,27 @@ package com.hibiscusmc.hmccosmetics.nms.v1_19_R1;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.animal.Cod; import net.minecraft.world.entity.decoration.ArmorStand;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
public class MEGEntity extends Cod { public class MEGEntity extends ArmorStand {
public MEGEntity(Location loc) { public MEGEntity(Location loc) {
super(EntityType.COD, ((CraftWorld) loc.getWorld()).getHandle()); super(EntityType.ARMOR_STAND, ((CraftWorld) loc.getWorld()).getHandle());
this.setPos(loc.getX(), loc.getY(), loc.getZ()); this.setPos(loc.getX(), loc.getY(), loc.getZ());
MessagesUtil.sendDebugMessages("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;
MessagesUtil.sendDebugMessages("Spawned MEGEntity at " + loc);
setInvisible(true);
setNoGravity(true);
setSilent(true);
setInvulnerable(true);
setSmall(true);
setMarker(true);
persist = false;
getBukkitEntity().getPersistentDataContainer().set(new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticMob"), PersistentDataType.SHORT, Short.valueOf("1")); getBukkitEntity().getPersistentDataContainer().set(new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticMob"), PersistentDataType.SHORT, Short.valueOf("1"));
((CraftWorld) loc.getWorld()).getHandle().addFreshEntity(this); ((CraftWorld) loc.getWorld()).getHandle().addFreshEntity(this);

View File

@@ -33,6 +33,7 @@ import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_19_R1.scoreboard.CraftScoreboard; import org.bukkit.craftbukkit.v1_19_R1.scoreboard.CraftScoreboard;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
@@ -71,8 +72,8 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
} }
@Override @Override
public org.bukkit.entity.Entity getMEGEntity(Location loc) { public ArmorStand getMEGEntity(Location loc) {
return new MEGEntity(loc).getBukkitEntity(); return (ArmorStand) new MEGEntity(loc).getBukkitEntity();
} }
@Override @Override
@@ -103,8 +104,8 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation());
balloonEntity1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); balloonEntity1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset()));
balloonEntity1.spawnModel(cosmeticBalloonType.getModelName(), user.getCosmeticColor(cosmeticBalloonType.getSlot())); balloonEntity1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
balloonEntity1.addPlayerToModel(player, cosmeticBalloonType.getModelName(), user.getCosmeticColor(cosmeticBalloonType.getSlot())); balloonEntity1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getPufferfishBalloonId(), EntityType.PUFFERFISH, balloonEntity1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getPufferfishBalloonId(), EntityType.PUFFERFISH, balloonEntity1.getPufferfishBalloonUniqueId(), sentTo);
PacketManager.sendInvisibilityPacket(balloonEntity1.getPufferfishBalloonId(), sentTo); PacketManager.sendInvisibilityPacket(balloonEntity1.getPufferfishBalloonId(), sentTo);

View File

@@ -17,6 +17,7 @@ public class InvisibleArmorstand extends ArmorStand {
setInvisible(true); setInvisible(true);
setInvulnerable(true); setInvulnerable(true);
setMarker(true); setMarker(true);
setSilent(true);
getBukkitLivingEntity().setCollidable(false); getBukkitLivingEntity().setCollidable(false);
persist = false; persist = false;
} }

View File

@@ -3,28 +3,28 @@ package com.hibiscusmc.hmccosmetics.nms.v1_19_R2;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.animal.Cod; import net.minecraft.world.entity.decoration.ArmorStand;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; import org.bukkit.craftbukkit.v1_19_R2.CraftWorld;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
public class MEGEntity extends Cod { public class MEGEntity extends ArmorStand {
public MEGEntity(Location loc) {
super(EntityType.ARMOR_STAND, ((CraftWorld) loc.getWorld()).getHandle());
this.setPos(loc.getX(), loc.getY(), loc.getZ());
public MEGEntity(Location loc) { MessagesUtil.sendDebugMessages("Spawned MEGEntity at " + loc);
super(EntityType.COD, ((CraftWorld) loc.getWorld()).getHandle()); setInvisible(true);
this.setPos(loc.getX(), loc.getY(), loc.getZ()); setNoGravity(true);
MessagesUtil.sendDebugMessages("Spawned MEGEntity at " + loc); setSilent(true);
getBukkitLivingEntity().setInvisible(true); setInvulnerable(true);
getBukkitLivingEntity().setInvulnerable(true); // NOTE - CREATIVE PLAYERS CAN DESTROY IT STILL setSmall(true);
getBukkitLivingEntity().setAI(false); setMarker(true);
getBukkitLivingEntity().setGravity(false);
getBukkitLivingEntity().setSilent(true);
getBukkitLivingEntity().setCollidable(false);
persist = false;
getBukkitEntity().getPersistentDataContainer().set(new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticMob"), PersistentDataType.SHORT, Short.valueOf("1")); persist = false;
getBukkitEntity().getPersistentDataContainer().set(new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticMob"), PersistentDataType.SHORT, Short.valueOf("1"));
((CraftWorld) loc.getWorld()).getHandle().addFreshEntity(this); ((CraftWorld) loc.getWorld()).getHandle().addFreshEntity(this);
} }
} }

View File

@@ -33,6 +33,7 @@ import org.bukkit.craftbukkit.v1_19_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_19_R2.scoreboard.CraftScoreboard; import org.bukkit.craftbukkit.v1_19_R2.scoreboard.CraftScoreboard;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
@@ -71,8 +72,8 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
} }
@Override @Override
public org.bukkit.entity.Entity getMEGEntity(Location loc) { public ArmorStand getMEGEntity(Location loc) {
return new MEGEntity(loc).getBukkitEntity(); return (ArmorStand) new MEGEntity(loc).getBukkitEntity();
} }
@Override @Override
@@ -103,8 +104,8 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation());
balloonEntity1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); balloonEntity1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset()));
balloonEntity1.spawnModel(cosmeticBalloonType.getModelName(), user.getCosmeticColor(cosmeticBalloonType.getSlot())); balloonEntity1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
balloonEntity1.addPlayerToModel(player, cosmeticBalloonType.getModelName(), user.getCosmeticColor(cosmeticBalloonType.getSlot())); balloonEntity1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getPufferfishBalloonId(), EntityType.PUFFERFISH, balloonEntity1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getPufferfishBalloonId(), EntityType.PUFFERFISH, balloonEntity1.getPufferfishBalloonUniqueId(), sentTo);
PacketManager.sendInvisibilityPacket(balloonEntity1.getPufferfishBalloonId(), sentTo); PacketManager.sendInvisibilityPacket(balloonEntity1.getPufferfishBalloonId(), sentTo);