Bug fixes and cleanup

Signed-off-by: Etzelia <etzelia@hotmail.com>
main
Etzelia 2020-06-16 22:13:43 -05:00
parent 403d911be9
commit b711813bee
No known key found for this signature in database
GPG Key ID: 708511AE7ABC5314
6 changed files with 25 additions and 70 deletions

View File

@ -6,7 +6,7 @@
<groupId>xyz.etztech</groupId> <groupId>xyz.etztech</groupId>
<artifactId>Mixtape</artifactId> <artifactId>Mixtape</artifactId>
<version>2.1</version> <version>2.2</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Mixtape</name> <name>Mixtape</name>
@ -70,7 +70,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.14.3-R0.1-SNAPSHOT</version> <version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -5,7 +5,6 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import xyz.etztech.mixtape.commands.CommandAlias; import xyz.etztech.mixtape.commands.CommandAlias;
import xyz.etztech.mixtape.commands.CommandMixtape; import xyz.etztech.mixtape.commands.CommandMixtape;
import xyz.etztech.mixtape.commands.CommandSlashAlias;
import xyz.etztech.mixtape.listeners.CommandPreprocessListener; import xyz.etztech.mixtape.listeners.CommandPreprocessListener;
import java.util.ArrayList; import java.util.ArrayList;
@ -35,8 +34,8 @@ public final class Mixtape extends JavaPlugin {
database = new Database(this); database = new Database(this);
this.getCommand("mixtape").setExecutor(new CommandMixtape(this)); this.getCommand("mixtape").setExecutor(new CommandMixtape(this));
this.getCommand("alias").setExecutor(new CommandAlias(this)); this.getCommand("alias").setExecutor(new CommandAlias(this, Database.AliasType.CHAT));
this.getCommand("/alias").setExecutor(new CommandSlashAlias(this)); this.getCommand("/alias").setExecutor(new CommandAlias(this, Database.AliasType.COMMAND));
getServer().getPluginManager().registerEvents(new CommandPreprocessListener(this), this); getServer().getPluginManager().registerEvents(new CommandPreprocessListener(this), this);
} }

View File

@ -22,7 +22,7 @@ public class MixtapeUtil {
if (permission.getPermission().startsWith("mixtape.limit.") && permission.getValue()) { if (permission.getPermission().startsWith("mixtape.limit.") && permission.getValue()) {
try { try {
int p = Integer.parseInt(permission.getPermission().replaceFirst("mixtape.limit.", "")); int p = Integer.parseInt(permission.getPermission().replaceFirst("mixtape.limit.", ""));
limit = limit > p ? limit : p; limit = Math.max(limit, p);
} catch (Exception ignored) {} } catch (Exception ignored) {}
} }
} }

View File

@ -1,6 +1,7 @@
package xyz.etztech.mixtape.commands; package xyz.etztech.mixtape.commands;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -15,9 +16,11 @@ import java.util.Arrays;
public class CommandAlias implements CommandExecutor { public class CommandAlias implements CommandExecutor {
Mixtape plugin; Mixtape plugin;
Database.AliasType aliasType;
public CommandAlias(Mixtape plugin) { public CommandAlias(Mixtape plugin, Database.AliasType aliasType) {
this.plugin = plugin; this.plugin = plugin;
this.aliasType = aliasType;
} }
@Override @Override
@ -27,13 +30,17 @@ public class CommandAlias implements CommandExecutor {
return true; return true;
} }
Player player = (Player) sender; Player player = (Player) sender;
if (!player.hasPermission("mixtape.alias.chat")) {
player.sendMessage(ChatColor.RED + "You do not have permission to create chat aliases."); boolean isChat = this.aliasType == Database.AliasType.CHAT;
String aliasType = isChat ? "chat" : "command";
if (!player.hasPermission(String.format("mixtape.alias.%s", aliasType))) {
player.sendMessage(ChatColor.RED + String.format("You do not have permission to create %s aliases.", aliasType));
return true; return true;
} }
if (args.length < 2) { if (args.length < 2) {
player.sendMessage(ChatColor.RED + "/alias <alias> <chat>"); player.sendMessage(ChatColor.RED + (isChat ? "/" : "//") + String.format("alias <alias> <%s>", aliasType));
return true; return true;
} }
@ -46,9 +53,13 @@ public class CommandAlias implements CommandExecutor {
String command = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " "); String command = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " ");
Mixtape.getDatabase().insert(player.getUniqueId().toString(), alias, command, Database.AliasType.CHAT); if (command.length() > 200) {
player.sendMessage(ChatColor.GREEN + "Chat alias created."); player.sendMessage(ChatColor.RED + "This alias is too large. Aliases are limited to 200 characters.");
return true;
}
Mixtape.getDatabase().insert(player.getUniqueId().toString(), alias, command, isChat ? Database.AliasType.CHAT : Database.AliasType.COMMAND);
player.sendMessage(ChatColor.GREEN + String.format("%s alias created.", StringUtils.capitalize(aliasType)));
return true; return true;
} }
} }

View File

@ -1,54 +0,0 @@
package xyz.etztech.mixtape.commands;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import xyz.etztech.mixtape.Database;
import xyz.etztech.mixtape.Mixtape;
import xyz.etztech.mixtape.MixtapeUtil;
import java.util.Arrays;
public class CommandSlashAlias implements CommandExecutor {
Mixtape plugin;
public CommandSlashAlias(Mixtape plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "This command is not supported in Console.");
return true;
}
Player player = (Player) sender;
if (!player.hasPermission("mixtape.alias.command")) {
player.sendMessage(ChatColor.RED + "You do not have permission to create command aliases.");
return true;
}
if (args.length < 2) {
player.sendMessage(ChatColor.RED + "//alias <alias> <command>");
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), " ");
Mixtape.getDatabase().insert(player.getUniqueId().toString(), alias, command, Database.AliasType.COMMAND);
player.sendMessage(ChatColor.GREEN + "Command alias created.");
return true;
}
}

View File

@ -52,15 +52,14 @@ public class CommandPreprocessListener implements Listener {
String[] args = command.trim().length() == base.trim().length() ? new String[0] : command.substring(base.length()+1).split(" "); String[] args = command.trim().length() == base.trim().length() ? new String[0] : command.substring(base.length()+1).split(" ");
event.setCancelled(handleEvent(event.getPlayer(), base, args)); event.setCancelled(handleEvent(event.getPlayer(), base, args));
} }
private boolean handleEvent(CommandSender sender, String base, String[] args) { private boolean handleEvent(CommandSender sender, String base, String[] args) {
// Global aliases // Global aliases
if (Mixtape.getGlobal()) { if (Mixtape.getGlobal()) {
List<?> configs = plugin.getConfig().getList("aliases"); List<?> configs = plugin.getConfig().getList("aliases", new ArrayList<>());
for (int i = 0; i < configs.size(); i++) { for (Object c : configs) {
LinkedHashMap<String, String> config = (LinkedHashMap<String, String>) configs.get(i); LinkedHashMap<String, String> config = (LinkedHashMap<String, String>) c;
String configBase = MixtapeUtil.stripSlash(config.get("alias")); String configBase = MixtapeUtil.stripSlash(config.get("alias"));
if (configBase.equalsIgnoreCase(base)) { if (configBase.equalsIgnoreCase(base)) {
String configCommand = MixtapeUtil.stripSlash(config.get("command")); String configCommand = MixtapeUtil.stripSlash(config.get("command"));