Commit 97b42c7c authored by Ticxo's avatar Ticxo
Browse files

help me

parent 9432fec1
......@@ -4,6 +4,7 @@ import io.lumine.cosmetics.api.players.CosmeticProfile;
public interface CosmeticManager {
public void equip(CosmeticProfile profile);
void equip(CosmeticProfile profile);
void unequip(CosmeticProfile profile);
}
......@@ -14,4 +14,6 @@ public interface CosmeticInventory {
Optional<Cosmetic> getEquipped(Class<? extends Cosmetic> tClass);
void equip(Cosmetic cosmetic);
void unequip(Class<? extends Cosmetic> tClass);
}
......@@ -26,4 +26,9 @@ public class BackManager extends MCCosmeticsManager<BackAccessory> {
public void equip(CosmeticProfile profile) {
((VolatileEquipmentHelper) getPlugin().getVolatileCodeHandler().getCosmeticHelper(BackAccessory.class)).apply(profile);
}
@Override
public void unequip(CosmeticProfile profile) {
((VolatileEquipmentHelper) getPlugin().getVolatileCodeHandler().getCosmeticHelper(BackAccessory.class)).unapply(profile);
}
}
package io.lumine.cosmetics.managers.chat;
import io.lumine.cosmetics.MCCosmeticsPlugin;
import io.lumine.cosmetics.api.players.CosmeticProfile;
import io.lumine.cosmetics.managers.MCCosmeticsManager;
......@@ -28,6 +28,11 @@ public class ChatTagManager extends MCCosmeticsManager<ChatTag> {
@Override
public void equip(CosmeticProfile profile) {}
@Override
public void unequip(CosmeticProfile profile) {
}
}
......@@ -42,6 +42,11 @@ public class GestureManager extends MCCosmeticsManager<Gesture> {
model.playAnimation(animation);
}
@Override
public void unequip(CosmeticProfile profile) {
}
private void loadGestures() {
final String type = CosmeticType.folder(cosmeticClass);
......
......@@ -60,4 +60,9 @@ public class HatManager extends MCCosmeticsManager<Hat> {
public void equip(CosmeticProfile profile) {
((VolatileEquipmentHelper) getPlugin().getVolatileCodeHandler().getCosmeticHelper(Hat.class)).apply(profile);
}
@Override
public void unequip(CosmeticProfile profile) {
((VolatileEquipmentHelper) getPlugin().getVolatileCodeHandler().getCosmeticHelper(Hat.class)).unapply(profile);
}
}
......@@ -50,17 +50,17 @@ public class FakeEntity extends BukkitPlayer {
@Override
public Location getLocation() {
Location location = player.getLocation();
Vector offset;
if (anchor == ModelAnchor.HEAD) {
MCLogger.log("head");
double pYaw = Math.toRadians(player.getLocation().getYaw());
double pPitch = Math.toRadians(player.getLocation().getPitch());
double pYaw = Math.toRadians(location.getYaw());
double pPitch = Math.toRadians(location.getPitch());
offset = Offset.rotateYaw(Offset.rotatePitch(this.offset.clone(), pitch + pPitch), yaw + pYaw);
} else {
double pYaw = getBodyYaw();
offset = Offset.rotateYaw(this.offset.clone(), yaw + pYaw);
}
return player.getLocation().add(offset);
return location.add(offset);
}
@Override
......
......@@ -4,6 +4,7 @@ import com.ticxo.modelengine.api.util.ConfigManager;
import io.lumine.cosmetics.api.players.CosmeticProfile;
import io.lumine.cosmetics.config.Scope;
import io.lumine.cosmetics.constants.CosmeticType;
import io.lumine.cosmetics.logging.MCLogger;
import io.lumine.cosmetics.managers.AbstractCosmetic;
import io.lumine.utils.config.properties.Property;
import io.lumine.utils.config.properties.types.EnumProp;
......
......@@ -5,6 +5,7 @@ import com.ticxo.modelengine.api.animation.StateProperty;
import com.ticxo.modelengine.api.model.ModeledEntity;
import io.lumine.cosmetics.MCCosmeticsPlugin;
import io.lumine.cosmetics.api.players.CosmeticProfile;
import io.lumine.cosmetics.logging.MCLogger;
import io.lumine.cosmetics.managers.MCCosmeticsManager;
import io.lumine.utils.Events;
import org.bukkit.entity.Player;
......@@ -64,12 +65,12 @@ public class MEGManager extends MCCosmeticsManager<MEGAccessory> {
activeModel.setAnimationMode(meg.getMode());
ModeledEntity modeledEntity = ModelEngineAPI.getModeledEntity(player.getUniqueId());
if(modeledEntity == null) {
modeledEntity = ModelEngineAPI.api.getModelManager().createModeledEntity(new FakeEntity(player, meg.getOffset(), meg.getAnchor()));
if(modeledEntity != null) {
modeledEntity.clearModels();
modeledEntity.getAllActiveModel().clear();
}
modeledEntity.clearModels();
modeledEntity.getAllActiveModel().clear();
modeledEntity = ModelEngineAPI.api.getModelManager().createModeledEntity(new FakeEntity(player, meg.getOffset(), meg.getAnchor()));
modeledEntity.addActiveModel(activeModel);
modeledEntity.setInvisible(false);
modeledEntity.detectPlayers();
......
......@@ -11,6 +11,7 @@ import io.lumine.utils.events.extra.ArmorEquipEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import java.io.File;
......@@ -48,17 +49,17 @@ public class OffhandManager extends MCCosmeticsManager<Offhand> {
});
}).bindWith(this);
Events.subscribe(ArmorEquipEvent.class)
Events.subscribe(PlayerSwapHandItemsEvent.class)
.handler(event -> {
final Player player = event.getPlayer();
getProfiles().awaitProfile(player).thenAcceptAsync(maybeProfile -> {
if(maybeProfile.isEmpty()) {
if(maybeProfile.isEmpty())
return;
}
final Profile profile = maybeProfile.get();
equip(profile);
});
}).bindWith(this);
}
@Override
......@@ -70,4 +71,9 @@ public class OffhandManager extends MCCosmeticsManager<Offhand> {
public void equip(CosmeticProfile profile) {
((VolatileEquipmentHelper) getPlugin().getVolatileCodeHandler().getCosmeticHelper(Offhand.class)).apply(profile);
}
@Override
public void unequip(CosmeticProfile profile) {
((VolatileEquipmentHelper) getPlugin().getVolatileCodeHandler().getCosmeticHelper(Offhand.class)).unapply(profile);
}
}
......@@ -15,7 +15,7 @@ public class ParticleAccessory extends AbstractCosmetic {
@Override
public String getPropertyNode() {
return "Particle." + key;
return key;
}
@Override
......
......@@ -21,4 +21,9 @@ public class ParticleManager extends MCCosmeticsManager<ParticleAccessory> {
public void equip(CosmeticProfile profile) {
// TODO: 15/3/2022 Impl particle accessory
}
@Override
public void unequip(CosmeticProfile profile) {
}
}
......@@ -31,4 +31,9 @@ public class PetManager extends MCCosmeticsManager<Pet> {
pet.getSpawner().equip(profile.getPlayer());
}
}
@Override
public void unequip(CosmeticProfile profile) {
}
}
package io.lumine.cosmetics.managers.sprays;
import io.lumine.utils.Events;
import io.lumine.utils.Schedulers;
import io.lumine.utils.cooldown.Cooldown;
import io.lumine.utils.cooldown.CooldownMap;
import io.lumine.utils.cooldown.CooldownMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Maps;
import io.lumine.cosmetics.MCCosmeticsPlugin;
import io.lumine.cosmetics.api.players.CosmeticProfile;
import io.lumine.cosmetics.config.Scope;
......@@ -82,7 +82,12 @@ public class SprayManager extends MCCosmeticsManager<Spray> {
@Override
public void equip(CosmeticProfile profile) {}
@Override
public void unequip(CosmeticProfile profile) {
}
private void loadSprayImages() {
images.clear();
......@@ -153,7 +158,7 @@ public class SprayManager extends MCCosmeticsManager<Spray> {
return true;
}
public void spawnSpray(Player player, Spray spray, Location location, BlockFace face, int rotation) {
public void spawnSpray(Player player, Spray spray, Location location, BlockFace face, int rotation) {
removeSpray(player);
int eid = ((VolatileSprayHelper) getNMSHelper()).drawSpray(spray, location, face, rotation);
......@@ -178,7 +183,7 @@ public class SprayManager extends MCCosmeticsManager<Spray> {
if(activeByPlayer.containsKey(player.getUniqueId())) {
int oid = activeByPlayer.get(player.getUniqueId());
getPlugin().getVolatileCodeHandler().removeFakeEntity(oid);
}
}
}
private int getRotation(float yaw, boolean allowDiagonals) {
......
......@@ -5,6 +5,7 @@ import io.lumine.cosmetics.api.players.CosmeticProfile;
public interface VolatileEquipmentHelper extends VolatileCosmeticHelper {
void apply(CosmeticProfile profile);
void unapply(CosmeticProfile profile);
static byte toByte(float val) {
return (byte)((int)(val * 256.0F / 360.0F));
......
......@@ -6,8 +6,10 @@ import io.lumine.cosmetics.MCCosmeticsPlugin;
import io.lumine.cosmetics.api.cosmetics.Cosmetic;
import io.lumine.cosmetics.api.players.CosmeticInventory;
import io.lumine.cosmetics.api.players.CosmeticProfile;
import io.lumine.cosmetics.constants.CosmeticType;
import io.lumine.cosmetics.managers.back.BackAccessory;
import io.lumine.cosmetics.managers.hats.Hat;
import io.lumine.cosmetics.managers.sprays.Spray;
import io.lumine.utils.serialize.Optl;
import lombok.Getter;
......@@ -21,8 +23,8 @@ public class ProfileInventory implements CosmeticInventory {
@Getter private transient CosmeticProfile profile;
private transient final Map<Class<? extends Cosmetic>, Cosmetic> equipped = Maps.newConcurrentMap();
@Getter private Map<String,List<String>> unlockedCosmetics = Maps.newConcurrentMap();
@Getter private Map<String,String> equippedCosmetics = Maps.newConcurrentMap();
@Getter private final Map<String,List<String>> unlockedCosmetics = Maps.newConcurrentMap();
@Getter private final Map<String,String> equippedCosmetics = Maps.newConcurrentMap();
@Override
public void initialize(CosmeticProfile profile) {
......@@ -50,6 +52,14 @@ public class ProfileInventory implements CosmeticInventory {
cosmetic.getManager().equip(profile);
}
@Override
public void unequip(Class<? extends Cosmetic> tClass) {
equippedCosmetics.remove(CosmeticType.type(tClass));
final var pCos = equipped.remove(tClass);
if(pCos != null)
pCos.getManager().unequip(profile);
}
public boolean isEquipped(Cosmetic cosmetic) {
return cosmetic.isEquipped(this);
}
......
......@@ -77,6 +77,16 @@ public class VolatileBackImpl implements VolatileEquipmentHelper {
nmsHandler.broadcastAround(player, equipmentPacket);
}
@Override
public void unapply(CosmeticProfile profile) {
Player player = profile.getPlayer();
ArmorStand stand = activeProfile.remove(player);
if(stand == null)
return;
ClientboundRemoveEntitiesPacket removePacket = new ClientboundRemoveEntitiesPacket(stand.getId());
nmsHandler.broadcastAround(player, removePacket);
}
@Override
public void read(Player sender, Object packet) {
if(packet instanceof ServerboundMovePlayerPacket) {
......
......@@ -14,6 +14,7 @@ import lombok.Getter;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.*;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
import org.bukkit.entity.Player;
......@@ -55,6 +56,16 @@ public class VolatileHatImpl implements VolatileEquipmentHelper {
}
@Override
public void unapply(CosmeticProfile profile) {
final var nmsPlayer = ((CraftPlayer) profile.getPlayer()).getHandle();
final var item = nmsPlayer.getItemBySlot(EquipmentSlot.HEAD);
if(item == ItemStack.EMPTY)
return;
ClientboundSetEquipmentPacket equipmentPacket = new ClientboundSetEquipmentPacket(nmsPlayer.getId(), List.of(Pair.of(EquipmentSlot.HEAD, item)));
nmsHandler.broadcastAround(nmsPlayer.getBukkitEntity(), equipmentPacket);
}
@Override
public void read(Player sender, Object packet) {
if(packet instanceof ServerboundAcceptTeleportationPacket) {
......
......@@ -6,15 +6,17 @@ import io.lumine.cosmetics.MCCosmeticsPlugin;
import io.lumine.cosmetics.api.cosmetics.Cosmetic;
import io.lumine.cosmetics.api.cosmetics.ItemCosmetic;
import io.lumine.cosmetics.api.players.CosmeticProfile;
import io.lumine.cosmetics.logging.MCLogger;
import io.lumine.cosmetics.managers.offhand.Offhand;
import io.lumine.cosmetics.nms.VolatileCodeEnabled_v1_18_R2;
import io.lumine.cosmetics.nms.cosmetic.VolatileEquipmentHelper;
import io.lumine.cosmetics.players.Profile;
import lombok.Getter;
import net.minecraft.network.protocol.game.*;
import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket;
import net.minecraft.network.protocol.game.ClientboundAddPlayerPacket;
import net.minecraft.network.protocol.game.ClientboundEntityEventPacket;
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
import org.bukkit.entity.Player;
......@@ -55,6 +57,16 @@ public class VolatileOffhandImpl implements VolatileEquipmentHelper {
}
@Override
public void unapply(CosmeticProfile profile) {
final var nmsPlayer = ((CraftPlayer) profile.getPlayer()).getHandle();
final var item = nmsPlayer.getItemBySlot(EquipmentSlot.OFFHAND);
if(item == ItemStack.EMPTY)
return;
ClientboundSetEquipmentPacket equipmentPacket = new ClientboundSetEquipmentPacket(nmsPlayer.getId(), List.of(Pair.of(EquipmentSlot.OFFHAND, item)));
nmsHandler.broadcastAround(nmsPlayer.getBukkitEntity(), equipmentPacket);
}
@Override
public List<Object> write(Player receiver, Object packet) {
if(packet instanceof ClientboundAddPlayerPacket playerPacket) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment