Add Ban Methods to Player Objects

Allows a more logical API for banning players.

player.banPlayer("Breaking the rules");
This commit is contained in:
Aikar
2018-04-28 10:28:50 -04:00
parent a97f03a018
commit 92482f8e92
2 changed files with 247 additions and 0 deletions

View File

@@ -67,6 +67,73 @@ public interface OfflinePlayer extends ServerOperator, AnimalTamer, Configuratio
* @return true if banned, otherwise false
*/
public boolean isBanned();
// Paper start
/**
* Permanently Bans this player from the server
*
* @param reason Reason for Ban
* @return Ban Entry
* @deprecated use {@link #ban(String, Date, String)}
*/
@NotNull
@Deprecated(since = "1.20.4")
public default BanEntry banPlayer(@Nullable String reason) {
return banPlayer(reason, null, null);
}
/**
* Permanently Bans this player from the server
* @param reason Reason for Ban
* @param source Source of the ban, or null for default
* @return Ban Entry
* @deprecated use {@link #ban(String, Date, String)}
*/
@NotNull
@Deprecated(since = "1.20.4")
public default BanEntry banPlayer(@Nullable String reason, @Nullable String source) {
return banPlayer(reason, null, source);
}
/**
* Bans this player from the server
* @param reason Reason for Ban
* @param expires When to expire the ban
* @return Ban Entry
* @deprecated use {@link #ban(String, Date, String)}
*/
@NotNull
@Deprecated(since = "1.20.4")
public default BanEntry banPlayer(@Nullable String reason, @Nullable java.util.Date expires) {
return banPlayer(reason, expires, null);
}
/**
* Bans this player from the server
* @param reason Reason for Ban
* @param expires When to expire the ban
* @param source Source of the ban or null for default
* @return Ban Entry
* @deprecated use {@link #ban(String, Date, String)}
*/
@NotNull
@Deprecated(since = "1.20.4")
public default BanEntry banPlayer(@Nullable String reason, @Nullable java.util.Date expires, @Nullable String source) {
return banPlayer(reason, expires, source, true);
}
/**
* @deprecated use {@link #ban(String, Date, String)}
*/
@NotNull
@Deprecated(since = "1.20.4")
public default BanEntry banPlayer(@Nullable String reason, @Nullable java.util.Date expires, @Nullable String source, boolean kickIfOnline) {
BanEntry banEntry = Bukkit.getServer().getBanList(BanList.Type.NAME).addBan(getName(), reason, expires, source);
if (kickIfOnline && isOnline()) {
getPlayer().kickPlayer(reason);
}
return banEntry;
}
// Paper end
/**
* Adds this user to the {@link ProfileBanList}. If a previous ban exists, this will