Don't reset custom name (TBC if 1.8.8 is affected)

This commit is contained in:
fullwall 2022-02-19 20:27:41 +08:00
parent 6fd6d12092
commit 87d27c09dc
3 changed files with 44 additions and 10 deletions

View File

@ -1980,7 +1980,7 @@ public class NPCCommands {
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "shop (name) (edit|show)", usage = "shop (edit|show) (name)",
desc = "NPC shop edit/show", desc = "NPC shop edit/show",
modifiers = { "shop" }, modifiers = { "shop" },
min = 1, min = 1,
@ -1988,17 +1988,25 @@ public class NPCCommands {
permission = "citizens.npc.shop") permission = "citizens.npc.shop")
public void shop(CommandContext args, Player sender, NPC npc) throws CommandException { public void shop(CommandContext args, Player sender, NPC npc) throws CommandException {
ShopTrait trait = npc.getOrAddTrait(ShopTrait.class); ShopTrait trait = npc.getOrAddTrait(ShopTrait.class);
NPCShop shop = trait.getDefaultShop();
if (args.argsLength() > 1) { if (args.argsLength() > 1) {
NPCShop shop = trait.getShop(args.getString(1)); if (args.argsLength() == 3) {
if (args.getString(2).equalsIgnoreCase("edit")) { if (args.getString(1).equalsIgnoreCase("edit")
&& !sender.hasPermission("citizens.npc.shop.edit." + args.getString(2).toLowerCase()))
throw new NoPermissionsException();
shop = trait.getShop(args.getString(2).toLowerCase());
}
if (args.getString(1).equalsIgnoreCase("edit")) {
if (!sender.hasPermission("citizens.npc.shop.edit"))
throw new NoPermissionsException();
shop.displayEditor(sender); shop.displayEditor(sender);
} else if (args.getString(2).equalsIgnoreCase("show") && args.argsLength() == 3) { } else if (args.getString(1).equalsIgnoreCase("show")) {
shop.display(sender); shop.display(sender);
} else { } else {
throw new CommandUsageException(); throw new CommandUsageException();
} }
} else { } else {
trait.getDefaultShop().display(sender); shop.display(sender);
} }
} }

View File

@ -427,8 +427,7 @@ public class CitizensNPC extends AbstractNPC {
private void updateCustomName() { private void updateCustomName() {
boolean nameVisibility = false; boolean nameVisibility = false;
if (!getEntity().isCustomNameVisible() if (!getEntity().isCustomNameVisible()
&& !data().<Object> get(NPC.Metadata.NAMEPLATE_VISIBLE, true).toString().equals("hover")) { && !data().<Object> get(NPC.Metadata.NAMEPLATE_VISIBLE, true).toString().equals("hover")) {
getEntity().setCustomName("");
} else if (!requiresNameHologram()) { } else if (!requiresNameHologram()) {
nameVisibility = true; nameVisibility = true;
getEntity().setCustomName(getFullName()); getEntity().setCustomName(getFullName());

View File

@ -1,9 +1,12 @@
package net.citizensnpcs.trait; package net.citizensnpcs.trait;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.citizensnpcs.api.persistence.Persist; import net.citizensnpcs.api.persistence.Persist;
@ -20,16 +23,20 @@ public class ShopTrait extends Trait {
} }
public NPCShop getDefaultShop() { public NPCShop getDefaultShop() {
return NPC_SHOPS.get(npc.getUniqueId().toString()); return NPC_SHOPS.computeIfAbsent(npc.getUniqueId().toString(), NPCShop::new);
} }
public NPCShop getShop(String name) { public NPCShop getShop(String name) {
return SHOPS.get(name); return SHOPS.computeIfAbsent(name, NPCShop::new);
} }
public static class NPCShop { public static class NPCShop {
@Persist @Persist
String name; private final String name;
@Persist(reify = true)
private final List<NPCShopPage> pages = Lists.newArrayList();
@Persist
private String title;
private NPCShop(String name) { private NPCShop(String name) {
this.name = name; this.name = name;
@ -40,6 +47,26 @@ public class ShopTrait extends Trait {
public void displayEditor(Player sender) { public void displayEditor(Player sender) {
} }
public String getName() {
return name;
}
}
public static class NPCShopItem {
@Persist
private int cost;
@Persist
private ItemStack display;
}
public static class NPCShopPage {
@Persist("")
private int index;
@Persist(reify = true)
private final Map<Integer, NPCShopItem> items = Maps.newHashMap();
@Persist
private String title;
} }
@Persist(value = "npcShops", namespace = "shopstrait") @Persist(value = "npcShops", namespace = "shopstrait")