1.1.0 | SubAlias, MiniMessage and more #3

Merged
JaTiTV merged 9 commits from 1.1 into main 2022-07-14 19:57:24 +00:00
16 changed files with 428 additions and 469 deletions
Showing only changes of commit d5669d82d4 - Show all commits

93
pom.xml
View File

@ -69,7 +69,8 @@
<dependency>
<groupId>net.t2code</groupId>
<artifactId>T2CodeLib</artifactId>
<version>12.0</version>
<version>12.4</version>
<classifier>dev-1</classifier>
</dependency>
<dependency>
<groupId>net.t2code</groupId>
@ -82,94 +83,10 @@
<version>3.0</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_18.r2</groupId>
<groupId>net.t2code.minecraft.1_19.r1</groupId>
<artifactId>spigot</artifactId>
<version>1.18r2</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_18.r1</groupId>
<artifactId>spigot</artifactId>
<version>1.18r1</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_17.r1</groupId>
<artifactId>spigot</artifactId>
<version>1.17r1</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_16.r3</groupId>
<artifactId>spigot</artifactId>
<version>1.16r3</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_16.r2</groupId>
<artifactId>spigot</artifactId>
<version>1.16r2</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_16.r1</groupId>
<artifactId>spigot</artifactId>
<version>1.16r1</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_15.r1</groupId>
<artifactId>spigot</artifactId>
<version>1.15r1</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_14.r1</groupId>
<artifactId>spigot</artifactId>
<version>1.14r1</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_13.r2</groupId>
<artifactId>spigot</artifactId>
<version>1.13r2</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_13.r1</groupId>
<artifactId>spigot</artifactId>
<version>1.13r1</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_12.r1</groupId>
<artifactId>spigot</artifactId>
<version>1.12r1</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_11.r1</groupId>
<artifactId>spigot</artifactId>
<version>1.11r1</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_10.r1</groupId>
<artifactId>spigot</artifactId>
<version>1.10r1</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_9.r2</groupId>
<artifactId>spigot</artifactId>
<version>1.9r2</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_9.r1</groupId>
<artifactId>spigot</artifactId>
<version>1.9r1</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_8.r3</groupId>
<artifactId>spigot</artifactId>
<version>1.8r3</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_8.r2</groupId>
<artifactId>spigot</artifactId>
<version>1.8r2</version>
</dependency>
<dependency>
<groupId>net.t2code.minecraft.1_8.r1</groupId>
<artifactId>spigot</artifactId>
<version>1.8r1</version>
<version>1.19r1</version>
</dependency>
</dependencies>
</project>

View File

