mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-02 08:39:49 +01:00
Starting on cleaning up null checks & type casting
This commit is contained in:
parent
7c211fa50c
commit
d2f6191615
@ -5,7 +5,9 @@ import java.util.Random;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
|
||||
public class Acrobatics {
|
||||
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
||||
private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
||||
private static Random random = new Random();
|
||||
|
||||
public static final int DODGE_MAX_CHANCE = advancedConfig.getDodgeChanceMax();
|
||||
public static final int DODGE_MAX_BONUS_LEVEL = advancedConfig.getDodgeMaxBonusLevel();
|
||||
public static final int DODGE_XP_MODIFIER = advancedConfig.getDodgeXPModifier();
|
||||
@ -18,9 +20,7 @@ public class Acrobatics {
|
||||
public static final int ROLL_XP_MODIFIER = advancedConfig.getRollXPModifier();
|
||||
public static final int FALL_XP_MODIFIER = advancedConfig.getFallXPModifier();
|
||||
|
||||
private static Random random = new Random();
|
||||
|
||||
public static Random getRandom() {
|
||||
protected static Random getRandom() {
|
||||
return random;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package com.gmail.nossr50.skills.acrobatics;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
|
||||
public abstract class AcrobaticsEventHandler {
|
||||
protected AcrobaticsManager manager;
|
||||
protected Player player;
|
||||
@ -51,14 +53,10 @@ public abstract class AcrobaticsEventHandler {
|
||||
* @return true if the damage is fatal, false otherwise
|
||||
*/
|
||||
protected boolean isFatal(int damage) {
|
||||
if(player == null)
|
||||
return true;
|
||||
|
||||
if (player.getHealth() - damage < 1) {
|
||||
if (Misc.isCitizensNPC(player) || player.getHealth() - damage < 1) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,13 @@ import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class AcrobaticsManager {
|
||||
private static Config config = Config.getInstance();
|
||||
|
||||
private Player player;
|
||||
private PlayerProfile profile;
|
||||
private int skillLevel;
|
||||
@ -26,29 +29,28 @@ public class AcrobaticsManager {
|
||||
* @param event The event to check
|
||||
*/
|
||||
public void rollCheck(EntityDamageEvent event) {
|
||||
if(player == null)
|
||||
return;
|
||||
|
||||
if (!Permissions.roll(player)) {
|
||||
if (Misc.isCitizensNPC(player) || !Permissions.roll(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(Config.getInstance().getAcrobaticsAFKDisabled() && player.isInsideVehicle())
|
||||
if (config.getAcrobaticsAFKDisabled() && player.isInsideVehicle()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RollEventHandler eventHandler = new RollEventHandler(this, event);
|
||||
|
||||
int randomChance = 100;
|
||||
|
||||
if (Permissions.luckyAcrobatics(player)) {
|
||||
randomChance = (int) (randomChance * 0.75);
|
||||
}
|
||||
|
||||
float chance = (float) (((double) Acrobatics.ROLL_MAX_CHANCE / (double) Acrobatics.ROLL_MAX_BONUS_LEVEL) * skillLevel);
|
||||
if (chance > Acrobatics.ROLL_MAX_CHANCE) chance = Acrobatics.ROLL_MAX_CHANCE;
|
||||
float chance;
|
||||
|
||||
if (eventHandler.isGraceful) {
|
||||
chance = (float) (((double) Acrobatics.GRACEFUL_MAX_CHANCE / (double) Acrobatics.GRACEFUL_MAX_BONUS_LEVEL) * skillLevel);
|
||||
if (chance > Acrobatics.GRACEFUL_MAX_CHANCE) chance = Acrobatics.GRACEFUL_MAX_CHANCE;
|
||||
chance = ((float) Acrobatics.GRACEFUL_MAX_CHANCE / Acrobatics.GRACEFUL_MAX_BONUS_LEVEL) * eventHandler.skillModifier;
|
||||
}
|
||||
else {
|
||||
chance = ((float) Acrobatics.ROLL_MAX_CHANCE / Acrobatics.ROLL_MAX_BONUS_LEVEL) * eventHandler.skillModifier;
|
||||
}
|
||||
|
||||
if (chance > Acrobatics.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
|
||||
@ -67,23 +69,18 @@ public class AcrobaticsManager {
|
||||
* @param event The event to check
|
||||
*/
|
||||
public void dodgeCheck(EntityDamageEvent event) {
|
||||
if(player == null)
|
||||
return;
|
||||
|
||||
if (!Permissions.dodge(player)) {
|
||||
if (Misc.isCitizensNPC(player) || !Permissions.dodge(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
DodgeEventHandler eventHandler = new DodgeEventHandler(this, event);
|
||||
|
||||
int randomChance = 100;
|
||||
|
||||
if (Permissions.luckyAcrobatics(player)) {
|
||||
randomChance = (int) (randomChance * 0.75);
|
||||
}
|
||||
|
||||
float chance = (float) (((double) Acrobatics.DODGE_MAX_CHANCE / (double) Acrobatics.DODGE_MAX_BONUS_LEVEL) * skillLevel);
|
||||
if (chance > Acrobatics.DODGE_MAX_CHANCE) chance = Acrobatics.DODGE_MAX_CHANCE;
|
||||
float chance = ((float) Acrobatics.DODGE_MAX_CHANCE / Acrobatics.DODGE_MAX_BONUS_LEVEL) * eventHandler.skillModifier;
|
||||
|
||||
if (chance > Acrobatics.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
|
||||
eventHandler.modifyEventDamage();
|
||||
|
@ -39,20 +39,14 @@ public class DodgeEventHandler extends AcrobaticsEventHandler {
|
||||
|
||||
@Override
|
||||
protected void sendAbilityMessage() {
|
||||
if(player == null)
|
||||
return;
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Acrobatics.Combat.Proc"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processXPGain(int xp) {
|
||||
if(player == null)
|
||||
return;
|
||||
|
||||
PlayerProfile profile = manager.getProfile();
|
||||
|
||||
if (System.currentTimeMillis() >= profile.getRespawnATS() + 5) {
|
||||
if (System.currentTimeMillis() >= profile.getRespawnATS() + Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS) {
|
||||
Skills.xpProcessing(player, profile, SkillType.ACROBATICS, xp);
|
||||
}
|
||||
}
|
||||
|
@ -56,9 +56,6 @@ public class RollEventHandler extends AcrobaticsEventHandler {
|
||||
|
||||
@Override
|
||||
protected void sendAbilityMessage() {
|
||||
if(player == null)
|
||||
return;
|
||||
|
||||
if (isGraceful) {
|
||||
player.sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc"));
|
||||
}
|
||||
@ -70,9 +67,6 @@ public class RollEventHandler extends AcrobaticsEventHandler {
|
||||
|
||||
@Override
|
||||
protected void processXPGain(int xpGain) {
|
||||
if(player == null)
|
||||
return;
|
||||
|
||||
Skills.xpProcessing(player, manager.getProfile(), SkillType.ACROBATICS, xpGain);
|
||||
}
|
||||
|
||||
@ -80,9 +74,6 @@ public class RollEventHandler extends AcrobaticsEventHandler {
|
||||
* Check if this is a graceful roll.
|
||||
*/
|
||||
private void isGracefulRoll() {
|
||||
if(player == null)
|
||||
return;
|
||||
|
||||
if (Permissions.gracefulRoll(player)) {
|
||||
this.isGraceful = player.isSneaking();
|
||||
}
|
||||
|
@ -63,8 +63,7 @@ public class MiningManager {
|
||||
return;
|
||||
}
|
||||
|
||||
MiningManager manager = new MiningManager(player);
|
||||
SuperBreakerEventHandler eventHandler = new SuperBreakerEventHandler(manager, block);
|
||||
SuperBreakerEventHandler eventHandler = new SuperBreakerEventHandler(this, block);
|
||||
|
||||
if (eventHandler.tierCheck()) {
|
||||
return;
|
||||
|
@ -23,6 +23,11 @@ public class Misc {
|
||||
private static Random random = new Random();
|
||||
|
||||
public static final int TOOL_DURABILITY_LOSS = Config.getInstance().getAbilityToolDamage();
|
||||
public static final int PLAYER_RESPAWN_COOLDOWN_SECONDS = 5;
|
||||
|
||||
public static boolean isCitizensNPC(Player player) {
|
||||
return player.hasMetadata("NPC");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a capitalized version of the target string.
|
||||
|
Loading…
Reference in New Issue
Block a user