Skip to content

Commit

Permalink
1.21.1, permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCurle committed Feb 7, 2025
1 parent b28bf07 commit d093a43
Show file tree
Hide file tree
Showing 7 changed files with 388 additions and 17 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ group = mod_group_id

repositories {
mavenLocal()
maven {
url "https://cursemaven.com"
content {
includeGroup "curse.maven"
}
}
}

base {
Expand Down Expand Up @@ -134,6 +140,8 @@ dependencies {
// For more info:
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html

implementation "curse.maven:luckperms-431733:${luckperms_version}"
}


Expand Down
8 changes: 5 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ parchment_mappings_version=2024.07.28
## Environment Properties
# You can find the latest versions here: https://projects.neoforged.net/neoforged/neoforge
# The Minecraft version must agree with the Neo version to get a valid artifact
minecraft_version=1.21
minecraft_version=1.21.1
# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.21,1.21.1)
minecraft_version_range=[1.21.1,1.21.4)
# The Neo version must agree with the Minecraft version to get a valid artifact
neo_version=21.0.167
neo_version=21.1.115
# The Neo version range can use any version of Neo as bounds
neo_version_range=[21.0.0-beta,)
# The loader version range can only use the major version of FML as bounds
Expand Down Expand Up @@ -47,3 +47,5 @@ mod_description=A reimplementation of some of the features of the old Essentials
issue_tracker_url=https://github.com/OblivionMC/bare-essentials/issues
update_json_url=https://raw.githubusercontent.com/OblivionMC/bare-essentials/dev/update.json
display_url=https://curseforge.com/minecraft/mc-mods/bare-essentials

luckperms_version=5654227
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ pluginManagement {
mavenLocal()
gradlePluginPortal()
maven { url = 'https://maven.neoforged.net/releases' }

}

}

