mirror of
https://github.com/TotalFreedomMC/TFGuilds.git
synced 2024-12-22 07:55:03 +00:00
refactor all of this because i am dumb
This commit is contained in:
parent
852a7fdc61
commit
f55e2ebb72
14 changed files with 233 additions and 234 deletions
4
pom.xml
4
pom.xml
|
@ -4,9 +4,9 @@
|
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>me.tf</groupId>
|
||||
<groupId>me.totalfreedom</groupId>
|
||||
<artifactId>TFGuilds</artifactId>
|
||||
<version>0.0.7</version>
|
||||
<version>0.0.8</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>TFGuilds</name>
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package totalfreedom.tfguilds;
|
||||
package me.totalfreedom.tfguilds;
|
||||
|
||||
import me.totalfreedom.tfguilds.util.GLog;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import totalfreedom.tfguilds.command.CreateGuildCommand;
|
||||
import totalfreedom.tfguilds.command.GuildChatCommand;
|
||||
import totalfreedom.tfguilds.command.GuildTagCommand;
|
||||
import totalfreedom.tfguilds.command.TfGuildsCommand;
|
||||
import totalfreedom.tfguilds.config.Config;
|
||||
import totalfreedom.tfguilds.listener.ChatManager;
|
||||
import totalfreedom.tfguilds.util.GLog;
|
||||
import me.totalfreedom.tfguilds.command.CreateGuildCommand;
|
||||
import me.totalfreedom.tfguilds.command.GuildChatCommand;
|
||||
import me.totalfreedom.tfguilds.command.GuildTagCommand;
|
||||
import me.totalfreedom.tfguilds.command.TfGuildsCommand;
|
||||
import me.totalfreedom.tfguilds.config.Config;
|
||||
import me.totalfreedom.tfguilds.listener.ChatManager;
|
||||
|
||||
public final class TFGuilds extends JavaPlugin
|
||||
{
|
|
@ -1,13 +1,13 @@
|
|||
package totalfreedom.tfguilds.command;
|
||||
package me.totalfreedom.tfguilds.command;
|
||||
|
||||
import me.totalfreedom.tfguilds.util.GBase;
|
||||
import me.totalfreedom.tfguilds.util.GUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import totalfreedom.tfguilds.util.GBase;
|
||||
import totalfreedom.tfguilds.util.GUtil;
|
||||
|
||||
public class CreateGuildCommand extends GBase implements CommandExecutor
|
||||
{
|
|
@ -1,13 +1,13 @@
|
|||
package totalfreedom.tfguilds.command;
|
||||
package me.totalfreedom.tfguilds.command;
|
||||
|
||||
import me.totalfreedom.tfguilds.util.GBase;
|
||||
import me.totalfreedom.tfguilds.util.GUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import totalfreedom.tfguilds.util.GBase;
|
||||
import totalfreedom.tfguilds.util.GUtil;
|
||||
|
||||
public class GuildChatCommand extends GBase implements CommandExecutor
|
||||
{
|
|
@ -1,12 +1,12 @@
|
|||
package totalfreedom.tfguilds.command;
|
||||
package me.totalfreedom.tfguilds.command;
|
||||
|
||||
import me.totalfreedom.tfguilds.util.GBase;
|
||||
import me.totalfreedom.tfguilds.util.GUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import totalfreedom.tfguilds.util.GBase;
|
||||
import totalfreedom.tfguilds.util.GUtil;
|
||||
|
||||
public class GuildTagCommand extends GBase implements CommandExecutor
|
||||
{
|
|
@ -1,10 +1,10 @@
|
|||
package totalfreedom.tfguilds.command;
|
||||
package me.totalfreedom.tfguilds.command;
|
||||
|
||||
import me.totalfreedom.tfguilds.util.GBase;
|
||||
import me.totalfreedom.tfguilds.util.GUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import totalfreedom.tfguilds.util.GBase;
|
||||
import totalfreedom.tfguilds.util.GUtil;
|
||||
|
||||
public class TfGuildsCommand extends GBase implements CommandExecutor
|
||||
{
|
|
@ -1,49 +1,49 @@
|
|||
package totalfreedom.tfguilds.config;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import totalfreedom.tfguilds.TFGuilds;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Config extends YamlConfiguration
|
||||
{
|
||||
private final TFGuilds plugin;
|
||||
private final File file;
|
||||
|
||||
public Config(TFGuilds plugin, String name)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.file = new File(plugin.getDataFolder(), name);
|
||||
|
||||
if (!file.exists())
|
||||
{
|
||||
options().copyDefaults(true);
|
||||
plugin.saveResource(name, false);
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
public void load()
|
||||
{
|
||||
try
|
||||
{
|
||||
super.load(file);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
try
|
||||
{
|
||||
super.save(file);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
package me.totalfreedom.tfguilds.config;
|
||||
|
||||
import me.totalfreedom.tfguilds.TFGuilds;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Config extends YamlConfiguration
|
||||
{
|
||||
private final TFGuilds plugin;
|
||||
private final File file;
|
||||
|
||||
public Config(TFGuilds plugin, String name)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.file = new File(plugin.getDataFolder(), name);
|
||||
|
||||
if (!file.exists())
|
||||
{
|
||||
options().copyDefaults(true);
|
||||
plugin.saveResource(name, false);
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
public void load()
|
||||
{
|
||||
try
|
||||
{
|
||||
super.load(file);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
try
|
||||
{
|
||||
super.save(file);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
package totalfreedom.tfguilds.listener;
|
||||
package me.totalfreedom.tfguilds.listener;
|
||||
|
||||
import me.totalfreedom.tfguilds.TFGuilds;
|
||||
import me.totalfreedom.tfguilds.util.GUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import totalfreedom.tfguilds.TFGuilds;
|
||||
import totalfreedom.tfguilds.util.GUtil;
|
||||
|
||||
public class ChatManager implements Listener
|
||||
{
|
8
src/main/java/me/totalfreedom/tfguilds/util/GBase.java
Normal file
8
src/main/java/me/totalfreedom/tfguilds/util/GBase.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package me.totalfreedom.tfguilds.util;
|
||||
|
||||
import me.totalfreedom.tfguilds.TFGuilds;
|
||||
|
||||
public class GBase
|
||||
{
|
||||
protected static TFGuilds plugin = TFGuilds.plugin;
|
||||
}
|
|
@ -1,30 +1,30 @@
|
|||
package totalfreedom.tfguilds.util;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class GLog
|
||||
{
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
private static final String prefix = "[TFGuilds] ";
|
||||
|
||||
private static void log(String s, Level l)
|
||||
{
|
||||
log.log(l, prefix + s);
|
||||
}
|
||||
|
||||
public static void info(String s)
|
||||
{
|
||||
log(s, Level.INFO);
|
||||
}
|
||||
|
||||
public static void warn(String s)
|
||||
{
|
||||
log(s, Level.WARNING);
|
||||
}
|
||||
|
||||
public static void severe(String s)
|
||||
{
|
||||
log(s, Level.SEVERE);
|
||||
}
|
||||
package me.totalfreedom.tfguilds.util;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class GLog
|
||||
{
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
private static final String prefix = "[TFGuilds] ";
|
||||
|
||||
private static void log(String s, Level l)
|
||||
{
|
||||
log.log(l, prefix + s);
|
||||
}
|
||||
|
||||
public static void info(String s)
|
||||
{
|
||||
log(s, Level.INFO);
|
||||
}
|
||||
|
||||
public static void warn(String s)
|
||||
{
|
||||
log(s, Level.WARNING);
|
||||
}
|
||||
|
||||
public static void severe(String s)
|
||||
{
|
||||
log(s, Level.SEVERE);
|
||||
}
|
||||
}
|
|
@ -1,118 +1,118 @@
|
|||
package totalfreedom.tfguilds.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import totalfreedom.tfguilds.TFGuilds;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class GUtil
|
||||
{
|
||||
public static TFGuilds plugin = TFGuilds.plugin;
|
||||
|
||||
public static boolean isConsole(CommandSender sender)
|
||||
{
|
||||
return sender instanceof ConsoleCommandSender;
|
||||
}
|
||||
|
||||
public static void createGuild(CommandSender owner, String guildName)
|
||||
{
|
||||
plugin.guilds.set("guilds." + guildName, guildName);
|
||||
plugin.guilds.set("guilds." + guildName + ".owner", owner.getName());
|
||||
plugin.guilds.set("guilds." + guildName + ".members", owner.getName());
|
||||
|
||||
List<String> players = plugin.guilds.getStringList("guilds." + guildName + ".members");
|
||||
players.add(owner.getName());
|
||||
plugin.guilds.set("guilds." + guildName + ".members", players);
|
||||
|
||||
plugin.guilds.save();
|
||||
GLog.info(owner.getName() + " has created a new guild: " + guildName);
|
||||
}
|
||||
|
||||
public static void setTag(String tag, String guildName)
|
||||
{
|
||||
plugin.guilds.set("guilds." + guildName + ".tag", tag);
|
||||
plugin.guilds.save();
|
||||
}
|
||||
|
||||
public static String getTag(String guildName)
|
||||
{
|
||||
return plugin.guilds.getString("guilds." + guildName + ".tag");
|
||||
}
|
||||
|
||||
public static boolean hasTag(String guildName)
|
||||
{
|
||||
return plugin.guilds.contains("guilds." + guildName + ".tag");
|
||||
}
|
||||
|
||||
public static String getGuild(Player player)
|
||||
{
|
||||
String g = "";
|
||||
boolean a = false;
|
||||
ConfigurationSection guildMembers = plugin.guilds.getConfigurationSection("guilds");
|
||||
if (guildMembers != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (String guild : guildMembers.getKeys(false))
|
||||
{
|
||||
List<String> members = plugin.guilds.getStringList("guilds." + guild + ".members");
|
||||
if (members.contains(player.getName()))
|
||||
{
|
||||
a = true;
|
||||
g = guild;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.fillInStackTrace();
|
||||
}
|
||||
}
|
||||
if (!a)
|
||||
return null;
|
||||
return g;
|
||||
}
|
||||
|
||||
public static String getOwner(String guildName)
|
||||
{
|
||||
return plugin.guilds.getString("guilds." + guildName + ".owner");
|
||||
}
|
||||
|
||||
public static List<String> getMember(String guildName)
|
||||
{
|
||||
return plugin.guilds.getStringList("guilds." + guildName + ".members");
|
||||
}
|
||||
|
||||
public static boolean isGuildMember(Player player, String guildName)
|
||||
{
|
||||
return getMember(guildName).contains(player.getName().toLowerCase());
|
||||
}
|
||||
|
||||
public static void guildChat(CommandSender sender, String message, String guildName)
|
||||
{
|
||||
String sent = ChatColor.DARK_GRAY + "[" + ChatColor.BLUE + "GC" + ChatColor.DARK_GRAY + "] " + getTag(guildName) + ChatColor.BLUE + sender
|
||||
.getName() + ChatColor.GRAY + ": " + ChatColor.AQUA + message;
|
||||
GLog.info(sent);
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (isGuildMember(player, guildName))
|
||||
{
|
||||
player.sendMessage(sent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> BLACKLISTED_NAMES_AND_TAGS = Arrays.asList(
|
||||
"admin", "owner", "moderator", "developer", "console", "dev", "staff", "mod", "sra", "tca", "sta", "sa");
|
||||
|
||||
public static String color(String s)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', s);
|
||||
}
|
||||
package me.totalfreedom.tfguilds.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import me.totalfreedom.tfguilds.TFGuilds;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class GUtil
|
||||
{
|
||||
public static TFGuilds plugin = TFGuilds.plugin;
|
||||
|
||||
public static boolean isConsole(CommandSender sender)
|
||||
{
|
||||
return sender instanceof ConsoleCommandSender;
|
||||
}
|
||||
|
||||
public static void createGuild(CommandSender owner, String guildName)
|
||||
{
|
||||
plugin.guilds.set("guilds." + guildName, guildName);
|
||||
plugin.guilds.set("guilds." + guildName + ".owner", owner.getName());
|
||||
plugin.guilds.set("guilds." + guildName + ".members", owner.getName());
|
||||
|
||||
List<String> players = plugin.guilds.getStringList("guilds." + guildName + ".members");
|
||||
players.add(owner.getName());
|
||||
plugin.guilds.set("guilds." + guildName + ".members", players);
|
||||
|
||||
plugin.guilds.save();
|
||||
GLog.info(owner.getName() + " has created a new guild: " + guildName);
|
||||
}
|
||||
|
||||
public static void setTag(String tag, String guildName)
|
||||
{
|
||||
plugin.guilds.set("guilds." + guildName + ".tag", tag);
|
||||
plugin.guilds.save();
|
||||
}
|
||||
|
||||
public static String getTag(String guildName)
|
||||
{
|
||||
return plugin.guilds.getString("guilds." + guildName + ".tag");
|
||||
}
|
||||
|
||||
public static boolean hasTag(String guildName)
|
||||
{
|
||||
return plugin.guilds.contains("guilds." + guildName + ".tag");
|
||||
}
|
||||
|
||||
public static String getGuild(Player player)
|
||||
{
|
||||
String g = "";
|
||||
boolean a = false;
|
||||
ConfigurationSection guildMembers = plugin.guilds.getConfigurationSection("guilds");
|
||||
if (guildMembers != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (String guild : guildMembers.getKeys(false))
|
||||
{
|
||||
List<String> members = plugin.guilds.getStringList("guilds." + guild + ".members");
|
||||
if (members.contains(player.getName()))
|
||||
{
|
||||
a = true;
|
||||
g = guild;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.fillInStackTrace();
|
||||
}
|
||||
}
|
||||
if (!a)
|
||||
return null;
|
||||
return g;
|
||||
}
|
||||
|
||||
public static String getOwner(String guildName)
|
||||
{
|
||||
return plugin.guilds.getString("guilds." + guildName + ".owner");
|
||||
}
|
||||
|
||||
public static List<String> getMember(String guildName)
|
||||
{
|
||||
return plugin.guilds.getStringList("guilds." + guildName + ".members");
|
||||
}
|
||||
|
||||
public static boolean isGuildMember(Player player, String guildName)
|
||||
{
|
||||
return getMember(guildName).contains(player.getName().toLowerCase());
|
||||
}
|
||||
|
||||
public static void guildChat(CommandSender sender, String message, String guildName)
|
||||
{
|
||||
String sent = ChatColor.DARK_GRAY + "[" + ChatColor.BLUE + "GC" + ChatColor.DARK_GRAY + "] " + getTag(guildName) + ChatColor.BLUE + sender
|
||||
.getName() + ChatColor.GRAY + ": " + ChatColor.AQUA + message;
|
||||
GLog.info(sent);
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (isGuildMember(player, guildName))
|
||||
{
|
||||
player.sendMessage(sent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> BLACKLISTED_NAMES_AND_TAGS = Arrays.asList(
|
||||
"admin", "owner", "moderator", "developer", "console", "dev", "staff", "mod", "sra", "tca", "sta", "sa");
|
||||
|
||||
public static String color(String s)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', s);
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package totalfreedom.tfguilds.util;
|
||||
|
||||
import totalfreedom.tfguilds.TFGuilds;
|
||||
|
||||
public class GBase
|
||||
{
|
||||
protected static TFGuilds plugin = TFGuilds.plugin;
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
# Guilds
|
||||
# <name>:
|
||||
# <owner>: speednt
|
||||
# <members>:
|
||||
# - speednt
|
||||
# guild:
|
||||
# owner: speednt
|
||||
# members:
|
||||
# - speednt
|
|
@ -1,7 +1,7 @@
|
|||
name: TFGuilds
|
||||
version: ${project.version}
|
||||
main: totalfreedom.tfguilds.TFGuilds
|
||||
api-version: 1.13
|
||||
main: me.totalfreedom.tfguilds.TFGuilds
|
||||
api-version: 1.15
|
||||
authors: [speednt]
|
||||
description: Plugin which allows for players to make their own guilds on the server
|
||||
commands:
|
||||
|
|
Loading…
Reference in a new issue