mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
add to central data class
add vanished variable to plexplayers finish admin cmd except msgs aren't done fix command source and plexcommand add sender source to admin events add admin listener register admin listener simplify playerlistener fix sql syntax on sqlconnection
This commit is contained in:
parent
542bba062c
commit
87abb0a964
@ -54,4 +54,14 @@ public class DataUtils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void insert(PlexPlayer plexPlayer)
|
||||||
|
{
|
||||||
|
if (Plex.get().getStorageType() == StorageType.MONGO)
|
||||||
|
{
|
||||||
|
Plex.get().getMongoPlayerData().save(plexPlayer);
|
||||||
|
} else {
|
||||||
|
Plex.get().getSqlPlayerData().insert(plexPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,8 @@ public class MongoPlayerData
|
|||||||
UpdateOperators.set("prefix", player.getPrefix()),
|
UpdateOperators.set("prefix", player.getPrefix()),
|
||||||
UpdateOperators.set("rank", player.getRank().toLowerCase()),
|
UpdateOperators.set("rank", player.getRank().toLowerCase()),
|
||||||
UpdateOperators.set("ips", player.getIps()),
|
UpdateOperators.set("ips", player.getIps()),
|
||||||
UpdateOperators.set("coins", player.getCoins()));
|
UpdateOperators.set("coins", player.getCoins()),
|
||||||
|
UpdateOperators.set("vanished", player.isVanished()));
|
||||||
|
|
||||||
updateOps.execute();
|
updateOps.execute();
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ import me.totalfreedom.plex.player.PlexPlayer;
|
|||||||
public class SQLPlayerData
|
public class SQLPlayerData
|
||||||
{
|
{
|
||||||
private final String SELECT = "SELECT * FROM `players` WHERE uuid=?";
|
private final String SELECT = "SELECT * FROM `players` WHERE uuid=?";
|
||||||
private final String UPDATE = "UPDATE `players` SET name=?, login_msg=?, prefix=?, rank=?, ips=?, coins=? WHERE uuid=?";
|
private final String UPDATE = "UPDATE `players` SET name=?, login_msg=?, prefix=?, rank=?, ips=?, coins=?, vanished=? WHERE uuid=?";
|
||||||
private final String INSERT = "INSERT INTO `players` (`uuid`, `name`, `login_msg`, `prefix`, `rank`, `ips`, `coins`) VALUES (?, ?, ?, ?, ?, ?, ?);";
|
private final String INSERT = "INSERT INTO `players` (`uuid`, `name`, `login_msg`, `prefix`, `rank`, `ips`, `coins`, `vanished`) VALUES (?, ?, ?, ?, ?, ?, ?, ?);";
|
||||||
|
|
||||||
public boolean exists(UUID uuid)
|
public boolean exists(UUID uuid)
|
||||||
{
|
{
|
||||||
@ -53,15 +53,15 @@ public class SQLPlayerData
|
|||||||
String prefix = set.getString("prefix");
|
String prefix = set.getString("prefix");
|
||||||
String rankName = set.getString("rank").toUpperCase();
|
String rankName = set.getString("rank").toUpperCase();
|
||||||
long coins = set.getLong("coins");
|
long coins = set.getLong("coins");
|
||||||
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>()
|
boolean vanished = set.getBoolean("vanished");
|
||||||
{
|
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>(){}.getType());
|
||||||
}.getType());
|
|
||||||
plexPlayer.setName(name);
|
plexPlayer.setName(name);
|
||||||
plexPlayer.setLoginMSG(loginMSG);
|
plexPlayer.setLoginMSG(loginMSG);
|
||||||
plexPlayer.setPrefix(prefix);
|
plexPlayer.setPrefix(prefix);
|
||||||
plexPlayer.setRank(rankName);
|
plexPlayer.setRank(rankName);
|
||||||
plexPlayer.setIps(ips);
|
plexPlayer.setIps(ips);
|
||||||
plexPlayer.setCoins(coins);
|
plexPlayer.setCoins(coins);
|
||||||
|
plexPlayer.setVanished(vanished);
|
||||||
}
|
}
|
||||||
return plexPlayer;
|
return plexPlayer;
|
||||||
}
|
}
|
||||||
@ -83,7 +83,8 @@ public class SQLPlayerData
|
|||||||
statement.setString(4, player.getRank().toLowerCase());
|
statement.setString(4, player.getRank().toLowerCase());
|
||||||
statement.setString(5, new Gson().toJson(player.getIps()));
|
statement.setString(5, new Gson().toJson(player.getIps()));
|
||||||
statement.setLong(6, player.getCoins());
|
statement.setLong(6, player.getCoins());
|
||||||
statement.setString(7, player.getUuid());
|
statement.setBoolean(7, player.isVanished());
|
||||||
|
statement.setString(8, player.getUuid());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
}
|
}
|
||||||
catch (SQLException throwables)
|
catch (SQLException throwables)
|
||||||
@ -103,6 +104,8 @@ public class SQLPlayerData
|
|||||||
statement.setString(4, player.getPrefix());
|
statement.setString(4, player.getPrefix());
|
||||||
statement.setString(5, player.getRank().toLowerCase());
|
statement.setString(5, player.getRank().toLowerCase());
|
||||||
statement.setString(6, new Gson().toJson(player.getIps()));
|
statement.setString(6, new Gson().toJson(player.getIps()));
|
||||||
|
statement.setLong(7, player.getCoins());
|
||||||
|
statement.setBoolean(8, player.isVanished());
|
||||||
statement.execute();
|
statement.execute();
|
||||||
}
|
}
|
||||||
catch (SQLException throwables)
|
catch (SQLException throwables)
|
||||||
|
@ -2,6 +2,7 @@ package me.totalfreedom.plex.command;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.totalfreedom.plex.command.source.CommandSource;
|
import me.totalfreedom.plex.command.source.CommandSource;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public interface IPlexCommand
|
public interface IPlexCommand
|
||||||
{
|
{
|
||||||
|
@ -74,11 +74,7 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.sender == null)
|
|
||||||
{
|
|
||||||
this.sender = new CommandSource(sender);
|
|
||||||
}
|
|
||||||
PlexLog.log(this.sender.getSender().getName());
|
|
||||||
if (commandSource == RequiredCommandSource.CONSOLE && sender instanceof Player)
|
if (commandSource == RequiredCommandSource.CONSOLE && sender instanceof Player)
|
||||||
{
|
{
|
||||||
sender.sendMessage(tl("noPermissionInGame"));
|
sender.sendMessage(tl("noPermissionInGame"));
|
||||||
@ -92,6 +88,8 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Player player = (Player)sender;
|
Player player = (Player)sender;
|
||||||
|
|
||||||
|
this.sender = new CommandSource(player);
|
||||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||||
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||||
{
|
{
|
||||||
@ -101,6 +99,7 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
this.sender = new CommandSource(sender);
|
||||||
execute(this.sender, args);
|
execute(this.sender, args);
|
||||||
}
|
}
|
||||||
catch (CommandArgumentException ex)
|
catch (CommandArgumentException ex)
|
||||||
@ -121,13 +120,12 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
|||||||
{
|
{
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
}
|
}
|
||||||
if (this.sender == null)
|
|
||||||
{
|
|
||||||
this.sender = new CommandSource(sender);
|
|
||||||
}
|
|
||||||
if (sender instanceof Player)
|
if (sender instanceof Player)
|
||||||
{
|
{
|
||||||
Player player = (Player)sender;
|
Player player = (Player)sender;
|
||||||
|
|
||||||
|
this.sender = new CommandSource(player);
|
||||||
|
|
||||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||||
if (plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
if (plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||||
{
|
{
|
||||||
@ -140,6 +138,7 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
this.sender = new CommandSource(sender);
|
||||||
return onTabComplete(this.sender, args);
|
return onTabComplete(this.sender, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,7 +191,7 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
|||||||
|
|
||||||
protected boolean isConsole()
|
protected boolean isConsole()
|
||||||
{
|
{
|
||||||
return sender instanceof ConsoleCommandSender;
|
return !(sender instanceof Player);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String tl(String s, Object... objects)
|
protected String tl(String s, Object... objects)
|
||||||
|
@ -20,10 +20,12 @@ import me.totalfreedom.plex.util.PlexUtils;
|
|||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = RequiredCommandSource.CONSOLE)
|
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(usage = "/<command> <add | remove | setrank | list> [player] [rank]", aliases = "saconfig,slconfig,adminconfig,adminmanage", description = "Manage all admins")
|
@CommandParameters(usage = "/<command> <add | remove | setrank | list> [player] [rank]", aliases = "saconfig,slconfig,adminconfig,adminmanage", description = "Manage all admins")
|
||||||
public class AdminCMD extends PlexCommand
|
public class AdminCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
|
//TODO: Better return messages
|
||||||
|
|
||||||
public AdminCMD()
|
public AdminCMD()
|
||||||
{
|
{
|
||||||
super("admin");
|
super("admin");
|
||||||
@ -46,23 +48,9 @@ public class AdminCMD extends PlexCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
if (!sender.isConsoleSender())
|
||||||
|
|
||||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
|
||||||
{
|
{
|
||||||
throw new PlayerNotFoundException();
|
sender.send("Console only");
|
||||||
}
|
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
|
||||||
plexPlayer.setRank(Rank.ADMIN.name());
|
|
||||||
DataUtils.update(plexPlayer);
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new AdminAddEvent(plexPlayer));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (args[0].equalsIgnoreCase("remove"))
|
|
||||||
{
|
|
||||||
if (args.length != 2)
|
|
||||||
{
|
|
||||||
sender.send(usage("/admin remove <player>"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,9 +61,49 @@ public class AdminCMD extends PlexCommand
|
|||||||
throw new PlayerNotFoundException();
|
throw new PlayerNotFoundException();
|
||||||
}
|
}
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||||
|
|
||||||
|
if (isAdmin(plexPlayer))
|
||||||
|
{
|
||||||
|
sender.send("Player is an admin");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
plexPlayer.setRank(Rank.ADMIN.name());
|
||||||
|
DataUtils.update(plexPlayer);
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(new AdminAddEvent(sender, plexPlayer));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args[0].equalsIgnoreCase("remove"))
|
||||||
|
{
|
||||||
|
if (args.length != 2)
|
||||||
|
{
|
||||||
|
sender.send(usage("/admin remove <player>"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sender.isConsoleSender())
|
||||||
|
{
|
||||||
|
sender.send("Console only");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||||
|
|
||||||
|
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||||
|
{
|
||||||
|
throw new PlayerNotFoundException();
|
||||||
|
}
|
||||||
|
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||||
|
|
||||||
|
if (!isAdmin(plexPlayer))
|
||||||
|
{
|
||||||
|
sender.send("Player is not an admin");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
plexPlayer.setRank("");
|
plexPlayer.setRank("");
|
||||||
DataUtils.update(plexPlayer);
|
DataUtils.update(plexPlayer);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new AdminRemoveEvent(plexPlayer));
|
Bukkit.getServer().getPluginManager().callEvent(new AdminRemoveEvent(sender, plexPlayer));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +115,12 @@ public class AdminCMD extends PlexCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!sender.isConsoleSender())
|
||||||
|
{
|
||||||
|
sender.send("Console only");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||||
|
|
||||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||||
@ -109,10 +143,17 @@ public class AdminCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||||
|
|
||||||
|
if (!isAdmin(plexPlayer))
|
||||||
|
{
|
||||||
|
sender.send("Player is not an admin");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
plexPlayer.setRank(rank.name().toLowerCase());
|
plexPlayer.setRank(rank.name().toLowerCase());
|
||||||
DataUtils.update(plexPlayer);
|
DataUtils.update(plexPlayer);
|
||||||
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new AdminSetRankEvent(plexPlayer, rank));
|
Bukkit.getServer().getPluginManager().callEvent(new AdminSetRankEvent(sender, plexPlayer, rank));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,12 @@ public class CommandSource
|
|||||||
private final CommandSender sender;
|
private final CommandSender sender;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final PlexPlayer plexPlayer;
|
private final PlexPlayer plexPlayer;
|
||||||
|
private final boolean isConsoleSender;
|
||||||
|
|
||||||
public CommandSource(CommandSender sender)
|
public CommandSource(CommandSender sender)
|
||||||
{
|
{
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
|
this.isConsoleSender = !(sender instanceof Player);
|
||||||
this.player = sender instanceof Player ? Bukkit.getPlayer(sender.getName()) : null;
|
this.player = sender instanceof Player ? Bukkit.getPlayer(sender.getName()) : null;
|
||||||
this.plexPlayer = sender instanceof Player ? PlayerCache.getPlexPlayerMap().get(((Player)sender).getUniqueId()) : null;
|
this.plexPlayer = sender instanceof Player ? PlayerCache.getPlexPlayerMap().get(((Player)sender).getUniqueId()) : null;
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
package me.totalfreedom.plex.event;
|
package me.totalfreedom.plex.event;
|
||||||
|
|
||||||
|
import me.totalfreedom.plex.command.source.CommandSource;
|
||||||
import me.totalfreedom.plex.player.PlexPlayer;
|
import me.totalfreedom.plex.player.PlexPlayer;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
public class AdminAddEvent extends Event
|
public class AdminAddEvent extends Event
|
||||||
{
|
{
|
||||||
private final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private CommandSource sender;
|
||||||
private PlexPlayer plexPlayer;
|
private PlexPlayer plexPlayer;
|
||||||
|
|
||||||
public AdminAddEvent(PlexPlayer plexPlayer)
|
public AdminAddEvent(CommandSource sender, PlexPlayer plexPlayer)
|
||||||
{
|
{
|
||||||
|
this.sender = sender;
|
||||||
this.plexPlayer = plexPlayer;
|
this.plexPlayer = plexPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,8 +24,17 @@ public class AdminAddEvent extends Event
|
|||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList()
|
||||||
|
{
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
public PlexPlayer getPlexPlayer()
|
public PlexPlayer getPlexPlayer()
|
||||||
{
|
{
|
||||||
return plexPlayer;
|
return plexPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommandSource getSender() {
|
||||||
|
return sender;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
package me.totalfreedom.plex.event;
|
package me.totalfreedom.plex.event;
|
||||||
|
|
||||||
|
import me.totalfreedom.plex.command.source.CommandSource;
|
||||||
import me.totalfreedom.plex.player.PlexPlayer;
|
import me.totalfreedom.plex.player.PlexPlayer;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
public class AdminRemoveEvent extends Event
|
public class AdminRemoveEvent extends Event
|
||||||
{
|
{
|
||||||
private final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
private PlexPlayer plexPlayer;
|
private PlexPlayer plexPlayer;
|
||||||
|
private CommandSource sender;
|
||||||
|
|
||||||
public AdminRemoveEvent(PlexPlayer plexPlayer)
|
public AdminRemoveEvent(CommandSource sender, PlexPlayer plexPlayer)
|
||||||
{
|
{
|
||||||
|
this.sender = sender;
|
||||||
this.plexPlayer = plexPlayer;
|
this.plexPlayer = plexPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,8 +24,17 @@ public class AdminRemoveEvent extends Event
|
|||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList()
|
||||||
|
{
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
public PlexPlayer getPlexPlayer()
|
public PlexPlayer getPlexPlayer()
|
||||||
{
|
{
|
||||||
return plexPlayer;
|
return plexPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommandSource getSender() {
|
||||||
|
return sender;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package me.totalfreedom.plex.event;
|
package me.totalfreedom.plex.event;
|
||||||
|
|
||||||
|
import me.totalfreedom.plex.command.source.CommandSource;
|
||||||
import me.totalfreedom.plex.player.PlexPlayer;
|
import me.totalfreedom.plex.player.PlexPlayer;
|
||||||
import me.totalfreedom.plex.rank.enums.Rank;
|
import me.totalfreedom.plex.rank.enums.Rank;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
@ -7,13 +8,15 @@ import org.bukkit.event.HandlerList;
|
|||||||
|
|
||||||
public class AdminSetRankEvent extends Event
|
public class AdminSetRankEvent extends Event
|
||||||
{
|
{
|
||||||
private final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private CommandSource sender;
|
||||||
private PlexPlayer plexPlayer;
|
private PlexPlayer plexPlayer;
|
||||||
private Rank rank;
|
private Rank rank;
|
||||||
|
|
||||||
public AdminSetRankEvent(PlexPlayer plexPlayer, Rank rank)
|
public AdminSetRankEvent(CommandSource sender, PlexPlayer plexPlayer, Rank rank)
|
||||||
{
|
{
|
||||||
|
this.sender = sender;
|
||||||
this.plexPlayer = plexPlayer;
|
this.plexPlayer = plexPlayer;
|
||||||
this.rank = rank;
|
this.rank = rank;
|
||||||
}
|
}
|
||||||
@ -24,6 +27,11 @@ public class AdminSetRankEvent extends Event
|
|||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList()
|
||||||
|
{
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
public PlexPlayer getPlexPlayer()
|
public PlexPlayer getPlexPlayer()
|
||||||
{
|
{
|
||||||
return plexPlayer;
|
return plexPlayer;
|
||||||
@ -33,4 +41,8 @@ public class AdminSetRankEvent extends Event
|
|||||||
{
|
{
|
||||||
return rank;
|
return rank;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommandSource getSender() {
|
||||||
|
return sender;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,7 @@ package me.totalfreedom.plex.handlers;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.totalfreedom.plex.listener.PlexListener;
|
import me.totalfreedom.plex.listener.PlexListener;
|
||||||
import me.totalfreedom.plex.listener.impl.ChatListener;
|
import me.totalfreedom.plex.listener.impl.*;
|
||||||
import me.totalfreedom.plex.listener.impl.FreezeListener;
|
|
||||||
import me.totalfreedom.plex.listener.impl.PlayerListener;
|
|
||||||
import me.totalfreedom.plex.listener.impl.ServerListener;
|
|
||||||
import me.totalfreedom.plex.listener.impl.WorldListener;
|
|
||||||
import me.totalfreedom.plex.util.PlexLog;
|
import me.totalfreedom.plex.util.PlexLog;
|
||||||
|
|
||||||
public class ListenerHandler
|
public class ListenerHandler
|
||||||
@ -21,6 +17,7 @@ public class ListenerHandler
|
|||||||
listeners.add(new PlayerListener());
|
listeners.add(new PlayerListener());
|
||||||
listeners.add(new WorldListener());
|
listeners.add(new WorldListener());
|
||||||
listeners.add(new FreezeListener());
|
listeners.add(new FreezeListener());
|
||||||
|
listeners.add(new AdminListener());
|
||||||
PlexLog.log(String.format("Registered %s listeners!", listeners.size()));
|
PlexLog.log(String.format("Registered %s listeners!", listeners.size()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
package me.totalfreedom.plex.listener.impl;
|
||||||
|
|
||||||
|
import me.totalfreedom.plex.event.AdminAddEvent;
|
||||||
|
import me.totalfreedom.plex.event.AdminRemoveEvent;
|
||||||
|
import me.totalfreedom.plex.event.AdminSetRankEvent;
|
||||||
|
import me.totalfreedom.plex.listener.PlexListener;
|
||||||
|
import me.totalfreedom.plex.player.PlexPlayer;
|
||||||
|
import me.totalfreedom.plex.rank.enums.Rank;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
|
||||||
|
public class AdminListener extends PlexListener
|
||||||
|
{
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onAdminAdd(AdminAddEvent event)
|
||||||
|
{
|
||||||
|
String userSender = event.getSender().getName();
|
||||||
|
PlexPlayer target = event.getPlexPlayer();
|
||||||
|
|
||||||
|
Bukkit.broadcastMessage(String.format(ChatColor.RED + "%s - Adding %s to the admin list!", userSender, target.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onAdminRemove(AdminRemoveEvent event)
|
||||||
|
{
|
||||||
|
String userSender = event.getSender().getName();
|
||||||
|
PlexPlayer target = event.getPlexPlayer();
|
||||||
|
|
||||||
|
Bukkit.broadcastMessage(String.format(ChatColor.RED + "%s - Removing %s from the admin list!", userSender, target.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onAdminSetrank(AdminSetRankEvent event)
|
||||||
|
{
|
||||||
|
String userSender = event.getSender().getName();
|
||||||
|
PlexPlayer target = event.getPlexPlayer();
|
||||||
|
Rank newRank = event.getRank();
|
||||||
|
|
||||||
|
Bukkit.broadcastMessage(String.format(ChatColor.RED + "%s - Setting %s's rank to %s!", userSender, target.getName(), newRank.name().toUpperCase()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,6 +3,7 @@ package me.totalfreedom.plex.listener.impl;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import me.totalfreedom.plex.admin.Admin;
|
import me.totalfreedom.plex.admin.Admin;
|
||||||
|
import me.totalfreedom.plex.cache.DataUtils;
|
||||||
import me.totalfreedom.plex.cache.MongoPlayerData;
|
import me.totalfreedom.plex.cache.MongoPlayerData;
|
||||||
import me.totalfreedom.plex.cache.PlayerCache;
|
import me.totalfreedom.plex.cache.PlayerCache;
|
||||||
import me.totalfreedom.plex.cache.SQLPlayerData;
|
import me.totalfreedom.plex.cache.SQLPlayerData;
|
||||||
@ -30,9 +31,21 @@ public class PlayerListener extends PlexListener
|
|||||||
{
|
{
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
PlexPlayer plexPlayer = null;
|
PlexPlayer plexPlayer;
|
||||||
|
|
||||||
if (mongoPlayerData != null) // Alright, check if we're saving with Mongo first
|
if (!DataUtils.hasPlayedBefore(player.getUniqueId()))
|
||||||
|
{
|
||||||
|
PlexLog.log("AYO THIS MAN DONT EXIST"); // funi msg
|
||||||
|
plexPlayer = new PlexPlayer(player.getUniqueId()); //it doesn't! okay so now create the object
|
||||||
|
plexPlayer.setName(player.getName()); //set the name of the player
|
||||||
|
plexPlayer.setIps(Arrays.asList(player.getAddress().getAddress().getHostAddress().trim())); //set the arraylist of ips
|
||||||
|
|
||||||
|
DataUtils.insert(plexPlayer); // insert data in some wack db
|
||||||
|
} else {
|
||||||
|
plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if (mongoPlayerData != null) // Alright, check if we're saving with Mongo first
|
||||||
{
|
{
|
||||||
if (!mongoPlayerData.exists(player.getUniqueId())) //okay, we're saving with mongo! now check if the player's document exists
|
if (!mongoPlayerData.exists(player.getUniqueId())) //okay, we're saving with mongo! now check if the player's document exists
|
||||||
{
|
{
|
||||||
@ -64,7 +77,7 @@ public class PlayerListener extends PlexListener
|
|||||||
plexPlayer = sqlPlayerData.getByUUID(player.getUniqueId()); //oh they do exist!
|
plexPlayer = sqlPlayerData.getByUUID(player.getUniqueId()); //oh they do exist!
|
||||||
plexPlayer.setName(plexPlayer.getName()); //set the name!
|
plexPlayer.setName(plexPlayer.getName()); //set the name!
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
PlayerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache
|
PlayerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache
|
||||||
PlayerCache.getPunishedPlayerMap().put(player.getUniqueId(), new PunishedPlayer(player.getUniqueId()));
|
PlayerCache.getPunishedPlayerMap().put(player.getUniqueId(), new PunishedPlayer(player.getUniqueId()));
|
||||||
|
@ -33,6 +33,8 @@ public class PlexPlayer
|
|||||||
private String loginMSG;
|
private String loginMSG;
|
||||||
private String prefix;
|
private String prefix;
|
||||||
|
|
||||||
|
private boolean vanished;
|
||||||
|
|
||||||
private long coins;
|
private long coins;
|
||||||
|
|
||||||
private String rank;
|
private String rank;
|
||||||
@ -54,6 +56,8 @@ public class PlexPlayer
|
|||||||
this.loginMSG = "";
|
this.loginMSG = "";
|
||||||
this.prefix = "";
|
this.prefix = "";
|
||||||
|
|
||||||
|
this.vanished = false;
|
||||||
|
|
||||||
this.coins = 0;
|
this.coins = 0;
|
||||||
|
|
||||||
this.ips = new ArrayList<>();
|
this.ips = new ArrayList<>();
|
||||||
|
@ -42,14 +42,15 @@ public class SQLConnection extends PlexBase
|
|||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `players` (\n" +
|
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `players` (\n" +
|
||||||
"\t`uuid` VARCHAR(46),\n" +
|
"\t`uuid` VARCHAR(46) NOT NULL,\n" +
|
||||||
"\t`name` VARCHAR(18),\n" +
|
"\t`name` VARCHAR(18),\n" +
|
||||||
"\t`login_msg` VARCHAR,\n" +
|
"\t`login_msg` VARCHAR,\n" +
|
||||||
"\t`prefix` VARCHAR,\n" +
|
"\t`prefix` VARCHAR,\n" +
|
||||||
"\t`rank` VARCHAR,\n" +
|
"\t`rank` VARCHAR,\n" +
|
||||||
"\t`ips` VARCHAR,\n" +
|
"\t`ips` VARCHAR,\n" +
|
||||||
"\t`coins` INT\n" +
|
"\t`coins` BIGINT,\n" +
|
||||||
//"\tPRIMARY KEY (`uuid`)\n" +
|
"\t`vanished` BOOLEAN,\n" +
|
||||||
|
"\tPRIMARY KEY (`uuid`)\n" +
|
||||||
");").execute();
|
");").execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user