|
| 1 | +/* |
| 2 | + * Copyright (C) 2025 eccentric_nz |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | +package me.eccentric_nz.TARDIS.lazarus.disguise; |
| 18 | + |
| 19 | +import com.destroystokyo.paper.SkinParts; |
| 20 | +import com.google.gson.JsonObject; |
| 21 | +import com.mojang.authlib.GameProfile; |
| 22 | +import com.mojang.authlib.properties.Property; |
| 23 | +import io.papermc.paper.datacomponent.item.ResolvableProfile; |
| 24 | +import me.eccentric_nz.TARDIS.TARDIS; |
| 25 | +import me.eccentric_nz.TARDIS.skins.SkinFetcher; |
| 26 | +import org.bukkit.Location; |
| 27 | +import org.bukkit.World; |
| 28 | +import org.bukkit.entity.EntityType; |
| 29 | +import org.bukkit.entity.Mannequin; |
| 30 | +import org.bukkit.entity.Player; |
| 31 | +import org.bukkit.inventory.EntityEquipment; |
| 32 | + |
| 33 | +import java.util.UUID; |
| 34 | + |
| 35 | +public class EmergencyProgramOneSpawner { |
| 36 | + |
| 37 | + private final Player player; |
| 38 | + private final Location location; |
| 39 | + private Mannequin npc = null; |
| 40 | + |
| 41 | + public EmergencyProgramOneSpawner(Player player, Location location) { |
| 42 | + this.player = player; |
| 43 | + this.location = location; |
| 44 | + } |
| 45 | + |
| 46 | + public void create() { |
| 47 | + SkinFetcher getter = new SkinFetcher(TARDIS.plugin, player.getUniqueId()); |
| 48 | + getter.fetchAsync((hasResult, fetched) -> { |
| 49 | + if (hasResult) { |
| 50 | + JsonObject properties = fetched.getSkin(); |
| 51 | + if (properties != null) { |
| 52 | + GameProfile gameProfile = new GameProfile(UUID.randomUUID(), player.getName()); |
| 53 | + // set the skin to the player's |
| 54 | + String value = properties.get("value").getAsString(); |
| 55 | + String signature = properties.get("signature").getAsString(); |
| 56 | + gameProfile.properties().removeAll("textures"); |
| 57 | + gameProfile.properties().put("textures", new Property("textures", value, signature)); |
| 58 | + ResolvableProfile profile = ResolvableProfile.resolvableProfile(player.getPlayerProfile()); |
| 59 | + World world = location.getWorld(); |
| 60 | + npc = (Mannequin) world.spawnEntity(location, EntityType.MANNEQUIN); |
| 61 | + npc.setHealth(20.0d); |
| 62 | + npc.setProfile(profile); |
| 63 | + npc.setSkinParts(SkinParts.allParts()); |
| 64 | + npc.setImmovable(true); |
| 65 | + npc.setInvulnerable(true); |
| 66 | + // set NPC equipment |
| 67 | + EntityEquipment equipment = npc.getEquipment(); |
| 68 | + equipment.setBoots(player.getInventory().getBoots()); |
| 69 | + equipment.setLeggings(player.getInventory().getLeggings()); |
| 70 | + equipment.setChestplate(player.getInventory().getChestplate()); |
| 71 | + equipment.setHelmet(player.getInventory().getHelmet()); |
| 72 | + equipment.setItemInMainHand(player.getInventory().getItemInMainHand()); |
| 73 | + equipment.setItemInOffHand(player.getInventory().getItemInOffHand()); |
| 74 | + } |
| 75 | + } |
| 76 | + }); |
| 77 | + } |
| 78 | + |
| 79 | + public Mannequin getMannequin() { |
| 80 | + return npc; |
| 81 | + } |
| 82 | +} |
0 commit comments