Implement new API

This commit is contained in:
fullwall 2022-06-12 01:37:38 +08:00
parent 53d8e96c8d
commit 21f3a7755a
18 changed files with 215 additions and 15 deletions

View File

@ -12,7 +12,10 @@ import java.util.concurrent.Callable;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
@ -27,6 +30,7 @@ import com.mojang.authlib.properties.Property;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.CitizensPlugin;
import net.citizensnpcs.api.InventoryHelper;
import net.citizensnpcs.api.SkullMetaProvider;
import net.citizensnpcs.api.ai.speech.SpeechFactory;
import net.citizensnpcs.api.command.CommandContext;
@ -79,6 +83,16 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
private final CommandManager commands = new CommandManager();
private Settings config;
private boolean enabled;
private final InventoryHelper inventoryHelper = new InventoryHelper() {
@Override
public void updateInventoryTitle(Player player, InventoryView view, String newTitle) {
if (view.getTopInventory().getType() == InventoryType.CRAFTING
|| view.getTopInventory().getType() == InventoryType.CREATIVE
|| view.getTopInventory().getType() == InventoryType.PLAYER)
return;
NMS.updateInventoryTitle(player, view, newTitle);
}
};
private CitizensNPCRegistry npcRegistry;
private boolean saveOnDisable = true;
private NPCDataStore saves;
@ -189,6 +203,11 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
return selector;
}
@Override
public InventoryHelper getInventoryHelper() {
return inventoryHelper;
}
@Override
public NPCRegistry getNamedNPCRegistry(String name) {
if (name.equals(npcRegistry.getName()))

View File

@ -4,20 +4,18 @@ import java.util.Map;
import java.util.function.Consumer;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import com.google.common.collect.Maps;
import net.citizensnpcs.api.gui.CitizensInventoryClickEvent;
import net.citizensnpcs.api.gui.InputMenu;
import net.citizensnpcs.api.gui.InventoryMenuPage;
import net.citizensnpcs.api.gui.InventoryMenuSlot;
import net.citizensnpcs.api.gui.Menu;
import net.citizensnpcs.api.gui.MenuContext;
import net.citizensnpcs.api.gui.ModalMenuInput;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Util;
@Menu(title = "Configure NPC", type = InventoryType.CHEST, dimensions = { 5, 9 })
@ -74,9 +72,8 @@ public class NPCConfigurator extends InventoryMenuPage {
SLOT_MAP.put(0, new ConfiguratorInfo(Util.getFallbackMaterial("OAK_SIGN", "SIGN"), (evt) -> {
evt.slot.setDescription("Edit NPC name\n" + evt.npc.getName());
if (evt.event != null) {
Messaging.send(evt.event.getWhoClicked(), "Type new NPC name or [[exit]]");
ModalMenuInput.captureInput((Player) evt.event.getWhoClicked(), evt.ctx.getMenu(),
(input) -> evt.npc.setName(input));
evt.ctx.getMenu()
.transition(InputMenu.setter(() -> evt.npc.getName(), (input) -> evt.npc.setName(input)));
}
}));

View File

@ -302,6 +302,7 @@ public class CitizensNPC extends AbstractNPC {
Messaging.debug("Couldn't spawn", CitizensNPC.this, "entity not added to world");
entityController.remove();
cancel();
Bukkit.getPluginManager().callEvent(new NPCNeedsRespawnEvent(CitizensNPC.this, to));
return;
}

View File

@ -5,7 +5,6 @@ import java.util.Map;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
@ -48,6 +47,8 @@ public class ShopTrait extends Trait {
@Persist(reify = true)
private final List<NPCShopPage> pages = Lists.newArrayList();
@Persist
private String requiredPermission;
@Persist
private final ShopType type = ShopType.VIEW;
private NPCShop(String name) {
@ -55,18 +56,31 @@ public class ShopTrait extends Trait {
}
public void display(Player sender) {
if (requiredPermission != null && !sender.hasPermission(requiredPermission))
return;
}
public void displayEditor(Player sender) {
InventoryMenu.create(new NPCShopEditor(this)).present(sender);
InventoryMenu.createSelfRegistered(new NPCShopEditor(this)).present(sender);
}
public String getName() {
return name;
}
public String getRequiredPermission() {
return requiredPermission;
}
public void setPermission(String permission) {
this.requiredPermission = permission;
if (requiredPermission != null && requiredPermission.isEmpty()) {
requiredPermission = null;
}
}
}
@Menu(title = "NPC Equipment", type = InventoryType.HOPPER, dimensions = { 0, 5 })
@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")
public static class NPCShopEditor extends InventoryMenuPage {
@ -82,13 +96,16 @@ public class ShopTrait extends Trait {
this.ctx = ctx;
}
@ClickHandler(slot = { 0, 2 }, filter = { InventoryAction.PICKUP_ALL, InventoryAction.PICKUP_ONE })
@ClickHandler(slot = { 0, 2 })
public void onPermissionChange(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
ctx.getMenu().transition(new InputMenu());
event.setCancelled(true);
ctx.getMenu()
.transition(InputMenu.setter(() -> shop.getRequiredPermission(), (p) -> shop.setPermission(p)));
}
@ClickHandler(slot = { 0, 0 }, filter = { InventoryAction.PICKUP_ALL, InventoryAction.PICKUP_ONE })
@ClickHandler(slot = { 0, 0 })
public void onShopTypeChange(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
event.setCancelled(true);
}
}

View File

@ -20,7 +20,7 @@ import net.citizensnpcs.trait.waypoint.triggers.WaypointTriggerRegistry;
import net.citizensnpcs.util.Messages;
/**
* Represents a {@link Location} with a number of {@link WaypointTriggers} that activate on reaching the location.
* Represents a {@link Location} with a number of {@link WaypointTrigger}s that activate on reaching the location.
*/
public class Waypoint implements Locatable {
@Persist(required = true)

View File

@ -20,6 +20,7 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector;
@ -620,6 +621,10 @@ public class NMS {
BRIDGE.trySwim(entity, power);
}
public static void updateInventoryTitle(Player player, InventoryView view, String newTitle) {
BRIDGE.updateInventoryTitle(player, view, newTitle);
}
public static void updateNavigationWorld(org.bukkit.entity.Entity entity, org.bukkit.World world) {
BRIDGE.updateNavigationWorld(entity, world);
}

View File

@ -15,6 +15,7 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector;
@ -187,6 +188,8 @@ public interface NMSBridge {
public void trySwim(Entity entity, float power);
public void updateInventoryTitle(Player player, InventoryView view, String newTitle);
public void updateNavigationWorld(Entity entity, World world);
public void updatePathfindingRange(NPC npc, float pathfindingRange);

View File

@ -39,6 +39,8 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginLoadOrder;
import org.bukkit.scoreboard.Team;
@ -160,6 +162,8 @@ import net.minecraft.server.v1_10_R1.AxisAlignedBB;
import net.minecraft.server.v1_10_R1.Block;
import net.minecraft.server.v1_10_R1.BlockPosition;
import net.minecraft.server.v1_10_R1.BossBattleServer;
import net.minecraft.server.v1_10_R1.ChatComponentText;
import net.minecraft.server.v1_10_R1.Container;
import net.minecraft.server.v1_10_R1.ControllerJump;
import net.minecraft.server.v1_10_R1.ControllerMove;
import net.minecraft.server.v1_10_R1.CrashReport;
@ -194,6 +198,7 @@ import net.minecraft.server.v1_10_R1.NavigationAbstract;
import net.minecraft.server.v1_10_R1.NetworkManager;
import net.minecraft.server.v1_10_R1.Packet;
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_10_R1.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_10_R1.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_10_R1.PacketPlayOutScoreboardTeam;
import net.minecraft.server.v1_10_R1.PathEntity;
@ -1151,6 +1156,17 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void updateInventoryTitle(Player player, InventoryView view, String newTitle) {
EntityPlayer handle = (EntityPlayer) getHandle(player);
Container active = handle.activeContainer;
InventoryType type = view.getTopInventory().getType();
Packet<?> packet = new PacketPlayOutOpenWindow(active.windowId, "minecraft:" + type.name().toLowerCase(),
new ChatComponentText(newTitle), view.getTopInventory().getSize());
handle.playerConnection.sendPacket(packet);
player.updateInventory();
}
@Override
public void updateNavigationWorld(org.bukkit.entity.Entity entity, World world) {
if (NAVIGATION_WORLD_FIELD == null)

View File

@ -38,6 +38,8 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginLoadOrder;
import org.bukkit.scoreboard.Team;
@ -175,6 +177,8 @@ import net.minecraft.server.v1_11_R1.AxisAlignedBB;
import net.minecraft.server.v1_11_R1.Block;
import net.minecraft.server.v1_11_R1.BlockPosition;
import net.minecraft.server.v1_11_R1.BossBattleServer;
import net.minecraft.server.v1_11_R1.ChatComponentText;
import net.minecraft.server.v1_11_R1.Container;
import net.minecraft.server.v1_11_R1.ControllerJump;
import net.minecraft.server.v1_11_R1.ControllerMove;
import net.minecraft.server.v1_11_R1.CrashReport;
@ -212,6 +216,7 @@ import net.minecraft.server.v1_11_R1.NavigationAbstract;
import net.minecraft.server.v1_11_R1.NetworkManager;
import net.minecraft.server.v1_11_R1.Packet;
import net.minecraft.server.v1_11_R1.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_11_R1.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_11_R1.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_11_R1.PacketPlayOutScoreboardTeam;
import net.minecraft.server.v1_11_R1.PathEntity;
@ -1215,6 +1220,17 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void updateInventoryTitle(Player player, InventoryView view, String newTitle) {
EntityPlayer handle = (EntityPlayer) getHandle(player);
Container active = handle.activeContainer;
InventoryType type = view.getTopInventory().getType();
Packet<?> packet = new PacketPlayOutOpenWindow(active.windowId, "minecraft:" + type.name().toLowerCase(),
new ChatComponentText(newTitle), view.getTopInventory().getSize());
handle.playerConnection.sendPacket(packet);
player.updateInventory();
}
@Override
public void updateNavigationWorld(org.bukkit.entity.Entity entity, World world) {
if (NAVIGATION_WORLD_FIELD == null)

View File

@ -38,6 +38,8 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginLoadOrder;
import org.bukkit.scoreboard.Team;
@ -178,6 +180,8 @@ import net.minecraft.server.v1_12_R1.AxisAlignedBB;
import net.minecraft.server.v1_12_R1.Block;
import net.minecraft.server.v1_12_R1.BlockPosition;
import net.minecraft.server.v1_12_R1.BossBattleServer;
import net.minecraft.server.v1_12_R1.ChatComponentText;
import net.minecraft.server.v1_12_R1.Container;
import net.minecraft.server.v1_12_R1.ControllerJump;
import net.minecraft.server.v1_12_R1.ControllerMove;
import net.minecraft.server.v1_12_R1.CrashReport;
@ -216,6 +220,7 @@ import net.minecraft.server.v1_12_R1.NavigationAbstract;
import net.minecraft.server.v1_12_R1.NetworkManager;
import net.minecraft.server.v1_12_R1.Packet;
import net.minecraft.server.v1_12_R1.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_12_R1.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_12_R1.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_12_R1.PacketPlayOutScoreboardTeam;
import net.minecraft.server.v1_12_R1.PathEntity;
@ -1223,6 +1228,17 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void updateInventoryTitle(Player player, InventoryView view, String newTitle) {
EntityPlayer handle = (EntityPlayer) getHandle(player);
Container active = handle.activeContainer;
InventoryType type = view.getTopInventory().getType();
Packet<?> packet = new PacketPlayOutOpenWindow(active.windowId, "minecraft:" + type.name().toLowerCase(),
new ChatComponentText(newTitle), view.getTopInventory().getSize());
handle.playerConnection.sendPacket(packet);
player.updateInventory();
}
@Override
public void updateNavigationWorld(org.bukkit.entity.Entity entity, World world) {
if (NAVIGATION_WORLD_FIELD == null)

View File

@ -40,6 +40,8 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginLoadOrder;
import org.bukkit.scoreboard.Team;
@ -192,6 +194,8 @@ import net.minecraft.server.v1_13_R2.AxisAlignedBB;
import net.minecraft.server.v1_13_R2.Block;
import net.minecraft.server.v1_13_R2.BlockPosition;
import net.minecraft.server.v1_13_R2.BossBattleServer;
import net.minecraft.server.v1_13_R2.ChatComponentText;
import net.minecraft.server.v1_13_R2.Container;
import net.minecraft.server.v1_13_R2.ControllerJump;
import net.minecraft.server.v1_13_R2.ControllerMove;
import net.minecraft.server.v1_13_R2.CrashReport;
@ -234,6 +238,7 @@ import net.minecraft.server.v1_13_R2.NavigationAbstract;
import net.minecraft.server.v1_13_R2.NetworkManager;
import net.minecraft.server.v1_13_R2.Packet;
import net.minecraft.server.v1_13_R2.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_13_R2.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_13_R2.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_13_R2.PacketPlayOutScoreboardTeam;
import net.minecraft.server.v1_13_R2.PathEntity;
@ -1262,6 +1267,17 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void updateInventoryTitle(Player player, InventoryView view, String newTitle) {
EntityPlayer handle = (EntityPlayer) getHandle(player);
Container active = handle.activeContainer;
InventoryType type = view.getTopInventory().getType();
Packet<?> packet = new PacketPlayOutOpenWindow(active.windowId, "minecraft:" + type.name().toLowerCase(),
new ChatComponentText(newTitle), view.getTopInventory().getSize());
handle.playerConnection.sendPacket(packet);
player.updateInventory();
}
@Override
public void updateNavigationWorld(org.bukkit.entity.Entity entity, World world) {
if (NAVIGATION_WORLD_FIELD == null)

View File

@ -41,6 +41,7 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginLoadOrder;
import org.bukkit.scoreboard.Team;
@ -207,7 +208,9 @@ import net.minecraft.server.v1_14_R1.BehaviorController;
import net.minecraft.server.v1_14_R1.Block;
import net.minecraft.server.v1_14_R1.BlockPosition;
import net.minecraft.server.v1_14_R1.BossBattleServer;
import net.minecraft.server.v1_14_R1.ChatComponentText;
import net.minecraft.server.v1_14_R1.ChunkProviderServer;
import net.minecraft.server.v1_14_R1.Container;
import net.minecraft.server.v1_14_R1.ControllerJump;
import net.minecraft.server.v1_14_R1.ControllerMove;
import net.minecraft.server.v1_14_R1.CrashReport;
@ -253,6 +256,7 @@ import net.minecraft.server.v1_14_R1.NavigationAbstract;
import net.minecraft.server.v1_14_R1.NetworkManager;
import net.minecraft.server.v1_14_R1.Packet;
import net.minecraft.server.v1_14_R1.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_14_R1.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_14_R1.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_14_R1.PacketPlayOutScoreboardTeam;
import net.minecraft.server.v1_14_R1.PathEntity;
@ -1322,6 +1326,15 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void updateInventoryTitle(Player player, InventoryView view, String newTitle) {
EntityPlayer handle = (EntityPlayer) getHandle(player);
Container active = handle.activeContainer;
handle.playerConnection.sendPacket(
new PacketPlayOutOpenWindow(active.windowId, active.getType(), new ChatComponentText(newTitle)));
player.updateInventory();
}
@Override
public void updateNavigationWorld(org.bukkit.entity.Entity entity, World world) {
if (NAVIGATION_WORLD_FIELD == null)

View File

@ -41,6 +41,7 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginLoadOrder;
import org.bukkit.scoreboard.Team;
@ -209,7 +210,9 @@ import net.minecraft.server.v1_15_R1.BehaviorController;
import net.minecraft.server.v1_15_R1.Block;
import net.minecraft.server.v1_15_R1.BlockPosition;
import net.minecraft.server.v1_15_R1.BossBattleServer;
import net.minecraft.server.v1_15_R1.ChatComponentText;
import net.minecraft.server.v1_15_R1.ChunkProviderServer;
import net.minecraft.server.v1_15_R1.Container;
import net.minecraft.server.v1_15_R1.ControllerJump;
import net.minecraft.server.v1_15_R1.ControllerMove;
import net.minecraft.server.v1_15_R1.ControllerMoveFlying;
@ -257,6 +260,7 @@ import net.minecraft.server.v1_15_R1.NavigationAbstract;
import net.minecraft.server.v1_15_R1.NetworkManager;
import net.minecraft.server.v1_15_R1.Packet;
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_15_R1.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_15_R1.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_15_R1.PacketPlayOutScoreboardTeam;
import net.minecraft.server.v1_15_R1.PathEntity;
@ -1361,6 +1365,15 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void updateInventoryTitle(Player player, InventoryView view, String newTitle) {
EntityPlayer handle = (EntityPlayer) getHandle(player);
Container active = handle.activeContainer;
handle.playerConnection.sendPacket(
new PacketPlayOutOpenWindow(active.windowId, active.getType(), new ChatComponentText(newTitle)));
player.updateInventory();
}
@Override
public void updateNavigationWorld(org.bukkit.entity.Entity entity, World world) {
if (NAVIGATION_WORLD_FIELD == null)

View File

@ -41,6 +41,7 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginLoadOrder;
import org.bukkit.scoreboard.Team;
@ -214,7 +215,9 @@ import net.minecraft.server.v1_16_R3.BehaviorController;
import net.minecraft.server.v1_16_R3.Block;
import net.minecraft.server.v1_16_R3.BlockPosition;
import net.minecraft.server.v1_16_R3.BossBattleServer;
import net.minecraft.server.v1_16_R3.ChatComponentText;
import net.minecraft.server.v1_16_R3.ChunkProviderServer;
import net.minecraft.server.v1_16_R3.Container;
import net.minecraft.server.v1_16_R3.ControllerJump;
import net.minecraft.server.v1_16_R3.ControllerMove;
import net.minecraft.server.v1_16_R3.ControllerMoveFlying;
@ -263,6 +266,7 @@ import net.minecraft.server.v1_16_R3.NavigationAbstract;
import net.minecraft.server.v1_16_R3.NetworkManager;
import net.minecraft.server.v1_16_R3.Packet;
import net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_16_R3.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_16_R3.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_16_R3.PacketPlayOutScoreboardTeam;
import net.minecraft.server.v1_16_R3.PathEntity;
@ -1383,6 +1387,15 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void updateInventoryTitle(Player player, InventoryView view, String newTitle) {
EntityPlayer handle = (EntityPlayer) getHandle(player);
Container active = handle.activeContainer;
handle.playerConnection.sendPacket(
new PacketPlayOutOpenWindow(active.windowId, active.getType(), new ChatComponentText(newTitle)));
player.updateInventory();
}
@Override
public void updateNavigationWorld(org.bukkit.entity.Entity entity, World world) {
if (NAVIGATION_WORLD_FIELD == null)

View File

@ -39,6 +39,7 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginLoadOrder;
import org.bukkit.scoreboard.Team;
@ -217,7 +218,9 @@ import net.minecraft.ReportedException;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
@ -268,6 +271,7 @@ import net.minecraft.world.entity.monster.EnderMan;
import net.minecraft.world.entity.monster.Shulker;
import net.minecraft.world.entity.projectile.FishingHook;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
@ -1381,6 +1385,15 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void updateInventoryTitle(Player player, InventoryView view, String newTitle) {
ServerPlayer handle = (ServerPlayer) getHandle(player);
InventoryMenu active = handle.inventoryMenu;
handle.connection.send(
new ClientboundOpenScreenPacket(active.containerId, active.getType(), new TextComponent(newTitle)));
player.updateInventory();
}
@Override
public void updateNavigationWorld(org.bukkit.entity.Entity entity, World world) {
if (NAVIGATION_WORLD_FIELD == null)

View File

@ -40,6 +40,7 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginLoadOrder;
import org.bukkit.scoreboard.Team;
@ -219,7 +220,9 @@ import net.minecraft.ReportedException;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
@ -271,6 +274,7 @@ import net.minecraft.world.entity.monster.EnderMan;
import net.minecraft.world.entity.monster.Shulker;
import net.minecraft.world.entity.projectile.FishingHook;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
@ -1388,6 +1392,15 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void updateInventoryTitle(Player player, InventoryView view, String newTitle) {
ServerPlayer handle = (ServerPlayer) getHandle(player);
InventoryMenu active = handle.inventoryMenu;
handle.connection.send(
new ClientboundOpenScreenPacket(active.containerId, active.getType(), new TextComponent(newTitle)));
player.updateInventory();
}
@Override
public void updateNavigationWorld(org.bukkit.entity.Entity entity, World world) {
if (NAVIGATION_WORLD_FIELD == null)

View File

@ -40,6 +40,7 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginLoadOrder;
import org.bukkit.scoreboard.Team;
@ -226,7 +227,10 @@ import net.minecraft.ReportedException;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.LiteralContents;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
@ -278,6 +282,7 @@ import net.minecraft.world.entity.monster.EnderMan;
import net.minecraft.world.entity.monster.Shulker;
import net.minecraft.world.entity.projectile.FishingHook;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
@ -1402,6 +1407,15 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void updateInventoryTitle(Player player, InventoryView view, String newTitle) {
ServerPlayer handle = (ServerPlayer) getHandle(player);
InventoryMenu active = handle.inventoryMenu;
handle.connection.send(new ClientboundOpenScreenPacket(active.containerId, active.getType(),
MutableComponent.create(new LiteralContents(""))));
player.updateInventory();
}
@Override
public void updateNavigationWorld(org.bukkit.entity.Entity entity, World world) {
if (NAVIGATION_WORLD_FIELD == null)

View File

@ -36,6 +36,8 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginLoadOrder;
import org.bukkit.scoreboard.Team;
@ -143,6 +145,8 @@ import net.minecraft.server.v1_8_R3.AttributeInstance;
import net.minecraft.server.v1_8_R3.AxisAlignedBB;
import net.minecraft.server.v1_8_R3.Block;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.ChatComponentText;
import net.minecraft.server.v1_8_R3.Container;
import net.minecraft.server.v1_8_R3.ControllerJump;
import net.minecraft.server.v1_8_R3.ControllerMove;
import net.minecraft.server.v1_8_R3.CrashReport;
@ -170,6 +174,7 @@ import net.minecraft.server.v1_8_R3.NavigationAbstract;
import net.minecraft.server.v1_8_R3.NetworkManager;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_8_R3.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_8_R3.PacketPlayOutScoreboardTeam;
import net.minecraft.server.v1_8_R3.PathEntity;
@ -1102,6 +1107,17 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void updateInventoryTitle(Player player, InventoryView view, String newTitle) {
EntityPlayer handle = (EntityPlayer) getHandle(player);
Container active = handle.activeContainer;
InventoryType type = view.getTopInventory().getType();
Packet<?> packet = new PacketPlayOutOpenWindow(active.windowId, "minecraft:" + type.name().toLowerCase(),
new ChatComponentText(newTitle), view.getTopInventory().getSize());
handle.playerConnection.sendPacket(packet);
player.updateInventory();
}
@Override
public void updateNavigationWorld(org.bukkit.entity.Entity entity, World world) {
if (NAVIGATION_WORLD_FIELD == null)
@ -1404,7 +1420,7 @@ public class NMSImpl implements NMSBridge {
public static void sendPacket(Player player, Packet<?> packet) {
if (packet == null)
return;
((EntityPlayer) NMSImpl.getHandle(player)).playerConnection.sendPacket(packet);
((EntityPlayer) getHandle(player)).playerConnection.sendPacket(packet);
}
public static void sendPacketNearby(Player from, Location location, Packet<?> packet) {
@ -1475,7 +1491,6 @@ public class NMSImpl implements NMSBridge {
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.SILVERFISH, EntityType.ENDERMITE,
EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE, EntityType.HORSE,
EntityType.GHAST);
private static final float DEFAULT_SPEED = 1F;
private static Method ENTITY_ATTACK_A = NMS.getMethod(Entity.class, "a", true, EntityLiving.class, Entity.class);
private static Map<Class<?>, Integer> ENTITY_CLASS_TO_INT;