Static Abuse Cleanup - EventUtils -> EventManager

This commit is contained in:
nossr50 2019-07-02 18:32:28 -07:00
parent fc9942fdc4
commit 4c4732695b
23 changed files with 92 additions and 78 deletions

View File

@ -4,7 +4,7 @@ import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.EventManager;
import com.gmail.nossr50.util.Permissions;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -35,7 +35,7 @@ public class AddlevelsCommand extends ExperienceCommand {
return;
}
EventUtils.tryLevelChangeEvent(player, skill, value, xpRemoved, true, XPGainReason.COMMAND);
pluginRef.getEventManager().tryLevelChangeEvent(player, skill, value, xpRemoved, true, XPGainReason.COMMAND);
}
@Override

View File

@ -4,7 +4,7 @@ import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.EventManager;
import com.gmail.nossr50.util.Permissions;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -40,7 +40,7 @@ public class MmoeditCommand extends ExperienceCommand {
return;
}
EventUtils.tryLevelEditEvent(player, skill, value, xpRemoved, value > skillLevel, XPGainReason.COMMAND, skillLevel);
pluginRef.getEventManager().tryLevelEditEvent(player, skill, value, xpRemoved, value > skillLevel, XPGainReason.COMMAND, skillLevel);
}
@Override

View File

@ -5,7 +5,7 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.EventManager;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
@ -137,7 +137,7 @@ public class SkillresetCommand implements TabExecutor {
return;
}
EventUtils.tryLevelChangeEvent(player, skill, levelsRemoved, xpRemoved, false, XPGainReason.COMMAND);
pluginRef.getEventManager().tryLevelChangeEvent(player, skill, levelsRemoved, xpRemoved, false, XPGainReason.COMMAND);
}
protected boolean permissionsCheckSelf(CommandSender sender) {

View File

@ -7,7 +7,7 @@ import com.gmail.nossr50.datatypes.party.PartyTeleportRecord;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.items.TeleportationWarmup;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.EventManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
@ -93,7 +93,7 @@ public class PtpCommand implements TabExecutor {
teleportingPlayer.sendMessage(pluginRef.getLocaleManager().getString("Teleport.Commencing", warmup));
new TeleportationWarmup(mcMMOPlayer, mcMMOTarget).runTaskLater(pluginRef, 20 * warmup);
} else {
EventUtils.handlePartyTeleportEvent(teleportingPlayer, targetPlayer);
pluginRef.getEventManager().handlePartyTeleportEvent(teleportingPlayer, targetPlayer);
}
}

View File

