Skip to content

Commit

Permalink
patch NPE possibilities
Browse files Browse the repository at this point in the history
  • Loading branch information
crashdemons committed Apr 2, 2019
1 parent 466b7bc commit e681151
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.crashdemons</groupId>
<artifactId>LoreKillCounter</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,35 @@ public void applyCounterOperation(List<String> lore, CounterOperation operation)
}

public void applyCounterOperation(ItemStack stack, CounterOperation operation){
if(stack==null) return;
ItemMeta meta = stack.getItemMeta();
if(meta==null) meta = Bukkit.getItemFactory().getItemMeta(stack.getType());
List<String> lore = (meta.hasLore()? meta.getLore() : new ArrayList<>());
applyCounterOperation(lore,operation);
meta.setLore(lore);
stack.setItemMeta(meta);
}
public void applyCounterOperation(Player player, CounterOperation operation){
ItemStack stack = player.getInventory().getItemInMainHand();
if(stack==null) return;
applyCounterOperation(stack,operation);
}

public void addCounter(List<String> lore, Counter counter){
lore.add(counter.toStringFormatted());
}
public void addCounter(ItemStack stack, Counter counter){
if(stack==null) return;
ItemMeta meta = stack.getItemMeta();
if(meta==null) meta = Bukkit.getItemFactory().getItemMeta(stack.getType());
List<String> lore = (meta.hasLore()? meta.getLore() : new ArrayList<>());
addCounter(lore,counter);
meta.setLore(lore);
stack.setItemMeta(meta);
}
public void addCounter(Player player, Counter counter){
ItemStack stack = player.getInventory().getItemInMainHand();
if(stack==null) return;
addCounter(stack,counter);
}

Expand Down

0 comments on commit e681151

Please sign in to comment.