From 725056d88da8bce021d827be099345b8b6a40421 Mon Sep 17 00:00:00 2001 From: NuclearW Date: Fri, 27 Jan 2012 21:37:41 -0500 Subject: [PATCH 1/7] Update version and fix compilation issues --- src/main/java/com/gmail/nossr50/skills/Repair.java | 6 +++--- src/main/resources/plugin.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/Repair.java b/src/main/java/com/gmail/nossr50/skills/Repair.java index 19fc55137..acd026bab 100644 --- a/src/main/java/com/gmail/nossr50/skills/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/Repair.java @@ -315,7 +315,7 @@ public class Repair { if(rank == 0) { - if(LoadProperties.mayLoseEnchants()) + if(LoadProperties.mayLoseEnchants) { player.sendMessage(mcLocale.getString("Repair.LostEnchants")); for(Enchantment x : enchants) @@ -328,7 +328,7 @@ public class Repair { boolean failure = false, downgrade = false; - if(LoadProperties.mayLoseEnchants()) + if(LoadProperties.mayLoseEnchants) { for(Enchantment x : enchants) { @@ -341,7 +341,7 @@ public class Repair { { if(enchantsLvl[pos] > 1) { - if(LoadProperties.mayDowngradeEnchants()) + if(LoadProperties.mayDowngradeEnchants) { if(Math.random() * 100 <= getDowngradeChance(rank)) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ba0c9f067..6ea4b0ba8 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: mcMMO main: com.gmail.nossr50.mcMMO -version: 1.2.08 +version: 1.2.08-dev softdepend: [Spout] author: TheYeti description: mcMMO takes core Minecraft game mechanics and expands them to add an extensive RPG experience, the goal of the project has always been a quality RPG experience. Everything in mcMMO is carefully thought out and is constantly improving. mcMMO adds eleven skills to train in and level in, while also offering a high level of customization for server admins. There are countless features, including custom sounds, graphical elements, and more added when running mcMMO in conjunction with Spout. I carefully read feedback and evaluate the mechanics of mcMMO in every update to provide an ever-evolving experience. From 7c60217882159645455a7cc161188bcf1b6f930f Mon Sep 17 00:00:00 2001 From: NuclearW Date: Fri, 27 Jan 2012 21:43:56 -0500 Subject: [PATCH 2/7] Update version and fix compilation issues --- src/main/java/com/gmail/nossr50/skills/Repair.java | 6 +++--- src/main/resources/plugin.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/Repair.java b/src/main/java/com/gmail/nossr50/skills/Repair.java index 19fc55137..acd026bab 100644 --- a/src/main/java/com/gmail/nossr50/skills/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/Repair.java @@ -315,7 +315,7 @@ public class Repair { if(rank == 0) { - if(LoadProperties.mayLoseEnchants()) + if(LoadProperties.mayLoseEnchants) { player.sendMessage(mcLocale.getString("Repair.LostEnchants")); for(Enchantment x : enchants) @@ -328,7 +328,7 @@ public class Repair { boolean failure = false, downgrade = false; - if(LoadProperties.mayLoseEnchants()) + if(LoadProperties.mayLoseEnchants) { for(Enchantment x : enchants) { @@ -341,7 +341,7 @@ public class Repair { { if(enchantsLvl[pos] > 1) { - if(LoadProperties.mayDowngradeEnchants()) + if(LoadProperties.mayDowngradeEnchants) { if(Math.random() * 100 <= getDowngradeChance(rank)) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ba0c9f067..56d786bb7 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: mcMMO main: com.gmail.nossr50.mcMMO -version: 1.2.08 +version: 1.2.09-dev softdepend: [Spout] author: TheYeti description: mcMMO takes core Minecraft game mechanics and expands them to add an extensive RPG experience, the goal of the project has always been a quality RPG experience. Everything in mcMMO is carefully thought out and is constantly improving. mcMMO adds eleven skills to train in and level in, while also offering a high level of customization for server admins. There are countless features, including custom sounds, graphical elements, and more added when running mcMMO in conjunction with Spout. I carefully read feedback and evaluate the mechanics of mcMMO in every update to provide an ever-evolving experience. From 299f440f637b05e243d2e72810475d8f9d488a65 Mon Sep 17 00:00:00 2001 From: NuclearW Date: Sat, 28 Jan 2012 01:24:29 -0500 Subject: [PATCH 3/7] Change damage to use events system Should provide a fix for issue #39 Also update pom and removed an unused import. --- pom.xml | 2 +- src/main/java/com/gmail/nossr50/Combat.java | 46 +++++++++++++++---- .../com/gmail/nossr50/runnables/mcTimer.java | 3 +- .../java/com/gmail/nossr50/skills/Axes.java | 5 +- .../com/gmail/nossr50/skills/Fishing.java | 3 +- .../java/com/gmail/nossr50/skills/Swords.java | 10 ++-- .../java/com/gmail/nossr50/skills/Taming.java | 1 - 7 files changed, 49 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index b645a2101..1ad8b4594 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.gmail.nossr50.mcMMO mcMMO - 1.2.08 + 1.2.09-dev mcMMO https://github.com/TheYeti/mcMMO diff --git a/src/main/java/com/gmail/nossr50/Combat.java b/src/main/java/com/gmail/nossr50/Combat.java index f41f7da0a..38e182d08 100644 --- a/src/main/java/com/gmail/nossr50/Combat.java +++ b/src/main/java/com/gmail/nossr50/Combat.java @@ -16,6 +16,7 @@ */ package com.gmail.nossr50; +import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.*; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -352,17 +353,42 @@ public class Combat Skills.XpCheckSkill(SkillType.ARCHERY, attacker); } } - public static void dealDamage(Entity target, int dmg){ - if(target instanceof Player){ - ((Player) target).damage(dmg); - } - if(target instanceof Animals){ - ((Animals) target).damage(dmg); - } - if(target instanceof Monster){ - ((Monster) target).damage(dmg); - } + + /** + * Attempt to damage target for value dmg with reason CUSTOM + * + * @param target LivingEntity which to attempt to damage + * @param dmg Amount of damage to attempt to do + */ + public static void dealDamage(LivingEntity target, int dmg){ + EntityDamageEvent ede = new EntityDamageEvent(target, EntityDamageEvent.DamageCause.CUSTOM, dmg); + Bukkit.getPluginManager().callEvent(ede); } + + /** + * Attempt to damage target for value dmg with reason cause + * + * @param target LivingEntity which to attempt to damage + * @param dmg Amount of damage to attempt to do + * @param cause DamageCause to pass to damage event + */ + public static void dealDamage(LivingEntity target, int dmg, DamageCause cause) { + EntityDamageEvent ede = new EntityDamageEvent(target, cause, dmg); + Bukkit.getPluginManager().callEvent(ede); + } + + /** + * Attempt to damage target for value dmg with reason ENTITY_ATTACK with damager attacker + * + * @param target LivingEntity which to attempt to damage + * @param dmg Amount of damage to attempt to do + * @param attacker Player to pass to event as damager + */ + public static void dealDamage(LivingEntity target, int dmg, Player attacker) { + EntityDamageEvent ede = new EntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.ENTITY_ATTACK, dmg); + Bukkit.getPluginManager().callEvent(ede); + } + public static boolean pvpAllowed(EntityDamageByEntityEvent event, World world) { if(!event.getEntity().getWorld().getPVP()) diff --git a/src/main/java/com/gmail/nossr50/runnables/mcTimer.java b/src/main/java/com/gmail/nossr50/runnables/mcTimer.java index 6b41db742..78572c228 100644 --- a/src/main/java/com/gmail/nossr50/runnables/mcTimer.java +++ b/src/main/java/com/gmail/nossr50/runnables/mcTimer.java @@ -17,6 +17,7 @@ package com.gmail.nossr50.runnables; import org.bukkit.entity.*; +import com.gmail.nossr50.Combat; import com.gmail.nossr50.Users; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.PlayerProfile; @@ -60,7 +61,7 @@ public class mcTimer implements Runnable */ if(thecount % 2 == 0 && PP.getBleedTicks() >= 1) { - player.damage(2); + Combat.dealDamage(player, 2); PP.decreaseBleedTicks(); } diff --git a/src/main/java/com/gmail/nossr50/skills/Axes.java b/src/main/java/com/gmail/nossr50/skills/Axes.java index 3561cb178..4c0e0e601 100644 --- a/src/main/java/com/gmail/nossr50/skills/Axes.java +++ b/src/main/java/com/gmail/nossr50/skills/Axes.java @@ -25,6 +25,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.plugin.Plugin; import com.gmail.nossr50.locale.mcLocale; +import com.gmail.nossr50.Combat; import com.gmail.nossr50.Users; import com.gmail.nossr50.m; import com.gmail.nossr50.mcPermissions; @@ -152,7 +153,7 @@ public class Axes { continue; if(targets >= 1 && derp.getWorld().getPVP()) { - target.damage(event.getDamage() / 2); + Combat.dealDamage(target, event.getDamage() / 2, attacker); target.sendMessage(ChatColor.DARK_RED+"Struck by CLEAVE!"); targets--; continue; @@ -161,7 +162,7 @@ public class Axes { else { LivingEntity target = (LivingEntity)derp; - target.damage(event.getDamage() / 2); + Combat.dealDamage(target, event.getDamage() / 2, attacker); targets--; } } diff --git a/src/main/java/com/gmail/nossr50/skills/Fishing.java b/src/main/java/com/gmail/nossr50/skills/Fishing.java index 9249e0617..46c5adff1 100644 --- a/src/main/java/com/gmail/nossr50/skills/Fishing.java +++ b/src/main/java/com/gmail/nossr50/skills/Fishing.java @@ -9,6 +9,7 @@ import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.material.Wool; +import com.gmail.nossr50.Combat; import com.gmail.nossr50.Users; import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; @@ -671,7 +672,7 @@ public class Fishing { if(le instanceof Player) return; - le.damage(1); + Combat.dealDamage(le, 1, event.getPlayer()); World world = le.getWorld(); /* Neutral Mobs */ diff --git a/src/main/java/com/gmail/nossr50/skills/Swords.java b/src/main/java/com/gmail/nossr50/skills/Swords.java index 204f98363..dec6ab17c 100644 --- a/src/main/java/com/gmail/nossr50/skills/Swords.java +++ b/src/main/java/com/gmail/nossr50/skills/Swords.java @@ -151,7 +151,7 @@ public class Swords continue; if(targets >= 1 && derp.getWorld().getPVP()) { - target.damage(event.getDamage() / 4); + Combat.dealDamage(target, event.getDamage() / 4, attacker); target.sendMessage(ChatColor.DARK_RED+"Struck by Serrated Strikes!"); Users.getProfile(target).addBleedTicks(5); targets--; @@ -164,7 +164,7 @@ public class Swords pluginx.misc.addToBleedQue((LivingEntity)derp); LivingEntity target = (LivingEntity)derp; - target.damage(event.getDamage() / 4); + Combat.dealDamage(target, event.getDamage() / 4, attacker); targets--; } } @@ -193,7 +193,7 @@ public class Swords { if(Math.random() * 2000 <= 600) { - Combat.dealDamage(f, event.getDamage() / 2); + Combat.dealDamage((LivingEntity) f, event.getDamage() / 2); defender.sendMessage(ChatColor.GREEN+"**COUNTER-ATTACKED**"); if(f instanceof Player) ((Player) f).sendMessage(ChatColor.DARK_RED+"Hit with counterattack!"); @@ -201,7 +201,7 @@ public class Swords } else if (Math.random() * 2000 <= PPd.getSkillLevel(SkillType.SWORDS)) { - Combat.dealDamage(f, event.getDamage() / 2); + Combat.dealDamage((LivingEntity) f, event.getDamage() / 2); defender.sendMessage(ChatColor.GREEN+"**COUNTER-ATTACKED**"); if(f instanceof Player) ((Player) f).sendMessage(ChatColor.DARK_RED+"Hit with counterattack!"); @@ -245,7 +245,7 @@ public class Swords } else { - x.damage(2); + Combat.dealDamage(x, 2); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/Taming.java b/src/main/java/com/gmail/nossr50/skills/Taming.java index 66b976709..cdafab982 100644 --- a/src/main/java/com/gmail/nossr50/skills/Taming.java +++ b/src/main/java/com/gmail/nossr50/skills/Taming.java @@ -16,7 +16,6 @@ */ package com.gmail.nossr50.skills; -import org.bukkit.craftbukkit.CraftOfflinePlayer; import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; From 23354ce04991a0601d3fc211ed8ea0901cb13aaf Mon Sep 17 00:00:00 2001 From: NuclearW Date: Sat, 28 Jan 2012 02:00:18 -0500 Subject: [PATCH 4/7] New custom event McMMOPlayerLevelUpEvent --- .../events/McMMOPlayerLevelUpEvent.java | 55 +++++++++++++++++++ .../java/com/gmail/nossr50/skills/Skills.java | 5 ++ 2 files changed, 60 insertions(+) create mode 100644 src/main/java/com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java diff --git a/src/main/java/com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java b/src/main/java/com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java new file mode 100644 index 000000000..222780a17 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java @@ -0,0 +1,55 @@ +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 + */ +@SuppressWarnings("serial") +public class McMMOPlayerLevelUpEvent extends Event { + private Player player; + private SkillType skill; + private int levelsGained; + + public McMMOPlayerLevelUpEvent(Player player, SkillType skill) { + this.player = player; + this.skill = 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 handers = new HandlerList(); + + public HandlerList getHandlers() { + return handers; + } + + public static HandlerList getHandlerList() { + return handers; + } +} diff --git a/src/main/java/com/gmail/nossr50/skills/Skills.java b/src/main/java/com/gmail/nossr50/skills/Skills.java index b8dd5db30..6f0bc2755 100644 --- a/src/main/java/com/gmail/nossr50/skills/Skills.java +++ b/src/main/java/com/gmail/nossr50/skills/Skills.java @@ -18,6 +18,7 @@ package com.gmail.nossr50.skills; import java.util.logging.Logger; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -35,6 +36,7 @@ import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerStat; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.events.McMMOPlayerLevelUpEvent; import com.gmail.nossr50.locale.mcLocale; @@ -326,6 +328,9 @@ public class Skills skillups++; PP.removeXP(skillType, PP.getXpToLevel(skillType)); PP.skillUp(skillType, 1); + + McMMOPlayerLevelUpEvent eventToFire = new McMMOPlayerLevelUpEvent(player, skillType); + Bukkit.getPluginManager().callEvent(eventToFire); } if(!LoadProperties.useMySQL) From fded7cad96b6ee04e3b027f66c8750e72d08fa88 Mon Sep 17 00:00:00 2001 From: NuclearW Date: Sat, 28 Jan 2012 02:35:20 -0500 Subject: [PATCH 5/7] Fix typo Stop programming at late night --- .../com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java b/src/main/java/com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java index 222780a17..0483125c2 100644 --- a/src/main/java/com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java +++ b/src/main/java/com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java @@ -43,13 +43,13 @@ public class McMMOPlayerLevelUpEvent extends Event { } /** Rest of file is required boilerplate for custom events **/ - private static final HandlerList handers = new HandlerList(); + private static final HandlerList handlers = new HandlerList(); public HandlerList getHandlers() { - return handers; + return handlers; } public static HandlerList getHandlerList() { - return handers; + return handlers; } } From 42ddf648b1151231ebfd96698f05dc55ccfea015 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Sat, 28 Jan 2012 12:44:49 -0500 Subject: [PATCH 6/7] Possible fix for [Issue #53] --- src/main/java/com/gmail/nossr50/skills/Repair.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/skills/Repair.java b/src/main/java/com/gmail/nossr50/skills/Repair.java index acd026bab..cffbddb27 100644 --- a/src/main/java/com/gmail/nossr50/skills/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/Repair.java @@ -192,7 +192,7 @@ public class Repair { removeItem(player, rIron); repairItem(player, enchants, enchantsLevel); - durabilityAfter = (short) (player.getItemInHand().getDurability()-getRepairAmount(is, player)); + durabilityAfter = (short) (player.getItemInHand().getDurability(); dif = (short) (durabilityBefore - durabilityAfter); if(m.isShovel(is)) dif = (short) (dif / 3); From c8869c86bec01a2c03895bf1b472287e44663a12 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Sat, 28 Jan 2012 19:41:39 -0500 Subject: [PATCH 7/7] Fix typo. --- src/main/java/com/gmail/nossr50/skills/Repair.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/skills/Repair.java b/src/main/java/com/gmail/nossr50/skills/Repair.java index cffbddb27..dbb9c067f 100644 --- a/src/main/java/com/gmail/nossr50/skills/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/Repair.java @@ -192,7 +192,7 @@ public class Repair { removeItem(player, rIron); repairItem(player, enchants, enchantsLevel); - durabilityAfter = (short) (player.getItemInHand().getDurability(); + durabilityAfter = player.getItemInHand().getDurability(); dif = (short) (durabilityBefore - durabilityAfter); if(m.isShovel(is)) dif = (short) (dif / 3);