Repairables can now specify multiple items that can be used for repairs

This commit is contained in:
nossr50 2019-03-22 15:32:53 -07:00
parent 0f98d9babe
commit 968636b8d4
11 changed files with 157 additions and 75 deletions

View File

@ -11,6 +11,9 @@ Version 2.2.0
mcMMO's config system has been rewritten
mcMMO will now warn you in the console if it thinks you are running incompatible server software
Parties no longer have a cap, you can level them forever for bragging rights
You can now specify multiple repair-items for an item (such as specifying that a wooden sword can be repaired by all types of planks)
Simplified the config entries for Repairables in the Repair config
Repairables in the repair config now use their internal registry key names instead of Bukkit material names
Optimizations were made for many anti-exploit behaviours
Acrobatic's Dodge will no longer reward XP for a few seconds after a TP
Roll will not give XP for a few seconds after a TP

View File

@ -8,7 +8,7 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.repair.ArcaneForging;
import com.gmail.nossr50.skills.repair.RepairManager;
import com.gmail.nossr50.skills.repair.repairables.Repairable;
import com.gmail.nossr50.skills.repair.repairables.SimpleRepairable;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.player.UserManager;
@ -17,6 +17,7 @@ import com.gmail.nossr50.util.skills.SkillActivationType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.Repairable;
import java.util.ArrayList;
import java.util.List;
@ -50,10 +51,10 @@ public class RepairCommand extends SkillCommand {
@Override
protected void dataCalculations(Player player, float skillValue) {
// We're using pickaxes here, not the best but it works
Repairable diamondRepairable = mcMMO.getRepairableManager().getRepairable(Material.DIAMOND_PICKAXE);
Repairable goldRepairable = mcMMO.getRepairableManager().getRepairable(Material.GOLDEN_PICKAXE);
Repairable ironRepairable = mcMMO.getRepairableManager().getRepairable(Material.IRON_PICKAXE);
Repairable stoneRepairable = mcMMO.getRepairableManager().getRepairable(Material.STONE_PICKAXE);
SimpleRepairable diamondRepairable = mcMMO.getRepairableManager().getRepairable(Material.DIAMOND_PICKAXE);
SimpleRepairable goldRepairable = mcMMO.getRepairableManager().getRepairable(Material.GOLDEN_PICKAXE);
SimpleRepairable ironRepairable = mcMMO.getRepairableManager().getRepairable(Material.IRON_PICKAXE);
SimpleRepairable stoneRepairable = mcMMO.getRepairableManager().getRepairable(Material.STONE_PICKAXE);
// TODO: This isn't really accurate - if they don't have pickaxes loaded it doesn't always mean the repair level is 0
diamondLevel = (diamondRepairable == null) ? 0 : diamondRepairable.getMinimumLevel();

View File

@ -47,7 +47,6 @@ import com.gmail.nossr50.config.treasure.HerbalismTreasureConfig;
import com.gmail.nossr50.datatypes.party.PartyFeature;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.repair.repairables.Repairable;
import com.gmail.nossr50.skills.repair.repairables.SimpleRepairable;
import com.gmail.nossr50.skills.repair.repairables.SimpleRepairableManager;
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;

View File

@ -5,7 +5,10 @@ import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer;
import org.bukkit.Material;
import ninja.leaping.configurate.util.EnumLookup;
import java.util.List;
import java.util.Optional;
public class RepairableSerializer implements TypeSerializer<SimpleRepairable> {
@ -37,23 +40,46 @@ public class RepairableSerializer implements TypeSerializer<SimpleRepairable> {
/* SimpleRepairable(Material itemMaterial, Material repairMaterial, int minimumQuantity, int minimumLevel, double xpMultiplier) */
Material item = value.getNode("Item").getValue(TypeToken.of(Material.class));
Material repairItem = value.getNode("Item-Used-To-Repair").getValue(TypeToken.of(Material.class));
String item = value.getNode("Item").getValue(TypeToken.of(String.class));
List<String> repairItems = value.getNode("Items-Used-To-Repair").getValue(new TypeToken<List<String>>() {});
/*String itemConstant = HOCONUtil.deserializeENUMName(value.getNode("Item").getString());
String repairConstant = HOCONUtil.deserializeENUMName(value.getNode("Item-Used-To-Repair").getString());
Material item = (Material) getEnum(itemConstant, TypeToken.of(Material.class));
Material repairItem = (Material) getEnum(repairConstant, TypeToken.of(Material.class));*/
int minimumQuantity = value.getNode("Minimum-Quantity-Used-To-Repair").getValue(TypeToken.of(Integer.class));
int minimumLevel = value.getNode("Skill-Level-Required-To-Repair").getValue(TypeToken.of(Integer.class));
double xpMultiplier = value.getNode("XP-Multiplier").getValue(TypeToken.of(Double.class));
return new SimpleRepairable(item, repairItem, minimumQuantity, minimumLevel, xpMultiplier);
return new SimpleRepairable(item, repairItems, minimumQuantity, minimumLevel, xpMultiplier);
}
@Override
public void serialize(TypeToken<?> type, SimpleRepairable obj, ConfigurationNode value) throws ObjectMappingException {
value.getNode("Item").setValue(obj.getItemMaterial());
value.getNode("Item-Used-To-Repair").setValue(obj.getRepairMaterial());
/*value.getNode("Item").setValue(HOCONUtil.serializeENUMName(obj.getItemMaterial().getKey().getKey()));
value.getNode("Item-Used-To-Repair").setValue(HOCONUtil.serializeENUMName(obj.getRepairMaterials().getKey().getKey()));*/
value.getNode("Item").setValue(obj.getItemMaterial().getKey().toString());
value.getNode("Items-Used-To-Repair").setValue(obj.getRepairMaterialsRegistryKeys());
value.getNode("Minimum-Quantity-Used-To-Repair").setValue(obj.getMinimumQuantity());
value.getNode("Skill-Level-Required-To-Repair").setValue(obj.getMinimumLevel());
value.getNode("XP-Multiplier").setValue(obj.getXpMultiplier());
}
private Enum getEnum(String enumConstant, TypeToken<?> type) throws ObjectMappingException
{
Optional<Enum> ret = (Optional) EnumLookup.lookupEnum(type.getRawType().asSubclass(Enum.class),
enumConstant); // XXX: intellij says this cast is optional but it isnt
if (!ret.isPresent()) {
throw new ObjectMappingException("Invalid enum constant provided for " + enumConstant + ": " +
"Expected a value of enum " + type + ", got " + enumConstant);
}
return ret.get();
}
}
}

View File

@ -5,8 +5,10 @@ import com.gmail.nossr50.config.hocon.skills.repair.repairmastery.ConfigRepairMa
import com.gmail.nossr50.skills.repair.repairables.SimpleRepairable;
import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
import org.bukkit.Material;
import java.util.ArrayList;
import java.util.Arrays;
import static org.bukkit.Material.*;
@ -14,14 +16,15 @@ import static org.bukkit.Material.*;
public class ConfigRepair {
public static final ArrayList<SimpleRepairable> CONFIG_REPAIRABLES_DEFAULTS;
public static final Material[] PLANKS = new Material[] { OAK_PLANKS, BIRCH_PLANKS, DARK_OAK_PLANKS, ACACIA_PLANKS, JUNGLE_PLANKS, SPRUCE_PLANKS};
static {
CONFIG_REPAIRABLES_DEFAULTS = new ArrayList<>();
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_SWORD, OAK_PLANKS, 1, 0, .25D));
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_SHOVEL, OAK_PLANKS, 1, 0, .15D));
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_PICKAXE, OAK_PLANKS, 1, 0, .5D));
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_AXE, OAK_PLANKS, 1, 0, .5D));
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_HOE, OAK_PLANKS, 1, 0, .25D));
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_SWORD, Arrays.asList(PLANKS), 1, 0, .25D));
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_SHOVEL, Arrays.asList(PLANKS), 1, 0, .15D));
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_PICKAXE, Arrays.asList(PLANKS), 1, 0, .5D));
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_AXE, Arrays.asList(PLANKS), 1, 0, .5D));
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_HOE, Arrays.asList(PLANKS), 1, 0, .25D));
/*
Repairables:

View File

@ -203,7 +203,7 @@ public class mcMMO extends JavaPlugin {
//getServer().getPluginManager().disablePlugin(this);
}
if(isIncompatibleVersion(Bukkit.getVersion(), Bukkit.getBukkitVersion()))
/*if(isIncompatibleVersion(Bukkit.getVersion(), Bukkit.getBukkitVersion()))
{
getLogger().severe("mcMMO is not supported for your current server software and or Minecraft version");
@ -220,7 +220,7 @@ public class mcMMO extends JavaPlugin {
getLogger().severe("Compatible Minecraft Versions: "+ COMPATIBLE_MINECRAFT_VERSIONS);
getLogger().info("TIP: Paper and Spigot are extensions of CraftBukkit and are completely safe to upgrade to from CraftBukkit, please consider upgrading.");
}
}
}*/
}
private boolean isIncompatibleVersion(String serverSoftwareString, String serverVersionString)

