finishing claiming logic and stuff
This commit is contained in:
parent
4400dd1357
commit
12ca1ccc34
@ -9,8 +9,8 @@ org.gradle.jvmargs=-Xmx2G
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.0.0
|
||||
maven_group = com.flemmli97
|
||||
archives_base_name = thisismyland
|
||||
maven_group = com.flemmli97.flan
|
||||
archives_base_name = flan
|
||||
|
||||
# Dependencies
|
||||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||
|
@ -6,23 +6,18 @@ 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.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
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.server.world.ServerWorld;
|
||||
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;
|
||||
@ -35,36 +30,43 @@ public class Claim {
|
||||
private UUID owner;
|
||||
|
||||
private UUID claimID;
|
||||
private final EnumSet<EnumPermission> globalPerm = EnumSet.noneOf(EnumPermission.class);
|
||||
private final EnumMap<EnumPermission, Boolean> globalPerm = Maps.newEnumMap(EnumPermission.class);
|
||||
private final Map<String, EnumMap<EnumPermission, Boolean>> permissions = Maps.newHashMap();
|
||||
|
||||
private final Map<UUID, String> playersGroups = Maps.newHashMap();
|
||||
|
||||
private final List<Claim> subClaims = Lists.newArrayList();
|
||||
|
||||
private UUID parent;
|
||||
private Claim parentClaim;
|
||||
|
||||
/**
|
||||
* Flag for players tracking this claim
|
||||
*/
|
||||
private boolean removed;
|
||||
|
||||
private Claim() {
|
||||
private final ServerWorld world;
|
||||
|
||||
private Claim(ServerWorld world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public Claim(BlockPos pos1, BlockPos pos2, UUID creator) {
|
||||
this(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ(), Math.min(pos1.getY(), pos2.getY()), creator);
|
||||
public Claim(BlockPos pos1, BlockPos pos2, UUID creator, ServerWorld 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) {
|
||||
public Claim(int x1, int x2, int z1, int z2, int minY, UUID creator, ServerWorld world) {
|
||||
this.minX = Math.min(x1, x2);
|
||||
this.minZ = Math.min(z1, z2);
|
||||
this.maxX = Math.max(x1, x2);
|
||||
this.maxZ = Math.max(z1, z2);
|
||||
this.minY = Math.max(0, minY);
|
||||
this.owner = creator;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public static Claim fromJson(JsonObject obj, UUID owner) {
|
||||
Claim claim = new Claim();
|
||||
public static Claim fromJson(JsonObject obj, UUID owner, ServerWorld world) {
|
||||
Claim claim = new Claim(world);
|
||||
claim.readJson(obj, owner);
|
||||
return claim;
|
||||
}
|
||||
@ -82,6 +84,25 @@ public class Claim {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
public Claim parentClaim(){
|
||||
if(this.parent==null)
|
||||
return null;
|
||||
if(this.parentClaim==null){
|
||||
ClaimStorage storage = ClaimStorage.get(this.world);
|
||||
this.parentClaim = storage.claimUUIDMap.get(this.parent);
|
||||
}
|
||||
return this.parentClaim;
|
||||
}
|
||||
|
||||
public void copySizes(Claim claim){
|
||||
this.minX = claim.minX;
|
||||
this.maxX = claim.maxX;
|
||||
this.minZ = claim.minZ;
|
||||
this.maxZ = claim.maxZ;
|
||||
this.minY = claim.minY;
|
||||
this.removed = false;
|
||||
}
|
||||
|
||||
public void setAdminClaim(){
|
||||
this.owner = null;
|
||||
}
|
||||
@ -118,52 +139,97 @@ public class Claim {
|
||||
return this.removed;
|
||||
}
|
||||
|
||||
public boolean canInteract(ServerPlayerEntity player, EnumPermission perm, BlockPos pos) {
|
||||
public boolean canInteract(ServerPlayerEntity player, EnumPermission perm, BlockPos pos){
|
||||
return this.canInteract(player, perm, pos, false);
|
||||
}
|
||||
|
||||
public boolean canInteract(ServerPlayerEntity player, EnumPermission perm, BlockPos pos, boolean message) {
|
||||
if (perm == EnumPermission.EXPLOSIONS || perm == EnumPermission.WITHER) {
|
||||
for (Claim claim : this.subClaims) {
|
||||
if (claim.insideClaim(pos)) {
|
||||
if (claim.canInteract(player, perm, pos))
|
||||
return claim.canInteract(player, perm, pos, message);
|
||||
}
|
||||
}
|
||||
if(this.hasPerm(perm))
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return this.permEnabled(perm);
|
||||
if(message)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false);
|
||||
return false;
|
||||
}
|
||||
if (player.getUuid().equals(this.owner))
|
||||
return true;
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if (player.hasPermissionLevel(2) && data.isAdminIgnoreClaim())
|
||||
return true;
|
||||
if(perm!=EnumPermission.EDITCLAIM && perm != EnumPermission.EDITPERMS)
|
||||
for (Claim claim : this.subClaims) {
|
||||
if (claim.insideClaim(pos)) {
|
||||
if (claim.canInteract(player, perm, pos))
|
||||
if(perm!=EnumPermission.EDITCLAIM && perm != EnumPermission.EDITPERMS)
|
||||
return claim.canInteract(player, perm, pos, message);
|
||||
else if(claim.canInteract(player, perm, pos, message))
|
||||
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))
|
||||
return map.get(perm);
|
||||
if (map != null && map.containsKey(perm)) {
|
||||
if(map.get(perm))
|
||||
return true;
|
||||
if(message)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false);
|
||||
return false;
|
||||
}
|
||||
return this.permEnabled(perm);
|
||||
}
|
||||
if(this.hasPerm(perm))
|
||||
return true;
|
||||
if(message)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false);
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean permEnabled(EnumPermission perm) {
|
||||
return this.globalPerm.contains(perm);
|
||||
/**
|
||||
* @return -1 for default, 0 for false, 1 for true
|
||||
*/
|
||||
public int permEnabled(EnumPermission perm) {
|
||||
return !this.globalPerm.containsKey(perm)?-1:this.globalPerm.get(perm)?1:0;
|
||||
}
|
||||
|
||||
private boolean hasPerm(EnumPermission perm){
|
||||
if(this.parentClaim()==null)
|
||||
return this.permEnabled(perm) == 1;
|
||||
if(this.permEnabled(perm)==-1)
|
||||
return this.parentClaim().permEnabled(perm)==1;
|
||||
return this.permEnabled(perm) == 1;
|
||||
}
|
||||
|
||||
private UUID generateUUID() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
for (Claim claim : this.subClaims)
|
||||
if(claim.claimID.equals(uuid)) {
|
||||
return generateUUID();
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public boolean tryCreateSubClaim(BlockPos pos1, BlockPos pos2) {
|
||||
Claim sub = new Claim(pos1, pos2, this.owner);
|
||||
Claim sub = new Claim(pos1, new BlockPos(pos2.getX(), 0, pos2.getZ()), this.owner, this.world);
|
||||
sub.setClaimID(this.generateUUID());
|
||||
for(Claim other : this.subClaims)
|
||||
if (sub.intersects(other)) {
|
||||
return false;
|
||||
}
|
||||
sub.parent = this.claimID;
|
||||
sub.parentClaim = this;
|
||||
this.subClaims.add(sub);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addSubClaimGriefprevention(Claim claim){
|
||||
claim.setClaimID(this.generateUUID());
|
||||
claim.parent = this.claimID;
|
||||
claim.parentClaim = this;
|
||||
this.subClaims.add(claim);
|
||||
}
|
||||
|
||||
public Claim getSubClaim(BlockPos pos) {
|
||||
for (Claim claim : this.subClaims)
|
||||
if (claim.insideClaim(pos))
|
||||
@ -171,10 +237,25 @@ public class Claim {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean deleteSubClaim(Claim claim){
|
||||
return this.subClaims.remove(claim);
|
||||
}
|
||||
|
||||
public List<Claim> getAllSubclaims(){
|
||||
return ImmutableList.copyOf(this.subClaims);
|
||||
}
|
||||
|
||||
public boolean resizeSubclaim(Claim claim, BlockPos from, BlockPos to){
|
||||
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, claim.claimID, this.world);
|
||||
for(Claim other : this.subClaims)
|
||||
if (!claim.equals(other) && newClaim.intersects(other))
|
||||
return false;
|
||||
claim.copySizes(newClaim);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean setPlayerGroup(UUID player, String group, boolean force) {
|
||||
if(this.owner!=null && this.owner.equals(player))
|
||||
return false;
|
||||
@ -208,11 +289,13 @@ public class Claim {
|
||||
return names;
|
||||
}
|
||||
|
||||
public void editGlobalPerms(EnumPermission toggle) {
|
||||
if (this.globalPerm.contains(toggle))
|
||||
public void editGlobalPerms(EnumPermission toggle, int mode) {
|
||||
if (mode > 1)
|
||||
mode = -1;
|
||||
if (mode == -1)
|
||||
this.globalPerm.remove(toggle);
|
||||
else
|
||||
this.globalPerm.add(toggle);
|
||||
this.globalPerm.put(toggle, mode == 1);
|
||||
this.setDirty();
|
||||
}
|
||||
|
||||
@ -267,10 +350,6 @@ public class Claim {
|
||||
return l;
|
||||
}
|
||||
|
||||
public boolean addSubClaims(Claim claim) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setDirty() {
|
||||
this.dirty = true;
|
||||
}
|
||||
@ -291,8 +370,19 @@ public class Claim {
|
||||
this.globalPerm.clear();
|
||||
this.permissions.clear();
|
||||
this.subClaims.clear();
|
||||
if(obj.has("Parent"))
|
||||
this.parent = UUID.fromString(obj.get("Parent").getAsString());
|
||||
if (obj.has("GlobalPerms")) {
|
||||
obj.getAsJsonArray("GlobalPerms").forEach(perm -> this.globalPerm.add(EnumPermission.valueOf(perm.getAsString())));
|
||||
if(this.parent==null) {
|
||||
obj.getAsJsonArray("GlobalPerms").forEach(perm -> {
|
||||
this.globalPerm.put(EnumPermission.valueOf(perm.getAsString()), true);
|
||||
});
|
||||
}
|
||||
else{
|
||||
obj.getAsJsonObject("GlobalPerms").entrySet().forEach(entry->{
|
||||
this.globalPerm.put(EnumPermission.valueOf(entry.getKey()), entry.getValue().getAsBoolean());
|
||||
});
|
||||
}
|
||||
}
|
||||
if (obj.has("PermGroup")) {
|
||||
JsonObject perms = obj.getAsJsonObject("PermGroup");
|
||||
@ -308,7 +398,7 @@ public class Claim {
|
||||
pl.entrySet().forEach(key -> this.playersGroups.put(UUID.fromString(key.getKey()), key.getValue().getAsString()));
|
||||
}
|
||||
if (obj.has("SubClaims")) {
|
||||
obj.getAsJsonArray("SubClaims").forEach(sub -> this.subClaims.add(Claim.fromJson(sub.getAsJsonObject(), this.owner)));
|
||||
obj.getAsJsonArray("SubClaims").forEach(sub -> this.subClaims.add(Claim.fromJson(sub.getAsJsonObject(), this.owner, this.world)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -320,11 +410,24 @@ public class Claim {
|
||||
pos.add(this.maxZ);
|
||||
pos.add(this.minY);
|
||||
obj.add("PosxXzZY", pos);
|
||||
|
||||
obj.addProperty("ID", this.claimID.toString());
|
||||
if(this.parent!=null)
|
||||
obj.addProperty("Parent", this.parent.toString());
|
||||
if (!this.globalPerm.isEmpty()) {
|
||||
JsonArray gPerm = new JsonArray();
|
||||
this.globalPerm.forEach(p -> gPerm.add(p.toString()));
|
||||
JsonElement gPerm;
|
||||
if(this.parent==null) {
|
||||
gPerm = new JsonArray();
|
||||
this.globalPerm.forEach((perm, bool) -> {
|
||||
if (bool)
|
||||
((JsonArray) gPerm).add(perm.toString());
|
||||
});
|
||||
}
|
||||
else{
|
||||
gPerm = new JsonObject();
|
||||
this.globalPerm.forEach((perm, bool) -> {
|
||||
((JsonObject) gPerm).addProperty(perm.toString(), bool);
|
||||
});
|
||||
}
|
||||
obj.add("GlobalPerms", gPerm);
|
||||
}
|
||||
if (!this.permissions.isEmpty()) {
|
||||
@ -380,13 +483,13 @@ public class Claim {
|
||||
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));
|
||||
l.add(PermHelper.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));
|
||||
l.add(PermHelper.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));
|
||||
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimInfoPerms, this.globalPerm), Formatting.RED));
|
||||
l.add(PermHelper.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());
|
||||
@ -398,12 +501,12 @@ public class Claim {
|
||||
}
|
||||
}
|
||||
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(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(), Lists.newArrayList())), Formatting.RED));
|
||||
}
|
||||
}
|
||||
l.add(PermissionChecker.simpleColoredText("=============================================", Formatting.GREEN));
|
||||
l.add(PermHelper.simpleColoredText("=============================================", Formatting.GREEN));
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,23 @@
|
||||
package com.flemmli97.flan.claim;
|
||||
|
||||
import com.flemmli97.flan.IClaimData;
|
||||
import com.flemmli97.flan.config.Config;
|
||||
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.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ibm.icu.impl.Pair;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectArrayMap;
|
||||
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.Formatting;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
@ -33,7 +30,6 @@ import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -50,8 +46,8 @@ public class ClaimStorage {
|
||||
return (ClaimStorage) ((IClaimData) world).getClaimData();
|
||||
}
|
||||
|
||||
public ClaimStorage(MinecraftServer server, RegistryKey<World> key) {
|
||||
this.read(server, key);
|
||||
public ClaimStorage(MinecraftServer server, ServerWorld world) {
|
||||
this.read(server, world);
|
||||
}
|
||||
|
||||
public UUID generateUUID() {
|
||||
@ -61,38 +57,52 @@ public class ClaimStorage {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public boolean createClaim(BlockPos pos1, BlockPos pos2, PlayerEntity player) {
|
||||
Claim claim = new Claim(pos1.down(5), pos2.down(5), player.getUuid());
|
||||
boolean conflicts = conflicts(claim, null);
|
||||
if (!conflicts) {
|
||||
public boolean createClaim(BlockPos pos1, BlockPos pos2, ServerPlayerEntity player) {
|
||||
Claim claim = new Claim(pos1.down(ConfigHandler.config.defaultClaimDepth), pos2.down(ConfigHandler.config.defaultClaimDepth), player.getUuid(), player.getServerWorld());
|
||||
Set<Claim> conflicts = conflicts(claim, null);
|
||||
if (conflicts.isEmpty()) {
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if (!data.useClaimBlocks(claim.getPlane()))
|
||||
if(claim.getPlane()<ConfigHandler.config.minClaimsize){
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.minClaimSize, ConfigHandler.config.minClaimsize), Formatting.RED), false);
|
||||
return false;
|
||||
}
|
||||
if (!data.canUseClaimBlocks(claim.getPlane())) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.notEnoughBlocks, Formatting.RED), false);
|
||||
return false;
|
||||
}
|
||||
claim.setClaimID(this.generateUUID());
|
||||
this.addClaim(claim);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.claimCreateSuccess, Formatting.GOLD), false);
|
||||
return true;
|
||||
}
|
||||
player.sendMessage(Text.of("Error creating claim"), false);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean conflicts(Claim claim, Claim except) {
|
||||
private Set<Claim> conflicts(Claim claim, Claim except) {
|
||||
Set<Claim> conflicted = Sets.newHashSet();
|
||||
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(new ChunkPos(x, z).toLong());
|
||||
if (claims != null)
|
||||
for (Claim other : claims) {
|
||||
if (claim.intersects(other) && !claim.equals(except)) {
|
||||
return true;
|
||||
if (claim.intersects(other) && !other.equals(except)) {
|
||||
conflicted.add(claim);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return conflicted;
|
||||
}
|
||||
|
||||
public boolean deleteClaim(Claim claim, MinecraftServer server) {
|
||||
public boolean deleteClaim(Claim claim, boolean updateClaim, EnumEditMode mode, ServerWorld world) {
|
||||
if(mode==EnumEditMode.SUBCLAIM){
|
||||
if(claim.parentClaim()!=null)
|
||||
return claim.parentClaim().deleteSubClaim(claim);
|
||||
return false;
|
||||
}
|
||||
if(updateClaim)
|
||||
claim.remove();
|
||||
int[] pos = getChunkPos(claim);
|
||||
for (int x = pos[0]; x <= pos[1]; x++)
|
||||
@ -106,13 +116,30 @@ public class ClaimStorage {
|
||||
});
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
public boolean resizeClaim(Claim claim, BlockPos pos) {
|
||||
public boolean resizeClaim(Claim claim, BlockPos from, BlockPos to, ServerPlayerEntity player) {
|
||||
int[] dims = claim.getDimensions(); //BlockPos from, BlockPos to
|
||||
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());
|
||||
Set<Claim> conflicts = conflicts(newClaim, claim);
|
||||
if(!conflicts.isEmpty()) {
|
||||
conflicts.forEach(conf->PlayerClaimData.get(player).addDisplayClaim(conf, EnumDisplayType.CONFLICT));
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
|
||||
return false;
|
||||
}
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
int diff = newClaim.getPlane()-claim.getPlane();
|
||||
if(data.canUseClaimBlocks(diff)) {
|
||||
this.deleteClaim(claim, false, EnumEditMode.DEFAULT, player.getServerWorld());
|
||||
claim.copySizes(newClaim);
|
||||
this.addClaim(claim);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeSuccess, Formatting.GOLD), false);
|
||||
return true;
|
||||
}
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.notEnoughBlocks, Formatting.RED), false);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -157,8 +184,8 @@ public class ClaimStorage {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public void read(MinecraftServer server, RegistryKey<World> reg) {
|
||||
File dir = new File(DimensionType.getSaveDirectory(reg, server.getSavePath(WorldSavePath.ROOT).toFile()), "/data/claims/");
|
||||
public void read(MinecraftServer server, ServerWorld world) {
|
||||
File dir = new File(DimensionType.getSaveDirectory(world.getRegistryKey(), server.getSavePath(WorldSavePath.ROOT).toFile()), "/data/claims/");
|
||||
if (dir.exists()) {
|
||||
try {
|
||||
for (File file : dir.listFiles()) {
|
||||
@ -171,7 +198,7 @@ public class ClaimStorage {
|
||||
continue;
|
||||
arr.forEach(el -> {
|
||||
if (el.isJsonObject()) {
|
||||
this.addClaim(Claim.fromJson((JsonObject) el, uuid));
|
||||
this.addClaim(Claim.fromJson((JsonObject) el, uuid, world));
|
||||
}
|
||||
});
|
||||
reader.close();
|
||||
@ -190,13 +217,23 @@ public class ClaimStorage {
|
||||
for (Map.Entry<UUID, Set<Claim>> e : this.playerClaimMap.entrySet()) {
|
||||
|
||||
File file = new File(dir, e.getKey().toString() + ".json");
|
||||
boolean dirty = false;
|
||||
if (!file.exists()) {
|
||||
if (e.getValue().isEmpty())
|
||||
continue;
|
||||
file.createNewFile();
|
||||
dirty = true;
|
||||
}
|
||||
else {
|
||||
for(Claim claim : e.getValue())
|
||||
if(claim.isDirty()) {
|
||||
dirty = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
FileWriter writer = new FileWriter(file);
|
||||
JsonArray arr = new JsonArray();
|
||||
if(dirty)
|
||||
e.getValue().forEach(claim -> arr.add(claim.toJson(new JsonObject())));
|
||||
ConfigHandler.GSON.toJson(arr, writer);
|
||||
writer.close();
|
||||
@ -208,7 +245,7 @@ public class ClaimStorage {
|
||||
|
||||
public static void readGriefPreventionData(MinecraftServer server) {
|
||||
Yaml yml = new Yaml();
|
||||
File griefPrevention = server.getSavePath(WorldSavePath.ROOT).resolve("GriefPreventionData/ClaimData").toFile();
|
||||
File griefPrevention = server.getSavePath(WorldSavePath.ROOT).resolve("plugins/GriefPreventionData/ClaimData").toFile();
|
||||
if (!griefPrevention.exists())
|
||||
return;
|
||||
Map<File, List<File>> subClaimMap = Maps.newHashMap();
|
||||
@ -239,34 +276,32 @@ public class ClaimStorage {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (File parent : intFileMap.values()) {
|
||||
Pair<String, Claim> parentClaim = parseFromYaml(parent, yml);
|
||||
Pair<ServerWorld, Claim> parentClaim = parseFromYaml(parent, yml, server);
|
||||
List<File> childs = subClaimMap.get(parent);
|
||||
if (childs != null && !childs.isEmpty()) {
|
||||
for (File childF : childs)
|
||||
parentClaim.second.addSubClaims(parseFromYaml(childF, yml).second);
|
||||
parentClaim.second.addSubClaimGriefprevention(parseFromYaml(childF, yml, server).second);
|
||||
}
|
||||
ClaimStorage.get(server.getWorld(worldRegFromString(parentClaim.first))).addClaim(parentClaim.second);
|
||||
ClaimStorage.get(parentClaim.first).addClaim(parentClaim.second);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static Pair<String, Claim> parseFromYaml(File file, Yaml yml) throws IOException {
|
||||
private static Pair<ServerWorld, Claim> parseFromYaml(File file, Yaml yml, MinecraftServer server) throws IOException {
|
||||
FileReader reader = new FileReader(file);
|
||||
Map<String, Object> values = yml.load(reader);
|
||||
reader.close();
|
||||
UUID owner = UUID.fromString(values.get("Owner").toString());
|
||||
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]));
|
||||
Claim claim = new Claim(Integer.parseInt(lesserCorner[1]), Integer.parseInt(greaterCorner[1]),
|
||||
Integer.parseInt(lesserCorner[3]), Integer.parseInt(greaterCorner[3]),
|
||||
Integer.parseInt(lesserCorner[2]), owner);
|
||||
|
||||
|
||||
return Pair.of(lesserCorner[0], claim);
|
||||
Integer.parseInt(lesserCorner[2]), owner, world);
|
||||
return Pair.of(world, claim);
|
||||
}
|
||||
|
||||
public static RegistryKey<World> worldRegFromString(String spigot) {
|
||||
|
@ -10,6 +10,9 @@ public class ParticleIndicators {
|
||||
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 EDITCLAIMCORNER = new DustParticleEffect(12/255f, 110/255f, 103/255f, 1);
|
||||
public static final DustParticleEffect EDITCLAIMMIDDLE = new DustParticleEffect(20/255f, 186/255f, 175/255f, 1);
|
||||
|
||||
public static final DustParticleEffect SETCORNER = new DustParticleEffect(18/255f, 38/255f, 150/255f, 1);
|
||||
|
||||
public static final DustParticleEffect OVERLAPCLAIM = DustParticleEffect.RED;
|
||||
|
@ -1,63 +0,0 @@
|
||||
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,7 +3,7 @@ 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.claim.PermHelper;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.gui.ClaimMenuScreenHandler;
|
||||
import com.flemmli97.flan.player.EnumDisplayType;
|
||||
@ -47,9 +47,13 @@ public class CommandClaim {
|
||||
CommandManager.literal("claimInfo").executes(CommandClaim::claimInfo),
|
||||
CommandManager.literal("delete").executes(CommandClaim::deleteClaim),
|
||||
CommandManager.literal("deleteAll").executes(CommandClaim::deleteAllClaim),
|
||||
CommandManager.literal("deleteSubClaim").executes(CommandClaim::deleteSubClaim),
|
||||
CommandManager.literal("deleteAllSubClaims").executes(CommandClaim::deleteAllSubClaim),
|
||||
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("readGriefPrevention").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::readGriefPreventionData),
|
||||
CommandManager.literal("setAdminClaim").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::setAdminClaim),
|
||||
CommandManager.literal("adminDelete").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::adminDelete)
|
||||
.then(CommandManager.literal("all").then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()))
|
||||
.executes(CommandClaim::adminDeleteAll)),
|
||||
@ -93,22 +97,45 @@ public class CommandClaim {
|
||||
|
||||
private static int openMenu(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
Claim claim = PermissionChecker.checkReturn(player, EnumPermission.EDITPERMS, PermissionChecker.genericNoPermMessage(player));
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if(data.getEditMode() == EnumEditMode.DEFAULT) {
|
||||
Claim claim = PermHelper.checkReturn(player, EnumPermission.EDITPERMS, PermHelper.genericNoPermMessage(player));
|
||||
if (claim == null)
|
||||
return 0;
|
||||
ClaimMenuScreenHandler.openClaimMenu(player, claim);
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
}
|
||||
else{
|
||||
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(player.getBlockPos());
|
||||
Claim sub = claim.getSubClaim(player.getBlockPos());
|
||||
if(sub!=null && (claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos()) ||sub.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())))
|
||||
ClaimMenuScreenHandler.openClaimMenu(player, sub);
|
||||
else if(claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos()))
|
||||
ClaimMenuScreenHandler.openClaimMenu(player, claim);
|
||||
else
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermission, Formatting.DARK_RED), false);
|
||||
}
|
||||
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());
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if (claim == null)
|
||||
return 0;
|
||||
if(data.getEditMode() == EnumEditMode.SUBCLAIM){
|
||||
Claim sub = claim.getSubClaim(player.getBlockPos());
|
||||
if(sub!=null){
|
||||
List<Text> info = sub.infoString(player);
|
||||
player.sendMessage(PermHelper.simpleColoredText("==SubclaimInfo==", Formatting.AQUA), false);
|
||||
for (Text text : info)
|
||||
player.sendMessage(text, false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
List<Text> info = claim.infoString(player);
|
||||
for(Text text : info)
|
||||
for (Text text : info)
|
||||
player.sendMessage(text, false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
@ -117,17 +144,17 @@ public class CommandClaim {
|
||||
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 ->{
|
||||
boolean check = PermHelper.check(player, player.getBlockPos(), claim, EnumPermission.EDITCLAIM, b ->{
|
||||
if(!b.isPresent())
|
||||
PermissionChecker.noClaimMessage(player);
|
||||
PermHelper.noClaimMessage(player);
|
||||
else if(!b.get())
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(ConfigHandler.lang.deleteClaimError, Formatting.DARK_RED), false);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaimError, Formatting.DARK_RED), false);
|
||||
else
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(ConfigHandler.lang.deleteClaim, Formatting.DARK_RED), false);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaim, Formatting.DARK_RED), false);
|
||||
});
|
||||
if (!check)
|
||||
return 0;
|
||||
storage.deleteClaim(claim, player.getServer());
|
||||
storage.deleteClaim(claim, true, PlayerClaimData.get(player).getEditMode(), player.getServerWorld());
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@ -137,17 +164,55 @@ public class CommandClaim {
|
||||
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()));
|
||||
storage.allClaimsFromPlayer(player.getUuid()).forEach((claim)->storage.deleteClaim(claim, true, PlayerClaimData.get(player).getEditMode(), player.getServerWorld()));
|
||||
}
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(ConfigHandler.lang.deleteAllClaim, Formatting.GOLD), false);
|
||||
player.sendMessage(PermHelper.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);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteAllClaimConfirm, Formatting.DARK_RED), false);
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int deleteSubClaim(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
Claim claim = storage.getClaimAt(player.getBlockPos());
|
||||
if(claim==null) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
|
||||
return 0;
|
||||
}
|
||||
Claim sub = claim.getSubClaim(player.getBlockPos());
|
||||
if(sub==null) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
|
||||
return 0;
|
||||
}
|
||||
boolean check = PermHelper.check(player, player.getBlockPos(), sub, EnumPermission.EDITCLAIM, b ->{
|
||||
if(!b.isPresent())
|
||||
PermHelper.noClaimMessage(player);
|
||||
else if(!b.get())
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaimError, Formatting.DARK_RED), false);
|
||||
else
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteSubClaim, Formatting.DARK_RED), false);
|
||||
});
|
||||
if (!check)
|
||||
return 0;
|
||||
claim.deleteSubClaim(sub);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int deleteAllSubClaim(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
Claim claim = PermHelper.checkReturn(player, EnumPermission.EDITCLAIM, PermHelper.genericNoPermMessage(player));
|
||||
if(claim==null)
|
||||
return 0;
|
||||
List<Claim> subs = claim.getAllSubclaims();
|
||||
subs.forEach(claim::deleteSubClaim);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteSubClaimAll, 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();
|
||||
@ -156,12 +221,12 @@ public class CommandClaim {
|
||||
claims.put(world, storage.allClaimsFromPlayer(player.getUuid()));
|
||||
}
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
||||
player.sendMessage(PermHelper.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);
|
||||
player.sendMessage(PermHelper.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(
|
||||
player.sendMessage(PermHelper.simpleColoredText(
|
||||
entry.getKey().getRegistryKey().getValue().toString() + " # " + claim.formattedClaim(), Formatting.YELLOW), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
@ -170,7 +235,7 @@ public class CommandClaim {
|
||||
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);
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.editMode, data.getEditMode()), Formatting.GOLD), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@ -178,7 +243,7 @@ public class CommandClaim {
|
||||
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);
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.adminMode, data.isAdminIgnoreClaim()), Formatting.GOLD), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@ -187,7 +252,7 @@ public class CommandClaim {
|
||||
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);
|
||||
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
|
||||
return 0;
|
||||
}
|
||||
if(src.getEntity() instanceof ServerPlayerEntity){
|
||||
@ -195,12 +260,12 @@ public class CommandClaim {
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if(!data.confirmedDeleteAll()) {
|
||||
data.setConfirmDeleteAll(true);
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(ConfigHandler.lang.deleteAllClaimConfirm, Formatting.DARK_RED), false);
|
||||
player.sendMessage(PermHelper.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);
|
||||
storage.deleteClaim(claim, true, EnumEditMode.DEFAULT, src.getWorld());
|
||||
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaim, Formatting.RED), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@ -211,7 +276,7 @@ public class CommandClaim {
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if(!data.confirmedDeleteAll()) {
|
||||
data.setConfirmDeleteAll(true);
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(ConfigHandler.lang.deleteAllClaimConfirm, Formatting.DARK_RED), false);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteAllClaimConfirm, Formatting.DARK_RED), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
@ -219,11 +284,11 @@ public class CommandClaim {
|
||||
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()));
|
||||
storage.allClaimsFromPlayer(prof.getId()).forEach((claim)->storage.deleteClaim(claim, true, EnumEditMode.DEFAULT, world));
|
||||
}
|
||||
players.add(prof.getName());
|
||||
}
|
||||
src.sendFeedback(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.adminDeleteAll, players.toString()), Formatting.GOLD), true);
|
||||
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.adminDeleteAll, players.toString()), Formatting.GOLD), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@ -232,11 +297,20 @@ public class CommandClaim {
|
||||
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);
|
||||
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
|
||||
return 0;
|
||||
}
|
||||
claim.setAdminClaim();
|
||||
src.sendFeedback(PermissionChecker.simpleColoredText(ConfigHandler.lang.setAdminClaim, Formatting.GOLD), true);
|
||||
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.setAdminClaim, Formatting.GOLD), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int readGriefPreventionData(CommandContext<ServerCommandSource> context){
|
||||
ServerCommandSource src = context.getSource();
|
||||
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.readGriefpreventionData, Formatting.GOLD), true);
|
||||
ClaimStorage.readGriefPreventionData(src.getMinecraftServer());
|
||||
PlayerClaimData.readGriefPreventionPlayerData(src.getMinecraftServer());
|
||||
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.readGriefpreventionDataSuccess, Formatting.GOLD), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@ -253,7 +327,7 @@ public class CommandClaim {
|
||||
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);
|
||||
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.giveClaimBlocks, players.toString(), amount), Formatting.GOLD), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@ -283,26 +357,26 @@ public class CommandClaim {
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
Claim claim = storage.getClaimAt(player.getBlockPos());
|
||||
if (claim == null) {
|
||||
PermissionChecker.noClaimMessage(player);
|
||||
PermHelper.noClaimMessage(player);
|
||||
return 0;
|
||||
}
|
||||
if(remove) {
|
||||
if (claim.removePermGroup(player, group))
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.groupRemove, group), Formatting.GOLD), false);
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.groupRemove, group), Formatting.GOLD), false);
|
||||
else {
|
||||
PermissionChecker.genericNoPermMessage(player);
|
||||
PermHelper.genericNoPermMessage(player);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(claim.groups().contains(group)){
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.groupExist, group), Formatting.RED), false);
|
||||
player.sendMessage(PermHelper.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);
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.groupAdd, group), Formatting.GOLD), false);
|
||||
else {
|
||||
PermissionChecker.genericNoPermMessage(player);
|
||||
PermHelper.genericNoPermMessage(player);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -328,11 +402,11 @@ public class CommandClaim {
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
Claim claim = storage.getClaimAt(player.getBlockPos());
|
||||
if (claim == null) {
|
||||
PermissionChecker.noClaimMessage(player);
|
||||
PermHelper.noClaimMessage(player);
|
||||
return 0;
|
||||
}
|
||||
if(!claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())){
|
||||
PermissionChecker.genericNoPermMessage(player);
|
||||
PermHelper.genericNoPermMessage(player);
|
||||
return 0;
|
||||
}
|
||||
List<String> modified = Lists.newArrayList();
|
||||
@ -341,9 +415,9 @@ public class CommandClaim {
|
||||
modified.add(prof.getName());
|
||||
}
|
||||
if(!modified.isEmpty())
|
||||
player.sendMessage(PermissionChecker.simpleColoredText(String.format(ConfigHandler.lang.playerModify, group, modified), Formatting.GOLD), false);
|
||||
player.sendMessage(PermHelper.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);
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.playerModifyNo, group, modified), Formatting.RED), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,10 @@ public class Config {
|
||||
public int startingBlocks = 500;
|
||||
public int maxClaimBlocks = 5000;
|
||||
public int ticksForNextBlock = 1200;
|
||||
public int minClaimsize = 100;
|
||||
public int defaultClaimDepth = 255;
|
||||
|
||||
public String[] blacklistedWorlds = new String[0];
|
||||
public String[] blacklistedWorlds = new String[] {"minecraft:the_nether"};
|
||||
public boolean worldWhitelist;
|
||||
|
||||
public Item claimingItem = Items.GOLDEN_HOE;
|
||||
|
@ -27,19 +27,30 @@ public class LangConfig {
|
||||
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 resizeClaim = "Resizing claim";
|
||||
public String resizeSuccess = "Resized Claims";
|
||||
public String claimCreateSuccess = "Created a new claim";
|
||||
public String subClaimCreateSuccess = "Created a new subclaim";
|
||||
|
||||
public String minClaimSize = "This is too small. Minimum claimsize is %d";
|
||||
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 = "You can't delete this claim here";
|
||||
public String deleteSubClaim = "Subclaim deleted";
|
||||
public String deleteSubClaimAll = "All Subclaims from this claim deleted";
|
||||
|
||||
public String adminDeleteAll = "Deleted all claims for following players: %s";
|
||||
public String setAdminClaim = "Claim changed to an Adminclaim";
|
||||
public String readGriefpreventionData = "Reading data from GriefPrevention";
|
||||
public String readGriefpreventionDataSuccess = "Successfully read data";
|
||||
public String giveClaimBlocks = "Gave following players %2$d claimblocks: %1$s";
|
||||
public String adminMode = "Adminmode (Ignore Claims) set to: %s";
|
||||
public String editMode = "Editing mode set to %s";
|
||||
|
||||
public String notEnoughBlocks = "Not enough claim blocks";
|
||||
public String conflictOther = "Claim would overlap other claims";
|
||||
public String stringScreenReturn = "Click on paper to go back";
|
||||
|
||||
public String wrongMode = "Wrong claim mode. You are in %s-mode";
|
||||
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";
|
||||
|
||||
@ -49,6 +60,8 @@ public class LangConfig {
|
||||
public String claimGroupPerms = " Permissions: %s";
|
||||
public String claimGroupPlayers = " Players: %s";
|
||||
|
||||
public String landClaimDisabledWorld = "Claiming is disabled in this world";
|
||||
|
||||
public LangConfig(MinecraftServer server) {
|
||||
this.configDir = server.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile();
|
||||
try {
|
||||
|
@ -4,6 +4,8 @@ import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.EnumPermission;
|
||||
import com.flemmli97.flan.claim.BlockToPermissionMap;
|
||||
import com.flemmli97.flan.claim.PermHelper;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.LockableContainerBlockEntity;
|
||||
@ -13,6 +15,7 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.ToolItem;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
@ -25,13 +28,14 @@ import net.minecraft.world.World;
|
||||
|
||||
public class BlockInteractEvents {
|
||||
|
||||
public static ActionResult breakBlocks(PlayerEntity player, World world, Hand hand, BlockPos pos, Direction dir) {
|
||||
public static ActionResult breakBlocks(PlayerEntity p, World world, Hand hand, BlockPos pos, Direction dir) {
|
||||
if (world.isClient)
|
||||
return ActionResult.PASS;
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
if (claim != null) {
|
||||
if (!claim.canInteract((ServerPlayerEntity) player, EnumPermission.BREAK, pos))
|
||||
if (!claim.canInteract(player, EnumPermission.BREAK, pos, true))
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
@ -42,6 +46,15 @@ public class BlockInteractEvents {
|
||||
if (world.isClient)
|
||||
return ActionResult.PASS;
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ItemStack stack = player.getStackInHand(hand);
|
||||
if (stack.getItem() == ConfigHandler.config.claimingItem) {
|
||||
ItemInteractEvents.claimLandHandling(player, hitResult.getBlockPos());
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
if (stack.getItem() == ConfigHandler.config.inspectionItem) {
|
||||
ItemInteractEvents.inspect(player, hitResult.getBlockPos());
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim claim = storage.getClaimAt(hitResult.getBlockPos());
|
||||
if (claim != null) {
|
||||
@ -52,15 +65,14 @@ public class BlockInteractEvents {
|
||||
BlockEntity blockEntity = world.getBlockEntity(hitResult.getBlockPos());
|
||||
if (blockEntity != null) {
|
||||
if (blockEntity instanceof LockableContainerBlockEntity)
|
||||
return claim.canInteract(player, EnumPermission.OPENCONTAINER, hitResult.getBlockPos()) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, EnumPermission.OPENCONTAINER, hitResult.getBlockPos(), true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
}
|
||||
EnumPermission perm = BlockToPermissionMap.getFromBlock(state.getBlock());
|
||||
if (perm != null)
|
||||
return claim.canInteract(player, perm, hitResult.getBlockPos()) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, perm, hitResult.getBlockPos(), true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
}
|
||||
ItemStack stack = player.getStackInHand(hand);
|
||||
if (stack.getItem() instanceof BlockItem || stack.getItem() instanceof ToolItem)
|
||||
return claim.canInteract(player, EnumPermission.PLACE, hitResult.getBlockPos()) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
if (stack.getItem() instanceof BlockItem || stack.getItem() instanceof ToolItem || stack.getItem() == Items.ARMOR_STAND)
|
||||
return claim.canInteract(player, EnumPermission.PLACE, hitResult.getBlockPos(), true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
@ -75,7 +87,7 @@ public class BlockInteractEvents {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
if (claim != null)
|
||||
return !claim.canInteract((ServerPlayerEntity) entity, perm, pos);
|
||||
return !claim.canInteract((ServerPlayerEntity) entity, perm, pos, true);
|
||||
} else if (entity instanceof ProjectileEntity) {
|
||||
EnumPermission perm = BlockToPermissionMap.getFromBlock(state.getBlock());
|
||||
if (perm != EnumPermission.PRESSUREPLATE && perm != EnumPermission.BUTTONLEVER)
|
||||
@ -85,7 +97,7 @@ public class BlockInteractEvents {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
if (claim != null)
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, perm, pos);
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, perm, pos, true);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -99,7 +111,7 @@ public class BlockInteractEvents {
|
||||
Claim claim = storage.getClaimAt(landedPosition);
|
||||
EnumPermission perm = BlockToPermissionMap.getFromBlock(landedState.getBlock());
|
||||
if (perm == EnumPermission.TRAMPLE)
|
||||
return !claim.canInteract((ServerPlayerEntity) entity, perm, landedPosition);
|
||||
return !claim.canInteract((ServerPlayerEntity) entity, perm, landedPosition, true);
|
||||
} else if (entity instanceof ProjectileEntity) {
|
||||
Entity owner = ((ProjectileEntity) entity).getOwner();
|
||||
if (owner instanceof ServerPlayerEntity) {
|
||||
@ -107,7 +119,7 @@ public class BlockInteractEvents {
|
||||
Claim claim = storage.getClaimAt(landedPosition);
|
||||
EnumPermission perm = BlockToPermissionMap.getFromBlock(landedState.getBlock());
|
||||
if (perm == EnumPermission.TRAMPLE)
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, perm, landedPosition);
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, perm, landedPosition, true);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -120,20 +132,20 @@ public class BlockInteractEvents {
|
||||
if (entity instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get(serverWorld);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
return !claim.canInteract((ServerPlayerEntity) entity, EnumPermission.TRAMPLE, pos);
|
||||
return !claim.canInteract((ServerPlayerEntity) entity, EnumPermission.TRAMPLE, pos, true);
|
||||
} else if (entity instanceof ProjectileEntity) {
|
||||
Entity owner = ((ProjectileEntity) entity).getOwner();
|
||||
if (owner instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get(serverWorld);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, EnumPermission.TRAMPLE, pos);
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, EnumPermission.TRAMPLE, pos, true);
|
||||
}
|
||||
} else if (entity instanceof ItemEntity) {
|
||||
Entity owner = serverWorld.getEntity(((ItemEntity) entity).getThrower());
|
||||
if (owner instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get(serverWorld);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, EnumPermission.TRAMPLE, pos);
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, EnumPermission.TRAMPLE, pos, true);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -48,7 +48,7 @@ public class EntityInteractEvents {
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
if (claim != null) {
|
||||
if (entity instanceof ArmorStandEntity) {
|
||||
if (!claim.canInteract((ServerPlayerEntity) player, EnumPermission.ARMORSTAND, pos))
|
||||
if (!claim.canInteract((ServerPlayerEntity) player, EnumPermission.ARMORSTAND, pos, true))
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
@ -65,18 +65,18 @@ public class EntityInteractEvents {
|
||||
if (claim != null) {
|
||||
//works
|
||||
if (entity instanceof BoatEntity)
|
||||
return claim.canInteract(player, EnumPermission.BOAT, pos) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, EnumPermission.BOAT, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
if (entity instanceof AbstractMinecartEntity) {
|
||||
if (entity instanceof StorageMinecartEntity)
|
||||
return claim.canInteract(player, EnumPermission.OPENCONTAINER, pos) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, EnumPermission.MINECART, pos) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, EnumPermission.OPENCONTAINER, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, EnumPermission.MINECART, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
}
|
||||
if (entity instanceof VillagerEntity)
|
||||
return claim.canInteract(player, EnumPermission.TRADING, pos) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, EnumPermission.TRADING, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
if (entity instanceof ItemFrameEntity)
|
||||
return claim.canInteract(player, EnumPermission.ITEMFRAMEROTATE, pos) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, EnumPermission.ITEMFRAMEROTATE, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
|
||||
return claim.canInteract(player, EnumPermission.ANIMALINTERACT, pos) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, EnumPermission.ANIMALINTERACT, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
@ -100,7 +100,7 @@ public class EntityInteractEvents {
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
if (claim == null)
|
||||
return false;
|
||||
boolean flag = !claim.canInteract(player, perm, pos);
|
||||
boolean flag = !claim.canInteract(player, perm, pos, true);
|
||||
if (flag) {
|
||||
if(proj instanceof PersistentProjectileEntity) {
|
||||
PersistentProjectileEntity pers = (PersistentProjectileEntity) proj;
|
||||
@ -138,10 +138,10 @@ public class EntityInteractEvents {
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
if (claim != null) {
|
||||
if (entity instanceof ArmorStandEntity || entity instanceof MinecartEntity || entity instanceof BoatEntity || entity instanceof ItemFrameEntity)
|
||||
return claim.canInteract(player, EnumPermission.BREAKNONLIVING, pos) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, EnumPermission.BREAKNONLIVING, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
if (entity instanceof PlayerEntity)
|
||||
return claim.canInteract(player, EnumPermission.HURTPLAYER, pos) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, EnumPermission.HURTANIMAL, pos) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, EnumPermission.HURTPLAYER, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
return claim.canInteract(player, EnumPermission.HURTANIMAL, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
@ -152,7 +152,7 @@ public class EntityInteractEvents {
|
||||
BlockPos pos = player.getBlockPos();
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
if (claim != null)
|
||||
return !claim.canInteract((ServerPlayerEntity) player, EnumPermission.XP, pos);
|
||||
return !claim.canInteract((ServerPlayerEntity) player, EnumPermission.XP, pos, false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -3,6 +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.PermHelper;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.player.EnumDisplayType;
|
||||
import com.flemmli97.flan.player.EnumEditMode;
|
||||
@ -15,6 +16,7 @@ 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.Formatting;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
@ -32,81 +34,129 @@ public class ItemInteractEvents {
|
||||
if (stack.getItem() == ConfigHandler.config.claimingItem) {
|
||||
HitResult ray = player.rayTrace(64, 0, false);
|
||||
if (ray != null && ray.getType() == HitResult.Type.BLOCK) {
|
||||
BlockHitResult blockRay = (BlockHitResult) ray;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim claim = storage.getClaimAt(blockRay.getBlockPos());
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if (claim != null) {
|
||||
if (claim.canInteract(player, EnumPermission.EDITCLAIM, blockRay.getBlockPos())) {
|
||||
if (data.getEditMode() == EnumEditMode.SUBCLAIM) {
|
||||
Claim subClaim = claim.getSubClaim(blockRay.getBlockPos());
|
||||
if (subClaim != null) {
|
||||
if (subClaim.isCorner(blockRay.getBlockPos()))
|
||||
data.setEditClaim(subClaim);
|
||||
} else {
|
||||
if (data.editingCorner() != null) {
|
||||
if (data.currentEdit() == null) {
|
||||
boolean fl = claim.tryCreateSubClaim(data.editingCorner(), blockRay.getBlockPos());
|
||||
} else {
|
||||
//subClaim.resizeClaim(data.currentEdit(), data.editingCorner());
|
||||
data.setEditClaim(null);
|
||||
}
|
||||
data.setEditingCorner(null);
|
||||
} else
|
||||
data.setEditingCorner(blockRay.getBlockPos());
|
||||
}
|
||||
} else {
|
||||
if (claim.isCorner(blockRay.getBlockPos()))
|
||||
data.setEditClaim(claim);
|
||||
}
|
||||
} else {
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
player.sendMessage(Text.of(ConfigHandler.lang.cantClaimHere), false);
|
||||
}
|
||||
} else {
|
||||
if (data.editingCorner() != null) {
|
||||
if (data.currentEdit() == null)
|
||||
storage.createClaim(data.editingCorner(), blockRay.getBlockPos(), player);
|
||||
else {
|
||||
storage.resizeClaim(data.currentEdit(), data.editingCorner());
|
||||
data.setEditClaim(null);
|
||||
}
|
||||
data.setEditingCorner(null);
|
||||
} else
|
||||
data.setEditingCorner(blockRay.getBlockPos());
|
||||
}
|
||||
}
|
||||
claimLandHandling(player, ((BlockHitResult) ray).getBlockPos());
|
||||
return TypedActionResult.success(stack);
|
||||
}
|
||||
return TypedActionResult.pass(stack);
|
||||
}
|
||||
if (stack.getItem() == ConfigHandler.config.inspectionItem) {
|
||||
HitResult ray = player.rayTrace(32, 0, false);
|
||||
if (ray != null && ray.getType() == HitResult.Type.BLOCK) {
|
||||
BlockHitResult blockRay = (BlockHitResult) ray;
|
||||
Claim claim = ClaimStorage.get((ServerWorld) world).getClaimAt(new BlockPos(ray.getPos()));
|
||||
if (claim != null) {
|
||||
String owner = "<UNKOWN>";
|
||||
GameProfile prof = world.getServer().getUserCache().getByUuid(claim.getOwner());
|
||||
if (prof != null && prof.getName() != null)
|
||||
owner = prof.getName();
|
||||
Text text = Text.of(String.format(ConfigHandler.lang.inspectBlockOwner,
|
||||
owner,
|
||||
blockRay.getBlockPos().getX(), blockRay.getBlockPos().getY(), blockRay.getBlockPos().getZ()));
|
||||
player.sendMessage(text, false);
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
} else
|
||||
player.sendMessage(Text.of(ConfigHandler.lang.inspectNoClaim), false);
|
||||
}
|
||||
inspect(player, ((BlockHitResult) ray).getBlockPos());
|
||||
return TypedActionResult.success(stack);
|
||||
}
|
||||
return TypedActionResult.pass(stack);
|
||||
}
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
BlockPos pos = player.getBlockPos();
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
if (claim == null)
|
||||
return TypedActionResult.pass(stack);
|
||||
if (stack.getItem() == Items.ENDER_PEARL)
|
||||
return claim.canInteract(player, EnumPermission.ENDERPEARL, pos) ? TypedActionResult.pass(stack) : TypedActionResult.fail(stack);
|
||||
return claim.canInteract(player, EnumPermission.ENDERPEARL, pos, true)? TypedActionResult.pass(stack) : TypedActionResult.fail(stack);
|
||||
if (stack.getItem() instanceof BucketItem)
|
||||
return claim.canInteract(player, EnumPermission.BUCKET, pos) ? TypedActionResult.pass(stack) : TypedActionResult.fail(stack);
|
||||
return claim.canInteract(player, EnumPermission.BUCKET, pos, true) ? TypedActionResult.pass(stack) : TypedActionResult.fail(stack);
|
||||
return TypedActionResult.pass(stack);
|
||||
}
|
||||
|
||||
public static void claimLandHandling(ServerPlayerEntity player, BlockPos target){
|
||||
for(String s : ConfigHandler.config.blacklistedWorlds){
|
||||
if(s.equals(player.getServerWorld().getRegistryKey().getValue().toString())) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.landClaimDisabledWorld, Formatting.DARK_RED), false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
Claim claim = storage.getClaimAt(target);
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if (claim != null) {
|
||||
if (claim.canInteract(player, EnumPermission.EDITCLAIM, target)) {
|
||||
if (data.getEditMode() == EnumEditMode.SUBCLAIM) {
|
||||
Claim subClaim = claim.getSubClaim(target);
|
||||
if (subClaim != null && data.currentEdit()==null) {
|
||||
if (subClaim.isCorner(target)) {
|
||||
data.setEditClaim(subClaim);
|
||||
data.setEditingCorner(target);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeClaim, Formatting.GOLD), false);
|
||||
}
|
||||
else {
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, Formatting.RED), false);
|
||||
}
|
||||
} else {
|
||||
if(data.currentEdit()!=null){
|
||||
boolean fl = claim.resizeSubclaim(data.currentEdit(), data.editingCorner(), target);
|
||||
if(!fl)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
|
||||
data.setEditClaim(null);
|
||||
data.setEditingCorner(null);
|
||||
}
|
||||
else if (data.editingCorner() != null) {
|
||||
boolean fl = claim.tryCreateSubClaim(data.editingCorner(), target);
|
||||
if(!fl)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
|
||||
else{
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.subClaimCreateSuccess, Formatting.GOLD), false);
|
||||
}
|
||||
data.setEditingCorner(null);
|
||||
} else
|
||||
data.setEditingCorner(target);
|
||||
}
|
||||
} else {
|
||||
if (claim.isCorner(target)) {
|
||||
data.setEditClaim(claim);
|
||||
data.setEditingCorner(target);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeClaim, Formatting.GOLD), false);
|
||||
}
|
||||
else if(data.currentEdit()!=null){
|
||||
storage.resizeClaim(data.currentEdit(), data.editingCorner(), target, player);
|
||||
data.setEditClaim(null);
|
||||
data.setEditingCorner(null);
|
||||
}
|
||||
else {
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, Formatting.RED), false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, Formatting.RED), false);
|
||||
}
|
||||
}
|
||||
else if(data.getEditMode() == EnumEditMode.SUBCLAIM){
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.wrongMode, data.getEditMode()), Formatting.RED), false);
|
||||
}
|
||||
else {
|
||||
if(data.currentEdit()!=null){
|
||||
storage.resizeClaim(data.currentEdit(), data.editingCorner(), target, player);
|
||||
data.setEditClaim(null);
|
||||
data.setEditingCorner(null);
|
||||
}
|
||||
else if (data.editingCorner() != null) {
|
||||
storage.createClaim(data.editingCorner(), target, player);
|
||||
data.setEditingCorner(null);
|
||||
}
|
||||
else
|
||||
data.setEditingCorner(target);
|
||||
}
|
||||
}
|
||||
|
||||
public static void inspect(ServerPlayerEntity player, BlockPos target){
|
||||
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(target);
|
||||
if (claim != null) {
|
||||
String owner = claim.getOwner()==null?"<Admin>":"<UNKOWN>";
|
||||
if(claim.getOwner()!=null) {
|
||||
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,
|
||||
owner,
|
||||
target.getX(), target.getY(), target.getZ()), Formatting.GREEN);
|
||||
player.sendMessage(text, false);
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
} else
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.inspectNoClaim, Formatting.RED), false);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package com.flemmli97.flan.gui;
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.player.EnumEditMode;
|
||||
import com.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
@ -27,7 +29,8 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
|
||||
this.claim = claim;
|
||||
}
|
||||
|
||||
public static void openClaimMenu(PlayerEntity player, Claim claim) {
|
||||
public static void openClaimMenu(ServerPlayerEntity player, Claim claim) {
|
||||
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
@ -36,7 +39,7 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
return Text.of("Claim-Menu");
|
||||
return Text.of(claim.parentClaim()!=null?"SubClaim-Menu":"Claim-Menu");
|
||||
}
|
||||
};
|
||||
player.openHandledScreen(fac);
|
||||
@ -96,7 +99,7 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
|
||||
break;
|
||||
case 8:
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
storage.deleteClaim(this.claim, player.getServer());
|
||||
storage.deleteClaim(this.claim, true, PlayerClaimData.get(player).getEditMode(), player.getServerWorld());
|
||||
player.closeHandledScreen();
|
||||
player.sendMessage(Text.of(ConfigHandler.lang.deleteClaim), false);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_ANVIL_PLACE, 1, 1f);
|
||||
|
@ -11,6 +11,7 @@ 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.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Style;
|
||||
@ -153,8 +154,14 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
if (this.group == null)
|
||||
this.claim.editGlobalPerms(perm);
|
||||
if (this.group == null) {
|
||||
int mode = -1;
|
||||
if(this.claim.parentClaim()==null)
|
||||
mode = this.claim.permEnabled(perm)==1?-1:1;
|
||||
else
|
||||
mode = this.claim.permEnabled(perm)+1;
|
||||
this.claim.editGlobalPerms(perm, mode);
|
||||
}
|
||||
else
|
||||
this.claim.editPerms(player, this.group, perm, this.claim.groupHasPerm(this.group, perm) + 1);
|
||||
slot.setStack(ServerScreenHelper.fromPermission(this.claim, perm, this.group));
|
||||
|
@ -8,6 +8,7 @@ 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.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.text.LiteralText;
|
||||
@ -28,8 +29,23 @@ public class ServerScreenHelper {
|
||||
stack.setCustomName(new LiteralText(perm.toString()).setStyle(Style.EMPTY.withFormatting(Formatting.GOLD)));
|
||||
ListTag lore = new ListTag();
|
||||
String permFlag;
|
||||
if (group == null)
|
||||
permFlag = "" + claim.permEnabled(perm);
|
||||
if (group == null) {
|
||||
if(claim.parentClaim()==null)
|
||||
permFlag = "" + (claim.permEnabled(perm)==1);
|
||||
else {
|
||||
switch (claim.permEnabled(perm)) {
|
||||
case -1:
|
||||
permFlag = "default";
|
||||
break;
|
||||
case 1:
|
||||
permFlag = "true";
|
||||
break;
|
||||
default:
|
||||
permFlag = "false";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (claim.groupHasPerm(group, perm)) {
|
||||
case -1:
|
||||
|
@ -17,22 +17,20 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Mixin(ServerWorld.class)
|
||||
public abstract class WorldClaimMixin extends World implements IClaimData {
|
||||
public abstract class WorldClaimMixin implements IClaimData {
|
||||
@Unique
|
||||
private ClaimStorage claimData;
|
||||
|
||||
protected WorldClaimMixin(MutableWorldProperties properties, RegistryKey<World> registryKey, DimensionType dimensionType, Supplier<Profiler> supplier, boolean bl, boolean bl2, long l) {
|
||||
super(properties, registryKey, dimensionType, supplier, bl, bl2, l);
|
||||
}
|
||||
|
||||
@Inject(method = "<init>*", at = @At("RETURN"))
|
||||
private void initData(CallbackInfo info) {
|
||||
this.claimData = new ClaimStorage(this.getServer(), this.getRegistryKey());
|
||||
ServerWorld world = ((ServerWorld)(Object)this);
|
||||
this.claimData = new ClaimStorage(world.getServer(), world);
|
||||
}
|
||||
|
||||
@Inject(method = "saveLevel()V", at = @At("RETURN"))
|
||||
private void saveClaimData(CallbackInfo info) {
|
||||
this.claimData.save(this.getServer(), this.getRegistryKey());
|
||||
ServerWorld world = ((ServerWorld)(Object)this);
|
||||
this.claimData.save(world.getServer(), world.getRegistryKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,6 +18,7 @@ public class ClaimDisplay {
|
||||
|
||||
private int displayTime;
|
||||
private final Claim toDisplay;
|
||||
public final EnumDisplayType type;
|
||||
private int[][] poss;
|
||||
|
||||
private int[][] middlePoss;
|
||||
@ -29,6 +30,7 @@ public class ClaimDisplay {
|
||||
this.toDisplay = claim;
|
||||
this.displayTime = ConfigHandler.config.claimDisplayTime;
|
||||
this.prevDims = claim.getDimensions();
|
||||
this.type = type;
|
||||
switch (type){
|
||||
case SUB:
|
||||
this.corner = ParticleIndicators.SUBCLAIMCORNER;
|
||||
@ -38,6 +40,10 @@ public class ClaimDisplay {
|
||||
this.corner = ParticleIndicators.OVERLAPCLAIM;
|
||||
this.middle = ParticleIndicators.OVERLAPCLAIM;
|
||||
break;
|
||||
case EDIT:
|
||||
this.corner = ParticleIndicators.EDITCLAIMCORNER;
|
||||
this.middle = ParticleIndicators.EDITCLAIMMIDDLE;
|
||||
break;
|
||||
default:
|
||||
this.corner = ParticleIndicators.CLAIMCORNER;
|
||||
this.middle = ParticleIndicators.CLAIMMIDDLE;
|
||||
@ -49,12 +55,12 @@ public class ClaimDisplay {
|
||||
this.displayTime--;
|
||||
int[] dims = this.toDisplay.getDimensions();
|
||||
if (this.poss == null || this.changed(dims)) {
|
||||
this.middlePoss = this.calculateDisplayPos(player.world);
|
||||
this.middlePoss = calculateDisplayPos(player.world, dims);
|
||||
this.poss = new int[][]{
|
||||
this.getPosFrom(player.world, this.prevDims[0], this.prevDims[2], this.prevDims[4]),
|
||||
this.getPosFrom(player.world, this.prevDims[1], this.prevDims[2], this.prevDims[4]),
|
||||
this.getPosFrom(player.world, this.prevDims[0], this.prevDims[3], this.prevDims[4]),
|
||||
this.getPosFrom(player.world, this.prevDims[1], this.prevDims[3], this.prevDims[4]),
|
||||
this.getPosFrom(player.world, dims[0], dims[2], dims[4]),
|
||||
this.getPosFrom(player.world, dims[1], dims[2], dims[4]),
|
||||
this.getPosFrom(player.world, dims[0], dims[3], dims[4]),
|
||||
this.getPosFrom(player.world, dims[1], dims[3], dims[4]),
|
||||
};
|
||||
}
|
||||
for (int[] pos : this.poss) {
|
||||
@ -75,30 +81,30 @@ public class ClaimDisplay {
|
||||
return false;
|
||||
}
|
||||
|
||||
private int[][] calculateDisplayPos(World world) {
|
||||
public static int[][] calculateDisplayPos(World world, int[] from) {
|
||||
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);
|
||||
addEvenly(from[0], from[1], 10, xs);
|
||||
xs.add(from[0]+1);
|
||||
xs.add(from[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);
|
||||
addEvenly(from[2], from[3], 10, zs);
|
||||
zs.add(from[2]+1);
|
||||
zs.add(from[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]));
|
||||
l.add(getPosFrom(world, x, from[2], from[4]));
|
||||
l.add(getPosFrom(world, x, from[3], from[4]));
|
||||
|
||||
}
|
||||
for (int z : zs) {
|
||||
l.add(this.getPosFrom(world, this.prevDims[0], z, this.prevDims[4]));
|
||||
l.add(this.getPosFrom(world, this.prevDims[1], z, this.prevDims[4]));
|
||||
l.add(getPosFrom(world, from[0], z, from[4]));
|
||||
l.add(getPosFrom(world, from[1], z, from[4]));
|
||||
}
|
||||
|
||||
return l.toArray(new int[0][]);
|
||||
}
|
||||
|
||||
private void addEvenly(int min, int max, int step, Set<Integer> l) {
|
||||
private static void addEvenly(int min, int max, int step, Set<Integer> l) {
|
||||
if (max - min < step * 1.5)
|
||||
return;
|
||||
if (max - min > 0 && max - min <= step * 0.5) {
|
||||
@ -108,10 +114,10 @@ public class ClaimDisplay {
|
||||
}
|
||||
l.add(max - step);
|
||||
l.add(min + step);
|
||||
this.addEvenly(min + step, max - step, step, l);
|
||||
addEvenly(min + step, max - step, step, l);
|
||||
}
|
||||
|
||||
private int[] getPosFrom(World world, int x, int z, int maxY) {
|
||||
private static int[] getPosFrom(World world, int x, int z, int maxY) {
|
||||
return new int[]{x, Math.max(maxY, world.getChunk(x >> 4, z >> 4).sampleHeightmap(Heightmap.Type.WORLD_SURFACE, x & 15, z & 15) + 1), z};
|
||||
}
|
||||
|
||||
|
@ -3,5 +3,6 @@ package com.flemmli97.flan.player;
|
||||
public enum EnumDisplayType {
|
||||
MAIN,
|
||||
SUB,
|
||||
CONFLICT
|
||||
CONFLICT,
|
||||
EDIT
|
||||
}
|
||||
|
@ -22,16 +22,19 @@ import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerClaimData {
|
||||
|
||||
private int claimBlocks, additionalClaimBlocks, usedClaimsBlocks, confirmTick;
|
||||
private int claimBlocks, additionalClaimBlocks, confirmTick;
|
||||
|
||||
private int lastBlockTick;
|
||||
private EnumEditMode mode = EnumEditMode.DEFAULT;
|
||||
private Claim editingClaim;
|
||||
private ClaimDisplay displayEditing;
|
||||
|
||||
private BlockPos firstCorner;
|
||||
|
||||
@ -78,17 +81,15 @@ public class PlayerClaimData {
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
public boolean useClaimBlocks(int amount) {
|
||||
if (this.usedClaimsBlocks + amount > this.claimBlocks + this.additionalClaimBlocks)
|
||||
public boolean canUseClaimBlocks(int amount) {
|
||||
int usedClaimsBlocks = this.usedClaimBlocks();
|
||||
if (usedClaimsBlocks + amount > this.claimBlocks + this.additionalClaimBlocks)
|
||||
return false;
|
||||
this.usedClaimsBlocks += amount;
|
||||
this.dirty = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int usedClaimBlocks(){
|
||||
this.calculateUsedClaimBlocks();
|
||||
return this.usedClaimsBlocks;
|
||||
return this.calculateUsedClaimBlocks();
|
||||
}
|
||||
|
||||
public Claim currentEdit() {
|
||||
@ -96,6 +97,10 @@ public class PlayerClaimData {
|
||||
}
|
||||
|
||||
public void setEditClaim(Claim claim) {
|
||||
if(claim!=null)
|
||||
this.displayEditing = new ClaimDisplay(claim, EnumDisplayType.EDIT);
|
||||
else
|
||||
this.displayEditing = null;
|
||||
this.editingClaim = claim;
|
||||
}
|
||||
|
||||
@ -149,23 +154,29 @@ public class PlayerClaimData {
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
this.claimDisplayList.addAll(this.displayToAdd);
|
||||
this.displayToAdd.forEach(add->{
|
||||
if(!this.claimDisplayList.add(add)){
|
||||
this.claimDisplayList.removeIf(c->c.equals(add) && c.type!=add.type);
|
||||
this.claimDisplayList.add(add);
|
||||
}
|
||||
});
|
||||
this.displayToAdd.clear();
|
||||
this.claimDisplayList.removeIf(d -> d.display(this.player));
|
||||
if (++this.lastBlockTick > ConfigHandler.config.ticksForNextBlock) {
|
||||
this.addClaimBlocks(1);
|
||||
this.lastBlockTick = 0;
|
||||
}
|
||||
if (this.firstCorner != null) {
|
||||
if (this.firstCorner != null)
|
||||
this.player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleIndicators.SETCORNER, true, this.firstCorner.getX() + 0.5, this.firstCorner.getY() + 1.25, this.firstCorner.getZ() + 0.5, 0, 0.25f, 0, 0, 3));
|
||||
if (--this.confirmTick < 0)
|
||||
this.confirmDeleteAll = false;
|
||||
if(this.displayEditing!=null)
|
||||
this.displayEditing.display(this.player);
|
||||
if (this.player.getMainHandStack().getItem() != ConfigHandler.config.claimingItem && this.player.getOffHandStack().getItem() != ConfigHandler.config.claimingItem) {
|
||||
this.firstCorner = null;
|
||||
this.editingClaim = null;
|
||||
}
|
||||
}
|
||||
if (--this.confirmTick < 0)
|
||||
this.confirmDeleteAll = false;
|
||||
}
|
||||
|
||||
public void save(MinecraftServer server) {
|
||||
File dir = new File(server.getSavePath(WorldSavePath.PLAYERDATA).toFile(), "/claimData/");
|
||||
@ -229,17 +240,18 @@ public class PlayerClaimData {
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateUsedClaimBlocks() {
|
||||
this.usedClaimsBlocks = 0;
|
||||
private int calculateUsedClaimBlocks() {
|
||||
int usedClaimsBlocks = 0;
|
||||
for (ServerWorld world : this.player.getServer().getWorlds()) {
|
||||
Collection<Claim> claims = ClaimStorage.get(world).playerClaimMap.get(this.player.getUuid());
|
||||
if (claims != null)
|
||||
claims.forEach(claim -> this.usedClaimsBlocks += claim.getPlane());
|
||||
usedClaimsBlocks += claims.stream().mapToInt(Claim::getPlane).sum();
|
||||
}
|
||||
return usedClaimsBlocks;
|
||||
}
|
||||
|
||||
public static void readGriefPreventionPlayerData(MinecraftServer server) {
|
||||
File griefPrevention = server.getSavePath(WorldSavePath.ROOT).resolve("GriefPreventionData/PlayerData").toFile();
|
||||
File griefPrevention = server.getSavePath(WorldSavePath.ROOT).resolve("plugins/GriefPreventionData/PlayerData").toFile();
|
||||
if (!griefPrevention.exists())
|
||||
return;
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user