add toggable mob spawning for claims close #18
This commit is contained in:
parent
0cbb5a576a
commit
2cce314d8e
@ -64,6 +64,7 @@ public class PermissionRegistry {
|
||||
public static ClaimPermission EXPLOSIONS = global(new ClaimPermission("EXPLOSIONS", () -> new ItemStack(Items.TNT), "Toggle explosions in claim"));
|
||||
public static ClaimPermission WITHER = global(new ClaimPermission("WITHER", () -> new ItemStack(Items.WITHER_SKELETON_SKULL), "Toggle wither breaking blocks in claim"));
|
||||
public static ClaimPermission FIRESPREAD = global(new ClaimPermission("FIRESPREAD", () -> new ItemStack(Items.BLAZE_POWDER), "Toggle firespread in claim"));
|
||||
public static ClaimPermission MOBSPAWN = global(new ClaimPermission("MOBSPAWN", () -> new ItemStack(Items.ZOMBIE_SPAWN_EGG), "Prevent mobspawn in claim"));
|
||||
|
||||
private static ClaimPermission register(ClaimPermission perm) {
|
||||
if (locked) {
|
||||
|
@ -1,14 +1,13 @@
|
||||
package com.flemmli97.flan.claim;
|
||||
|
||||
import com.flemmli97.flan.api.ClaimPermission;
|
||||
import com.flemmli97.flan.api.PermissionRegistry;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class GlobalClaim implements IPermissionContainer {
|
||||
|
||||
private final ServerWorld world;
|
||||
@ -27,6 +26,8 @@ public class GlobalClaim implements IPermissionContainer {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
||||
return false;
|
||||
}
|
||||
if (perm == PermissionRegistry.MOBSPAWN)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -406,10 +406,10 @@ public class CommandClaim {
|
||||
if (claim != null && claim.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos())) {
|
||||
list = claim.groups();
|
||||
}
|
||||
for(int i = 0; i < list.size(); i++){
|
||||
if(allowed.matcher(list.get(i)).matches())
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (allowed.matcher(list.get(i)).matches())
|
||||
continue;
|
||||
list.set(i, '\"'+list.get(i)+'\"');
|
||||
list.set(i, '\"' + list.get(i) + '\"');
|
||||
}
|
||||
return CommandSource.suggestMatching(list, build);
|
||||
}
|
||||
|
@ -146,8 +146,8 @@ public class Config {
|
||||
return getGlobal(world, perm) != null;
|
||||
}
|
||||
|
||||
public Boolean getGlobal(ServerWorld world, ClaimPermission perm){
|
||||
if(perm == PermissionRegistry.MOBSPAWN && !this.allowMobSpawnToggle)
|
||||
public Boolean getGlobal(ServerWorld world, ClaimPermission perm) {
|
||||
if (perm == PermissionRegistry.MOBSPAWN && !this.allowMobSpawnToggle)
|
||||
return Boolean.FALSE;
|
||||
Map<ClaimPermission, Boolean> permMap = ConfigHandler.config.globalDefaultPerms.get(world.getRegistryKey().getValue().toString());
|
||||
return permMap == null ? null : permMap.getOrDefault(perm, null);
|
||||
|
@ -3,8 +3,10 @@ package com.flemmli97.flan.event;
|
||||
import com.flemmli97.flan.api.PermissionRegistry;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.IPermissionContainer;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.piston.PistonBehavior;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@ -64,11 +66,18 @@ public class WorldEvents {
|
||||
|
||||
public static boolean canStartRaid(ServerPlayerEntity player) {
|
||||
IPermissionContainer claim = ClaimStorage.get(player.getServerWorld()).getForPermissionCheck(player.getBlockPos());
|
||||
return claim == null || claim.canInteract(player, PermissionRegistry.RAID, player.getBlockPos());
|
||||
return claim.canInteract(player, PermissionRegistry.RAID, player.getBlockPos());
|
||||
}
|
||||
|
||||
public static boolean canFireSpread(ServerWorld world, BlockPos pos) {
|
||||
IPermissionContainer claim = ClaimStorage.get(world).getForPermissionCheck(pos);
|
||||
return claim == null || claim.canInteract(null, PermissionRegistry.FIRESPREAD, pos);
|
||||
return claim.canInteract(null, PermissionRegistry.FIRESPREAD, pos);
|
||||
}
|
||||
|
||||
public static boolean preventMobSpawn(ServerWorld world, MobEntity entity) {
|
||||
if (!ConfigHandler.config.allowMobSpawnToggle)
|
||||
return false;
|
||||
IPermissionContainer claim = ClaimStorage.get(world).getForPermissionCheck(entity.getBlockPos());
|
||||
return claim.canInteract(null, PermissionRegistry.MOBSPAWN, entity.getBlockPos());
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,6 @@ import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ServerScreenHelper {
|
||||
|
||||
public static ItemStack emptyFiller() {
|
||||
|
22
src/main/java/com/flemmli97/flan/mixin/SpawnHelperMixin.java
Normal file
22
src/main/java/com/flemmli97/flan/mixin/SpawnHelperMixin.java
Normal file
@ -0,0 +1,22 @@
|
||||
package com.flemmli97.flan.mixin;
|
||||
|
||||
import com.flemmli97.flan.event.WorldEvents;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.world.SpawnHelper;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(SpawnHelper.class)
|
||||
public class SpawnHelperMixin {
|
||||
|
||||
@Inject(method = "isValidSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/mob/MobEntity;canSpawn(Lnet/minecraft/world/WorldAccess;Lnet/minecraft/entity/SpawnReason;)Z"), cancellable = true)
|
||||
private static void isValidSpawn(ServerWorld world, MobEntity entity, double squaredDistance, CallbackInfoReturnable<Boolean> info) {
|
||||
if (WorldEvents.preventMobSpawn(world, entity)) {
|
||||
info.setReturnValue(false);
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
}
|
@ -21,7 +21,8 @@
|
||||
"FluidMixin",
|
||||
"PistonMixin",
|
||||
"RaidManagerMixin",
|
||||
"FireBlockMixin"
|
||||
"FireBlockMixin",
|
||||
"SpawnHelperMixin"
|
||||
],
|
||||
"server": [
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user