View File

@ -10,7 +10,7 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.repair.repairables.Repairable;
import com.gmail.nossr50.skills.repair.repairables.SimpleRepairable;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
@ -61,9 +61,11 @@ public class RepairManager extends SkillManager {
togglePlacedAnvil();
}
public void handleRepair(ItemStack item) {
Player player = getPlayer();
Repairable repairable = mcMMO.getRepairableManager().getRepairable(item.getType());
SimpleRepairable repairable = mcMMO.getRepairableManager().getRepairable(item.getType());
if (item.getItemMeta().isUnbreakable()) {
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Anvil.Unbreakable");
@ -91,8 +93,15 @@ public class RepairManager extends SkillManager {
}
PlayerInventory inventory = player.getInventory();
Material repairMaterial = null;
//Find the first compatible repair material
for(Material repairMaterialCandidate : repairable.getRepairMaterials())
{
if(player.getInventory().contains(new ItemStack(repairMaterialCandidate)))
repairMaterial = repairMaterialCandidate;
}
Material repairMaterial = repairable.getRepairMaterial();
//byte repairMaterialMetadata = repairable.getRepairMaterialMetadata();
ItemStack toRemove = new ItemStack(repairMaterial);

View File

@ -1,3 +1,4 @@
/*
package com.gmail.nossr50.skills.repair.repairables;
import com.gmail.nossr50.datatypes.skills.ItemType;
@ -6,70 +7,89 @@ import org.bukkit.Material;
public interface Repairable {
*/
/**
* Gets the type of this repairable item
*
* @return the type of this repairable
*/
*//*
public Material getItemMaterial();
*/
/**
* Gets the id of the material used to repair this item
*
* @return the id of the repair material
*/
public Material getRepairMaterial();
*//*
public Material getRepairMaterials();
*/
/**
* Gets the RepairItemType value for this repairable item
*
* @return the RepairItemType for this repairable
*/
*//*
public ItemType getRepairItemType();
*/
/**
* Gets the RepairMaterialType value for this repairable item
*
* @return the RepairMaterialType for this repairable
*/
*//*
public MaterialType getRepairMaterialType();
*/
/**
* Gets the minimum quantity of repair materials ignoring all other repair bonuses
*
* This is typically set to the number of items needed to create that item, for example 5 for helmets or 2 for swords
*
* @return the minimum number of items
*/
*//*
public int getMinimumQuantity();
*/
/**
* Gets the maximum durability of this item before it breaks
*
* @return the maximum durability
*/
*//*
public short getMaximumDurability();
*/
/**
* Gets the base repair durability on which to calculate bonuses.
*
* This is actually the maximum durability divided by the minimum quantity
*
* @return the base repair durability
*/
*//*
public short getBaseRepairDurability();
*/
/**
* Gets the minimum repair level needed to repair this item
*
* @return the minimum level to repair this item, or 0 for no minimum
*/
*//*
public int getMinimumLevel();
*/
/**
* Gets the xpMultiplier for this repairable
*
* @return the xpMultiplier of this repairable
*/
*//*
public double getXpMultiplier();
}
*/

View File

@ -6,41 +6,39 @@ import com.gmail.nossr50.util.ItemUtils;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
import java.util.List;
public class SimpleRepairable implements Repairable {
private final Material itemMaterial, repairMaterial;
public class SimpleRepairable {
private final Material itemMaterial;
private final List<Material> repairMaterials;
private final int minimumQuantity, minimumLevel;
private final short maximumDurability, baseRepairDurability;
/*private String repairMaterialPrettyName;*/
private final ItemType repairItemType;
private final MaterialType repairMaterialType;
private final double xpMultiplier;
/* protected SimpleRepairable(Material type, Material repairMaterial, String repairMaterialPrettyName, int minimumLevel, int minimumQuantity, short maximumDurability, ItemType repairItemType, MaterialType repairMaterialType, double xpMultiplier) {
this.itemMaterial = type;
this.repairMaterial = repairMaterial;
this.repairMaterialPrettyName = repairMaterialPrettyName;
this.repairItemType = repairItemType;
this.repairMaterialType = repairMaterialType;
this.minimumLevel = minimumLevel;
this.minimumQuantity = minimumQuantity;
this.maximumDurability = maximumDurability;
this.baseRepairDurability = (short) (maximumDurability / minimumQuantity);
this.xpMultiplier = xpMultiplier;
}*/
public SimpleRepairable(Material itemMaterial, Material repairMaterial, int minimumQuantity, int minimumLevel, double xpMultiplier) {
this.itemMaterial = itemMaterial;
this.repairMaterial = repairMaterial;
this(itemMaterial.getKey().getKey(), ItemUtils.getRepairItemMaterials(Arrays.asList(repairMaterial)), minimumQuantity, minimumLevel, xpMultiplier);
}
public SimpleRepairable(Material itemMaterial, List<Material> repairMaterials, int minimumQuantity, int minimumLevel, double xpMultiplier) {
this(itemMaterial.getKey().getKey(), ItemUtils.getRepairItemMaterials(repairMaterials), minimumQuantity, minimumLevel, xpMultiplier);
}
public SimpleRepairable(String itemMaterial, List<String> repairMaterials, int minimumQuantity, int minimumLevel, double xpMultiplier) {
this.itemMaterial = Material.matchMaterial(itemMaterial);
this.repairMaterials = ItemUtils.matchMaterials(repairMaterials);
this.minimumQuantity = minimumQuantity;
this.minimumLevel = minimumLevel;
this.xpMultiplier = xpMultiplier;
this.maximumDurability = itemMaterial.getMaxDurability();
this.maximumDurability = this.itemMaterial.getMaxDurability();
this.baseRepairDurability = (short) (maximumDurability / minimumQuantity);
this.repairItemType = determineItemType(itemMaterial);
this.repairMaterialType = determineMaterialType(repairMaterial);
this.repairItemType = determineItemType(this.itemMaterial);
this.repairMaterialType = determineMaterialType(this.repairMaterials.get(0));
}
public MaterialType determineMaterialType(Material material) {
@ -88,47 +86,43 @@ public class SimpleRepairable implements Repairable {
}
}
@Override
public Material getItemMaterial() {
return itemMaterial;
}
@Override
public Material getRepairMaterial() {
return repairMaterial;
public List<Material> getRepairMaterials() {
return repairMaterials;
}
@Override
public List<String> getRepairMaterialsRegistryKeys() {
return ItemUtils.getRepairItemMaterials(repairMaterials);
}
public ItemType getRepairItemType() {
return repairItemType;
}
@Override
public MaterialType getRepairMaterialType() {
return repairMaterialType;
}
@Override
public int getMinimumQuantity() {
return minimumQuantity;
}
@Override
public short getMaximumDurability() {
return maximumDurability;
}
@Override
public short getBaseRepairDurability() {
return baseRepairDurability;
}
@Override
public int getMinimumLevel() {
return minimumLevel;
}
@Override
public double getXpMultiplier() {
return xpMultiplier;
}

View File

@ -39,7 +39,7 @@ public class SimpleRepairableManager implements Unload {
return isRepairable(itemStack.getType());
}
public Repairable getRepairable(Material type) {
public SimpleRepairable getRepairable(Material type) {
return repairables.get(type);
}
}

View File

@ -10,9 +10,36 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
public final class ItemUtils {
private ItemUtils() {}
public static ArrayList<String> getRepairItemMaterials(List<Material> repairItemList)
{
ArrayList<String> repairMaterialList = new ArrayList<>();
for(Material m : repairItemList)
{
repairMaterialList.add(m.getKey().toString());
}
return repairMaterialList;
}
public static ArrayList<Material> matchMaterials(List<String> ItemBlockRegistryKeyList)
{
ArrayList<Material> matchedMaterials = new ArrayList<>();
for(String s : ItemBlockRegistryKeyList)
{
matchedMaterials.add(Material.matchMaterial(s));
}
return matchedMaterials;
}
/**
* Checks if the item is a bow.
*