mirror of
https://github.com/Aust1n46/VentureChat.git
synced 2025-05-22 18:09:06 +00:00
Refactored alias implementation.
This commit is contained in:
parent
d429327952
commit
c1f94dc4d0
@ -35,7 +35,7 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import mineverse.Aust1n46.chat.alias.AliasInfo;
|
||||
import mineverse.Aust1n46.chat.alias.Alias;
|
||||
import mineverse.Aust1n46.chat.api.MineverseChatAPI;
|
||||
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
|
||||
import mineverse.Aust1n46.chat.api.events.VentureChatEvent;
|
||||
@ -78,7 +78,6 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
||||
private static Field knownCommands;
|
||||
|
||||
// Misc --------------------------------
|
||||
public static AliasInfo aaInfo;
|
||||
public boolean quickchat = true;
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
@ -152,9 +151,8 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
||||
Localization.initialize();
|
||||
|
||||
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Registering Listeners"));
|
||||
// Channel information reference
|
||||
aaInfo = new AliasInfo(this);
|
||||
|
||||
Alias.initialize();
|
||||
JsonFormat.initialize();
|
||||
GuiSlot.initialize();
|
||||
|
||||
@ -336,7 +334,7 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
||||
pluginManager.registerEvents(new Channel(), this);
|
||||
pluginManager.registerEvents(new ChatListener(), this);
|
||||
pluginManager.registerEvents(new SignListener(), this);
|
||||
pluginManager.registerEvents(new CommandListener(aaInfo), this);
|
||||
pluginManager.registerEvents(new CommandListener(), this);
|
||||
pluginManager.registerEvents(new LoginListener(), this);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,16 @@
|
||||
package mineverse.Aust1n46.chat.alias;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import mineverse.Aust1n46.chat.MineverseChat;
|
||||
|
||||
public class Alias {
|
||||
private static MineverseChat plugin = MineverseChat.getInstance();
|
||||
private static List<Alias> aliases = new ArrayList<Alias>();
|
||||
|
||||
private String name;
|
||||
private int arguments;
|
||||
private List<String> components;
|
||||
@ -14,6 +22,21 @@ public class Alias {
|
||||
this.components = components;
|
||||
this.permission = "venturechat." + permission;
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
ConfigurationSection cs = plugin.getConfig().getConfigurationSection("alias");
|
||||
for(String key : cs.getKeys(false)) {
|
||||
String name = key;
|
||||
int arguments = cs.getInt(key + ".arguments", 0);
|
||||
List<String> components = cs.getStringList(key + ".components");
|
||||
String permissions = cs.getString(key + ".permissions", "None");
|
||||
aliases.add(new Alias(name, arguments, components, permissions));
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Alias> getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@ -34,4 +57,4 @@ public class Alias {
|
||||
public boolean hasPermission() {
|
||||
return !permission.equalsIgnoreCase("venturechat.none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
package mineverse.Aust1n46.chat.alias;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import mineverse.Aust1n46.chat.MineverseChat;
|
||||
|
||||
public class AliasInfo {
|
||||
private Alias[] aa;
|
||||
|
||||
public AliasInfo(MineverseChat plugin) {
|
||||
String name = "";
|
||||
int arguments = 0;
|
||||
String permissions;
|
||||
List<String> components;
|
||||
ConfigurationSection cs = plugin.getConfig().getConfigurationSection("alias");
|
||||
aa = new Alias[cs.getKeys(false).size()];
|
||||
int x = 0;
|
||||
for(String key : cs.getKeys(false)) {
|
||||
name = key;
|
||||
arguments = cs.getInt(key + ".arguments", 0);
|
||||
components = cs.getStringList(key + ".components");
|
||||
permissions = cs.getString(key + ".permissions", "None");
|
||||
Alias a = new Alias(name, arguments, components, permissions);
|
||||
aa[x++] = a;
|
||||
}
|
||||
}
|
||||
|
||||
public Alias[] getAliases() {
|
||||
return aa;
|
||||
}
|
||||
|
||||
public Alias getAliasInfo(String name) {
|
||||
for(Alias a : aa) {
|
||||
if(a.getName().equalsIgnoreCase(name))
|
||||
return a;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ import java.io.FileNotFoundException;
|
||||
|
||||
import mineverse.Aust1n46.chat.MineverseChat;
|
||||
import mineverse.Aust1n46.chat.alias.Alias;
|
||||
import mineverse.Aust1n46.chat.alias.AliasInfo;
|
||||
import mineverse.Aust1n46.chat.api.MineverseChatAPI;
|
||||
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
|
||||
import mineverse.Aust1n46.chat.channel.ChatChannel;
|
||||
@ -36,11 +35,6 @@ import me.clip.placeholderapi.PlaceholderAPI;
|
||||
//in the custom commands such as aliases.
|
||||
public class CommandListener implements CommandExecutor, Listener {
|
||||
private MineverseChat plugin = MineverseChat.getInstance();
|
||||
private AliasInfo aa;
|
||||
|
||||
public CommandListener(AliasInfo aa) {
|
||||
this.aa = aa;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) throws FileNotFoundException {
|
||||
@ -81,7 +75,7 @@ public class CommandListener implements CommandExecutor, Listener {
|
||||
Database.writeVentureChat(mcp.getUUID().toString(), mcp.getName(), "Local", "Command_Component", event.getMessage().replace("'", "''"), "Command");
|
||||
}
|
||||
|
||||
for(Alias a : aa.getAliases()) {
|
||||
for(Alias a : Alias.getAliases()) {
|
||||
if(message.toLowerCase().substring(1).split(" ")[0].equals(a.getName().toLowerCase())) {
|
||||
for(String s : a.getComponents()) {
|
||||
if(!mcp.getPlayer().hasPermission(a.getPermission()) && a.hasPermission()) {
|
||||
@ -268,4 +262,4 @@ public class CommandListener implements CommandExecutor, Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user