This commit is contained in:
JaTiTV 2022-03-10 21:02:31 +01:00
parent 9bc90def9f
commit 5cea9f9a7c
6 changed files with 29 additions and 23 deletions

View File

@ -6,7 +6,7 @@
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>
<artifactId>AutoResponse</artifactId> <artifactId>AutoResponse</artifactId>
<version>0.0.1-DEV-2</version> <version>0.0.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>T2C-AutoResponse</name> <name>T2C-AutoResponse</name>
@ -82,7 +82,7 @@
<dependency> <dependency>
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>
<artifactId>T2CodeLib</artifactId> <artifactId>T2CodeLib</artifactId>
<version>11.0</version> <version>11.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>

View File

@ -9,11 +9,12 @@ import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
public class CreateExampleResponse { public class CreateExampleResponse {
public static void configCreate() { public static void configCreate() {
Long long_ = Long.valueOf(System.currentTimeMillis()); long long_ = System.currentTimeMillis();
if (new File(Main.getPath(), "config.yml").exists()) { 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.plugin.getConfig().getBoolean("Plugin.Debug")) send.console(Util.getPrefix() + " §5DEBUG: §6" + " §4config.yml are created / updated...");
} else send.console(Util.getPrefix() + " §4config.yml are created..."); } else send.console(Util.getPrefix() + " §4config.yml are created...");
@ -24,7 +25,7 @@ public class CreateExampleResponse {
Config.set("Response.Enable", true, yamlConfiguration); Config.set("Response.Enable", true, yamlConfiguration);
Config.set("Response.ResponseKey", ".example", yamlConfiguration); Config.set("Response.ResponseKeys", Collections.singletonList(".example"), yamlConfiguration);
Config.set("Response.Contains", false, yamlConfiguration); Config.set("Response.Contains", false, yamlConfiguration);
Config.set("Response.Permission.Necessary", true, yamlConfiguration); Config.set("Response.Permission.Necessary", true, yamlConfiguration);
Config.set("Response.Permission.Permission", "t2c-autoresponse.response.example", yamlConfiguration); Config.set("Response.Permission.Permission", "t2c-autoresponse.response.example", yamlConfiguration);
@ -32,7 +33,7 @@ public class CreateExampleResponse {
Config.set("Response.Command.Enable", false, yamlConfiguration); Config.set("Response.Command.Enable", false, yamlConfiguration);
Config.set("Response.Command.CommandAsConsole", false, yamlConfiguration); Config.set("Response.Command.CommandAsConsole", false, yamlConfiguration);
Config.set("Response.Command.BungeeCommand", false, yamlConfiguration); Config.set("Response.Command.BungeeCommand", false, yamlConfiguration);
Config.set("Response.Command.Commands", Arrays.asList("say hi"), yamlConfiguration); Config.set("Response.Command.Commands", Collections.singletonList("say hi"), yamlConfiguration);
Config.set("Response.Message.Enable", true, yamlConfiguration); Config.set("Response.Message.Enable", true, yamlConfiguration);
Config.set("Response.Message.Messages", Arrays.asList("&2This is an Automated response from §8[§4T2Code§7-§bAutoResponse§8]&2.", "&6Contact us for questions / support on our Discord."), yamlConfiguration); Config.set("Response.Message.Messages", Arrays.asList("&2This is an Automated response from §8[§4T2Code§7-§bAutoResponse§8]&2.", "&6Contact us for questions / support on our Discord."), yamlConfiguration);
@ -46,6 +47,6 @@ public class CreateExampleResponse {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
send.console(Util.getPrefix() + " §2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms"); send.console(Util.getPrefix() + " §2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
} }
} }

View File

@ -20,7 +20,7 @@ public class SelectResponses {
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config_gui); YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config_gui);
ResponsesObject response = new ResponsesObject( ResponsesObject response = new ResponsesObject(
yamlConfiguration.getBoolean("Response.Enable"), yamlConfiguration.getBoolean("Response.Enable"),
yamlConfiguration.getString("Response.ResponseKey"), yamlConfiguration.getStringList("Response.ResponseKeys"),
yamlConfiguration.getBoolean("Response.Contains"), yamlConfiguration.getBoolean("Response.Contains"),
yamlConfiguration.getBoolean("Response.Permission.Necessary"), yamlConfiguration.getBoolean("Response.Permission.Necessary"),
yamlConfiguration.getString("Response.Permission.Permission"), yamlConfiguration.getString("Response.Permission.Permission"),

View File

@ -12,7 +12,6 @@ import net.t2code.lib.Spigot.Lib.messages.TextBuilder;
import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.Lib.plugins.PluginCheck; import net.t2code.lib.Spigot.Lib.plugins.PluginCheck;
import net.t2code.lib.Spigot.Lib.replace.Replace; import net.t2code.lib.Spigot.Lib.replace.Replace;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -32,21 +31,27 @@ public class ResponseListener implements Listener {
for (ResponsesObject response : Main.allResponses) { for (ResponsesObject response : Main.allResponses) {
if (!response.permNecessary || player.hasPermission(response.permission)) { if (!response.permNecessary || player.hasPermission(response.permission)) {
if (response.contains) { if (response.contains) {
if (e.getMessage().contains(response.responseKey)) { for (String responseKey : response.responseKeys){
execute(e, player, response); if (e.getMessage().contains(responseKey)) {
execute(e, player, response, responseKey);
return; return;
} }
}
} else { } else {
if (e.getMessage().equals(response.responseKey)) { for (String responseKey : response.responseKeys){
execute(e, player, response); if (e.getMessage().equals(responseKey)) {
execute(e, player, response, responseKey);
return; return;
} }
} }
}
} }
} }
} }
private static void execute(AsyncPlayerChatEvent e, Player player, ResponsesObject response) { private static void execute(AsyncPlayerChatEvent e, Player player, ResponsesObject response, String responseKey) {
if (response.commandEnable) { if (response.commandEnable) {
for (String cmd : response.command) { for (String cmd : response.command) {
if (response.bungeeCommand) { if (response.bungeeCommand) {
@ -69,7 +74,7 @@ public class ResponseListener implements Listener {
Cmd.player(player, cmd.replace("[player]", player.getName())); Cmd.player(player, cmd.replace("[player]", player.getName()));
} }
} }
use(e, player, response); use(e, player, responseKey);
} }
} }
if (response.messageEnable) { if (response.messageEnable) {
@ -93,13 +98,13 @@ public class ResponseListener implements Listener {
} else { } else {
send.player(player, text); send.player(player, text);
} }
use(e, player, response); use(e, player, responseKey);
} }
} }
} }
private static void use(AsyncPlayerChatEvent e, Player player, ResponsesObject response) { private static void use(AsyncPlayerChatEvent e, Player player, String responseKey) {
e.setCancelled(true); e.setCancelled(true);
if (SelectConfig.logConsole) send.console(Util.getPrefix() + " §6Player: §e" + player.getName() + " §6use AutoResponse: §e" + response.responseKey); if (SelectConfig.logConsole) send.console(Util.getPrefix() + " §6Player: §e" + player.getName() + " §6use AutoResponse: §e" +responseKey);
} }
} }

