H2 Support

Added H2 Database
Added conversion for old plugin.yml
Updated docs
Fixes #1
Fixes #2
master
Etzelia 2018-10-20 01:36:57 -05:00
parent 1d7470313c
commit 2f0f38b206
11 changed files with 341 additions and 193 deletions

View File

@ -9,3 +9,4 @@ Changelogs
:maxdepth: 1 :maxdepth: 1
v1.2 <v1.2> v1.2 <v1.2>
v2.0 <v2.0>

View File

@ -3,7 +3,7 @@
.. _deluxegroups_v1.2: .. _deluxegroups_v1.2:
DeluxeGroups v1.2 DeluxeGroups v1.2
======== =================
Additions Additions
--------- ---------

View File

@ -0,0 +1,14 @@
.. include:: ../common.rst
.. _deluxegroups_v2.0:
DeluxeGroups v2.0
=================
Additions
---------
* Implemented H2 support! (Includes conversion for old groups.yml)
Bug Fixes
---------
None

View File

@ -3,7 +3,7 @@
<groupId>xyz.etztech</groupId> <groupId>xyz.etztech</groupId>
<artifactId>DeluxeGroups</artifactId> <artifactId>DeluxeGroups</artifactId>
<!-- Version is used in plugin.yml --> <!-- Version is used in plugin.yml -->
<version>1.2</version> <version>2.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<!-- Plugin Information --> <!-- Plugin Information -->
@ -38,19 +38,16 @@
<groupId>us.dynmap</groupId> <groupId>us.dynmap</groupId>
<artifactId>dynmap-api</artifactId> <artifactId>dynmap-api</artifactId>
<version>1.9.4</version> <version>1.9.4</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>xyz.etztech</groupId> <groupId>xyz.etztech</groupId>
<artifactId>EtzCore</artifactId> <artifactId>EtzCore</artifactId>
<version>1.0.4</version> <version>1.0.5</version>
<scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-lang</groupId> <groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId> <artifactId>commons-lang</artifactId>
<version>2.6</version> <version>2.6</version>
<scope>provided</scope>
</dependency> </dependency>

View File

