finishing world interactions, commands etc.
This commit is contained in:
parent
fdbdd5cfb0
commit
4400dd1357
@ -1,5 +1,5 @@
|
||||
# Done to increase the memory available to gradle.
|
||||
org.gradle.jvmargs=-Xmx1G
|
||||
org.gradle.jvmargs=-Xmx2G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/use
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.flemmli97.flan;
|
||||
|
||||
import com.flemmli97.flan.claim.ObjectToPermissionMap;
|
||||
import com.flemmli97.flan.claim.BlockToPermissionMap;
|
||||
import com.flemmli97.flan.commands.CommandClaim;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.event.BlockInteractEvents;
|
||||
@ -19,19 +19,14 @@ public class Flan implements ModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
|
||||
//Events
|
||||
AttackBlockCallback.EVENT.register(BlockInteractEvents::breakBlocks);
|
||||
UseBlockCallback.EVENT.register(BlockInteractEvents::useBlocks);
|
||||
UseEntityCallback.EVENT.register(EntityInteractEvents::useAtEntity);
|
||||
AttackEntityCallback.EVENT.register(EntityInteractEvents::attackEntity);
|
||||
UseItemCallback.EVENT.register(ItemInteractEvents::useItem);
|
||||
ServerLifecycleEvents.SERVER_STARTING.register(ConfigHandler::serverLoad);
|
||||
ServerLifecycleEvents.SERVER_STARTING.register(ObjectToPermissionMap::reload);
|
||||
//Explosion
|
||||
//XP
|
||||
//TARGETBLOCK
|
||||
//Commands
|
||||
ServerLifecycleEvents.SERVER_STARTING.register(BlockToPermissionMap::reload);
|
||||
|
||||
CommandRegistrationCallback.EVENT.register(CommandClaim::register);
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ObjectToPermissionMap {
|
||||
public class BlockToPermissionMap {
|
||||
|
||||
private static final Map<Block, EnumPermission> blockToPermission = Maps.newHashMap();
|
||||
|
@ -1,20 +1,28 @@
|
||||
package com.flemmli97.flan.claim;
|
||||
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.player.PlayerClaimData;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.client.RunArgs;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumMap;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -25,6 +33,7 @@ public class Claim {
|
||||
private int minX, minZ, maxX, maxZ, minY;
|
||||
|
||||
private UUID owner;
|
||||
|
||||
private UUID claimID;
|
||||
private final EnumSet<EnumPermission> globalPerm = EnumSet.noneOf(EnumPermission.class);
|
||||
private final Map<String, EnumMap<EnumPermission, Boolean>> permissions = Maps.newHashMap();
|
||||
@ -54,12 +63,6 @@ public class Claim {
|
||||
this.owner = creator;
|
||||
}
|
||||
|
||||
public static Claim fromTag(CompoundTag tag) {
|
||||
Claim claim = new Claim();
|
||||
claim.read(tag);
|
||||
return claim;
|
||||
}
|
||||
|
||||
public static Claim fromJson(JsonObject obj, UUID owner) {
|
||||
Claim claim = new Claim();
|
||||
claim.readJson(obj, owner);
|
||||
@ -79,6 +82,10 @@ public class Claim {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
public void setAdminClaim(){
|
||||
this.owner = null;
|
||||
}
|
||||
|
||||
public int getPlane() {
|
||||
return (this.maxX - this.minX) * (this.maxZ - this.minZ);
|
||||
}
|
||||
@ -111,7 +118,7 @@ public class Claim {
|
||||
return this.removed;
|
||||
}
|
||||
|
||||
public boolean canInteract(PlayerEntity player, EnumPermission perm, BlockPos pos) {
|
||||
public boolean canInteract(ServerPlayerEntity player, EnumPermission perm, BlockPos pos) {
|
||||
if (perm == EnumPermission.EXPLOSIONS || perm == EnumPermission.WITHER) {
|
||||
for (Claim claim : this.subClaims) {
|
||||
if (claim.insideClaim(pos)) {
|
||||
@ -127,13 +134,14 @@ public class Claim {
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if (player.hasPermissionLevel(2) && data.isAdminIgnoreClaim())
|
||||
return true;
|
||||
for (Claim claim : this.subClaims) {
|
||||
if (claim.insideClaim(pos)) {
|
||||
if (claim.canInteract(player, perm, pos))
|
||||
return true;
|
||||
break;
|
||||
if(perm!=EnumPermission.EDITCLAIM && perm != EnumPermission.EDITPERMS)
|
||||
for (Claim claim : this.subClaims) {
|
||||
if (claim.insideClaim(pos)) {
|
||||
if (claim.canInteract(player, perm, pos))
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.playersGroups.containsKey(player.getUuid())) {
|
||||
EnumMap<EnumPermission, Boolean> map = this.permissions.get(this.playersGroups.get(player.getUuid()));
|
||||
if (map != null && map.containsKey(perm))
|
||||
@ -147,7 +155,13 @@ public class Claim {
|
||||
}
|
||||
|
||||
public boolean tryCreateSubClaim(BlockPos pos1, BlockPos pos2) {
|
||||
return false;
|
||||
Claim sub = new Claim(pos1, pos2, this.owner);
|
||||
for(Claim other : this.subClaims)
|
||||
if (sub.intersects(other)) {
|
||||
return false;
|
||||
}
|
||||
this.subClaims.add(sub);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Claim getSubClaim(BlockPos pos) {
|
||||
@ -157,12 +171,19 @@ public class Claim {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Claim> getAllSubclaims(){
|
||||
return ImmutableList.copyOf(this.subClaims);
|
||||
}
|
||||
|
||||
public boolean setPlayerGroup(UUID player, String group, boolean force) {
|
||||
if(this.owner!=null && this.owner.equals(player))
|
||||
return false;
|
||||
if (group == null) {
|
||||
this.playersGroups.remove(player);
|
||||
this.setDirty();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!this.playersGroups.containsKey(player) || force) {
|
||||
this.playersGroups.put(player, group);
|
||||
this.setDirty();
|
||||
@ -201,8 +222,8 @@ public class Claim {
|
||||
* @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(PlayerEntity player, String group, EnumPermission perm, int mode) {
|
||||
if (player.getUuid().equals(this.owner) || this.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())) {
|
||||
public boolean editPerms(ServerPlayerEntity player, String group, EnumPermission perm, int mode) {
|
||||
if (this.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())) {
|
||||
if (mode > 1)
|
||||
mode = -1;
|
||||
boolean has = this.permissions.containsKey(group);
|
||||
@ -219,8 +240,8 @@ public class Claim {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removePermGroup(PlayerEntity player, String group) {
|
||||
if (player.getUuid().equals(this.owner) || this.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())) {
|
||||
public boolean removePermGroup(ServerPlayerEntity player, String group) {
|
||||
if (this.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())) {
|
||||
this.permissions.remove(group);
|
||||
List<UUID> toRemove = Lists.newArrayList();
|
||||
this.playersGroups.forEach((uuid, g) -> {
|
||||
@ -328,90 +349,61 @@ public class Claim {
|
||||
return obj;
|
||||
}
|
||||
|
||||
public CompoundTag save(CompoundTag tag) {
|
||||
tag.putIntArray("PosxXzZY", new int[]{this.minX, this.maxX, this.minZ, this.maxZ, this.minY});
|
||||
tag.putUuid("Owner", this.owner);
|
||||
tag.putUuid("ID", this.claimID);
|
||||
if (!this.globalPerm.isEmpty()) {
|
||||
ListTag list = new ListTag();
|
||||
this.globalPerm.forEach(p -> list.add(StringTag.of(p.toString())));
|
||||
tag.put("GlobalPerms", list);
|
||||
}
|
||||
if (!this.permissions.isEmpty()) {
|
||||
CompoundTag perms = new CompoundTag();
|
||||
this.permissions.forEach((s, pmap) -> {
|
||||
CompoundTag group = new CompoundTag();
|
||||
pmap.forEach((perm, bool) -> group.putBoolean(perm.toString(), bool));
|
||||
perms.put(s, group);
|
||||
});
|
||||
tag.put("PermGroup", perms);
|
||||
}
|
||||
if (!this.playersGroups.isEmpty()) {
|
||||
CompoundTag pl = new CompoundTag();
|
||||
this.playersGroups.forEach((uuid, s) -> pl.putString(uuid.toString(), s));
|
||||
tag.put("PlayerPerms", pl);
|
||||
}
|
||||
if (!this.subClaims.isEmpty()) {
|
||||
ListTag list = new ListTag();
|
||||
this.subClaims.forEach(p -> list.add(p.save(new CompoundTag())));
|
||||
tag.put("SubClaims", list);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void read(CompoundTag tag) {
|
||||
int[] pos = tag.getIntArray("PosxXzZY");
|
||||
this.minY = pos[0];
|
||||
this.maxX = pos[1];
|
||||
this.minZ = pos[2];
|
||||
this.maxZ = pos[3];
|
||||
this.minY = pos[4];
|
||||
this.owner = tag.getUuid("Owner");
|
||||
this.claimID = tag.getUuid("ID");
|
||||
this.globalPerm.clear();
|
||||
this.permissions.clear();
|
||||
this.subClaims.clear();
|
||||
if (tag.contains("GlobalPerms")) {
|
||||
tag.getList("GlobalPerms", 8).forEach(perm -> this.globalPerm.add(EnumPermission.valueOf(perm.asString())));
|
||||
}
|
||||
if (tag.contains("PermGroup")) {
|
||||
CompoundTag perms = tag.getCompound("PermGroup");
|
||||
perms.getKeys().forEach(key -> {
|
||||
EnumMap<EnumPermission, Boolean> map = new EnumMap<>(EnumPermission.class);
|
||||
CompoundTag group = perms.getCompound(key);
|
||||
group.getKeys().forEach(gkey -> map.put(EnumPermission.valueOf(gkey), group.getBoolean(gkey)));
|
||||
this.permissions.put(key, map);
|
||||
});
|
||||
}
|
||||
if (tag.contains("PlayerPerms")) {
|
||||
CompoundTag pl = tag.getCompound("PlayerPerms");
|
||||
pl.getKeys().forEach(key -> this.playersGroups.put(UUID.fromString(key), pl.getString(key)));
|
||||
}
|
||||
if (tag.contains("SubClaims")) {
|
||||
tag.getList("SubClaims", 10).forEach(sub -> this.subClaims.add(Claim.fromTag((CompoundTag) sub)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.claimID.hashCode();
|
||||
return this.claimID==null?Arrays.hashCode(this.getDimensions()):this.claimID.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj instanceof Claim)
|
||||
return this.claimID.equals(((Claim) obj).claimID);
|
||||
if (obj instanceof Claim) {
|
||||
Claim other = (Claim) obj;
|
||||
if (this.claimID==null && other.claimID==null)
|
||||
return Arrays.equals(this.getDimensions(), ((Claim) obj).getDimensions());
|
||||
if(this.claimID!=null)
|
||||
return this.claimID.equals(((Claim) obj).claimID);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Claim:[Owner:%s, from: x=%d; z=%d, to: x=%d, z=%d", this.owner.toString(), this.minX, this.minZ, this.maxX, this.maxZ);
|
||||
return String.format("Claim:[ID=%s, Owner=%s, from: x=%d; z=%d, to: x=%d, z=%d", this.claimID!=null?this.claimID.toString():"null", this.owner.toString(), this.minX, this.minZ, this.maxX, this.maxZ);
|
||||
}
|
||||
|
||||
public String formattedClaim() {
|
||||
return String.format("[x=%d,z=%d] to: [x=%d,z=%d]", this.minX, this.minZ, this.maxX, this.maxZ);
|
||||
return String.format("[x=%d,z=%d] - [x=%d,z=%d]", this.minX, this.minZ, this.maxX, this.maxZ);
|
||||
}
|
||||
|
||||
public List<Text> infoString(ServerPlayerEntity player){
|
||||
boolean perms = this.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos());
|
||||
List<Text> l = Lists.newArrayList();
|
||||
l.add(PermissionChecker.simpleColoredText("=============================================", Formatting.GREEN));
|
||||
GameProfile prof = this.owner!=null?player.getServer().getUserCache().getByUuid(this.owner):null;
|
||||
String ownerName = this.owner==null?"Admin":prof!=null?prof.getName():"<UNKNOWN>";
|
||||
l.add(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.claimBasicInfo, ownerName, this.minX, this.minZ, this.maxX, this.maxZ, this.subClaims.size()), Formatting.GOLD));
|
||||
if(perms) {
|
||||
l.add(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.claimInfoPerms, this.globalPerm), Formatting.RED));
|
||||
l.add(PermissionChecker.simpleColoredText(ConfigHandler.lang.claimGroupInfoHeader, Formatting.RED));
|
||||
Map<String, List<String>> nameToGroup = Maps.newHashMap();
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, EnumMap<EnumPermission, Boolean>> e : this.permissions.entrySet()) {
|
||||
l.add(PermissionChecker.simpleColoredText(String.format(" %s:", e.getKey()), Formatting.DARK_RED));
|
||||
l.add(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.claimGroupPerms, e.getValue()), Formatting.RED));
|
||||
l.add(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.claimGroupPlayers, nameToGroup.getOrDefault(e.getKey(), Lists.newArrayList())), Formatting.RED));
|
||||
}
|
||||
}
|
||||
l.add(PermissionChecker.simpleColoredText("=============================================", Formatting.GREEN));
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.flemmli97.flan.claim;
|
||||
|
||||
import com.flemmli97.flan.IClaimData;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.player.EnumDisplayType;
|
||||
import com.flemmli97.flan.player.PlayerClaimData;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
@ -16,6 +18,7 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
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.WorldSavePath;
|
||||
@ -39,8 +42,6 @@ import java.util.UUID;
|
||||
|
||||
public class ClaimStorage {
|
||||
|
||||
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
||||
|
||||
public final Long2ObjectArrayMap<List<Claim>> claims = new Long2ObjectArrayMap<>();
|
||||
public final Map<UUID, Claim> claimUUIDMap = Maps.newHashMap();
|
||||
public final Map<UUID, Set<Claim>> playerClaimMap = Maps.newHashMap();
|
||||
@ -69,7 +70,7 @@ public class ClaimStorage {
|
||||
return false;
|
||||
claim.setClaimID(this.generateUUID());
|
||||
this.addClaim(claim);
|
||||
data.addDisplayClaim(claim);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
return true;
|
||||
}
|
||||
player.sendMessage(Text.of("Error creating claim"), false);
|
||||
@ -91,13 +92,9 @@ public class ClaimStorage {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean deleteClaim(Claim claim) {
|
||||
System.out.println("claim " + claim);
|
||||
System.out.println("claimmap " + this.claims);
|
||||
|
||||
public boolean deleteClaim(Claim claim, MinecraftServer server) {
|
||||
claim.remove();
|
||||
int[] pos = getChunkPos(claim);
|
||||
System.out.println("" + Arrays.toString(pos));
|
||||
for (int x = pos[0]; x <= pos[1]; x++)
|
||||
for (int z = pos[2]; z <= pos[3]; z++) {
|
||||
ChunkPos chunkPos = new ChunkPos(x, z);
|
||||
@ -108,8 +105,10 @@ public class ClaimStorage {
|
||||
return val.isEmpty() ? null : val;
|
||||
});
|
||||
}
|
||||
System.out.println(this.claims);
|
||||
this.playerClaimMap.getOrDefault(claim.getOwner(), Sets.newHashSet()).remove(claim);
|
||||
ServerPlayerEntity owner = claim.getOwner()!=null?server.getPlayerManager().getPlayer(claim.getOwner()):null;
|
||||
if(owner!=null)
|
||||
PlayerClaimData.get(owner).usedClaimBlocks();
|
||||
return this.claimUUIDMap.remove(claim.getClaimID()) != null;
|
||||
}
|
||||
|
||||
@ -128,22 +127,19 @@ public class ClaimStorage {
|
||||
}
|
||||
|
||||
private void addClaim(Claim claim) {
|
||||
System.out.println("adding claim " + claim);
|
||||
int[] pos = getChunkPos(claim);
|
||||
System.out.println("" + Arrays.toString(pos));
|
||||
for (int x = pos[0]; x <= pos[1]; x++)
|
||||
for (int z = pos[2]; z <= pos[3]; z++) {
|
||||
ChunkPos chunkPos = new ChunkPos(x, z);
|
||||
this.claims.merge(chunkPos.toLong(), Lists.newArrayList(claim), (key, val) -> {
|
||||
val.add(claim);
|
||||
return val;
|
||||
this.claims.merge(chunkPos.toLong(), Lists.newArrayList(claim), (old, val) -> {
|
||||
old.add(claim);
|
||||
return old;
|
||||
});
|
||||
}
|
||||
System.out.println("claimmap " + this.claims);
|
||||
this.claimUUIDMap.put(claim.getClaimID(), claim);
|
||||
this.playerClaimMap.merge(claim.getOwner(), Sets.newHashSet(claim), (key, val) -> {
|
||||
val.add(claim);
|
||||
return val;
|
||||
this.playerClaimMap.merge(claim.getOwner(), Sets.newHashSet(claim), (old, val) -> {
|
||||
old.add(claim);
|
||||
return old;
|
||||
});
|
||||
}
|
||||
|
||||
@ -161,22 +157,6 @@ public class ClaimStorage {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public void fromTag(CompoundTag compoundTag) {
|
||||
ListTag list = compoundTag.getList("Claims", 10);
|
||||
list.forEach(tag -> {
|
||||
Claim claim = Claim.fromTag((CompoundTag) tag);
|
||||
this.addClaim(claim);
|
||||
});
|
||||
}
|
||||
|
||||
public CompoundTag toTag(CompoundTag compoundTag) {
|
||||
ListTag list = new ListTag();
|
||||
this.claims.forEach((l, cList) ->
|
||||
cList.forEach(claim -> list.add(claim.save(new CompoundTag()))));
|
||||
compoundTag.put("Claims", list);
|
||||
return compoundTag;
|
||||
}
|
||||
|
||||
public void read(MinecraftServer server, RegistryKey<World> reg) {
|
||||
File dir = new File(DimensionType.getSaveDirectory(reg, server.getSavePath(WorldSavePath.ROOT).toFile()), "/data/claims/");
|
||||
if (dir.exists()) {
|
||||
@ -186,7 +166,7 @@ public class ClaimStorage {
|
||||
continue;
|
||||
UUID uuid = UUID.fromString(file.getName().replace(".json", ""));
|
||||
FileReader reader = new FileReader(file);
|
||||
JsonArray arr = GSON.fromJson(reader, JsonArray.class);
|
||||
JsonArray arr = ConfigHandler.GSON.fromJson(reader, JsonArray.class);
|
||||
if (arr == null)
|
||||
continue;
|
||||
arr.forEach(el -> {
|
||||
@ -218,7 +198,7 @@ public class ClaimStorage {
|
||||
FileWriter writer = new FileWriter(file);
|
||||
JsonArray arr = new JsonArray();
|
||||
e.getValue().forEach(claim -> arr.add(claim.toJson(new JsonObject())));
|
||||
GSON.toJson(arr, writer);
|
||||
ConfigHandler.GSON.toJson(arr, writer);
|
||||
writer.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -6,11 +6,11 @@ import net.minecraft.item.Items;
|
||||
|
||||
public enum EnumPermission {
|
||||
|
||||
EDITPERMS(Items.COMMAND_BLOCK), //---
|
||||
EDITCLAIM(ConfigHandler.config.claimingItem), //---
|
||||
EDITPERMS(Items.COMMAND_BLOCK),
|
||||
EDITCLAIM(ConfigHandler.config.claimingItem),
|
||||
BREAK(Items.DIAMOND_PICKAXE),
|
||||
PLACE(Items.GRASS_BLOCK),
|
||||
OPENCONTAINER(Items.CHEST), //---
|
||||
OPENCONTAINER(Items.CHEST),
|
||||
ANVIL(Items.ANVIL),
|
||||
BED(Items.RED_BED),
|
||||
BEACON(Items.BEACON),
|
||||
|
@ -4,13 +4,13 @@ import net.minecraft.particle.DustParticleEffect;
|
||||
|
||||
public class ParticleIndicators {
|
||||
|
||||
public static final DustParticleEffect CLAIMCORNER = new DustParticleEffect(0.0F, 1.0F, 0.0F, 1.0F);
|
||||
public static final DustParticleEffect CLAIMMIDDLE = new DustParticleEffect(0.0F, 1.0F, 1.0F, 1.0F);
|
||||
public static final DustParticleEffect CLAIMCORNER = new DustParticleEffect(7/255f, 94/255f, 27/255f, 1);
|
||||
public static final DustParticleEffect CLAIMMIDDLE = new DustParticleEffect(9/255f, 186/255f, 51/255f, 1);
|
||||
|
||||
public static final DustParticleEffect SUBCLAIMCORNER = DustParticleEffect.RED;
|
||||
public static final DustParticleEffect SUBCLAIMMIDDLE = DustParticleEffect.RED;
|
||||
public static final DustParticleEffect SUBCLAIMCORNER = new DustParticleEffect(12/255f, 110/255f, 103/255f, 1);
|
||||
public static final DustParticleEffect SUBCLAIMMIDDLE = new DustParticleEffect(20/255f, 186/255f, 175/255f, 1);
|
||||
|
||||
public static final DustParticleEffect SETCORNER = new DustParticleEffect(0.0F, 0.9F, 1.0F, 1.0F);
|
||||
public static final DustParticleEffect SETCORNER = new DustParticleEffect(18/255f, 38/255f, 150/255f, 1);
|
||||
|
||||
public static final DustParticleEffect OVERLAPCLAIM = DustParticleEffect.RED;
|
||||
}
|
||||
|
@ -0,0 +1,63 @@
|
||||
package com.flemmli97.flan.claim;
|
||||
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class PermissionChecker {
|
||||
|
||||
public static boolean check(ServerPlayerEntity player, BlockPos pos, Claim claim, EnumPermission perm, Consumer<Optional<Boolean>> cons){
|
||||
if(claim==null) {
|
||||
cons.accept(Optional.empty());
|
||||
return false;
|
||||
}
|
||||
boolean hasPerm = claim.canInteract(player, perm, pos);
|
||||
cons.accept(Optional.of(hasPerm));
|
||||
return hasPerm;
|
||||
}
|
||||
|
||||
public static boolean check(ServerPlayerEntity player, BlockPos pos, EnumPermission perm, Consumer<Optional<Boolean>> cons){
|
||||
return check(player, pos, ClaimStorage.get(player.getServerWorld()).getClaimAt(pos), perm, cons);
|
||||
}
|
||||
|
||||
public static boolean check(ServerPlayerEntity player, EnumPermission perm, Consumer<Optional<Boolean>> cons){
|
||||
BlockPos pos = player.getBlockPos();
|
||||
return check(player, pos, ClaimStorage.get(player.getServerWorld()).getClaimAt(pos), perm, cons);
|
||||
}
|
||||
|
||||
public static Claim checkReturn(ServerPlayerEntity player, BlockPos pos, EnumPermission perm, Consumer<Optional<Boolean>> cons) {
|
||||
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(pos);
|
||||
return check(player, pos, claim, perm, cons)?claim:null;
|
||||
}
|
||||
|
||||
public static Claim checkReturn(ServerPlayerEntity player, EnumPermission perm, Consumer<Optional<Boolean>> cons) {
|
||||
BlockPos pos = player.getBlockPos();
|
||||
Claim claim = ClaimStorage.get(player.getServerWorld()).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 Consumer<Optional<Boolean>> genericNoPermMessage(ServerPlayerEntity player){
|
||||
return (b ->{
|
||||
if(!b.isPresent())
|
||||
PermissionChecker.noClaimMessage(player);
|
||||
else if(!b.get())
|
||||
player.sendMessage(simpleColoredText(ConfigHandler.lang.noPermission, Formatting.DARK_RED), false);
|
||||
});
|
||||
}
|
||||
|
||||
public static Text simpleColoredText(String text, Formatting... formatting){
|
||||
return new LiteralText(text).setStyle(formatting!=null?Style.EMPTY.withFormatting(formatting):Style.EMPTY);
|
||||
}
|
||||
}
|
@ -3,8 +3,10 @@ package com.flemmli97.flan.commands;
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.EnumPermission;
|
||||
import com.flemmli97.flan.claim.PermissionChecker;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.gui.ClaimMenuScreenHandler;
|
||||
import com.flemmli97.flan.player.EnumDisplayType;
|
||||
import com.flemmli97.flan.player.EnumEditMode;
|
||||
import com.flemmli97.flan.player.PlayerClaimData;
|
||||
import com.google.common.collect.Lists;
|
||||
@ -16,6 +18,10 @@ import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import net.minecraft.command.argument.GameProfileArgumentType;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.CommandSource;
|
||||
@ -23,194 +29,52 @@ import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class CommandClaim {
|
||||
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated) {
|
||||
|
||||
LiteralArgumentBuilder<ServerCommandSource> main = CommandManager.literal("claim");
|
||||
dispatcher.register(addToMainCommand(CommandManager.literal("claim"),
|
||||
CommandManager.literal("menu").executes(context -> {
|
||||
ServerCommandSource src = context.getSource();
|
||||
if (src.getPlayer() == null)
|
||||
return 0;
|
||||
ClaimStorage storage = ClaimStorage.get(context.getSource().getWorld());
|
||||
Claim claim = storage.getClaimAt(src.getPlayer().getBlockPos());
|
||||
if (claim == null || !claim.canInteract(src.getPlayer(), EnumPermission.EDITCLAIM, src.getPlayer().getBlockPos()))
|
||||
return 0;
|
||||
ClaimMenuScreenHandler.openClaimMenu(src.getPlayer(), claim);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}),
|
||||
CommandManager.literal("delete").executes(context -> {
|
||||
ServerCommandSource src = context.getSource();
|
||||
if (src.getPlayer() == null)
|
||||
return 0;
|
||||
ClaimStorage storage = ClaimStorage.get(src.getWorld());
|
||||
Claim claim = storage.getClaimAt(src.getPlayer().getBlockPos());
|
||||
if (claim == null || !claim.canInteract(src.getPlayer(), EnumPermission.EDITCLAIM, src.getPlayer().getBlockPos())) {
|
||||
src.getPlayer().sendMessage(Text.of(ConfigHandler.lang.deleteClaimError), false);
|
||||
return 0;
|
||||
}
|
||||
storage.deleteClaim(claim);
|
||||
src.getPlayer().sendMessage(Text.of(ConfigHandler.lang.deleteClaim), false);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}),
|
||||
CommandManager.literal("deleteAll").executes(context -> {
|
||||
ServerCommandSource src = context.getSource();
|
||||
if (src.getPlayer() == null)
|
||||
return 0;
|
||||
PlayerClaimData data = PlayerClaimData.get(src.getPlayer());
|
||||
if (data.confirmedDeleteAll()) {
|
||||
for (ServerWorld world : src.getWorld().getServer().getWorlds()) {
|
||||
ClaimStorage storage = ClaimStorage.get(world);
|
||||
storage.allClaimsFromPlayer(src.getPlayer().getUuid()).forEach(storage::deleteClaim);
|
||||
}
|
||||
src.getPlayer().sendMessage(Text.of(ConfigHandler.lang.deleteAllClaim), false);
|
||||
data.setConfirmDeleteAll(false);
|
||||
} else {
|
||||
data.setConfirmDeleteAll(true);
|
||||
src.getPlayer().sendMessage(Text.of(ConfigHandler.lang.deleteAllClaimConfirm), false);
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}),
|
||||
CommandManager.literal("list").executes(context -> {
|
||||
ServerCommandSource src = context.getSource();
|
||||
if (src.getPlayer() == null)
|
||||
return 0;
|
||||
Map<World, Collection<Claim>> claims = Maps.newHashMap();
|
||||
for (ServerWorld world : src.getWorld().getServer().getWorlds()) {
|
||||
ClaimStorage storage = ClaimStorage.get(world);
|
||||
claims.put(world, storage.allClaimsFromPlayer(src.getPlayer().getUuid()));
|
||||
}
|
||||
src.getPlayer().sendMessage(Text.of(ConfigHandler.lang.listClaims), false);
|
||||
for (Map.Entry<World, Collection<Claim>> entry : claims.entrySet())
|
||||
for (Claim claim : entry.getValue())
|
||||
src.getPlayer().sendMessage(Text.of(entry.getKey().getRegistryKey().getValue().toString() + " - " + claim.formattedClaim()), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}),
|
||||
CommandManager.literal("switchMode").executes(context -> {
|
||||
ServerCommandSource src = context.getSource();
|
||||
if (src.getPlayer() == null)
|
||||
return 0;
|
||||
PlayerClaimData data = PlayerClaimData.get(src.getPlayer());
|
||||
data.setEditMode(data.getEditMode() == EnumEditMode.DEFAULT ? EnumEditMode.SUBCLAIM : EnumEditMode.DEFAULT);
|
||||
src.getPlayer().sendMessage(Text.of(String.format(ConfigHandler.lang.editMode, data.getEditMode())), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}),
|
||||
CommandManager.literal("adminMode").requires(src -> src.hasPermissionLevel(2)).executes(context -> {
|
||||
ServerCommandSource src = context.getSource();
|
||||
if (src.getPlayer() == null)
|
||||
return 0;
|
||||
PlayerClaimData data = PlayerClaimData.get(src.getPlayer());
|
||||
data.setAdminIgnoreClaim(!data.isAdminIgnoreClaim());
|
||||
src.getPlayer().sendMessage(Text.of(String.format(ConfigHandler.lang.adminMode, data.isAdminIgnoreClaim())), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}),
|
||||
CommandManager.literal("adminRemove").requires(src -> src.hasPermissionLevel(2)).executes(context -> {
|
||||
ServerCommandSource src = context.getSource();
|
||||
ClaimStorage storage = ClaimStorage.get(src.getWorld());
|
||||
Claim claim = storage.getClaimAt(new BlockPos(src.getPosition()));
|
||||
if (claim == null) {
|
||||
src.sendFeedback(Text.of(ConfigHandler.lang.deleteClaimError), false);
|
||||
return 0;
|
||||
}
|
||||
storage.deleteClaim(claim);
|
||||
src.sendFeedback(Text.of(ConfigHandler.lang.deleteClaim), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}).then(CommandManager.literal("all").then(CommandManager.argument("player", GameProfileArgumentType.gameProfile())).executes(context -> {
|
||||
ServerCommandSource src = context.getSource();
|
||||
Iterator<GameProfile> it = GameProfileArgumentType.getProfileArgument(context, "player").iterator();
|
||||
List<String> players = Lists.newArrayList();
|
||||
while (it.hasNext()) {
|
||||
GameProfile prof = it.next();
|
||||
for (ServerWorld world : src.getWorld().getServer().getWorlds()) {
|
||||
ClaimStorage storage = ClaimStorage.get(world);
|
||||
storage.allClaimsFromPlayer(prof.getId()).forEach(storage::deleteClaim);
|
||||
}
|
||||
players.add(prof.getName());
|
||||
}
|
||||
src.sendFeedback(Text.of(String.format(ConfigHandler.lang.adminDeleteAll, players.toString())), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})),
|
||||
CommandManager.literal("giveClaimBlocks").requires(src -> src.hasPermissionLevel(2)).then(CommandManager.argument("player", GameProfileArgumentType.gameProfile())
|
||||
.then(CommandManager.argument("amount", IntegerArgumentType.integer()).executes(context -> {
|
||||
ServerCommandSource src = context.getSource();
|
||||
Iterator<GameProfile> it = GameProfileArgumentType.getProfileArgument(context, "player").iterator();
|
||||
List<String> players = Lists.newArrayList();
|
||||
int amount = IntegerArgumentType.getInteger(context, "amount");
|
||||
while (it.hasNext()) {
|
||||
GameProfile prof = it.next();
|
||||
ServerPlayerEntity player = src.getMinecraftServer().getPlayerManager().getPlayer(prof.getId());
|
||||
if (player != null) {
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
data.setAdditionalClaims(data.getAdditionalClaims() + amount);
|
||||
} else
|
||||
PlayerClaimData.editForOfflinePlayer(src.getMinecraftServer(), prof.getId(), amount);
|
||||
players.add(prof.getName());
|
||||
}
|
||||
src.sendFeedback(Text.of(String.format(ConfigHandler.lang.giveClaimBlocks, players.toString(), amount)), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}))),
|
||||
dispatcher.register(addToMainCommand(CommandManager.literal("flan"),
|
||||
CommandManager.literal("reload").executes(CommandClaim::reloadConfig),
|
||||
CommandManager.literal("menu").executes(CommandClaim::openMenu),
|
||||
CommandManager.literal("claimInfo").executes(CommandClaim::claimInfo),
|
||||
CommandManager.literal("delete").executes(CommandClaim::deleteClaim),
|
||||
CommandManager.literal("deleteAll").executes(CommandClaim::deleteAllClaim),
|
||||
CommandManager.literal("list").executes(CommandClaim::listClaims),
|
||||
CommandManager.literal("switchMode").executes(CommandClaim::switchClaimMode),
|
||||
CommandManager.literal("adminMode").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::switchAdminMode),
|
||||
CommandManager.literal("adminDelete").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::adminDelete)
|
||||
.then(CommandManager.literal("all").then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()))
|
||||
.executes(CommandClaim::adminDeleteAll)),
|
||||
CommandManager.literal("giveClaimBlocks").requires(src -> src.hasPermissionLevel(2)).then(CommandManager.argument("players", GameProfileArgumentType.gameProfile())
|
||||
.then(CommandManager.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::giveClaimBlocks))),
|
||||
addToMainCommand(CommandManager.literal("group"),
|
||||
CommandManager.literal("add").then(CommandManager.argument("name", StringArgumentType.word()).executes(context -> {
|
||||
ServerCommandSource src = context.getSource();
|
||||
String group = StringArgumentType.getString(context, "name");
|
||||
if (src.getPlayer() == null)
|
||||
return 0;
|
||||
ClaimStorage storage = ClaimStorage.get(src.getWorld());
|
||||
Claim claim = storage.getClaimAt(src.getPlayer().getBlockPos());
|
||||
if (claim == null || !claim.canInteract(src.getPlayer(), EnumPermission.EDITCLAIM, src.getPlayer().getBlockPos())) {
|
||||
src.getPlayer().sendMessage(Text.of(ConfigHandler.lang.deleteClaimError), false);
|
||||
return 0;
|
||||
}
|
||||
claim.editPerms(src.getPlayer(), group, EnumPermission.EDITCLAIM, -1);
|
||||
src.getPlayer().sendMessage(Text.of(ConfigHandler.lang.deleteClaim), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})),
|
||||
CommandManager.literal("remove").then(CommandManager.argument("name", StringArgumentType.word()).suggests((context, build) -> {
|
||||
List<String> list = Lists.newArrayList();
|
||||
ServerCommandSource src = context.getSource();
|
||||
String group = StringArgumentType.getString(context, "name");
|
||||
if (src.getPlayer() != null) {
|
||||
ClaimStorage storage = ClaimStorage.get(src.getWorld());
|
||||
Claim claim = storage.getClaimAt(src.getPlayer().getBlockPos());
|
||||
if (claim != null && claim.canInteract(src.getPlayer(), EnumPermission.EDITCLAIM, src.getPlayer().getBlockPos())) {
|
||||
list = claim.groups();
|
||||
}
|
||||
}
|
||||
return CommandSource.suggestMatching(list, build);
|
||||
}).executes(context -> {
|
||||
ServerCommandSource src = context.getSource();
|
||||
String group = StringArgumentType.getString(context, "name");
|
||||
if (src.getPlayer() == null)
|
||||
return 0;
|
||||
ClaimStorage storage = ClaimStorage.get(src.getWorld());
|
||||
Claim claim = storage.getClaimAt(src.getPlayer().getBlockPos());
|
||||
if (claim == null || !claim.canInteract(src.getPlayer(), EnumPermission.EDITCLAIM, src.getPlayer().getBlockPos())) {
|
||||
src.getPlayer().sendMessage(Text.of(ConfigHandler.lang.deleteClaimError), false);
|
||||
return 0;
|
||||
}
|
||||
claim.removePermGroup(src.getPlayer(), group);
|
||||
src.getPlayer().sendMessage(Text.of(ConfigHandler.lang.deleteClaim), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})),
|
||||
CommandManager.literal("player").then(CommandManager.argument("player", GameProfileArgumentType.gameProfile())).executes(context -> {
|
||||
ServerCommandSource src = context.getSource();
|
||||
GameProfileArgumentType.getProfileArgument(context, "player");
|
||||
if (src.getPlayer() == null)
|
||||
return 0;
|
||||
|
||||
//print
|
||||
return 0;
|
||||
})
|
||||
CommandManager.literal("add").then(CommandManager.argument("group", StringArgumentType.word()).executes(CommandClaim::addGroup)),
|
||||
CommandManager.literal("remove").then(CommandManager.argument("group", StringArgumentType.word())
|
||||
.suggests(CommandClaim::groupSuggestion).executes(CommandClaim::removeGroup)),
|
||||
addToMainCommand(CommandManager.literal("players"),
|
||||
CommandManager.literal("add").then(CommandManager.argument("group", StringArgumentType.word()).suggests(CommandClaim::groupSuggestion)
|
||||
.then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()).executes(CommandClaim::addPlayer)
|
||||
.then(CommandManager.literal("overwrite").executes(CommandClaim::forceAddPlayer)))),
|
||||
CommandManager.literal("remove").then(CommandManager.argument("group", StringArgumentType.word()).suggests(CommandClaim::groupSuggestion)
|
||||
.then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()).suggests((context, build) -> {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
List<String> list = Lists.newArrayList();
|
||||
ServerCommandSource src = context.getSource();
|
||||
ClaimStorage storage = ClaimStorage.get(src.getWorld());
|
||||
Claim claim = storage.getClaimAt(src.getPlayer().getBlockPos());
|
||||
if (claim != null && claim.canInteract(src.getPlayer(), EnumPermission.EDITCLAIM, src.getPlayer().getBlockPos())) {
|
||||
list = claim.playersFromGroup(player.getServer(), "");
|
||||
}
|
||||
return CommandSource.suggestMatching(list, build);
|
||||
}).executes(CommandClaim::removePlayer))))
|
||||
)));
|
||||
}
|
||||
|
||||
@ -221,4 +85,265 @@ public class CommandClaim {
|
||||
return main;
|
||||
}
|
||||
|
||||
private static int reloadConfig(CommandContext<ServerCommandSource> context){
|
||||
ConfigHandler.reloadConfigs();
|
||||
context.getSource().sendFeedback(Text.of(ConfigHandler.lang.configReload), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int openMenu(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
Claim claim = PermissionChecker.checkReturn(player, EnumPermission.EDITPERMS, PermissionChecker.genericNoPermMessage(player));
|
||||
if (claim == null)
|
||||
return 0;
|
||||
ClaimMenuScreenHandler.openClaimMenu(player, claim);
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int claimInfo(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(player.getBlockPos());
|
||||
if (claim == null)
|
||||
return 0;
|
||||
List<Text> info = claim.infoString(player);
|
||||
for(Text text : info)
|
||||
player.sendMessage(text, false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int deleteClaim(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
Claim claim = storage.getClaimAt(player.getBlockPos());
|
||||
boolean check = PermissionChecker.check(player, player.getBlockPos(), claim, EnumPermission.EDITCLAIM, b ->{
|
||||
if(!b.isPresent())
|
||||
PermissionChecker.noClaimMessage(player);
|
||||
else if(!b.get())
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(ConfigHandler.lang.deleteClaimError, Formatting.DARK_RED), false);
|
||||
else
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(ConfigHandler.lang.deleteClaim, Formatting.DARK_RED), false);
|
||||
});
|
||||
if (!check)
|
||||
return 0;
|
||||
storage.deleteClaim(claim, player.getServer());
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int deleteAllClaim(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if (data.confirmedDeleteAll()) {
|
||||
for (ServerWorld world : player.getServer().getWorlds()) {
|
||||
ClaimStorage storage = ClaimStorage.get(world);
|
||||
storage.allClaimsFromPlayer(player.getUuid()).forEach((claim)->storage.deleteClaim(claim, player.getServer()));
|
||||
}
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(ConfigHandler.lang.deleteAllClaim, Formatting.GOLD), false);
|
||||
data.setConfirmDeleteAll(false);
|
||||
} else {
|
||||
data.setConfirmDeleteAll(true);
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(ConfigHandler.lang.deleteAllClaimConfirm, Formatting.DARK_RED), false);
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int listClaims(CommandContext<ServerCommandSource> context) throws CommandSyntaxException{
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
Map<World, Collection<Claim>> claims = Maps.newHashMap();
|
||||
for (ServerWorld world : player.getServer().getWorlds()) {
|
||||
ClaimStorage storage = ClaimStorage.get(world);
|
||||
claims.put(world, storage.allClaimsFromPlayer(player.getUuid()));
|
||||
}
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
||||
data.getClaimBlocks(), data.getAdditionalClaims(), data.usedClaimBlocks()), Formatting.GOLD), false);
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(ConfigHandler.lang.listClaims, Formatting.GOLD), false);
|
||||
for (Map.Entry<World, Collection<Claim>> entry : claims.entrySet())
|
||||
for (Claim claim : entry.getValue())
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(
|
||||
entry.getKey().getRegistryKey().getValue().toString() + " # " + claim.formattedClaim(), Formatting.YELLOW), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int switchClaimMode(CommandContext<ServerCommandSource> context) throws CommandSyntaxException{
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
data.setEditMode(data.getEditMode() == EnumEditMode.DEFAULT ? EnumEditMode.SUBCLAIM : EnumEditMode.DEFAULT);
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.editMode, data.getEditMode()), Formatting.GOLD), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int switchAdminMode(CommandContext<ServerCommandSource> context) throws CommandSyntaxException{
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
data.setAdminIgnoreClaim(!data.isAdminIgnoreClaim());
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.adminMode, data.isAdminIgnoreClaim()), Formatting.GOLD), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int adminDelete(CommandContext<ServerCommandSource> context){
|
||||
ServerCommandSource src = context.getSource();
|
||||
ClaimStorage storage = ClaimStorage.get(src.getWorld());
|
||||
Claim claim = storage.getClaimAt(new BlockPos(src.getPosition()));
|
||||
if (claim == null) {
|
||||
src.sendFeedback(PermissionChecker.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
|
||||
return 0;
|
||||
}
|
||||
if(src.getEntity() instanceof ServerPlayerEntity){
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) src.getEntity();
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if(!data.confirmedDeleteAll()) {
|
||||
data.setConfirmDeleteAll(true);
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(ConfigHandler.lang.deleteAllClaimConfirm, Formatting.DARK_RED), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
storage.deleteClaim(claim, src.getMinecraftServer());
|
||||
src.sendFeedback(PermissionChecker.simpleColoredText(ConfigHandler.lang.deleteClaim, Formatting.RED), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int adminDeleteAll(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerCommandSource src = context.getSource();
|
||||
if(src.getEntity() instanceof ServerPlayerEntity){
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) src.getEntity();
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if(!data.confirmedDeleteAll()) {
|
||||
data.setConfirmDeleteAll(true);
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(ConfigHandler.lang.deleteAllClaimConfirm, Formatting.DARK_RED), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
List<String> players = Lists.newArrayList();
|
||||
for(GameProfile prof : GameProfileArgumentType.getProfileArgument(context, "players")) {
|
||||
for (ServerWorld world : src.getWorld().getServer().getWorlds()) {
|
||||
ClaimStorage storage = ClaimStorage.get(world);
|
||||
storage.allClaimsFromPlayer(prof.getId()).forEach((claim)->storage.deleteClaim(claim, src.getMinecraftServer()));
|
||||
}
|
||||
players.add(prof.getName());
|
||||
}
|
||||
src.sendFeedback(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.adminDeleteAll, players.toString()), Formatting.GOLD), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int setAdminClaim(CommandContext<ServerCommandSource> context){
|
||||
ServerCommandSource src = context.getSource();
|
||||
ClaimStorage storage = ClaimStorage.get(src.getWorld());
|
||||
Claim claim = storage.getClaimAt(new BlockPos(src.getPosition()));
|
||||
if (claim == null) {
|
||||
src.sendFeedback(PermissionChecker.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
|
||||
return 0;
|
||||
}
|
||||
claim.setAdminClaim();
|
||||
src.sendFeedback(PermissionChecker.simpleColoredText(ConfigHandler.lang.setAdminClaim, Formatting.GOLD), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int giveClaimBlocks(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerCommandSource src = context.getSource();
|
||||
List<String> players = Lists.newArrayList();
|
||||
int amount = IntegerArgumentType.getInteger(context, "amount");
|
||||
for(GameProfile prof : GameProfileArgumentType.getProfileArgument(context, "players")) {
|
||||
ServerPlayerEntity player = src.getMinecraftServer().getPlayerManager().getPlayer(prof.getId());
|
||||
if (player != null) {
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
data.setAdditionalClaims(data.getAdditionalClaims() + amount);
|
||||
} else
|
||||
PlayerClaimData.editForOfflinePlayer(src.getMinecraftServer(), prof.getId(), amount);
|
||||
players.add(prof.getName());
|
||||
}
|
||||
src.sendFeedback(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.giveClaimBlocks, players.toString(), amount), Formatting.GOLD), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static CompletableFuture<Suggestions> groupSuggestion(CommandContext<ServerCommandSource> context, SuggestionsBuilder build) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
List<String> list = Lists.newArrayList();
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
Claim claim = storage.getClaimAt(player.getBlockPos());
|
||||
if (claim != null && claim.canInteract(player, EnumPermission.EDITCLAIM, player.getBlockPos())) {
|
||||
list = claim.groups();
|
||||
}
|
||||
return CommandSource.suggestMatching(list, build);
|
||||
}
|
||||
|
||||
private static int addGroup(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
return modifyGroup(context, false);
|
||||
|
||||
}
|
||||
|
||||
private static int removeGroup(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
return modifyGroup(context, true);
|
||||
}
|
||||
|
||||
private static int modifyGroup(CommandContext<ServerCommandSource> context, boolean remove) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
String group = StringArgumentType.getString(context, "group");
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
Claim claim = storage.getClaimAt(player.getBlockPos());
|
||||
if (claim == null) {
|
||||
PermissionChecker.noClaimMessage(player);
|
||||
return 0;
|
||||
}
|
||||
if(remove) {
|
||||
if (claim.removePermGroup(player, group))
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.groupRemove, group), Formatting.GOLD), false);
|
||||
else {
|
||||
PermissionChecker.genericNoPermMessage(player);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(claim.groups().contains(group)){
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.groupExist, group), Formatting.RED), false);
|
||||
return 0;
|
||||
}
|
||||
else if(claim.editPerms(player, group, EnumPermission.EDITCLAIM, -1))
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.groupAdd, group), Formatting.GOLD), false);
|
||||
else {
|
||||
PermissionChecker.genericNoPermMessage(player);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int forceAddPlayer(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
String group = StringArgumentType.getString(context, "group");
|
||||
return modifyPlayer(context, group, true);
|
||||
}
|
||||
|
||||
private static int addPlayer(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
String group = StringArgumentType.getString(context, "group");
|
||||
return modifyPlayer(context, group, false);
|
||||
}
|
||||
|
||||
private static int removePlayer(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
return modifyPlayer(context, null, false);
|
||||
}
|
||||
|
||||
private static int modifyPlayer(CommandContext<ServerCommandSource> context, String group, boolean force) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
Claim claim = storage.getClaimAt(player.getBlockPos());
|
||||
if (claim == null) {
|
||||
PermissionChecker.noClaimMessage(player);
|
||||
return 0;
|
||||
}
|
||||
if(!claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())){
|
||||
PermissionChecker.genericNoPermMessage(player);
|
||||
return 0;
|
||||
}
|
||||
List<String> modified = Lists.newArrayList();
|
||||
for(GameProfile prof :GameProfileArgumentType.getProfileArgument(context, "players")){
|
||||
if(claim.setPlayerGroup(prof.getId(), group, force))
|
||||
modified.add(prof.getName());
|
||||
}
|
||||
if(!modified.isEmpty())
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.playerModify, group, modified), Formatting.GOLD), false);
|
||||
else
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.playerModifyNo, group, modified), Formatting.RED), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,16 @@
|
||||
package com.flemmli97.flan.config;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Config {
|
||||
|
||||
@ -15,7 +20,7 @@ public class Config {
|
||||
public int maxClaimBlocks = 5000;
|
||||
public int ticksForNextBlock = 1200;
|
||||
|
||||
public String[] blacklistedWorlds;
|
||||
public String[] blacklistedWorlds = new String[0];
|
||||
public boolean worldWhitelist;
|
||||
|
||||
public Item claimingItem = Items.GOLDEN_HOE;
|
||||
@ -25,6 +30,16 @@ public class Config {
|
||||
|
||||
public Config(MinecraftServer server) {
|
||||
this.configDir = server.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile();
|
||||
try {
|
||||
if(!this.configDir.exists())
|
||||
this.configDir.mkdirs();
|
||||
File file = new File(this.configDir, "flan_config.json");
|
||||
if(!file.exists())
|
||||
file.createNewFile();
|
||||
this.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -32,7 +47,23 @@ public class Config {
|
||||
|
||||
}
|
||||
|
||||
public void save() {
|
||||
|
||||
private void save(File file) {
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.addProperty("startingBlocks", this.startingBlocks);
|
||||
obj.addProperty("maxClaimBlocks", this.maxClaimBlocks);
|
||||
obj.addProperty("ticksForNextBlock", this.ticksForNextBlock);
|
||||
JsonArray arr = new JsonArray();
|
||||
obj.add("blacklistedWorlds", arr);
|
||||
obj.addProperty("worldWhitelist", this.worldWhitelist);
|
||||
obj.addProperty("claimingItem", Registry.ITEM.getId(this.claimingItem).toString());
|
||||
obj.addProperty("inspectionItem", Registry.ITEM.getId(this.inspectionItem).toString());
|
||||
obj.addProperty("claimDisplayTime", this.claimDisplayTime);
|
||||
try {
|
||||
FileWriter writer = new FileWriter(file);
|
||||
ConfigHandler.GSON.toJson(obj, writer);
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,24 @@
|
||||
package com.flemmli97.flan.config;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class ConfigHandler {
|
||||
|
||||
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
||||
|
||||
public static Config config;
|
||||
public static LangConfig lang;
|
||||
|
||||
public static void serverLoad(MinecraftServer server) {
|
||||
config = new Config(server);
|
||||
config.load();
|
||||
lang = new LangConfig(server);
|
||||
reloadConfigs();
|
||||
}
|
||||
|
||||
public static void reloadConfigs(){
|
||||
config.load();
|
||||
lang.load();
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,41 @@
|
||||
package com.flemmli97.flan.config;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LangConfig {
|
||||
|
||||
private final File configDir;
|
||||
|
||||
public String noClaim = "There is no claim here.";
|
||||
public String noPermission = "You don't have the required permissions to do that here!";
|
||||
public String noPermissionSimple = "Sorry you can't do that here!";
|
||||
public String configReload = "Configs reloaded";
|
||||
public String inspectBlockOwner = "This is %1$s's claim";
|
||||
public String inspectNoClaim = "Nobody owns this block";
|
||||
public String cantClaimHere = "Sorry you cant claim here";
|
||||
public String claimBlocksFormat = "Claim Blocks: %1$d + (Bonus) %2$d; Used: %3$d";
|
||||
public String listClaims = "Listing all claims:";
|
||||
public String groupAdd = "Added group %s";
|
||||
public String groupRemove = "Removed group %s";
|
||||
public String groupExist = "Group already exist";
|
||||
public String playerModify = "Modified permission group for following players to %1$s: %2$s";
|
||||
public String playerModifyNo = "Couldn't set permission group for the players. Probably cause they already belong to a group";
|
||||
|
||||
public String deleteClaim = "Claim deleted";
|
||||
public String deleteAllClaimConfirm = "Are you sure you want to delete all claims? Type it again to confirm";
|
||||
public String deleteAllClaim = "All claims deleted";
|
||||
public String deleteClaimError = "No claim for you to delete here";
|
||||
public String deleteClaimError = "You can't delete this claim here";
|
||||
public String adminDeleteAll = "Deleted all claims for following players: %s";
|
||||
|
||||
public String setAdminClaim = "Claim changed to an Adminclaim";
|
||||
public String giveClaimBlocks = "Gave following players %2$d claimblocks: %1$s";
|
||||
public String adminMode = "Adminmode set to: ";
|
||||
public String adminMode = "Adminmode (Ignore Claims) set to: %s";
|
||||
public String editMode = "Editing mode set to %s";
|
||||
|
||||
public String stringScreenReturn = "Click on paper to go back";
|
||||
@ -29,11 +43,39 @@ public class LangConfig {
|
||||
public String playerGroupAddFail = "Couldn't add that player to the group either cause the player " +
|
||||
"is already in a group or no player matching the name was found";
|
||||
|
||||
public String claimBasicInfo = "Owner: %1$s, from: [x=%2$d,z=%3$d] to [x=%4$d,z=%5$d]; Subclaim-amount: %6$d";
|
||||
public String claimInfoPerms = "Permissions: %s";
|
||||
public String claimGroupInfoHeader = "Groups: ";
|
||||
public String claimGroupPerms = " Permissions: %s";
|
||||
public String claimGroupPlayers = " Players: %s";
|
||||
|
||||
public LangConfig(MinecraftServer server) {
|
||||
this.configDir = server.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile();
|
||||
try {
|
||||
if(!this.configDir.exists())
|
||||
this.configDir.mkdirs();
|
||||
File file = new File(this.configDir, "flan_lang.json");
|
||||
if(!file.exists())
|
||||
file.createNewFile();
|
||||
this.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
|
||||
}
|
||||
|
||||
private void save(File file){
|
||||
JsonObject obj = new JsonObject();
|
||||
|
||||
try {
|
||||
FileWriter writer = new FileWriter(file);
|
||||
ConfigHandler.GSON.toJson(obj, writer);
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package com.flemmli97.flan.event;
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.EnumPermission;
|
||||
import com.flemmli97.flan.claim.ObjectToPermissionMap;
|
||||
import com.flemmli97.flan.claim.BlockToPermissionMap;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.LockableContainerBlockEntity;
|
||||
@ -31,16 +31,17 @@ public class BlockInteractEvents {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
if (claim != null) {
|
||||
if (!claim.canInteract(player, EnumPermission.BREAK, pos))
|
||||
if (!claim.canInteract((ServerPlayerEntity) player, EnumPermission.BREAK, pos))
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
//Right click block
|
||||
public static ActionResult useBlocks(PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) {
|
||||
public static ActionResult useBlocks(PlayerEntity p, World world, Hand hand, BlockHitResult hitResult) {
|
||||
if (world.isClient)
|
||||
return ActionResult.PASS;
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim claim = storage.getClaimAt(hitResult.getBlockPos());
|
||||
if (claim != null) {
|
||||
@ -53,7 +54,7 @@ public class BlockInteractEvents {
|
||||
if (blockEntity instanceof LockableContainerBlockEntity)
|
||||
return claim.canInteract(player, EnumPermission.OPENCONTAINER, hitResult.getBlockPos()) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
}
|
||||
EnumPermission perm = ObjectToPermissionMap.getFromBlock(state.getBlock());
|
||||
EnumPermission perm = BlockToPermissionMap.getFromBlock(state.getBlock());
|
||||
if (perm != null)
|
||||
return claim.canInteract(player, perm, hitResult.getBlockPos()) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
}
|
||||
@ -67,24 +68,24 @@ public class BlockInteractEvents {
|
||||
public static boolean blockCollisionEntity(BlockState state, World world, BlockPos pos, Entity entity) {
|
||||
if (entity.world.isClient)
|
||||
return false;
|
||||
if (entity instanceof PlayerEntity) {
|
||||
EnumPermission perm = ObjectToPermissionMap.getFromBlock(state.getBlock());
|
||||
if (entity instanceof ServerPlayerEntity) {
|
||||
EnumPermission perm = BlockToPermissionMap.getFromBlock(state.getBlock());
|
||||
if (perm != EnumPermission.PRESSUREPLATE && perm != EnumPermission.PORTAL)
|
||||
return false;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
if (claim != null)
|
||||
return !claim.canInteract((PlayerEntity) entity, perm, pos);
|
||||
return !claim.canInteract((ServerPlayerEntity) entity, perm, pos);
|
||||
} else if (entity instanceof ProjectileEntity) {
|
||||
EnumPermission perm = ObjectToPermissionMap.getFromBlock(state.getBlock());
|
||||
EnumPermission perm = BlockToPermissionMap.getFromBlock(state.getBlock());
|
||||
if (perm != EnumPermission.PRESSUREPLATE && perm != EnumPermission.BUTTONLEVER)
|
||||
return false;
|
||||
Entity owner = ((ProjectileEntity) entity).getOwner();
|
||||
if (owner instanceof PlayerEntity) {
|
||||
if (owner instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
if (claim != null)
|
||||
return !claim.canInteract((PlayerEntity) owner, perm, pos);
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, perm, pos);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -96,17 +97,17 @@ public class BlockInteractEvents {
|
||||
if (entity instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) entity.world);
|
||||
Claim claim = storage.getClaimAt(landedPosition);
|
||||
EnumPermission perm = ObjectToPermissionMap.getFromBlock(landedState.getBlock());
|
||||
EnumPermission perm = BlockToPermissionMap.getFromBlock(landedState.getBlock());
|
||||
if (perm == EnumPermission.TRAMPLE)
|
||||
return !claim.canInteract((PlayerEntity) entity, perm, landedPosition);
|
||||
return !claim.canInteract((ServerPlayerEntity) entity, perm, landedPosition);
|
||||
} else if (entity instanceof ProjectileEntity) {
|
||||
Entity owner = ((ProjectileEntity) entity).getOwner();
|
||||
if (owner instanceof PlayerEntity) {
|
||||
if (owner instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) entity.world);
|
||||
Claim claim = storage.getClaimAt(landedPosition);
|
||||
EnumPermission perm = ObjectToPermissionMap.getFromBlock(landedState.getBlock());
|
||||
EnumPermission perm = BlockToPermissionMap.getFromBlock(landedState.getBlock());
|
||||
if (perm == EnumPermission.TRAMPLE)
|
||||
return !claim.canInteract((PlayerEntity) owner, perm, landedPosition);
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, perm, landedPosition);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -119,20 +120,20 @@ public class BlockInteractEvents {
|
||||
if (entity instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get(serverWorld);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
return !claim.canInteract((PlayerEntity) entity, EnumPermission.TRAMPLE, pos);
|
||||
return !claim.canInteract((ServerPlayerEntity) entity, EnumPermission.TRAMPLE, pos);
|
||||
} else if (entity instanceof ProjectileEntity) {
|
||||
Entity owner = ((ProjectileEntity) entity).getOwner();
|
||||
if (owner instanceof PlayerEntity) {
|
||||
if (owner instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get(serverWorld);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
return !claim.canInteract((PlayerEntity) owner, EnumPermission.TRAMPLE, pos);
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, EnumPermission.TRAMPLE, pos);
|
||||
}
|
||||
} else if (entity instanceof ItemEntity) {
|
||||
Entity owner = serverWorld.getEntity(((ItemEntity) entity).getThrower());
|
||||
if (owner instanceof PlayerEntity) {
|
||||
if (owner instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get(serverWorld);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
return !claim.canInteract((PlayerEntity) owner, EnumPermission.TRAMPLE, pos);
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, EnumPermission.TRAMPLE, pos);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -3,7 +3,7 @@ package com.flemmli97.flan.event;
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.EnumPermission;
|
||||
import com.flemmli97.flan.claim.ObjectToPermissionMap;
|
||||
import com.flemmli97.flan.claim.BlockToPermissionMap;
|
||||
import com.flemmli97.flan.mixin.IPersistentProjectileVars;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
@ -20,6 +20,8 @@ import net.minecraft.entity.vehicle.AbstractMinecartEntity;
|
||||
import net.minecraft.entity.vehicle.BoatEntity;
|
||||
import net.minecraft.entity.vehicle.MinecartEntity;
|
||||
import net.minecraft.entity.vehicle.StorageMinecartEntity;
|
||||
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
|
||||
import net.minecraft.server.ServerTask;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
@ -46,14 +48,17 @@ public class EntityInteractEvents {
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
if (claim != null) {
|
||||
if (entity instanceof ArmorStandEntity) {
|
||||
if (!claim.canInteract(player, EnumPermission.ARMORSTAND, pos))
|
||||
if (!claim.canInteract((ServerPlayerEntity) player, EnumPermission.ARMORSTAND, pos))
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
public static ActionResult useEntity(PlayerEntity player, World world, Hand hand, Entity entity) {
|
||||
public static ActionResult useEntity(PlayerEntity p, World world, Hand hand, Entity entity) {
|
||||
if(p.world.isClient)
|
||||
return ActionResult.PASS;
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
BlockPos pos = entity.getBlockPos();
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
@ -80,13 +85,13 @@ public class EntityInteractEvents {
|
||||
if (proj.world.isClient)
|
||||
return false;
|
||||
Entity owner = proj.getOwner();
|
||||
if (owner instanceof PlayerEntity) {
|
||||
PlayerEntity player = (PlayerEntity) owner;
|
||||
if (owner instanceof ServerPlayerEntity) {
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) owner;
|
||||
if (res.getType() == HitResult.Type.BLOCK) {
|
||||
BlockHitResult blockRes = (BlockHitResult) res;
|
||||
BlockPos pos = blockRes.getBlockPos();
|
||||
BlockState state = proj.world.getBlockState(pos);
|
||||
EnumPermission perm = ObjectToPermissionMap.getFromBlock(state.getBlock());
|
||||
EnumPermission perm = BlockToPermissionMap.getFromBlock(state.getBlock());
|
||||
if (proj instanceof EnderPearlEntity)
|
||||
perm = EnumPermission.ENDERPEARL;
|
||||
if (perm != EnumPermission.ENDERPEARL && perm != EnumPermission.TARGETBLOCK && perm != EnumPermission.PROJECTILES)
|
||||
@ -96,21 +101,24 @@ public class EntityInteractEvents {
|
||||
if (claim == null)
|
||||
return false;
|
||||
boolean flag = !claim.canInteract(player, perm, pos);
|
||||
if (flag && 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));
|
||||
((IPersistentProjectileVars) pers).setInGround(true);
|
||||
pers.shake = 7;
|
||||
pers.setCritical(false);
|
||||
pers.setPierceLevel((byte) 0);
|
||||
pers.setSound(SoundEvents.ENTITY_ARROW_HIT);
|
||||
pers.setShotFromCrossbow(false);
|
||||
((IPersistentProjectileVars) pers).resetPiercingStatus();
|
||||
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));
|
||||
((IPersistentProjectileVars) pers).setInGround(true);
|
||||
pers.shake = 7;
|
||||
pers.setCritical(false);
|
||||
pers.setPierceLevel((byte) 0);
|
||||
pers.setSound(SoundEvents.ENTITY_ARROW_HIT);
|
||||
pers.setShotFromCrossbow(false);
|
||||
((IPersistentProjectileVars) pers).resetPiercingStatus();
|
||||
}
|
||||
//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)
|
||||
@ -119,12 +127,13 @@ public class EntityInteractEvents {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ActionResult attackSimple(PlayerEntity player, Entity entity) {
|
||||
if (player.world.isClient)
|
||||
public static ActionResult attackSimple(PlayerEntity p, Entity entity) {
|
||||
if (p.world.isClient)
|
||||
return ActionResult.PASS;
|
||||
if (entity instanceof Monster)
|
||||
return ActionResult.PASS;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) player.world);
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
BlockPos pos = entity.getBlockPos();
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
if (claim != null) {
|
||||
@ -143,7 +152,7 @@ public class EntityInteractEvents {
|
||||
BlockPos pos = player.getBlockPos();
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
if (claim != null)
|
||||
return !claim.canInteract(player, EnumPermission.XP, pos);
|
||||
return !claim.canInteract((ServerPlayerEntity) player, EnumPermission.XP, pos);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.EnumPermission;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.player.EnumDisplayType;
|
||||
import com.flemmli97.flan.player.EnumEditMode;
|
||||
import com.flemmli97.flan.player.PlayerClaimData;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
@ -11,6 +12,7 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BucketItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Hand;
|
||||
@ -22,9 +24,10 @@ import net.minecraft.world.World;
|
||||
|
||||
public class ItemInteractEvents {
|
||||
|
||||
public static TypedActionResult<ItemStack> useItem(PlayerEntity player, World world, Hand hand) {
|
||||
public static TypedActionResult<ItemStack> useItem(PlayerEntity p, World world, Hand hand) {
|
||||
if (world.isClient)
|
||||
return TypedActionResult.pass(player.getStackInHand(hand));
|
||||
return TypedActionResult.pass(p.getStackInHand(hand));
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ItemStack stack = player.getStackInHand(hand);
|
||||
if (stack.getItem() == ConfigHandler.config.claimingItem) {
|
||||
HitResult ray = player.rayTrace(64, 0, false);
|
||||
@ -57,7 +60,7 @@ public class ItemInteractEvents {
|
||||
data.setEditClaim(claim);
|
||||
}
|
||||
} else {
|
||||
data.addDisplayClaim(claim);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
player.sendMessage(Text.of(ConfigHandler.lang.cantClaimHere), false);
|
||||
}
|
||||
} else {
|
||||
@ -89,7 +92,7 @@ public class ItemInteractEvents {
|
||||
owner,
|
||||
blockRay.getBlockPos().getX(), blockRay.getBlockPos().getY(), blockRay.getBlockPos().getZ()));
|
||||
player.sendMessage(text, false);
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim);
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
} else
|
||||
player.sendMessage(Text.of(ConfigHandler.lang.inspectNoClaim), false);
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
|
||||
break;
|
||||
case 8:
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
storage.deleteClaim(this.claim);
|
||||
storage.deleteClaim(this.claim, player.getServer());
|
||||
player.closeHandledScreen();
|
||||
player.sendMessage(Text.of(ConfigHandler.lang.deleteClaim), false);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_ANVIL_PLACE, 1, 1f);
|
||||
|
@ -21,7 +21,7 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
|
||||
|
||||
private final Claim claim;
|
||||
private final String group;
|
||||
private final int page;
|
||||
private int page;
|
||||
|
||||
private PermissionScreenHandler(int syncId, PlayerInventory playerInventory, Claim claim, String group, int page) {
|
||||
super(syncId, playerInventory, 6, claim, group, page);
|
||||
@ -80,13 +80,48 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
|
||||
inv.setStack(i, ServerScreenHelper.emptyFiller());
|
||||
else {
|
||||
int row = i / 9 - 1;
|
||||
int id = (i % 9) + row * 7 - 1 + page * 54;
|
||||
int id = (i % 9) + row * 7 - 1 + page * 28;
|
||||
if (id < EnumPermission.values().length)
|
||||
inv.setStack(i, ServerScreenHelper.fromPermission((Claim) additionalData[0], EnumPermission.values()[id], String.valueOf(additionalData[1])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void flipPage(){
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
close.setCustomName(new LiteralText("Back").setStyle(Style.EMPTY.withFormatting(Formatting.DARK_RED)));
|
||||
this.slots.get(i).setStack(close);
|
||||
} else if (this.page == 1 && i == 47) {
|
||||
ItemStack stack = ItemStack.EMPTY;
|
||||
if(this.page == 1){
|
||||
stack =new ItemStack(Items.ARROW);
|
||||
stack.setCustomName(new LiteralText("Prev").setStyle(Style.EMPTY.withFormatting(Formatting.WHITE)));
|
||||
}
|
||||
this.slots.get(i).setStack(stack);
|
||||
} else if (this.page == 0 && i == 51) {
|
||||
ItemStack stack = ItemStack.EMPTY;
|
||||
if(this.page == 1) {
|
||||
stack = new ItemStack(Items.ARROW);
|
||||
stack.setCustomName(new LiteralText("Next").setStyle(Style.EMPTY.withFormatting(Formatting.WHITE)));
|
||||
}
|
||||
this.slots.get(i).setStack(stack);
|
||||
}
|
||||
else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
this.slots.get(i).setStack(ServerScreenHelper.emptyFiller());
|
||||
else {
|
||||
int row = i / 9 - 1;
|
||||
int id = (i % 9) + row * 7 - 1 + this.page * 28;
|
||||
if (id < EnumPermission.values().length)
|
||||
this.slots.get(i).setStack(ServerScreenHelper.fromPermission(this.claim, EnumPermission.values()[id], this.group));
|
||||
else
|
||||
this.slots.get(i).setStack(ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
this.sendContentUpdates();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleSlotClicked(ServerPlayerEntity player, int index, Slot slot, int clickType) {
|
||||
if (index == 0) {
|
||||
@ -101,13 +136,13 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
|
||||
return true;
|
||||
}
|
||||
if (index == 47) {
|
||||
player.closeHandledScreen();
|
||||
player.getServer().execute(() -> PermissionScreenHandler.openClaimMenu(player, this.claim, this.group, 0));
|
||||
this.page = 0;
|
||||
this.flipPage();
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
}
|
||||
if (index == 51) {
|
||||
player.closeHandledScreen();
|
||||
player.getServer().execute(() -> PermissionScreenHandler.openClaimMenu(player, this.claim, this.group, 1));
|
||||
this.page = 1;
|
||||
this.flipPage();
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
}
|
||||
ItemStack stack = slot.getStack();
|
||||
|
@ -6,6 +6,7 @@ import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
|
||||
import net.minecraft.particle.DustParticleEffect;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.World;
|
||||
@ -23,10 +24,25 @@ public class ClaimDisplay {
|
||||
|
||||
private int[] prevDims;
|
||||
|
||||
public ClaimDisplay(Claim claim) {
|
||||
private final DustParticleEffect corner, middle;
|
||||
public ClaimDisplay(Claim claim, EnumDisplayType type) {
|
||||
this.toDisplay = claim;
|
||||
this.displayTime = ConfigHandler.config.claimDisplayTime;
|
||||
this.prevDims = claim.getDimensions();
|
||||
switch (type){
|
||||
case SUB:
|
||||
this.corner = ParticleIndicators.SUBCLAIMCORNER;
|
||||
this.middle = ParticleIndicators.SUBCLAIMMIDDLE;
|
||||
break;
|
||||
case CONFLICT:
|
||||
this.corner = ParticleIndicators.OVERLAPCLAIM;
|
||||
this.middle = ParticleIndicators.OVERLAPCLAIM;
|
||||
break;
|
||||
default:
|
||||
this.corner = ParticleIndicators.CLAIMCORNER;
|
||||
this.middle = ParticleIndicators.CLAIMMIDDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean display(ServerPlayerEntity player) {
|
||||
@ -41,13 +57,13 @@ public class ClaimDisplay {
|
||||
this.getPosFrom(player.world, this.prevDims[1], this.prevDims[3], this.prevDims[4]),
|
||||
};
|
||||
}
|
||||
|
||||
for (int[] pos : this.poss) {
|
||||
player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleIndicators.CLAIMCORNER, true, pos[0] + 0.5, pos[1] + 0.25, pos[2] + 0.5, 0, 0.25f, 0, 0, 1));
|
||||
}
|
||||
for (int[] pos : this.middlePoss) {
|
||||
player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleIndicators.CLAIMMIDDLE, true, pos[0] + 0.5, pos[1] + 0.25, pos[2] + 0.5, 0, 0.25f, 0, 0, 1));
|
||||
player.networkHandler.sendPacket(new ParticleS2CPacket(this.corner, true, pos[0] + 0.5, pos[1] + 0.25, pos[2] + 0.5, 0, 0.25f, 0, 0, 1));
|
||||
}
|
||||
if(this.middlePoss!=null)
|
||||
for (int[] pos : this.middlePoss) {
|
||||
player.networkHandler.sendPacket(new ParticleS2CPacket(this.middle, true, pos[0] + 0.5, pos[1] + 0.25, pos[2] + 0.5, 0, 0.25f, 0, 0, 1));
|
||||
}
|
||||
this.prevDims = dims;
|
||||
return toDisplay.isRemoved() || displayTime < 0;
|
||||
}
|
||||
@ -63,8 +79,12 @@ public class ClaimDisplay {
|
||||
List<int[]> l = Lists.newArrayList();
|
||||
Set<Integer> xs = Sets.newHashSet();
|
||||
this.addEvenly(this.prevDims[0], this.prevDims[1], 10, xs);
|
||||
xs.add(this.prevDims[0]+1);
|
||||
xs.add(this.prevDims[1]-1);
|
||||
Set<Integer> zs = Sets.newHashSet();
|
||||
this.addEvenly(this.prevDims[2], this.prevDims[3], 10, zs);
|
||||
zs.add(this.prevDims[2]+1);
|
||||
zs.add(this.prevDims[3]-1);
|
||||
for (int x : xs) {
|
||||
l.add(this.getPosFrom(world, x, this.prevDims[2], this.prevDims[4]));
|
||||
l.add(this.getPosFrom(world, x, this.prevDims[3], this.prevDims[4]));
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.flemmli97.flan.player;
|
||||
|
||||
public enum EnumDisplayType {
|
||||
MAIN,
|
||||
SUB,
|
||||
CONFLICT
|
||||
}
|
@ -86,6 +86,11 @@ public class PlayerClaimData {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int usedClaimBlocks(){
|
||||
this.calculateUsedClaimBlocks();
|
||||
return this.usedClaimsBlocks;
|
||||
}
|
||||
|
||||
public Claim currentEdit() {
|
||||
return this.editingClaim;
|
||||
}
|
||||
@ -94,8 +99,11 @@ public class PlayerClaimData {
|
||||
this.editingClaim = claim;
|
||||
}
|
||||
|
||||
public void addDisplayClaim(Claim claim) {
|
||||
this.displayToAdd.add(new ClaimDisplay(claim));
|
||||
public void addDisplayClaim(Claim claim, EnumDisplayType type) {
|
||||
this.displayToAdd.add(new ClaimDisplay(claim, type));
|
||||
if(type==EnumDisplayType.MAIN)
|
||||
for(Claim sub : claim.getAllSubclaims())
|
||||
this.displayToAdd.add(new ClaimDisplay(sub, EnumDisplayType.SUB));
|
||||
}
|
||||
|
||||
public EnumEditMode getEditMode() {
|
||||
@ -173,7 +181,7 @@ public class PlayerClaimData {
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.addProperty("ClaimBlocks", this.claimBlocks);
|
||||
obj.addProperty("AdditionalBlocks", this.additionalClaimBlocks);
|
||||
ClaimStorage.GSON.toJson(obj, writer);
|
||||
ConfigHandler.GSON.toJson(obj, writer);
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
|
||||
@ -189,7 +197,7 @@ public class PlayerClaimData {
|
||||
if (!file.exists())
|
||||
return;
|
||||
FileReader reader = new FileReader(file);
|
||||
JsonObject obj = ClaimStorage.GSON.fromJson(reader, JsonObject.class);
|
||||
JsonObject obj = ConfigHandler.GSON.fromJson(reader, JsonObject.class);
|
||||
this.claimBlocks = obj.get("ClaimBlocks").getAsInt();
|
||||
this.additionalClaimBlocks = obj.get("AdditionalBlocks").getAsInt();
|
||||
reader.close();
|
||||
@ -207,14 +215,14 @@ public class PlayerClaimData {
|
||||
if (!file.exists())
|
||||
file.createNewFile();
|
||||
FileReader reader = new FileReader(file);
|
||||
JsonObject obj = ClaimStorage.GSON.fromJson(reader, JsonObject.class);
|
||||
JsonObject obj = ConfigHandler.GSON.fromJson(reader, JsonObject.class);
|
||||
reader.close();
|
||||
if (obj == null)
|
||||
obj = new JsonObject();
|
||||
int additionalBlocks = obj.get("AdditionalBlocks").getAsInt();
|
||||
obj.addProperty("AdditionalBlocks", additionalBlocks + additionalClaimBlocks);
|
||||
FileWriter writer = new FileWriter(file);
|
||||
ClaimStorage.GSON.toJson(obj, writer);
|
||||
ConfigHandler.GSON.toJson(obj, writer);
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
|
||||
@ -258,7 +266,7 @@ public class PlayerClaimData {
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.addProperty("ClaimBlocks", reader.readLine());
|
||||
obj.addProperty("AdditionalBlocks", reader.readLine());
|
||||
ClaimStorage.GSON.toJson(obj, writer);
|
||||
ConfigHandler.GSON.toJson(obj, writer);
|
||||
writer.close();
|
||||
}
|
||||
reader.close();
|
||||
|
@ -10,10 +10,10 @@
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "",
|
||||
"sources": "https://github.com/FabricMC/fabric-example-mod"
|
||||
"sources": "https://github.com/Flemmli97/Flan"
|
||||
},
|
||||
|
||||
"license": "CC0-1.0",
|
||||
"license": "ARR",
|
||||
"icon": "assets/modid/icon.png",
|
||||
|
||||
"environment": "*",
|
||||
|
Loading…
Reference in New Issue
Block a user