add nohunger permission
This commit is contained in:
parent
1263d1adc7
commit
f099028c88
@ -69,6 +69,7 @@ public class PermissionRegistry {
|
||||
public static ClaimPermission FLIGHT = register(new ClaimPermission("FLIGHT", () -> new ItemStack(Items.FEATHER), true, "Allow non creative flight"));
|
||||
public static ClaimPermission CANSTAY = register(new ClaimPermission("CANSTAY", () -> new ItemStack(Items.PAPER), true, "Allow player to enter your claim"));
|
||||
public static ClaimPermission TELEPORT = register(new ClaimPermission("TELEPORT", () -> new ItemStack(Items.END_PORTAL_FRAME), false, "Allow player to teleport to your claim home position"));
|
||||
public static ClaimPermission NOHUNGER = register(new ClaimPermission("NOHUNGER", () -> new ItemStack(Items.COOKED_BEEF), false, "Disable hunger"));
|
||||
|
||||
public static ClaimPermission HURTPLAYER = global(new ClaimPermission("HURTPLAYER", () -> new ItemStack(Items.DIAMOND_SWORD), "Permission to hurt other players"));
|
||||
public static ClaimPermission EXPLOSIONS = global(new ClaimPermission("EXPLOSIONS", () -> new ItemStack(Items.TNT), "Toggle explosions in claim"));
|
||||
|
@ -12,6 +12,7 @@ import io.github.flemmli97.flan.api.PermissionRegistry;
|
||||
import io.github.flemmli97.flan.config.Config;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
@ -19,6 +20,7 @@ import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.chunk.ChunkStatus;
|
||||
|
||||
@ -58,6 +60,8 @@ public class Claim implements IPermissionContainer {
|
||||
|
||||
private final ServerWorld world;
|
||||
|
||||
private Map<StatusEffect, Integer> potions = new HashMap<>();
|
||||
|
||||
private Claim(ServerWorld world) {
|
||||
this.world = world;
|
||||
}
|
||||
@ -192,6 +196,10 @@ public class Claim implements IPermissionContainer {
|
||||
return this.minX <= other.maxX && this.maxX >= other.minX && this.minZ <= other.maxZ && this.maxZ >= other.minZ;
|
||||
}
|
||||
|
||||
public boolean intersects(Box box) {
|
||||
return this.minX <= box.maxX && this.maxX >= box.minX && this.minZ <= box.maxZ && this.maxZ >= box.minZ && box.maxY > this.minY;
|
||||
}
|
||||
|
||||
public boolean isCorner(BlockPos pos) {
|
||||
return (pos.getX() == this.minX && pos.getZ() == this.minZ) || (pos.getX() == this.minX && pos.getZ() == this.maxZ)
|
||||
|| (pos.getX() == this.maxX && pos.getZ() == this.minZ) || (pos.getX() == this.maxX && pos.getZ() == this.maxZ);
|
||||
@ -456,6 +464,7 @@ public class Claim implements IPermissionContainer {
|
||||
public boolean setHomePos(BlockPos homePos) {
|
||||
if (this.insideClaim(homePos)) {
|
||||
this.homePos = homePos;
|
||||
this.setDirty(true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -81,6 +81,7 @@ public class Config {
|
||||
perms.put(PermissionRegistry.FLIGHT, GlobalType.ALLTRUE);
|
||||
perms.put(PermissionRegistry.MOBSPAWN, GlobalType.ALLFALSE);
|
||||
perms.put(PermissionRegistry.TELEPORT, GlobalType.ALLFALSE);
|
||||
perms.put(PermissionRegistry.NOHUNGER, GlobalType.ALLFALSE);
|
||||
})));
|
||||
|
||||
public Config(MinecraftServer server) {
|
||||
|
@ -7,6 +7,7 @@ import io.github.flemmli97.flan.claim.ClaimStorage;
|
||||
import io.github.flemmli97.flan.claim.IPermissionContainer;
|
||||
import io.github.flemmli97.flan.claim.ObjectToPermissionMap;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.mixin.IHungerAccessor;
|
||||
import io.github.flemmli97.flan.mixin.IPersistentProjectileVars;
|
||||
import io.github.flemmli97.flan.player.IOwnedItem;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
@ -309,7 +310,7 @@ public class EntityInteractEvents {
|
||||
BlockPos rounded = TeleportUtils.roundedBlockPos(pos.add(0, player.getActiveEyeHeight(player.getPose(), player.getDimensions(player.getPose())), 0));
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
if (currentClaim != null) {
|
||||
if (!currentClaim.insideClaim(rounded)) {
|
||||
if (!currentClaim.intersects(player.getBoundingBox())) {
|
||||
cons.accept(null);
|
||||
} else {
|
||||
if (!player.isSpectator()) {
|
||||
@ -322,6 +323,9 @@ public class EntityInteractEvents {
|
||||
player.abilities.flying = false;
|
||||
player.networkHandler.sendPacket(new PlayerAbilitiesS2CPacket(player.abilities));
|
||||
}
|
||||
if (player.getHungerManager().getSaturationLevel() < 2 && currentClaim.canInteract(player, PermissionRegistry.NOHUNGER, bPos, false)) {
|
||||
((IHungerAccessor) player.getHungerManager()).setSaturation(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (player.age % 3 == 0) {
|
||||
|
@ -0,0 +1,12 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import net.minecraft.entity.player.HungerManager;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(HungerManager.class)
|
||||
public interface IHungerAccessor {
|
||||
|
||||
@Accessor("foodSaturationLevel")
|
||||
void setSaturation(float saturation);
|
||||
}
|
@ -19,7 +19,8 @@
|
||||
"ItemEntityMixin",
|
||||
"EndermanPickupMixin",
|
||||
"EndermanPlaceMixin",
|
||||
"IItemAccessor"
|
||||
"IItemAccessor",
|
||||
"IHungerAccessor"
|
||||
],
|
||||
"server": [
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user