code changes | update status 80%

This commit is contained in:
JaTiTV 2022-07-07 13:48:08 +02:00
parent d5669d82d4
commit 41c2c95b36
21 changed files with 135 additions and 77 deletions

View File

@ -19,9 +19,9 @@ public final class Main extends JavaPlugin {
return plugin.getDataFolder();
}
public static String version;
public static List<String> autor;
public static Main plugin;
private static String version;
private static List<String> autor;
private static Main plugin;
public static HashMap<String, AliasObject> aliasHashMap = new HashMap<>();
public static HashMap<String, SubAliasObject> subAliasHashMap = new HashMap<>();
public static ArrayList<String> allAliases = new ArrayList<>();
@ -79,4 +79,16 @@ public final class Main extends JavaPlugin {
return false;
}
}
public static Main getPlugin() {
return plugin;
}
public static String getVersion() {
return version;
}
public static List<String> getAutor() {
return autor;
}
}

View File

@ -62,11 +62,6 @@ 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

@ -7,12 +7,14 @@ 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.update.UpdateAPI;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Commands {
public static void info(CommandSender sender) {
T2CodeTemplate.sendInfo(sender, Util.getPrefix(),Util.getSpigot(),Util.getDiscord(),Main.autor,Main.version, UpdateAPI.PluginVersionen.get(Main.plugin.getName()).publicVersion);
T2CodeTemplate.sendInfo(sender, Util.getPrefix(), Util.getSpigot(), Util.getDiscord(), Main.getAutor(), Main.getVersion(),
UpdateAPI.PluginVersionen.get(Main.getPlugin().getName()).publicVersion);
}
public static void reload(CommandSender sender) {
@ -21,6 +23,7 @@ public class Commands {
send.console(Util.getPrefix() + " §6Plugin reload...");
send.console(Util.getPrefix() + "§8-------------------------------");
Load.loadReload();
Main.getPlugin().onEnable();
if (sender instanceof Player) sender.sendMessage(SelectMessages.reloadEnd);
send.console(Util.getPrefix() + "§8-------------------------------");
send.console(Util.getPrefix() + " §2Plugin successfully reloaded.");

View File

@ -259,7 +259,6 @@ public class ExecuteAlias {
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 {

View File

@ -21,19 +21,22 @@ public class RegisterCommands extends Command {
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
send.debugmsg(Main.plugin, "tabevent");
AliasObject alias = Main.aliasHashMap.get(this.alias);
if (alias == null) {
send.error(Main.getPlugin(), "The alias " + this.alias + " does not exist.");
return false;
}
if (!alias.aliasEnable) {
send.sender(sender, SelectMessages.aliasDisabled);
return true;
}
if (args.length == 0) {
if (sender instanceof Player) {
ExecuteAlias.aliasPlayer(sender, alias, this.alias);
ExecuteAlias.aliasPlayer(sender, alias, this.alias);
} else {
if (alias.consoleEnable) {
ExecuteAlias.aliasConsole(alias, sender, prefix);
ExecuteAlias.aliasConsole(alias, sender, prefix);
} else send.sender(sender, SelectMessages.onlyForPlayer);
}
} else {

View File

@ -11,8 +11,6 @@ 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

View File

@ -0,0 +1,36 @@
package net.t2code.alias.Spigot.config.alias;
import net.t2code.alias.Spigot.Main;
import net.t2code.lib.Spigot.Lib.messages.send;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
public class AliasConfigConverter {
/**
* Converter 1.1
*
* @param yamlConfiguration
* @param config_gui
*/
public static void convertAliasList(YamlConfiguration yamlConfiguration, File config_gui) {
yamlConfiguration.set("Alias.AliasList", Collections.singletonList(config_gui.getName().replace(".yml", "")));
try {
yamlConfiguration.save(config_gui);
} catch (IOException e) {
e.printStackTrace();
}
send.error(Main.getPlugin(), "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
send.error(Main.getPlugin(), "");
send.warning(Main.getPlugin(), "The " + config_gui.getName() + " file is converted to the new config format.");
send.warning(Main.getPlugin(), "The alias is no longer the filename, this is now adjustable in the file under 'Alias.AliasList'!");
send.warning(Main.getPlugin(), "This allows a function to have multiple alias commands without creating multiple files!");
send.error(Main.getPlugin(), "");
send.error(Main.getPlugin(), "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
}

View File

@ -1,4 +1,4 @@
package net.t2code.alias.Spigot.config.config;
package net.t2code.alias.Spigot.config.alias;
import net.t2code.alias.Spigot.Main;
import net.t2code.alias.Util;

View File

@ -1,14 +1,16 @@
package net.t2code.alias.Spigot.config.config;
package net.t2code.alias.Spigot.config.alias;
import net.t2code.alias.Spigot.Main;
import net.t2code.alias.Spigot.config.config.SelectConfig;
import net.t2code.alias.Spigot.system.AliasRegister;
import net.t2code.alias.Spigot.objects.AliasObject;
import net.t2code.alias.Util;
import net.t2code.lib.Spigot.Lib.messages.send;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.Collections;
import java.io.IOException;
import java.util.List;
public class SelectAlias {
@ -22,17 +24,22 @@ public class SelectAlias {
File[] fileArray = f.listFiles();
for (File config_gui : fileArray) {
if (config_gui.getName().equals("X_aliasDeclaration_X.yml")) continue;
String sub = config_gui.getName().substring(config_gui.getName().length() - 4);
YamlConfiguration yamlConfiguration;
if (sub.equals(".yml")) {
try {
yamlConfiguration = YamlConfiguration.loadConfiguration(config_gui);
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config_gui);
} catch (Exception ex) {
continue;
}
Boolean aliasEnable = yamlConfiguration.getBoolean("Alias.Enable");
List<String> aliasList;
if (yamlConfiguration.get("Alias.AliasList") != null) {
aliasList = yamlConfiguration.getStringList("Alias.AliasList");
} else aliasList = Collections.singletonList(config_gui.getName().toLowerCase());
if (SelectConfig.isConfigVersion < 3 && yamlConfiguration.get("Alias.AliasList") == null) {
AliasConfigConverter.convertAliasList(yamlConfiguration, config_gui);
}
aliasList = yamlConfiguration.getStringList("Alias.AliasList");
Boolean permNecessary = yamlConfiguration.getBoolean("Alias.Permission.Necessary");
Boolean costEnable = yamlConfiguration.getBoolean("Alias.Cost.Enable");
@ -69,13 +76,16 @@ public class SelectAlias {
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);
}
}
send.console(Prefix + " §aAlias file §e" + config_gui.getName() + " §awas loaded");
}
AliasRegister.onRegister();
}
private YamlConfiguration loadFile(File file) throws InvalidConfigurationException {
return YamlConfiguration.loadConfiguration(file);
}
}

View File

@ -10,25 +10,24 @@ import java.io.File;
import java.io.IOException;
public class CreateConfig {
public static Integer ConfigVersion = 2;
public static void configCreate() {
long long_ = System.currentTimeMillis();
if (new File(Main.getPath(), "config.yml").exists()) {
if (Main.plugin.getConfig().getBoolean("Plugin.Debug")) send.console(Util.getPrefix() + " §5DEBUG: §6" + " §4config.yml are created / updated...");
if (Main.getPlugin().getConfig().getBoolean("Plugin.Debug")) send.console(Util.getPrefix() + " §5DEBUG: §6" + " §4config.yml are created / updated...");
} else send.console(Util.getPrefix() + " §4config.yml are created...");
File config = new File(Main.getPath(), "config.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
yamlConfiguration.set("ConfigVersion", ConfigVersion);
Config.set("Plugin.language", "english", yamlConfiguration);
Config.set("BungeeCord.Enable", false, yamlConfiguration);
Config.set("BungeeCord.ThisServer", "server", yamlConfiguration);
Config.set("Buy.Message", true, yamlConfiguration);
Config.set("SubAlias.TabComplete", true, yamlConfiguration);
try {
yamlConfiguration.save(config);

View File

@ -4,20 +4,24 @@ import net.t2code.alias.Spigot.Main;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
public class SelectConfig {
public static Integer ConfigVersion;
private static Integer ConfigVersion = 3;
public static Integer isConfigVersion;
public static Boolean UpdateCheckOnJoin;
public static String language;
public static Boolean Bungee;
public static String thisServer;
public static Boolean buyMessage;
public static Boolean subAliasTab;
public static void onSelect() {
File config = new File(Main.getPath(), "config.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
ConfigVersion =yamlConfiguration.getInt("ConfigVersion");
isConfigVersion = yamlConfiguration.getInt("ConfigVersion");
UpdateCheckOnJoin = yamlConfiguration.getBoolean("Plugin.UpdateCheckOnJoin");
language = yamlConfiguration.getString("Plugin.language");
@ -25,5 +29,16 @@ public class SelectConfig {
thisServer = yamlConfiguration.getString("BungeeCord.ThisServer");
buyMessage = yamlConfiguration.getBoolean("Buy.Message");
subAliasTab = yamlConfiguration.getBoolean("SubAlias.TabComplete");
}
public static void setConfigVersion() {
File config = new File(Main.getPath(), "config.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
yamlConfiguration.set("ConfigVersion", ConfigVersion);
try {
yamlConfiguration.save(config);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -11,10 +11,9 @@ import java.io.File;
import java.io.IOException;
public class LanguagesCreate {
private static Plugin plugin = Main.plugin;
public static void langCreate() {
send.debug(plugin,"§4Language files are created / updated...");
send.debug(Main.getPlugin(),"§4Language files are created / updated...");
long long_ = System.currentTimeMillis();
/**
@ -38,7 +37,7 @@ public class LanguagesCreate {
try {
yamlConfigurationEN.save(messagesEN);
} catch (IOException e) {
send.warning(plugin,e.getMessage());
send.warning(Main.getPlugin(),e.getMessage());
e.printStackTrace();
}
@ -64,7 +63,7 @@ public class LanguagesCreate {
try {
yamlConfigurationDE.save(messagesDE);
} catch (IOException e) {
send.warning(plugin,e.getMessage());
send.warning(Main.getPlugin(),e.getMessage());
e.printStackTrace();
}

View File

@ -26,8 +26,8 @@ public class SelectMessages {
public static void onSelect(String Prefix) {
send.debug(Main.plugin, "§4Select language...");
Long long_ = Long.valueOf(System.currentTimeMillis());
send.debug(Main.getPlugin(), "§4Select language...");
long long_ = System.currentTimeMillis();
File msg;
@ -52,7 +52,7 @@ public class SelectMessages {
buy = replace(yamlConfiguration.getString("Cost.Buy"));
noMoney = replace(yamlConfiguration.getString("Cost.NoMoney"));
send.console(Prefix + " §2Language successfully selected to: §6" + selectMSG + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms");
send.console(Prefix + " §2Language successfully selected to: §6" + selectMSG + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
}
private static String replace(String text) {

View File

@ -1,4 +1,4 @@
package net.t2code.alias.Spigot.config.config;
package net.t2code.alias.Spigot.config.subAlias;
import net.t2code.alias.Spigot.Main;
import net.t2code.alias.Util;

View File

@ -1,4 +1,4 @@
package net.t2code.alias.Spigot.config.config;
package net.t2code.alias.Spigot.config.subAlias;
import net.t2code.alias.Spigot.Main;
import net.t2code.alias.Spigot.objects.SubAliasObject;
@ -28,14 +28,13 @@ public class SelectSubAlias {
Boolean aliasEnable = yamlConfiguration.getBoolean("SubAlias.Enable");
List<String> subAliasList = yamlConfiguration.getStringList("SubAlias.SubAliasList");
String subAliasFor = yamlConfiguration.getString("SubAlias.SubAliasFor");
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[] imp = subAliasFor.split(" ");
if (!Main.allAliases.contains(imp[0])) {
send.error(Main.getPlugin(), "Den Alias " + imp[0] + " in der Datei " + config_gui.getName() + " existiert nicht!");
}
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");
@ -78,6 +77,7 @@ public class SelectSubAlias {
}
Main.allSubAliases.addAll(subAliasList);
Main.allForSubAliases.add(subAliasFor);
send.console(Prefix + " §aSubAlias file §e" + config_gui.getName() + " §awas loaded");
}
}
}

View File

@ -13,7 +13,6 @@ import java.lang.reflect.Field;
public class AliasRegister {
public static void onRegister() {
Plugin plugin = Main.plugin;
for (String alias : Main.allAliases) {
if (Main.aliasHashMap.get(alias) != null) {
if (alias.equals(" ")) continue;
@ -27,7 +26,7 @@ public class AliasRegister {
e.printStackTrace();
}
}
} else send.warning(plugin, " §4AliasHashmap is null! - " + alias);
} else send.warning(Main.getPlugin(), " §4AliasHashmap is null! - " + alias);
}
}
}

View File

@ -9,7 +9,7 @@ public class AliasRegisterPermissions {
public static void onPermRegister() {
for (String alias : Main.allAliases){
if (Bukkit.getPluginManager().getPermission("t2code.alias.use." + alias.toLowerCase()) == null) {
Register.permission("t2code.alias.use." + alias.toLowerCase(), Main.plugin);
Register.permission("t2code.alias.use." + alias.toLowerCase(), Main.getPlugin());
}
}
}

View File

@ -30,10 +30,10 @@ public class BCommandSenderReciver {
}
if (sender instanceof Player) {
Player player = (Player) sender;
player.sendPluginMessage(Main.plugin, "t2codealias:bungee", stream.toByteArray());
player.sendPluginMessage(Main.getPlugin(), "t2codealias:bungee", stream.toByteArray());
}else {
for(Player player : Bukkit.getOnlinePlayers()){
player.sendPluginMessage(Main.plugin, "t2codealias:bungee", stream.toByteArray());
player.sendPluginMessage(Main.getPlugin(), "t2codealias:bungee", stream.toByteArray());
return;
}
}

View File

@ -17,19 +17,6 @@ public class JoinEvent implements Listener {
@EventHandler
public void onJoinEvent(PlayerLoginEvent event) {
Player player = event.getPlayer();
new BukkitRunnable() {
@Override
public void run() {
String publicVersion = UpdateAPI.PluginVersionen.get(Main.plugin.getName()).publicVersion;
if (player.hasPermission("alias.updatemsg") || player.isOp()) {
if (!Main.version.equals(publicVersion)) {
if (SelectLibConfig.UpdateCheckOnJoin) {
UpdateAPI.sendUpdateMsg(Util.getPrefix(), Util.getSpigot(), Util.getDiscord(), Main.version, publicVersion, player);
}
}
}
}
}.runTaskLater(Main.plugin, 200L);
UpdateAPI.join(Main.getPlugin(),Util.getPrefix(), "t2code.alias.updatemsg", event.getPlayer(), Util.getSpigot(), Util.getDiscord());
}
}

View File

@ -3,9 +3,13 @@ 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.alias.CreateExampleAliasConfig;
import net.t2code.alias.Spigot.config.alias.SelectAlias;
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.Spigot.config.subAlias.CreateExampleSubAliasConfig;
import net.t2code.alias.Spigot.config.subAlias.SelectSubAlias;
import net.t2code.alias.Util;
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate;
import net.t2code.lib.Spigot.Lib.messages.send;
@ -19,11 +23,11 @@ import java.io.File;
import java.util.List;
public class Load {
static Plugin plugin = Main.plugin;
private static Main plugin = Main.getPlugin();
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());
plugin.getCommand("t2code-alias").setExecutor(new AliasCmdExecuter());
loadReload();
UpdateAPI.onUpdateCheck(plugin, prefix, spigot, spigotID, discord);
Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), plugin);
@ -59,21 +63,20 @@ public class Load {
LanguagesCreate.langCreate();
SelectConfig.onSelect();
SelectMessages.onSelect(Util.getPrefix());
T2CodeTemplate.onLoadSeparateStroke(Util.getPrefix());
SelectAlias.onSelect();
T2CodeTemplate.onLoadSeparateStroke(Util.getPrefix());
SelectSubAlias.onSelect();
Register.listener(new TabEvent(), plugin);
SelectConfig.setConfigVersion();
if (SelectConfig.subAliasTab) {
Register.listener(new TabEvent(), plugin);
}
if (SelectConfig.Bungee) {
Main.plugin.getServer().getMessenger().registerOutgoingPluginChannel(Main.plugin, "BungeeCord");
Bukkit.getMessenger().registerOutgoingPluginChannel(Main.plugin, "t2codealias:bungee");
plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord");
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2codealias:bungee");
}
AliasRegisterPermissions.onPermRegister();
send.debugmsg(plugin, Main.aliasHashMap.toString());
send.debugmsg(plugin, Main.allAliases.toString());
send.debugmsg(plugin, Main.subAliasHashMap.toString());
send.debugmsg(plugin, Main.allSubAliases.toString());
}
}

View File

@ -1,7 +1,7 @@
package net.t2code.alias;
public class Util {
private static String requiredT2CodeLibVersion = "12.4_dev-1";
private static String requiredT2CodeLibVersion = "12.4";
private static String Prefix = "§8[§4T2Code§7-§aAlias§8]";
private static Integer SpigotID = 96389;
private static Integer BstatsID = 12517;