Assorted event updates. Created new McMMOPlayerRepairEvent for when a

repair is completed.
This commit is contained in:
GJ 2012-03-26 23:01:51 -04:00
parent 6a8737547f
commit 2d3b01ba34
19 changed files with 143 additions and 85 deletions

View File

@ -18,8 +18,8 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.config.LoadProperties;
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.events.FakeEntityDamageByEntityEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.FakeEntityDamageEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.runnables.GainXp; import com.gmail.nossr50.runnables.GainXp;

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.datatypes;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.config.LoadProperties;
@ -99,4 +100,8 @@ public enum SkillType
public double getXpModifier() { public double getXpModifier() {
return xpModifier; return xpModifier;
} }
public int getSkillLevel(Player player) {
return Users.getProfile(player).getSkillLevel(this);
}
} }

View File

@ -0,0 +1,33 @@
package com.gmail.nossr50.events;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import com.gmail.nossr50.datatypes.SkillType;
public class McMMOPlayerExperienceEvent extends PlayerEvent{
protected SkillType skill;
public McMMOPlayerExperienceEvent(Player player, SkillType skill) {
super(player);
this.skill = skill;
}
public SkillType getSkill() {
return skill;
}
/** 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;
}
}

View File

@ -1,54 +1,24 @@
package com.gmail.nossr50.events; package com.gmail.nossr50.events;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
/** /**
* Called when a user levels up in a skill * Called when a user levels up in a skill
*/ */
public class McMMOPlayerLevelUpEvent extends Event { public class McMMOPlayerLevelUpEvent extends McMMOPlayerExperienceEvent {
private Player player;
private SkillType skill;
private int levelsGained; private int levelsGained;
public McMMOPlayerLevelUpEvent(Player player, SkillType skill) { public McMMOPlayerLevelUpEvent(Player player, SkillType skill) {
this.player = player; super(player, skill);
this.skill = skill;
this.levelsGained = 1; // Always 1 for now as we call in the loop where the levelups are calculated, could change later! this.levelsGained = 1; // Always 1 for now as we call in the loop where the levelups are calculated, could change later!
} }
/**
* @return Player leveling up
*/
public Player getPlayer() {
return player;
}
/**
* @return SkillType that is being leveled up
*/
public SkillType getSkill() {
return skill;
}
/** /**
* @return The number of levels gained in this event * @return The number of levels gained in this event
*/ */
public int getLevelsGained() { public int getLevelsGained() {
return levelsGained; return levelsGained;
} }
/** Rest of file is required boilerplate for custom events **/
private static final HandlerList handlers = new HandlerList();
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
} }

View File

@ -0,0 +1,26 @@
package com.gmail.nossr50.events;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.datatypes.SkillType;
public class McMMOPlayerRepairEvent extends McMMOPlayerSkillEvent{
private ItemStack item;
private short repairAmount;
public McMMOPlayerRepairEvent(Player player, ItemStack item, short repairAmount) {
super(player, SkillType.REPAIR);
this.item = item;
this.repairAmount = repairAmount;
}
public ItemStack getItem() {
return item;
}
public int getRepairAmount() {
return repairAmount;
}
}

View File

@ -0,0 +1,35 @@
package com.gmail.nossr50.events;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import com.gmail.nossr50.datatypes.SkillType;
public class McMMOPlayerSkillEvent extends PlayerEvent{
protected SkillType skill;
protected int skillLevel;
public McMMOPlayerSkillEvent(Player player, SkillType skill) {
super(player);
this.skill = skill;
}
public SkillType getSkill() {
return skill;
}
/** 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;
}
}

View File

@ -1,51 +1,21 @@
package com.gmail.nossr50.events; package com.gmail.nossr50.events;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
public class McMMOPlayerXpGainEvent extends Event { public class McMMOPlayerXpGainEvent extends McMMOPlayerExperienceEvent {
private Player player;
private SkillType skill;
private int xpGained; private int xpGained;
public McMMOPlayerXpGainEvent(Player player, SkillType skill, int xpGained) { public McMMOPlayerXpGainEvent(Player player, SkillType skill, int xpGained) {
this.player = player; super(player, skill);
this.skill = skill;
this.xpGained = xpGained; this.xpGained = xpGained;
} }
/**
* @return Player gaining experience (can be null)
*/
public Player getPlayer() {
return player;
}
/**
* @return SkillType that is gaining experience
*/
public SkillType getSkill() {
return skill;
}
/** /**
* @return The number experience gained in this event * @return The number experience gained in this event
*/ */
public int getXpGained() { public int getXpGained() {
return xpGained; return xpGained;
} }
/** Rest of file is required boilerplate for custom events **/
private static final HandlerList handlers = new HandlerList();
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
} }

View File

@ -1,4 +1,4 @@
package com.gmail.nossr50.events; package com.gmail.nossr50.events.fake;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,9 +1,10 @@
package com.gmail.nossr50.events; package com.gmail.nossr50.events.fake;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
public class FakeEntityDamageByEntityEvent extends EntityDamageByEntityEvent { public class FakeEntityDamageByEntityEvent extends EntityDamageByEntityEvent {
public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, int damage) { public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, int damage) {
super(damager, damagee, cause, damage); super(damager, damagee, cause, damage);
} }

View File

@ -1,4 +1,4 @@
package com.gmail.nossr50.events; package com.gmail.nossr50.events.fake;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;

View File

@ -0,0 +1,12 @@
package com.gmail.nossr50.events.fake;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerAnimationEvent;
public class FakePlayerAnimationEvent extends PlayerAnimationEvent{
public FakePlayerAnimationEvent(Player player) {
super(player);
}
}

