use of org.bukkit.command.CommandSender in project solinia3-core by mixxit.
the class CommandEditNpc 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.editnpc")) {
player.sendMessage("You do not have permission to access this command");
return false;
}
}
if (args.length == 0) {
return false;
}
int npcid = Integer.parseInt(args[0]);
if (args.length == 1) {
try {
ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
if (npc != null) {
npc.sendNpcSettingsToSender(sender);
} else {
sender.sendMessage("NPC ID doesnt exist");
}
return true;
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
}
}
if (args.length < 3) {
sender.sendMessage("Insufficient arguments: npcid setting value");
return false;
}
String setting = args[1];
String value = args[2];
// for 'text' based npc settings like trigger texts etc, get the whole thing as a string
if (args.length > 3 && (setting.toLowerCase().contains("text") || setting.toLowerCase().contains("title"))) {
value = "";
int current = 0;
for (String entry : args) {
current++;
if (current <= 2)
continue;
value = value + entry + " ";
}
value = value.trim();
}
if (npcid < 1) {
sender.sendMessage("Invalid npc id");
return false;
}
try {
if (StateManager.getInstance().getConfigurationManager().getNPC(npcid) == null) {
sender.sendMessage("Cannot locate npc id: " + npcid);
return false;
}
if (StateManager.getInstance().getConfigurationManager().getNPC(npcid).isOperatorCreated() && !sender.isOp()) {
sender.sendMessage("This npc was op created and you are not an op. Only ops can edit op npcs");
return false;
}
try {
StateManager.getInstance().getConfigurationManager().editNPC(npcid, setting, value);
sender.sendMessage("Updating setting on npc");
} catch (java.io.IOException e) {
sender.sendMessage("Failed to update NPC - If this was a request to change custom head data, the mojang servers may be unable to fetch the player skin, try the same command again in a few moments");
}
} catch (InvalidNpcSettingException ne) {
sender.sendMessage("Invalid NPC 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 CommandCreateNPCEvent 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.sendMessage("This is an operator only command");
return false;
}
}
if (args.length < 4) {
sender.sendMessage("Insufficient arguments: npcid eventtype trigger response");
return false;
}
String response = "";
int counter = 0;
for (String entry : args) {
counter++;
if (counter < 4)
continue;
response += entry + " ";
}
if (response.length() > 0) {
response = response.trim();
}
if (response.equals("")) {
sender.sendMessage("Blank responses not allowed when creating an npc event");
return false;
}
Integer npcid = Integer.parseInt(args[0]);
String eventtype = args[1];
String trigger = args[2];
if (npcid < 1) {
sender.sendMessage("NPC does not exist");
return false;
}
try {
ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
if (npc == null) {
sender.sendMessage("NPC does not exist");
return false;
}
boolean foundtype = false;
InteractionType interactiontype = null;
for (InteractionType type : InteractionType.values()) {
if (!type.name().toUpperCase().equals(eventtype))
continue;
foundtype = true;
interactiontype = type;
break;
}
if (foundtype == false) {
sender.sendMessage("Cannot find interaction type specified");
return false;
}
if (trigger == null || trigger.equals("")) {
sender.sendMessage("Trigger provided is empty");
return false;
}
boolean exists = false;
for (ISoliniaNPCEventHandler seek : npc.getEventHandlers()) {
if (!seek.getInteractiontype().equals(interactiontype))
continue;
if (!seek.getTriggerdata().toUpperCase().equals(trigger))
continue;
exists = true;
}
if (exists) {
sender.sendMessage("Event handler already exists");
return false;
}
SoliniaNPCEventHandler eventhandler = new SoliniaNPCEventHandler();
eventhandler.setNpcId(npc.getId());
eventhandler.setInteractiontype(interactiontype);
eventhandler.setTriggerdata(trigger.toUpperCase());
eventhandler.setChatresponse(response);
npc.addEventHandler(eventhandler);
sender.sendMessage("New EventHandler added to NPC");
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
}
return true;
}
use of org.bukkit.command.CommandSender in project solinia3-core by mixxit.
the class CommandCreateFaction method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player) && !(sender instanceof CommandSender))
return false;
try {
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp() && !player.hasPermission("solinia.createfaction")) {
player.sendMessage("You do not have permission to access this command");
return false;
}
}
if (args.length < 2) {
sender.sendMessage("Insufficient arguments: basestandingvalue name");
return false;
}
// args
// defaultnpcid
// spawngroupname
int base = Integer.parseInt(args[0]);
String factionname = "";
int count = 0;
for (String entry : args) {
if (count == 0) {
count++;
continue;
}
factionname += entry;
count++;
}
if (factionname.equals("")) {
sender.sendMessage("Blank name not allowed when creating faction");
return false;
}
factionname = factionname.replace(" ", "_").toUpperCase();
if (StateManager.getInstance().getConfigurationManager().getFaction(factionname) != null) {
sender.sendMessage("Faction already exists");
return true;
}
ISoliniaFaction faction = SoliniaFactionFactory.CreateFaction(factionname, base, sender.isOp());
sender.sendMessage("Created faction: " + faction.getId());
return true;
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
sender.sendMessage(e.getMessage());
}
return true;
}
use of org.bukkit.command.CommandSender in project solinia3-core by mixxit.
the class CommandCreateItem 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.createitem")) {
player.sendMessage("You do not have permission to access this command");
return false;
}
}
ItemStack itemstack = null;
if (args.length == 0 && sender instanceof Player) {
Player player = (Player) sender;
itemstack = player.getInventory().getItemInMainHand();
if (itemstack.getType().equals(Material.AIR)) {
player.sendMessage(ChatColor.GRAY + "Empty item in hand. You must hold the item you want to make a new item from");
return false;
}
if (Utils.IsSoliniaItem(itemstack)) {
player.sendMessage("You can only create a new item from core minecraft items, not solinia items");
return true;
}
} else {
itemstack = new ItemStack(Material.valueOf(args[0]));
}
sender.sendMessage("Building new item based on: " + itemstack.getType().name());
try {
ISoliniaItem item = SoliniaItemFactory.CreateItem(itemstack, sender.isOp());
sender.sendMessage("New Item Created with ID: " + item.getId());
sender.sendMessage("Use /edititem ID to further edit this item");
} catch (Exception e) {
sender.sendMessage(e.getMessage());
}
return true;
}
use of org.bukkit.command.CommandSender in project solinia3-core by mixxit.
the class CommandCreateNpcCopy 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.createnpccopy")) {
player.sendMessage("You do not have permission to access this command");
return false;
}
}
if (args.length < 2) {
sender.sendMessage("Insufficient arguments: sourcenpcid npcname");
return false;
}
int npcid = Integer.parseInt(args[0]);
if (npcid < 1) {
sender.sendMessage("Invalid npc id");
return false;
}
try {
if (StateManager.getInstance().getConfigurationManager().getNPC(npcid) == null) {
sender.sendMessage("Cannot locate npc id: " + npcid);
return false;
}
String name = "";
int i = 0;
for (String element : args) {
if (i <= 0) {
i++;
continue;
}
name += element;
i++;
}
if (name.equals("")) {
sender.sendMessage("Name of NPC cannot be null");
return false;
}
if (name.length() > 16) {
sender.sendMessage("Name of NPC cannot exceed 16 characters");
return false;
}
name = name.replace(" ", "_");
ISoliniaNPC npc = SoliniaNPCFactory.CreateNPCCopy(npcid, name, sender.isOp());
sender.sendMessage("Created NPC Copy: " + npc.getId());
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
sender.sendMessage(e.getMessage());
}
return true;
}
Aggregations