mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-30 00:56:47 +01:00
More cleaning on listeners. Also fixes NPE with itemInHand, because
Bukkit is dumb.
This commit is contained in:
parent
8736aae2ef
commit
7c59621c9e
@ -103,7 +103,7 @@ public class BlockListener implements Listener {
|
|||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (Misc.isNPC(player)) {
|
if (Misc.isNPCPlayer(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,7 +229,7 @@ public class BlockListener implements Listener {
|
|||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
ItemStack inHand = player.getItemInHand();
|
ItemStack inHand = player.getItemInHand();
|
||||||
|
|
||||||
if (Misc.isNPC(player)) {
|
if (Misc.isNPCPlayer(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ import com.gmail.nossr50.skills.SkillType;
|
|||||||
import com.gmail.nossr50.skills.Skills;
|
import com.gmail.nossr50.skills.Skills;
|
||||||
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
|
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
|
||||||
import com.gmail.nossr50.skills.archery.Archery;
|
import com.gmail.nossr50.skills.archery.Archery;
|
||||||
|
import com.gmail.nossr50.skills.herbalism.Herbalism;
|
||||||
import com.gmail.nossr50.skills.mining.MiningManager;
|
import com.gmail.nossr50.skills.mining.MiningManager;
|
||||||
import com.gmail.nossr50.skills.taming.TamingManager;
|
import com.gmail.nossr50.skills.taming.TamingManager;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
@ -53,7 +54,12 @@ public class EntityListener implements Listener {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
/**
|
||||||
|
* Monitor EntityChangeBlock events.
|
||||||
|
*
|
||||||
|
* @param event The event to watch
|
||||||
|
*/
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
|
public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
|
|
||||||
@ -74,7 +80,7 @@ public class EntityListener implements Listener {
|
|||||||
/**
|
/**
|
||||||
* Monitor EntityDamageByEntity events.
|
* Monitor EntityDamageByEntity events.
|
||||||
*
|
*
|
||||||
* @param event The event to monitor
|
* @param event The event to watch
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||||
@ -128,7 +134,7 @@ public class EntityListener implements Listener {
|
|||||||
/**
|
/**
|
||||||
* Monitor EntityDamage events.
|
* Monitor EntityDamage events.
|
||||||
*
|
*
|
||||||
* @param event The event to monitor
|
* @param event The event to watch
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onEntityDamage(EntityDamageEvent event) {
|
public void onEntityDamage(EntityDamageEvent event) {
|
||||||
@ -194,46 +200,45 @@ public class EntityListener implements Listener {
|
|||||||
/**
|
/**
|
||||||
* Monitor EntityDeath events.
|
* Monitor EntityDeath events.
|
||||||
*
|
*
|
||||||
* @param event The event to monitor
|
* @param event The event to watch
|
||||||
*/
|
*/
|
||||||
@EventHandler (priority = EventPriority.MONITOR)
|
@EventHandler (priority = EventPriority.MONITOR)
|
||||||
public void onEntityDeath(EntityDeathEvent event) {
|
public void onEntityDeath(EntityDeathEvent event) {
|
||||||
LivingEntity entity = event.getEntity();
|
LivingEntity entity = event.getEntity();
|
||||||
|
|
||||||
if (entity.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
|
if (Misc.isNPCEntity(entity)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
entity.setFireTicks(0);
|
entity.setFireTicks(0);
|
||||||
BleedTimer.remove(entity);
|
BleedTimer.remove(entity);
|
||||||
Archery.arrowRetrievalCheck(entity);
|
Archery.arrowRetrievalCheck(entity);
|
||||||
mcMMO.placeStore.removeSpawnedMob(entity);
|
mcMMO.placeStore.removeSpawnedMob(entity);
|
||||||
mcMMO.placeStore.removeSpawnedPet(entity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monitor CreatureSpawn events.
|
* Monitor CreatureSpawn events.
|
||||||
*
|
*
|
||||||
* @param event The event to monitor
|
* @param event The event to watch
|
||||||
*/
|
*/
|
||||||
@EventHandler (priority = EventPriority.MONITOR)
|
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||||
SpawnReason reason = event.getSpawnReason();
|
SpawnReason reason = event.getSpawnReason();
|
||||||
|
|
||||||
if ((reason.equals(SpawnReason.SPAWNER) || reason.equals(SpawnReason.SPAWNER_EGG)) && !Config.getInstance().getExperienceGainsMobspawnersEnabled()) {
|
if ((reason.equals(SpawnReason.SPAWNER) || reason.equals(SpawnReason.SPAWNER_EGG)) && Misc.isSpawnerXPEnabled) {
|
||||||
mcMMO.placeStore.addSpawnedMob(event.getEntity());
|
mcMMO.placeStore.addSpawnedMob(event.getEntity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monitor ExplosionPrime events.
|
* Handle ExplosionPrime events that involve modifying the event.
|
||||||
*
|
*
|
||||||
* @param event The event to monitor
|
* @param event The event to modify
|
||||||
*/
|
*/
|
||||||
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onExplosionPrime(ExplosionPrimeEvent event) {
|
public void onExplosionPrime(ExplosionPrimeEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
|
|
||||||
if (entity.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
|
|
||||||
|
|
||||||
if (entity instanceof TNTPrimed) {
|
if (entity instanceof TNTPrimed) {
|
||||||
int id = entity.getEntityId();
|
int id = entity.getEntityId();
|
||||||
|
|
||||||
@ -249,25 +254,23 @@ public class EntityListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monitor EntityExplode events.
|
* Handle EntityExplode events that involve modifying the event.
|
||||||
*
|
*
|
||||||
* @param event The event to monitor
|
* @param event The event to modify
|
||||||
*/
|
*/
|
||||||
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onEnitityExplode(EntityExplodeEvent event) {
|
public void onEnitityExplode(EntityExplodeEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
|
|
||||||
if (entity == null) return;
|
|
||||||
|
|
||||||
if (entity.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
|
|
||||||
|
|
||||||
if (entity instanceof TNTPrimed) {
|
if (entity instanceof TNTPrimed) {
|
||||||
int id = entity.getEntityId();
|
int id = entity.getEntityId();
|
||||||
|
|
||||||
if (plugin.tntIsTracked(id)) {
|
if (plugin.tntIsTracked(id)) {
|
||||||
Player player = plugin.getTNTPlayer(id);
|
Player player = plugin.getTNTPlayer(id);
|
||||||
|
|
||||||
MiningManager miningManager = new MiningManager(player);
|
MiningManager miningManager = new MiningManager(player);
|
||||||
miningManager.blastMiningDropProcessing(event);
|
miningManager.blastMiningDropProcessing(event);
|
||||||
|
|
||||||
plugin.removeFromTNTTracker(id);
|
plugin.removeFromTNTTracker(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -276,17 +279,20 @@ public class EntityListener implements Listener {
|
|||||||
/**
|
/**
|
||||||
* Monitor FoodLevelChange events.
|
* Monitor FoodLevelChange events.
|
||||||
*
|
*
|
||||||
* @param event The event to monitor
|
* @param event The event to watch
|
||||||
*/
|
*/
|
||||||
@EventHandler (priority = EventPriority.LOW)
|
@EventHandler (priority = EventPriority.LOW)
|
||||||
public void onFoodLevelChange(FoodLevelChangeEvent event) {
|
public void onFoodLevelChange(FoodLevelChangeEvent event) {
|
||||||
AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
Entity entity = event.getEntity();
|
||||||
if (event.getEntity() instanceof Player) {
|
|
||||||
Player player = (Player) event.getEntity();
|
|
||||||
|
|
||||||
if (player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
|
|
||||||
|
|
||||||
|
if (entity instanceof Player) {
|
||||||
|
Player player = (Player) entity;
|
||||||
PlayerProfile profile = Users.getProfile(player);
|
PlayerProfile profile = Users.getProfile(player);
|
||||||
|
|
||||||
|
if (Misc.isNPCPlayer(player, profile)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int currentFoodLevel = player.getFoodLevel();
|
int currentFoodLevel = player.getFoodLevel();
|
||||||
int newFoodLevel = event.getFoodLevel();
|
int newFoodLevel = event.getFoodLevel();
|
||||||
|
|
||||||
@ -305,72 +311,69 @@ public class EntityListener implements Listener {
|
|||||||
int rankChange = 0;
|
int rankChange = 0;
|
||||||
boolean fish = false;
|
boolean fish = false;
|
||||||
boolean herb = false;
|
boolean herb = false;
|
||||||
int herbFoodRank1 = advancedConfig.getFarmerDietRankChange();
|
int fishFoodRank1 = AdvancedConfig.getInstance().getFishermanDietRankChange();
|
||||||
int herbFoodRank2 = advancedConfig.getFarmerDietRankChange() * 2;
|
int fishFoodRank2 = AdvancedConfig.getInstance().getFishermanDietRankChange() * 2;
|
||||||
int herbFoodRankMax = advancedConfig.getFarmerDietRankChange() * 5;
|
int fishFoodRankMax = AdvancedConfig.getInstance().getFishermanDietRankChange() * 5;
|
||||||
int fishFoodRank1 = advancedConfig.getFishermanDietRankChange();
|
|
||||||
int fishFoodRank2 = advancedConfig.getFishermanDietRankChange() * 2;
|
|
||||||
int fishFoodRankMax = advancedConfig.getFishermanDietRankChange() * 5;
|
|
||||||
|
|
||||||
switch (food) {
|
switch (food) {
|
||||||
case BREAD:
|
case BREAD:
|
||||||
/* BREAD RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
|
/* BREAD RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
|
||||||
herb = true;
|
herb = true;
|
||||||
rankChange = herbFoodRank1;
|
rankChange = Herbalism.farmersDietRankLevel1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COOKIE:
|
case COOKIE:
|
||||||
/* COOKIE RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
|
/* COOKIE RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
|
||||||
herb = true;
|
herb = true;
|
||||||
rankChange = herbFoodRank2;
|
rankChange = Herbalism.farmersDietRankLevel2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MELON:
|
case MELON:
|
||||||
/* MELON RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
/* MELON RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
||||||
herb = true;
|
herb = true;
|
||||||
rankChange = herbFoodRank2;
|
rankChange = Herbalism.farmersDietRankLevel2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MUSHROOM_SOUP:
|
case MUSHROOM_SOUP:
|
||||||
/* MUSHROOM SOUP RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
|
/* MUSHROOM SOUP RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
|
||||||
herb = true;
|
herb = true;
|
||||||
rankChange = herbFoodRank1;
|
rankChange = Herbalism.farmersDietRankLevel1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CARROT_ITEM:
|
case CARROT_ITEM:
|
||||||
/* CARROT RESTORES 2 HUNGER - RESTORES 4 1/2 HUNGER @ 1000 */
|
/* CARROT RESTORES 2 HUNGER - RESTORES 4 1/2 HUNGER @ 1000 */
|
||||||
herb = true;
|
herb = true;
|
||||||
rankChange = herbFoodRank1;
|
rankChange = Herbalism.farmersDietRankLevel1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case POTATO_ITEM:
|
case POTATO_ITEM:
|
||||||
/* POTATO RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
|
/* POTATO RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
|
||||||
herb = true;
|
herb = true;
|
||||||
rankChange = herbFoodRank2;
|
rankChange = Herbalism.farmersDietRankLevel2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BAKED_POTATO:
|
case BAKED_POTATO:
|
||||||
/* BAKED POTATO RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
|
/* BAKED POTATO RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
|
||||||
herb = true;
|
herb = true;
|
||||||
rankChange = herbFoodRank1;
|
rankChange = Herbalism.farmersDietRankLevel1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case POISONOUS_POTATO:
|
case POISONOUS_POTATO:
|
||||||
/* POISONOUS POTATO RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
/* POISONOUS POTATO RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
||||||
herb = true;
|
herb = true;
|
||||||
rankChange = herbFoodRank2;
|
rankChange = Herbalism.farmersDietRankLevel2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GOLDEN_CARROT:
|
case GOLDEN_CARROT:
|
||||||
/* GOLDEN CARROT RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
|
/* GOLDEN CARROT RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
|
||||||
herb = true;
|
herb = true;
|
||||||
rankChange = herbFoodRank1;
|
rankChange = Herbalism.farmersDietRankLevel1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PUMPKIN_PIE:
|
case PUMPKIN_PIE:
|
||||||
/* PUMPKIN PIE RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
|
/* PUMPKIN PIE RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
|
||||||
herb = true;
|
herb = true;
|
||||||
rankChange = herbFoodRank1;
|
rankChange = Herbalism.farmersDietRankLevel1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RAW_FISH:
|
case RAW_FISH:
|
||||||
@ -394,7 +397,7 @@ public class EntityListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = herbFoodRank1; i <= herbFoodRankMax; i += rankChange) {
|
for (int i = Herbalism.farmersDietRankLevel1; i <= Herbalism.farmersDietMaxLevel; i += rankChange) {
|
||||||
if (herbLevel >= i) {
|
if (herbLevel >= i) {
|
||||||
foodChange++;
|
foodChange++;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ public class PlayerListener implements Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
PlayerProfile profile = Users.getProfile(player);
|
PlayerProfile profile = Users.getProfile(player);
|
||||||
|
|
||||||
if (Misc.isNPC(player, profile)) {
|
if (Misc.isNPCPlayer(player, profile)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ public class PlayerListener implements Listener {
|
|||||||
public void onPlayerFish(PlayerFishEvent event) {
|
public void onPlayerFish(PlayerFishEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (Misc.isNPC(player)) {
|
if (Misc.isNPCPlayer(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ public class PlayerListener implements Listener {
|
|||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (Misc.isNPC(player)) {
|
if (Misc.isNPCPlayer(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ public class PlayerListener implements Listener {
|
|||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (Misc.isNPC(player)) {
|
if (Misc.isNPCPlayer(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ public class PlayerListener implements Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
PlayerProfile profile = Users.getProfile(player);
|
PlayerProfile profile = Users.getProfile(player);
|
||||||
|
|
||||||
if (Misc.isNPC(player, profile)) {
|
if (Misc.isNPCPlayer(player, profile)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,18 +189,18 @@ public class PlayerListener implements Listener {
|
|||||||
/**
|
/**
|
||||||
* Handle PlayerInteract events that involve modifying the event.
|
* Handle PlayerInteract events that involve modifying the event.
|
||||||
*
|
*
|
||||||
* @param event The event to watch
|
* @param event The event to modify
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerInteractLowest(PlayerInteractEvent event) {
|
public void onPlayerInteractLowest(PlayerInteractEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (Misc.isNPC(player)) {
|
if (Misc.isNPCPlayer(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Block block = event.getClickedBlock();
|
Block block = event.getClickedBlock();
|
||||||
ItemStack heldItem = event.getItem();
|
ItemStack heldItem = player.getItemInHand();
|
||||||
|
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case RIGHT_CLICK_BLOCK:
|
case RIGHT_CLICK_BLOCK:
|
||||||
@ -252,12 +252,12 @@ public class PlayerListener implements Listener {
|
|||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (Misc.isNPC(player)) {
|
if (Misc.isNPCPlayer(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Block block = event.getClickedBlock();
|
Block block = event.getClickedBlock();
|
||||||
ItemStack heldItem = event.getItem();
|
ItemStack heldItem = player.getItemInHand();
|
||||||
|
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case RIGHT_CLICK_BLOCK:
|
case RIGHT_CLICK_BLOCK:
|
||||||
@ -339,7 +339,7 @@ public class PlayerListener implements Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
PlayerProfile profile = Users.getProfile(player);
|
PlayerProfile profile = Users.getProfile(player);
|
||||||
|
|
||||||
if (Misc.isNPC(player, profile)) {
|
if (Misc.isNPCPlayer(player, profile)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,7 +327,7 @@ public class Combat {
|
|||||||
|
|
||||||
for (Entity entity : target.getNearbyEntities(2.5, 2.5, 2.5)) {
|
for (Entity entity : target.getNearbyEntities(2.5, 2.5, 2.5)) {
|
||||||
if (entity instanceof Player) {
|
if (entity instanceof Player) {
|
||||||
if (Misc.isNPC((Player) entity)) {
|
if (Misc.isNPCPlayer((Player) entity)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.gmail.nossr50.skills;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.getspout.spoutapi.SpoutManager;
|
import org.getspout.spoutapi.SpoutManager;
|
||||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||||
@ -25,6 +26,28 @@ public class Skills {
|
|||||||
public static int abilityLengthIncreaseLevel = advancedConfig.getAbilityLength();
|
public static int abilityLengthIncreaseLevel = advancedConfig.getAbilityLength();
|
||||||
public static boolean abilitiesEnabled = Config.getInstance().getAbilitiesEnabled();
|
public static boolean abilitiesEnabled = Config.getInstance().getAbilitiesEnabled();
|
||||||
|
|
||||||
|
public static void handleFoodSkills(Player player, SkillType skill, FoodLevelChangeEvent event, int baseLevel, int maxLevel, int rankChange) {
|
||||||
|
int skillLevel = Users.getProfile(player).getSkillLevel(skill);
|
||||||
|
int currentFoodLevel = player.getFoodLevel();
|
||||||
|
int newFoodLevel = event.getFoodLevel();
|
||||||
|
int foodChange = newFoodLevel - currentFoodLevel;
|
||||||
|
|
||||||
|
for (int i = baseLevel; i <= maxLevel; i+= rankChange) {
|
||||||
|
if (skillLevel >= i) {
|
||||||
|
foodChange++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make sure we don't go over the max value */
|
||||||
|
newFoodLevel = currentFoodLevel + foodChange;
|
||||||
|
if (newFoodLevel > 20) {
|
||||||
|
event.setFoodLevel(20);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
event.setFoodLevel(newFoodLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks to see if the cooldown for an item or ability is expired.
|
* Checks to see if the cooldown for an item or ability is expired.
|
||||||
*
|
*
|
||||||
|
@ -53,7 +53,7 @@ public abstract class AcrobaticsEventHandler {
|
|||||||
* @return true if the damage is fatal, false otherwise
|
* @return true if the damage is fatal, false otherwise
|
||||||
*/
|
*/
|
||||||
protected boolean isFatal(int damage) {
|
protected boolean isFatal(int damage) {
|
||||||
if (Misc.isNPC(player) || player.getHealth() - damage < 1) {
|
if (Misc.isNPCPlayer(player) || player.getHealth() - damage < 1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ public class AcrobaticsManager extends SkillManager {
|
|||||||
* @param event The event to check
|
* @param event The event to check
|
||||||
*/
|
*/
|
||||||
public void rollCheck(EntityDamageEvent event) {
|
public void rollCheck(EntityDamageEvent event) {
|
||||||
if (Misc.isNPC(player) || !Permissions.roll(player)) {
|
if (Misc.isNPCPlayer(player) || !Permissions.roll(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ public class AcrobaticsManager extends SkillManager {
|
|||||||
* @param event The event to check
|
* @param event The event to check
|
||||||
*/
|
*/
|
||||||
public void dodgeCheck(EntityDamageEvent event) {
|
public void dodgeCheck(EntityDamageEvent event) {
|
||||||
if (Misc.isNPC(player) || !Permissions.dodge(player)) {
|
if (Misc.isNPCPlayer(player) || !Permissions.dodge(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ public class ArcheryManager extends SkillManager {
|
|||||||
* @param livingEntity Entity damaged by the arrow
|
* @param livingEntity Entity damaged by the arrow
|
||||||
*/
|
*/
|
||||||
public void trackArrows(LivingEntity livingEntity) {
|
public void trackArrows(LivingEntity livingEntity) {
|
||||||
if (Misc.isNPC(player) || !Permissions.trackArrows(player)) {
|
if (Misc.isNPCPlayer(player) || !Permissions.trackArrows(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ public class ArcheryManager extends SkillManager {
|
|||||||
* @param event The event to modify
|
* @param event The event to modify
|
||||||
*/
|
*/
|
||||||
public void dazeCheck(Player defender, EntityDamageEvent event) {
|
public void dazeCheck(Player defender, EntityDamageEvent event) {
|
||||||
if (Misc.isNPC(player) || !Permissions.daze(player)) {
|
if (Misc.isNPCPlayer(player) || !Permissions.daze(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ public class ArcheryManager extends SkillManager {
|
|||||||
* @param event The event to modify.
|
* @param event The event to modify.
|
||||||
*/
|
*/
|
||||||
public void skillShot(EntityDamageEvent event) {
|
public void skillShot(EntityDamageEvent event) {
|
||||||
if (Misc.isNPC(player) || !Permissions.archeryBonus(player)) {
|
if (Misc.isNPCPlayer(player) || !Permissions.archeryBonus(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ public class AxeManager extends SkillManager {
|
|||||||
* @param event The event to modify
|
* @param event The event to modify
|
||||||
*/
|
*/
|
||||||
public void bonusDamage(EntityDamageByEntityEvent event) {
|
public void bonusDamage(EntityDamageByEntityEvent event) {
|
||||||
if (Misc.isNPC(player) || !Permissions.axeBonus(player)) {
|
if (Misc.isNPCPlayer(player) || !Permissions.axeBonus(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ public class AxeManager extends SkillManager {
|
|||||||
* @param event The event to modify
|
* @param event The event to modify
|
||||||
*/
|
*/
|
||||||
public void criticalHitCheck(EntityDamageByEntityEvent event) {
|
public void criticalHitCheck(EntityDamageByEntityEvent event) {
|
||||||
if (Misc.isNPC(player) || !Permissions.criticalHit(player)) {
|
if (Misc.isNPCPlayer(player) || !Permissions.criticalHit(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ public class AxeManager extends SkillManager {
|
|||||||
* @param event The event to modify
|
* @param event The event to modify
|
||||||
*/
|
*/
|
||||||
public void impact(EntityDamageByEntityEvent event) {
|
public void impact(EntityDamageByEntityEvent event) {
|
||||||
if (Misc.isNPC(player) || !Permissions.impact(player)) {
|
if (Misc.isNPCPlayer(player) || !Permissions.impact(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ public class AxeManager extends SkillManager {
|
|||||||
* @param event The event to process
|
* @param event The event to process
|
||||||
*/
|
*/
|
||||||
public void skullSplitter(EntityDamageByEntityEvent event) {
|
public void skullSplitter(EntityDamageByEntityEvent event) {
|
||||||
if (Misc.isNPC(player) || !Permissions.skullSplitter(player) || !profile.getAbilityMode(AbilityType.SKULL_SPLIITER)) {
|
if (Misc.isNPCPlayer(player) || !Permissions.skullSplitter(player) || !profile.getAbilityMode(AbilityType.SKULL_SPLIITER)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.material.MaterialData;
|
import org.bukkit.material.MaterialData;
|
||||||
@ -28,8 +29,9 @@ import com.gmail.nossr50.util.Permissions;
|
|||||||
import com.gmail.nossr50.util.Users;
|
import com.gmail.nossr50.util.Users;
|
||||||
|
|
||||||
public class Herbalism {
|
public class Herbalism {
|
||||||
public static int farmersDietRankChangeLevel = AdvancedConfig.getInstance().getFarmerDietRankChange();
|
public static int farmersDietRankLevel1 = AdvancedConfig.getInstance().getFarmerDietRankChange();
|
||||||
public static int farmersDietMaxLevel = farmersDietRankChangeLevel * 5;
|
public static int farmersDietRankLevel2 = farmersDietRankLevel1 * 2;
|
||||||
|
public static int farmersDietMaxLevel = farmersDietRankLevel1 * 5;
|
||||||
|
|
||||||
public static int greenThumbStageChangeLevel = AdvancedConfig.getInstance().getGreenThumbStageChange();
|
public static int greenThumbStageChangeLevel = AdvancedConfig.getInstance().getGreenThumbStageChange();
|
||||||
public static int greenThumbStageMaxLevel = greenThumbStageChangeLevel * 4;
|
public static int greenThumbStageMaxLevel = greenThumbStageChangeLevel * 4;
|
||||||
@ -44,6 +46,14 @@ public class Herbalism {
|
|||||||
public static double hylianLuckMaxChance = AdvancedConfig.getInstance().getHylianLuckChanceMax();
|
public static double hylianLuckMaxChance = AdvancedConfig.getInstance().getHylianLuckChanceMax();
|
||||||
public static int hylianLuckMaxLevel = AdvancedConfig.getInstance().getHylianLucksMaxLevel();
|
public static int hylianLuckMaxLevel = AdvancedConfig.getInstance().getHylianLucksMaxLevel();
|
||||||
|
|
||||||
|
public static void farmersDiet(Player player, int rankChange, FoodLevelChangeEvent event) {
|
||||||
|
if (!Permissions.farmersDiet(player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Skills.handleFoodSkills(player, SkillType.HERBALISM, event, farmersDietRankLevel1, farmersDietMaxLevel, rankChange);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activate the Green Terra ability.
|
* Activate the Green Terra ability.
|
||||||
*
|
*
|
||||||
|
@ -37,7 +37,7 @@ public class HerbalismCommand extends SkillCommand {
|
|||||||
greenTerraLengthEndurance = greenTerraStrings[1];
|
greenTerraLengthEndurance = greenTerraStrings[1];
|
||||||
|
|
||||||
//FARMERS DIET
|
//FARMERS DIET
|
||||||
farmersDietRank = calculateRank(Herbalism.farmersDietMaxLevel, Herbalism.farmersDietRankChangeLevel);
|
farmersDietRank = calculateRank(Herbalism.farmersDietMaxLevel, Herbalism.farmersDietRankLevel1);
|
||||||
|
|
||||||
//GREEN THUMB
|
//GREEN THUMB
|
||||||
greenThumbStage = calculateRank(Herbalism.greenThumbStageMaxLevel, Herbalism.greenThumbStageMaxLevel);
|
greenThumbStage = calculateRank(Herbalism.greenThumbStageMaxLevel, Herbalism.greenThumbStageMaxLevel);
|
||||||
|
@ -58,7 +58,7 @@ public class MiningManager extends SkillManager{
|
|||||||
* @param event Event whose explosion is being processed
|
* @param event Event whose explosion is being processed
|
||||||
*/
|
*/
|
||||||
public void blastMiningDropProcessing(EntityExplodeEvent event) {
|
public void blastMiningDropProcessing(EntityExplodeEvent event) {
|
||||||
if (Misc.isNPC(player)) {
|
if (Misc.isNPCPlayer(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ public class MiningManager extends SkillManager{
|
|||||||
* @param event Event whose explosion damage is being reduced
|
* @param event Event whose explosion damage is being reduced
|
||||||
*/
|
*/
|
||||||
public void demolitionsExpertise(EntityDamageEvent event) {
|
public void demolitionsExpertise(EntityDamageEvent event) {
|
||||||
if (Misc.isNPC(player)) {
|
if (Misc.isNPCPlayer(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ public class MiningManager extends SkillManager{
|
|||||||
* @param event Event whose explosion radius is being changed
|
* @param event Event whose explosion radius is being changed
|
||||||
*/
|
*/
|
||||||
public void biggerBombs(ExplosionPrimeEvent event) {
|
public void biggerBombs(ExplosionPrimeEvent event) {
|
||||||
if (Misc.isNPC(player)) {
|
if (Misc.isNPCPlayer(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ public class SmeltingManager extends SkillManager {
|
|||||||
* @param event The {@link FurnaceBurnEvent} to modify.
|
* @param event The {@link FurnaceBurnEvent} to modify.
|
||||||
*/
|
*/
|
||||||
public void fuelEfficiency(FurnaceBurnEvent event) {
|
public void fuelEfficiency(FurnaceBurnEvent event) {
|
||||||
if (Misc.isNPC(player) || !Permissions.fuelEfficiency(player)) {
|
if (Misc.isNPCPlayer(player) || !Permissions.fuelEfficiency(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ public class SmeltingManager extends SkillManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void smeltProcessing(FurnaceSmeltEvent event) {
|
public void smeltProcessing(FurnaceSmeltEvent event) {
|
||||||
if (Misc.isNPC(player)) {
|
if (Misc.isNPCPlayer(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ public class SwordsManager extends SkillManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void serratedStrikes(LivingEntity target, int damage) {
|
public void serratedStrikes(LivingEntity target, int damage) {
|
||||||
if (Misc.isNPC(player) || !Permissions.serratedStrikes(player) || !profile.getAbilityMode(AbilityType.SERRATED_STRIKES)) {
|
if (Misc.isNPCPlayer(player) || !Permissions.serratedStrikes(player) || !profile.getAbilityMode(AbilityType.SERRATED_STRIKES)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ public class UnarmedManager extends SkillManager {
|
|||||||
* @param defender The defending player
|
* @param defender The defending player
|
||||||
*/
|
*/
|
||||||
public void disarmCheck(Player defender) {
|
public void disarmCheck(Player defender) {
|
||||||
if (Misc.isNPC(player) || !Permissions.disarm(player)) {
|
if (Misc.isNPCPlayer(player) || !Permissions.disarm(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.AnimalTamer;
|
import org.bukkit.entity.AnimalTamer;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -29,6 +30,7 @@ public class Misc {
|
|||||||
|
|
||||||
public static int toolDurabilityLoss = Config.getInstance().getAbilityToolDamage();
|
public static int toolDurabilityLoss = Config.getInstance().getAbilityToolDamage();
|
||||||
public static int abilityLengthIncreaseLevel = AdvancedConfig.getInstance().getAbilityLength();
|
public static int abilityLengthIncreaseLevel = AdvancedConfig.getInstance().getAbilityLength();
|
||||||
|
public static boolean isSpawnerXPEnabled = Config.getInstance().getExperienceGainsMobspawnersEnabled();
|
||||||
|
|
||||||
public static final int PLAYER_RESPAWN_COOLDOWN_SECONDS = 5;
|
public static final int PLAYER_RESPAWN_COOLDOWN_SECONDS = 5;
|
||||||
public static final int TIME_CONVERSION_FACTOR = 1000;
|
public static final int TIME_CONVERSION_FACTOR = 1000;
|
||||||
@ -82,7 +84,15 @@ public class Misc {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNPC(Player player) {
|
public static boolean isNPCEntity(Entity entity) {
|
||||||
|
if (entity == null || entity.hasMetadata("NPC")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNPCPlayer(Player player) {
|
||||||
if (player == null || Users.getProfile(player) == null || player.hasMetadata("NPC")) {
|
if (player == null || Users.getProfile(player) == null || player.hasMetadata("NPC")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -90,7 +100,7 @@ public class Misc {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNPC(Player player, PlayerProfile profile) {
|
public static boolean isNPCPlayer(Player player, PlayerProfile profile) {
|
||||||
if (player == null || profile == null || player.hasMetadata("NPC")) {
|
if (player == null || profile == null || player.hasMetadata("NPC")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user