1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-02 14:29:07 +01:00

Check for null if possible

- Fix NPE when a item not found in enchant_table
- Melon can be used for now as melon_block
- We needs the redstone_lamp_on material, #440
This commit is contained in:
montlikadani 2019-05-30 18:40:41 +02:00
parent 1db6723904
commit 23e349bd10
23 changed files with 82 additions and 168 deletions

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>Jobs</groupId>
<artifactId>jobs</artifactId>
<version>4.11.2</version>
<version>4.12.0</version>
<name>Jobs</name>
<url>http://maven.apache.org</url>
<properties>
@ -16,16 +16,16 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14.1-R0.1-SNAPSHOT</version>
<version>1.14.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- MyPet -->
<dependency>
<groupId>de.Keyle.MyPet</groupId>
<artifactId>MyPet</artifactId>
<version>3.0-SNAPSHOT</version>
<version>3.1-SNAPSHOT-B1433</version>
<scope>system</scope>
<systemPath>${basedir}/libs/MyPet-3.0-SNAPSHOT.jar</systemPath>
<systemPath>${basedir}/libs/MyPet-3.1-SNAPSHOT-B1433.jar</systemPath>
</dependency>
<!-- McMMO -->
<dependency>

View File

@ -169,8 +169,8 @@ public class ActionBarTitleMessages {
}
} catch (SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchFieldException ex) {
simpleTitleMessages = true;
Bukkit.getLogger().log(Level.SEVERE, "Your server can't fully support title messages. They will be shown in chat instead.");
simpleTitleMessages = true;
Bukkit.getLogger().log(Level.SEVERE, "Your server can't fully support title messages. They will be shown in chat instead.");
}
return;
});

View File