@ -1,7 +1,7 @@
package net.t2code.alias.Spigot;
import net.t2code.alias.Spigot.objects.AliasObjekt;
import net.t2code.alias.Spigot.objects.SubAliasObjekt;
import net.t2code.alias.Spigot.objects.AliasObject;
import net.t2code.alias.Spigot.objects.SubAliasObject;
import net.t2code.alias.Spigot.system.Load;
import net.t2code.alias.Util;
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate;
@ -12,7 +12,6 @@ import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.logging.Level;
public final class Main extends JavaPlugin {
@ -23,10 +22,11 @@ public final class Main extends JavaPlugin {
public static String version;
public static List<String> autor;
public static Main plugin;
public static HashMap<String, AliasObjekt> aliasHashMap = new HashMap<>();
public static HashMap<String, SubAliasObjekt> subAliasHashMap = new HashMap<>();
public static HashMap<String, AliasObject> aliasHashMap = new HashMap<>();
public static HashMap<String, SubAliasObject> subAliasHashMap = new HashMap<>();
public static ArrayList<String> allAliases = new ArrayList<>();
public static ArrayList<String> allSubAliases = new ArrayList<>();
public static ArrayList<String> allForSubAliases = new ArrayList<>();
@Override
public void onEnable() {
@ -47,17 +47,32 @@ public final class Main extends JavaPlugin {
T2CodeTemplate.onDisable(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
}
public static Boolean pluginNotFound(String pl, Integer spigotID, double ver) {
public static Boolean pluginNotFound(String pl, Integer spigotID, String ver) {
if (Bukkit.getPluginManager().getPlugin(pl) == null) {
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §e" + pl + " §4could not be found. Please download it here: " +
"§6https://spigotmc.org/resources/" + pl + "." + spigotID + " §4to be able to use this plugin.");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §e" + pl + " §4could not be found. Please download it here: "
+ "§6https://spigotmc.org/resources/" + pl + "." + spigotID + " §4to be able to use this plugin.");
Main.plugin.getPluginLoader().disablePlugin(Main.plugin);
return true;
} else {
if (Double.parseDouble(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(pl)).getDescription().getVersion()) < ver) {
String plVer = Bukkit.getPluginManager().getPlugin(pl).getDescription().getVersion();
if (ver.contains("_")) {
if (!plVer.equals(ver)) {
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §e" + pl + " §4is out of date! This plugin requires the version §2"
+ ver + " §4of §6" + pl + " §4Please use this version! Please download it here or contact us in Discord: §6https://spigotmc.org/resources/"
+ pl + "." + spigotID + " Or contact us in Discord: http://dc.t2code.net");
Main.plugin.getPluginLoader().disablePlugin(Main.plugin);
return true;
}
return false;
}
String[] split = plVer.split("_");
if (Double.parseDouble(split[0]) < Double.parseDouble(ver)) {
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §e" + pl + " §4is out of date! This plugin requires at least version §2" + ver + " §4of §6" + pl + " §4Please update it here: §6https://spigotmc.org/resources/" + pl + "." + spigotID + " §4to use this version of " + plugin.getDescription().getName() + ".");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §e" + pl + " §4is out of date! This plugin requires at least version §2"
+ ver + " §4of §6" + pl + " §4Please update it here: §6https://spigotmc.org/resources/" + pl + "." + spigotID
+ " §4to use this version of " + plugin.getDescription().getName() + ".");
Main.plugin.getPluginLoader().disablePlugin(Main.plugin);
return true;
}

View File

@ -1,5 +1,6 @@
package net.t2code.alias.Spigot.cmdManagement;
import net.t2code.alias.Spigot.Main;
import net.t2code.alias.Spigot.config.languages.SelectMessages;
import net.t2code.lib.Spigot.Lib.messages.send;
import org.bukkit.command.Command;
@ -9,6 +10,7 @@ import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@ -60,6 +62,11 @@ public class AliasCmdExecuter implements CommandExecutor, TabCompleter {
List<String> list = new ArrayList<>();
if (sender instanceof Player) {
Player p = (Player) sender;
send.debugmsg(Main.plugin, "------------");
send.debugmsg(Main.plugin, "tab a: " + 0);
send.debugmsg(Main.plugin, "tab a: " + args.length);
send.debugmsg(Main.plugin, "tab a: " + Arrays.toString(args));
send.debugmsg(Main.plugin, "tab a: " + arg1.toString());
if (args.length == 1) {
for (String command : arg1.keySet()) {
Boolean passend = true;

View File

@ -0,0 +1,288 @@
package net.t2code.alias.Spigot.cmdManagement;
import net.t2code.alias.Spigot.config.config.SelectConfig;
import net.t2code.alias.Spigot.config.languages.SelectMessages;
import net.t2code.alias.Spigot.objects.AliasObject;
import net.t2code.alias.Spigot.objects.SubAliasObject;
import net.t2code.alias.Spigot.system.BCommandSenderReciver;
import net.t2code.alias.Util;
import net.t2code.lib.Spigot.Lib.commands.Cmd;
import net.t2code.lib.Spigot.Lib.eco.Eco;
import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.Lib.plugins.PluginCheck;
import net.t2code.lib.Spigot.Lib.replace.Replace;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ExecuteAlias {
private static final String prefix = Util.getPrefix();
protected static void aliasPlayer(CommandSender sender, AliasObject aliasObject, String alias) {
Player player = (Player) sender;
if (aliasObject.adminEnable) {
if (player.hasPermission(aliasObject.adminPermission)) {
if (aliasObject.adminCommandEnable) {
aliasAdminCommand(aliasObject, player);
}
if (aliasObject.adminMessageEnable) {
aliasAdminMessage(aliasObject, player);
}
return;
}
}
if (aliasObject.permNecessary) {
if (!(player.hasPermission("t2code.alias.use." + alias.toLowerCase()) || player.hasPermission("t2code.alias.admin"))) {
send.player(player, SelectMessages.noPermissionForCommand.replace("[cmd]", "/" + alias.toLowerCase())
.replace("[perm]", "t2code.alias.use." + alias.toLowerCase()));
return;
}
}
if (aliasObject.costEnable) {
if (!(aliasObject.costAllowBypass && player.hasPermission("t2code.alias.buy.bypass"))) {
if (!Eco.moneyRemove(prefix, player, aliasObject.costPrice)) {
send.player(player, SelectMessages.noMoney);
return;
}
if (SelectConfig.buyMessage) send.player(player, SelectMessages.buy.replace("[price]", aliasObject.costPrice.toString()));
}
}
if (aliasObject.commandEnable) {
aliasCommand(aliasObject, player);
}
if (aliasObject.messageEnable) {
aliasMessage(aliasObject, player);
}
}
protected static void subAliasPlayer(CommandSender sender, SubAliasObject aliasObject, String alias) {
if (!aliasObject.subAliasEnable) {
send.sender(sender, SelectMessages.aliasDisabled);
return;
}
if (sender instanceof Player) {
Player player = (Player) sender;
if (aliasObject.adminEnable) {
if (player.hasPermission(aliasObject.adminPermission)) {
if (aliasObject.adminCommandEnable) {
subAliasAdminCommand(aliasObject, player);
}
if (aliasObject.adminMessageEnable) {
subAliasAdminMessage(aliasObject, player);
}
return;
}
}
if (aliasObject.permNecessary) {
if (!(player.hasPermission("t2code.alias.use.subalias." + alias.toLowerCase()) || player.hasPermission("t2code.alias.admin"))) {
send.player(player, SelectMessages.noPermissionForCommand.replace("[cmd]", "/" + alias.toLowerCase())
.replace("[perm]", "t2code.alias.subalias.use." + alias.toLowerCase()));
return;
}
}
if (aliasObject.costEnable) {
if (!(aliasObject.costAllowBypass && player.hasPermission("t2code.alias.buy.bypass"))) {
if (!Eco.moneyRemove(prefix, player, aliasObject.costPrice)) {
send.player(player, SelectMessages.noMoney);
return;
}
if (SelectConfig.buyMessage) send.player(player, SelectMessages.buy.replace("[price]", aliasObject.costPrice.toString()));
}
}
if (aliasObject.commandEnable) {
subAliasCommand(aliasObject, player);
}
if (aliasObject.messageEnable) {
subAliasMessage(aliasObject, player);
}
} else {
if (aliasObject.consoleEnable) {
subAliasConsole(aliasObject, sender);
} else send.sender(sender, SelectMessages.onlyForPlayer);
}
}
protected static void aliasConsole(AliasObject alias, CommandSender sender, String prefix) {
if (alias.consoleCommandEnable) {
for (String cmd : alias.consoleCommands) {
if (alias.consoleBungeeCommand) {
if (SelectConfig.Bungee) {
BCommandSenderReciver.sendToBungee(sender, cmd, true);
} else {
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
send.sender(sender, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
}
} else {
Cmd.console(cmd);
}
}
}
if (alias.consoleMessageEnable) {
for (String msg : alias.consoleMessages) {
send.console(Replace.replace(prefix, msg));
}
}
}
private static void subAliasConsole(SubAliasObject alias, CommandSender sender) {
if (alias.consoleCommandEnable) {
for (String cmd : alias.consoleCommands) {
if (alias.consoleBungeeCommand) {
if (SelectConfig.Bungee) {
BCommandSenderReciver.sendToBungee(sender, cmd, true);
} else {
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
send.sender(sender, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
}
} else {
Cmd.console(cmd);
}
}
}
if (alias.consoleMessageEnable) {
for (String msg : alias.consoleMessages) {
send.console(Replace.replace(prefix, msg));
}
}
}
private static void aliasAdminCommand(AliasObject alias, Player player) {
for (String cmd : alias.adminCommands) {
if (alias.adminBungeeCommand) {
if (SelectConfig.Bungee) {
BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), alias.adminCommandAsConsole);
} else {
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
}
} else {
if (alias.adminCommandAsConsole) {
Cmd.console(cmd.replace("[player]", player.getName()));
} else {
Cmd.player(player, cmd.replace("[player]", player.getName()));
}
}
}
}
private static void subAliasAdminCommand(SubAliasObject alias, Player player) {
for (String cmd : alias.adminCommands) {
if (alias.adminBungeeCommand) {
if (SelectConfig.Bungee) {
BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), alias.adminCommandAsConsole);
} else {
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
}
} else {
if (alias.adminCommandAsConsole) {
Cmd.console(cmd.replace("[player]", player.getName()));
} else {
Cmd.player(player, cmd.replace("[player]", player.getName()));
}
}
}
}
private static void aliasAdminMessage(AliasObject alias, Player player) {
for (String msg : alias.adminMessages) {
String text;
String hover;
if (PluginCheck.papi()) {
text = Replace.replace(prefix, player, replacePlayer(msg, player));
} else {
text = Replace.replace(prefix, replacePlayer(msg, player));
}
send.player(player, text);
}
}
private static void subAliasAdminMessage(SubAliasObject alias, Player player) {
for (String msg : alias.adminMessages) {
String text;
String hover;
if (PluginCheck.papi()) {
text = Replace.replace(prefix, player, replacePlayer(msg, player));
} else {
text = Replace.replace(prefix, replacePlayer(msg, player));
}
send.player(player, text);
}
}
private static void aliasCommand(AliasObject alias, Player player) {
for (String cmd : alias.command) {
if (alias.bungeeCommand) {
if (SelectConfig.Bungee) {
BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), alias.commandAsConsole);
} else {
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
}
} else {
if (alias.commandAsConsole) {
Cmd.console(cmd.replace("[player]", player.getName()));
} else {
Cmd.player(player, cmd.replace("[player]", player.getName()));
}
}
}
}
private static void subAliasCommand(SubAliasObject alias, Player player) {
for (String cmd : alias.command) {
if (alias.bungeeCommand) {
if (SelectConfig.Bungee) {
BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), alias.commandAsConsole);
} else {
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
}
} else {
if (alias.commandAsConsole) {
Cmd.console(cmd.replace("[player]", player.getName()));
} else {
Cmd.player(player, cmd.replace("[player]", player.getName()));
}
}
}
}
private static void aliasMessage(AliasObject alias, Player player) {
for (String msg : alias.messages) {
String text;
String hover;
if (PluginCheck.papi()) {
text = Replace.replace(prefix, player, replacePlayer(msg, player));
} else {
text = Replace.replace(prefix, replacePlayer(msg, player));
}
send.player(player, text);
}
}
private static void subAliasMessage(SubAliasObject alias, Player player) {
for (String msg : alias.messages) {
String text;
String hover;
if (PluginCheck.papi()) {
text = Replace.replace(prefix, player, replacePlayer(msg, player));
} else {
text = Replace.replace(prefix, replacePlayer(msg, player));
}
send.player(player, text);
}
}
private static String replacePlayer(String s, Player player) {
return s.replace("[player]", player.getName());
}
}

View File

@ -1,28 +1,16 @@
package net.t2code.alias.Spigot.cmdManagement;
import net.t2code.alias.Spigot.Main;
import net.t2code.alias.Spigot.config.config.SelectConfig;
import net.t2code.alias.Spigot.config.languages.SelectMessages;
import net.t2code.alias.Spigot.objects.AliasObjekt;
import net.t2code.alias.Spigot.objects.SubAliasObjekt;
import net.t2code.alias.Spigot.system.*;
import net.t2code.alias.Spigot.objects.AliasObject;
import net.t2code.alias.Spigot.objects.SubAliasObject;
import net.t2code.alias.Util;
import net.t2code.lib.Spigot.Lib.commands.Cmd;
import net.t2code.lib.Spigot.Lib.commands.Tab;
import net.t2code.lib.Spigot.Lib.eco.Eco;
import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.Lib.plugins.PluginCheck;
import net.t2code.lib.Spigot.Lib.replace.Replace;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class RegisterCommands extends Command implements TabCompleter {
public class RegisterCommands extends Command {
private String alias;
private String prefix = Util.getPrefix();
@ -33,7 +21,8 @@ public class RegisterCommands extends Command implements TabCompleter {
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
AliasObjekt alias = Main.aliasHashMap.get(this.alias);
send.debugmsg(Main.plugin, "tabevent");
AliasObject alias = Main.aliasHashMap.get(this.alias);
if (!alias.aliasEnable) {
send.sender(sender, SelectMessages.aliasDisabled);
@ -41,19 +30,20 @@ public class RegisterCommands extends Command implements TabCompleter {
}
if (args.length == 0) {
if (sender instanceof Player) {
exPlayer(sender, alias);
ExecuteAlias.aliasPlayer(sender, alias, this.alias);
} else {
if (alias.consoleEnable) {
console(alias, sender, prefix);
ExecuteAlias.aliasConsole(alias, sender, prefix);
} else send.sender(sender, SelectMessages.onlyForPlayer);
}
} else {
if (!Main.allForSubAliases.contains(this.alias)) return false;
for (String sals : Main.allSubAliases) {
SubAliasObjekt sal = Main.subAliasHashMap.get(sals);
if (args.length == sal.subAliasArg) {
SubAliasObject sal = Main.subAliasHashMap.get(sals);
if (args.length == sal.subAliasArg + 1) {
for (String al : sal.subAliasList) {
if (args[sal.subAliasArg].toLowerCase().equals(al)) {
RegisterSubAliasCommands.execute(sender, sal, al);
ExecuteAlias.subAliasPlayer(sender, sal, al);
}
}
}
@ -61,156 +51,5 @@ public class RegisterCommands extends Command implements TabCompleter {
}
return true;
}
private void exPlayer(CommandSender sender, AliasObjekt alias) {
Player player = (Player) sender;
if (alias.adminEnable) {
if (player.hasPermission(alias.adminPermission)) {
if (alias.adminCommandEnable) {
adminCommand(alias, player);
}
if (alias.adminMessageEnable) {
adminMessage(alias, player, prefix);
}
return;
}
}
if (alias.permNecessary) {
if (!(player.hasPermission("t2code.alias.use." + this.alias.toLowerCase()) || player.hasPermission("t2code.alias.admin"))) {
send.player(player, SelectMessages.noPermissionForCommand.replace("[cmd]", "/" + this.alias.toLowerCase())
.replace("[perm]", "t2code.alias.use." + this.alias.toLowerCase()));
return;
}
}
if (alias.costEnable) {
if (!(alias.costAllowBypass && player.hasPermission("t2code.alias.buy.bypass"))) {
if (!Eco.moneyRemove(prefix, player, alias.costPrice)) {
send.player(player, SelectMessages.noMoney);
return;
}
if (SelectConfig.buyMessage) send.player(player, SelectMessages.buy.replace("[price]", alias.costPrice.toString()));
}
}
if (alias.commandEnable) {
command(alias, player);
}
if (alias.messageEnable) {
message(alias, player, prefix);
}
}
private static void adminCommand(AliasObjekt alias, Player player) {
for (String cmd : alias.adminCommands) {
if (alias.adminBungeeCommand) {
if (SelectConfig.Bungee) {
if (alias.adminCommandAsConsole) {
BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), true);
} else BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), false);
} else {
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
}
} else {
if (alias.adminCommandAsConsole) {
Cmd.console(cmd.replace("[player]", player.getName()));
} else {
Cmd.player(player, cmd.replace("[player]", player.getName()));
}
}
}
}
private static void adminMessage(AliasObjekt alias, Player player, String prefix) {
for (String msg : alias.adminMessages) {
String text;
String hover;
if (PluginCheck.papi()) {
text = Replace.replace(prefix, player, replacePlayer(msg, player));
} else {
text = Replace.replace(prefix, replacePlayer(msg, player));
}
send.player(player, text);
}
}
private static void command(AliasObjekt alias, Player player) {
for (String cmd : alias.command) {
if (alias.bungeeCommand) {
if (SelectConfig.Bungee) {
if (alias.commandAsConsole) {
BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), true);
} else BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), false);
} else {
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
}
} else {
if (alias.commandAsConsole) {
Cmd.console(cmd.replace("[player]", player.getName()));
} else {
Cmd.player(player, cmd.replace("[player]", player.getName()));
}
}
}
}
private static void message(AliasObjekt alias, Player player, String prefix) {
for (String msg : alias.messages) {
String text;
String hover;
if (PluginCheck.papi()) {
text = Replace.replace(prefix, player, replacePlayer(msg, player));
} else {
text = Replace.replace(prefix, replacePlayer(msg, player));
}
send.player(player, text);
}
}
private static void console(AliasObjekt alias, CommandSender sender, String prefix) {
if (alias.consoleCommandEnable) {
for (String cmd : alias.consoleCommands) {
if (alias.consoleBungeeCommand) {
if (SelectConfig.Bungee) {
BCommandSenderReciver.sendToBungee(sender, cmd, true);
} else {
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
send.sender(sender, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
}
} else {
Cmd.console(cmd);
}
}
}
if (alias.consoleMessageEnable) {
for (String msg : alias.consoleMessages) {
send.console(Replace.replace(prefix, msg));
}
}
}
private static String replacePlayer(String s, Player player) {
return s.replace("[player]", player.getName());
}
private static HashMap<String, String> arg1 = new HashMap<String, String>();
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String s, String[] args) {
List<String> list = new ArrayList<>();
arg1.clear();
for (String sals : Main.allSubAliases) {
SubAliasObjekt sal = Main.subAliasHashMap.get(sals);
for (String al : sal.subAliasList) {
arg1.put(al, "t2code.alias.use.subalias." + al.toLowerCase());
}
Tab.tab(list, sender, sal.subAliasArg, args, arg1);
}
return list;
}
}

