1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 14:05:25 +01:00

Fix NullPointerExceptions (again)

Other:
- Add SuppressWarnings deprecation
- Fix skull owner set of offline player
This commit is contained in:
montlikadani 2018-08-23 09:20:07 +02:00
parent 0f74421559
commit 1852cb5bc3
22 changed files with 58 additions and 32 deletions

View File

@ -136,6 +136,7 @@ public class CMIEffectManager {
private Effect effect;
private Object EnumParticle;
private int[] extra;
@SuppressWarnings("unused")
private CMIParticleDataType dataType = CMIParticleDataType.Void;
CMIParticle(String name, int id, CMIParticleType type) {

View File

@ -32,7 +32,8 @@ public class ItemManager {
static HashMap<CMIMaterial, CMIItemStack> byMaterial = new HashMap<>();
static final Version version = Jobs.getVersionCheckManager().getVersion();
public static void load() {
@SuppressWarnings("deprecation")
public static void load() {
for (CMIMaterial one : CMIMaterial.values()) {
if (one == null)
@ -127,7 +128,8 @@ public class ItemManager {
static HashMap<String, ItemStack> headCache = new HashMap<>();
public static CMIItemStack getItem(String name) {
@SuppressWarnings("deprecation")
public static CMIItemStack getItem(String name) {
if (byBukkitName.isEmpty())
load();
CMIItemStack cm = null;
@ -182,7 +184,7 @@ public class ItemManager {
if (d.length() == 36) {
try {
OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(UUID.fromString(d));
skullMeta.setOwningPlayer(offPlayer);
skullMeta.setOwner(offPlayer.getName());
} catch (Exception e) {
break main;
}
@ -308,7 +310,8 @@ public class ItemManager {
return results;
}
static public Material getMaterial(String name) {
@SuppressWarnings("deprecation")
static public Material getMaterial(String name) {
CMIItemStack cm = getItem(name);
if (cm == null)
return Material.AIR;
@ -1522,6 +1525,7 @@ public class ItemManager {
return mat == null ? null : mat;
}
@SuppressWarnings("deprecation")
public void updateMaterial() {
if (mat == null) {
for (Material one : Material.class.getEnumConstants()) {
@ -1557,6 +1561,7 @@ public class ItemManager {
}
}
@SuppressWarnings("deprecation")
public ItemStack newItemStack() {
if (mat == null) {
for (Material one : Material.class.getEnumConstants()) {
@ -1699,6 +1704,7 @@ public class ItemManager {
return CMIMaterial.NONE;
}
@SuppressWarnings("deprecation")
public static CMIMaterial get(Material mat) {
for (CMIMaterial one : CMIMaterial.values()) {
if (one.getMaterial() == null)
@ -1710,6 +1716,7 @@ public class ItemManager {
return CMIMaterial.NONE;
}
@SuppressWarnings("deprecation")
public static CMIMaterial get(int id) {
for (CMIMaterial one : CMIMaterial.values()) {
if (one.getMaterial() == null)
@ -1731,7 +1738,8 @@ public class ItemManager {
// int tid = CMI.getInstance().getNMS().getEggId(item);
// return get(item.getType().getId(), tid);
// }
CMIMaterial m = get(item.getType().getId(), item.getData().getData());
@SuppressWarnings("deprecation")
CMIMaterial m = get(item.getType().getId(), item.getData().getData());
if (m == null) {
CMIItemStack cm = byBukkitName.get(item.getType().toString().toLowerCase().replace("_", ""));
@ -1743,7 +1751,8 @@ public class ItemManager {
}
public static CMIMaterial get(Block block) {
CMIMaterial m = get(block.getType().getId(), block.getData());
@SuppressWarnings("deprecation")
CMIMaterial m = get(block.getType().getId(), block.getData());
if (m == null) {
CMIItemStack cm = byBukkitName.get(block.getType().toString().replace("_", "").toLowerCase());
if (cm != null)
@ -2304,7 +2313,8 @@ public class ItemManager {
}
}
private static SlabType checkSlab(Block block) {
@SuppressWarnings("deprecation")
private static SlabType checkSlab(Block block) {
if (!CMIMaterial.isSlab(block.getType()))
return SlabType.NOTSLAB;

View File

@ -87,7 +87,8 @@ public class ItemReflection {
try {
Object nmsStack = asNMSCopy(item);
Method itemMeth = Item.getMethod("getById", int.class);
Object res = itemMeth.invoke(Item, item.getType().getId());
@SuppressWarnings("deprecation")
Object res = itemMeth.invoke(Item, item.getType().getId());
String ff = "b";
switch (Jobs.getVersionCheckManager().getVersion()) {
@ -135,7 +136,8 @@ public class ItemReflection {
try {
Object nmsStack = asNMSCopy(item);
Method itemMeth = Item.getMethod("getById", int.class);
Object res = itemMeth.invoke(Item, item.getType().getId());
@SuppressWarnings("deprecation")
Object res = itemMeth.invoke(Item, item.getType().getId());
Method nameThingy = Item.getMethod("j", IStack);
Object resThingy = nameThingy.invoke(res, nmsStack);
return resThingy.toString();

View File

@ -871,7 +871,8 @@ public class Jobs extends JavaPlugin {
this.setEnabled(false);
}
@Deprecated
@SuppressWarnings("unused")
@Deprecated
private static void checkDailyQuests(JobsPlayer jPlayer, JobProgression prog, ActionInfo info) {
checkDailyQuests(jPlayer, prog.getJob(), info);
}
@ -1354,4 +1355,8 @@ public class Jobs extends JavaPlugin {
if (pageCount != 0)
rm.show(sender);
}
public static boolean isRunning() {
return running;
}
}

View File

@ -20,7 +20,8 @@ public class Reflections {
private Class<?> CraftItemStack;
private Class<?> Item;
private Class<?> IStack;
private Jobs plugin;
@SuppressWarnings("unused")
private Jobs plugin;
public Reflections(Jobs plugin) {
this.plugin = plugin;
@ -78,7 +79,8 @@ public class Reflections {
try {
Object nmsStack = asNMSCopy(item);
Method itemMeth = Item.getMethod("getById", int.class);
Object res = itemMeth.invoke(Item, item.getType().getId());
@SuppressWarnings("deprecation")
Object res = itemMeth.invoke(Item, item.getType().getId());
String ff = "b";
switch (Jobs.getVersionCheckManager().getVersion()) {

View File

@ -18,7 +18,8 @@ import com.sk89q.worldguard.protection.regions.ProtectedRegion;
public class WorldGuardManager {
private Jobs plugin;
@SuppressWarnings("unused")
private Jobs plugin;
WorldGuardPlugin wg;
public WorldGuardManager(Jobs plugin) {

View File

@ -34,7 +34,7 @@ public class bp implements Cmd {
Location loc = player.getLocation();
final List<Block> changedBlocks = new ArrayList<Block>();
final List<Block> changedBlocks = new ArrayList<>();
for (int x = -10; x < 10; x++) {
for (int y = -10; y < 10; y++) {

View File

@ -22,7 +22,7 @@ public class browse implements Cmd {
public boolean perform(Jobs plugin, CommandSender sender, final String[] args) {
if (Jobs.getGCManager().BrowseUseNewLook) {
List<Job> jobList = new ArrayList<Job>(Jobs.getJobs());
List<Job> jobList = new ArrayList<>(Jobs.getJobs());
if (jobList.size() == 0) {
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("command.browse.error.nojobs"));
@ -151,7 +151,7 @@ public class browse implements Cmd {
} else {
ArrayList<String> lines = new ArrayList<String>();
ArrayList<String> lines = new ArrayList<>();
for (Job job : Jobs.getJobs()) {
if (Jobs.getGCManager().getHideJobsWithoutPermission()) {
if (!Jobs.getCommandManager().hasJobPermission(sender, job))

View File

@ -26,7 +26,8 @@ import com.gamingmesh.jobs.stuff.VersionChecker.Version;
public class editjobs implements Cmd {
@Override
@SuppressWarnings("deprecation")
@Override
@JobCommand(475)
public boolean perform(Jobs plugin, CommandSender sender, String[] args) {

View File

@ -30,7 +30,7 @@ public class glog implements Cmd {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
Map<LogAmounts, Double> unsortMap = new HashMap<LogAmounts, Double>();
Map<LogAmounts, Double> unsortMap = new HashMap<>();
int time = TimeManage.timeInInt();

View File

@ -63,7 +63,7 @@ public class gtop implements Cmd {
}
} else {
List<String> ls = new ArrayList<String>();
List<String> ls = new ArrayList<>();
int i = st;
for (TopList one : FullList) {

View File

@ -39,7 +39,7 @@ public class itembonus implements Cmd {
ItemStack iih = Jobs.getNms().getItemInMainHand(player);
List<ItemStack> items = new ArrayList<ItemStack>();
List<ItemStack> items = new ArrayList<>();
if (iih != null && !iih.getType().equals(Material.AIR))
items.add(iih);

View File

@ -55,7 +55,7 @@ public class log implements Cmd {
return true;
}
Map<String, Double> unsortMap = new HashMap<String, Double>();
Map<String, Double> unsortMap = new HashMap<>();
for (Entry<String, Log> l : logList.entrySet()) {
Log one = l.getValue();

View File

@ -65,7 +65,7 @@ public class quests implements Cmd {
"[required]", q.getQuest().getAmount());
List<String> hoverMsgs = Jobs.getLanguage().getMessageList("command.quests.output.hover");
List<String> hoverList = new ArrayList<String>();
List<String> hoverList = new ArrayList<>();
for (int i = 0; i < hoverMsgs.size(); i++) {
String current = hoverMsgs.get(i);

View File

@ -2,7 +2,6 @@ package com.gamingmesh.jobs.commands.list;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.commands.Cmd;
@ -19,8 +18,7 @@ public class reload implements Cmd {
} catch (Exception e) {
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.admin.error"));
String message = org.bukkit.ChatColor.translateAlternateColorCodes('&', "&4There was an error when performing a reload: ");
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
console.sendMessage(message);
Bukkit.getServer().getConsoleSender().sendMessage(message);
e.printStackTrace();
}
return true;

View File

@ -77,7 +77,7 @@ public class top implements Cmd {
}
} else {
List<String> ls = new ArrayList<String>();
List<String> ls = new ArrayList<>();
int i = st;
for (TopList one : FullList) {

View File

@ -166,7 +166,8 @@ public class ConfigManager {
}
public KeyValues getKeyValue(String myKey, ActionType actionType, String jobName) {
@SuppressWarnings("deprecation")
public KeyValues getKeyValue(String myKey, ActionType actionType, String jobName) {
String type = null;
String subType = "";

View File

@ -30,7 +30,7 @@ public class LanguageManager {
}
public static List<String> getClassesFromPackage(String pckgname, String cleaner) throws ClassNotFoundException {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
try {
for (URL jarURL : ((URLClassLoader) Jobs.class.getClassLoader()).getURLs()) {
try {

View File

@ -114,6 +114,8 @@ public class NameTranslatorManager {
case MMKILL:
return Jobs.getMythicManager().getDisplayName(materialName);
default:
break;
}
return materialName;
@ -180,7 +182,7 @@ public class NameTranslatorManager {
file.renameTo(file2);
// Just copying default language files, except en, that one will be generated
List<String> languages = new ArrayList<String>();
List<String> languages = new ArrayList<>();
try {
languages.addAll(LanguageManager.getClassesFromPackage("TranslatableWords", "Words_"));

View File

@ -10,7 +10,8 @@ import com.gamingmesh.jobs.dao.JobsManager.DataBaseType;
public class JobsMySQL extends JobsDAO {
private String database;
private Jobs plugin;
@SuppressWarnings("unused")
private Jobs plugin;
JobsMySQL(Jobs plugin, String hostname, String database, String username, String password, String prefix, boolean certificate, boolean ssl) {
super(plugin, "com.mysql.jdbc.Driver", "jdbc:mysql://" + hostname + "/" + database + "?autoReconnect=true&useSSL=" + ssl + "&verifyServerCertificate=" + certificate, username, password, prefix);

View File

@ -11,7 +11,8 @@ import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.dao.JobsManager.DataBaseType;
public class JobsSQLite extends JobsDAO {
private Jobs plugin;
@SuppressWarnings("unused")
private Jobs plugin;
public void initialize() {
try {

View File

@ -651,7 +651,8 @@ public class JobsPaymentListener implements Listener {
}
@Deprecated
@SuppressWarnings("unused")
@Deprecated
private Integer schedulePostDetection(final HumanEntity player, final ItemStack compareItem, final JobsPlayer jPlayer, final ItemStack resultStack) {
return schedulePostDetection(player, compareItem, jPlayer, resultStack, ActionType.CRAFT);
}