mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-01-31 14:49:35 +01:00
Cleanup.
This commit is contained in:
parent
d7b8ec1274
commit
9525ce8299
@ -14,12 +14,10 @@ import com.gmail.nossr50.skills.repair.Repairable;
|
||||
import com.gmail.nossr50.skills.repair.RepairableFactory;
|
||||
|
||||
public class RepairConfig extends ConfigLoader {
|
||||
private final String fileName;
|
||||
private List<Repairable> repairables;
|
||||
|
||||
public RepairConfig(mcMMO plugin, String fileName) {
|
||||
super(plugin, fileName);
|
||||
this.fileName = fileName;
|
||||
this.config = YamlConfiguration.loadConfiguration(this.configFile);
|
||||
}
|
||||
|
||||
@ -34,19 +32,19 @@ public class RepairConfig extends ConfigLoader {
|
||||
|
||||
ConfigurationSection section = config.getConfigurationSection("Repairables");
|
||||
Set<String> keys = section.getKeys(false);
|
||||
for(String key : keys) {
|
||||
for (String key : keys) {
|
||||
// Validate all the things!
|
||||
List<String> reason = new ArrayList<String>();
|
||||
|
||||
if(!config.contains("Repairables." + key + ".ItemId")) {
|
||||
if (!config.contains("Repairables." + key + ".ItemId")) {
|
||||
reason.add(key + " is missing ItemId");
|
||||
}
|
||||
|
||||
if(!config.contains("Repairables." + key + ".RepairMaterialId")) {
|
||||
if (!config.contains("Repairables." + key + ".RepairMaterialId")) {
|
||||
reason.add(key + " is missing RepairMaterialId");
|
||||
}
|
||||
|
||||
if(!config.contains("Repairables." + key + ".MaximumDurability")) {
|
||||
if (!config.contains("Repairables." + key + ".MaximumDurability")) {
|
||||
reason.add(key + " is missing MaximumDurability");
|
||||
}
|
||||
|
||||
@ -65,27 +63,29 @@ public class RepairConfig extends ConfigLoader {
|
||||
String repairItemTypeString = config.getString("Repairables." + key + ".ItemType", "OTHER");
|
||||
String repairMaterialTypeString = config.getString("Repairables." + key + ".MaterialType", "OTHER");
|
||||
|
||||
if(minimumLevel < 0) {
|
||||
if (minimumLevel < 0) {
|
||||
reason.add(key + " has an invalid MinimumLevel of " + minimumLevel);
|
||||
}
|
||||
|
||||
if(minimumQuantity < 0) {
|
||||
if (minimumQuantity < 0) {
|
||||
reason.add(key + " has an invalid MinimumQuantity of " + minimumQuantity);
|
||||
}
|
||||
|
||||
try {
|
||||
repairItemType = RepairItemType.valueOf(repairItemTypeString);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
reason.add(key + " has an invalid ItemType of " + repairItemTypeString);
|
||||
}
|
||||
|
||||
try {
|
||||
repairMaterialType = RepairMaterialType.valueOf(repairMaterialTypeString);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
reason.add(key + " has an invalid MaterialType of " + repairMaterialTypeString);
|
||||
}
|
||||
|
||||
if(noErrorsInRepairable(reason)) {
|
||||
if (noErrorsInRepairable(reason)) {
|
||||
Repairable repairable = RepairableFactory.getRepairable(itemId, repairMaterialId, (byte) repairMetadata, minimumLevel, minimumQuantity, (short) maximumDurability, repairItemType, repairMaterialType, xpMultiplier);
|
||||
repairables.add(repairable);
|
||||
}
|
||||
@ -93,7 +93,10 @@ public class RepairConfig extends ConfigLoader {
|
||||
}
|
||||
|
||||
protected List<Repairable> getLoadedRepairables() {
|
||||
if(repairables == null) return new ArrayList<Repairable>();
|
||||
if (repairables == null) {
|
||||
return new ArrayList<Repairable>();
|
||||
}
|
||||
|
||||
return repairables;
|
||||
}
|
||||
|
||||
|
@ -19,10 +19,13 @@ public enum RepairItemType {
|
||||
switch (this) {
|
||||
case ARMOR:
|
||||
return Permissions.getInstance().armorRepair(player);
|
||||
|
||||
case TOOL:
|
||||
return Permissions.getInstance().toolRepair(player);
|
||||
|
||||
case OTHER:
|
||||
return Permissions.getInstance().otherRepair(player);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -24,20 +24,28 @@ public enum RepairMaterialType {
|
||||
switch (this) {
|
||||
case STRING:
|
||||
return Permissions.getInstance().stringRepair(player);
|
||||
|
||||
case LEATHER:
|
||||
return Permissions.getInstance().leatherRepair(player);
|
||||
|
||||
case WOOD:
|
||||
return Permissions.getInstance().woodRepair(player);
|
||||
|
||||
case STONE:
|
||||
return Permissions.getInstance().stoneRepair(player);
|
||||
|
||||
case IRON:
|
||||
return Permissions.getInstance().ironRepair(player);
|
||||
|
||||
case GOLD:
|
||||
return Permissions.getInstance().goldRepair(player);
|
||||
|
||||
case DIAMOND:
|
||||
return Permissions.getInstance().diamondRepair(player);
|
||||
|
||||
case OTHER:
|
||||
return Permissions.getInstance().otherMaterialRepair(player);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class SimpleRepairManager implements RepairManager {
|
||||
|
||||
@Override
|
||||
public void registerRepairables(List<Repairable> repairables) {
|
||||
for(Repairable repairable : repairables) {
|
||||
for (Repairable repairable : repairables) {
|
||||
registerRepairable(repairable);
|
||||
}
|
||||
}
|
||||
@ -67,28 +67,28 @@ public class SimpleRepairManager implements RepairManager {
|
||||
Repairable repairable = repairables.get(item.getTypeId());
|
||||
|
||||
// Permissions checks on material and item types
|
||||
if(!repairable.getRepairItemType().getPermissions(player)) {
|
||||
if (!repairable.getRepairItemType().getPermissions(player)) {
|
||||
player.sendMessage(LocaleLoader.getString("mcMMO.NoPermission"));
|
||||
return;
|
||||
}
|
||||
|
||||
if(!repairable.getRepairMaterialType().getPermissions(player)) {
|
||||
if (!repairable.getRepairMaterialType().getPermissions(player)) {
|
||||
player.sendMessage(LocaleLoader.getString("mcMMO.NoPermission"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Level check
|
||||
if(skillLevel < repairable.getMinimumLevel()) {
|
||||
if (skillLevel < repairable.getMinimumLevel()) {
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Skills.Adept", new Object[] { String.valueOf(repairable.getMinimumLevel()), Misc.prettyItemString(item.getTypeId()) } ));
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if they have the proper material to repair with
|
||||
if(!inventory.contains(repairable.getRepairMaterialId())) {
|
||||
if (!inventory.contains(repairable.getRepairMaterialId())) {
|
||||
String message = LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.YELLOW + Misc.prettyItemString(repairable.getRepairMaterialId());
|
||||
if(repairable.getRepairMaterialMetadata() != (byte) -1) {
|
||||
if (repairable.getRepairMaterialMetadata() != (byte) -1) {
|
||||
// TODO: Do something nicer than append the metadata as a :# ?
|
||||
if(findInInventory(inventory, repairable.getRepairMaterialId(), repairable.getRepairMaterialMetadata()) == -1) {
|
||||
if (findInInventory(inventory, repairable.getRepairMaterialId(), repairable.getRepairMaterialMetadata()) == -1) {
|
||||
message += ":" + repairable.getRepairMaterialMetadata();
|
||||
}
|
||||
}
|
||||
@ -97,33 +97,34 @@ public class SimpleRepairManager implements RepairManager {
|
||||
}
|
||||
|
||||
// Do not repair if at full durability
|
||||
if(startDurability <= 0) {
|
||||
if (startDurability <= 0) {
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Skills.FullDurability"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not repair stacked items
|
||||
if(item.getAmount() != 1) {
|
||||
if (item.getAmount() != 1) {
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Skills.StackedItems"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Lets get down to business,
|
||||
// To defeat, the huns.
|
||||
int baseRepairAmount = repairable.getBaseRepairDurability();
|
||||
short newDurability = Repair.repairCalculate(player, skillLevel, startDurability, baseRepairAmount);
|
||||
int baseRepairAmount = repairable.getBaseRepairDurability(); // Did they send me daughters?
|
||||
short newDurability = Repair.repairCalculate(player, skillLevel, startDurability, baseRepairAmount); // When I asked for sons?
|
||||
|
||||
// We're going to hold onto our repair item location
|
||||
int repairItemLocation;
|
||||
if(repairable.getRepairMaterialMetadata() == (byte) -1) {
|
||||
if (repairable.getRepairMaterialMetadata() == (byte) -1) {
|
||||
repairItemLocation = findInInventory(inventory, repairable.getRepairMaterialId());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// Special case for when the repairable has metadata that must be addressed
|
||||
repairItemLocation = findInInventory(inventory, repairable.getRepairMaterialId(), repairable.getRepairMaterialMetadata());
|
||||
}
|
||||
|
||||
// This should never happen, but if it does we need to complain loudly about it.
|
||||
if(repairItemLocation == -1) {
|
||||
if (repairItemLocation == -1) {
|
||||
player.sendMessage("mcMMO encountered an error attempting to repair this item!"); // TODO: Locale ?
|
||||
return;
|
||||
}
|
||||
@ -160,9 +161,10 @@ public class SimpleRepairManager implements RepairManager {
|
||||
*/
|
||||
private void removeOneFrom(PlayerInventory inventory, int index) {
|
||||
ItemStack item = inventory.getItem(index);
|
||||
if(item.getAmount() > 1) {
|
||||
if (item.getAmount() > 1) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
item = new ItemStack(0);
|
||||
}
|
||||
|
||||
@ -179,10 +181,12 @@ public class SimpleRepairManager implements RepairManager {
|
||||
*/
|
||||
private int findInInventory(PlayerInventory inventory, int itemId) {
|
||||
int location = inventory.first(itemId);
|
||||
|
||||
// VALIDATE
|
||||
if(inventory.getItem(location).getTypeId() == itemId) {
|
||||
if (inventory.getItem(location).getTypeId() == itemId) {
|
||||
return location;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -199,14 +203,16 @@ public class SimpleRepairManager implements RepairManager {
|
||||
int location = -1;
|
||||
|
||||
ItemStack[] contents = inventory.getContents();
|
||||
for(int i = 0; i < contents.length; i++) {
|
||||
for (int i = 0; i < contents.length; i++) {
|
||||
ItemStack item = contents[i];
|
||||
if(item.getTypeId() == itemId) {
|
||||
if(item.getData().getData() == metadata) {
|
||||
if (item.getTypeId() == itemId) {
|
||||
if (item.getData().getData() == metadata) {
|
||||
location = i;
|
||||
}
|
||||
}
|
||||
if(location != -1) break;
|
||||
if (location != -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return location;
|
||||
|
Loading…
x
Reference in New Issue
Block a user