View File

@ -1,166 +0,0 @@
package net.t2code.alias.Spigot.cmdManagement;
import net.t2code.alias.Spigot.config.config.SelectConfig;
import net.t2code.alias.Spigot.config.languages.SelectMessages;
import net.t2code.alias.Spigot.objects.SubAliasObjekt;
import net.t2code.alias.Spigot.system.BCommandSenderReciver;
import net.t2code.alias.Util;
import net.t2code.lib.Spigot.Lib.commands.Cmd;
import net.t2code.lib.Spigot.Lib.eco.Eco;
import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.Lib.plugins.PluginCheck;
import net.t2code.lib.Spigot.Lib.replace.Replace;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RegisterSubAliasCommands {
private static String prefix = Util.getPrefix();
public static void execute(CommandSender sender, SubAliasObjekt alias, String aliasString) {
if (!alias.subAliasEnable) {
send.sender(sender, SelectMessages.aliasDisabled);
return ;
}
if (sender instanceof Player) {
Player player = (Player) sender;
if (alias.adminEnable) {
if (player.hasPermission(alias.adminPermission)) {
if (alias.adminCommandEnable) {
adminCommand(alias, player);
}
if (alias.adminMessageEnable) {
adminMessage(alias, player, prefix);
}
return ;
}
}
if (alias.permNecessary) {
if (!(player.hasPermission("t2code.alias.use.subalias." + aliasString.toLowerCase()) || player.hasPermission("t2code.alias.admin"))) {
send.player(player, SelectMessages.noPermissionForCommand.replace("[cmd]", "/" +aliasString.toLowerCase())
.replace("[perm]", "t2code.alias.subalias.use." + aliasString.toLowerCase()));
return ;
}
}
if (alias.costEnable) {
if (!(alias.costAllowBypass && player.hasPermission("t2code.alias.buy.bypass"))) {
if (!Eco.moneyRemove(prefix, player, alias.costPrice)) {
send.player(player, SelectMessages.noMoney);
return ;
}
if (SelectConfig.buyMessage) send.player(player, SelectMessages.buy.replace("[price]", alias.costPrice.toString()));
}
}
if (alias.commandEnable) {
command(alias, player);
}
if (alias.messageEnable) {
message(alias, player, prefix);
}
} else {
if (alias.consoleEnable) {
console(alias, sender, prefix);
} else send.sender(sender, SelectMessages.onlyForPlayer);
}
}
private static void adminCommand(SubAliasObjekt alias, Player player) {
for (String cmd : alias.adminCommands) {
if (alias.adminBungeeCommand) {
if (SelectConfig.Bungee) {
if (alias.adminCommandAsConsole) {
BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), true);
} else BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), false);
} else {
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
}
} else {
if (alias.adminCommandAsConsole) {
Cmd.console(cmd.replace("[player]", player.getName()));
} else {
Cmd.player(player, cmd.replace("[player]", player.getName()));
}
}
}
}
private static void adminMessage(SubAliasObjekt alias, Player player, String prefix) {
for (String msg : alias.adminMessages) {
String text;
String hover;
if (PluginCheck.papi()) {
text = Replace.replace(prefix, player, replacePlayer(msg, player));
} else {
text = Replace.replace(prefix, replacePlayer(msg, player));
}
send.player(player, text);
}
}
private static void command(SubAliasObjekt alias, Player player) {
for (String cmd : alias.command) {
if (alias.bungeeCommand) {
if (SelectConfig.Bungee) {
if (alias.commandAsConsole) {
BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), true);
} else BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), false);
} else {
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
}
} else {
if (alias.commandAsConsole) {
Cmd.console(cmd.replace("[player]", player.getName()));
} else {
Cmd.player(player, cmd.replace("[player]", player.getName()));
}
}
}
}
private static void message(SubAliasObjekt alias, Player player, String prefix) {
for (String msg : alias.messages) {
String text;
String hover;
if (PluginCheck.papi()) {
text = Replace.replace(prefix, player, replacePlayer(msg, player));
} else {
text = Replace.replace(prefix, replacePlayer(msg, player));
}
send.player(player, text);
}
}
private static void console(SubAliasObjekt alias, CommandSender sender, String prefix) {
if (alias.consoleCommandEnable) {
for (String cmd : alias.consoleCommands) {
if (alias.consoleBungeeCommand) {
if (SelectConfig.Bungee) {
BCommandSenderReciver.sendToBungee(sender, cmd, true);
} else {
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
send.sender(sender, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
}
} else {
Cmd.console(cmd);
}
}
}
if (alias.consoleMessageEnable) {
for (String msg : alias.consoleMessages) {
send.console(Replace.replace(prefix, msg));
}
}
}
private static String replacePlayer(String s, Player player) {
return s.replace("[player]", player.getName());
}
}