@ -147,48 +147,48 @@ public class CMIItemStack {
}
public CMIItemStack addEnchant(Enchantment enchant, Integer level) {
if (enchant == null)
return this;
ItemMeta meta = getItemStack().getItemMeta();
meta.addEnchant(enchant, level, true);
getItemStack().setItemMeta(meta);
return this;
if (enchant == null)
return this;
ItemMeta meta = getItemStack().getItemMeta();
meta.addEnchant(enchant, level, true);
getItemStack().setItemMeta(meta);
return this;
}
public CMIItemStack addEnchant(HashMap<Enchantment, Integer> enchants) {
if (enchants == null || enchants.isEmpty())
return this;
for (Entry<Enchantment, Integer> oneEnch : enchants.entrySet()) {
addEnchant(oneEnch.getKey(), oneEnch.getValue());
}
return this;
if (enchants == null || enchants.isEmpty())
return this;
for (Entry<Enchantment, Integer> oneEnch : enchants.entrySet()) {
addEnchant(oneEnch.getKey(), oneEnch.getValue());
}
return this;
}
public CMIItemStack clearEnchants() {
ItemMeta meta = getItemStack().getItemMeta();
meta.getEnchants().clear();
getItemStack().setItemMeta(meta);
return this;
ItemMeta meta = getItemStack().getItemMeta();
meta.getEnchants().clear();
getItemStack().setItemMeta(meta);
return this;
}
public List<String> getLore() {
ItemMeta meta = this.getItemStack().getItemMeta();
ItemMeta meta = this.getItemStack().getItemMeta();
// List<String> lore = null;
if (meta != null) {
List<String> lore = meta.getLore();
if (lore == null) {
lore = new ArrayList<String>();
meta.setLore(lore);
if (meta != null) {
List<String> lore = meta.getLore();
if (lore == null) {
lore = new ArrayList<String>();
meta.setLore(lore);
// this.getItemStack().setItemMeta(meta);
}
}
return meta.getLore() == null ? new ArrayList<String>() : meta.getLore();
}
return new ArrayList<String>();
return meta.getLore() == null ? new ArrayList<String>() : meta.getLore();
}
return new ArrayList<String>();
}
public String getRealName() {
return getCMIType() == null || getCMIType() == CMIMaterial.NONE ? getType().name() : getCMIType().getName();
return getCMIType() == null || getCMIType() == CMIMaterial.NONE ? getType().name() : getCMIType().getName();
// if (this.getItemStack() != null) {
//
//// String translated = CMI.getInstance().getItemManager().getTranslatedName(this.getItemStack());
@ -203,11 +203,11 @@ public class CMIItemStack {
}
public String getBukkitName() {
return bukkitName == null || bukkitName.isEmpty() ? null : bukkitName;
return bukkitName == null || bukkitName.isEmpty() ? null : bukkitName;
}
public void setBukkitName(String bukkitName) {
this.bukkitName = bukkitName;
this.bukkitName = bukkitName;
}
public String getMojangName() {
@ -218,7 +218,7 @@ public class CMIItemStack {
// } catch (Exception e) {
//
// }
return mojangName == null || mojangName.isEmpty() ? getCMIType().getMaterial().name() : mojangName;
return mojangName == null || mojangName.isEmpty() ? getCMIType().getMaterial().name() : mojangName;
}
public void setMojangName(String mojangName) {

View File

@ -1534,7 +1534,7 @@ public class ItemManager {
MAGMA_CREAM(378, 0, 25097, "Magma Cream"),
MAGMA_CUBE_SPAWN_EGG(383, 62, 26638, "Spawn Magma Cube", "Magma Cube Spawn Egg"),
MAP(395, 0, 21655, "Empty Map"),
MELON(103, 0, 25172, "Melon", "Melon_Block"),
MELON_BLOCK(103, 0, 25172, "Melon"),
MELON_SEEDS(362, 0, 18340, "Melon Seeds"),
MELON_SLICE(360, 0, 5347, "Melon Slice"),
MELON_STEM(105, 0, 8247, "Melon Stem"),
@ -2035,7 +2035,7 @@ public class ItemManager {
LEGACY_DIODE_BLOCK_ON(94, 0, null, "Diode Block On"),
LEGACY_BREWING_STAND(117, null, null, "Brewing Stand"),
// LEGACY_CAULDRON(118, 0, null, "LEGACY_CAULDRON", ""),
// LEGACY_REDSTONE_LAMP_ON(124, null, null, "LEGACY_REDSTONE_LAMP_ON", ""),
LEGACY_REDSTONE_LAMP_ON(124, 0, null, "LEGACY_REDSTONE_LAMP_ON"),
// LEGACY_WOOD_DOUBLE_STEP(125, null, null, "LEGACY_WOOD_DOUBLE_STEP", ""),
// LEGACY_FLOWER_POT(140, null, null, "LEGACY_FLOWER_POT", ""),
LEGACY_REDSTONE_COMPARATOR_OFF(149, 0, null, "Redstone Comparator Off", ""),

View File

@ -87,7 +87,7 @@ public class ItemReflection {
Object nmsStack = asNMSCopy(item);
Method itemMeth = Item.getMethod("getById", int.class);
@SuppressWarnings("deprecation")
Object res = itemMeth.invoke(Item, item.getType().getId());
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

@ -18,7 +18,6 @@ public class McMMOManager {
private HashMap<UUID, HashMap<String, Long>> map = new HashMap<>();
public double getMultiplier(Player player) {
if (player == null)
return 0D;
@ -32,14 +31,14 @@ public class McMMOManager {
return -(1 - Jobs.getGCManager().TreeFellerMultiplier);
InfoMap.remove(SuperAbilityType.TREE_FELLER.toString());
}
t = InfoMap.get(SuperAbilityType.GIGA_DRILL_BREAKER.toString());
if (t != null) {
if (t > System.currentTimeMillis())
return -(1 - Jobs.getGCManager().gigaDrillMultiplier);
InfoMap.remove(SuperAbilityType.GIGA_DRILL_BREAKER.toString());
}
t = InfoMap.get(SuperAbilityType.SUPER_BREAKER.toString());
if (t != null) {
if (t > System.currentTimeMillis())

View File

@ -396,11 +396,11 @@ public class Placeholder {
case user_totallevels:
return Integer.toString(user.getTotalLevels());
case user_points:
PlayerPoints pointInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(user.getPlayerUUID());
return Double.toString(pointInfo.getCurrentPoints());
PlayerPoints pointInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(user.getPlayerUUID());
return Double.toString(pointInfo.getCurrentPoints());
case user_total_points:
pointInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(user.getPlayerUUID());
return Double.toString(pointInfo.getTotalPoints());
pointInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(user.getPlayerUUID());
return Double.toString(pointInfo.getTotalPoints());
case user_issaved:
return convert(user.isSaved());
case user_displayhonorific:

View File

@ -0,0 +1,18 @@
package com.gamingmesh.jobs.api;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class BaseEvent extends Event {
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -1,13 +1,10 @@
package com.gamingmesh.jobs.api;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.gamingmesh.jobs.container.CuboidArea;
public final class JobsAreaSelectionEvent extends Event {
private static final HandlerList handlers = new HandlerList();
public final class JobsAreaSelectionEvent extends BaseEvent {
private CuboidArea area;
private Player player;
@ -23,13 +20,4 @@ public final class JobsAreaSelectionEvent extends Event {
public CuboidArea getArea() {
return area;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -3,11 +3,8 @@ package com.gamingmesh.jobs.api;
import org.bukkit.Chunk;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public final class JobsChunkChangeEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
public final class JobsChunkChangeEvent extends BaseEvent implements Cancellable {
private Player player;
private Chunk oldChunk;
private Chunk newChunk;
@ -40,13 +37,4 @@ public final class JobsChunkChangeEvent extends Event implements Cancellable {
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -2,13 +2,10 @@ package com.gamingmesh.jobs.api;
import org.bukkit.OfflinePlayer;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.gamingmesh.jobs.container.Job;
public final class JobsExpGainEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
public final class JobsExpGainEvent extends BaseEvent implements Cancellable {
private OfflinePlayer offlinePlayer;
private double exp;
private Job job;
@ -45,13 +42,4 @@ public final class JobsExpGainEvent extends Event implements Cancellable {
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -1,14 +1,11 @@
package com.gamingmesh.jobs.api;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobsPlayer;
public final class JobsJoinEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
public final class JobsJoinEvent extends BaseEvent implements Cancellable {
private JobsPlayer player;
private Job job;
private boolean cancelled = false;
@ -35,13 +32,4 @@ public final class JobsJoinEvent extends Event implements Cancellable {
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -1,14 +1,11 @@
package com.gamingmesh.jobs.api;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobsPlayer;
public final class JobsLeaveEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
public final class JobsLeaveEvent extends BaseEvent implements Cancellable {
private JobsPlayer player;
private Job job;
private boolean cancelled = false;
@ -35,13 +32,4 @@ public final class JobsLeaveEvent extends Event implements Cancellable {
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -2,14 +2,11 @@ package com.gamingmesh.jobs.api;
import org.bukkit.Sound;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.container.Title;
public final class JobsLevelUpEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
public final class JobsLevelUpEvent extends BaseEvent implements Cancellable {
private JobsPlayer player;
private String JobName;
private Title OldTitle;
@ -157,13 +154,4 @@ public final class JobsLevelUpEvent extends Event implements Cancellable {
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -2,11 +2,8 @@ package com.gamingmesh.jobs.api;
import com.gamingmesh.jobs.container.Schedule;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class JobsScheduleStartEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
public class JobsScheduleStartEvent extends BaseEvent implements Cancellable {
private boolean cancelled = false;
private Schedule schedule;
@ -27,13 +24,4 @@ public class JobsScheduleStartEvent extends Event implements Cancellable {
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -2,11 +2,8 @@ package com.gamingmesh.jobs.api;
import com.gamingmesh.jobs.container.Schedule;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class JobsScheduleStopEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
public class JobsScheduleStopEvent extends BaseEvent implements Cancellable {
private boolean cancelled = false;
private Schedule schedule;
@ -27,13 +24,4 @@ public class JobsScheduleStopEvent extends Event implements Cancellable {
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -52,7 +52,7 @@ public class exp implements Cmd {
double amount = 0.0;
try {
amount = Double.parseDouble(args[3]);
amount = Double.parseDouble(args[3]);
} catch (Throwable e) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error"));
return true;
@ -80,7 +80,7 @@ public class exp implements Cmd {
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success"));
} else
sender.sendMessage(Jobs.getLanguage().getMessage("command.exp.error.nojob"));
sender.sendMessage(Jobs.getLanguage().getMessage("command.exp.error.nojob"));
} catch (Throwable e) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error"));
}

View File

@ -16,7 +16,6 @@ import com.gamingmesh.jobs.container.QuestObjective;
import com.gamingmesh.jobs.container.QuestProgression;
import com.gamingmesh.jobs.CMILib.RawMessage;
import com.gamingmesh.jobs.stuff.TimeManage;
import com.gamingmesh.jobs.stuff.Util;
public class quests implements Cmd {
@ -81,18 +80,14 @@ public class quests implements Cmd {
}
for (Entry<String, QuestObjective> oneObjective : q.getQuest().getObjectives().entrySet()) {
hoverList.add(Jobs.getLanguage().getMessage("command.info.output." + oneObjective.getValue().getAction().toString().toLowerCase() + ".info") + " " +
Jobs.getNameTranslatorManager().Translate(oneObjective.getKey(), oneObjective.getValue().getAction(), oneObjective.getValue().getTargetId(), oneObjective.getValue()
.getTargetMeta(), oneObjective.getValue().getTargetName())
+ " " + q.getAmountDone(oneObjective.getValue()) + "/"
+ oneObjective.getValue().getAmount());
}
String hover = "";
for (String one : hoverList) {
if (!hover.isEmpty())
hover += "\n";

View File

@ -33,7 +33,6 @@ import com.gamingmesh.jobs.dao.JobsDAO;
import com.gamingmesh.jobs.economy.PaymentData;
import com.gamingmesh.jobs.resources.jfep.Parser;
import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.Debug;
import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling;
import com.gamingmesh.jobs.stuff.TimeManage;
@ -907,7 +906,7 @@ public class JobsPlayer {
g.put(qp.getQuest().getConfigName(), qp);
}
if (qp.getQuest() == null) {
g.remove(one.getKey());
continue;

View File

@ -24,8 +24,8 @@ public class Quest {
private List<String> rewardCmds = new ArrayList<>();
private List<String> rewards = new ArrayList<>();
private HashMap<String, QuestObjective> objectives = new HashMap<String, QuestObjective>();
private Set<ActionType> actions = new HashSet<ActionType>();
private HashMap<String, QuestObjective> objectives = new HashMap<>();
private Set<ActionType> actions = new HashSet<>();
public Quest(String questName, Job job) {
this.questName = questName;

View File

@ -12,7 +12,7 @@ public class QuestProgression {
// private int amountDone = 0;
private Long validUntil;
private boolean givenReward = false;
private HashMap<QuestObjective, Integer> done = new HashMap<QuestObjective, Integer>();
private HashMap<QuestObjective, Integer> done = new HashMap<>();
public QuestProgression(Quest quest) {
this.quest = quest;

View File

@ -402,7 +402,7 @@ public class JobsPaymentListener implements Listener {
if (item != null && !item.getType().equals(Material.AIR)) {
// Prevent item durability loss
if (!Jobs.getGCManager().payItemDurabilityLoss && item.getType().getMaxDurability()
- Jobs.getNms().getDurability(item) != item.getType().getMaxDurability())
- Jobs.getNms().getDurability(item) != item.getType().getMaxDurability())
return;
// Protection for block break with silktouch
@ -715,7 +715,6 @@ public class JobsPaymentListener implements Listener {
return stack != null && stack.getAmount() > 0;
}
@SuppressWarnings("deprecation")
private static boolean hasSameItem(ItemStack a, ItemStack b) {
if (a == null)
return b == null;
@ -723,8 +722,8 @@ public class JobsPaymentListener implements Listener {
return false;
CMIMaterial mat1 = CMIMaterial.get(a);
CMIMaterial mat2 = CMIMaterial.get(b);
return mat1 == mat2 && a.getDurability() == b.getDurability() && Objects.equal(a.getData(), b.getData()) && Objects.equal(a.getEnchantments(), b
.getEnchantments());
return mat1 == mat2 && Jobs.getNms().getDurability(a) == Jobs.getNms().getDurability(b) && Objects.equal(a.getData(), b.getData()) &&
Objects.equal(a.getEnchantments(), b.getEnchantments());
}
private static boolean isStackSumLegal(ItemStack a, ItemStack b) {
@ -812,7 +811,7 @@ public class JobsPaymentListener implements Listener {
if (jPlayer == null)
return;
if (Jobs.getGCManager().PayForEnchantingOnAnvil && inv.getItem(1).getType().equals(Material.ENCHANTED_BOOK)) {
if (Jobs.getGCManager().PayForEnchantingOnAnvil && inv.getItem(1) != null && inv.getItem(1).getType().equals(Material.ENCHANTED_BOOK)) {
Map<Enchantment, Integer> enchants = resultStack.getEnchantments();
for (Entry<Enchantment, Integer> oneEnchant : enchants.entrySet()) {
Enchantment enchant = oneEnchant.getKey();
@ -1119,7 +1118,7 @@ public class JobsPaymentListener implements Listener {
if (item != null && !item.getType().equals(Material.AIR)) {
// Prevent item durability loss
if (!Jobs.getGCManager().payItemDurabilityLoss && item.getType().getMaxDurability()
- Jobs.getNms().getDurability(item) != item.getType().getMaxDurability())
- Jobs.getNms().getDurability(item) != item.getType().getMaxDurability())
return;
}