Skip to content

Commit

Permalink
Fix bans since MC 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
ibot3 committed Feb 12, 2025
1 parent 8c48b90 commit 6c3f550
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 12 deletions.
4 changes: 2 additions & 2 deletions bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>net.vyhub</groupId>
<artifactId>VyHubMinecraft</artifactId>
<version>2.0.2</version>
<version>3.0.0</version>
</parent>

<artifactId>bukkit</artifactId>
Expand All @@ -29,7 +29,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<version>1.21.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand Down
20 changes: 19 additions & 1 deletion bukkit/src/main/java/net/vyhub/command/Ban.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.ban.ProfileBanList;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -57,8 +58,25 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

String reason = args.length == 3 ? args[2] : null;
Date expireDate = new Date(Calendar.getInstance().getTimeInMillis() + (minutes * 60 * 1000));

try {
((ProfileBanList) Bukkit.getBanList(BanList.Type.PROFILE)).addBan(
p.getPlayerProfile(),
reason,
expireDate,
sender.getName()
);
} catch (NoSuchMethodError | NoSuchFieldError e) {
Bukkit.getBanList(BanList.Type.NAME).addBan(
p.getName(),
reason,
expireDate,
sender.getName()
);
}

p.kickPlayer(String.format(platform.getI18n().get("youGotTimeBanned"), minutes, reason));
Bukkit.getBanList(BanList.Type.NAME).addBan(p.getUniqueId().toString(), reason, new Date(Calendar.getInstance().getTimeInMillis() + (minutes * 60 * 1000)), sender.getName());
} else {
sender.sendMessage(platform.getI18n().get("playerMustBeOnline"));
}
Expand Down
26 changes: 24 additions & 2 deletions bukkit/src/main/java/net/vyhub/tasks/TBans.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import net.vyhub.abstractClasses.AUser;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.ban.ProfileBanList;
import org.bukkit.entity.Player;
import org.bukkit.profile.PlayerProfile;

import java.time.ZonedDateTime;
import java.util.Date;
Expand All @@ -25,7 +28,19 @@ public boolean addMinecraftBan(String playerID, net.vyhub.entity.Ban vyhubBan) {
endDate = Date.from(expiresDate.toInstant());
}

Bukkit.getBanList(BanList.Type.NAME).addBan(playerID, vyhubBan.getReason(), endDate, "VyHub");
String creator = "VyHub";
if (vyhubBan.getCreator() != null) {
creator = vyhubBan.getCreator().getUsername();
}

try {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(playerID));
PlayerProfile playerProfile = Bukkit.createPlayerProfile(UUID.fromString(playerID), offlinePlayer.getName());

((ProfileBanList) Bukkit.getBanList(BanList.Type.PROFILE)).addBan(playerProfile, vyhubBan.getReason(), endDate, creator);
} catch (NoSuchMethodError e) {
Bukkit.getBanList(BanList.Type.NAME).addBan(playerID, vyhubBan.getReason(), endDate, creator);
}

Player bannnedPlayer = Bukkit.getPlayer(UUID.fromString(playerID));
if (bannnedPlayer != null) {
Expand All @@ -40,7 +55,14 @@ public boolean addMinecraftBan(String playerID, net.vyhub.entity.Ban vyhubBan) {

@Override
public boolean unbanMinecraftBan(String playerID) {
Bukkit.getBanList(BanList.Type.NAME).pardon(playerID);
try {
PlayerProfile playerProfile = Bukkit.createPlayerProfile(UUID.fromString(playerID), "");

((ProfileBanList) Bukkit.getBanList(BanList.Type.PROFILE)).pardon(playerProfile);
} catch (NoSuchMethodError e) {
Bukkit.getBanList(BanList.Type.NAME).pardon(playerID);
}

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion bungeeCord/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>net.vyhub</groupId>
<artifactId>VyHubMinecraft</artifactId>
<version>2.0.2</version>
<version>3.0.0</version>
</parent>

<artifactId>bungeeCord</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>net.vyhub</groupId>
<artifactId>VyHubMinecraft</artifactId>
<version>2.0.2</version>
<version>3.0.0</version>
</parent>

<artifactId>common</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/net/vyhub/abstractClasses/ABans.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public abstract class ABans extends VyHubAbstractBase{
private static Set<String> processedPlayers = new HashSet<>();
private static Map<String, MinecraftBan> minecraftBans = null;
private static Map<String, List<Ban>> vyhubBans = null;
private final AUser aUser;
protected final AUser aUser;
private final AGroups aGroups;

public ABans(VyHubPlatform platform, AUser aUser, AGroups aGroups) {
Expand Down
12 changes: 11 additions & 1 deletion common/src/main/java/net/vyhub/entity/Ban.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ public class Ban {
private String ends_on;
private String status;
private Boolean active;
private VyHubUser creator;

public Ban(String id, String reason, Integer length, String ends_on, String status, Boolean active) {
public Ban(String id, String reason, Integer length, String ends_on, String status, Boolean active, VyHubUser creator) {
this.id = id;
this.reason = reason;
this.length = length;
this.ends_on = ends_on;
this.status = status;
this.active = active;
this.creator = creator;
}

public String getId() {
Expand All @@ -40,4 +42,12 @@ public String getStatus() {
public Boolean getActive() {
return active;
}

public VyHubUser getCreator() {
return creator;
}

public void setCreator(VyHubUser creator) {
this.creator = creator;
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.vyhub</groupId>
<artifactId>VyHubMinecraft</artifactId>
<version>2.0.2</version>
<version>3.0.0</version>
<packaging>pom</packaging>
<modules>
<module>bukkit</module>
Expand Down
2 changes: 1 addition & 1 deletion velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>net.vyhub</groupId>
<artifactId>VyHubMinecraft</artifactId>
<version>2.0.2</version>
<version>3.0.0</version>
</parent>

<build>
Expand Down
2 changes: 1 addition & 1 deletion velocity/src/main/java/net/vyhub/VyHubPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;

@Plugin(id = "vyhub", name = "vyhub", version = "2.0.2",
@Plugin(id = "vyhub", name = "vyhub", version = "3.0.0",
url = "https://vyhub.net", description = "VyHub plugin to manage and monetize your Minecraft server. You can create your webstore for free with VyHub!", authors = {"VyHub, Matbyte"})
public class VyHubPlugin {
public static VyHubPlugin plugin;
Expand Down

0 comments on commit 6c3f550

Please sign in to comment.