add fire spread protection and changed some permission to always be global

This commit is contained in:
Flemmli97 2020-09-01 22:59:12 +02:00
parent 045f42cafc
commit fdab079aed
8 changed files with 97 additions and 12 deletions

View File

@ -160,7 +160,7 @@ public class Claim {
} }
public boolean canInteract(ServerPlayerEntity player, EnumPermission perm, BlockPos pos, boolean message) { public boolean canInteract(ServerPlayerEntity player, EnumPermission perm, BlockPos pos, boolean message) {
if (perm == EnumPermission.EXPLOSIONS || perm == EnumPermission.WITHER) { if (perm.isAlwaysGlobalPerm()) {
for (Claim claim : this.subClaims) { for (Claim claim : this.subClaims) {
if (claim.insideClaim(pos)) { if (claim.insideClaim(pos)) {
return claim.canInteract(player, perm, pos, message); return claim.canInteract(player, perm, pos, message);

View File

@ -30,6 +30,7 @@ import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -260,11 +261,27 @@ public class ClaimStorage {
Map<File, List<File>> subClaimMap = Maps.newHashMap(); Map<File, List<File>> subClaimMap = Maps.newHashMap();
Map<Integer, File> intFileMap = Maps.newHashMap(); Map<Integer, File> intFileMap = Maps.newHashMap();
EnumSet<EnumPermission> managers = EnumSet.complementOf(EnumSet.of(EnumPermission.EDITCLAIM));
EnumSet<EnumPermission> builders = EnumSet.complementOf(EnumSet.of(EnumPermission.EDITPERMS, EnumPermission.EDITCLAIM));
EnumSet<EnumPermission> containers = EnumSet.complementOf(EnumSet.of(EnumPermission.EDITPERMS, EnumPermission.EDITCLAIM,
EnumPermission.BREAK, EnumPermission.PLACE, EnumPermission.NOTEBLOCK, EnumPermission.REDSTONE, EnumPermission.JUKEBOX,
EnumPermission.ITEMFRAMEROTATE, EnumPermission.LECTERNTAKE, EnumPermission.ENDCRYSTALPLACE, EnumPermission.PROJECTILES,
EnumPermission.TRAMPLE, EnumPermission.RAID, EnumPermission.BUCKET, EnumPermission.ARMORSTAND, EnumPermission.BREAKNONLIVING));
EnumSet<EnumPermission> accessors = EnumSet.complementOf(EnumSet.of(EnumPermission.EDITPERMS, EnumPermission.EDITCLAIM,
EnumPermission.BREAK, EnumPermission.PLACE, EnumPermission.OPENCONTAINER, EnumPermission.ANVIL, EnumPermission.BEACON,
EnumPermission.NOTEBLOCK, EnumPermission.REDSTONE, EnumPermission.JUKEBOX, EnumPermission.ITEMFRAMEROTATE,
EnumPermission.LECTERNTAKE, EnumPermission.ENDCRYSTALPLACE, EnumPermission.PROJECTILES, EnumPermission.TRAMPLE, EnumPermission.RAID,
EnumPermission.BUCKET, EnumPermission.ANIMALINTERACT, EnumPermission.HURTANIMAL, EnumPermission.TRADING, EnumPermission.ARMORSTAND,
EnumPermission.BREAKNONLIVING));
System.out.println(managers);
System.out.println(builders);
System.out.println(containers);
System.out.println(accessors);
try { try {
//Get all parent claims //Get all parent claims
Set<String> failedClaimsFile = Sets.newHashSet(); Set<String> failedClaimsFile = Sets.newHashSet();
for (File f : griefPrevention.listFiles()) { for (File f : griefPrevention.listFiles()) {
System.out.println("f " + f.getName());
if (f.getName().endsWith(".yml")) { if (f.getName().endsWith(".yml")) {
FileReader reader = new FileReader(f); FileReader reader = new FileReader(f);
Map<String, Object> values = yml.load(reader); Map<String, Object> values = yml.load(reader);
@ -278,8 +295,6 @@ public class ClaimStorage {
} }
} }
} }
System.out.println(subClaimMap);
System.out.println(intFileMap);
//Map child to parent claims //Map child to parent claims
for (File f : griefPrevention.listFiles()) { for (File f : griefPrevention.listFiles()) {
if (f.getName().endsWith(".yml")) { if (f.getName().endsWith(".yml")) {

View File

@ -6,6 +6,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.village.raid.Raid; import net.minecraft.village.raid.Raid;
import java.util.EnumSet;
public enum EnumPermission { public enum EnumPermission {
EDITCLAIM(ConfigHandler.config.claimingItem), EDITCLAIM(ConfigHandler.config.claimingItem),
@ -38,16 +40,19 @@ public enum EnumPermission {
ENDERPEARL(Items.ENDER_PEARL), ENDERPEARL(Items.ENDER_PEARL),
ANIMALINTERACT(Items.CHICKEN_SPAWN_EGG), ANIMALINTERACT(Items.CHICKEN_SPAWN_EGG),
HURTANIMAL(Items.BEEF), HURTANIMAL(Items.BEEF),
HURTPLAYER(Items.DIAMOND_SWORD),
XP(Items.EXPERIENCE_BOTTLE), XP(Items.EXPERIENCE_BOTTLE),
TRADING(Items.EMERALD), TRADING(Items.EMERALD),
ARMORSTAND(Items.ARMOR_STAND),
BREAKNONLIVING(Items.COMMAND_BLOCK_MINECART),
HURTPLAYER(Items.DIAMOND_SWORD),
EXPLOSIONS(Items.TNT), EXPLOSIONS(Items.TNT),
WITHER(Items.WITHER_SKELETON_SKULL), WITHER(Items.WITHER_SKELETON_SKULL),
ARMORSTAND(Items.ARMOR_STAND), FIRESPREAD(Items.BLAZE_POWDER);
BREAKNONLIVING(Items.COMMAND_BLOCK_MINECART);
private final Item item; private final Item item;
private static final EnumSet<EnumPermission> alwaysGlobal = EnumSet.of(HURTPLAYER, EXPLOSIONS, WITHER, FIRESPREAD);
EnumPermission(Item item) { EnumPermission(Item item) {
this.item = item; this.item = item;
} }
@ -57,4 +62,12 @@ public enum EnumPermission {
return Raid.getOminousBanner(); return Raid.getOminousBanner();
return new ItemStack(this.item); return new ItemStack(this.item);
} }
public boolean isAlwaysGlobalPerm(){
return alwaysGlobal.contains(this);
}
public static int alwaysGlobalLength(){
return alwaysGlobal.size();
}
} }

View File

@ -86,9 +86,9 @@ public class CommandClaim {
))); )));
} }
private static LiteralArgumentBuilder<ServerCommandSource> addToMainCommand(LiteralArgumentBuilder<ServerCommandSource> main, ArgumentBuilder... other) { private static <S, T extends ArgumentBuilder<S,T>> T addToMainCommand(T main, ArgumentBuilder<S,T>... other) {
if (other != null) if (other != null)
for (ArgumentBuilder o : other) for (ArgumentBuilder<S,T> o : other)
main.then(o); main.then(o);
return main; return main;
} }

View File

@ -68,4 +68,11 @@ public class WorldEvents {
return false; return false;
return true; return true;
} }
public static boolean canFireSpread(ServerWorld world, BlockPos pos){
Claim claim = ClaimStorage.get(world).getClaimAt(pos);
if(claim!=null && !claim.canInteract(null, EnumPermission.FIRESPREAD, pos))
return false;
return true;
}
} }

View File

@ -82,7 +82,10 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
else { else {
int row = i / 9 - 1; int row = i / 9 - 1;
int id = (i % 9) + row * 7 - 1 + page * 28; int id = (i % 9) + row * 7 - 1 + page * 28;
if (id < EnumPermission.values().length) int length = EnumPermission.values().length;
if(group!=null)
length-=EnumPermission.alwaysGlobalLength();
if (id < length)
inv.setStack(i, ServerScreenHelper.fromPermission((Claim) additionalData[0], EnumPermission.values()[id], additionalData[1] == null ? null : additionalData[1].toString())); inv.setStack(i, ServerScreenHelper.fromPermission((Claim) additionalData[0], EnumPermission.values()[id], additionalData[1] == null ? null : additionalData[1].toString()));
} }
} }
@ -113,8 +116,12 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
else { else {
int row = i / 9 - 1; int row = i / 9 - 1;
int id = (i % 9) + row * 7 - 1 + this.page * 28; int id = (i % 9) + row * 7 - 1 + this.page * 28;
if (id < EnumPermission.values().length) int length = EnumPermission.values().length;
if(group!=null)
length-=EnumPermission.alwaysGlobalLength();
if (id < length) {
this.slots.get(i).setStack(ServerScreenHelper.fromPermission(this.claim, EnumPermission.values()[id], this.group)); this.slots.get(i).setStack(ServerScreenHelper.fromPermission(this.claim, EnumPermission.values()[id], this.group));
}
else else
this.slots.get(i).setStack(ItemStack.EMPTY); this.slots.get(i).setStack(ItemStack.EMPTY);
} }

View File

@ -0,0 +1,42 @@
package com.flemmli97.flan.mixin;
import com.flemmli97.flan.event.WorldEvents;
import net.minecraft.block.BlockState;
import net.minecraft.block.FireBlock;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldView;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Random;
@Mixin(FireBlock.class)
public abstract class FireBlockMixin {
@Inject(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getGameRules()Lnet/minecraft/world/GameRules;"), cancellable = true)
public void tick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo info) {
if (!WorldEvents.canFireSpread(world, pos)) {
info.cancel();
}
}
@Inject(method = "getBurnChance(Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;)I", at = @At(value = "HEAD"), cancellable = true)
public void burn(WorldView worldView, BlockPos pos, CallbackInfoReturnable<Integer> info){
if(worldView instanceof ServerWorld && !WorldEvents.canFireSpread((ServerWorld) worldView, pos)){
info.setReturnValue(0);
info.cancel();
}
}
@Inject(method = "trySpreadingFire", at = @At(value = "HEAD"), cancellable = true)
public void spread(World world, BlockPos pos, int spreadFactor, Random rand, int currentAge, CallbackInfo info){
if(!world.isClient && !WorldEvents.canFireSpread((ServerWorld) world, pos)){
info.cancel();
}
}
}

View File

@ -20,7 +20,8 @@
"ILecternBlockValues", "ILecternBlockValues",
"FluidMixin", "FluidMixin",
"PistonMixin", "PistonMixin",
"RaidManagerMixin" "RaidManagerMixin",
"FireBlockMixin"
], ],
"server": [ "server": [
], ],