use of org.bukkit.command.CommandSender in project solinia3-core by mixxit.
the class CommandRebuildSpellItems method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player) && !(sender instanceof CommandSender)) {
sender.sendMessage("This is a Player/Console only command");
return false;
}
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp()) {
player.sendMessage("This is an operator only command");
return true;
}
}
int updated = 0;
sender.sendMessage("Rebuilding Item Lists, this may take some time");
try {
for (ISoliniaSpell spell : StateManager.getInstance().getConfigurationManager().getSpells()) {
int worth = 10;
int minLevel = 1;
int lowestLevel = 1000;
for (SoliniaSpellClass spellClass : spell.getAllowedClasses()) {
if (spellClass.getMinlevel() < lowestLevel)
lowestLevel = spellClass.getMinlevel();
}
if (lowestLevel > minLevel && lowestLevel < 100)
minLevel = lowestLevel;
worth = worth * minLevel;
// Spell exists
if (StateManager.getInstance().getConfigurationManager().getSpellItem(spell.getId()).size() > 0) {
for (ISoliniaItem item : StateManager.getInstance().getConfigurationManager().getSpellItem(spell.getId())) {
item.setAbilityid(spell.getId());
item.setDisplayname("Spell: " + spell.getName());
item.setSpellscroll(true);
item.setAllowedClassNames(new ArrayList<String>());
item.setLore("This appears to be some sort of magical spell that could be learned");
item.setWorth(worth);
StateManager.getInstance().getConfigurationManager().updateItem(item);
updated++;
}
} else {
// Doesnt exist, create it
ISoliniaItem item = SoliniaItemFactory.CreateItem(new ItemStack(Material.ENCHANTED_BOOK), sender.isOp());
item.setAbilityid(spell.getId());
item.setDisplayname("Spell: " + spell.getName());
item.setSpellscroll(true);
item.setAllowedClassNames(new ArrayList<String>());
item.setLore("This appears to be some sort of magical spell that could be learned");
item.setWorth(worth);
StateManager.getInstance().getConfigurationManager().updateItem(item);
updated++;
}
}
} catch (Exception e) {
e.printStackTrace();
sender.sendMessage(e.getMessage());
}
sender.sendMessage("Updated " + updated + " items");
return true;
}
use of org.bukkit.command.CommandSender in project solinia3-core by mixxit.
the class CommandConvertMerchantToLootDrop method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player) && !(sender instanceof CommandSender)) {
sender.sendMessage("This is a Player/Console only command");
return false;
}
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp() && !player.hasPermission("solinia.convertmerchanttolootdrop")) {
player.sendMessage("You do not have permission to access this command");
return false;
}
}
if (args.length < 5) {
sender.sendMessage("args: merchantid newlootdropname count always chance");
return true;
}
int merchant = Integer.parseInt(args[0]);
String name = args[1].toUpperCase();
int count = Integer.parseInt(args[2]);
boolean always = Boolean.parseBoolean(args[3]);
int chance = Integer.parseInt(args[4]);
if (name.length() > 25) {
sender.sendMessage("Lootdrop name cannot be longer than 25 characters");
return true;
}
try {
if (StateManager.getInstance().getConfigurationManager().getNPCMerchant(merchant) == null) {
sender.sendMessage("Cannot find merchantid");
return true;
}
if (StateManager.getInstance().getConfigurationManager().getLootDrop(name.toUpperCase()) != null) {
sender.sendMessage("Lootdrop name already in use");
return true;
}
SoliniaLootFactory.CreateLootDropFromMerchant(StateManager.getInstance().getConfigurationManager().getNPCMerchant(merchant), name, count, always, chance, sender.isOp());
sender.sendMessage("LootDrop Created: " + StateManager.getInstance().getConfigurationManager().getLootDrop(name.toUpperCase()).getId());
return true;
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
}
return false;
}
use of org.bukkit.command.CommandSender in project solinia3-core by mixxit.
the class CommandAddClass method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player) && !(sender instanceof CommandSender)) {
sender.sendMessage("This is a Player/Console only command");
return false;
}
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp()) {
player.sendMessage("This is an operator only command");
return true;
}
}
if (args.length < 2)
return false;
String classname = args[0];
boolean adminonly = Boolean.parseBoolean(args[1]);
try {
SoliniaClassFactory.CreateClass(classname, adminonly);
sender.sendMessage("* Class created");
} catch (CoreStateInitException | SoliniaClassCreationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
sender.sendMessage("Error: " + e.getMessage());
return true;
}
return true;
}
use of org.bukkit.command.CommandSender in project solinia3-core by mixxit.
the class CommandEditZone method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player) && !(sender instanceof CommandSender))
return false;
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp() && !player.hasPermission("solinia.editzone")) {
player.sendMessage("You do not have permission to access this command");
return false;
}
}
if (args.length < 1) {
sender.sendMessage("Insufficient arguments: zoneid");
return false;
}
if (args.length == 0) {
return false;
}
int zoneid = Integer.parseInt(args[0]);
if (args.length == 1) {
try {
SoliniaZone zone = StateManager.getInstance().getConfigurationManager().getZone(zoneid);
if (zone != null) {
zone.sendZoneSettingsToSender(sender);
} else {
sender.sendMessage("Zone ID doesnt exist");
}
return true;
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
}
}
if (args.length < 3) {
sender.sendMessage("Insufficient arguments: zoneid setting value");
return false;
}
String setting = args[1];
String value = args[2];
if (zoneid < 1) {
sender.sendMessage("Invalid zoneid");
return false;
}
try {
if (StateManager.getInstance().getConfigurationManager().getZone(zoneid) == null) {
sender.sendMessage("Cannot locate zone id: " + zoneid);
return false;
}
/*if (StateManager.getInstance().getConfigurationManager().getZone(zoneid).isOperatorCreated() && !sender.isOp())
{
sender.sendMessage("This zone was op created and you are not an op. Only ops can edit op zone items");
return false;
}*/
StateManager.getInstance().getConfigurationManager().editZone(zoneid, setting, value);
sender.sendMessage("Updating setting on Zone");
} catch (InvalidZoneSettingException ne) {
sender.sendMessage("Invalid zone setting: " + ne.getMessage());
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
sender.sendMessage(e.getMessage());
}
return true;
}
use of org.bukkit.command.CommandSender in project solinia3-core by mixxit.
the class CommandEquip method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player) && !(sender instanceof CommandSender))
return false;
Player player = (Player) sender;
try {
ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(player);
showCurrentEquippedItems(solPlayer);
ItemStack primaryItem = player.getInventory().getItemInMainHand();
if (primaryItem.getType().equals(Material.AIR)) {
player.sendMessage(ChatColor.GRAY + "Empty item in primary hand. You must hold the item you want to equip in your main hand");
return false;
}
if (!Utils.IsSoliniaItem(primaryItem)) {
player.sendMessage("You can only equip solinia items this way");
return true;
}
ISoliniaItem item = SoliniaItemAdapter.Adapt(primaryItem);
if (item == null) {
player.sendMessage("You cannot equip this item this way");
return true;
}
if (item.getMinLevel() > solPlayer.getLevel()) {
player.sendMessage("You cannot equip this item (minlevel: " + item.getMinLevel() + ")");
return true;
}
if (solPlayer.getClassObj() == null) {
player.sendMessage(ChatColor.GRAY + "Your class cannot wear this equipment");
return true;
}
if (item.isSpellscroll()) {
player.sendMessage("You cannot equip this item");
return true;
}
if (!item.getAllowedClassNames().contains(solPlayer.getClassObj().getName().toUpperCase())) {
player.sendMessage(ChatColor.GRAY + "Your class cannot wear this equipment");
return true;
}
if (item.getMinLevel() > solPlayer.getLevel()) {
player.sendMessage(ChatColor.GRAY + "Your are not sufficient level to wear this equipment");
return true;
}
if (item.isFingersItem())
if (solPlayer.getFingersItem() > 0) {
player.sendMessage("You have already equipped an item in that slot");
return true;
} else {
solPlayer.setFingersItem(item.getId());
player.getInventory().setItemInMainHand(null);
player.updateInventory();
player.sendMessage("You have equipped this item");
return true;
}
if (item.isShouldersItem())
if (solPlayer.getShouldersItem() > 0) {
player.sendMessage("You have already equipped an item in that slot");
return true;
} else {
solPlayer.setShouldersItem(item.getId());
player.getInventory().setItemInMainHand(null);
player.updateInventory();
player.sendMessage("You have equipped this item");
return true;
}
if (item.isNeckItem())
if (solPlayer.getNeckItem() > 0) {
player.sendMessage("You have already equipped an item in that slot");
return true;
} else {
solPlayer.setNeckItem(item.getId());
player.getInventory().setItemInMainHand(null);
player.updateInventory();
player.sendMessage("You have equipped this item");
return true;
}
return false;
} catch (CoreStateInitException e) {
return false;
} catch (SoliniaItemException e) {
player.sendMessage("You cannot equip this item");
return true;
}
}
Aggregations