Event updates

This commit is contained in:
GJ 2013-10-18 08:31:00 -04:00
parent 3f56a8fbcf
commit b8c1f868f5
21 changed files with 219 additions and 185 deletions

View File

@ -2,10 +2,9 @@ package com.gmail.nossr50.commands.experience;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class AddlevelsCommand extends ExperienceCommand { public class AddlevelsCommand extends ExperienceCommand {
@ -21,11 +20,14 @@ public class AddlevelsCommand extends ExperienceCommand {
@Override @Override
protected void handleCommand(SkillType skill) { protected void handleCommand(SkillType skill) {
float xpRemoved = profile.getSkillXpLevelRaw(skill);
profile.addLevels(skill, value); profile.addLevels(skill, value);
if (player != null) { if (player == null) {
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelUpEvent(player, skill, value)); return;
} }
EventUtils.handleLevelChangeEvent(player, skill, value, xpRemoved, true);
} }
@Override @Override

View File

@ -2,11 +2,9 @@ package com.gmail.nossr50.commands.experience;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelDownEvent;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class MmoeditCommand extends ExperienceCommand { public class MmoeditCommand extends ExperienceCommand {
@ -22,20 +20,16 @@ public class MmoeditCommand extends ExperienceCommand {
@Override @Override
protected void handleCommand(SkillType skill) { protected void handleCommand(SkillType skill) {
int skillLevel = profile.getSkillLevel(skill);
float xpRemoved = profile.getSkillXpLevelRaw(skill);
profile.modifySkill(skill, value); profile.modifySkill(skill, value);
if (player == null) { if (player == null || value == skillLevel) {
return; return;
} }
int skillLevel = profile.getSkillLevel(skill); EventUtils.handleLevelChangeEvent(player, skill, value, xpRemoved, value > skillLevel);
if (value > skillLevel) {
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelUpEvent(player, skill, value - skillLevel));
}
else if (value < skillLevel) {
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelDownEvent(player, skill, skillLevel - value));
}
} }
@Override @Override

View File

@ -6,8 +6,8 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelDownEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
@ -102,11 +102,16 @@ public class SkillresetCommand extends ExperienceCommand {
return; return;
} }
int levelsRemoved = profile.getSkillLevel(skill);
float xpRemoved = profile.getSkillXpLevelRaw(skill);
profile.modifySkill(skill, 0); profile.modifySkill(skill, 0);
if (player != null) { if (player == null) {
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelDownEvent(player, skill, profile.getSkillLevel(skill))); return;
} }
EventUtils.handleLevelChangeEvent(player, skill, levelsRemoved, xpRemoved, false);
} }
@Override @Override

View File

@ -14,10 +14,10 @@ import org.bukkit.util.StringUtil;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.items.TeleportationWarmup; import com.gmail.nossr50.runnables.items.TeleportationWarmup;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
@ -177,25 +177,7 @@ public class PtpCommand implements TabExecutor {
new TeleportationWarmup(mcMMOPlayer, mcMMOTarget).runTaskLater(mcMMO.p, 20 * warmup); new TeleportationWarmup(mcMMOPlayer, mcMMOTarget).runTaskLater(mcMMO.p, 20 * warmup);
} }
else { else {
handlePartyTeleportEvent(teleportingPlayer, targetPlayer); EventUtils.handlePartyTeleportEvent(teleportingPlayer, targetPlayer);
} }
} }
public static void handlePartyTeleportEvent(Player teleportingPlayer, Player targetPlayer) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(teleportingPlayer);
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(teleportingPlayer, targetPlayer, mcMMOPlayer.getParty().getName());
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
teleportingPlayer.teleport(targetPlayer);
teleportingPlayer.sendMessage(LocaleLoader.getString("Party.Teleport.Player", targetPlayer.getName()));
targetPlayer.sendMessage(LocaleLoader.getString("Party.Teleport.Target", teleportingPlayer.getName()));
mcMMOPlayer.actualizePtpLastUse();
}
} }

View File

