use of org.bukkit.command.CommandSender in project solinia3-core by mixxit.
the class CommandForceLevel 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 < 2) {
sender.sendMessage("Insufficient arguments (<mcname> <level>)");
return false;
}
String name = args[0];
int level = Integer.parseInt(args[1]);
if (level < 1) {
sender.sendMessage("Level must be greater than 0");
}
boolean found = false;
Double experience = Utils.getExperienceRequirementForLevel(level);
for (Player currentplayer : Bukkit.getServer().getOnlinePlayers()) {
if (!currentplayer.getName().toUpperCase().equals(name.toUpperCase()))
continue;
try {
ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(currentplayer);
found = true;
if (found) {
solplayer.setExperience(experience);
sender.sendMessage("* Player " + name + " set to " + level);
solplayer.updateMaxHp();
return true;
} else {
sender.sendMessage("Force level command failed. Is that a valid level and a valid online mcaccount?");
return false;
}
} catch (CoreStateInitException e) {
e.printStackTrace();
sender.sendMessage(e.getMessage());
}
}
if (found == false) {
sender.sendMessage("Failed to find player by that minecraft username");
return false;
}
return true;
}
use of org.bukkit.command.CommandSender in project solinia3-core by mixxit.
the class CommandListSpells 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 == 0) {
sender.sendMessage("You must provide some text to filter the spells by");
return true;
}
// Filter for name
int found = 0;
try {
for (ISoliniaSpell spell : StateManager.getInstance().getConfigurationManager().getSpells()) {
found++;
if (spell.getName().toUpperCase().contains(args[0].toUpperCase())) {
String spellmessage = spell.getId() + " - " + spell.getName();
sender.sendMessage(spellmessage);
}
}
if (found == 0) {
sender.sendMessage("Spell could not be located by search string");
}
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
sender.sendMessage(e.getMessage());
e.printStackTrace();
}
return true;
}
use of org.bukkit.command.CommandSender in project solinia3-core by mixxit.
the class CommandEditNpcEvent 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 == 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.sendNPCEvents(sender);
} else {
sender.sendMessage("NPC ID doesnt exist");
}
return true;
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
}
}
String triggertext = args[1];
if (args.length == 2) {
try {
ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
if (npc != null) {
boolean found = false;
for (ISoliniaNPCEventHandler handler : npc.getEventHandlers()) {
if (handler.getTriggerdata().toUpperCase().equals(triggertext.toUpperCase())) {
found = true;
npc.sendNPCEvent(sender, triggertext);
}
}
if (found == false) {
sender.sendMessage("Trigger event doesnt exist on npc");
}
} else {
sender.sendMessage("NPC ID doesnt exist");
}
return true;
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
}
}
if (args.length < 4) {
sender.sendMessage("Insufficient arguments: npcid triggertext setting value");
return false;
}
String setting = args[2];
String value = args[3];
// for 'text' based npc settings like trigger texts etc, get the whole thing as a string
if (args.length > 4 && (setting.toLowerCase().equals("chatresponse") || setting.toLowerCase().equals("title") || setting.toLowerCase().equals("randomisedgearsuffix"))) {
value = "";
int current = 0;
for (String entry : args) {
current++;
if (current <= 3)
continue;
value = value + entry + " ";
}
value = value.trim();
}
if (npcid < 1) {
sender.sendMessage("Invalid NPC id");
return false;
}
try {
ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
if (npc != null) {
boolean found = false;
for (ISoliniaNPCEventHandler handler : npc.getEventHandlers()) {
if (handler.getTriggerdata().toUpperCase().equals(triggertext.toUpperCase())) {
found = true;
}
}
if (found == false) {
sender.sendMessage("Trigger event doesnt exist on npc");
return false;
}
} else {
sender.sendMessage("NPC ID doesnt exist");
return false;
}
StateManager.getInstance().getConfigurationManager().editNpcTriggerEvent(npcid, triggertext, setting, value);
sender.sendMessage("Updating setting on NPC Event");
} catch (InvalidNPCEventSettingException ne) {
sender.sendMessage("Invalid NPC Event 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 CommandGrantTitle 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;
if (Bukkit.getPlayer(args[0]) == null) {
sender.sendMessage("Cannot find player");
return true;
}
String targetTitle = "";
int current = 0;
for (String entry : args) {
current++;
if (current < 2)
continue;
targetTitle = targetTitle + entry + " ";
}
targetTitle = targetTitle.trim();
try {
ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(Bukkit.getPlayer(args[0]));
boolean success = solplayer.grantTitle(targetTitle);
if (success)
sender.sendMessage("Player title granted: " + targetTitle);
else
sender.sendMessage("Player already has title: " + targetTitle);
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 CommandListItems 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.listitems")) {
player.sendMessage("You do not have permission to access this command");
return false;
}
}
if (args.length == 0) {
sender.sendMessage("You must provide some text to filter the item name by");
return true;
}
// Filter for name
int found = 0;
try {
for (ISoliniaItem item : StateManager.getInstance().getConfigurationManager().getItems()) {
found++;
if (item.getDisplayname().toUpperCase().contains(args[0].toUpperCase())) {
String itemmessage = item.getId() + " - " + item.getDisplayname();
sender.sendMessage(itemmessage);
}
}
if (found == 0) {
sender.sendMessage("Item could not be located by search string");
}
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
sender.sendMessage(e.getMessage());
e.printStackTrace();
}
return true;
}
Aggregations