Added mcMMO woodcutting XP support

This commit is contained in:
Esophose 2019-02-10 21:50:07 -07:00
parent 6c788c216e
commit 69d7a665f4
5 changed files with 71 additions and 2 deletions

View File

@ -15,6 +15,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.songoda.ultimatetimber.commands.CommandHandler;
import com.songoda.ultimatetimber.configurations.DefaultConfig;
import com.songoda.ultimatetimber.hooks.McMMOHook;
import com.songoda.ultimatetimber.treefall.CustomLoot;
import com.songoda.ultimatetimber.treefall.TreeFallAnimation;
import com.songoda.ultimatetimber.treefall.TreeFallListener;
@ -74,6 +75,12 @@ public class UltimateTimber extends JavaPlugin {
*/
this.reloadValidWorlds();
/*
Check for McMMO
*/
if (Bukkit.getPluginManager().isPluginEnabled("mcMMO"))
McMMOHook.setEnabled();
/*
Register command executor and tab completer
*/

View File

@ -0,0 +1,58 @@
package com.songoda.ultimatetimber.hooks;
import java.util.ArrayList;
import java.util.HashSet;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import com.gmail.nossr50.api.ExperienceAPI;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.util.player.UserManager;
import com.songoda.ultimatetimber.utils.WoodToLogConverter;
public class McMMOHook {
private static boolean enabled = false;
/**
* Updates a Player's Wood Cutting skill based on the number of logs they broke
*
* @param player The Player to update
* @param treeBlocks The tree blocks that were broken
*/
public static void updateWoodCuttingSkill(Player player, HashSet<Block> treeBlocks) {
if (!enabled) return;
if (player.getGameMode().equals(GameMode.CREATIVE)) return;
ExperienceAPI.addXpFromBlocksBySkill(getLogStates(treeBlocks), UserManager.getPlayer(player), PrimarySkillType.WOODCUTTING);
}
/**
* Sets the hook to enabled
*/
public static void setEnabled() {
enabled = true;
}
/**
* Counts the number of logs
*
* @param treeBlocks The potential log blocks
* @return The number of logs
*/
private static ArrayList<BlockState> getLogStates(HashSet<Block> treeBlocks) {
ArrayList<BlockState> logs = new ArrayList<>();
for (Block block : treeBlocks) {
Material material = WoodToLogConverter.convert(block.getType());
if (material.name().endsWith("LOG")) {
logs.add(block.getState());
}
}
return logs;
}
}

View File

@ -15,6 +15,7 @@ import com.songoda.ultimatetimber.UltimateTimber;
import com.songoda.ultimatetimber.configurations.DefaultConfig;
import com.songoda.ultimatetimber.events.TreeFallEvent;
import com.songoda.ultimatetimber.events.TreeFellEvent;
import com.songoda.ultimatetimber.hooks.McMMOHook;
public class TreeFallListener implements Listener {
@ -58,6 +59,9 @@ public class TreeFallListener implements Listener {
// Do not let any items drop, it will be handled later
event.setDropItems(false);
// Add to mcMMO XP if installed
McMMOHook.updateWoodCuttingSkill(event.getPlayer(), blocks);
if (fileConfiguration.getBoolean(DefaultConfig.ACCURATE_AXE_DURABILITY))
AxeDurability.adjustAxeDamage(blocks, event.getPlayer());
if (fileConfiguration.getBoolean(DefaultConfig.CUSTOM_AUDIO))

View File

@ -24,7 +24,7 @@ class TreeLoot {
return;
if (hasSilkTouch) { // No bonus loot for silk touch
world.dropItem(location, new ItemStack(originalMaterial, 1));
world.dropItem(location, new ItemStack(WoodToLogConverter.convert(originalMaterial), 1));
return;
}

View File

@ -3,7 +3,7 @@ version: maven-version-number
author: Songoda
main: com.songoda.ultimatetimber.UltimateTimber
api-version: 1.13
softdepend: [Multiverse-Core]
softdepend: [Multiverse-Core, mcMMO]
commands:
ultimatetimber:
description: Reloads the configuration file