@ -22,7 +22,6 @@ import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType; import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.party.ShareHandler; import com.gmail.nossr50.party.ShareHandler;
@ -593,15 +592,10 @@ public class McMMOPlayer {
return; return;
} }
McMMOPlayerXpGainEvent event = new McMMOPlayerXpGainEvent(player, skillType, xp); if (!EventUtils.handleXpGainEvent(player, skillType, xp)) {
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return; return;
} }
profile.setSkillXpLevel(skillType, profile.getSkillXpLevelRaw(skillType) + event.getRawXpGained());
isUsingUnarmed = (skillType == SkillType.UNARMED); isUsingUnarmed = (skillType == SkillType.UNARMED);
checkXp(skillType); checkXp(skillType);
} }
@ -626,13 +620,11 @@ public class McMMOPlayer {
profile.skillUp(skillType, 1); profile.skillUp(skillType, 1);
} }
else { else {
profile.addLevels(skillType, 0); profile.addLevels(skillType, 0); // This seems kinda pointless... why do we have this again?
} }
} }
if (EventUtils.callLevelUpEvent(player, skillType, levelsGained).isCancelled()) { if (!EventUtils.handleLevelChangeEvent(player, skillType, levelsGained, xpRemoved, true)) {
profile.modifySkill(skillType, profile.getSkillLevel(skillType) - levelsGained);
profile.setSkillXpLevel(skillType, profile.getSkillXpLevelRaw(skillType) + xpRemoved);
return; return;
} }

View File

@ -3,28 +3,16 @@ package com.gmail.nossr50.events.skills.abilities;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
public class McMMOPlayerAbilityActivateEvent extends McMMOPlayerSkillEvent implements Cancellable { public class McMMOPlayerAbilityActivateEvent extends McMMOPlayerAbilityEvent implements Cancellable {
private AbilityType abilityType;
private boolean cancelled; private boolean cancelled;
public McMMOPlayerAbilityActivateEvent(Player player, SkillType skill) { public McMMOPlayerAbilityActivateEvent(Player player, SkillType skill) {
super(player, skill); super(player, skill);
abilityType = skill.getAbility();
cancelled = false; cancelled = false;
} }
/**
* @return The ability type involved in this event
*/
public AbilityType getAbilityType() {
return abilityType;
}
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return cancelled;
} }

View File

@ -2,21 +2,10 @@ package com.gmail.nossr50.events.skills.abilities;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
public class McMMOPlayerAbilityDeactivateEvent extends McMMOPlayerSkillEvent {
private AbilityType ability;
public class McMMOPlayerAbilityDeactivateEvent extends McMMOPlayerAbilityEvent {
public McMMOPlayerAbilityDeactivateEvent(Player player, SkillType skill) { public McMMOPlayerAbilityDeactivateEvent(Player player, SkillType skill) {
super(player, skill); super(player, skill);
this.ability = skill.getAbility();
} }
public AbilityType getAbility() {
return ability;
}
} }

View File

@ -0,0 +1,20 @@
package com.gmail.nossr50.events.skills.abilities;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
public class McMMOPlayerAbilityEvent extends McMMOPlayerSkillEvent {
private AbilityType ability;
protected McMMOPlayerAbilityEvent(Player player, SkillType skill) {
super(player, skill);
ability = skill.getAbility();
}
public AbilityType getAbility() {
return ability;
}
}

View File

@ -0,0 +1,24 @@
package com.gmail.nossr50.events.skills.fishing;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
public class McMMOPlayerFishingEvent extends McMMOPlayerSkillEvent implements Cancellable {
private boolean cancelled;
protected McMMOPlayerFishingEvent(Player player) {
super(player, SkillType.FISHING);
cancelled = false;
}
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean newValue) {
this.cancelled = newValue;
}
}

View File

@ -1,20 +1,14 @@
package com.gmail.nossr50.events.skills.fishing; package com.gmail.nossr50.events.skills.fishing;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.datatypes.skills.SkillType; public class McMMOPlayerFishingTreasureEvent extends McMMOPlayerFishingEvent {
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
public class McMMOPlayerFishingTreasureEvent extends McMMOPlayerSkillEvent implements Cancellable {
private boolean cancelled = false;
private ItemStack treasure; private ItemStack treasure;
private int xp; private int xp;
public McMMOPlayerFishingTreasureEvent(Player player, ItemStack treasure, int xp) { public McMMOPlayerFishingTreasureEvent(Player player, ItemStack treasure, int xp) {
super(player, SkillType.FISHING); super(player);
this.treasure = treasure; this.treasure = treasure;
this.xp = xp; this.xp = xp;
} }
@ -27,14 +21,6 @@ public class McMMOPlayerFishingTreasureEvent extends McMMOPlayerSkillEvent imple
this.treasure = item; this.treasure = item;
} }
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean newValue) {
this.cancelled = newValue;
}
public int getXp() { public int getXp() {
return xp; return xp;
} }

