forked from BanManagement/BanManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to implement paid unban command
- Loading branch information
Showing
10 changed files
with
208 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
common/src/main/java/me/confuser/banmanager/common/commands/UnbanPaidCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package me.confuser.banmanager.common.commands; | ||
|
||
import me.confuser.banmanager.common.BanManagerPlugin; | ||
import me.confuser.banmanager.common.data.PlayerBanData; | ||
import me.confuser.banmanager.common.data.PlayerData; | ||
import me.confuser.banmanager.common.util.Message; | ||
import me.confuser.banmanager.common.util.parsers.UnbanCommandParser; | ||
|
||
import java.sql.SQLException; | ||
import java.util.UUID; | ||
|
||
public class UnbanPaidCommand extends CommonCommand { | ||
|
||
public UnbanPaidCommand(BanManagerPlugin plugin) { | ||
super(plugin, "unbanpaid", true, UnbanCommandParser.class, 0); | ||
} | ||
|
||
@Override | ||
public boolean onCommand(final CommonSender sender, CommandParser originalParser) { | ||
final UnbanCommandParser parser = (UnbanCommandParser) originalParser; | ||
final boolean isDelete = parser.isDelete(); | ||
|
||
if (isDelete && !sender.hasPermission(getPermission() + ".delete")) { | ||
sender.sendMessage(Message.getString("sender.error.noPermission")); | ||
return true; | ||
} | ||
|
||
if (parser.args.length < 1) { | ||
return false; | ||
} | ||
|
||
// Check if UUID vs name | ||
final String playerName = parser.args[0]; | ||
final boolean isUUID = playerName.length() > 16; | ||
boolean isBanned; | ||
|
||
if (isUUID) { | ||
try { | ||
isBanned = getPlugin().getPlayerBanStorage().isBanned(UUID.fromString(playerName)); | ||
} catch (IllegalArgumentException e) { | ||
sender.sendMessage(Message.get("sender.error.notFound").set("player", playerName).toString()); | ||
return true; | ||
} | ||
} else { | ||
isBanned = getPlugin().getPlayerBanStorage().isBanned(playerName); | ||
} | ||
|
||
if (!isBanned) { | ||
Message message = Message.get("unbanpaid.error.noExists"); | ||
message.set("player", playerName); | ||
|
||
sender.sendMessage(message.toString()); | ||
return true; | ||
} | ||
|
||
final String reason = parser.getReason().getMessage(); | ||
|
||
getPlugin().getScheduler().runAsync(() -> { | ||
PlayerBanData ban; | ||
|
||
if (isUUID) { | ||
ban = getPlugin().getPlayerBanStorage().getBan(UUID.fromString(playerName)); | ||
} else { | ||
ban = getPlugin().getPlayerBanStorage().getBan(playerName); | ||
} | ||
|
||
if (ban == null) { | ||
sender.sendMessage(Message.get("sender.error.notFound").set("player", playerName).toString()); | ||
return; | ||
} | ||
|
||
final PlayerData actor = sender.getData(); | ||
|
||
//TODO refactor if async perm check is problem | ||
if (!actor.getUUID().equals(ban.getActor().getUUID()) && !sender.hasPermission("bm.exempt.override.aban") | ||
&& sender.hasPermission("bm.command.unbanpaid.own")) { | ||
Message.get("unbanpaid.error.notOwn").set("player", ban.getPlayer().getName()).sendTo(sender); | ||
return; | ||
} | ||
|
||
boolean unbanned; | ||
|
||
try { | ||
unbanned = getPlugin().getPlayerBanStorage().unban(ban, actor, reason, isDelete, true); | ||
} catch (SQLException e) { | ||
sender.sendMessage(Message.get("sender.error.exception").toString()); | ||
e.printStackTrace(); | ||
return; | ||
} | ||
|
||
if (!unbanned) { | ||
return; | ||
} | ||
|
||
Message message = Message.get("unbanpaid.notify"); | ||
message | ||
.set("player", ban.getPlayer().getName()) | ||
.set("playerId", ban.getPlayer().getUUID().toString()) | ||
.set("actor", actor.getName()) | ||
.set("id", ban.getId()) | ||
.set("reason", reason); | ||
|
||
if (sender.isTrueNotConsole()) { | ||
sender.sendMessage(message); | ||
} | ||
|
||
if (!sender.hasPermission("bm.notify.unbanpaid") || parser.isSilent()) { | ||
message.sendTo(sender); | ||
} | ||
|
||
if (!parser.isSilent()) { | ||
getPlugin().getServer().broadcast(message.toString(), "bm.notify.unbanpaid"); | ||
} | ||
}); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters