Updated to latest changes from private repo

main
Etzelia 2018-09-12 11:05:11 -05:00 committed by John Olheiser
parent d8a895f7f3
commit bc4e7d5aab
4 changed files with 33 additions and 7 deletions

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>xyz.etztech</groupId> <groupId>xyz.etztech</groupId>
<artifactId>mixtape</artifactId> <artifactId>Mixtape</artifactId>
<version>1.0</version> <version>1.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -18,6 +18,8 @@ public final class Mixtape extends JavaPlugin {
private static Mixtape instance; private static Mixtape instance;
public static FileConfiguration config; public static FileConfiguration config;
private static int loops;
private static Map<String, Map<String, String>> chatAliases = new HashMap<>(); private static Map<String, Map<String, String>> chatAliases = new HashMap<>();
private static Map<String, Map<String, String>> commandAliases = new HashMap<>(); private static Map<String, Map<String, String>> commandAliases = new HashMap<>();
private static boolean global; private static boolean global;
@ -45,6 +47,7 @@ public final class Mixtape extends JavaPlugin {
public void reloadConfig() { public void reloadConfig() {
super.reloadConfig(); super.reloadConfig();
config = Bukkit.getPluginManager().getPlugin("Mixtape").getConfig(); config = Bukkit.getPluginManager().getPlugin("Mixtape").getConfig();
loops = config.getInt("loop");
validate(); validate();
} }
@ -92,6 +95,10 @@ public final class Mixtape extends JavaPlugin {
global = bool; global = bool;
} }
public static int getLoops() {
return loops;
}
private void validate() { private void validate() {
List<String> errors = new ArrayList<>(); List<String> errors = new ArrayList<>();
try { try {

View File

@ -13,10 +13,7 @@ import org.bukkit.event.server.ServerCommandEvent;
import xyz.etztech.mixtape.Mixtape; import xyz.etztech.mixtape.Mixtape;
import xyz.etztech.mixtape.MixtapeUtil; import xyz.etztech.mixtape.MixtapeUtil;
import java.util.Arrays; import java.util.*;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -25,6 +22,8 @@ public class CommandPreprocessListener implements Listener {
private final String ERROR = "Mixtape/Error"; private final String ERROR = "Mixtape/Error";
private final Pattern PATTERN = Pattern.compile("<([^>]+)>"); private final Pattern PATTERN = Pattern.compile("<([^>]+)>");
private static Map<String, Integer> loops = new HashMap<>();
Mixtape plugin; Mixtape plugin;
public CommandPreprocessListener(Mixtape plugin) { public CommandPreprocessListener(Mixtape plugin) {
@ -78,13 +77,20 @@ public class CommandPreprocessListener implements Listener {
if (sender instanceof Player) { if (sender instanceof Player) {
Player player = (Player) sender; Player player = (Player) sender;
if (!increment(player.getUniqueId().toString())) {
player.sendMessage(ChatColor.RED + "You went too deep! What is this, Inception?");
loops.put(player.getUniqueId().toString(), 0);
return true;
}
// Command aliases // Command aliases
Map<String, String> commands = Mixtape.getCommandAliases(player.getUniqueId().toString()); Map<String, String> commands = Mixtape.getCommandAliases(player.getUniqueId().toString());
for (String alias : commands.keySet()) { for (String alias : commands.keySet()) {
if (alias.equalsIgnoreCase(base)) { if (alias.equalsIgnoreCase(base)) {
String resolved = resolve(commands.get(alias), args); String resolved = resolve(commands.get(alias), args);
resolved = resolved.startsWith("/") ? resolved : "/" + resolved;
if (!ERROR.equalsIgnoreCase(resolved)) { if (!ERROR.equalsIgnoreCase(resolved)) {
Bukkit.dispatchCommand(player, resolved); player.chat(resolved);
} else { } else {
player.sendMessage(ChatColor.RED + usage(base, commands.get(alias))); player.sendMessage(ChatColor.RED + usage(base, commands.get(alias)));
} }
@ -106,6 +112,7 @@ public class CommandPreprocessListener implements Listener {
return true; return true;
} }
} }
loops.put(player.getUniqueId().toString(), 0);
} }
return false; return false;
@ -136,5 +143,13 @@ public class CommandPreprocessListener implements Listener {
return template.trim() + " " + StringUtils.join(Arrays.copyOfRange(parts, idx, parts.length), " "); return template.trim() + " " + StringUtils.join(Arrays.copyOfRange(parts, idx, parts.length), " ");
} }
private static boolean increment(String uuid) {
Integer current = loops.get(uuid);
current = current == null ? 1 : ++current;
loops.put(uuid, current);
return current <= Mixtape.getLoops();
}
} }

View File

@ -3,4 +3,8 @@
# You could run /donator Etzelia 1m # You could run /donator Etzelia 1m
aliases: aliases:
- alias: /donator - alias: /donator
command: /lp user <username> parent addtemp donator <time> accumulate command: /lp user <username> parent addtemp donator <time> accumulate
# How many times can an alias call another alias before aborting?
loop: 5