View File

@ -7,7 +7,6 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class McMMOPlayerMagicHunterEvent extends McMMOPlayerFishingTreasureEvent { public class McMMOPlayerMagicHunterEvent extends McMMOPlayerFishingTreasureEvent {
private Map<Enchantment, Integer> enchants; private Map<Enchantment, Integer> enchants;
public McMMOPlayerMagicHunterEvent(Player player, ItemStack treasure, int xp, Map<Enchantment, Integer> enchants) { public McMMOPlayerMagicHunterEvent(Player player, ItemStack treasure, int xp, Map<Enchantment, Integer> enchants) {

View File

@ -1,30 +1,16 @@
package com.gmail.nossr50.events.skills.fishing; package com.gmail.nossr50.events.skills.fishing;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.datatypes.skills.SkillType; public class McMMOPlayerShakeEvent extends McMMOPlayerFishingEvent {
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
public class McMMOPlayerShakeEvent extends McMMOPlayerSkillEvent implements Cancellable {
private boolean cancelled = false;
private ItemStack drop; private ItemStack drop;
public McMMOPlayerShakeEvent(Player player, ItemStack drop) { public McMMOPlayerShakeEvent(Player player, ItemStack drop) {
super(player, SkillType.FISHING); super(player);
this.drop = drop; this.drop = drop;
} }
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean newValue) {
this.cancelled = newValue;
}
public ItemStack getDrop() { public ItemStack getDrop() {
return drop; return drop;
} }
@ -32,5 +18,4 @@ public class McMMOPlayerShakeEvent extends McMMOPlayerSkillEvent implements Canc
public void setDrop(ItemStack drop) { public void setDrop(ItemStack drop) {
this.drop = drop; this.drop = drop;
} }
} }

View File

@ -4,11 +4,11 @@ import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.commands.party.teleport.PtpCommand;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
@ -58,6 +58,6 @@ public class TeleportationWarmup extends BukkitRunnable {
} }
} }
PtpCommand.handlePartyTeleportEvent(teleportingPlayer, targetPlayer); EventUtils.handlePartyTeleportEvent(teleportingPlayer, targetPlayer);
} }
} }

View File

@ -7,8 +7,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.HiddenConfig; import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.skills.ParticleEffectUtils; import com.gmail.nossr50.util.skills.ParticleEffectUtils;
import com.gmail.nossr50.util.skills.PerksUtils; import com.gmail.nossr50.util.skills.PerksUtils;
@ -47,8 +46,7 @@ public class AbilityDisableTask extends BukkitRunnable {
break; break;
} }
McMMOPlayerAbilityDeactivateEvent event = new McMMOPlayerAbilityDeactivateEvent(player, SkillType.byAbility(ability)); EventUtils.callAbilityDeactivateEvent(player, ability);
mcMMO.p.getServer().getPluginManager().callEvent(event);
mcMMOPlayer.setAbilityMode(ability, false); mcMMOPlayer.setAbilityMode(ability, false);
mcMMOPlayer.setAbilityInformed(ability, false); mcMMOPlayer.setAbilityInformed(ability, false);

View File

