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