use of com.bencodez.advancedcore.api.time.TimeType in project AdvancedCore by BenCodez.
the class AdvancedCorePlugin method loadTabComplete.
public void loadTabComplete() {
TabCompleteHandler.getInstance().addTabCompleteOption(new TabCompleteHandle("(AllPlayer)", new ArrayList<String>()) {
@Override
public void reload() {
ArrayList<String> players = new ArrayList<String>();
for (String name : getUuidNameCache().values()) {
if (!players.contains(name)) {
players.add(name);
}
}
setReplace(players);
}
@Override
public void updateReplacements() {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!getReplace().contains(player.getName())) {
getReplace().add(player.getName());
}
}
}
});
TabCompleteHandler.getInstance().addTabCompleteOption(new TabCompleteHandle("(Player)", new ArrayList<String>()) {
@Override
public void reload() {
}
@Override
public void updateReplacements() {
ArrayList<String> list = new ArrayList<String>();
for (Player player : Bukkit.getOnlinePlayers()) {
list.add(player.getName());
}
setReplace(list);
}
});
TabCompleteHandler.getInstance().addTabCompleteOption(new TabCompleteHandle("(PlayerExact)", new ArrayList<String>()) {
@Override
public void reload() {
}
@Override
public void updateReplacements() {
ArrayList<String> list = new ArrayList<String>();
for (Player player : Bukkit.getOnlinePlayers()) {
list.add(player.getName());
}
setReplace(list);
}
});
TabCompleteHandler.getInstance().addTabCompleteOption(new TabCompleteHandle("(uuid)", new ArrayList<String>()) {
@Override
public void reload() {
ArrayList<String> uuids = new ArrayList<String>();
for (String name : getUuidNameCache().keySet()) {
if (!uuids.contains(name)) {
uuids.add(name);
}
}
setReplace(uuids);
}
@Override
public void updateReplacements() {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!getReplace().contains(player.getUniqueId().toString())) {
getReplace().add(player.getUniqueId().toString());
}
}
}
});
ArrayList<String> options = new ArrayList<String>();
options.add("True");
options.add("False");
TabCompleteHandler.getInstance().addTabCompleteOption("(Boolean)", options);
options = new ArrayList<String>();
TabCompleteHandler.getInstance().addTabCompleteOption("(List)", options);
TabCompleteHandler.getInstance().addTabCompleteOption("(String)", options);
TabCompleteHandler.getInstance().addTabCompleteOption("(Text)", options);
TabCompleteHandler.getInstance().addTabCompleteOption("(Number)", options);
TabCompleteHandler.getInstance().addTabCompleteOption(new TabCompleteHandle("(Reward)", options) {
@Override
public void reload() {
ArrayList<String> rewards = new ArrayList<String>();
for (Reward reward : rewardHandler.getRewards()) {
if (!reward.getConfig().isDirectlyDefinedReward()) {
rewards.add(reward.getRewardName());
}
}
setReplace(rewards);
}
@Override
public void updateReplacements() {
}
});
TabCompleteHandler.getInstance().addTabCompleteOption(new TabCompleteHandle("(ChoiceReward)", options) {
@Override
public void reload() {
ArrayList<String> rewards = new ArrayList<String>();
for (Reward reward : rewardHandler.getRewards()) {
if (reward.getConfig().getEnableChoices()) {
rewards.add(reward.getRewardName());
}
}
setReplace(rewards);
}
@Override
public void updateReplacements() {
}
});
ArrayList<String> method = new ArrayList<String>();
for (InputMethod me : InputMethod.values()) {
method.add(me.toString());
}
TabCompleteHandler.getInstance().addTabCompleteOption("(RequestMethod)", method);
ArrayList<String> userStorage = new ArrayList<String>();
for (UserStorage storage : UserStorage.values()) {
userStorage.add(storage.toString());
}
TabCompleteHandler.getInstance().addTabCompleteOption("(UserStorage)", userStorage);
ArrayList<String> times = new ArrayList<String>();
for (TimeType ty : TimeType.values()) {
times.add(ty.toString());
}
TabCompleteHandler.getInstance().addTabCompleteOption("(TimeType)", times);
}
use of com.bencodez.advancedcore.api.time.TimeType in project AdvancedCore by BenCodez.
the class CommandLoader method getBasicAdminCommands.
public ArrayList<CommandHandler> getBasicAdminCommands(String permPrefix) {
ArrayList<CommandHandler> cmds = new ArrayList<CommandHandler>();
cmds.add(new CommandHandler(new String[] { "RunCMD", "All", "(List)" }, permPrefix + ".RunCMD.All", "Run command for every user, use %player% for player") {
@Override
public void execute(CommandSender sender, String[] args) {
String str = "";
for (int i = 2; i < args.length; i++) {
str += args[i] + " ";
}
final String cmd = str;
ArrayList<AdvancedCoreUser> users = new ArrayList<AdvancedCoreUser>();
for (String uuid : plugin.getUserManager().getAllUUIDs()) {
AdvancedCoreUser user = plugin.getUserManager().getUser(UUID.fromString(uuid));
user.dontCache();
users.add(user);
Bukkit.getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
Bukkit.getServer().dispatchCommand(sender, StringParser.getInstance().replacePlaceHolder(cmd, "player", user.getPlayerName()));
}
});
}
}
});
cmds.add(new CommandHandler(new String[] { "GiveAll", "(reward)" }, permPrefix + ".GiveAll", "Give all users a reward") {
@Override
public void execute(CommandSender sender, String[] args) {
Reward reward = plugin.getRewardHandler().getReward(args[1]);
ArrayList<AdvancedCoreUser> users = new ArrayList<AdvancedCoreUser>();
for (String uuid : plugin.getUserManager().getAllUUIDs()) {
AdvancedCoreUser user = plugin.getUserManager().getUser(UUID.fromString(uuid));
user.dontCache();
users.add(user);
}
for (AdvancedCoreUser user : users) {
new RewardBuilder(reward).send(user);
}
sendMessage(sender, "&cGave all players reward file " + args[1]);
}
});
cmds.add(new CommandHandler(new String[] { "GiveAllOnline", "(reward)" }, permPrefix + ".GiveAllOnline", "Give all users a reward") {
@Override
public void execute(CommandSender sender, String[] args) {
Reward reward = plugin.getRewardHandler().getReward(args[1]);
for (Player p : Bukkit.getOnlinePlayers()) {
AdvancedCoreUser user = plugin.getUserManager().getUser(p);
new RewardBuilder(reward).send(user);
}
}
});
cmds.add(new CommandHandler(new String[] { "GiveReward", "(Player)", "(Reward)" }, permPrefix + ".GiveReward", "Give a player a reward file", true) {
@Override
public void execute(CommandSender sender, String[] args) {
AdvancedCoreUser user = plugin.getUserManager().getUser(args[1]);
plugin.getRewardHandler().giveReward(user, args[2], new RewardOptions().setOnline(user.isOnline()));
sendMessage(sender, "&cGave " + args[1] + " the reward file " + args[2]);
}
});
cmds.add(new CommandHandler(new String[] { "User", "(Player)", "ForceReward", "(Reward)" }, permPrefix + ".GiveReward", "Give a player a reward file", true) {
@Override
public void execute(CommandSender sender, String[] args) {
if (args[1].equalsIgnoreCase("all")) {
Reward reward = plugin.getRewardHandler().getReward(args[3]);
ArrayList<AdvancedCoreUser> users = new ArrayList<AdvancedCoreUser>();
for (String uuid : plugin.getUserManager().getAllUUIDs()) {
AdvancedCoreUser user = plugin.getUserManager().getUser(UUID.fromString(uuid));
user.dontCache();
users.add(user);
}
for (AdvancedCoreUser user : users) {
new RewardBuilder(reward).send(user);
}
sendMessage(sender, "&cGave all players reward file " + args[3]);
} else {
AdvancedCoreUser user = plugin.getUserManager().getUser(args[1]);
plugin.getRewardHandler().giveReward(user, args[3], new RewardOptions().setOnline(user.isOnline()));
sender.sendMessage("&cGave " + args[1] + " the reward file " + args[3]);
}
}
});
cmds.add(new CommandHandler(new String[] { "GiveReward", "(Player)", "(Reward)", "(Text)", "(Text)" }, permPrefix + ".GiveReward", "Give a player a reward file and set a placeholder", true) {
@Override
public void execute(CommandSender sender, String[] args) {
AdvancedCoreUser user = plugin.getUserManager().getUser(args[1]);
plugin.getRewardHandler().giveReward(user, args[2], new RewardOptions().setOnline(user.isOnline()).addPlaceholder(args[3], args[4]));
sender.sendMessage("&cGave " + args[1] + " the reward file " + args[2]);
}
});
cmds.add(new CommandHandler(new String[] { "Report" }, permPrefix + ".Report", "Create Report File") {
@Override
public void execute(CommandSender sender, String[] args) {
ZipCreator.getInstance().createReport();
sender.sendMessage("Created zip file");
}
});
cmds.add(new CommandHandler(new String[] { "ClearOfflineRewards" }, permPrefix + ".ClearOfflineRewards", "Clear offline rewards", true, true) {
@Override
public void execute(CommandSender sender, String[] args) {
sendMessage(sender, "&cStarting to clear offline rewards");
plugin.getUserManager().removeAllKeyValues(plugin.getUserManager().getOfflineRewardsPath(), DataType.STRING);
sendMessage(sender, "&cFinished clearing offline rewards");
}
});
cmds.add(new CommandHandler(new String[] { "GUI" }, permPrefix + ".AdminGUI", "Open AdminGUI", false) {
@Override
public void execute(CommandSender sender, String[] args) {
AdminGUI.getInstance().openGUI((Player) sender);
}
});
cmds.add(new CommandHandler(new String[] { "Rewards" }, permPrefix + ".RewardEdit", "Open RewardGUI", false) {
@Override
public void execute(CommandSender sender, String[] args) {
RewardEditGUI.getInstance().openRewardsGUI((Player) sender);
}
});
cmds.add(new CommandHandler(new String[] { "User" }, permPrefix + ".UserEdit", "Open UserGUI", false) {
@Override
public void execute(CommandSender sender, String[] args) {
UserGUI.getInstance().openUsersGUI((Player) sender);
}
});
cmds.add(new CommandHandler(new String[] { "User", "(Player)" }, permPrefix + ".UserEdit", "Open UserGUI", false) {
@Override
public void execute(CommandSender sender, String[] args) {
UserGUI.getInstance().openUserGUI((Player) sender, args[1]);
}
});
cmds.add(new CommandHandler(new String[] { "User", "(Player)", "RemoveTempPermissions" }, permPrefix + ".RemoveTempPermission", "Remove temp permissions") {
@Override
public void execute(CommandSender sender, String[] args) {
plugin.getPermissionHandler().removePermission(UUID.fromString(PlayerUtils.getInstance().getUUID(args[1])));
sendMessage(sender, "&cRemoved temporary permissions from " + args[1]);
}
});
cmds.add(new CommandHandler(new String[] { "User", "(Player)", "AddTempPermissions", "(Text)", "(Number)" }, permPrefix + ".AddTempPermission", "Add temp permission for number of seconds") {
@Override
public void execute(CommandSender sender, String[] args) {
plugin.getPermissionHandler().addPermission(UUID.fromString(PlayerUtils.getInstance().getUUID(args[1])), args[3], Integer.valueOf(args[4]));
sendMessage(sender, "&cAdded temporary permission to " + args[1] + " for " + args[4]);
}
});
cmds.add(new CommandHandler(new String[] { "User", "(Player)", "AddTempPermissions", "(Text)" }, permPrefix + ".AddTempPermission", "Add temp permission") {
@Override
public void execute(CommandSender sender, String[] args) {
plugin.getPermissionHandler().addPermission(UUID.fromString(PlayerUtils.getInstance().getUUID(args[1])), args[3]);
sendMessage(sender, "&cAdded temporary permission to " + args[1]);
}
});
cmds.add(new CommandHandler(new String[] { "Report" }, permPrefix + ".Report", "Create a zip file to send for debuging") {
@Override
public void execute(CommandSender sender, String[] args) {
ZipCreator.getInstance().createReport();
sender.sendMessage("Created Zip File!");
}
});
cmds.add(new CommandHandler(new String[] { "UserRemove", "(player)" }, permPrefix + ".UserRemove", "Remove User") {
@Override
public void execute(CommandSender sender, String[] args) {
sendMessage(sender, "&cRemoving " + args[1]);
AdvancedCoreUser user = plugin.getUserManager().getUser(args[1]);
user.getData().remove();
sendMessage(sender, "&cRemoved " + args[1]);
}
});
cmds.add(new CommandHandler(new String[] { "UserUUIDRemove", "(uuid)" }, permPrefix + ".UserRemove", "Remove User") {
@Override
public void execute(CommandSender sender, String[] args) {
sendMessage(sender, "&cRemoving " + args[1]);
AdvancedCoreUser user = plugin.getUserManager().getUser(UUID.fromString(args[1]));
user.getData().remove();
sendMessage(sender, "&cRemoved " + args[1]);
}
});
cmds.add(new CommandHandler(new String[] { "ClearCache" }, permPrefix + ".ClearCache", "Clear MySQL Cache") {
@Override
public void execute(CommandSender sender, String[] args) {
if (plugin.getStorageType().equals(UserStorage.MYSQL)) {
if (plugin.getMysql() != null) {
plugin.getMysql().clearCacheBasic();
} else {
sender.sendMessage(StringParser.getInstance().colorize("&cMySQL not loaded"));
}
}
plugin.getUserManager().getDataManager().clearCache();
sender.sendMessage(StringParser.getInstance().colorize("&cCache cleared"));
}
});
cmds.add(new CommandHandler(new String[] { "Purge" }, permPrefix + ".Purge", "Purge Data") {
@Override
public void execute(CommandSender sender, String[] args) {
plugin.getUserManager().purgeOldPlayersNow();
sendMessage(sender, "&cPurged data");
}
});
if (!plugin.getJenkinsSite().isEmpty()) {
cmds.add(new CommandHandler(new String[] { "DownloadJenkins" }, permPrefix + ".Download", "Download from jenkins. Please use at your own risk") {
@Override
public void execute(CommandSender sender, String[] args) {
if (plugin.getOptions().isEnableJenkins() && !plugin.getJenkinsSite().isEmpty()) {
sender.sendMessage(StringParser.getInstance().colorize("&cAttempting to download from jenkins... restart server to fully update, Note: USE THESE DEV BUILDS AT YOUR OWN RISK"));
UpdateDownloader.getInstance().downloadFromJenkins(plugin.getJenkinsSite(), plugin.getName());
sender.sendMessage(StringParser.getInstance().colorize("&cDownloaded jar"));
} else {
sendMessage(sender, "&cNot enabled, please enable to use this. Note: USE THESE DEV BUILDS AT YOUR OWN RISK");
}
}
});
}
cmds.add(new CommandHandler(new String[] { "ForceTimeChanged", "(TimeType)" }, permPrefix + ".ForceTimeChange", "Force time change, use at your own risk!", true, true) {
@Override
public void execute(CommandSender sender, String[] args) {
try {
TimeType time = TimeType.getTimeType(args[1]);
sendMessage(sender, "&cForcing time change for " + time.toString() + ". May take awhile to process");
plugin.getTimeChecker().forceChanged(time);
} catch (Exception e) {
e.printStackTrace();
}
}
});
cmds.add(new CommandHandler(new String[] { "Javascript", "(List)" }, permPrefix + ".Javascript", "Execute javascript") {
@Override
public void execute(CommandSender sender, String[] args) {
String str = "";
for (int i = 1; i < args.length; i++) {
str += args[i] + " ";
}
JavascriptEngine engine = new JavascriptEngine();
engine.addPlayer(sender);
sendMessage(sender, "&cJavascript result: " + engine.getStringValue(str.trim()));
}
});
cmds.add(new CommandHandler(new String[] { "SetRequestMethod", "(RequestMethod)" }, permPrefix + ".SetRequestMethod", "SetRequestMethod", false) {
@Override
public void execute(CommandSender sender, String[] args) {
AdvancedCoreUser user = plugin.getUserManager().getUser((Player) sender);
InputMethod method = InputMethod.getMethod(args[1]);
if (method == null) {
user.sendMessage("&cInvalid request method: " + args[1]);
} else {
user.setUserInputMethod(method);
user.sendMessage("&cRequest method set to " + method.toString());
}
}
});
cmds.add(new CommandHandler(new String[] { "SetRequestMethod" }, permPrefix + ".SetRequestMethod", "SetRequestMethod", false) {
@Override
public void execute(CommandSender sender, String[] args) {
ArrayList<String> methods = new ArrayList<String>();
for (InputMethod method : InputMethod.values()) {
methods.add(method.toString());
}
new ValueRequest(InputMethod.INVENTORY).requestString((Player) sender, "", ArrayUtils.getInstance().convert(methods), false, new StringListener() {
@Override
public void onInput(Player player, String value) {
AdvancedCoreUser user = plugin.getUserManager().getUser(player);
user.setUserInputMethod(InputMethod.getMethod(value));
}
});
}
});
cmds.add(new CommandHandler(new String[] { "User", "All", "SetData", "(text)", "(text)" }, permPrefix + ".SetAllData", "Set all users data") {
@Override
public void execute(CommandSender sender, String[] args) {
String data = args[4];
if (data.equalsIgnoreCase("\"\"")) {
data = "";
}
for (String uuid : plugin.getUserManager().getAllUUIDs()) {
AdvancedCoreUser user = plugin.getUserManager().getUser(UUID.fromString(uuid));
user.dontCache();
user.getData().setString(args[3], data);
}
sender.sendMessage(StringParser.getInstance().colorize("&cSet all users " + args[3] + " to " + args[4]));
}
});
cmds.add(new CommandHandler(new String[] { "User", "(player)", "SetData", "(text)", "(text)" }, permPrefix + ".SetData", "Set user data") {
@Override
public void execute(CommandSender sender, String[] args) {
AdvancedCoreUser user = plugin.getUserManager().getUser(args[1]);
String data = args[4];
if (data.equalsIgnoreCase("\"\"")) {
data = "";
}
user.getData().setString(args[3], data);
sender.sendMessage(StringParser.getInstance().colorize("&cSet " + args[3] + " for " + args[1] + " to " + args[4]));
}
});
cmds.add(new CommandHandler(new String[] { "User", "(Player)", "ViewData" }, permPrefix + ".ViewData", "View playerdata") {
@Override
public void execute(CommandSender sender, String[] args) {
AdvancedCoreUser user = plugin.getUserManager().getUser(args[1]);
for (String key : user.getData().getKeys()) {
String str = user.getData().getString(key, true);
if (plugin.getOptions().getStorageType().equals(UserStorage.MYSQL)) {
if (plugin.getMysql().isIntColumn(key)) {
str = "" + user.getData().getInt(key, true);
}
}
sendMessage(sender, "&c&l" + key + " &c" + str);
}
}
});
cmds.add(new CommandHandler(new String[] { "User", "(Player)", "HasPermission", "(Text)" }, permPrefix + ".HasPermission", "View playerdata") {
@Override
public void execute(CommandSender sender, String[] args) {
AdvancedCoreUser user = plugin.getUserManager().getUser(args[1]);
sendMessage(sender, "User " + args[1] + " permission " + args[3] + ":" + user.hasPermission(args[3]));
}
});
cmds.add(new CommandHandler(new String[] { "Choices", "SetPreference", "(ChoiceReward)", "(String)", "(Player)" }, permPrefix + ".ChoicesSetPreferenceOther", "Let user pick his choice preferences", false) {
@Override
public void execute(CommandSender sender, String[] args) {
AdvancedCoreUser user = plugin.getUserManager().getUser(args[4]);
user.setChoicePreference(args[2], args[3]);
user.sendMessage("&cPreference set to " + args[3] + " for " + args[4]);
}
});
if (plugin.isLoadUserData()) {
cmds.add(new CommandHandler(new String[] { "ConvertToData", "(UserStorage)" }, permPrefix + ".Commands.AdminVote.ConvertToData", "Convert user storage from current storage type the one specificed", true, true) {
@Override
public void execute(CommandSender sender, String[] args) {
sendMessage(sender, "&cStarting convert from " + plugin.getStorageType().toString() + " to " + args[1]);
plugin.convertDataStorage(plugin.getStorageType(), UserStorage.value(args[1]));
sendMessage(sender, "&cFinished converting");
}
});
cmds.add(new CommandHandler(new String[] { "ConvertFromData", "(UserStorage)" }, permPrefix + ".Commands.AdminVote.ConvertFromData", "Convert user storage from current storage type from the one specificed", true, true) {
@Override
public void execute(CommandSender sender, String[] args) {
sendMessage(sender, "&cStarting convert from " + args[1] + " to " + plugin.getStorageType().toString());
plugin.convertDataStorage(UserStorage.value(args[1]), plugin.getStorageType());
sendMessage(sender, "&cFinished converting");
}
});
}
for (CommandHandler cmd : cmds) {
cmd.setAdvancedCoreCommand(true);
}
return cmds;
}
Aggregations