@ -28,7 +28,6 @@ import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.ThrownPotion; import org.bukkit.entity.ThrownPotion;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Wool; import org.bukkit.material.Wool;
@ -47,16 +46,14 @@ import com.gmail.nossr50.datatypes.treasure.EnchantmentTreasure;
import com.gmail.nossr50.datatypes.treasure.FishingTreasure; import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
import com.gmail.nossr50.datatypes.treasure.Rarity; import com.gmail.nossr50.datatypes.treasure.Rarity;
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure; import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakePlayerFishEvent;
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent; import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent;
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerMagicHunterEvent;
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerShakeEvent; import com.gmail.nossr50.events.skills.fishing.McMMOPlayerShakeEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.skills.KrakenAttackTask; import com.gmail.nossr50.runnables.skills.KrakenAttackTask;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.fishing.Fishing.Tier; import com.gmail.nossr50.skills.fishing.Fishing.Tier;
import com.gmail.nossr50.util.BlockUtils; import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.ItemUtils; import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@ -211,10 +208,7 @@ public class FishingManager extends SkillManager {
return false; return false;
} }
FakeBlockBreakEvent blockBreakEvent = new FakeBlockBreakEvent(block, player); return EventUtils.simulateBlockBreak(block, player, false);
mcMMO.p.getServer().getPluginManager().callEvent(blockBreakEvent);
return !blockBreakEvent.isCancelled();
} }
/** /**
@ -278,7 +272,7 @@ public class FishingManager extends SkillManager {
} }
// Recast in the new spot // Recast in the new spot
mcMMO.p.getServer().getPluginManager().callEvent(new FakePlayerFishEvent(getPlayer(), null, hook, PlayerFishEvent.State.FISHING)); EventUtils.callFakeFishEvent(getPlayer(), hook);
} }
public void masterAngler(Fish hook) { public void masterAngler(Fish hook) {
@ -316,26 +310,20 @@ public class FishingManager extends SkillManager {
if (treasure != null) { if (treasure != null) {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.ItemFound")); player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.ItemFound"));
treasureXp = treasure.getXp();
ItemStack treasureDrop = treasure.getDrop().clone(); // Not cloning is bad, m'kay? ItemStack treasureDrop = treasure.getDrop().clone(); // Not cloning is bad, m'kay?
McMMOPlayerFishingTreasureEvent event;
Map<Enchantment, Integer> enchants = new HashMap<Enchantment, Integer>(); Map<Enchantment, Integer> enchants = new HashMap<Enchantment, Integer>();
if (Permissions.magicHunter(player) && ItemUtils.isEnchantable(treasureDrop)) { if (Permissions.magicHunter(player) && ItemUtils.isEnchantable(treasureDrop)) {
enchants = handleMagicHunter(treasureDrop); enchants = handleMagicHunter(treasureDrop);
event = new McMMOPlayerMagicHunterEvent(player, treasureDrop, treasureXp, enchants);
}
else {
event = new McMMOPlayerFishingTreasureEvent(player, treasureDrop, treasureXp);
} }
mcMMO.p.getServer().getPluginManager().callEvent(event); McMMOPlayerFishingTreasureEvent event = EventUtils.callFishingTreasureEvent(player, treasureDrop, treasure.getXp(), enchants);
if (!event.isCancelled()) {
treasureDrop = event.getTreasure(); treasureDrop = event.getTreasure();
treasureXp = event.getXp(); treasureXp = event.getXp();
}
if (event.isCancelled()) { else {
treasureDrop = null; treasureDrop = null;
treasureXp = 0; treasureXp = 0;
} }
@ -353,7 +341,6 @@ public class FishingManager extends SkillManager {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.MagicFound")); player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.MagicFound"));
} }
// Misc.dropItem(player.getEyeLocation(), fishingCatch.getItemStack());
fishingCatch.setItemStack(treasureDrop); fishingCatch.setItemStack(treasureDrop);
} }
} }

View File

@ -16,7 +16,6 @@ import org.bukkit.material.CocoaPlant.CocoaPlantSize;
import org.bukkit.material.Crops; import org.bukkit.material.Crops;
import org.bukkit.material.NetherWarts; import org.bukkit.material.NetherWarts;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.experience.ExperienceConfig;
@ -31,6 +30,7 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.skills.HerbalismBlockUpdaterTask; import com.gmail.nossr50.runnables.skills.HerbalismBlockUpdaterTask;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.BlockUtils; import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModUtils; import com.gmail.nossr50.util.ModUtils;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@ -229,21 +229,16 @@ public class HerbalismManager extends SkillManager {
return false; return false;
} }
if (treasures.isEmpty()) { Player player = getPlayer();
return false;
}
FakeBlockBreakEvent blockBreakEvent = new FakeBlockBreakEvent(blockState.getBlock(), getPlayer()); if (treasures.isEmpty() || EventUtils.simulateBlockBreak(blockState.getBlock(), player, false)) {
mcMMO.p.getServer().getPluginManager().callEvent(blockBreakEvent);
if (blockBreakEvent.isCancelled()) {
return false; return false;
} }
blockState.setType(Material.AIR); blockState.setType(Material.AIR);
Misc.dropItem(blockState.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop()); Misc.dropItem(blockState.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
getPlayer().sendMessage(LocaleLoader.getString("Herbalism.HylianLuck")); player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
return true; return true;
} }

View File

@ -17,11 +17,11 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.repair.ArcaneForging.Tier; import com.gmail.nossr50.skills.repair.ArcaneForging.Tier;
import com.gmail.nossr50.skills.repair.repairables.Repairable; import com.gmail.nossr50.skills.repair.repairables.Repairable;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
@ -116,10 +116,7 @@ public class RepairManager extends SkillManager {
short newDurability = repairCalculate(startDurability, baseRepairAmount); // When I asked for sons? short newDurability = repairCalculate(startDurability, baseRepairAmount); // When I asked for sons?
// Call event // Call event
McMMOPlayerRepairCheckEvent event = new McMMOPlayerRepairCheckEvent(player, (short) (startDurability - newDurability), toRemove, item); if (EventUtils.callRepairCheckEvent(player, (short) (startDurability - newDurability), toRemove, item).isCancelled()) {
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return; return;
} }

View File

@ -8,14 +8,13 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
import org.bukkit.material.SmoothBrick; import org.bukkit.material.SmoothBrick;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType; import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.events.skills.unarmed.McMMOPlayerDisarmEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.CombatUtils;
@ -83,17 +82,16 @@ public class UnarmedManager extends SkillManager {
*/ */
public void disarmCheck(Player defender) { public void disarmCheck(Player defender) {
if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Unarmed.disarmMaxChance, Unarmed.disarmMaxBonusLevel) && !hasIronGrip(defender)) { if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Unarmed.disarmMaxChance, Unarmed.disarmMaxBonusLevel) && !hasIronGrip(defender)) {
McMMOPlayerDisarmEvent disarmEvent = new McMMOPlayerDisarmEvent(defender); if (EventUtils.callDisarmEvent(defender).isCancelled()) {
mcMMO.p.getServer().getPluginManager().callEvent(disarmEvent); return;
}
if (!disarmEvent.isCancelled()) {
Misc.dropItem(defender.getLocation(), defender.getItemInHand()); Misc.dropItem(defender.getLocation(), defender.getItemInHand());
defender.setItemInHand(new ItemStack(Material.AIR)); defender.setItemInHand(new ItemStack(Material.AIR));
defender.sendMessage(LocaleLoader.getString("Skills.Disarmed")); defender.sendMessage(LocaleLoader.getString("Skills.Disarmed"));
} }
} }
}
/** /**
* Check for arrow deflection. * Check for arrow deflection.

View File

@ -1,16 +1,38 @@
package com.gmail.nossr50.util; package com.gmail.nossr50.util;
import java.util.Map;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Fish;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelChangeEvent;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelDownEvent;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent; import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent; import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.events.fake.FakePlayerFishEvent;
import com.gmail.nossr50.events.hardcore.McMMOPlayerDeathPenaltyEvent;
import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent; import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent;
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent;
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerMagicHunterEvent;
import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent;
import com.gmail.nossr50.events.skills.unarmed.McMMOPlayerDisarmEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.player.UserManager;
public class EventUtils { public class EventUtils {
public static McMMOPlayerAbilityActivateEvent callPlayerAbilityActivateEvent(Player player, SkillType skill) { public static McMMOPlayerAbilityActivateEvent callPlayerAbilityActivateEvent(Player player, SkillType skill) {
@ -27,11 +49,20 @@ public class EventUtils {
return event; return event;
} }
public static McMMOPlayerLevelUpEvent callLevelUpEvent(Player player, SkillType skill, int levelsGained) { public static boolean handleLevelChangeEvent(Player player, SkillType skill, int levelsChanged, float xpRemoved, boolean isLevelUp) {
McMMOPlayerLevelUpEvent event = new McMMOPlayerLevelUpEvent(player, skill, levelsGained); McMMOPlayerLevelChangeEvent event = isLevelUp ? new McMMOPlayerLevelUpEvent(player, skill, levelsChanged) : new McMMOPlayerLevelDownEvent(player, skill, levelsChanged);
mcMMO.p.getServer().getPluginManager().callEvent(event); mcMMO.p.getServer().getPluginManager().callEvent(event);
return event; boolean isCancelled = event.isCancelled();
if (isCancelled) {
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
profile.modifySkill(skill, profile.getSkillLevel(skill) - (isLevelUp ? levelsChanged : - levelsChanged));
profile.setSkillXpLevel(skill, profile.getSkillXpLevelRaw(skill) + xpRemoved);
}
return !isCancelled;
} }
/** /**
@ -58,5 +89,78 @@ public class EventUtils {
return !damageEvent.isCancelled() && !breakEvent.isCancelled(); return !damageEvent.isCancelled() && !breakEvent.isCancelled();
} }
}
public static void handlePartyTeleportEvent(Player teleportingPlayer, Player targetPlayer) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(teleportingPlayer);
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(teleportingPlayer, targetPlayer, mcMMOPlayer.getParty().getName());
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
teleportingPlayer.teleport(targetPlayer);
teleportingPlayer.sendMessage(LocaleLoader.getString("Party.Teleport.Player", targetPlayer.getName()));
targetPlayer.sendMessage(LocaleLoader.getString("Party.Teleport.Target", teleportingPlayer.getName()));
mcMMOPlayer.actualizePtpLastUse();
}
public static boolean handleXpGainEvent(Player player, SkillType skill, float xpGained) {
McMMOPlayerXpGainEvent event = new McMMOPlayerXpGainEvent(player, skill, xpGained);
mcMMO.p.getServer().getPluginManager().callEvent(event);
boolean isCancelled = event.isCancelled();
if (!isCancelled) {
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
profile.setSkillXpLevel(skill, profile.getSkillXpLevelRaw(skill) + event.getRawXpGained());
}
return isCancelled;
}
public static McMMOPlayerAbilityDeactivateEvent callAbilityDeactivateEvent(Player player, AbilityType ability) {
McMMOPlayerAbilityDeactivateEvent event = new McMMOPlayerAbilityDeactivateEvent(player, SkillType.byAbility(ability));
mcMMO.p.getServer().getPluginManager().callEvent(event);
return event;
}
public static 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);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return event;
}
public static FakePlayerFishEvent callFakeFishEvent(Player player, Fish hook) {
FakePlayerFishEvent event = new FakePlayerFishEvent(player, null, hook, PlayerFishEvent.State.FISHING);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return event;
}
public static McMMOPlayerRepairCheckEvent callRepairCheckEvent(Player player, short durability, ItemStack repairMaterial, ItemStack repairedObject) {
McMMOPlayerRepairCheckEvent event = new McMMOPlayerRepairCheckEvent(player, durability, repairMaterial, repairedObject);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return event;
}
public static McMMOPlayerDeathPenaltyEvent callDeathPenaltyEvent(Player player) {
McMMOPlayerDeathPenaltyEvent event = new McMMOPlayerDeathPenaltyEvent(player);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return event;
}
public static McMMOPlayerDisarmEvent callDisarmEvent(Player defender) {
McMMOPlayerDisarmEvent event = new McMMOPlayerDisarmEvent(defender);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return event;
}
}

View File

@ -2,11 +2,9 @@ package com.gmail.nossr50.util;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.hardcore.McMMOPlayerDeathPenaltyEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
@ -16,10 +14,7 @@ public final class HardcoreManager {
public static void invokeStatPenalty(Player player) { public static void invokeStatPenalty(Player player) {
double statLossPercentage = Config.getInstance().getHardcoreDeathStatPenaltyPercentage(); double statLossPercentage = Config.getInstance().getHardcoreDeathStatPenaltyPercentage();
McMMOPlayerDeathPenaltyEvent eventToFire = new McMMOPlayerDeathPenaltyEvent(player); if (EventUtils.callDeathPenaltyEvent(player).isCancelled()) {
mcMMO.p.getServer().getPluginManager().callEvent(eventToFire);
if (eventToFire.isCancelled()) {
return; return;
} }
@ -45,10 +40,7 @@ public final class HardcoreManager {
public static void invokeVampirism(Player killer, Player victim) { public static void invokeVampirism(Player killer, Player victim) {
double vampirismStatLeechPercentage = Config.getInstance().getHardcoreVampirismStatLeechPercentage(); double vampirismStatLeechPercentage = Config.getInstance().getHardcoreVampirismStatLeechPercentage();
McMMOPlayerDeathPenaltyEvent eventToFire = new McMMOPlayerDeathPenaltyEvent(victim); if (EventUtils.callDeathPenaltyEvent(victim).isCancelled()) {
mcMMO.p.getServer().getPluginManager().callEvent(eventToFire);
if (eventToFire.isCancelled()) {
return; return;
} }

View File

@ -24,7 +24,6 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.skills.AwardCombatXpTask; import com.gmail.nossr50.runnables.skills.AwardCombatXpTask;
@ -36,6 +35,7 @@ import com.gmail.nossr50.skills.swords.Swords;
import com.gmail.nossr50.skills.swords.SwordsManager; import com.gmail.nossr50.skills.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.UnarmedManager; import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.ItemUtils; import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.MobHealthbarUtils; import com.gmail.nossr50.util.MobHealthbarUtils;
@ -415,7 +415,7 @@ public final class CombatUtils {
} }
LivingEntity livingEntity = (LivingEntity) entity; LivingEntity livingEntity = (LivingEntity) entity;
mcMMO.p.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(attacker)); EventUtils.callFakeArmSwingEvent(attacker);
switch (type) { switch (type) {
case SWORDS: case SWORDS:
@ -543,7 +543,7 @@ public final class CombatUtils {
* @param entity The defending Entity * @param entity The defending Entity
* @return true if the Entity should be damaged, false otherwise. * @return true if the Entity should be damaged, false otherwise.
*/ */
public static boolean shouldBeAffected(Player player, Entity entity) { private static boolean shouldBeAffected(Player player, Entity entity) {
if (entity instanceof Player) { if (entity instanceof Player) {
Player defender = (Player) entity; Player defender = (Player) entity;
@ -556,10 +556,7 @@ public final class CombatUtils {
} }
// It may seem a bit redundant but we need a check here to prevent bleed from being applied in applyAbilityAoE() // It may seem a bit redundant but we need a check here to prevent bleed from being applied in applyAbilityAoE()
EntityDamageEvent ede = new FakeEntityDamageByEntityEvent(player, entity, EntityDamageEvent.DamageCause.ENTITY_ATTACK, 1); if (callFakeDamageEvent(player, entity, 1.0) == 0) {
mcMMO.p.getServer().getPluginManager().callEvent(ede);
if (ede.isCancelled()) {
return false; return false;
} }
} }
@ -617,11 +614,11 @@ public final class CombatUtils {
return (target instanceof Player || (target instanceof Tameable && ((Tameable) target).isTamed())) ? skill.getPVPEnabled() : skill.getPVEEnabled(); return (target instanceof Player || (target instanceof Tameable && ((Tameable) target).isTamed())) ? skill.getPVPEnabled() : skill.getPVEEnabled();
} }
public static double callFakeDamageEvent(LivingEntity attacker, LivingEntity target, double damage) { public static double callFakeDamageEvent(Entity attacker, Entity target, double damage) {
return callFakeDamageEvent(attacker, target, DamageCause.ENTITY_ATTACK, damage); return callFakeDamageEvent(attacker, target, DamageCause.ENTITY_ATTACK, damage);
} }
public static double callFakeDamageEvent(Entity attacker, LivingEntity target, DamageCause cause, double damage) { public static double callFakeDamageEvent(Entity attacker, Entity target, DamageCause cause, double damage) {
if (Config.getInstance().getEventCallbackEnabled()) { if (Config.getInstance().getEventCallbackEnabled()) {
EntityDamageEvent damageEvent = attacker == null ? new FakeEntityDamageEvent(target, cause, damage) : new FakeEntityDamageByEntityEvent(attacker, target, cause, damage); EntityDamageEvent damageEvent = attacker == null ? new FakeEntityDamageEvent(target, cause, damage) : new FakeEntityDamageByEntityEvent(attacker, target, cause, damage);
mcMMO.p.getServer().getPluginManager().callEvent(damageEvent); mcMMO.p.getServer().getPluginManager().callEvent(damageEvent);