mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-01-18 16:35:25 +01:00
Added McMMOPlayerPreDeathPenaltyEvent and McMMOPlayerStatLossEvent
McMMOPlayerPreDeathPenaltyEvent is fired before hardcore calculations take place, use this if you want to cancel hardcore penalties. Use McMMOPlayerVampirismEvent and McMMOPlayerStatLossEvent when you want to know how many levels or experience the player lost or if you want to modify this.
This commit is contained in:
parent
809779e508
commit
f10a1d0ffb
@ -20,6 +20,7 @@ Version 1.5.01-dev
|
||||
+ Added options to tools.yml and armor.yml config files to set a pretty repair material name
|
||||
+ Added full support for repairables in tools.yml and armor.yml config files
|
||||
+ Added new API class SkillAPI used to get a list of valid skill names
|
||||
+ Added new API events for hardcore features, McMMOPlayerPreDeathPenaltyEvent, McMMOPlayerStatLossEvent and McMMOPlayerVampirismEvent
|
||||
+ Added magical mod config file import command, for Cauldron 1.7+. Check wiki for usage
|
||||
= Fixed bug where pistons would mess with the block tracking
|
||||
= Fixed bug where the Updater was running on the main thread.
|
||||
@ -47,6 +48,7 @@ Version 1.5.01-dev
|
||||
! Changed Alchemy XP distribution. XP is granted based on the stage of the potion.
|
||||
! Changed behavior of the Blast Mining ability "Demolition Expert"; now only decreases damage for the ability user
|
||||
! Updated for new getOnlinePlayers() behavior
|
||||
! Changed McMMOPlayerDeathPenaltyEvent to get fired after hardcore penalty calculations, use McMMOPlayerPreDeathPenaltyEvent for old behavior
|
||||
- Removed salvage ability from Repair, salvage has it's own (child) skill now
|
||||
|
||||
Version 1.5.00
|
||||
|
@ -214,6 +214,16 @@ public class PlayerProfile {
|
||||
skillsXp.put(skill, skillsXp.get(skill) - xp);
|
||||
}
|
||||
|
||||
public void removeXp(SkillType skill, float xp) {
|
||||
if (skill.isChildSkill()) {
|
||||
return;
|
||||
}
|
||||
|
||||
changed = true;
|
||||
|
||||
skillsXp.put(skill, skillsXp.get(skill) - xp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify a skill level.
|
||||
*
|
||||
|
@ -1,25 +1,45 @@
|
||||
package com.gmail.nossr50.events.hardcore;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
|
||||
public class McMMOPlayerDeathPenaltyEvent extends PlayerEvent implements Cancellable {
|
||||
private SkillType skill;
|
||||
private HashMap<String, Integer> levelChanged;
|
||||
private HashMap<String, Float> experienceChanged;
|
||||
|
||||
private boolean cancelled;
|
||||
|
||||
public McMMOPlayerDeathPenaltyEvent(Player player, HashMap<String, Integer> levelChanged, HashMap<String, Float> experienceChanged) {
|
||||
super(player);
|
||||
this.levelChanged = levelChanged;
|
||||
this.experienceChanged = experienceChanged;
|
||||
this.cancelled = false;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public McMMOPlayerDeathPenaltyEvent(Player player) {
|
||||
super(player);
|
||||
this.cancelled = false;
|
||||
}
|
||||
|
||||
public McMMOPlayerDeathPenaltyEvent(Player player, SkillType skill) {
|
||||
super(player);
|
||||
this.skill = skill;
|
||||
this.cancelled = false;
|
||||
public HashMap<String, Integer> getLevelChanged() {
|
||||
return levelChanged;
|
||||
}
|
||||
|
||||
public void setLevelChanged(HashMap<String, Integer> levelChanged) {
|
||||
this.levelChanged = levelChanged;
|
||||
}
|
||||
|
||||
public HashMap<String, Float> getExperienceChanged() {
|
||||
return experienceChanged;
|
||||
}
|
||||
|
||||
public void setExperienceChanged(HashMap<String, Float> experienceChanged) {
|
||||
this.experienceChanged = experienceChanged;
|
||||
}
|
||||
|
||||
/** Following are required for Cancellable **/
|
||||
@ -44,8 +64,4 @@ public class McMMOPlayerDeathPenaltyEvent extends PlayerEvent implements Cancell
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public SkillType getSkill() {
|
||||
return skill;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package com.gmail.nossr50.events.hardcore;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
public class McMMOPlayerPreDeathPenaltyEvent extends PlayerEvent implements Cancellable {
|
||||
private boolean cancelled;
|
||||
|
||||
public McMMOPlayerPreDeathPenaltyEvent(Player player) {
|
||||
super(player);
|
||||
this.cancelled = false;
|
||||
}
|
||||
|
||||
/** Following are required for Cancellable **/
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
/** Rest of file is required boilerplate for custom events **/
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.gmail.nossr50.events.hardcore;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class McMMOPlayerStatLossEvent extends McMMOPlayerDeathPenaltyEvent {
|
||||
|
||||
public McMMOPlayerStatLossEvent(Player player, HashMap<String, Integer> levelChanged, HashMap<String, Float> experienceChanged) {
|
||||
super(player, levelChanged, experienceChanged);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.gmail.nossr50.events.hardcore;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class McMMOPlayerVampirismEvent extends McMMOPlayerDeathPenaltyEvent {
|
||||
private boolean isVictim;
|
||||
|
||||
public McMMOPlayerVampirismEvent(Player player, boolean isVictim, HashMap<String, Integer> levelChanged, HashMap<String, Float> experienceChanged) {
|
||||
super(player, levelChanged, experienceChanged);
|
||||
this.isVictim = isVictim;
|
||||
}
|
||||
|
||||
public boolean isVictim() {
|
||||
return isVictim;
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.gmail.nossr50.events.hardcore;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
|
||||
public class McMMOPlayerVampirismPenaltyEvent extends McMMOPlayerDeathPenaltyEvent {
|
||||
private int levelChanged;
|
||||
private float experienceChanged;
|
||||
|
||||
public McMMOPlayerVampirismPenaltyEvent(Player player, SkillType skill, int levelChanged, float experienceChanged) {
|
||||
super(player, skill);
|
||||
this.levelChanged = levelChanged;
|
||||
this.experienceChanged = experienceChanged;
|
||||
}
|
||||
|
||||
public int getLevelChanged() {
|
||||
return levelChanged;
|
||||
}
|
||||
|
||||
public void setLevelChanged(int levelChanged) {
|
||||
this.levelChanged = levelChanged;
|
||||
}
|
||||
|
||||
public float getExperienceChanged() {
|
||||
return experienceChanged;
|
||||
}
|
||||
|
||||
public void setExperienceChanged(float experienceChanged) {
|
||||
this.experienceChanged = experienceChanged;
|
||||
}
|
||||
}
|
@ -141,7 +141,7 @@ public class PlayerListener implements Listener {
|
||||
Player killer = killedPlayer.getKiller();
|
||||
|
||||
if (statLossEnabled || (killer != null && vampirismEnabled)) {
|
||||
if (EventUtils.callDeathPenaltyEvent(killedPlayer, null).isCancelled()) {
|
||||
if (EventUtils.callPreDeathPenaltyEvent(killedPlayer).isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
@ -27,8 +28,9 @@ import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
|
||||
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
|
||||
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.hardcore.McMMOPlayerVampirismPenaltyEvent;
|
||||
import com.gmail.nossr50.events.hardcore.McMMOPlayerPreDeathPenaltyEvent;
|
||||
import com.gmail.nossr50.events.hardcore.McMMOPlayerStatLossEvent;
|
||||
import com.gmail.nossr50.events.hardcore.McMMOPlayerVampirismEvent;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyLevelUpEvent;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyXpGainEvent;
|
||||
@ -164,32 +166,72 @@ public class EventUtils {
|
||||
return !isCancelled;
|
||||
}
|
||||
|
||||
public static boolean handleVampirismEvent(Player killer, Player victim, SkillType skillType, int levelsStolen, int xpStolen) {
|
||||
McMMOPlayerVampirismPenaltyEvent eventKiller = new McMMOPlayerVampirismPenaltyEvent(killer, skillType, levelsStolen, xpStolen);
|
||||
McMMOPlayerVampirismPenaltyEvent eventVictim = new McMMOPlayerVampirismPenaltyEvent(victim, skillType, -levelsStolen, -xpStolen);
|
||||
public static boolean handleStatsLossEvent(Player player, HashMap<String, Integer> levelChanged, HashMap<String, Float> experienceChanged) {
|
||||
McMMOPlayerStatLossEvent event = new McMMOPlayerStatLossEvent(player, levelChanged, experienceChanged);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
boolean isCancelled = event.isCancelled();
|
||||
|
||||
if (!isCancelled) {
|
||||
levelChanged = event.getLevelChanged();
|
||||
experienceChanged = event.getExperienceChanged();
|
||||
PlayerProfile playerProfile = UserManager.getPlayer(player).getProfile();
|
||||
|
||||
for (SkillType skillType : SkillType.NON_CHILD_SKILLS) {
|
||||
String skillName = skillType.toString();
|
||||
int playerSkillLevel = playerProfile.getSkillLevel(skillType);
|
||||
|
||||
playerProfile.modifySkill(skillType, playerSkillLevel - levelChanged.get(skillName));
|
||||
playerProfile.removeXp(skillType, experienceChanged.get(skillName));
|
||||
|
||||
if (playerProfile.getSkillXpLevel(skillType) < 0) {
|
||||
playerProfile.setSkillXpLevel(skillType, 0);
|
||||
}
|
||||
|
||||
if (playerProfile.getSkillLevel(skillType) < 0) {
|
||||
playerProfile.modifySkill(skillType, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !isCancelled;
|
||||
}
|
||||
|
||||
public static boolean handleVampirismEvent(Player killer, Player victim, HashMap<String, Integer> levelChanged, HashMap<String, Float> experienceChanged) {
|
||||
McMMOPlayerVampirismEvent eventKiller = new McMMOPlayerVampirismEvent(killer, false, levelChanged, experienceChanged);
|
||||
McMMOPlayerVampirismEvent eventVictim = new McMMOPlayerVampirismEvent(victim, true, levelChanged, experienceChanged);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(eventKiller);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(eventVictim);
|
||||
|
||||
boolean isCancelled = eventKiller.isCancelled() || eventVictim.isCancelled();
|
||||
|
||||
if (!isCancelled) {
|
||||
HashMap<String, Integer> levelChangedKiller = eventKiller.getLevelChanged();
|
||||
HashMap<String, Float> experienceChangedKiller = eventKiller.getExperienceChanged();
|
||||
|
||||
HashMap<String, Integer> levelChangedVictim = eventVictim.getLevelChanged();
|
||||
HashMap<String, Float> experienceChangedVictim = eventVictim.getExperienceChanged();
|
||||
|
||||
McMMOPlayer killerPlayer = UserManager.getPlayer(killer);
|
||||
PlayerProfile victimProfile = UserManager.getPlayer(victim).getProfile();
|
||||
int victimSkillLevel = victimProfile.getSkillLevel(skillType);
|
||||
|
||||
killerPlayer.addLevels(skillType, eventKiller.getLevelChanged());
|
||||
killerPlayer.beginUnsharedXpGain(skillType, eventKiller.getExperienceChanged(), XPGainReason.VAMPIRISM);
|
||||
for (SkillType skillType : SkillType.NON_CHILD_SKILLS) {
|
||||
String skillName = skillType.toString();
|
||||
int victimSkillLevel = victimProfile.getSkillLevel(skillType);
|
||||
|
||||
// For victims McMMOPlayerVampirismPenaltyEvent is fired with negative levels changed and XP changed
|
||||
victimProfile.modifySkill(skillType, victimSkillLevel + eventVictim.getLevelChanged());
|
||||
victimProfile.removeXp(skillType, (int) - eventVictim.getExperienceChanged());
|
||||
killerPlayer.addLevels(skillType, levelChangedKiller.get(skillName));
|
||||
killerPlayer.beginUnsharedXpGain(skillType, experienceChangedKiller.get(skillName), XPGainReason.VAMPIRISM);
|
||||
|
||||
if (victimProfile.getSkillXpLevel(skillType) < 0) {
|
||||
victimProfile.setSkillXpLevel(skillType, 0);
|
||||
}
|
||||
victimProfile.modifySkill(skillType, victimSkillLevel - levelChangedVictim.get(skillName));
|
||||
victimProfile.removeXp(skillType, experienceChangedVictim.get(skillName));
|
||||
|
||||
if (victimProfile.getSkillLevel(skillType) < 0) {
|
||||
victimProfile.modifySkill(skillType, 0);
|
||||
if (victimProfile.getSkillXpLevel(skillType) < 0) {
|
||||
victimProfile.setSkillXpLevel(skillType, 0);
|
||||
}
|
||||
|
||||
if (victimProfile.getSkillLevel(skillType) < 0) {
|
||||
victimProfile.modifySkill(skillType, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,8 +266,8 @@ public class EventUtils {
|
||||
return event;
|
||||
}
|
||||
|
||||
public static McMMOPlayerDeathPenaltyEvent callDeathPenaltyEvent(Player player, SkillType skill) {
|
||||
McMMOPlayerDeathPenaltyEvent event = new McMMOPlayerDeathPenaltyEvent(player, skill);
|
||||
public static McMMOPlayerPreDeathPenaltyEvent callPreDeathPenaltyEvent(Player player) {
|
||||
McMMOPlayerPreDeathPenaltyEvent event = new McMMOPlayerPreDeathPenaltyEvent(player);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
return event;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
@ -18,6 +20,9 @@ public final class HardcoreManager {
|
||||
PlayerProfile playerProfile = UserManager.getPlayer(player).getProfile();
|
||||
int totalLevelsLost = 0;
|
||||
|
||||
HashMap<String, Integer> levelChanged = new HashMap<String, Integer>();
|
||||
HashMap<String, Float> experienceChanged = new HashMap<String, Float>();
|
||||
|
||||
for (SkillType skillType : SkillType.NON_CHILD_SKILLS) {
|
||||
if (!skillType.getHardcoreStatLossEnabled()) {
|
||||
break;
|
||||
@ -33,19 +38,14 @@ public final class HardcoreManager {
|
||||
double statsLost = playerSkillLevel * (statLossPercentage * 0.01D);
|
||||
int levelsLost = (int) statsLost;
|
||||
int xpLost = (int) Math.floor(playerSkillXpLevel * (statsLost - levelsLost));
|
||||
levelChanged.put(skillType.toString(), levelsLost);
|
||||
experienceChanged.put(skillType.toString(), (float) xpLost);
|
||||
|
||||
totalLevelsLost += levelsLost;
|
||||
}
|
||||
|
||||
playerProfile.modifySkill(skillType, playerSkillLevel - levelsLost);
|
||||
playerProfile.removeXp(skillType, xpLost);
|
||||
|
||||
if (playerProfile.getSkillXpLevel(skillType) < 0) {
|
||||
playerProfile.setSkillXpLevel(skillType, 0);
|
||||
}
|
||||
|
||||
if (playerProfile.getSkillLevel(skillType) < 0) {
|
||||
playerProfile.modifySkill(skillType, 0);
|
||||
}
|
||||
if (!EventUtils.handleStatsLossEvent(player, levelChanged, experienceChanged)) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Hardcore.DeathStatLoss.PlayerDeath", totalLevelsLost));
|
||||
@ -59,6 +59,9 @@ public final class HardcoreManager {
|
||||
PlayerProfile victimProfile = UserManager.getPlayer(victim).getProfile();
|
||||
int totalLevelsStolen = 0;
|
||||
|
||||
HashMap<String, Integer> levelChanged = new HashMap<String, Integer>();
|
||||
HashMap<String, Float> experienceChanged = new HashMap<String, Float>();
|
||||
|
||||
for (SkillType skillType : SkillType.NON_CHILD_SKILLS) {
|
||||
if (!skillType.getHardcoreVampirismEnabled()) {
|
||||
break;
|
||||
@ -76,10 +79,14 @@ public final class HardcoreManager {
|
||||
double statsStolen = victimSkillLevel * (vampirismStatLeechPercentage * 0.01D);
|
||||
int levelsStolen = (int) statsStolen;
|
||||
int xpStolen = (int) Math.floor(victimSkillXpLevel * (statsStolen - levelsStolen));
|
||||
levelChanged.put(skillType.toString(), levelsStolen);
|
||||
experienceChanged.put(skillType.toString(), (float) xpStolen);
|
||||
|
||||
if (EventUtils.handleVampirismEvent(killer, victim, skillType, levelsStolen, xpStolen)) {
|
||||
totalLevelsStolen += levelsStolen;
|
||||
}
|
||||
totalLevelsStolen += levelsStolen;
|
||||
}
|
||||
|
||||
if (!EventUtils.handleVampirismEvent(killer, victim, levelChanged, experienceChanged)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (totalLevelsStolen > 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user