@ -1,7 +1,7 @@
package com.gmail.nossr50.datatypes.party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.EventManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.sounds.SoundManager;
@ -203,7 +203,7 @@ public class Party {
* @param xp Experience amount to add
*/
public void applyXpGain(double xp) {
if (!EventUtils.handlePartyXpGainEvent(this, xp)) {
if (!pluginRef.getEventManager().handlePartyXpGainEvent(this, xp)) {
return;
}
@ -224,7 +224,7 @@ public class Party {
levelsGained++;
}
if (!EventUtils.handlePartyLevelChangeEvent(this, levelsGained, xpRemoved)) {
if (!pluginRef.getEventManager().handlePartyLevelChangeEvent(this, levelsGained, xpRemoved)) {
return;
}

View File

@ -32,7 +32,7 @@ import com.gmail.nossr50.skills.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.EventManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.experience.ExperienceBarManager;
@ -581,7 +581,7 @@ public class McMMOPlayer {
return;
}
if (!EventUtils.handleXpGainEvent(player, primarySkillType, xp, xpGainReason)) {
if (!pluginRef.getEventManager().handleXpGainEvent(player, primarySkillType, xp, xpGainReason)) {
return;
}
@ -617,7 +617,7 @@ public class McMMOPlayer {
levelsGained++;
}
if (EventUtils.tryLevelChangeEvent(player, primarySkillType, levelsGained, xpRemoved, true, xpGainReason)) {
if (pluginRef.getEventManager().tryLevelChangeEvent(player, primarySkillType, levelsGained, xpRemoved, true, xpGainReason)) {
return;
}
@ -867,7 +867,7 @@ public class McMMOPlayer {
return;
}
if (EventUtils.callPlayerAbilityActivateEvent(player, skill).isCancelled()) {
if (pluginRef.getEventManager().callPlayerAbilityActivateEvent(player, skill).isCancelled()) {
return;
}

View File

@ -6,7 +6,7 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.EventManager;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.random.RandomChanceSkill;
@ -59,14 +59,14 @@ public class Roll extends AcrobaticsSubSkill {
EntityDamageEvent entityDamageEvent = (EntityDamageEvent) event;
//Make sure a real player was damaged in this event
if (!EventUtils.isRealPlayerDamaged(entityDamageEvent))
if (!pluginRef.getEventManager().isRealPlayerDamaged(entityDamageEvent))
return false;
switch (entityDamageEvent.getCause()) {
case FALL:
//Grab the player
McMMOPlayer mcMMOPlayer = EventUtils.getMcMMOPlayer(entityDamageEvent.getEntity());
McMMOPlayer mcMMOPlayer = pluginRef.getEventManager().getMcMMOPlayer(entityDamageEvent.getEntity());
if (mcMMOPlayer == null)
break;

View File

@ -18,7 +18,7 @@ import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.salvage.Salvage;
import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager;
import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.EventManager;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
@ -546,15 +546,15 @@ public class BlockListener implements Listener {
blockState.update(true);
}
} else if (mcMMOPlayer.getAbilityMode(SuperAbilityType.BERSERK) && heldItem.getType() == Material.AIR) {
if (SuperAbilityType.BERSERK.blockCheck(block.getState()) && EventUtils.simulateBlockBreak(block, player, true)) {
if (SuperAbilityType.BERSERK.blockCheck(block.getState()) && pluginRef.getEventManager().simulateBlockBreak(block, player, true)) {
event.setInstaBreak(true);
SoundManager.sendSound(player, block.getLocation(), SoundType.POP);
} else if (mcMMOPlayer.getUnarmedManager().canUseBlockCracker() && BlockUtils.affectedByBlockCracker(blockState) && EventUtils.simulateBlockBreak(block, player, true)) {
} else if (mcMMOPlayer.getUnarmedManager().canUseBlockCracker() && BlockUtils.affectedByBlockCracker(blockState) && pluginRef.getEventManager().simulateBlockBreak(block, player, true)) {
if (mcMMOPlayer.getUnarmedManager().blockCrackerCheck(blockState)) {
blockState.update();
}
}
} else if (mcMMOPlayer.getWoodcuttingManager().canUseLeafBlower(heldItem) && BlockUtils.isLeaves(blockState) && EventUtils.simulateBlockBreak(block, player, true)) {
} else if (mcMMOPlayer.getWoodcuttingManager().canUseLeafBlower(heldItem) && BlockUtils.isLeaves(blockState) && pluginRef.getEventManager().simulateBlockBreak(block, player, true)) {
event.setInstaBreak(true);
SoundManager.sendSound(player, block.getLocation(), SoundType.POP);
}

View File

@ -161,7 +161,7 @@ public class PlayerListener implements Listener {
}
if (statLossEnabled || (killer != null && vampirismEnabled)) {
if (EventUtils.callPreDeathPenaltyEvent(killedPlayer).isCancelled()) {
if (pluginRef.getEventManager().callPreDeathPenaltyEvent(killedPlayer).isCancelled()) {
return;
}
@ -760,7 +760,7 @@ public class PlayerListener implements Listener {
if (herbalismManager.canGreenThumbBlock(blockState)) {
Bukkit.getPluginManager().callEvent(fakeSwing);
player.getInventory().setItemInMainHand(new ItemStack(Material.WHEAT_SEEDS, heldItem.getAmount() - 1));
if (herbalismManager.processGreenThumbBlocks(blockState) && EventUtils.simulateBlockBreak(block, player, false)) {
if (herbalismManager.processGreenThumbBlocks(blockState) && pluginRef.getEventManager().simulateBlockBreak(block, player, false)) {
blockState.update(true);
}
}
@ -768,7 +768,7 @@ public class PlayerListener implements Listener {
else if (herbalismManager.canUseShroomThumb(blockState)) {
Bukkit.getPluginManager().callEvent(fakeSwing);
event.setCancelled(true);
if (herbalismManager.processShroomThumb(blockState) && EventUtils.simulateBlockBreak(block, player, false)) {
if (herbalismManager.processShroomThumb(blockState) && pluginRef.getEventManager().simulateBlockBreak(block, player, false)) {
blockState.update(true);
}
}

View File

@ -71,6 +71,7 @@ public class mcMMO extends JavaPlugin {
private LocaleManager localeManager;
private ChatManager chatManager;
private MobHealthBarManager mobHealthBarManager;
private EventManager eventManager;
/* File Paths */
private String mainDirectory;
@ -181,6 +182,8 @@ public class mcMMO extends JavaPlugin {
getLogger().info("Please do not replace the mcMMO jar while the server is running.");
}
//TODO: Put all manager init somewhere nice and tidy
//Init Material Maps
materialMapStore = new MaterialMapStore();
@ -195,6 +198,9 @@ public class mcMMO extends JavaPlugin {
//Init Mob Health Bar Manager
mobHealthBarManager = new MobHealthBarManager(this);
//Init Event Manager
eventManager = new EventManager(this);
}
@Override
@ -629,4 +635,8 @@ public class mcMMO extends JavaPlugin {
public MobHealthBarManager getMobHealthBarManager() {
return mobHealthBarManager;
}
public EventManager getEventManager() {
return eventManager;
}
}

View File

@ -1,7 +1,7 @@
package com.gmail.nossr50.runnables.items;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.EventManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.skills.SkillUtils;
import org.bukkit.Location;
@ -48,6 +48,6 @@ public class TeleportationWarmup extends BukkitRunnable {
}
}
EventUtils.handlePartyTeleportEvent(teleportingPlayer, targetPlayer);
pluginRef.getEventManager().handlePartyTeleportEvent(teleportingPlayer, targetPlayer);
}
}

View File

@ -3,7 +3,7 @@ package com.gmail.nossr50.runnables.skills;
import com.gmail.nossr50.datatypes.interactions.NotificationType;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.EventManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.skills.PerksUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
@ -43,7 +43,7 @@ public class AbilityDisableTask extends BukkitRunnable {
break;
}
EventUtils.callAbilityDeactivateEvent(player, ability);
pluginRef.getEventManager().callAbilityDeactivateEvent(player, ability);
mcMMOPlayer.setAbilityMode(ability, false);
mcMMOPlayer.setAbilityInformed(ability, false);

View File

@ -183,7 +183,7 @@ public class FishingManager extends SkillManager {
return false;
}
return EventUtils.simulateBlockBreak(block, player, false);
return pluginRef.getEventManager().simulateBlockBreak(block, player, false);
}
/**
@ -237,7 +237,7 @@ public class FishingManager extends SkillManager {
}
// Recast in the new spot
EventUtils.callFakeFishEvent(getPlayer(), hook);
pluginRef.getEventManager().callFakeFishEvent(getPlayer(), hook);
}
public void masterAngler(FishHook hook) {
@ -289,7 +289,7 @@ public class FishingManager extends SkillManager {
enchants = handleMagicHunter(treasureDrop);
}
McMMOPlayerFishingTreasureEvent event = EventUtils.callFishingTreasureEvent(player, treasureDrop, treasure.getXp(), enchants);
McMMOPlayerFishingTreasureEvent event = pluginRef.getEventManager().callFishingTreasureEvent(player, treasureDrop, treasure.getXp(), enchants);
if (!event.isCancelled()) {
treasureDrop = event.getTreasure();

View File

@ -227,7 +227,7 @@ public class HerbalismManager extends SkillManager {
for (HylianTreasure treasure : treasures) {
if (skillLevel >= treasure.getDropLevel()
&& RandomChanceUtil.checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(treasure.getDropChance(), getPlayer(), SubSkillType.HERBALISM_HYLIAN_LUCK))) {
if (!EventUtils.simulateBlockBreak(blockState.getBlock(), player, false)) {
if (!pluginRef.getEventManager().simulateBlockBreak(blockState.getBlock(), player, false)) {
return false;
}
blockState.setType(Material.AIR);

View File

@ -10,7 +10,7 @@ import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.runnables.skills.AbilityCooldownTask;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.EventManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.random.RandomChanceUtil;
@ -111,7 +111,7 @@ public class MiningManager extends SkillManager {
Block targetBlock = player.getTargetBlock(BlockUtils.getTransparentBlocks(), BlastMining.MAXIMUM_REMOTE_DETONATION_DISTANCE);
//Blast mining cooldown check needs to be first so the player can be messaged
if (!blastMiningCooldownOver() || targetBlock.getType() != Material.TNT || !EventUtils.simulateBlockBreak(targetBlock, player, true)) {
if (!blastMiningCooldownOver() || targetBlock.getType() != Material.TNT || !pluginRef.getEventManager().simulateBlockBreak(targetBlock, player, true)) {
return;
}

View File

@ -6,7 +6,7 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.EventManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
@ -130,7 +130,7 @@ public class SalvageManager extends SkillManager {
ItemStack salvageResults = new ItemStack(salvageable.getSalvagedItemMaterial(), lotteryResults);
//Call event
if (EventUtils.callSalvageCheckEvent(player, item, salvageResults, enchantBook).isCancelled()) {
if (pluginRef.getEventManager().callSalvageCheckEvent(player, item, salvageResults, enchantBook).isCancelled()) {
return;
}

View File

@ -8,7 +8,7 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.EventManager;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
@ -95,7 +95,7 @@ public class UnarmedManager extends SkillManager {
*/
public void disarmCheck(Player defender) {
if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.UNARMED_DISARM, getPlayer()) && !hasIronGrip(defender)) {
if (EventUtils.callDisarmEvent(defender).isCancelled()) {
if (pluginRef.getEventManager().callDisarmEvent(defender).isCancelled()) {
return;
}

View File

@ -117,7 +117,7 @@ public class WoodcuttingManager extends SkillManager {
for (BlockState blockState : treeFellerBlocks) {
Block block = blockState.getBlock();
if (!EventUtils.simulateBlockBreak(block, player, true)) {
if (!pluginRef.getEventManager().simulateBlockBreak(block, player, true)) {
break; // TODO: Shouldn't we use continue instead?
}

View File

@ -30,6 +30,7 @@ import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent;
import com.gmail.nossr50.events.skills.salvage.McMMOPlayerSalvageCheckEvent;
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillEvent;
import com.gmail.nossr50.events.skills.unarmed.McMMOPlayerDisarmEvent;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.CombatUtils;
import net.md_5.bungee.api.chat.TextComponent;
@ -53,10 +54,13 @@ import java.util.Map;
/**
* This class is meant to help make event related code less boilerplate
*/
public class EventUtils {
/*
* Quality of Life methods
*/
public class EventManager {
private mcMMO pluginRef;
public EventManager(mcMMO pluginRef) {
this.pluginRef = pluginRef;
}
/**
* Checks to see if damage is from natural sources
@ -65,7 +69,7 @@ public class EventUtils {
* @param event this event
* @return true if damage is NOT from an unnatural mcMMO skill (such as bleed DOTs)
*/
public static boolean isDamageFromMcMMOComplexBehaviour(Event event) {
public boolean isDamageFromMcMMOComplexBehaviour(Event event) {
if (event instanceof FakeEntityDamageEvent) {
return true;
}
@ -78,7 +82,7 @@ public class EventUtils {
* @param entity target entity
* @return the associated McMMOPlayer for this entity
*/
public static McMMOPlayer getMcMMOPlayer(Entity entity) {
public McMMOPlayer getMcMMOPlayer(Entity entity) {
return UserManager.getPlayer((Player) entity);
}
@ -95,7 +99,7 @@ public class EventUtils {
* @param entityDamageEvent
* @return
*/
public static boolean isRealPlayerDamaged(EntityDamageEvent entityDamageEvent) {
public boolean isRealPlayerDamaged(EntityDamageEvent entityDamageEvent) {
//Make sure the damage is above 0
double damage = entityDamageEvent.getDamage();
double finalDamage = entityDamageEvent.getFinalDamage();
@ -163,7 +167,7 @@ public class EventUtils {
* Others
*/
public static McMMOPlayerAbilityActivateEvent callPlayerAbilityActivateEvent(Player player, PrimarySkillType skill) {
public McMMOPlayerAbilityActivateEvent callPlayerAbilityActivateEvent(Player player, PrimarySkillType skill) {
McMMOPlayerAbilityActivateEvent event = new McMMOPlayerAbilityActivateEvent(player, skill);
pluginRef.getServer().getPluginManager().callEvent(event);
@ -178,7 +182,7 @@ public class EventUtils {
* @return the event after it has been fired
*/
@Deprecated
public static SubSkillEvent callSubSkillEvent(Player player, SubSkillType subSkillType) {
public SubSkillEvent callSubSkillEvent(Player player, SubSkillType subSkillType) {
SubSkillEvent event = new SubSkillEvent(player, subSkillType);
pluginRef.getServer().getPluginManager().callEvent(event);
@ -192,20 +196,20 @@ public class EventUtils {
* @param abstractSubSkill target subskill
* @return the event after it has been fired
*/
public static SubSkillEvent callSubSkillEvent(Player player, AbstractSubSkill abstractSubSkill) {
public SubSkillEvent callSubSkillEvent(Player player, AbstractSubSkill abstractSubSkill) {
SubSkillEvent event = new SubSkillEvent(player, abstractSubSkill);
pluginRef.getServer().getPluginManager().callEvent(event);
return event;
}
public static void callFakeArmSwingEvent(Player player) {
public void callFakeArmSwingEvent(Player player) {
FakePlayerAnimationEvent event = new FakePlayerAnimationEvent(player);
pluginRef.getServer().getPluginManager().callEvent(event);
}
public static boolean tryLevelChangeEvent(Player player, PrimarySkillType skill, int levelsChanged, float xpRemoved, boolean isLevelUp, XPGainReason xpGainReason) {
public boolean tryLevelChangeEvent(Player player, PrimarySkillType skill, int levelsChanged, float xpRemoved, boolean isLevelUp, XPGainReason xpGainReason) {
McMMOPlayerLevelChangeEvent event = isLevelUp ? new McMMOPlayerLevelUpEvent(player, skill, levelsChanged, xpGainReason) : new McMMOPlayerLevelDownEvent(player, skill, levelsChanged, xpGainReason);
pluginRef.getServer().getPluginManager().callEvent(event);
@ -221,7 +225,7 @@ public class EventUtils {
return isCancelled;
}
public static boolean tryLevelEditEvent(Player player, PrimarySkillType skill, int levelsChanged, float xpRemoved, boolean isLevelUp, XPGainReason xpGainReason, int oldLevel) {
public boolean tryLevelEditEvent(Player player, PrimarySkillType skill, int levelsChanged, float xpRemoved, boolean isLevelUp, XPGainReason xpGainReason, int oldLevel) {
McMMOPlayerLevelChangeEvent event = isLevelUp ? new McMMOPlayerLevelUpEvent(player, skill, levelsChanged - oldLevel, xpGainReason) : new McMMOPlayerLevelDownEvent(player, skill, levelsChanged, xpGainReason);
pluginRef.getServer().getPluginManager().callEvent(event);
@ -245,7 +249,7 @@ public class EventUtils {
* @param shouldArmSwing true if an armswing event should be fired, false otherwise
* @return true if the event wasn't cancelled, false otherwise
*/
public static boolean simulateBlockBreak(Block block, Player player, boolean shouldArmSwing) {
public boolean simulateBlockBreak(Block block, Player player, boolean shouldArmSwing) {
PluginManager pluginManager = pluginRef.getServer().getPluginManager();
// Support for NoCheat
@ -262,7 +266,7 @@ public class EventUtils {
return !damageEvent.isCancelled() && !breakEvent.isCancelled();
}
public static void handlePartyTeleportEvent(Player teleportingPlayer, Player targetPlayer) {
public void handlePartyTeleportEvent(Player teleportingPlayer, Player targetPlayer) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(teleportingPlayer);
if (mcMMOPlayer == null)
@ -283,7 +287,7 @@ public class EventUtils {
mcMMOPlayer.getPartyTeleportRecord().actualizeLastUse();
}
public static boolean handlePartyXpGainEvent(Party party, double xpGained) {
public boolean handlePartyXpGainEvent(Party party, double xpGained) {
McMMOPartyXpGainEvent event = new McMMOPartyXpGainEvent(party, xpGained);
pluginRef.getServer().getPluginManager().callEvent(event);
@ -296,7 +300,7 @@ public class EventUtils {
return !isCancelled;
}
public static boolean handlePartyLevelChangeEvent(Party party, int levelsChanged, double xpRemoved) {
public boolean handlePartyLevelChangeEvent(Party party, int levelsChanged, double xpRemoved) {
McMMOPartyLevelUpEvent event = new McMMOPartyLevelUpEvent(party, levelsChanged);
pluginRef.getServer().getPluginManager().callEvent(event);
@ -311,7 +315,7 @@ public class EventUtils {
return !isCancelled;
}
public static boolean handleXpGainEvent(Player player, PrimarySkillType skill, double xpGained, XPGainReason xpGainReason) {
public boolean handleXpGainEvent(Player player, PrimarySkillType skill, double xpGained, XPGainReason xpGainReason) {
McMMOPlayerXpGainEvent event = new McMMOPlayerXpGainEvent(player, skill, xpGained, xpGainReason);
pluginRef.getServer().getPluginManager().callEvent(event);
@ -325,7 +329,7 @@ public class EventUtils {
return !isCancelled;
}
public static boolean handleStatsLossEvent(Player player, HashMap<String, Integer> levelChanged, HashMap<String, Double> experienceChanged) {
public boolean handleStatsLossEvent(Player player, HashMap<String, Integer> levelChanged, HashMap<String, Double> experienceChanged) {
if (UserManager.getPlayer(player) == null)
return true;
@ -359,7 +363,7 @@ public class EventUtils {
return !isCancelled;
}
public static boolean handleVampirismEvent(Player killer, Player victim, HashMap<String, Integer> levelChanged, HashMap<String, Double> experienceChanged) {
public boolean handleVampirismEvent(Player killer, Player victim, HashMap<String, Integer> levelChanged, HashMap<String, Double> experienceChanged) {
McMMOPlayerVampirismEvent eventKiller = new McMMOPlayerVampirismEvent(killer, false, levelChanged, experienceChanged);
McMMOPlayerVampirismEvent eventVictim = new McMMOPlayerVampirismEvent(victim, true, levelChanged, experienceChanged);
pluginRef.getServer().getPluginManager().callEvent(eventKiller);
@ -409,47 +413,47 @@ public class EventUtils {
return !isCancelled;
}
public static void callAbilityDeactivateEvent(Player player, SuperAbilityType ability) {
public void callAbilityDeactivateEvent(Player player, SuperAbilityType ability) {
McMMOPlayerAbilityDeactivateEvent event = new McMMOPlayerAbilityDeactivateEvent(player, PrimarySkillType.byAbility(ability));
pluginRef.getServer().getPluginManager().callEvent(event);
}
public static McMMOPlayerFishingTreasureEvent callFishingTreasureEvent(Player player, ItemStack treasureDrop, int treasureXp, Map<Enchantment, Integer> enchants) {
public McMMOPlayerFishingTreasureEvent callFishingTreasureEvent(Player player, ItemStack treasureDrop, int treasureXp, Map<Enchantment, Integer> enchants) {
McMMOPlayerFishingTreasureEvent event = enchants.isEmpty() ? new McMMOPlayerFishingTreasureEvent(player, treasureDrop, treasureXp) : new McMMOPlayerMagicHunterEvent(player, treasureDrop, treasureXp, enchants);
pluginRef.getServer().getPluginManager().callEvent(event);
return event;
}
public static void callFakeFishEvent(Player player, FishHook hook) {
public void callFakeFishEvent(Player player, FishHook hook) {
FakePlayerFishEvent event = new FakePlayerFishEvent(player, null, hook, PlayerFishEvent.State.FISHING);
pluginRef.getServer().getPluginManager().callEvent(event);
}
public static McMMOPlayerRepairCheckEvent callRepairCheckEvent(Player player, short durability, ItemStack repairMaterial, ItemStack repairedObject) {
public McMMOPlayerRepairCheckEvent callRepairCheckEvent(Player player, short durability, ItemStack repairMaterial, ItemStack repairedObject) {
McMMOPlayerRepairCheckEvent event = new McMMOPlayerRepairCheckEvent(player, durability, repairMaterial, repairedObject);
pluginRef.getServer().getPluginManager().callEvent(event);
return event;
}
public static McMMOPlayerPreDeathPenaltyEvent callPreDeathPenaltyEvent(Player player) {
public McMMOPlayerPreDeathPenaltyEvent callPreDeathPenaltyEvent(Player player) {
McMMOPlayerPreDeathPenaltyEvent event = new McMMOPlayerPreDeathPenaltyEvent(player);
pluginRef.getServer().getPluginManager().callEvent(event);
return event;
}
public static McMMOPlayerDisarmEvent callDisarmEvent(Player defender) {
public McMMOPlayerDisarmEvent callDisarmEvent(Player defender) {
McMMOPlayerDisarmEvent event = new McMMOPlayerDisarmEvent(defender);
pluginRef.getServer().getPluginManager().callEvent(event);
return event;
}
public static McMMOPlayerSalvageCheckEvent callSalvageCheckEvent(Player player, ItemStack salvageMaterial, ItemStack salvageResults, ItemStack enchantedBook) {
public McMMOPlayerSalvageCheckEvent callSalvageCheckEvent(Player player, ItemStack salvageMaterial, ItemStack salvageResults, ItemStack enchantedBook) {
McMMOPlayerSalvageCheckEvent event = new McMMOPlayerSalvageCheckEvent(player, salvageMaterial, salvageResults, enchantedBook);
pluginRef.getServer().getPluginManager().callEvent(event);
@ -463,7 +467,7 @@ public class EventUtils {
* @param textComponent text component used for the message
* @return the McMMOPlayerNotificationEvent after its been fired
*/
public static McMMOPlayerNotificationEvent createAndCallNotificationEvent(Player player, NotificationType notificationType, TextComponent textComponent) {
public McMMOPlayerNotificationEvent createAndCallNotificationEvent(Player player, NotificationType notificationType, TextComponent textComponent) {
//Init event
McMMOPlayerNotificationEvent customEvent = new McMMOPlayerNotificationEvent(notificationType, player, pluginRef.getNotificationManager().getPlayerNotificationSettings(notificationType), textComponent);
@ -479,7 +483,7 @@ public class EventUtils {
* @param message string used for the message
* @return the McMMOPlayerNotificationEvent after its been fired
*/
public static McMMOPlayerNotificationEvent createAndCallNotificationEvent(Player player, NotificationType notificationType, String message) {
public McMMOPlayerNotificationEvent createAndCallNotificationEvent(Player player, NotificationType notificationType, String message) {
//Init event
McMMOPlayerNotificationEvent customEvent = new McMMOPlayerNotificationEvent(notificationType, player, pluginRef.getNotificationManager().getPlayerNotificationSettings(notificationType), message);

View File

@ -59,7 +59,7 @@ public final class HardcoreManager {
totalLevelsLost += levelsLost;
}
if (!EventUtils.handleStatsLossEvent(player, levelChanged, experienceChanged)) {
if (!pluginRef.getEventManager().handleStatsLossEvent(player, levelChanged, experienceChanged)) {
return;
}
@ -114,7 +114,7 @@ public final class HardcoreManager {
totalLevelsStolen += levelsStolen;
}
if (!EventUtils.handleVampirismEvent(killer, victim, levelChanged, experienceChanged)) {
if (!pluginRef.getEventManager().handleVampirismEvent(killer, victim, levelChanged, experienceChanged)) {
return;
}

View File

@ -7,7 +7,7 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.events.skills.McMMOPlayerNotificationEvent;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.EventManager;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.sounds.SoundManager;
@ -67,7 +67,7 @@ public class NotificationManager {
return;
TextComponent textComponent = TextComponentFactory.getNotificationTextComponentFromLocale(key);
McMMOPlayerNotificationEvent customEvent = EventUtils.createAndCallNotificationEvent(player, notificationType, textComponent);
McMMOPlayerNotificationEvent customEvent = pluginRef.getEventManager().createAndCallNotificationEvent(player, notificationType, textComponent);
sendNotification(customEvent);
}
@ -120,7 +120,7 @@ public class NotificationManager {
return;
TextComponent textComponent = buildTextComponent(key, values);
McMMOPlayerNotificationEvent customEvent = EventUtils.createAndCallNotificationEvent(player, notificationType, textComponent);
McMMOPlayerNotificationEvent customEvent = pluginRef.getEventManager().createAndCallNotificationEvent(player, notificationType, textComponent);
sendNotification(customEvent);
}
@ -137,7 +137,7 @@ public class NotificationManager {
return;
TextComponent levelUpTextComponent = TextComponentFactory.getNotificationLevelUpTextComponent(skillName, levelsGained, newLevel);
McMMOPlayerNotificationEvent customEvent = EventUtils.createAndCallNotificationEvent(mcMMOPlayer.getPlayer(), NotificationType.LEVEL_UP_MESSAGE, levelUpTextComponent);
McMMOPlayerNotificationEvent customEvent = pluginRef.getEventManager().createAndCallNotificationEvent(mcMMOPlayer.getPlayer(), NotificationType.LEVEL_UP_MESSAGE, levelUpTextComponent);
sendNotification(customEvent);
}

View File

@ -5,7 +5,7 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillEvent;
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillRandomCheckEvent;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.EventManager;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.SkillActivationType;
import org.bukkit.entity.Player;
@ -35,7 +35,7 @@ public class RandomChanceUtil {
case RANDOM_STATIC_CHANCE:
return checkRandomStaticChanceExecutionSuccess(player, subSkillType);
case ALWAYS_FIRES:
SubSkillEvent event = EventUtils.callSubSkillEvent(player, subSkillType);
SubSkillEvent event = pluginRef.getEventManager().callSubSkillEvent(player, subSkillType);
return !event.isCancelled();
default:
return false;

View File

@ -487,7 +487,7 @@ public final class CombatUtils {
}
LivingEntity livingEntity = (LivingEntity) entity;
EventUtils.callFakeArmSwingEvent(attacker);
pluginRef.getEventManager().callFakeArmSwingEvent(attacker);
switch (type) {
case SWORDS: