diff --git a/api/src/main/java/com/lishid/openinv/IOpenInv.java b/api/src/main/java/com/lishid/openinv/IOpenInv.java index db8919b..d968b63 100644 --- a/api/src/main/java/com/lishid/openinv/IOpenInv.java +++ b/api/src/main/java/com/lishid/openinv/IOpenInv.java @@ -19,9 +19,11 @@ package com.lishid.openinv; import com.lishid.openinv.internal.IAnySilentContainer; import com.lishid.openinv.internal.IInventoryAccess; import com.lishid.openinv.internal.ISpecialEnderChest; +import com.lishid.openinv.internal.ISpecialInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -49,8 +51,7 @@ public interface IOpenInv { * @return the ISilentContainer * @throws IllegalStateException if the server version is unsupported */ - @NotNull - IAnySilentContainer getAnySilentContainer(); + @NotNull IAnySilentContainer getAnySilentContainer(); /** * Gets the active IInventoryAccess implementation. @@ -58,8 +59,7 @@ public interface IOpenInv { * @return the IInventoryAccess * @throws IllegalStateException if the server version is unsupported */ - @NotNull - IInventoryAccess getInventoryAccess(); + @NotNull IInventoryAccess getInventoryAccess(); /** * Gets the provided player's AnyChest setting. @@ -78,8 +78,7 @@ public interface IOpenInv { * @return the identifier * @throws IllegalStateException if the server version is unsupported */ - @NotNull - String getPlayerID(@NotNull OfflinePlayer offline); + @NotNull String getPlayerID(@NotNull OfflinePlayer offline); /** * Gets a player's SilentChest setting. @@ -99,8 +98,7 @@ public interface IOpenInv { * @throws IllegalStateException if the server version is unsupported * @throws InstantiationException if the ISpecialEnderChest could not be instantiated */ - @NotNull - ISpecialEnderChest getSpecialEnderChest(@NotNull Player player, boolean online) throws InstantiationException; + @NotNull ISpecialEnderChest getSpecialEnderChest(@NotNull Player player, boolean online) throws InstantiationException; /** * Gets an ISpecialPlayerInventory for the given Player. @@ -111,8 +109,7 @@ public interface IOpenInv { * @throws IllegalStateException if the server version is unsupported * @throws InstantiationException if the ISpecialPlayerInventory could not be instantiated */ - @NotNull - ISpecialPlayerInventory getSpecialInventory(@NotNull Player player, boolean online) throws InstantiationException; + @NotNull ISpecialPlayerInventory getSpecialInventory(@NotNull Player player, boolean online) throws InstantiationException; /** * Checks if the server version is supported by OpenInv. @@ -128,8 +125,7 @@ public interface IOpenInv { * @return the Player, or null * @throws IllegalStateException if the server version is unsupported */ - @Nullable - Player loadPlayer(@NotNull final OfflinePlayer offline); + @Nullable Player loadPlayer(@NotNull final OfflinePlayer offline); /** * Get an OfflinePlayer by name. @@ -141,8 +137,16 @@ public interface IOpenInv { * @param name the name of the Player * @return the OfflinePlayer with the closest matching name or null if no players have ever logged in */ - @Nullable - OfflinePlayer matchPlayer(@NotNull String name); + @Nullable OfflinePlayer matchPlayer(@NotNull String name); + + /** + * Open an ISpecialInventory for a Player. + * + * @param player the Player + * @param inventory the ISpecialInventory + * @return the InventoryView for the opened ISpecialInventory + */ + @Nullable InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory); /** * Check the configuration value for whether or not OpenInv displays a notification to the user diff --git a/api/src/main/java/com/lishid/openinv/internal/IInventoryAccess.java b/api/src/main/java/com/lishid/openinv/internal/IInventoryAccess.java index 648cce9..97f1160 100644 --- a/api/src/main/java/com/lishid/openinv/internal/IInventoryAccess.java +++ b/api/src/main/java/com/lishid/openinv/internal/IInventoryAccess.java @@ -29,8 +29,7 @@ public interface IInventoryAccess { * @param inventory the Inventory * @return the ISpecialEnderChest or null */ - @Nullable - ISpecialEnderChest getSpecialEnderChest(@NotNull Inventory inventory); + @Nullable ISpecialEnderChest getSpecialEnderChest(@NotNull Inventory inventory); /** * Gets an ISpecialPlayerInventory from an Inventory or null if the Inventory is not backed by @@ -39,8 +38,7 @@ public interface IInventoryAccess { * @param inventory the Inventory * @return the ISpecialPlayerInventory or null */ - @Nullable - ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull Inventory inventory); + @Nullable ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull Inventory inventory); /** * Check if an Inventory is an ISpecialEnderChest implementation. diff --git a/api/src/main/java/com/lishid/openinv/internal/ISpecialEnderChest.java b/api/src/main/java/com/lishid/openinv/internal/ISpecialEnderChest.java index 5cc04ef..03f1570 100644 --- a/api/src/main/java/com/lishid/openinv/internal/ISpecialEnderChest.java +++ b/api/src/main/java/com/lishid/openinv/internal/ISpecialEnderChest.java @@ -16,37 +16,6 @@ package com.lishid.openinv.internal; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.jetbrains.annotations.NotNull; - -public interface ISpecialEnderChest { - - /** - * Gets the Inventory associated with this ISpecialEnderChest. - * - * @return the Inventory - */ - @NotNull - Inventory getBukkitInventory(); - - /** - * Sets the Player associated with this ISpecialEnderChest online. - * - * @param player the Player coming online - */ - void setPlayerOnline(@NotNull Player player); - - /** - * Sets the Player associated with this ISpecialEnderChest offline. - */ - void setPlayerOffline(); - - /** - * Gets whether or not this ISpecialEnderChest is in use. - * - * @return true if the ISpecialEnderChest is in use - */ - boolean isInUse(); +public interface ISpecialEnderChest extends ISpecialInventory { } diff --git a/api/src/main/java/com/lishid/openinv/internal/ISpecialInventory.java b/api/src/main/java/com/lishid/openinv/internal/ISpecialInventory.java new file mode 100644 index 0000000..22a1be7 --- /dev/null +++ b/api/src/main/java/com/lishid/openinv/internal/ISpecialInventory.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2011-2019 lishid. All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lishid.openinv.internal; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.jetbrains.annotations.NotNull; + +public interface ISpecialInventory { + + /** + * Gets the Inventory associated with this ISpecialEnderChest. + * + * @return the Inventory + */ + @NotNull Inventory getBukkitInventory(); + + /** + * Sets the Player associated with this ISpecialEnderChest online. + * + * @param player the Player coming online + */ + void setPlayerOnline(@NotNull Player player); + + /** + * Sets the Player associated with this ISpecialEnderChest offline. + */ + void setPlayerOffline(); + + /** + * Gets whether or not this ISpecialEnderChest is in use. + * + * @return true if the ISpecialEnderChest is in use + */ + boolean isInUse(); + +} diff --git a/api/src/main/java/com/lishid/openinv/internal/ISpecialPlayerInventory.java b/api/src/main/java/com/lishid/openinv/internal/ISpecialPlayerInventory.java index 5420962..51bc06a 100644 --- a/api/src/main/java/com/lishid/openinv/internal/ISpecialPlayerInventory.java +++ b/api/src/main/java/com/lishid/openinv/internal/ISpecialPlayerInventory.java @@ -16,37 +16,6 @@ package com.lishid.openinv.internal; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.jetbrains.annotations.NotNull; - -public interface ISpecialPlayerInventory { - - /** - * Gets the Inventory associated with this ISpecialPlayerInventory. - * - * @return the Inventory - */ - @NotNull - Inventory getBukkitInventory(); - - /** - * Sets the Player associated with this ISpecialPlayerInventory online. - * - * @param player the Player coming online - */ - void setPlayerOnline(@NotNull Player player); - - /** - * Sets the Player associated with this ISpecialPlayerInventory offline. - */ - void setPlayerOffline(); - - /** - * Gets whether or not this ISpecialPlayerInventory is in use. - * - * @return true if the ISpecialPlayerInventory is in use - */ - boolean isInUse(); +public interface ISpecialPlayerInventory extends ISpecialInventory { } diff --git a/common/src/main/java/com/lishid/openinv/internal/IPlayerDataManager.java b/common/src/main/java/com/lishid/openinv/internal/IPlayerDataManager.java index 3dc3d75..4419118 100644 --- a/common/src/main/java/com/lishid/openinv/internal/IPlayerDataManager.java +++ b/common/src/main/java/com/lishid/openinv/internal/IPlayerDataManager.java @@ -19,6 +19,7 @@ package com.lishid.openinv.internal; import java.util.Collection; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -32,8 +33,7 @@ public interface IPlayerDataManager { * @param offline the OfflinePlayer * @return the Player loaded */ - @Nullable - Player loadPlayer(@NotNull OfflinePlayer offline); + @Nullable Player loadPlayer(@NotNull OfflinePlayer offline); /** * Gets a unique identifying string for an OfflinePlayer. @@ -41,8 +41,7 @@ public interface IPlayerDataManager { * @param offline the OfflinePlayer * @return the unique identifier */ - @NotNull - String getPlayerDataID(@NotNull OfflinePlayer offline); + @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline); /** * Gets an OfflinePlayer by the given unique identifier. @@ -50,15 +49,23 @@ public interface IPlayerDataManager { * @param identifier the unique identifier * @return the OfflinePlayer, or null if no exact match was found */ - @Nullable - OfflinePlayer getPlayerByID(@NotNull String identifier); + @Nullable OfflinePlayer getPlayerByID(@NotNull String identifier); /** * Gets a Collection of all Players currently online. * * @return the Collection of Players */ - @NotNull - Collection getOnlinePlayers(); + @NotNull Collection getOnlinePlayers(); + + /** + * Opens an ISpecialInventory for a Player. + * + * @param player the Player opening the ISpecialInventory + * @param inventory the Inventory + *` + * @return the InventoryView opened + */ + InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory); } diff --git a/internal/1_4_5/src/main/java/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java b/internal/1_4_5/src/main/java/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java index f92cc0e..96270cb 100644 --- a/internal/1_4_5/src/main/java/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java +++ b/internal/1_4_5/src/main/java/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_4_5; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import java.util.Arrays; import java.util.Collection; import net.minecraft.server.v1_4_5.EntityPlayer; @@ -28,6 +29,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_4_5.CraftServer; import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -55,9 +57,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getName(); } @@ -71,9 +72,8 @@ public class PlayerDataManager implements IPlayerDataManager { return player; } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Arrays.asList(Bukkit.getOnlinePlayers()); } @@ -97,4 +97,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/1_4_6/src/main/java/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java b/internal/1_4_6/src/main/java/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java index 5ce88e0..f6805ec 100644 --- a/internal/1_4_6/src/main/java/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java +++ b/internal/1_4_6/src/main/java/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_4_6; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import java.util.Arrays; import java.util.Collection; import net.minecraft.server.v1_4_6.EntityPlayer; @@ -28,6 +29,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_4_6.CraftServer; import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -55,9 +57,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getName(); } @@ -71,9 +72,8 @@ public class PlayerDataManager implements IPlayerDataManager { return player; } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Arrays.asList(Bukkit.getOnlinePlayers()); } @@ -97,4 +97,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_10_R1/src/main/java/com/lishid/openinv/internal/v1_10_R1/PlayerDataManager.java b/internal/v1_10_R1/src/main/java/com/lishid/openinv/internal/v1_10_R1/PlayerDataManager.java index 6d5d91c..702eb6a 100644 --- a/internal/v1_10_R1/src/main/java/com/lishid/openinv/internal/v1_10_R1/PlayerDataManager.java +++ b/internal/v1_10_R1/src/main/java/com/lishid/openinv/internal/v1_10_R1/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_10_R1; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import com.mojang.authlib.GameProfile; import java.util.Collection; import java.util.UUID; @@ -29,6 +30,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_10_R1.CraftServer; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -56,9 +58,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getUniqueId().toString(); } @@ -78,9 +79,8 @@ public class PlayerDataManager implements IPlayerDataManager { } } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Bukkit.getOnlinePlayers(); } @@ -104,4 +104,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/PlayerDataManager.java b/internal/v1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/PlayerDataManager.java index 083bc0f..433f40d 100644 --- a/internal/v1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/PlayerDataManager.java +++ b/internal/v1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_11_R1; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import com.mojang.authlib.GameProfile; import java.util.Collection; import java.util.UUID; @@ -29,6 +30,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_11_R1.CraftServer; import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -56,9 +58,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getUniqueId().toString(); } @@ -78,9 +79,8 @@ public class PlayerDataManager implements IPlayerDataManager { } } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Bukkit.getOnlinePlayers(); } @@ -104,4 +104,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_12_R1/src/main/java/com/lishid/openinv/internal/v1_12_R1/PlayerDataManager.java b/internal/v1_12_R1/src/main/java/com/lishid/openinv/internal/v1_12_R1/PlayerDataManager.java index 6261ae6..266b68a 100644 --- a/internal/v1_12_R1/src/main/java/com/lishid/openinv/internal/v1_12_R1/PlayerDataManager.java +++ b/internal/v1_12_R1/src/main/java/com/lishid/openinv/internal/v1_12_R1/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_12_R1; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import com.mojang.authlib.GameProfile; import java.util.Collection; import java.util.UUID; @@ -29,6 +30,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_12_R1.CraftServer; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -54,9 +56,8 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Bukkit.getOnlinePlayers(); } @@ -76,8 +77,7 @@ public class PlayerDataManager implements IPlayerDataManager { } } - @NotNull - @Override + @NotNull @Override public String getPlayerDataID(@NotNull final OfflinePlayer offline) { return offline.getUniqueId().toString(); } @@ -105,4 +105,9 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_13_R1/src/main/java/com/lishid/openinv/internal/v1_13_R1/PlayerDataManager.java b/internal/v1_13_R1/src/main/java/com/lishid/openinv/internal/v1_13_R1/PlayerDataManager.java index f36015e..c6f4e3a 100644 --- a/internal/v1_13_R1/src/main/java/com/lishid/openinv/internal/v1_13_R1/PlayerDataManager.java +++ b/internal/v1_13_R1/src/main/java/com/lishid/openinv/internal/v1_13_R1/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_13_R1; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import com.mojang.authlib.GameProfile; import java.util.Collection; import java.util.UUID; @@ -29,6 +30,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_13_R1.CraftServer; import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -53,9 +55,8 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Bukkit.getOnlinePlayers(); } @@ -75,9 +76,8 @@ public class PlayerDataManager implements IPlayerDataManager { } } - @NotNull - @Override - public String getPlayerDataID(@NotNull final OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull final OfflinePlayer offline) { return offline.getUniqueId().toString(); } @@ -104,4 +104,9 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_13_R2/src/main/java/com/lishid/openinv/internal/v1_13_R2/PlayerDataManager.java b/internal/v1_13_R2/src/main/java/com/lishid/openinv/internal/v1_13_R2/PlayerDataManager.java index 79fd697..b5b5a23 100644 --- a/internal/v1_13_R2/src/main/java/com/lishid/openinv/internal/v1_13_R2/PlayerDataManager.java +++ b/internal/v1_13_R2/src/main/java/com/lishid/openinv/internal/v1_13_R2/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_13_R2; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import com.mojang.authlib.GameProfile; import java.util.Collection; import java.util.UUID; @@ -30,6 +31,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_13_R2.CraftServer; import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -54,9 +56,8 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Bukkit.getOnlinePlayers(); } @@ -76,9 +77,8 @@ public class PlayerDataManager implements IPlayerDataManager { } } - @NotNull - @Override - public String getPlayerDataID(@NotNull final OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull final OfflinePlayer offline) { return offline.getUniqueId().toString(); } @@ -105,4 +105,9 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_14_R1/src/main/java/com/lishid/openinv/internal/v1_14_R1/PlayerDataManager.java b/internal/v1_14_R1/src/main/java/com/lishid/openinv/internal/v1_14_R1/PlayerDataManager.java index 35b5202..8144f21 100644 --- a/internal/v1_14_R1/src/main/java/com/lishid/openinv/internal/v1_14_R1/PlayerDataManager.java +++ b/internal/v1_14_R1/src/main/java/com/lishid/openinv/internal/v1_14_R1/PlayerDataManager.java @@ -17,19 +17,32 @@ package com.lishid.openinv.internal.v1_14_R1; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import com.mojang.authlib.GameProfile; import java.util.Collection; import java.util.UUID; +import net.minecraft.server.v1_14_R1.ChatComponentText; +import net.minecraft.server.v1_14_R1.Container; +import net.minecraft.server.v1_14_R1.Containers; import net.minecraft.server.v1_14_R1.DimensionManager; +import net.minecraft.server.v1_14_R1.EntityHuman; import net.minecraft.server.v1_14_R1.EntityPlayer; import net.minecraft.server.v1_14_R1.MinecraftServer; +import net.minecraft.server.v1_14_R1.PacketPlayOutOpenWindow; import net.minecraft.server.v1_14_R1.PlayerInteractManager; +import net.minecraft.server.v1_14_R1.PlayerInventory; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.Server; import org.bukkit.craftbukkit.v1_14_R1.CraftServer; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_14_R1.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftContainer; +import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -54,9 +67,8 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } - @NotNull @Override - public Collection getOnlinePlayers() { + public @NotNull Collection getOnlinePlayers() { return Bukkit.getOnlinePlayers(); } @@ -76,9 +88,8 @@ public class PlayerDataManager implements IPlayerDataManager { } } - @NotNull @Override - public String getPlayerDataID(@NotNull final OfflinePlayer offline) { + public @NotNull String getPlayerDataID(@NotNull final OfflinePlayer offline) { return offline.getUniqueId().toString(); } @@ -105,4 +116,68 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + + EntityPlayer nmsPlayer = getHandle(player); + + if (nmsPlayer == null || nmsPlayer.playerConnection == null) { + return null; + } + + String title; + if (inventory instanceof SpecialEnderChest) { + HumanEntity owner = (HumanEntity) ((SpecialEnderChest) inventory).getBukkitOwner(); + title = (owner.getName() != null ? owner.getName() : owner.getUniqueId().toString()) + "'s Ender Chest"; + } else if (inventory instanceof SpecialPlayerInventory) { + EntityHuman owner = ((PlayerInventory) inventory).player; + title = (owner.getName() != null ? owner.getName() : owner.getUniqueID().toString()) + "'s Inventory"; + } else { + return player.openInventory(inventory.getBukkitInventory()); + } + + Container container = new CraftContainer(new InventoryView() { + @Override + public @NotNull Inventory getTopInventory() { + return inventory.getBukkitInventory(); + } + @Override + public @NotNull Inventory getBottomInventory() { + return player.getInventory(); + } + @Override + public @NotNull HumanEntity getPlayer() { + return player; + } + @Override + public @NotNull InventoryType getType() { + return inventory.getBukkitInventory().getType(); + } + @Override + public @NotNull String getTitle() { + return title; + } + }, nmsPlayer, nmsPlayer.nextContainerCounter()) { + @Override + public Containers getType() { + return inventory instanceof SpecialEnderChest ? Containers.GENERIC_9X3 : Containers.GENERIC_9X5; + } + }; + + container.setTitle(new ChatComponentText(title)); + container = CraftEventFactory.callInventoryOpenEvent(nmsPlayer, container); + + if (container == null) { + return null; + } + + nmsPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, container.getType(), + new ChatComponentText(container.getBukkitView().getTitle()))); + nmsPlayer.activeContainer = container; + container.addSlotListener(nmsPlayer); + + return container.getBukkitView(); + + } + } diff --git a/internal/v1_14_R1/src/main/java/com/lishid/openinv/internal/v1_14_R1/SpecialEnderChest.java b/internal/v1_14_R1/src/main/java/com/lishid/openinv/internal/v1_14_R1/SpecialEnderChest.java index ea18d13..0ffe279 100644 --- a/internal/v1_14_R1/src/main/java/com/lishid/openinv/internal/v1_14_R1/SpecialEnderChest.java +++ b/internal/v1_14_R1/src/main/java/com/lishid/openinv/internal/v1_14_R1/SpecialEnderChest.java @@ -31,7 +31,6 @@ import org.bukkit.craftbukkit.v1_14_R1.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventory; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.NotNull; @@ -51,7 +50,7 @@ public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEn } @Override - public @NotNull Inventory getBukkitInventory() { + public @NotNull CraftInventory getBukkitInventory() { return inventory; } diff --git a/internal/v1_14_R1/src/main/java/com/lishid/openinv/internal/v1_14_R1/SpecialPlayerInventory.java b/internal/v1_14_R1/src/main/java/com/lishid/openinv/internal/v1_14_R1/SpecialPlayerInventory.java index df9f668..944832f 100644 --- a/internal/v1_14_R1/src/main/java/com/lishid/openinv/internal/v1_14_R1/SpecialPlayerInventory.java +++ b/internal/v1_14_R1/src/main/java/com/lishid/openinv/internal/v1_14_R1/SpecialPlayerInventory.java @@ -47,8 +47,6 @@ import org.bukkit.craftbukkit.v1_14_R1.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventory; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -63,13 +61,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP public SpecialPlayerInventory(final Player bukkitPlayer, final Boolean online) { super(PlayerDataManager.getHandle(bukkitPlayer)); - this.inventory = new CraftInventory(this) { - @NotNull - @Override - public InventoryType getType() { - return InventoryType.CHEST; - } - }; + this.inventory = new CraftInventory(this); this.playerOnline = online; this.player = super.player; this.items = this.player.inventory.items; @@ -98,7 +90,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP } @Override - public @NotNull Inventory getBukkitInventory() { + public @NotNull CraftInventory getBukkitInventory() { return this.inventory; } diff --git a/internal/v1_4_R1/src/main/java/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java b/internal/v1_4_R1/src/main/java/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java index 827a3cf..21b283e 100644 --- a/internal/v1_4_R1/src/main/java/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java +++ b/internal/v1_4_R1/src/main/java/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_4_R1; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import java.util.Arrays; import java.util.Collection; import net.minecraft.server.v1_4_R1.EntityPlayer; @@ -28,6 +29,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_4_R1.CraftServer; import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; @@ -56,9 +58,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getName(); } @@ -72,9 +73,8 @@ public class PlayerDataManager implements IPlayerDataManager { return player; } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Arrays.asList(Bukkit.getOnlinePlayers()); } @@ -98,4 +98,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_5_R2/src/main/java/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java b/internal/v1_5_R2/src/main/java/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java index e6248c8..676978f 100644 --- a/internal/v1_5_R2/src/main/java/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java +++ b/internal/v1_5_R2/src/main/java/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_5_R2; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import java.util.Arrays; import java.util.Collection; import net.minecraft.server.v1_5_R2.EntityPlayer; @@ -28,6 +29,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_5_R2.CraftServer; import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -55,9 +57,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getName(); } @@ -71,9 +72,8 @@ public class PlayerDataManager implements IPlayerDataManager { return player; } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Arrays.asList(Bukkit.getOnlinePlayers()); } @@ -97,4 +97,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_5_R3/src/main/java/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java b/internal/v1_5_R3/src/main/java/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java index 1054c49..d596fcc 100644 --- a/internal/v1_5_R3/src/main/java/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java +++ b/internal/v1_5_R3/src/main/java/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_5_R3; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import java.util.Arrays; import java.util.Collection; import net.minecraft.server.v1_5_R3.EntityPlayer; @@ -28,6 +29,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_5_R3.CraftServer; import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -55,9 +57,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getName(); } @@ -71,9 +72,8 @@ public class PlayerDataManager implements IPlayerDataManager { return player; } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Arrays.asList(Bukkit.getOnlinePlayers()); } @@ -97,4 +97,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_6_R1/src/main/java/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java b/internal/v1_6_R1/src/main/java/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java index 75a55f8..63d32d0 100644 --- a/internal/v1_6_R1/src/main/java/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java +++ b/internal/v1_6_R1/src/main/java/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_6_R1; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import java.util.Arrays; import java.util.Collection; import net.minecraft.server.v1_6_R1.EntityPlayer; @@ -28,6 +29,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_6_R1.CraftServer; import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -55,9 +57,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getName(); } @@ -71,9 +72,8 @@ public class PlayerDataManager implements IPlayerDataManager { return player; } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Arrays.asList(Bukkit.getOnlinePlayers()); } @@ -97,4 +97,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_6_R2/src/main/java/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java b/internal/v1_6_R2/src/main/java/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java index 2fdf434..8d1066c 100644 --- a/internal/v1_6_R2/src/main/java/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java +++ b/internal/v1_6_R2/src/main/java/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_6_R2; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import java.util.Arrays; import java.util.Collection; import net.minecraft.server.v1_6_R2.EntityPlayer; @@ -28,6 +29,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_6_R2.CraftServer; import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -55,9 +57,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getName(); } @@ -71,9 +72,8 @@ public class PlayerDataManager implements IPlayerDataManager { return player; } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Arrays.asList(Bukkit.getOnlinePlayers()); } @@ -97,4 +97,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_6_R3/src/main/java/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java b/internal/v1_6_R3/src/main/java/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java index 5ae8ab7..ca50c18 100644 --- a/internal/v1_6_R3/src/main/java/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java +++ b/internal/v1_6_R3/src/main/java/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_6_R3; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import java.util.Arrays; import java.util.Collection; import net.minecraft.server.v1_6_R3.EntityPlayer; @@ -28,6 +29,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_6_R3.CraftServer; import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -55,9 +57,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getName(); } @@ -71,9 +72,8 @@ public class PlayerDataManager implements IPlayerDataManager { return player; } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Arrays.asList(Bukkit.getOnlinePlayers()); } @@ -97,4 +97,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_7_R1/src/main/java/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java b/internal/v1_7_R1/src/main/java/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java index a90e3e8..76c78b5 100644 --- a/internal/v1_7_R1/src/main/java/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java +++ b/internal/v1_7_R1/src/main/java/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_7_R1; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import java.util.Arrays; import java.util.Collection; import net.minecraft.server.v1_7_R1.EntityPlayer; @@ -29,6 +30,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_7_R1.CraftServer; import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -56,9 +58,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getName(); } @@ -72,9 +73,8 @@ public class PlayerDataManager implements IPlayerDataManager { return player; } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Arrays.asList(Bukkit.getOnlinePlayers()); } @@ -98,4 +98,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_7_R2/src/main/java/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java b/internal/v1_7_R2/src/main/java/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java index f8100c0..5124854 100644 --- a/internal/v1_7_R2/src/main/java/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java +++ b/internal/v1_7_R2/src/main/java/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_7_R2; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import java.util.Arrays; import java.util.Collection; import net.minecraft.server.v1_7_R2.EntityPlayer; @@ -29,6 +30,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_7_R2.CraftServer; import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; @SuppressWarnings("deprecation") // Deprecated methods are used properly and will not change. @@ -57,9 +59,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getName(); } @@ -73,9 +74,8 @@ public class PlayerDataManager implements IPlayerDataManager { return player; } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Arrays.asList(Bukkit.getOnlinePlayers()); } @@ -99,4 +99,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_7_R3/src/main/java/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java b/internal/v1_7_R3/src/main/java/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java index eec7474..a5682ef 100644 --- a/internal/v1_7_R3/src/main/java/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java +++ b/internal/v1_7_R3/src/main/java/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_7_R3; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import java.util.Arrays; import java.util.Collection; import java.util.UUID; @@ -30,6 +31,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_7_R3.CraftServer; import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -57,9 +59,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getUniqueId().toString(); } @@ -79,9 +80,8 @@ public class PlayerDataManager implements IPlayerDataManager { } } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Arrays.asList(Bukkit.getOnlinePlayers()); } @@ -105,4 +105,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_7_R4/src/main/java/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java b/internal/v1_7_R4/src/main/java/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java index ba130ed..8e93cec 100644 --- a/internal/v1_7_R4/src/main/java/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java +++ b/internal/v1_7_R4/src/main/java/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_7_R4; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import java.util.Collection; import java.util.UUID; import net.minecraft.server.v1_7_R4.EntityPlayer; @@ -29,6 +30,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_7_R4.CraftServer; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -56,9 +58,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getUniqueId().toString(); } @@ -78,9 +79,8 @@ public class PlayerDataManager implements IPlayerDataManager { } } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Bukkit.getOnlinePlayers(); } @@ -104,4 +104,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_8_R1/src/main/java/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java b/internal/v1_8_R1/src/main/java/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java index 413eab4..c9036de 100644 --- a/internal/v1_8_R1/src/main/java/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java +++ b/internal/v1_8_R1/src/main/java/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_8_R1; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import com.mojang.authlib.GameProfile; import java.util.Collection; import java.util.UUID; @@ -29,6 +30,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_8_R1.CraftServer; import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -56,9 +58,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getUniqueId().toString(); } @@ -78,9 +79,8 @@ public class PlayerDataManager implements IPlayerDataManager { } } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Bukkit.getOnlinePlayers(); } @@ -104,4 +104,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_8_R2/src/main/java/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java b/internal/v1_8_R2/src/main/java/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java index 3ba11c6..3f11bd8 100644 --- a/internal/v1_8_R2/src/main/java/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java +++ b/internal/v1_8_R2/src/main/java/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_8_R2; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import com.mojang.authlib.GameProfile; import java.util.Collection; import java.util.UUID; @@ -29,6 +30,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_8_R2.CraftServer; import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -56,9 +58,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getUniqueId().toString(); } @@ -78,9 +79,8 @@ public class PlayerDataManager implements IPlayerDataManager { } } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Bukkit.getOnlinePlayers(); } @@ -104,4 +104,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_8_R3/src/main/java/com/lishid/openinv/internal/v1_8_R3/PlayerDataManager.java b/internal/v1_8_R3/src/main/java/com/lishid/openinv/internal/v1_8_R3/PlayerDataManager.java index 85852fd..74d5c79 100644 --- a/internal/v1_8_R3/src/main/java/com/lishid/openinv/internal/v1_8_R3/PlayerDataManager.java +++ b/internal/v1_8_R3/src/main/java/com/lishid/openinv/internal/v1_8_R3/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_8_R3; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import com.mojang.authlib.GameProfile; import java.util.Collection; import java.util.UUID; @@ -29,6 +30,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_8_R3.CraftServer; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -56,9 +58,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getUniqueId().toString(); } @@ -78,9 +79,8 @@ public class PlayerDataManager implements IPlayerDataManager { } } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Bukkit.getOnlinePlayers(); } @@ -104,4 +104,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_9_R1/src/main/java/com/lishid/openinv/internal/v1_9_R1/PlayerDataManager.java b/internal/v1_9_R1/src/main/java/com/lishid/openinv/internal/v1_9_R1/PlayerDataManager.java index b7dd8b2..2399398 100644 --- a/internal/v1_9_R1/src/main/java/com/lishid/openinv/internal/v1_9_R1/PlayerDataManager.java +++ b/internal/v1_9_R1/src/main/java/com/lishid/openinv/internal/v1_9_R1/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_9_R1; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import com.mojang.authlib.GameProfile; import java.util.Collection; import java.util.UUID; @@ -29,6 +30,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_9_R1.CraftServer; import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -56,9 +58,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getUniqueId().toString(); } @@ -78,9 +79,8 @@ public class PlayerDataManager implements IPlayerDataManager { } } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Bukkit.getOnlinePlayers(); } @@ -104,4 +104,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/internal/v1_9_R2/src/main/java/com/lishid/openinv/internal/v1_9_R2/PlayerDataManager.java b/internal/v1_9_R2/src/main/java/com/lishid/openinv/internal/v1_9_R2/PlayerDataManager.java index 8eecdb6..a5e770a 100644 --- a/internal/v1_9_R2/src/main/java/com/lishid/openinv/internal/v1_9_R2/PlayerDataManager.java +++ b/internal/v1_9_R2/src/main/java/com/lishid/openinv/internal/v1_9_R2/PlayerDataManager.java @@ -17,6 +17,7 @@ package com.lishid.openinv.internal.v1_9_R2; import com.lishid.openinv.internal.IPlayerDataManager; +import com.lishid.openinv.internal.ISpecialInventory; import com.mojang.authlib.GameProfile; import java.util.Collection; import java.util.UUID; @@ -29,6 +30,7 @@ import org.bukkit.Server; import org.bukkit.craftbukkit.v1_9_R2.CraftServer; import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public class PlayerDataManager implements IPlayerDataManager { @@ -56,9 +58,8 @@ public class PlayerDataManager implements IPlayerDataManager { return target; } - @NotNull - @Override - public String getPlayerDataID(@NotNull OfflinePlayer offline) { + @Override + public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) { return offline.getUniqueId().toString(); } @@ -78,9 +79,8 @@ public class PlayerDataManager implements IPlayerDataManager { } } - @NotNull - @Override - public Collection getOnlinePlayers() { + @Override + public @NotNull Collection getOnlinePlayers() { return Bukkit.getOnlinePlayers(); } @@ -104,4 +104,9 @@ public class PlayerDataManager implements IPlayerDataManager { return nmsPlayer; } + @Override + public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return player.openInventory(inventory.getBukkitInventory()); + } + } diff --git a/plugin/plugin-core/src/main/java/com/lishid/openinv/OpenInv.java b/plugin/plugin-core/src/main/java/com/lishid/openinv/OpenInv.java index 29355d3..c7a02f4 100644 --- a/plugin/plugin-core/src/main/java/com/lishid/openinv/OpenInv.java +++ b/plugin/plugin-core/src/main/java/com/lishid/openinv/OpenInv.java @@ -27,6 +27,7 @@ import com.lishid.openinv.commands.SilentChestPluginCommand; import com.lishid.openinv.internal.IAnySilentContainer; import com.lishid.openinv.internal.IInventoryAccess; import com.lishid.openinv.internal.ISpecialEnderChest; +import com.lishid.openinv.internal.ISpecialInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.listeners.InventoryClickListener; import com.lishid.openinv.listeners.InventoryCloseListener; @@ -56,6 +57,7 @@ import org.bukkit.command.PluginCommand; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -458,6 +460,11 @@ public class OpenInv extends JavaPlugin implements IOpenInv { return player; } + @Override + public @Nullable InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) { + return this.accessor.getPlayerDataManager().openInventory(player, inventory); + } + @Override public boolean notifyAnyChest() { return this.getConfig().getBoolean("notify.any-chest", true); diff --git a/plugin/plugin-core/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java b/plugin/plugin-core/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java index fac7dec..581f153 100644 --- a/plugin/plugin-core/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java +++ b/plugin/plugin-core/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java @@ -142,7 +142,7 @@ public class OpenEnderPluginCommand implements CommandExecutor { } // Open the inventory - player.openInventory(chest.getBukkitInventory()); + plugin.openInventory(player, chest); } } diff --git a/plugin/plugin-core/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java b/plugin/plugin-core/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java index 798251a..af46725 100644 --- a/plugin/plugin-core/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java +++ b/plugin/plugin-core/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java @@ -151,7 +151,7 @@ public class OpenInvPluginCommand implements CommandExecutor { } // Open the inventory - player.openInventory(inv.getBukkitInventory()); + plugin.openInventory(player, inv); } }