View File

@ -4,7 +4,7 @@ import java.util.List;
public class ResponsesObject { public class ResponsesObject {
public Boolean enable; public Boolean enable;
public String responseKey; public List<String> responseKeys;
public Boolean contains; public Boolean contains;
public Boolean commandEnable; public Boolean commandEnable;
public Boolean permNecessary; public Boolean permNecessary;
@ -22,7 +22,7 @@ public class ResponsesObject {
public String actionValue; public String actionValue;
public ResponsesObject(Boolean enable, public ResponsesObject(Boolean enable,
String responseKey, List<String> responseKeys,
Boolean contains, Boolean contains,
Boolean permNecessary, Boolean permNecessary,
String permission, String permission,
@ -38,7 +38,7 @@ public class ResponsesObject {
String action, String action,
String actionValue) { String actionValue) {
this.enable = enable; this.enable = enable;
this.responseKey = responseKey; this.responseKeys = responseKeys;
this.contains=contains; this.contains=contains;
this.permNecessary = permNecessary; this.permNecessary = permNecessary;
this.permission = permission; this.permission = permission;

View File

@ -7,7 +7,7 @@ import org.bukkit.permissions.PermissionDefault;
public class Permissions { public class Permissions {
public static final String key = "t2c-autoresponse."; public static final String key = "t2code.autoresponse.";
public static final String info = key + "command.info"; public static final String info = key + "command.info";
public static final String updatemsg = key + "updatemsg"; public static final String updatemsg = key + "updatemsg";
public static final String admin = key + "admin"; public static final String admin = key + "admin";