plugins {
Expand Down
68 changes: 67 additions & 1 deletion src/main/java/uk/gemwire/bareessentials/BareEssentials.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
* Bare Essentials - https://github.com/OblivionMC/bare-essentials/
* Copyright (C) 2022-2023 Curle
* Copyright (C) 2022-2025 Curle
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,6 +23,7 @@
*/
package uk.gemwire.bareessentials;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.GameRules;
import net.neoforged.bus.api.IEventBus;
Expand All @@ -33,15 +34,78 @@
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import net.neoforged.neoforge.event.server.ServerStartedEvent;
import net.neoforged.neoforge.event.tick.ServerTickEvent;
import net.neoforged.neoforge.server.permission.PermissionAPI;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import uk.gemwire.bareessentials.commands.BareCommands;
import uk.gemwire.bareessentials.commands.PermissionNodes;
import uk.gemwire.bareessentials.data.Bank;
import uk.gemwire.bareessentials.data.Homes;


/**
* Provides the following commands
*
* For OP:
* setspawn
* editsign set/clear
* repair
* tp random/all/offline/toggle/here
* bank set/value set
* speed
* move top/up/down/bottom/forward
* editbook title/author/name/text
* more
* sleep
* warp set/remove
* break
* broadcast
* lightning
* invsee ender
* enchant
* fly
* vanish
* pos
* god
* infinite
* item lore/name
* burn
* xp get/set/give
* feed
* heal
* kittycannon
* beezooka
* tempban
* tempbanip
* unbanip
*
*
* For players:
* bank get/value get/top/pay get/offer/toggle/accept/deny
* nick set/get
* whois
* condense
* mail read/clear/send/sendtemp
* home set/get/goto
* warp list/goto
* near
* tp back/deny/accept auto/ask cancel
* seen
* pos
* ping
* afk
* list
* r/reply
* playtime
* spawn
*/

@Mod("bareessentials")
public class BareEssentials {

// Bank is enabled by default, but we'll set it off if we recognize an economy mod loading alongside us *cough* OblivionEconomy
public static GameRules.Key<GameRules.BooleanValue> BANK_ENABLED = GameRules.register("be.bankEnabled", GameRules.Category.PLAYER, GameRules.BooleanValue.create(true));

public static GameRules.Key<GameRules.IntegerValue> CURRENCY_SYMBOL = GameRules.register("be.currencySymbol", GameRules.Category.CHAT, GameRules.IntegerValue.create(0));
public static GameRules.Key<GameRules.IntegerValue> STARTING_BALANCE = GameRules.register("be.bankStartingBalance", GameRules.Category.PLAYER, GameRules.IntegerValue.create(500));
public static GameRules.Key<GameRules.IntegerValue> DAILY_INCOME = GameRules.register("be.bankDailyIncome", GameRules.Category.PLAYER, GameRules.IntegerValue.create(10));
Expand All @@ -59,6 +123,7 @@ public class BareEssentials {
public BareEssentials() {
IEventBus forge = NeoForge.EVENT_BUS;
forge.addListener(BareCommands::registerCommands);
forge.addListener(PermissionNodes::registerPermissions);
}

@EventBusSubscriber(modid = "bareessentials", bus = EventBusSubscriber.Bus.MOD)
Expand All @@ -68,6 +133,7 @@ public static void started(ServerStartedEvent e) {
// Load bank details into the static map.
Bank accts = Bank.getOrCreate(e.getServer().overworld());
LOGGER.info("Loaded " + accts.accounts.size() + " bank accounts.");

Homes homes = Homes.getOrCreate(e.getServer().overworld());
LOGGER.info("Loaded " + homes.homes.size() + " user homes.");
}
Expand Down
37 changes: 28 additions & 9 deletions src/main/java/uk/gemwire/bareessentials/commands/BareCommands.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
* Bare Essentials - https://github.com/OblivionMC/bare-essentials/
* Copyright (C) 2022-2023 Curle
* Copyright (C) 2022-2025 Curle
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -25,31 +25,54 @@

import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.core.BlockPos;
import net.neoforged.neoforge.event.RegisterCommandsEvent;
import net.neoforged.neoforge.server.permission.PermissionAPI;
import net.neoforged.neoforge.server.permission.nodes.PermissionDynamicContext;
import net.neoforged.neoforge.server.permission.nodes.PermissionDynamicContextKey;
import net.neoforged.neoforge.server.permission.nodes.PermissionNode;
import uk.gemwire.bareessentials.invsee.Inventory;

import java.util.Arrays;
import java.util.function.Consumer;
import java.util.function.Predicate;

import static net.minecraft.commands.Commands.LEVEL_ADMINS;
import static net.minecraft.commands.Commands.literal;

public class BareCommands {

private static Predicate<CommandSourceStack> hasPermissionNode(PermissionNode<Boolean>... node) {
return (CommandSourceStack s) -> !s.isPlayer() || Arrays.stream(node).allMatch(p -> PermissionAPI.getPermission(s.getPlayer(), p, null));
}

public static void registerCommands(RegisterCommandsEvent event) {
event.getDispatcher().register(
literal("setspawn")
.requires(s -> s.hasPermission(Commands.LEVEL_ADMINS))
.executes((s) -> CmdSetWorldSpawn.execute(s.getSource(),
BlockPos.containing(s.getSource().getPosition()), 0.0F))
literal("spawn")
.then(Commands.literal("set")
.requires(hasPermissionNode(PermissionNodes.SPAWN_SET))
.executes((s) -> CmdSetWorldSpawn.execute(s.getSource(),
BlockPos.containing(s.getSource().getPosition()), 0.0F))
)
.then(Commands.literal("find")
.requires(hasPermissionNode(PermissionNodes.SPAWN_FIND))
.executes(s -> CmdSpawnFind.execute(s.getSource()))
)
.requires(hasPermissionNode(PermissionNodes.SPAWN_GOTO))
.executes((s) -> CmdSpawn.execute(s.getSource()))
);

event.getDispatcher().register(
literal("tpa")
.then(Commands.argument("user", EntityArgument.player())
.requires(hasPermissionNode(PermissionNodes.TPA))
.executes(CmdTeleportRequest::tpa)
)
.then(Commands.literal("accept")
.requires(hasPermissionNode(PermissionNodes.TPA_ACCEPT))
.executes(CmdTeleportRequest::accept)
)
.then(Commands.literal("deny")
Expand All @@ -64,10 +87,6 @@ public static void registerCommands(RegisterCommandsEvent event) {
)
);

event.getDispatcher().register(
literal("spawn")
.executes((s) -> CmdSpawn.execute(s.getSource()))
);

event.getDispatcher().register(
literal("fly")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
* Bare Essentials - https://github.com/OblivionMC/bare-essentials/
* Copyright (C) 2022-2023 Curle
* Copyright (C) 2022-2025 Curle
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -35,10 +35,9 @@

public class CmdSpawn {

//TODO Check for lava or things that can cause harm
public static int execute(CommandSourceStack player) {
ServerLevel level = player.getServer().getLevel(Level.OVERWORLD);
if (player.getPlayer() != null) {
ServerLevel level = player.getServer().getLevel(Level.OVERWORLD);
if (level == null) {
return 0;
}
Expand All @@ -47,14 +46,15 @@ public static int execute(CommandSourceStack player) {
Bank bk = Bank.getOrCreate(level);

if (cd.isCooldownExpired(player.getPlayer(), "spawn")) {
if (!bk.chargePlayer(player.getPlayer(), level.getGameRules().getInt(BareEssentials.SPAWN_COST)))
if (!bk.playerHasEnough(player.getPlayer(), level.getGameRules().getInt(BareEssentials.SPAWN_COST)))
return 0;
player.sendSystemMessage(Component.translatable(Language.getInstance()
.getOrDefault("bareessentials.spawn.tospawn")));
// Random teleport = cancel if the destination is unsafe
if (!player.getPlayer().randomTeleport(level.getSharedSpawnPos().getX() + 0.5, level.getSharedSpawnPos().getY(), level.getSharedSpawnPos().getZ() + 0.5, false))
player.sendSystemMessage(Component.translatable(Language.getInstance().getOrDefault("bareessentials.teleport.unsafe")));

bk.chargePlayer(player.getPlayer(), level.getGameRules().getInt(BareEssentials.SPAWN_COST));
cd.setCooldownFor(player.getPlayer(), "spawn", level.getGameTime() + player.getLevel().getGameRules().getInt(BareEssentials.SPAWN_COOLDOWN));
} else {
player.sendSystemMessage(Component.translatable(Language.getInstance().getOrDefault("bareessentials.cooldown.active"), cd.getRemainingTimeFor(player.getPlayer(), "spawn")/20));
Expand Down
Loading

0 comments on commit d093a43

Please sign in to comment.