瀏覽代碼

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

GJ 13 年之前
父節點
當前提交
e9af0ebdc5

+ 11 - 0
src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java

@@ -9,11 +9,14 @@ import java.util.ArrayList;
 
 import org.bukkit.GameMode;
 import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
 
 import com.gmail.nossr50.config.Config;
 import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
 import com.gmail.nossr50.party.Party;
+import com.gmail.nossr50.util.ItemChecks;
 import com.gmail.nossr50.util.Misc;
+import com.gmail.nossr50.util.ModChecks;
 import com.gmail.nossr50.util.Users;
 import com.gmail.nossr50.mcMMO;
 
@@ -1027,6 +1030,14 @@ public class PlayerProfile {
             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));
         skillsXp.put(skillType, skillsXp.get(skillType) + xp);
         lastgained = skillType;

+ 0 - 1
src/main/java/com/gmail/nossr50/util/Combat.java

@@ -381,7 +381,6 @@ public class Combat {
             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)) {
             if (!(entity instanceof LivingEntity)) {
                 continue;

+ 16 - 0
src/main/java/com/gmail/nossr50/util/ModChecks.java

@@ -22,4 +22,20 @@ public class ModChecks {
 
         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;
+    }
 }

+ 1 - 1
src/main/resources/plugin.yml

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