Fix unban

This commit is contained in:
Telesphoreo 2022-01-29 19:53:22 -06:00
parent fd780463f8
commit bc41415034
9 changed files with 71 additions and 42 deletions

View File

@ -84,6 +84,7 @@ public class Plex extends JavaPlugin
{
config.load();
messages.load();
ranksOrPermissions = config.getString("commands.permissions");
try
{
@ -108,13 +109,12 @@ public class Plex extends JavaPlugin
new ListenerHandler(); // this doesn't need a variable.
new CommandHandler();
ranksOrPermissions = config.getString("commands.permissions");
rankManager = new RankManager();
rankManager.generateDefaultRanks();
rankManager.importDefaultRanks();
adminList = new AdminList();
PlexLog.log("Rank Manager initialized");
rankManager = new RankManager();
rankManager.generateDefaultRanks();
rankManager.importDefaultRanks();
adminList = new AdminList();
PlexLog.log("Rank Manager initialized");
punishmentManager = new PunishmentManager();
banManager = new BanManager();

View File

@ -24,10 +24,11 @@ public class BanManager
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
Plex.get().getMongoConnection().getDatastore().save(ban);
} else {
}
else
{
try (Connection con = Plex.get().getSqlConnection().getCon())
{
PreparedStatement statement = con.prepareStatement(INSERT);
statement.setString(1, ban.getId());
statement.setString(2, ban.getUuid().toString());
@ -38,7 +39,9 @@ public class BanManager
statement.setBoolean(7, ban.isActive());
statement.execute();
} catch (SQLException throwables) {
}
catch (SQLException throwables)
{
throwables.printStackTrace();
}
}
@ -50,18 +53,28 @@ public class BanManager
{
return Plex.get().getMongoConnection().getDatastore().find(Ban.class)
.filter(Filters.eq("uuid", uuid.toString())).filter(Filters.eq("active", true)).first() != null;
} else {
}
else
{
try (Connection con = Plex.get().getSqlConnection().getCon())
{
PreparedStatement statement = con.prepareStatement(SELECT);
statement.setString(1, uuid.toString());
ResultSet set = statement.executeQuery();
if (!set.next()) return false;
if (!set.next())
{
return false;
}
while (set.next())
{
if (set.getBoolean("active")) return true;
if (set.getBoolean("active"))
{
return true;
}
}
} catch (SQLException throwables) {
}
catch (SQLException throwables)
{
throwables.printStackTrace();
}
}
@ -77,14 +90,18 @@ public class BanManager
{
query.update(UpdateOperators.set("active", false)).execute();
}
} else {
}
else
{
try (Connection con = Plex.get().getSqlConnection().getCon())
{
PreparedStatement statement = con.prepareStatement("UPDATE `bans` SET active=? WHERE uuid=?");
statement.setBoolean(1, false);
statement.setString(2, uuid.toString());
statement.executeUpdate();
} catch (SQLException throwables) {
}
catch (SQLException throwables)
{
throwables.printStackTrace();
}
}
@ -99,14 +116,18 @@ public class BanManager
{
query.update(UpdateOperators.set("active", false)).execute();
}
} else {
}
else
{
try (Connection con = Plex.get().getSqlConnection().getCon())
{
PreparedStatement statement = con.prepareStatement("UPDATE `bans` SET active=? WHERE banID=?");
statement.setBoolean(1, false);
statement.setString(2, id);
statement.executeUpdate();
} catch (SQLException throwables) {
}
catch (SQLException throwables)
{
throwables.printStackTrace();
}
}
@ -121,7 +142,9 @@ public class BanManager
{
bans.add(ban);
}
} else {
}
else
{
try (Connection con = Plex.get().getSqlConnection().getCon())
{
PreparedStatement statement = con.prepareStatement("SELECT * FROM `bans`");
@ -140,12 +163,12 @@ public class BanManager
bans.add(ban);
}
}
} catch (SQLException throwables) {
}
catch (SQLException throwables)
{
throwables.printStackTrace();
}
}
return bans;
}
}

View File

@ -9,6 +9,7 @@ import dev.plex.command.exception.CommandArgumentException;
import dev.plex.command.exception.CommandFailException;
import dev.plex.command.exception.ConsoleMustDefinePlayerException;
import dev.plex.command.exception.ConsoleOnlyException;
import dev.plex.command.exception.PlayerNotBannedException;
import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer;
@ -123,7 +124,8 @@ public abstract class PlexCommand extends Command
send(sender, getUsage().replace("<command>", getLabel()));
}
catch (PlayerNotFoundException | CommandFailException
| ConsoleOnlyException | ConsoleMustDefinePlayerException ex)
| ConsoleOnlyException | ConsoleMustDefinePlayerException
| PlayerNotBannedException ex)
{
send(sender, ex.getMessage());
}

View File

@ -4,7 +4,6 @@ import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.bukkit.permissions.Permission;
@Retention(RetentionPolicy.RUNTIME)
public @interface CommandPermissions

View File

@ -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"));
}
}

View File

@ -2,24 +2,17 @@ package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.cache.DataUtils;
import dev.plex.cache.PlayerCache;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.PlayerNotBannedException;
import dev.plex.command.exception.PlayerNotFoundException;
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.util.PlexUtils;
import java.time.Instant;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -40,15 +33,20 @@ public class UnbanCMD extends PlexCommand
if (args.length == 1)
{
UUID targetUUID = PlexUtils.getFromName(args[0]);
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
Player player = getNonNullPlayer(args[0]);
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
{
throw new PlayerNotFoundException();
}
if (!plugin.getBanManager().isBanned(targetUUID))
{
throw new PlayerNotBannedException();
}
plugin.getBanManager().unban(targetUUID);
PlexUtils.broadcast(tl("unbanningPlayer", sender.getName(), plexPlayer.getName()));
PlexUtils.broadcast(tl("unbanningPlayer", sender.getName(), player.getName()));
}
return null;
}

View File

@ -1,7 +1,6 @@
package dev.plex.services.impl;
import dev.plex.Plex;
import dev.plex.PlexBase;
import dev.plex.banning.Ban;
import dev.plex.services.AbstractService;
import java.util.Date;

View File

@ -162,12 +162,7 @@ public class PlexUtils extends PlexBase
{
return;
}
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());
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());
World world = c1.getWorld();
for (int y = sy; y <= ey; y++)
{
@ -183,7 +178,7 @@ public class PlexUtils extends PlexBase
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)
@ -238,6 +233,7 @@ public class PlexUtils extends PlexBase
{
return ThreadLocalRandom.current().nextInt(limit);
}
public static int randomNum(int start, int limit)
{
return ThreadLocalRandom.current().nextInt(start, limit);

View File

@ -69,4 +69,5 @@ rankMustBeHigherThanAdmin: "<e>The rank you entered must be higher than Admin."
consoleOnly: "<e>This command can only be executed by the console."
yourRank: "<b>Your rank is: <v>"
banningPlayer: "<e><v> - Banning <v>"
unbanningPlayer: "<b><v> - Unbanning <v>"
unbanningPlayer: "<b><v> - Unbanning <v>"
playerNotBanned: "<e>That player is not banned!"