More work on new repair datatypes

This commit is contained in:
nossr50 2019-06-18 23:08:14 -07:00
parent 1e338e6aec
commit 458e198fdb
4 changed files with 144 additions and 113 deletions

View File

@ -37,6 +37,8 @@ import com.gmail.nossr50.config.hocon.skills.mining.ConfigMining;
import com.gmail.nossr50.config.hocon.skills.ranks.ConfigRanks;
import com.gmail.nossr50.config.hocon.skills.ranks.SkillRankProperty;
import com.gmail.nossr50.config.hocon.skills.repair.ConfigRepair;
import com.gmail.nossr50.skills.repair.RepairCost;
import com.gmail.nossr50.skills.repair.RepairTransaction;
import com.gmail.nossr50.skills.repair.RepairWildcard;
import com.gmail.nossr50.config.hocon.skills.salvage.ConfigSalvage;
import com.gmail.nossr50.config.hocon.skills.smelting.ConfigSmelting;
@ -279,6 +281,8 @@ public final class ConfigManager {
customSerializers.registerType(TypeToken.of(SoundSetting.class), new SoundSettingSerializer());
customSerializers.registerType(TypeToken.of(ItemStack.class), new ItemStackSerializer());
customSerializers.registerType(TypeToken.of(RepairWildcard.class), new RepairWildcardSerializer());
customSerializers.registerType(TypeToken.of(RepairCost.class), new RepairCostSerializer());
customSerializers.registerType(TypeToken.of(RepairTransaction.class), new RepairTransactionSerializer());
}
/**

View File

@ -0,0 +1,27 @@
package com.gmail.nossr50.config.hocon.serializers;
import com.gmail.nossr50.util.nbt.RawNBT;
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.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
public class RawNBTSerializer implements TypeSerializer<RawNBT> {
private static final String NBT = "NBT";
@Nullable
@Override
public RawNBT deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException {
String nbtString = value.getNode(NBT).getValue(TypeToken.of(String.class));
return new RawNBT(nbtString);
}
@Override
public void serialize(@NonNull TypeToken<?> type, @Nullable RawNBT obj, @NonNull ConfigurationNode value) throws ObjectMappingException {
value.getNode(NBT).setValue(obj.getNbtContents());
}
}

View File

@ -60,123 +60,123 @@ public class RepairManager extends SkillManager {
public void handleRepair(ItemStack item) {
Player player = getPlayer();
Repairable repairable = mcMMO.getRepairableManager().getRepairable(item.getType());
if(item.getItemMeta() != null && item.getItemMeta().isUnbreakable()) {
mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Anvil.Unbreakable");
return;
}
// Permissions checks on material and item types
// if (!Permissions.repairMaterialType(player, repairable.getRepairItemMaterialCategory())) {
// mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.NO_PERMISSION, "mcMMO.NoPermission");
// Player player = getPlayer();
// Repairable repairable = mcMMO.getRepairableManager().getRepairable(item.getType());
//
// if(item.getItemMeta() != null && item.getItemMeta().isUnbreakable()) {
// mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Anvil.Unbreakable");
// return;
// }
//
// if (!Permissions.repairItemType(player, repairable.getRepairItemType())) {
// mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.NO_PERMISSION, "mcMMO.NoPermission");
// // Permissions checks on material and item types
//// if (!Permissions.repairMaterialType(player, repairable.getRepairItemMaterialCategory())) {
//// mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.NO_PERMISSION, "mcMMO.NoPermission");
//// return;
//// }
////
//// if (!Permissions.repairItemType(player, repairable.getRepairItemType())) {
//// mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.NO_PERMISSION, "mcMMO.NoPermission");
//// return;
//// }
//
// int skillLevel = getSkillLevel();
// int minimumRepairableLevel = repairable.getMinimumLevel();
//
// // Level check
// if (skillLevel < minimumRepairableLevel) {
// mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Repair.Skills.Adept", String.valueOf(minimumRepairableLevel), StringUtils.getPrettyItemString(item.getType()));
// return;
// }
int skillLevel = getSkillLevel();
int minimumRepairableLevel = repairable.getMinimumLevel();
// Level check
if (skillLevel < minimumRepairableLevel) {
mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Repair.Skills.Adept", String.valueOf(minimumRepairableLevel), StringUtils.getPrettyItemString(item.getType()));
return;
}
PlayerInventory inventory = player.getInventory();
Material repairMaterial = null;
boolean foundNonBasicMaterial = false;
//Find the first compatible repair material
for (Material repairMaterialCandidate : repairable.getRepairMaterials()) {
for (ItemStack is : player.getInventory().getContents()) {
if(is == null)
continue; //Ignore IntelliJ this can be null
//Match to repair material
if (is.getType() == repairMaterialCandidate) {
//Check for item meta
if(is.getItemMeta() != null) {
//Check for lore
if(is.getItemMeta().getLore() != null) {
if(is.getItemMeta().getLore().isEmpty()) {
//Lore is empty so this item is fine
repairMaterial = repairMaterialCandidate;
break;
} else {
foundNonBasicMaterial = true;
}
} else {
//No lore so this item is fine
repairMaterial = repairMaterialCandidate;
break;
}
} else {
//No Item Meta so this item is fine
repairMaterial = repairMaterialCandidate;
break;
}
}
}
}
/* Abort the repair if no compatible basic repairing item found */
if (repairMaterial == null && foundNonBasicMaterial == true) {
player.sendMessage(LocaleLoader.getString("Repair.NoBasicRepairMatsFound"));
return;
}
ItemStack toRemove = new ItemStack(repairMaterial);
toRemove.setAmount(1);
short startDurability = item.getDurability();
// Do not repair if at full durability
if (startDurability <= 0) {
mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Repair.Skills.FullDurability");
return;
}
// Clear ability buffs before trying to repair.
SkillUtils.removeAbilityBuff(item);
// Lets get down to business,
// To defeat, the huns.
int baseRepairAmount = repairable.getBaseRepairDurability(); // Did they send me daughters?
short newDurability = repairCalculate(startDurability, baseRepairAmount); // When I asked for sons?
// Call event
if (EventUtils.callRepairCheckEvent(player, (short) (startDurability - newDurability), toRemove, item).isCancelled()) {
return;
}
// Handle the enchants
if (mcMMO.getConfigManager().getConfigRepair().getArcaneForging().isMayLoseEnchants() && !Permissions.hasRepairEnchantBypassPerk(player)) {
addEnchants(item);
}
// Remove the item
inventory.removeItem(toRemove);
// Give out XP like candy
applyXpGain(((getPercentageRepaired(startDurability, newDurability, repairable.getMaximumDurability())
* repairable.getXpMultiplier())
* mcMMO.getConfigManager().getConfigExperience().getRepairXPBase())
* mcMMO.getConfigManager().getConfigExperience().getExperienceRepair().getItemMaterialXPMultiplier(repairable.getRepairItemMaterialCategory()), XPGainReason.PVE);
// BWONG BWONG BWONG
if (mcMMO.getConfigManager().getConfigRepair().getRepairGeneral().isAnvilUseSounds()) {
SoundManager.sendSound(player, player.getLocation(), SoundType.ANVIL);
SoundManager.sendSound(player, player.getLocation(), SoundType.ITEM_BREAK);
}
// Repair the item!
item.setDurability(newDurability);
//
// PlayerInventory inventory = player.getInventory();
// Material repairMaterial = null;
// boolean foundNonBasicMaterial = false;
//
// //Find the first compatible repair material
// for (Material repairMaterialCandidate : repairable.getRepairMaterials()) {
// for (ItemStack is : player.getInventory().getContents()) {
// if(is == null)
// continue; //Ignore IntelliJ this can be null
//
// //Match to repair material
// if (is.getType() == repairMaterialCandidate) {
// //Check for item meta
// if(is.getItemMeta() != null) {
// //Check for lore
// if(is.getItemMeta().getLore() != null) {
// if(is.getItemMeta().getLore().isEmpty()) {
// //Lore is empty so this item is fine
// repairMaterial = repairMaterialCandidate;
// break;
// } else {
// foundNonBasicMaterial = true;
// }
// } else {
// //No lore so this item is fine
// repairMaterial = repairMaterialCandidate;
// break;
// }
// } else {
// //No Item Meta so this item is fine
// repairMaterial = repairMaterialCandidate;
// break;
// }
// }
// }
// }
//
// /* Abort the repair if no compatible basic repairing item found */
// if (repairMaterial == null && foundNonBasicMaterial == true) {
// player.sendMessage(LocaleLoader.getString("Repair.NoBasicRepairMatsFound"));
// return;
// }
//
// ItemStack toRemove = new ItemStack(repairMaterial);
// toRemove.setAmount(1);
//
// short startDurability = item.getDurability();
//
// // Do not repair if at full durability
// if (startDurability <= 0) {
// mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Repair.Skills.FullDurability");
// return;
// }
//
// // Clear ability buffs before trying to repair.
// SkillUtils.removeAbilityBuff(item);
//
// // Lets get down to business,
// // To defeat, the huns.
// int baseRepairAmount = repairable.getBaseRepairDurability(); // Did they send me daughters?
// short newDurability = repairCalculate(startDurability, baseRepairAmount); // When I asked for sons?
//
// // Call event
// if (EventUtils.callRepairCheckEvent(player, (short) (startDurability - newDurability), toRemove, item).isCancelled()) {
// return;
// }
//
// // Handle the enchants
// if (mcMMO.getConfigManager().getConfigRepair().getArcaneForging().isMayLoseEnchants() && !Permissions.hasRepairEnchantBypassPerk(player)) {
// addEnchants(item);
// }
//
// // Remove the item
// inventory.removeItem(toRemove);
//
// // Give out XP like candy
// applyXpGain(((getPercentageRepaired(startDurability, newDurability, repairable.getMaximumDurability())
// * repairable.getXpMultiplier())
// * mcMMO.getConfigManager().getConfigExperience().getRepairXPBase())
// * mcMMO.getConfigManager().getConfigExperience().getExperienceRepair().getItemMaterialXPMultiplier(repairable.getRepairItemMaterialCategory()), XPGainReason.PVE);
//
// // BWONG BWONG BWONG
// if (mcMMO.getConfigManager().getConfigRepair().getRepairGeneral().isAnvilUseSounds()) {
// SoundManager.sendSound(player, player.getLocation(), SoundType.ANVIL);
// SoundManager.sendSound(player, player.getLocation(), SoundType.ITEM_BREAK);
// }
//
// // Repair the item!
// item.setDurability(newDurability);
}
private double getPercentageRepaired(short startDurability, short newDurability, short totalDurability) {

View File

@ -15,7 +15,7 @@ public class RepairableManager {
}
public void registerRepairable(Repairable repairable) {
Material item = repairable.getItemMaterial();
Material item = repairable.getItem().getType();
repairables.put(item, repairable);
}