port to 1.18
This commit is contained in:
parent
0f895b7f56
commit
a8d1737e53
17
build.gradle
17
build.gradle
@ -5,8 +5,8 @@ buildscript {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "architectury-plugin" version "3.1-SNAPSHOT"
|
||||
id "dev.architectury.loom" version "0.7.2-SNAPSHOT" apply false
|
||||
id "architectury-plugin" version "3.4-SNAPSHOT"
|
||||
id "dev.architectury.loom" version "0.10.0-SNAPSHOT" apply false
|
||||
id 'com.matthewprenger.cursegradle' version '1.4.0'
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ subprojects {
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
mappings loom.officialMojangMappings()
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,10 +42,7 @@ allprojects {
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
def targetVersion = 8
|
||||
if (JavaVersion.current().isJava9Compatible()) {
|
||||
options.release = targetVersion
|
||||
}
|
||||
options.release = 17
|
||||
}
|
||||
|
||||
java {
|
||||
@ -119,7 +116,7 @@ curseforge {
|
||||
addGameVersion "Fabric"
|
||||
mainArtifact(project(":fabric").tasks.getByName('remapJar')) {
|
||||
def txt = changelog(1).replace("\n-", "\n\n- ")
|
||||
txt = txt + "\n\n" + "For past versions see: https://github.com/Flemmli97/Flan/blob/1.16/Changelog.md"
|
||||
txt = txt + "\n\n" + "For past versions see: ${project.full_changelog}"
|
||||
changelog = txt
|
||||
changelogType = "markdown"
|
||||
releaseType = 'release'
|
||||
@ -138,7 +135,7 @@ curseforge {
|
||||
addGameVersion "Forge"
|
||||
mainArtifact(project(":forge").tasks.getByName('remapJar')) {
|
||||
def txt = changelog(1).replace("\n-", "\n\n- ")
|
||||
txt = txt + "\n\n" + "For past versions see: https://github.com/Flemmli97/Flan/blob/1.16/Changelog.md"
|
||||
txt = txt + "\n\n" + "For past versions see: ${project.full_changelog}"
|
||||
changelog = txt
|
||||
changelogType = "markdown"
|
||||
releaseType = 'release'
|
||||
@ -161,7 +158,7 @@ tasks.getByName("curseforge").doLast {
|
||||
def message = new Message()
|
||||
def version = project.curse_versions.split(', ')[0]
|
||||
message.setUsername("Curseforge Release")
|
||||
message.setContent("<@&852113509243682817> ${project.project_name} ${project.mod_version} for Minecraft ${version} has been released!")
|
||||
message.setContent("${project.discord_role} ${project.project_name} ${project.mod_version} for Minecraft ${version} has been released!")
|
||||
message.setAvatarUrl("https://cdn.discordapp.com/avatars/680540027255652407/e4b7a058b24843ae13389a9a3cc3ae8c.png?size=128")
|
||||
|
||||
def embed = new Embed()
|
||||
|
@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id "com.github.johnrengelman.shadow" version "5.0.0"
|
||||
id "com.github.johnrengelman.shadow" version "7.1.0"
|
||||
}
|
||||
|
||||
configurations {
|
||||
@ -34,10 +34,6 @@ transformProductionForge {
|
||||
input.set shadowJar.archiveFile
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenCommon(MavenPublication) {
|
||||
|
@ -1,12 +1,12 @@
|
||||
package io.github.flemmli97.flan;
|
||||
|
||||
import me.shedaniel.architectury.annotations.ExpectPlatform;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.item.Item;
|
||||
import dev.architectury.injectables.annotations.ExpectPlatform;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
@ -18,7 +18,7 @@ public class CrossPlatformStuff {
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static SimpleRegistryWrapper<StatusEffect> registryStatusEffects() {
|
||||
public static SimpleRegistryWrapper<MobEffect> registryStatusEffects() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,15 @@
|
||||
package io.github.flemmli97.flan;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
/**
|
||||
* Simple structure to get stuff from registries
|
||||
*/
|
||||
public interface SimpleRegistryWrapper<T> {
|
||||
|
||||
T getFromId(Identifier id);
|
||||
T getFromId(ResourceLocation id);
|
||||
|
||||
Identifier getIDFrom(T entry);
|
||||
ResourceLocation getIDFrom(T entry);
|
||||
|
||||
Iterable<T> getIterator();
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ import io.github.flemmli97.flan.claim.ClaimStorage;
|
||||
import io.github.flemmli97.flan.player.OfflinePlayerData;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -19,14 +19,14 @@ public class ClaimHandler {
|
||||
* You can then use IPermissionContainer#getForPermissionCheck
|
||||
* to return an {@link IPermissionContainer} for which you can then check permissions against
|
||||
*/
|
||||
public static IPermissionStorage getPermissionStorage(ServerWorld world) {
|
||||
public static IPermissionStorage getPermissionStorage(ServerLevel world) {
|
||||
return ClaimStorage.get(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the claim data for the given player
|
||||
*/
|
||||
public static IPlayerData getPlayerData(ServerPlayerEntity player) {
|
||||
public static IPlayerData getPlayerData(ServerPlayer player) {
|
||||
return PlayerClaimData.get(player);
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ public class ClaimHandler {
|
||||
* Same as the above but with an uuid. Use this if the player is not online.
|
||||
*/
|
||||
public static IPlayerData getPlayerData(MinecraftServer server, UUID uuid) {
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
ServerPlayer player = server.getPlayerList().getPlayer(uuid);
|
||||
if (player != null)
|
||||
return getPlayerData(player);
|
||||
return new OfflinePlayerData(server, uuid);
|
||||
|
@ -1,12 +1,12 @@
|
||||
package io.github.flemmli97.flan.api.data;
|
||||
|
||||
import io.github.flemmli97.flan.api.permission.ClaimPermission;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public interface IPermissionContainer {
|
||||
|
||||
default boolean canInteract(ServerPlayerEntity player, ClaimPermission perm, BlockPos pos) {
|
||||
default boolean canInteract(ServerPlayer player, ClaimPermission perm, BlockPos pos) {
|
||||
return this.canInteract(player, perm, pos, false);
|
||||
}
|
||||
|
||||
@ -15,6 +15,6 @@ public interface IPermissionContainer {
|
||||
*
|
||||
* @param player The player doing the action. Can be null
|
||||
*/
|
||||
boolean canInteract(ServerPlayerEntity player, ClaimPermission perm, BlockPos pos, boolean message);
|
||||
boolean canInteract(ServerPlayer player, ClaimPermission perm, BlockPos pos, boolean message);
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.github.flemmli97.flan.api.data;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
||||
public interface IPermissionStorage {
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
package io.github.flemmli97.flan.api.permission;
|
||||
|
||||
import io.github.flemmli97.flan.claim.Claim;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@ -56,7 +56,7 @@ public class ClaimPermission {
|
||||
}
|
||||
|
||||
public interface ClaimTest {
|
||||
PermissionFlag test(Claim claim, PlayerEntity player, BlockPos pos);
|
||||
PermissionFlag test(Claim claim, Player player, BlockPos pos);
|
||||
}
|
||||
|
||||
private static final ClaimTest pass = (claim, player, pos) -> PermissionFlag.PASS;
|
||||
|
@ -1,36 +1,36 @@
|
||||
package io.github.flemmli97.flan.api.permission;
|
||||
|
||||
import io.github.flemmli97.flan.CrossPlatformStuff;
|
||||
import net.minecraft.block.AbstractButtonBlock;
|
||||
import net.minecraft.block.AbstractPressurePlateBlock;
|
||||
import net.minecraft.block.AbstractRedstoneGateBlock;
|
||||
import net.minecraft.block.AnvilBlock;
|
||||
import net.minecraft.block.BeaconBlock;
|
||||
import net.minecraft.block.BedBlock;
|
||||
import net.minecraft.block.BellBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.CampfireBlock;
|
||||
import net.minecraft.block.ChorusFlowerBlock;
|
||||
import net.minecraft.block.DaylightDetectorBlock;
|
||||
import net.minecraft.block.DoorBlock;
|
||||
import net.minecraft.block.EnchantingTableBlock;
|
||||
import net.minecraft.block.EnderChestBlock;
|
||||
import net.minecraft.block.FarmlandBlock;
|
||||
import net.minecraft.block.FenceGateBlock;
|
||||
import net.minecraft.block.JukeboxBlock;
|
||||
import net.minecraft.block.LeverBlock;
|
||||
import net.minecraft.block.NetherPortalBlock;
|
||||
import net.minecraft.block.NoteBlock;
|
||||
import net.minecraft.block.RedstoneWireBlock;
|
||||
import net.minecraft.block.TargetBlock;
|
||||
import net.minecraft.block.TntBlock;
|
||||
import net.minecraft.block.TrapdoorBlock;
|
||||
import net.minecraft.block.TurtleEggBlock;
|
||||
import net.minecraft.item.BucketItem;
|
||||
import net.minecraft.item.EnderPearlItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.item.BucketItem;
|
||||
import net.minecraft.world.item.EnderpearlItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.block.AnvilBlock;
|
||||
import net.minecraft.world.level.block.BasePressurePlateBlock;
|
||||
import net.minecraft.world.level.block.BeaconBlock;
|
||||
import net.minecraft.world.level.block.BedBlock;
|
||||
import net.minecraft.world.level.block.BellBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.ButtonBlock;
|
||||
import net.minecraft.world.level.block.CampfireBlock;
|
||||
import net.minecraft.world.level.block.ChorusFlowerBlock;
|
||||
import net.minecraft.world.level.block.DaylightDetectorBlock;
|
||||
import net.minecraft.world.level.block.DiodeBlock;
|
||||
import net.minecraft.world.level.block.DoorBlock;
|
||||
import net.minecraft.world.level.block.EnchantmentTableBlock;
|
||||
import net.minecraft.world.level.block.EnderChestBlock;
|
||||
import net.minecraft.world.level.block.FarmBlock;
|
||||
import net.minecraft.world.level.block.FenceGateBlock;
|
||||
import net.minecraft.world.level.block.JukeboxBlock;
|
||||
import net.minecraft.world.level.block.LeverBlock;
|
||||
import net.minecraft.world.level.block.NetherPortalBlock;
|
||||
import net.minecraft.world.level.block.NoteBlock;
|
||||
import net.minecraft.world.level.block.RedStoneWireBlock;
|
||||
import net.minecraft.world.level.block.TargetBlock;
|
||||
import net.minecraft.world.level.block.TntBlock;
|
||||
import net.minecraft.world.level.block.TrapDoorBlock;
|
||||
import net.minecraft.world.level.block.TurtleEggBlock;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -95,21 +95,21 @@ public class ObjectToPermissionMap {
|
||||
registerBlockPredicateMap((block) -> block instanceof BeaconBlock, () -> PermissionRegistry.BEACON);
|
||||
registerBlockPredicateMap((block) -> block instanceof DoorBlock, () -> PermissionRegistry.DOOR);
|
||||
registerBlockPredicateMap((block) -> block instanceof FenceGateBlock, () -> PermissionRegistry.FENCEGATE);
|
||||
registerBlockPredicateMap((block) -> block instanceof TrapdoorBlock, () -> PermissionRegistry.TRAPDOOR);
|
||||
registerBlockPredicateMap((block) -> block instanceof LeverBlock || block instanceof AbstractButtonBlock, () -> PermissionRegistry.BUTTONLEVER);
|
||||
registerBlockPredicateMap((block) -> block instanceof TrapDoorBlock, () -> PermissionRegistry.TRAPDOOR);
|
||||
registerBlockPredicateMap((block) -> block instanceof LeverBlock || block instanceof ButtonBlock, () -> PermissionRegistry.BUTTONLEVER);
|
||||
registerBlockPredicateMap((block) -> block instanceof NoteBlock, () -> PermissionRegistry.NOTEBLOCK);
|
||||
registerBlockPredicateMap((block) -> block instanceof AbstractRedstoneGateBlock || block instanceof RedstoneWireBlock || block instanceof DaylightDetectorBlock, () -> PermissionRegistry.REDSTONE);
|
||||
registerBlockPredicateMap((block) -> block instanceof DiodeBlock || block instanceof RedStoneWireBlock || block instanceof DaylightDetectorBlock, () -> PermissionRegistry.REDSTONE);
|
||||
registerBlockPredicateMap((block) -> block instanceof JukeboxBlock, () -> PermissionRegistry.JUKEBOX);
|
||||
registerBlockPredicateMap((block) -> block instanceof AbstractPressurePlateBlock, () -> PermissionRegistry.PRESSUREPLATE);
|
||||
registerBlockPredicateMap((block) -> block instanceof BasePressurePlateBlock, () -> PermissionRegistry.PRESSUREPLATE);
|
||||
registerBlockPredicateMap((block) -> block instanceof NetherPortalBlock, () -> PermissionRegistry.PORTAL);
|
||||
registerBlockPredicateMap((block) -> block instanceof TurtleEggBlock || block instanceof FarmlandBlock, () -> PermissionRegistry.TRAMPLE);
|
||||
registerBlockPredicateMap((block) -> block instanceof TurtleEggBlock || block instanceof FarmBlock, () -> PermissionRegistry.TRAMPLE);
|
||||
registerBlockPredicateMap((block) -> block instanceof TargetBlock, () -> PermissionRegistry.TARGETBLOCK);
|
||||
registerBlockPredicateMap((block) -> block instanceof BellBlock || block instanceof CampfireBlock
|
||||
|| block instanceof TntBlock || block instanceof ChorusFlowerBlock, () -> PermissionRegistry.PROJECTILES);
|
||||
registerBlockPredicateMap((block) -> block instanceof EnderChestBlock, () -> PermissionRegistry.ENDERCHEST);
|
||||
registerBlockPredicateMap((block) -> block instanceof EnchantingTableBlock, () -> PermissionRegistry.ENCHANTMENTTABLE);
|
||||
registerBlockPredicateMap((block) -> block instanceof EnchantmentTableBlock, () -> PermissionRegistry.ENCHANTMENTTABLE);
|
||||
|
||||
registerItemPredicateMap(item -> item instanceof EnderPearlItem, () -> PermissionRegistry.ENDERPEARL);
|
||||
registerItemPredicateMap(item -> item instanceof EnderpearlItem, () -> PermissionRegistry.ENDERPEARL);
|
||||
registerItemPredicateMap(item -> item instanceof BucketItem, () -> PermissionRegistry.BUCKET);
|
||||
registerItemPredicateMap(item -> item == Items.END_CRYSTAL, () -> PermissionRegistry.ENDCRYSTALPLACE);
|
||||
registerItemPredicateMap(item -> item == Items.CHORUS_FRUIT, () -> PermissionRegistry.CHORUSFRUIT);
|
||||
|
@ -1,10 +1,10 @@
|
||||
package io.github.flemmli97.flan.api.permission;
|
||||
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.village.raid.Raid;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.raid.Raid;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -21,9 +21,9 @@ public class PermissionRegistry {
|
||||
private static final Map<String, ClaimPermission> permissions = new LinkedHashMap<>();
|
||||
private static final Map<String, ClaimPermission> globalPermissions = new LinkedHashMap<>();
|
||||
|
||||
private static final Map<Identifier, ClaimPermission> interactBlocks = new HashMap<>();
|
||||
private static final Map<Identifier, ClaimPermission> breakBlocks = new HashMap<>();
|
||||
private static final Map<Identifier, ClaimPermission> items = new HashMap<>();
|
||||
private static final Map<ResourceLocation, ClaimPermission> interactBlocks = new HashMap<>();
|
||||
private static final Map<ResourceLocation, ClaimPermission> breakBlocks = new HashMap<>();
|
||||
private static final Map<ResourceLocation, ClaimPermission> items = new HashMap<>();
|
||||
|
||||
private static boolean locked;
|
||||
|
||||
@ -55,7 +55,7 @@ public class PermissionRegistry {
|
||||
public static ClaimPermission TRAMPLE = register(new ClaimPermission("TRAMPLE", () -> new ItemStack(Items.FARMLAND), "Permission to enable block trampling", "(farmland, turtle eggs)"));
|
||||
public static ClaimPermission FROSTWALKER = register(new ClaimPermission("FROSTWALKER", () -> new ItemStack(Items.LEATHER_BOOTS), "Permission for frostwalker to activate"));
|
||||
public static ClaimPermission PORTAL = register(new ClaimPermission("PORTAL", () -> new ItemStack(Items.OBSIDIAN), true, "Permission to use nether portals"));
|
||||
public static ClaimPermission RAID = register(new ClaimPermission("RAID", Raid::getOminousBanner, "Permission to trigger raids in claim.", "Wont prevent raids (just) outside"));
|
||||
public static ClaimPermission RAID = register(new ClaimPermission("RAID", Raid::getLeaderBannerInstance, "Permission to trigger raids in claim.", "Wont prevent raids (just) outside"));
|
||||
public static ClaimPermission BOAT = register(new ClaimPermission("BOAT", () -> new ItemStack(Items.OAK_BOAT), "Permission to sit in boats"));
|
||||
public static ClaimPermission MINECART = register(new ClaimPermission("MINECART", () -> new ItemStack(Items.MINECART), "Permission to sit in minecarts"));
|
||||
public static ClaimPermission BUCKET = register(new ClaimPermission("BUCKET", () -> new ItemStack(Items.BUCKET), "Permission to take liquids with buckets"));
|
||||
@ -121,23 +121,23 @@ public class PermissionRegistry {
|
||||
return globalPermissions.values();
|
||||
}
|
||||
|
||||
public static ClaimPermission registerBreakPerm(ClaimPermission perm, Identifier... affectedBlocks) {
|
||||
public static ClaimPermission registerBreakPerm(ClaimPermission perm, ResourceLocation... affectedBlocks) {
|
||||
ClaimPermission reg = register(perm);
|
||||
for (Identifier blocks : affectedBlocks)
|
||||
for (ResourceLocation blocks : affectedBlocks)
|
||||
breakBlocks.put(blocks, perm);
|
||||
return reg;
|
||||
}
|
||||
|
||||
public static ClaimPermission registerBlockInteract(ClaimPermission perm, Identifier... affectedBlocks) {
|
||||
public static ClaimPermission registerBlockInteract(ClaimPermission perm, ResourceLocation... affectedBlocks) {
|
||||
ClaimPermission reg = register(perm);
|
||||
for (Identifier blocks : affectedBlocks)
|
||||
for (ResourceLocation blocks : affectedBlocks)
|
||||
interactBlocks.put(blocks, perm);
|
||||
return reg;
|
||||
}
|
||||
|
||||
public static ClaimPermission registerItemUse(ClaimPermission perm, Identifier... affectedBlocks) {
|
||||
public static ClaimPermission registerItemUse(ClaimPermission perm, ResourceLocation... affectedBlocks) {
|
||||
ClaimPermission reg = register(perm);
|
||||
for (Identifier blocks : affectedBlocks)
|
||||
for (ResourceLocation blocks : affectedBlocks)
|
||||
items.put(blocks, perm);
|
||||
return reg;
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import com.google.common.collect.Lists;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import io.github.flemmli97.flan.CrossPlatformStuff;
|
||||
import io.github.flemmli97.flan.Flan;
|
||||
import io.github.flemmli97.flan.api.data.IPermissionContainer;
|
||||
@ -15,20 +14,21 @@ import io.github.flemmli97.flan.config.Config;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.player.LogoutTracker;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetSubtitleTextPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.chunk.ChunkStatus;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -65,30 +65,30 @@ public class Claim implements IPermissionContainer {
|
||||
*/
|
||||
private boolean removed;
|
||||
|
||||
private final ServerWorld world;
|
||||
private final ServerLevel world;
|
||||
|
||||
private final Map<StatusEffect, Integer> potions = new HashMap<>();
|
||||
private final Map<MobEffect, Integer> potions = new HashMap<>();
|
||||
|
||||
public Text enterTitle, enterSubtitle, leaveTitle, leaveSubtitle;
|
||||
public Component enterTitle, enterSubtitle, leaveTitle, leaveSubtitle;
|
||||
|
||||
private Claim(ServerWorld world) {
|
||||
private Claim(ServerLevel world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public Claim(BlockPos pos1, BlockPos pos2, ServerPlayerEntity creator) {
|
||||
this(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ(), Math.min(pos1.getY(), pos2.getY()), creator.getUuid(), creator.getServerWorld(), PlayerClaimData.get(creator).playerDefaultGroups().isEmpty());
|
||||
public Claim(BlockPos pos1, BlockPos pos2, ServerPlayer creator) {
|
||||
this(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ(), Math.min(pos1.getY(), pos2.getY()), creator.getUUID(), creator.getLevel(), PlayerClaimData.get(creator).playerDefaultGroups().isEmpty());
|
||||
PlayerClaimData.get(creator).playerDefaultGroups().forEach((s, m) -> m.forEach((perm, bool) -> this.editPerms(null, s, perm, bool ? 1 : 0, true)));
|
||||
}
|
||||
|
||||
public Claim(BlockPos pos1, BlockPos pos2, UUID creator, ServerWorld world) {
|
||||
public Claim(BlockPos pos1, BlockPos pos2, UUID creator, ServerLevel world) {
|
||||
this(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ(), Math.min(pos1.getY(), pos2.getY()), creator, world);
|
||||
}
|
||||
|
||||
public Claim(int x1, int x2, int z1, int z2, int minY, UUID creator, ServerWorld world) {
|
||||
public Claim(int x1, int x2, int z1, int z2, int minY, UUID creator, ServerLevel world) {
|
||||
this(x1, x2, z1, z2, minY, creator, world, true);
|
||||
}
|
||||
|
||||
public Claim(int x1, int x2, int z1, int z2, int minY, UUID creator, ServerWorld world, boolean setDefaultGroups) {
|
||||
public Claim(int x1, int x2, int z1, int z2, int minY, UUID creator, ServerLevel world, boolean setDefaultGroups) {
|
||||
this.minX = Math.min(x1, x2);
|
||||
this.minZ = Math.min(z1, z2);
|
||||
this.maxX = Math.max(x1, x2);
|
||||
@ -103,7 +103,7 @@ public class Claim implements IPermissionContainer {
|
||||
ConfigHandler.config.defaultGroups.forEach((s, m) -> m.forEach((perm, bool) -> this.editPerms(null, s, perm, bool ? 1 : 0, true)));
|
||||
}
|
||||
|
||||
public static Claim fromJson(JsonObject obj, UUID owner, ServerWorld world) {
|
||||
public static Claim fromJson(JsonObject obj, UUID owner, ServerLevel world) {
|
||||
Claim claim = new Claim(world);
|
||||
claim.readJson(obj, owner);
|
||||
ClaimUpdater.updateClaim(claim);
|
||||
@ -112,7 +112,7 @@ public class Claim implements IPermissionContainer {
|
||||
|
||||
private BlockPos getInitCenterPos() {
|
||||
BlockPos center = new BlockPos(this.minX + (this.maxX - this.minX) * 0.5, 0, this.minZ + (this.maxZ - this.minZ) * 0.5);
|
||||
int y = this.world.getChunk(center.getX() >> 4, center.getZ() >> 4, ChunkStatus.HEIGHTMAPS).sampleHeightmap(Heightmap.Type.MOTION_BLOCKING, center.getX() & 15, center.getZ() & 15);
|
||||
int y = this.world.getChunk(center.getX() >> 4, center.getZ() >> 4, ChunkStatus.HEIGHTMAPS).getHeight(Heightmap.Types.MOTION_BLOCKING, center.getX() & 15, center.getZ() & 15);
|
||||
return new BlockPos(center.getX(), y + 1, center.getZ());
|
||||
}
|
||||
|
||||
@ -148,13 +148,13 @@ public class Claim implements IPermissionContainer {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
public Optional<ServerPlayerEntity> getOwnerPlayer() {
|
||||
public Optional<ServerPlayer> getOwnerPlayer() {
|
||||
if (this.getOwner() != null)
|
||||
return Optional.ofNullable(this.world.getServer().getPlayerManager().getPlayer(this.getOwner()));
|
||||
return Optional.ofNullable(this.world.getServer().getPlayerList().getPlayer(this.getOwner()));
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public ServerWorld getWorld() {
|
||||
public ServerLevel getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
@ -178,9 +178,9 @@ public class Claim implements IPermissionContainer {
|
||||
this.setDirty(true);
|
||||
}
|
||||
|
||||
public void toggleAdminClaim(ServerPlayerEntity player, boolean flag) {
|
||||
public void toggleAdminClaim(ServerPlayer player, boolean flag) {
|
||||
if (!flag)
|
||||
this.transferOwner(player.getUuid());
|
||||
this.transferOwner(player.getUUID());
|
||||
else {
|
||||
this.owner = null;
|
||||
this.subClaims.forEach(claim -> claim.owner = null);
|
||||
@ -217,7 +217,7 @@ 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) {
|
||||
public boolean intersects(AABB box) {
|
||||
return this.minX < box.maxX && this.maxX + 1 > box.minX && this.minZ < box.maxZ && this.maxZ + 1 > box.minZ && box.maxY >= this.minY;
|
||||
}
|
||||
|
||||
@ -235,16 +235,16 @@ public class Claim implements IPermissionContainer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(ServerPlayerEntity player, ClaimPermission perm, BlockPos pos, boolean message) {
|
||||
ActionResult res = ClaimPermissionCheck.check(player, perm, pos);
|
||||
if (res != ActionResult.PASS)
|
||||
return res != ActionResult.FAIL;
|
||||
public boolean canInteract(ServerPlayer player, ClaimPermission perm, BlockPos pos, boolean message) {
|
||||
InteractionResult res = ClaimPermissionCheck.check(player, perm, pos);
|
||||
if (res != InteractionResult.PASS)
|
||||
return res != InteractionResult.FAIL;
|
||||
if (perm != null) {
|
||||
ClaimPermission.PermissionFlag flag = perm.test.test(this, player, pos);
|
||||
if (flag != ClaimPermission.PermissionFlag.PASS) {
|
||||
if (flag == ClaimPermission.PermissionFlag.NO) {
|
||||
if (message)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, ChatFormatting.DARK_RED), true);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -256,7 +256,7 @@ public class Claim implements IPermissionContainer {
|
||||
if (global.getValue() || (player != null && this.isAdminIgnore(player)))
|
||||
return true;
|
||||
if (message)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, ChatFormatting.DARK_RED), true);
|
||||
return false;
|
||||
}
|
||||
if (ConfigHandler.config.offlineProtectActivation != -1 && (LogoutTracker.getInstance(this.world.getServer()).justLoggedOut(this.getOwner()) || this.getOwnerPlayer().isPresent())) {
|
||||
@ -272,10 +272,10 @@ public class Claim implements IPermissionContainer {
|
||||
if (this.hasPerm(perm))
|
||||
return true;
|
||||
if (message)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, ChatFormatting.DARK_RED), true);
|
||||
return false;
|
||||
}
|
||||
if (this.isAdminIgnore(player) || player.getUuid().equals(this.owner))
|
||||
if (this.isAdminIgnore(player) || player.getUUID().equals(this.owner))
|
||||
return true;
|
||||
if (perm != PermissionRegistry.EDITCLAIM && perm != PermissionRegistry.EDITPERMS)
|
||||
for (Claim claim : this.subClaims) {
|
||||
@ -283,25 +283,25 @@ public class Claim implements IPermissionContainer {
|
||||
return claim.canInteract(player, perm, pos, message);
|
||||
}
|
||||
}
|
||||
if (this.playersGroups.containsKey(player.getUuid())) {
|
||||
Map<ClaimPermission, Boolean> map = this.permissions.get(this.playersGroups.get(player.getUuid()));
|
||||
if (this.playersGroups.containsKey(player.getUUID())) {
|
||||
Map<ClaimPermission, Boolean> map = this.permissions.get(this.playersGroups.get(player.getUUID()));
|
||||
if (map != null && map.containsKey(perm)) {
|
||||
if (map.get(perm))
|
||||
return true;
|
||||
if (message)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, ChatFormatting.DARK_RED), true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (this.hasPerm(perm))
|
||||
return true;
|
||||
if (message)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, ChatFormatting.DARK_RED), true);
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isAdminIgnore(ServerPlayerEntity player) {
|
||||
return player == null || ((this.isAdminClaim() && player.hasPermissionLevel(2)) || PlayerClaimData.get(player).isAdminIgnoreClaim());
|
||||
private boolean isAdminIgnore(ServerPlayer player) {
|
||||
return player == null || ((this.isAdminClaim() && player.hasPermissions(2)) || PlayerClaimData.get(player).isAdminIgnoreClaim());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -408,17 +408,13 @@ public class Claim implements IPermissionContainer {
|
||||
l.add(uuid);
|
||||
});
|
||||
List<String> names = new ArrayList<>();
|
||||
l.forEach(uuid -> {
|
||||
GameProfile prof = server.getUserCache().getByUuid(uuid);
|
||||
if (prof != null)
|
||||
names.add(prof.getName());
|
||||
});
|
||||
l.forEach(uuid -> server.getProfileCache().get(uuid).ifPresent(prof -> names.add(prof.getName())));
|
||||
names.sort(null);
|
||||
return names;
|
||||
}
|
||||
|
||||
public boolean editGlobalPerms(ServerPlayerEntity player, ClaimPermission toggle, int mode) {
|
||||
if ((player != null && !this.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos())) || (!this.isAdminClaim() && ConfigHandler.config.globallyDefined(this.world, toggle)))
|
||||
public boolean editGlobalPerms(ServerPlayer player, ClaimPermission toggle, int mode) {
|
||||
if ((player != null && !this.canInteract(player, PermissionRegistry.EDITPERMS, player.blockPosition())) || (!this.isAdminClaim() && ConfigHandler.config.globallyDefined(this.world, toggle)))
|
||||
return false;
|
||||
if (mode > 1)
|
||||
mode = -1;
|
||||
@ -430,7 +426,7 @@ public class Claim implements IPermissionContainer {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean editPerms(ServerPlayerEntity player, String group, ClaimPermission perm, int mode) {
|
||||
public boolean editPerms(ServerPlayer player, String group, ClaimPermission perm, int mode) {
|
||||
return this.editPerms(player, group, perm, mode, false);
|
||||
}
|
||||
|
||||
@ -440,10 +436,10 @@ public class Claim implements IPermissionContainer {
|
||||
* @param mode -1 = makes it resort to the global perm, 0 = deny perm, 1 = allow perm
|
||||
* @return If editing was successful or not
|
||||
*/
|
||||
public boolean editPerms(ServerPlayerEntity player, String group, ClaimPermission perm, int mode, boolean alwaysCan) {
|
||||
public boolean editPerms(ServerPlayer player, String group, ClaimPermission perm, int mode, boolean alwaysCan) {
|
||||
if (PermissionRegistry.globalPerms().contains(perm) || (!this.isAdminClaim() && ConfigHandler.config.globallyDefined(this.world, perm)))
|
||||
return false;
|
||||
if (alwaysCan || this.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos())) {
|
||||
if (alwaysCan || this.canInteract(player, PermissionRegistry.EDITPERMS, player.blockPosition())) {
|
||||
if (mode > 1)
|
||||
mode = -1;
|
||||
boolean has = this.permissions.containsKey(group);
|
||||
@ -460,8 +456,8 @@ public class Claim implements IPermissionContainer {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removePermGroup(ServerPlayerEntity player, String group) {
|
||||
if (this.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos())) {
|
||||
public boolean removePermGroup(ServerPlayer player, String group) {
|
||||
if (this.canInteract(player, PermissionRegistry.EDITPERMS, player.blockPosition())) {
|
||||
this.permissions.remove(group);
|
||||
List<UUID> toRemove = new ArrayList<>();
|
||||
this.playersGroups.forEach((uuid, g) -> {
|
||||
@ -496,54 +492,54 @@ public class Claim implements IPermissionContainer {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addPotion(StatusEffect effect, int amplifier) {
|
||||
public void addPotion(MobEffect effect, int amplifier) {
|
||||
this.potions.put(effect, amplifier);
|
||||
this.setDirty(true);
|
||||
}
|
||||
|
||||
public void removePotion(StatusEffect effect) {
|
||||
public void removePotion(MobEffect effect) {
|
||||
this.potions.remove(effect);
|
||||
this.setDirty(true);
|
||||
}
|
||||
|
||||
public Map<StatusEffect, Integer> getPotions() {
|
||||
public Map<MobEffect, Integer> getPotions() {
|
||||
return this.potions;
|
||||
}
|
||||
|
||||
public void applyEffects(ServerPlayerEntity player) {
|
||||
if (player.world.getTime() % 80 == 0)
|
||||
this.potions.forEach((effect, amp) -> player.applyStatusEffect(new StatusEffectInstance(effect, 200, amp - 1, true, false)));
|
||||
public void applyEffects(ServerPlayer player) {
|
||||
if (player.level.getGameTime() % 80 == 0)
|
||||
this.potions.forEach((effect, amp) -> player.forceAddEffect(new MobEffectInstance(effect, 200, amp - 1, true, false), null));
|
||||
}
|
||||
|
||||
public BlockPos getHomePos() {
|
||||
return this.homePos;
|
||||
}
|
||||
|
||||
public void setEnterTitle(Text title, Text sub) {
|
||||
public void setEnterTitle(Component title, Component sub) {
|
||||
this.enterTitle = title;
|
||||
this.enterSubtitle = sub;
|
||||
this.setDirty(true);
|
||||
}
|
||||
|
||||
public void setLeaveTitle(Text title, Text sub) {
|
||||
public void setLeaveTitle(Component title, Component sub) {
|
||||
this.leaveTitle = title;
|
||||
this.leaveSubtitle = sub;
|
||||
this.setDirty(true);
|
||||
}
|
||||
|
||||
public void displayEnterTitle(ServerPlayerEntity player) {
|
||||
public void displayEnterTitle(ServerPlayer player) {
|
||||
if (this.enterTitle != null) {
|
||||
player.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.TITLE, this.enterTitle));
|
||||
player.connection.send(new ClientboundSetTitleTextPacket(this.enterTitle));
|
||||
if (this.enterSubtitle != null)
|
||||
player.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.SUBTITLE, this.enterSubtitle));
|
||||
player.connection.send(new ClientboundSetSubtitleTextPacket(this.enterSubtitle));
|
||||
}
|
||||
}
|
||||
|
||||
public void displayLeaveTitle(ServerPlayerEntity player) {
|
||||
public void displayLeaveTitle(ServerPlayer player) {
|
||||
if (this.leaveTitle != null) {
|
||||
player.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.TITLE, this.leaveTitle));
|
||||
player.connection.send(new ClientboundSetTitleTextPacket(this.leaveTitle));
|
||||
if (this.leaveSubtitle != null)
|
||||
player.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.SUBTITLE, this.leaveSubtitle));
|
||||
player.connection.send(new ClientboundSetSubtitleTextPacket(this.leaveSubtitle));
|
||||
}
|
||||
}
|
||||
|
||||
@ -579,18 +575,18 @@ public class Claim implements IPermissionContainer {
|
||||
}
|
||||
String message = ConfigHandler.fromJson(obj, "EnterTitle", "");
|
||||
if (!message.isEmpty())
|
||||
this.enterTitle = Text.Serializer.fromJson(message);
|
||||
this.enterTitle = Component.Serializer.fromJson(message);
|
||||
message = ConfigHandler.fromJson(obj, "EnterSubtitle", "");
|
||||
if (!message.isEmpty())
|
||||
this.enterSubtitle = Text.Serializer.fromJson(message);
|
||||
this.enterSubtitle = Component.Serializer.fromJson(message);
|
||||
message = ConfigHandler.fromJson(obj, "LeaveTitle", "");
|
||||
if (!message.isEmpty())
|
||||
this.leaveTitle = Text.Serializer.fromJson(message);
|
||||
this.leaveTitle = Component.Serializer.fromJson(message);
|
||||
message = ConfigHandler.fromJson(obj, "LeaveSubtitle", "");
|
||||
if (!message.isEmpty())
|
||||
this.leaveSubtitle = Text.Serializer.fromJson(message);
|
||||
this.leaveSubtitle = Component.Serializer.fromJson(message);
|
||||
JsonObject potion = ConfigHandler.fromJson(obj, "Potions");
|
||||
potion.entrySet().forEach(e -> this.potions.put(CrossPlatformStuff.registryStatusEffects().getFromId(new Identifier(e.getKey())), e.getValue().getAsInt()));
|
||||
potion.entrySet().forEach(e -> this.potions.put(CrossPlatformStuff.registryStatusEffects().getFromId(new ResourceLocation(e.getKey())), e.getValue().getAsInt()));
|
||||
if (ConfigHandler.fromJson(obj, "AdminClaim", false))
|
||||
this.owner = null;
|
||||
else
|
||||
@ -655,10 +651,10 @@ public class Claim implements IPermissionContainer {
|
||||
home.add(this.homePos.getY());
|
||||
home.add(this.homePos.getZ());
|
||||
obj.add("Home", home);
|
||||
obj.addProperty("EnterTitle", this.enterTitle == null ? "" : Text.Serializer.toJson(this.enterTitle));
|
||||
obj.addProperty("EnterSubtitle", this.enterSubtitle == null ? "" : Text.Serializer.toJson(this.enterSubtitle));
|
||||
obj.addProperty("LeaveTitle", this.leaveTitle == null ? "" : Text.Serializer.toJson(this.leaveTitle));
|
||||
obj.addProperty("LeaveSubtitle", this.leaveSubtitle == null ? "" : Text.Serializer.toJson(this.leaveSubtitle));
|
||||
obj.addProperty("EnterTitle", this.enterTitle == null ? "" : Component.Serializer.toJson(this.enterTitle));
|
||||
obj.addProperty("EnterSubtitle", this.enterSubtitle == null ? "" : Component.Serializer.toJson(this.enterSubtitle));
|
||||
obj.addProperty("LeaveTitle", this.leaveTitle == null ? "" : Component.Serializer.toJson(this.leaveTitle));
|
||||
obj.addProperty("LeaveSubtitle", this.leaveSubtitle == null ? "" : Component.Serializer.toJson(this.leaveSubtitle));
|
||||
JsonObject potions = new JsonObject();
|
||||
this.potions.forEach((effect, amp) -> potions.addProperty(CrossPlatformStuff.registryStatusEffects().getIDFrom(effect).toString(), amp));
|
||||
obj.add("Potions", potions);
|
||||
@ -730,46 +726,45 @@ public class Claim implements IPermissionContainer {
|
||||
return String.format("%s:[x=%d,z=%d] - [x=%d,z=%d]", this.claimName, this.minX, this.minZ, this.maxX, this.maxZ);
|
||||
}
|
||||
|
||||
public List<Text> infoString(ServerPlayerEntity player, InfoType infoType) {
|
||||
boolean perms = this.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos());
|
||||
List<Text> l = new ArrayList<>();
|
||||
l.add(PermHelper.simpleColoredText("=============================================", Formatting.GREEN));
|
||||
GameProfile prof = this.owner != null ? player.getServer().getUserCache().getByUuid(this.owner) : null;
|
||||
String ownerName = this.isAdminClaim() ? "Admin" : prof != null ? prof.getName() : "<UNKNOWN>";
|
||||
public List<Component> infoString(ServerPlayer player, InfoType infoType) {
|
||||
boolean perms = this.canInteract(player, PermissionRegistry.EDITPERMS, player.blockPosition());
|
||||
List<Component> l = new ArrayList<>();
|
||||
l.add(PermHelper.simpleColoredText("=============================================", ChatFormatting.GREEN));
|
||||
String ownerName = this.isAdminClaim() ? "Admin" : player.getServer().getProfileCache().get(this.owner).map(prof -> prof.getName()).orElse("<UNKNOWN>");
|
||||
if (this.parent == null) {
|
||||
if (this.claimName.isEmpty())
|
||||
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBasicInfo, ownerName, this.minX, this.minZ, this.maxX, this.maxZ, this.subClaims.size()), Formatting.GOLD));
|
||||
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBasicInfo, ownerName, this.minX, this.minZ, this.maxX, this.maxZ, this.subClaims.size()), ChatFormatting.GOLD));
|
||||
else
|
||||
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBasicInfoNamed, ownerName, this.minX, this.minZ, this.maxX, this.maxZ, this.subClaims.size(), this.claimName), Formatting.GOLD));
|
||||
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBasicInfoNamed, ownerName, this.minX, this.minZ, this.maxX, this.maxZ, this.subClaims.size(), this.claimName), ChatFormatting.GOLD));
|
||||
} else {
|
||||
if (this.claimName.isEmpty())
|
||||
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBasicInfoSub, ownerName, this.minX, this.minZ, this.maxX, this.maxZ), Formatting.GOLD));
|
||||
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBasicInfoSub, ownerName, this.minX, this.minZ, this.maxX, this.maxZ), ChatFormatting.GOLD));
|
||||
else
|
||||
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBasicInfoSubNamed, ownerName, this.minX, this.minZ, this.maxX, this.maxZ, this.claimName), Formatting.GOLD));
|
||||
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBasicInfoSubNamed, ownerName, this.minX, this.minZ, this.maxX, this.maxZ, this.claimName), ChatFormatting.GOLD));
|
||||
}
|
||||
if (perms) {
|
||||
if (infoType == InfoType.ALL || infoType == InfoType.GLOBAL)
|
||||
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimInfoPerms, this.globalPerm), Formatting.RED));
|
||||
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimInfoPerms, this.globalPerm), ChatFormatting.RED));
|
||||
if (infoType == InfoType.ALL || infoType == InfoType.GROUP) {
|
||||
l.add(PermHelper.simpleColoredText(ConfigHandler.lang.claimGroupInfoHeader, Formatting.RED));
|
||||
l.add(PermHelper.simpleColoredText(ConfigHandler.lang.claimGroupInfoHeader, ChatFormatting.RED));
|
||||
Map<String, List<String>> nameToGroup = new HashMap<>();
|
||||
for (Map.Entry<UUID, String> e : this.playersGroups.entrySet()) {
|
||||
GameProfile pgroup = player.getServer().getUserCache().getByUuid(e.getKey());
|
||||
if (prof != null) {
|
||||
nameToGroup.merge(e.getValue(), Lists.newArrayList(pgroup.getName()), (old, val) -> {
|
||||
old.add(pgroup.getName());
|
||||
return old;
|
||||
});
|
||||
}
|
||||
player.getServer().getProfileCache().get(e.getKey()).ifPresent(pgroup ->
|
||||
|
||||
nameToGroup.merge(e.getValue(), Lists.newArrayList(pgroup.getName()), (old, val) -> {
|
||||
old.add(pgroup.getName());
|
||||
return old;
|
||||
})
|
||||
);
|
||||
}
|
||||
for (Map.Entry<String, Map<ClaimPermission, Boolean>> e : this.permissions.entrySet()) {
|
||||
l.add(PermHelper.simpleColoredText(String.format(" %s:", e.getKey()), Formatting.DARK_RED));
|
||||
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimGroupPerms, e.getValue()), Formatting.RED));
|
||||
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimGroupPlayers, nameToGroup.getOrDefault(e.getKey(), new ArrayList<>())), Formatting.RED));
|
||||
l.add(PermHelper.simpleColoredText(String.format(" %s:", e.getKey()), ChatFormatting.DARK_RED));
|
||||
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimGroupPerms, e.getValue()), ChatFormatting.RED));
|
||||
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimGroupPlayers, nameToGroup.getOrDefault(e.getKey(), new ArrayList<>())), ChatFormatting.RED));
|
||||
}
|
||||
}
|
||||
}
|
||||
l.add(PermHelper.simpleColoredText("=============================================", Formatting.GREEN));
|
||||
l.add(PermHelper.simpleColoredText("=============================================", ChatFormatting.GREEN));
|
||||
return l;
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,15 @@
|
||||
package io.github.flemmli97.flan.claim;
|
||||
|
||||
import dev.architectury.injectables.annotations.ExpectPlatform;
|
||||
import io.github.flemmli97.flan.api.permission.ClaimPermission;
|
||||
import me.shedaniel.architectury.annotations.ExpectPlatform;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
||||
public class ClaimPermissionCheck {
|
||||
|
||||
@ExpectPlatform
|
||||
public static ActionResult check(ServerPlayerEntity player, ClaimPermission permission, BlockPos pos) {
|
||||
public static InteractionResult check(ServerPlayer player, ClaimPermission permission, BlockPos pos) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
@ -22,21 +22,21 @@ import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import io.github.flemmli97.flan.player.PlayerDataHandler;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.HoverEvent;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.ClickEvent;
|
||||
import net.minecraft.text.HoverEvent;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Pair;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.Tuple;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.File;
|
||||
@ -64,11 +64,11 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
private final Set<UUID> dirty = new HashSet<>();
|
||||
private final GlobalClaim globalClaim;
|
||||
|
||||
public static ClaimStorage get(ServerWorld world) {
|
||||
public static ClaimStorage get(ServerLevel world) {
|
||||
return ((IClaimStorage) world).get();
|
||||
}
|
||||
|
||||
public ClaimStorage(MinecraftServer server, ServerWorld world) {
|
||||
public ClaimStorage(MinecraftServer server, ServerLevel world) {
|
||||
this.globalClaim = new GlobalClaim(world);
|
||||
this.read(server, world);
|
||||
PlayerDataHandler.deleteUnusedClaims(server, this, world);
|
||||
@ -81,36 +81,36 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public boolean createClaim(BlockPos pos1, BlockPos pos2, ServerPlayerEntity player) {
|
||||
Claim claim = new Claim(pos1.down(ConfigHandler.config.defaultClaimDepth), pos2.down(ConfigHandler.config.defaultClaimDepth), player);
|
||||
public boolean createClaim(BlockPos pos1, BlockPos pos2, ServerPlayer player) {
|
||||
Claim claim = new Claim(pos1.below(ConfigHandler.config.defaultClaimDepth), pos2.below(ConfigHandler.config.defaultClaimDepth), player);
|
||||
Set<Claim> conflicts = this.conflicts(claim, null);
|
||||
if (conflicts.isEmpty()) {
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if (claim.getPlane() < ConfigHandler.config.minClaimsize) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.minClaimSize, ConfigHandler.config.minClaimsize), Formatting.RED), false);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.minClaimSize, ConfigHandler.config.minClaimsize), ChatFormatting.RED), false);
|
||||
return false;
|
||||
}
|
||||
if (!data.isAdminIgnoreClaim() && ConfigHandler.config.maxClaims != -1 && !PermissionNodeHandler.permBelowEqVal(player, PermissionNodeHandler.permMaxClaims, this.playerClaimMap.getOrDefault(player.getUuid(), Sets.newHashSet()).size() + 1, ConfigHandler.config.maxClaims)) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.maxClaims), Formatting.RED), false);
|
||||
if (!data.isAdminIgnoreClaim() && ConfigHandler.config.maxClaims != -1 && !PermissionNodeHandler.permBelowEqVal(player, PermissionNodeHandler.permMaxClaims, this.playerClaimMap.getOrDefault(player.getUUID(), Sets.newHashSet()).size() + 1, ConfigHandler.config.maxClaims)) {
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.maxClaims), ChatFormatting.RED), false);
|
||||
return false;
|
||||
}
|
||||
if (!data.isAdminIgnoreClaim() && !data.canUseClaimBlocks(claim.getPlane())) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.notEnoughBlocks, Formatting.RED), false);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.notEnoughBlocks, ChatFormatting.RED), false);
|
||||
return false;
|
||||
}
|
||||
claim.setClaimID(this.generateUUID());
|
||||
Flan.log("Creating new claim {}", claim);
|
||||
this.addClaim(claim);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY());
|
||||
data.updateScoreboard();
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.claimCreateSuccess, Formatting.GOLD), false);
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
||||
data.getClaimBlocks(), data.getAdditionalClaims(), data.usedClaimBlocks()), Formatting.GOLD), false);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.claimCreateSuccess, ChatFormatting.GOLD), false);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
||||
data.getClaimBlocks(), data.getAdditionalClaims(), data.usedClaimBlocks()), ChatFormatting.GOLD), false);
|
||||
return true;
|
||||
}
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
conflicts.forEach(conf -> data.addDisplayClaim(conf, EnumDisplayType.CONFLICT, player.getBlockPos().getY()));
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
|
||||
conflicts.forEach(conf -> data.addDisplayClaim(conf, EnumDisplayType.CONFLICT, player.blockPosition().getY()));
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, ChatFormatting.RED), false);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
int[] chunks = getChunkPos(claim);
|
||||
for (int x = chunks[0]; x <= chunks[1]; x++)
|
||||
for (int z = chunks[2]; z <= chunks[3]; z++) {
|
||||
List<Claim> claims = this.claims.get(ChunkPos.toLong(x, z));
|
||||
List<Claim> claims = this.claims.get(ChunkPos.asLong(x, z));
|
||||
if (claims != null)
|
||||
for (Claim other : claims) {
|
||||
if (claim.intersects(other) && !other.equals(except)) {
|
||||
@ -130,7 +130,7 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
return conflicted;
|
||||
}
|
||||
|
||||
public boolean deleteClaim(Claim claim, boolean updateClaim, EnumEditMode mode, ServerWorld world) {
|
||||
public boolean deleteClaim(Claim claim, boolean updateClaim, EnumEditMode mode, ServerLevel world) {
|
||||
if (mode == EnumEditMode.SUBCLAIM) {
|
||||
if (claim.parentClaim() != null)
|
||||
return claim.parentClaim().deleteSubClaim(claim);
|
||||
@ -140,7 +140,7 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
int[] pos = getChunkPos(claim);
|
||||
for (int x = pos[0]; x <= pos[1]; x++)
|
||||
for (int z = pos[2]; z <= pos[3]; z++) {
|
||||
this.claims.compute(ChunkPos.toLong(x, z), (key, val) -> {
|
||||
this.claims.compute(ChunkPos.asLong(x, z), (key, val) -> {
|
||||
if (val == null)
|
||||
return null;
|
||||
val.remove(claim);
|
||||
@ -156,9 +156,9 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
return this.claimUUIDMap.remove(claim.getClaimID()) != null;
|
||||
}
|
||||
|
||||
public void toggleAdminClaim(ServerPlayerEntity player, Claim claim, boolean toggle) {
|
||||
public void toggleAdminClaim(ServerPlayer player, Claim claim, boolean toggle) {
|
||||
Flan.log("Set claim {} to an admin claim", claim);
|
||||
this.deleteClaim(claim, false, EnumEditMode.DEFAULT, player.getServerWorld());
|
||||
this.deleteClaim(claim, false, EnumEditMode.DEFAULT, player.getLevel());
|
||||
if (toggle)
|
||||
claim.getOwnerPlayer().ifPresent(o -> PlayerClaimData.get(o).updateScoreboard());
|
||||
claim.toggleAdminClaim(player, toggle);
|
||||
@ -167,18 +167,18 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
this.addClaim(claim);
|
||||
}
|
||||
|
||||
public boolean resizeClaim(Claim claim, BlockPos from, BlockPos to, ServerPlayerEntity player) {
|
||||
public boolean resizeClaim(Claim claim, BlockPos from, BlockPos to, ServerPlayer player) {
|
||||
int[] dims = claim.getDimensions();
|
||||
BlockPos opposite = new BlockPos(dims[0] == from.getX() ? dims[1] : dims[0], dims[4], dims[2] == from.getZ() ? dims[3] : dims[2]);
|
||||
Claim newClaim = new Claim(opposite, to, player.getUuid(), player.getServerWorld());
|
||||
Claim newClaim = new Claim(opposite, to, player.getUUID(), player.getLevel());
|
||||
if (newClaim.getPlane() < ConfigHandler.config.minClaimsize) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.minClaimSize, ConfigHandler.config.minClaimsize), Formatting.RED), false);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.minClaimSize, ConfigHandler.config.minClaimsize), ChatFormatting.RED), false);
|
||||
return false;
|
||||
}
|
||||
Set<Claim> conflicts = this.conflicts(newClaim, claim);
|
||||
if (!conflicts.isEmpty()) {
|
||||
conflicts.forEach(conf -> PlayerClaimData.get(player).addDisplayClaim(conf, EnumDisplayType.CONFLICT, player.getBlockPos().getY()));
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
|
||||
conflicts.forEach(conf -> PlayerClaimData.get(player).addDisplayClaim(conf, EnumDisplayType.CONFLICT, player.blockPosition().getY()));
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, ChatFormatting.RED), false);
|
||||
return false;
|
||||
}
|
||||
int diff = newClaim.getPlane() - claim.getPlane();
|
||||
@ -191,23 +191,23 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
boolean enoughBlocks = claim.isAdminClaim() || data.isAdminIgnoreClaim() || newData.canUseClaimBlocks(diff);
|
||||
if (enoughBlocks) {
|
||||
Flan.log("Resizing claim {}", claim);
|
||||
this.deleteClaim(claim, false, EnumEditMode.DEFAULT, player.getServerWorld());
|
||||
this.deleteClaim(claim, false, EnumEditMode.DEFAULT, player.getLevel());
|
||||
claim.copySizes(newClaim);
|
||||
this.addClaim(claim);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY());
|
||||
if (newData instanceof PlayerClaimData)
|
||||
((PlayerClaimData) newData).updateScoreboard();
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeSuccess, Formatting.GOLD), false);
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
||||
newData.getClaimBlocks(), newData.getAdditionalClaims(), newData.usedClaimBlocks()), Formatting.GOLD), false);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeSuccess, ChatFormatting.GOLD), false);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
||||
newData.getClaimBlocks(), newData.getAdditionalClaims(), newData.usedClaimBlocks()), ChatFormatting.GOLD), false);
|
||||
return true;
|
||||
}
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.notEnoughBlocks, Formatting.RED), false);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.notEnoughBlocks, ChatFormatting.RED), false);
|
||||
return false;
|
||||
}
|
||||
|
||||
public Claim getClaimAt(BlockPos pos) {
|
||||
long chunk = ChunkPos.toLong(pos.getX() >> 4, pos.getZ() >> 4);
|
||||
long chunk = ChunkPos.asLong(pos.getX() >> 4, pos.getZ() >> 4);
|
||||
List<Claim> list = this.claims.get(chunk);
|
||||
if (list != null)
|
||||
for (Claim claim : list) {
|
||||
@ -233,7 +233,7 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
int[] pos = getChunkPos(claim);
|
||||
for (int x = pos[0]; x <= pos[1]; x++)
|
||||
for (int z = pos[2]; z <= pos[3]; z++) {
|
||||
this.claims.merge(ChunkPos.toLong(x, z), Lists.newArrayList(claim), (old, val) -> {
|
||||
this.claims.merge(ChunkPos.asLong(x, z), Lists.newArrayList(claim), (old, val) -> {
|
||||
old.add(claim);
|
||||
return old;
|
||||
});
|
||||
@ -245,8 +245,8 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
});
|
||||
}
|
||||
|
||||
public boolean transferOwner(Claim claim, ServerPlayerEntity player, UUID newOwner) {
|
||||
if (!player.getUuid().equals(claim.getOwner()))
|
||||
public boolean transferOwner(Claim claim, ServerPlayer player, UUID newOwner) {
|
||||
if (!player.getUUID().equals(claim.getOwner()))
|
||||
return false;
|
||||
this.playerClaimMap.merge(claim.getOwner(), new HashSet<>(), (old, val) -> {
|
||||
old.remove(claim);
|
||||
@ -281,9 +281,9 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public void read(MinecraftServer server, ServerWorld world) {
|
||||
Flan.log("Loading claim data for world {}", world.getRegistryKey());
|
||||
Path dir = ConfigHandler.getClaimSavePath(server, world.getRegistryKey());
|
||||
public void read(MinecraftServer server, ServerLevel world) {
|
||||
Flan.log("Loading claim data for world {}", world.dimension());
|
||||
Path dir = ConfigHandler.getClaimSavePath(server, world.dimension());
|
||||
if (Files.exists(dir)) {
|
||||
try {
|
||||
for (Path file : Files.walk(dir).filter(Files::isRegularFile).collect(Collectors.toSet())) {
|
||||
@ -310,7 +310,7 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
}
|
||||
}
|
||||
|
||||
public void save(MinecraftServer server, RegistryKey<World> reg) {
|
||||
public void save(MinecraftServer server, ResourceKey<Level> reg) {
|
||||
Flan.log("Saving claims for world {}", reg);
|
||||
Path dir = ConfigHandler.getClaimSavePath(server, reg);
|
||||
try {
|
||||
@ -354,11 +354,11 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean readGriefPreventionData(MinecraftServer server, ServerCommandSource src) {
|
||||
public static boolean readGriefPreventionData(MinecraftServer server, CommandSourceStack src) {
|
||||
Yaml yml = new Yaml();
|
||||
File griefPrevention = server.getSavePath(WorldSavePath.ROOT).resolve("plugins/GriefPreventionData/ClaimData").toFile();
|
||||
File griefPrevention = server.getWorldPath(LevelResource.ROOT).resolve("plugins/GriefPreventionData/ClaimData").toFile();
|
||||
if (!griefPrevention.exists()) {
|
||||
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.cantFindData, griefPrevention.getAbsolutePath()), Formatting.DARK_RED), false);
|
||||
src.sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.cantFindData, griefPrevention.getAbsolutePath()), ChatFormatting.DARK_RED), false);
|
||||
return false;
|
||||
}
|
||||
Map<File, List<File>> subClaimMap = new HashMap<>();
|
||||
@ -392,7 +392,7 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
try {
|
||||
intFileMap.put(Integer.valueOf(f.getName().replace(".yml", "")), f);
|
||||
} catch (NumberFormatException e) {
|
||||
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.errorFile, f.getName(), Formatting.RED)), false);
|
||||
src.sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.errorFile, f.getName(), ChatFormatting.RED)), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -413,28 +413,28 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
}
|
||||
for (File parent : intFileMap.values()) {
|
||||
try {
|
||||
Pair<ServerWorld, Claim> parentClaim = parseFromYaml(parent, yml, server, perms);
|
||||
Tuple<ServerLevel, Claim> parentClaim = parseFromYaml(parent, yml, server, perms);
|
||||
List<File> childs = subClaimMap.get(parent);
|
||||
if (childs != null && !childs.isEmpty()) {
|
||||
for (File childF : childs)
|
||||
parentClaim.getRight().addSubClaimGriefprevention(parseFromYaml(childF, yml, server, perms).getRight());
|
||||
parentClaim.getB().addSubClaimGriefprevention(parseFromYaml(childF, yml, server, perms).getB());
|
||||
}
|
||||
ClaimStorage storage = ClaimStorage.get(parentClaim.getLeft());
|
||||
Set<Claim> conflicts = storage.conflicts(parentClaim.getRight(), null);
|
||||
ClaimStorage storage = ClaimStorage.get(parentClaim.getA());
|
||||
Set<Claim> conflicts = storage.conflicts(parentClaim.getB(), null);
|
||||
if (conflicts.isEmpty()) {
|
||||
parentClaim.getRight().setClaimID(storage.generateUUID());
|
||||
storage.addClaim(parentClaim.getRight());
|
||||
parentClaim.getB().setClaimID(storage.generateUUID());
|
||||
storage.addClaim(parentClaim.getB());
|
||||
} else {
|
||||
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.readConflict, parent.getName(), conflicts), Formatting.DARK_RED), false);
|
||||
src.sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.readConflict, parent.getName(), conflicts), ChatFormatting.DARK_RED), false);
|
||||
for (Claim claim : conflicts) {
|
||||
int[] dim = claim.getDimensions();
|
||||
MutableText text = PermHelper.simpleColoredText(String.format("@[x=%d;z=%d]", dim[0], dim[2]), Formatting.RED);
|
||||
text.setStyle(text.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/tp @s " + dim[0] + " ~ " + dim[2])).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableText("chat.coordinates.tooltip"))));
|
||||
src.sendFeedback(text, false);
|
||||
MutableComponent text = PermHelper.simpleColoredText(String.format("@[x=%d;z=%d]", dim[0], dim[2]), ChatFormatting.RED);
|
||||
text.setStyle(text.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/tp @s " + dim[0] + " ~ " + dim[2])).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableComponent("chat.coordinates.tooltip"))));
|
||||
src.sendSuccess(text, false);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.errorFile, parent.getName(), Formatting.RED)), false);
|
||||
src.sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.errorFile, parent.getName(), ChatFormatting.RED)), false);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -451,8 +451,8 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
return set;
|
||||
}
|
||||
|
||||
private static Pair<ServerWorld, Claim> parseFromYaml(File file, Yaml yml, MinecraftServer server,
|
||||
Map<String, Set<ClaimPermission>> perms) throws IOException {
|
||||
private static Tuple<ServerLevel, Claim> parseFromYaml(File file, Yaml yml, MinecraftServer server,
|
||||
Map<String, Set<ClaimPermission>> perms) throws IOException {
|
||||
FileReader reader = new FileReader(file);
|
||||
Map<String, Object> values = yml.load(reader);
|
||||
reader.close();
|
||||
@ -465,7 +465,7 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
List<String> accessors = readList(values, "Accessors");
|
||||
String[] lesserCorner = values.get("Lesser Boundary Corner").toString().split(";");
|
||||
String[] greaterCorner = values.get("Greater Boundary Corner").toString().split(";");
|
||||
ServerWorld world = server.getWorld(worldRegFromString(lesserCorner[0]));
|
||||
ServerLevel world = server.getLevel(worldRegFromString(lesserCorner[0]));
|
||||
Claim claim = new Claim(Integer.parseInt(lesserCorner[1]), Integer.parseInt(greaterCorner[1]),
|
||||
Integer.parseInt(lesserCorner[3]), Integer.parseInt(greaterCorner[3]), ConfigHandler.config.defaultClaimDepth == 255 ? 0 :
|
||||
Integer.parseInt(lesserCorner[2]), owner, world);
|
||||
@ -513,7 +513,7 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
accessors.forEach(s -> claim.setPlayerGroup(UUID.fromString(s), "Accessors", true));
|
||||
}
|
||||
}
|
||||
return new Pair<>(world, claim);
|
||||
return new Tuple<>(world, claim);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -524,11 +524,11 @@ public class ClaimStorage implements IPermissionStorage {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public static RegistryKey<World> worldRegFromString(String spigot) {
|
||||
public static ResourceKey<Level> worldRegFromString(String spigot) {
|
||||
if (spigot.equals("world_the_end"))
|
||||
return World.END;
|
||||
return Level.END;
|
||||
if (spigot.equals("world_nether"))
|
||||
return World.NETHER;
|
||||
return World.OVERWORLD;
|
||||
return Level.NETHER;
|
||||
return Level.OVERWORLD;
|
||||
}
|
||||
}
|
||||
|
@ -6,27 +6,27 @@ import io.github.flemmli97.flan.api.permission.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.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class GlobalClaim implements IPermissionContainer {
|
||||
|
||||
private final ServerWorld world;
|
||||
private final ServerLevel world;
|
||||
|
||||
public GlobalClaim(ServerWorld world) {
|
||||
public GlobalClaim(ServerLevel world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(ServerPlayerEntity player, ClaimPermission perm, BlockPos pos, boolean message) {
|
||||
public boolean canInteract(ServerPlayer player, ClaimPermission perm, BlockPos pos, boolean message) {
|
||||
Config.GlobalType global = ConfigHandler.config.getGlobal(this.world, perm);
|
||||
if (global != Config.GlobalType.NONE && (player == null || !PlayerClaimData.get(player).isAdminIgnoreClaim())) {
|
||||
if (global.getValue())
|
||||
return true;
|
||||
if (message)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, ChatFormatting.DARK_RED), true);
|
||||
return false;
|
||||
}
|
||||
return perm != PermissionRegistry.MOBSPAWN && perm != PermissionRegistry.ANIMALSPAWN;
|
||||
|
@ -1,19 +1,20 @@
|
||||
package io.github.flemmli97.flan.claim;
|
||||
|
||||
import net.minecraft.particle.DustParticleEffect;
|
||||
import com.mojang.math.Vector3f;
|
||||
import net.minecraft.core.particles.DustParticleOptions;
|
||||
|
||||
public class ParticleIndicators {
|
||||
|
||||
public static final DustParticleEffect CLAIMCORNER = new DustParticleEffect(194 / 255f, 130 / 255f, 4 / 255f, 3);
|
||||
public static final DustParticleEffect CLAIMMIDDLE = new DustParticleEffect(237 / 255f, 187 / 255f, 38 / 255f, 3);
|
||||
public static final DustParticleOptions CLAIMCORNER = new DustParticleOptions(new Vector3f(194 / 255f, 130 / 255f, 4 / 255f), 3);
|
||||
public static final DustParticleOptions CLAIMMIDDLE = new DustParticleOptions(new Vector3f(237 / 255f, 187 / 255f, 38 / 255f), 3);
|
||||
|
||||
public static final DustParticleEffect SUBCLAIMCORNER = new DustParticleEffect(125 / 255f, 125 / 255f, 125 / 255f, 3);
|
||||
public static final DustParticleEffect SUBCLAIMMIDDLE = new DustParticleEffect(194 / 255f, 194 / 255f, 194 / 255f, 3);
|
||||
public static final DustParticleOptions SUBCLAIMCORNER = new DustParticleOptions(new Vector3f(125 / 255f, 125 / 255f, 125 / 255f), 3);
|
||||
public static final DustParticleOptions SUBCLAIMMIDDLE = new DustParticleOptions(new Vector3f(194 / 255f, 194 / 255f, 194 / 255f), 3);
|
||||
|
||||
public static final DustParticleEffect EDITCLAIMCORNER = new DustParticleEffect(12 / 255f, 110 / 255f, 103 / 255f, 3);
|
||||
public static final DustParticleEffect EDITCLAIMMIDDLE = new DustParticleEffect(20 / 255f, 186 / 255f, 175 / 255f, 3);
|
||||
public static final DustParticleOptions EDITCLAIMCORNER = new DustParticleOptions(new Vector3f(12 / 255f, 110 / 255f, 103 / 255f), 3);
|
||||
public static final DustParticleOptions EDITCLAIMMIDDLE = new DustParticleOptions(new Vector3f(20 / 255f, 186 / 255f, 175 / 255f), 3);
|
||||
|
||||
public static final DustParticleEffect SETCORNER = new DustParticleEffect(18 / 255f, 38 / 255f, 150 / 255f, 3);
|
||||
public static final DustParticleOptions SETCORNER = new DustParticleOptions(new Vector3f(18 / 255f, 38 / 255f, 150 / 255f), 3);
|
||||
|
||||
public static final DustParticleEffect OVERLAPCLAIM = new DustParticleEffect(255 / 255f, 0 / 255f, 0 / 255f, 3);
|
||||
public static final DustParticleOptions OVERLAPCLAIM = new DustParticleOptions(new Vector3f(255 / 255f, 0 / 255f, 0 / 255f), 3);
|
||||
}
|
||||
|
@ -2,19 +2,19 @@ package io.github.flemmli97.flan.claim;
|
||||
|
||||
import io.github.flemmli97.flan.api.permission.ClaimPermission;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class PermHelper {
|
||||
|
||||
public static boolean check(ServerPlayerEntity player, BlockPos pos, Claim claim, ClaimPermission perm, Consumer<Optional<Boolean>> cons) {
|
||||
public static boolean check(ServerPlayer player, BlockPos pos, Claim claim, ClaimPermission perm, Consumer<Optional<Boolean>> cons) {
|
||||
if (claim == null) {
|
||||
cons.accept(Optional.empty());
|
||||
return false;
|
||||
@ -24,26 +24,26 @@ public class PermHelper {
|
||||
return hasPerm;
|
||||
}
|
||||
|
||||
public static Claim checkReturn(ServerPlayerEntity player, ClaimPermission perm, Consumer<Optional<Boolean>> cons) {
|
||||
BlockPos pos = player.getBlockPos();
|
||||
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(pos);
|
||||
public static Claim checkReturn(ServerPlayer player, ClaimPermission perm, Consumer<Optional<Boolean>> cons) {
|
||||
BlockPos pos = player.blockPosition();
|
||||
Claim claim = ClaimStorage.get(player.getLevel()).getClaimAt(pos);
|
||||
return check(player, pos, claim, perm, cons) ? claim : null;
|
||||
}
|
||||
|
||||
public static void noClaimMessage(ServerPlayerEntity player) {
|
||||
player.sendMessage(new LiteralText(ConfigHandler.lang.noClaim).setStyle(Style.EMPTY.withFormatting(Formatting.DARK_RED)), false);
|
||||
public static void noClaimMessage(ServerPlayer player) {
|
||||
player.displayClientMessage(new TextComponent(ConfigHandler.lang.noClaim).setStyle(Style.EMPTY.applyFormat(ChatFormatting.DARK_RED)), false);
|
||||
}
|
||||
|
||||
public static Consumer<Optional<Boolean>> genericNoPermMessage(ServerPlayerEntity player) {
|
||||
public static Consumer<Optional<Boolean>> genericNoPermMessage(ServerPlayer player) {
|
||||
return (b -> {
|
||||
if (!b.isPresent())
|
||||
PermHelper.noClaimMessage(player);
|
||||
else if (!b.get())
|
||||
player.sendMessage(simpleColoredText(ConfigHandler.lang.noPermission, Formatting.DARK_RED), false);
|
||||
player.displayClientMessage(simpleColoredText(ConfigHandler.lang.noPermission, ChatFormatting.DARK_RED), false);
|
||||
});
|
||||
}
|
||||
|
||||
public static MutableText simpleColoredText(String text, Formatting... formatting) {
|
||||
return new LiteralText(text).setStyle(formatting != null ? Style.EMPTY.withFormatting(formatting) : Style.EMPTY);
|
||||
public static MutableComponent simpleColoredText(String text, ChatFormatting... formatting) {
|
||||
return new TextComponent(text).setStyle(formatting != null ? Style.EMPTY.applyFormats(formatting) : Style.EMPTY);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,11 +7,11 @@ import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.ClickEvent;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -19,64 +19,64 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class CommandHelp {
|
||||
|
||||
public static int helpMessage(CommandContext<ServerCommandSource> context, Collection<CommandNode<ServerCommandSource>> nodes) {
|
||||
public static int helpMessage(CommandContext<CommandSourceStack> context, Collection<CommandNode<CommandSourceStack>> nodes) {
|
||||
int page = IntegerArgumentType.getInteger(context, "page");
|
||||
return helpMessage(context, page, nodes);
|
||||
}
|
||||
|
||||
public static int helpMessage(CommandContext<ServerCommandSource> context, int page, Collection<CommandNode<ServerCommandSource>> nodes) {
|
||||
public static int helpMessage(CommandContext<CommandSourceStack> context, int page, Collection<CommandNode<CommandSourceStack>> nodes) {
|
||||
List<String> subCommands = registeredCommands(context, nodes);
|
||||
subCommands.remove("?");
|
||||
int max = subCommands.size() / 8;
|
||||
if (page > max)
|
||||
page = max;
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.helpHeader, page), Formatting.GOLD), false);
|
||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.helpHeader, page), ChatFormatting.GOLD), false);
|
||||
for (int i = 8 * page; i < 8 * (page + 1); i++)
|
||||
if (i < subCommands.size()) {
|
||||
MutableText cmdText = PermHelper.simpleColoredText("- " + subCommands.get(i), Formatting.GRAY);
|
||||
context.getSource().sendFeedback(cmdText.fillStyle(cmdText.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/flan help cmd " + subCommands.get(i)))), false);
|
||||
MutableComponent cmdText = PermHelper.simpleColoredText("- " + subCommands.get(i), ChatFormatting.GRAY);
|
||||
context.getSource().sendSuccess(cmdText.withStyle(cmdText.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/flan help cmd " + subCommands.get(i)))), false);
|
||||
}
|
||||
MutableText pageText = PermHelper.simpleColoredText((page > 0 ? " " : "") + " ", Formatting.DARK_GREEN);
|
||||
MutableComponent pageText = PermHelper.simpleColoredText((page > 0 ? " " : "") + " ", ChatFormatting.DARK_GREEN);
|
||||
if (page > 0) {
|
||||
MutableText pageTextBack = PermHelper.simpleColoredText("<<", Formatting.DARK_GREEN);
|
||||
pageTextBack.fillStyle(pageTextBack.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/flan help " + (page - 1))));
|
||||
MutableComponent pageTextBack = PermHelper.simpleColoredText("<<", ChatFormatting.DARK_GREEN);
|
||||
pageTextBack.withStyle(pageTextBack.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/flan help " + (page - 1))));
|
||||
pageText = pageTextBack.append(pageText);
|
||||
}
|
||||
if (page < max) {
|
||||
MutableText pageTextNext = PermHelper.simpleColoredText(">>");
|
||||
pageTextNext.fillStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/flan help " + (page + 1))));
|
||||
MutableComponent pageTextNext = PermHelper.simpleColoredText(">>");
|
||||
pageTextNext.withStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/flan help " + (page + 1))));
|
||||
pageText = pageText.append(pageTextNext);
|
||||
}
|
||||
context.getSource().sendFeedback(pageText, false);
|
||||
context.getSource().sendSuccess(pageText, false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
public static int helpCmd(CommandContext<ServerCommandSource> context) {
|
||||
public static int helpCmd(CommandContext<CommandSourceStack> context) {
|
||||
String command = StringArgumentType.getString(context, "command");
|
||||
return helpCmd(context, command);
|
||||
}
|
||||
|
||||
public static int helpCmd(CommandContext<ServerCommandSource> context, String command) {
|
||||
public static int helpCmd(CommandContext<CommandSourceStack> context, String command) {
|
||||
String[] cmdHelp = ConfigHandler.lang.cmdLang.getCommandHelp(command);
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.helpCmdHeader, Formatting.DARK_GREEN), false);
|
||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.lang.helpCmdHeader, ChatFormatting.DARK_GREEN), false);
|
||||
for (int i = 0; i < cmdHelp.length; i++) {
|
||||
if (i == 0) {
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.helpCmdSyntax, cmdHelp[i]), Formatting.GOLD), false);
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(""), false);
|
||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.helpCmdSyntax, cmdHelp[i]), ChatFormatting.GOLD), false);
|
||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(""), false);
|
||||
} else {
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(cmdHelp[i], Formatting.GOLD), false);
|
||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(cmdHelp[i], ChatFormatting.GOLD), false);
|
||||
}
|
||||
}
|
||||
if (command.equals("help")) {
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.wiki, Formatting.GOLD), false);
|
||||
MutableText wiki = PermHelper.simpleColoredText("https://github.com/Flemmli97/Flan/wiki", Formatting.GREEN);
|
||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.lang.wiki, ChatFormatting.GOLD), false);
|
||||
MutableComponent wiki = PermHelper.simpleColoredText("https://github.com/Flemmli97/Flan/wiki", ChatFormatting.GREEN);
|
||||
wiki.setStyle(wiki.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/Flemmli97/Flan/wiki")));
|
||||
context.getSource().sendFeedback(wiki, false);
|
||||
context.getSource().sendSuccess(wiki, false);
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
public static List<String> registeredCommands(CommandContext<ServerCommandSource> context, Collection<CommandNode<ServerCommandSource>> nodes) {
|
||||
public static List<String> registeredCommands(CommandContext<CommandSourceStack> context, Collection<CommandNode<CommandSourceStack>> nodes) {
|
||||
return nodes.stream().filter(node -> node.canUse(context.getSource())).map(CommandNode::getName).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,12 @@ import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.ClaimStorage;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.argument.GameProfileArgumentType;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.commands.arguments.GameProfileArgument;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -32,21 +32,21 @@ public class CommandHelpers {
|
||||
|
||||
private static final Pattern allowed = Pattern.compile("[a-zA-Z0-9_+.-]+");
|
||||
|
||||
public static CompletableFuture<Suggestions> claimSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder build, UUID owner) {
|
||||
return CommandSource.suggestMatching(ClaimStorage.get(context.getSource().getWorld()).allClaimsFromPlayer(owner)
|
||||
public static CompletableFuture<Suggestions> claimSuggestions(CommandContext<CommandSourceStack> context, SuggestionsBuilder build, UUID owner) {
|
||||
return SharedSuggestionProvider.suggest(ClaimStorage.get(context.getSource().getLevel()).allClaimsFromPlayer(owner)
|
||||
.stream().map(claim -> claim.getClaimName().isEmpty() ? claim.getClaimID().toString() : claim.getClaimName()).collect(Collectors.toList()), build);
|
||||
}
|
||||
|
||||
public static GameProfile singleProfile(CommandContext<ServerCommandSource> context, String arg) throws CommandSyntaxException {
|
||||
Collection<GameProfile> profs = GameProfileArgumentType.getProfileArgument(context, arg);
|
||||
public static GameProfile singleProfile(CommandContext<CommandSourceStack> context, String arg) throws CommandSyntaxException {
|
||||
Collection<GameProfile> profs = GameProfileArgument.getGameProfiles(context, arg);
|
||||
if (profs.size() != 1) {
|
||||
throw new SimpleCommandExceptionType(() -> ConfigHandler.lang.onlyOnePlayer).create();
|
||||
}
|
||||
return profs.stream().findFirst().get();
|
||||
}
|
||||
|
||||
public static CompletableFuture<Suggestions> permSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder build, boolean group) {
|
||||
ServerWorld world = context.getSource().getWorld();
|
||||
public static CompletableFuture<Suggestions> permSuggestions(CommandContext<CommandSourceStack> context, SuggestionsBuilder build, boolean group) {
|
||||
ServerLevel world = context.getSource().getLevel();
|
||||
Claim claim = ClaimStorage.get(world).getClaimAt(new BlockPos(context.getSource().getPosition()));
|
||||
boolean admin = claim != null && claim.isAdminClaim();
|
||||
List<String> allowedPerms = new ArrayList<>();
|
||||
@ -57,15 +57,15 @@ public class CommandHelpers {
|
||||
if (!group || !PermissionRegistry.globalPerms().contains(perm))
|
||||
allowedPerms.add(perm.id);
|
||||
}
|
||||
return CommandSource.suggestMatching(allowedPerms, build);
|
||||
return SharedSuggestionProvider.suggest(allowedPerms, build);
|
||||
}
|
||||
|
||||
public static CompletableFuture<Suggestions> groupSuggestion(CommandContext<ServerCommandSource> context, SuggestionsBuilder build) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
public static CompletableFuture<Suggestions> groupSuggestion(CommandContext<CommandSourceStack> context, SuggestionsBuilder build) throws CommandSyntaxException {
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
List<String> list = new ArrayList<>();
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
Claim claim = storage.getClaimAt(player.getBlockPos());
|
||||
if (claim != null && claim.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos())) {
|
||||
ClaimStorage storage = ClaimStorage.get(player.getLevel());
|
||||
Claim claim = storage.getClaimAt(player.blockPosition());
|
||||
if (claim != null && claim.canInteract(player, PermissionRegistry.EDITPERMS, player.blockPosition())) {
|
||||
list = claim.groups();
|
||||
}
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
@ -73,11 +73,11 @@ public class CommandHelpers {
|
||||
continue;
|
||||
list.set(i, '\"' + list.get(i) + '\"');
|
||||
}
|
||||
return CommandSource.suggestMatching(list, build);
|
||||
return SharedSuggestionProvider.suggest(list, build);
|
||||
}
|
||||
|
||||
public static CompletableFuture<Suggestions> personalGroupSuggestion(CommandContext<ServerCommandSource> context, SuggestionsBuilder build) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
public static CompletableFuture<Suggestions> personalGroupSuggestion(CommandContext<CommandSourceStack> context, SuggestionsBuilder build) throws CommandSyntaxException {
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
List<String> list = new ArrayList<>(PlayerClaimData.get(player).playerDefaultGroups().keySet());
|
||||
list.sort(null);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
@ -85,7 +85,7 @@ public class CommandHelpers {
|
||||
continue;
|
||||
list.set(i, '\"' + list.get(i) + '\"');
|
||||
}
|
||||
return CommandSource.suggestMatching(list, build);
|
||||
return SharedSuggestionProvider.suggest(list, build);
|
||||
}
|
||||
|
||||
public static <T extends Enum<T>> T parseEnum(Class<T> clss, String name, T fallback) {
|
||||
@ -97,6 +97,6 @@ public class CommandHelpers {
|
||||
}
|
||||
|
||||
public static <T extends Enum<T>> CompletableFuture<Suggestions> enumSuggestion(Class<T> clss, SuggestionsBuilder build) {
|
||||
return CommandSource.suggestMatching(Stream.of(clss.getEnumConstants()).map(Object::toString), build);
|
||||
return SharedSuggestionProvider.suggest(Stream.of(clss.getEnumConstants()).map(Object::toString), build);
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,11 @@ import io.github.flemmli97.flan.CrossPlatformStuff;
|
||||
import io.github.flemmli97.flan.Flan;
|
||||
import io.github.flemmli97.flan.api.permission.ClaimPermission;
|
||||
import io.github.flemmli97.flan.api.permission.PermissionRegistry;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@ -144,9 +144,9 @@ public class Config {
|
||||
this.worldWhitelist = ConfigHandler.fromJson(obj, "worldWhitelist", this.worldWhitelist);
|
||||
|
||||
if (obj.has("claimingItem"))
|
||||
this.claimingItem = CrossPlatformStuff.registryItems().getFromId(new Identifier((obj.get("claimingItem").getAsString())));
|
||||
this.claimingItem = CrossPlatformStuff.registryItems().getFromId(new ResourceLocation((obj.get("claimingItem").getAsString())));
|
||||
if (obj.has("inspectionItem"))
|
||||
this.inspectionItem = CrossPlatformStuff.registryItems().getFromId(new Identifier((obj.get("inspectionItem").getAsString())));
|
||||
this.inspectionItem = CrossPlatformStuff.registryItems().getFromId(new ResourceLocation((obj.get("inspectionItem").getAsString())));
|
||||
this.claimDisplayTime = ConfigHandler.fromJson(obj, "claimDisplayTime", this.claimDisplayTime);
|
||||
this.permissionLevel = ConfigHandler.fromJson(obj, "permissionLevel", this.permissionLevel);
|
||||
|
||||
@ -291,26 +291,26 @@ public class Config {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean globallyDefined(ServerWorld world, ClaimPermission perm) {
|
||||
public boolean globallyDefined(ServerLevel world, ClaimPermission perm) {
|
||||
return !this.getGlobal(world, perm).canModify();
|
||||
}
|
||||
|
||||
public GlobalType getGlobal(ServerWorld world, ClaimPermission perm) {
|
||||
public GlobalType getGlobal(ServerLevel world, ClaimPermission perm) {
|
||||
//Update permission map if not done already
|
||||
Map<ClaimPermission, GlobalType> allMap = ConfigHandler.config.globalDefaultPerms.get("*");
|
||||
if (allMap != null) {
|
||||
world.getServer().getWorlds().forEach(w -> {
|
||||
Map<ClaimPermission, GlobalType> wMap = ConfigHandler.config.globalDefaultPerms.getOrDefault(w.getRegistryKey().getValue().toString(), new HashMap<>());
|
||||
world.getServer().getAllLevels().forEach(w -> {
|
||||
Map<ClaimPermission, GlobalType> wMap = ConfigHandler.config.globalDefaultPerms.getOrDefault(w.dimension().location().toString(), new HashMap<>());
|
||||
allMap.forEach((key, value) -> {
|
||||
if (!wMap.containsKey(key))
|
||||
wMap.put(key, value);
|
||||
});
|
||||
ConfigHandler.config.globalDefaultPerms.put(w.getRegistryKey().getValue().toString(), wMap);
|
||||
ConfigHandler.config.globalDefaultPerms.put(w.dimension().location().toString(), wMap);
|
||||
});
|
||||
ConfigHandler.config.globalDefaultPerms.remove("*");
|
||||
}
|
||||
|
||||
Map<ClaimPermission, GlobalType> permMap = ConfigHandler.config.globalDefaultPerms.get(world.getRegistryKey().getValue().toString());
|
||||
Map<ClaimPermission, GlobalType> permMap = ConfigHandler.config.globalDefaultPerms.get(world.dimension().location().toString());
|
||||
return permMap == null ? GlobalType.NONE : permMap.getOrDefault(perm, GlobalType.NONE);
|
||||
}
|
||||
|
||||
|
@ -4,11 +4,11 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
@ -20,7 +20,7 @@ public class ConfigHandler {
|
||||
|
||||
public static Config config;
|
||||
public static LangConfig lang;
|
||||
private static Map<RegistryKey<World>, Path> claimSavePath = new HashMap<>();
|
||||
private static Map<ResourceKey<Level>, Path> claimSavePath = new HashMap<>();
|
||||
private static Path playerSavePath;
|
||||
|
||||
public static void serverLoad(MinecraftServer server) {
|
||||
@ -34,13 +34,13 @@ public class ConfigHandler {
|
||||
lang.load();
|
||||
}
|
||||
|
||||
public static Path getClaimSavePath(MinecraftServer server, RegistryKey<World> reg) {
|
||||
return claimSavePath.computeIfAbsent(reg, r -> DimensionType.getSaveDirectory(r, server.getSavePath(WorldSavePath.ROOT).toFile()).toPath().resolve("data").resolve("claims"));
|
||||
public static Path getClaimSavePath(MinecraftServer server, ResourceKey<Level> reg) {
|
||||
return claimSavePath.computeIfAbsent(reg, r -> DimensionType.getStorageFolder(r, server.getWorldPath(LevelResource.ROOT)).resolve("data").resolve("claims"));
|
||||
}
|
||||
|
||||
public static Path getPlayerSavePath(MinecraftServer server) {
|
||||
if (playerSavePath == null)
|
||||
playerSavePath = server.getSavePath(WorldSavePath.PLAYERDATA).resolve("claimData");
|
||||
playerSavePath = server.getWorldPath(LevelResource.PLAYER_DATA_DIR).resolve("claimData");
|
||||
return playerSavePath;
|
||||
}
|
||||
|
||||
|
@ -10,49 +10,49 @@ import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.gui.LockedLecternScreenHandler;
|
||||
import io.github.flemmli97.flan.player.EnumDisplayType;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.DoorBlock;
|
||||
import net.minecraft.block.LecternBlock;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.LecternBlockEntity;
|
||||
import net.minecraft.block.enums.DoubleBlockHalf;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.DoorBlock;
|
||||
import net.minecraft.world.level.block.LecternBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.LecternBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlockInteractEvents {
|
||||
|
||||
public static ActionResult startBreakBlocks(PlayerEntity player, World world, Hand hand, BlockPos pos, Direction direction) {
|
||||
return breakBlocks(world, player, pos, world.getBlockState(pos), world.getBlockEntity(pos)) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
public static InteractionResult startBreakBlocks(Player player, Level world, InteractionHand hand, BlockPos pos, Direction direction) {
|
||||
return breakBlocks(world, player, pos, world.getBlockState(pos), world.getBlockEntity(pos)) ? InteractionResult.PASS : InteractionResult.FAIL;
|
||||
}
|
||||
|
||||
public static boolean breakBlocks(World world, PlayerEntity p, BlockPos pos, BlockState state, BlockEntity tile) {
|
||||
if (world.isClient || p.isSpectator())
|
||||
public static boolean breakBlocks(Level world, Player p, BlockPos pos, BlockState state, BlockEntity tile) {
|
||||
if (world.isClientSide || p.isSpectator())
|
||||
return true;
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
ServerPlayer player = (ServerPlayer) p;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) world);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null) {
|
||||
Identifier id = CrossPlatformStuff.registryBlocks().getIDFrom(state.getBlock());
|
||||
ResourceLocation id = CrossPlatformStuff.registryBlocks().getIDFrom(state.getBlock());
|
||||
if (contains(id, world.getBlockEntity(pos), ConfigHandler.config.breakBlockBlacklist, ConfigHandler.config.breakBETagBlacklist))
|
||||
return true;
|
||||
if (!claim.canInteract(player, PermissionRegistry.BREAK, pos, true)) {
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -60,92 +60,92 @@ public class BlockInteractEvents {
|
||||
}
|
||||
|
||||
//Right click block
|
||||
public static ActionResult useBlocks(PlayerEntity p, World world, Hand hand, BlockHitResult hitResult) {
|
||||
if (world.isClient)
|
||||
return ActionResult.PASS;
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ItemStack stack = player.getStackInHand(hand);
|
||||
public static InteractionResult useBlocks(Player p, Level world, InteractionHand hand, BlockHitResult hitResult) {
|
||||
if (world.isClientSide)
|
||||
return InteractionResult.PASS;
|
||||
ServerPlayer player = (ServerPlayer) p;
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
if (stack.getItem() == ConfigHandler.config.claimingItem) {
|
||||
ItemInteractEvents.claimLandHandling(player, hitResult.getBlockPos());
|
||||
return ActionResult.SUCCESS;
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
if (stack.getItem() == ConfigHandler.config.inspectionItem) {
|
||||
ItemInteractEvents.inspect(player, hitResult.getBlockPos());
|
||||
return ActionResult.SUCCESS;
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) world);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(hitResult.getBlockPos());
|
||||
if (claim != null) {
|
||||
BlockState state = world.getBlockState(hitResult.getBlockPos());
|
||||
Identifier id = CrossPlatformStuff.registryBlocks().getIDFrom(state.getBlock());
|
||||
ResourceLocation id = CrossPlatformStuff.registryBlocks().getIDFrom(state.getBlock());
|
||||
BlockEntity blockEntity = world.getBlockEntity(hitResult.getBlockPos());
|
||||
if (contains(id, blockEntity, ConfigHandler.config.interactBlockBlacklist, ConfigHandler.config.interactBETagBlacklist))
|
||||
return ActionResult.PASS;
|
||||
return InteractionResult.PASS;
|
||||
ClaimPermission perm = ObjectToPermissionMap.getFromBlock(state.getBlock());
|
||||
if (perm == PermissionRegistry.PROJECTILES)
|
||||
perm = PermissionRegistry.OPENCONTAINER;
|
||||
//Pressureplate handled elsewhere
|
||||
if (perm != null && perm != PermissionRegistry.PRESSUREPLATE) {
|
||||
if (claim.canInteract(player, perm, hitResult.getBlockPos(), true))
|
||||
return ActionResult.PASS;
|
||||
return InteractionResult.PASS;
|
||||
if (state.getBlock() instanceof DoorBlock) {
|
||||
DoubleBlockHalf half = state.get(DoorBlock.HALF);
|
||||
DoubleBlockHalf half = state.getValue(DoorBlock.HALF);
|
||||
if (half == DoubleBlockHalf.LOWER) {
|
||||
BlockState other = world.getBlockState(hitResult.getBlockPos().up());
|
||||
player.networkHandler.sendPacket(new BlockUpdateS2CPacket(hitResult.getBlockPos().up(), other));
|
||||
BlockState other = world.getBlockState(hitResult.getBlockPos().above());
|
||||
player.connection.send(new ClientboundBlockUpdatePacket(hitResult.getBlockPos().above(), other));
|
||||
} else {
|
||||
BlockState other = world.getBlockState(hitResult.getBlockPos().down());
|
||||
player.networkHandler.sendPacket(new BlockUpdateS2CPacket(hitResult.getBlockPos().down(), other));
|
||||
BlockState other = world.getBlockState(hitResult.getBlockPos().below());
|
||||
player.connection.send(new ClientboundBlockUpdatePacket(hitResult.getBlockPos().below(), other));
|
||||
}
|
||||
}
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
return ActionResult.FAIL;
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY());
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
if (blockEntity != null) {
|
||||
if (blockEntity instanceof LecternBlockEntity) {
|
||||
if (claim.canInteract(player, PermissionRegistry.LECTERNTAKE, hitResult.getBlockPos(), false))
|
||||
return ActionResult.PASS;
|
||||
if (state.get(LecternBlock.HAS_BOOK))
|
||||
return InteractionResult.PASS;
|
||||
if (state.getValue(LecternBlock.HAS_BOOK))
|
||||
LockedLecternScreenHandler.create(player, (LecternBlockEntity) blockEntity);
|
||||
return ActionResult.FAIL;
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
if (!ConfigHandler.config.lenientBlockEntityCheck || CrossPlatformStuff.isInventoryTile(blockEntity)) {
|
||||
if (claim.canInteract(player, PermissionRegistry.OPENCONTAINER, hitResult.getBlockPos(), true))
|
||||
return ActionResult.PASS;
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
return ActionResult.FAIL;
|
||||
return InteractionResult.PASS;
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY());
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
}
|
||||
return claim.canInteract(player, PermissionRegistry.INTERACTBLOCK, hitResult.getBlockPos(), false) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, PermissionRegistry.INTERACTBLOCK, hitResult.getBlockPos(), false) ? InteractionResult.PASS : InteractionResult.FAIL;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
public static boolean contains(Identifier id, BlockEntity blockEntity, List<String> idList, List<String> tagList) {
|
||||
public static boolean contains(ResourceLocation id, BlockEntity blockEntity, List<String> idList, List<String> tagList) {
|
||||
if (idList.contains(id.getNamespace())
|
||||
|| idList.contains(id.toString()))
|
||||
return true;
|
||||
if (blockEntity != null && !tagList.isEmpty()) {
|
||||
CompoundTag nbt = blockEntity.toTag(new CompoundTag());
|
||||
CompoundTag nbt = blockEntity.saveWithoutMetadata();
|
||||
return tagList.stream().anyMatch(tag -> CrossPlatformStuff.blockDataContains(nbt, tag));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean cancelEntityBlockCollision(BlockState state, World world, BlockPos pos, Entity entity) {
|
||||
if (world.isClient)
|
||||
public static boolean cancelEntityBlockCollision(BlockState state, Level world, BlockPos pos, Entity entity) {
|
||||
if (world.isClientSide)
|
||||
return false;
|
||||
ServerPlayerEntity player = null;
|
||||
if (entity instanceof ServerPlayerEntity)
|
||||
player = (ServerPlayerEntity) entity;
|
||||
else if (entity instanceof ProjectileEntity) {
|
||||
Entity owner = ((ProjectileEntity) entity).getOwner();
|
||||
if (owner instanceof ServerPlayerEntity)
|
||||
player = (ServerPlayerEntity) owner;
|
||||
ServerPlayer player = null;
|
||||
if (entity instanceof ServerPlayer)
|
||||
player = (ServerPlayer) entity;
|
||||
else if (entity instanceof Projectile) {
|
||||
Entity owner = ((Projectile) entity).getOwner();
|
||||
if (owner instanceof ServerPlayer)
|
||||
player = (ServerPlayer) owner;
|
||||
} else if (entity instanceof ItemEntity) {
|
||||
Entity owner = ((ServerWorld) world).getEntity(((ItemEntity) entity).getThrower());
|
||||
if (owner instanceof ServerPlayerEntity)
|
||||
player = (ServerPlayerEntity) owner;
|
||||
Entity owner = ((ServerLevel) world).getEntity(((ItemEntity) entity).getThrower());
|
||||
if (owner instanceof ServerPlayer)
|
||||
player = (ServerPlayer) owner;
|
||||
}
|
||||
if (player == null)
|
||||
return false;
|
||||
@ -154,7 +154,7 @@ public class BlockInteractEvents {
|
||||
return false;
|
||||
if (perm != PermissionRegistry.PRESSUREPLATE && perm != PermissionRegistry.PORTAL)
|
||||
return false;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) world);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null)
|
||||
return !claim.canInteract(player, perm, pos, false);
|
||||
@ -162,58 +162,58 @@ public class BlockInteractEvents {
|
||||
}
|
||||
|
||||
public static boolean preventFallOn(Entity entity, double heightDifference, boolean onGround, BlockState landedState, BlockPos landedPosition) {
|
||||
if (entity.world.isClient)
|
||||
if (entity.level.isClientSide)
|
||||
return false;
|
||||
if (entity instanceof ServerPlayerEntity) {
|
||||
if (entity instanceof ServerPlayer) {
|
||||
ClaimPermission perm = ObjectToPermissionMap.getFromBlock(landedState.getBlock());
|
||||
if (perm != PermissionRegistry.TRAMPLE)
|
||||
return false;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) entity.world);
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) entity.level);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(landedPosition);
|
||||
if (claim == null)
|
||||
return false;
|
||||
return !claim.canInteract((ServerPlayerEntity) entity, perm, landedPosition, true);
|
||||
} else if (entity instanceof ProjectileEntity) {
|
||||
Entity owner = ((ProjectileEntity) entity).getOwner();
|
||||
if (owner instanceof ServerPlayerEntity) {
|
||||
return !claim.canInteract((ServerPlayer) entity, perm, landedPosition, true);
|
||||
} else if (entity instanceof Projectile) {
|
||||
Entity owner = ((Projectile) entity).getOwner();
|
||||
if (owner instanceof ServerPlayer) {
|
||||
ClaimPermission perm = ObjectToPermissionMap.getFromBlock(landedState.getBlock());
|
||||
if (perm != PermissionRegistry.TRAMPLE)
|
||||
return false;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) entity.world);
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) entity.level);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(landedPosition);
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, perm, landedPosition, true);
|
||||
return !claim.canInteract((ServerPlayer) owner, perm, landedPosition, true);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean canBreakTurtleEgg(World world, BlockPos pos, Entity entity) {
|
||||
if (world.isClient)
|
||||
public static boolean canBreakTurtleEgg(Level world, BlockPos pos, Entity entity) {
|
||||
if (world.isClientSide)
|
||||
return false;
|
||||
ServerWorld serverWorld = (ServerWorld) world;
|
||||
if (entity instanceof ServerPlayerEntity) {
|
||||
ServerLevel serverWorld = (ServerLevel) world;
|
||||
if (entity instanceof ServerPlayer) {
|
||||
ClaimStorage storage = ClaimStorage.get(serverWorld);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim == null)
|
||||
return false;
|
||||
return !claim.canInteract((ServerPlayerEntity) entity, PermissionRegistry.TRAMPLE, pos, true);
|
||||
} else if (entity instanceof ProjectileEntity) {
|
||||
Entity owner = ((ProjectileEntity) entity).getOwner();
|
||||
if (owner instanceof ServerPlayerEntity) {
|
||||
return !claim.canInteract((ServerPlayer) entity, PermissionRegistry.TRAMPLE, pos, true);
|
||||
} else if (entity instanceof Projectile) {
|
||||
Entity owner = ((Projectile) entity).getOwner();
|
||||
if (owner instanceof ServerPlayer) {
|
||||
ClaimStorage storage = ClaimStorage.get(serverWorld);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim == null)
|
||||
return false;
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, PermissionRegistry.TRAMPLE, pos, true);
|
||||
return !claim.canInteract((ServerPlayer) owner, PermissionRegistry.TRAMPLE, pos, true);
|
||||
}
|
||||
} else if (entity instanceof ItemEntity) {
|
||||
Entity owner = serverWorld.getEntity(((ItemEntity) entity).getThrower());
|
||||
if (owner instanceof ServerPlayerEntity) {
|
||||
if (owner instanceof ServerPlayer) {
|
||||
ClaimStorage storage = ClaimStorage.get(serverWorld);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim == null)
|
||||
return false;
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, PermissionRegistry.TRAMPLE, pos, true);
|
||||
return !claim.canInteract((ServerPlayer) owner, PermissionRegistry.TRAMPLE, pos, true);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -14,166 +14,166 @@ import io.github.flemmli97.flan.player.IOwnedItem;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import io.github.flemmli97.flan.player.TeleportUtils;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.boss.WitherEntity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.decoration.ArmorStandEntity;
|
||||
import net.minecraft.entity.decoration.ItemFrameEntity;
|
||||
import net.minecraft.entity.mob.EndermanEntity;
|
||||
import net.minecraft.entity.mob.Monster;
|
||||
import net.minecraft.entity.passive.SnowGolemEntity;
|
||||
import net.minecraft.entity.passive.TameableEntity;
|
||||
import net.minecraft.entity.passive.VillagerEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.projectile.PersistentProjectileEntity;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
import net.minecraft.entity.projectile.thrown.EggEntity;
|
||||
import net.minecraft.entity.projectile.thrown.EnderPearlEntity;
|
||||
import net.minecraft.entity.projectile.thrown.PotionEntity;
|
||||
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
|
||||
import net.minecraft.entity.vehicle.BoatEntity;
|
||||
import net.minecraft.entity.vehicle.StorageMinecartEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.packet.s2c.play.InventoryS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.PlayerAbilitiesS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.TamableAnimal;
|
||||
import net.minecraft.world.entity.animal.SnowGolem;
|
||||
import net.minecraft.world.entity.boss.wither.WitherBoss;
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
import net.minecraft.world.entity.decoration.ItemFrame;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.monster.EnderMan;
|
||||
import net.minecraft.world.entity.monster.Enemy;
|
||||
import net.minecraft.world.entity.npc.Villager;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.projectile.AbstractArrow;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.entity.projectile.ThrownEgg;
|
||||
import net.minecraft.world.entity.projectile.ThrownEnderpearl;
|
||||
import net.minecraft.world.entity.projectile.ThrownPotion;
|
||||
import net.minecraft.world.entity.vehicle.AbstractMinecart;
|
||||
import net.minecraft.world.entity.vehicle.AbstractMinecartContainer;
|
||||
import net.minecraft.world.entity.vehicle.Boat;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class EntityInteractEvents {
|
||||
|
||||
public static ActionResult attackEntity(PlayerEntity player, World world, Hand hand, Entity entity, EntityHitResult hitResult) {
|
||||
public static InteractionResult attackEntity(Player player, Level world, InteractionHand hand, Entity entity, EntityHitResult hitResult) {
|
||||
return attackSimple(player, entity, true);
|
||||
}
|
||||
|
||||
public static ActionResult useAtEntity(PlayerEntity player, World world, Hand hand, Entity entity, /* Nullable */ EntityHitResult hitResult) {
|
||||
if (player.world.isClient || player.isSpectator() || canInteract(entity))
|
||||
return ActionResult.PASS;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
BlockPos pos = entity.getBlockPos();
|
||||
public static InteractionResult useAtEntity(Player player, Level world, InteractionHand hand, Entity entity, /* Nullable */ EntityHitResult hitResult) {
|
||||
if (player.level.isClientSide || player.isSpectator() || canInteract(entity))
|
||||
return InteractionResult.PASS;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) world);
|
||||
BlockPos pos = entity.blockPosition();
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null) {
|
||||
if (entity instanceof ArmorStandEntity) {
|
||||
if (!claim.canInteract((ServerPlayerEntity) player, PermissionRegistry.ARMORSTAND, pos, true))
|
||||
return ActionResult.FAIL;
|
||||
if (entity instanceof ArmorStand) {
|
||||
if (!claim.canInteract((ServerPlayer) player, PermissionRegistry.ARMORSTAND, pos, true))
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
public static ActionResult useEntity(PlayerEntity p, World world, Hand hand, Entity entity) {
|
||||
if (p.world.isClient || p.isSpectator() || canInteract(entity))
|
||||
return ActionResult.PASS;
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
BlockPos pos = entity.getBlockPos();
|
||||
public static InteractionResult useEntity(Player p, Level world, InteractionHand hand, Entity entity) {
|
||||
if (p.level.isClientSide || p.isSpectator() || canInteract(entity))
|
||||
return InteractionResult.PASS;
|
||||
ServerPlayer player = (ServerPlayer) p;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) world);
|
||||
BlockPos pos = entity.blockPosition();
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null) {
|
||||
if (entity instanceof BoatEntity)
|
||||
return claim.canInteract(player, PermissionRegistry.BOAT, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
if (entity instanceof AbstractMinecartEntity) {
|
||||
if (entity instanceof StorageMinecartEntity)
|
||||
return claim.canInteract(player, PermissionRegistry.OPENCONTAINER, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, PermissionRegistry.MINECART, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
if (entity instanceof Boat)
|
||||
return claim.canInteract(player, PermissionRegistry.BOAT, pos, true) ? InteractionResult.PASS : InteractionResult.FAIL;
|
||||
if (entity instanceof AbstractMinecart) {
|
||||
if (entity instanceof AbstractMinecartContainer)
|
||||
return claim.canInteract(player, PermissionRegistry.OPENCONTAINER, pos, true) ? InteractionResult.PASS : InteractionResult.FAIL;
|
||||
return claim.canInteract(player, PermissionRegistry.MINECART, pos, true) ? InteractionResult.PASS : InteractionResult.FAIL;
|
||||
}
|
||||
if (entity instanceof VillagerEntity)
|
||||
return claim.canInteract(player, PermissionRegistry.TRADING, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
if (entity instanceof ItemFrameEntity)
|
||||
return claim.canInteract(player, PermissionRegistry.ITEMFRAMEROTATE, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
if (entity instanceof TameableEntity) {
|
||||
TameableEntity tame = (TameableEntity) entity;
|
||||
if (tame.isOwner(player))
|
||||
return ActionResult.PASS;
|
||||
if (entity instanceof Villager)
|
||||
return claim.canInteract(player, PermissionRegistry.TRADING, pos, true) ? InteractionResult.PASS : InteractionResult.FAIL;
|
||||
if (entity instanceof ItemFrame)
|
||||
return claim.canInteract(player, PermissionRegistry.ITEMFRAMEROTATE, pos, true) ? InteractionResult.PASS : InteractionResult.FAIL;
|
||||
if (entity instanceof TamableAnimal) {
|
||||
TamableAnimal tame = (TamableAnimal) entity;
|
||||
if (tame.isOwnedBy(player))
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
return claim.canInteract(player, PermissionRegistry.ANIMALINTERACT, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, PermissionRegistry.ANIMALINTERACT, pos, true) ? InteractionResult.PASS : InteractionResult.FAIL;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
public static boolean canInteract(Entity entity) {
|
||||
Identifier id = CrossPlatformStuff.registryEntities().getIDFrom(entity.getType());
|
||||
ResourceLocation id = CrossPlatformStuff.registryEntities().getIDFrom(entity.getType());
|
||||
return ConfigHandler.config.ignoredEntityTypes.contains(id.getNamespace())
|
||||
|| ConfigHandler.config.ignoredEntityTypes.contains(id.toString())
|
||||
|| entity.getScoreboardTags().stream().anyMatch(ConfigHandler.config.entityTagIgnore::contains);
|
||||
|| entity.getTags().stream().anyMatch(ConfigHandler.config.entityTagIgnore::contains);
|
||||
}
|
||||
|
||||
public static boolean projectileHit(ProjectileEntity proj, HitResult res) {
|
||||
if (proj.world.isClient)
|
||||
public static boolean projectileHit(Projectile proj, HitResult res) {
|
||||
if (proj.level.isClientSide)
|
||||
return false;
|
||||
Entity owner = proj.getOwner();
|
||||
if (owner instanceof ServerPlayerEntity) {
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) owner;
|
||||
if (owner instanceof ServerPlayer) {
|
||||
ServerPlayer player = (ServerPlayer) owner;
|
||||
if (res.getType() == HitResult.Type.BLOCK) {
|
||||
BlockHitResult blockRes = (BlockHitResult) res;
|
||||
BlockPos pos = blockRes.getBlockPos();
|
||||
BlockState state = proj.world.getBlockState(pos);
|
||||
BlockState state = proj.level.getBlockState(pos);
|
||||
ClaimPermission perm;
|
||||
if (proj instanceof EnderPearlEntity)
|
||||
if (proj instanceof ThrownEnderpearl)
|
||||
perm = PermissionRegistry.ENDERPEARL;
|
||||
else if (proj instanceof EggEntity || proj instanceof PotionEntity)
|
||||
else if (proj instanceof ThrownEgg || proj instanceof ThrownPotion)
|
||||
perm = PermissionRegistry.PROJECTILES;
|
||||
else
|
||||
perm = ObjectToPermissionMap.getFromBlock(state.getBlock());
|
||||
if (perm != PermissionRegistry.ENDERPEARL && perm != PermissionRegistry.TARGETBLOCK && perm != PermissionRegistry.PROJECTILES)
|
||||
return false;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) proj.world);
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) proj.level);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim == null)
|
||||
return false;
|
||||
boolean flag = !claim.canInteract(player, perm, pos, true);
|
||||
if (flag) {
|
||||
if (proj instanceof PersistentProjectileEntity) {
|
||||
PersistentProjectileEntity pers = (PersistentProjectileEntity) proj;
|
||||
((IPersistentProjectileVars) pers).setInBlockState(pers.world.getBlockState(pos));
|
||||
Vec3d vec3d = blockRes.getPos().subtract(pers.getX(), pers.getY(), pers.getZ());
|
||||
pers.setVelocity(vec3d);
|
||||
Vec3d vec3d2 = vec3d.normalize().multiply(0.05000000074505806D);
|
||||
pers.setPos(pers.getX() - vec3d2.x, pers.getY() - vec3d2.y, pers.getZ() - vec3d2.z);
|
||||
pers.playSound(((IPersistentProjectileVars) pers).getSoundEvent(), 1.0F, 1.2F / (pers.world.random.nextFloat() * 0.2F + 0.9F));
|
||||
if (proj instanceof AbstractArrow) {
|
||||
AbstractArrow pers = (AbstractArrow) proj;
|
||||
((IPersistentProjectileVars) pers).setInBlockState(pers.level.getBlockState(pos));
|
||||
Vec3 vec3d = blockRes.getLocation().subtract(pers.getX(), pers.getY(), pers.getZ());
|
||||
pers.setDeltaMovement(vec3d);
|
||||
Vec3 vec3d2 = vec3d.normalize().scale(0.05000000074505806D);
|
||||
pers.setPosRaw(pers.getX() - vec3d2.x, pers.getY() - vec3d2.y, pers.getZ() - vec3d2.z);
|
||||
pers.playSound(((IPersistentProjectileVars) pers).getSoundEvent(), 1.0F, 1.2F / (pers.level.random.nextFloat() * 0.2F + 0.9F));
|
||||
((IPersistentProjectileVars) pers).setInGround(true);
|
||||
pers.shake = 7;
|
||||
pers.setCritical(false);
|
||||
pers.shakeTime = 7;
|
||||
pers.setCritArrow(false);
|
||||
pers.setPierceLevel((byte) 0);
|
||||
pers.setSound(SoundEvents.ENTITY_ARROW_HIT);
|
||||
pers.setSoundEvent(SoundEvents.ARROW_HIT);
|
||||
pers.setShotFromCrossbow(false);
|
||||
((IPersistentProjectileVars) pers).resetPiercingStatus();
|
||||
}
|
||||
if (proj instanceof EnderPearlEntity)
|
||||
proj.remove();
|
||||
if (proj instanceof ThrownEnderpearl)
|
||||
proj.remove(Entity.RemovalReason.KILLED);
|
||||
//TODO: find a way to properly update chorus fruit break on hit
|
||||
//player.getServer().send(new ServerTask(player.getServer().getTicks()+2, ()->player.world.updateListeners(pos, state, state, 2)));
|
||||
}
|
||||
return flag;
|
||||
} else if (res.getType() == HitResult.Type.ENTITY) {
|
||||
if (proj instanceof EnderPearlEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) proj.world);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(proj.getBlockPos());
|
||||
return claim.canInteract(player, PermissionRegistry.ENDERPEARL, proj.getBlockPos(), true);
|
||||
if (proj instanceof ThrownEnderpearl) {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) proj.level);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(proj.blockPosition());
|
||||
return claim.canInteract(player, PermissionRegistry.ENDERPEARL, proj.blockPosition(), true);
|
||||
}
|
||||
Entity hit = ((EntityHitResult) res).getEntity();
|
||||
boolean fail = attackSimple(player, hit, true) != ActionResult.PASS;
|
||||
if (fail && proj instanceof PersistentProjectileEntity && ((PersistentProjectileEntity) proj).getPierceLevel() > 0) {
|
||||
PersistentProjectileEntity pers = (PersistentProjectileEntity) proj;
|
||||
boolean fail = attackSimple(player, hit, true) != InteractionResult.PASS;
|
||||
if (fail && proj instanceof AbstractArrow && ((AbstractArrow) proj).getPierceLevel() > 0) {
|
||||
AbstractArrow pers = (AbstractArrow) proj;
|
||||
IntOpenHashSet pierced = ((IPersistentProjectileVars) pers).getPiercedEntities();
|
||||
if (pierced == null)
|
||||
pierced = new IntOpenHashSet(5);
|
||||
pierced.add(hit.getEntityId());
|
||||
pierced.add(hit.getId());
|
||||
((IPersistentProjectileVars) pers).setPiercedEntities(pierced);
|
||||
pers.setPierceLevel((byte) (pers.getPierceLevel() + 1));
|
||||
}
|
||||
@ -184,60 +184,60 @@ public class EntityInteractEvents {
|
||||
}
|
||||
|
||||
public static boolean preventDamage(Entity entity, DamageSource source) {
|
||||
if (source.getAttacker() instanceof ServerPlayerEntity)
|
||||
return attackSimple((ServerPlayerEntity) source.getAttacker(), entity, true) != ActionResult.PASS;
|
||||
else if (source.isExplosive() && !entity.world.isClient) {
|
||||
IPermissionContainer claim = ClaimStorage.get((ServerWorld) entity.world).getForPermissionCheck(entity.getBlockPos());
|
||||
return claim != null && !claim.canInteract(null, PermissionRegistry.EXPLOSIONS, entity.getBlockPos());
|
||||
if (source.getEntity() instanceof ServerPlayer)
|
||||
return attackSimple((ServerPlayer) source.getEntity(), entity, true) != InteractionResult.PASS;
|
||||
else if (source.isExplosion() && !entity.level.isClientSide) {
|
||||
IPermissionContainer claim = ClaimStorage.get((ServerLevel) entity.level).getForPermissionCheck(entity.blockPosition());
|
||||
return claim != null && !claim.canInteract(null, PermissionRegistry.EXPLOSIONS, entity.blockPosition());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ActionResult attackSimple(PlayerEntity p, Entity entity, boolean message) {
|
||||
if (p.world.isClient || p.isSpectator() || canInteract(entity))
|
||||
return ActionResult.PASS;
|
||||
if (entity instanceof Monster)
|
||||
return ActionResult.PASS;
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
BlockPos pos = entity.getBlockPos();
|
||||
public static InteractionResult attackSimple(Player p, Entity entity, boolean message) {
|
||||
if (p.level.isClientSide || p.isSpectator() || canInteract(entity))
|
||||
return InteractionResult.PASS;
|
||||
if (entity instanceof Enemy)
|
||||
return InteractionResult.PASS;
|
||||
ServerPlayer player = (ServerPlayer) p;
|
||||
ClaimStorage storage = ClaimStorage.get(player.getLevel());
|
||||
BlockPos pos = entity.blockPosition();
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null) {
|
||||
if (!(entity instanceof LivingEntity))
|
||||
return claim.canInteract(player, PermissionRegistry.BREAKNONLIVING, pos, message) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
if (entity instanceof PlayerEntity)
|
||||
return claim.canInteract(player, PermissionRegistry.HURTPLAYER, pos, message) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, PermissionRegistry.HURTANIMAL, pos, message) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, PermissionRegistry.BREAKNONLIVING, pos, message) ? InteractionResult.PASS : InteractionResult.FAIL;
|
||||
if (entity instanceof Player)
|
||||
return claim.canInteract(player, PermissionRegistry.HURTPLAYER, pos, message) ? InteractionResult.PASS : InteractionResult.FAIL;
|
||||
return claim.canInteract(player, PermissionRegistry.HURTANIMAL, pos, message) ? InteractionResult.PASS : InteractionResult.FAIL;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
public static boolean xpAbsorb(PlayerEntity player) {
|
||||
if (player instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) player.world);
|
||||
BlockPos pos = player.getBlockPos();
|
||||
public static boolean xpAbsorb(Player player) {
|
||||
if (player instanceof ServerPlayer) {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) player.level);
|
||||
BlockPos pos = player.blockPosition();
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null)
|
||||
return !claim.canInteract((ServerPlayerEntity) player, PermissionRegistry.XP, pos, false);
|
||||
return !claim.canInteract((ServerPlayer) player, PermissionRegistry.XP, pos, false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean canCollideWith(PlayerEntity player, Entity entity) {
|
||||
if (player instanceof ServerPlayerEntity) {
|
||||
ServerPlayerEntity sPlayer = (ServerPlayerEntity) player;
|
||||
public static boolean canCollideWith(Player player, Entity entity) {
|
||||
if (player instanceof ServerPlayer) {
|
||||
ServerPlayer sPlayer = (ServerPlayer) player;
|
||||
if (entity instanceof ItemEntity) {
|
||||
IOwnedItem ownedItem = (IOwnedItem) entity;
|
||||
if (ownedItem.getDeathPlayer() != null) {
|
||||
ServerPlayerEntity other = sPlayer.getServer().getPlayerManager().getPlayer(ownedItem.getDeathPlayer());
|
||||
ServerPlayer other = sPlayer.getServer().getPlayerList().getPlayer(ownedItem.getDeathPlayer());
|
||||
if (other == null)
|
||||
return false;
|
||||
return ownedItem.getDeathPlayer().equals(player.getUuid()) || PlayerClaimData.get(other).deathItemsUnlocked();
|
||||
return ownedItem.getDeathPlayer().equals(player.getUUID()) || PlayerClaimData.get(other).deathItemsUnlocked();
|
||||
}
|
||||
if (sPlayer.getUuid().equals(ownedItem.getPlayerOrigin()))
|
||||
if (sPlayer.getUUID().equals(ownedItem.getPlayerOrigin()))
|
||||
return true;
|
||||
ClaimStorage storage = ClaimStorage.get(sPlayer.getServerWorld());
|
||||
BlockPos pos = sPlayer.getBlockPos();
|
||||
ClaimStorage storage = ClaimStorage.get(sPlayer.getLevel());
|
||||
BlockPos pos = sPlayer.blockPosition();
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null)
|
||||
return claim.canInteract(sPlayer, PermissionRegistry.PICKUP, pos, false);
|
||||
@ -246,36 +246,36 @@ public class EntityInteractEvents {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean canDropItem(PlayerEntity player, ItemStack stack) {
|
||||
if (!player.isDead() && player instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) player.world);
|
||||
BlockPos pos = player.getBlockPos();
|
||||
public static boolean canDropItem(Player player, ItemStack stack) {
|
||||
if (!player.isDeadOrDying() && player instanceof ServerPlayer) {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) player.level);
|
||||
BlockPos pos = player.blockPosition();
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
boolean allow = true;
|
||||
if (claim != null)
|
||||
allow = claim.canInteract((ServerPlayerEntity) player, PermissionRegistry.DROP, pos, false);
|
||||
allow = claim.canInteract((ServerPlayer) player, PermissionRegistry.DROP, pos, false);
|
||||
if (!allow) {
|
||||
player.inventory.insertStack(stack);
|
||||
DefaultedList<ItemStack> stacks = DefaultedList.of();
|
||||
for (int j = 0; j < player.currentScreenHandler.slots.size(); ++j) {
|
||||
ItemStack itemStack2 = player.currentScreenHandler.slots.get(j).getStack();
|
||||
player.getInventory().add(stack);
|
||||
NonNullList<ItemStack> stacks = NonNullList.create();
|
||||
for (int j = 0; j < player.containerMenu.slots.size(); ++j) {
|
||||
ItemStack itemStack2 = player.containerMenu.slots.get(j).getItem();
|
||||
stacks.add(itemStack2.isEmpty() ? ItemStack.EMPTY : itemStack2);
|
||||
}
|
||||
((ServerPlayerEntity) player).networkHandler.sendPacket(new InventoryS2CPacket(player.currentScreenHandler.syncId, stacks));
|
||||
((ServerPlayer) player).connection.send(new ClientboundContainerSetContentPacket(player.containerMenu.containerId, 0, stacks, player.inventoryMenu.getCarried()));
|
||||
}
|
||||
return allow;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean witherCanDestroy(WitherEntity wither) {
|
||||
if (wither.world.isClient)
|
||||
public static boolean witherCanDestroy(WitherBoss wither) {
|
||||
if (wither.level.isClientSide)
|
||||
return true;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) wither.world);
|
||||
BlockPos.Mutable pos = new BlockPos.Mutable();
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) wither.level);
|
||||
BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
|
||||
for (int x = -1; x <= 1; x++)
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
pos.set(wither.getBlockPos(), x, 3, z);
|
||||
pos.setWithOffset(wither.blockPosition(), x, 3, z);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (!claim.canInteract(null, PermissionRegistry.WITHER, pos, false))
|
||||
return false;
|
||||
@ -283,38 +283,38 @@ public class EntityInteractEvents {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean canEndermanInteract(EndermanEntity enderman, BlockPos pos) {
|
||||
if (enderman.world.isClient)
|
||||
public static boolean canEndermanInteract(EnderMan enderman, BlockPos pos) {
|
||||
if (enderman.level.isClientSide)
|
||||
return true;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) enderman.world);
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) enderman.level);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
return claim.canInteract(null, PermissionRegistry.ENDERMAN, pos, false);
|
||||
}
|
||||
|
||||
public static boolean canSnowGolemInteract(SnowGolemEntity snowgolem) {
|
||||
if (snowgolem.world.isClient)
|
||||
public static boolean canSnowGolemInteract(SnowGolem snowgolem) {
|
||||
if (snowgolem.level.isClientSide)
|
||||
return true;
|
||||
int x, y, z;
|
||||
for (int l = 0; l < 4; ++l) {
|
||||
x = MathHelper.floor(snowgolem.getX() + (l % 2 * 2 - 1) * 0.25F);
|
||||
y = MathHelper.floor(snowgolem.getY());
|
||||
z = MathHelper.floor(snowgolem.getZ() + (l / 2 % 2 * 2 - 1) * 0.25F);
|
||||
x = Mth.floor(snowgolem.getX() + (l % 2 * 2 - 1) * 0.25F);
|
||||
y = Mth.floor(snowgolem.getY());
|
||||
z = Mth.floor(snowgolem.getZ() + (l / 2 % 2 * 2 - 1) * 0.25F);
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
IPermissionContainer claim = ClaimStorage.get((ServerWorld) snowgolem.world).getForPermissionCheck(pos);
|
||||
IPermissionContainer claim = ClaimStorage.get((ServerLevel) snowgolem.level).getForPermissionCheck(pos);
|
||||
if (!claim.canInteract(null, PermissionRegistry.SNOWGOLEM, pos, false))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void updateDroppedItem(PlayerEntity player, ItemEntity entity) {
|
||||
public static void updateDroppedItem(Player player, ItemEntity entity) {
|
||||
((IOwnedItem) entity).setOriginPlayer((player));
|
||||
}
|
||||
|
||||
public static void updateClaim(ServerPlayerEntity player, Claim currentClaim, Consumer<Claim> cons) {
|
||||
Vec3d pos = player.getPos();
|
||||
BlockPos rounded = TeleportUtils.roundedBlockPos(pos.add(0, player.getActiveEyeHeight(player.getPose(), player.getDimensions(player.getPose())), 0));
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
public static void updateClaim(ServerPlayer player, Claim currentClaim, Consumer<Claim> cons) {
|
||||
Vec3 pos = player.position();
|
||||
BlockPos rounded = TeleportUtils.roundedBlockPos(pos.add(0, player.getStandingEyeHeight(player.getPose(), player.getDimensions(player.getPose())), 0));
|
||||
ClaimStorage storage = ClaimStorage.get(player.getLevel());
|
||||
if (currentClaim != null) {
|
||||
if (!currentClaim.intersects(player.getBoundingBox())) {
|
||||
Claim claim = storage.getClaimAt(rounded);
|
||||
@ -325,22 +325,22 @@ public class EntityInteractEvents {
|
||||
claim.displayEnterTitle(player);
|
||||
} else {
|
||||
if (!player.isSpectator()) {
|
||||
BlockPos.Mutable bPos = rounded.mutableCopy();
|
||||
BlockPos.MutableBlockPos bPos = rounded.mutable();
|
||||
if (!currentClaim.canInteract(player, PermissionRegistry.CANSTAY, bPos, true)) {
|
||||
Vec3d tp = TeleportUtils.getTeleportPos(player, pos, storage, currentClaim.getDimensions(), bPos, (claim, nPos) -> claim.canInteract(player, PermissionRegistry.CANSTAY, nPos, false));
|
||||
player.teleport(tp.getX(), tp.getY(), tp.getZ());
|
||||
Vec3 tp = TeleportUtils.getTeleportPos(player, pos, storage, currentClaim.getDimensions(), bPos, (claim, nPos) -> claim.canInteract(player, PermissionRegistry.CANSTAY, nPos, false));
|
||||
player.teleportToWithTicket(tp.x(), tp.y(), tp.z());
|
||||
}
|
||||
if (player.abilities.flying && !player.isCreative() && !currentClaim.canInteract(player, PermissionRegistry.FLIGHT, rounded, true)) {
|
||||
player.abilities.flying = false;
|
||||
player.networkHandler.sendPacket(new PlayerAbilitiesS2CPacket(player.abilities));
|
||||
if (player.getAbilities().flying && !player.isCreative() && !currentClaim.canInteract(player, PermissionRegistry.FLIGHT, rounded, true)) {
|
||||
player.getAbilities().flying = false;
|
||||
player.connection.send(new ClientboundPlayerAbilitiesPacket(player.getAbilities()));
|
||||
}
|
||||
if (player.getHungerManager().getSaturationLevel() < 2 && currentClaim.canInteract(player, PermissionRegistry.NOHUNGER, bPos, false)) {
|
||||
((IHungerAccessor) player.getHungerManager()).setSaturation(2);
|
||||
if (player.getFoodData().getSaturationLevel() < 2 && currentClaim.canInteract(player, PermissionRegistry.NOHUNGER, bPos, false)) {
|
||||
((IHungerAccessor) player.getFoodData()).setSaturation(2);
|
||||
}
|
||||
currentClaim.applyEffects(player);
|
||||
}
|
||||
}
|
||||
} else if (player.age % 3 == 0) {
|
||||
} else if (player.tickCount % 3 == 0) {
|
||||
Claim claim = storage.getClaimAt(rounded);
|
||||
cons.accept(claim);
|
||||
if (claim != null)
|
||||
@ -348,19 +348,19 @@ public class EntityInteractEvents {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canFrostwalkerFreeze(ServerWorld world, BlockPos pos, LivingEntity entity) {
|
||||
if (entity instanceof ServerPlayerEntity) {
|
||||
public static boolean canFrostwalkerFreeze(ServerLevel world, BlockPos pos, LivingEntity entity) {
|
||||
if (entity instanceof ServerPlayer) {
|
||||
IPermissionContainer claim = ClaimStorage.get(world).getForPermissionCheck(pos);
|
||||
return claim.canInteract((ServerPlayerEntity) entity, PermissionRegistry.FROSTWALKER, pos, false);
|
||||
return claim.canInteract((ServerPlayer) entity, PermissionRegistry.FROSTWALKER, pos, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean preventLightningConvert(Entity entity) {
|
||||
if (entity.world.isClient || entity instanceof Monster)
|
||||
if (entity.level.isClientSide || entity instanceof Enemy)
|
||||
return false;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) entity.world);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(entity.getBlockPos());
|
||||
return !claim.canInteract(null, PermissionRegistry.LIGHTNING, entity.getBlockPos(), false);
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) entity.level);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(entity.blockPosition());
|
||||
return !claim.canInteract(null, PermissionRegistry.LIGHTNING, entity.blockPosition(), false);
|
||||
}
|
||||
}
|
||||
|
@ -15,157 +15,157 @@ import io.github.flemmli97.flan.mixin.IItemAccessor;
|
||||
import io.github.flemmli97.flan.player.EnumDisplayType;
|
||||
import io.github.flemmli97.flan.player.EnumEditMode;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.RaycastContext;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class ItemInteractEvents {
|
||||
|
||||
public static TypedActionResult<ItemStack> useItem(PlayerEntity p, World world, Hand hand) {
|
||||
if (world.isClient || p.isSpectator())
|
||||
return TypedActionResult.pass(p.getStackInHand(hand));
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ItemStack stack = player.getStackInHand(hand);
|
||||
public static InteractionResultHolder<ItemStack> useItem(Player p, Level world, InteractionHand hand) {
|
||||
if (world.isClientSide || p.isSpectator())
|
||||
return InteractionResultHolder.pass(p.getItemInHand(hand));
|
||||
ServerPlayer player = (ServerPlayer) p;
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
if (stack.getItem() == ConfigHandler.config.claimingItem) {
|
||||
HitResult ray = player.raycast(64, 0, false);
|
||||
HitResult ray = player.pick(64, 0, false);
|
||||
if (ray != null && ray.getType() == HitResult.Type.BLOCK) {
|
||||
claimLandHandling(player, ((BlockHitResult) ray).getBlockPos());
|
||||
return TypedActionResult.success(stack);
|
||||
return InteractionResultHolder.success(stack);
|
||||
}
|
||||
return TypedActionResult.pass(stack);
|
||||
return InteractionResultHolder.pass(stack);
|
||||
}
|
||||
if (stack.getItem() == ConfigHandler.config.inspectionItem) {
|
||||
HitResult ray = player.raycast(32, 0, false);
|
||||
HitResult ray = player.pick(32, 0, false);
|
||||
if (ray != null && ray.getType() == HitResult.Type.BLOCK) {
|
||||
inspect(player, ((BlockHitResult) ray).getBlockPos());
|
||||
return TypedActionResult.success(stack);
|
||||
return InteractionResultHolder.success(stack);
|
||||
}
|
||||
return TypedActionResult.pass(stack);
|
||||
return InteractionResultHolder.pass(stack);
|
||||
}
|
||||
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
BlockPos pos = player.getBlockPos();
|
||||
BlockHitResult hitResult = IItemAccessor.getRaycast(world, player, RaycastContext.FluidHandling.SOURCE_ONLY);
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) world);
|
||||
BlockPos pos = player.blockPosition();
|
||||
BlockHitResult hitResult = IItemAccessor.getRaycast(world, player, ClipContext.Fluid.SOURCE_ONLY);
|
||||
if (hitResult.getType() == HitResult.Type.BLOCK) {
|
||||
pos = new ItemPlacementContext(player, hand, stack, hitResult).getBlockPos();
|
||||
pos = new BlockPlaceContext(player, hand, stack, hitResult).getClickedPos();
|
||||
}
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim == null)
|
||||
return TypedActionResult.pass(stack);
|
||||
return InteractionResultHolder.pass(stack);
|
||||
ClaimPermission perm = ObjectToPermissionMap.getFromItem(stack.getItem());
|
||||
if (perm != null) {
|
||||
boolean success = claim.canInteract(player, perm, pos, true);
|
||||
if (success)
|
||||
return TypedActionResult.pass(stack);
|
||||
return InteractionResultHolder.pass(stack);
|
||||
if (perm == PermissionRegistry.PLACE) {
|
||||
BlockPos update = pos;
|
||||
if (stack.getItem() == Items.LILY_PAD) {
|
||||
BlockHitResult upResult = hitResult.withBlockPos(hitResult.getBlockPos().up());
|
||||
update = new ItemPlacementContext(new ItemUsageContext(player, hand, upResult)).getBlockPos();
|
||||
BlockHitResult upResult = hitResult.withPosition(hitResult.getBlockPos().above());
|
||||
update = new BlockPlaceContext(new UseOnContext(player, hand, upResult)).getClickedPos();
|
||||
}
|
||||
player.networkHandler.sendPacket(new BlockUpdateS2CPacket(update, world.getBlockState(update)));
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
player.connection.send(new ClientboundBlockUpdatePacket(update, world.getBlockState(update)));
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY());
|
||||
updateHeldItem(player);
|
||||
}
|
||||
return TypedActionResult.fail(stack);
|
||||
return InteractionResultHolder.fail(stack);
|
||||
}
|
||||
return TypedActionResult.pass(stack);
|
||||
return InteractionResultHolder.pass(stack);
|
||||
}
|
||||
|
||||
private static final Set<Item> blackListedItems = Sets.newHashSet(Items.COMPASS, Items.FILLED_MAP, Items.FIREWORK_ROCKET);
|
||||
|
||||
public static ActionResult onItemUseBlock(ItemUsageContext context) {
|
||||
public static InteractionResult onItemUseBlock(UseOnContext context) {
|
||||
//Check for Fakeplayer. Since there is no api for that directly check the class
|
||||
if (!(context.getPlayer() instanceof ServerPlayerEntity) || !context.getPlayer().getClass().equals(ServerPlayerEntity.class) || context.getStack().isEmpty())
|
||||
return ActionResult.PASS;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) context.getWorld());
|
||||
BlockPos placePos = new ItemPlacementContext(context).getBlockPos();
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(placePos.add(0, 255, 0));
|
||||
if (!(context.getPlayer() instanceof ServerPlayer) || !context.getPlayer().getClass().equals(ServerPlayer.class) || context.getItemInHand().isEmpty())
|
||||
return InteractionResult.PASS;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) context.getLevel());
|
||||
BlockPos placePos = new BlockPlaceContext(context).getClickedPos();
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(placePos.offset(0, 255, 0));
|
||||
if (claim == null)
|
||||
return ActionResult.PASS;
|
||||
if (blackListedItems.contains(context.getStack().getItem()))
|
||||
return ActionResult.PASS;
|
||||
return InteractionResult.PASS;
|
||||
if (blackListedItems.contains(context.getItemInHand().getItem()))
|
||||
return InteractionResult.PASS;
|
||||
boolean actualInClaim = !(claim instanceof Claim) || placePos.getY() >= ((Claim) claim).getDimensions()[4];
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) context.getPlayer();
|
||||
ClaimPermission perm = ObjectToPermissionMap.getFromItem(context.getStack().getItem());
|
||||
ServerPlayer player = (ServerPlayer) context.getPlayer();
|
||||
ClaimPermission perm = ObjectToPermissionMap.getFromItem(context.getItemInHand().getItem());
|
||||
if (perm != null) {
|
||||
if (claim.canInteract(player, perm, placePos, false))
|
||||
return ActionResult.PASS;
|
||||
return InteractionResult.PASS;
|
||||
else if (actualInClaim) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
||||
return ActionResult.FAIL;
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, ChatFormatting.DARK_RED), true);
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
}
|
||||
if (claim.canInteract(player, PermissionRegistry.PLACE, placePos, false)) {
|
||||
if (!actualInClaim && context.getStack().getItem() instanceof BlockItem) {
|
||||
if (!actualInClaim && context.getItemInHand().getItem() instanceof BlockItem) {
|
||||
((Claim) claim).extendDownwards(placePos);
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
return InteractionResult.PASS;
|
||||
} else if (actualInClaim) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
||||
BlockState other = context.getWorld().getBlockState(placePos.up());
|
||||
player.networkHandler.sendPacket(new BlockUpdateS2CPacket(placePos.up(), other));
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, ChatFormatting.DARK_RED), true);
|
||||
BlockState other = context.getLevel().getBlockState(placePos.above());
|
||||
player.connection.send(new ClientboundBlockUpdatePacket(placePos.above(), other));
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY());
|
||||
updateHeldItem(player);
|
||||
return ActionResult.FAIL;
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* -2 == Main inventory update
|
||||
*/
|
||||
private static void updateHeldItem(ServerPlayerEntity player) {
|
||||
player.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(-2, player.inventory.selectedSlot, player.inventory.getMainHandStack()));
|
||||
player.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(-2, 40, player.inventory.getStack(40)));
|
||||
private static void updateHeldItem(ServerPlayer player) {
|
||||
player.connection.send(new ClientboundContainerSetSlotPacket(-2, 0, player.getInventory().selected, player.getInventory().getSelected()));
|
||||
player.connection.send(new ClientboundContainerSetSlotPacket(-2, 0, 40, player.getInventory().getItem(40)));
|
||||
}
|
||||
|
||||
private static boolean cantClaimInWorld(ServerWorld world) {
|
||||
private static boolean cantClaimInWorld(ServerLevel world) {
|
||||
for (String s : ConfigHandler.config.blacklistedWorlds) {
|
||||
if (s.equals(world.getRegistryKey().getValue().toString())) {
|
||||
if (s.equals(world.dimension().location().toString())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void claimLandHandling(ServerPlayerEntity player, BlockPos target) {
|
||||
public static void claimLandHandling(ServerPlayer player, BlockPos target) {
|
||||
if (!PermissionNodeHandler.perm(player, PermissionNodeHandler.claimCreate, false)) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermission, Formatting.DARK_RED), true);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermission, ChatFormatting.DARK_RED), true);
|
||||
return;
|
||||
}
|
||||
if (ConfigHandler.config.worldWhitelist) {
|
||||
if (!cantClaimInWorld(player.getServerWorld())) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.landClaimDisabledWorld, Formatting.DARK_RED), false);
|
||||
if (!cantClaimInWorld(player.getLevel())) {
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.landClaimDisabledWorld, ChatFormatting.DARK_RED), false);
|
||||
return;
|
||||
}
|
||||
} else if (cantClaimInWorld(player.getServerWorld())) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.landClaimDisabledWorld, Formatting.DARK_RED), false);
|
||||
} else if (cantClaimInWorld(player.getLevel())) {
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.landClaimDisabledWorld, ChatFormatting.DARK_RED), false);
|
||||
return;
|
||||
}
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
Claim claim = storage.getClaimAt(target.add(0, 255, 0));
|
||||
ClaimStorage storage = ClaimStorage.get(player.getLevel());
|
||||
Claim claim = storage.getClaimAt(target.offset(0, 255, 0));
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if (data.claimCooldown())
|
||||
return;
|
||||
@ -176,20 +176,20 @@ public class ItemInteractEvents {
|
||||
Claim subClaim = claim.getSubClaim(target);
|
||||
if (subClaim != null && data.currentEdit() == null) {
|
||||
if (subClaim.isCorner(target)) {
|
||||
data.setEditClaim(subClaim, player.getBlockPos().getY());
|
||||
data.setEditClaim(subClaim, player.blockPosition().getY());
|
||||
data.setEditingCorner(target);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeClaim, Formatting.GOLD), false);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeClaim, ChatFormatting.GOLD), false);
|
||||
} else {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, Formatting.RED), false);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, ChatFormatting.RED), false);
|
||||
}
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY());
|
||||
} else {
|
||||
if (data.currentEdit() != null) {
|
||||
if (!data.editingCorner().equals(target)) {
|
||||
Set<Claim> fl = claim.resizeSubclaim(data.currentEdit(), data.editingCorner(), target);
|
||||
if (!fl.isEmpty()) {
|
||||
fl.forEach(confl -> data.addDisplayClaim(confl, EnumDisplayType.MAIN, player.getBlockPos().getY()));
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
|
||||
fl.forEach(confl -> data.addDisplayClaim(confl, EnumDisplayType.MAIN, player.blockPosition().getY()));
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, ChatFormatting.RED), false);
|
||||
}
|
||||
data.setEditClaim(null, 0);
|
||||
data.setEditingCorner(null);
|
||||
@ -197,12 +197,12 @@ public class ItemInteractEvents {
|
||||
} else if (data.editingCorner() != null) {
|
||||
if (!data.editingCorner().equals(target)) {
|
||||
Set<Claim> fl = claim.tryCreateSubClaim(data.editingCorner(), target);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY());
|
||||
if (!fl.isEmpty()) {
|
||||
fl.forEach(confl -> data.addDisplayClaim(confl, EnumDisplayType.CONFLICT, player.getBlockPos().getY()));
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
|
||||
fl.forEach(confl -> data.addDisplayClaim(confl, EnumDisplayType.CONFLICT, player.blockPosition().getY()));
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, ChatFormatting.RED), false);
|
||||
} else {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.subClaimCreateSuccess, Formatting.GOLD), false);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.subClaimCreateSuccess, ChatFormatting.GOLD), false);
|
||||
}
|
||||
data.setEditingCorner(null);
|
||||
}
|
||||
@ -211,24 +211,24 @@ public class ItemInteractEvents {
|
||||
}
|
||||
} else {
|
||||
if (claim.isCorner(target)) {
|
||||
data.setEditClaim(claim, player.getBlockPos().getY());
|
||||
data.setEditClaim(claim, player.blockPosition().getY());
|
||||
data.setEditingCorner(target);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeClaim, Formatting.GOLD), false);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeClaim, ChatFormatting.GOLD), false);
|
||||
} else if (data.currentEdit() != null) {
|
||||
storage.resizeClaim(data.currentEdit(), data.editingCorner(), target, player);
|
||||
data.setEditClaim(null, 0);
|
||||
data.setEditingCorner(null);
|
||||
} else {
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, Formatting.RED), false);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY());
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, ChatFormatting.RED), false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, Formatting.RED), false);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY());
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, ChatFormatting.RED), false);
|
||||
}
|
||||
} else if (data.getEditMode() == EnumEditMode.SUBCLAIM) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.wrongMode, data.getEditMode()), Formatting.RED), false);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.wrongMode, data.getEditMode()), ChatFormatting.RED), false);
|
||||
} else {
|
||||
if (data.currentEdit() != null) {
|
||||
storage.resizeClaim(data.currentEdit(), data.editingCorner(), target, player);
|
||||
@ -242,25 +242,20 @@ public class ItemInteractEvents {
|
||||
}
|
||||
}
|
||||
|
||||
public static void inspect(ServerPlayerEntity player, BlockPos target) {
|
||||
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(target);
|
||||
public static void inspect(ServerPlayer player, BlockPos target) {
|
||||
Claim claim = ClaimStorage.get(player.getLevel()).getClaimAt(target);
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if (data.claimCooldown())
|
||||
return;
|
||||
data.setClaimActionCooldown();
|
||||
if (claim != null) {
|
||||
String owner = claim.isAdminClaim() ? "<Admin>" : "<UNKOWN>";
|
||||
if (!claim.isAdminClaim()) {
|
||||
GameProfile prof = player.getServer().getUserCache().getByUuid(claim.getOwner());
|
||||
if (prof != null && prof.getName() != null)
|
||||
owner = prof.getName();
|
||||
}
|
||||
Text text = PermHelper.simpleColoredText(String.format(ConfigHandler.lang.inspectBlockOwner,
|
||||
String owner = claim.isAdminClaim() ? "<Admin>" : player.getServer().getProfileCache().get(claim.getOwner()).map(GameProfile::getName).orElse("<UNKOWN>");
|
||||
Component text = PermHelper.simpleColoredText(String.format(ConfigHandler.lang.inspectBlockOwner,
|
||||
owner,
|
||||
target.getX(), target.getY(), target.getZ()), Formatting.GREEN);
|
||||
player.sendMessage(text, false);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
target.getX(), target.getY(), target.getZ()), ChatFormatting.GREEN);
|
||||
player.displayClientMessage(text, false);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY());
|
||||
} else
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.inspectNoClaim, Formatting.RED), false);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.inspectNoClaim, ChatFormatting.RED), false);
|
||||
}
|
||||
}
|
||||
|
@ -2,23 +2,23 @@ package io.github.flemmli97.flan.event;
|
||||
|
||||
import io.github.flemmli97.flan.player.LogoutTracker;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public class PlayerEvents {
|
||||
|
||||
public static void saveClaimData(PlayerEntity player) {
|
||||
if (player instanceof ServerPlayerEntity)
|
||||
PlayerClaimData.get((ServerPlayerEntity) player).save(player.getServer());
|
||||
public static void saveClaimData(Player player) {
|
||||
if (player instanceof ServerPlayer)
|
||||
PlayerClaimData.get((ServerPlayer) player).save(player.getServer());
|
||||
}
|
||||
|
||||
public static void readClaimData(PlayerEntity player) {
|
||||
if (player instanceof ServerPlayerEntity)
|
||||
PlayerClaimData.get((ServerPlayerEntity) player).read(player.getServer());
|
||||
public static void readClaimData(Player player) {
|
||||
if (player instanceof ServerPlayer)
|
||||
PlayerClaimData.get((ServerPlayer) player).read(player.getServer());
|
||||
}
|
||||
|
||||
public static void onLogout(PlayerEntity player) {
|
||||
public static void onLogout(Player player) {
|
||||
if (player.getServer() != null)
|
||||
LogoutTracker.getInstance(player.getServer()).track(player.getUuid());
|
||||
LogoutTracker.getInstance(player.getServer()).track(player.getUUID());
|
||||
}
|
||||
}
|
||||
|
@ -4,24 +4,24 @@ import io.github.flemmli97.flan.api.data.IPermissionContainer;
|
||||
import io.github.flemmli97.flan.api.permission.PermissionRegistry;
|
||||
import io.github.flemmli97.flan.claim.ClaimStorage;
|
||||
import io.github.flemmli97.flan.player.LogoutTracker;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.LightningEntity;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.explosion.Explosion;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.LightningBolt;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class WorldEvents {
|
||||
|
||||
public static void modifyExplosion(Explosion explosion, ServerWorld world) {
|
||||
public static void modifyExplosion(Explosion explosion, ServerLevel world) {
|
||||
ClaimStorage storage = ClaimStorage.get(world);
|
||||
explosion.getAffectedBlocks().removeIf(pos -> {
|
||||
explosion.getToBlow().removeIf(pos -> {
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null)
|
||||
return !claim.canInteract(null, PermissionRegistry.EXPLOSIONS, pos);
|
||||
@ -29,16 +29,16 @@ public class WorldEvents {
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean pistonCanPush(BlockState state, World world, BlockPos blockPos, Direction direction, Direction pistonDir) {
|
||||
if (world.isClient || state.isAir())
|
||||
public static boolean pistonCanPush(BlockState state, Level world, BlockPos blockPos, Direction direction, Direction pistonDir) {
|
||||
if (world.isClientSide || state.isAir())
|
||||
return true;
|
||||
BlockPos dirPos = blockPos.offset(direction);
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
BlockPos dirPos = blockPos.relative(direction);
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) world);
|
||||
IPermissionContainer from = storage.getForPermissionCheck(blockPos);
|
||||
IPermissionContainer to = storage.getForPermissionCheck(dirPos);
|
||||
boolean flag = true;
|
||||
if (from.equals(to)) {
|
||||
BlockPos oppPoos = blockPos.offset(direction.getOpposite());
|
||||
BlockPos oppPoos = blockPos.relative(direction.getOpposite());
|
||||
IPermissionContainer opp = storage.getForPermissionCheck(oppPoos);
|
||||
if (!from.equals(opp))
|
||||
flag = from.canInteract(null, PermissionRegistry.PISTONBORDER, oppPoos);
|
||||
@ -47,44 +47,44 @@ public class WorldEvents {
|
||||
if (!flag) {
|
||||
//Idk enough about piston behaviour to update more blocks when slime is involved.
|
||||
//Ghost blocks appear when trying to push slime contraptions across border
|
||||
world.updateListeners(blockPos, state, state, 20);
|
||||
world.sendBlockUpdated(blockPos, state, state, 20);
|
||||
BlockState toState = world.getBlockState(dirPos);
|
||||
world.updateListeners(dirPos, toState, toState, 20);
|
||||
world.sendBlockUpdated(dirPos, toState, toState, 20);
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
public static boolean canFlow(BlockState fluidBlockState, BlockView world, BlockPos blockPos, Direction direction) {
|
||||
if (!(world instanceof ServerWorld) || direction == Direction.UP || direction == Direction.DOWN)
|
||||
public static boolean canFlow(BlockState fluidBlockState, BlockGetter world, BlockPos blockPos, Direction direction) {
|
||||
if (!(world instanceof ServerLevel) || direction == Direction.UP || direction == Direction.DOWN)
|
||||
return true;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) world);
|
||||
IPermissionContainer from = storage.getForPermissionCheck(blockPos);
|
||||
IPermissionContainer to = storage.getForPermissionCheck(blockPos.offset(direction));
|
||||
IPermissionContainer to = storage.getForPermissionCheck(blockPos.relative(direction));
|
||||
return from.equals(to) || to.canInteract(null, PermissionRegistry.WATERBORDER, blockPos);
|
||||
}
|
||||
|
||||
public static boolean canStartRaid(ServerPlayerEntity player) {
|
||||
IPermissionContainer claim = ClaimStorage.get(player.getServerWorld()).getForPermissionCheck(player.getBlockPos());
|
||||
return claim.canInteract(player, PermissionRegistry.RAID, player.getBlockPos());
|
||||
public static boolean canStartRaid(ServerPlayer player) {
|
||||
IPermissionContainer claim = ClaimStorage.get(player.getLevel()).getForPermissionCheck(player.blockPosition());
|
||||
return claim.canInteract(player, PermissionRegistry.RAID, player.blockPosition());
|
||||
}
|
||||
|
||||
public static boolean canFireSpread(ServerWorld world, BlockPos pos) {
|
||||
public static boolean canFireSpread(ServerLevel world, BlockPos pos) {
|
||||
IPermissionContainer claim = ClaimStorage.get(world).getForPermissionCheck(pos);
|
||||
return claim.canInteract(null, PermissionRegistry.FIRESPREAD, pos);
|
||||
}
|
||||
|
||||
public static boolean preventMobSpawn(ServerWorld world, MobEntity entity) {
|
||||
IPermissionContainer claim = ClaimStorage.get(world).getForPermissionCheck(entity.getBlockPos());
|
||||
if (entity.getType().getSpawnGroup() == SpawnGroup.MONSTER)
|
||||
return claim.canInteract(null, PermissionRegistry.MOBSPAWN, entity.getBlockPos());
|
||||
return claim.canInteract(null, PermissionRegistry.ANIMALSPAWN, entity.getBlockPos());
|
||||
public static boolean preventMobSpawn(ServerLevel world, Mob entity) {
|
||||
IPermissionContainer claim = ClaimStorage.get(world).getForPermissionCheck(entity.blockPosition());
|
||||
if (entity.getType().getCategory() == MobCategory.MONSTER)
|
||||
return claim.canInteract(null, PermissionRegistry.MOBSPAWN, entity.blockPosition());
|
||||
return claim.canInteract(null, PermissionRegistry.ANIMALSPAWN, entity.blockPosition());
|
||||
}
|
||||
|
||||
public static boolean lightningFire(LightningEntity lightning) {
|
||||
if (!(lightning.world instanceof ServerWorld))
|
||||
public static boolean lightningFire(LightningBolt lightning) {
|
||||
if (!(lightning.level instanceof ServerLevel))
|
||||
return true;
|
||||
BlockPos.Mutable mutable = lightning.getBlockPos().mutableCopy();
|
||||
ServerWorld world = (ServerWorld) lightning.world;
|
||||
BlockPos.MutableBlockPos mutable = lightning.blockPosition().mutable();
|
||||
ServerLevel world = (ServerLevel) lightning.level;
|
||||
for (int x = -1; x <= 1; x++)
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
mutable.set(mutable.getX() + x, mutable.getY(), mutable.getZ() + z);
|
||||
|
@ -8,84 +8,84 @@ import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
|
||||
private final Claim claim;
|
||||
|
||||
private ClaimMenuScreenHandler(int syncId, PlayerInventory playerInventory, Claim claim) {
|
||||
private ClaimMenuScreenHandler(int syncId, Inventory playerInventory, Claim claim) {
|
||||
super(syncId, playerInventory, 1, claim);
|
||||
this.claim = claim;
|
||||
}
|
||||
|
||||
public static void openClaimMenu(ServerPlayerEntity player, Claim claim) {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
public static void openClaimMenu(ServerPlayer player, Claim claim) {
|
||||
MenuProvider fac = new MenuProvider() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
public AbstractContainerMenu createMenu(int syncId, Inventory inv, Player player) {
|
||||
return new ClaimMenuScreenHandler(syncId, inv, claim);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
public Component getDisplayName() {
|
||||
return PermHelper.simpleColoredText(claim.parentClaim() != null ? ConfigHandler.lang.screenMenuSub : ConfigHandler.lang.screenMenu);
|
||||
}
|
||||
};
|
||||
player.openHandledScreen(fac);
|
||||
player.openMenu(fac);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, Claim claim) {
|
||||
protected void fillInventoryWith(Player player, SeparateInv inv, Claim claim) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenClose, Formatting.DARK_RED));
|
||||
close.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenClose, ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, close);
|
||||
break;
|
||||
case 2:
|
||||
ItemStack perm = new ItemStack(Items.BEACON);
|
||||
perm.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuGlobal, Formatting.GOLD));
|
||||
if (player instanceof ServerPlayerEntity && !this.hasEditPerm(claim, (ServerPlayerEntity) player))
|
||||
ServerScreenHelper.addLore(perm, ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNoPerm, Formatting.DARK_RED));
|
||||
perm.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuGlobal, ChatFormatting.GOLD));
|
||||
if (player instanceof ServerPlayer && !this.hasEditPerm(claim, (ServerPlayer) player))
|
||||
ServerScreenHelper.addLore(perm, ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNoPerm, ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, perm);
|
||||
break;
|
||||
case 3:
|
||||
ItemStack group = new ItemStack(Items.WRITABLE_BOOK);
|
||||
group.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuGroup, Formatting.GOLD));
|
||||
if (player instanceof ServerPlayerEntity && !this.hasEditPerm(claim, (ServerPlayerEntity) player))
|
||||
ServerScreenHelper.addLore(group, ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNoPerm, Formatting.DARK_RED));
|
||||
group.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuGroup, ChatFormatting.GOLD));
|
||||
if (player instanceof ServerPlayer && !this.hasEditPerm(claim, (ServerPlayer) player))
|
||||
ServerScreenHelper.addLore(group, ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNoPerm, ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, group);
|
||||
break;
|
||||
case 4:
|
||||
ItemStack potions = new ItemStack(Items.POTION);
|
||||
potions.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuPotion, Formatting.GOLD));
|
||||
if (player instanceof ServerPlayerEntity && !this.hasPerm(claim, (ServerPlayerEntity) player, PermissionRegistry.EDITPOTIONS))
|
||||
ServerScreenHelper.addLore(potions, ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNoPerm, Formatting.DARK_RED));
|
||||
potions.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuPotion, ChatFormatting.GOLD));
|
||||
if (player instanceof ServerPlayer && !this.hasPerm(claim, (ServerPlayer) player, PermissionRegistry.EDITPOTIONS))
|
||||
ServerScreenHelper.addLore(potions, ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNoPerm, ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, potions);
|
||||
break;
|
||||
case 5:
|
||||
ItemStack sign = new ItemStack(Items.OAK_SIGN);
|
||||
sign.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuClaimText, Formatting.GOLD));
|
||||
if (player instanceof ServerPlayerEntity && !this.hasPerm(claim, (ServerPlayerEntity) player, PermissionRegistry.EDITCLAIM))
|
||||
ServerScreenHelper.addLore(sign, ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNoPerm, Formatting.DARK_RED));
|
||||
sign.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuClaimText, ChatFormatting.GOLD));
|
||||
if (player instanceof ServerPlayer && !this.hasPerm(claim, (ServerPlayer) player, PermissionRegistry.EDITCLAIM))
|
||||
ServerScreenHelper.addLore(sign, ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNoPerm, ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, sign);
|
||||
break;
|
||||
case 8:
|
||||
ItemStack delete = new ItemStack(Items.BARRIER);
|
||||
delete.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuDelete, Formatting.RED));
|
||||
if (player instanceof ServerPlayerEntity && !this.hasPerm(claim, (ServerPlayerEntity) player, PermissionRegistry.EDITCLAIM))
|
||||
ServerScreenHelper.addLore(delete, ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNoPerm, Formatting.DARK_RED));
|
||||
delete.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuDelete, ChatFormatting.RED));
|
||||
if (player instanceof ServerPlayer && !this.hasPerm(claim, (ServerPlayer) player, PermissionRegistry.EDITCLAIM))
|
||||
ServerScreenHelper.addLore(delete, ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNoPerm, ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, delete);
|
||||
break;
|
||||
default:
|
||||
@ -100,75 +100,75 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleSlotClicked(ServerPlayerEntity player, int index, Slot slot, int clickType) {
|
||||
protected boolean handleSlotClicked(ServerPlayer player, int index, Slot slot, int clickType) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
break;
|
||||
case 2:
|
||||
if (this.hasEditPerm(this.claim, player)) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> PermissionScreenHandler.openClaimMenu(player, this.claim, null));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
} else
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f);
|
||||
break;
|
||||
case 3:
|
||||
if (this.hasEditPerm(this.claim, player)) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> GroupScreenHandler.openGroupMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
} else
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f);
|
||||
break;
|
||||
case 4:
|
||||
if (this.hasPerm(this.claim, player, PermissionRegistry.EDITPOTIONS)) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> PotionEditScreenHandler.openPotionMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
} else
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f);
|
||||
break;
|
||||
case 5:
|
||||
if (this.hasPerm(this.claim, player, PermissionRegistry.EDITCLAIM)) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> ClaimTextHandler.openClaimMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
} else
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f);
|
||||
break;
|
||||
case 8:
|
||||
if (this.hasPerm(this.claim, player, PermissionRegistry.EDITCLAIM)) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> ConfirmScreenHandler.openConfirmScreen(player, (bool) -> {
|
||||
if (bool) {
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
storage.deleteClaim(this.claim, true, PlayerClaimData.get(player).getEditMode(), player.getServerWorld());
|
||||
player.closeHandledScreen();
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaim, Formatting.RED), false);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_ANVIL_PLACE, 1, 1f);
|
||||
ClaimStorage storage = ClaimStorage.get(player.getLevel());
|
||||
storage.deleteClaim(this.claim, true, PlayerClaimData.get(player).getEditMode(), player.getLevel());
|
||||
player.closeContainer();
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaim, ChatFormatting.RED), false);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ANVIL_PLACE, 1, 1f);
|
||||
} else {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> ClaimMenuScreenHandler.openClaimMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f);
|
||||
}
|
||||
}));
|
||||
} else
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean hasEditPerm(Claim claim, ServerPlayerEntity player) {
|
||||
return ((claim.parentClaim() != null && claim.parentClaim().canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos()))
|
||||
|| claim.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos()));
|
||||
private boolean hasEditPerm(Claim claim, ServerPlayer player) {
|
||||
return ((claim.parentClaim() != null && claim.parentClaim().canInteract(player, PermissionRegistry.EDITPERMS, player.blockPosition()))
|
||||
|| claim.canInteract(player, PermissionRegistry.EDITPERMS, player.blockPosition()));
|
||||
}
|
||||
|
||||
private boolean hasPerm(Claim claim, ServerPlayerEntity player, ClaimPermission perm) {
|
||||
private boolean hasPerm(Claim claim, ServerPlayer player, ClaimPermission perm) {
|
||||
if (claim.parentClaim() != null)
|
||||
return claim.parentClaim().canInteract(player, perm, player.getBlockPos());
|
||||
return claim.canInteract(player, perm, player.getBlockPos());
|
||||
return claim.parentClaim().canInteract(player, perm, player.blockPosition());
|
||||
return claim.canInteract(player, perm, player.blockPosition());
|
||||
}
|
||||
}
|
||||
|
@ -6,20 +6,20 @@ import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.ClickEvent;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@ -27,59 +27,59 @@ public class ClaimTextHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
|
||||
private final Claim claim;
|
||||
|
||||
private ClaimTextHandler(int syncId, PlayerInventory playerInventory, Claim claim) {
|
||||
private ClaimTextHandler(int syncId, Inventory playerInventory, Claim claim) {
|
||||
super(syncId, playerInventory, 1, claim);
|
||||
this.claim = claim;
|
||||
}
|
||||
|
||||
public static void openClaimMenu(ServerPlayerEntity player, Claim claim) {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
public static void openClaimMenu(ServerPlayer player, Claim claim) {
|
||||
MenuProvider fac = new MenuProvider() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
public AbstractContainerMenu createMenu(int syncId, Inventory inv, Player player) {
|
||||
return new ClaimTextHandler(syncId, inv, claim);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
public Component getDisplayName() {
|
||||
return PermHelper.simpleColoredText(claim.parentClaim() != null ? ConfigHandler.lang.screenTitleEditorSub : ConfigHandler.lang.screenTitleEditor);
|
||||
}
|
||||
};
|
||||
player.openHandledScreen(fac);
|
||||
player.openMenu(fac);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, Claim claim) {
|
||||
protected void fillInventoryWith(Player player, SeparateInv inv, Claim claim) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, Formatting.DARK_RED));
|
||||
close.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, close);
|
||||
break;
|
||||
case 2:
|
||||
ItemStack stack = new ItemStack(Items.OAK_SIGN);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenEnterText, Formatting.GOLD));
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenEnterText, ChatFormatting.GOLD));
|
||||
if (claim.enterTitle != null)
|
||||
ServerScreenHelper.addLore(stack, claim.enterTitle);
|
||||
inv.updateStack(i, stack);
|
||||
break;
|
||||
case 3:
|
||||
ItemStack stack2 = new ItemStack(Items.OAK_SIGN);
|
||||
stack2.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenEnterSubText, Formatting.GOLD));
|
||||
stack2.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenEnterSubText, ChatFormatting.GOLD));
|
||||
if (claim.enterSubtitle != null)
|
||||
ServerScreenHelper.addLore(stack2, claim.enterSubtitle);
|
||||
inv.updateStack(i, stack2);
|
||||
break;
|
||||
case 4:
|
||||
ItemStack stack3 = new ItemStack(Items.OAK_SIGN);
|
||||
stack3.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenLeaveText, Formatting.GOLD));
|
||||
stack3.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenLeaveText, ChatFormatting.GOLD));
|
||||
if (claim.leaveTitle != null)
|
||||
ServerScreenHelper.addLore(stack3, claim.leaveTitle);
|
||||
inv.updateStack(i, stack3);
|
||||
break;
|
||||
case 5:
|
||||
ItemStack stack4 = new ItemStack(Items.OAK_SIGN);
|
||||
stack4.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenLeaveSubText, Formatting.GOLD));
|
||||
stack4.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenLeaveSubText, ChatFormatting.GOLD));
|
||||
if (claim.leaveSubtitle != null)
|
||||
ServerScreenHelper.addLore(stack4, claim.leaveSubtitle);
|
||||
inv.updateStack(i, stack4);
|
||||
@ -96,13 +96,13 @@ public class ClaimTextHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleSlotClicked(ServerPlayerEntity player, int index, Slot slot, int clickType) {
|
||||
protected boolean handleSlotClicked(ServerPlayer player, int index, Slot slot, int clickType) {
|
||||
if (index == 0) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> ClaimMenuScreenHandler.openClaimMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
} else {
|
||||
Consumer<Text> cons = null;
|
||||
Consumer<Component> cons = null;
|
||||
switch (index) {
|
||||
case 2:
|
||||
cons = text -> this.claim.setEnterTitle(text, this.claim.enterSubtitle);
|
||||
@ -118,25 +118,25 @@ public class ClaimTextHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
break;
|
||||
}
|
||||
if (cons != null) {
|
||||
player.closeHandledScreen();
|
||||
Consumer<Text> finalCons = cons;
|
||||
player.closeContainer();
|
||||
Consumer<Component> finalCons = cons;
|
||||
if (clickType == 0) {
|
||||
player.getServer().execute(() -> StringResultScreenHandler.createNewStringResult(player, (s) -> {
|
||||
player.closeHandledScreen();
|
||||
finalCons.accept(new LiteralText(s).fillStyle(Style.EMPTY.withItalic(false).withFormatting(Formatting.WHITE)));
|
||||
player.closeContainer();
|
||||
finalCons.accept(new TextComponent(s).withStyle(Style.EMPTY.withItalic(false).applyFormat(ChatFormatting.WHITE)));
|
||||
player.getServer().execute(() -> ClaimTextHandler.openClaimMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_ANVIL_USE, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ANVIL_USE, 1, 1f);
|
||||
}, () -> {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> ClaimTextHandler.openClaimMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f);
|
||||
}));
|
||||
} else {
|
||||
LiteralText text = new LiteralText(ConfigHandler.lang.chatClaimTextEdit);
|
||||
TextComponent text = new TextComponent(ConfigHandler.lang.chatClaimTextEdit);
|
||||
String command = "/flan claimMessage" + (index == 2 || index == 3 ? " enter" : " leave")
|
||||
+ (index == 2 || index == 4 ? " title" : " subtitle") + " text ";
|
||||
text.fillStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command)));
|
||||
player.sendMessage(text, false);
|
||||
text.withStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command)));
|
||||
player.displayClientMessage(text, false);
|
||||
}
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
}
|
||||
@ -144,14 +144,14 @@ public class ClaimTextHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean hasEditPerm(Claim claim, ServerPlayerEntity player) {
|
||||
return ((claim.parentClaim() != null && claim.parentClaim().canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos()))
|
||||
|| claim.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos()));
|
||||
private boolean hasEditPerm(Claim claim, ServerPlayer player) {
|
||||
return ((claim.parentClaim() != null && claim.parentClaim().canInteract(player, PermissionRegistry.EDITPERMS, player.blockPosition()))
|
||||
|| claim.canInteract(player, PermissionRegistry.EDITPERMS, player.blockPosition()));
|
||||
}
|
||||
|
||||
private boolean hasPerm(Claim claim, ServerPlayerEntity player, ClaimPermission perm) {
|
||||
private boolean hasPerm(Claim claim, ServerPlayer player, ClaimPermission perm) {
|
||||
if (claim.parentClaim() != null)
|
||||
return claim.parentClaim().canInteract(player, perm, player.getBlockPos());
|
||||
return claim.canInteract(player, perm, player.getBlockPos());
|
||||
return claim.parentClaim().canInteract(player, perm, player.blockPosition());
|
||||
return claim.canInteract(player, perm, player.blockPosition());
|
||||
}
|
||||
}
|
||||
|
@ -3,16 +3,16 @@ package io.github.flemmli97.flan.gui;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@ -20,39 +20,39 @@ public class ConfirmScreenHandler extends ServerOnlyScreenHandler<Object> {
|
||||
|
||||
private final Consumer<Boolean> cons;
|
||||
|
||||
private ConfirmScreenHandler(int syncId, PlayerInventory playerInventory, Consumer<Boolean> cons) {
|
||||
private ConfirmScreenHandler(int syncId, Inventory playerInventory, Consumer<Boolean> cons) {
|
||||
super(syncId, playerInventory, 1, null);
|
||||
this.cons = cons;
|
||||
}
|
||||
|
||||
public static void openConfirmScreen(ServerPlayerEntity player, Consumer<Boolean> process) {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
public static void openConfirmScreen(ServerPlayer player, Consumer<Boolean> process) {
|
||||
MenuProvider fac = new MenuProvider() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
public AbstractContainerMenu createMenu(int syncId, Inventory inv, Player player) {
|
||||
return new ConfirmScreenHandler(syncId, inv, process);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
public Component getDisplayName() {
|
||||
return PermHelper.simpleColoredText(ConfigHandler.lang.screenConfirm);
|
||||
}
|
||||
};
|
||||
player.openHandledScreen(fac);
|
||||
player.openMenu(fac);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, Object additionalData) {
|
||||
protected void fillInventoryWith(Player player, SeparateInv inv, Object additionalData) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
switch (i) {
|
||||
case 3:
|
||||
ItemStack yes = new ItemStack(Items.GREEN_WOOL);
|
||||
yes.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenYes, Formatting.GREEN));
|
||||
yes.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenYes, ChatFormatting.GREEN));
|
||||
inv.updateStack(i, yes);
|
||||
break;
|
||||
case 5:
|
||||
ItemStack no = new ItemStack(Items.RED_WOOL);
|
||||
no.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNo, Formatting.RED));
|
||||
no.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNo, ChatFormatting.RED));
|
||||
inv.updateStack(i, no);
|
||||
break;
|
||||
default:
|
||||
@ -67,7 +67,7 @@ public class ConfirmScreenHandler extends ServerOnlyScreenHandler<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleSlotClicked(ServerPlayerEntity player, int index, Slot slot, int clickType) {
|
||||
protected boolean handleSlotClicked(ServerPlayer player, int index, Slot slot, int clickType) {
|
||||
switch (index) {
|
||||
case 3:
|
||||
this.cons.accept(true);
|
||||
|
@ -5,20 +5,20 @@ import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import net.minecraft.block.entity.SkullBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtHelper;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.block.entity.SkullBlockEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -28,7 +28,7 @@ public class GroupPlayerScreenHandler extends ServerOnlyScreenHandler<ClaimGroup
|
||||
private final String group;
|
||||
private boolean removeMode;
|
||||
|
||||
private GroupPlayerScreenHandler(int syncId, PlayerInventory playerInventory, Claim claim, String group) {
|
||||
private GroupPlayerScreenHandler(int syncId, Inventory playerInventory, Claim claim, String group) {
|
||||
super(syncId, playerInventory, 6, new ClaimGroup() {
|
||||
|
||||
@Override
|
||||
@ -45,37 +45,37 @@ public class GroupPlayerScreenHandler extends ServerOnlyScreenHandler<ClaimGroup
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public static void openPlayerGroupMenu(PlayerEntity player, Claim claim, String group) {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
public static void openPlayerGroupMenu(Player player, Claim claim, String group) {
|
||||
MenuProvider fac = new MenuProvider() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
public AbstractContainerMenu createMenu(int syncId, Inventory inv, Player player) {
|
||||
return new GroupPlayerScreenHandler(syncId, inv, claim, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
public Component getDisplayName() {
|
||||
return PermHelper.simpleColoredText(String.format(ConfigHandler.lang.screenGroupPlayers, group));
|
||||
}
|
||||
};
|
||||
player.openHandledScreen(fac);
|
||||
player.openMenu(fac);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, ClaimGroup additionalData) {
|
||||
protected void fillInventoryWith(Player player, SeparateInv inv, ClaimGroup additionalData) {
|
||||
Claim claim = additionalData.getClaim();
|
||||
List<String> players = claim.playersFromGroup(player.getServer(), additionalData.getGroup());
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, Formatting.DARK_RED));
|
||||
close.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, close);
|
||||
} else if (i == 3) {
|
||||
ItemStack stack = new ItemStack(Items.ANVIL);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenAdd, Formatting.DARK_GREEN));
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenAdd, ChatFormatting.DARK_GREEN));
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i == 4) {
|
||||
ItemStack stack = new ItemStack(Items.REDSTONE_BLOCK);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse), Formatting.DARK_RED));
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse), ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
inv.updateStack(i, ServerScreenHelper.emptyFiller());
|
||||
@ -85,8 +85,7 @@ public class GroupPlayerScreenHandler extends ServerOnlyScreenHandler<ClaimGroup
|
||||
if (id < players.size()) {
|
||||
ItemStack group = new ItemStack(Items.PLAYER_HEAD);
|
||||
GameProfile gameProfile = new GameProfile(null, players.get(id));
|
||||
gameProfile = SkullBlockEntity.loadProperties(gameProfile);
|
||||
group.getOrCreateTag().put("SkullOwner", NbtHelper.fromGameProfile(new CompoundTag(), gameProfile));
|
||||
SkullBlockEntity.updateGameprofile(gameProfile, prof -> group.getOrCreateTag().put("SkullOwner", NbtUtils.writeGameProfile(new CompoundTag(), prof)));
|
||||
inv.updateStack(i, group);
|
||||
}
|
||||
}
|
||||
@ -99,30 +98,29 @@ public class GroupPlayerScreenHandler extends ServerOnlyScreenHandler<ClaimGroup
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleSlotClicked(ServerPlayerEntity player, int index, Slot slot, int clickType) {
|
||||
protected boolean handleSlotClicked(ServerPlayer player, int index, Slot slot, int clickType) {
|
||||
if (index == 0) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> GroupScreenHandler.openGroupMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
return true;
|
||||
}
|
||||
if (index == 3) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> StringResultScreenHandler.createNewStringResult(player, (s) -> {
|
||||
GameProfile prof = player.getServer().getUserCache().findByName(s);
|
||||
boolean fl = prof == null || this.claim.setPlayerGroup(prof.getId(), this.group, false);
|
||||
player.closeHandledScreen();
|
||||
boolean fl = player.getServer().getProfileCache().get(s).map(prof -> this.claim.setPlayerGroup(prof.getId(), this.group, false)).orElse(true);
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> GroupPlayerScreenHandler.openPlayerGroupMenu(player, this.claim, this.group));
|
||||
if (fl)
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_ANVIL_USE, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ANVIL_USE, 1, 1f);
|
||||
else {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.playerGroupAddFail, Formatting.RED), false);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.playerGroupAddFail, ChatFormatting.RED), false);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f);
|
||||
}
|
||||
}, () -> {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> GroupPlayerScreenHandler.openPlayerGroupMenu(player, this.claim, this.group));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f);
|
||||
}));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
return true;
|
||||
@ -130,18 +128,18 @@ public class GroupPlayerScreenHandler extends ServerOnlyScreenHandler<ClaimGroup
|
||||
if (index == 4) {
|
||||
this.removeMode = !this.removeMode;
|
||||
ItemStack stack = new ItemStack(Items.REDSTONE_BLOCK);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse), Formatting.DARK_RED));
|
||||
slot.setStack(stack);
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse), ChatFormatting.DARK_RED));
|
||||
slot.set(stack);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
return true;
|
||||
}
|
||||
ItemStack stack = slot.getStack();
|
||||
ItemStack stack = slot.getItem();
|
||||
if (!stack.isEmpty()) {
|
||||
CompoundTag tag = stack.getOrCreateSubTag("SkullOwner");
|
||||
CompoundTag tag = stack.getOrCreateTagElement("SkullOwner");
|
||||
if (this.removeMode && tag.contains("Id")) {
|
||||
this.claim.setPlayerGroup(tag.getUuid("Id"), null, false);
|
||||
slot.setStack(ItemStack.EMPTY);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_BAT_DEATH, 1, 1f);
|
||||
this.claim.setPlayerGroup(tag.getUUID("Id"), null, false);
|
||||
slot.set(ItemStack.EMPTY);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BAT_DEATH, 1, 1f);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -5,17 +5,17 @@ import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -25,40 +25,40 @@ public class GroupScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
|
||||
private boolean removeMode;
|
||||
|
||||
private GroupScreenHandler(int syncId, PlayerInventory playerInventory, Claim claim) {
|
||||
private GroupScreenHandler(int syncId, Inventory playerInventory, Claim claim) {
|
||||
super(syncId, playerInventory, 6, claim);
|
||||
this.claim = claim;
|
||||
}
|
||||
|
||||
public static void openGroupMenu(PlayerEntity player, Claim claim) {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
public static void openGroupMenu(Player player, Claim claim) {
|
||||
MenuProvider fac = new MenuProvider() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
public AbstractContainerMenu createMenu(int syncId, Inventory inv, Player player) {
|
||||
return new GroupScreenHandler(syncId, inv, claim);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
public Component getDisplayName() {
|
||||
return PermHelper.simpleColoredText(ConfigHandler.lang.screenGroups);
|
||||
}
|
||||
};
|
||||
player.openHandledScreen(fac);
|
||||
player.openMenu(fac);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, Claim claim) {
|
||||
protected void fillInventoryWith(Player player, SeparateInv inv, Claim claim) {
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack stack = new ItemStack(Items.TNT);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, Formatting.DARK_RED));
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i == 3) {
|
||||
ItemStack stack = new ItemStack(Items.ANVIL);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenAdd, Formatting.DARK_GREEN));
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenAdd, ChatFormatting.DARK_GREEN));
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i == 4) {
|
||||
ItemStack stack = new ItemStack(Items.REDSTONE_BLOCK);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse), Formatting.DARK_RED));
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse), ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
inv.updateStack(i, ServerScreenHelper.emptyFiller());
|
||||
@ -68,7 +68,7 @@ public class GroupScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
int id = (i % 9) + row * 7 - 1;
|
||||
if (id < groups.size()) {
|
||||
ItemStack group = new ItemStack(Items.PAPER);
|
||||
group.setCustomName(ServerScreenHelper.coloredGuiText(groups.get(id), Formatting.DARK_BLUE));
|
||||
group.setHoverName(ServerScreenHelper.coloredGuiText(groups.get(id), ChatFormatting.DARK_BLUE));
|
||||
inv.updateStack(i, group);
|
||||
}
|
||||
}
|
||||
@ -81,24 +81,24 @@ public class GroupScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleSlotClicked(ServerPlayerEntity player, int index, Slot slot, int clickType) {
|
||||
protected boolean handleSlotClicked(ServerPlayer player, int index, Slot slot, int clickType) {
|
||||
if (index == 0) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> ClaimMenuScreenHandler.openClaimMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
return true;
|
||||
}
|
||||
if (index == 3) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> StringResultScreenHandler.createNewStringResult(player, (s) -> {
|
||||
this.claim.editPerms(player, s, PermissionRegistry.EDITPERMS, -1);
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> GroupScreenHandler.openGroupMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_ANVIL_USE, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ANVIL_USE, 1, 1f);
|
||||
}, () -> {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> GroupScreenHandler.openGroupMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f);
|
||||
}));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
return true;
|
||||
@ -106,24 +106,24 @@ public class GroupScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
if (index == 4) {
|
||||
this.removeMode = !this.removeMode;
|
||||
ItemStack stack = new ItemStack(Items.REDSTONE_BLOCK);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse), Formatting.DARK_RED));
|
||||
slot.setStack(stack);
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse), ChatFormatting.DARK_RED));
|
||||
slot.set(stack);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
return true;
|
||||
}
|
||||
ItemStack stack = slot.getStack();
|
||||
ItemStack stack = slot.getItem();
|
||||
if (!stack.isEmpty()) {
|
||||
String name = stack.getName().asString();
|
||||
String name = stack.getHoverName().getContents();
|
||||
if (this.removeMode) {
|
||||
this.claim.removePermGroup(player, name);
|
||||
slot.setStack(ItemStack.EMPTY);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_BAT_DEATH, 1, 1f);
|
||||
slot.set(ItemStack.EMPTY);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BAT_DEATH, 1, 1f);
|
||||
} else {
|
||||
if (clickType == 1) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> PermissionScreenHandler.openClaimMenu(player, this.claim, name));
|
||||
} else {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> GroupPlayerScreenHandler.openPlayerGroupMenu(player, this.claim, name));
|
||||
}
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
|
@ -3,45 +3,45 @@ package io.github.flemmli97.flan.gui;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.mixin.ILecternBlockValues;
|
||||
import net.minecraft.block.entity.LecternBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.screen.LecternScreenHandler;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.PropertyDelegate;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ContainerData;
|
||||
import net.minecraft.world.inventory.LecternMenu;
|
||||
import net.minecraft.world.level.block.entity.LecternBlockEntity;
|
||||
|
||||
public class LockedLecternScreenHandler extends LecternScreenHandler {
|
||||
public class LockedLecternScreenHandler extends LecternMenu {
|
||||
|
||||
public LockedLecternScreenHandler(int syncId, Inventory inventory, PropertyDelegate propertyDelegate) {
|
||||
public LockedLecternScreenHandler(int syncId, Container inventory, ContainerData propertyDelegate) {
|
||||
super(syncId, inventory, propertyDelegate);
|
||||
}
|
||||
|
||||
public static void create(ServerPlayerEntity player, LecternBlockEntity lectern) {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
public static void create(ServerPlayer player, LecternBlockEntity lectern) {
|
||||
MenuProvider fac = new MenuProvider() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
public AbstractContainerMenu createMenu(int syncId, Inventory inv, Player player) {
|
||||
return new LockedLecternScreenHandler(syncId, ((ILecternBlockValues) lectern).getInv(), ((ILecternBlockValues) lectern).getProp());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
public Component getDisplayName() {
|
||||
return lectern.getDisplayName();
|
||||
}
|
||||
};
|
||||
player.openHandledScreen(fac);
|
||||
player.openMenu(fac);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onButtonClick(PlayerEntity player, int id) {
|
||||
public boolean clickMenuButton(Player player, int id) {
|
||||
if (id == 3) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false);
|
||||
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, ChatFormatting.DARK_RED), false);
|
||||
return false;
|
||||
}
|
||||
return super.onButtonClick(player, id);
|
||||
return super.clickMenuButton(player, id);
|
||||
}
|
||||
}
|
||||
|
@ -6,17 +6,17 @@ import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -28,7 +28,7 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler<ClaimGroup>
|
||||
private int page, maxPages;
|
||||
private List<ClaimPermission> perms;
|
||||
|
||||
private PermissionScreenHandler(int syncId, PlayerInventory playerInventory, Claim claim, String group) {
|
||||
private PermissionScreenHandler(int syncId, Inventory playerInventory, Claim claim, String group) {
|
||||
super(syncId, playerInventory, 6, new ClaimGroup() {
|
||||
@Override
|
||||
public Claim getClaim() {
|
||||
@ -44,23 +44,23 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler<ClaimGroup>
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public static void openClaimMenu(PlayerEntity player, Claim claim, String group) {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
public static void openClaimMenu(Player player, Claim claim, String group) {
|
||||
MenuProvider fac = new MenuProvider() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
public AbstractContainerMenu createMenu(int syncId, Inventory inv, Player player) {
|
||||
return new PermissionScreenHandler(syncId, inv, claim, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
public Component getDisplayName() {
|
||||
return PermHelper.simpleColoredText(group == null ? ConfigHandler.lang.screenGlobalPerms : String.format(ConfigHandler.lang.screenGroupPerms, group));
|
||||
}
|
||||
};
|
||||
player.openHandledScreen(fac);
|
||||
player.openMenu(fac);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, ClaimGroup additionalData) {
|
||||
protected void fillInventoryWith(Player player, SeparateInv inv, ClaimGroup additionalData) {
|
||||
this.perms = new ArrayList<>(PermissionRegistry.getPerms());
|
||||
if (additionalData.getGroup() != null)
|
||||
this.perms.removeAll(PermissionRegistry.globalPerms());
|
||||
@ -68,11 +68,11 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler<ClaimGroup>
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, Formatting.DARK_RED));
|
||||
close.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, close);
|
||||
} else if (i == 51) {
|
||||
ItemStack close = new ItemStack(Items.ARROW);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNext, Formatting.WHITE));
|
||||
close.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNext, ChatFormatting.WHITE));
|
||||
inv.updateStack(i, close);
|
||||
} else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
inv.updateStack(i, ServerScreenHelper.emptyFiller());
|
||||
@ -89,44 +89,44 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler<ClaimGroup>
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, Formatting.DARK_RED));
|
||||
this.slots.get(i).setStack(close);
|
||||
close.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, ChatFormatting.DARK_RED));
|
||||
this.slots.get(i).set(close);
|
||||
} else if (i == 47) {
|
||||
ItemStack stack = ServerScreenHelper.emptyFiller();
|
||||
if (this.page >= 1) {
|
||||
stack = new ItemStack(Items.ARROW);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenPrevious, Formatting.WHITE));
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenPrevious, ChatFormatting.WHITE));
|
||||
}
|
||||
this.slots.get(i).setStack(stack);
|
||||
this.slots.get(i).set(stack);
|
||||
} else if (i == 51) {
|
||||
ItemStack stack = ServerScreenHelper.emptyFiller();
|
||||
if (this.page < this.maxPages) {
|
||||
stack = new ItemStack(Items.ARROW);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNext, Formatting.WHITE));
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNext, ChatFormatting.WHITE));
|
||||
}
|
||||
this.slots.get(i).setStack(stack);
|
||||
this.slots.get(i).set(stack);
|
||||
} else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
this.slots.get(i).setStack(ServerScreenHelper.emptyFiller());
|
||||
this.slots.get(i).set(ServerScreenHelper.emptyFiller());
|
||||
else {
|
||||
int row = i / 9 - 1;
|
||||
int id = (i % 9) + row * 7 - 1 + this.page * 28;
|
||||
if (id < this.perms.size()) {
|
||||
this.slots.get(i).setStack(ServerScreenHelper.fromPermission(this.claim, this.perms.get(id), this.group));
|
||||
this.slots.get(i).set(ServerScreenHelper.fromPermission(this.claim, this.perms.get(id), this.group));
|
||||
} else
|
||||
this.slots.get(i).setStack(ItemStack.EMPTY);
|
||||
this.slots.get(i).set(ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
this.sendContentUpdates();
|
||||
this.broadcastChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleSlotClicked(ServerPlayerEntity player, int index, Slot slot, int clickType) {
|
||||
protected boolean handleSlotClicked(ServerPlayer player, int index, Slot slot, int clickType) {
|
||||
if (index == 0) {
|
||||
if (this.group == null) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> ClaimMenuScreenHandler.openClaimMenu(player, this.claim));
|
||||
} else {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> GroupScreenHandler.openGroupMenu(player, this.claim));
|
||||
}
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
@ -142,8 +142,8 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler<ClaimGroup>
|
||||
this.flipPage();
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
}
|
||||
ItemStack stack = slot.getStack();
|
||||
String name = stack.getName().asString();
|
||||
ItemStack stack = slot.getItem();
|
||||
String name = stack.getHoverName().getContents();
|
||||
ClaimPermission perm;
|
||||
try {
|
||||
perm = PermissionRegistry.get(name);
|
||||
@ -160,11 +160,11 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler<ClaimGroup>
|
||||
success = this.claim.editGlobalPerms(player, perm, mode);
|
||||
} else
|
||||
success = this.claim.editPerms(player, this.group, perm, this.claim.groupHasPerm(this.group, perm) + 1);
|
||||
slot.setStack(ServerScreenHelper.fromPermission(this.claim, perm, this.group));
|
||||
slot.set(ServerScreenHelper.fromPermission(this.claim, perm, this.group));
|
||||
if (success)
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_NOTE_BLOCK_PLING, 1, 1.2f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.NOTE_BLOCK_PLING, 1, 1.2f);
|
||||
else
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -5,17 +5,17 @@ import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -24,52 +24,52 @@ public class PersonalGroupScreenHandler extends ServerOnlyScreenHandler<Object>
|
||||
|
||||
private boolean removeMode;
|
||||
|
||||
private PersonalGroupScreenHandler(int syncId, PlayerInventory playerInventory) {
|
||||
private PersonalGroupScreenHandler(int syncId, Inventory playerInventory) {
|
||||
super(syncId, playerInventory, 6, null);
|
||||
}
|
||||
|
||||
public static void openGroupMenu(PlayerEntity player) {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
public static void openGroupMenu(Player player) {
|
||||
MenuProvider fac = new MenuProvider() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
public AbstractContainerMenu createMenu(int syncId, Inventory inv, Player player) {
|
||||
return new PersonalGroupScreenHandler(syncId, inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
public Component getDisplayName() {
|
||||
return PermHelper.simpleColoredText(ConfigHandler.lang.screenPersonalGroups);
|
||||
}
|
||||
};
|
||||
player.openHandledScreen(fac);
|
||||
player.openMenu(fac);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, Object additionalData) {
|
||||
if (!(player instanceof ServerPlayerEntity))
|
||||
protected void fillInventoryWith(Player player, SeparateInv inv, Object additionalData) {
|
||||
if (!(player instanceof ServerPlayer))
|
||||
return;
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, Formatting.DARK_RED));
|
||||
close.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, close);
|
||||
} else if (i == 3) {
|
||||
ItemStack stack = new ItemStack(Items.ANVIL);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenAdd, Formatting.DARK_GREEN));
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenAdd, ChatFormatting.DARK_GREEN));
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i == 4) {
|
||||
ItemStack stack = new ItemStack(Items.REDSTONE_BLOCK);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse), Formatting.DARK_RED));
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse), ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
inv.updateStack(i, ServerScreenHelper.emptyFiller());
|
||||
else {
|
||||
List<String> groups = new ArrayList<>(PlayerClaimData.get((ServerPlayerEntity) player).playerDefaultGroups().keySet());
|
||||
List<String> groups = new ArrayList<>(PlayerClaimData.get((ServerPlayer) player).playerDefaultGroups().keySet());
|
||||
groups.sort(null);
|
||||
int row = i / 9 - 1;
|
||||
int id = (i % 9) + row * 7 - 1;
|
||||
if (id < groups.size()) {
|
||||
ItemStack group = new ItemStack(Items.PAPER);
|
||||
group.setCustomName(ServerScreenHelper.coloredGuiText(groups.get(id), Formatting.DARK_BLUE));
|
||||
group.setHoverName(ServerScreenHelper.coloredGuiText(groups.get(id), ChatFormatting.DARK_BLUE));
|
||||
inv.updateStack(i, group);
|
||||
}
|
||||
}
|
||||
@ -82,23 +82,23 @@ public class PersonalGroupScreenHandler extends ServerOnlyScreenHandler<Object>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleSlotClicked(ServerPlayerEntity player, int index, Slot slot, int clickType) {
|
||||
protected boolean handleSlotClicked(ServerPlayer player, int index, Slot slot, int clickType) {
|
||||
if (index == 0) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
return true;
|
||||
}
|
||||
if (index == 3) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> StringResultScreenHandler.createNewStringResult(player, (s) -> {
|
||||
PlayerClaimData.get(player).editDefaultPerms(s, PermissionRegistry.EDITPERMS, -1);
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> PersonalGroupScreenHandler.openGroupMenu(player));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_ANVIL_USE, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ANVIL_USE, 1, 1f);
|
||||
}, () -> {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> PersonalGroupScreenHandler.openGroupMenu(player));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f);
|
||||
}));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
return true;
|
||||
@ -106,20 +106,20 @@ public class PersonalGroupScreenHandler extends ServerOnlyScreenHandler<Object>
|
||||
if (index == 4) {
|
||||
this.removeMode = !this.removeMode;
|
||||
ItemStack stack = new ItemStack(Items.REDSTONE_BLOCK);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse), Formatting.DARK_RED));
|
||||
slot.setStack(stack);
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse), ChatFormatting.DARK_RED));
|
||||
slot.set(stack);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
return true;
|
||||
}
|
||||
ItemStack stack = slot.getStack();
|
||||
ItemStack stack = slot.getItem();
|
||||
if (!stack.isEmpty()) {
|
||||
String name = stack.getName().asString();
|
||||
String name = stack.getHoverName().getContents();
|
||||
if (this.removeMode) {
|
||||
PlayerClaimData.get(player).playerDefaultGroups().remove(name);
|
||||
slot.setStack(ItemStack.EMPTY);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_BAT_DEATH, 1, 1f);
|
||||
slot.set(ItemStack.EMPTY);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BAT_DEATH, 1, 1f);
|
||||
} else {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> PersonalPermissionScreenHandler.openClaimMenu(player, name));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
}
|
||||
|
@ -6,17 +6,17 @@ import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -27,32 +27,32 @@ public class PersonalPermissionScreenHandler extends ServerOnlyScreenHandler<Str
|
||||
|
||||
private final String group;
|
||||
private int page;
|
||||
private final PlayerEntity player;
|
||||
private final Player player;
|
||||
|
||||
private PersonalPermissionScreenHandler(int syncId, PlayerInventory playerInventory, String group) {
|
||||
private PersonalPermissionScreenHandler(int syncId, Inventory playerInventory, String group) {
|
||||
super(syncId, playerInventory, 6, group);
|
||||
this.group = group;
|
||||
this.player = playerInventory.player;
|
||||
}
|
||||
|
||||
public static void openClaimMenu(PlayerEntity player, String group) {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
public static void openClaimMenu(Player player, String group) {
|
||||
MenuProvider fac = new MenuProvider() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
public AbstractContainerMenu createMenu(int syncId, Inventory inv, Player player) {
|
||||
return new PersonalPermissionScreenHandler(syncId, inv, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
public Component getDisplayName() {
|
||||
return PermHelper.simpleColoredText(String.format(ConfigHandler.lang.screenPersonalPermissions, group));
|
||||
}
|
||||
};
|
||||
player.openHandledScreen(fac);
|
||||
player.openMenu(fac);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, String group) {
|
||||
if (!(player instanceof ServerPlayerEntity))
|
||||
protected void fillInventoryWith(Player player, SeparateInv inv, String group) {
|
||||
if (!(player instanceof ServerPlayer))
|
||||
return;
|
||||
List<ClaimPermission> perms = new ArrayList<>(PermissionRegistry.getPerms());
|
||||
if (this.group != null)
|
||||
@ -61,15 +61,15 @@ public class PersonalPermissionScreenHandler extends ServerOnlyScreenHandler<Str
|
||||
int page = 0;
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, Formatting.DARK_RED));
|
||||
close.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, close);
|
||||
} else if (page == 1 && i == 47) {
|
||||
ItemStack close = new ItemStack(Items.ARROW);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenPrevious, Formatting.WHITE));
|
||||
close.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenPrevious, ChatFormatting.WHITE));
|
||||
inv.updateStack(i, close);
|
||||
} else if (page == 0 && i == 51) {
|
||||
ItemStack close = new ItemStack(Items.ARROW);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNext, Formatting.WHITE));
|
||||
close.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNext, ChatFormatting.WHITE));
|
||||
inv.updateStack(i, close);
|
||||
} else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
inv.updateStack(i, ServerScreenHelper.emptyFiller());
|
||||
@ -77,13 +77,13 @@ public class PersonalPermissionScreenHandler extends ServerOnlyScreenHandler<Str
|
||||
int row = i / 9 - 1;
|
||||
int id = (i % 9) + row * 7 - 1 + page * 28;
|
||||
if (id < perms.size())
|
||||
inv.updateStack(i, ServerScreenHelper.getFromPersonal((ServerPlayerEntity) player, perms.get(id), group));
|
||||
inv.updateStack(i, ServerScreenHelper.getFromPersonal((ServerPlayer) player, perms.get(id), group));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void flipPage() {
|
||||
if (!(this.player instanceof ServerPlayerEntity))
|
||||
if (!(this.player instanceof ServerPlayer))
|
||||
return;
|
||||
List<ClaimPermission> perms = new ArrayList<>(PermissionRegistry.getPerms());
|
||||
if (this.group != null)
|
||||
@ -92,40 +92,40 @@ public class PersonalPermissionScreenHandler extends ServerOnlyScreenHandler<Str
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, Formatting.DARK_RED));
|
||||
this.slots.get(i).setStack(close);
|
||||
close.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, ChatFormatting.DARK_RED));
|
||||
this.slots.get(i).set(close);
|
||||
} else if (i == 47) {
|
||||
ItemStack stack = ServerScreenHelper.emptyFiller();
|
||||
if (this.page >= 1) {
|
||||
stack = new ItemStack(Items.ARROW);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenPrevious, Formatting.WHITE));
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenPrevious, ChatFormatting.WHITE));
|
||||
}
|
||||
this.slots.get(i).setStack(stack);
|
||||
this.slots.get(i).set(stack);
|
||||
} else if (i == 51) {
|
||||
ItemStack stack = ServerScreenHelper.emptyFiller();
|
||||
if (this.page < maxPages) {
|
||||
stack = new ItemStack(Items.ARROW);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNext, Formatting.WHITE));
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenNext, ChatFormatting.WHITE));
|
||||
}
|
||||
this.slots.get(i).setStack(stack);
|
||||
this.slots.get(i).set(stack);
|
||||
} else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
this.slots.get(i).setStack(ServerScreenHelper.emptyFiller());
|
||||
this.slots.get(i).set(ServerScreenHelper.emptyFiller());
|
||||
else {
|
||||
int row = i / 9 - 1;
|
||||
int id = (i % 9) + row * 7 - 1 + this.page * 28;
|
||||
if (id < perms.size()) {
|
||||
this.slots.get(i).setStack(ServerScreenHelper.getFromPersonal((ServerPlayerEntity) this.player, perms.get(id), this.group));
|
||||
this.slots.get(i).set(ServerScreenHelper.getFromPersonal((ServerPlayer) this.player, perms.get(id), this.group));
|
||||
} else
|
||||
this.slots.get(i).setStack(ItemStack.EMPTY);
|
||||
this.slots.get(i).set(ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
this.sendContentUpdates();
|
||||
this.broadcastChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleSlotClicked(ServerPlayerEntity player, int index, Slot slot, int clickType) {
|
||||
protected boolean handleSlotClicked(ServerPlayer player, int index, Slot slot, int clickType) {
|
||||
if (index == 0) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> PersonalGroupScreenHandler.openGroupMenu(player));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
return true;
|
||||
@ -140,8 +140,8 @@ public class PersonalPermissionScreenHandler extends ServerOnlyScreenHandler<Str
|
||||
this.flipPage();
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
}
|
||||
ItemStack stack = slot.getStack();
|
||||
String name = stack.getName().asString();
|
||||
ItemStack stack = slot.getItem();
|
||||
String name = stack.getHoverName().getContents();
|
||||
ClaimPermission perm;
|
||||
try {
|
||||
perm = PermissionRegistry.get(name);
|
||||
@ -151,11 +151,11 @@ public class PersonalPermissionScreenHandler extends ServerOnlyScreenHandler<Str
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
Map<ClaimPermission, Boolean> perms = data.playerDefaultGroups().getOrDefault(this.group, new HashMap<>());
|
||||
boolean success = data.editDefaultPerms(this.group, perm, (perms.containsKey(perm) ? perms.get(perm) ? 1 : 0 : -1) + 1);
|
||||
slot.setStack(ServerScreenHelper.getFromPersonal(player, perm, this.group));
|
||||
slot.set(ServerScreenHelper.getFromPersonal(player, perm, this.group));
|
||||
if (success)
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_NOTE_BLOCK_PLING, 1, 1.2f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.NOTE_BLOCK_PLING, 1, 1.2f);
|
||||
else
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -6,23 +6,23 @@ import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.entity.effect.StatusEffects;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.potion.PotionUtil;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.alchemy.PotionUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -36,43 +36,43 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
|
||||
private boolean removeMode;
|
||||
|
||||
protected PotionEditScreenHandler(int syncId, PlayerInventory playerInventory, Claim claim) {
|
||||
protected PotionEditScreenHandler(int syncId, Inventory playerInventory, Claim claim) {
|
||||
super(syncId, playerInventory, 6, claim);
|
||||
this.claim = claim;
|
||||
}
|
||||
|
||||
public static void openPotionMenu(PlayerEntity player, Claim claim) {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
public static void openPotionMenu(Player player, Claim claim) {
|
||||
MenuProvider fac = new MenuProvider() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
public AbstractContainerMenu createMenu(int syncId, Inventory inv, Player player) {
|
||||
return new PotionEditScreenHandler(syncId, inv, claim);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
public Component getDisplayName() {
|
||||
return PermHelper.simpleColoredText(ConfigHandler.lang.screenPotions);
|
||||
}
|
||||
};
|
||||
player.openHandledScreen(fac);
|
||||
player.openMenu(fac);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillInventoryWith(PlayerEntity player, SeparateInv inv, Claim claim) {
|
||||
Map<StatusEffect, Integer> potions = claim.getPotions();
|
||||
List<StatusEffect> key = Lists.newArrayList(potions.keySet());
|
||||
protected void fillInventoryWith(Player player, SeparateInv inv, Claim claim) {
|
||||
Map<MobEffect, Integer> potions = claim.getPotions();
|
||||
List<MobEffect> key = Lists.newArrayList(potions.keySet());
|
||||
key.sort(Comparator.comparing(eff -> CrossPlatformStuff.registryStatusEffects().getIDFrom(eff).toString()));
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, Formatting.DARK_RED));
|
||||
close.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenBack, ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, close);
|
||||
} else if (i == 3) {
|
||||
ItemStack stack = new ItemStack(Items.ANVIL);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenAdd, Formatting.DARK_GREEN));
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenAdd, ChatFormatting.DARK_GREEN));
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i == 4) {
|
||||
ItemStack stack = new ItemStack(Items.REDSTONE_BLOCK);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse), Formatting.DARK_RED));
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse), ChatFormatting.DARK_RED));
|
||||
inv.updateStack(i, stack);
|
||||
} else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
inv.updateStack(i, ServerScreenHelper.emptyFiller());
|
||||
@ -80,13 +80,13 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
int row = i / 9 - 1;
|
||||
int id = (i % 9) + row * 7 - 1;
|
||||
if (id < potions.size()) {
|
||||
StatusEffect effect = key.get(id);
|
||||
MobEffect effect = key.get(id);
|
||||
ItemStack effectStack = new ItemStack(Items.POTION);
|
||||
TranslatableText txt = new TranslatableText(effect.getTranslationKey());
|
||||
Collection<StatusEffectInstance> inst = Collections.singleton(new StatusEffectInstance(effect, 0, potions.get(effect)));
|
||||
TranslatableComponent txt = new TranslatableComponent(effect.getDescriptionId());
|
||||
Collection<MobEffectInstance> inst = Collections.singleton(new MobEffectInstance(effect, 0, potions.get(effect)));
|
||||
effectStack.getOrCreateTag().putString("FlanEffect", CrossPlatformStuff.registryStatusEffects().getIDFrom(effect).toString());
|
||||
effectStack.getTag().putInt("CustomPotionColor", PotionUtil.getColor(inst));
|
||||
effectStack.setCustomName(txt.setStyle(txt.getStyle().withItalic(false).withFormatting(Formatting.DARK_BLUE)).append(ServerScreenHelper.coloredGuiText("-" + potions.get(effect), Formatting.DARK_BLUE)));
|
||||
effectStack.getTag().putInt("CustomPotionColor", PotionUtils.getColor(inst));
|
||||
effectStack.setHoverName(txt.setStyle(txt.getStyle().withItalic(false).applyFormat(ChatFormatting.DARK_BLUE)).append(ServerScreenHelper.coloredGuiText("-" + potions.get(effect), ChatFormatting.DARK_BLUE)));
|
||||
inv.updateStack(i, effectStack);
|
||||
}
|
||||
}
|
||||
@ -99,21 +99,21 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleSlotClicked(ServerPlayerEntity player, int index, Slot slot, int clickType) {
|
||||
protected boolean handleSlotClicked(ServerPlayer player, int index, Slot slot, int clickType) {
|
||||
if (index == 0) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> ClaimMenuScreenHandler.openClaimMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
return true;
|
||||
}
|
||||
if (index == 3) {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> StringResultScreenHandler.createNewStringResult(player, (s) -> {
|
||||
String[] potion = s.split(";");
|
||||
int amp = 1;
|
||||
StatusEffect effect = CrossPlatformStuff.registryStatusEffects().getFromId(new Identifier(potion[0]));
|
||||
if (effect == null || (effect == StatusEffects.LUCK && !potion[0].equals("minecraft:luck"))) {
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
MobEffect effect = CrossPlatformStuff.registryStatusEffects().getFromId(new ResourceLocation(potion[0]));
|
||||
if (effect == null || (effect == MobEffects.LUCK && !potion[0].equals("minecraft:luck"))) {
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f);
|
||||
return;
|
||||
}
|
||||
if (potion.length > 1) {
|
||||
@ -123,13 +123,13 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
}
|
||||
}
|
||||
this.claim.addPotion(effect, amp);
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> PotionEditScreenHandler.openPotionMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_ANVIL_USE, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ANVIL_USE, 1, 1f);
|
||||
}, () -> {
|
||||
player.closeHandledScreen();
|
||||
player.closeContainer();
|
||||
player.getServer().execute(() -> PotionEditScreenHandler.openPotionMenu(player, this.claim));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f);
|
||||
}));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
return true;
|
||||
@ -137,17 +137,17 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
if (index == 4) {
|
||||
this.removeMode = !this.removeMode;
|
||||
ItemStack stack = new ItemStack(Items.REDSTONE_BLOCK);
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse), Formatting.DARK_RED));
|
||||
slot.setStack(stack);
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenRemoveMode, this.removeMode ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse), ChatFormatting.DARK_RED));
|
||||
slot.set(stack);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
return true;
|
||||
}
|
||||
ItemStack stack = slot.getStack();
|
||||
ItemStack stack = slot.getItem();
|
||||
if (!stack.isEmpty() && this.removeMode) {
|
||||
String effect = stack.getOrCreateTag().getString("FlanEffect");
|
||||
this.claim.removePotion(CrossPlatformStuff.registryStatusEffects().getFromId(new Identifier(effect)));
|
||||
slot.setStack(ItemStack.EMPTY);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_BAT_DEATH, 1, 1f);
|
||||
this.claim.removePotion(CrossPlatformStuff.registryStatusEffects().getFromId(new ResourceLocation(effect)));
|
||||
slot.set(ItemStack.EMPTY);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BAT_DEATH, 1, 1f);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -3,27 +3,24 @@ package io.github.flemmli97.flan.gui;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInv;
|
||||
import io.github.flemmli97.flan.gui.inv.SeparateInvImpl;
|
||||
import io.github.flemmli97.flan.gui.inv.SlotDelegate;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.GenericContainerScreenHandler;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.ScreenHandlerListener;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.screen.slot.SlotActionType;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import io.github.flemmli97.flan.mixin.AbstractContainerAccessor;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ChestMenu;
|
||||
import net.minecraft.world.inventory.ClickType;
|
||||
import net.minecraft.world.inventory.ContainerListener;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ServerOnlyScreenHandler<T> extends ScreenHandler {
|
||||
public abstract class ServerOnlyScreenHandler<T> extends AbstractContainerMenu {
|
||||
|
||||
private final SeparateInvImpl inventory;
|
||||
private final List<ScreenHandlerListener> listeners = new ArrayList<>();
|
||||
private boolean update = true;
|
||||
|
||||
protected ServerOnlyScreenHandler(int syncId, PlayerInventory playerInventory, int rows, T additionalData) {
|
||||
protected ServerOnlyScreenHandler(int syncId, Inventory playerInventory, int rows, T additionalData) {
|
||||
super(fromRows(rows), syncId);
|
||||
int i = (rows - 4) * 18;
|
||||
this.inventory = new SeparateInvImpl(rows * 9);
|
||||
@ -40,12 +37,12 @@ public abstract class ServerOnlyScreenHandler<T> extends ScreenHandler {
|
||||
for (m = 0; m < 9; ++m) {
|
||||
this.addSlot(new Slot(playerInventory, m + n * 9 + 9, 8 + m * 18, 103 + n * 18 + i) {
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack) {
|
||||
public boolean mayPlace(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeItems(PlayerEntity playerEntity) {
|
||||
public boolean mayPickup(Player playerEntity) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
@ -55,81 +52,82 @@ public abstract class ServerOnlyScreenHandler<T> extends ScreenHandler {
|
||||
for (n = 0; n < 9; ++n) {
|
||||
this.addSlot(new Slot(playerInventory, n, 8 + n * 18, 161 + i) {
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack) {
|
||||
public boolean mayPlace(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeItems(PlayerEntity playerEntity) {
|
||||
public boolean mayPickup(Player playerEntity) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static ScreenHandlerType<GenericContainerScreenHandler> fromRows(int rows) {
|
||||
private static MenuType<ChestMenu> fromRows(int rows) {
|
||||
switch (rows) {
|
||||
case 2:
|
||||
return ScreenHandlerType.GENERIC_9X2;
|
||||
return MenuType.GENERIC_9x2;
|
||||
case 3:
|
||||
return ScreenHandlerType.GENERIC_9X3;
|
||||
return MenuType.GENERIC_9x3;
|
||||
case 4:
|
||||
return ScreenHandlerType.GENERIC_9X4;
|
||||
return MenuType.GENERIC_9x4;
|
||||
case 5:
|
||||
return ScreenHandlerType.GENERIC_9X5;
|
||||
return MenuType.GENERIC_9x5;
|
||||
case 6:
|
||||
return ScreenHandlerType.GENERIC_9X6;
|
||||
return MenuType.GENERIC_9x6;
|
||||
}
|
||||
return ScreenHandlerType.GENERIC_9X1;
|
||||
return MenuType.GENERIC_9x1;
|
||||
}
|
||||
|
||||
protected abstract void fillInventoryWith(PlayerEntity player, SeparateInv inv, T additionalData);
|
||||
protected abstract void fillInventoryWith(Player player, SeparateInv inv, T additionalData);
|
||||
|
||||
@Override
|
||||
public boolean canUse(PlayerEntity player) {
|
||||
public boolean stillValid(Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onSlotClick(int i, int j, SlotActionType actionType, PlayerEntity playerEntity) {
|
||||
public void clicked(int i, int j, ClickType actionType, Player playerEntity) {
|
||||
if (i < 0)
|
||||
return ItemStack.EMPTY;
|
||||
return;
|
||||
Slot slot = this.slots.get(i);
|
||||
if (this.isRightSlot(i))
|
||||
this.handleSlotClicked((ServerPlayerEntity) playerEntity, i, slot, j);
|
||||
ItemStack stack = slot.getStack().copy();
|
||||
for (ScreenHandlerListener listener : this.listeners)
|
||||
listener.onSlotUpdate(this, i, stack);
|
||||
((ServerPlayerEntity) playerEntity).updateCursorStack();
|
||||
return stack;
|
||||
if (this.isRightSlot(i)) {
|
||||
if (((AbstractContainerAccessor) this).containerSync() != null)
|
||||
((AbstractContainerAccessor) this).containerSync().sendCarriedChange(this, this.getCarried().copy());
|
||||
this.handleSlotClicked((ServerPlayer) playerEntity, i, slot, j);
|
||||
}
|
||||
ItemStack stack = slot.getItem().copy();
|
||||
for (ContainerListener listener : ((AbstractContainerAccessor) this).listeners())
|
||||
listener.slotChanged(this, i, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferSlot(PlayerEntity player, int index) {
|
||||
public ItemStack quickMoveStack(Player player, int index) {
|
||||
if (index < 0)
|
||||
return ItemStack.EMPTY;
|
||||
Slot slot = this.slots.get(index);
|
||||
if (this.isRightSlot(index))
|
||||
this.handleSlotClicked((ServerPlayerEntity) player, index, slot, 0);
|
||||
return slot.getStack().copy();
|
||||
this.handleSlotClicked((ServerPlayer) player, index, slot, 0);
|
||||
return slot.getItem().copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(ScreenHandlerListener listener) {
|
||||
/*@Override
|
||||
public void addSlotListener(ContainerListener listener) {
|
||||
this.update = false;
|
||||
super.addListener(listener);
|
||||
super.addSlotListener(listener);
|
||||
if (!this.listeners.contains(listener)) {
|
||||
this.listeners.add(listener);
|
||||
listener.onHandlerRegistered(this, this.getStacks());
|
||||
listener.refreshContainer(this, this.getItems());
|
||||
this.update = true;
|
||||
this.sendContentUpdates();
|
||||
this.broadcastChanges();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void sendContentUpdates() {
|
||||
if (this.update)
|
||||
super.sendContentUpdates();
|
||||
public void broadcastChanges() {
|
||||
//if (this.update)
|
||||
super.broadcastChanges();
|
||||
}
|
||||
|
||||
protected abstract boolean isRightSlot(int slot);
|
||||
@ -137,5 +135,5 @@ public abstract class ServerOnlyScreenHandler<T> extends ScreenHandler {
|
||||
/**
|
||||
* @param clickType 0 for left click, 1 for right click
|
||||
*/
|
||||
protected abstract boolean handleSlotClicked(ServerPlayerEntity player, int index, Slot slot, int clickType);
|
||||
protected abstract boolean handleSlotClicked(ServerPlayer player, int index, Slot slot, int clickType);
|
||||
}
|
||||
|
@ -6,18 +6,18 @@ import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.Config;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -28,24 +28,24 @@ public class ServerScreenHelper {
|
||||
|
||||
public static ItemStack emptyFiller() {
|
||||
ItemStack stack = new ItemStack(Items.GRAY_STAINED_GLASS_PANE);
|
||||
stack.setCustomName(PermHelper.simpleColoredText(""));
|
||||
stack.setHoverName(PermHelper.simpleColoredText(""));
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack fromPermission(Claim claim, ClaimPermission perm, String group) {
|
||||
ItemStack stack = perm.getItem();
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(perm.id, Formatting.GOLD));
|
||||
List<Text> lore = new ArrayList<>();
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(perm.id, ChatFormatting.GOLD));
|
||||
List<Component> lore = new ArrayList<>();
|
||||
for (String pdesc : perm.desc) {
|
||||
Text trans = ServerScreenHelper.coloredGuiText(pdesc, Formatting.YELLOW);
|
||||
Component trans = ServerScreenHelper.coloredGuiText(pdesc, ChatFormatting.YELLOW);
|
||||
lore.add(trans);
|
||||
}
|
||||
Config.GlobalType global = ConfigHandler.config.getGlobal(claim.getWorld(), perm);
|
||||
if (!claim.isAdminClaim() && !global.canModify()) {
|
||||
Text text = ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenUneditable, Formatting.DARK_RED);
|
||||
Component text = ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenUneditable, ChatFormatting.DARK_RED);
|
||||
lore.add(text);
|
||||
String permFlag = global.getValue() ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse;
|
||||
Text text2 = ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenEnableText, permFlag), permFlag.equals(ConfigHandler.lang.screenTrue) ? Formatting.GREEN : Formatting.RED);
|
||||
Component text2 = ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenEnableText, permFlag), permFlag.equals(ConfigHandler.lang.screenTrue) ? ChatFormatting.GREEN : ChatFormatting.RED);
|
||||
lore.add(text2);
|
||||
} else {
|
||||
String permFlag;
|
||||
@ -78,28 +78,28 @@ public class ServerScreenHelper {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Text text = ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenEnableText, permFlag), permFlag.equals(ConfigHandler.lang.screenTrue) ? Formatting.GREEN : Formatting.RED);
|
||||
Component text = ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenEnableText, permFlag), permFlag.equals(ConfigHandler.lang.screenTrue) ? ChatFormatting.GREEN : ChatFormatting.RED);
|
||||
lore.add(text);
|
||||
}
|
||||
addLore(stack, lore);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack getFromPersonal(ServerPlayerEntity player, ClaimPermission perm, String group) {
|
||||
public static ItemStack getFromPersonal(ServerPlayer player, ClaimPermission perm, String group) {
|
||||
ItemStack stack = perm.getItem();
|
||||
stack.setCustomName(ServerScreenHelper.coloredGuiText(perm.id, Formatting.GOLD));
|
||||
stack.setHoverName(ServerScreenHelper.coloredGuiText(perm.id, ChatFormatting.GOLD));
|
||||
ListTag lore = new ListTag();
|
||||
for (String pdesc : perm.desc) {
|
||||
Text trans = ServerScreenHelper.coloredGuiText(pdesc, Formatting.YELLOW);
|
||||
lore.add(StringTag.of(Text.Serializer.toJson(trans)));
|
||||
Component trans = ServerScreenHelper.coloredGuiText(pdesc, ChatFormatting.YELLOW);
|
||||
lore.add(StringTag.valueOf(Component.Serializer.toJson(trans)));
|
||||
}
|
||||
Config.GlobalType global = ConfigHandler.config.getGlobal(player.getServerWorld(), perm);
|
||||
Config.GlobalType global = ConfigHandler.config.getGlobal(player.getLevel(), perm);
|
||||
if (!global.canModify()) {
|
||||
Text text = ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenUneditable, Formatting.DARK_RED);
|
||||
lore.add(StringTag.of(Text.Serializer.toJson(text)));
|
||||
Component text = ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenUneditable, ChatFormatting.DARK_RED);
|
||||
lore.add(StringTag.valueOf(Component.Serializer.toJson(text)));
|
||||
String permFlag = String.valueOf(global.getValue());
|
||||
Text text2 = ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenEnableText, permFlag), permFlag.equals(ConfigHandler.lang.screenTrue) ? Formatting.GREEN : Formatting.RED);
|
||||
lore.add(StringTag.of(Text.Serializer.toJson(text2)));
|
||||
Component text2 = ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenEnableText, permFlag), permFlag.equals(ConfigHandler.lang.screenTrue) ? ChatFormatting.GREEN : ChatFormatting.RED);
|
||||
lore.add(StringTag.valueOf(Component.Serializer.toJson(text2)));
|
||||
} else {
|
||||
String permFlag;
|
||||
Map<ClaimPermission, Boolean> map = PlayerClaimData.get(player).playerDefaultGroups().getOrDefault(group, new HashMap<>());
|
||||
@ -107,31 +107,31 @@ public class ServerScreenHelper {
|
||||
permFlag = map.get(perm) ? ConfigHandler.lang.screenTrue : ConfigHandler.lang.screenFalse;
|
||||
else
|
||||
permFlag = ConfigHandler.lang.screenDefault;
|
||||
Text text = ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenEnableText, permFlag), permFlag.equals(ConfigHandler.lang.screenTrue) ? Formatting.GREEN : Formatting.RED);
|
||||
lore.add(StringTag.of(Text.Serializer.toJson(text)));
|
||||
Component text = ServerScreenHelper.coloredGuiText(String.format(ConfigHandler.lang.screenEnableText, permFlag), permFlag.equals(ConfigHandler.lang.screenTrue) ? ChatFormatting.GREEN : ChatFormatting.RED);
|
||||
lore.add(StringTag.valueOf(Component.Serializer.toJson(text)));
|
||||
}
|
||||
stack.getOrCreateSubTag("display").put("Lore", lore);
|
||||
stack.getOrCreateTagElement("display").put("Lore", lore);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static void playSongToPlayer(ServerPlayerEntity player, SoundEvent event, float vol, float pitch) {
|
||||
player.networkHandler.sendPacket(
|
||||
new PlaySoundS2CPacket(event, SoundCategory.PLAYERS, player.getPos().x, player.getPos().y, player.getPos().z, vol, pitch));
|
||||
public static void playSongToPlayer(ServerPlayer player, SoundEvent event, float vol, float pitch) {
|
||||
player.connection.send(
|
||||
new ClientboundSoundPacket(event, SoundSource.PLAYERS, player.position().x, player.position().y, player.position().z, vol, pitch));
|
||||
}
|
||||
|
||||
public static Text coloredGuiText(String text, Formatting... formattings) {
|
||||
return new LiteralText(text).setStyle(Style.EMPTY.withItalic(false).withFormatting(formattings));
|
||||
public static Component coloredGuiText(String text, ChatFormatting... formattings) {
|
||||
return new TextComponent(text).setStyle(Style.EMPTY.withItalic(false).applyFormats(formattings));
|
||||
}
|
||||
|
||||
public static void addLore(ItemStack stack, Text text) {
|
||||
public static void addLore(ItemStack stack, Component text) {
|
||||
ListTag lore = new ListTag();
|
||||
lore.add(StringTag.of(Text.Serializer.toJson(text)));
|
||||
stack.getOrCreateSubTag("display").put("Lore", lore);
|
||||
lore.add(StringTag.valueOf(Component.Serializer.toJson(text)));
|
||||
stack.getOrCreateTagElement("display").put("Lore", lore);
|
||||
}
|
||||
|
||||
public static void addLore(ItemStack stack, List<Text> texts) {
|
||||
public static void addLore(ItemStack stack, List<Component> texts) {
|
||||
ListTag lore = new ListTag();
|
||||
texts.forEach(text -> lore.add(StringTag.of(Text.Serializer.toJson(text))));
|
||||
stack.getOrCreateSubTag("display").put("Lore", lore);
|
||||
texts.forEach(text -> lore.add(StringTag.valueOf(Component.Serializer.toJson(text))));
|
||||
stack.getOrCreateTagElement("display").put("Lore", lore);
|
||||
}
|
||||
}
|
||||
|
@ -2,28 +2,29 @@ package io.github.flemmli97.flan.gui;
|
||||
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.network.packet.s2c.play.ExperienceBarUpdateS2CPacket;
|
||||
import net.minecraft.screen.AnvilScreenHandler;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.ScreenHandlerListener;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.screen.slot.SlotActionType;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import io.github.flemmli97.flan.mixin.AbstractContainerAccessor;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetExperiencePacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.AnvilMenu;
|
||||
import net.minecraft.world.inventory.ClickType;
|
||||
import net.minecraft.world.inventory.ContainerListener;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class StringResultScreenHandler extends AnvilScreenHandler {
|
||||
public class StringResultScreenHandler extends AnvilMenu {
|
||||
|
||||
private final List<ScreenHandlerListener> listeners = new ArrayList<>();
|
||||
private final List<ContainerListener> listeners = new ArrayList<>();
|
||||
|
||||
private final Consumer<String> cons;
|
||||
private final Runnable ret;
|
||||
@ -31,119 +32,119 @@ public class StringResultScreenHandler extends AnvilScreenHandler {
|
||||
private boolean init;
|
||||
private String name;
|
||||
|
||||
private StringResultScreenHandler(int syncId, PlayerInventory playerInventory, Consumer<String> cons, Runnable ret) {
|
||||
private StringResultScreenHandler(int syncId, Inventory playerInventory, Consumer<String> cons, Runnable ret) {
|
||||
super(syncId, playerInventory);
|
||||
ItemStack stack = new ItemStack(Items.PAPER);
|
||||
stack.setCustomName(PermHelper.simpleColoredText(""));
|
||||
this.input.setStack(0, stack);
|
||||
stack.setHoverName(PermHelper.simpleColoredText(""));
|
||||
this.inputSlots.setItem(0, stack);
|
||||
ItemStack out = new ItemStack(Items.BOOK);
|
||||
out.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.stringScreenReturn));
|
||||
this.output.setStack(0, out);
|
||||
out.setHoverName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.stringScreenReturn));
|
||||
this.resultSlots.setItem(0, out);
|
||||
this.cons = cons;
|
||||
this.ret = ret;
|
||||
}
|
||||
|
||||
public static void createNewStringResult(PlayerEntity player, Consumer<String> cons, Runnable ret) {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
public static void createNewStringResult(Player player, Consumer<String> cons, Runnable ret) {
|
||||
MenuProvider fac = new MenuProvider() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
public AbstractContainerMenu createMenu(int syncId, Inventory inv, Player player) {
|
||||
return new StringResultScreenHandler(syncId, inv, cons, ret);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
public Component getDisplayName() {
|
||||
return PermHelper.simpleColoredText("");
|
||||
}
|
||||
};
|
||||
player.openHandledScreen(fac);
|
||||
player.openMenu(fac);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(PlayerEntity player) {
|
||||
public boolean stillValid(Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canTakeOutput(PlayerEntity player, boolean present) {
|
||||
protected boolean mayPickup(Player player, boolean present) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onSlotClick(int i, int j, SlotActionType actionType, PlayerEntity playerEntity) {
|
||||
if (i < 0 || !(playerEntity instanceof ServerPlayerEntity))
|
||||
return ItemStack.EMPTY;
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) playerEntity;
|
||||
public void clicked(int i, int j, ClickType actionType, Player playerEntity) {
|
||||
if (i < 0 || !(playerEntity instanceof ServerPlayer))
|
||||
return;
|
||||
ServerPlayer player = (ServerPlayer) playerEntity;
|
||||
Slot slot = this.slots.get(i);
|
||||
if (((AbstractContainerAccessor) this).containerSync() != null)
|
||||
((AbstractContainerAccessor) this).containerSync().sendCarriedChange(this, this.getCarried().copy());
|
||||
if (i == 0)
|
||||
this.ret.run();
|
||||
else if (i == 2) {
|
||||
String s = slot.getStack().hasCustomName() ? slot.getStack().getName().asString() : "";
|
||||
String s = slot.getItem().hasCustomHoverName() ? slot.getItem().getHoverName().getContents() : "";
|
||||
if (!s.isEmpty() && !s.equals(ConfigHandler.lang.stringScreenReturn)) {
|
||||
this.cons.accept(s);
|
||||
}
|
||||
player.networkHandler.sendPacket(new ExperienceBarUpdateS2CPacket(player.experienceProgress, player.totalExperience, player.experienceLevel));
|
||||
player.connection.send(new ClientboundSetExperiencePacket(player.experienceProgress, player.totalExperience, player.experienceLevel));
|
||||
}
|
||||
this.sendContentUpdates();
|
||||
player.updateCursorStack();
|
||||
return slot.getStack();
|
||||
this.broadcastChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferSlot(PlayerEntity player, int index) {
|
||||
if (!(player instanceof ServerPlayerEntity))
|
||||
public ItemStack quickMoveStack(Player player, int index) {
|
||||
if (!(player instanceof ServerPlayer))
|
||||
return ItemStack.EMPTY;
|
||||
if (index == 0)
|
||||
this.ret.run();
|
||||
else if (index == 2) {
|
||||
Slot slot = this.slots.get(index);
|
||||
String s = slot.getStack().hasCustomName() ? slot.getStack().getName().asString() : "";
|
||||
String s = slot.getItem().hasCustomHoverName() ? slot.getItem().getHoverName().getContents() : "";
|
||||
if (!s.isEmpty() && !s.equals(ConfigHandler.lang.stringScreenReturn))
|
||||
this.cons.accept(s);
|
||||
((ServerPlayerEntity) player).networkHandler.sendPacket(new ExperienceBarUpdateS2CPacket(player.experienceProgress, player.totalExperience, player.experienceLevel));
|
||||
((ServerPlayer) player).connection.send(new ClientboundSetExperiencePacket(player.experienceProgress, player.totalExperience, player.experienceLevel));
|
||||
}
|
||||
this.sendContentUpdates();
|
||||
this.broadcastChanges();
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void addListener(ScreenHandlerListener listener) {
|
||||
public void addSlotListener(ContainerListener listener) {
|
||||
if (!this.listeners.contains(listener)) {
|
||||
this.listeners.add(listener);
|
||||
listener.onHandlerRegistered(this, this.getStacks());
|
||||
this.sendContentUpdates();
|
||||
listener.refreshContainer(this, this.getItems());
|
||||
this.broadcastChanges();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void sendContentUpdates() {
|
||||
public void broadcastChanges() {
|
||||
int j;
|
||||
for (j = 0; j < this.slots.size(); ++j) {
|
||||
ItemStack itemStack = this.slots.get(j).getStack();
|
||||
ItemStack itemStack = this.slots.get(j).getItem();
|
||||
|
||||
for (ScreenHandlerListener screenHandlerListener : this.listeners) {
|
||||
screenHandlerListener.onSlotUpdate(this, j, itemStack.copy());
|
||||
for (ContainerListener screenHandlerListener : this.listeners) {
|
||||
screenHandlerListener.slotChanged(this, j, itemStack.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateResult() {
|
||||
public void createResult() {
|
||||
if (!this.init)
|
||||
this.init = true;
|
||||
else {
|
||||
ItemStack out = this.slots.get(2).getStack();
|
||||
ItemStack out = this.slots.get(2).getItem();
|
||||
if (StringUtils.isBlank(this.name))
|
||||
out.removeCustomName();
|
||||
else if (!this.name.equals(out.getName().getString())) {
|
||||
out.setCustomName(ServerScreenHelper.coloredGuiText(this.name));
|
||||
out.resetHoverName();
|
||||
else if (!this.name.equals(out.getHoverName().getString())) {
|
||||
out.setHoverName(ServerScreenHelper.coloredGuiText(this.name));
|
||||
}
|
||||
}
|
||||
this.sendContentUpdates();
|
||||
this.broadcastChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNewItemName(String string) {
|
||||
public void setItemName(String string) {
|
||||
this.name = string;
|
||||
this.updateResult();
|
||||
this.createResult();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.github.flemmli97.flan.gui.inv;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
/**
|
||||
* This ensures that other mods will never be able to modify and get items from the inventory.
|
||||
|
@ -1,71 +1,71 @@
|
||||
package io.github.flemmli97.flan.gui.inv;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.SimpleInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.SimpleContainer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SeparateInvImpl extends SimpleInventory implements SeparateInv {
|
||||
public class SeparateInvImpl extends SimpleContainer implements SeparateInv {
|
||||
|
||||
public SeparateInvImpl(int size) {
|
||||
super(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack(int slot) {
|
||||
public ItemStack getItem(int slot) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> clearToList() {
|
||||
public List<ItemStack> removeAllItems() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStack(int slot, int amount) {
|
||||
public ItemStack removeItem(int slot, int amount) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItem(Item item, int count) {
|
||||
public ItemStack removeItemType(Item item, int count) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addStack(ItemStack stack) {
|
||||
public ItemStack addItem(ItemStack stack) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack) {
|
||||
public boolean canAddItem(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStack(int slot) {
|
||||
public ItemStack removeItemNoUpdate(int slot) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(int slot, ItemStack stack) {
|
||||
public void setItem(int slot, ItemStack stack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayerUse(PlayerEntity player) {
|
||||
public boolean stillValid(Player player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStack(int slot, ItemStack stack) {
|
||||
super.setStack(slot, stack);
|
||||
super.setItem(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getActualStack(int slot) {
|
||||
return super.getStack(slot);
|
||||
return super.getItem(slot);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package io.github.flemmli97.flan.gui.inv;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class SlotDelegate extends Slot {
|
||||
|
||||
@ -14,22 +14,22 @@ public class SlotDelegate extends Slot {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(ItemStack stack) {
|
||||
((SeparateInvImpl) this.inventory).updateStack(this.index, stack);
|
||||
public void set(ItemStack stack) {
|
||||
((SeparateInvImpl) this.container).updateStack(this.index, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack() {
|
||||
return ((SeparateInvImpl) this.inventory).getActualStack(this.index);
|
||||
public ItemStack getItem() {
|
||||
return ((SeparateInvImpl) this.container).getActualStack(this.index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack) {
|
||||
public boolean mayPlace(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeItems(PlayerEntity playerEntity) {
|
||||
public boolean mayPickup(Player playerEntity) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -2,18 +2,18 @@ package io.github.flemmli97.flan.integration.currency;
|
||||
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import me.shedaniel.architectury.annotations.ExpectPlatform;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import dev.architectury.injectables.annotations.ExpectPlatform;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
public class CommandCurrency {
|
||||
|
||||
@ExpectPlatform
|
||||
public static int sellClaimBlocks(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
public static int sellClaimBlocks(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static int buyClaimBlocks(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
public static int buyClaimBlocks(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package io.github.flemmli97.flan.integration.permissions;
|
||||
|
||||
import me.shedaniel.architectury.annotations.ExpectPlatform;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import dev.architectury.injectables.annotations.ExpectPlatform;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class PermissionNodeHandler {
|
||||
|
||||
@ -47,22 +47,22 @@ public class PermissionNodeHandler {
|
||||
public static final String permClaimBlocks = "flan.claim.blocks.max";
|
||||
public static final String permMaxClaims = "flan.claims.amount";
|
||||
|
||||
public static boolean perm(ServerCommandSource src, String perm) {
|
||||
public static boolean perm(CommandSourceStack src, String perm) {
|
||||
return perm(src, perm, false);
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static boolean perm(ServerCommandSource src, String perm, boolean adminCmd) {
|
||||
public static boolean perm(CommandSourceStack src, String perm, boolean adminCmd) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static boolean perm(ServerPlayerEntity src, String perm, boolean adminCmd) {
|
||||
public static boolean perm(ServerPlayer src, String perm, boolean adminCmd) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static boolean permBelowEqVal(ServerPlayerEntity src, String perm, int val, int fallback) {
|
||||
public static boolean permBelowEqVal(ServerPlayer src, String perm, int val, int fallback) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.BlockInteractEvents;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@ -17,12 +17,12 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(AbstractBlock.AbstractBlockState.class)
|
||||
@Mixin(BlockBehaviour.BlockStateBase.class)
|
||||
public abstract class AbstractBlockStateMixin {
|
||||
|
||||
@Inject(method = "onEntityCollision", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void collision(World world, BlockPos pos, Entity entity, CallbackInfo info) {
|
||||
if (BlockInteractEvents.cancelEntityBlockCollision(this.asBlockState(), world, pos, entity)) {
|
||||
@Inject(method = "entityInside", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void collision(Level world, BlockPos pos, Entity entity, CallbackInfo info) {
|
||||
if (BlockInteractEvents.cancelEntityBlockCollision(this.asState(), world, pos, entity)) {
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
@ -31,15 +31,15 @@ public abstract class AbstractBlockStateMixin {
|
||||
* Can't use the hooks from both fabric or forge cause they are too generic.
|
||||
* Wouldn't be able to place blocks after cancelling them
|
||||
*/
|
||||
@Inject(method = "onUse", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void useBlock(World world, PlayerEntity player, Hand hand, BlockHitResult result, CallbackInfoReturnable<ActionResult> info) {
|
||||
ActionResult res = BlockInteractEvents.useBlocks(player, world, hand, result);
|
||||
if (res != ActionResult.PASS) {
|
||||
@Inject(method = "use", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void useBlock(Level world, Player player, InteractionHand hand, BlockHitResult result, CallbackInfoReturnable<InteractionResult> info) {
|
||||
InteractionResult res = BlockInteractEvents.useBlocks(player, world, hand, result);
|
||||
if (res != InteractionResult.PASS) {
|
||||
info.setReturnValue(res);
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Shadow
|
||||
protected abstract BlockState asBlockState();
|
||||
protected abstract BlockState asState();
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ContainerListener;
|
||||
import net.minecraft.world.inventory.ContainerSynchronizer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(AbstractContainerMenu.class)
|
||||
public interface AbstractContainerAccessor {
|
||||
|
||||
@Accessor("containerListeners")
|
||||
List<ContainerListener> listeners();
|
||||
|
||||
@Accessor("synchronizer")
|
||||
ContainerSynchronizer containerSync();
|
||||
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import net.minecraft.server.BanEntry;
|
||||
import net.minecraft.server.players.BanListEntry;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Mixin(BanEntry.class)
|
||||
@Mixin(BanListEntry.class)
|
||||
public interface BannedEntryAccessor {
|
||||
|
||||
@Accessor("creationDate")
|
||||
@Accessor("created")
|
||||
Date getCreationDate();
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.EntityInteractEvents;
|
||||
import net.minecraft.entity.mob.EndermanEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.monster.EnderMan;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
|
||||
@Mixin(targets = "net/minecraft/entity/mob/EndermanEntity$PickUpBlockGoal")
|
||||
@Mixin(targets = "net/minecraft/world/entity/monster/EnderMan$EndermanTakeBlockGoal")
|
||||
public abstract class EndermanPickupMixin {
|
||||
|
||||
@Shadow
|
||||
private EndermanEntity enderman;
|
||||
private EnderMan enderman;
|
||||
|
||||
@ModifyVariable(method = "Lnet/minecraft/entity/mob/EndermanEntity$PickUpBlockGoal;tick()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;"), ordinal = 0)
|
||||
@ModifyVariable(method = "Lnet/minecraft/world/entity/monster/EnderMan$EndermanTakeBlockGoal;tick()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;getBlockState(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/block/state/BlockState;"), ordinal = 0)
|
||||
private BlockPos pickupCheck(BlockPos pos) {
|
||||
if (!EntityInteractEvents.canEndermanInteract(this.enderman, pos)) {
|
||||
return BlockPos.ORIGIN;
|
||||
return BlockPos.ZERO;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.EntityInteractEvents;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.mob.EndermanEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.monster.EnderMan;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(targets = "net/minecraft/entity/mob/EndermanEntity$PlaceBlockGoal")
|
||||
@Mixin(targets = "net/minecraft/world/entity/monster/EnderMan$EndermanLeaveBlockGoal")
|
||||
public abstract class EndermanPlaceMixin {
|
||||
|
||||
@Shadow
|
||||
private EndermanEntity enderman;
|
||||
private EnderMan enderman;
|
||||
|
||||
@Inject(method = "Lnet/minecraft/entity/mob/EndermanEntity$PlaceBlockGoal;canPlaceOn(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/block/BlockState;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;)Z", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void placeCheck(World world, BlockPos posAbove, BlockState carriedState, BlockState stateAbove, BlockState state, BlockPos pos, CallbackInfoReturnable<Boolean> info) {
|
||||
@Inject(method = "Lnet/minecraft/world/entity/monster/EnderMan$EndermanLeaveBlockGoal;canPlaceBlock(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;)Z", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void placeCheck(Level world, BlockPos posAbove, BlockState carriedState, BlockState stateAbove, BlockState state, BlockPos pos, CallbackInfoReturnable<Boolean> info) {
|
||||
if (!EntityInteractEvents.canEndermanInteract(this.enderman, pos)) {
|
||||
info.setReturnValue(false);
|
||||
info.cancel();
|
||||
|
@ -1,9 +1,9 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.BlockInteractEvents;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(Entity.class)
|
||||
public abstract class EntityMixin {
|
||||
|
||||
@Inject(method = "fall", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;onLandedUpon(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;F)V"), cancellable = true)
|
||||
@Inject(method = "checkFallDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;fallOn(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/Entity;F)V"), cancellable = true)
|
||||
private void fallOnBlock(double heightDifference, boolean onGround, BlockState landedState, BlockPos landedPosition, CallbackInfo info) {
|
||||
if (BlockInteractEvents.preventFallOn((Entity) (Object) this, heightDifference, onGround, landedState, landedPosition))
|
||||
info.cancel();
|
||||
|
@ -1,11 +1,11 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import io.github.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.WorldView;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.FireBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@ -17,16 +17,22 @@ 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)
|
||||
private void tick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo info) {
|
||||
/**
|
||||
* Stop ticking overall if fire is in claim
|
||||
*/
|
||||
@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;getGameRules()Lnet/minecraft/world/level/GameRules;"), cancellable = true)
|
||||
private void tick(BlockState state, ServerLevel 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)
|
||||
private void burn(WorldView worldView, BlockPos pos, CallbackInfoReturnable<Integer> info) {
|
||||
if (worldView instanceof ServerWorld && !WorldEvents.canFireSpread((ServerWorld) worldView, pos)) {
|
||||
/**
|
||||
* Check if fire can spread to this block
|
||||
*/
|
||||
@Inject(method = "getFireOdds", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void burn(LevelReader worldView, BlockPos pos, CallbackInfoReturnable<Integer> info) {
|
||||
if (worldView instanceof ServerLevel && !WorldEvents.canFireSpread((ServerLevel) worldView, pos)) {
|
||||
info.setReturnValue(0);
|
||||
info.cancel();
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.WorldEvents;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.fluid.FlowableFluid;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.FlowingFluid;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
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(FlowableFluid.class)
|
||||
@Mixin(FlowingFluid.class)
|
||||
public abstract class FluidMixin {
|
||||
|
||||
@Inject(method = "canFlow", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void crossClaimFlow(BlockView world, BlockPos fluidPos, BlockState fluidBlockState, Direction flowDirection, BlockPos flowTo,
|
||||
@Inject(method = "canSpreadTo", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void crossClaimFlow(BlockGetter world, BlockPos fluidPos, BlockState fluidBlockState, Direction flowDirection, BlockPos flowTo,
|
||||
BlockState flowToBlockState, FluidState fluidState, Fluid fluid, CallbackInfoReturnable<Boolean> info) {
|
||||
if (!WorldEvents.canFlow(fluidBlockState, world, fluidPos, flowDirection)) {
|
||||
info.setReturnValue(false);
|
||||
|
@ -1,12 +1,12 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.EntityInteractEvents;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.enchantment.FrostWalkerEnchantment;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldView;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.enchantment.FrostWalkerEnchantment;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
@ -14,10 +14,10 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
@Mixin(FrostWalkerEnchantment.class)
|
||||
public abstract class FrostWalkerMixin {
|
||||
|
||||
@Redirect(method = "freezeWater", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;canPlaceAt(Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;)Z"))
|
||||
private static boolean freeze(BlockState state, WorldView world, BlockPos pos, LivingEntity entity) {
|
||||
if (world instanceof ServerWorld && !EntityInteractEvents.canFrostwalkerFreeze((ServerWorld) world, pos, entity))
|
||||
@Redirect(method = "onEntityMoved", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;canSurvive(Lnet/minecraft/world/level/LevelReader;Lnet/minecraft/core/BlockPos;)Z"))
|
||||
private static boolean freeze(BlockState state, LevelReader world, BlockPos pos, LivingEntity entity) {
|
||||
if (world instanceof ServerLevel && !EntityInteractEvents.canFrostwalkerFreeze((ServerLevel) world, pos, entity))
|
||||
return false;
|
||||
return state.canPlaceAt(world, pos);
|
||||
return state.canSurvive(world, pos);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import net.minecraft.entity.player.HungerManager;
|
||||
import net.minecraft.world.food.FoodData;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(HungerManager.class)
|
||||
@Mixin(FoodData.class)
|
||||
public interface IHungerAccessor {
|
||||
|
||||
@Accessor("foodSaturationLevel")
|
||||
@Accessor("saturationLevel")
|
||||
void setSaturation(float saturation);
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.world.RaycastContext;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
@Mixin(Item.class)
|
||||
public interface IItemAccessor {
|
||||
|
||||
@Invoker("raycast")
|
||||
static BlockHitResult getRaycast(World world, PlayerEntity player, RaycastContext.FluidHandling fluidHandling) {
|
||||
@Invoker("getPlayerPOVHitResult")
|
||||
static BlockHitResult getRaycast(Level world, Player player, ClipContext.Fluid fluidHandling) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import net.minecraft.block.entity.LecternBlockEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.screen.PropertyDelegate;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.inventory.ContainerData;
|
||||
import net.minecraft.world.level.block.entity.LecternBlockEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(LecternBlockEntity.class)
|
||||
public interface ILecternBlockValues {
|
||||
|
||||
@Accessor("inventory")
|
||||
Inventory getInv();
|
||||
@Accessor("bookAccess")
|
||||
Container getInv();
|
||||
|
||||
@Accessor("propertyDelegate")
|
||||
PropertyDelegate getProp();
|
||||
@Accessor("dataAccess")
|
||||
ContainerData getProp();
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.projectile.PersistentProjectileEntity;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.entity.projectile.AbstractArrow;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
@Mixin(PersistentProjectileEntity.class)
|
||||
@Mixin(AbstractArrow.class)
|
||||
public interface IPersistentProjectileVars {
|
||||
|
||||
@Accessor("inBlockState")
|
||||
@Accessor("lastState")
|
||||
void setInBlockState(BlockState state);
|
||||
|
||||
@Accessor("inGround")
|
||||
void setInGround(boolean flag);
|
||||
|
||||
@Invoker("getSound")
|
||||
@Invoker("getHitGroundSoundEvent")
|
||||
SoundEvent getSoundEvent();
|
||||
|
||||
@Invoker("clearPiercingStatus")
|
||||
@Invoker("resetPiercedEntities")
|
||||
void resetPiercingStatus();
|
||||
|
||||
@Accessor("piercedEntities")
|
||||
@Accessor("piercingIgnoreEntityIds")
|
||||
IntOpenHashSet getPiercedEntities();
|
||||
|
||||
@Accessor("piercedEntities")
|
||||
@Accessor("piercingIgnoreEntityIds")
|
||||
void setPiercedEntities(IntOpenHashSet set);
|
||||
}
|
||||
|
@ -2,10 +2,10 @@ package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.player.IOwnedItem;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@ -22,22 +22,22 @@ public abstract class ItemEntityMixin implements IOwnedItem {
|
||||
@Unique
|
||||
private UUID flanDeathPlayerOrigin;
|
||||
|
||||
@Inject(method = "readCustomDataFromTag", at = @At("RETURN"))
|
||||
@Inject(method = "readAdditionalSaveData", at = @At("RETURN"))
|
||||
private void readData(CompoundTag tag, CallbackInfo info) {
|
||||
if (tag.contains("Flan:PlayerOrigin"))
|
||||
this.flanPlayerOrigin = tag.getUuid("Flan:PlayerOrigin");
|
||||
this.flanPlayerOrigin = tag.getUUID("Flan:PlayerOrigin");
|
||||
}
|
||||
|
||||
@Inject(method = "writeCustomDataToTag", at = @At("RETURN"))
|
||||
@Inject(method = "addAdditionalSaveData", at = @At("RETURN"))
|
||||
private void writeData(CompoundTag tag, CallbackInfo info) {
|
||||
if (this.flanPlayerOrigin != null)
|
||||
tag.putUuid("Flan:PlayerOrigin", this.flanPlayerOrigin);
|
||||
tag.putUUID("Flan:PlayerOrigin", this.flanPlayerOrigin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOriginPlayer(PlayerEntity player) {
|
||||
this.flanPlayerOrigin = player.getUuid();
|
||||
if (player instanceof ServerPlayerEntity && PlayerClaimData.get((ServerPlayerEntity) player).setDeathItemOwner())
|
||||
public void setOriginPlayer(Player player) {
|
||||
this.flanPlayerOrigin = player.getUUID();
|
||||
if (player instanceof ServerPlayer && PlayerClaimData.get((ServerPlayer) player).setDeathItemOwner())
|
||||
this.flanDeathPlayerOrigin = this.flanPlayerOrigin;
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.ItemInteractEvents;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@ -12,10 +12,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
@Mixin(ItemStack.class)
|
||||
public abstract class ItemStackMixin {
|
||||
|
||||
@Inject(method = "useOnBlock", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void blockUse(ItemUsageContext context, CallbackInfoReturnable<ActionResult> info) {
|
||||
ActionResult result = ItemInteractEvents.onItemUseBlock(context);
|
||||
if (result != ActionResult.PASS) {
|
||||
@Inject(method = "useOn", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void blockUse(UseOnContext context, CallbackInfoReturnable<InteractionResult> info) {
|
||||
InteractionResult result = ItemInteractEvents.onItemUseBlock(context);
|
||||
if (result != InteractionResult.PASS) {
|
||||
info.setReturnValue(result);
|
||||
info.cancel();
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.WorldEvents;
|
||||
import net.minecraft.entity.LightningEntity;
|
||||
import net.minecraft.world.entity.LightningBolt;
|
||||
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;
|
||||
|
||||
@Mixin(LightningEntity.class)
|
||||
@Mixin(LightningBolt.class)
|
||||
public abstract class LightningFireEntityMixin {
|
||||
|
||||
@Inject(method = "spawnFire", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void stopFire(int attempts, CallbackInfo info) {
|
||||
if (!WorldEvents.lightningFire((LightningEntity) (Object) this))
|
||||
if (!WorldEvents.lightningFire((LightningBolt) (Object) this))
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.player.IPlayerClaimImpl;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ServerPlayerEntity.class)
|
||||
@Mixin(ServerPlayer.class)
|
||||
public abstract class PlayerClaimMixin implements IPlayerClaimImpl {
|
||||
|
||||
@Unique
|
||||
@ -26,7 +26,7 @@ public abstract class PlayerClaimMixin implements IPlayerClaimImpl {
|
||||
|
||||
@Inject(method = "<init>*", at = @At("RETURN"))
|
||||
private void initData(CallbackInfo info) {
|
||||
this.flanClaimData = new PlayerClaimData((ServerPlayerEntity) (Object) this);
|
||||
this.flanClaimData = new PlayerClaimData((ServerPlayer) (Object) this);
|
||||
}
|
||||
|
||||
/*@Inject(method = "readCustomDataFromTag", at = @At("RETURN"))
|
||||
@ -44,8 +44,8 @@ public abstract class PlayerClaimMixin implements IPlayerClaimImpl {
|
||||
this.flanClaimData.tick(this.flanCurrentClaim, claim -> this.flanCurrentClaim = claim);
|
||||
}
|
||||
|
||||
@Inject(method = "copyFrom", at = @At("RETURN"))
|
||||
private void copyOld(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo info) {
|
||||
@Inject(method = "restoreFrom", at = @At("RETURN"))
|
||||
private void copyOld(ServerPlayer oldPlayer, boolean alive, CallbackInfo info) {
|
||||
this.flanClaimData.clone(PlayerClaimData.get(oldPlayer));
|
||||
}
|
||||
|
||||
|
@ -1,27 +1,27 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.EntityInteractEvents;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
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.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(PlayerEntity.class)
|
||||
@Mixin(Player.class)
|
||||
public abstract class PlayerMixin {
|
||||
|
||||
@ModifyVariable(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ItemEntity;setPickupDelay(I)V"))
|
||||
@ModifyVariable(method = "drop(Lnet/minecraft/world/item/ItemStack;ZZ)Lnet/minecraft/world/entity/item/ItemEntity;", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/item/ItemEntity;setPickUpDelay(I)V"))
|
||||
private ItemEntity ownerDrop(ItemEntity entity) {
|
||||
EntityInteractEvents.updateDroppedItem((PlayerEntity) (Object) this, entity);
|
||||
EntityInteractEvents.updateDroppedItem((Player) (Object) this, entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Inject(method = "collideWithEntity", at = @At(value = "HEAD"), cancellable = true)
|
||||
@Inject(method = "touch", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void entityCollide(Entity entity, CallbackInfo info) {
|
||||
if (!EntityInteractEvents.canCollideWith((PlayerEntity) (Object) this, entity)) {
|
||||
if (!EntityInteractEvents.canCollideWith((Player) (Object) this, entity)) {
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,19 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.WorldEvents;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.village.raid.Raid;
|
||||
import net.minecraft.village.raid.RaidManager;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.raid.Raid;
|
||||
import net.minecraft.world.entity.raid.Raids;
|
||||
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)
|
||||
@Mixin(Raids.class)
|
||||
public abstract class RaidManagerMixin {
|
||||
|
||||
@Inject(method = "startRaid", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void checkRaid(ServerPlayerEntity player, CallbackInfoReturnable<Raid> info) {
|
||||
@Inject(method = "createOrExtendRaid", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void checkRaid(ServerPlayer player, CallbackInfoReturnable<Raid> info) {
|
||||
if (!WorldEvents.canStartRaid(player)) {
|
||||
info.setReturnValue(null);
|
||||
info.cancel();
|
||||
|
@ -2,28 +2,28 @@ package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.claim.ClaimStorage;
|
||||
import io.github.flemmli97.flan.claim.IClaimStorage;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ServerWorld.class)
|
||||
@Mixin(ServerLevel.class)
|
||||
public abstract class ServerWorldMixin implements IClaimStorage {
|
||||
@Unique
|
||||
private ClaimStorage flanClaimData;
|
||||
|
||||
@Inject(method = "<init>*", at = @At("RETURN"))
|
||||
private void initData(CallbackInfo info) {
|
||||
ServerWorld world = ((ServerWorld) (Object) this);
|
||||
ServerLevel world = ((ServerLevel) (Object) this);
|
||||
this.flanClaimData = new ClaimStorage(world.getServer(), world);
|
||||
}
|
||||
|
||||
@Inject(method = "saveLevel()V", at = @At("RETURN"))
|
||||
@Inject(method = "saveLevelData", at = @At("RETURN"))
|
||||
private void saveClaimData(CallbackInfo info) {
|
||||
ServerWorld world = ((ServerWorld) (Object) this);
|
||||
this.flanClaimData.save(world.getServer(), world.getRegistryKey());
|
||||
ServerLevel world = ((ServerLevel) (Object) this);
|
||||
this.flanClaimData.save(world.getServer(), world.dimension());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,10 +1,11 @@
|
||||
package io.github.flemmli97.flan.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.BlockInteractEvents;
|
||||
import net.minecraft.block.TurtleEggBlock;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.TurtleEggBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@ -13,8 +14,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(TurtleEggBlock.class)
|
||||
public abstract class TurtleEggMixin {
|
||||
|
||||
@Inject(method = "onSteppedOn", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void collision(World world, BlockPos pos, Entity entity, CallbackInfo info) {
|
||||
@Inject(method = "destroyEgg", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void collision(Level world, BlockState blockState, BlockPos pos, Entity entity, int chance, CallbackInfo info) {
|
||||
if (BlockInteractEvents.canBreakTurtleEgg(world, pos, entity)) {
|
||||
info.cancel();
|
||||
}
|
||||
|
@ -3,13 +3,12 @@ package io.github.flemmli97.flan.player;
|
||||
import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.ParticleIndicators;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
|
||||
import net.minecraft.particle.DustParticleEffect;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.particles.DustParticleOptions;
|
||||
import net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@ -28,7 +27,7 @@ public class ClaimDisplay {
|
||||
|
||||
private int[] prevDims;
|
||||
|
||||
private final DustParticleEffect corner, middle;
|
||||
private final DustParticleOptions corner, middle;
|
||||
|
||||
public ClaimDisplay(Claim claim, EnumDisplayType type, int y) {
|
||||
this.toDisplay = claim;
|
||||
@ -56,29 +55,29 @@ public class ClaimDisplay {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean display(ServerPlayerEntity player, boolean remove) {
|
||||
public boolean display(ServerPlayer player, boolean remove) {
|
||||
if (--this.displayTime % 2 == 0)
|
||||
return this.toDisplay.isRemoved();
|
||||
int[] dims = this.toDisplay.getDimensions();
|
||||
if (this.poss == null || this.changed(dims)) {
|
||||
this.middlePoss = calculateDisplayPos(player.getServerWorld(), dims, this.height);
|
||||
this.middlePoss = calculateDisplayPos(player.getLevel(), dims, this.height);
|
||||
this.poss = new int[][]{
|
||||
getPosFrom(player.getServerWorld(), dims[0], dims[2], this.height),
|
||||
getPosFrom(player.getServerWorld(), dims[1], dims[2], this.height),
|
||||
getPosFrom(player.getServerWorld(), dims[0], dims[3], this.height),
|
||||
getPosFrom(player.getServerWorld(), dims[1], dims[3], this.height),
|
||||
getPosFrom(player.getLevel(), dims[0], dims[2], this.height),
|
||||
getPosFrom(player.getLevel(), dims[1], dims[2], this.height),
|
||||
getPosFrom(player.getLevel(), dims[0], dims[3], this.height),
|
||||
getPosFrom(player.getLevel(), dims[1], dims[3], this.height),
|
||||
};
|
||||
}
|
||||
for (int[] pos : this.poss) {
|
||||
if (pos[1] != pos[2])
|
||||
player.networkHandler.sendPacket(new ParticleS2CPacket(this.corner, true, pos[0] + 0.5, pos[2] + 0.25, pos[3] + 0.5, 0, 0.5f, 0, 0, 1));
|
||||
player.networkHandler.sendPacket(new ParticleS2CPacket(this.corner, true, pos[0] + 0.5, pos[1] + 0.25, pos[3] + 0.5, 0, 0.5f, 0, 0, 1));
|
||||
player.connection.send(new ClientboundLevelParticlesPacket(this.corner, true, pos[0] + 0.5, pos[2] + 0.25, pos[3] + 0.5, 0, 0.5f, 0, 0, 1));
|
||||
player.connection.send(new ClientboundLevelParticlesPacket(this.corner, true, pos[0] + 0.5, pos[1] + 0.25, pos[3] + 0.5, 0, 0.5f, 0, 0, 1));
|
||||
}
|
||||
if (this.middlePoss != null)
|
||||
for (int[] pos : this.middlePoss) {
|
||||
if (pos[1] != pos[2])
|
||||
player.networkHandler.sendPacket(new ParticleS2CPacket(this.middle, true, pos[0] + 0.5, pos[2] + 0.25, pos[3] + 0.5, 0, 0.5f, 0, 0, 1));
|
||||
player.networkHandler.sendPacket(new ParticleS2CPacket(this.middle, true, pos[0] + 0.5, pos[1] + 0.25, pos[3] + 0.5, 0, 0.5f, 0, 0, 1));
|
||||
player.connection.send(new ClientboundLevelParticlesPacket(this.middle, true, pos[0] + 0.5, pos[2] + 0.25, pos[3] + 0.5, 0, 0.5f, 0, 0, 1));
|
||||
player.connection.send(new ClientboundLevelParticlesPacket(this.middle, true, pos[0] + 0.5, pos[1] + 0.25, pos[3] + 0.5, 0, 0.5f, 0, 0, 1));
|
||||
}
|
||||
this.prevDims = dims;
|
||||
return this.toDisplay.isRemoved() || (remove && this.displayTime < 0);
|
||||
@ -91,7 +90,7 @@ public class ClaimDisplay {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int[][] calculateDisplayPos(ServerWorld world, int[] from, int height) {
|
||||
public static int[][] calculateDisplayPos(ServerLevel world, int[] from, int height) {
|
||||
List<int[]> l = new ArrayList<>();
|
||||
Set<Integer> xs = new HashSet<>();
|
||||
addEvenly(from[0], from[1], 10, xs);
|
||||
@ -131,37 +130,37 @@ public class ClaimDisplay {
|
||||
* Returns an array of of form [x,y1,y2,z] where y1 = height of the lowest replaceable block and y2 = height of the
|
||||
* lowest air block above water (if possible)
|
||||
*/
|
||||
public static int[] getPosFrom(ServerWorld world, int x, int z, int maxY) {
|
||||
public static int[] getPosFrom(ServerLevel world, int x, int z, int maxY) {
|
||||
int[] y = nextAirAndWaterBlockFrom(world, x, maxY, z);
|
||||
return new int[]{x, y[0], y[1], z};
|
||||
}
|
||||
|
||||
private static int[] nextAirAndWaterBlockFrom(ServerWorld world, int x, int y, int z) {
|
||||
private static int[] nextAirAndWaterBlockFrom(ServerLevel world, int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
BlockState state = world.getBlockState(pos);
|
||||
if (state.getMaterial().isReplaceable()) {
|
||||
pos = pos.down();
|
||||
pos = pos.below();
|
||||
state = world.getBlockState(pos);
|
||||
while (state.getMaterial().isReplaceable() && !World.isOutOfBuildLimitVertically(pos)) {
|
||||
pos = pos.down();
|
||||
while (state.getMaterial().isReplaceable() && !world.isOutsideBuildHeight(pos)) {
|
||||
pos = pos.below();
|
||||
state = world.getBlockState(pos);
|
||||
}
|
||||
pos = pos.up();
|
||||
pos = pos.above();
|
||||
state = world.getBlockState(pos);
|
||||
} else {
|
||||
pos = pos.up();
|
||||
pos = pos.above();
|
||||
state = world.getBlockState(pos);
|
||||
while (!state.getMaterial().isReplaceable()) {
|
||||
pos = pos.up();
|
||||
pos = pos.above();
|
||||
state = world.getBlockState(pos);
|
||||
}
|
||||
}
|
||||
int[] yRet = {pos.getY(), pos.getY()};
|
||||
if (state.getMaterial().isLiquid()) {
|
||||
pos = pos.up();
|
||||
pos = pos.above();
|
||||
state = world.getBlockState(pos);
|
||||
while (state.getMaterial().isLiquid()) {
|
||||
pos = pos.up();
|
||||
pos = pos.above();
|
||||
state = world.getBlockState(pos);
|
||||
}
|
||||
if (state.getMaterial().isReplaceable())
|
||||
|
@ -1,12 +1,12 @@
|
||||
package io.github.flemmli97.flan.player;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface IOwnedItem {
|
||||
|
||||
void setOriginPlayer(PlayerEntity player);
|
||||
void setOriginPlayer(Player player);
|
||||
|
||||
UUID getDeathPlayer();
|
||||
|
||||
|
@ -3,16 +3,15 @@ package io.github.flemmli97.flan.player;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import io.github.flemmli97.flan.Flan;
|
||||
import io.github.flemmli97.flan.api.data.IPlayerData;
|
||||
import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.ClaimStorage;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.mixin.BannedEntryAccessor;
|
||||
import net.minecraft.server.BannedPlayerEntry;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.players.UserBanListEntry;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -76,7 +75,7 @@ public class OfflinePlayerData implements IPlayerData {
|
||||
@Override
|
||||
public int usedClaimBlocks() {
|
||||
int usedClaimsBlocks = 0;
|
||||
for (ServerWorld world : this.server.getWorlds()) {
|
||||
for (ServerLevel world : this.server.getAllLevels()) {
|
||||
Collection<Claim> claims = ClaimStorage.get(world).allClaimsFromPlayer(this.owner);
|
||||
if (claims != null)
|
||||
usedClaimsBlocks += claims.stream().filter(claim -> !claim.isAdminClaim()).mapToInt(Claim::getPlane).sum();
|
||||
@ -113,9 +112,8 @@ public class OfflinePlayerData implements IPlayerData {
|
||||
}
|
||||
|
||||
public boolean isExpired(LocalDateTime now) {
|
||||
GameProfile prof = this.server.getUserCache().getByUuid(this.owner);
|
||||
BannedPlayerEntry entry = prof != null ? this.server.getPlayerManager().getUserBanList().get(prof) : null;
|
||||
boolean banned = entry != null && entry.getExpiryDate() == null;
|
||||
UserBanListEntry entry = this.server.getProfileCache().get(this.owner).map(this.server.getPlayerList().getBans()::get).orElse(null);
|
||||
boolean banned = entry != null && entry.getExpires() == null;
|
||||
if (banned) {
|
||||
LocalDateTime bannedTime = LocalDateTime.ofInstant(((BannedEntryAccessor) entry).getCreationDate().toInstant(), ZoneId.systemDefault());
|
||||
return ConfigHandler.config.bannedDeletionTime != -1 && now.isAfter(bannedTime.plusDays(ConfigHandler.config.bannedDeletionTime));
|
||||
|
@ -16,21 +16,20 @@ import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.event.EntityInteractEvents;
|
||||
import io.github.flemmli97.flan.integration.permissions.PermissionNodeHandler;
|
||||
import io.github.flemmli97.flan.scoreboard.ClaimCriterias;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
|
||||
import net.minecraft.scoreboard.ScoreboardCriterion;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.chunk.ChunkStatus;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@ -57,7 +56,7 @@ public class PlayerClaimData implements IPlayerData {
|
||||
private int usedBlocks;
|
||||
|
||||
private int lastBlockTick, trappedTick = -1, deathPickupTick;
|
||||
private Vec3d trappedPos;
|
||||
private Vec3 trappedPos;
|
||||
private BlockPos tpPos;
|
||||
private EnumEditMode mode = EnumEditMode.DEFAULT;
|
||||
private Claim editingClaim;
|
||||
@ -69,7 +68,7 @@ public class PlayerClaimData implements IPlayerData {
|
||||
private final Set<ClaimDisplay> claimDisplayList = new HashSet<>();
|
||||
private final Set<ClaimDisplay> displayToAdd = new HashSet<>();
|
||||
|
||||
private final ServerPlayerEntity player;
|
||||
private final ServerPlayer player;
|
||||
|
||||
private boolean confirmDeleteAll, adminIgnoreClaim, claimBlockMessage;
|
||||
|
||||
@ -77,12 +76,12 @@ public class PlayerClaimData implements IPlayerData {
|
||||
|
||||
private boolean shouldProtectDrop, calculateShouldDrop = true;
|
||||
|
||||
public PlayerClaimData(ServerPlayerEntity player) {
|
||||
public PlayerClaimData(ServerPlayer player) {
|
||||
this.player = player;
|
||||
this.claimBlocks = ConfigHandler.config.startingBlocks;
|
||||
}
|
||||
|
||||
public static PlayerClaimData get(ServerPlayerEntity player) {
|
||||
public static PlayerClaimData get(ServerPlayer player) {
|
||||
return ((IPlayerClaimImpl) player).get();
|
||||
}
|
||||
|
||||
@ -185,12 +184,12 @@ public class PlayerClaimData implements IPlayerData {
|
||||
|
||||
public void setEditingCorner(BlockPos pos) {
|
||||
if (pos != null) {
|
||||
BlockState state = this.player.world.getBlockState(pos);
|
||||
BlockState state = this.player.level.getBlockState(pos);
|
||||
while (state.isAir() || state.getMaterial().isReplaceable()) {
|
||||
pos = pos.down();
|
||||
state = this.player.world.getBlockState(pos);
|
||||
pos = pos.below();
|
||||
state = this.player.level.getBlockState(pos);
|
||||
}
|
||||
this.cornerRenderPos = ClaimDisplay.getPosFrom(this.player.getServerWorld(), pos.getX(), pos.getZ(), pos.getY());
|
||||
this.cornerRenderPos = ClaimDisplay.getPosFrom(this.player.getLevel(), pos.getX(), pos.getZ(), pos.getY());
|
||||
} else
|
||||
this.cornerRenderPos = null;
|
||||
this.firstCorner = pos;
|
||||
@ -218,7 +217,7 @@ public class PlayerClaimData implements IPlayerData {
|
||||
}
|
||||
|
||||
public boolean editDefaultPerms(String group, ClaimPermission perm, int mode) {
|
||||
if (PermissionRegistry.globalPerms().contains(perm) || ConfigHandler.config.globallyDefined(this.player.getServerWorld(), perm))
|
||||
if (PermissionRegistry.globalPerms().contains(perm) || ConfigHandler.config.globallyDefined(this.player.getLevel(), perm))
|
||||
return false;
|
||||
if (mode > 1)
|
||||
mode = -1;
|
||||
@ -235,9 +234,9 @@ public class PlayerClaimData implements IPlayerData {
|
||||
|
||||
public boolean setTrappedRescue() {
|
||||
Claim claim = ((IPlayerClaimImpl) this.player).getCurrentClaim();
|
||||
if (this.trappedTick < 0 && claim != null && !this.player.getUuid().equals(claim.getOwner())) {
|
||||
if (this.trappedTick < 0 && claim != null && !this.player.getUUID().equals(claim.getOwner())) {
|
||||
this.trappedTick = 101;
|
||||
this.trappedPos = this.player.getPos();
|
||||
this.trappedPos = this.player.position();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -246,7 +245,7 @@ public class PlayerClaimData implements IPlayerData {
|
||||
public boolean setTeleportTo(BlockPos tp) {
|
||||
if (this.trappedTick < 0) {
|
||||
this.trappedTick = 101;
|
||||
this.trappedPos = this.player.getPos();
|
||||
this.trappedPos = this.player.position();
|
||||
this.tpPos = tp;
|
||||
return true;
|
||||
}
|
||||
@ -255,10 +254,10 @@ public class PlayerClaimData implements IPlayerData {
|
||||
|
||||
public void tick(Claim currentClaim, Consumer<Claim> cons) {
|
||||
EntityInteractEvents.updateClaim(this.player, currentClaim, cons);
|
||||
boolean tool = this.player.getMainHandStack().getItem() == ConfigHandler.config.claimingItem
|
||||
|| this.player.getOffHandStack().getItem() == ConfigHandler.config.claimingItem;
|
||||
boolean stick = this.player.getMainHandStack().getItem() == ConfigHandler.config.inspectionItem
|
||||
|| this.player.getOffHandStack().getItem() == ConfigHandler.config.inspectionItem;
|
||||
boolean tool = this.player.getMainHandItem().getItem() == ConfigHandler.config.claimingItem
|
||||
|| this.player.getOffhandItem().getItem() == ConfigHandler.config.claimingItem;
|
||||
boolean stick = this.player.getMainHandItem().getItem() == ConfigHandler.config.inspectionItem
|
||||
|| this.player.getOffhandItem().getItem() == ConfigHandler.config.inspectionItem;
|
||||
this.displayToAdd.forEach(add -> {
|
||||
if (!this.claimDisplayList.add(add)) {
|
||||
this.claimDisplayList.removeIf(c -> c.equals(add) && c.type != add.type);
|
||||
@ -273,8 +272,8 @@ public class PlayerClaimData implements IPlayerData {
|
||||
}
|
||||
if (this.cornerRenderPos != null) {
|
||||
if (this.cornerRenderPos[1] != this.cornerRenderPos[2])
|
||||
this.player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleIndicators.SETCORNER, true, this.cornerRenderPos[0] + 0.5, this.cornerRenderPos[2] + 0.25, this.cornerRenderPos[3] + 0.5, 0, 0.25f, 0, 0, 2));
|
||||
this.player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleIndicators.SETCORNER, true, this.cornerRenderPos[0] + 0.5, this.cornerRenderPos[1] + 0.25, this.cornerRenderPos[3] + 0.5, 0, 0.25f, 0, 0, 2));
|
||||
this.player.connection.send(new ClientboundLevelParticlesPacket(ParticleIndicators.SETCORNER, true, this.cornerRenderPos[0] + 0.5, this.cornerRenderPos[2] + 0.25, this.cornerRenderPos[3] + 0.5, 0, 0.25f, 0, 0, 2));
|
||||
this.player.connection.send(new ClientboundLevelParticlesPacket(ParticleIndicators.SETCORNER, true, this.cornerRenderPos[0] + 0.5, this.cornerRenderPos[1] + 0.25, this.cornerRenderPos[3] + 0.5, 0, 0.25f, 0, 0, 2));
|
||||
}
|
||||
if (--this.confirmTick < 0)
|
||||
this.confirmDeleteAll = false;
|
||||
@ -286,43 +285,43 @@ public class PlayerClaimData implements IPlayerData {
|
||||
this.claimBlockMessage = false;
|
||||
} else if (!this.claimBlockMessage) {
|
||||
this.claimBlockMessage = true;
|
||||
this.player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
||||
this.getClaimBlocks(), this.getAdditionalClaims(), this.usedClaimBlocks()), Formatting.GOLD), false);
|
||||
this.player.displayClientMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
||||
this.getClaimBlocks(), this.getAdditionalClaims(), this.usedClaimBlocks()), ChatFormatting.GOLD), false);
|
||||
}
|
||||
this.actionCooldown--;
|
||||
if (--this.trappedTick >= 0) {
|
||||
if (this.trappedTick == 0) {
|
||||
if (this.tpPos != null) {
|
||||
BlockPos.Mutable tpTo = this.tpPos.mutableCopy();
|
||||
Vec3d offset = new Vec3d(this.tpPos.getX() + 0.5, this.tpPos.getY() + 0.01, this.tpPos.getZ() + 0.5).subtract(this.player.getPos());
|
||||
int yHighest = this.player.world.getChunk(this.tpPos.getX() >> 4, this.tpPos.getZ() >> 4, ChunkStatus.HEIGHTMAPS).sampleHeightmap(Heightmap.Type.MOTION_BLOCKING, this.tpPos.getX() & 15, this.tpPos.getZ() & 15);
|
||||
Box box = this.player.getBoundingBox().offset(offset);
|
||||
BlockPos.MutableBlockPos tpTo = this.tpPos.mutable();
|
||||
Vec3 offset = new Vec3(this.tpPos.getX() + 0.5, this.tpPos.getY() + 0.01, this.tpPos.getZ() + 0.5).subtract(this.player.position());
|
||||
int yHighest = this.player.level.getChunk(this.tpPos.getX() >> 4, this.tpPos.getZ() >> 4, ChunkStatus.HEIGHTMAPS).getHeight(Heightmap.Types.MOTION_BLOCKING, this.tpPos.getX() & 15, this.tpPos.getZ() & 15);
|
||||
AABB box = this.player.getBoundingBox().move(offset);
|
||||
if (tpTo.getY() < yHighest) {
|
||||
while (tpTo.getY() < yHighest) {
|
||||
if (this.player.world.getBlockCollisions(this.player, box, (state, pos) -> true).allMatch(VoxelShape::isEmpty))
|
||||
if (this.player.level.noCollision(this.player, box))
|
||||
break;
|
||||
tpTo.set(tpTo.getX(), tpTo.getY() + 1, tpTo.getZ());
|
||||
box = box.offset(0, 1, 0);
|
||||
box = box.move(0, 1, 0);
|
||||
}
|
||||
tpTo.set(tpTo.getX(), tpTo.getY() + 1, tpTo.getZ());
|
||||
} else
|
||||
tpTo.set(tpTo.getX(), yHighest, tpTo.getZ());
|
||||
this.player.teleport(tpTo.getX() + 0.5, tpTo.getY(), tpTo.getZ() + 0.5);
|
||||
this.player.teleportToWithTicket(tpTo.getX() + 0.5, tpTo.getY(), tpTo.getZ() + 0.5);
|
||||
this.tpPos = null;
|
||||
} else {
|
||||
Vec3d tp = TeleportUtils.getTeleportPos(this.player, this.player.getPos(), ClaimStorage.get(this.player.getServerWorld()),
|
||||
Vec3 tp = TeleportUtils.getTeleportPos(this.player, this.player.position(), ClaimStorage.get(this.player.getLevel()),
|
||||
((IPlayerClaimImpl) this.player).getCurrentClaim().getDimensions(),
|
||||
TeleportUtils.roundedBlockPos(this.player.getPos()).mutableCopy(), (claim, nPos) -> false);
|
||||
this.player.teleport(tp.getX(), tp.getY(), tp.getZ());
|
||||
TeleportUtils.roundedBlockPos(this.player.position()).mutable(), (claim, nPos) -> false);
|
||||
this.player.teleportToWithTicket(tp.x(), tp.y(), tp.z());
|
||||
}
|
||||
} else if (this.player.getPos().squaredDistanceTo(this.trappedPos) > 0.15) {
|
||||
} else if (this.player.position().distanceToSqr(this.trappedPos) > 0.15) {
|
||||
this.trappedTick = -1;
|
||||
this.trappedPos = null;
|
||||
this.player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.trappedMove, Formatting.RED), false);
|
||||
this.player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.lang.trappedMove, ChatFormatting.RED), false);
|
||||
}
|
||||
}
|
||||
this.deathPickupTick--;
|
||||
if (!this.player.isDead())
|
||||
if (!this.player.isDeadOrDying())
|
||||
this.calculateShouldDrop = true;
|
||||
}
|
||||
|
||||
@ -340,7 +339,7 @@ public class PlayerClaimData implements IPlayerData {
|
||||
this.defaultGroups.clear();
|
||||
this.defaultGroups.putAll(data.defaultGroups);
|
||||
if (data.setDeathItemOwner())
|
||||
this.player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.unlockDropsCmd, "/flan unlockDrops"), Formatting.GOLD), false);
|
||||
this.player.displayClientMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.unlockDropsCmd, "/flan unlockDrops"), ChatFormatting.GOLD), false);
|
||||
}
|
||||
|
||||
public void updateScoreboard() {
|
||||
@ -353,8 +352,8 @@ public class PlayerClaimData implements IPlayerData {
|
||||
private int updateClaimScores() {
|
||||
int usedClaimsBlocks = 0;
|
||||
int claimsAmount = 0;
|
||||
for (ServerWorld world : this.player.getServer().getWorlds()) {
|
||||
Collection<Claim> claims = ClaimStorage.get(world).allClaimsFromPlayer(this.player.getUuid());
|
||||
for (ServerLevel world : this.player.getServer().getAllLevels()) {
|
||||
Collection<Claim> claims = ClaimStorage.get(world).allClaimsFromPlayer(this.player.getUUID());
|
||||
if (claims != null) {
|
||||
usedClaimsBlocks += claims.stream().filter(claim -> !claim.isAdminClaim()).mapToInt(Claim::getPlane).sum();
|
||||
claimsAmount += claims.size();
|
||||
@ -366,8 +365,8 @@ public class PlayerClaimData implements IPlayerData {
|
||||
|
||||
private int calculateUsedClaimBlocks() {
|
||||
int usedClaimsBlocks = 0;
|
||||
for (ServerWorld world : this.player.getServer().getWorlds()) {
|
||||
Collection<Claim> claims = ClaimStorage.get(world).allClaimsFromPlayer(this.player.getUuid());
|
||||
for (ServerLevel world : this.player.getServer().getAllLevels()) {
|
||||
Collection<Claim> claims = ClaimStorage.get(world).allClaimsFromPlayer(this.player.getUUID());
|
||||
if (claims != null) {
|
||||
usedClaimsBlocks += claims.stream().filter(claim -> !claim.isAdminClaim()).mapToInt(Claim::getPlane).sum();
|
||||
}
|
||||
@ -376,11 +375,11 @@ public class PlayerClaimData implements IPlayerData {
|
||||
}
|
||||
|
||||
public boolean setDeathItemOwner() {
|
||||
if (!this.player.isDead())
|
||||
if (!this.player.isDeadOrDying())
|
||||
return false;
|
||||
if (this.calculateShouldDrop) {
|
||||
BlockPos rounded = TeleportUtils.roundedBlockPos(this.player.getPos().add(0, this.player.getActiveEyeHeight(this.player.getPose(), this.player.getDimensions(this.player.getPose())), 0));
|
||||
this.shouldProtectDrop = ClaimStorage.get(this.player.getServerWorld()).getForPermissionCheck(rounded)
|
||||
BlockPos rounded = TeleportUtils.roundedBlockPos(this.player.position().add(0, this.player.getStandingEyeHeight(this.player.getPose(), this.player.getDimensions(this.player.getPose())), 0));
|
||||
this.shouldProtectDrop = ClaimStorage.get(this.player.getLevel()).getForPermissionCheck(rounded)
|
||||
.canInteract(this.player, PermissionRegistry.LOCKITEMS, rounded);
|
||||
this.calculateShouldDrop = false;
|
||||
}
|
||||
@ -388,11 +387,11 @@ public class PlayerClaimData implements IPlayerData {
|
||||
}
|
||||
|
||||
public void save(MinecraftServer server) {
|
||||
Flan.log("Saving player data for player {} with uuid {}", this.player.getName(), this.player.getUuid());
|
||||
Flan.log("Saving player data for player {} with uuid {}", this.player.getName(), this.player.getUUID());
|
||||
Path dir = ConfigHandler.getPlayerSavePath(server);
|
||||
try {
|
||||
Files.createDirectories(dir);
|
||||
Path file = dir.resolve(this.player.getUuid() + ".json");
|
||||
Path file = dir.resolve(this.player.getUUID() + ".json");
|
||||
try {
|
||||
Files.createFile(file);
|
||||
} catch (FileAlreadyExistsException e) {
|
||||
@ -418,11 +417,11 @@ public class PlayerClaimData implements IPlayerData {
|
||||
}
|
||||
|
||||
public void read(MinecraftServer server) {
|
||||
Flan.log("Reading player data for player {} with uuid {}", this.player.getName(), this.player.getUuid());
|
||||
Flan.log("Reading player data for player {} with uuid {}", this.player.getName(), this.player.getUUID());
|
||||
try {
|
||||
Path file = ConfigHandler.getPlayerSavePath(server).resolve(this.player.getUuid() + ".json");
|
||||
Path file = ConfigHandler.getPlayerSavePath(server).resolve(this.player.getUUID() + ".json");
|
||||
if (!Files.exists(file)) {
|
||||
Flan.log("No player data found for player {} with uuid {}", this.player.getName(), this.player.getUuid());
|
||||
Flan.log("No player data found for player {} with uuid {}", this.player.getName(), this.player.getUUID());
|
||||
return;
|
||||
}
|
||||
JsonReader reader = ConfigHandler.GSON.newJsonReader(Files.newBufferedReader(file, StandardCharsets.UTF_8));
|
||||
@ -438,7 +437,7 @@ public class PlayerClaimData implements IPlayerData {
|
||||
try {
|
||||
this.editDefaultPerms(e.getKey(), PermissionRegistry.get(p.getKey()), p.getValue().getAsBoolean() ? 1 : 0);
|
||||
} catch (NullPointerException ex) {
|
||||
Flan.logger.error("Error reading Permission {} for personal group {} for player {}. Permission doesnt exist", p.getKey(), e.getKey(), this.player.getName().asString());
|
||||
Flan.logger.error("Error reading Permission {} for personal group {} for player {}. Permission doesnt exist", p.getKey(), e.getKey(), this.player.getName().getContents());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -450,8 +449,8 @@ public class PlayerClaimData implements IPlayerData {
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateScoreFor(ServerPlayerEntity player, ScoreboardCriterion criterion, int val) {
|
||||
player.getScoreboard().forEachScore(criterion, player.getEntityName(), (scoreboardPlayerScore) -> {
|
||||
public static void updateScoreFor(ServerPlayer player, ObjectiveCriteria criterion, int val) {
|
||||
player.getScoreboard().forAllObjectives(criterion, player.getScoreboardName(), (scoreboardPlayerScore) -> {
|
||||
scoreboardPlayerScore.setScore(val);
|
||||
});
|
||||
}
|
||||
@ -482,11 +481,11 @@ public class PlayerClaimData implements IPlayerData {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean readGriefPreventionPlayerData(MinecraftServer server, ServerCommandSource src) {
|
||||
public static boolean readGriefPreventionPlayerData(MinecraftServer server, CommandSourceStack src) {
|
||||
Flan.log("Reading grief prevention data");
|
||||
File griefPrevention = server.getSavePath(WorldSavePath.ROOT).resolve("plugins/GriefPreventionData/PlayerData").toFile();
|
||||
File griefPrevention = server.getWorldPath(LevelResource.ROOT).resolve("plugins/GriefPreventionData/PlayerData").toFile();
|
||||
if (!griefPrevention.exists()) {
|
||||
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.cantFindData, griefPrevention.getAbsolutePath()), Formatting.DARK_RED), false);
|
||||
src.sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.cantFindData, griefPrevention.getAbsolutePath()), ChatFormatting.DARK_RED), false);
|
||||
return false;
|
||||
}
|
||||
for (File f : griefPrevention.listFiles()) {
|
||||
@ -497,14 +496,14 @@ public class PlayerClaimData implements IPlayerData {
|
||||
|
||||
} else {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(f));
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(UUID.fromString(f.getName()));
|
||||
ServerPlayer player = server.getPlayerList().getPlayer(UUID.fromString(f.getName()));
|
||||
if (player != null) {
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
reader.readLine();
|
||||
data.claimBlocks = Integer.parseInt(reader.readLine());
|
||||
data.additionalClaimBlocks = Integer.parseInt(reader.readLine());
|
||||
} else {
|
||||
File dir = new File(server.getSavePath(WorldSavePath.PLAYERDATA).toFile(), "/claimData/");
|
||||
File dir = new File(server.getWorldPath(LevelResource.PLAYER_DATA_DIR).toFile(), "/claimData/");
|
||||
if (!dir.exists())
|
||||
dir.mkdir();
|
||||
File file = new File(dir, f.getName() + ".json");
|
||||
@ -521,7 +520,7 @@ public class PlayerClaimData implements IPlayerData {
|
||||
reader.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.errorFile, f.getName(), Formatting.RED)), false);
|
||||
src.sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.errorFile, f.getName(), ChatFormatting.RED)), false);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -4,7 +4,7 @@ import io.github.flemmli97.flan.Flan;
|
||||
import io.github.flemmli97.flan.claim.ClaimStorage;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -40,11 +40,11 @@ public class PlayerDataHandler {
|
||||
return playerDatas;
|
||||
}
|
||||
|
||||
public static void deleteUnusedClaims(MinecraftServer server, ClaimStorage storage, ServerWorld world) {
|
||||
public static void deleteUnusedClaims(MinecraftServer server, ClaimStorage storage, ServerLevel world) {
|
||||
if (inActivePlayerData == null)
|
||||
initInactivePlayers(server);
|
||||
inActivePlayerData.forEach((uuid, data) -> {
|
||||
Flan.log("{} Deleting all claims for inactive player {} last seen {}", world.getRegistryKey(), data.owner, data.lastOnline);
|
||||
Flan.log("{} Deleting all claims for inactive player {} last seen {}", world.dimension(), data.owner, data.lastOnline);
|
||||
storage.allClaimsFromPlayer(data.owner)
|
||||
.forEach(claim -> storage.deleteClaim(claim, true, EnumEditMode.DEFAULT, world));
|
||||
});
|
||||
|
@ -2,39 +2,38 @@ package io.github.flemmli97.flan.player;
|
||||
|
||||
import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.ClaimStorage;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Pair;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.chunk.ChunkStatus;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.Tuple;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class TeleportUtils {
|
||||
|
||||
public static BlockPos roundedBlockPos(Vec3d pos) {
|
||||
public static BlockPos roundedBlockPos(Vec3 pos) {
|
||||
return new BlockPos(pos);
|
||||
}
|
||||
|
||||
public static Vec3d getTeleportPos(ServerPlayerEntity player, Vec3d playerPos, ClaimStorage storage, int[] dim, BlockPos.Mutable bPos, BiFunction<Claim, BlockPos, Boolean> check) {
|
||||
Pair<Direction, Vec3d> pos = nearestOutside(dim, playerPos);
|
||||
bPos.set(pos.getRight().getX(), pos.getRight().getY(), pos.getRight().getZ());
|
||||
public static Vec3 getTeleportPos(ServerPlayer player, Vec3 playerPos, ClaimStorage storage, int[] dim, BlockPos.MutableBlockPos bPos, BiFunction<Claim, BlockPos, Boolean> check) {
|
||||
Tuple<Direction, Vec3> pos = nearestOutside(dim, playerPos);
|
||||
bPos.set(pos.getB().x(), pos.getB().y(), pos.getB().z());
|
||||
Claim claim = storage.getClaimAt(bPos);
|
||||
if (claim == null || check.apply(claim, bPos)) {
|
||||
Vec3d ret = pos.getRight();
|
||||
Vec3 ret = pos.getB();
|
||||
BlockPos rounded = roundedBlockPos(ret);
|
||||
int y = player.getServerWorld().getChunk(rounded.getX() >> 4, rounded.getZ() >> 4, ChunkStatus.HEIGHTMAPS)
|
||||
.sampleHeightmap(Heightmap.Type.MOTION_BLOCKING, rounded.getX() & 15, rounded.getZ() & 15);
|
||||
Vec3d dest = new Vec3d(ret.x, y + 1, ret.z);
|
||||
if (player.world.getBlockCollisions(player, player.getBoundingBox().offset(dest.subtract(player.getPos())), (state, p) -> true).allMatch(VoxelShape::isEmpty))
|
||||
int y = player.getLevel().getChunk(rounded.getX() >> 4, rounded.getZ() >> 4, ChunkStatus.HEIGHTMAPS)
|
||||
.getHeight(Heightmap.Types.MOTION_BLOCKING, rounded.getX() & 15, rounded.getZ() & 15);
|
||||
Vec3 dest = new Vec3(ret.x, y + 1, ret.z);
|
||||
if (player.level.noCollision(player, player.getBoundingBox().move(dest.subtract(player.position()))))
|
||||
return dest;
|
||||
return new Vec3d(rounded.getX() + 0.5, y + 1, rounded.getZ() + 0.5);
|
||||
return new Vec3(rounded.getX() + 0.5, y + 1, rounded.getZ() + 0.5);
|
||||
}
|
||||
int[] newDim = claim.getDimensions();
|
||||
switch (pos.getLeft()) {
|
||||
switch (pos.getA()) {
|
||||
case NORTH:
|
||||
dim[2] = newDim[2];
|
||||
break;
|
||||
@ -51,28 +50,28 @@ public class TeleportUtils {
|
||||
return getTeleportPos(player, playerPos, storage, dim, bPos, check);
|
||||
}
|
||||
|
||||
private static Pair<Direction, Vec3d> nearestOutside(int[] dim, Vec3d from) {
|
||||
double northDist = Math.abs(from.getZ() - dim[2]);
|
||||
double southDist = Math.abs(dim[3] - from.getZ());
|
||||
double westDist = Math.abs(from.getX() - dim[0]);
|
||||
double eastDist = Math.abs(dim[1] - from.getX());
|
||||
private static Tuple<Direction, Vec3> nearestOutside(int[] dim, Vec3 from) {
|
||||
double northDist = Math.abs(from.z() - dim[2]);
|
||||
double southDist = Math.abs(dim[3] - from.z());
|
||||
double westDist = Math.abs(from.x() - dim[0]);
|
||||
double eastDist = Math.abs(dim[1] - from.x());
|
||||
if (northDist > southDist) {
|
||||
if (eastDist > westDist) {
|
||||
if (southDist > westDist)
|
||||
return new Pair<>(Direction.WEST, new Vec3d(dim[0] - 1.5, from.getY(), from.getZ()));
|
||||
return new Pair<>(Direction.SOUTH, new Vec3d(from.getX(), from.getY(), dim[3] + 1.5));
|
||||
return new Tuple<>(Direction.WEST, new Vec3(dim[0] - 1.5, from.y(), from.z()));
|
||||
return new Tuple<>(Direction.SOUTH, new Vec3(from.x(), from.y(), dim[3] + 1.5));
|
||||
}
|
||||
if (southDist > eastDist)
|
||||
return new Pair<>(Direction.EAST, new Vec3d(dim[1] + 1.5, from.getY(), from.getZ()));
|
||||
return new Pair<>(Direction.SOUTH, new Vec3d(from.getX(), from.getY(), dim[3] + 1.5));
|
||||
return new Tuple<>(Direction.EAST, new Vec3(dim[1] + 1.5, from.y(), from.z()));
|
||||
return new Tuple<>(Direction.SOUTH, new Vec3(from.x(), from.y(), dim[3] + 1.5));
|
||||
}
|
||||
if (eastDist > westDist) {
|
||||
if (northDist > westDist)
|
||||
return new Pair<>(Direction.WEST, new Vec3d(dim[0] - 1.5, from.getY(), from.getZ()));
|
||||
return new Pair<>(Direction.NORTH, new Vec3d(from.getX(), from.getY(), dim[2] - 1.5));
|
||||
return new Tuple<>(Direction.WEST, new Vec3(dim[0] - 1.5, from.y(), from.z()));
|
||||
return new Tuple<>(Direction.NORTH, new Vec3(from.x(), from.y(), dim[2] - 1.5));
|
||||
}
|
||||
if (northDist > eastDist)
|
||||
return new Pair<>(Direction.EAST, new Vec3d(dim[1] + 1.5, from.getY(), from.getZ()));
|
||||
return new Pair<>(Direction.NORTH, new Vec3d(from.getX(), from.getY(), dim[2] - 1.5));
|
||||
return new Tuple<>(Direction.EAST, new Vec3(dim[1] + 1.5, from.y(), from.z()));
|
||||
return new Tuple<>(Direction.NORTH, new Vec3(from.x(), from.y(), dim[2] - 1.5));
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
package io.github.flemmli97.flan.scoreboard;
|
||||
|
||||
import net.minecraft.scoreboard.ScoreboardCriterion;
|
||||
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class ClaimCriterias {
|
||||
|
||||
public static ScoreboardCriterion AMOUNT = create("flan:total_claimblocks", true, ScoreboardCriterion.RenderType.INTEGER);
|
||||
public static ScoreboardCriterion USED = create("flan:used_claimblocks", true, ScoreboardCriterion.RenderType.INTEGER);
|
||||
public static ScoreboardCriterion FREE = create("flan:free_claimblocks", true, ScoreboardCriterion.RenderType.INTEGER);
|
||||
public static ScoreboardCriterion CLAIMS = create("flan:claim_number", true, ScoreboardCriterion.RenderType.INTEGER);
|
||||
public static ObjectiveCriteria AMOUNT = create("flan:total_claimblocks", true, ObjectiveCriteria.RenderType.INTEGER);
|
||||
public static ObjectiveCriteria USED = create("flan:used_claimblocks", true, ObjectiveCriteria.RenderType.INTEGER);
|
||||
public static ObjectiveCriteria FREE = create("flan:free_claimblocks", true, ObjectiveCriteria.RenderType.INTEGER);
|
||||
public static ObjectiveCriteria CLAIMS = create("flan:claim_number", true, ObjectiveCriteria.RenderType.INTEGER);
|
||||
|
||||
public static void init() {
|
||||
|
||||
@ -19,9 +19,9 @@ public class ClaimCriterias {
|
||||
/**
|
||||
* Just reflection cause its only called once during init
|
||||
*/
|
||||
private static ScoreboardCriterion create(String name, boolean readOnly, ScoreboardCriterion.RenderType renderType) {
|
||||
private static ObjectiveCriteria create(String name, boolean readOnly, ObjectiveCriteria.RenderType renderType) {
|
||||
try {
|
||||
Constructor<ScoreboardCriterion> cons = ScoreboardCriterion.class.getDeclaredConstructor(String.class, boolean.class, ScoreboardCriterion.RenderType.class);
|
||||
Constructor<ObjectiveCriteria> cons = ObjectiveCriteria.class.getDeclaredConstructor(String.class, boolean.class, ObjectiveCriteria.RenderType.class);
|
||||
cons.setAccessible(true);
|
||||
return cons.newInstance(name, readOnly, renderType);
|
||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
|
@ -24,7 +24,8 @@
|
||||
"FrostWalkerMixin",
|
||||
"LightningFireEntityMixin",
|
||||
"BannedEntryAccessor",
|
||||
"MinecraftServerMixin"
|
||||
"MinecraftServerMixin",
|
||||
"AbstractContainerAccessor"
|
||||
],
|
||||
"server": [
|
||||
],
|
||||
|
@ -1,9 +1,5 @@
|
||||
plugins {
|
||||
id "com.github.johnrengelman.shadow" version "5.0.0"
|
||||
}
|
||||
|
||||
configurations {
|
||||
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
|
||||
id "com.github.johnrengelman.shadow" version "7.1.0"
|
||||
}
|
||||
|
||||
architectury {
|
||||
@ -11,6 +7,14 @@ architectury {
|
||||
fabric()
|
||||
}
|
||||
|
||||
configurations {
|
||||
common
|
||||
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
|
||||
compileClasspath.extendsFrom common
|
||||
runtimeClasspath.extendsFrom common
|
||||
developmentFabric.extendsFrom common
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
@ -44,7 +48,10 @@ dependencies {
|
||||
|
||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}"
|
||||
|
||||
|
||||
common(project(path: ":common", configuration: "namedElements")) { transitive false }
|
||||
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
|
||||
/*
|
||||
modImplementation "me.lucko:fabric-permissions-api:${rootProject.fabric_permissions_api}"
|
||||
modCompileOnly "io.github.gunpowder:gunpowder-api:${rootProject.gunpowder_version}"
|
||||
modRuntime "io.github.gunpowder:gunpowder-base:${rootProject.gunpowder_version}"
|
||||
@ -52,17 +59,7 @@ dependencies {
|
||||
|
||||
modImplementation "io.github.ladysnake:PlayerAbilityLib:${rootProject.player_ability_lib}"
|
||||
|
||||
implementation(project(path: ":common")) {
|
||||
transitive = false
|
||||
}
|
||||
developmentFabric(project(path: ":common")) {
|
||||
transitive = false
|
||||
}
|
||||
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) {
|
||||
transitive = false
|
||||
}
|
||||
|
||||
modImplementation("dev.ftb.mods:ftb-ranks-fabric:1605.1.2-build.17")
|
||||
modImplementation("dev.ftb.mods:ftb-ranks-fabric:1605.1.2-build.17")*/
|
||||
}
|
||||
|
||||
processResources {
|
||||
@ -88,10 +85,6 @@ jar {
|
||||
classifier "dev"
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
sourcesJar {
|
||||
def commonSources = project(":common").sourcesJar
|
||||
dependsOn commonSources
|
||||
@ -99,6 +92,12 @@ sourcesJar {
|
||||
classifier "fabric-source"
|
||||
}
|
||||
|
||||
components.java {
|
||||
withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
|
||||
skip()
|
||||
}
|
||||
}
|
||||
|
||||
task apiJar(type: Jar, dependsOn: classes) {
|
||||
archiveClassifier.set "fabric-api-source"
|
||||
from project(":common").sourceSets.main.output + sourceSets.main.output
|
||||
|
5
fabric/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
fabric/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
@ -1,7 +1,7 @@
|
||||
package io.github.flemmli97.flan;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class FabricRegistryWrapper<T> implements SimpleRegistryWrapper<T> {
|
||||
|
||||
@ -12,13 +12,13 @@ public class FabricRegistryWrapper<T> implements SimpleRegistryWrapper<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getFromId(Identifier id) {
|
||||
public T getFromId(ResourceLocation id) {
|
||||
return this.delegate.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getIDFrom(T entry) {
|
||||
return this.delegate.getId(entry);
|
||||
public ResourceLocation getIDFrom(T entry) {
|
||||
return this.delegate.getKey(entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,9 +3,9 @@ package io.github.flemmli97.flan.api.fabric;
|
||||
import io.github.flemmli97.flan.api.permission.ClaimPermission;
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
||||
public class PermissionCheckEvent {
|
||||
|
||||
@ -19,21 +19,21 @@ public class PermissionCheckEvent {
|
||||
* @param pos The block pos where the action is occuring
|
||||
* @return ActionResult#PASS to do nothing. ActionResult#FAIL to prevent the action. Else to allow the action
|
||||
*/
|
||||
ActionResult check(ServerPlayerEntity player, ClaimPermission permission, BlockPos pos);
|
||||
InteractionResult check(ServerPlayer player, ClaimPermission permission, BlockPos pos);
|
||||
|
||||
}
|
||||
|
||||
public static Event<PermissionCheck> CHECK = EventFactory.createArrayBacked(PermissionCheck.class,
|
||||
(listeners) -> (player, permission, pos) -> {
|
||||
for (PermissionCheck event : listeners) {
|
||||
ActionResult result = event.check(player, permission, pos);
|
||||
InteractionResult result = event.check(player, permission, pos);
|
||||
|
||||
if (result != ActionResult.PASS) {
|
||||
if (result != InteractionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -2,13 +2,13 @@ package io.github.flemmli97.flan.claim.fabric;
|
||||
|
||||
import io.github.flemmli97.flan.api.fabric.PermissionCheckEvent;
|
||||
import io.github.flemmli97.flan.api.permission.ClaimPermission;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
||||
public class ClaimPermissionCheckImpl {
|
||||
|
||||
public static ActionResult check(ServerPlayerEntity player, ClaimPermission permission, BlockPos pos) {
|
||||
public static InteractionResult check(ServerPlayer player, ClaimPermission permission, BlockPos pos) {
|
||||
return PermissionCheckEvent.CHECK.invoker().check(player, permission, pos);
|
||||
}
|
||||
}
|
||||
|
@ -3,16 +3,16 @@ package io.github.flemmli97.flan.fabric;
|
||||
import io.github.flemmli97.flan.FabricRegistryWrapper;
|
||||
import io.github.flemmli97.flan.SimpleRegistryWrapper;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.InventoryProvider;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.WorldlyContainerHolder;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
@ -22,16 +22,16 @@ public class CrossPlatformStuffImpl {
|
||||
return FabricLoader.getInstance().getConfigDir();
|
||||
}
|
||||
|
||||
public static StatusEffect effectFromString(String s) {
|
||||
return Registry.STATUS_EFFECT.get(new Identifier(s));
|
||||
public static MobEffect effectFromString(String s) {
|
||||
return Registry.MOB_EFFECT.get(new ResourceLocation(s));
|
||||
}
|
||||
|
||||
public static String stringFromEffect(StatusEffect s) {
|
||||
return Registry.STATUS_EFFECT.getId(s).toString();
|
||||
public static String stringFromEffect(MobEffect s) {
|
||||
return Registry.MOB_EFFECT.getKey(s).toString();
|
||||
}
|
||||
|
||||
public static SimpleRegistryWrapper<StatusEffect> registryStatusEffects() {
|
||||
return new FabricRegistryWrapper<>(Registry.STATUS_EFFECT);
|
||||
public static SimpleRegistryWrapper<MobEffect> registryStatusEffects() {
|
||||
return new FabricRegistryWrapper<>(Registry.MOB_EFFECT);
|
||||
}
|
||||
|
||||
public static SimpleRegistryWrapper<Block> registryBlocks() {
|
||||
@ -47,7 +47,7 @@ public class CrossPlatformStuffImpl {
|
||||
}
|
||||
|
||||
public static boolean isInventoryTile(BlockEntity blockEntity) {
|
||||
return blockEntity instanceof Inventory || blockEntity instanceof InventoryProvider;
|
||||
return blockEntity instanceof Container || blockEntity instanceof WorldlyContainerHolder;
|
||||
}
|
||||
|
||||
public static boolean blockDataContains(CompoundTag nbt, String tag) {
|
||||
|
@ -1,25 +1,25 @@
|
||||
package io.github.flemmli97.flan.fabric.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.EntityInteractEvents;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.decoration.AbstractDecorationEntity;
|
||||
import net.minecraft.entity.decoration.ArmorStandEntity;
|
||||
import net.minecraft.entity.decoration.EndCrystalEntity;
|
||||
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
|
||||
import net.minecraft.entity.vehicle.BoatEntity;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
import net.minecraft.world.entity.decoration.HangingEntity;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.vehicle.AbstractMinecart;
|
||||
import net.minecraft.world.entity.vehicle.Boat;
|
||||
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({LivingEntity.class, Entity.class, AbstractDecorationEntity.class, AbstractMinecartEntity.class, ArmorStandEntity.class, BoatEntity.class
|
||||
, EndCrystalEntity.class, ItemEntity.class})
|
||||
@Mixin({LivingEntity.class, Entity.class, HangingEntity.class, AbstractMinecart.class, ArmorStand.class, Boat.class
|
||||
, EndCrystal.class, ItemEntity.class})
|
||||
public abstract class EntityDamageMixin {
|
||||
|
||||
@Inject(method = "damage", at = @At(value = "HEAD"), cancellable = true)
|
||||
@Inject(method = "hurt", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void onDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> info) {
|
||||
if (EntityInteractEvents.preventDamage((Entity) (Object) this, source)) {
|
||||
info.setReturnValue(false);
|
||||
|
@ -1,10 +1,10 @@
|
||||
package io.github.flemmli97.flan.fabric.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.WorldEvents;
|
||||
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.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.FireBlock;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@ -15,9 +15,12 @@ import java.util.Random;
|
||||
@Mixin(FireBlock.class)
|
||||
public abstract class FabricFireMixin {
|
||||
|
||||
@Inject(method = "trySpreadingFire", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void spread(World world, BlockPos pos, int spreadFactor, Random rand, int currentAge, CallbackInfo info) {
|
||||
if (!world.isClient && !WorldEvents.canFireSpread((ServerWorld) world, pos)) {
|
||||
/**
|
||||
* Check for blocks reacting to fire (e.g. tnt)
|
||||
*/
|
||||
@Inject(method = "checkBurnOut", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void spread(Level world, BlockPos pos, int spreadFactor, Random rand, int currentAge, CallbackInfo info) {
|
||||
if (!world.isClientSide && !WorldEvents.canFireSpread((ServerLevel) world, pos)) {
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
package io.github.flemmli97.flan.fabric.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.EntityInteractEvents;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LightningEntity;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LightningBolt;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(LightningEntity.class)
|
||||
@Mixin(LightningBolt.class)
|
||||
public abstract class LightningHitMixin {
|
||||
|
||||
@ModifyVariable(method = "tick", at = @At(value = "INVOKE", target = "Ljava/util/List;iterator()Ljava/util/Iterator;"), require = 1)
|
||||
|
@ -1,21 +1,21 @@
|
||||
package io.github.flemmli97.flan.fabric.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.WorldEvents;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.PistonBlock;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.piston.PistonBaseBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
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(PistonBlock.class)
|
||||
@Mixin(PistonBaseBlock.class)
|
||||
public abstract class PistonMixin {
|
||||
|
||||
@Inject(method = "isMovable", at = @At(value = "HEAD"), cancellable = true)
|
||||
private static void checkMovable(BlockState blockState, World world, BlockPos blockPos, Direction direction, boolean canBreak, Direction pistonDir, CallbackInfoReturnable<Boolean> info) {
|
||||
@Inject(method = "isPushable", at = @At(value = "HEAD"), cancellable = true)
|
||||
private static void checkMovable(BlockState blockState, Level world, BlockPos blockPos, Direction direction, boolean canBreak, Direction pistonDir, CallbackInfoReturnable<Boolean> info) {
|
||||
if (!WorldEvents.pistonCanPush(blockState, world, blockPos, direction, pistonDir)) {
|
||||
info.setReturnValue(false);
|
||||
info.cancel();
|
||||
|
@ -1,20 +1,20 @@
|
||||
package io.github.flemmli97.flan.fabric.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.EntityInteractEvents;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
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(PlayerEntity.class)
|
||||
@Mixin(Player.class)
|
||||
public abstract class PlayerDropMixin {
|
||||
|
||||
@Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At(value = "HEAD"), cancellable = true)
|
||||
@Inject(method = "drop(Lnet/minecraft/world/item/ItemStack;ZZ)Lnet/minecraft/world/entity/item/ItemEntity;", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void drop(ItemStack stack, boolean throwRandomly, boolean retainOwnership, CallbackInfoReturnable<ItemEntity> info) {
|
||||
if (!EntityInteractEvents.canDropItem((PlayerEntity) (Object) this, stack)) {
|
||||
if (!EntityInteractEvents.canDropItem((Player) (Object) this, stack)) {
|
||||
info.setReturnValue(null);
|
||||
info.cancel();
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
package io.github.flemmli97.flan.fabric.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.EntityInteractEvents;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Fabric APIs UseEntityCallback is at Entity#interactAt and thats only used for armor stand. Why its only there idk...
|
||||
*/
|
||||
@Mixin(Player.class)
|
||||
public abstract class PlayerInteractEntityMixin {
|
||||
|
||||
@Inject(method = "interactOn", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void interactOnEntity(Entity entity, InteractionHand interactionHand, CallbackInfoReturnable<InteractionResult> info) {
|
||||
if (entity == null || !(entity.level instanceof ServerLevel))
|
||||
return;
|
||||
InteractionResult result = EntityInteractEvents.useEntity((Player) (Object) this, entity.level, interactionHand, entity);
|
||||
if (result != InteractionResult.PASS) {
|
||||
info.setReturnValue(InteractionResult.PASS);
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
}
|
@ -2,18 +2,18 @@ package io.github.flemmli97.flan.fabric.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.PlayerEvents;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.PlayerManager;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
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(PlayerManager.class)
|
||||
@Mixin(PlayerList.class)
|
||||
public abstract class PlayerManagerMixin {
|
||||
|
||||
@Inject(method = "loadPlayerData", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;fromTag(Lnet/minecraft/nbt/CompoundTag;)V"))
|
||||
private void singlePlayerRead(ServerPlayerEntity player, CallbackInfoReturnable<CompoundTag> info) {
|
||||
@Inject(method = "load", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;load(Lnet/minecraft/nbt/CompoundTag;)V"))
|
||||
private void singlePlayerRead(ServerPlayer player, CallbackInfoReturnable<CompoundTag> info) {
|
||||
PlayerEvents.readClaimData(player);
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
package io.github.flemmli97.flan.fabric.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.EntityInteractEvents;
|
||||
import net.minecraft.entity.projectile.DragonFireballEntity;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
import net.minecraft.entity.projectile.thrown.EggEntity;
|
||||
import net.minecraft.entity.projectile.thrown.EnderPearlEntity;
|
||||
import net.minecraft.entity.projectile.thrown.ExperienceBottleEntity;
|
||||
import net.minecraft.entity.projectile.thrown.PotionEntity;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.world.entity.projectile.DragonFireball;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.entity.projectile.ThrownEgg;
|
||||
import net.minecraft.world.entity.projectile.ThrownEnderpearl;
|
||||
import net.minecraft.world.entity.projectile.ThrownExperienceBottle;
|
||||
import net.minecraft.world.entity.projectile.ThrownPotion;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
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;
|
||||
|
||||
@Mixin(value = {ProjectileEntity.class, EggEntity.class, PotionEntity.class, ExperienceBottleEntity.class, DragonFireballEntity.class, EnderPearlEntity.class})
|
||||
@Mixin(value = {Projectile.class, ThrownEgg.class, ThrownPotion.class, ThrownExperienceBottle.class, DragonFireball.class, ThrownEnderpearl.class})
|
||||
public abstract class ProjectileMixin {
|
||||
|
||||
@Inject(method = "onCollision", at = @At(value = "HEAD"), cancellable = true)
|
||||
@Inject(method = "onHit", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void collision(HitResult hitResult, CallbackInfo info) {
|
||||
if (EntityInteractEvents.projectileHit((ProjectileEntity) (Object) this, hitResult)) {
|
||||
if (EntityInteractEvents.projectileHit((Projectile) (Object) this, hitResult)) {
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +0,0 @@
|
||||
package io.github.flemmli97.flan.fabric.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.EntityInteractEvents;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
/**
|
||||
* Fabric APIs UseEntityCallback is at Entity#interactAt and thats only used for armor stand. Why its only there idk...
|
||||
*/
|
||||
@Mixin(ServerPlayNetworkHandler.class)
|
||||
public abstract class ServerPlayNetworkHandlerMixin {
|
||||
|
||||
@Shadow
|
||||
private ServerPlayerEntity player;
|
||||
|
||||
@Inject(method = "onPlayerInteractEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;interact(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;"), cancellable = true)
|
||||
private void onPlayerInteractEntity(PlayerInteractEntityC2SPacket packet, CallbackInfo info) {
|
||||
World world = this.player.getEntityWorld();
|
||||
Entity entity = packet.getEntity(world);
|
||||
if (entity != null) {
|
||||
ActionResult result = EntityInteractEvents.useEntity(this.player, world, packet.getHand(), entity);
|
||||
if (result != ActionResult.PASS) {
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,22 +1,22 @@
|
||||
package io.github.flemmli97.flan.fabric.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.WorldEvents;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.world.explosion.Explosion;
|
||||
import net.minecraft.world.explosion.ExplosionBehavior;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.ExplosionDamageCalculator;
|
||||
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;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
@Mixin(ServerWorld.class)
|
||||
@Mixin(ServerLevel.class)
|
||||
public abstract class ServerWorldMixin {
|
||||
|
||||
@Inject(method = "createExplosion", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/explosion/Explosion;collectBlocksAndDamageEntities()V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
private void explosionHook(Entity entity, DamageSource damageSource, ExplosionBehavior explosionBehavior, double d, double e, double f, float g, boolean bl, Explosion.DestructionType destructionType, CallbackInfoReturnable<Explosion> info, Explosion explosion) {
|
||||
WorldEvents.modifyExplosion(explosion, (ServerWorld) (Object) this);
|
||||
@Inject(method = "explode", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Explosion;explode()V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
private void explosionHook(Entity entity, DamageSource damageSource, ExplosionDamageCalculator explosionBehavior, double d, double e, double f, float g, boolean bl, Explosion.BlockInteraction destructionType, CallbackInfoReturnable<Explosion> info, Explosion explosion) {
|
||||
WorldEvents.modifyExplosion(explosion, (ServerLevel) (Object) this);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
package io.github.flemmli97.flan.fabric.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.EntityInteractEvents;
|
||||
import net.minecraft.entity.passive.SnowGolemEntity;
|
||||
import net.minecraft.world.entity.animal.SnowGolem;
|
||||
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;
|
||||
|
||||
@Mixin(SnowGolemEntity.class)
|
||||
@Mixin(SnowGolem.class)
|
||||
public abstract class SnowGolemMixin {
|
||||
|
||||
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getGameRules()Lnet/minecraft/world/GameRules;"), cancellable = true)
|
||||
@Inject(method = "aiStep", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;getGameRules()Lnet/minecraft/world/level/GameRules;"), cancellable = true)
|
||||
private void checkSnow(CallbackInfo info) {
|
||||
if (!EntityInteractEvents.canSnowGolemInteract((SnowGolemEntity) (Object) this)) {
|
||||
if (!EntityInteractEvents.canSnowGolemInteract((SnowGolem) (Object) this)) {
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,19 @@
|
||||
package io.github.flemmli97.flan.fabric.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.WorldEvents;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.world.SpawnHelper;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.level.NaturalSpawner;
|
||||
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)
|
||||
@Mixin(NaturalSpawner.class)
|
||||
public abstract 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) {
|
||||
@Inject(method = "isValidPositionForMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;checkSpawnRules(Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/world/entity/MobSpawnType;)Z"), cancellable = true)
|
||||
private static void isValidSpawn(ServerLevel world, Mob entity, double squaredDistance, CallbackInfoReturnable<Boolean> info) {
|
||||
if (WorldEvents.preventMobSpawn(world, entity)) {
|
||||
info.setReturnValue(false);
|
||||
info.cancel();
|
||||
|
@ -1,22 +1,22 @@
|
||||
package io.github.flemmli97.flan.fabric.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.EntityInteractEvents;
|
||||
import net.minecraft.entity.boss.WitherEntity;
|
||||
import net.minecraft.world.entity.boss.wither.WitherBoss;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(WitherEntity.class)
|
||||
@Mixin(WitherBoss.class)
|
||||
public abstract class WitherMixin {
|
||||
|
||||
@Shadow
|
||||
private int field_7082;
|
||||
private int destroyBlocksTick;
|
||||
|
||||
@Inject(method = "mobTick", at = @At(value = "HEAD"))
|
||||
@Inject(method = "customServerAiStep", at = @At(value = "HEAD"))
|
||||
private void preventClaimDmg(CallbackInfo info) {
|
||||
if (!EntityInteractEvents.witherCanDestroy((WitherEntity) (Object) this))
|
||||
this.field_7082 = -1;
|
||||
if (!EntityInteractEvents.witherCanDestroy((WitherBoss) (Object) this))
|
||||
this.destroyBlocksTick = -1;
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
package io.github.flemmli97.flan.fabric.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.PlayerEvents;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.WorldSaveHandler;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.storage.PlayerDataStorage;
|
||||
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;
|
||||
|
||||
@Mixin(WorldSaveHandler.class)
|
||||
@Mixin(PlayerDataStorage.class)
|
||||
public abstract class WorldSaveHandlerMixin {
|
||||
|
||||
@Inject(method = "savePlayerData", at = @At(value = "RETURN"))
|
||||
private void save(PlayerEntity player, CallbackInfo info) {
|
||||
@Inject(method = "save", at = @At(value = "RETURN"))
|
||||
private void save(Player player, CallbackInfo info) {
|
||||
PlayerEvents.saveClaimData(player);
|
||||
}
|
||||
|
||||
@Inject(method = "loadPlayerData", at = @At(value = "RETURN"))
|
||||
private void load(PlayerEntity player, CallbackInfoReturnable<CompoundTag> info) {
|
||||
@Inject(method = "load", at = @At(value = "RETURN"))
|
||||
private void load(Player player, CallbackInfoReturnable<CompoundTag> info) {
|
||||
PlayerEvents.readClaimData(player);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
package io.github.flemmli97.flan.fabric.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.event.EntityInteractEvents;
|
||||
import net.minecraft.entity.ExperienceOrbEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.world.entity.ExperienceOrb;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
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;
|
||||
|
||||
@Mixin(ExperienceOrbEntity.class)
|
||||
@Mixin(ExperienceOrb.class)
|
||||
public abstract class XpEntityMixin {
|
||||
|
||||
@Inject(method = "onPlayerCollision", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void collision(PlayerEntity player, CallbackInfo info) {
|
||||
@Inject(method = "playerTouch", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void collision(Player player, CallbackInfo info) {
|
||||
if (EntityInteractEvents.xpAbsorb(player)) {
|
||||
info.cancel();
|
||||
}
|
||||
|
@ -1,66 +1,59 @@
|
||||
package io.github.flemmli97.flan.integration.currency.fabric;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import io.github.flemmli97.flan.Flan;
|
||||
import io.github.flemmli97.flan.claim.PermHelper;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import io.github.gunpowder.api.GunpowderMod;
|
||||
import io.github.gunpowder.api.module.currency.dataholders.StoredBalance;
|
||||
import io.github.gunpowder.api.module.currency.modelhandlers.BalanceHandler;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
public class CommandCurrencyImpl {
|
||||
|
||||
public static int sellClaimBlocks(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
public static int sellClaimBlocks(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
if (!Flan.gunpowder) {
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.currencyMissing, Formatting.DARK_RED), false);
|
||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.lang.currencyMissing, ChatFormatting.DARK_RED), false);
|
||||
return 0;
|
||||
}
|
||||
if (ConfigHandler.config.sellPrice == -1) {
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.sellDisabled, Formatting.DARK_RED), false);
|
||||
/*if (ConfigHandler.config.sellPrice == -1) {
|
||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.lang.sellDisabled, ChatFormatting.DARK_RED), false);
|
||||
return 0;
|
||||
}
|
||||
int amount = Math.max(0, IntegerArgumentType.getInteger(context, "amount"));
|
||||
PlayerClaimData data = PlayerClaimData.get(context.getSource().getPlayer());
|
||||
PlayerClaimData data = PlayerClaimData.get(context.getSource().getPlayerOrException());
|
||||
if (data.getAdditionalClaims() - Math.max(0, data.usedClaimBlocks() - data.getClaimBlocks()) < amount) {
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.sellFail, Formatting.DARK_RED), false);
|
||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.lang.sellFail, ChatFormatting.DARK_RED), false);
|
||||
return 0;
|
||||
}
|
||||
StoredBalance bal = GunpowderMod.getInstance().getRegistry().getModelHandler(BalanceHandler.class).getUser(context.getSource().getPlayer().getUuid());
|
||||
StoredBalance bal = GunpowderMod.getInstance().getRegistry().getModelHandler(BalanceHandler.class).getUser(context.getSource().getPlayerOrException().getUUID());
|
||||
BigDecimal price = BigDecimal.valueOf(amount * ConfigHandler.config.sellPrice);
|
||||
bal.setBalance(bal.getBalance().add(price));
|
||||
data.setAdditionalClaims(data.getAdditionalClaims() - amount);
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.sellSuccess, amount, price), Formatting.GOLD), false);
|
||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.sellSuccess, amount, price), ChatFormatting.GOLD), false);*/
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
public static int buyClaimBlocks(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
public static int buyClaimBlocks(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
if (!Flan.gunpowder) {
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.currencyMissing, Formatting.DARK_RED), false);
|
||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.lang.currencyMissing, ChatFormatting.DARK_RED), false);
|
||||
return 0;
|
||||
}
|
||||
if (ConfigHandler.config.buyPrice == -1) {
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.buyDisabled, Formatting.DARK_RED), false);
|
||||
/*if (ConfigHandler.config.buyPrice == -1) {
|
||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.lang.buyDisabled, ChatFormatting.DARK_RED), false);
|
||||
return 0;
|
||||
}
|
||||
StoredBalance bal = GunpowderMod.getInstance().getRegistry().getModelHandler(BalanceHandler.class).getUser(context.getSource().getPlayer().getUuid());
|
||||
StoredBalance bal = GunpowderMod.getInstance().getRegistry().getModelHandler(BalanceHandler.class).getUser(context.getSource().getPlayerOrException().getUUID());
|
||||
int amount = Math.max(0, IntegerArgumentType.getInteger(context, "amount"));
|
||||
BigDecimal price = BigDecimal.valueOf(amount * ConfigHandler.config.buyPrice);
|
||||
if (bal.getBalance().compareTo(price) >= 0) {
|
||||
PlayerClaimData data = PlayerClaimData.get(context.getSource().getPlayer());
|
||||
PlayerClaimData data = PlayerClaimData.get(context.getSource().getPlayerOrException());
|
||||
data.setAdditionalClaims(data.getAdditionalClaims() + amount);
|
||||
bal.setBalance(bal.getBalance().subtract(price));
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.buySuccess, amount, price), Formatting.GOLD), false);
|
||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.buySuccess, amount, price), ChatFormatting.GOLD), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.buyFail, Formatting.DARK_RED), false);
|
||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.lang.buyFail, ChatFormatting.DARK_RED), false);*/
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +1,41 @@
|
||||
package io.github.flemmli97.flan.integration.permissions.fabric;
|
||||
|
||||
import dev.ftb.mods.ftbranks.api.FTBRanksAPI;
|
||||
import io.github.flemmli97.flan.Flan;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class PermissionNodeHandlerImpl {
|
||||
|
||||
public static boolean perm(ServerCommandSource src, String perm, boolean adminCmd) {
|
||||
if (Flan.permissionAPI) {
|
||||
public static boolean perm(CommandSourceStack src, String perm, boolean adminCmd) {
|
||||
/*if (Flan.permissionAPI) {
|
||||
if (adminCmd)
|
||||
return Permissions.check(src, perm, ConfigHandler.config.permissionLevel);
|
||||
return Permissions.check(src, perm, true);
|
||||
}
|
||||
if (Flan.ftbRanks && src.getEntity() instanceof ServerPlayerEntity) {
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) src.getEntity();
|
||||
return FTBRanksAPI.getPermissionValue(player, perm).asBoolean().orElse(!adminCmd || player.hasPermissionLevel(ConfigHandler.config.permissionLevel));
|
||||
}
|
||||
return !adminCmd || src.hasPermissionLevel(ConfigHandler.config.permissionLevel);
|
||||
if (Flan.ftbRanks && src.getEntity() instanceof ServerPlayer) {
|
||||
ServerPlayer player = (ServerPlayer) src.getEntity();
|
||||
return FTBRanksAPI.getPermissionValue(player, perm).asBoolean().orElse(!adminCmd || player.hasPermissions(ConfigHandler.config.permissionLevel));
|
||||
}*/
|
||||
return !adminCmd || src.hasPermission(ConfigHandler.config.permissionLevel);
|
||||
}
|
||||
|
||||
public static boolean perm(ServerPlayerEntity src, String perm, boolean adminCmd) {
|
||||
if (Flan.permissionAPI) {
|
||||
public static boolean perm(ServerPlayer src, String perm, boolean adminCmd) {
|
||||
/*if (Flan.permissionAPI) {
|
||||
if (adminCmd)
|
||||
return Permissions.check(src, perm, ConfigHandler.config.permissionLevel);
|
||||
return Permissions.check(src, perm, true);
|
||||
}
|
||||
if (Flan.ftbRanks) {
|
||||
return FTBRanksAPI.getPermissionValue(src, perm).asBoolean().orElse(!adminCmd || src.hasPermissionLevel(ConfigHandler.config.permissionLevel));
|
||||
}
|
||||
return !adminCmd || src.hasPermissionLevel(ConfigHandler.config.permissionLevel);
|
||||
return FTBRanksAPI.getPermissionValue(src, perm).asBoolean().orElse(!adminCmd || src.hasPermissions(ConfigHandler.config.permissionLevel));
|
||||
}*/
|
||||
return !adminCmd || src.hasPermissions(ConfigHandler.config.permissionLevel);
|
||||
}
|
||||
|
||||
public static boolean permBelowEqVal(ServerPlayerEntity src, String perm, int val, int fallback) {
|
||||
if (Flan.ftbRanks) {
|
||||
public static boolean permBelowEqVal(ServerPlayer src, String perm, int val, int fallback) {
|
||||
/*if (Flan.ftbRanks) {
|
||||
int max = FTBRanksAPI.getPermissionValue(src, perm).asInteger().orElse(fallback);
|
||||
return val <= max;
|
||||
}
|
||||
}*/
|
||||
return val <= fallback;
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,17 @@
|
||||
package io.github.flemmli97.flan.integration.playerability;
|
||||
|
||||
import io.github.flemmli97.flan.api.data.IPermissionContainer;
|
||||
import io.github.flemmli97.flan.api.permission.PermissionRegistry;
|
||||
import io.github.flemmli97.flan.claim.ClaimStorage;
|
||||
import io.github.ladysnake.pal.AbilitySource;
|
||||
import io.github.ladysnake.pal.PlayerAbility;
|
||||
import io.github.ladysnake.pal.PlayerAbilityEnableCallback;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class PlayerAbilityEvents {
|
||||
|
||||
public static void register() {
|
||||
PlayerAbilityEnableCallback.EVENT.register(PlayerAbilityEvents::checkAbility);
|
||||
//PlayerAbilityEnableCallback.EVENT.register(PlayerAbilityEvents::checkAbility);
|
||||
}
|
||||
|
||||
public static boolean checkAbility(PlayerEntity player, PlayerAbility ability, AbilitySource abilitySource) {
|
||||
if (player.world.isClient)
|
||||
/*public static boolean checkAbility(Player player, PlayerAbility ability, AbilitySource abilitySource) {
|
||||
if (player.level.isClientSide)
|
||||
return true;
|
||||
BlockPos pos = player.getBlockPos();
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) player.world);
|
||||
BlockPos pos = player.blockPosition();
|
||||
ClaimStorage storage = ClaimStorage.get((ServerLevel) player.level);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
return claim.canInteract((ServerPlayerEntity) player, PermissionRegistry.FLIGHT, pos, true);
|
||||
}
|
||||
return claim.canInteract((ServerPlayer) player, PermissionRegistry.FLIGHT, pos, true);
|
||||
}*/
|
||||
}
|
||||
|
@ -2,12 +2,12 @@
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "io.github.flemmli97.flan.fabric.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"compatibilityLevel": "JAVA_16",
|
||||
"mixins": [
|
||||
"ServerWorldMixin",
|
||||
"PistonMixin",
|
||||
"SpawnHelperMixin",
|
||||
"ServerPlayNetworkHandlerMixin",
|
||||
"PlayerInteractEntityMixin",
|
||||
"ProjectileMixin",
|
||||
"EntityDamageMixin",
|
||||
"XpEntityMixin",
|
||||
|
@ -1,9 +1,5 @@
|
||||
plugins {
|
||||
id "com.github.johnrengelman.shadow" version "5.0.0"
|
||||
}
|
||||
|
||||
configurations {
|
||||
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
|
||||
id "com.github.johnrengelman.shadow" version "7.1.0"
|
||||
}
|
||||
|
||||
architectury {
|
||||
@ -11,9 +7,18 @@ architectury {
|
||||
forge()
|
||||
}
|
||||
|
||||
configurations {
|
||||
common
|
||||
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
|
||||
compileClasspath.extendsFrom common
|
||||
runtimeClasspath.extendsFrom common
|
||||
developmentForge.extendsFrom common
|
||||
}
|
||||
|
||||
loom {
|
||||
mixinConfigs = ["flan.mixins.json", "flan.forge.mixins.json"]
|
||||
useFabricMixin = true
|
||||
forge {
|
||||
mixinConfigs = ["flan.mixins.json", "flan.forge.mixins.json"]
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
@ -31,18 +36,11 @@ repositories {
|
||||
dependencies {
|
||||
forge "net.minecraftforge:forge:${rootProject.minecraft_version}-${rootProject.forge_version}"
|
||||
|
||||
implementation(project(path: ":common")) {
|
||||
transitive = false
|
||||
}
|
||||
developmentForge(project(path: ":common")) {
|
||||
transitive = false
|
||||
}
|
||||
shadowCommon(project(path: ":common", configuration: "transformProductionForge")) {
|
||||
transitive = false
|
||||
}
|
||||
common(project(path: ":common", configuration: "namedElements")) { transitive false }
|
||||
shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false }
|
||||
|
||||
modImplementation("dev.ftb.mods:ftb-ranks-forge:${ftb_ranks}")
|
||||
modImplementation(dicemcmm)
|
||||
//modImplementation("dev.ftb.mods:ftb-ranks-forge:${ftb_ranks}")
|
||||
//modImplementation(dicemcmm)
|
||||
}
|
||||
|
||||
processResources {
|
||||
@ -70,10 +68,6 @@ jar {
|
||||
classifier "dev"
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
sourcesJar {
|
||||
def commonSources = project(":common").sourcesJar
|
||||
dependsOn commonSources
|
||||
@ -81,6 +75,11 @@ sourcesJar {
|
||||
classifier "forge-sources"
|
||||
}
|
||||
|
||||
components.java {
|
||||
withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
|
||||
skip()
|
||||
}
|
||||
}
|
||||
|
||||
task apiJar(type: Jar, dependsOn: classes) {
|
||||
archiveClassifier.set "forge-api-source"
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.flemmli97.flan;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import io.github.flemmli97.flan.SimpleRegistryWrapper;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
@ -13,12 +14,12 @@ public class ForgeRegistryWrapper<T extends IForgeRegistryEntry<T>> implements S
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getFromId(Identifier id) {
|
||||
public T getFromId(ResourceLocation id) {
|
||||
return this.registry.getValue(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getIDFrom(T entry) {
|
||||
public ResourceLocation getIDFrom(T entry) {
|
||||
return entry.getRegistryName();
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user