Skip to content

Commit

Permalink
More correctly make aban feature
Browse files Browse the repository at this point in the history
  • Loading branch information
BoomEaro committed Aug 17, 2024
1 parent 305ef00 commit 0e8e69a
Show file tree
Hide file tree
Showing 19 changed files with 354 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,19 @@ public CommonEvent callEvent(String name, Object... args) {
event = new PlayerBanEvent((PlayerBanData) args[0], (boolean) args[1]);
break;
case "PlayerABanEvent":
event = new PlayerABanEvent((PlayerBanData) args[0], (boolean) args[1]);
event = new PlayerABanEvent((PlayerABanData) args[0], (boolean) args[1]);
break;
case "PlayerBannedEvent":
event = new PlayerBannedEvent((PlayerBanData) args[0], (boolean) args[1]);
break;
case "PlayerABannedEvent":
event = new PlayerABannedEvent((PlayerBanData) args[0], (boolean) args[1]);
event = new PlayerABannedEvent((PlayerABanData) args[0], (boolean) args[1]);
break;
case "PlayerUnbanEvent":
event = new PlayerUnbanEvent((PlayerBanData) args[0], (PlayerData) args[1], (String) args[2]);
break;
case "PlayerAUnbanEvent":
event = new PlayerAUnbanEvent((PlayerBanData) args[0], (PlayerData) args[1], (String) args[2]);
event = new PlayerAUnbanEvent((PlayerABanData) args[0], (PlayerData) args[1], (String) args[2]);
break;
case "IpBanEvent":
event = new IpBanEvent((IpBanData) args[0], (boolean) args[1]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package me.confuser.banmanager.bukkit.api.events;

import lombok.Getter;
import me.confuser.banmanager.common.data.PlayerBanData;
import me.confuser.banmanager.common.data.PlayerABanData;


public class PlayerABanEvent extends SilentCancellableEvent {

@Getter
private PlayerBanData ban;
private PlayerABanData ban;

public PlayerABanEvent(PlayerBanData ban, boolean isSilent) {
public PlayerABanEvent(PlayerABanData ban, boolean isSilent) {
super(isSilent, true);
this.ban = ban;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package me.confuser.banmanager.bukkit.api.events;

import lombok.Getter;
import me.confuser.banmanager.common.data.PlayerBanData;
import me.confuser.banmanager.common.data.PlayerABanData;


public class PlayerABannedEvent extends SilentEvent {

@Getter
private PlayerBanData ban;
private PlayerABanData ban;

public PlayerABannedEvent(PlayerBanData ban, boolean isSilent) {
public PlayerABannedEvent(PlayerABanData ban, boolean isSilent) {
super(isSilent, true);
this.ban = ban;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package me.confuser.banmanager.bukkit.api.events;

import lombok.Getter;
import me.confuser.banmanager.common.data.PlayerBanData;
import me.confuser.banmanager.common.data.PlayerABanData;
import me.confuser.banmanager.common.data.PlayerData;


public class PlayerAUnbanEvent extends CustomCancellableEvent {

@Getter
private PlayerBanData ban;
private PlayerABanData ban;
@Getter
private PlayerData actor;
@Getter
private String reason;

public PlayerAUnbanEvent(PlayerBanData ban, PlayerData actor, String reason) {
public PlayerAUnbanEvent(PlayerABanData ban, PlayerData actor, String reason) {
super(true);

this.ban = ban;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,19 @@ public CommonEvent callEvent(String name, Object... args) {
event = new PlayerBanEvent((PlayerBanData) args[0], (boolean) args[1]);
break;
case "PlayerABanEvent":
event = new PlayerABanEvent((PlayerBanData) args[0], (boolean) args[1]);
event = new PlayerABanEvent((PlayerABanData) args[0], (boolean) args[1]);
break;
case "PlayerBannedEvent":
event = new PlayerBannedEvent((PlayerBanData) args[0], (boolean) args[1]);
break;
case "PlayerABannedEvent":
event = new PlayerABannedEvent((PlayerBanData) args[0], (boolean) args[1]);
event = new PlayerABannedEvent((PlayerABanData) args[0], (boolean) args[1]);
break;
case "PlayerUnbanEvent":
event = new PlayerUnbanEvent((PlayerBanData) args[0], (PlayerData) args[1], (String) args[2]);
break;
case "PlayerAUnbanEvent":
event = new PlayerAUnbanEvent((PlayerBanData) args[0], (PlayerData) args[1], (String) args[2]);
event = new PlayerAUnbanEvent((PlayerABanData) args[0], (PlayerData) args[1], (String) args[2]);
break;
case "IpBanEvent":
event = new IpBanEvent((IpBanData) args[0], (boolean) args[1]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package me.confuser.banmanager.bungee.api.events;

import lombok.Getter;
import me.confuser.banmanager.common.data.PlayerBanData;
import me.confuser.banmanager.common.data.PlayerABanData;


public class PlayerABanEvent extends SilentCancellableEvent {

@Getter
private PlayerBanData ban;
private PlayerABanData ban;

public PlayerABanEvent(PlayerBanData ban, boolean isSilent) {
public PlayerABanEvent(PlayerABanData ban, boolean isSilent) {
super(isSilent);
this.ban = ban;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package me.confuser.banmanager.bungee.api.events;

import lombok.Getter;
import me.confuser.banmanager.common.data.PlayerBanData;
import me.confuser.banmanager.common.data.PlayerABanData;


public class PlayerABannedEvent extends SilentEvent {

@Getter
private PlayerBanData ban;
private PlayerABanData ban;

public PlayerABannedEvent(PlayerBanData ban, boolean isSilent) {
public PlayerABannedEvent(PlayerABanData ban, boolean isSilent) {
super(isSilent);
this.ban = ban;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package me.confuser.banmanager.bungee.api.events;

import lombok.Getter;
import me.confuser.banmanager.common.data.PlayerBanData;
import me.confuser.banmanager.common.data.PlayerABanData;
import me.confuser.banmanager.common.data.PlayerData;


public class PlayerAUnbanEvent extends CustomCancellableEvent {

@Getter
private PlayerBanData ban;
private PlayerABanData ban;
@Getter
private PlayerData actor;
@Getter
private String reason;

public PlayerAUnbanEvent(PlayerBanData ban, PlayerData actor, String reason) {
public PlayerAUnbanEvent(PlayerABanData ban, PlayerData actor, String reason) {
super();

this.ban = ban;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import me.confuser.banmanager.common.BanManagerPlugin;
import me.confuser.banmanager.common.CommonPlayer;
import me.confuser.banmanager.common.data.PlayerBanData;
import me.confuser.banmanager.common.data.PlayerABanData;
import me.confuser.banmanager.common.data.PlayerData;
import me.confuser.banmanager.common.util.DateUtils;
import me.confuser.banmanager.common.util.Message;
Expand Down Expand Up @@ -112,7 +112,7 @@ public boolean onCommand(CommonSender sender, CommandParser parser) {
if (actor == null) return;

if (isBanned) {
PlayerBanData ban;
PlayerABanData ban;

if (isUUID) {
ban = getPlugin().getPlayerABanStorage().getBan(UUID.fromString(playerName));
Expand All @@ -131,7 +131,7 @@ public boolean onCommand(CommonSender sender, CommandParser parser) {
}
}

final PlayerBanData ban = new PlayerBanData(player, actor, parser.getReason().getMessage(), isSilent);
final PlayerABanData ban = new PlayerABanData(player, actor, parser.getReason().getMessage(), isSilent);
boolean created;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


import me.confuser.banmanager.common.BanManagerPlugin;
import me.confuser.banmanager.common.data.PlayerBanData;
import me.confuser.banmanager.common.data.PlayerABanData;
import me.confuser.banmanager.common.data.PlayerData;
import me.confuser.banmanager.common.util.Message;
import me.confuser.banmanager.common.util.parsers.UnbanCommandParser;
Expand Down Expand Up @@ -57,7 +57,7 @@ public boolean onCommand(final CommonSender sender, CommandParser originalParser
final String reason = parser.getReason().getMessage();

getPlugin().getScheduler().runAsync(() -> {
PlayerBanData ban;
PlayerABanData ban;

if (isUUID) {
ban = getPlugin().getPlayerABanStorage().getBan(UUID.fromString(playerName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public class LocalDatabaseConfig extends DatabaseConfig {
put("duplicatePlayers", DuplicatePlayerData.class);

put("playerBans", PlayerBanData.class);
put("playerABans", PlayerBanData.class);
put("playerABans", PlayerABanData.class);

put("playerBanRecords", PlayerBanRecord.class);
put("playerABanRecords", PlayerBanRecord.class);
put("playerABanRecords", PlayerABanRecord.class);

put("playerMutes", PlayerMuteData.class);
put("playerMuteRecords", PlayerMuteRecord.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package me.confuser.banmanager.common.data;

import lombok.Getter;
import me.confuser.banmanager.common.ormlite.field.DatabaseField;
import me.confuser.banmanager.common.ormlite.table.DatabaseTable;
import me.confuser.banmanager.common.storage.mysql.ByteArray;

@DatabaseTable
public class PlayerABanData {

@DatabaseField(generatedId = true)
@Getter
private int id;
@DatabaseField(canBeNull = false, foreign = true, foreignAutoRefresh = true, uniqueIndex = true, persisterClass = ByteArray.class, columnDefinition = "BINARY(16) NOT NULL")
@Getter
private PlayerData player;
@DatabaseField(canBeNull = false)
@Getter
private String reason;
@Getter
@DatabaseField(canBeNull = false, foreign = true, foreignAutoRefresh = true, persisterClass = ByteArray.class, columnDefinition = "BINARY(16) NOT NULL")
private PlayerData actor;

// Should always be database time
@DatabaseField(index = true, columnDefinition = "BIGINT UNSIGNED NOT NULL")
@Getter
private long created = System.currentTimeMillis() / 1000L;
@DatabaseField(index = true, columnDefinition = "BIGINT UNSIGNED NOT NULL")
@Getter
private long updated = System.currentTimeMillis() / 1000L;
@DatabaseField(index = true, columnDefinition = "BIGINT UNSIGNED NOT NULL")
@Getter
private long expires = 0;

@DatabaseField
@Getter
private boolean silent = false;

PlayerABanData() {

}

public PlayerABanData(PlayerData player, PlayerData actor, String reason, boolean silent) {
this.player = player;
this.reason = reason;
this.actor = actor;
this.silent = silent;
}

public PlayerABanData(PlayerData player, PlayerData actor, String reason, boolean silent, long expires) {
this(player, actor, reason, silent);

this.expires = expires;
}

// Only use for imports!
public PlayerABanData(PlayerData player, PlayerData actor, String reason, boolean silent, long expires, long created) {
this(player, actor, reason, silent, expires);

this.created = created;
}

public PlayerABanData(int id, PlayerData player, PlayerData actor, String reason, boolean silent, long expires, long created, long updated) {
this(player, actor, reason, silent, expires, created);

this.id = id;
this.updated = updated;
}

public PlayerABanData(PlayerBanRecord record) {
this(record.getPlayer(), record.getPastActor(), record.getReason(), record.isSilent(), record.getExpired(), record.getPastCreated());
}

public boolean hasExpired() {
return getExpires() != 0 && getExpires() <= (System.currentTimeMillis() / 1000L);
}

public boolean equalsBan(PlayerABanData ban) {
return ban.getReason().equals(this.reason)
&& ban.getExpires() == expires
&& ban.getCreated() == this.created
&& ban.getPlayer().getUUID().equals(this.getPlayer().getUUID())
&& ban.getActor().getUUID().equals(this.actor.getUUID());
}
}
Loading

0 comments on commit 0e8e69a

Please sign in to comment.