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

@ -535,40 +535,40 @@ public class LootModule extends MiniPlugin
String key = metadataSplit[0];
String[] values = new String[metadataSplit.length - 1];
for (int i = 1; i < metadataSplit.length; i++)
{
values[i - 1] = metadataSplit[i];
}
System.arraycopy(metadataSplit, 1, values, 0, metadataSplit.length - 1);
switch (key)
{
case "RANK_UPGRADE":
reward = new LootRankReward(itemStack);
break;
case "SHARD":
reward = new LootShardReward(Integer.parseInt(values[0]) * 1000, itemStack, Integer.parseInt(values[1]));
break;
case "CHEST":
reward = new LootChestReward(Integer.parseInt(values[0]) * 1000, itemStack, values[1], Integer.parseInt(values[2]));
break;
case "GADGET":
String gadget = "";
case "RANK_UPGRADE":
reward = new LootRankReward(itemStack);
break;
case "SHARD":
reward = new LootShardReward(Integer.parseInt(values[0]) * 1000, itemStack, Integer.parseInt(values[1]));
break;
case "CHEST":
reward = new LootChestReward(Integer.parseInt(values[0]) * 1000, itemStack, values[1], Integer.parseInt(values[2]));
break;
case "GADGET":
String gadget = "";
for (int i = 1; i < values.length; i++)
{
gadget += values[i] + " ";
}
for (int i = 1; i < values.length; i++)
{
gadget += values[i] + " ";
}
reward = new LootGadgetReward(Integer.parseInt(values[0]) * 1000, itemStack, gadget.trim());
break;
default:
return;
reward = new LootGadgetReward(Integer.parseInt(values[0]) * 1000, itemStack, gadget.trim());
break;
default:
return;
}
_itemRewards.add(reward);
}
reward.collectItem(player);
if (reward != null)
{
reward.collectItem(player);
}
}
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.FoodLevelChangeEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
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.player.*;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.plugin.java.JavaPlugin;
@ -52,7 +48,8 @@ public class WorldListeners implements Listener
@EventHandler
public void deletePlayerData(PlayerQuitEvent event)
{
_plugin.getServer().getScheduler().runTaskLater(_plugin, () -> {
_plugin.getServer().getScheduler().runTaskLater(_plugin, () ->
{
World world = event.getPlayer().getWorld();
UUID uuid = event.getPlayer().getUniqueId();
String path = world.getWorldFolder().getPath();
@ -213,6 +210,12 @@ public class WorldListeners implements Listener
}
}
@EventHandler
public void bucketEmpty(PlayerBucketEmptyEvent event)
{
event.setCancelled(true);
}
public boolean shouldBlock(Player player)
{
return player.getGameMode() != GameMode.CREATIVE;