Fixing everything you guys broke while I was gone...

This commit is contained in:
GJ 2013-05-14 11:28:50 -04:00
parent 0b18ae8ff2
commit 501f5de55a
5 changed files with 54 additions and 46 deletions

View File

@ -15,7 +15,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
@ -302,13 +301,21 @@ public class EntityListener implements Listener {
return; return;
} }
SpawnReason reason = event.getSpawnReason(); switch (event.getSpawnReason()) {
case SPAWNER:
case SPAWNER_EGG:
LivingEntity entity = event.getEntity();
Entity passenger = entity.getPassenger();
if (reason == SpawnReason.SPAWNER || reason == SpawnReason.SPAWNER_EGG) { entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue);
event.getEntity().setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue);
if(event.getEntity().getPassenger() != null) { if (passenger != null) {
event.getEntity().getPassenger().setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue); passenger.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue);
} }
return;
default:
return;
} }
} }

View File

@ -320,14 +320,15 @@ public class PlayerListener implements Listener {
public void onPlayerInteractLowest(PlayerInteractEvent event) { public void onPlayerInteractLowest(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
ItemStack heldItem = player.getItemInHand();
if (Misc.isNPCEntity(player) || player.getGameMode() == GameMode.CREATIVE) { if (Misc.isNPCEntity(player) || player.getGameMode() == GameMode.CREATIVE) {
return; return;
} }
ItemStack heldItem = player.getItemInHand();
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
// This shouldn't be possible - this is probably a band-aid for a larger issue somewhere else.
if (mcMMOPlayer == null) { if (mcMMOPlayer == null) {
return; return;
} }
@ -427,6 +428,7 @@ public class PlayerListener implements Listener {
ItemStack heldItem = player.getItemInHand(); ItemStack heldItem = player.getItemInHand();
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
// This shouldn't be possible - this is probably a band-aid for a larger issue somewhere else.
if (mcMMOPlayer == null) { if (mcMMOPlayer == null) {
return; return;
} }
@ -532,7 +534,8 @@ public class PlayerListener implements Listener {
if (mcMMOPlayer == null) { if (mcMMOPlayer == null) {
return; return;
} }
else if (mcMMOPlayer.getPartyChatMode()) {
if (mcMMOPlayer.getPartyChatMode()) {
Party party = mcMMOPlayer.getParty(); Party party = mcMMOPlayer.getParty();
if (party == null) { if (party == null) {

View File

@ -49,7 +49,7 @@ import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
public class FishingManager extends SkillManager { public class FishingManager extends SkillManager {
private static HashMap<Material, List<Enchantment>> enchantableCache = new HashMap<Material, List<Enchantment>>(); private final HashMap<Material, List<Enchantment>> enchantableCache = new HashMap<Material, List<Enchantment>>();
private final long FISHING_COOLDOWN_SECONDS = 1000L; private final long FISHING_COOLDOWN_SECONDS = 1000L;
private int fishingTries = 0; private int fishingTries = 0;
@ -112,12 +112,7 @@ public class FishingManager extends SkillManager {
player.setItemInHand(null); player.setItemInHand(null);
Creature kraken; Creature kraken = (Creature) world.spawnEntity(player.getEyeLocation(), (Misc.getRandom().nextInt(100) == 0 ? EntityType.CHICKEN : EntityType.SQUID));
if (Misc.getRandom().nextInt(100) == 0) {
kraken = (Creature) world.spawnEntity(player.getEyeLocation(), EntityType.CHICKEN);
} else {
kraken = (Creature) world.spawnEntity(player.getEyeLocation(), EntityType.SQUID);
}
kraken.setCustomName(AdvancedConfig.getInstance().getKrakenName()); kraken.setCustomName(AdvancedConfig.getInstance().getKrakenName());
if (!kraken.isValid()) { if (!kraken.isValid()) {
@ -418,23 +413,7 @@ public class FishingManager extends SkillManager {
return false; return false;
} }
// When calculating the possible enchantments, we should cache the possible enchantments to minimize List<Enchantment> possibleEnchantments = getPossibleEnchantments(treasureDrop);
// looping every time someone fishes.
List<Enchantment> possibleEnchantments;
if (enchantableCache.containsKey(treasureDrop.getType())) { // Check if possible enchantments is already cached for this item.
possibleEnchantments = enchantableCache.get(treasureDrop.getType());
} else { // If not, check which enchantments are possible
possibleEnchantments = new ArrayList<Enchantment>();
for (Enchantment enchantment : Enchantment.values()) {
if (enchantment.canEnchantItem(treasureDrop)) {
possibleEnchantments.add(enchantment);
}
}
enchantableCache.put(treasureDrop.getType(), possibleEnchantments); // Cache these enchantments.
}
// This make sure that the order isn't always the same, for example previously Unbreaking had a lot more chance to be used than any other enchant // This make sure that the order isn't always the same, for example previously Unbreaking had a lot more chance to be used than any other enchant
Collections.shuffle(possibleEnchantments, Misc.getRandom()); Collections.shuffle(possibleEnchantments, Misc.getRandom());
@ -443,20 +422,38 @@ public class FishingManager extends SkillManager {
int specificChance = 1; int specificChance = 1;
for (Enchantment possibleEnchantment : possibleEnchantments) { for (Enchantment possibleEnchantment : possibleEnchantments) {
if (!treasureDrop.getItemMeta().hasConflictingEnchant(possibleEnchantment) && Misc.getRandom().nextInt(specificChance) == 0) { if (treasureDrop.getItemMeta().hasConflictingEnchant(possibleEnchantment) || Misc.getRandom().nextInt(specificChance) != 0) {
// We need our random enchantment level to fall in the range between getStartLevel() and getMaxLevel() continue;
// so we take a random number in the range of their difference, then add the start level. }
final int levelDiff = possibleEnchantment.getMaxLevel() - possibleEnchantment.getStartLevel();
treasureDrop.addEnchantment(possibleEnchantment, Misc.getRandom().nextInt(levelDiff + 1) + possibleEnchantment.getStartLevel()); treasureDrop.addEnchantment(possibleEnchantment, Math.max(Misc.getRandom().nextInt(possibleEnchantment.getMaxLevel()) + 1, possibleEnchantment.getStartLevel()));
specificChance++; specificChance++;
enchanted = true; enchanted = true;
} }
}
return enchanted; return enchanted;
} }
private List<Enchantment> getPossibleEnchantments(ItemStack treasureDrop) {
Material dropType = treasureDrop.getType();
if (enchantableCache.containsKey(dropType)) {
return enchantableCache.get(dropType);
}
List<Enchantment> possibleEnchantments = new ArrayList<Enchantment>();
for (Enchantment enchantment : Enchantment.values()) {
if (enchantment.canEnchantItem(treasureDrop)) {
possibleEnchantments.add(enchantment);
}
}
enchantableCache.put(dropType, possibleEnchantments);
return possibleEnchantments;
}
/** /**
* Gets the vanilla XP multiplier * Gets the vanilla XP multiplier
* *

View File

@ -46,10 +46,11 @@ public final class MobHealthbarUtils {
PlayerProfile profile = UserManager.getPlayer(player).getProfile(); PlayerProfile profile = UserManager.getPlayer(player).getProfile();
if (profile == null) { if (profile.getMobHealthbarType() == null) {
return; profile.setMobHealthbarType(Config.getInstance().getMobHealthbarDefault());
} }
else if (profile.getMobHealthbarType() == MobHealthbarType.DISABLED) {
if (profile.getMobHealthbarType() == MobHealthbarType.DISABLED) {
return; return;
} }