UStacker fix, add utils for text & gui

This commit is contained in:
jascotty2 2019-08-27 10:24:19 -05:00
parent c784f7b252
commit 49d8503592
6 changed files with 264 additions and 39 deletions

View File

@ -1828,4 +1828,42 @@ public enum LegacyMaterials {
}
return false;
}
/**
* Checks if this material is a food that can be cooked and is in its cooked state
*/
public boolean isCooked() {
switch(this) {
case BAKED_POTATO:
case COOKED_BEEF:
case COOKED_CHICKEN:
case COOKED_COD:
case COOKED_MUTTON:
case COOKED_PORKCHOP:
case COOKED_RABBIT:
case COOKED_SALMON:
case DRIED_KELP:
return true;
}
return false;
}
/**
* Checks if this material is a food that can be cooked and is in its raw state
*/
public boolean isRaw() {
switch(this) {
case BEEF:
case CHICKEN:
case COD:
case KELP: // not edible, but is the raw state of DRIED_KELP
case MUTTON:
case PORKCHOP:
case POTATO:
case RABBIT:
case SALMON:
return true;
}
return false;
}
}

View File

@ -1,5 +1,6 @@
package com.songoda.core.gui;
import com.songoda.core.compatibility.LegacyMaterials;
import com.songoda.core.gui.methods.Clickable;
import com.songoda.core.gui.methods.Closable;
import com.songoda.core.gui.methods.Droppable;
@ -7,6 +8,7 @@ import com.songoda.core.gui.methods.Openable;
import com.songoda.core.gui.methods.Pagable;
import com.songoda.core.gui.methods.SimpleClickable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
@ -400,6 +402,61 @@ public class DoubleGUI extends GUI {
return (DoubleGUI) super.setItem(row, col, item);
}
@Override
public DoubleGUI updateItem(int cell, String name, String... lore) {
return (DoubleGUI) super.updateItem(cell, name, lore);
}
@Override
public DoubleGUI updateItem(int row, int col, String name, List<String> lore) {
return (DoubleGUI) super.updateItem(col + row * 9, name, lore);
}
@Override
public DoubleGUI updateItem(int cell, String name, List<String> lore) {
return (DoubleGUI) super.updateItem(cell, name, lore);
}
@Override
public DoubleGUI updateItem(int row, int col, ItemStack itemTo, String title, String... lore) {
return (DoubleGUI) super.updateItem(col + row * 9, itemTo, title, lore);
}
@Override
public DoubleGUI updateItem(int cell, ItemStack itemTo, String title, String... lore) {
return (DoubleGUI) super.updateItem(cell, itemTo, title, lore);
}
@Override
public DoubleGUI updateItem(int row, int col, LegacyMaterials itemTo, String title, String... lore) {
return (DoubleGUI) super.updateItem(col + row * 9, itemTo, title, lore);
}
@Override
public DoubleGUI updateItem(int cell, LegacyMaterials itemTo, String title, String... lore) {
return (DoubleGUI) super.updateItem(cell, itemTo, title, lore);
}
@Override
public DoubleGUI updateItem(int row, int col, ItemStack itemTo, String title, List<String> lore) {
return (DoubleGUI) super.updateItem(col + row * 9, itemTo, title, lore);
}
@Override
public DoubleGUI updateItem(int cell, ItemStack itemTo, String title, List<String> lore) {
return (DoubleGUI) super.updateItem(cell, itemTo, title, lore);
}
@Override
public DoubleGUI updateItem(int row, int col, LegacyMaterials itemTo, String title, List<String> lore) {
return (DoubleGUI) super.updateItem(col + row * 9, itemTo, title, lore);
}
@Override
public DoubleGUI updateItem(int cell, LegacyMaterials itemTo, String title, List<String> lore) {
return (DoubleGUI) super.updateItem(cell, itemTo, title, lore);
}
@Override
public DoubleGUI setAction(int cell, Clickable action) {
return (DoubleGUI) super.setAction(cell, action);

View File

@ -1,5 +1,6 @@
package com.songoda.core.gui;
import com.songoda.core.compatibility.LegacyMaterials;
import com.songoda.core.gui.methods.Pagable;
import com.songoda.core.gui.methods.Clickable;
import com.songoda.core.gui.methods.Droppable;
@ -221,6 +222,78 @@ public class GUI {
return this;
}
public GUI updateItem(int row, int col, String name, String... lore) {
return updateItem(col + row * 9, name, lore);
}
public GUI updateItem(int cell, String name, String... lore) {
ItemStack item = cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, title, lore));
}
return this;
}
public GUI updateItem(int row, int col, String name, List<String> lore) {
return updateItem(col + row * 9, name, lore);
}
public GUI updateItem(int cell, String name, List<String> lore) {
ItemStack item = cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, title, lore));
}
return this;
}
public GUI updateItem(int row, int col, ItemStack itemTo, String title, String... lore) {
return updateItem(col + row * 9, itemTo, title, lore);
}
public GUI updateItem(int cell, ItemStack itemTo, String title, String... lore) {
ItemStack item = cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
}
return this;
}
public GUI updateItem(int row, int col, LegacyMaterials itemTo, String title, String... lore) {
return updateItem(col + row * 9, itemTo, title, lore);
}
public GUI updateItem(int cell, LegacyMaterials itemTo, String title, String... lore) {
ItemStack item = cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
}
return this;
}
public GUI updateItem(int row, int col, ItemStack itemTo, String title, List<String> lore) {
return updateItem(col + row * 9, itemTo, title, lore);
}
public GUI updateItem(int cell, ItemStack itemTo, String title, List<String> lore) {
ItemStack item = cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
}
return this;
}
public GUI updateItem(int row, int col, LegacyMaterials itemTo, String title, List<String> lore) {
return updateItem(col + row * 9, itemTo, title, lore);
}
public GUI updateItem(int cell, LegacyMaterials itemTo, String title, List<String> lore) {
ItemStack item = cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
}
return this;
}
public GUI setAction(int cell, Clickable action) {
setConditional(cell, null, action, null);
return this;

View File

@ -2,11 +2,9 @@ package com.songoda.core.gui;
import com.songoda.core.compatibility.LegacyMaterials;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -31,14 +29,6 @@ public class GuiUtils {
return item;
}
public static ItemStack getBorderItem(Material mat) {
ItemStack item = new ItemStack(mat);
ItemMeta glassmeta = item.getItemMeta();
glassmeta.setDisplayName(ChatColor.BLACK.toString());
item.setItemMeta(glassmeta);
return item;
}
public static ItemStack getBorderItem(LegacyMaterials mat) {
ItemStack item = mat.getItem();
ItemMeta glassmeta = item.getItemMeta();
@ -47,19 +37,6 @@ public class GuiUtils {
return item;
}
public static ItemStack createButtonItem(Material mat, String title, String... lore) {
ItemStack item = new ItemStack(mat);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(title);
if (lore != null) {
meta.setLore(Arrays.asList(lore.length == 1 ? lore[0].split("\n") : lore));
} else {
meta.setLore(Collections.EMPTY_LIST);
}
item.setItemMeta(meta);
return item;
}
public static ItemStack createButtonItem(LegacyMaterials mat, String title, String... lore) {
ItemStack item = mat.getItem();
ItemMeta meta = item.getItemMeta();
@ -86,19 +63,6 @@ public class GuiUtils {
return item;
}
public static ItemStack createButtonItem(Material mat, String title, List<String> lore) {
ItemStack item = new ItemStack(mat);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(title);
if (lore != null) {
meta.setLore(lore.size() == 1 ? Arrays.asList(lore.get(0).split("\n")) : lore);
} else {
meta.setLore(Collections.EMPTY_LIST);
}
item.setItemMeta(meta);
return item;
}
public static ItemStack createButtonItem(LegacyMaterials mat, String title, List<String> lore) {
ItemStack item = mat.getItem();
ItemMeta meta = item.getItemMeta();
@ -124,4 +88,88 @@ public class GuiUtils {
item.setItemMeta(meta);
return item;
}
public static ItemStack updateItem(ItemStack item, String title, String... lore) {
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(title);
if (lore != null) {
meta.setLore(Arrays.asList(lore.length == 1 ? lore[0].split("\n") : lore));
} else {
meta.setLore(Collections.EMPTY_LIST);
}
item.setItemMeta(meta);
return item;
}
public static ItemStack updateItem(ItemStack item, LegacyMaterials matTo, String title, String... lore) {
if(!matTo.matches(item)) {
item = matTo.getItem();
}
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(title);
if (lore != null) {
meta.setLore(Arrays.asList(lore.length == 1 ? lore[0].split("\n") : lore));
} else {
meta.setLore(Collections.EMPTY_LIST);
}
item.setItemMeta(meta);
return item;
}
public static ItemStack updateItem(ItemStack item, ItemStack to, String title, String... lore) {
if(!LegacyMaterials.getMaterial(item).matches(to)) {
item = to.clone();
}
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(title);
if (lore != null) {
meta.setLore(Arrays.asList(lore.length == 1 ? lore[0].split("\n") : lore));
} else {
meta.setLore(Collections.EMPTY_LIST);
}
item.setItemMeta(meta);
return item;
}
public static ItemStack updateItem(ItemStack item, String title, List<String> lore) {
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(title);
if (lore != null) {
meta.setLore(lore.size() == 1 ? Arrays.asList(lore.get(0).split("\n")) : lore);
} else {
meta.setLore(Collections.EMPTY_LIST);
}
item.setItemMeta(meta);
return item;
}
public static ItemStack updateItem(ItemStack item, LegacyMaterials matTo, String title, List<String> lore) {
if(!matTo.matches(item)) {
item = matTo.getItem();
}
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(title);
if (lore != null) {
meta.setLore(lore.size() == 1 ? Arrays.asList(lore.get(0).split("\n")) : lore);
} else {
meta.setLore(Collections.EMPTY_LIST);
}
item.setItemMeta(meta);
return item;
}
public static ItemStack updateItem(ItemStack item, ItemStack to, String title, List<String> lore) {
if(!LegacyMaterials.getMaterial(item).matches(to)) {
item = to.clone();
}
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(title);
if (lore != null) {
meta.setLore(lore.size() == 1 ? Arrays.asList(lore.get(0).split("\n")) : lore);
} else {
meta.setLore(Collections.EMPTY_LIST);
}
item.setItemMeta(meta);
return item;
}
}

View File

@ -9,14 +9,14 @@ import org.bukkit.entity.LivingEntity;
public class UltimateStacker extends Stacker {
private final com.songoda.ultimatestacker.UltimateStacker plugin;
private boolean itemStackMethods = true;
private boolean oldItemMethods = false;
private Method oldUltimateStacker_updateItemAmount;
public UltimateStacker() {
this.plugin = com.songoda.ultimatestacker.UltimateStacker.getInstance();
try {
oldUltimateStacker_updateItemAmount = com.songoda.ultimatestacker.utils.Methods.class.getDeclaredMethod("updateItemAmount", Item.class, int.class);
itemStackMethods = true;
oldItemMethods = true;
} catch (NoSuchMethodException | SecurityException ex) {
}
}
@ -43,7 +43,8 @@ public class UltimateStacker extends Stacker {
@Override
public void setItemAmount(Item item, int amount) {
if (itemStackMethods) {
if (oldItemMethods) {
// TODO: direct reference when this is re-added to the API
try {
oldUltimateStacker_updateItemAmount.invoke(null, item, amount);
} catch (Exception ex) {

View File

@ -16,4 +16,12 @@ public class TextUtils {
return ChatColor.translateAlternateColorCodes('&', text);
}
public static String convertToInvisibleString(String s) {
if (s == null || s.equals(""))
return "";
StringBuilder hidden = new StringBuilder();
for (char c : s.toCharArray()) hidden.append(ChatColor.COLOR_CHAR + "").append(c);
return hidden.toString();
}
}