1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-04 23:37:49 +01:00

Correct some things

This commit is contained in:
montlikadani 2020-06-27 13:30:04 +02:00
parent 1c8316a4c1
commit c162f1a2be
4 changed files with 12 additions and 44 deletions

View File

@ -116,10 +116,11 @@ public class ActionBarTitleMessages {
sendTitle(receivingPacket, title, subtitle, 0, 20, 20);
}
public static void sendTitle(final Player receivingPacket, final Object title, final Object subtitle, final int fadeIn, final int keep, final int fadeOut) {
@SuppressWarnings("deprecation")
public static void sendTitle(final Player receivingPacket, final Object title, final Object subtitle, final int fadeIn, final int keep, final int fadeOut) {
Bukkit.getScheduler().runTaskAsynchronously(Jobs.getInstance(), () -> {
String t = title == null ? null : CMIChatColor.translateAlternateColorCodes((String) title);
String s = subtitle == null ? null : CMIChatColor.translateAlternateColorCodes((String) subtitle);
String t = title == null ? null : CMIChatColor.translate((String) title);
String s = subtitle == null ? null : CMIChatColor.translate((String) subtitle);
if (simpleTitleMessages) {
receivingPacket.sendMessage(t);

View File

@ -2653,10 +2653,7 @@ public enum CMIMaterial {
}
public boolean equals(Material mat) {
if (getMaterial() == null) {
return false;
}
return this.getMaterial().equals(mat);
return getMaterial() == null ? false : getMaterial().equals(mat);
}
public List<String> getLegacyNames() {
@ -2681,7 +2678,7 @@ public enum CMIMaterial {
public String getMojangName() {
if (mojangName == null)
mojangName = Reflections.getItemMinecraftName(this.newItemStack());
mojangName = ItemReflection.getItemMinecraftName(newItemStack());
return mojangName;
}

View File

@ -21,9 +21,9 @@ import com.gamingmesh.jobs.stuff.Util;
public class ItemManager {
static HashMap<Material, CMIMaterial> byRealMaterial = new HashMap<Material, CMIMaterial>();
static HashMap<Integer, CMIMaterial> byId = new HashMap<Integer, CMIMaterial>();
static HashMap<String, CMIMaterial> byName = new HashMap<String, CMIMaterial>();
static HashMap<Material, CMIMaterial> byRealMaterial = new HashMap<>();
static HashMap<Integer, CMIMaterial> byId = new HashMap<>();
static HashMap<String, CMIMaterial> byName = new HashMap<>();
public HashMap<Integer, CMIMaterial> idMap() {
return byId;
@ -218,7 +218,7 @@ public class ItemManager {
return cm;
}
HashMap<String, ItemStack> headCache = new HashMap<String, ItemStack>();
HashMap<String, ItemStack> headCache = new HashMap<>();
public CMIItemStack getItem(String name) {
// if (byBukkitName.isEmpty())
@ -471,7 +471,7 @@ public class ItemManager {
}
public List<Recipe> getAllRecipes() {
List<Recipe> results = new ArrayList<Recipe>();
List<Recipe> results = new ArrayList<>();
Iterator<Recipe> iter = Bukkit.recipeIterator();
while (iter.hasNext()) {
Recipe recipe = iter.next();
@ -481,7 +481,7 @@ public class ItemManager {
}
public List<Recipe> getRecipesFor(ItemStack result) {
List<Recipe> results = new ArrayList<Recipe>();
List<Recipe> results = new ArrayList<>();
Iterator<Recipe> iter = Bukkit.recipeIterator();
while (iter.hasNext()) {
Recipe recipe = iter.next();

View File

@ -4,21 +4,18 @@
package com.gamingmesh.jobs.CMILib;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.VersionChecker.Version;
public class Reflections {
private Class<?> CraftServerClass;
private Object CraftServer;
private static Class<?> Item;
private static Class<?> NBTTagCompound;
private Class<?> NBTBase;
// private Class<?> NBTTagList;
@ -48,7 +45,6 @@ public class Reflections {
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) {
e.printStackTrace();
}*/
Item = getMinecraftClass("Item");
IStack = getMinecraftClass("ItemStack");
} catch (ClassCastException | ClassNotFoundException e) {
e.printStackTrace();
@ -288,30 +284,4 @@ public class Reflections {
public Object getCraftServer() {
return CraftServer;
}
public static String getItemMinecraftName(ItemStack item) {
try {
Object nmsStack = asNMSCopy(item);
if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) {
Object pre = nmsStack.getClass().getMethod("getItem").invoke(nmsStack);
Object n = pre.getClass().getMethod("getName").invoke(pre);
Class<?> ll = Class.forName("net.minecraft.server." + Version.getCurrent() + ".LocaleLanguage");
Object lla = ll.getMethod("a").invoke(ll);
return (String) lla.getClass().getMethod("a", String.class).invoke(lla, (String) n);
}
Field field = Item.getField("REGISTRY");
Object reg = field.get(field);
Method meth = reg.getClass().getMethod("b", Object.class);
meth.setAccessible(true);
Method secmeth = nmsStack.getClass().getMethod("getItem");
Object res2 = secmeth.invoke(nmsStack);
Object res = meth.invoke(reg, res2);
return res.toString();
} catch (Exception e) {
return null;
}
}
}