This repository has been archived by the owner on Feb 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RecipearUtil.java
121 lines (96 loc) · 3.25 KB
/
RecipearUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package mods.recipear;
import java.util.ArrayList;
import java.util.HashSet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatMessageComponent;
import net.minecraftforge.oredict.OreDictionary;
public class RecipearUtil {
public static boolean isOP(EntityPlayer player) {
return (MinecraftServer.getServer().getConfigurationManager().getOps().contains(player.username.toLowerCase()) ? true : false);
}
public static ItemStack[] concat(ItemStack[] A, ItemStack[] B) {
int aLen = A.length;
int bLen = B.length;
ItemStack[] C= new ItemStack[aLen+bLen];
System.arraycopy(A, 0, C, 0, aLen);
System.arraycopy(B, 0, C, aLen, bLen);
return C;
}
public static String getLanguageRegistryEntry (ItemStack itemstack) {
String name = "Unknown";
try {
if(itemstack.getUnlocalizedName() != null) {
name = itemstack.getUnlocalizedName();
}
}
catch (NullPointerException ex) {
return "Unknown";
}
return name;
}
public static boolean isInteger(String s) {
try
{
Integer.parseInt(s);
}
catch(NumberFormatException e)
{
return false;
}
return true;
}
public static void RemoveBannedItemsFromInventory(EntityPlayer player) {
if (!isOP(player) && (BannedRecipes.GetBannedRecipeAmount() > 0)) {
ItemStack[] whole_inventory = concat(
player.inventory.mainInventory,
player.inventory.armorInventory);
for (ItemStack ITEM : whole_inventory) {
if (ITEM != null)
{
String DISPLAYNAME = RecipearUtil.getLanguageRegistryEntry(ITEM);
if (BannedRecipes.CheckSpecifically(ITEM.itemID, ITEM.getItemDamage(), "INVENTORY") || BannedRecipes.CheckSpecifically(DISPLAYNAME, "INVENTORY"))
{
player.inventory.clearInventory(ITEM.itemID, ITEM.getItemDamage());
msgPlayer(player, String.format(RecipearConfig.removeIngameMsg.replace("$", "\u00A7"), DISPLAYNAME));
RecipearLogger.info(String.format("Removing %s(%s:%s) from " + player.username, DISPLAYNAME, ITEM.itemID, ITEM.getItemDamage()));
}
}
}
whole_inventory = null;
}
}
public static String getOreName(ItemStack itemstack) {
int oreid = OreDictionary.getOreID(itemstack);
if(oreid >= 0) {
return OreDictionary.getOreName(oreid);
}
return "Unknown";
}
public static void msgPlayer(EntityPlayer player, String msg) {
player.sendChatToPlayer(new ChatMessageComponent().createFromText(msg.replace("$", "\u00A7")));
}
public static String getFancyItemStackInfo(ItemStack itemstack) {
return getLanguageRegistryEntry(itemstack) + "@" + itemstack.itemID + ":" + itemstack.getItemDamage() + " x " + itemstack.stackSize;
}
public static ItemStack[] getitem(int id) {
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
if(id <= 32000) {
int index = 0;
while(index < 16) {
ItemStack itemstack = new ItemStack(id, 1, index);
if(itemstack != null) {
if((index > 0) && !(getLanguageRegistryEntry(items.get(0)).equals(getLanguageRegistryEntry(itemstack)))) {
items.add(itemstack);
} else if (index == 0) {
items.add(itemstack);
}
}
index++;
}
}
return items.toArray(new ItemStack[0]);
}
}