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

Work on Balloon dyeing

This commit is contained in:
LoJoSho
2022-12-09 11:37:32 -06:00
parent c44620fafc
commit 9f0dc320e8
7 changed files with 47 additions and 13 deletions

View File

@@ -3,6 +3,8 @@ package com.hibiscusmc.hmccosmetics.command;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -12,7 +14,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -32,6 +33,9 @@ public class CosmeticCommandTabComplete implements TabCompleter {
completions.add("dye");
}
if (!(sender instanceof Player)) return completions;
CosmeticUser user = CosmeticUsers.getUser(((Player) sender).getUniqueId());
// This needs to be redone.
if (args.length >= 2) {
if (args[0].equalsIgnoreCase("apply")) {
@@ -47,7 +51,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
completions.add(player.getName());
}
} else if (args[0].equalsIgnoreCase("dye")) {
for (CosmeticSlot slot : CosmeticSlot.values()) {
for (CosmeticSlot slot : user.getDyeableSlots()) {
completions.add(slot.name());
}
}

View File

@@ -21,6 +21,8 @@ public class Cosmetic {
setEquipable(false);
setDyable(config.node("dyeable").getBoolean(false));
HMCCosmeticsPlugin.getInstance().getLogger().info("Dyeable " + dyable);
Cosmetics.addCosmetic(this);
}
@@ -71,5 +73,4 @@ public class Cosmetic {
public void update(CosmeticUser user) {
// Override
}
}

View File

@@ -7,6 +7,9 @@ import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.ticxo.modelengine.api.ModelEngineAPI;
import com.ticxo.modelengine.api.model.ActiveModel;
import com.ticxo.modelengine.api.model.ModeledEntity;
import com.ticxo.modelengine.api.nms.entity.fake.BoneRenderer;
import com.ticxo.modelengine.api.nms.entity.fake.FakeEntity;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@@ -27,7 +30,7 @@ public class BalloonEntity {
this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset()));
}
public void spawnModel(final String id) {
public void spawnModel(final String id, Color color) {
HMCCosmeticsPlugin.getInstance().getLogger().info("Attempting Spawning for " + id);
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(id) == null) {
HMCCosmeticsPlugin.getInstance().getLogger().warning("Invalid Model Engine Blueprint " + id);
@@ -36,6 +39,11 @@ public class BalloonEntity {
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(modelEntity);
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(id));
modeledEntity.addModel(model, false);
if (color != null) {
modeledEntity.getModels().forEach((d, singleModel) -> {
singleModel.getRendererHandler().setColor(color);
});
}
}
public void remove() {
@@ -49,12 +57,17 @@ public class BalloonEntity {
//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 Player player, final String id, Color color) {
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
if (model == null) {
spawnModel(id);
spawnModel(id, color);
return;
}
if (model.getRangeManager().getPlayerInRange().contains(player)) return;

View File

@@ -5,6 +5,7 @@ import com.hibiscusmc.hmccolor.gui.guis.Gui;
import com.hibiscusmc.hmccolor.gui.guis.GuiItem;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.misc.Placeholder;
import org.bukkit.Color;
@@ -20,7 +21,6 @@ public class DyeMenu {
public static void openMenu(CosmeticUser user, Cosmetic cosmetic) {
ItemStack originalItem = user.getUserCosmeticItem(cosmetic);
if (originalItem == null || !cosmetic.isDyable()) return;

View File

@@ -13,6 +13,7 @@ import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@@ -20,10 +21,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.*;
public class CosmeticUser {
@@ -141,6 +139,9 @@ public class CosmeticUser {
item = cosmetic1.getBackpackItem();
HMCCosmeticsPlugin.getInstance().getLogger().info("GetUserCosemticUser Backpack");
}
if (cosmetic instanceof CosmeticBalloonType) {
item = new ItemStack(Material.LEATHER_HORSE_ARMOR);
}
if (item == null) {
HMCCosmeticsPlugin.getInstance().getLogger().info("GetUserCosemticUser Item is null");
return null;
@@ -238,6 +239,20 @@ public class CosmeticUser {
return Bukkit.getPlayer(uniqueId);
}
public Color getCosmeticColor(CosmeticSlot slot) {
return colors.get(slot);
}
public List<CosmeticSlot> getDyeableSlots() {
ArrayList<CosmeticSlot> dyableSlots = new ArrayList();
for (Cosmetic cosmetic : getCosmetic()) {
if (cosmetic.isDyable()) dyableSlots.add(cosmetic.getSlot());
}
return dyableSlots;
}
public boolean hasCosmetic(Cosmetic cosmetic) {
if (!cosmetic.requiresPermission()) return true;
if (getPlayer().hasPermission(cosmetic.getPermission())) return true;

View File

@@ -44,7 +44,7 @@ public class CosmeticUsers {
if (entity.getType().equals(EntityType.PLAYER)) return null;
return COSMETIC_USERS.get(entity.getUniqueId());
}
public static CosmeticUser getUser(String playerName) {
return getUser(Bukkit.getPlayer(playerName).getUniqueId());
}

View File

@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.nms.v1_19_R1;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.entities.BalloonEntity;
@@ -89,8 +90,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());
balloonEntity1.addPlayerToModel(player, cosmeticBalloonType.getModelName());
balloonEntity1.spawnModel(cosmeticBalloonType.getModelName(), user.getCosmeticColor(cosmeticBalloonType.getSlot()));
balloonEntity1.addPlayerToModel(player, cosmeticBalloonType.getModelName(), user.getCosmeticColor(cosmeticBalloonType.getSlot()));
PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getPufferfishBalloonId(), EntityType.PUFFERFISH, balloonEntity1.getPufferfishBalloonUniqueId(), sentTo);
PacketManager.sendInvisibilityPacket(balloonEntity1.getPufferfishBalloonId(), sentTo);