Originally Posted by
RiiPiiNFtW
Make an array, and loop through it.
He obviously has no clue what an array is, nor how to use one. I believe that is the reason behind him making this post.
OT: I will show you how below...
first, create an array with all the item id's you do not want people to spawn like so:
Code:
public final int[] NO_SPAWN = {995,6950,15272};
When you add in item id's, just add a comma to seperate that id from the others in the array.
Then your spawn method should looking something like this:
Code:
public void execute(Client client, String command) {
if (client.isOwner() || client.isAlan()) {
try {
String[] args = command.split(" ");
if (args.length == 2) {
int newItemID = Integer.parseInt(args[1]);
if ((newItemID < Config.ITEM_LIMIT) && (newItemID > 0)) {
client.getItems().addItem(newItemID, 1);
} else {
client.sendMessage("You cannot spawn items that high.");
}
} else if (args.length == 3) {
int newItemID = Integer.parseInt(args[1]);
int newItemAmount = Integer.parseInt(args[2]);
if ((newItemID < Config.ITEM_LIMIT) && (newItemID > 0)) {
client.getItems().addItem(newItemID, newItemAmount);
} else {
client.sendMessage("You cannot spawn items that high.");
}
} else {
client.sendMessage("Use as ::item 995 100");
}
} catch (Exception e) {
}
}
}
Yours is most likely different because i re-formatted my commands.
Add this in:
Code:
for(int no : NO_SPAWN){
if(newItemID == no){
c.sendMessage("You cannot spawn this item!");
return;
}
}
So it looks like this:
Code:
package server.model.players.Content.command.impl;
import server.Config;
import server.model.players.Client;
import server.model.players.Content.command.CommandHandler;
public class Item implements CommandHandler {
public void execute(Client client, String command) {
if (client.isOwner() || client.isAlan()) {
try {
String[] args = command.split(" ");
if (args.length == 2) {
int newItemID = Integer.parseInt(args[1]);
for(int no : NO_SPAWN){
if(newItemID == no){
c.sendMessage("You cannot spawn this item!");
return;
}
}
if ((newItemID < Config.ITEM_LIMIT) && (newItemID > 0)) {
client.getItems().addItem(newItemID, 1);
} else {
client.sendMessage("You cannot spawn items that high.");
}
} else if (args.length == 3) {
int newItemID = Integer.parseInt(args[1]);
int newItemAmount = Integer.parseInt(args[2]);
for(int no : NO_SPAWN){
if(newItemID == no){
c.sendMessage("You cannot spawn this item!");
return;
}
}
if ((newItemID < Config.ITEM_LIMIT) && (newItemID > 0)) {
client.getItems().addItem(newItemID, newItemAmount);
} else {
client.sendMessage("You cannot spawn items that high.");
}
} else {
client.sendMessage("Use as ::item 995 100");
}
} catch (Exception e) {
}
}
}
}