use of net.md_5.bungee.api.CommandSender in project VotingPlugin by Ben12345rocks.
the class AdminVoteHelp method adminHelpText.
/**
* Admin help text.
*
* @param sender the sender
* @return the array list
*/
public ArrayList<TextComponent> adminHelpText(CommandSender sender) {
ArrayList<TextComponent> msg = new ArrayList<TextComponent>();
HashMap<String, TextComponent> unsorted = new HashMap<String, TextComponent>();
boolean requirePerms = plugin.getConfigFile().getFormatCommandsVoteHelpRequirePermission();
for (CommandHandler cmdHandle : plugin.getAdminVoteCommand()) {
if (!requirePerms || cmdHandle.hasPerm(sender)) {
unsorted.put(cmdHandle.getHelpLineCommand("/adminvote"), cmdHandle.getHelpLine("/adminvote"));
}
}
ArrayList<String> unsortedList = new ArrayList<String>();
unsortedList.addAll(unsorted.keySet());
Collections.sort(unsortedList, String.CASE_INSENSITIVE_ORDER);
for (String cmd : unsortedList) {
msg.add(unsorted.get(cmd));
}
return msg;
}
use of net.md_5.bungee.api.CommandSender in project VotingPlugin by Ben12345rocks.
the class VoteHelp method helpText.
public ArrayList<TextComponent> helpText(CommandSender sender) {
ArrayList<TextComponent> msg = new ArrayList<TextComponent>();
HashMap<String, TextComponent> unsorted = new HashMap<String, TextComponent>();
boolean requirePerms = plugin.getConfigFile().getFormatCommandsVoteHelpRequirePermission();
String colorStr = plugin.getConfigFile().getFormatCommandsVoteHelpHoverColor();
ChatColor hoverColor = null;
try {
hoverColor = ChatColor.of(colorStr);
} catch (Exception e) {
plugin.getLogger().warning("Failed to get color for hover help message");
e.printStackTrace();
hoverColor = ChatColor.AQUA;
}
for (CommandHandler cmdHandle : plugin.getVoteCommand()) {
if (!requirePerms || cmdHandle.hasPerm(sender)) {
unsorted.put(cmdHandle.getHelpLineCommand("/vote"), cmdHandle.getHelpLine("/vote", plugin.getConfigFile().getFormatCommandsVoteHelpLine(), hoverColor));
}
}
ArrayList<String> unsortedList = new ArrayList<String>();
unsortedList.addAll(unsorted.keySet());
Collections.sort(unsortedList, String.CASE_INSENSITIVE_ORDER);
for (String cmd : unsortedList) {
msg.add(unsorted.get(cmd));
}
return msg;
}
use of net.md_5.bungee.api.CommandSender in project solinia3-core by mixxit.
the class CommandClaim method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
try {
if (args.length < 1) {
sender.sendMessage(ChatColor.GRAY + "Insufficient arguments (list,claim)");
return true;
}
switch(args[0]) {
case "list":
if (!(sender instanceof Player))
return false;
Player player = (Player) sender;
ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
sender.sendMessage("Current Claims: " + solplayer.getAccountClaims().stream().filter(claim -> claim.getItemid() > 0).collect(Collectors.toList()).size());
for (SoliniaAccountClaim claim : solplayer.getAccountClaims().stream().filter(claim -> claim.getItemid() > 0).collect(Collectors.toList())) {
// sender.sendMessage("Item: " + claim.getItemid());
ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(claim.getItemid());
if (item == null)
continue;
TextComponent tc = new TextComponent();
tc.setText(ChatColor.LIGHT_PURPLE + item.getDisplayname() + ChatColor.AQUA + " [ Click here to remove ]");
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim claim " + claim.getId()));
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(item.asJsonString()).create()));
sender.spigot().sendMessage(tc);
}
sender.sendMessage("Use /claim claim all - to claim all your items");
return true;
case "give":
if (!sender.isOp() && !sender.hasPermission("solinia.claim.give"))
return false;
if (args.length < 3) {
sender.sendMessage("That is not a claim id - /claim give mcaccountname itemid");
return true;
}
String mcaccountname = args[1];
int itemId = Integer.parseInt(args[2].toUpperCase());
if (PlayerUtils.AddAccountClaim(mcaccountname, itemId))
sender.sendMessage("Account claim added!");
Player targetplayer = Bukkit.getPlayer(mcaccountname);
if (targetplayer != null && targetplayer.isOnline()) {
targetplayer.sendMessage(ChatColor.YELLOW + "* You seem to have received an item in your /claims");
}
return true;
case "claim":
if (!(sender instanceof Player))
return false;
Player claimPlayer = (Player) sender;
ISoliniaPlayer solClaimPlayer = SoliniaPlayerAdapter.Adapt(claimPlayer);
if (args.length < 2) {
sender.sendMessage("That is not a claim id or the word all - /claim claim claimid (see /claim list) or /claim claim all");
return true;
}
if (args[1].toUpperCase().equals("ALL")) {
for (SoliniaAccountClaim claim : StateManager.getInstance().getConfigurationManager().getAccountClaims(claimPlayer.getName().toUpperCase())) {
getClaim(claimPlayer, claim.getId());
}
} else {
int seekClaimId = Integer.parseInt(args[1].toUpperCase());
getClaim(claimPlayer, seekClaimId);
}
return true;
default:
sender.sendMessage(ChatColor.GRAY + "Invalid arguments (list,claim)");
return true;
}
} catch (CoreStateInitException e) {
}
return true;
}
use of net.md_5.bungee.api.CommandSender in project solinia3-core by mixxit.
the class CommandAA method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player))
return false;
Player player = (Player) sender;
try {
ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
player.sendMessage("Current AA Points: " + solplayer.getAAPoints());
if (args.length < 1) {
player.sendMessage(ChatColor.GRAY + "Insufficient arguments (list,buy)");
return true;
}
switch(args[0]) {
case "list":
int pageno = 1;
if (args.length > 1)
pageno = Integer.parseInt(args[1]);
pageno = pageno - 1;
int sizePerPage = 8;
List<ISoliniaAARank> fullaaranks = solplayer.getBuyableAARanks();
List<ISoliniaAARank> aaranks = fullaaranks.stream().skip(pageno * sizePerPage).limit(sizePerPage).collect(Collectors.toCollection(ArrayList::new));
for (ISoliniaAARank aarank : aaranks) {
ISoliniaAAAbility aaAbility = StateManager.getInstance().getConfigurationManager().getAAAbility(aarank.getAbilityid());
if (aaAbility != null)
if (!aaAbility.isEnabled())
continue;
if (aarank.getCost() <= solplayer.getAAPoints()) {
if (solplayer.canPurchaseAlternateAdvancementRank(aaAbility, aarank)) {
TextComponent tc = new TextComponent(TextComponent.fromLegacyText(ChatColor.LIGHT_PURPLE + aaAbility.getName() + " Rank " + aarank.getPosition() + ChatColor.RESET + " Cost: " + ChatColor.YELLOW + aarank.getCost() + ChatColor.RESET + " AA " + ChatColor.LIGHT_PURPLE + "[Click to Buy]" + ChatColor.RESET));
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/aa buy " + aarank.getId()));
String details = ChatColor.GOLD + aaAbility.getName() + " Rank: " + aarank.getPosition() + ChatColor.RESET + System.lineSeparator() + aarank.getDescription() + ChatColor.RESET + System.lineSeparator() + "Cost: " + aarank.getCost() + " AA points";
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
sender.spigot().sendMessage(tc);
} else {
if (aarank.getLevel_req() <= solplayer.getActualLevel()) {
TextComponent tc = new TextComponent(TextComponent.fromLegacyText(ChatColor.GRAY + "NB " + aaAbility.getName() + " Rank " + aarank.getPosition() + ChatColor.GRAY + " Cost: " + ChatColor.GRAY + aarank.getCost() + ChatColor.GRAY + " Cannot purchase yet"));
String details = ChatColor.GOLD + aaAbility.getName() + " Rank: " + aarank.getPosition() + ChatColor.RESET + System.lineSeparator() + aarank.getDescription() + ChatColor.RESET;
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
sender.spigot().sendMessage(tc);
}
}
} else {
TextComponent tc = new TextComponent(TextComponent.fromLegacyText(ChatColor.GRAY + "NA " + aaAbility.getName() + " Rank " + aarank.getPosition() + ChatColor.GRAY + " Cost: " + ChatColor.RED + aarank.getCost() + ChatColor.GRAY + " Insufficient AA points"));
String details = ChatColor.GOLD + aaAbility.getName() + " Rank: " + aarank.getPosition() + ChatColor.RESET + System.lineSeparator() + aarank.getDescription() + ChatColor.RESET;
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
sender.spigot().sendMessage(tc);
}
}
player.sendMessage("Displayed Page " + ChatColor.GOLD + (pageno + 1) + ChatColor.RESET + "/" + ChatColor.GOLD + Math.ceil((float) fullaaranks.size() / (float) sizePerPage) + ChatColor.RESET + " (See /aa list <pageno>");
player.sendMessage("More items may appear when you have more AA points available to spend");
break;
case "give":
if (args.length < 3) {
player.sendMessage("That is not a valid player name and amount /aa give playername amount");
return true;
}
if (!player.isOp()) {
player.sendMessage("Op only command");
return true;
}
Player targetplayer = Bukkit.getPlayer(args[1]);
if (targetplayer == null) {
player.sendMessage("Cannot find player");
return true;
}
int newpoints = Integer.parseInt(args[2]);
if (newpoints < 1) {
player.sendMessage("Too few points never give them less than 1");
return true;
}
if (newpoints > 5) {
player.sendMessage("Too many points man.... never give them more than 5, its supposed to be hard to achieve");
return true;
}
ISoliniaPlayer targetsolplayer = SoliniaPlayerAdapter.Adapt(targetplayer);
targetsolplayer.setAAPoints(targetsolplayer.getAAPoints() + newpoints);
player.sendMessage("* Granted player " + newpoints + " aa points");
targetplayer.sendMessage("* You have been granted " + newpoints + " AA points by Operator " + player.getName());
break;
case "buy":
if (args.length < 2) {
player.sendMessage("That is not a valid AA rank id - /aa buy aaabilityrankid (see /aa list)");
return true;
}
int seekRankId = Integer.parseInt(args[1].toUpperCase());
ISoliniaAARank aarank = StateManager.getInstance().getConfigurationManager().getAARankCache(seekRankId);
if (aarank == null) {
player.sendMessage("That is not a valid AA rank id - /aa buy aaabilityrankid (see /aa list)");
return true;
}
ISoliniaAAAbility aa = StateManager.getInstance().getConfigurationManager().getAAAbility(aarank.getAbilityid());
if (aa == null) {
player.sendMessage("That is not a valid AA rank id - /aa buy aaabilityrankid (see /aa list)");
return true;
}
if (!solplayer.canPurchaseAlternateAdvancementRank(aa, aarank)) {
player.sendMessage("You cannot buy that AA");
return true;
}
solplayer.purchaseAlternateAdvancementRank(aa, aarank);
try {
ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt(player);
if (player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() < solentity.getMaxHP()) {
solplayer.updateMaxHp();
}
} catch (CoreStateInitException e) {
}
return true;
default:
player.sendMessage(ChatColor.GRAY + "Invalid arguments (list,buy)");
return true;
}
} catch (CoreStateInitException e) {
}
return true;
}
use of net.md_5.bungee.api.CommandSender in project solinia3-core by mixxit.
the class CommandListCrafts 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.isOp() && !sender.hasPermission("solinia.listcrafts")) {
sender.sendMessage("You do not have permission to access this command");
return false;
}
try {
if (args.length == 0) {
// Return all
for (SoliniaCraft entity : StateManager.getInstance().getConfigurationManager().getCrafts()) {
TextComponent textComponent = new TextComponent();
String title = "CraftID: " + ChatColor.GOLD + entity.getId() + ChatColor.RESET + " - " + entity.getRecipeName() + " outputId: " + entity.getOutputItem();
textComponent.setText(title);
String transfertext = "/editcraft " + entity.getId() + "";
textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, transfertext));
sender.spigot().sendMessage(textComponent);
}
return true;
}
if (args.length > 0 && args[0].equals(".criteria")) {
try {
ChatUtils.sendFilterByCriteria(StateManager.getInstance().getConfigurationManager().getCrafts(), sender, args, SoliniaCraft.class);
return true;
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
sender.sendMessage(e.getMessage());
e.printStackTrace();
}
}
// Filter for name
for (SoliniaCraft entity : StateManager.getInstance().getConfigurationManager().getCrafts()) {
if (entity.getRecipeName().toUpperCase().contains(args[0].toUpperCase())) {
TextComponent textComponent = new TextComponent();
String title = "CraftID: " + ChatColor.GOLD + entity.getId() + ChatColor.RESET + " - " + entity.getRecipeName() + " outputId: " + entity.getOutputItem();
textComponent.setText(title);
String transfertext = "/editcraft " + entity.getId() + "";
textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, transfertext));
sender.spigot().sendMessage(textComponent);
}
}
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
}
return true;
}
Aggregations