diff --git a/src/main/java/com/gmail/nossr50/Combat.java b/src/main/java/com/gmail/nossr50/Combat.java index 9e63281d5..268bfdf62 100644 --- a/src/main/java/com/gmail/nossr50/Combat.java +++ b/src/main/java/com/gmail/nossr50/Combat.java @@ -18,8 +18,8 @@ import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; -import com.gmail.nossr50.events.FakeEntityDamageByEntityEvent; -import com.gmail.nossr50.events.FakeEntityDamageEvent; +import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent; +import com.gmail.nossr50.events.fake.FakeEntityDamageEvent; import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.party.Party; import com.gmail.nossr50.runnables.GainXp; diff --git a/src/main/java/com/gmail/nossr50/datatypes/SkillType.java b/src/main/java/com/gmail/nossr50/datatypes/SkillType.java index ac84cba27..a986bd528 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/SkillType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/SkillType.java @@ -2,6 +2,7 @@ package com.gmail.nossr50.datatypes; import org.bukkit.entity.Player; +import com.gmail.nossr50.Users; import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.config.LoadProperties; @@ -99,4 +100,8 @@ public enum SkillType public double getXpModifier() { return xpModifier; } + + public int getSkillLevel(Player player) { + return Users.getProfile(player).getSkillLevel(this); + } } diff --git a/src/main/java/com/gmail/nossr50/events/McMMOPlayerExperienceEvent.java b/src/main/java/com/gmail/nossr50/events/McMMOPlayerExperienceEvent.java new file mode 100644 index 000000000..4e393161c --- /dev/null +++ b/src/main/java/com/gmail/nossr50/events/McMMOPlayerExperienceEvent.java @@ -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; + } +} diff --git a/src/main/java/com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java b/src/main/java/com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java index 209a34ff1..3c6fbc808 100644 --- a/src/main/java/com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java +++ b/src/main/java/com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java @@ -1,54 +1,24 @@ package com.gmail.nossr50.events; import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; import com.gmail.nossr50.datatypes.SkillType; /** * Called when a user levels up in a skill */ -public class McMMOPlayerLevelUpEvent extends Event { - private Player player; - private SkillType skill; +public class McMMOPlayerLevelUpEvent extends McMMOPlayerExperienceEvent { private int levelsGained; public McMMOPlayerLevelUpEvent(Player player, SkillType skill) { - this.player = player; - this.skill = skill; + super(player, skill); 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 */ public int getLevelsGained() { 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; - } } diff --git a/src/main/java/com/gmail/nossr50/events/McMMOPlayerRepairEvent.java b/src/main/java/com/gmail/nossr50/events/McMMOPlayerRepairEvent.java new file mode 100644 index 000000000..c97367469 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/events/McMMOPlayerRepairEvent.java @@ -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; + } +} diff --git a/src/main/java/com/gmail/nossr50/events/McMMOPlayerSkillEvent.java b/src/main/java/com/gmail/nossr50/events/McMMOPlayerSkillEvent.java new file mode 100644 index 000000000..2fd380e80 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/events/McMMOPlayerSkillEvent.java @@ -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; + } +} + diff --git a/src/main/java/com/gmail/nossr50/events/McMMOPlayerXpGainEvent.java b/src/main/java/com/gmail/nossr50/events/McMMOPlayerXpGainEvent.java index 9b6204ed8..ef0b30fc6 100644 --- a/src/main/java/com/gmail/nossr50/events/McMMOPlayerXpGainEvent.java +++ b/src/main/java/com/gmail/nossr50/events/McMMOPlayerXpGainEvent.java @@ -1,51 +1,21 @@ package com.gmail.nossr50.events; import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; import com.gmail.nossr50.datatypes.SkillType; -public class McMMOPlayerXpGainEvent extends Event { - private Player player; - private SkillType skill; +public class McMMOPlayerXpGainEvent extends McMMOPlayerExperienceEvent { private int xpGained; public McMMOPlayerXpGainEvent(Player player, SkillType skill, int xpGained) { - this.player = player; - this.skill = skill; + super(player, skill); 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 */ public int getXpGained() { 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; - } } diff --git a/src/main/java/com/gmail/nossr50/events/FakeBlockBreakEvent.java b/src/main/java/com/gmail/nossr50/events/fake/FakeBlockBreakEvent.java similarity index 90% rename from src/main/java/com/gmail/nossr50/events/FakeBlockBreakEvent.java rename to src/main/java/com/gmail/nossr50/events/fake/FakeBlockBreakEvent.java index 121b6196c..a182766fa 100644 --- a/src/main/java/com/gmail/nossr50/events/FakeBlockBreakEvent.java +++ b/src/main/java/com/gmail/nossr50/events/fake/FakeBlockBreakEvent.java @@ -1,4 +1,4 @@ -package com.gmail.nossr50.events; +package com.gmail.nossr50.events.fake; import java.util.ArrayList; diff --git a/src/main/java/com/gmail/nossr50/events/FakeEntityDamageByEntityEvent.java b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageByEntityEvent.java similarity index 87% rename from src/main/java/com/gmail/nossr50/events/FakeEntityDamageByEntityEvent.java rename to src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageByEntityEvent.java index bc2749318..1bd2f00ee 100644 --- a/src/main/java/com/gmail/nossr50/events/FakeEntityDamageByEntityEvent.java +++ b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageByEntityEvent.java @@ -1,9 +1,10 @@ -package com.gmail.nossr50.events; +package com.gmail.nossr50.events.fake; import org.bukkit.entity.Entity; import org.bukkit.event.entity.EntityDamageByEntityEvent; public class FakeEntityDamageByEntityEvent extends EntityDamageByEntityEvent { + public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, int damage) { super(damager, damagee, cause, damage); } diff --git a/src/main/java/com/gmail/nossr50/events/FakeEntityDamageEvent.java b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageEvent.java similarity index 87% rename from src/main/java/com/gmail/nossr50/events/FakeEntityDamageEvent.java rename to src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageEvent.java index c47d0c908..1ac79be2d 100644 --- a/src/main/java/com/gmail/nossr50/events/FakeEntityDamageEvent.java +++ b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageEvent.java @@ -1,4 +1,4 @@ -package com.gmail.nossr50.events; +package com.gmail.nossr50.events.fake; import org.bukkit.entity.Entity; import org.bukkit.event.entity.EntityDamageEvent; diff --git a/src/main/java/com/gmail/nossr50/events/fake/FakePlayerAnimationEvent.java b/src/main/java/com/gmail/nossr50/events/fake/FakePlayerAnimationEvent.java new file mode 100644 index 000000000..96f13783f --- /dev/null +++ b/src/main/java/com/gmail/nossr50/events/fake/FakePlayerAnimationEvent.java @@ -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); + } + +} diff --git a/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java b/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java index 3018468f8..f385cf1d7 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java @@ -18,7 +18,8 @@ import com.gmail.nossr50.skills.Repair; import com.gmail.nossr50.skills.Skills; import com.gmail.nossr50.skills.WoodCutting; 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.CropState; @@ -34,7 +35,6 @@ import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.player.PlayerAnimationEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; @@ -266,7 +266,7 @@ public class mcBlockListener implements Listener { } else if (PP.getBerserkMode() && Skills.triggerCheck(player, block, AbilityType.BERSERK)) { if (inhand.getType().equals(Material.AIR)) { - PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); + FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); Bukkit.getPluginManager().callEvent(armswing); event.setInstaBreak(true); diff --git a/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java b/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java index e08f0e2cf..ca5ed6077 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java @@ -30,8 +30,8 @@ import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; -import com.gmail.nossr50.events.FakeEntityDamageByEntityEvent; -import com.gmail.nossr50.events.FakeEntityDamageEvent; +import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent; +import com.gmail.nossr50.events.fake.FakeEntityDamageEvent; import com.gmail.nossr50.party.Party; import com.gmail.nossr50.runnables.mcBleedTimer; import com.gmail.nossr50.skills.Acrobatics; diff --git a/src/main/java/com/gmail/nossr50/m.java b/src/main/java/com/gmail/nossr50/m.java index 23d4202e1..574a89e0d 100644 --- a/src/main/java/com/gmail/nossr50/m.java +++ b/src/main/java/com/gmail/nossr50/m.java @@ -9,13 +9,13 @@ import org.bukkit.block.Block; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerAnimationEvent; import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; -import com.gmail.nossr50.events.FakeBlockBreakEvent; import com.gmail.nossr50.events.McMMOItemSpawnEvent; +import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; +import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; public class m { @@ -127,7 +127,7 @@ public class m { //Support for NoCheat if (shouldArmSwing) { - PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); + FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); Bukkit.getPluginManager().callEvent(armswing); } diff --git a/src/main/java/com/gmail/nossr50/runnables/RemoveProfileFromMemoryTask.java b/src/main/java/com/gmail/nossr50/runnables/RemoveProfileFromMemoryTask.java index c84ccfe5c..feb7065de 100644 --- a/src/main/java/com/gmail/nossr50/runnables/RemoveProfileFromMemoryTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/RemoveProfileFromMemoryTask.java @@ -19,4 +19,4 @@ public class RemoveProfileFromMemoryTask implements Runnable { Users.removeUserByName(player.getName()); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/gmail/nossr50/skills/Excavation.java b/src/main/java/com/gmail/nossr50/skills/Excavation.java index 25c0b8796..7c45a6242 100644 --- a/src/main/java/com/gmail/nossr50/skills/Excavation.java +++ b/src/main/java/com/gmail/nossr50/skills/Excavation.java @@ -10,7 +10,6 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.event.player.PlayerAnimationEvent; import com.gmail.nossr50.spout.SpoutSounds; 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.SkillType; import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure; +import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import org.getspout.spoutapi.sound.SoundEffect; @@ -134,7 +134,7 @@ public class Excavation { Skills.abilityDurabilityLoss(player.getItemInHand(), LoadProperties.abilityDurabilityLoss); if (!block.hasMetadata("mcmmoPlacedBlock")) { - PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); + FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); Bukkit.getPluginManager().callEvent(armswing); Excavation.excavationProcCheck(block, player); diff --git a/src/main/java/com/gmail/nossr50/skills/Mining.java b/src/main/java/com/gmail/nossr50/skills/Mining.java index 4a5db4bce..5fc96bd13 100644 --- a/src/main/java/com/gmail/nossr50/skills/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/Mining.java @@ -11,7 +11,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.getspout.spoutapi.sound.SoundEffect; import org.bukkit.enchantments.Enchantment; -import org.bukkit.event.player.PlayerAnimationEvent; import com.gmail.nossr50.Users; 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.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; public class Mining { @@ -217,7 +217,7 @@ public class Mining { Material type = block.getType(); int tier = m.getTier(player.getItemInHand()); int durabilityLoss = LoadProperties.abilityDurabilityLoss; - PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); + FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); switch (type) { case OBSIDIAN: diff --git a/src/main/java/com/gmail/nossr50/skills/Repair.java b/src/main/java/com/gmail/nossr50/skills/Repair.java index ce04e65b2..bebb2a1f7 100644 --- a/src/main/java/com/gmail/nossr50/skills/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/Repair.java @@ -4,6 +4,7 @@ import java.util.Map; import java.util.Random; import java.util.Map.Entry; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; 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.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.events.McMMOPlayerRepairEvent; import com.gmail.nossr50.locale.mcLocale; public class Repair { @@ -437,7 +439,11 @@ public class Repair { 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); } /** diff --git a/src/main/java/com/gmail/nossr50/skills/WoodCutting.java b/src/main/java/com/gmail/nossr50/skills/WoodCutting.java index 9266b62d8..fed66bb97 100644 --- a/src/main/java/com/gmail/nossr50/skills/WoodCutting.java +++ b/src/main/java/com/gmail/nossr50/skills/WoodCutting.java @@ -10,7 +10,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.material.Tree; import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.player.PlayerAnimationEvent; import org.bukkit.Bukkit; import com.gmail.nossr50.Combat; @@ -20,6 +19,7 @@ import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.spout.SpoutSounds; @@ -306,7 +306,7 @@ public class WoodCutting { * @param block Block being broken */ public static void leafBlower(Player player, Block block) { - PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); + FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); Bukkit.getPluginManager().callEvent(armswing); if (LoadProperties.woodcuttingrequiresaxe) {