add raid permission

This commit is contained in:
Flemmli97 2020-08-26 20:15:46 +02:00
parent 85e9ff23fd
commit 2a1d65a30d
5 changed files with 40 additions and 4 deletions

View File

@ -2,7 +2,9 @@ package com.flemmli97.flan.claim;
import com.flemmli97.flan.config.ConfigHandler;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.village.raid.Raid;
public enum EnumPermission {
@ -29,6 +31,7 @@ public enum EnumPermission {
PROJECTILES(Items.ARROW),
TRAMPLE(Items.FARMLAND),
PORTAL(Items.OBSIDIAN),
RAID(null),
BOAT(Items.OAK_BOAT),
MINECART(Items.MINECART),
BUCKET(Items.BUCKET),
@ -49,7 +52,9 @@ public enum EnumPermission {
this.item = item;
}
public Item getItem() {
return this.item;
public ItemStack getItem() {
if(this==RAID)
return Raid.getOminousBanner();
return new ItemStack(this.item);
}
}

View File

@ -5,6 +5,7 @@ import com.flemmli97.flan.claim.ClaimStorage;
import com.flemmli97.flan.claim.EnumPermission;
import net.minecraft.block.BlockState;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
@ -60,4 +61,11 @@ public class WorldEvents {
fl = from.equals(to);
return fl;
}
public static boolean canStartRaid(ServerPlayerEntity player){
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(player.getBlockPos());
if(claim!=null && !claim.canInteract(player, EnumPermission.RAID, player.getBlockPos()))
return false;
return true;
}
}

View File

@ -25,7 +25,7 @@ public class ServerScreenHelper {
}
public static ItemStack fromPermission(Claim claim, EnumPermission perm, String group) {
ItemStack stack = new ItemStack(perm.getItem());
ItemStack stack = perm.getItem();
stack.setCustomName(new LiteralText(perm.toString()).setStyle(Style.EMPTY.withFormatting(Formatting.GOLD)));
ListTag lore = new ListTag();
String permFlag;

View File

@ -0,0 +1,22 @@
package com.flemmli97.flan.mixin;
import com.flemmli97.flan.event.WorldEvents;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.village.raid.Raid;
import net.minecraft.village.raid.RaidManager;
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(RaidManager.class)
public class RaidManagerMixin {
@Inject(method = "startRaid", at = @At(value = "HEAD"), cancellable = true)
public void checkRaid(ServerPlayerEntity player, CallbackInfoReturnable<Raid> info){
if(!WorldEvents.canStartRaid(player)){
info.setReturnValue(null);
info.cancel();
}
}
}

View File

@ -19,7 +19,8 @@
"ItemStackMixin",
"ILecternBlockValues",
"FluidMixin",
"PistonMixin"
"PistonMixin",
"RaidManagerMixin"
],
"server": [
],