mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-20 15:39:16 +00:00
Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66c5fd86c5 | ||
|
|
80eb333b39 | ||
|
|
8b2b771a9b | ||
|
|
7873b3fe04 | ||
|
|
9854e77bf5 | ||
|
|
cad78636d0 | ||
|
|
14d256feed | ||
|
|
53163feb60 | ||
|
|
caf168d29d | ||
|
|
2a7686e6b7 | ||
|
|
5309c37902 | ||
|
|
ea1b87c128 | ||
|
|
9d92ed0dda | ||
|
|
e24d5697e7 | ||
|
|
8c59b27302 | ||
|
|
df3544726d | ||
|
|
27af0a6085 | ||
|
|
1db96c38d9 | ||
|
|
d9b92d5336 | ||
|
|
0905071dd2 | ||
|
|
1804e4691b | ||
|
|
223f8bdb9c | ||
|
|
c757752038 | ||
|
|
243644301a | ||
|
|
652b20c148 | ||
|
|
6c3ffbb71e | ||
|
|
fb6e5abb8b | ||
|
|
f546500f1e | ||
|
|
044528188d |
@@ -9,7 +9,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "com.hibiscusmc"
|
||||
version = "2.0.2"
|
||||
version = "2.1.0"
|
||||
|
||||
allprojects {
|
||||
apply(plugin = "java")
|
||||
@@ -54,19 +54,13 @@ allprojects {
|
||||
|
||||
// UpdateChecker
|
||||
maven("https://hub.jeff-media.com/nexus/repository/jeff-media-public/")
|
||||
|
||||
// ParticleHelper
|
||||
maven("https://repo.bytecode.space/repository/maven-public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(path = ":common"))
|
||||
implementation(project(path = ":v1_19_R1", 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")
|
||||
@@ -78,6 +72,16 @@ dependencies {
|
||||
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
|
||||
compileOnly("it.unimi.dsi:fastutil:8.5.11")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
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_R2", configuration = "reobf"))
|
||||
|
||||
//compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT")
|
||||
implementation("net.kyori:adventure-api:4.11.0")
|
||||
implementation ("net.kyori:adventure-text-minimessage:4.11.0")
|
||||
@@ -86,6 +90,7 @@ dependencies {
|
||||
implementation("org.spongepowered:configurate-yaml:4.1.2")
|
||||
implementation("org.bstats:bstats-bukkit:3.0.0")
|
||||
implementation("com.jeff_media:SpigotUpdateChecker:3.0.0")
|
||||
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
|
||||
}
|
||||
|
||||
tasks {
|
||||
@@ -109,6 +114,8 @@ tasks {
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
dependsOn(":v1_17_R1:reobfJar")
|
||||
dependsOn(":v1_18_R2:reobfJar")
|
||||
dependsOn(":v1_19_R1:reobfJar")
|
||||
dependsOn(":v1_19_R2:reobfJar")
|
||||
mergeServiceFiles()
|
||||
@@ -121,6 +128,7 @@ tasks {
|
||||
relocate("com.zaxxer.hikaricp", "com.hisbiscusmc.hmccosmetics.hikaricp")
|
||||
relocate("com.j256.ormlite", "com.hisbiscusmc.hmccosmetics.ormlite")
|
||||
relocate("com.jeff_media.updatechecker", "com.hisbiscusmc.hmccosmetics.updatechecker")
|
||||
relocate("com.woen1212055.particlehelper", "com.hisbiscusmc.hmccosmetics.particlehelper")
|
||||
archiveFileName.set("HMCCosmeticsRemapped-${project.version}.jar")
|
||||
|
||||
dependencies {
|
||||
@@ -145,7 +153,7 @@ tasks {
|
||||
bukkit {
|
||||
load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD
|
||||
main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin"
|
||||
apiVersion = "1.19"
|
||||
apiVersion = "1.16"
|
||||
authors = listOf("LoJoSho")
|
||||
depend = listOf("ProtocolLib", "PlaceholderAPI")
|
||||
softDepend = listOf("ModelEngine", "Oraxen", "ItemsAdder", "HMCColor", "WorldGuard", "MythicMobs")
|
||||
|
||||
@@ -24,6 +24,7 @@ dependencies {
|
||||
implementation("org.spongepowered:configurate-yaml:4.1.2")
|
||||
implementation("org.bstats:bstats-bukkit:3.0.0")
|
||||
implementation("com.jeff_media:SpigotUpdateChecker:3.0.0")
|
||||
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
|
||||
}
|
||||
|
||||
java {
|
||||
|
||||
@@ -8,10 +8,12 @@ import org.bukkit.event.HandlerList;
|
||||
public class PlayerCosmeticHideEvent extends Event implements Cancellable {
|
||||
|
||||
private CosmeticUser user;
|
||||
private CosmeticUser.HiddenReason reason;
|
||||
private boolean isCancelled;
|
||||
|
||||
public PlayerCosmeticHideEvent(CosmeticUser user) {
|
||||
public PlayerCosmeticHideEvent(CosmeticUser user, CosmeticUser.HiddenReason reason) {
|
||||
this.user = user;
|
||||
this.reason = reason;
|
||||
this.isCancelled = false;
|
||||
}
|
||||
|
||||
@@ -39,4 +41,7 @@ public class PlayerCosmeticHideEvent extends Event implements Cancellable {
|
||||
public CosmeticUser getUser() {
|
||||
return user;
|
||||
}
|
||||
public CosmeticUser.HiddenReason getReason() {
|
||||
return reason;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,9 +326,8 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
|
||||
MessagesUtil.sendMessage(sender, "hide-cosmetic");
|
||||
user.hideCosmetics();
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
|
||||
return true;
|
||||
}
|
||||
case ("show") -> {
|
||||
|
||||
@@ -2,11 +2,13 @@ package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
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.util.MessagesUtil;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
@@ -14,6 +16,7 @@ import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Cosmetics {
|
||||
|
||||
@@ -78,23 +81,27 @@ public class Cosmetics {
|
||||
|
||||
private static void setupCosmetics(CommentedConfigurationNode config) {
|
||||
for (ConfigurationNode cosmeticConfig : config.childrenMap().values()) {
|
||||
try {
|
||||
String id = cosmeticConfig.key().toString();
|
||||
MessagesUtil.sendDebugMessages("Attempting to add " + id);
|
||||
ConfigurationNode slotNode = cosmeticConfig.node("slot");
|
||||
if (slotNode.virtual()) {
|
||||
MessagesUtil.sendDebugMessages("Unable to create " + id + " because there is no slot defined!", Level.WARNING);
|
||||
continue;
|
||||
}
|
||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, slotNode.getString())) {
|
||||
MessagesUtil.sendDebugMessages("Unable to create " + id + " because " + slotNode.getString() + " is not a valid slot!", Level.WARNING);
|
||||
continue;
|
||||
}
|
||||
switch (CosmeticSlot.valueOf(cosmeticConfig.node("slot").getString())) {
|
||||
case BALLOON -> {
|
||||
new CosmeticBalloonType(id, cosmeticConfig);
|
||||
case BALLOON -> new CosmeticBalloonType(id, cosmeticConfig);
|
||||
case BACKPACK -> new CosmeticBackpackType(id, cosmeticConfig);
|
||||
case MAINHAND -> new CosmeticMainhandType(id, cosmeticConfig);
|
||||
default -> new CosmeticArmorType(id, cosmeticConfig);
|
||||
}
|
||||
case BACKPACK -> {
|
||||
new CosmeticBackpackType(id, cosmeticConfig);
|
||||
} catch (Exception e) {
|
||||
if (Settings.isDebugEnabled()) e.printStackTrace();
|
||||
}
|
||||
case MAINHAND -> {
|
||||
new CosmeticMainhandType(id, cosmeticConfig);
|
||||
}
|
||||
default -> {
|
||||
new CosmeticArmorType(id, cosmeticConfig);
|
||||
}
|
||||
}
|
||||
//new Cosmetic(id, cosmeticConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,8 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
Player player = Bukkit.getPlayer(user.getUniqueId());
|
||||
Location loc = player.getLocation().clone();
|
||||
|
||||
if (user.isInWardrobe()) return;
|
||||
|
||||
if (loc.getWorld() != user.getBackpackEntity().getWorld()) {
|
||||
user.getBackpackEntity().teleport(loc);
|
||||
}
|
||||
|
||||
@@ -5,22 +5,45 @@ import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.entities.BalloonEntity;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class CosmeticBalloonType extends Cosmetic {
|
||||
|
||||
private String modelName;
|
||||
private List<String> dyableParts;
|
||||
//private HashMap<Animations, String> animationBalloons;
|
||||
|
||||
public CosmeticBalloonType(String id, ConfigurationNode config) {
|
||||
super(id, config);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -43,9 +66,9 @@ public class CosmeticBalloonType extends Cosmetic {
|
||||
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.setVelocity(velocity);
|
||||
|
||||
PacketManager.sendTeleportPacket(balloonEntity.getPufferfishBalloonId(), newLocation, false, viewer);
|
||||
if (!user.getHidden()) PacketManager.sendLeashPacket(balloonEntity.getPufferfishBalloonId(), player.getEntityId(), viewer);
|
||||
@@ -54,4 +77,21 @@ public class CosmeticBalloonType extends Cosmetic {
|
||||
public String getModelName() {
|
||||
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);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package com.hibiscusmc.hmccosmetics.entities;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.ticxo.modelengine.api.ModelEngineAPI;
|
||||
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||
import com.ticxo.modelengine.api.model.ModeledEntity;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
@@ -15,13 +18,12 @@ import org.bukkit.util.Vector;
|
||||
import java.util.UUID;
|
||||
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 {
|
||||
|
||||
private BalloonType balloonType;
|
||||
private final int balloonID;
|
||||
private final UUID uniqueID;
|
||||
private final Entity modelEntity;
|
||||
private ModeledEntity modeledEntity;
|
||||
private final ArmorStand modelEntity;
|
||||
|
||||
public BalloonEntity(Location location) {
|
||||
this.uniqueID = UUID.randomUUID();
|
||||
@@ -29,8 +31,21 @@ public class BalloonEntity {
|
||||
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);
|
||||
|
||||
if (balloonType == BalloonType.MODELENGINE) {
|
||||
String id = cosmeticBalloonType.getModelName();
|
||||
MessagesUtil.sendDebugMessages("Attempting Spawning for " + id);
|
||||
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(id) == null) {
|
||||
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + id, Level.SEVERE);
|
||||
@@ -42,14 +57,21 @@ public class BalloonEntity {
|
||||
modeledEntity.addModel(model, false);
|
||||
if (color != null) {
|
||||
modeledEntity.getModels().forEach((d, singleModel) -> {
|
||||
if (cosmeticBalloonType.isDyablePart(d)) {
|
||||
singleModel.getRendererHandler().setColor(color);
|
||||
singleModel.getRendererHandler().update();
|
||||
}
|
||||
});
|
||||
}
|
||||
this.modeledEntity = modeledEntity;
|
||||
return;
|
||||
}
|
||||
if (balloonType == BalloonType.ITEM) {
|
||||
modelEntity.getEquipment().setHelmet(cosmeticBalloonType.getItem());
|
||||
}
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
if (balloonType == BalloonType.MODELENGINE) {
|
||||
final ModeledEntity entity = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
|
||||
|
||||
if (entity == null) return;
|
||||
@@ -57,34 +79,47 @@ public class BalloonEntity {
|
||||
for (final Player player : entity.getRangeManager().getPlayerInRange()) {
|
||||
entity.hideFromPlayer(player);
|
||||
}
|
||||
|
||||
//ModelEngineAPI.removeModeledEntity(megEntity.getUniqueId());
|
||||
entity.destroy();
|
||||
}
|
||||
|
||||
modelEntity.remove();
|
||||
}
|
||||
|
||||
public void addPlayerToModel(final Player player, final String id) {
|
||||
addPlayerToModel(player, id, null);
|
||||
public void addPlayerToModel(final CosmeticUser user, final CosmeticBalloonType cosmeticBalloonType) {
|
||||
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) {
|
||||
if (balloonType == BalloonType.MODELENGINE) {
|
||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
|
||||
if (model == null) {
|
||||
spawnModel(id, color);
|
||||
spawnModel(cosmeticBalloonType, color);
|
||||
MessagesUtil.sendDebugMessages("model is null");
|
||||
return;
|
||||
}
|
||||
//if (model.getRangeManager().getPlayerInRange().contains(player)) return;
|
||||
model.showToPlayer(player);
|
||||
model.showToPlayer(user.getPlayer());
|
||||
MessagesUtil.sendDebugMessages("Show to player");
|
||||
return;
|
||||
}
|
||||
if (balloonType == BalloonType.ITEM) {
|
||||
modelEntity.getEquipment().setHelmet(user.getUserCosmeticItem(cosmeticBalloonType));
|
||||
}
|
||||
}
|
||||
public void removePlayerFromModel(final Player player) {
|
||||
if (balloonType == BalloonType.MODELENGINE) {
|
||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
|
||||
|
||||
if (model == null) return;
|
||||
|
||||
model.hideFromPlayer(player);
|
||||
MessagesUtil.sendDebugMessages("Hidden from player");
|
||||
return;
|
||||
}
|
||||
if (balloonType == BalloonType.ITEM) {
|
||||
modelEntity.getEquipment().clear();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public Entity getModelEntity() {
|
||||
@@ -118,4 +153,10 @@ public class BalloonEntity {
|
||||
public void setVelocity(Vector vector) {
|
||||
this.getModelEntity().setVelocity(vector);
|
||||
}
|
||||
|
||||
public enum BalloonType {
|
||||
MODELENGINE,
|
||||
ITEM,
|
||||
NONE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.Types;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.PAPIHook;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.Adventure;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.Placeholder;
|
||||
@@ -137,8 +138,6 @@ public class Menu {
|
||||
MessagesUtil.sendDebugMessages("something went wrong! " + item);
|
||||
continue;
|
||||
}
|
||||
ItemStack originalItem = item.clone();
|
||||
item = updateLore(player, item);
|
||||
|
||||
Type type = null;
|
||||
|
||||
@@ -147,6 +146,9 @@ public class Menu {
|
||||
if (Types.isType(typeId)) type = Types.getType(typeId);
|
||||
}
|
||||
|
||||
ItemStack originalItem = item.clone();
|
||||
item = updateLore(user, item, type, config);
|
||||
|
||||
GuiItem guiItem = ItemBuilder.from(item).asGuiItem();
|
||||
|
||||
Type finalType = type;
|
||||
@@ -155,7 +157,7 @@ public class Menu {
|
||||
if (finalType != null) finalType.run(user, config, clickType);
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
@@ -190,21 +192,9 @@ public class Menu {
|
||||
return slots;
|
||||
}
|
||||
|
||||
private ItemStack updateLore(Player player, ItemStack itemStack) {
|
||||
private ItemStack updateLore(CosmeticUser user, ItemStack itemStack, Type type, ConfigurationNode config) {
|
||||
if (itemStack.hasItemMeta()) {
|
||||
List<String> processedLore = new ArrayList<>();
|
||||
|
||||
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);
|
||||
itemStack.setItemMeta(type.setLore(user, config, itemStack.getItemMeta()));
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
@@ -12,6 +13,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Menus {
|
||||
|
||||
@@ -67,7 +69,12 @@ public class Menus {
|
||||
} catch (ConfigurateException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ public class Actions {
|
||||
private static ActionPlayerCommand ACTION_CONSOLE_COMMAND = new ActionPlayerCommand();
|
||||
private static ActionConsoleCommand ACTION_PLAYER_COMMAND = new ActionConsoleCommand();
|
||||
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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,10 @@ public class DyeMenu {
|
||||
//user.removeCosmeticSlot(cosmetic);
|
||||
user.addPlayerCosmetic(cosmetic, color);
|
||||
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);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,18 +1,28 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.type.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
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.special.DyeMenu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.PAPIHook;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
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.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TypeCosmetic extends Type {
|
||||
|
||||
@@ -70,7 +80,73 @@ public class TypeCosmetic extends Type {
|
||||
} catch (SerializationException 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,11 @@ package com.hibiscusmc.hmccosmetics.gui.type.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Actions;
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.PAPIHook;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
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.
|
||||
// If you need help with that, check the Types class.
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ public class ItemAdderHook extends ItemHook implements Listener {
|
||||
@Override
|
||||
public ItemStack get(String itemid) {
|
||||
if (enabled) {
|
||||
return CustomStack.getInstance(itemid).getItemStack();
|
||||
CustomStack stack = CustomStack.getInstance(itemid);
|
||||
if (stack == null) return null;
|
||||
return stack.getItemStack();
|
||||
} else {
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class WGListener implements Listener {
|
||||
}
|
||||
for (ProtectedRegion protectedRegion : set.getRegions()) {
|
||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
|
||||
user.hideCosmetics();
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||
return;
|
||||
}
|
||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
|
||||
|
||||
@@ -24,10 +24,12 @@ import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
@@ -35,6 +37,7 @@ import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -196,6 +199,23 @@ public class PlayerGameListener implements Listener {
|
||||
}, 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
|
||||
public void onMainHandSwitch(PlayerItemHeldEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
@@ -278,6 +298,7 @@ public class PlayerGameListener implements Listener {
|
||||
}
|
||||
}
|
||||
packet.getItemListModifier().write(0, slotData);
|
||||
packet.getItemModifier().write(0, event.getPacket().getItemModifier().read(0));
|
||||
event.setPacket(packet);
|
||||
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) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
MessagesUtil.sendDebugMessages("equipment packet is activated");
|
||||
Player player = event.getPlayer(); // Player that's sent
|
||||
int entityID = event.getPacket().getIntegers().read(0);
|
||||
// User
|
||||
CosmeticUser user = CosmeticUsers.getUser(entityID);
|
||||
if (user == null) {
|
||||
MessagesUtil.sendDebugMessages("equipment packet is activated - user null");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.entities.BalloonEntity;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -20,7 +21,7 @@ public interface NMSHandler {
|
||||
|
||||
Entity getInvisibleArmorstand(Location loc);
|
||||
|
||||
Entity getMEGEntity(Location loc);
|
||||
ArmorStand getMEGEntity(Location loc);
|
||||
|
||||
Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.logging.Level;
|
||||
|
||||
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 String version;
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ public class CosmeticUser {
|
||||
// Cosmetic Settings/Toggles
|
||||
private boolean hideBackpack;
|
||||
private boolean hideCosmetics;
|
||||
private HiddenReason hiddenReason;
|
||||
private HashMap<CosmeticSlot, Color> colors = new HashMap<>();
|
||||
|
||||
public CosmeticUser() {
|
||||
@@ -246,9 +247,25 @@ public class CosmeticUser {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (!getWardrobe().getWardrobeStatus().equals(Wardrobe.WardrobeStatus.RUNNING)) return;
|
||||
|
||||
getWardrobe().setWardrobeStatus(Wardrobe.WardrobeStatus.STOPPING);
|
||||
|
||||
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() {
|
||||
@@ -306,6 +323,20 @@ public class CosmeticUser {
|
||||
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) {
|
||||
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;
|
||||
PlayerCosmeticHideEvent event = new PlayerCosmeticHideEvent(this);
|
||||
PlayerCosmeticHideEvent event = new PlayerCosmeticHideEvent(this, reason);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
hideCosmetics = true;
|
||||
hiddenReason = reason;
|
||||
if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||
getBalloonEntity().removePlayerFromModel(getPlayer());
|
||||
List<Player> viewer = PlayerUtils.getNearbyPlayers(getPlayer());
|
||||
@@ -399,10 +431,12 @@ public class CosmeticUser {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
hideCosmetics = false;
|
||||
hiddenReason = HiddenReason.NONE;
|
||||
if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||
CosmeticBalloonType balloonType = (CosmeticBalloonType) getCosmetic(CosmeticSlot.BALLOON);
|
||||
getBalloonEntity().addPlayerToModel(getPlayer(), balloonType.getModelName());
|
||||
getBalloonEntity().addPlayerToModel(this, balloonType);
|
||||
List<Player> viewer = PlayerUtils.getNearbyPlayers(getPlayer());
|
||||
PacketManager.sendLeashPacket(getBalloonEntity().getPufferfishBalloonId(), getPlayer().getEntityId(), viewer);
|
||||
}
|
||||
@@ -418,4 +452,14 @@ public class CosmeticUser {
|
||||
public boolean getHidden() {
|
||||
return this.hideCosmetics;
|
||||
}
|
||||
|
||||
public HiddenReason getHiddenReason() {
|
||||
return hiddenReason;
|
||||
}
|
||||
|
||||
public enum HiddenReason {
|
||||
NONE,
|
||||
WORLDGUARD,
|
||||
PLUGIN
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,15 +39,18 @@ public class Wardrobe {
|
||||
private Location exitLocation;
|
||||
private BossBar bossBar;
|
||||
private boolean active;
|
||||
private WardrobeStatus wardrobeStatus;
|
||||
|
||||
public Wardrobe(CosmeticUser user) {
|
||||
NPC_ID = NMSHandlers.getHandler().getNextEntityId();
|
||||
ARMORSTAND_ID = NMSHandlers.getHandler().getNextEntityId();
|
||||
WARDROBE_UUID = UUID.randomUUID();
|
||||
VIEWER = user;
|
||||
wardrobeStatus = WardrobeStatus.SETUP;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
setWardrobeStatus(WardrobeStatus.STARTING);
|
||||
Player player = VIEWER.getPlayer();
|
||||
|
||||
this.originalGamemode = player.getGameMode();
|
||||
@@ -62,6 +65,8 @@ public class Wardrobe {
|
||||
|
||||
VIEWER.hidePlayer();
|
||||
List<Player> viewer = List.of(player);
|
||||
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
|
||||
outsideViewers.remove(player);
|
||||
|
||||
MessagesUtil.sendMessage(player, "opened-wardrobe");
|
||||
|
||||
@@ -119,6 +124,7 @@ public class Wardrobe {
|
||||
|
||||
this.active = true;
|
||||
update();
|
||||
setWardrobeStatus(WardrobeStatus.RUNNING);
|
||||
};
|
||||
|
||||
|
||||
@@ -138,9 +144,12 @@ public class Wardrobe {
|
||||
}
|
||||
|
||||
public void end() {
|
||||
setWardrobeStatus(WardrobeStatus.STOPPING);
|
||||
Player player = VIEWER.getPlayer();
|
||||
|
||||
List<Player> viewer = List.of(player);
|
||||
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
|
||||
outsideViewers.remove(player);
|
||||
|
||||
MessagesUtil.sendMessage(player, "closed-wardrobe");
|
||||
|
||||
@@ -164,11 +173,13 @@ public class Wardrobe {
|
||||
VIEWER.showPlayer();
|
||||
|
||||
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)) {
|
||||
PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), viewer);
|
||||
VIEWER.respawnBalloon();
|
||||
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), viewer);
|
||||
}
|
||||
|
||||
if (exitLocation == null) {
|
||||
@@ -189,20 +200,8 @@ public class Wardrobe {
|
||||
|
||||
VIEWER.updateCosmetic();
|
||||
};
|
||||
|
||||
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() {
|
||||
final AtomicInteger data = new AtomicInteger();
|
||||
@@ -217,13 +216,15 @@ public class Wardrobe {
|
||||
}
|
||||
MessagesUtil.sendDebugMessages("Update ");
|
||||
List<Player> viewer = List.of(VIEWER.getPlayer());
|
||||
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
|
||||
outsideViewers.remove(VIEWER.getPlayer());
|
||||
|
||||
Location location = WardrobeSettings.getWardrobeLocation().clone();
|
||||
int yaw = data.get();
|
||||
location.setYaw(yaw);
|
||||
|
||||
PacketManager.sendLookPacket(NPC_ID, location, viewer);
|
||||
//VIEWER.updateCosmetic();
|
||||
VIEWER.hidePlayer();
|
||||
int rotationSpeed = WardrobeSettings.getRotationSpeed();
|
||||
location.setYaw(getNextYaw(yaw - 30, rotationSpeed));
|
||||
PacketManager.sendRotationPacket(NPC_ID, location, true, viewer);
|
||||
@@ -238,11 +239,14 @@ public class Wardrobe {
|
||||
PacketManager.sendTeleportPacket(VIEWER.getArmorstandId(), location, false, viewer);
|
||||
PacketManager.ridingMountPacket(NPC_ID, VIEWER.getBackpackEntity().getEntityId(), viewer);
|
||||
VIEWER.getBackpackEntity().setRotation(nextyaw, 0);
|
||||
PacketManager.sendEntityDestroyPacket(VIEWER.getArmorstandId(), outsideViewers);
|
||||
}
|
||||
|
||||
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||
PacketManager.sendTeleportPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()), false, viewer);
|
||||
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?
|
||||
}
|
||||
|
||||
@@ -267,4 +271,19 @@ public class Wardrobe {
|
||||
public int getArmorstandId() {
|
||||
return ARMORSTAND_ID;
|
||||
}
|
||||
|
||||
public WardrobeStatus getWardrobeStatus() {
|
||||
return wardrobeStatus;
|
||||
}
|
||||
|
||||
public void setWardrobeStatus(WardrobeStatus status) {
|
||||
this.wardrobeStatus = status;
|
||||
}
|
||||
|
||||
public enum WardrobeStatus {
|
||||
SETUP,
|
||||
STARTING,
|
||||
RUNNING,
|
||||
STOPPING,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ public class MessagesUtil {
|
||||
|
||||
public static void sendMessage(CommandSender sender, String key) {
|
||||
Component finalMessage = processString(null, key);
|
||||
if (finalMessage == null) return;
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).sender(sender);
|
||||
|
||||
target.sendMessage(finalMessage);
|
||||
@@ -130,7 +131,7 @@ public class MessagesUtil {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
package com.hibiscusmc.hmccosmetics.util;
|
||||
|
||||
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.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ServerUtils {
|
||||
|
||||
@@ -36,4 +46,84 @@ public class ServerUtils {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ cosmetic-settings:
|
||||
y: 3
|
||||
z: 0.5
|
||||
dye-menu:
|
||||
title: "<white>"
|
||||
title: "§f"
|
||||
wardrobe:
|
||||
# spawn static wardrobe if in this radius of wardrobe-location
|
||||
static-radius: 10
|
||||
@@ -48,6 +48,7 @@ wardrobe:
|
||||
text: "Left-Click to open the menu!"
|
||||
progress: 1.0 # Goes between 0.0 -> 1.0
|
||||
overlay: PROGRESS
|
||||
color: BLUE
|
||||
transition:
|
||||
enabled: true
|
||||
text: "<black>"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
title: "<white>"
|
||||
rows: 5
|
||||
rows: 6
|
||||
items:
|
||||
beanie:
|
||||
slots:
|
||||
- 1
|
||||
- 0
|
||||
item:
|
||||
material: hmccosmetics:beanie
|
||||
lore:
|
||||
@@ -14,7 +14,7 @@ items:
|
||||
cosmetic: beanie
|
||||
backpack:
|
||||
slots:
|
||||
- 2
|
||||
- 1
|
||||
item:
|
||||
material: hmccosmetics:backpack
|
||||
lore:
|
||||
@@ -25,7 +25,7 @@ items:
|
||||
cosmetic: backpack
|
||||
future_wings:
|
||||
slots:
|
||||
- 3
|
||||
- 2
|
||||
item:
|
||||
material: hmccosmetics:future_wings
|
||||
lore:
|
||||
@@ -36,7 +36,7 @@ items:
|
||||
cosmetic: future_wings
|
||||
lantern_cosmetic:
|
||||
slots:
|
||||
- 4
|
||||
- 3
|
||||
item:
|
||||
material: hmccosmetics:lantern_cosmetic
|
||||
lore:
|
||||
@@ -47,7 +47,7 @@ items:
|
||||
cosmetic: lantern_cosmetic
|
||||
baseball_hat:
|
||||
slots:
|
||||
- 5
|
||||
- 4
|
||||
item:
|
||||
material: hmccosmetics:baseball_hat
|
||||
lore:
|
||||
@@ -58,7 +58,7 @@ items:
|
||||
cosmetic: baseball_hat
|
||||
frog_hat:
|
||||
slots:
|
||||
- 6
|
||||
- 5
|
||||
item:
|
||||
material: hmccosmetics:frog_hat
|
||||
lore:
|
||||
@@ -69,7 +69,7 @@ items:
|
||||
cosmetic: frog_hat
|
||||
jetpack:
|
||||
slots:
|
||||
- 7
|
||||
- 6
|
||||
item:
|
||||
material: hmccosmetics:jetpack
|
||||
lore:
|
||||
@@ -80,7 +80,7 @@ items:
|
||||
cosmetic: jetpack
|
||||
hammer:
|
||||
slots:
|
||||
- 10
|
||||
- 7
|
||||
item:
|
||||
material: hmccosmetics:hammer
|
||||
lore:
|
||||
@@ -91,7 +91,7 @@ items:
|
||||
cosmetic: hammer
|
||||
chestplate:
|
||||
slots:
|
||||
- 11
|
||||
- 8
|
||||
item:
|
||||
material: hmccosmetics:chestplate
|
||||
lore:
|
||||
@@ -102,7 +102,7 @@ items:
|
||||
cosmetic: chestplate
|
||||
pants:
|
||||
slots:
|
||||
- 12
|
||||
- 9
|
||||
item:
|
||||
material: hmccosmetics:pants
|
||||
lore:
|
||||
@@ -113,7 +113,7 @@ items:
|
||||
cosmetic: pants
|
||||
boots:
|
||||
slots:
|
||||
- 13
|
||||
- 10
|
||||
item:
|
||||
material: hmccosmetics:boots
|
||||
lore:
|
||||
@@ -124,7 +124,7 @@ items:
|
||||
cosmetic: boots
|
||||
kite:
|
||||
slots:
|
||||
- 14
|
||||
- 11
|
||||
item:
|
||||
material: hmccosmetics:kite
|
||||
lore:
|
||||
|
||||
@@ -7,6 +7,8 @@ pluginManagement {
|
||||
rootProject.name = "HMCCosmetics"
|
||||
include(
|
||||
"common",
|
||||
"v1_17_R1",
|
||||
"v1_18_R2",
|
||||
"v1_19_R1",
|
||||
"v1_19_R2"
|
||||
)
|
||||
|
||||
27
v1_17_R1/build.gradle.kts
Normal file
27
v1_17_R1/build.gradle.kts
Normal 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()
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
27
v1_18_R2/build.gradle.kts
Normal 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()
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ public class InvisibleArmorstand extends ArmorStand {
|
||||
setInvisible(true);
|
||||
setInvulnerable(true);
|
||||
setMarker(true);
|
||||
setSilent(true);
|
||||
getBukkitLivingEntity().setCollidable(false);
|
||||
persist = false;
|
||||
}
|
||||
|
||||
@@ -3,26 +3,27 @@ package com.hibiscusmc.hmccosmetics.nms.v1_19_R1;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
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.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class MEGEntity extends Cod {
|
||||
public class MEGEntity extends ArmorStand {
|
||||
|
||||
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());
|
||||
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"));
|
||||
|
||||
((CraftWorld) loc.getWorld()).getHandle().addFreshEntity(this);
|
||||
|
||||
@@ -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.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.scoreboard.CraftScoreboard;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
@@ -71,8 +72,8 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getMEGEntity(Location loc) {
|
||||
return new MEGEntity(loc).getBukkitEntity();
|
||||
public ArmorStand getMEGEntity(Location loc) {
|
||||
return (ArmorStand) new MEGEntity(loc).getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,8 +104,8 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
|
||||
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation());
|
||||
balloonEntity1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset()));
|
||||
|
||||
balloonEntity1.spawnModel(cosmeticBalloonType.getModelName(), user.getCosmeticColor(cosmeticBalloonType.getSlot()));
|
||||
balloonEntity1.addPlayerToModel(player, cosmeticBalloonType.getModelName(), user.getCosmeticColor(cosmeticBalloonType.getSlot()));
|
||||
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);
|
||||
|
||||
@@ -17,6 +17,7 @@ public class InvisibleArmorstand extends ArmorStand {
|
||||
setInvisible(true);
|
||||
setInvulnerable(true);
|
||||
setMarker(true);
|
||||
setSilent(true);
|
||||
getBukkitLivingEntity().setCollidable(false);
|
||||
persist = false;
|
||||
}
|
||||
|
||||
@@ -3,26 +3,26 @@ package com.hibiscusmc.hmccosmetics.nms.v1_19_R2;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
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.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.CraftWorld;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class MEGEntity extends Cod {
|
||||
|
||||
public class MEGEntity extends ArmorStand {
|
||||
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());
|
||||
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"));
|
||||
|
||||
((CraftWorld) loc.getWorld()).getHandle().addFreshEntity(this);
|
||||
|
||||
@@ -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.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.scoreboard.CraftScoreboard;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
@@ -71,8 +72,8 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getMEGEntity(Location loc) {
|
||||
return new MEGEntity(loc).getBukkitEntity();
|
||||
public ArmorStand getMEGEntity(Location loc) {
|
||||
return (ArmorStand) new MEGEntity(loc).getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,8 +104,8 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
|
||||
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation());
|
||||
balloonEntity1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset()));
|
||||
|
||||
balloonEntity1.spawnModel(cosmeticBalloonType.getModelName(), user.getCosmeticColor(cosmeticBalloonType.getSlot()));
|
||||
balloonEntity1.addPlayerToModel(player, cosmeticBalloonType.getModelName(), user.getCosmeticColor(cosmeticBalloonType.getSlot()));
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user