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