Make llamatrait 1.12 compatible, work on /npc shop

This commit is contained in:
fullwall 2022-07-17 22:29:11 +08:00
parent 34aea6553c
commit 9c9199d2a1
10 changed files with 353 additions and 78 deletions

View File

@ -442,7 +442,7 @@ public class NPCCommands {
: Messages.COMMANDS_RANDOM_UNSET);
} else if (args.getString(1).equalsIgnoreCase("itemcost")) {
if (!(sender instanceof Player))
throw new CommandException(Messages.COMMAND_MUST_BE_INGAME);
throw new CommandException(CommandMessages.MUST_BE_INGAME);
InventoryMenu.createSelfRegistered(new ItemRequirementGUI(commands)).present(((Player) sender));
} else {
throw new CommandUsageException();
@ -704,7 +704,7 @@ public class NPCCommands {
};
if (npc == null || args.argsLength() == 2) {
if (args.argsLength() < 2) {
throw new CommandException(Messages.COMMAND_MUST_HAVE_SELECTED);
throw new CommandException(CommandMessages.MUST_HAVE_SELECTED);
}
NPCCommandSelector.startWithCallback(callback, CitizensAPI.getNPCRegistry(), sender, args,
args.getString(1));
@ -810,10 +810,10 @@ public class NPCCommands {
@Override
public void run(NPC followingNPC) throws CommandException {
if (followingNPC == null)
throw new CommandException(Messages.COMMAND_MUST_HAVE_SELECTED);
throw new CommandException(CommandMessages.MUST_HAVE_SELECTED);
if (!(sender instanceof ConsoleCommandSender)
&& !followingNPC.getOrAddTrait(Owner.class).isOwnedBy(sender))
throw new CommandException(Messages.COMMAND_MUST_BE_OWNER);
throw new CommandException(CommandMessages.MUST_BE_OWNER);
if (followingNPC.getEntity() instanceof Player) {
boolean following = followingNPC.getOrAddTrait(FollowTrait.class)
.toggle((Player) followingNPC.getEntity(), protect);
@ -1922,10 +1922,10 @@ public class NPCCommands {
@Override
public void run(NPC npc) throws CommandException {
if (npc == null)
throw new CommandException(Messages.COMMAND_MUST_HAVE_SELECTED);
throw new CommandException(CommandMessages.MUST_HAVE_SELECTED);
if (!(sender instanceof ConsoleCommandSender)
&& !npc.getOrAddTrait(Owner.class).isOwnedBy(sender))
throw new CommandException(Messages.COMMAND_MUST_BE_OWNER);
throw new CommandException(CommandMessages.MUST_BE_OWNER);
if (!sender.hasPermission("citizens.npc.remove") && !sender.hasPermission("citizens.admin"))
throw new NoPermissionsException();
history.add(sender, new RemoveNPCHistoryItem(npc));
@ -1939,9 +1939,9 @@ public class NPCCommands {
}
}
if (npc == null)
throw new CommandException(Messages.COMMAND_MUST_HAVE_SELECTED);
throw new CommandException(CommandMessages.MUST_HAVE_SELECTED);
if (!(sender instanceof ConsoleCommandSender) && !npc.getOrAddTrait(Owner.class).isOwnedBy(sender))
throw new CommandException(Messages.COMMAND_MUST_BE_OWNER);
throw new CommandException(CommandMessages.MUST_BE_OWNER);
if (!sender.hasPermission("citizens.npc.remove") && !sender.hasPermission("citizens.admin"))
throw new NoPermissionsException();
history.add(sender, new RemoveNPCHistoryItem(npc));

View File

@ -4,18 +4,6 @@ import java.util.List;
import javax.annotation.Nullable;
import net.citizensnpcs.Citizens;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.command.Command;
import net.citizensnpcs.api.command.CommandContext;
import net.citizensnpcs.api.command.Requirements;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.npc.Template;
import net.citizensnpcs.npc.Template.TemplateBuilder;
import net.citizensnpcs.util.Messages;
import org.bukkit.command.CommandSender;
import com.google.common.base.Function;
@ -23,6 +11,19 @@ import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import net.citizensnpcs.Citizens;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.command.Command;
import net.citizensnpcs.api.command.CommandContext;
import net.citizensnpcs.api.command.CommandMessages;
import net.citizensnpcs.api.command.Requirements;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.npc.Template;
import net.citizensnpcs.npc.Template.TemplateBuilder;
import net.citizensnpcs.util.Messages;
@Requirements(selected = true, ownership = true)
public class TemplateCommands {
public TemplateCommands(Citizens plugin) {
@ -43,7 +44,7 @@ public class TemplateCommands {
int appliedCount = 0;
if (args.argsLength() == 2) {
if (npc == null)
throw new CommandException(Messaging.tr(Messages.COMMAND_MUST_HAVE_SELECTED));
throw new CommandException(Messaging.tr(CommandMessages.MUST_HAVE_SELECTED));
template.apply(npc);
appliedCount++;
} else {

View File

@ -4,7 +4,6 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
@ -17,7 +16,6 @@ import org.bukkit.inventory.ItemStack;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCDeathEvent;
import net.citizensnpcs.api.gui.InventoryMenu;
import net.citizensnpcs.api.gui.InventoryMenuPage;
@ -59,7 +57,6 @@ public class DropsTrait extends Trait {
public static class DropsGUI extends InventoryMenuPage {
private final Map<Integer, Double> chances = Maps.newHashMap();
private Inventory inventory;
private int taskId;
private DropsTrait trait;
private DropsGUI() {
@ -72,7 +69,6 @@ public class DropsTrait extends Trait {
@Override
public void initialise(MenuContext ctx) {
this.taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(CitizensAPI.getPlugin(), this, 0, 1);
this.inventory = ctx.getInventory();
int k = 0;
for (int i = 1; i < 5; i += 2) {
@ -114,11 +110,6 @@ public class DropsTrait extends Trait {
@Override
public void onClose(HumanEntity player) {
Bukkit.getScheduler().cancelTask(taskId);
}
@Override
public void run() {
List<ItemDrop> drops = Lists.newArrayList();
for (int i = 0; i < 5; i += 2) {
for (int j = 0; j < 9; j++) {

View File

@ -2,12 +2,17 @@ package net.citizensnpcs.trait;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@ -48,7 +53,9 @@ public class ShopTrait extends Trait {
@Persist(reify = true)
private final List<NPCShopPage> pages = Lists.newArrayList();
@Persist
private ShopType type = ShopType.VIEW;
private String title;
@Persist
private ShopType type = ShopType.COMMAND;
@Persist
private String viewPermission;
@ -69,10 +76,28 @@ public class ShopTrait extends Trait {
return name;
}
public NPCShopPage getOrCreatePage(int page) {
while (pages.size() <= page) {
pages.add(new NPCShopPage(page));
}
return pages.get(page);
}
public String getRequiredPermission() {
return viewPermission;
}
public void removePage(int index) {
for (int i = 0; i < pages.size(); i++) {
if (pages.get(i).index == index) {
pages.remove(i--);
index = -1;
} else if (index == -1) {
pages.get(i).index--;
}
}
}
public void setPermission(String permission) {
this.viewPermission = permission;
if (viewPermission != null && viewPermission.isEmpty()) {
@ -81,6 +106,87 @@ public class ShopTrait extends Trait {
}
}
@Menu(title = "NPC Shop Contents Editor", type = InventoryType.CHEST, dimensions = { 5, 9 })
public static class NPCShopContentsEditor extends InventoryMenuPage {
private MenuContext ctx;
private int page = 0;
private final NPCShop shop;
public NPCShopContentsEditor(NPCShop shop) {
this.shop = shop;
}
public void changePage(int newPage) {
this.page = newPage;
NPCShopPage sp = shop.getOrCreatePage(page);
for (int i = 0; i < ctx.getInventory().getSize(); i++) {
ctx.getSlot(i).clear();
NPCShopItem item = sp.items.get(i);
final int idx = i;
ctx.getSlot(i).addClickHandler(evt -> {
ctx.clearSlots();
NPCShopItem display = item;
if (display == null) {
display = new NPCShopItem();
if (evt.getCursor() != null) {
display.display = evt.getCursor().clone();
}
}
ctx.getMenu().transition(new NPCShopItemEditor(display, modified -> {
if (modified == null) {
sp.items.remove(idx);
} else {
sp.items.put(idx, modified);
}
}));
});
if (item == null)
continue;
ctx.getSlot(i).setItemStack(item.display);
}
InventoryMenuSlot prev = ctx.getSlot(4 * 9 + 3);
InventoryMenuSlot edit = ctx.getSlot(4 * 9 + 4);
InventoryMenuSlot next = ctx.getSlot(4 * 9 + 5);
prev.clear();
if (page > 0) {
prev.setItemStack(new ItemStack(Material.FEATHER, 1), "Previous page (" + (page) + ")");
prev.addClickHandler(evt -> {
evt.setCancelled(true);
changePage(page - 1);
});
}
next.clear();
next.setItemStack(new ItemStack(Material.FEATHER, 1),
page + 1 >= shop.pages.size() ? "New page" : "Next page (" + (page + 1) + ")");
next.addClickHandler(evt -> {
evt.setCancelled(true);
changePage(page + 1);
});
edit.clear();
edit.setItemStack(new ItemStack(Material.BOOK), "Edit page");
edit.addClickHandler(evt -> {
evt.setCancelled(true);
ctx.getMenu().transition(new NPCShopPageEditor(shop.getOrCreatePage(page)));
});
}
@Override
public void initialise(MenuContext ctx) {
this.ctx = ctx;
if (ctx.data().containsKey("removePage")) {
int index = (int) ctx.data().remove("removePage");
shop.removePage(index);
page = Math.max(page - 1, 0);
}
changePage(page);
}
}
@Menu(title = "NPC Shop Editor", type = InventoryType.HOPPER, dimensions = { 0, 5 })
@MenuSlot(slot = { 0, 0 }, material = Material.BOOK, amount = 1, lore = "Edit shop type")
@MenuSlot(slot = { 0, 2 }, material = Material.OAK_SIGN, amount = 1, lore = "Edit shop permission")
@ -101,14 +207,13 @@ public class ShopTrait extends Trait {
@ClickHandler(slot = { 0, 4 })
public void onEditItems(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
event.setCancelled(true);
ctx.getMenu().transition(new NPCShopItemEditor(shop));
ctx.getMenu().transition(new NPCShopContentsEditor(shop));
}
@ClickHandler(slot = { 0, 2 })
public void onPermissionChange(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
event.setCancelled(true);
ctx.getMenu().transition(
InputMenus.stringSetter(() -> shop.getRequiredPermission(), p -> shop.setPermission(p)));
ctx.getMenu().transition(InputMenus.stringSetter(shop::getRequiredPermission, shop::setPermission));
}
@ClickHandler(slot = { 0, 0 })
@ -118,30 +223,120 @@ public class ShopTrait extends Trait {
shop.type = chosen.getValue();
}, Choice.<ShopType> of(ShopType.BUY, Material.DIAMOND, "Players buy items", shop.type == ShopType.BUY),
Choice.of(ShopType.SELL, Material.EMERALD, "Players sell items", shop.type == ShopType.SELL),
Choice.of(ShopType.VIEW, Material.ENDER_EYE, "Players view items only",
shop.type == ShopType.VIEW)));
Choice.of(ShopType.COMMAND, Material.ENDER_EYE, "Clicks trigger commands only",
shop.type == ShopType.COMMAND)));
}
}
public static class NPCShopItem {
public static class NPCShopItem implements Cloneable {
@Persist
private int cost;
@Persist
private ItemStack display;
@Override
public NPCShopItem clone() {
try {
return (NPCShopItem) super.clone();
} catch (CloneNotSupportedException e) {
throw new Error(e);
}
}
}
@Menu(title = "NPC Shop Item Editor", type = InventoryType.CHEST, dimensions = { 5, 9 })
@MenuSlot(slot = { 0, 4 }, material = Material.DISPENSER, amount = 1, title = "Display item")
public static class NPCShopItemEditor extends InventoryMenuPage {
private final Consumer<NPCShopItem> consumer;
private MenuContext ctx;
private final NPCShop shop;
private final NPCShopItem modified;
private NPCShopItem original;
public NPCShopItemEditor(NPCShop shop) {
this.shop = shop;
public NPCShopItemEditor(NPCShopItem item, Consumer<NPCShopItem> ret) {
this.original = item;
this.modified = original.clone();
this.consumer = ret;
}
@Override
public void initialise(MenuContext ctx) {
this.ctx = ctx;
if (modified.display != null) {
ctx.getSlot(9 + 4).setItemStack(modified.display);
}
}
@ClickHandler(slot = { 4, 3 })
@MenuSlot(slot = { 4, 3 }, material = Material.REDSTONE_BLOCK, amount = 1, title = "Cancel")
public void onCancel(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
event.setCancelled(true);
ctx.getMenu().transitionBack();
}
@Override
public void onClose(HumanEntity who) {
if (original.display == null) {
original = null;
}
consumer.accept(original);
}
@MenuSlot(slot = { 0, 3 }, material = Material.BOOK, amount = 1, title = "Set description")
@ClickHandler(slot = { 0, 3 })
public void onEditDescription(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
event.setCancelled(true);
if (modified.display != null) {
ctx.getMenu()
.transition(InputMenus.stringSetter(
() -> Joiner.on("<br>").skipNulls().join(modified.display.getItemMeta().getLore()),
description -> {
ItemMeta meta = modified.display.getItemMeta();
meta.setLore(Lists.newArrayList(Splitter.on("<br>").split(description)));
modified.display.setItemMeta(meta);
}));
}
}
@MenuSlot(slot = { 0, 5 }, material = Material.FEATHER, amount = 1, title = "Set name")
@ClickHandler(slot = { 0, 5 })
public void onEditName(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
event.setCancelled(true);
if (modified.display != null) {
ctx.getMenu()
.transition(InputMenus.stringSetter(modified.display.getItemMeta()::getDisplayName, name -> {
ItemMeta meta = modified.display.getItemMeta();
meta.setDisplayName(name);
modified.display.setItemMeta(meta);
}));
}
}
@ClickHandler(slot = { 1, 4 })
public void onModifyDisplayItem(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
event.setCancelled(true);
if (event.getCursor() != null) {
event.setCurrentItem(event.getCursor());
modified.display = event.getCursor().clone();
} else {
event.setCurrentItem(null);
modified.display = null;
}
}
@ClickHandler(slot = { 4, 4 })
@MenuSlot(slot = { 4, 4 }, material = Material.TNT, amount = 1, lore = "<c>Remove")
public void onRemove(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
original = null;
event.setCancelled(true);
ctx.getMenu().transitionBack();
}
@ClickHandler(slot = { 4, 5 })
@MenuSlot(slot = { 4, 5 }, material = Material.EMERALD_BLOCK, amount = 1, lore = "Save")
public void onSave(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
original = modified;
event.setCancelled(true);
ctx.getMenu().transitionBack();
}
}
@ -152,12 +347,49 @@ public class ShopTrait extends Trait {
private final Map<Integer, NPCShopItem> items = Maps.newHashMap();
@Persist
private String title;
public NPCShopPage(int page) {
this.index = page;
}
}
@Menu(title = "NPC Shop Page Editor", type = InventoryType.CHEST, dimensions = { 5, 9 })
public static class NPCShopPageEditor extends InventoryMenuPage {
private MenuContext ctx;
private final NPCShopPage page;
public NPCShopPageEditor(NPCShopPage page) {
this.page = page;
}
@ClickHandler(slot = { 0, 4 })
@MenuSlot(slot = { 0, 4 }, material = Material.FEATHER, amount = 1)
public void editPageTitle(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
event.setCancelled(true);
ctx.getMenu().transition(InputMenus.stringSetter(() -> page.title, newTitle -> {
page.title = newTitle.isEmpty() ? null : newTitle;
}));
}
@Override
public void initialise(MenuContext ctx) {
this.ctx = ctx;
ctx.getSlot(4).setDescription("Set page title<br>Currently: " + page.title);
}
@ClickHandler(slot = { 4, 3 })
@MenuSlot(slot = { 4, 4 }, material = Material.TNT, amount = 1, title = "<c>Remove page")
public void removePage(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
event.setCancelled(true);
ctx.data().put("removePage", page.index);
ctx.getMenu().transitionBack();
}
}
public enum ShopType {
BUY,
SELL,
VIEW;
COMMAND,
SELL;
}
@Persist(value = "npcShops", reify = true, namespace = "shopstrait")

View File

@ -1,18 +1,19 @@
package net.citizensnpcs.trait.versioned;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Llama;
import org.bukkit.entity.Llama.Color;
import net.citizensnpcs.api.command.Command;
import net.citizensnpcs.api.command.CommandContext;
import net.citizensnpcs.api.command.CommandMessages;
import net.citizensnpcs.api.command.Requirements;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import net.citizensnpcs.api.trait.trait.MobType;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.trait.HorseModifiers;
import net.citizensnpcs.util.Messages;
@ -62,8 +63,10 @@ public class LlamaTrait extends Trait {
min = 1,
max = 1,
permission = "citizens.npc.llama")
@Requirements(selected = true, ownership = true, types = { EntityType.LLAMA, EntityType.TRADER_LLAMA })
@Requirements(selected = true, ownership = true)
public static void llama(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (npc.getOrAddTrait(MobType.class).getType().name().contains("LLAMA"))
throw new CommandException(CommandMessages.REQUIREMENTS_INVALID_MOB_TYPE);
LlamaTrait trait = npc.getOrAddTrait(LlamaTrait.class);
String output = "";
if (args.hasValueFlag("color") || args.hasValueFlag("colour")) {

View File

@ -35,6 +35,7 @@ import net.citizensnpcs.api.astar.AStarNode;
import net.citizensnpcs.api.astar.Agent;
import net.citizensnpcs.api.astar.Plan;
import net.citizensnpcs.api.command.CommandContext;
import net.citizensnpcs.api.command.CommandMessages;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.persistence.PersistenceLoader;
import net.citizensnpcs.api.util.DataKey;
@ -81,7 +82,7 @@ public class GuidedWaypointProvider implements EnumerableWaypointProvider {
@Override
public WaypointEditor createEditor(final CommandSender sender, CommandContext args) {
if (!(sender instanceof Player)) {
Messaging.sendErrorTr(sender, Messages.COMMAND_MUST_BE_INGAME);
Messaging.sendErrorTr(sender, CommandMessages.MUST_BE_INGAME);
return null;
}
final Player player = (Player) sender;

View File

@ -36,6 +36,7 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.ai.event.NavigatorCallback;
import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer;
import net.citizensnpcs.api.command.CommandContext;
import net.citizensnpcs.api.command.CommandMessages;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.NPCDespawnEvent;
import net.citizensnpcs.api.event.NPCRemoveEvent;
@ -114,7 +115,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
cachePaths = !cachePaths;
return null;
} else if (!(sender instanceof Player)) {
Messaging.sendErrorTr(sender, Messages.COMMAND_MUST_BE_INGAME);
Messaging.sendErrorTr(sender, CommandMessages.MUST_BE_INGAME);
return null;
}
return new LinearWaypointEditor((Player) sender);

View File

@ -64,19 +64,12 @@ public class Messages {
public static final String COMMAND_INVALID_MOBTYPE = "citizens.commands.invalid-mobtype";
public static final String COMMAND_LEFT_HAND_HEADER = "citizens.commands.npc.command.left-hand-header";
public static final String COMMAND_MISSING = "citizens.commands.help.command-missing";
public static final String COMMAND_MUST_BE_INGAME = "citizens.commands.requirements.must-be-ingame";
public static final String COMMAND_MUST_BE_OWNER = "citizens.commands.requirements.must-be-owner";
public static final String COMMAND_MUST_HAVE_SELECTED = "citizens.commands.requirements.must-have-selected";
public static final String COMMAND_NO_COMMANDS_ADDED = "citizens.commands.npc.command.none-added";
public static final String COMMAND_PAGE_MISSING = "citizens.commands.page-missing";
public static final String COMMAND_REMOVED = "citizens.commands.npc.command.command-removed";
public static final String COMMAND_REPORT_ERROR = "citizens.commands.console-error";
public static final String COMMAND_REQUIREMENTS_INVALID_MOB_TYPE = "citizens.commands.requirements.disallowed-mobtype";
public static final String COMMAND_RIGHT_HAND_HEADER = "citizens.commands.npc.command.right-hand-header";
public static final String COMMAND_SAVE_HELP = "citizens.commands.citizens.save.help";
public static final String COMMAND_TEMPORARY_PERMISSIONS_SET = "citizens.commands.npc.command.temporary-permissions-set";
public static final String COMMAND_TOO_FEW_ARGUMENTS = "citizens.commands.requirements.too-few-arguments";
public static final String COMMAND_TOO_MANY_ARGUMENTS = "citizens.commands.requirements.too-many-arguments";
public static final String COMMAND_UNKNOWN_COMMAND_ID = "citizens.commands.npc.command.unknown-id";
public static final String COMMANDS_RANDOM_SET = "citizens.commands.npc.commands.random-set";
public static final String COMMANDS_RANDOM_UNSET = "citizens.commands.npc.commands.random-unset";
@ -109,14 +102,9 @@ public class Messages {
public static final String ERROR_GETTING_METHOD = "citizens.nms-errors.getting-method";
public static final String ERROR_INITALISING_SUB_PLUGIN = "citizens.sub-plugins.error-on-load";
public static final String ERROR_RESTORING_GOALS = "citizens.nms-errors.restoring-goals";
public static final String ERROR_SETTING_ENTITY_PERSISTENT = "citizens.nms-errors.error-setting-persistent";
public static final String ERROR_SETTING_LOOKCLOSE_RANGE = "citizens.commands.npc.lookclose.error-random-range";
public static final String ERROR_SETTING_SKIN_URL = "citizens.commands.npc.skin.error-setting-url";
public static final String ERROR_SPAWNING_CUSTOM_ENTITY = "citizens.nms-errors.spawning-custom-entity";
public static final String ERROR_STOPPING_NETWORK_THREADS = "citizens.nms-errors.stopping-network-threads";
public static final String ERROR_UPDATING_NAVIGATION_WORLD = "citizens.nms-errors.updating-navigation-world";
public static final String ERROR_UPDATING_PATHFINDING_RANGE = "citizens.nms-errors.updating-pathfinding-range";
public static final String ERROR_UPDATING_SPEED = "citizens.nms-errors.updating-land-modifier";
public static final String EXCEPTION_UPDATING_NPC = "citizens.notifications.exception-updating-npc";
public static final String FAILED_LOAD_SAVES = "citizens.saves.load-failed";
public static final String FAILED_TO_MOUNT_NPC = "citizens.commands.npc.mount.failed";
@ -353,7 +341,6 @@ public class Messages {
public static final String TEXT_EDITOR_ADD_PROMPT = "citizens.editors.text.add-prompt";
public static final String TEXT_EDITOR_ADDED_ENTRY = "citizens.editors.text.added-entry";
public static final String TEXT_EDITOR_BEGIN = "citizens.editors.text.begin";
public static final String TEXT_EDITOR_CLOSE_TALKER_SET = "citizens.editors.text.close-talker-set";
public static final String TEXT_EDITOR_DELAY_SET = "citizens.editors.text.delay-set";
public static final String TEXT_EDITOR_END = "citizens.editors.text.end";
public static final String TEXT_EDITOR_INVALID_DELAY = "citizens.editors.text.invalid-delay";
@ -362,12 +349,8 @@ public class Messages {
public static final String TEXT_EDITOR_INVALID_PAGE = "citizens.editors.text.invalid-page";
public static final String TEXT_EDITOR_INVALID_RANGE = "citizens.editors.text.invalid-range";
public static final String TEXT_EDITOR_MISSING_ITEM_PATTERN = "citizens.editors.text.missing-item-set-pattern";
public static final String TEXT_EDITOR_PAGE_PROMPT = "citizens.editors.text.change-page-prompt";
public static final String TEXT_EDITOR_RANDOM_TALKER_SET = "citizens.editors.text.random-talker-set";
public static final String TEXT_EDITOR_RANGE_SET = "citizens.editors.text.range-set";
public static final String TEXT_EDITOR_REALISTIC_LOOKING_SET = "citizens.editors.text.realistic-looking-set";
public static final String TEXT_EDITOR_SET_ITEM = "citizens.editors.text.talk-item-set";
public static final String TEXT_EDITOR_SPEECH_BUBBLES_SET = "citizens.editors.text.speech-bubbles-set";
public static final String TEXT_EDITOR_START_PROMPT = "citizens.editors.text.start-prompt";
public static final String TO_ENTITY_NOT_FOUND = "citizens.commands.npc.tpto.to-not-found";
public static final String TOGGLED_USING_HELD_ITEM = "citizens.commands.npc.useitem.held-item-toggled";
@ -427,10 +410,4 @@ public class Messages {
public static final String WAYPOINT_TRIGGER_TELEPORT_PROMPT = "citizens.editors.waypoints.triggers.teleport.prompt";
public static final String WOLF_TRAIT_UPDATED = "citizens.commands.wolf.traits-updated";
public static final String WORLD_NOT_FOUND = "citizens.commands.errors.missing-world";
public static final String WRITING_DEFAULT_SETTING = "citizens.settings.writing-default";
public static final String ZOMBIE_BABY_SET = "citizens.commands.npc.zombiemod.baby-set";
public static final String ZOMBIE_BABY_UNSET = "citizens.commands.npc.zombiemod.baby-unset";
public static final String ZOMBIE_VILLAGER_PROFESSION_SET = "citizens.commands.npc.zombiemod.villager-profession-set";
public static final String ZOMBIE_VILLAGER_SET = "citizens.commands.npc.zombiemod.villager-set";
public static final String ZOMBIE_VILLAGER_UNSET = "citizens.commands.npc.zombiemod.villager-unset";
}

View File

@ -263,13 +263,8 @@ citizens.commands.npc.wolf.collar-color-unsupported=[[{0}]] is not a RGB color c
citizens.commands.npc.villager.level-set=Level set to [[{0}]].
citizens.commands.npc.villager.invalid-type=Invalid villager type. Valid types are: [[{0}]].
citizens.commands.npc.villager.type-set=Type set to [[{0}]].
citizens.commands.npc.undo.successful=Undo successful
citizens.commands.npc.undo.unsuccessful=No commands to undo
citizens.commands.npc.zombiemod.villager-set=[[{0}]] is now a villager.
citizens.commands.npc.zombiemod.villager-unset=[[{0}]] is no longer a villager.
citizens.commands.npc.zombiemod.baby-set=[[{0}]] is now a baby.
citizens.commands.npc.zombiemod.baby-unset=[[{0}]] is no longer a baby.
citizens.commands.npc.zombiemod.villager-profession-set=[[{0}]]''s profession set to [[{1}]].
citizens.commands.npc.undo.successful=Undo successful.
citizens.commands.npc.undo.unsuccessful=No commands to undo.
citizens.commands.page-missing=The page [[{0}]] does not exist.
citizens.commands.requirements.disallowed-mobtype=The NPC cannot be the mob type [[{0}]] for that command.
citizens.commands.requirements.living-entity=The NPC must be a living entity.

View File

@ -293,6 +293,7 @@ import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.inventory.AnvilMenu;
import net.minecraft.world.inventory.ContainerLevelAccess;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
@ -1471,9 +1472,82 @@ public class NMSImpl implements NMSBridge {
@Override
public void updateInventoryTitle(Player player, InventoryView view, String newTitle) {
ServerPlayer handle = (ServerPlayer) getHandle(player);
MenuType<?> menuType = null;
switch (view.getTopInventory().getType()) {
case ANVIL:
menuType = MenuType.ANVIL;
break;
case BARREL:
menuType = MenuType.GENERIC_9x3;
break;
case BEACON:
menuType = MenuType.BEACON;
break;
case BLAST_FURNACE:
menuType = MenuType.BLAST_FURNACE;
break;
case BREWING:
menuType = MenuType.BREWING_STAND;
break;
case CARTOGRAPHY:
menuType = MenuType.CARTOGRAPHY_TABLE;
break;
case CHEST:
menuType = MenuType.GENERIC_9x5;
break;
case COMPOSTER:
break;
case PLAYER:
case CRAFTING:
case CREATIVE:
return;
case DISPENSER:
case DROPPER:
menuType = MenuType.GENERIC_3x3;
break;
case ENCHANTING:
menuType = MenuType.ENCHANTMENT;
break;
case ENDER_CHEST:
menuType = MenuType.GENERIC_9x3;
break;
case FURNACE:
menuType = MenuType.FURNACE;
break;
case GRINDSTONE:
menuType = MenuType.GRINDSTONE;
break;
case HOPPER:
menuType = MenuType.HOPPER;
break;
case LECTERN:
menuType = MenuType.LECTERN;
break;
case LOOM:
menuType = MenuType.LOOM;
break;
case MERCHANT:
menuType = MenuType.MERCHANT;
break;
case SHULKER_BOX:
menuType = MenuType.SHULKER_BOX;
break;
case SMITHING:
menuType = MenuType.SMITHING;
break;
case SMOKER:
menuType = MenuType.SMOKER;
break;
case STONECUTTER:
menuType = MenuType.STONECUTTER;
break;
case WORKBENCH:
menuType = MenuType.CRAFTING;
break;
}
InventoryMenu active = handle.inventoryMenu;
handle.connection.send(new ClientboundOpenScreenPacket(active.containerId, active.getType(),
MutableComponent.create(new LiteralContents(""))));
handle.connection.send(new ClientboundOpenScreenPacket(active.containerId, menuType,
MutableComponent.create(new LiteralContents(newTitle))));
player.updateInventory();
}