Project cleanup pre merge.
This commit is contained in:
@@ -21,236 +21,234 @@ import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Eighty
|
||||
*
|
||||
*/
|
||||
public class MakeItemCmd extends AbstractDevCmd {
|
||||
|
||||
public MakeItemCmd() {
|
||||
public MakeItemCmd() {
|
||||
super("makeitem");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pc, String[] words,
|
||||
AbstractGameObject target) {
|
||||
|
||||
if (words[0].equals("resources")){
|
||||
for (int ibID : Warehouse.getMaxResources().keySet()){
|
||||
if (ibID == 7)
|
||||
continue;
|
||||
|
||||
ItemBase ib = ItemBase.getItemBase(ibID);
|
||||
|
||||
short weight = ib.getWeight();
|
||||
if (!pc.getCharItemManager().hasRoomInventory(weight)) {
|
||||
throwbackError(pc, "Not enough room in inventory for any more of this item");
|
||||
|
||||
pc.getCharItemManager().updateInventory();
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pc, String[] words,
|
||||
AbstractGameObject target) {
|
||||
|
||||
boolean worked = false;
|
||||
Item item = new Item(ib, pc.getObjectUUID(),
|
||||
OwnerType.PlayerCharacter, (byte)0, (byte)0, (short)ib.getDurability(), (short)ib.getDurability(),
|
||||
true, false, ItemContainerType.INVENTORY, (byte) 0,
|
||||
new ArrayList<>(),"");
|
||||
|
||||
item.setNumOfItems(Warehouse.getMaxResources().get(ibID));
|
||||
if (words[0].equals("resources")) {
|
||||
for (int ibID : Warehouse.getMaxResources().keySet()) {
|
||||
if (ibID == 7)
|
||||
continue;
|
||||
|
||||
try {
|
||||
item = DbManager.ItemQueries.ADD_ITEM(item);
|
||||
worked = true;
|
||||
} catch (Exception e) {
|
||||
throwbackError(pc, "DB error 1: Unable to create item. " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
ItemBase ib = ItemBase.getItemBase(ibID);
|
||||
|
||||
if (item == null || !worked) {
|
||||
throwbackError(pc, "DB error 2: Unable to create item.");
|
||||
return;
|
||||
}
|
||||
short weight = ib.getWeight();
|
||||
if (!pc.getCharItemManager().hasRoomInventory(weight)) {
|
||||
throwbackError(pc, "Not enough room in inventory for any more of this item");
|
||||
|
||||
|
||||
pc.getCharItemManager().updateInventory();
|
||||
return;
|
||||
}
|
||||
|
||||
//add item to inventory
|
||||
pc.getCharItemManager().addItemToInventory(item);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (words.length < 3 || words.length > 5) {
|
||||
this.sendUsage(pc);
|
||||
return;
|
||||
}
|
||||
boolean worked = false;
|
||||
Item item = new Item(ib, pc.getObjectUUID(),
|
||||
OwnerType.PlayerCharacter, (byte) 0, (byte) 0, (short) ib.getDurability(), (short) ib.getDurability(),
|
||||
true, false, ItemContainerType.INVENTORY, (byte) 0,
|
||||
new ArrayList<>(), "");
|
||||
|
||||
int quantity = 1;
|
||||
if (words.length > 3) {
|
||||
try {
|
||||
quantity = Integer.parseInt(words[3]);
|
||||
} catch (NumberFormatException e) {
|
||||
throwbackError(pc, "Quantity must be a number, " + words[3] + " is invalid");
|
||||
return;
|
||||
}
|
||||
if (quantity < 1 || quantity > 100)
|
||||
quantity = 1;
|
||||
}
|
||||
item.setNumOfItems(Warehouse.getMaxResources().get(ibID));
|
||||
|
||||
int numItems = 1;
|
||||
if (words.length > 4) {
|
||||
try {
|
||||
numItems = Integer.parseInt(words[4]);
|
||||
} catch (NumberFormatException e) {
|
||||
throwbackError(pc, "numResources must be a number, " + words[4] + " is invalid");
|
||||
return;
|
||||
}
|
||||
numItems = (numItems < 1) ? 1 : numItems;
|
||||
numItems = (numItems > 5000) ? 5000 : numItems;
|
||||
}
|
||||
try {
|
||||
item = DbManager.ItemQueries.ADD_ITEM(item);
|
||||
worked = true;
|
||||
} catch (Exception e) {
|
||||
throwbackError(pc, "DB error 1: Unable to create item. " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
int itembaseID;
|
||||
try {
|
||||
itembaseID = Integer.parseInt(words[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
itembaseID = ItemBase.getIDByName(words[0].toLowerCase());
|
||||
if (itembaseID == 0) {
|
||||
throwbackError(pc, "Supplied type " + words[0]
|
||||
+ " failed to parse to an Integer");
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throwbackError(pc,
|
||||
"An unknown exception occurred when trying to use createitem command for type "
|
||||
+ words[0]);
|
||||
return; // NaN
|
||||
}
|
||||
if (item == null || !worked) {
|
||||
throwbackError(pc, "DB error 2: Unable to create item.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (itembaseID == 7) {
|
||||
this.throwbackInfo(pc, "use /addgold to add gold.");
|
||||
return;
|
||||
}
|
||||
|
||||
String prefix = "";
|
||||
String suffix = "";
|
||||
//add item to inventory
|
||||
pc.getCharItemManager().addItemToInventory(item);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (words.length < 3 || words.length > 5) {
|
||||
this.sendUsage(pc);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(words[1].equals("0"))) {
|
||||
prefix = words[1];
|
||||
if (!(prefix.substring(0, 4).equals("PRE-")))
|
||||
prefix = EffectsBase.getItemEffectsByName(prefix.toLowerCase());
|
||||
if (!(prefix.substring(0, 4).equals("PRE-"))) {
|
||||
throwbackError(pc, "Invalid Prefix. Prefix must consist of PRE-001 to PRE-334 or 0 for no Prefix.");
|
||||
return;
|
||||
}
|
||||
int quantity = 1;
|
||||
if (words.length > 3) {
|
||||
try {
|
||||
quantity = Integer.parseInt(words[3]);
|
||||
} catch (NumberFormatException e) {
|
||||
throwbackError(pc, "Quantity must be a number, " + words[3] + " is invalid");
|
||||
return;
|
||||
}
|
||||
if (quantity < 1 || quantity > 100)
|
||||
quantity = 1;
|
||||
}
|
||||
|
||||
boolean validInt = false;
|
||||
try {
|
||||
int num = Integer.parseInt(prefix.substring(4, 7));
|
||||
if (num > 0 && num < 335)
|
||||
validInt = true;
|
||||
} catch (Exception e) {
|
||||
throwbackError(pc, "error parsing number " + prefix);
|
||||
}
|
||||
if (!validInt) {
|
||||
throwbackError(pc, "Invalid Prefix. Prefix must consist of PRE-001 to PRE-334 or 0 for no Prefix.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
int numItems = 1;
|
||||
if (words.length > 4) {
|
||||
try {
|
||||
numItems = Integer.parseInt(words[4]);
|
||||
} catch (NumberFormatException e) {
|
||||
throwbackError(pc, "numResources must be a number, " + words[4] + " is invalid");
|
||||
return;
|
||||
}
|
||||
numItems = (numItems < 1) ? 1 : numItems;
|
||||
numItems = (numItems > 5000) ? 5000 : numItems;
|
||||
}
|
||||
|
||||
if (!(words[2].equals("0"))) {
|
||||
suffix = words[2];
|
||||
int itembaseID;
|
||||
try {
|
||||
itembaseID = Integer.parseInt(words[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
itembaseID = ItemBase.getIDByName(words[0].toLowerCase());
|
||||
if (itembaseID == 0) {
|
||||
throwbackError(pc, "Supplied type " + words[0]
|
||||
+ " failed to parse to an Integer");
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throwbackError(pc,
|
||||
"An unknown exception occurred when trying to use createitem command for type "
|
||||
+ words[0]);
|
||||
return; // NaN
|
||||
}
|
||||
|
||||
if (!(suffix.substring(0, 4).equals("SUF-")))
|
||||
suffix = EffectsBase.getItemEffectsByName(suffix.toLowerCase());
|
||||
if (!(suffix.substring(0, 4).equals("SUF-"))) {
|
||||
throwbackError(pc, "Invalid Suffix. Suffix must consist of SUF-001 to SUF-328 or 0 for no Suffix.");
|
||||
return;
|
||||
}
|
||||
if (itembaseID == 7) {
|
||||
this.throwbackInfo(pc, "use /addgold to add gold.");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean validInt = false;
|
||||
try {
|
||||
int num = Integer.parseInt(suffix.substring(4, 7));
|
||||
if (num > 0 && num < 329)
|
||||
validInt = true;
|
||||
} catch (Exception e) {
|
||||
throwbackError(pc, "error parsing number " + suffix);
|
||||
}
|
||||
if (!validInt) {
|
||||
throwbackError(pc, "Invalid Suffix. Suffix must consist of SUF-001 to SUF-328 or 0 for no Suffix.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
ItemBase ib = ItemBase.getItemBase(itembaseID);
|
||||
if (ib == null) {
|
||||
throwbackError(pc, "Unable to find itembase of ID " + itembaseID);
|
||||
return;
|
||||
}
|
||||
String prefix = "";
|
||||
String suffix = "";
|
||||
|
||||
if ((numItems > 1)
|
||||
&& (ib.getType().equals(ItemType.RESOURCE) == false)
|
||||
&& (ib.getType().equals(ItemType.OFFERING)) == false)
|
||||
numItems = 1;
|
||||
if (!(words[1].equals("0"))) {
|
||||
prefix = words[1];
|
||||
if (!(prefix.substring(0, 4).equals("PRE-")))
|
||||
prefix = EffectsBase.getItemEffectsByName(prefix.toLowerCase());
|
||||
if (!(prefix.substring(0, 4).equals("PRE-"))) {
|
||||
throwbackError(pc, "Invalid Prefix. Prefix must consist of PRE-001 to PRE-334 or 0 for no Prefix.");
|
||||
return;
|
||||
}
|
||||
|
||||
CharacterItemManager cim = pc.getCharItemManager();
|
||||
if (cim == null) {
|
||||
throwbackError(pc, "Unable to find the character item manager for player " + pc.getFirstName() + '.');
|
||||
return;
|
||||
}
|
||||
boolean validInt = false;
|
||||
try {
|
||||
int num = Integer.parseInt(prefix.substring(4, 7));
|
||||
if (num > 0 && num < 335)
|
||||
validInt = true;
|
||||
} catch (Exception e) {
|
||||
throwbackError(pc, "error parsing number " + prefix);
|
||||
}
|
||||
if (!validInt) {
|
||||
throwbackError(pc, "Invalid Prefix. Prefix must consist of PRE-001 to PRE-334 or 0 for no Prefix.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
byte charges = (byte) ib.getNumCharges();
|
||||
short dur = (short) ib.getDurability();
|
||||
if (!(words[2].equals("0"))) {
|
||||
suffix = words[2];
|
||||
|
||||
String result = "";
|
||||
for (int i = 0; i < quantity; i++) {
|
||||
short weight = ib.getWeight();
|
||||
if (!cim.hasRoomInventory(weight)) {
|
||||
throwbackError(pc, "Not enough room in inventory for any more of this item. " + i + " produced.");
|
||||
if (i > 0)
|
||||
cim.updateInventory();
|
||||
return;
|
||||
}
|
||||
if (!(suffix.substring(0, 4).equals("SUF-")))
|
||||
suffix = EffectsBase.getItemEffectsByName(suffix.toLowerCase());
|
||||
if (!(suffix.substring(0, 4).equals("SUF-"))) {
|
||||
throwbackError(pc, "Invalid Suffix. Suffix must consist of SUF-001 to SUF-328 or 0 for no Suffix.");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean worked = false;
|
||||
Item item = new Item(ib, pc.getObjectUUID(),
|
||||
OwnerType.PlayerCharacter, charges, charges, dur, dur,
|
||||
true, false, ItemContainerType.INVENTORY, (byte) 0,
|
||||
new ArrayList<>(),"");
|
||||
if (numItems > 1)
|
||||
item.setNumOfItems(numItems);
|
||||
boolean validInt = false;
|
||||
try {
|
||||
int num = Integer.parseInt(suffix.substring(4, 7));
|
||||
if (num > 0 && num < 329)
|
||||
validInt = true;
|
||||
} catch (Exception e) {
|
||||
throwbackError(pc, "error parsing number " + suffix);
|
||||
}
|
||||
if (!validInt) {
|
||||
throwbackError(pc, "Invalid Suffix. Suffix must consist of SUF-001 to SUF-328 or 0 for no Suffix.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
ItemBase ib = ItemBase.getItemBase(itembaseID);
|
||||
if (ib == null) {
|
||||
throwbackError(pc, "Unable to find itembase of ID " + itembaseID);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
item = DbManager.ItemQueries.ADD_ITEM(item);
|
||||
worked = true;
|
||||
} catch (Exception e) {
|
||||
throwbackError(pc, "DB error 1: Unable to create item. " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
if ((numItems > 1)
|
||||
&& (ib.getType().equals(ItemType.RESOURCE) == false)
|
||||
&& (ib.getType().equals(ItemType.OFFERING)) == false)
|
||||
numItems = 1;
|
||||
|
||||
if (item == null || !worked) {
|
||||
throwbackError(pc, "DB error 2: Unable to create item.");
|
||||
return;
|
||||
}
|
||||
CharacterItemManager cim = pc.getCharItemManager();
|
||||
if (cim == null) {
|
||||
throwbackError(pc, "Unable to find the character item manager for player " + pc.getFirstName() + '.');
|
||||
return;
|
||||
}
|
||||
|
||||
//create prefix
|
||||
if (!prefix.isEmpty())
|
||||
item.addPermanentEnchantmentForDev(prefix, 0);
|
||||
byte charges = (byte) ib.getNumCharges();
|
||||
short dur = (short) ib.getDurability();
|
||||
|
||||
//create suffix
|
||||
if (!suffix.isEmpty())
|
||||
item.addPermanentEnchantmentForDev(suffix, 0);
|
||||
String result = "";
|
||||
for (int i = 0; i < quantity; i++) {
|
||||
short weight = ib.getWeight();
|
||||
if (!cim.hasRoomInventory(weight)) {
|
||||
throwbackError(pc, "Not enough room in inventory for any more of this item. " + i + " produced.");
|
||||
if (i > 0)
|
||||
cim.updateInventory();
|
||||
return;
|
||||
}
|
||||
|
||||
//add item to inventory
|
||||
cim.addItemToInventory(item);
|
||||
result += " " + item.getObjectUUID();
|
||||
}
|
||||
this.setResult(result);
|
||||
cim.updateInventory();
|
||||
}
|
||||
boolean worked = false;
|
||||
Item item = new Item(ib, pc.getObjectUUID(),
|
||||
OwnerType.PlayerCharacter, charges, charges, dur, dur,
|
||||
true, false, ItemContainerType.INVENTORY, (byte) 0,
|
||||
new ArrayList<>(), "");
|
||||
if (numItems > 1)
|
||||
item.setNumOfItems(numItems);
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
try {
|
||||
item = DbManager.ItemQueries.ADD_ITEM(item);
|
||||
worked = true;
|
||||
} catch (Exception e) {
|
||||
throwbackError(pc, "DB error 1: Unable to create item. " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (item == null || !worked) {
|
||||
throwbackError(pc, "DB error 2: Unable to create item.");
|
||||
return;
|
||||
}
|
||||
|
||||
//create prefix
|
||||
if (!prefix.isEmpty())
|
||||
item.addPermanentEnchantmentForDev(prefix, 0);
|
||||
|
||||
//create suffix
|
||||
if (!suffix.isEmpty())
|
||||
item.addPermanentEnchantmentForDev(suffix, 0);
|
||||
|
||||
//add item to inventory
|
||||
cim.addItemToInventory(item);
|
||||
result += " " + item.getObjectUUID();
|
||||
}
|
||||
this.setResult(result);
|
||||
cim.updateInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Creates an item of type 'itembaseID' with a prefix and suffix";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "'./makeitem itembaseID PrefixID SuffixID [quantity] [numResources]'";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user