mirror of
https://github.com/plexusorg/Plex.git
synced 2025-07-01 15:46:42 +00:00
That's right, Redis is working!
- Fix end date for bans not being correct - Add a lot of debug information - Add ban reasons
This commit is contained in:
@ -13,12 +13,14 @@ 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.PlexLog;
|
||||
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.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.time.DateUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -38,42 +40,51 @@ public class BanCMD extends PlexCommand
|
||||
return usage(getUsage());
|
||||
}
|
||||
|
||||
if (args.length == 1)
|
||||
UUID targetUUID = PlexUtils.getFromName(args[0]);
|
||||
String reason;
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
{
|
||||
UUID targetUUID = PlexUtils.getFromName(args[0]);
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
Player player = Bukkit.getPlayer(targetUUID);
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
if (isAdmin(plexPlayer))
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
|
||||
if (isAdmin(plexPlayer))
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
||||
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
|
||||
{
|
||||
PlexPlayer plexPlayer1 = getPlexPlayer((Player)sender);
|
||||
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
|
||||
{
|
||||
return tl("higherRankThanYou");
|
||||
}
|
||||
return tl("higherRankThanYou");
|
||||
}
|
||||
}
|
||||
|
||||
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(targetUUID) == null ? new PunishedPlayer(targetUUID) : PlayerCache.getPunishedPlayer(targetUUID);
|
||||
Punishment punishment = new Punishment(targetUUID, getUUID(sender));
|
||||
punishment.setType(PunishmentType.BAN);
|
||||
punishment.setReason("");
|
||||
punishment.setPunishedUsername(plexPlayer.getName());
|
||||
punishment.setEndDate(new Date(Instant.now().plusSeconds(PlexUtils.hoursToSeconds(24)).getEpochSecond()));
|
||||
punishment.setCustomTime(false);
|
||||
plugin.getPunishmentManager().doPunishment(punishedPlayer, punishment);
|
||||
PlexUtils.broadcast(tl("banningPlayer", sender.getName(), plexPlayer.getName()));
|
||||
if (Bukkit.getPlayer(targetUUID) != null)
|
||||
{
|
||||
Bukkit.getPlayer(targetUUID).kick(componentFromString("&cYou've been banned."));
|
||||
}
|
||||
}
|
||||
|
||||
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(targetUUID) == null ? new PunishedPlayer(targetUUID) : PlayerCache.getPunishedPlayer(targetUUID);
|
||||
Punishment punishment = new Punishment(targetUUID, getUUID(sender));
|
||||
punishment.setType(PunishmentType.BAN);
|
||||
if (args.length > 1)
|
||||
{
|
||||
reason = StringUtils.join(args, " ", 1, args.length);
|
||||
punishment.setReason(reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
punishment.setReason("No reason provided.");
|
||||
}
|
||||
punishment.setPunishedUsername(plexPlayer.getName());
|
||||
Date date = new Date();
|
||||
punishment.setEndDate(DateUtils.addDays(date, 1));
|
||||
punishment.setCustomTime(false);
|
||||
plugin.getPunishmentManager().doPunishment(punishedPlayer, punishment);
|
||||
PlexUtils.broadcast(tl("banningPlayer", sender.getName(), plexPlayer.getName()));
|
||||
if (player != null)
|
||||
{
|
||||
player.kick(componentFromString("&cYou've been banned."));
|
||||
}
|
||||
PlexLog.debug("(From /ban command) PunishedPlayer UUID: " + punishedPlayer.getUuid());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -11,11 +11,11 @@ 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.apache.commons.lang.time.DateUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -36,7 +36,8 @@ public class FreezeCMD extends PlexCommand
|
||||
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());
|
||||
Punishment punishment = new Punishment(UUID.fromString(punishedPlayer.getUuid()), getUUID(sender));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setEndDate(new Date(Instant.now().plusSeconds(10).toEpochMilli()));
|
||||
Date date = new Date();
|
||||
punishment.setEndDate(DateUtils.addDays(date, 1));
|
||||
punishment.setType(PunishmentType.FREEZE);
|
||||
punishment.setPunishedUsername(player.getName());
|
||||
punishment.setReason("");
|
||||
|
@ -6,6 +6,7 @@ import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import java.util.List;
|
||||
@ -28,7 +29,7 @@ public class PlexCMD extends PlexCommand
|
||||
send(sender, ChatColor.LIGHT_PURPLE + "Plex. The long awaited TotalFreedomMod rewrite starts here...");
|
||||
return componentFromString(ChatColor.LIGHT_PURPLE + "Plugin version: " + ChatColor.GOLD + "1.0");
|
||||
}
|
||||
if (args[0].equals("reload"))
|
||||
if (args[0].equalsIgnoreCase("reload"))
|
||||
{
|
||||
checkRank(sender, Rank.SENIOR_ADMIN, "plex.reload");
|
||||
Plex.get().config.load();
|
||||
@ -39,6 +40,17 @@ public class PlexCMD extends PlexCommand
|
||||
send(sender, "Imported ranks");
|
||||
send(sender, "Plex successfully reloaded.");
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("redis"))
|
||||
{
|
||||
checkRank(sender, Rank.SENIOR_ADMIN, "plex.redis");
|
||||
if (!plugin.getRedisConnection().isEnabled())
|
||||
{
|
||||
throw new CommandFailException("&cRedis is not enabled.");
|
||||
}
|
||||
plugin.getRedisConnection().getJedis().set("test", "123");
|
||||
send(sender, "Set test to 123. Now outputting key test...");
|
||||
send(sender, plugin.getRedisConnection().getJedis().get("test"));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CommandArgumentException();
|
||||
@ -49,6 +61,6 @@ public class PlexCMD extends PlexCommand
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return ImmutableList.of("reload");
|
||||
return ImmutableList.of("reload", "redis");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user