View File

@ -0,0 +1,49 @@
package net.t2code.alias.Spigot.cmdManagement;
import net.t2code.alias.Spigot.Main;
import net.t2code.alias.Spigot.objects.SubAliasObject;
import net.t2code.lib.Spigot.Lib.commands.Tab;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.TabCompleteEvent;
import org.bukkit.plugin.Plugin;
import java.util.*;
public class TabEvent implements Listener {
Plugin plugin = Main.plugin;
private static HashMap<String, String> arg1 = new HashMap<String, String>();
@EventHandler
public void onTab(TabCompleteEvent e) {
String buffer = e.getBuffer();
String[] imp = buffer.replace("/", "").split(" ");
if (!Main.allAliases.contains(imp[0])) return;
if (!Main.allForSubAliases.contains(imp[0])) return;
arg1.clear();
List<String> list = new ArrayList<>(Collections.emptyList());
for (String sals : Main.allSubAliases) {
SubAliasObject sal = Main.subAliasHashMap.get(sals);
if (!buffer.contains(sal.subAliasFor)) continue;
String[] im = sal.subAliasFor.split(" ");
String input = buffer.replace("/" + im[0] + " ", "");
String[] args = input.split(" ", -1);
for (String al : sal.subAliasList) {
arg1.put(al, "t2code.alias.use.subalias." + al.toLowerCase());
}
int arg = sal.subAliasArg;
if (args.length - 1 == arg) {
for (String command : sal.subAliasList) {
if (Tab.hasPermission(e.getSender(), arg1.get(command)) && Tab.passend(command, args[arg])) {
list.add(command);
}
}
}
}
e.setCompletions(list);
}
}

