New commands and limits
/mixtape list [<player>] (Fixes #5) /mixtape delete <alias> (Fixes #6) Global limit for aliases Per-user permission node limit for aliasesmain
parent
44fa5eb4c2
commit
f23062b3f5
|
@ -5,6 +5,12 @@
|
|||
Commands
|
||||
========
|
||||
|
||||
``/alias <alias> <message>`` - Create a chat alias
|
||||
``/alias <alias> <message>`` - Create a chat alias.
|
||||
|
||||
``//alias <alias> <command>`` - Create a command alias
|
||||
``//alias <alias> <command>`` - Create a command alias.
|
||||
|
||||
``/mixtape list [<player>]`` - List aliases. If a player has the ``mixtape.list.other`` permission, they can view other player's aliases as well.
|
||||
|
||||
``/mixtape delete <alias>`` - Delete an alias
|
||||
|
||||
``/mixtape reload`` - Reload Mixtape
|
||||
|
|
|
@ -5,7 +5,15 @@
|
|||
Permissions
|
||||
===========
|
||||
|
||||
``mixtape.admin`` - Allows use of Mixtape admin commands, namely ``/mixtape reload``
|
||||
``mixtape.admin`` - Allows use of Mixtape admin commands, namely ``/mixtape reload``.
|
||||
|
||||
``mixtape.list`` - Allows a player to list their aliases.
|
||||
|
||||
``mixtape.list.other`` - Allows a player to list other player's aliases.
|
||||
|
||||
``mixtape.list.*`` - Wildcard permission for the two above nodes.
|
||||
|
||||
``mixtape.limit.x`` - Give a player a specific limit for creating aliases. Overrides the global limit.
|
||||
|
||||
``mixtape.alias.chat`` - Allows players to create chat aliases.
|
||||
|
||||
|
@ -13,3 +21,5 @@ Permissions
|
|||
|
||||
``mixtape.alias.*`` - Wildcard permission for the two above nodes.
|
||||
|
||||
``mixtape.*`` - Wildcard permission for all nodes.
|
||||
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>xyz.etztech</groupId>
|
||||
<artifactId>Mixtape</artifactId>
|
||||
<version>2.0</version>
|
||||
<version>2.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Mixtape</name>
|
||||
|
|
|
@ -18,10 +18,11 @@ public final class Mixtape extends JavaPlugin {
|
|||
private Logger log = Logger.getLogger( "Minecraft" );
|
||||
|
||||
private static Mixtape instance;
|
||||
public static FileConfiguration config;
|
||||
private static FileConfiguration config;
|
||||
private static Database database;
|
||||
|
||||
private static int loops;
|
||||
private static int limit;
|
||||
|
||||
private static boolean global;
|
||||
|
||||
|
@ -49,7 +50,8 @@ public final class Mixtape extends JavaPlugin {
|
|||
public void reloadConfig() {
|
||||
super.reloadConfig();
|
||||
config = Bukkit.getPluginManager().getPlugin("Mixtape").getConfig();
|
||||
loops = config.getInt("loop");
|
||||
loops = config.getInt("loop", 5);
|
||||
limit = config.getInt("limit", -1);
|
||||
validate();
|
||||
}
|
||||
|
||||
|
@ -79,6 +81,10 @@ public final class Mixtape extends JavaPlugin {
|
|||
return loops;
|
||||
}
|
||||
|
||||
public static int getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
private void validate() {
|
||||
List<String> errors = new ArrayList<>();
|
||||
try {
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
package xyz.etztech.mixtape;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MixtapeUtil {
|
||||
|
||||
public static String stripSlash(String base) {
|
||||
|
@ -9,4 +15,24 @@ public class MixtapeUtil {
|
|||
return base;
|
||||
}
|
||||
|
||||
private static int getLimit(Set<PermissionAttachmentInfo> permissions) {
|
||||
int global = Mixtape.getLimit();
|
||||
int limit = 0;
|
||||
for (PermissionAttachmentInfo permission : permissions) {
|
||||
if (permission.getPermission().startsWith("mixtape.limit.") && permission.getValue()) {
|
||||
try {
|
||||
int p = Integer.parseInt(permission.getPermission().replaceFirst("mixtape.limit.", ""));
|
||||
limit = limit > p ? limit : p;
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
return limit != 0 ? limit : global;
|
||||
}
|
||||
|
||||
public static boolean isLimited(Player player) {
|
||||
int current = Mixtape.getDatabase().getAliases(player.getUniqueId().toString()).size();
|
||||
int limit = getLimit(player.getEffectivePermissions());
|
||||
return (current >= limit && limit != -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,6 +37,11 @@ public class CommandAlias implements CommandExecutor {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (MixtapeUtil.isLimited(player)) {
|
||||
player.sendMessage(ChatColor.RED + "You have hit your limit of allowed aliases. Delete one and try again.");
|
||||
return true;
|
||||
}
|
||||
|
||||
String alias = MixtapeUtil.stripSlash(args[0]);
|
||||
|
||||
String command = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " ");
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
package xyz.etztech.mixtape.commands;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.etztech.mixtape.Alias;
|
||||
import xyz.etztech.mixtape.Mixtape;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandMixtape implements CommandExecutor {
|
||||
|
||||
Mixtape plugin;
|
||||
|
@ -24,32 +21,101 @@ public class CommandMixtape implements CommandExecutor {
|
|||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String base, String[] args) {
|
||||
boolean hasAdmin = sender.hasPermission("alias.admin");
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(ChatColor.GOLD + "===== Mixtape =====");
|
||||
sender.sendMessage(ChatColor.YELLOW + "/mixtape reload");
|
||||
} else if (sender.hasPermission("alias.admin")) {
|
||||
if ("reload".equalsIgnoreCase(args[0])) {
|
||||
plugin.reloadConfig();
|
||||
sender.sendMessage(ChatColor.GREEN + "Mixtape Reloaded.");
|
||||
} else if ("purge".equalsIgnoreCase(args[0])) {
|
||||
if (args.length > 1) {
|
||||
Player player = Bukkit.getPlayerExact(args[1]);
|
||||
if (player != null) {
|
||||
Mixtape.getDatabase().purge(player.getUniqueId().toString());
|
||||
sender.sendMessage(ChatColor.GREEN + "Purged all of " + player.getName() + "'s aliases.");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "No player found.");
|
||||
sender.sendMessage(ChatColor.YELLOW + "/mixtape list" + (hasAdmin ? " [<player>]" : ""));
|
||||
sender.sendMessage(ChatColor.YELLOW + "/mixtape delete <alias>");
|
||||
if (hasAdmin) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "/mixtape purge [<player>]");
|
||||
}
|
||||
} else {
|
||||
if ("list".equalsIgnoreCase(args[0])) {
|
||||
if (sender instanceof Player) {
|
||||
list(sender, args.length == 2 ? args[1] : null);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Console can only use global aliases defined in the config.");
|
||||
}
|
||||
} else if ("delete".equalsIgnoreCase(args[0])) {
|
||||
if (sender instanceof Player) {
|
||||
if (args.length > 1) {
|
||||
delete(sender, args[1]);
|
||||
}
|
||||
} else {
|
||||
for (OfflinePlayer offline : Bukkit.getBannedPlayers()) {
|
||||
Mixtape.getDatabase().purge(offline.getUniqueId().toString());
|
||||
sender.sendMessage(ChatColor.RED + "Console can only use global aliases defined in the config.");
|
||||
}
|
||||
}
|
||||
if (hasAdmin) {
|
||||
if ("reload".equalsIgnoreCase(args[0])) {
|
||||
plugin.reloadConfig();
|
||||
sender.sendMessage(ChatColor.GREEN + "Mixtape Reloaded.");
|
||||
} else if ("purge".equalsIgnoreCase(args[0])) {
|
||||
if (args.length > 1) {
|
||||
Player player = Bukkit.getPlayerExact(args[1]);
|
||||
if (player != null) {
|
||||
Mixtape.getDatabase().purge(player.getUniqueId().toString());
|
||||
sender.sendMessage(ChatColor.GREEN + "Purged all of " + player.getName() + "'s aliases.");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "No player found.");
|
||||
}
|
||||
} else {
|
||||
for (OfflinePlayer offline : Bukkit.getBannedPlayers()) {
|
||||
Mixtape.getDatabase().purge(offline.getUniqueId().toString());
|
||||
}
|
||||
sender.sendMessage(ChatColor.GREEN + "Purged all banned players' aliases.");
|
||||
}
|
||||
sender.sendMessage(ChatColor.GREEN + "Purged all banned players' aliases.");
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void list(CommandSender sender, String username) {
|
||||
if (username == null || !sender.hasPermission("mixtape.list.other")) {
|
||||
username = sender.getName();
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(username);
|
||||
if (player != null) {
|
||||
StringBuilder message = new StringBuilder();
|
||||
message.append(ChatColor.GOLD).append("|").append(ChatColor.YELLOW);
|
||||
message.append(" Aliases for ").append(username).append(" ");
|
||||
message.append(ChatColor.GOLD).append("|").append(ChatColor.YELLOW);
|
||||
message.append("\n");
|
||||
message.append(ChatColor.GOLD).append("|").append(ChatColor.YELLOW);
|
||||
message.append(" Type ");
|
||||
message.append(ChatColor.GOLD).append("|").append(ChatColor.YELLOW);
|
||||
message.append(" Alias ");
|
||||
message.append(ChatColor.GOLD).append("|").append(ChatColor.YELLOW);
|
||||
message.append(" Command ");
|
||||
message.append(ChatColor.GOLD).append("|").append(ChatColor.YELLOW);
|
||||
for (Alias alias : Mixtape.getDatabase().getAliases(player.getUniqueId().toString())) {
|
||||
message.append("\n");
|
||||
message.append(ChatColor.GOLD).append("| ").append(ChatColor.YELLOW);
|
||||
message.append(alias.getType().name());
|
||||
message.append(ChatColor.GOLD).append(" | ").append(ChatColor.YELLOW);
|
||||
message.append(alias.getFrom());
|
||||
message.append(ChatColor.GOLD).append(" | ").append(ChatColor.YELLOW);
|
||||
message.append(alias.getTo());
|
||||
message.append(ChatColor.GOLD).append(" |").append(ChatColor.YELLOW);
|
||||
}
|
||||
sender.sendMessage(message.toString());
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "No aliases found for " + username + ". Are they online?");
|
||||
}
|
||||
}
|
||||
|
||||
private void delete(CommandSender sender, String from) {
|
||||
Player player = (Player) sender;
|
||||
int id = Mixtape.getDatabase().exists(player.getUniqueId().toString(), from);
|
||||
if (id > 0) {
|
||||
Mixtape.getDatabase().delete(id);
|
||||
player.sendMessage(ChatColor.RED + "Deleted alias for '" + from + "'");
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "No alias found for '" + from + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -37,6 +37,11 @@ public class CommandSlashAlias implements CommandExecutor {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (MixtapeUtil.isLimited(player)) {
|
||||
player.sendMessage(ChatColor.RED + "You have hit your limit of allowed aliases. Delete one and try again.");
|
||||
return true;
|
||||
}
|
||||
|
||||
String alias = MixtapeUtil.stripSlash(args[0]);
|
||||
|
||||
String command = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " ");
|
||||
|
|
|
@ -7,4 +7,11 @@ aliases:
|
|||
|
||||
|
||||
# How many times can an alias call another alias before aborting?
|
||||
loop: 5
|
||||
loop: 5
|
||||
|
||||
# Global limit for aliases. Set to -1 (default) for unlimited
|
||||
# This only affects players without a limit permission node
|
||||
# For per-permission settings, use the permission nodes
|
||||
# mixtape.limit.x
|
||||
# Where 'x' is the limit
|
||||
limit: -1
|
|
@ -15,6 +15,18 @@ permissions:
|
|||
mixtape.admin:
|
||||
description: Ability to use Mixtape command to reload
|
||||
default: op
|
||||
mixtape.list:
|
||||
description: Ability to use Mixtape command to list aliases
|
||||
default: op
|
||||
mixtape.list.other:
|
||||
description: Ability to use Mixtape command to list aliases of other players
|
||||
default: op
|
||||
mixtape.list.*:
|
||||
description: Wildcard permission for listing aliases
|
||||
default: op
|
||||
children:
|
||||
mixtape.list: true
|
||||
mixtape.list.other: true
|
||||
mixtape.alias.command:
|
||||
description: Ability to create personal alias commands
|
||||
default: op
|
||||
|
@ -32,4 +44,5 @@ permissions:
|
|||
default: op
|
||||
children:
|
||||
mixtape.admin: true
|
||||
mixtape.alias.*: true
|
||||
mixtape.alias.*: true
|
||||
mixtape.list.*: true
|
Loading…
Reference in New Issue