mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 06:36:45 +01:00
More work on new repair datatypes
This commit is contained in:
parent
1e338e6aec
commit
458e198fdb
@ -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.ConfigRanks;
|
||||||
import com.gmail.nossr50.config.hocon.skills.ranks.SkillRankProperty;
|
import com.gmail.nossr50.config.hocon.skills.ranks.SkillRankProperty;
|
||||||
import com.gmail.nossr50.config.hocon.skills.repair.ConfigRepair;
|
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.skills.repair.RepairWildcard;
|
||||||
import com.gmail.nossr50.config.hocon.skills.salvage.ConfigSalvage;
|
import com.gmail.nossr50.config.hocon.skills.salvage.ConfigSalvage;
|
||||||
import com.gmail.nossr50.config.hocon.skills.smelting.ConfigSmelting;
|
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(SoundSetting.class), new SoundSettingSerializer());
|
||||||
customSerializers.registerType(TypeToken.of(ItemStack.class), new ItemStackSerializer());
|
customSerializers.registerType(TypeToken.of(ItemStack.class), new ItemStackSerializer());
|
||||||
customSerializers.registerType(TypeToken.of(RepairWildcard.class), new RepairWildcardSerializer());
|
customSerializers.registerType(TypeToken.of(RepairWildcard.class), new RepairWildcardSerializer());
|
||||||
|
customSerializers.registerType(TypeToken.of(RepairCost.class), new RepairCostSerializer());
|
||||||
|
customSerializers.registerType(TypeToken.of(RepairTransaction.class), new RepairTransactionSerializer());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -60,123 +60,123 @@ public class RepairManager extends SkillManager {
|
|||||||
|
|
||||||
|
|
||||||
public void handleRepair(ItemStack item) {
|
public void handleRepair(ItemStack item) {
|
||||||
Player player = getPlayer();
|
// Player player = getPlayer();
|
||||||
Repairable repairable = mcMMO.getRepairableManager().getRepairable(item.getType());
|
// Repairable repairable = mcMMO.getRepairableManager().getRepairable(item.getType());
|
||||||
|
//
|
||||||
if(item.getItemMeta() != null && item.getItemMeta().isUnbreakable()) {
|
// if(item.getItemMeta() != null && item.getItemMeta().isUnbreakable()) {
|
||||||
mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Anvil.Unbreakable");
|
// 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");
|
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// if (!Permissions.repairItemType(player, repairable.getRepairItemType())) {
|
// // Permissions checks on material and item types
|
||||||
// mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.NO_PERMISSION, "mcMMO.NoPermission");
|
//// 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;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
//
|
||||||
int skillLevel = getSkillLevel();
|
// PlayerInventory inventory = player.getInventory();
|
||||||
int minimumRepairableLevel = repairable.getMinimumLevel();
|
// Material repairMaterial = null;
|
||||||
|
// boolean foundNonBasicMaterial = false;
|
||||||
// Level check
|
//
|
||||||
if (skillLevel < minimumRepairableLevel) {
|
// //Find the first compatible repair material
|
||||||
mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Repair.Skills.Adept", String.valueOf(minimumRepairableLevel), StringUtils.getPrettyItemString(item.getType()));
|
// for (Material repairMaterialCandidate : repairable.getRepairMaterials()) {
|
||||||
return;
|
// for (ItemStack is : player.getInventory().getContents()) {
|
||||||
}
|
// if(is == null)
|
||||||
|
// continue; //Ignore IntelliJ this can be null
|
||||||
PlayerInventory inventory = player.getInventory();
|
//
|
||||||
Material repairMaterial = null;
|
// //Match to repair material
|
||||||
boolean foundNonBasicMaterial = false;
|
// if (is.getType() == repairMaterialCandidate) {
|
||||||
|
// //Check for item meta
|
||||||
//Find the first compatible repair material
|
// if(is.getItemMeta() != null) {
|
||||||
for (Material repairMaterialCandidate : repairable.getRepairMaterials()) {
|
// //Check for lore
|
||||||
for (ItemStack is : player.getInventory().getContents()) {
|
// if(is.getItemMeta().getLore() != null) {
|
||||||
if(is == null)
|
// if(is.getItemMeta().getLore().isEmpty()) {
|
||||||
continue; //Ignore IntelliJ this can be null
|
// //Lore is empty so this item is fine
|
||||||
|
// repairMaterial = repairMaterialCandidate;
|
||||||
//Match to repair material
|
// break;
|
||||||
if (is.getType() == repairMaterialCandidate) {
|
// } else {
|
||||||
//Check for item meta
|
// foundNonBasicMaterial = true;
|
||||||
if(is.getItemMeta() != null) {
|
// }
|
||||||
//Check for lore
|
// } else {
|
||||||
if(is.getItemMeta().getLore() != null) {
|
// //No lore so this item is fine
|
||||||
if(is.getItemMeta().getLore().isEmpty()) {
|
// repairMaterial = repairMaterialCandidate;
|
||||||
//Lore is empty so this item is fine
|
// break;
|
||||||
repairMaterial = repairMaterialCandidate;
|
// }
|
||||||
break;
|
// } else {
|
||||||
} else {
|
// //No Item Meta so this item is fine
|
||||||
foundNonBasicMaterial = true;
|
// repairMaterial = repairMaterialCandidate;
|
||||||
}
|
// break;
|
||||||
} else {
|
// }
|
||||||
//No lore so this item is fine
|
// }
|
||||||
repairMaterial = repairMaterialCandidate;
|
// }
|
||||||
break;
|
// }
|
||||||
}
|
//
|
||||||
} else {
|
// /* Abort the repair if no compatible basic repairing item found */
|
||||||
//No Item Meta so this item is fine
|
// if (repairMaterial == null && foundNonBasicMaterial == true) {
|
||||||
repairMaterial = repairMaterialCandidate;
|
// player.sendMessage(LocaleLoader.getString("Repair.NoBasicRepairMatsFound"));
|
||||||
break;
|
// return;
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
}
|
// ItemStack toRemove = new ItemStack(repairMaterial);
|
||||||
}
|
// toRemove.setAmount(1);
|
||||||
|
//
|
||||||
/* Abort the repair if no compatible basic repairing item found */
|
// short startDurability = item.getDurability();
|
||||||
if (repairMaterial == null && foundNonBasicMaterial == true) {
|
//
|
||||||
player.sendMessage(LocaleLoader.getString("Repair.NoBasicRepairMatsFound"));
|
// // Do not repair if at full durability
|
||||||
return;
|
// if (startDurability <= 0) {
|
||||||
}
|
// mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Repair.Skills.FullDurability");
|
||||||
|
// return;
|
||||||
ItemStack toRemove = new ItemStack(repairMaterial);
|
// }
|
||||||
toRemove.setAmount(1);
|
//
|
||||||
|
// // Clear ability buffs before trying to repair.
|
||||||
short startDurability = item.getDurability();
|
// SkillUtils.removeAbilityBuff(item);
|
||||||
|
//
|
||||||
// Do not repair if at full durability
|
// // Lets get down to business,
|
||||||
if (startDurability <= 0) {
|
// // To defeat, the huns.
|
||||||
mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Repair.Skills.FullDurability");
|
// int baseRepairAmount = repairable.getBaseRepairDurability(); // Did they send me daughters?
|
||||||
return;
|
// short newDurability = repairCalculate(startDurability, baseRepairAmount); // When I asked for sons?
|
||||||
}
|
//
|
||||||
|
// // Call event
|
||||||
// Clear ability buffs before trying to repair.
|
// if (EventUtils.callRepairCheckEvent(player, (short) (startDurability - newDurability), toRemove, item).isCancelled()) {
|
||||||
SkillUtils.removeAbilityBuff(item);
|
// return;
|
||||||
|
// }
|
||||||
// Lets get down to business,
|
//
|
||||||
// To defeat, the huns.
|
// // Handle the enchants
|
||||||
int baseRepairAmount = repairable.getBaseRepairDurability(); // Did they send me daughters?
|
// if (mcMMO.getConfigManager().getConfigRepair().getArcaneForging().isMayLoseEnchants() && !Permissions.hasRepairEnchantBypassPerk(player)) {
|
||||||
short newDurability = repairCalculate(startDurability, baseRepairAmount); // When I asked for sons?
|
// addEnchants(item);
|
||||||
|
// }
|
||||||
// Call event
|
//
|
||||||
if (EventUtils.callRepairCheckEvent(player, (short) (startDurability - newDurability), toRemove, item).isCancelled()) {
|
// // Remove the item
|
||||||
return;
|
// inventory.removeItem(toRemove);
|
||||||
}
|
//
|
||||||
|
// // Give out XP like candy
|
||||||
// Handle the enchants
|
// applyXpGain(((getPercentageRepaired(startDurability, newDurability, repairable.getMaximumDurability())
|
||||||
if (mcMMO.getConfigManager().getConfigRepair().getArcaneForging().isMayLoseEnchants() && !Permissions.hasRepairEnchantBypassPerk(player)) {
|
// * repairable.getXpMultiplier())
|
||||||
addEnchants(item);
|
// * mcMMO.getConfigManager().getConfigExperience().getRepairXPBase())
|
||||||
}
|
// * mcMMO.getConfigManager().getConfigExperience().getExperienceRepair().getItemMaterialXPMultiplier(repairable.getRepairItemMaterialCategory()), XPGainReason.PVE);
|
||||||
|
//
|
||||||
// Remove the item
|
// // BWONG BWONG BWONG
|
||||||
inventory.removeItem(toRemove);
|
// if (mcMMO.getConfigManager().getConfigRepair().getRepairGeneral().isAnvilUseSounds()) {
|
||||||
|
// SoundManager.sendSound(player, player.getLocation(), SoundType.ANVIL);
|
||||||
// Give out XP like candy
|
// SoundManager.sendSound(player, player.getLocation(), SoundType.ITEM_BREAK);
|
||||||
applyXpGain(((getPercentageRepaired(startDurability, newDurability, repairable.getMaximumDurability())
|
// }
|
||||||
* repairable.getXpMultiplier())
|
//
|
||||||
* mcMMO.getConfigManager().getConfigExperience().getRepairXPBase())
|
// // Repair the item!
|
||||||
* mcMMO.getConfigManager().getConfigExperience().getExperienceRepair().getItemMaterialXPMultiplier(repairable.getRepairItemMaterialCategory()), XPGainReason.PVE);
|
// item.setDurability(newDurability);
|
||||||
|
|
||||||
// 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) {
|
private double getPercentageRepaired(short startDurability, short newDurability, short totalDurability) {
|
||||||
|
@ -15,7 +15,7 @@ public class RepairableManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerRepairable(Repairable repairable) {
|
public void registerRepairable(Repairable repairable) {
|
||||||
Material item = repairable.getItemMaterial();
|
Material item = repairable.getItem().getType();
|
||||||
repairables.put(item, repairable);
|
repairables.put(item, repairable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user