View File

@ -22,7 +22,7 @@ public class CreateExampleSubAliasConfig {
Config.set("SubAlias.Enable", true, yamlConfiguration);
Config.set("SubAlias.SubAliasList", Arrays.asList("test"),yamlConfiguration);
Config.set("SubAlias.SubAliasFor", Arrays.asList("aliasexample1"),yamlConfiguration);
Config.set("SubAlias.SubAliasFor", "aliasexample1",yamlConfiguration);
Config.set("SubAlias.Permission.Necessary", true, yamlConfiguration);
@ -49,7 +49,7 @@ public class CreateExampleSubAliasConfig {
Config.set("SubAlias.Admin.Command.Enable", true, yamlConfiguration);
Config.set("SubAlias.Admin.Command.CommandAsConsole", true, yamlConfiguration);
Config.set("SubAlias.Admin.Command.BungeeCommand", false, yamlConfiguration);
Config.set("SubAlias.Admin.Command.Commands", Collections.singletonList("say hi"), yamlConfiguration);
Config.set("SubAlias.Admin.Command.Commands", Collections.singletonList("say subalias hi"), yamlConfiguration);
Config.set("SubAlias.Admin.Message.Enable", false, yamlConfiguration);
Config.set("SubAlias.Admin.Message.Messages", Collections.emptyList(), yamlConfiguration);

View File

@ -1,16 +1,13 @@
package net.t2code.alias.Spigot.config.config;
import net.minecraft.world.level.levelgen.DensityFunctions;
import net.t2code.alias.Spigot.Main;
import net.t2code.alias.Spigot.system.AliasRegister;
import net.t2code.alias.Spigot.objects.AliasObjekt;
import net.t2code.alias.Spigot.objects.AliasObject;
import net.t2code.alias.Util;
import net.t2code.lib.Spigot.Lib.messages.send;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -69,11 +66,12 @@ public class SelectAlias {
List<String> consoleMessages = yamlConfiguration.getStringList("Alias.Console.Message.Messages");
Main.allAliases.addAll(aliasList);
AliasObjekt alias = new AliasObjekt(aliasEnable, aliasList, permNecessary, costEnable, costPrice, costAllowBypass, commandEnable, commandAsConsole, bungeeCommand,
AliasObject alias = new AliasObject(aliasEnable, aliasList, permNecessary, costEnable, costPrice, costAllowBypass, commandEnable, commandAsConsole, bungeeCommand,
command, messageEnable, messages, adminEnable, adminPermission, adminCommandEnable, adminCommandAsConsole, adminBungeeCommand, adminCommands,
adminMessageEnable, adminMessages, consoleEnable, consoleCommandEnable, consoleBungeeCommand, consoleCommands, consoleMessageEnable, consoleMessages);
for (String al : aliasList) {
send.debugmsg(Main.plugin,"put " + al);
Main.aliasHashMap.put(al, alias);
}
}

View File

@ -1,10 +1,7 @@
package net.t2code.alias.Spigot.config.config;
import net.minecraft.world.level.levelgen.DensityFunctions;
import net.t2code.alias.Spigot.Main;
import net.t2code.alias.Spigot.objects.SubAliasObjekt;
import net.t2code.alias.Spigot.system.AliasRegister;
import net.t2code.alias.Spigot.objects.AliasObjekt;
import net.t2code.alias.Spigot.objects.SubAliasObject;
import net.t2code.alias.Util;
import net.t2code.lib.Spigot.Lib.messages.send;
import org.bukkit.configuration.file.YamlConfiguration;
@ -17,8 +14,8 @@ public class SelectSubAlias {
public static void onSelect() {
Main.aliasHashMap.clear();
Main.allAliases.clear();
Main.subAliasHashMap.clear();
Main.allSubAliases.clear();
File f = new File(Main.getPath() + "/SubAlias/");
File[] fileArray = f.listFiles();
for (File config_gui : fileArray) {
@ -31,7 +28,16 @@ public class SelectSubAlias {
Boolean aliasEnable = yamlConfiguration.getBoolean("SubAlias.Enable");
List<String> subAliasList = yamlConfiguration.getStringList("SubAlias.SubAliasList");
String subAliasFor = yamlConfiguration.getString("SubAlias.SubAliasFor");
Integer subAliasArg = yamlConfiguration.getInt("SubAlias.SubAliasArg");
String[] imp = subAliasFor.split(" ");
if (!Main.allAliases.contains(imp[0])) {
send.error(Main.plugin, "Den Alias " + imp[0] + " in der Datei " + config_gui.getName() + " existiert nicht!");
}
int subAliasArg = 0;
if (subAliasFor != null) {
String[] args = subAliasFor.split(" ");
send.debugmsg(Main.plugin, config_gui.getName() + " " +String.valueOf(args.length));
subAliasArg = args.length - 1;
}
Boolean permNecessary = yamlConfiguration.getBoolean("SubAlias.Permission.Necessary");
Boolean costEnable = yamlConfiguration.getBoolean("SubAlias.Cost.Enable");
@ -64,13 +70,14 @@ public class SelectSubAlias {
Boolean consoleMessageEnable = yamlConfiguration.getBoolean("SubAlias.Console.Message.Enable");
List<String> consoleMessages = yamlConfiguration.getStringList("SubAlias.Console.Message.Messages");
SubAliasObjekt subAlias = new SubAliasObjekt(aliasEnable, subAliasList, subAliasFor, subAliasArg, permNecessary, costEnable, costPrice, costAllowBypass, commandEnable, commandAsConsole, bungeeCommand,
SubAliasObject subAlias = new SubAliasObject(aliasEnable, subAliasList, subAliasFor, subAliasArg, permNecessary, costEnable, costPrice, costAllowBypass, commandEnable, commandAsConsole, bungeeCommand,
command, messageEnable, messages, adminEnable, adminPermission, adminCommandEnable, adminCommandAsConsole, adminBungeeCommand, adminCommands,
adminMessageEnable, adminMessages, consoleEnable, consoleCommandEnable, consoleBungeeCommand, consoleCommands, consoleMessageEnable, consoleMessages);
for (String sal : subAliasList) {
Main.subAliasHashMap.put(sal, subAlias);
}
Main.allSubAliases.addAll(subAliasList);
Main.allForSubAliases.add(subAliasFor);
}
}
}

View File

@ -2,7 +2,7 @@ package net.t2code.alias.Spigot.objects;
import java.util.List;
public class AliasObjekt {
public class AliasObject {
public Boolean aliasEnable;
public List<String> aliasList;
@ -35,7 +35,7 @@ public class AliasObjekt {
public Boolean consoleMessageEnable;
public List<String> consoleMessages;
public AliasObjekt(Boolean aliasEnable,
public AliasObject(Boolean aliasEnable,
List<String> aliasList,
Boolean permNecessary,

View File

@ -2,7 +2,7 @@ package net.t2code.alias.Spigot.objects;
import java.util.List;
public class SubAliasObjekt {
public class SubAliasObject {
public Boolean subAliasEnable;
public List<String> subAliasList;
public Integer subAliasArg;
@ -37,7 +37,7 @@ public class SubAliasObjekt {
public Boolean consoleMessageEnable;
public List<String> consoleMessages;
public SubAliasObjekt(Boolean subAliasEnable,
public SubAliasObject(Boolean subAliasEnable,
List<String> subAliasList,
String subAliasFor,
Integer subAliasArg,

View File

@ -1,6 +1,7 @@
package net.t2code.alias.Spigot.system;
import net.t2code.alias.Spigot.Main;
import net.t2code.alias.Spigot.cmdManagement.AliasCmdExecuter;
import net.t2code.alias.Spigot.cmdManagement.RegisterCommands;
import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.Lib.minecraftVersion.NMSVersion;
@ -19,12 +20,10 @@ public class AliasRegister {
if (Main.aliasHashMap.get(alias).aliasEnable) {
try {
final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
bukkitCommandMap.setAccessible(true);
CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer());
commandMap.register(alias, new RegisterCommands(alias));
} catch(Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
}

View File

@ -2,12 +2,14 @@ package net.t2code.alias.Spigot.system;
import net.t2code.alias.Spigot.Main;
import net.t2code.alias.Spigot.cmdManagement.AliasCmdExecuter;
import net.t2code.alias.Spigot.cmdManagement.TabEvent;
import net.t2code.alias.Spigot.config.config.*;
import net.t2code.alias.Spigot.config.languages.LanguagesCreate;
import net.t2code.alias.Spigot.config.languages.SelectMessages;
import net.t2code.alias.Util;
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate;
import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.Lib.register.Register;
import net.t2code.lib.Spigot.Lib.update.UpdateAPI;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
@ -18,6 +20,7 @@ import java.util.List;
public class Load {
static Plugin plugin = Main.plugin;
public static void onLoad(String prefix, List autor, String version, String spigot, int spigotID, String discord, int bstatsID) {
Long long_ = T2CodeTemplate.onLoadHeader(prefix, autor, version, spigot, discord);
Main.plugin.getCommand("t2code-alias").setExecutor(new AliasCmdExecuter());
@ -25,7 +28,7 @@ public class Load {
UpdateAPI.onUpdateCheck(plugin, prefix, spigot, spigotID, discord);
Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), plugin);
T2CodeTemplate.onLoadFooter(prefix, long_,version);
T2CodeTemplate.onLoadFooter(prefix, long_, version);
Metrics.Bstats(plugin, bstatsID);
}
@ -35,18 +38,20 @@ public class Load {
CreateExampleAliasConfig.configCreate();
} catch (Exception e) {
e.printStackTrace();
}try {
}
try {
CreateExampleSubAliasConfig.configCreate();
} catch (Exception e) {
e.printStackTrace();
}
}
try {
plugin.saveResource("Alias/X_aliasDeclaration_X.yml",true);
plugin.saveResource("Alias/X_aliasDeclaration_X.yml", true);
} catch (Exception e) {
e.printStackTrace();
}try {
plugin.saveResource("SubAlias/X_subaliasDeclaration_X.yml",true);
}
try {
plugin.saveResource("SubAlias/X_subAliasDeclaration_X.yml", true);
} catch (Exception e) {
e.printStackTrace();
}
@ -56,6 +61,7 @@ public class Load {
SelectMessages.onSelect(Util.getPrefix());
SelectAlias.onSelect();
SelectSubAlias.onSelect();
Register.listener(new TabEvent(), plugin);
if (SelectConfig.Bungee) {
Main.plugin.getServer().getMessenger().registerOutgoingPluginChannel(Main.plugin, "BungeeCord");
@ -63,11 +69,11 @@ public class Load {
}
AliasRegisterPermissions.onPermRegister();
send.debugmsg(plugin,Main.aliasHashMap.toString());
send.debugmsg(plugin,Main.allAliases.toString());
send.debugmsg(plugin,Main.subAliasHashMap.toString());
send.debugmsg(plugin, Main.aliasHashMap.toString());
send.debugmsg(plugin, Main.allAliases.toString());
send.debugmsg(plugin, Main.subAliasHashMap.toString());
send.debugmsg(plugin,Main.allSubAliases.toString());
send.debugmsg(plugin, Main.allSubAliases.toString());
}
}

View File

@ -1,14 +1,14 @@
package net.t2code.alias;
public class Util {
private static double requiredT2CodeLibVersion = 11.6;
private static String requiredT2CodeLibVersion = "12.4_dev-1";
private static String Prefix = "§8[§4T2Code§7-§aAlias§8]";
private static Integer SpigotID = 96389;
private static Integer BstatsID = 12517;
private static String Spigot = "https://www.spigotmc.org/resources/" + SpigotID;
private static String Discord = "http://dc.t2code.net";
public static double getRequiredT2CodeLibVersion() {
public static String getRequiredT2CodeLibVersion() {
return requiredT2CodeLibVersion;
}