Bump version to 1.0.12, mcMMO Classic support, fix axe durability
This commit is contained in:
parent
69d7a665f4
commit
1b370a73dd
|
@ -4,7 +4,7 @@ stages:
|
|||
variables:
|
||||
name: "UltimateTimber"
|
||||
path: "/builds/$CI_PROJECT_PATH"
|
||||
version: "1.0.11"
|
||||
version: "1.0.12"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
|
|
|
@ -78,8 +78,13 @@ public class UltimateTimber extends JavaPlugin {
|
|||
/*
|
||||
Check for McMMO
|
||||
*/
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("mcMMO"))
|
||||
McMMOHook.setEnabled();
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("mcMMO")) {
|
||||
if (McMMOHook.setEnabled()) {
|
||||
console.sendMessage("Hooks: Hooked into mcMMO");
|
||||
} else {
|
||||
console.sendMessage("Hooks: Unable to hook with mcMMO, the version installed is not supported!");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Register command executor and tab completer
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
package com.songoda.ultimatetimber.hooks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
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.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
import com.songoda.ultimatetimber.utils.WoodToLogConverter;
|
||||
|
||||
public class McMMOHook {
|
||||
|
||||
private static boolean enabled = false;
|
||||
private static Enum<?> woodcuttingEnum;
|
||||
private static Method getXpMethod;
|
||||
|
||||
/**
|
||||
* Updates a Player's Wood Cutting skill based on the number of logs they broke
|
||||
|
@ -28,31 +29,62 @@ public class McMMOHook {
|
|||
if (!enabled) return;
|
||||
if (player.getGameMode().equals(GameMode.CREATIVE)) return;
|
||||
|
||||
ExperienceAPI.addXpFromBlocksBySkill(getLogStates(treeBlocks), UserManager.getPlayer(player), PrimarySkillType.WOODCUTTING);
|
||||
try {
|
||||
ExperienceAPI.addXP(player, "woodcutting", getLogXP(treeBlocks), "pve");
|
||||
} catch (Exception ex) {
|
||||
Bukkit.getLogger().warning("[UltimateTimber] Warning: The version of mcMMO you are using is not compatible with UltimateTimber. Disabling hook...");
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hook to enabled
|
||||
*/
|
||||
public static void setEnabled() {
|
||||
public static boolean setEnabled() {
|
||||
try { // Try to find mcMMO Overhaul
|
||||
Class<?> primarySkillTypeClass = Class.forName("com.gmail.nossr50.datatypes.skills.PrimarySkillType");
|
||||
for (Object enumValue : primarySkillTypeClass.getEnumConstants()) {
|
||||
Enum<?> primarySkillTypeEnum = (Enum<?>) enumValue;
|
||||
if (primarySkillTypeEnum.name().equals("WOODCUTTING")) {
|
||||
woodcuttingEnum = primarySkillTypeEnum;
|
||||
break;
|
||||
}
|
||||
}
|
||||
getXpMethod = ExperienceConfig.class.getMethod("getXp", woodcuttingEnum.getClass(), Material.class);
|
||||
} catch (Exception ex) {
|
||||
try { // Try to find mcMMO Classic
|
||||
Class<?> skillTypeClass = Class.forName("com.gmail.nossr50.datatypes.skills.SkillType");
|
||||
for (Object enumValue : skillTypeClass.getEnumConstants()) {
|
||||
Enum<?> skillTypeEnum = (Enum<?>) enumValue;
|
||||
if (skillTypeEnum.name().equals("WOODCUTTING")) {
|
||||
woodcuttingEnum = skillTypeEnum;
|
||||
break;
|
||||
}
|
||||
}
|
||||
getXpMethod = ExperienceConfig.class.getMethod("getXp", woodcuttingEnum.getClass(), Material.class);
|
||||
} catch (Exception ex2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
enabled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of logs
|
||||
* Gets the XP that a player would obtain from breaking the logs in the tree
|
||||
*
|
||||
* @param treeBlocks The potential log blocks
|
||||
* @return The number of logs
|
||||
* @return The XP a player should gain
|
||||
*/
|
||||
private static ArrayList<BlockState> getLogStates(HashSet<Block> treeBlocks) {
|
||||
ArrayList<BlockState> logs = new ArrayList<>();
|
||||
private static int getLogXP(HashSet<Block> treeBlocks) throws Exception {
|
||||
int xp = 0;
|
||||
for (Block block : treeBlocks) {
|
||||
Material material = WoodToLogConverter.convert(block.getType());
|
||||
if (material.name().endsWith("LOG")) {
|
||||
logs.add(block.getState());
|
||||
}
|
||||
if (!material.name().endsWith("LOG")) continue;
|
||||
xp += (int) getXpMethod.invoke(ExperienceConfig.getInstance(), woodcuttingEnum, material);
|
||||
}
|
||||
return logs;
|
||||
return xp;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ import org.bukkit.inventory.ItemStack;
|
|||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.songoda.ultimatetimber.utils.WoodToLogConverter;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
class AxeDurability {
|
||||
|
@ -26,20 +28,23 @@ class AxeDurability {
|
|||
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
Damageable damageableMeta = (Damageable) itemMeta;
|
||||
for (Block block : blocks)
|
||||
if (block.getType().equals(Material.ACACIA_LOG) ||
|
||||
block.getType().equals(Material.BIRCH_LOG) ||
|
||||
block.getType().equals(Material.DARK_OAK_LOG) ||
|
||||
block.getType().equals(Material.JUNGLE_LOG) ||
|
||||
block.getType().equals(Material.OAK_LOG) ||
|
||||
block.getType().equals(Material.SPRUCE_LOG) ||
|
||||
block.getType().equals(Material.STRIPPED_ACACIA_LOG) ||
|
||||
block.getType().equals(Material.STRIPPED_BIRCH_LOG) ||
|
||||
block.getType().equals(Material.STRIPPED_DARK_OAK_LOG) ||
|
||||
block.getType().equals(Material.STRIPPED_JUNGLE_LOG) ||
|
||||
block.getType().equals(Material.STRIPPED_OAK_LOG) ||
|
||||
block.getType().equals(Material.STRIPPED_SPRUCE_LOG))
|
||||
for (Block block : blocks) {
|
||||
Material material = WoodToLogConverter.convert(block.getType());
|
||||
if (material.equals(Material.ACACIA_LOG) ||
|
||||
material.equals(Material.BIRCH_LOG) ||
|
||||
material.equals(Material.DARK_OAK_LOG) ||
|
||||
material.equals(Material.JUNGLE_LOG) ||
|
||||
material.equals(Material.OAK_LOG) ||
|
||||
material.equals(Material.SPRUCE_LOG) ||
|
||||
material.equals(Material.STRIPPED_ACACIA_LOG) ||
|
||||
material.equals(Material.STRIPPED_BIRCH_LOG) ||
|
||||
material.equals(Material.STRIPPED_DARK_OAK_LOG) ||
|
||||
material.equals(Material.STRIPPED_JUNGLE_LOG) ||
|
||||
material.equals(Material.STRIPPED_OAK_LOG) ||
|
||||
material.equals(Material.STRIPPED_SPRUCE_LOG))
|
||||
damageableMeta.setDamage(damageableMeta.getDamage() + 1);
|
||||
}
|
||||
|
||||
|
||||
item.setItemMeta((ItemMeta) damageableMeta);
|
||||
|
||||
|
|
Loading…
Reference in New Issue