Skip to content

Commit 387ec1c

Browse files
Properly set abandoned name for modelled exteriors
1 parent 8b3a33b commit 387ec1c

File tree

1 file changed

+30
-36
lines changed

1 file changed

+30
-36
lines changed

src/main/java/me/eccentric_nz/TARDIS/commands/tardis/TARDISAbandonCommand.java

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@
1919
import me.eccentric_nz.TARDIS.TARDIS;
2020
import me.eccentric_nz.TARDIS.api.event.TARDISAbandonEvent;
2121
import me.eccentric_nz.TARDIS.blueprints.TARDISPermission;
22-
import me.eccentric_nz.TARDIS.builders.exterior.TARDISBuilderUtility;
2322
import me.eccentric_nz.TARDIS.commands.admin.TARDISAbandonLister;
2423
import me.eccentric_nz.TARDIS.control.TARDISPowerButton;
25-
import me.eccentric_nz.TARDIS.custommodels.keys.ChameleonVariant;
26-
import me.eccentric_nz.TARDIS.custommodels.keys.ColouredVariant;
2724
import me.eccentric_nz.TARDIS.database.converters.TARDISAbandonUpdate;
2825
import me.eccentric_nz.TARDIS.database.data.Current;
2926
import me.eccentric_nz.TARDIS.database.resultset.ResultSetCurrentFromId;
@@ -41,15 +38,19 @@
4138
import me.eccentric_nz.TARDIS.enumeration.ChameleonPreset;
4239
import me.eccentric_nz.TARDIS.enumeration.TardisModule;
4340
import net.kyori.adventure.text.Component;
44-
import org.bukkit.*;
41+
import org.bukkit.Location;
42+
import org.bukkit.Tag;
43+
import org.bukkit.World;
4544
import org.bukkit.block.Block;
4645
import org.bukkit.block.Sign;
4746
import org.bukkit.block.sign.Side;
4847
import org.bukkit.block.sign.SignSide;
4948
import org.bukkit.command.CommandSender;
49+
import org.bukkit.entity.ArmorStand;
5050
import org.bukkit.entity.Entity;
51-
import org.bukkit.entity.ItemFrame;
5251
import org.bukkit.entity.Player;
52+
import org.bukkit.inventory.EntityEquipment;
53+
import org.bukkit.inventory.EquipmentSlot;
5354
import org.bukkit.inventory.ItemStack;
5455
import org.bukkit.inventory.meta.ItemMeta;
5556

@@ -282,39 +283,32 @@ boolean doAbandon(CommandSender sender, boolean list) {
282283
// always clear sign
283284
if (preset.usesArmourStand()) {
284285
World world = current.location().getWorld();
285-
// remove name from the item frame item
286-
for (Entity e : world.getNearbyEntities(current.location(), 1.0d, 1.0d, 1.0d)) {
287-
if (e instanceof ItemFrame frame) {
288-
Material dye = TARDISBuilderUtility.getMaterialForArmourStand(preset, id, true);
289-
ItemStack is = ItemStack.of(dye, 1);
286+
// remove custom name from the armour stand / helmet item
287+
for (Entity e : world.getNearbyEntities(current.location(), 1.1d, 1.1d, 1.1d)) {
288+
if (e instanceof ArmorStand stand) {
289+
ItemStack is = stand.getItem(EquipmentSlot.HEAD);
290290
ItemMeta im = is.getItemMeta();
291-
NamespacedKey model = switch (is.getType()) {
292-
case BLACK_DYE -> ChameleonVariant.BLACK_CLOSED.getKey();
293-
case BLUE_DYE -> ChameleonVariant.BLUE_CLOSED.getKey();
294-
case BROWN_DYE -> ChameleonVariant.BROWN_CLOSED.getKey();
295-
case CYAN_DYE -> ChameleonVariant.CYAN_CLOSED.getKey();
296-
case GRAY_DYE -> ChameleonVariant.GRAY_CLOSED.getKey();
297-
case GREEN_DYE -> ChameleonVariant.GREEN_CLOSED.getKey();
298-
case LIGHT_BLUE_DYE -> ChameleonVariant.LIGHT_BLUE_CLOSED.getKey();
299-
case LIGHT_GRAY_DYE -> ChameleonVariant.LIGHT_GRAY_CLOSED.getKey();
300-
case LIME_DYE -> ChameleonVariant.LIME_CLOSED.getKey();
301-
case MAGENTA_DYE -> ChameleonVariant.MAGENTA_CLOSED.getKey();
302-
case ORANGE_DYE -> ChameleonVariant.ORANGE_CLOSED.getKey();
303-
case PINK_DYE -> ChameleonVariant.PINK_CLOSED.getKey();
304-
case PURPLE_DYE -> ChameleonVariant.PURPLE_CLOSED.getKey();
305-
case RED_DYE -> ChameleonVariant.RED_CLOSED.getKey();
306-
case WHITE_DYE -> ChameleonVariant.WHITE_CLOSED.getKey();
307-
case YELLOW_DYE -> ChameleonVariant.YELLOW_CLOSED.getKey();
308-
case CYAN_STAINED_GLASS_PANE -> ChameleonVariant.TENNANT_CLOSED.getKey();
309-
case GRAY_STAINED_GLASS_PANE -> ChameleonVariant.WEEPING_ANGEL_CLOSED.getKey();
310-
case ENDER_PEARL -> ChameleonVariant.PANDORICA_CLOSED.getKey();
311-
case LEATHER_HORSE_ARMOR -> ColouredVariant.TINTED_CLOSED.getKey();
312-
default -> new NamespacedKey(plugin, TARDISBuilderUtility.getCustomModelPath(is.getType().toString()) + "_closed");
313-
};
314-
im.setItemModel(model);
315-
im.displayName(Component.empty());
291+
String pb = "";
292+
switch (preset) {
293+
case WEEPING_ANGEL -> pb = "Weeping Angel";
294+
case PANDORICA -> pb = "Pandorica";
295+
case ITEM -> {
296+
for (String k : plugin.getCustomModelConfig().getConfigurationSection("models").getKeys(false)) {
297+
if (is.getType().toString().equals(plugin.getCustomModelConfig().getString("models." + k + ".item"))) {
298+
pb = k;
299+
break;
300+
}
301+
}
302+
}
303+
default -> pb = "Police Box";
304+
}
305+
Component custom = Component.text("Abandoned " + pb);
306+
im.displayName(custom);
316307
is.setItemMeta(im);
317-
frame.setItem(is, false);
308+
EntityEquipment ee = stand.getEquipment();
309+
ee.setHelmet(is, true);
310+
stand.customName(custom);
311+
stand.setCustomNameVisible(true);
318312
break;
319313
}
320314
}

0 commit comments

Comments
 (0)