Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add playername tabcompleting to the root money command. #41

Merged
merged 7 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Convert from other economy plugins using the Vault command:
`/vault-convert {economyplugin} iconomy5.11` (replace 5.11 with the iConomy version number.)

#### Commands:
<img src=https://user-images.githubusercontent.com/879756/66089320-606ffe80-e544-11e9-86fa-d324a384aaeb.png>
<img src=https://feen.us/gsffuk.png alt="showcase">

#### Permission Nodes:
Permission nodes can be gotten from the [plugin.yml](https://github.com/iconomy5legacy/iConomy/blob/master/src/main/resources/plugin.yml) They are already given out by default for the most part.
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/com/iConomy/MoneyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;

import com.iConomy.util.StringMgmt;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
Expand Down Expand Up @@ -189,7 +190,7 @@ public boolean accept(File file, String name) {
}

private final List<String> SUB_CMDS = Arrays.asList("?", "rank", "top", "pay", "grant", "set", "hide", "create",
"remove", "preset", "purge", "empty", "stats", "help", "?");
"remove", "preset", "purge", "empty", "stats");
private final List<String> PLAYER_CMDS = Arrays.asList("rank", "pay", "grant", "set", "hide", "create", "remove",
"reset");
private final List<String> AMOUNT_CMDS = Arrays.asList("pay","grant","set") ;
Expand All @@ -202,19 +203,23 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
String subCmdArg = args[0].toLowerCase(Locale.ROOT);

if (args.length == 1) {
return SUB_CMDS.stream().filter(s -> s.startsWith(subCmdArg)).collect(Collectors.toList());
if (StringMgmt.filterByStart(SUB_CMDS, subCmdArg).size() > 0) {
return SUB_CMDS.stream().filter(s -> s.startsWith(subCmdArg)).collect(Collectors.toList());
} else {
return null;
}
} else if (args.length == 2) {
if (PLAYER_CMDS.contains(subCmdArg))
return null;
if (subCmdArg.equals("top"))
return Arrays.asList("<amount>");
return List.of("<amount>");
} else if (args.length == 3) {
if (AMOUNT_CMDS.contains(subCmdArg))
return Arrays.asList("<amount>");
return List.of("<amount>");
if (subCmdArg.equals("hide"))
return Arrays.asList("true", "false");
} else if (args.length == 4 && subCmdArg.equals("grant")) {
return Arrays.asList("silent");
return List.of("silent");
}

