Updated SmartInvs

Updated SmartInvs to 1.30 Snapshot.
Added Lore to inventory items.
OfflinePlayer bug fix.
This commit is contained in:
jameslfc19 2020-04-19 15:03:15 +01:00
parent 27fe9f489a
commit 7d4380ddb6
5 changed files with 51 additions and 26 deletions

12
pom.xml
View File

@ -41,6 +41,10 @@
<url>https://repo.codemc.org/repository/maven-public</url>
</repository>
<repository>
<id>sytm-nexus</id>
<url>https://repo.sytm.de/repository/maven-hosted/</url>
</repository>
</repositories>
@ -60,10 +64,16 @@
<version>3.4</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>fr.minuskube.inv</groupId>-->
<!-- <artifactId>smart-invs</artifactId>-->
<!-- <version>1.2.7</version>-->
<!-- </dependency>-->
<dependency>
<groupId>fr.minuskube.inv</groupId>
<artifactId>smart-invs</artifactId>
<version>1.2.7</version>
<version>1.3.0-SNAPSHOT</version>
</dependency>
<dependency>

View File

@ -39,9 +39,9 @@ public class ChestLinkInventory implements InventoryProvider {
@Override
public void init(Player player, InventoryContents contents) {
Pagination pagination = contents.pagination();
List<ClickableItem> itemList = new ArrayList<>();
pagination.setItems(itemList.toArray(new ClickableItem[0]));
// List<ClickableItem> itemList = new ArrayList<>();
//
// pagination.setItems(itemList.toArray(new ClickableItem[0]));
pagination.setItemsPerPage(28);
contents.fillBorders(ClickableItem.empty(Utils.getNamedItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE)," ")));
@ -49,9 +49,9 @@ public class ChestLinkInventory implements InventoryProvider {
contents.add(item);
}
contents.set(5, 2, ClickableItem.of(Utils.getNamedItem(new ItemStack(Material.ARROW),"Previous"),
contents.set(2, 2, ClickableItem.from(Utils.getNamedItem(new ItemStack(Material.ARROW),"Previous"),
e -> inventory.open(player, pagination.previous().getPage())));
contents.set(5, 6, ClickableItem.of(Utils.getNamedItem(new ItemStack(Material.ARROW),"Next"),
contents.set(2, 6, ClickableItem.from(Utils.getNamedItem(new ItemStack(Material.ARROW),"Next"),
e -> inventory.open(player, pagination.next().getPage())));
}

View File

@ -9,8 +9,10 @@ import fr.minuskube.inv.SmartInventory;
import fr.minuskube.inv.content.InventoryContents;
import fr.minuskube.inv.content.InventoryProvider;
import fr.minuskube.inv.content.Pagination;
import fr.minuskube.inv.content.SlotPos;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
@ -32,6 +34,7 @@ public class ChestLinkMenu implements InventoryProvider {
.title("Inventory Storage")
.provider(this)
.manager(ChestsPlusPlus.INVENTORY_MANAGER)
.size(6,9)
.build();
//menu.setInsertable(true);
}
@ -53,21 +56,20 @@ public class ChestLinkMenu implements InventoryProvider {
List<ClickableItem> itemList = new ArrayList<>();
for(InventoryStorage storage : storages){
ClickableItem item = storage.getClickableItem(player);
//item.setRemoveable(true);
itemList.add(item);
}
pagination.setItems(itemList.toArray(new ClickableItem[0]));
pagination.setItemsPerPage(28);
pagination.setItemsPerPage(54);
contents.fillBorders(ClickableItem.empty(Utils.getNamedItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE)," ")));
for(ClickableItem item : pagination.getPageItems()){
contents.add(item);
}
contents.set(5, 2, ClickableItem.of(Utils.getNamedItem(new ItemStack(Material.ARROW),"Previous"),
contents.set(5, 2, ClickableItem.from(Utils.getNamedItem(new ItemStack(Material.ARROW),"Previous"),
e -> menu.open(player, pagination.previous().getPage())));
contents.set(5, 6, ClickableItem.of(Utils.getNamedItem(new ItemStack(Material.ARROW),"Next"),
contents.set(5, 6, ClickableItem.from(Utils.getNamedItem(new ItemStack(Material.ARROW),"Next"),
e -> menu.open(player, pagination.next().getPage())));
}

View File

@ -240,21 +240,21 @@ public class Utils {
return getPlayersAsNameList(Bukkit.getOnlinePlayers());
}
public static List<String> getPlayersAsNameList(Collection<? extends Player> players){
public static List<String> getPlayersAsNameList(Collection<? extends OfflinePlayer> players){
List<String> arr = new ArrayList<>();
for(Player player : players){
arr.add(ChatColor.stripColor(player.getDisplayName()));
for(OfflinePlayer player : players){
arr.add(ChatColor.stripColor(player.getName()));
}
return arr;
}
public static String prettyPrintPlayers(ChatColor highlight, List<Player> players){
public static String prettyPrintPlayers(ChatColor highlight, List<OfflinePlayer> players){
StringBuilder str = new StringBuilder();
str.append(players.size());
if(players.size() > 0) {
str.append(" - " + highlight + "[");
for (Player player : players) {
str.append(ChatColor.WHITE + ChatColor.stripColor(player.getDisplayName())).append(", ");
for (OfflinePlayer player : players) {
str.append(ChatColor.WHITE + ChatColor.stripColor(player.getName())).append(", ");
}
str.delete(str.length() - 2, str.length());
str.append(highlight + "]");

View File

@ -6,10 +6,7 @@ import com.jamesdpeters.minecraft.chests.misc.Utils;
import com.jamesdpeters.minecraft.chests.interfaces.VirtualInventoryHolder;
import com.jamesdpeters.minecraft.chests.runnables.VirtualChestToHopper;
import fr.minuskube.inv.ClickableItem;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
@ -19,14 +16,14 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
public class InventoryStorage implements ConfigurationSerializable {
Inventory inventory; //Old Inventory
ArrayList<ItemStack> items;
ArrayList<Location> locationsList;
ArrayList<String> members; //Members UUID
List<Player> bukkitMembers;
List<OfflinePlayer> bukkitMembers;
String inventoryName = "Chest";
VirtualChestToHopper chestToHopper;
Player player;
@ -62,7 +59,7 @@ public class InventoryStorage implements ConfigurationSerializable {
members = (ArrayList<String>) map.get("members");
bukkitMembers = new ArrayList<>();
for(String uuid : members){
bukkitMembers.add(Bukkit.getOfflinePlayer(UUID.fromString(uuid)).getPlayer());
bukkitMembers.add(Bukkit.getOfflinePlayer(UUID.fromString(uuid)));
}
}
@ -138,7 +135,13 @@ public class InventoryStorage implements ConfigurationSerializable {
ItemMeta meta = toReturn.getItemMeta();
if(meta != null) {
meta.setDisplayName(ChatColor.BOLD + "" + ChatColor.GREEN + "" + getIdentifier());
meta.setDisplayName(ChatColor.BOLD + "" + ChatColor.GREEN + "" + getIdentifier() + ": " +ChatColor.WHITE+ ""+getTotalItems()+" items");
if(getMembers() != null) {
List<String> memberNames = new ArrayList<>();
memberNames.add(ChatColor.BOLD+""+ChatColor.UNDERLINE+"Members:");
getMembers().forEach(player1 -> memberNames.add(ChatColor.stripColor(player1.getName())));
meta.setLore(memberNames);
}
toReturn.setItemMeta(meta);
}
toReturn.setAmount(1);
@ -146,7 +149,7 @@ public class InventoryStorage implements ConfigurationSerializable {
}
public ClickableItem getClickableItem(Player player) {
return ClickableItem.of(getIventoryIcon(), event -> {
return ClickableItem.from(getIventoryIcon(), event -> {
Utils.openInventory(player,getInventory());
});
}
@ -185,7 +188,17 @@ public class InventoryStorage implements ConfigurationSerializable {
return false;
}
public List<Player> getMembers(){
public List<OfflinePlayer> getMembers(){
return bukkitMembers;
}
public int getTotalItems(){
int total = 0;
if(inventory != null) {
for(ItemStack itemStack : inventory.getContents()){
if(itemStack != null) total += itemStack.getAmount();
}
}
return total;
}
}