mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
Fix unban
This commit is contained in:
parent
fd780463f8
commit
bc41415034
@ -84,6 +84,7 @@ public class Plex extends JavaPlugin
|
|||||||
{
|
{
|
||||||
config.load();
|
config.load();
|
||||||
messages.load();
|
messages.load();
|
||||||
|
ranksOrPermissions = config.getString("commands.permissions");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -108,13 +109,12 @@ public class Plex extends JavaPlugin
|
|||||||
new ListenerHandler(); // this doesn't need a variable.
|
new ListenerHandler(); // this doesn't need a variable.
|
||||||
new CommandHandler();
|
new CommandHandler();
|
||||||
|
|
||||||
ranksOrPermissions = config.getString("commands.permissions");
|
|
||||||
|
|
||||||
rankManager = new RankManager();
|
rankManager = new RankManager();
|
||||||
rankManager.generateDefaultRanks();
|
rankManager.generateDefaultRanks();
|
||||||
rankManager.importDefaultRanks();
|
rankManager.importDefaultRanks();
|
||||||
adminList = new AdminList();
|
adminList = new AdminList();
|
||||||
PlexLog.log("Rank Manager initialized");
|
PlexLog.log("Rank Manager initialized");
|
||||||
|
|
||||||
punishmentManager = new PunishmentManager();
|
punishmentManager = new PunishmentManager();
|
||||||
banManager = new BanManager();
|
banManager = new BanManager();
|
||||||
|
@ -24,10 +24,11 @@ public class BanManager
|
|||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||||
{
|
{
|
||||||
Plex.get().getMongoConnection().getDatastore().save(ban);
|
Plex.get().getMongoConnection().getDatastore().save(ban);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||||
{
|
{
|
||||||
|
|
||||||
PreparedStatement statement = con.prepareStatement(INSERT);
|
PreparedStatement statement = con.prepareStatement(INSERT);
|
||||||
statement.setString(1, ban.getId());
|
statement.setString(1, ban.getId());
|
||||||
statement.setString(2, ban.getUuid().toString());
|
statement.setString(2, ban.getUuid().toString());
|
||||||
@ -38,7 +39,9 @@ public class BanManager
|
|||||||
statement.setBoolean(7, ban.isActive());
|
statement.setBoolean(7, ban.isActive());
|
||||||
statement.execute();
|
statement.execute();
|
||||||
|
|
||||||
} catch (SQLException throwables) {
|
}
|
||||||
|
catch (SQLException throwables)
|
||||||
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,18 +53,28 @@ public class BanManager
|
|||||||
{
|
{
|
||||||
return Plex.get().getMongoConnection().getDatastore().find(Ban.class)
|
return Plex.get().getMongoConnection().getDatastore().find(Ban.class)
|
||||||
.filter(Filters.eq("uuid", uuid.toString())).filter(Filters.eq("active", true)).first() != null;
|
.filter(Filters.eq("uuid", uuid.toString())).filter(Filters.eq("active", true)).first() != null;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||||
{
|
{
|
||||||
PreparedStatement statement = con.prepareStatement(SELECT);
|
PreparedStatement statement = con.prepareStatement(SELECT);
|
||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
ResultSet set = statement.executeQuery();
|
ResultSet set = statement.executeQuery();
|
||||||
if (!set.next()) return false;
|
if (!set.next())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
while (set.next())
|
while (set.next())
|
||||||
{
|
{
|
||||||
if (set.getBoolean("active")) return true;
|
if (set.getBoolean("active"))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException throwables) {
|
}
|
||||||
|
catch (SQLException throwables)
|
||||||
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,14 +90,18 @@ public class BanManager
|
|||||||
{
|
{
|
||||||
query.update(UpdateOperators.set("active", false)).execute();
|
query.update(UpdateOperators.set("active", false)).execute();
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||||
{
|
{
|
||||||
PreparedStatement statement = con.prepareStatement("UPDATE `bans` SET active=? WHERE uuid=?");
|
PreparedStatement statement = con.prepareStatement("UPDATE `bans` SET active=? WHERE uuid=?");
|
||||||
statement.setBoolean(1, false);
|
statement.setBoolean(1, false);
|
||||||
statement.setString(2, uuid.toString());
|
statement.setString(2, uuid.toString());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
} catch (SQLException throwables) {
|
}
|
||||||
|
catch (SQLException throwables)
|
||||||
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,14 +116,18 @@ public class BanManager
|
|||||||
{
|
{
|
||||||
query.update(UpdateOperators.set("active", false)).execute();
|
query.update(UpdateOperators.set("active", false)).execute();
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||||
{
|
{
|
||||||
PreparedStatement statement = con.prepareStatement("UPDATE `bans` SET active=? WHERE banID=?");
|
PreparedStatement statement = con.prepareStatement("UPDATE `bans` SET active=? WHERE banID=?");
|
||||||
statement.setBoolean(1, false);
|
statement.setBoolean(1, false);
|
||||||
statement.setString(2, id);
|
statement.setString(2, id);
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
} catch (SQLException throwables) {
|
}
|
||||||
|
catch (SQLException throwables)
|
||||||
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,7 +142,9 @@ public class BanManager
|
|||||||
{
|
{
|
||||||
bans.add(ban);
|
bans.add(ban);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||||
{
|
{
|
||||||
PreparedStatement statement = con.prepareStatement("SELECT * FROM `bans`");
|
PreparedStatement statement = con.prepareStatement("SELECT * FROM `bans`");
|
||||||
@ -140,12 +163,12 @@ public class BanManager
|
|||||||
bans.add(ban);
|
bans.add(ban);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException throwables) {
|
}
|
||||||
|
catch (SQLException throwables)
|
||||||
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bans;
|
return bans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import dev.plex.command.exception.CommandArgumentException;
|
|||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.exception.ConsoleMustDefinePlayerException;
|
import dev.plex.command.exception.ConsoleMustDefinePlayerException;
|
||||||
import dev.plex.command.exception.ConsoleOnlyException;
|
import dev.plex.command.exception.ConsoleOnlyException;
|
||||||
|
import dev.plex.command.exception.PlayerNotBannedException;
|
||||||
import dev.plex.command.exception.PlayerNotFoundException;
|
import dev.plex.command.exception.PlayerNotFoundException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
@ -123,7 +124,8 @@ public abstract class PlexCommand extends Command
|
|||||||
send(sender, getUsage().replace("<command>", getLabel()));
|
send(sender, getUsage().replace("<command>", getLabel()));
|
||||||
}
|
}
|
||||||
catch (PlayerNotFoundException | CommandFailException
|
catch (PlayerNotFoundException | CommandFailException
|
||||||
| ConsoleOnlyException | ConsoleMustDefinePlayerException ex)
|
| ConsoleOnlyException | ConsoleMustDefinePlayerException
|
||||||
|
| PlayerNotBannedException ex)
|
||||||
{
|
{
|
||||||
send(sender, ex.getMessage());
|
send(sender, ex.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import dev.plex.command.source.RequiredCommandSource;
|
|||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import org.bukkit.permissions.Permission;
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface CommandPermissions
|
public @interface CommandPermissions
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package dev.plex.command.exception;
|
||||||
|
|
||||||
|
import static dev.plex.util.PlexUtils.tl;
|
||||||
|
|
||||||
|
public class PlayerNotBannedException extends RuntimeException
|
||||||
|
{
|
||||||
|
public PlayerNotBannedException()
|
||||||
|
{
|
||||||
|
super(tl("playerNotBanned"));
|
||||||
|
}
|
||||||
|
}
|
@ -2,24 +2,17 @@ package dev.plex.command.impl;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.cache.PlayerCache;
|
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
|
import dev.plex.command.exception.PlayerNotBannedException;
|
||||||
import dev.plex.command.exception.PlayerNotFoundException;
|
import dev.plex.command.exception.PlayerNotFoundException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.player.PlexPlayer;
|
|
||||||
import dev.plex.player.PunishedPlayer;
|
|
||||||
import dev.plex.punishment.Punishment;
|
|
||||||
import dev.plex.punishment.PunishmentType;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -40,15 +33,20 @@ public class UnbanCMD extends PlexCommand
|
|||||||
if (args.length == 1)
|
if (args.length == 1)
|
||||||
{
|
{
|
||||||
UUID targetUUID = PlexUtils.getFromName(args[0]);
|
UUID targetUUID = PlexUtils.getFromName(args[0]);
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
Player player = getNonNullPlayer(args[0]);
|
||||||
|
|
||||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||||
{
|
{
|
||||||
throw new PlayerNotFoundException();
|
throw new PlayerNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!plugin.getBanManager().isBanned(targetUUID))
|
||||||
|
{
|
||||||
|
throw new PlayerNotBannedException();
|
||||||
|
}
|
||||||
|
|
||||||
plugin.getBanManager().unban(targetUUID);
|
plugin.getBanManager().unban(targetUUID);
|
||||||
PlexUtils.broadcast(tl("unbanningPlayer", sender.getName(), plexPlayer.getName()));
|
PlexUtils.broadcast(tl("unbanningPlayer", sender.getName(), player.getName()));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package dev.plex.services.impl;
|
package dev.plex.services.impl;
|
||||||
|
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.PlexBase;
|
|
||||||
import dev.plex.banning.Ban;
|
import dev.plex.banning.Ban;
|
||||||
import dev.plex.services.AbstractService;
|
import dev.plex.services.AbstractService;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -162,12 +162,7 @@ public class PlexUtils extends PlexBase
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int sy = Math.min(c1.getBlockY(), c2.getBlockY()),
|
int sy = Math.min(c1.getBlockY(), c2.getBlockY()), ey = Math.max(c1.getBlockY(), c2.getBlockY()), sx = Math.min(c1.getBlockX(), c2.getBlockX()), ex = Math.max(c1.getBlockX(), c2.getBlockX()), sz = Math.min(c1.getBlockZ(), c2.getBlockZ()), ez = Math.max(c1.getBlockZ(), c2.getBlockZ());
|
||||||
ey = Math.max(c1.getBlockY(), c2.getBlockY()),
|
|
||||||
sx = Math.min(c1.getBlockX(), c2.getBlockX()),
|
|
||||||
ex = Math.max(c1.getBlockX(), c2.getBlockX()),
|
|
||||||
sz = Math.min(c1.getBlockZ(), c2.getBlockZ()),
|
|
||||||
ez = Math.max(c1.getBlockZ(), c2.getBlockZ());
|
|
||||||
World world = c1.getWorld();
|
World world = c1.getWorld();
|
||||||
for (int y = sy; y <= ey; y++)
|
for (int y = sy; y <= ey; y++)
|
||||||
{
|
{
|
||||||
@ -183,7 +178,7 @@ public class PlexUtils extends PlexBase
|
|||||||
|
|
||||||
public static List<String> getPlayerNameList()
|
public static List<String> getPlayerNameList()
|
||||||
{
|
{
|
||||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void broadcast(String s)
|
public static void broadcast(String s)
|
||||||
@ -238,6 +233,7 @@ public class PlexUtils extends PlexBase
|
|||||||
{
|
{
|
||||||
return ThreadLocalRandom.current().nextInt(limit);
|
return ThreadLocalRandom.current().nextInt(limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int randomNum(int start, int limit)
|
public static int randomNum(int start, int limit)
|
||||||
{
|
{
|
||||||
return ThreadLocalRandom.current().nextInt(start, limit);
|
return ThreadLocalRandom.current().nextInt(start, limit);
|
||||||
|
@ -70,3 +70,4 @@ consoleOnly: "<e>This command can only be executed by the console."
|
|||||||
yourRank: "<b>Your rank is: <v>"
|
yourRank: "<b>Your rank is: <v>"
|
||||||
banningPlayer: "<e><v> - Banning <v>"
|
banningPlayer: "<e><v> - Banning <v>"
|
||||||
unbanningPlayer: "<b><v> - Unbanning <v>"
|
unbanningPlayer: "<b><v> - Unbanning <v>"
|
||||||
|
playerNotBanned: "<e>That player is not banned!"
|
Loading…
Reference in New Issue
Block a user