return Arrays.asList("");
Expand Down
38 changes: 17 additions & 21 deletions src/main/java/com/iConomy/entity/Players.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,53 +51,51 @@ public Players(String directory) {
* instances of the same help lines.
*/
private void getMoneyHelp(CommandSender sender) {
Messaging.send(sender, "`y ");
Messaging.send(sender, "`w iConomy (`r" + Constants.Codename + "`w)");
Messaging.send(sender, "`y ");
Messaging.send(sender, "`w [] Required, () Optional");
Messaging.send(sender, " ");

Messaging.send(sender, "`w <> Required, [] Optional");

if(sender instanceof Player){
Messaging.send(sender, "`G /money `y Check your balance");
Messaging.send(sender, "`G /money `y Check your balance.");
}
Messaging.send(sender, "`G /money `g[player] `y check someone's balance.");

Messaging.send(sender, "`G /money `g? `y For help & Information");

if (iConomy.hasPermissions(sender, "iConomy.rank", true)) {
Messaging.send(sender, "`G /money `grank `G(`wplayer`G) `y Rank on the topcharts. ");
Messaging.send(sender, "`G /money `grank `G[`wplayer`G] `y Rank on the topcharts. ");
}

if (iConomy.hasPermissions(sender, "iConomy.list", true)) {
Messaging.send(sender, "`G /money `gtop `G(`wamount`G) `y Richest players listing. ");
Messaging.send(sender, "`G /money `gtop `G[`wamount`G] `y Richest players listing. ");
}

if (iConomy.hasPermissions(sender, "iConomy.payment", true)) {
Messaging.send(sender, "`G /money `gpay `G[`wplayer`G] [`wamount`G] `y Send money to a player.");
Messaging.send(sender, "`G /money `gpay `G<`wplayer`G> <`wamount`G> `y Send money to a player.");
}

if (iConomy.hasPermissions(sender, "iConomy.admin.grant", true)) {
Messaging.send(sender, "`G /money `ggrant `G[`wplayer`G] [`wamount`G] {`wsilent`G} `y Give money, optionally silent.");
Messaging.send(sender, "`G /money `ggrant `G[`wplayer`G] -[`wamount`G] {`wsilent`G} `y Take money, optionally silent.");
Messaging.send(sender, "`G /money `ggrant `G<`wplayer`G> <`wamount`G> [`wsilent`G] `y Give money, optionally silent.");
Messaging.send(sender, "`G /money `ggrant `G<`wplayer`G> -<`wamount`G> [wsilent`G] `y Take money, optionally silent.");
}

if (iConomy.hasPermissions(sender, "iConomy.admin.set", true)) {
Messaging.send(sender, "`G /money `gset `G[`wplayer`G] [`wamount`G] `y Sets a players balance.");
Messaging.send(sender, "`G /money `gset `G<`wplayer`G> <`wamount`G> `y Sets a players balance.");
}

if (iConomy.hasPermissions(sender, "iConomy.admin.hide", true)) {
Messaging.send(sender, "`G /money `ghide `G[`wplayer`G] `wtrue`G/`wfalse `y Hide or show an account.");
Messaging.send(sender, "`G /money `ghide `G<`wplayer`G> `wtrue`G/`wfalse `y Hide or show an account.");
}

if (iConomy.hasPermissions(sender, "iConomy.admin.account.create", true)) {
Messaging.send(sender, "`G /money `gcreate `G[`wplayer`G] `y Create player account.");
Messaging.send(sender, "`G /money `gcreate `G<`wplayer`G> `y Create player account.");
}

if (iConomy.hasPermissions(sender, "iConomy.admin.account.remove", true)) {
Messaging.send(sender, "`G /money `gremove `G[`wplayer`G] `y Remove player account.");
Messaging.send(sender, "`G /money `gremove `G<`wplayer`G> `y Remove player account.");
}

if (iConomy.hasPermissions(sender, "iConomy.admin.reset", true)) {
Messaging.send(sender, "`G /money `greset `G[`wplayer`G] `y Reset player account.");
Messaging.send(sender, "`G /money `greset `G<`wplayer`G> `y Reset player account.");
}

if (iConomy.hasPermissions(sender, "iConomy.admin.purge", true)) {
Expand All @@ -111,8 +109,6 @@ private void getMoneyHelp(CommandSender sender) {
if (iConomy.hasPermissions(sender, "iConomy.admin.stats", true)) {
Messaging.send(sender, "`G /money `gstats `y Check all economic stats.");
}

Messaging.send(sender, " ");
}

/**
Expand Down Expand Up @@ -325,17 +321,17 @@ private void showSet(CommandSender sender, String name, Player controller, doubl

iConomy.getTransactions().insert("[System]", name, 0.0D, balance.doubleValue(), amount, 0.0D, 0.0D);

if (online != null) {
if (online != null && controller != null) {
Messaging.send(online, this.Template.color("tag.money") + this.Template.parse("personal.set", new String[] { "+by", "+amount,+a" }, new String[] { console ? "Console" : controller.getName(), iConomy.format(amount) }));

showBalance(name, online, true);
}

if (controller != null) {
if (controller == null) {
Messaging.send(sender, this.Template.color("tag.money") + this.Template.parse("player.set", new String[] { "+name,+n", "+amount,+a" }, new String[] { name, iConomy.format(amount) }));
}

if (console)
if (console || controller == null)
log.info("Player " + account + "'s account had " + iConomy.format(amount) + " set to it.");
else
log.info("Player " + account + "'s account had " + iConomy.format(amount) + " set to it by " + controller.getName() + ".");
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/iConomy/util/StringMgmt.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.iConomy.util;

import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

public class StringMgmt {
public static String[] remFirstArg(String[] arr) {

Expand Down Expand Up @@ -37,4 +42,18 @@ else if (end < start)
return newSplit;
}
}

/**
* Returns strings that start with a string
*
* @param list strings to check
* @param startingWith string to check with list
* @return strings from list that start with startingWith
*/
public static List<String> filterByStart(List<String> list, String startingWith) {
if (list == null || startingWith == null) {
return Collections.emptyList();
}
return list.stream().filter(name -> name.toLowerCase(Locale.ROOT).startsWith(startingWith.toLowerCase(Locale.ROOT))).collect(Collectors.toList());
}
}