Fix loot module NPE

This commit is contained in:
Sam 2017-04-05 21:14:12 +01:00
parent b85214c7f0
commit 4552fc2e9b
2 changed files with 47 additions and 44 deletions

View File

@ -534,41 +534,41 @@ public class LootModule extends MiniPlugin
String[] metadataSplit = lootItem.getMetadata().split(" "); String[] metadataSplit = lootItem.getMetadata().split(" ");
String key = metadataSplit[0]; String key = metadataSplit[0];
String[] values = new String[metadataSplit.length - 1]; String[] values = new String[metadataSplit.length - 1];
for (int i = 1; i < metadataSplit.length; i++) System.arraycopy(metadataSplit, 1, values, 0, metadataSplit.length - 1);
{
values[i - 1] = metadataSplit[i];
}
switch (key) switch (key)
{ {
case "RANK_UPGRADE": case "RANK_UPGRADE":
reward = new LootRankReward(itemStack); reward = new LootRankReward(itemStack);
break; break;
case "SHARD": case "SHARD":
reward = new LootShardReward(Integer.parseInt(values[0]) * 1000, itemStack, Integer.parseInt(values[1])); reward = new LootShardReward(Integer.parseInt(values[0]) * 1000, itemStack, Integer.parseInt(values[1]));
break; break;
case "CHEST": case "CHEST":
reward = new LootChestReward(Integer.parseInt(values[0]) * 1000, itemStack, values[1], Integer.parseInt(values[2])); reward = new LootChestReward(Integer.parseInt(values[0]) * 1000, itemStack, values[1], Integer.parseInt(values[2]));
break; break;
case "GADGET": case "GADGET":
String gadget = ""; String gadget = "";
for (int i = 1; i < values.length; i++) for (int i = 1; i < values.length; i++)
{ {
gadget += values[i] + " "; gadget += values[i] + " ";
} }
reward = new LootGadgetReward(Integer.parseInt(values[0]) * 1000, itemStack, gadget.trim()); reward = new LootGadgetReward(Integer.parseInt(values[0]) * 1000, itemStack, gadget.trim());
break; break;
default: default:
return; return;
} }
_itemRewards.add(reward); _itemRewards.add(reward);
} }
reward.collectItem(player); if (reward != null)
{
reward.collectItem(player);
}
} }
public void addItemReward(LootItemReward reward) public void addItemReward(LootItemReward reward)

View File

@ -24,11 +24,7 @@ import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.*;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.weather.WeatherChangeEvent; import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -52,7 +48,8 @@ public class WorldListeners implements Listener
@EventHandler @EventHandler
public void deletePlayerData(PlayerQuitEvent event) public void deletePlayerData(PlayerQuitEvent event)
{ {
_plugin.getServer().getScheduler().runTaskLater(_plugin, () -> { _plugin.getServer().getScheduler().runTaskLater(_plugin, () ->
{
World world = event.getPlayer().getWorld(); World world = event.getPlayer().getWorld();
UUID uuid = event.getPlayer().getUniqueId(); UUID uuid = event.getPlayer().getUniqueId();
String path = world.getWorldFolder().getPath(); String path = world.getWorldFolder().getPath();
@ -60,7 +57,7 @@ public class WorldListeners implements Listener
new File(path + File.separator + "stats" + File.separator + uuid + ".json").delete(); new File(path + File.separator + "stats" + File.separator + uuid + ".json").delete();
}, 10); }, 10);
} }
@EventHandler @EventHandler
public void customDamage(CustomDamageEvent event) public void customDamage(CustomDamageEvent event)
{ {
@ -117,7 +114,7 @@ public class WorldListeners implements Listener
{ {
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler @EventHandler
public void itemFrames(PlayerInteractEntityEvent event) public void itemFrames(PlayerInteractEntityEvent event)
{ {
@ -134,16 +131,16 @@ public class WorldListeners implements Listener
{ {
event.setCancelled(true); event.setCancelled(true);
} }
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
if (block == null) if (block == null)
{ {
return; return;
} }
Material material = block.getType(); Material material = block.getType();
if (material == Material.BEACON || material == Material.DISPENSER || material == Material.HOPPER || material == Material.BREWING_STAND || material == Material.DROPPER) if (material == Material.BEACON || material == Material.DISPENSER || material == Material.HOPPER || material == Material.BREWING_STAND || material == Material.DROPPER)
{ {
event.setCancelled(true); event.setCancelled(true);
@ -162,7 +159,7 @@ public class WorldListeners implements Listener
{ {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
} }
@ -173,7 +170,7 @@ public class WorldListeners implements Listener
{ {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
} }
@ -188,7 +185,7 @@ public class WorldListeners implements Listener
{ {
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler @EventHandler
public void leavesDecay(LeavesDecayEvent event) public void leavesDecay(LeavesDecayEvent event)
{ {
@ -203,7 +200,7 @@ public class WorldListeners implements Listener
// Some witchcraft from the arcade, seems to make hunger not ridiculous. // Some witchcraft from the arcade, seems to make hunger not ridiculous.
player.setSaturation(3.8F); player.setSaturation(3.8F);
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void weather(WeatherChangeEvent event) public void weather(WeatherChangeEvent event)
{ {
@ -213,6 +210,12 @@ public class WorldListeners implements Listener
} }
} }
@EventHandler
public void bucketEmpty(PlayerBucketEmptyEvent event)
{
event.setCancelled(true);
}
public boolean shouldBlock(Player player) public boolean shouldBlock(Player player)
{ {
return player.getGameMode() != GameMode.CREATIVE; return player.getGameMode() != GameMode.CREATIVE;