Skip to content

Commit

Permalink
move permissions to one class
Browse files Browse the repository at this point in the history
  • Loading branch information
BasiqueEvangelist committed Aug 6, 2024
1 parent 590e746 commit a40dcda
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
import me.basiqueevangelist.onedatastore.api.DataStore;
import me.basiqueevangelist.onedatastore.impl.OneDataStoreInit;
import me.basiqueevangelist.onedatastore.impl.OneDataStoreState;
import me.lucko.fabric.api.permissions.v0.Permissions;
import me.basiqueevangelist.pingspam.logic.PingspamPermissions;
import net.minecraft.command.CommandSource;
import net.minecraft.command.argument.GameProfileArgumentType;
import net.minecraft.command.argument.IdentifierArgumentType;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
Expand All @@ -39,7 +38,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(
literal("onedatastore")
.then(literal("purge")
.requires(Permissions.require("onedatastore.purge", 4))
.requires(PingspamPermissions::purge)
.then(literal("player")
.then(argument("target", GameProfileArgumentType.gameProfile())
.executes(PurgeCommand::purgePlayer)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import me.basiqueevangelist.onedatastore.api.DataStore;
import me.basiqueevangelist.pingspam.PingSpam;
import me.basiqueevangelist.pingspam.data.PingspamPlayerData;
import me.basiqueevangelist.pingspam.logic.PingspamPermissions;
import me.basiqueevangelist.pingspam.network.ServerNetworkLogic;
import me.basiqueevangelist.pingspam.utils.CommandUtil;
import me.basiqueevangelist.pingspam.logic.NameLogic;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.argument.GameProfileArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -48,11 +48,11 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
.then(literal("list")
.executes(AliasCommand::listAliases))
.then(literal("add")
.requires(x -> Permissions.check(x, "pingspam.alias.own.add", true))
.requires(PingspamPermissions::addOwnAlias)
.then(argument("alias", StringArgumentType.string())
.executes(AliasCommand::addAliases)))
.then(literal("remove")
.requires(x -> Permissions.check(x, "pingspam.alias.own.remove", true))
.requires(PingspamPermissions::removeOwnAlias)
.then(argument("alias", StringArgumentType.string())
.executes(AliasCommand::removeAlias)
.suggests(AliasCommand::suggestOwnAliases)))
Expand All @@ -62,11 +62,11 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
.then(literal("list")
.executes(AliasCommand::listPlayerAliases))
.then(literal("add")
.requires(x -> Permissions.check(x, "pingspam.alias.player.add", 2))
.requires(PingspamPermissions::addPlayerAlias)
.then(argument("alias", StringArgumentType.string())
.executes(AliasCommand::addPlayerAlias)))
.then(literal("remove")
.requires(x -> Permissions.check(x, "pingspam.alias.player.remove", 2))
.requires(PingspamPermissions::removePlayerAlias)
.then(argument("alias", StringArgumentType.string())
.executes(AliasCommand::removePlayerAlias)
.suggests(AliasCommand::suggestPlayerAliases))))))
Expand Down Expand Up @@ -142,7 +142,7 @@ private static int addPlayerAlias(CommandContext<ServerCommandSource> ctx) throw
if (NameLogic.isValidName(src.getServer(), newAlias, false))
throw ALIAS_COLLISION.create();

if (data.aliases().size() >= ALIAS_LIMIT && !Permissions.check(src, "pingspam.bypass.aliaslimit", 2))
if (data.aliases().size() >= ALIAS_LIMIT && !PingspamPermissions.bypassAliasLimit(src))
throw TOO_MANY_ALIASES.create();

data.aliases().add(newAlias);
Expand Down Expand Up @@ -243,7 +243,7 @@ private static int addAliases(CommandContext<ServerCommandSource> ctx) throws Co
if (NameLogic.isValidName(src.getServer(), newAlias, false))
throw ALIAS_COLLISION.create();

if (data.aliases().size() >= ALIAS_LIMIT && !Permissions.check(src, "pingspam.bypass.aliaslimit", 2))
if (data.aliases().size() >= ALIAS_LIMIT && !PingspamPermissions.bypassAliasLimit(src))
throw TOO_MANY_ALIASES.create();

data.aliases().add(newAlias);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import me.basiqueevangelist.onedatastore.api.DataStore;
import me.basiqueevangelist.pingspam.PingSpam;
import me.basiqueevangelist.pingspam.data.PingspamPlayerData;
import me.basiqueevangelist.pingspam.logic.PingspamPermissions;
import me.basiqueevangelist.pingspam.network.ServerNetworkLogic;
import me.basiqueevangelist.pingspam.utils.CommandUtil;
import me.basiqueevangelist.pingspam.logic.NameLogic;
import me.basiqueevangelist.pingspam.utils.NameUtil;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.argument.GameProfileArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -50,21 +50,21 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
.then(literal("list")
.executes(GroupCommand::listPlayersInGroup))
.then(literal("add")
.requires(Permissions.require("pingspam.group.player.add", 2))
.requires(PingspamPermissions::addGroupPlayer)
.then(argument("player", GameProfileArgumentType.gameProfile())
.suggests(CommandUtil::suggestPlayers)
.executes(GroupCommand::addPlayerToGroup)))
.then(literal("remove")
.requires(Permissions.require("pingspam.group.player.add", 2))
.requires(PingspamPermissions::addGroupPlayer)
.then(argument("player", GameProfileArgumentType.gameProfile())
.suggests(CommandUtil::suggestPlayers)
.executes(GroupCommand::removePlayerFromGroup)))
.then(literal("pingable")
.requires(Permissions.require("pingspam.group.configure", 2))
.requires(PingspamPermissions::configureGroup)
.then(argument("value", BoolArgumentType.bool())
.executes(GroupCommand::configurePingable)))
.then(literal("haschat")
.requires(Permissions.require("pingspam.group.configure", 2))
.requires(PingspamPermissions::configureGroup)
.then(argument("value", BoolArgumentType.bool())
.executes(GroupCommand::configureGroupChat)))
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.mojang.brigadier.CommandDispatcher;
import me.basiqueevangelist.pingspam.PingSpam;
import me.basiqueevangelist.pingspam.commands.mail.*;
import me.lucko.fabric.api.permissions.v0.Permissions;
import me.basiqueevangelist.pingspam.logic.PingspamPermissions;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
Expand All @@ -27,7 +27,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher, C
dispatcher.register(
literal("pingspam")
.then(literal("reload")
.requires(x -> Permissions.check(x, "pingspam.reload", 2))
.requires(PingspamPermissions::reload)
.executes(ctx -> {
PingSpam.CONFIG.load();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import me.basiqueevangelist.onedatastore.api.DataStore;
import me.basiqueevangelist.pingspam.PingSpam;
import me.basiqueevangelist.pingspam.data.PechkinPlayerData;
import me.basiqueevangelist.pingspam.logic.PingspamPermissions;
import me.basiqueevangelist.pingspam.utils.CommandUtil;
import me.basiqueevangelist.pingspam.utils.NameUtil;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.argument.GameProfileArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -29,7 +29,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
.then(literal("clear")
.executes(ClearCommand::clear)
.then(argument("player", GameProfileArgumentType.gameProfile())
.requires(Permissions.require("pechkin.clear.other", 2))
.requires(PingspamPermissions::clearOtherMail)
.suggests(CommandUtil::suggestPlayersExceptSelf)
.executes(ClearCommand::clearOther))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import me.basiqueevangelist.pingspam.PingSpam;
import me.basiqueevangelist.pingspam.data.PechkinPlayerData;
import me.basiqueevangelist.pingspam.hack.StateTracker;
import me.basiqueevangelist.pingspam.logic.PingspamPermissions;
import me.basiqueevangelist.pingspam.utils.CommandUtil;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.argument.GameProfileArgumentType;
import net.minecraft.command.argument.UuidArgumentType;
import net.minecraft.server.command.ServerCommandSource;
Expand All @@ -37,8 +37,8 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
.then(argument("message", UuidArgumentType.uuid())
.executes(DeleteCommand::deleteList)))
.then(literal("delete_list_other")
.requires(Permissions.require("pechkin.list.other", 2))
.requires(Permissions.require("pechkin.delete.other", 2))
.requires(PingspamPermissions::listOtherMail)
.requires(PingspamPermissions::deleteOtherMail)
.then(argument("player", GameProfileArgumentType.gameProfile())
.then(argument("message", UuidArgumentType.uuid())
.executes(DeleteCommand::deleteListOther))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import me.basiqueevangelist.pingspam.PingSpam;
import me.basiqueevangelist.pingspam.data.MailMessage;
import me.basiqueevangelist.pingspam.data.PechkinPlayerData;
import me.basiqueevangelist.pingspam.logic.PingspamPermissions;
import me.basiqueevangelist.pingspam.utils.TimeUtils;
import me.basiqueevangelist.pingspam.utils.CommandUtil;
import me.basiqueevangelist.pingspam.utils.NameUtil;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.argument.GameProfileArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -32,7 +32,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
.executes(ListCommand::list)
.then(argument("player", GameProfileArgumentType.gameProfile())
.suggests(CommandUtil::suggestPlayersExceptSelf)
.requires(Permissions.require("pechkin.list.other", 2))
.requires(PingspamPermissions::listOtherMail)
.executes(ListCommand::listOther)))
.executes(ListCommand::list));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import me.basiqueevangelist.pingspam.data.PechkinPlayerData;
import me.basiqueevangelist.pingspam.logic.IgnoreLogic;
import me.basiqueevangelist.pingspam.logic.MailLogic;
import me.basiqueevangelist.pingspam.logic.PingspamPermissions;
import me.basiqueevangelist.pingspam.utils.CommandUtil;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.argument.GameProfileArgumentType;
import net.minecraft.command.argument.MessageArgumentType;
import net.minecraft.server.command.ServerCommandSource;
Expand Down Expand Up @@ -40,12 +40,12 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
.then(argument("player", GameProfileArgumentType.gameProfile())
.suggests(CommandUtil::suggestPlayers)
.then(argument("message", MessageArgumentType.message())
.requires(Permissions.require("pechkin.send", true))
.requires(PingspamPermissions::sendMail)
.executes(SendCommand::send)))));

dispatcher.register(literal("r")
.then(argument("message", MessageArgumentType.message())
.requires(Permissions.require("pechkin.send", true))
.requires(PingspamPermissions::sendMail)
.executes(SendCommand::reply)));
}

Expand Down Expand Up @@ -82,7 +82,7 @@ private static void sendMessage(ServerCommandSource src, ServerPlayerEntity send

IgnoreLogic.throwIfIgnored(sender, recipientId);

if (!Permissions.check(sender, "pechkin.bypass.cooldown", 2)) {
if (!PingspamPermissions.bypassCooldown(sender)) {
int sendCost = PingSpam.CONFIG.getConfig().mail.sendCost;

if (!senderData.leakyBucket().hasEnoughFor(sendCost))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import me.basiqueevangelist.onedatastore.api.DataStore;
import me.basiqueevangelist.pingspam.PingSpam;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

Expand All @@ -18,7 +17,7 @@ private IgnoreLogic() {
}

public static boolean isIgnored(ServerPlayerEntity player, UUID by) {
if (Permissions.check(player, "pingspam.bypass.ignore", 2)) return false;
if (PingspamPermissions.bypassIgnore(player)) return false;

return DataStore.getFor(player.server).getPlayer(by, PingSpam.PLAYER_DATA).ignoredPlayers().contains(player.getUuid());
}
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/me/basiqueevangelist/pingspam/logic/PingLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import me.basiqueevangelist.pingspam.data.PingspamPlayerData;
import me.basiqueevangelist.pingspam.utils.NameUtil;
import me.basiqueevangelist.pingspam.utils.PlayerUtils;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory;
Expand Down Expand Up @@ -60,7 +59,7 @@ public static ProcessedPing processPings(MinecraftServer server, Text messageCon
private static void processMention(ProcessedPing result, String mention, Text message) {
switch (mention) {
case "everyone":
if (result.sender == null || Permissions.check(result.sender, "pingspam.ping.everyone", 2)) {
if (result.sender == null || PingspamPermissions.pingEveryone(result.sender)) {
for (UUID playerId : PlayerUtils.getAllPlayers(result.server)) {
pingPlayer(result, playerId, message);
}
Expand All @@ -70,7 +69,7 @@ private static void processMention(ProcessedPing result, String mention, Text me
}
break;
case "online":
if (result.sender == null || Permissions.check(result.sender, "pingspam.ping.online", 2)) {
if (result.sender == null || PingspamPermissions.pingOnline(result.sender)) {
for (ServerPlayerEntity player : result.server.getPlayerManager().getPlayerList()) {
pingPlayer(result, player.getUuid(), message);
}
Expand All @@ -80,7 +79,7 @@ private static void processMention(ProcessedPing result, String mention, Text me
}
break;
case "offline":
if (result.sender == null || Permissions.check(result.sender, "pingspam.ping.offline", 2)) {
if (result.sender == null || PingspamPermissions.pingOffline(result.sender)) {
for (PlayerDataEntry entry : DataStore.getFor(result.server).players()) {
if (result.server.getPlayerManager().getPlayer(entry.playerId()) != null) continue;

Expand All @@ -94,7 +93,7 @@ private static void processMention(ProcessedPing result, String mention, Text me
default:
PingspamGroupData pingGroup = DataStore.getFor(result.server).get(PingSpam.GLOBAL_DATA).groups().get(mention);
if (pingGroup != null && pingGroup.isPingable()) {
if (result.sender == null || Permissions.check(result.sender, "pingspam.ping.group", true)) {
if (result.sender == null || PingspamPermissions.pingGroup(result.sender)) {
for (UUID playerId : pingGroup.members()) {
pingPlayer(result, playerId, message);
}
Expand Down Expand Up @@ -122,14 +121,14 @@ private static void processMention(ProcessedPing result, String mention, Text me

PingspamPlayerData foundData = DataStore.getFor(result.server).getPlayer(foundPlayerId, PingSpam.PLAYER_DATA);

if (result.sender != null && !Permissions.check(result.sender, "pingspam.bypass.ignore", 2)) {
if (result.sender != null && !PingspamPermissions.bypassIgnore(result.sender)) {
if (foundData.ignoredPlayers().contains(result.sender.getUuid())) {
PingLogic.sendPingError(result.sender, NameUtil.getNameFromUUID(foundPlayerId) + " has ignored you, they won't receive your ping.");
break;
}
}

if (result.sender != null && !Permissions.check(result.sender, "pingspam.ping.player", true)) {
if (result.sender != null && !PingspamPermissions.pingPlayer(result.sender)) {
PingLogic.sendPingError(result.sender, "You do not have enough permissions to ping @" + mention + "!");
return;
}
Expand Down
Loading

0 comments on commit a40dcda

Please sign in to comment.