@ -0,0 +1,228 @@
package xyz.etztech.deluxegroups;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.java.JavaPlugin;
import xyz.etztech.core.db.DataSource;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class Database extends DataSource {
public Database(JavaPlugin plugin) {
super(plugin);
create();
}
private void create() {
try {
Connection connection = getConnection();
final String CREATE1 = "CREATE TABLE IF NOT EXISTS `groups` (`id` INT AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(50) NOT NULL, `password` VARCHAR(50), `permanent` BOOLEAN NOT NULL);";
PreparedStatement pst = connection.prepareStatement(CREATE1);
pst.execute();
final String CREATE2 = "CREATE TABLE IF NOT EXISTS `players` (`id` INT AUTO_INCREMENT PRIMARY KEY, `uuid` VARCHAR(36) NOT NULL, `group_id` INT NOT NULL);";
pst = connection.prepareStatement(CREATE2);
pst.execute();
connection.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public int addGroup(DeluxeGroup group) {
int id = 0;
try {
Connection connection = getConnection();
final String GROUP = "INSERT INTO `groups` (`name`, `password`, `permanent`) VALUES (?, ?, FALSE);";
PreparedStatement pst = connection.prepareStatement(GROUP, Statement.RETURN_GENERATED_KEYS);
pst.setString(1, group.getName());
pst.setString(2, group.getPassword());
pst.executeUpdate();
ResultSet keys = pst.getGeneratedKeys();
if (keys.next()) {
id = keys.getInt("id");
}
connection.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return id;
}
public void removeGroup(int groupId) {
try {
Connection connection = getConnection();
final String REMOVE = "DELETE FROM `groups` WHERE `id` = ?;";
PreparedStatement pst = connection.prepareStatement(REMOVE);
pst.setInt(1, groupId);
pst.executeUpdate();
connection.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void updateGroup(DeluxeGroup group) {
try {
Connection connection = getConnection();
final String UPDATE = "UPDATE `groups` SET `name` = ?, `password` = ?, `permanent` = ? WHERE `id` = ?;";
PreparedStatement pst = connection.prepareStatement(UPDATE);
pst.setString(1, group.getName());
pst.setString(2, group.getPassword());
pst.setBoolean(3, group.getPermanent());
pst.setInt(4, group.getId());
pst.executeUpdate();
connection.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void addPlayer(String uuid, int groupId) {
try {
Connection connection = getConnection();
final String PLAYER = "INSERT INTO `players` (`uuid`, `group_id`) VALUES (?, ?);";
PreparedStatement pst = connection.prepareStatement(PLAYER);
pst.setString(1, uuid);
pst.setInt(2, groupId);
pst.executeUpdate();
connection.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void removePlayer(String uuid) {
try {
Connection connection = getConnection();
final String REMOVE = "DELETE FROM `players` WHERE `uuid` = ?;";
PreparedStatement pst = connection.prepareStatement(REMOVE);
pst.setString(1, uuid);
pst.executeUpdate();
connection.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public DeluxeGroup getGroup(String groupName) {
try {
Connection connection = getConnection();
final String GROUP = "SELECT `id`, `name`, `password`, `permanent` FROM `groups` WHERE LOWER(`name`) = LOWER(?);";
PreparedStatement pst = connection.prepareStatement(GROUP);
pst.setString(1, groupName);
ResultSet rs = pst.executeQuery();
DeluxeGroup group = getDeluxeGroup(rs);
connection.close();
return group;
} catch (Exception ex) {
ex.printStackTrace();
}
return new DeluxeGroup();
}
public DeluxeGroup getPlayerGroup(String uuid) {
try {
Connection connection = getConnection();
final String GROUP = "SELECT `id`, `name`, `password`, `permanent` FROM `groups` WHERE `id` = (SELECT `group_id` FROM `players` WHERE `uuid` = ?);";
PreparedStatement pst = connection.prepareStatement(GROUP);
pst.setString(1, uuid);
ResultSet rs = pst.executeQuery();
DeluxeGroup group = getDeluxeGroup(rs);
connection.close();
return group;
} catch (Exception ex) {
ex.printStackTrace();
}
return new DeluxeGroup();
}
public List<DeluxeGroup> getGroups() {
List<DeluxeGroup> groups = new ArrayList<>();
try {
Connection connection = getConnection();
final String GROUPS = "SELECT `id`, `name`, `password`, `permanent` FROM `groups`;";
PreparedStatement pst = connection.prepareStatement(GROUPS);
ResultSet rs = pst.executeQuery();
while (rs.next()) {
DeluxeGroup group = new DeluxeGroup();
group.setId(rs.getInt("id"));
group.setName(rs.getString("name"));
group.setPassword(rs.getString("password"));
group.setPermanent(rs.getBoolean("permanent"));
groups.add(group);
}
connection.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return groups;
}
public List<OfflinePlayer> getPlayers(int groupId) {
List<OfflinePlayer> players = new ArrayList<>();
try {
Connection connection = getConnection();
final String PLAYERS = "SELECT `uuid` FROM `players` WHERE `group_id` = ?;";
PreparedStatement pst = connection.prepareStatement(PLAYERS);
pst.setInt(1, groupId);
ResultSet rs = pst.executeQuery();
while (rs.next()) {
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(rs.getString("uuid")));
players.add(player);
}
connection.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return players;
}
public boolean inGroup(String uuid) {
boolean inGroup = false;
try {
Connection connection = getConnection();
final String INGROUP = "SELECT `uuid` FROM `players` WHERE `uuid` = ?;";
PreparedStatement pst = connection.prepareStatement(INGROUP);
pst.setString(1, uuid);
ResultSet rs = pst.executeQuery();
inGroup = rs.next();
connection.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return inGroup;
}
public boolean groupExists(String groupName) {
boolean exists = false;
try {
Connection connection = getConnection();
final String EXISTS = "SELECT `id` FROM `groups` WHERE LOWER(`name`) = LOWER(?);";
PreparedStatement pst = connection.prepareStatement(EXISTS);
pst.setString(1, groupName);
ResultSet rs = pst.executeQuery();
exists = rs.next();
connection.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return exists;
}
private DeluxeGroup getDeluxeGroup(ResultSet rs) throws SQLException {
if (rs.next()) {
DeluxeGroup group = new DeluxeGroup();
group.setId(rs.getInt("id"));
group.setName(rs.getString("name"));
group.setPassword(rs.getString("password"));
group.setPermanent(rs.getBoolean("permanent"));
group.setGroupList(new ArrayList<>(getPlayers(group.getId())));
return group;
}
return new DeluxeGroup();
}
}

View File

@ -14,6 +14,7 @@ import java.util.List;
public class DeluxeGroup { public class DeluxeGroup {
private int id;
private String name; private String name;
private String password; private String password;
private boolean permanent; private boolean permanent;
@ -22,6 +23,7 @@ public class DeluxeGroup {
private PrintWriter log; private PrintWriter log;
public DeluxeGroup() { public DeluxeGroup() {
this.id = 0;
this.name = ""; this.name = "";
this.password = ""; this.password = "";
this.permanent = false; this.permanent = false;
@ -29,6 +31,14 @@ public class DeluxeGroup {
} }
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() { public String getName() {
return name; return name;
} }
@ -134,6 +144,4 @@ public class DeluxeGroup {
String message = player + ": " + chat; String message = player + ": " + chat;
DeluxeUtil.log(this.log, message, false); DeluxeUtil.log(this.log, message, false);
} }
} }

View File

@ -6,9 +6,9 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.dynmap.DynmapAPI;
import xyz.etztech.core.api.IMinecraftManager; import xyz.etztech.core.api.IMinecraftManager;
import xyz.etztech.core.maven.MavenLibrary;
import xyz.etztech.core.maven.MavenPlugin;
import xyz.etztech.deluxegroups.command.CommandGroup; import xyz.etztech.deluxegroups.command.CommandGroup;
import xyz.etztech.deluxegroups.command.CommandMain; import xyz.etztech.deluxegroups.command.CommandMain;
import xyz.etztech.deluxegroups.listeners.AsyncPlayerChatListener; import xyz.etztech.deluxegroups.listeners.AsyncPlayerChatListener;
@ -21,34 +21,29 @@ import java.util.*;
import java.util.logging.Logger; import java.util.logging.Logger;
@MavenLibrary(group = "us.dynmap", artifact = "dynmap-api", version = "1.9.4", repository = "http://repo.mikeprimm.com/") public class DeluxeGroups extends JavaPlugin {
@MavenLibrary(group = "commons-lang", artifact = "commons-lang", version = "2.6")
public class DeluxeGroups extends MavenPlugin {
private static DeluxeGroups instance; private static DeluxeGroups instance;
public static FileConfiguration config; public static FileConfiguration config;
public static FileConfiguration groupConfig;
private Logger log = Logger.getLogger( "Minecraft" ); private Logger log = Logger.getLogger( "Minecraft" );
private static Database database;
protected static Map<String, String> inGroup = new HashMap();
protected static Map<String, DeluxeGroup> groups = new HashMap();
// Objects that can be reloaded // Objects that can be reloaded
AsyncPlayerChatListener chatListener; private AsyncPlayerChatListener chatListener;
// Dynmap API // Dynmap API
private static Object dynmap = null; private static DynmapAPI dynmap = null;
// MinecraftManager API // MinecraftManager API
private static IMinecraftManager minecraftManager = null; private static IMinecraftManager minecraftManager = null;
@Override public void onEnable() {
public void enable() {
instance = this; instance = this;
database = new Database(this);
saveDefaultConfig(); saveDefaultConfig();
reloadConfig(); reloadConfig();
@ -62,7 +57,7 @@ public class DeluxeGroups extends MavenPlugin {
// Dynmap integration // Dynmap integration
if (Bukkit.getPluginManager().isPluginEnabled("dynmap")) { if (Bukkit.getPluginManager().isPluginEnabled("dynmap")) {
dynmap = Bukkit.getPluginManager().getPlugin("dynmap"); dynmap = (DynmapAPI) Bukkit.getPluginManager().getPlugin("dynmap");
DeluxeUtil.setupDynmap(dynmap); DeluxeUtil.setupDynmap(dynmap);
getServer().getPluginManager().registerEvents(new SessionListener(), this); getServer().getPluginManager().registerEvents(new SessionListener(), this);
} }
@ -88,32 +83,7 @@ public class DeluxeGroups extends MavenPlugin {
} }
} }
@Override public void onDisable() {}
public void disable() {
log("Saving groups.");
String root;
for (DeluxeGroup group : groups.values()) {
root = group.getName().toLowerCase();
groupConfig.createSection(root);
groupConfig.set(root + ".name", group.getName());
groupConfig.set(root + ".password", group.getPassword());
groupConfig.set(root + ".permanent", group.getPermanent());
groupConfig.set(root + ".players", group.getSize() > 0 ? group.getUUIDList() : null);
}
File groupf = new File(getDataFolder(), "groups.yml");
try {
PrintWriter pw = new PrintWriter(groupf);
pw.write("# This is a file for saving all your groups\n" +
"# Do not manually edit this file!\n\n");
pw.close();
} catch (Exception ex) {}
try {
groupf.createNewFile();
groupConfig.save(groupf);
} catch (IOException e) {
e.printStackTrace();
}
}
public void loadConfig() { public void loadConfig() {
config = Bukkit.getPluginManager().getPlugin("DeluxeGroups").getConfig(); config = Bukkit.getPluginManager().getPlugin("DeluxeGroups").getConfig();
@ -123,46 +93,47 @@ public class DeluxeGroups extends MavenPlugin {
public void reloadConfig() { public void reloadConfig() {
super.reloadConfig(); super.reloadConfig();
loadConfig(); loadConfig();
loadGroupConfig(); convertConfig();
if (chatListener != null) { if (chatListener != null) {
chatListener.reload(); chatListener.reload();
} }
} }
public void loadGroupConfig() {
@Deprecated
public boolean convertConfig() {
File groupf = new File(getDataFolder(), "groups.yml"); File groupf = new File(getDataFolder(), "groups.yml");
if (!groupf.exists()) { if (!groupf.exists()) {
groupf.getParentFile().mkdirs(); return false;
saveResource("groups.yml", false);
} }
groupConfig = new YamlConfiguration(); log("Converting old groups.yml to H2.");
FileConfiguration groupConfig = new YamlConfiguration();
try { try {
groupConfig.load(groupf); groupConfig.load(groupf);
int loaded = 0; int loaded = 0;
OfflinePlayer offlinePlayer;
DeluxeGroup group; DeluxeGroup group;
for (String key : groupConfig.getKeys(false)) { for (String key : groupConfig.getKeys(false)) {
group = new DeluxeGroup(); group = new DeluxeGroup();
group.setName(groupConfig.getString(key + ".name")); group.setName(groupConfig.getString(key + ".name"));
group.setPassword(groupConfig.getString(key + ".password")); group.setPassword(groupConfig.getString(key + ".password"));
group.setPermanent(groupConfig.getBoolean(key + ".permanent")); group.setPermanent(groupConfig.getBoolean(key + ".permanent"));
ArrayList<OfflinePlayer> playerList = new ArrayList<>(); int id = database.addGroup(group);
for (String uuid : groupConfig.getStringList(key + ".players")) { for (String uuid : groupConfig.getStringList(key + ".players")) {
offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(uuid)); database.addPlayer(uuid, id);
playerList.add(offlinePlayer);
setInGroup(uuid, group.getName());
} }
group.setGroupList(playerList);
addGroup(group);
loaded++; loaded++;
} }
log("Loaded " + loaded + " groups!"); log("Converted " + loaded + " groups to H2! The groups.yml will be deleted next time the server is stopped.");
groupf.deleteOnExit();
return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return false;
} }
public void log(String message) { public void log(String message) {
log.info( "[DeluxeGroups]: " + message ); log.info( "[DeluxeGroups]: " + message );
} }
@ -171,63 +142,11 @@ public class DeluxeGroups extends MavenPlugin {
return instance; return instance;
} }
public static Collection<DeluxeGroup> getGroups() { public static Database getDatabase() {
return groups.values(); return database;
} }
public static void addGroup(DeluxeGroup group) { public static DynmapAPI getDynmap() {
groups.put(group.getName().toLowerCase(), group);
}
public static void removeGroup(DeluxeGroup group) {
groups.remove(group.getName().toLowerCase());
}
public static DeluxeGroup getGroup(String name) {
name = name.toLowerCase();
if (groups.containsKey(name)) {
return groups.get(name);
}
return null;
}
public static void setInGroup(String uuid, String group) {
inGroup.put(uuid, group.toLowerCase());
}
public static void removeFromInGroup(String uuid) {
inGroup.remove(uuid);
}
public static String getInGroup(String uuid) {
if (inGroup.containsKey(uuid)) {
return inGroup.get(uuid);
}
return null;
}
public static void addToGroup(Player uuid, String group) {
group = group.toLowerCase();
if (groups.containsKey(group)) {
groups.get(group).add(uuid);
}
}
public static void removeFromGroup(Player player, String group) {
group = group.toLowerCase();
if (groups.containsKey(group)) {
groups.get(group).remove(player);
}
}
public static void removeFromGroup(OfflinePlayer player, String group) {
group = group.toLowerCase();
if (groups.containsKey(group)) {
groups.get(group).remove(player.getUniqueId().toString());
}
}
public static Object getDynmap() {
return dynmap; return dynmap;
} }

View File

@ -31,8 +31,8 @@ public class CommandGroup
Player localPlayer1 = (Player)sender; Player localPlayer1 = (Player)sender;
if (args.length == 0) { if (args.length == 0) {
if (DeluxeGroups.getInGroup(localPlayer1.getUniqueId().toString()) != null) { if (DeluxeGroups.getDatabase().inGroup(localPlayer1.getUniqueId().toString())) {
DeluxeGroup deluxeGroup = DeluxeGroups.getGroup(DeluxeGroups.getInGroup(localPlayer1.getUniqueId().toString())); DeluxeGroup deluxeGroup = DeluxeGroups.getDatabase().getPlayerGroup(localPlayer1.getUniqueId().toString());
DeluxeUtil.sms(localPlayer1, ChatColor.AQUA + "You are in group " + deluxeGroup.getName()); DeluxeUtil.sms(localPlayer1, ChatColor.AQUA + "You are in group " + deluxeGroup.getName());
} else { } else {
DeluxeUtil.sms(localPlayer1, ChatColor.RED + "You are not in a group!"); DeluxeUtil.sms(localPlayer1, ChatColor.RED + "You are not in a group!");
@ -44,7 +44,7 @@ public class CommandGroup
} else if ("join".equals(subcommand.toLowerCase())) { } else if ("join".equals(subcommand.toLowerCase())) {
joinGroup(localPlayer1, args); joinGroup(localPlayer1, args);
} else if ("leave".equals(subcommand.toLowerCase())) { } else if ("leave".equals(subcommand.toLowerCase())) {
leaveGroup(localPlayer1, args, false); leaveGroup(localPlayer1, false);
} else if ("list".equals(subcommand.toLowerCase())) { } else if ("list".equals(subcommand.toLowerCase())) {
listGroup(localPlayer1, args); listGroup(localPlayer1, args);
} else if ("password".equals(subcommand.toLowerCase())) { } else if ("password".equals(subcommand.toLowerCase())) {
@ -61,26 +61,18 @@ public class CommandGroup
return true; return true;
} }
private boolean groupExists(String groupName) {
for (DeluxeGroup group : DeluxeGroups.getGroups()) {
if (group.getName().toLowerCase().equals(groupName.toLowerCase())) {
return true;
}
}
return false;
}
private void createGroup(Player player, String[] args) { private void createGroup(Player player, String[] args) {
if (args.length < 2) { if (args.length < 2) {
DeluxeUtil.sms(player, ChatColor.RED + Usage.CREATE.getFullUsage(player)); DeluxeUtil.sms(player, ChatColor.RED + Usage.CREATE.getFullUsage(player));
return; return;
} }
if (DeluxeGroups.getInGroup(player.getUniqueId().toString()) != null) { if (DeluxeGroups.getDatabase().inGroup(player.getUniqueId().toString())) {
DeluxeUtil.sms(player, ChatColor.RED + "You are already in a group! Leave it first to create a new one."); DeluxeUtil.sms(player, ChatColor.RED + "You are already in a group! Leave it first to create a new one.");
return; return;
} }
DeluxeGroup cg = new DeluxeGroup(); DeluxeGroup cg = new DeluxeGroup();
if (!groupExists(args[1])) { if (!DeluxeGroups.getDatabase().groupExists(args[1])) {
cg.setName(args[1]); cg.setName(args[1]);
if (args.length == 2) { if (args.length == 2) {
DeluxeUtil.sms(player, ChatColor.AQUA + "Creating " + args[1] + " with no password."); DeluxeUtil.sms(player, ChatColor.AQUA + "Creating " + args[1] + " with no password.");
@ -102,8 +94,8 @@ public class CommandGroup
return; return;
} }
cg.add(player); cg.add(player);
DeluxeGroups.setInGroup(player.getUniqueId().toString(), args[1]); int id = DeluxeGroups.getDatabase().addGroup(cg);
DeluxeGroups.addGroup(cg); DeluxeGroups.getDatabase().addPlayer(player.getUniqueId().toString(), id);
} else { } else {
DeluxeUtil.sms(player, ChatColor.RED + "A group with that name already exists!"); DeluxeUtil.sms(player, ChatColor.RED + "A group with that name already exists!");
} }
@ -114,22 +106,22 @@ public class CommandGroup
DeluxeUtil.sms(player, ChatColor.RED + Usage.JOIN.getFullUsage(player)); DeluxeUtil.sms(player, ChatColor.RED + Usage.JOIN.getFullUsage(player));
return; return;
} }
if (groupExists(args[1])) { if (DeluxeGroups.getDatabase().groupExists(args[1])) {
if (DeluxeGroups.getInGroup(player.getUniqueId().toString()) != null) { if (DeluxeGroups.getDatabase().inGroup(player.getUniqueId().toString())) {
if (args[1].toLowerCase().equals(DeluxeGroups.getInGroup(player.getUniqueId().toString()).toLowerCase())) { DeluxeGroup group = DeluxeGroups.getDatabase().getPlayerGroup(player.getUniqueId().toString());
if (args[1].toLowerCase().equals(group.getName().toLowerCase())) {
DeluxeUtil.sms(player, ChatColor.RED + "You are already in " DeluxeUtil.sms(player, ChatColor.RED + "You are already in "
+ DeluxeGroups.getInGroup(player.getUniqueId().toString())); + group.getName());
return; return;
} }
leaveGroup(player, args, true); leaveGroup(player, true);
} }
DeluxeGroup group = DeluxeGroups.getGroup(args[1]); DeluxeGroup group = DeluxeGroups.getDatabase().getGroup(args[1]);
if (args.length == 2) { if (args.length == 2) {
if (!group.hasPassword()) { if (!group.hasPassword()) {
group.sendMessage(player.getName() + " has joined the group!"); group.sendMessage(player.getName() + " has joined the group!");
DeluxeUtil.sms(player, ChatColor.AQUA + "You have joined " + group.getName() + "!"); DeluxeUtil.sms(player, ChatColor.AQUA + "You have joined " + group.getName() + "!");
DeluxeGroups.setInGroup(player.getUniqueId().toString(), group.getName()); DeluxeGroups.getDatabase().addPlayer(player.getUniqueId().toString(), group.getId());
DeluxeGroups.addToGroup(player, group.getName());
} else { } else {
DeluxeUtil.sms(player, ChatColor.RED + group.getName() + " is password protected."); DeluxeUtil.sms(player, ChatColor.RED + group.getName() + " is password protected.");
} }
@ -137,13 +129,11 @@ public class CommandGroup
if (group.hasPassword() && args[2].equals(group.getPassword())) { if (group.hasPassword() && args[2].equals(group.getPassword())) {
group.sendMessage(player.getName() + " has joined the group!"); group.sendMessage(player.getName() + " has joined the group!");
DeluxeUtil.sms(player, ChatColor.AQUA + "You have joined " + group.getName() + "!"); DeluxeUtil.sms(player, ChatColor.AQUA + "You have joined " + group.getName() + "!");
DeluxeGroups.setInGroup(player.getUniqueId().toString(), group.getName()); DeluxeGroups.getDatabase().addPlayer(player.getUniqueId().toString(), group.getId());
DeluxeGroups.addToGroup(player, group.getName());
} else if (!group.hasPassword()) { } else if (!group.hasPassword()) {
group.sendMessage(player.getName() + " has joined the group!"); group.sendMessage(player.getName() + " has joined the group!");
DeluxeUtil.sms(player, ChatColor.AQUA + "You have joined " + group.getName() + "!"); DeluxeUtil.sms(player, ChatColor.AQUA + "You have joined " + group.getName() + "!");
DeluxeGroups.setInGroup(player.getUniqueId().toString(), group.getName()); DeluxeGroups.getDatabase().addPlayer(player.getUniqueId().toString(), group.getId());
DeluxeGroups.addToGroup(player, group.getName());
} else { } else {
DeluxeUtil.sms(player, ChatColor.RED + "Incorrect password."); DeluxeUtil.sms(player, ChatColor.RED + "Incorrect password.");
} }
@ -157,8 +147,8 @@ public class CommandGroup
private void listGroup(Player player, String[] args) { private void listGroup(Player player, String[] args) {
if (args.length == 1) { if (args.length == 1) {
if (DeluxeGroups.getInGroup(player.getUniqueId().toString()) != null) { if (DeluxeGroups.getDatabase().inGroup(player.getUniqueId().toString())) {
DeluxeGroup deluxeGroup = DeluxeGroups.getGroup(DeluxeGroups.getInGroup(player.getUniqueId().toString())); DeluxeGroup deluxeGroup = DeluxeGroups.getDatabase().getPlayerGroup(player.getUniqueId().toString());
StringBuilder message = new StringBuilder(ChatColor.DARK_AQUA + "===== " + deluxeGroup.getName() + " ====="); StringBuilder message = new StringBuilder(ChatColor.DARK_AQUA + "===== " + deluxeGroup.getName() + " =====");
for (OfflinePlayer groupPlayer : deluxeGroup.getGroupList()) { for (OfflinePlayer groupPlayer : deluxeGroup.getGroupList()) {
if (groupPlayer.isOnline()) { if (groupPlayer.isOnline()) {
@ -173,7 +163,7 @@ public class CommandGroup
} }
} else if (args.length == 2) { } else if (args.length == 2) {
if (player.hasPermission("deluxegroups.admin")) { if (player.hasPermission("deluxegroups.admin")) {
DeluxeGroup carrotGroup = DeluxeGroups.getGroup(args[1]); DeluxeGroup carrotGroup = DeluxeGroups.getDatabase().getGroup(args[1]);
if (carrotGroup != null) { if (carrotGroup != null) {
StringBuilder message = new StringBuilder(ChatColor.DARK_AQUA + "===== " + carrotGroup.getName() + " ====="); StringBuilder message = new StringBuilder(ChatColor.DARK_AQUA + "===== " + carrotGroup.getName() + " =====");
for (OfflinePlayer groupPlayer : carrotGroup.getGroupList()) { for (OfflinePlayer groupPlayer : carrotGroup.getGroupList()) {
@ -195,16 +185,16 @@ public class CommandGroup
} }
} }
private void leaveGroup(Player player, String[] args, boolean fromJoin) { private void leaveGroup(Player player, boolean fromJoin) {
if (DeluxeGroups.getInGroup(player.getUniqueId().toString()) != null) { if (DeluxeGroups.getDatabase().inGroup(player.getUniqueId().toString())) {
DeluxeGroups.removeFromGroup(player, DeluxeGroups.getInGroup(player.getUniqueId().toString())); DeluxeGroup leaveGroup = DeluxeGroups.getDatabase().getPlayerGroup(player.getUniqueId().toString());
DeluxeGroup leaveGroup = DeluxeGroups.getGroup(DeluxeGroups.getInGroup(player.getUniqueId().toString())); DeluxeGroups.getDatabase().removePlayer(player.getUniqueId().toString());
DeluxeGroups.removeFromInGroup(player.getUniqueId().toString());
DeluxeUtil.sms(player, ChatColor.AQUA + "You have left " + leaveGroup.getName()); DeluxeUtil.sms(player, ChatColor.AQUA + "You have left " + leaveGroup.getName());
leaveGroup.remove(player);
leaveGroup.sendMessage(ChatColor.AQUA + player.getName() + " has left the group."); leaveGroup.sendMessage(ChatColor.AQUA + player.getName() + " has left the group.");
if (leaveGroup.getSize() < 1 && !leaveGroup.getPermanent()) { if (leaveGroup.getSize() < 1 && !leaveGroup.getPermanent()) {
// Disband // Disband
DeluxeGroups.removeGroup(leaveGroup); DeluxeGroups.getDatabase().removeGroup(leaveGroup.getId());
} }
} else if (!fromJoin){ } else if (!fromJoin){
DeluxeUtil.sms(player, ChatColor.RED + "You are not in a group!"); DeluxeUtil.sms(player, ChatColor.RED + "You are not in a group!");
@ -220,10 +210,11 @@ public class CommandGroup
DeluxeUtil.sms(player, ChatColor.RED + Usage.PASSWORD.getFullUsage(player)); DeluxeUtil.sms(player, ChatColor.RED + Usage.PASSWORD.getFullUsage(player));
return; return;
} }
DeluxeGroup group = DeluxeGroups.getGroup(args[1]); DeluxeGroup group = DeluxeGroups.getDatabase().getGroup(args[1]);
if (group != null) { if (group != null) {
if (args[2].equals(args[3])) { if (args[2].equals(args[3])) {
DeluxeGroups.getGroup(args[1]).setPassword(args[2]); group.setPassword(args[2]);
DeluxeGroups.getDatabase().updateGroup(group);
DeluxeUtil.sms(player, ChatColor.GREEN + "Password for " + group.getName() + " changed to '" + group.getPassword() + "'."); DeluxeUtil.sms(player, ChatColor.GREEN + "Password for " + group.getName() + " changed to '" + group.getPassword() + "'.");
} else { } else {
DeluxeUtil.sms(player, ChatColor.RED + "Passwords did not match."); DeluxeUtil.sms(player, ChatColor.RED + "Passwords did not match.");
@ -242,15 +233,16 @@ public class CommandGroup
DeluxeUtil.sms(player, ChatColor.RED + Usage.PERMANENT.getFullUsage(player)); DeluxeUtil.sms(player, ChatColor.RED + Usage.PERMANENT.getFullUsage(player));
return; return;
} }
DeluxeGroup group = DeluxeGroups.getGroup(args[1]); DeluxeGroup group = DeluxeGroups.getDatabase().getGroup(args[1]);
if (group != null) { if (group != null) {
Boolean perm = DeluxeUtil.resolveBoolean(args[2]); Boolean perm = DeluxeUtil.resolveBoolean(args[2]);
if (perm != null) { if (perm != null) {
DeluxeGroups.getGroup(args[1]).setPermanent(perm); group.setPermanent(perm);
DeluxeGroups.getDatabase().updateGroup(group);
DeluxeUtil.sms(player, ChatColor.GREEN + group.getName() + " is " + (group.getPermanent() ? "now" : "no longer") + " permanent."); DeluxeUtil.sms(player, ChatColor.GREEN + group.getName() + " is " + (group.getPermanent() ? "now" : "no longer") + " permanent.");
if (!group.getPermanent() && group.getSize() < 1) { if (!group.getPermanent() && group.getSize() < 1) {
// Disband // Disband
DeluxeGroups.removeGroup(group); DeluxeGroups.getDatabase().removeGroup(group.getId());
} }
} else { } else {
DeluxeUtil.sms(player, ChatColor.RED + Usage.PERMANENT.getFullUsage(player)); DeluxeUtil.sms(player, ChatColor.RED + Usage.PERMANENT.getFullUsage(player));
@ -271,13 +263,15 @@ public class CommandGroup
} }
Player argPlayer = Bukkit.getPlayer(args[1]); Player argPlayer = Bukkit.getPlayer(args[1]);
if (argPlayer != null) { if (argPlayer != null) {
if (DeluxeGroups.getInGroup(argPlayer.getUniqueId().toString()) != null) { if (DeluxeGroups.getDatabase().inGroup(argPlayer.getUniqueId().toString())) {
DeluxeGroup group = DeluxeGroups.getGroup(DeluxeGroups.getInGroup(argPlayer.getUniqueId().toString())); DeluxeGroup group = DeluxeGroups.getDatabase().getPlayerGroup(argPlayer.getUniqueId().toString());
DeluxeGroups.removeFromGroup(argPlayer, group.getName()); DeluxeGroups.getDatabase().removePlayer(argPlayer.getUniqueId().toString());
//group.remove(argPlayer.getUniqueId().toString());
DeluxeGroups.removeFromInGroup(argPlayer.getUniqueId().toString());
DeluxeUtil.sms(player, ChatColor.GREEN + argPlayer.getName() + " was kicked from " + group.getName() + "."); DeluxeUtil.sms(player, ChatColor.GREEN + argPlayer.getName() + " was kicked from " + group.getName() + ".");
DeluxeUtil.sms(argPlayer, ChatColor.RED + "You were kicked from " + group.getName() + "."); DeluxeUtil.sms(argPlayer, ChatColor.RED + "You were kicked from " + group.getName() + ".");
if (!group.getPermanent() && group.getSize() < 1) {
// Disband
DeluxeGroups.getDatabase().removeGroup(group.getId());
}
} else { } else {
DeluxeUtil.sms(player, ChatColor.RED + argPlayer.getName() + " is not in a group."); DeluxeUtil.sms(player, ChatColor.RED + argPlayer.getName() + " is not in a group.");
} }
@ -289,10 +283,9 @@ public class CommandGroup
offPlayer = null; offPlayer = null;
} }
if (offPlayer != null) { if (offPlayer != null) {
if (DeluxeGroups.getInGroup(offPlayer.getUniqueId().toString()) != null) { if (DeluxeGroups.getDatabase().inGroup(argPlayer.getUniqueId().toString())) {
DeluxeGroup group = DeluxeGroups.getGroup(DeluxeGroups.getInGroup(offPlayer.getUniqueId().toString())); DeluxeGroup group = DeluxeGroups.getDatabase().getPlayerGroup(argPlayer.getUniqueId().toString());
DeluxeGroups.removeFromGroup(offPlayer, group.getName()); DeluxeGroups.getDatabase().removePlayer(argPlayer.getUniqueId().toString());
DeluxeGroups.removeFromInGroup(offPlayer.getUniqueId().toString());
DeluxeUtil.sms(player, ChatColor.GREEN + offPlayer.getName() + " was kicked from " + group.getName() + "."); DeluxeUtil.sms(player, ChatColor.GREEN + offPlayer.getName() + " was kicked from " + group.getName() + ".");
if (offPlayer.isOnline()) { if (offPlayer.isOnline()) {
Player onPlayer = Bukkit.getPlayer(offPlayer.getUniqueId()); Player onPlayer = Bukkit.getPlayer(offPlayer.getUniqueId());
@ -307,7 +300,7 @@ public class CommandGroup
} }
} }
private void help(Player player) { public static void help(Player player) {
StringBuilder message = new StringBuilder(ChatColor.GOLD + "===== Group Help ====="); StringBuilder message = new StringBuilder(ChatColor.GOLD + "===== Group Help =====");
for (Usage usage : Usage.values()) { for (Usage usage : Usage.values()) {
if (usage.canUse(player)) { if (usage.canUse(player)) {
@ -362,7 +355,7 @@ public class CommandGroup
} }
public boolean canUse(Player player) { public boolean canUse(Player player) {
return (permission != null && player.hasPermission(permission)) || alternate != null; return permission == null || player.hasPermission(permission);
} }
public String getFullUsage(Player player) { public String getFullUsage(Player player) {

View File

@ -5,6 +5,7 @@ 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 xyz.etztech.deluxegroups.DeluxeGroups; import xyz.etztech.deluxegroups.DeluxeGroups;
public class CommandMain implements CommandExecutor { public class CommandMain implements CommandExecutor {
@ -25,14 +26,9 @@ public class CommandMain implements CommandExecutor {
case "help": case "help":
sender.sendMessage(ChatColor.GOLD + "----- DeluxeGroups Commands -----"); sender.sendMessage(ChatColor.GOLD + "----- DeluxeGroups Commands -----");
sender.sendMessage(ChatColor.YELLOW + "/dg reload - Reload the config"); sender.sendMessage(ChatColor.YELLOW + "/dg reload - Reload the config");
sender.sendMessage(ChatColor.GOLD + "----- DeluxeGroups Group Commands -----"); if (sender instanceof Player) {
sender.sendMessage(ChatColor.YELLOW + "/group - Display your group"); CommandGroup.help((Player) sender);
sender.sendMessage(ChatColor.YELLOW + "/group create - Create a new group."); }
sender.sendMessage(ChatColor.YELLOW + "/group join - Join a group");
sender.sendMessage(ChatColor.YELLOW + "/group leave - Leave a group");
sender.sendMessage(ChatColor.YELLOW + "/group list - List the players in a group");
sender.sendMessage(ChatColor.YELLOW + "/group password - Modify the password for your group");
sender.sendMessage(ChatColor.YELLOW + "/group kick - Kick a player from the group");
break; break;
case "reload": case "reload":
reload(sender); reload(sender);

View File

@ -42,11 +42,11 @@ public class AsyncPlayerChatListener implements Listener {
return; return;
} }
DynmapAPI dynmap = (DynmapAPI) DeluxeGroups.getDynmap(); DynmapAPI dynmap = DeluxeGroups.getDynmap();
IMinecraftManager minecraftManager = DeluxeGroups.getMinecraftManager(); IMinecraftManager minecraftManager = DeluxeGroups.getMinecraftManager();
if (DeluxeGroups.getInGroup(sender.getUniqueId().toString()) != null) { if (DeluxeGroups.getDatabase().inGroup(sender.getUniqueId().toString())) {
boolean groupChat = false; boolean groupChat = false;
for (String prefix : this.groupPrefixes) { for (String prefix : this.groupPrefixes) {
// If chat starts with 1 prefix, it is group chat. // If chat starts with 1 prefix, it is group chat.
@ -58,15 +58,7 @@ public class AsyncPlayerChatListener implements Listener {
event.setMessage(chat); event.setMessage(chat);
// Normal chat // Normal chat
if (!event.isCancelled()) { normalChat(event, sender, chat, dynmap, minecraftManager);
if (dynmap != null) {
dynmap.postPlayerMessageToWeb(sender.getName(), sender.getName(), chat);
//dynmap.sendBroadcastToWeb(sender.getName(), chat);
}
if (minecraftManager != null) {
minecraftManager.globalLog(sender, chat);
}
}
return; return;
} }
break; break;
@ -74,8 +66,7 @@ public class AsyncPlayerChatListener implements Listener {
} }
if (groupChat) { if (groupChat) {
String groupName = DeluxeGroups.getInGroup(sender.getUniqueId().toString()); DeluxeGroup group = DeluxeGroups.getDatabase().getPlayerGroup(sender.getUniqueId().toString());
DeluxeGroup group = DeluxeGroups.getGroup(groupName);
group.log(sender.getPlayer().getName(), chat); group.log(sender.getPlayer().getName(), chat);
String format = plugin.getConfig().getString("format.custom"); String format = plugin.getConfig().getString("format.custom");
@ -102,10 +93,13 @@ public class AsyncPlayerChatListener implements Listener {
} }
// Normal chat // Normal chat
normalChat(event, sender, chat, dynmap, minecraftManager);
}
private void normalChat(AsyncPlayerChatEvent event, Player sender, String chat, DynmapAPI dynmap, IMinecraftManager minecraftManager) {
if (!event.isCancelled()) { if (!event.isCancelled()) {
if (dynmap != null) { if (dynmap != null) {
dynmap.postPlayerMessageToWeb(sender.getName(), sender.getName(), chat); dynmap.postPlayerMessageToWeb(sender.getName(), sender.getName(), chat);
//dynmap.sendBroadcastToWeb(sender.getName(), chat);
} }
if (minecraftManager != null) { if (minecraftManager != null) {
minecraftManager.globalLog(sender, chat); minecraftManager.globalLog(sender, chat);

View File

@ -1,2 +0,0 @@
# This is a file for saving all your groups
# Do not manually edit this file!