Custom tools - modify XP gain from breaking blocks on a per tool basis.

This commit is contained in:
GJ 2012-05-15 14:21:21 -04:00
parent 29ee8a035b
commit e9af0ebdc5
4 changed files with 28 additions and 2 deletions

View File

@ -9,11 +9,14 @@ import java.util.ArrayList;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent; import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModChecks;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
@ -1027,6 +1030,14 @@ public class PlayerProfile {
xp += trueBonus; xp += trueBonus;
} }
if (Config.getInstance().getToolModsEnabled()) {
ItemStack item = player.getItemInHand();
if (ItemChecks.isCustomTool(item)) {
xp = (int) (xp * ModChecks.getToolFromItemStack(item).getXpMultiplier());
}
}
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp)); mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp));
skillsXp.put(skillType, skillsXp.get(skillType) + xp); skillsXp.put(skillType, skillsXp.get(skillType) + xp);
lastgained = skillType; lastgained = skillType;

View File

@ -381,7 +381,6 @@ public class Combat {
damageAmount = 1; damageAmount = 1;
} }
//TODO: Looking at this, I think it's busted. Need to test to confirm.
for (Entity entity : target.getNearbyEntities(2.5, 2.5, 2.5)) { for (Entity entity : target.getNearbyEntities(2.5, 2.5, 2.5)) {
if (!(entity instanceof LivingEntity)) { if (!(entity instanceof LivingEntity)) {
continue; continue;

View File

@ -22,4 +22,20 @@ public class ModChecks {
return false; return false;
} }
/**
* Get the custom tool associated with an item.
*
* @param item The item to check
* @return the tool if it exists, null otherwise
*/
public static CustomTool getToolFromItemStack(ItemStack item) {
for (CustomTool tool : LoadCustomTools.getInstance().customTools) {
if (tool.getItemID() == item.getTypeId()) {
return tool;
}
}
return null;
}
} }

View File

@ -45,7 +45,7 @@ commands:
aliases: [] aliases: []
description: Make yourself invulnerable description: Make yourself invulnerable
mcstats: mcstats:
aliases: [] aliases: [/stats]
description: Shows your mcMMO stats and xp description: Shows your mcMMO stats and xp
mcremove: mcremove:
aliases: [] aliases: []