View File

@ -18,7 +18,8 @@ import com.gmail.nossr50.skills.Repair;
import com.gmail.nossr50.skills.Skills; import com.gmail.nossr50.skills.Skills;
import com.gmail.nossr50.skills.WoodCutting; import com.gmail.nossr50.skills.WoodCutting;
import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.spout.SpoutSounds;
import com.gmail.nossr50.events.FakeBlockBreakEvent; import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.CropState; import org.bukkit.CropState;
@ -34,7 +35,6 @@ import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
@ -266,7 +266,7 @@ public class mcBlockListener implements Listener {
} }
else if (PP.getBerserkMode() && Skills.triggerCheck(player, block, AbilityType.BERSERK)) { else if (PP.getBerserkMode() && Skills.triggerCheck(player, block, AbilityType.BERSERK)) {
if (inhand.getType().equals(Material.AIR)) { if (inhand.getType().equals(Material.AIR)) {
PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
Bukkit.getPluginManager().callEvent(armswing); Bukkit.getPluginManager().callEvent(armswing);
event.setInstaBreak(true); event.setInstaBreak(true);

View File

@ -30,8 +30,8 @@ import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.config.LoadProperties;
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.events.FakeEntityDamageByEntityEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.FakeEntityDamageEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.runnables.mcBleedTimer; import com.gmail.nossr50.runnables.mcBleedTimer;
import com.gmail.nossr50.skills.Acrobatics; import com.gmail.nossr50.skills.Acrobatics;

View File

@ -9,13 +9,13 @@ import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
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.events.FakeBlockBreakEvent;
import com.gmail.nossr50.events.McMMOItemSpawnEvent; import com.gmail.nossr50.events.McMMOItemSpawnEvent;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
public class m { public class m {
@ -127,7 +127,7 @@ public class m {
//Support for NoCheat //Support for NoCheat
if (shouldArmSwing) { if (shouldArmSwing) {
PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
Bukkit.getPluginManager().callEvent(armswing); Bukkit.getPluginManager().callEvent(armswing);
} }

View File

@ -19,4 +19,4 @@ public class RemoveProfileFromMemoryTask implements Runnable {
Users.removeUserByName(player.getName()); Users.removeUserByName(player.getName());
} }
} }
} }

View File

@ -10,7 +10,6 @@ import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.event.player.PlayerAnimationEvent;
import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.spout.SpoutSounds;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
@ -21,6 +20,7 @@ import com.gmail.nossr50.config.LoadTreasures;
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.datatypes.treasure.ExcavationTreasure; import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import org.getspout.spoutapi.sound.SoundEffect; import org.getspout.spoutapi.sound.SoundEffect;
@ -134,7 +134,7 @@ public class Excavation {
Skills.abilityDurabilityLoss(player.getItemInHand(), LoadProperties.abilityDurabilityLoss); Skills.abilityDurabilityLoss(player.getItemInHand(), LoadProperties.abilityDurabilityLoss);
if (!block.hasMetadata("mcmmoPlacedBlock")) { if (!block.hasMetadata("mcmmoPlacedBlock")) {
PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
Bukkit.getPluginManager().callEvent(armswing); Bukkit.getPluginManager().callEvent(armswing);
Excavation.excavationProcCheck(block, player); Excavation.excavationProcCheck(block, player);

View File

@ -11,7 +11,6 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.getspout.spoutapi.sound.SoundEffect; import org.getspout.spoutapi.sound.SoundEffect;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.player.PlayerAnimationEvent;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.m; import com.gmail.nossr50.m;
@ -20,6 +19,7 @@ import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.spout.SpoutSounds;
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.events.fake.FakePlayerAnimationEvent;
public class Mining { public class Mining {
@ -217,7 +217,7 @@ public class Mining {
Material type = block.getType(); Material type = block.getType();
int tier = m.getTier(player.getItemInHand()); int tier = m.getTier(player.getItemInHand());
int durabilityLoss = LoadProperties.abilityDurabilityLoss; int durabilityLoss = LoadProperties.abilityDurabilityLoss;
PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
switch (type) { switch (type) {
case OBSIDIAN: case OBSIDIAN:

View File

@ -4,6 +4,7 @@ import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
@ -21,6 +22,7 @@ import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.spout.SpoutSounds;
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.events.McMMOPlayerRepairEvent;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
public class Repair { public class Repair {
@ -437,7 +439,11 @@ public class Repair {
addEnchants(player, is); addEnchants(player, is);
} }
is.setDurability(getRepairAmount(is, player)); short repairAmount = getRepairAmount(is, player);
is.setDurability(repairAmount);
McMMOPlayerRepairEvent event = new McMMOPlayerRepairEvent(player, is, repairAmount);
Bukkit.getPluginManager().callEvent(event);
} }
/** /**

View File

@ -10,7 +10,6 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Tree; import org.bukkit.material.Tree;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import com.gmail.nossr50.Combat; import com.gmail.nossr50.Combat;
@ -20,6 +19,7 @@ import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.config.LoadProperties;
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.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.spout.SpoutSounds;
@ -306,7 +306,7 @@ public class WoodCutting {
* @param block Block being broken * @param block Block being broken
*/ */
public static void leafBlower(Player player, Block block) { public static void leafBlower(Player player, Block block) {
PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
Bukkit.getPluginManager().callEvent(armswing); Bukkit.getPluginManager().callEvent(armswing);
if (LoadProperties.woodcuttingrequiresaxe) { if (LoadProperties.woodcuttingrequiresaxe) {