code cleanups

This commit is contained in:
Flemmli97 2020-08-25 19:43:52 +02:00
parent 2570e35ef5
commit e08787ee28
33 changed files with 369 additions and 338 deletions

View File

@ -15,6 +15,7 @@ import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.fabricmc.fabric.api.event.player.UseEntityCallback; import net.fabricmc.fabric.api.event.player.UseEntityCallback;
import net.fabricmc.fabric.api.event.player.UseItemCallback; import net.fabricmc.fabric.api.event.player.UseItemCallback;
public class Flan implements ModInitializer { public class Flan implements ModInitializer {
@Override @Override

View File

@ -16,7 +16,6 @@ import net.minecraft.block.DoorBlock;
import net.minecraft.block.FarmlandBlock; import net.minecraft.block.FarmlandBlock;
import net.minecraft.block.FenceGateBlock; import net.minecraft.block.FenceGateBlock;
import net.minecraft.block.JukeboxBlock; import net.minecraft.block.JukeboxBlock;
import net.minecraft.block.LecternBlock;
import net.minecraft.block.LeverBlock; import net.minecraft.block.LeverBlock;
import net.minecraft.block.NetherPortalBlock; import net.minecraft.block.NetherPortalBlock;
import net.minecraft.block.NoteBlock; import net.minecraft.block.NoteBlock;

View File

@ -86,17 +86,17 @@ public class Claim {
return this.owner; return this.owner;
} }
public Claim parentClaim(){ public Claim parentClaim() {
if(this.parent==null) if (this.parent == null)
return null; return null;
if(this.parentClaim==null){ if (this.parentClaim == null) {
ClaimStorage storage = ClaimStorage.get(this.world); ClaimStorage storage = ClaimStorage.get(this.world);
this.parentClaim = storage.claimUUIDMap.get(this.parent); this.parentClaim = storage.claimUUIDMap.get(this.parent);
} }
return this.parentClaim; return this.parentClaim;
} }
public void copySizes(Claim claim){ public void copySizes(Claim claim) {
this.minX = claim.minX; this.minX = claim.minX;
this.maxX = claim.maxX; this.maxX = claim.maxX;
this.minZ = claim.minZ; this.minZ = claim.minZ;
@ -105,7 +105,7 @@ public class Claim {
this.removed = false; this.removed = false;
} }
public void setAdminClaim(){ public void setAdminClaim() {
this.owner = null; this.owner = null;
} }
@ -141,7 +141,7 @@ public class Claim {
return this.removed; 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); return this.canInteract(player, perm, pos, false);
} }
@ -152,9 +152,9 @@ public class Claim {
return claim.canInteract(player, perm, pos, message); return claim.canInteract(player, perm, pos, message);
} }
} }
if(this.hasPerm(perm)) if (this.hasPerm(perm))
return true; return true;
if(message) if (message)
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false);
return false; return false;
} }
@ -165,25 +165,25 @@ public class Claim {
return true; return true;
for (Claim claim : this.subClaims) { for (Claim claim : this.subClaims) {
if (claim.insideClaim(pos)) { if (claim.insideClaim(pos)) {
if(perm!=EnumPermission.EDITCLAIM && perm != EnumPermission.EDITPERMS) if (perm != EnumPermission.EDITCLAIM && perm != EnumPermission.EDITPERMS)
return claim.canInteract(player, perm, pos, message); return claim.canInteract(player, perm, pos, message);
else if(claim.canInteract(player, perm, pos, message)) else if (claim.canInteract(player, perm, pos, message))
return true; return true;
} }
} }
if (this.playersGroups.containsKey(player.getUuid())) { if (this.playersGroups.containsKey(player.getUuid())) {
EnumMap<EnumPermission, Boolean> map = this.permissions.get(this.playersGroups.get(player.getUuid())); EnumMap<EnumPermission, Boolean> map = this.permissions.get(this.playersGroups.get(player.getUuid()));
if (map != null && map.containsKey(perm)) { if (map != null && map.containsKey(perm)) {
if(map.get(perm)) if (map.get(perm))
return true; return true;
if(message) if (message)
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false);
return false; return false;
} }
} }
if(this.hasPerm(perm)) if (this.hasPerm(perm))
return true; return true;
if(message) if (message)
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false);
return false; return false;
} }
@ -192,21 +192,21 @@ public class Claim {
* @return -1 for default, 0 for false, 1 for true * @return -1 for default, 0 for false, 1 for true
*/ */
public int permEnabled(EnumPermission perm) { public int permEnabled(EnumPermission perm) {
return !this.globalPerm.containsKey(perm)?-1:this.globalPerm.get(perm)?1:0; return !this.globalPerm.containsKey(perm) ? -1 : this.globalPerm.get(perm) ? 1 : 0;
} }
private boolean hasPerm(EnumPermission perm){ private boolean hasPerm(EnumPermission perm) {
if(this.parentClaim()==null) if (this.parentClaim() == null)
return this.permEnabled(perm) == 1; return this.permEnabled(perm) == 1;
if(this.permEnabled(perm)==-1) if (this.permEnabled(perm) == -1)
return this.parentClaim().permEnabled(perm)==1; return this.parentClaim().permEnabled(perm) == 1;
return this.permEnabled(perm) == 1; return this.permEnabled(perm) == 1;
} }
private UUID generateUUID() { private UUID generateUUID() {
UUID uuid = UUID.randomUUID(); UUID uuid = UUID.randomUUID();
for (Claim claim : this.subClaims) for (Claim claim : this.subClaims)
if(claim.claimID.equals(uuid)) { if (claim.claimID.equals(uuid)) {
return generateUUID(); return generateUUID();
} }
return uuid; return uuid;
@ -216,11 +216,11 @@ public class Claim {
Claim sub = new Claim(pos1, new BlockPos(pos2.getX(), 0, pos2.getZ()), this.owner, this.world); Claim sub = new Claim(pos1, new BlockPos(pos2.getX(), 0, pos2.getZ()), this.owner, this.world);
sub.setClaimID(this.generateUUID()); sub.setClaimID(this.generateUUID());
Set<Claim> conflicts = Sets.newHashSet(); Set<Claim> conflicts = Sets.newHashSet();
for(Claim other : this.subClaims) for (Claim other : this.subClaims)
if (sub.intersects(other)) { if (sub.intersects(other)) {
conflicts.add(sub); conflicts.add(sub);
} }
if(conflicts.isEmpty()) { if (conflicts.isEmpty()) {
sub.parent = this.claimID; sub.parent = this.claimID;
sub.parentClaim = this; sub.parentClaim = this;
this.subClaims.add(sub); this.subClaims.add(sub);
@ -228,7 +228,7 @@ public class Claim {
return conflicts; return conflicts;
} }
public void addSubClaimGriefprevention(Claim claim){ public void addSubClaimGriefprevention(Claim claim) {
claim.setClaimID(this.generateUUID()); claim.setClaimID(this.generateUUID());
claim.parent = this.claimID; claim.parent = this.claimID;
claim.parentClaim = this; claim.parentClaim = this;
@ -242,36 +242,35 @@ public class Claim {
return null; return null;
} }
public boolean deleteSubClaim(Claim claim){ public boolean deleteSubClaim(Claim claim) {
return this.subClaims.remove(claim); return this.subClaims.remove(claim);
} }
public List<Claim> getAllSubclaims(){ public List<Claim> getAllSubclaims() {
return ImmutableList.copyOf(this.subClaims); return ImmutableList.copyOf(this.subClaims);
} }
public Set<Claim> resizeSubclaim(Claim claim, BlockPos from, BlockPos to){ public Set<Claim> resizeSubclaim(Claim claim, BlockPos from, BlockPos to) {
int[] dims = claim.getDimensions(); 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]); 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); Claim newClaim = new Claim(opposite, to, claim.claimID, this.world);
Set<Claim> conflicts = Sets.newHashSet(); Set<Claim> conflicts = Sets.newHashSet();
for(Claim other : this.subClaims) for (Claim other : this.subClaims)
if (!claim.equals(other) && newClaim.intersects(other)) if (!claim.equals(other) && newClaim.intersects(other))
conflicts.add(other); conflicts.add(other);
if(conflicts.isEmpty()) if (conflicts.isEmpty())
claim.copySizes(newClaim); claim.copySizes(newClaim);
return conflicts; return conflicts;
} }
public boolean setPlayerGroup(UUID player, String group, boolean force) { public boolean setPlayerGroup(UUID player, String group, boolean force) {
if(this.owner!=null && this.owner.equals(player)) if (this.owner != null && this.owner.equals(player))
return false; return false;
if (group == null) { if (group == null) {
this.playersGroups.remove(player); this.playersGroups.remove(player);
this.setDirty(); this.setDirty();
return true; return true;
} }
if (!this.playersGroups.containsKey(player) || force) { if (!this.playersGroups.containsKey(player) || force) {
this.playersGroups.put(player, group); this.playersGroups.put(player, group);
this.setDirty(); this.setDirty();
@ -377,18 +376,13 @@ public class Claim {
this.globalPerm.clear(); this.globalPerm.clear();
this.permissions.clear(); this.permissions.clear();
this.subClaims.clear(); this.subClaims.clear();
if(obj.has("Parent")) if (obj.has("Parent"))
this.parent = UUID.fromString(obj.get("Parent").getAsString()); this.parent = UUID.fromString(obj.get("Parent").getAsString());
if (obj.has("GlobalPerms")) { if (obj.has("GlobalPerms")) {
if(this.parent==null) { if (this.parent == null) {
obj.getAsJsonArray("GlobalPerms").forEach(perm -> { obj.getAsJsonArray("GlobalPerms").forEach(perm -> this.globalPerm.put(EnumPermission.valueOf(perm.getAsString()), true));
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()));
}
else{
obj.getAsJsonObject("GlobalPerms").entrySet().forEach(entry->{
this.globalPerm.put(EnumPermission.valueOf(entry.getKey()), entry.getValue().getAsBoolean());
});
} }
} }
if (obj.has("PermGroup")) { if (obj.has("PermGroup")) {
@ -418,22 +412,19 @@ public class Claim {
pos.add(this.minY); pos.add(this.minY);
obj.add("PosxXzZY", pos); obj.add("PosxXzZY", pos);
obj.addProperty("ID", this.claimID.toString()); obj.addProperty("ID", this.claimID.toString());
if(this.parent!=null) if (this.parent != null)
obj.addProperty("Parent", this.parent.toString()); obj.addProperty("Parent", this.parent.toString());
if (!this.globalPerm.isEmpty()) { if (!this.globalPerm.isEmpty()) {
JsonElement gPerm; JsonElement gPerm;
if(this.parent==null) { if (this.parent == null) {
gPerm = new JsonArray(); gPerm = new JsonArray();
this.globalPerm.forEach((perm, bool) -> { this.globalPerm.forEach((perm, bool) -> {
if (bool) if (bool)
((JsonArray) gPerm).add(perm.toString()); ((JsonArray) gPerm).add(perm.toString());
}); });
} } else {
else{
gPerm = new JsonObject(); gPerm = new JsonObject();
this.globalPerm.forEach((perm, bool) -> { this.globalPerm.forEach((perm, bool) -> ((JsonObject) gPerm).addProperty(perm.toString(), bool));
((JsonObject) gPerm).addProperty(perm.toString(), bool);
});
} }
obj.add("GlobalPerms", gPerm); obj.add("GlobalPerms", gPerm);
} }
@ -461,7 +452,7 @@ public class Claim {
@Override @Override
public int hashCode() { public int hashCode() {
return this.claimID==null?Arrays.hashCode(this.getDimensions()):this.claimID.hashCode(); return this.claimID == null ? Arrays.hashCode(this.getDimensions()) : this.claimID.hashCode();
} }
@Override @Override
@ -470,9 +461,9 @@ public class Claim {
return true; return true;
if (obj instanceof Claim) { if (obj instanceof Claim) {
Claim other = (Claim) obj; Claim other = (Claim) obj;
if (this.claimID==null && other.claimID==null) if (this.claimID == null && other.claimID == null)
return Arrays.equals(this.getDimensions(), ((Claim) obj).getDimensions()); return Arrays.equals(this.getDimensions(), ((Claim) obj).getDimensions());
if(this.claimID!=null) if (this.claimID != null)
return this.claimID.equals(((Claim) obj).claimID); return this.claimID.equals(((Claim) obj).claimID);
} }
return false; return false;
@ -480,21 +471,21 @@ public class Claim {
@Override @Override
public String toString() { public String toString() {
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); 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() { public String formattedClaim() {
return String.format("[x=%d,z=%d] - [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){ public List<Text> infoString(ServerPlayerEntity player) {
boolean perms = this.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos()); boolean perms = this.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos());
List<Text> l = Lists.newArrayList(); List<Text> l = Lists.newArrayList();
l.add(PermHelper.simpleColoredText("=============================================", Formatting.GREEN)); l.add(PermHelper.simpleColoredText("=============================================", Formatting.GREEN));
GameProfile prof = this.owner!=null?player.getServer().getUserCache().getByUuid(this.owner):null; GameProfile prof = this.owner != null ? player.getServer().getUserCache().getByUuid(this.owner) : null;
String ownerName = this.owner==null?"Admin":prof!=null?prof.getName():"<UNKNOWN>"; String ownerName = this.owner == null ? "Admin" : prof != null ? prof.getName() : "<UNKNOWN>";
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBasicInfo, ownerName, this.minX, this.minZ, this.maxX, this.maxZ, this.subClaims.size()), Formatting.GOLD)); l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBasicInfo, ownerName, this.minX, this.minZ, this.maxX, this.maxZ, this.subClaims.size()), Formatting.GOLD));
if(perms) { if (perms) {
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimInfoPerms, this.globalPerm), Formatting.RED)); l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimInfoPerms, this.globalPerm), Formatting.RED));
l.add(PermHelper.simpleColoredText(ConfigHandler.lang.claimGroupInfoHeader, Formatting.RED)); l.add(PermHelper.simpleColoredText(ConfigHandler.lang.claimGroupInfoHeader, Formatting.RED));
Map<String, List<String>> nameToGroup = Maps.newHashMap(); Map<String, List<String>> nameToGroup = Maps.newHashMap();

View File

@ -1,7 +1,6 @@
package com.flemmli97.flan.claim; package com.flemmli97.flan.claim;
import com.flemmli97.flan.IClaimData; import com.flemmli97.flan.IClaimData;
import com.flemmli97.flan.config.Config;
import com.flemmli97.flan.config.ConfigHandler; import com.flemmli97.flan.config.ConfigHandler;
import com.flemmli97.flan.player.EnumDisplayType; import com.flemmli97.flan.player.EnumDisplayType;
import com.flemmli97.flan.player.EnumEditMode; import com.flemmli97.flan.player.EnumEditMode;
@ -62,7 +61,7 @@ public class ClaimStorage {
Set<Claim> conflicts = conflicts(claim, null); Set<Claim> conflicts = conflicts(claim, null);
if (conflicts.isEmpty()) { if (conflicts.isEmpty()) {
PlayerClaimData data = PlayerClaimData.get(player); PlayerClaimData data = PlayerClaimData.get(player);
if(claim.getPlane()<ConfigHandler.config.minClaimsize){ if (claim.getPlane() < ConfigHandler.config.minClaimsize) {
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.minClaimSize, ConfigHandler.config.minClaimsize), Formatting.RED), false); player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.minClaimSize, ConfigHandler.config.minClaimsize), Formatting.RED), false);
return false; return false;
} }
@ -77,7 +76,7 @@ public class ClaimStorage {
return true; return true;
} }
PlayerClaimData data = PlayerClaimData.get(player); PlayerClaimData data = PlayerClaimData.get(player);
conflicts.forEach(conf->data.addDisplayClaim(conf, EnumDisplayType.CONFLICT, player.getBlockPos().getY())); conflicts.forEach(conf -> data.addDisplayClaim(conf, EnumDisplayType.CONFLICT, player.getBlockPos().getY()));
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
return false; return false;
} }
@ -99,12 +98,12 @@ public class ClaimStorage {
} }
public boolean deleteClaim(Claim claim, boolean updateClaim, EnumEditMode mode, ServerWorld world) { public boolean deleteClaim(Claim claim, boolean updateClaim, EnumEditMode mode, ServerWorld world) {
if(mode==EnumEditMode.SUBCLAIM){ if (mode == EnumEditMode.SUBCLAIM) {
if(claim.parentClaim()!=null) if (claim.parentClaim() != null)
return claim.parentClaim().deleteSubClaim(claim); return claim.parentClaim().deleteSubClaim(claim);
return false; return false;
} }
if(updateClaim) if (updateClaim)
claim.remove(); claim.remove();
int[] pos = getChunkPos(claim); int[] pos = getChunkPos(claim);
for (int x = pos[0]; x <= pos[1]; x++) for (int x = pos[0]; x <= pos[1]; x++)
@ -122,18 +121,18 @@ public class ClaimStorage {
} }
public boolean resizeClaim(Claim claim, BlockPos from, BlockPos to, ServerPlayerEntity player) { public boolean resizeClaim(Claim claim, BlockPos from, BlockPos to, ServerPlayerEntity player) {
int[] dims = claim.getDimensions(); //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]); BlockPos opposite = new BlockPos(dims[0] == from.getX() ? dims[1] : dims[0], dims[4], dims[2] == from.getZ() ? dims[3] : dims[2]);
Claim newClaim = new Claim(opposite, to, player.getUuid(), player.getServerWorld()); Claim newClaim = new Claim(opposite, to, player.getUuid(), player.getServerWorld());
Set<Claim> conflicts = conflicts(newClaim, claim); Set<Claim> conflicts = conflicts(newClaim, claim);
if(!conflicts.isEmpty()) { if (!conflicts.isEmpty()) {
conflicts.forEach(conf->PlayerClaimData.get(player).addDisplayClaim(conf, EnumDisplayType.CONFLICT, player.getBlockPos().getY())); conflicts.forEach(conf -> PlayerClaimData.get(player).addDisplayClaim(conf, EnumDisplayType.CONFLICT, player.getBlockPos().getY()));
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
return false; return false;
} }
PlayerClaimData data = PlayerClaimData.get(player); PlayerClaimData data = PlayerClaimData.get(player);
int diff = newClaim.getPlane()-claim.getPlane(); int diff = newClaim.getPlane() - claim.getPlane();
if(data.canUseClaimBlocks(diff)) { if (data.canUseClaimBlocks(diff)) {
this.deleteClaim(claim, false, EnumEditMode.DEFAULT, player.getServerWorld()); this.deleteClaim(claim, false, EnumEditMode.DEFAULT, player.getServerWorld());
claim.copySizes(newClaim); claim.copySizes(newClaim);
this.addClaim(claim); this.addClaim(claim);
@ -206,7 +205,7 @@ public class ClaimStorage {
reader.close(); reader.close();
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace();
} }
} }
} }
@ -225,15 +224,14 @@ public class ClaimStorage {
continue; continue;
file.createNewFile(); file.createNewFile();
dirty = true; dirty = true;
} } else {
else { for (Claim claim : e.getValue())
for(Claim claim : e.getValue()) if (claim.isDirty()) {
if(claim.isDirty()) {
dirty = true; dirty = true;
break; break;
} }
} }
if(dirty){ if (dirty) {
FileWriter writer = new FileWriter(file); FileWriter writer = new FileWriter(file);
JsonArray arr = new JsonArray(); JsonArray arr = new JsonArray();
e.getValue().forEach(claim -> arr.add(claim.toJson(new JsonObject()))); e.getValue().forEach(claim -> arr.add(claim.toJson(new JsonObject())));
@ -242,15 +240,15 @@ public class ClaimStorage {
} }
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace();
} }
} }
public static void readGriefPreventionData(MinecraftServer server) { public static List<String> readGriefPreventionData(MinecraftServer server) {
Yaml yml = new Yaml(); Yaml yml = new Yaml();
File griefPrevention = server.getSavePath(WorldSavePath.ROOT).resolve("plugins/GriefPreventionData/ClaimData").toFile(); File griefPrevention = server.getSavePath(WorldSavePath.ROOT).resolve("plugins/GriefPreventionData/ClaimData").toFile();
if (!griefPrevention.exists()) if (!griefPrevention.exists())
return; return null;
Map<File, List<File>> subClaimMap = Maps.newHashMap(); Map<File, List<File>> subClaimMap = Maps.newHashMap();
Map<Integer, File> intFileMap = Maps.newHashMap(); Map<Integer, File> intFileMap = Maps.newHashMap();
@ -279,6 +277,7 @@ public class ClaimStorage {
} }
} }
} }
List<String> failedClaimsFile = Lists.newArrayList();
for (File parent : intFileMap.values()) { for (File parent : intFileMap.values()) {
Pair<ServerWorld, Claim> parentClaim = parseFromYaml(parent, yml, server); Pair<ServerWorld, Claim> parentClaim = parseFromYaml(parent, yml, server);
List<File> childs = subClaimMap.get(parent); List<File> childs = subClaimMap.get(parent);
@ -286,11 +285,18 @@ public class ClaimStorage {
for (File childF : childs) for (File childF : childs)
parentClaim.second.addSubClaimGriefprevention(parseFromYaml(childF, yml, server).second); parentClaim.second.addSubClaimGriefprevention(parseFromYaml(childF, yml, server).second);
} }
ClaimStorage.get(parentClaim.first).addClaim(parentClaim.second); ClaimStorage storage = ClaimStorage.get(parentClaim.first);
if (storage.conflicts(parentClaim.second, null).isEmpty())
storage.addClaim(parentClaim.second);
else
failedClaimsFile.add(parent.getName());
} }
if (!failedClaimsFile.isEmpty())
return failedClaimsFile;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace();
} }
return null;
} }
private static Pair<ServerWorld, Claim> parseFromYaml(File file, Yaml yml, MinecraftServer server) throws IOException { private static Pair<ServerWorld, Claim> parseFromYaml(File file, Yaml yml, MinecraftServer server) throws IOException {

View File

@ -1,8 +0,0 @@
package com.flemmli97.flan.claim;
public enum EnumClaimRank {
COOWNER,
BUILDER,
MANAGER
}

View File

@ -6,8 +6,8 @@ import net.minecraft.item.Items;
public enum EnumPermission { public enum EnumPermission {
EDITPERMS(Items.COMMAND_BLOCK),
EDITCLAIM(ConfigHandler.config.claimingItem), EDITCLAIM(ConfigHandler.config.claimingItem),
EDITPERMS(Items.COMMAND_BLOCK),
BREAK(Items.DIAMOND_PICKAXE), BREAK(Items.DIAMOND_PICKAXE),
PLACE(Items.GRASS_BLOCK), PLACE(Items.GRASS_BLOCK),
OPENCONTAINER(Items.CHEST), OPENCONTAINER(Items.CHEST),

View File

@ -4,16 +4,16 @@ import net.minecraft.particle.DustParticleEffect;
public class ParticleIndicators { public class ParticleIndicators {
public static final DustParticleEffect CLAIMCORNER = new DustParticleEffect(7/255f, 94/255f, 27/255f, 1); public static final DustParticleEffect CLAIMCORNER = new DustParticleEffect(194 / 255f, 130 / 255f, 4 / 255f, 1);
public static final DustParticleEffect CLAIMMIDDLE = new DustParticleEffect(9/255f, 186/255f, 51/255f, 1); public static final DustParticleEffect CLAIMMIDDLE = new DustParticleEffect(230 / 255f, 170 / 255f, 53 / 255f, 1);
public static final DustParticleEffect SUBCLAIMCORNER = new DustParticleEffect(12/255f, 110/255f, 103/255f, 1); public static final DustParticleEffect SUBCLAIMCORNER = new DustParticleEffect(125 / 255f, 125 / 255f, 125 / 255f, 1);
public static final DustParticleEffect SUBCLAIMMIDDLE = new DustParticleEffect(20/255f, 186/255f, 175/255f, 1); public static final DustParticleEffect SUBCLAIMMIDDLE = new DustParticleEffect(194 / 255f, 194 / 255f, 194 / 255f, 1);
public static final DustParticleEffect EDITCLAIMCORNER = new DustParticleEffect(12/255f, 110/255f, 103/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 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 SETCORNER = new DustParticleEffect(18 / 255f, 38 / 255f, 150 / 255f, 1);
public static final DustParticleEffect OVERLAPCLAIM = DustParticleEffect.RED; public static final DustParticleEffect OVERLAPCLAIM = DustParticleEffect.RED;
} }

View File

@ -13,8 +13,8 @@ import java.util.function.Consumer;
public class PermHelper { public class PermHelper {
public static boolean check(ServerPlayerEntity player, BlockPos pos, Claim claim, EnumPermission perm, Consumer<Optional<Boolean>> cons){ public static boolean check(ServerPlayerEntity player, BlockPos pos, Claim claim, EnumPermission perm, Consumer<Optional<Boolean>> cons) {
if(claim==null) { if (claim == null) {
cons.accept(Optional.empty()); cons.accept(Optional.empty());
return false; return false;
} }
@ -26,23 +26,23 @@ public class PermHelper {
public static Claim checkReturn(ServerPlayerEntity player, EnumPermission perm, Consumer<Optional<Boolean>> cons) { public static Claim checkReturn(ServerPlayerEntity player, EnumPermission perm, Consumer<Optional<Boolean>> cons) {
BlockPos pos = player.getBlockPos(); BlockPos pos = player.getBlockPos();
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(pos); Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(pos);
return check(player, pos, claim, perm, cons)?claim:null; return check(player, pos, claim, perm, cons) ? claim : null;
} }
public static void noClaimMessage(ServerPlayerEntity player){ public static void noClaimMessage(ServerPlayerEntity player) {
player.sendMessage(new LiteralText(ConfigHandler.lang.noClaim).setStyle(Style.EMPTY.withFormatting(Formatting.DARK_RED)), false); player.sendMessage(new LiteralText(ConfigHandler.lang.noClaim).setStyle(Style.EMPTY.withFormatting(Formatting.DARK_RED)), false);
} }
public static Consumer<Optional<Boolean>> genericNoPermMessage(ServerPlayerEntity player){ public static Consumer<Optional<Boolean>> genericNoPermMessage(ServerPlayerEntity player) {
return (b ->{ return (b -> {
if(!b.isPresent()) if (!b.isPresent())
PermHelper.noClaimMessage(player); PermHelper.noClaimMessage(player);
else if(!b.get()) else if (!b.get())
player.sendMessage(simpleColoredText(ConfigHandler.lang.noPermission, Formatting.DARK_RED), false); player.sendMessage(simpleColoredText(ConfigHandler.lang.noPermission, Formatting.DARK_RED), false);
}); });
} }
public static Text simpleColoredText(String text, Formatting... formatting){ public static Text simpleColoredText(String text, Formatting... formatting) {
return new LiteralText(text).setStyle(formatting!=null?Style.EMPTY.withFormatting(formatting):Style.EMPTY); return new LiteralText(text).setStyle(formatting != null ? Style.EMPTY.withFormatting(formatting) : Style.EMPTY);
} }
} }

View File

@ -66,17 +66,17 @@ public class CommandClaim {
addToMainCommand(CommandManager.literal("players"), addToMainCommand(CommandManager.literal("players"),
CommandManager.literal("add").then(CommandManager.argument("group", StringArgumentType.word()).suggests(CommandClaim::groupSuggestion) CommandManager.literal("add").then(CommandManager.argument("group", StringArgumentType.word()).suggests(CommandClaim::groupSuggestion)
.then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()).executes(CommandClaim::addPlayer) .then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()).executes(CommandClaim::addPlayer)
.then(CommandManager.literal("overwrite").executes(CommandClaim::forceAddPlayer)))), .then(CommandManager.literal("overwrite").executes(CommandClaim::forceAddPlayer)))),
CommandManager.literal("remove").then(CommandManager.argument("group", StringArgumentType.word()).suggests(CommandClaim::groupSuggestion) CommandManager.literal("remove").then(CommandManager.argument("group", StringArgumentType.word()).suggests(CommandClaim::groupSuggestion)
.then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()).suggests((context, build) -> { .then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()).suggests((context, build) -> {
ServerPlayerEntity player = context.getSource().getPlayer(); ServerPlayerEntity player = context.getSource().getPlayer();
List<String> list = Lists.newArrayList(); List<String> list = Lists.newArrayList();
ServerCommandSource src = context.getSource(); ServerCommandSource src = context.getSource();
ClaimStorage storage = ClaimStorage.get(src.getWorld()); ClaimStorage storage = ClaimStorage.get(src.getWorld());
Claim claim = storage.getClaimAt(src.getPlayer().getBlockPos()); Claim claim = storage.getClaimAt(src.getPlayer().getBlockPos());
if (claim != null && claim.canInteract(src.getPlayer(), EnumPermission.EDITCLAIM, src.getPlayer().getBlockPos())) { if (claim != null && claim.canInteract(src.getPlayer(), EnumPermission.EDITCLAIM, src.getPlayer().getBlockPos())) {
list = claim.playersFromGroup(player.getServer(), ""); list = claim.playersFromGroup(player.getServer(), "");
} }
return CommandSource.suggestMatching(list, build); return CommandSource.suggestMatching(list, build);
}).executes(CommandClaim::removePlayer)))) }).executes(CommandClaim::removePlayer))))
))); )));
@ -89,7 +89,7 @@ public class CommandClaim {
return main; return main;
} }
private static int reloadConfig(CommandContext<ServerCommandSource> context){ private static int reloadConfig(CommandContext<ServerCommandSource> context) {
ConfigHandler.reloadConfigs(); ConfigHandler.reloadConfigs();
context.getSource().sendFeedback(Text.of(ConfigHandler.lang.configReload), true); context.getSource().sendFeedback(Text.of(ConfigHandler.lang.configReload), true);
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
@ -98,19 +98,18 @@ public class CommandClaim {
private static int openMenu(CommandContext<ServerCommandSource> context) throws CommandSyntaxException { private static int openMenu(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerPlayerEntity player = context.getSource().getPlayer(); ServerPlayerEntity player = context.getSource().getPlayer();
PlayerClaimData data = PlayerClaimData.get(player); PlayerClaimData data = PlayerClaimData.get(player);
if(data.getEditMode() == EnumEditMode.DEFAULT) { if (data.getEditMode() == EnumEditMode.DEFAULT) {
Claim claim = PermHelper.checkReturn(player, EnumPermission.EDITPERMS, PermHelper.genericNoPermMessage(player)); Claim claim = PermHelper.checkReturn(player, EnumPermission.EDITPERMS, PermHelper.genericNoPermMessage(player));
if (claim == null) if (claim == null)
return 0; return 0;
ClaimMenuScreenHandler.openClaimMenu(player, claim); ClaimMenuScreenHandler.openClaimMenu(player, claim);
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY()); data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
} } else {
else{
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(player.getBlockPos()); Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(player.getBlockPos());
Claim sub = claim.getSubClaim(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()))) if (sub != null && (claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos()) || sub.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())))
ClaimMenuScreenHandler.openClaimMenu(player, sub); ClaimMenuScreenHandler.openClaimMenu(player, sub);
else if(claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())) else if (claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos()))
ClaimMenuScreenHandler.openClaimMenu(player, claim); ClaimMenuScreenHandler.openClaimMenu(player, claim);
else else
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermission, Formatting.DARK_RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermission, Formatting.DARK_RED), false);
@ -124,9 +123,9 @@ public class CommandClaim {
PlayerClaimData data = PlayerClaimData.get(player); PlayerClaimData data = PlayerClaimData.get(player);
if (claim == null) if (claim == null)
return 0; return 0;
if(data.getEditMode() == EnumEditMode.SUBCLAIM){ if (data.getEditMode() == EnumEditMode.SUBCLAIM) {
Claim sub = claim.getSubClaim(player.getBlockPos()); Claim sub = claim.getSubClaim(player.getBlockPos());
if(sub!=null){ if (sub != null) {
List<Text> info = sub.infoString(player); List<Text> info = sub.infoString(player);
player.sendMessage(PermHelper.simpleColoredText("==SubclaimInfo==", Formatting.AQUA), false); player.sendMessage(PermHelper.simpleColoredText("==SubclaimInfo==", Formatting.AQUA), false);
for (Text text : info) for (Text text : info)
@ -144,10 +143,10 @@ public class CommandClaim {
ServerPlayerEntity player = context.getSource().getPlayer(); ServerPlayerEntity player = context.getSource().getPlayer();
ClaimStorage storage = ClaimStorage.get(player.getServerWorld()); ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
Claim claim = storage.getClaimAt(player.getBlockPos()); Claim claim = storage.getClaimAt(player.getBlockPos());
boolean check = PermHelper.check(player, player.getBlockPos(), claim, EnumPermission.EDITCLAIM, b ->{ boolean check = PermHelper.check(player, player.getBlockPos(), claim, EnumPermission.EDITCLAIM, b -> {
if(!b.isPresent()) if (!b.isPresent())
PermHelper.noClaimMessage(player); PermHelper.noClaimMessage(player);
else if(!b.get()) else if (!b.get())
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaimError, Formatting.DARK_RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaimError, Formatting.DARK_RED), false);
else else
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaim, Formatting.DARK_RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaim, Formatting.DARK_RED), false);
@ -164,7 +163,7 @@ public class CommandClaim {
if (data.confirmedDeleteAll()) { if (data.confirmedDeleteAll()) {
for (ServerWorld world : player.getServer().getWorlds()) { for (ServerWorld world : player.getServer().getWorlds()) {
ClaimStorage storage = ClaimStorage.get(world); ClaimStorage storage = ClaimStorage.get(world);
storage.allClaimsFromPlayer(player.getUuid()).forEach((claim)->storage.deleteClaim(claim, true, PlayerClaimData.get(player).getEditMode(), player.getServerWorld())); storage.allClaimsFromPlayer(player.getUuid()).forEach((claim) -> storage.deleteClaim(claim, true, PlayerClaimData.get(player).getEditMode(), player.getServerWorld()));
} }
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteAllClaim, Formatting.GOLD), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteAllClaim, Formatting.GOLD), false);
data.setConfirmDeleteAll(false); data.setConfirmDeleteAll(false);
@ -179,19 +178,19 @@ public class CommandClaim {
ServerPlayerEntity player = context.getSource().getPlayer(); ServerPlayerEntity player = context.getSource().getPlayer();
ClaimStorage storage = ClaimStorage.get(player.getServerWorld()); ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
Claim claim = storage.getClaimAt(player.getBlockPos()); Claim claim = storage.getClaimAt(player.getBlockPos());
if(claim==null) { if (claim == null) {
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
return 0; return 0;
} }
Claim sub = claim.getSubClaim(player.getBlockPos()); Claim sub = claim.getSubClaim(player.getBlockPos());
if(sub==null) { if (sub == null) {
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
return 0; return 0;
} }
boolean check = PermHelper.check(player, player.getBlockPos(), sub, EnumPermission.EDITCLAIM, b ->{ boolean check = PermHelper.check(player, player.getBlockPos(), sub, EnumPermission.EDITCLAIM, b -> {
if(!b.isPresent()) if (!b.isPresent())
PermHelper.noClaimMessage(player); PermHelper.noClaimMessage(player);
else if(!b.get()) else if (!b.get())
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaimError, Formatting.DARK_RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaimError, Formatting.DARK_RED), false);
else else
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteSubClaim, Formatting.DARK_RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteSubClaim, Formatting.DARK_RED), false);
@ -205,7 +204,7 @@ public class CommandClaim {
private static int deleteAllSubClaim(CommandContext<ServerCommandSource> context) throws CommandSyntaxException { private static int deleteAllSubClaim(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerPlayerEntity player = context.getSource().getPlayer(); ServerPlayerEntity player = context.getSource().getPlayer();
Claim claim = PermHelper.checkReturn(player, EnumPermission.EDITCLAIM, PermHelper.genericNoPermMessage(player)); Claim claim = PermHelper.checkReturn(player, EnumPermission.EDITCLAIM, PermHelper.genericNoPermMessage(player));
if(claim==null) if (claim == null)
return 0; return 0;
List<Claim> subs = claim.getAllSubclaims(); List<Claim> subs = claim.getAllSubclaims();
subs.forEach(claim::deleteSubClaim); subs.forEach(claim::deleteSubClaim);
@ -213,7 +212,7 @@ public class CommandClaim {
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
private static int listClaims(CommandContext<ServerCommandSource> context) throws CommandSyntaxException{ private static int listClaims(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerPlayerEntity player = context.getSource().getPlayer(); ServerPlayerEntity player = context.getSource().getPlayer();
Map<World, Collection<Claim>> claims = Maps.newHashMap(); Map<World, Collection<Claim>> claims = Maps.newHashMap();
for (ServerWorld world : player.getServer().getWorlds()) { for (ServerWorld world : player.getServer().getWorlds()) {
@ -231,7 +230,7 @@ public class CommandClaim {
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
private static int switchClaimMode(CommandContext<ServerCommandSource> context) throws CommandSyntaxException{ private static int switchClaimMode(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerPlayerEntity player = context.getSource().getPlayer(); ServerPlayerEntity player = context.getSource().getPlayer();
PlayerClaimData data = PlayerClaimData.get(player); PlayerClaimData data = PlayerClaimData.get(player);
data.setEditMode(data.getEditMode() == EnumEditMode.DEFAULT ? EnumEditMode.SUBCLAIM : EnumEditMode.DEFAULT); data.setEditMode(data.getEditMode() == EnumEditMode.DEFAULT ? EnumEditMode.SUBCLAIM : EnumEditMode.DEFAULT);
@ -239,7 +238,7 @@ public class CommandClaim {
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
private static int switchAdminMode(CommandContext<ServerCommandSource> context) throws CommandSyntaxException{ private static int switchAdminMode(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerPlayerEntity player = context.getSource().getPlayer(); ServerPlayerEntity player = context.getSource().getPlayer();
PlayerClaimData data = PlayerClaimData.get(player); PlayerClaimData data = PlayerClaimData.get(player);
data.setAdminIgnoreClaim(!data.isAdminIgnoreClaim()); data.setAdminIgnoreClaim(!data.isAdminIgnoreClaim());
@ -247,7 +246,7 @@ public class CommandClaim {
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
private static int adminDelete(CommandContext<ServerCommandSource> context){ private static int adminDelete(CommandContext<ServerCommandSource> context) {
ServerCommandSource src = context.getSource(); ServerCommandSource src = context.getSource();
ClaimStorage storage = ClaimStorage.get(src.getWorld()); ClaimStorage storage = ClaimStorage.get(src.getWorld());
Claim claim = storage.getClaimAt(new BlockPos(src.getPosition())); Claim claim = storage.getClaimAt(new BlockPos(src.getPosition()));
@ -255,10 +254,10 @@ public class CommandClaim {
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false); src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
return 0; return 0;
} }
if(src.getEntity() instanceof ServerPlayerEntity){ if (src.getEntity() instanceof ServerPlayerEntity) {
ServerPlayerEntity player = (ServerPlayerEntity) src.getEntity(); ServerPlayerEntity player = (ServerPlayerEntity) src.getEntity();
PlayerClaimData data = PlayerClaimData.get(player); PlayerClaimData data = PlayerClaimData.get(player);
if(!data.confirmedDeleteAll()) { if (!data.confirmedDeleteAll()) {
data.setConfirmDeleteAll(true); data.setConfirmDeleteAll(true);
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteAllClaimConfirm, Formatting.DARK_RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteAllClaimConfirm, Formatting.DARK_RED), false);
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
@ -271,20 +270,20 @@ public class CommandClaim {
private static int adminDeleteAll(CommandContext<ServerCommandSource> context) throws CommandSyntaxException { private static int adminDeleteAll(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerCommandSource src = context.getSource(); ServerCommandSource src = context.getSource();
if(src.getEntity() instanceof ServerPlayerEntity){ if (src.getEntity() instanceof ServerPlayerEntity) {
ServerPlayerEntity player = (ServerPlayerEntity) src.getEntity(); ServerPlayerEntity player = (ServerPlayerEntity) src.getEntity();
PlayerClaimData data = PlayerClaimData.get(player); PlayerClaimData data = PlayerClaimData.get(player);
if(!data.confirmedDeleteAll()) { if (!data.confirmedDeleteAll()) {
data.setConfirmDeleteAll(true); data.setConfirmDeleteAll(true);
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteAllClaimConfirm, Formatting.DARK_RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteAllClaimConfirm, Formatting.DARK_RED), false);
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
} }
List<String> players = Lists.newArrayList(); List<String> players = Lists.newArrayList();
for(GameProfile prof : GameProfileArgumentType.getProfileArgument(context, "players")) { for (GameProfile prof : GameProfileArgumentType.getProfileArgument(context, "players")) {
for (ServerWorld world : src.getWorld().getServer().getWorlds()) { for (ServerWorld world : src.getWorld().getServer().getWorlds()) {
ClaimStorage storage = ClaimStorage.get(world); ClaimStorage storage = ClaimStorage.get(world);
storage.allClaimsFromPlayer(prof.getId()).forEach((claim)->storage.deleteClaim(claim, true, EnumEditMode.DEFAULT, world)); storage.allClaimsFromPlayer(prof.getId()).forEach((claim) -> storage.deleteClaim(claim, true, EnumEditMode.DEFAULT, world));
} }
players.add(prof.getName()); players.add(prof.getName());
} }
@ -292,7 +291,7 @@ public class CommandClaim {
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
private static int setAdminClaim(CommandContext<ServerCommandSource> context){ private static int setAdminClaim(CommandContext<ServerCommandSource> context) {
ServerCommandSource src = context.getSource(); ServerCommandSource src = context.getSource();
ClaimStorage storage = ClaimStorage.get(src.getWorld()); ClaimStorage storage = ClaimStorage.get(src.getWorld());
Claim claim = storage.getClaimAt(new BlockPos(src.getPosition())); Claim claim = storage.getClaimAt(new BlockPos(src.getPosition()));
@ -305,12 +304,15 @@ public class CommandClaim {
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
private static int readGriefPreventionData(CommandContext<ServerCommandSource> context){ private static int readGriefPreventionData(CommandContext<ServerCommandSource> context) {
ServerCommandSource src = context.getSource(); ServerCommandSource src = context.getSource();
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.readGriefpreventionData, Formatting.GOLD), true); src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.readGriefpreventionData, Formatting.GOLD), true);
ClaimStorage.readGriefPreventionData(src.getMinecraftServer()); List<String> errors = ClaimStorage.readGriefPreventionData(src.getMinecraftServer());
PlayerClaimData.readGriefPreventionPlayerData(src.getMinecraftServer()); PlayerClaimData.readGriefPreventionPlayerData(src.getMinecraftServer());
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.readGriefpreventionDataSuccess, Formatting.GOLD), true); if (errors == null)
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.readGriefpreventionDataSuccess, Formatting.GOLD), true);
else
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.readGriefpreventionDataFail, errors), Formatting.RED), true);
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
@ -318,7 +320,7 @@ public class CommandClaim {
ServerCommandSource src = context.getSource(); ServerCommandSource src = context.getSource();
List<String> players = Lists.newArrayList(); List<String> players = Lists.newArrayList();
int amount = IntegerArgumentType.getInteger(context, "amount"); int amount = IntegerArgumentType.getInteger(context, "amount");
for(GameProfile prof : GameProfileArgumentType.getProfileArgument(context, "players")) { for (GameProfile prof : GameProfileArgumentType.getProfileArgument(context, "players")) {
ServerPlayerEntity player = src.getMinecraftServer().getPlayerManager().getPlayer(prof.getId()); ServerPlayerEntity player = src.getMinecraftServer().getPlayerManager().getPlayer(prof.getId());
if (player != null) { if (player != null) {
PlayerClaimData data = PlayerClaimData.get(player); PlayerClaimData data = PlayerClaimData.get(player);
@ -360,20 +362,18 @@ public class CommandClaim {
PermHelper.noClaimMessage(player); PermHelper.noClaimMessage(player);
return 0; return 0;
} }
if(remove) { if (remove) {
if (claim.removePermGroup(player, group)) if (claim.removePermGroup(player, group))
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.groupRemove, group), Formatting.GOLD), false); player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.groupRemove, group), Formatting.GOLD), false);
else { else {
PermHelper.genericNoPermMessage(player); PermHelper.genericNoPermMessage(player);
return 0; return 0;
} }
} } else {
else{ if (claim.groups().contains(group)) {
if(claim.groups().contains(group)){
player.sendMessage(PermHelper.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; return 0;
} } else if (claim.editPerms(player, group, EnumPermission.EDITCLAIM, -1))
else if(claim.editPerms(player, group, EnumPermission.EDITCLAIM, -1))
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.groupAdd, group), Formatting.GOLD), false); player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.groupAdd, group), Formatting.GOLD), false);
else { else {
PermHelper.genericNoPermMessage(player); PermHelper.genericNoPermMessage(player);
@ -405,16 +405,16 @@ public class CommandClaim {
PermHelper.noClaimMessage(player); PermHelper.noClaimMessage(player);
return 0; return 0;
} }
if(!claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())){ if (!claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())) {
PermHelper.genericNoPermMessage(player); PermHelper.genericNoPermMessage(player);
return 0; return 0;
} }
List<String> modified = Lists.newArrayList(); List<String> modified = Lists.newArrayList();
for(GameProfile prof :GameProfileArgumentType.getProfileArgument(context, "players")){ for (GameProfile prof : GameProfileArgumentType.getProfileArgument(context, "players")) {
if(claim.setPlayerGroup(prof.getId(), group, force)) if (claim.setPlayerGroup(prof.getId(), group, force))
modified.add(prof.getName()); modified.add(prof.getName());
} }
if(!modified.isEmpty()) if (!modified.isEmpty())
player.sendMessage(PermHelper.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 else
player.sendMessage(PermHelper.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);

View File

@ -8,7 +8,6 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.WorldSavePath; import net.minecraft.util.WorldSavePath;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import org.lwjgl.system.CallbackI;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
@ -25,7 +24,7 @@ public class Config {
public int minClaimsize = 100; public int minClaimsize = 100;
public int defaultClaimDepth = 255; public int defaultClaimDepth = 255;
public String[] blacklistedWorlds = new String[] {"minecraft:the_nether"}; public String[] blacklistedWorlds = new String[0];
public boolean worldWhitelist; public boolean worldWhitelist;
public Item claimingItem = Items.GOLDEN_HOE; public Item claimingItem = Items.GOLDEN_HOE;
@ -36,10 +35,10 @@ public class Config {
public Config(MinecraftServer server) { public Config(MinecraftServer server) {
File configDir = server.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile(); File configDir = server.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile();
try { try {
if(!configDir.exists()) if (!configDir.exists())
configDir.mkdirs(); configDir.mkdirs();
this.config = new File(configDir, "flan_config.json"); this.config = new File(configDir, "flan_config.json");
if(!this.config.exists()) { if (!this.config.exists()) {
this.config.createNewFile(); this.config.createNewFile();
this.save(); this.save();
} }
@ -60,7 +59,7 @@ public class Config {
this.defaultClaimDepth = obj.get("defaultClaimDepth").getAsInt(); this.defaultClaimDepth = obj.get("defaultClaimDepth").getAsInt();
JsonArray arr = obj.getAsJsonArray("blacklistedWorlds"); JsonArray arr = obj.getAsJsonArray("blacklistedWorlds");
this.blacklistedWorlds = new String[arr.size()]; this.blacklistedWorlds = new String[arr.size()];
for(int i = 0; i < arr.size(); i ++) for (int i = 0; i < arr.size(); i++)
this.blacklistedWorlds[i] = arr.get(i).getAsString(); this.blacklistedWorlds[i] = arr.get(i).getAsString();
this.worldWhitelist = obj.get("worldWhitelist").getAsBoolean(); this.worldWhitelist = obj.get("worldWhitelist").getAsBoolean();
this.claimingItem = Registry.ITEM.get(new Identifier((obj.get("claimingItem").getAsString()))); this.claimingItem = Registry.ITEM.get(new Identifier((obj.get("claimingItem").getAsString())));

View File

@ -17,7 +17,7 @@ public class ConfigHandler {
reloadConfigs(); reloadConfigs();
} }
public static void reloadConfigs(){ public static void reloadConfigs() {
config.load(); config.load();
lang.load(); lang.load();
} }

View File

@ -1,12 +1,10 @@
package com.flemmli97.flan.config; package com.flemmli97.flan.config;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.util.WorldSavePath; import net.minecraft.util.WorldSavePath;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
@ -59,6 +57,7 @@ public class LangConfig {
public String setAdminClaim = "Claim changed to an Adminclaim"; public String setAdminClaim = "Claim changed to an Adminclaim";
public String readGriefpreventionData = "Reading data from GriefPrevention"; public String readGriefpreventionData = "Reading data from GriefPrevention";
public String readGriefpreventionDataSuccess = "Successfully read data"; public String readGriefpreventionDataSuccess = "Successfully read data";
public String readGriefpreventionDataFail = "Failed reading data for following claim files (Check the logs!): %s";
public String giveClaimBlocks = "Gave following players %2$d claimblocks: %1$s"; public String giveClaimBlocks = "Gave following players %2$d claimblocks: %1$s";
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 claimBasicInfo = "Owner: %1$s, from: [x=%2$d,z=%3$d] to [x=%4$d,z=%5$d]; Subclaim-amount: %6$d";
@ -70,10 +69,10 @@ public class LangConfig {
public LangConfig(MinecraftServer server) { public LangConfig(MinecraftServer server) {
File configDir = server.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile(); File configDir = server.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile();
try { try {
if(!configDir.exists()) if (!configDir.exists())
configDir.mkdirs(); configDir.mkdirs();
this.config = new File(configDir, "flan_lang.json"); this.config = new File(configDir, "flan_lang.json");
if(!this.config.exists()) { if (!this.config.exists()) {
this.config.createNewFile(); this.config.createNewFile();
this.save(); this.save();
} }
@ -87,8 +86,8 @@ public class LangConfig {
FileReader reader = new FileReader(this.config); FileReader reader = new FileReader(this.config);
JsonObject obj = ConfigHandler.GSON.fromJson(reader, JsonObject.class); JsonObject obj = ConfigHandler.GSON.fromJson(reader, JsonObject.class);
reader.close(); reader.close();
for(Field field : this.getClass().getDeclaredFields()){ for (Field field : this.getClass().getDeclaredFields()) {
if(field.getDeclaringClass().equals(String.class)){ if (field.getDeclaringClass().equals(String.class)) {
field.set(this, obj.get(field.getName()).getAsString()); field.set(this, obj.get(field.getName()).getAsString());
} }
} }
@ -97,11 +96,11 @@ public class LangConfig {
} }
} }
private void save(){ private void save() {
JsonObject obj = new JsonObject(); JsonObject obj = new JsonObject();
try { try {
for(Field field : this.getClass().getDeclaredFields()){ for (Field field : this.getClass().getDeclaredFields()) {
if(field.getType().equals(String.class)){ if (field.getType().equals(String.class)) {
obj.addProperty(field.getName(), (String) field.get(this)); obj.addProperty(field.getName(), (String) field.get(this));
} }
} }

View File

@ -1,10 +1,9 @@
package com.flemmli97.flan.event; package com.flemmli97.flan.event;
import com.flemmli97.flan.claim.BlockToPermissionMap;
import com.flemmli97.flan.claim.Claim; import com.flemmli97.flan.claim.Claim;
import com.flemmli97.flan.claim.ClaimStorage; import com.flemmli97.flan.claim.ClaimStorage;
import com.flemmli97.flan.claim.EnumPermission; 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 com.flemmli97.flan.config.ConfigHandler;
import com.flemmli97.flan.gui.LockedLecternScreenHandler; import com.flemmli97.flan.gui.LockedLecternScreenHandler;
import com.flemmli97.flan.player.EnumDisplayType; import com.flemmli97.flan.player.EnumDisplayType;
@ -20,10 +19,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.ItemEntity; import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack; 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.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
@ -74,12 +70,12 @@ public class BlockInteractEvents {
BlockEntity blockEntity = world.getBlockEntity(hitResult.getBlockPos()); BlockEntity blockEntity = world.getBlockEntity(hitResult.getBlockPos());
if (blockEntity != null) { if (blockEntity != null) {
if (blockEntity instanceof LockableContainerBlockEntity) { if (blockEntity instanceof LockableContainerBlockEntity) {
if(claim.canInteract(player, EnumPermission.OPENCONTAINER, hitResult.getBlockPos(), true)) if (claim.canInteract(player, EnumPermission.OPENCONTAINER, hitResult.getBlockPos(), true))
return ActionResult.PASS; return ActionResult.PASS;
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY()); PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
return ActionResult.FAIL; return ActionResult.FAIL;
} }
if(blockEntity instanceof LecternBlockEntity) { if (blockEntity instanceof LecternBlockEntity) {
if (claim.canInteract(player, EnumPermission.LECTERNTAKE, hitResult.getBlockPos(), false)) if (claim.canInteract(player, EnumPermission.LECTERNTAKE, hitResult.getBlockPos(), false))
return ActionResult.PASS; return ActionResult.PASS;
if (state.get(LecternBlock.HAS_BOOK)) if (state.get(LecternBlock.HAS_BOOK))
@ -89,16 +85,15 @@ public class BlockInteractEvents {
} }
EnumPermission perm = BlockToPermissionMap.getFromBlock(state.getBlock()); EnumPermission perm = BlockToPermissionMap.getFromBlock(state.getBlock());
//Pressureplate handled elsewhere //Pressureplate handled elsewhere
if (perm!=null && perm != EnumPermission.PRESSUREPLATE) { if (perm != null && perm != EnumPermission.PRESSUREPLATE) {
if(claim.canInteract(player, perm, hitResult.getBlockPos(), true)) if (claim.canInteract(player, perm, hitResult.getBlockPos(), true))
return ActionResult.PASS; return ActionResult.PASS;
if(state.getBlock() instanceof DoorBlock){ if (state.getBlock() instanceof DoorBlock) {
DoubleBlockHalf half = state.get(DoorBlock.HALF); DoubleBlockHalf half = state.get(DoorBlock.HALF);
if(half==DoubleBlockHalf.LOWER) { if (half == DoubleBlockHalf.LOWER) {
BlockState other = world.getBlockState(hitResult.getBlockPos().up()); BlockState other = world.getBlockState(hitResult.getBlockPos().up());
player.world.updateListeners(hitResult.getBlockPos().up(), other, other, 2); player.world.updateListeners(hitResult.getBlockPos().up(), other, other, 2);
} } else {
else {
BlockState other = world.getBlockState(hitResult.getBlockPos().down()); BlockState other = world.getBlockState(hitResult.getBlockPos().down());
player.world.updateListeners(hitResult.getBlockPos().down(), other, other, 2); player.world.updateListeners(hitResult.getBlockPos().down(), other, other, 2);
} }
@ -111,7 +106,7 @@ public class BlockInteractEvents {
return ActionResult.PASS; return ActionResult.PASS;
} }
public static boolean blockCollisionEntity(BlockState state, World world, BlockPos pos, Entity entity) { public static boolean cancelEntityBlockCollision(BlockState state, World world, BlockPos pos, Entity entity) {
if (entity.world.isClient) if (entity.world.isClient)
return false; return false;
if (entity instanceof ServerPlayerEntity) { if (entity instanceof ServerPlayerEntity) {
@ -137,7 +132,7 @@ public class BlockInteractEvents {
return false; return false;
} }
public static boolean entityFall(Entity entity, double heightDifference, boolean onGround, BlockState landedState, BlockPos landedPosition) { public static boolean preventFallOn(Entity entity, double heightDifference, boolean onGround, BlockState landedState, BlockPos landedPosition) {
if (entity.world.isClient) if (entity.world.isClient)
return false; return false;
if (entity instanceof ServerPlayerEntity) { if (entity instanceof ServerPlayerEntity) {
@ -159,7 +154,7 @@ public class BlockInteractEvents {
return false; return false;
} }
public static boolean turtleEggHandle(World world, BlockPos pos, Entity entity) { public static boolean canBreakTurtleEgg(World world, BlockPos pos, Entity entity) {
if (world.isClient) if (world.isClient)
return false; return false;
ServerWorld serverWorld = (ServerWorld) world; ServerWorld serverWorld = (ServerWorld) world;

View File

@ -1,32 +1,27 @@
package com.flemmli97.flan.event; package com.flemmli97.flan.event;
import com.flemmli97.flan.claim.BlockToPermissionMap;
import com.flemmli97.flan.claim.Claim; import com.flemmli97.flan.claim.Claim;
import com.flemmli97.flan.claim.ClaimStorage; import com.flemmli97.flan.claim.ClaimStorage;
import com.flemmli97.flan.claim.EnumPermission; import com.flemmli97.flan.claim.EnumPermission;
import com.flemmli97.flan.claim.BlockToPermissionMap;
import com.flemmli97.flan.mixin.IPersistentProjectileVars; import com.flemmli97.flan.mixin.IPersistentProjectileVars;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.boss.WitherEntity; import net.minecraft.entity.boss.WitherEntity;
import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.EntityDamageSource;
import net.minecraft.entity.decoration.ArmorStandEntity; import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.entity.decoration.ItemFrameEntity; import net.minecraft.entity.decoration.ItemFrameEntity;
import net.minecraft.entity.mob.Monster; import net.minecraft.entity.mob.Monster;
import net.minecraft.entity.passive.VillagerEntity; import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ArrowEntity;
import net.minecraft.entity.projectile.PersistentProjectileEntity; import net.minecraft.entity.projectile.PersistentProjectileEntity;
import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.entity.projectile.TridentEntity;
import net.minecraft.entity.projectile.thrown.EnderPearlEntity; import net.minecraft.entity.projectile.thrown.EnderPearlEntity;
import net.minecraft.entity.vehicle.AbstractMinecartEntity; import net.minecraft.entity.vehicle.AbstractMinecartEntity;
import net.minecraft.entity.vehicle.BoatEntity; import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.entity.vehicle.MinecartEntity; import net.minecraft.entity.vehicle.MinecartEntity;
import net.minecraft.entity.vehicle.StorageMinecartEntity; 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.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
@ -61,14 +56,13 @@ public class EntityInteractEvents {
} }
public static ActionResult useEntity(PlayerEntity p, World world, Hand hand, Entity entity) { public static ActionResult useEntity(PlayerEntity p, World world, Hand hand, Entity entity) {
if(p.world.isClient || p.isSpectator()) if (p.world.isClient || p.isSpectator())
return ActionResult.PASS; return ActionResult.PASS;
ServerPlayerEntity player = (ServerPlayerEntity) p; ServerPlayerEntity player = (ServerPlayerEntity) p;
ClaimStorage storage = ClaimStorage.get((ServerWorld) world); ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
BlockPos pos = entity.getBlockPos(); BlockPos pos = entity.getBlockPos();
Claim claim = storage.getClaimAt(pos); Claim claim = storage.getClaimAt(pos);
if (claim != null) { if (claim != null) {
//works
if (entity instanceof BoatEntity) if (entity instanceof BoatEntity)
return claim.canInteract(player, EnumPermission.BOAT, pos, true) ? ActionResult.PASS : ActionResult.FAIL; return claim.canInteract(player, EnumPermission.BOAT, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
if (entity instanceof AbstractMinecartEntity) { if (entity instanceof AbstractMinecartEntity) {
@ -80,7 +74,6 @@ public class EntityInteractEvents {
return claim.canInteract(player, EnumPermission.TRADING, pos, true) ? ActionResult.PASS : ActionResult.FAIL; return claim.canInteract(player, EnumPermission.TRADING, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
if (entity instanceof ItemFrameEntity) if (entity instanceof ItemFrameEntity)
return claim.canInteract(player, EnumPermission.ITEMFRAMEROTATE, pos, true) ? ActionResult.PASS : ActionResult.FAIL; return claim.canInteract(player, EnumPermission.ITEMFRAMEROTATE, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
return claim.canInteract(player, EnumPermission.ANIMALINTERACT, pos, true) ? ActionResult.PASS : ActionResult.FAIL; return claim.canInteract(player, EnumPermission.ANIMALINTERACT, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
} }
return ActionResult.PASS; return ActionResult.PASS;
@ -107,7 +100,7 @@ public class EntityInteractEvents {
return false; return false;
boolean flag = !claim.canInteract(player, perm, pos, true); boolean flag = !claim.canInteract(player, perm, pos, true);
if (flag) { if (flag) {
if(proj instanceof PersistentProjectileEntity) { if (proj instanceof PersistentProjectileEntity) {
PersistentProjectileEntity pers = (PersistentProjectileEntity) proj; PersistentProjectileEntity pers = (PersistentProjectileEntity) proj;
((IPersistentProjectileVars) pers).setInBlockState(pers.world.getBlockState(pos)); ((IPersistentProjectileVars) pers).setInBlockState(pers.world.getBlockState(pos));
Vec3d vec3d = blockRes.getPos().subtract(pers.getX(), pers.getY(), pers.getZ()); Vec3d vec3d = blockRes.getPos().subtract(pers.getX(), pers.getY(), pers.getZ());
@ -123,11 +116,12 @@ public class EntityInteractEvents {
pers.setShotFromCrossbow(false); pers.setShotFromCrossbow(false);
((IPersistentProjectileVars) pers).resetPiercingStatus(); ((IPersistentProjectileVars) pers).resetPiercingStatus();
} }
//find a way to properly update chorus fruit break on hit
//player.getServer().send(new ServerTask(player.getServer().getTicks()+2, ()->player.world.updateListeners(pos, state, state, 2))); //player.getServer().send(new ServerTask(player.getServer().getTicks()+2, ()->player.world.updateListeners(pos, state, state, 2)));
} }
return flag; return flag;
} else if (res.getType() == HitResult.Type.ENTITY){ } else if (res.getType() == HitResult.Type.ENTITY) {
if(proj instanceof EnderPearlEntity) { if (proj instanceof EnderPearlEntity) {
ClaimStorage storage = ClaimStorage.get((ServerWorld) proj.world); ClaimStorage storage = ClaimStorage.get((ServerWorld) proj.world);
Claim claim = storage.getClaimAt(proj.getBlockPos()); Claim claim = storage.getClaimAt(proj.getBlockPos());
return claim.canInteract(player, EnumPermission.ENDERPEARL, proj.getBlockPos(), true); return claim.canInteract(player, EnumPermission.ENDERPEARL, proj.getBlockPos(), true);
@ -138,13 +132,12 @@ public class EntityInteractEvents {
return false; return false;
} }
public static boolean hurtEntity(LivingEntity entity, DamageSource source){ public static boolean preventDamage(LivingEntity entity, DamageSource source) {
if(source.getAttacker() instanceof ServerPlayerEntity) if (source.getAttacker() instanceof ServerPlayerEntity)
return attackSimple((ServerPlayerEntity) source.getAttacker(), entity, false)!=ActionResult.PASS; return attackSimple((ServerPlayerEntity) source.getAttacker(), entity, false) != ActionResult.PASS;
else if(source.isExplosive() && !entity.world.isClient){ else if (source.isExplosive() && !entity.world.isClient) {
Claim claim = ClaimStorage.get((ServerWorld) entity.world).getClaimAt(entity.getBlockPos()); Claim claim = ClaimStorage.get((ServerWorld) entity.world).getClaimAt(entity.getBlockPos());
if(claim!=null && !claim.canInteract(null, EnumPermission.EXPLOSIONS, entity.getBlockPos())) return claim != null && !claim.canInteract(null, EnumPermission.EXPLOSIONS, entity.getBlockPos());
return true;
} }
return false; return false;
} }

View File

@ -11,18 +11,13 @@ import com.flemmli97.flan.player.PlayerClaimData;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.LecternBlock;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.BucketItem; import net.minecraft.item.BucketItem;
import net.minecraft.item.EndCrystalItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext; import net.minecraft.item.ItemUsageContext;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.item.ToolItem;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.network.ServerPlayerInteractionManager;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
@ -65,30 +60,31 @@ public class ItemInteractEvents {
if (claim == null) if (claim == null)
return TypedActionResult.pass(stack); return TypedActionResult.pass(stack);
if (stack.getItem() == Items.ENDER_PEARL) if (stack.getItem() == Items.ENDER_PEARL)
return claim.canInteract(player, EnumPermission.ENDERPEARL, pos, true)? 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) if (stack.getItem() instanceof BucketItem)
return claim.canInteract(player, EnumPermission.BUCKET, pos, true) ? TypedActionResult.pass(stack) : TypedActionResult.fail(stack); return claim.canInteract(player, EnumPermission.BUCKET, pos, true) ? TypedActionResult.pass(stack) : TypedActionResult.fail(stack);
return TypedActionResult.pass(stack); return TypedActionResult.pass(stack);
} }
private static Set<Item> blackListedItems = Sets.newHashSet(Items.COMPASS, Items.FILLED_MAP, Items.FIREWORK_ROCKET); private static final Set<Item> blackListedItems = Sets.newHashSet(Items.COMPASS, Items.FILLED_MAP, Items.FIREWORK_ROCKET);
public static ActionResult onItemUseBlock(ItemUsageContext context){
if(context.getWorld().isClient || context.getStack().isEmpty()) public static ActionResult onItemUseBlock(ItemUsageContext context) {
if (context.getWorld().isClient || context.getStack().isEmpty())
return ActionResult.PASS; return ActionResult.PASS;
ClaimStorage storage = ClaimStorage.get((ServerWorld) context.getWorld()); ClaimStorage storage = ClaimStorage.get((ServerWorld) context.getWorld());
BlockPos placePos = context.getBlockPos().offset(context.getSide()); BlockPos placePos = context.getBlockPos().offset(context.getSide());
Claim claim = storage.getClaimAt(placePos); Claim claim = storage.getClaimAt(placePos);
if(claim==null) if (claim == null)
return ActionResult.PASS; return ActionResult.PASS;
if(blackListedItems.contains(context.getStack().getItem())) if (blackListedItems.contains(context.getStack().getItem()))
return ActionResult.PASS; return ActionResult.PASS;
ServerPlayerEntity player = (ServerPlayerEntity) context.getPlayer(); ServerPlayerEntity player = (ServerPlayerEntity) context.getPlayer();
if(context.getStack().getItem() == Items.END_CRYSTAL) { if (context.getStack().getItem() == Items.END_CRYSTAL) {
if(claim.canInteract(player, EnumPermission.ENDCRYSTALPLACE, placePos, true)) if (claim.canInteract(player, EnumPermission.ENDCRYSTALPLACE, placePos, true))
return ActionResult.PASS; return ActionResult.PASS;
return ActionResult.FAIL; return ActionResult.FAIL;
} }
if(claim.canInteract(player, EnumPermission.PLACE, placePos, true)) if (claim.canInteract(player, EnumPermission.PLACE, placePos, true))
return ActionResult.PASS; return ActionResult.PASS;
BlockState other = context.getWorld().getBlockState(placePos.up()); BlockState other = context.getWorld().getBlockState(placePos.up());
player.world.updateListeners(placePos.up(), other, other, 2); player.world.updateListeners(placePos.up(), other, other, 2);
@ -96,23 +92,22 @@ public class ItemInteractEvents {
return ActionResult.FAIL; return ActionResult.FAIL;
} }
private static boolean cantClaimInWorld(ServerWorld world){ private static boolean cantClaimInWorld(ServerWorld world) {
for(String s : ConfigHandler.config.blacklistedWorlds){ for (String s : ConfigHandler.config.blacklistedWorlds) {
if(s.equals(world.getRegistryKey().getValue().toString())) { if (s.equals(world.getRegistryKey().getValue().toString())) {
return true; return true;
} }
} }
return false; return false;
} }
public static void claimLandHandling(ServerPlayerEntity player, BlockPos target){ public static void claimLandHandling(ServerPlayerEntity player, BlockPos target) {
if(ConfigHandler.config.worldWhitelist){ if (ConfigHandler.config.worldWhitelist) {
if(!cantClaimInWorld(player.getServerWorld())) { if (!cantClaimInWorld(player.getServerWorld())) {
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.landClaimDisabledWorld, Formatting.DARK_RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.landClaimDisabledWorld, Formatting.DARK_RED), false);
return; return;
} }
} } else if (cantClaimInWorld(player.getServerWorld())) {
else if(cantClaimInWorld(player.getServerWorld())) {
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.landClaimDisabledWorld, Formatting.DARK_RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.landClaimDisabledWorld, Formatting.DARK_RED), false);
return; return;
} }
@ -123,34 +118,31 @@ public class ItemInteractEvents {
if (claim.canInteract(player, EnumPermission.EDITCLAIM, target)) { if (claim.canInteract(player, EnumPermission.EDITCLAIM, target)) {
if (data.getEditMode() == EnumEditMode.SUBCLAIM) { if (data.getEditMode() == EnumEditMode.SUBCLAIM) {
Claim subClaim = claim.getSubClaim(target); Claim subClaim = claim.getSubClaim(target);
if (subClaim != null && data.currentEdit()==null) { if (subClaim != null && data.currentEdit() == null) {
if (subClaim.isCorner(target)) { if (subClaim.isCorner(target)) {
data.setEditClaim(subClaim, player.getBlockPos().getY()); data.setEditClaim(subClaim, player.getBlockPos().getY());
data.setEditingCorner(target); data.setEditingCorner(target);
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeClaim, Formatting.GOLD), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeClaim, Formatting.GOLD), false);
} } else {
else {
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY()); data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, Formatting.RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, Formatting.RED), false);
} }
} else { } else {
if(data.currentEdit()!=null){ if (data.currentEdit() != null) {
Set<Claim> fl = claim.resizeSubclaim(data.currentEdit(), data.editingCorner(), target); Set<Claim> fl = claim.resizeSubclaim(data.currentEdit(), data.editingCorner(), target);
if(!fl.isEmpty()) { if (!fl.isEmpty()) {
fl.forEach(confl -> data.addDisplayClaim(confl, EnumDisplayType.MAIN, player.getBlockPos().getY())); fl.forEach(confl -> data.addDisplayClaim(confl, EnumDisplayType.MAIN, player.getBlockPos().getY()));
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
} }
data.setEditClaim(null, 0); data.setEditClaim(null, 0);
data.setEditingCorner(null); data.setEditingCorner(null);
} } else if (data.editingCorner() != null) {
else if (data.editingCorner() != null) {
Set<Claim> fl = claim.tryCreateSubClaim(data.editingCorner(), target); Set<Claim> fl = claim.tryCreateSubClaim(data.editingCorner(), target);
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY()); data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
if(!fl.isEmpty()) { if (!fl.isEmpty()) {
fl.forEach(confl -> data.addDisplayClaim(confl, EnumDisplayType.MAIN, player.getBlockPos().getY())); fl.forEach(confl -> data.addDisplayClaim(confl, EnumDisplayType.MAIN, player.getBlockPos().getY()));
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
} } else {
else{
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.subClaimCreateSuccess, Formatting.GOLD), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.subClaimCreateSuccess, Formatting.GOLD), false);
} }
data.setEditingCorner(null); data.setEditingCorner(null);
@ -162,13 +154,11 @@ public class ItemInteractEvents {
data.setEditClaim(claim, player.getBlockPos().getY()); data.setEditClaim(claim, player.getBlockPos().getY());
data.setEditingCorner(target); data.setEditingCorner(target);
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeClaim, Formatting.GOLD), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeClaim, Formatting.GOLD), false);
} } else if (data.currentEdit() != null) {
else if(data.currentEdit()!=null){
storage.resizeClaim(data.currentEdit(), data.editingCorner(), target, player); storage.resizeClaim(data.currentEdit(), data.editingCorner(), target, player);
data.setEditClaim(null, 0); data.setEditClaim(null, 0);
data.setEditingCorner(null); data.setEditingCorner(null);
} } else {
else {
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY()); data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, Formatting.RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, Formatting.RED), false);
} }
@ -177,30 +167,26 @@ public class ItemInteractEvents {
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY()); data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, Formatting.RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, Formatting.RED), false);
} }
} } else if (data.getEditMode() == EnumEditMode.SUBCLAIM) {
else if(data.getEditMode() == EnumEditMode.SUBCLAIM){
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.wrongMode, data.getEditMode()), Formatting.RED), false); player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.wrongMode, data.getEditMode()), Formatting.RED), false);
} } else {
else { if (data.currentEdit() != null) {
if(data.currentEdit()!=null){
storage.resizeClaim(data.currentEdit(), data.editingCorner(), target, player); storage.resizeClaim(data.currentEdit(), data.editingCorner(), target, player);
data.setEditClaim(null, 0); data.setEditClaim(null, 0);
data.setEditingCorner(null); data.setEditingCorner(null);
} } else if (data.editingCorner() != null) {
else if (data.editingCorner() != null) {
storage.createClaim(data.editingCorner(), target, player); storage.createClaim(data.editingCorner(), target, player);
data.setEditingCorner(null); data.setEditingCorner(null);
} } else
else
data.setEditingCorner(target); data.setEditingCorner(target);
} }
} }
public static void inspect(ServerPlayerEntity player, BlockPos target){ public static void inspect(ServerPlayerEntity player, BlockPos target) {
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(target); Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(target);
if (claim != null) { if (claim != null) {
String owner = claim.getOwner()==null?"<Admin>":"<UNKOWN>"; String owner = claim.getOwner() == null ? "<Admin>" : "<UNKOWN>";
if(claim.getOwner()!=null) { if (claim.getOwner() != null) {
GameProfile prof = player.getServer().getUserCache().getByUuid(claim.getOwner()); GameProfile prof = player.getServer().getUserCache().getByUuid(claim.getOwner());
if (prof != null && prof.getName() != null) if (prof != null && prof.getName() != null)
owner = prof.getName(); owner = prof.getName();

View File

@ -3,7 +3,6 @@ package com.flemmli97.flan.gui;
import com.flemmli97.flan.claim.Claim; import com.flemmli97.flan.claim.Claim;
import com.flemmli97.flan.claim.ClaimStorage; import com.flemmli97.flan.claim.ClaimStorage;
import com.flemmli97.flan.config.ConfigHandler; import com.flemmli97.flan.config.ConfigHandler;
import com.flemmli97.flan.player.EnumEditMode;
import com.flemmli97.flan.player.PlayerClaimData; import com.flemmli97.flan.player.PlayerClaimData;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
@ -30,7 +29,6 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
} }
public static void openClaimMenu(ServerPlayerEntity player, Claim claim) { public static void openClaimMenu(ServerPlayerEntity player, Claim claim) {
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() { NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
@Override @Override
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) { public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
@ -39,7 +37,7 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
@Override @Override
public Text getDisplayName() { public Text getDisplayName() {
return Text.of(claim.parentClaim()!=null?"SubClaim-Menu":"Claim-Menu"); return Text.of(claim.parentClaim() != null ? "SubClaim-Menu" : "Claim-Menu");
} }
}; };
player.openHandledScreen(fac); player.openHandledScreen(fac);
@ -98,11 +96,20 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f); ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
break; break;
case 8: case 8:
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
storage.deleteClaim(this.claim, true, PlayerClaimData.get(player).getEditMode(), player.getServerWorld());
player.closeHandledScreen(); player.closeHandledScreen();
player.sendMessage(Text.of(ConfigHandler.lang.deleteClaim), false); player.getServer().execute(() -> ConfirmScreenHandler.openConfirmScreen(player, (bool) -> {
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_ANVIL_PLACE, 1, 1f); if (bool) {
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
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);
} else {
player.closeHandledScreen();
player.getServer().execute(() -> ClaimMenuScreenHandler.openClaimMenu(player, this.claim));
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
}
}));
break; break;
} }
return true; return true;

View File

@ -0,0 +1,81 @@
package com.flemmli97.flan.gui;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import java.util.function.Consumer;
public class ConfirmScreenHandler extends ServerOnlyScreenHandler {
private final Consumer<Boolean> cons;
private ConfirmScreenHandler(int syncId, PlayerInventory playerInventory, Consumer<Boolean> cons) {
super(syncId, playerInventory, 1);
this.cons = cons;
}
public static void openConfirmScreen(ServerPlayerEntity player, Consumer<Boolean> process) {
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
@Override
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
return new ConfirmScreenHandler(syncId, inv, process);
}
@Override
public Text getDisplayName() {
return Text.of("Confirm");
}
};
player.openHandledScreen(fac);
}
@Override
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Object... additionalData) {
for (int i = 0; i < 9; i++) {
switch (i) {
case 3:
ItemStack yes = new ItemStack(Items.GREEN_WOOL);
yes.setCustomName(new LiteralText("Yes").setStyle(Style.EMPTY.withFormatting(Formatting.GREEN)));
inv.setStack(i, yes);
break;
case 5:
ItemStack no = new ItemStack(Items.RED_WOOL);
no.setCustomName(new LiteralText("No").setStyle(Style.EMPTY.withFormatting(Formatting.RED)));
inv.setStack(i, no);
break;
default:
inv.setStack(i, ServerScreenHelper.emptyFiller());
}
}
}
@Override
protected boolean isRightSlot(int slot) {
return slot == 3 || slot == 5;
}
@Override
protected boolean handleSlotClicked(ServerPlayerEntity player, int index, Slot slot, int clickType) {
switch (index) {
case 3:
this.cons.accept(true);
break;
case 5:
this.cons.accept(false);
break;
}
return true;
}
}

View File

@ -1,10 +1,8 @@
package com.flemmli97.flan.gui; package com.flemmli97.flan.gui;
import com.flemmli97.flan.claim.Claim;
import com.flemmli97.flan.claim.PermHelper; import com.flemmli97.flan.claim.PermHelper;
import com.flemmli97.flan.config.ConfigHandler; import com.flemmli97.flan.config.ConfigHandler;
import com.flemmli97.flan.mixin.ILecternBlockValues; import com.flemmli97.flan.mixin.ILecternBlockValues;
import net.minecraft.block.LecternBlock;
import net.minecraft.block.entity.LecternBlockEntity; import net.minecraft.block.entity.LecternBlockEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
@ -27,7 +25,7 @@ public class LockedLecternScreenHandler extends LecternScreenHandler {
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() { NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
@Override @Override
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) { public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
return new LockedLecternScreenHandler(syncId, ((ILecternBlockValues)lectern).getInv(), ((ILecternBlockValues)lectern).getProp()); return new LockedLecternScreenHandler(syncId, ((ILecternBlockValues) lectern).getInv(), ((ILecternBlockValues) lectern).getProp());
} }
@Override @Override
@ -40,7 +38,7 @@ public class LockedLecternScreenHandler extends LecternScreenHandler {
@Override @Override
public boolean onButtonClick(PlayerEntity player, int id) { public boolean onButtonClick(PlayerEntity player, int id) {
if(id==3) { if (id == 3) {
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false);
return false; return false;
} }

View File

@ -11,7 +11,6 @@ import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.Slot;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Style; import net.minecraft.text.Style;
@ -88,7 +87,7 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
} }
} }
private void flipPage(){ private void flipPage() {
for (int i = 0; i < 54; i++) { for (int i = 0; i < 54; i++) {
if (i == 0) { if (i == 0) {
ItemStack close = new ItemStack(Items.TNT); ItemStack close = new ItemStack(Items.TNT);
@ -96,20 +95,19 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
this.slots.get(i).setStack(close); this.slots.get(i).setStack(close);
} else if (i == 47) { } else if (i == 47) {
ItemStack stack = ItemStack.EMPTY; ItemStack stack = ItemStack.EMPTY;
if(this.page == 1){ if (this.page == 1) {
stack =new ItemStack(Items.ARROW); stack = new ItemStack(Items.ARROW);
stack.setCustomName(new LiteralText("Prev").setStyle(Style.EMPTY.withFormatting(Formatting.WHITE))); stack.setCustomName(new LiteralText("Prev").setStyle(Style.EMPTY.withFormatting(Formatting.WHITE)));
} }
this.slots.get(i).setStack(stack); this.slots.get(i).setStack(stack);
} else if (i == 51) { } else if (i == 51) {
ItemStack stack = ItemStack.EMPTY; ItemStack stack = ItemStack.EMPTY;
if(this.page == 0) { if (this.page == 0) {
stack = new ItemStack(Items.ARROW); stack = new ItemStack(Items.ARROW);
stack.setCustomName(new LiteralText("Next").setStyle(Style.EMPTY.withFormatting(Formatting.WHITE))); stack.setCustomName(new LiteralText("Next").setStyle(Style.EMPTY.withFormatting(Formatting.WHITE)));
} }
this.slots.get(i).setStack(stack); this.slots.get(i).setStack(stack);
} } else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
this.slots.get(i).setStack(ServerScreenHelper.emptyFiller()); this.slots.get(i).setStack(ServerScreenHelper.emptyFiller());
else { else {
int row = i / 9 - 1; int row = i / 9 - 1;
@ -155,14 +153,13 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
return false; return false;
} }
if (this.group == null) { if (this.group == null) {
int mode = -1; int mode;
if(this.claim.parentClaim()==null) if (this.claim.parentClaim() == null)
mode = this.claim.permEnabled(perm)==1?-1:1; mode = this.claim.permEnabled(perm) == 1 ? -1 : 1;
else else
mode = this.claim.permEnabled(perm)+1; mode = this.claim.permEnabled(perm) + 1;
this.claim.editGlobalPerms(perm, mode); this.claim.editGlobalPerms(perm, mode);
} } else
else
this.claim.editPerms(player, this.group, perm, this.claim.groupHasPerm(this.group, perm) + 1); this.claim.editPerms(player, this.group, perm, this.claim.groupHasPerm(this.group, perm) + 1);
slot.setStack(ServerScreenHelper.fromPermission(this.claim, perm, this.group)); slot.setStack(ServerScreenHelper.fromPermission(this.claim, perm, this.group));
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_NOTE_BLOCK_PLING, 1, 1.2f); ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_NOTE_BLOCK_PLING, 1, 1.2f);

View File

@ -30,7 +30,7 @@ public abstract class ServerOnlyScreenHandler extends ScreenHandler {
int m; int m;
for (n = 0; n < rows; ++n) { for (n = 0; n < rows; ++n) {
for (m = 0; m < 9; ++m) { for (m = 0; m < 9; ++m) {
this.addSlot(new Slot(inventory, m + n * 9, 8 + m * 18, 18 + n * 18)); this.addSlot(new Slot(this.inventory, m + n * 9, 8 + m * 18, 18 + n * 18));
} }
} }

View File

@ -8,7 +8,6 @@ import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag; import net.minecraft.nbt.StringTag;
import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket; import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvent;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
@ -30,8 +29,8 @@ public class ServerScreenHelper {
ListTag lore = new ListTag(); ListTag lore = new ListTag();
String permFlag; String permFlag;
if (group == null) { if (group == null) {
if(claim.parentClaim()==null) if (claim.parentClaim() == null)
permFlag = "" + (claim.permEnabled(perm)==1); permFlag = "" + (claim.permEnabled(perm) == 1);
else { else {
switch (claim.permEnabled(perm)) { switch (claim.permEnabled(perm)) {
case -1: case -1:
@ -45,8 +44,7 @@ public class ServerScreenHelper {
break; break;
} }
} }
} } else {
else {
switch (claim.groupHasPerm(group, perm)) { switch (claim.groupHasPerm(group, perm)) {
case -1: case -1:
permFlag = "default"; permFlag = "default";

View File

@ -17,7 +17,7 @@ public abstract class AbstractBlockStateMixin {
@Inject(method = "onEntityCollision", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "onEntityCollision", at = @At(value = "HEAD"), cancellable = true)
public void collision(World world, BlockPos pos, Entity entity, CallbackInfo info) { public void collision(World world, BlockPos pos, Entity entity, CallbackInfo info) {
if (BlockInteractEvents.blockCollisionEntity(this.asBlockState(), world, pos, entity)) { if (BlockInteractEvents.cancelEntityBlockCollision(this.asBlockState(), world, pos, entity)) {
info.cancel(); info.cancel();
} }
} }

View File

@ -14,7 +14,7 @@ public abstract class EntityMixin {
@Inject(method = "fall", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;onLandedUpon(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;F)V"), cancellable = true) @Inject(method = "fall", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;onLandedUpon(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;F)V"), cancellable = true)
public void fallOnBlock(double heightDifference, boolean onGround, BlockState landedState, BlockPos landedPosition, CallbackInfo info) { public void fallOnBlock(double heightDifference, boolean onGround, BlockState landedState, BlockPos landedPosition, CallbackInfo info) {
if (BlockInteractEvents.entityFall((Entity) (Object) this, heightDifference, onGround, landedState, landedPosition)) if (BlockInteractEvents.preventFallOn((Entity) (Object) this, heightDifference, onGround, landedState, landedPosition))
info.cancel(); info.cancel();
} }

View File

@ -18,8 +18,8 @@ public abstract class FluidMixin {
@Inject(method = "canFlow", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "canFlow", at = @At(value = "HEAD"), cancellable = true)
public void crossClaimFlow(BlockView world, BlockPos fluidPos, BlockState fluidBlockState, Direction flowDirection, BlockPos flowTo, public void crossClaimFlow(BlockView world, BlockPos fluidPos, BlockState fluidBlockState, Direction flowDirection, BlockPos flowTo,
BlockState flowToBlockState, FluidState fluidState, Fluid fluid, CallbackInfoReturnable<Boolean> info){ BlockState flowToBlockState, FluidState fluidState, Fluid fluid, CallbackInfoReturnable<Boolean> info) {
if(!WorldEvents.canFlow(fluidBlockState, world, fluidPos, flowDirection)){ if (!WorldEvents.canFlow(fluidBlockState, world, fluidPos, flowDirection)) {
info.setReturnValue(false); info.setReturnValue(false);
info.cancel(); info.cancel();
} }

View File

@ -1,20 +1,17 @@
package com.flemmli97.flan.mixin; package com.flemmli97.flan.mixin;
import net.minecraft.block.entity.LecternBlockEntity; import net.minecraft.block.entity.LecternBlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory; import net.minecraft.inventory.Inventory;
import net.minecraft.screen.PropertyDelegate; import net.minecraft.screen.PropertyDelegate;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(LecternBlockEntity.class) @Mixin(LecternBlockEntity.class)
public interface ILecternBlockValues { public interface ILecternBlockValues {
@Accessor("inventory") @Accessor("inventory")
public Inventory getInv(); Inventory getInv();
@Accessor("propertyDelegate") @Accessor("propertyDelegate")
public PropertyDelegate getProp(); PropertyDelegate getProp();
} }

View File

@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
public abstract class ItemStackMixin { public abstract class ItemStackMixin {
@Inject(method = "useOnBlock", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "useOnBlock", at = @At(value = "HEAD"), cancellable = true)
public void blockUse(ItemUsageContext context, CallbackInfoReturnable<ActionResult> info){ public void blockUse(ItemUsageContext context, CallbackInfoReturnable<ActionResult> info) {
ActionResult result = ItemInteractEvents.onItemUseBlock(context); ActionResult result = ItemInteractEvents.onItemUseBlock(context);
if (result != ActionResult.PASS) { if (result != ActionResult.PASS) {
info.setReturnValue(result); info.setReturnValue(result);

View File

@ -6,15 +6,14 @@ import net.minecraft.entity.damage.DamageSource;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(LivingEntity.class) @Mixin(LivingEntity.class)
public abstract class LivingEntityMixin { public abstract class LivingEntityMixin {
@Inject(method = "damage", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "damage", at = @At(value = "HEAD"), cancellable = true)
public void onDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> info){ public void onDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> info) {
if(EntityInteractEvents.hurtEntity((LivingEntity)(Object)this, source)) { if (EntityInteractEvents.preventDamage((LivingEntity) (Object) this, source)) {
info.setReturnValue(false); info.setReturnValue(false);
info.cancel(); info.cancel();
} }

View File

@ -2,7 +2,6 @@ package com.flemmli97.flan.mixin;
import com.flemmli97.flan.event.WorldEvents; import com.flemmli97.flan.event.WorldEvents;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.PistonBlock; import net.minecraft.block.PistonBlock;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
@ -16,8 +15,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
public class PistonMixin { public class PistonMixin {
@Inject(method = "isMovable", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "isMovable", at = @At(value = "HEAD"), cancellable = true)
private static void checkMovable(BlockState blockState, World world, BlockPos blockPos, Direction direction, boolean canBreak, Direction pistonDir, CallbackInfoReturnable<Boolean> info){ private static void checkMovable(BlockState blockState, World world, BlockPos blockPos, Direction direction, boolean canBreak, Direction pistonDir, CallbackInfoReturnable<Boolean> info) {
if(!WorldEvents.pistonCanPush(blockState, world, blockPos, direction, pistonDir)) { if (!WorldEvents.pistonCanPush(blockState, world, blockPos, direction, pistonDir)) {
info.setReturnValue(false); info.setReturnValue(false);
info.cancel(); info.cancel();
} }

View File

@ -15,7 +15,7 @@ public abstract class TurtleEggMixin {
@Inject(method = "onSteppedOn", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "onSteppedOn", at = @At(value = "HEAD"), cancellable = true)
public void collision(World world, BlockPos pos, Entity entity, CallbackInfo info) { public void collision(World world, BlockPos pos, Entity entity, CallbackInfo info) {
if (BlockInteractEvents.turtleEggHandle(world, pos, entity)) { if (BlockInteractEvents.canBreakTurtleEgg(world, pos, entity)) {
info.cancel(); info.cancel();
} }
} }

View File

@ -9,16 +9,16 @@ import net.minecraft.block.BlockState;
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
import net.minecraft.particle.DustParticleEffect; import net.minecraft.particle.DustParticleEffect;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Heightmap;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
public class ClaimDisplay { public class ClaimDisplay {
private int displayTime, height; private int displayTime;
private final int height;
private final Claim toDisplay; private final Claim toDisplay;
public final EnumDisplayType type; public final EnumDisplayType type;
private int[][] poss; private int[][] poss;
@ -28,13 +28,14 @@ public class ClaimDisplay {
private int[] prevDims; private int[] prevDims;
private final DustParticleEffect corner, middle; private final DustParticleEffect corner, middle;
public ClaimDisplay(Claim claim, EnumDisplayType type, int y) { public ClaimDisplay(Claim claim, EnumDisplayType type, int y) {
this.toDisplay = claim; this.toDisplay = claim;
this.displayTime = ConfigHandler.config.claimDisplayTime; this.displayTime = ConfigHandler.config.claimDisplayTime;
this.prevDims = claim.getDimensions(); this.prevDims = claim.getDimensions();
this.type = type; this.type = type;
this.height = y; this.height = y;
switch (type){ switch (type) {
case SUB: case SUB:
this.corner = ParticleIndicators.SUBCLAIMCORNER; this.corner = ParticleIndicators.SUBCLAIMCORNER;
this.middle = ParticleIndicators.SUBCLAIMMIDDLE; this.middle = ParticleIndicators.SUBCLAIMMIDDLE;
@ -60,16 +61,16 @@ public class ClaimDisplay {
if (this.poss == null || this.changed(dims)) { if (this.poss == null || this.changed(dims)) {
this.middlePoss = calculateDisplayPos(player.getServerWorld(), dims, this.height); this.middlePoss = calculateDisplayPos(player.getServerWorld(), dims, this.height);
this.poss = new int[][]{ this.poss = new int[][]{
this.getPosFrom(player.getServerWorld(), dims[0], dims[2], this.height), getPosFrom(player.getServerWorld(), dims[0], dims[2], this.height),
this.getPosFrom(player.getServerWorld(), dims[1], dims[2], this.height), getPosFrom(player.getServerWorld(), dims[1], dims[2], this.height),
this.getPosFrom(player.getServerWorld(), dims[0], dims[3], this.height), getPosFrom(player.getServerWorld(), dims[0], dims[3], this.height),
this.getPosFrom(player.getServerWorld(), dims[1], dims[3], this.height), getPosFrom(player.getServerWorld(), dims[1], dims[3], this.height),
}; };
} }
for (int[] pos : this.poss) { for (int[] pos : this.poss) {
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)); 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) if (this.middlePoss != null)
for (int[] pos : this.middlePoss) { 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)); 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));
} }
@ -88,12 +89,12 @@ public class ClaimDisplay {
List<int[]> l = Lists.newArrayList(); List<int[]> l = Lists.newArrayList();
Set<Integer> xs = Sets.newHashSet(); Set<Integer> xs = Sets.newHashSet();
addEvenly(from[0], from[1], 10, xs); addEvenly(from[0], from[1], 10, xs);
xs.add(from[0]+1); xs.add(from[0] + 1);
xs.add(from[1]-1); xs.add(from[1] - 1);
Set<Integer> zs = Sets.newHashSet(); Set<Integer> zs = Sets.newHashSet();
addEvenly(from[2], from[3], 10, zs); addEvenly(from[2], from[3], 10, zs);
zs.add(from[2]+1); zs.add(from[2] + 1);
zs.add(from[3]-1); zs.add(from[3] - 1);
for (int x : xs) { for (int x : xs) {
l.add(getPosFrom(world, x, from[2], height)); l.add(getPosFrom(world, x, from[2], height));
l.add(getPosFrom(world, x, from[3], height)); l.add(getPosFrom(world, x, from[3], height));
@ -125,19 +126,18 @@ public class ClaimDisplay {
return new int[]{x, y, z}; return new int[]{x, y, z};
} }
private static int nextAirBlockFrom(ServerWorld world, int x, int y, int z){ private static int nextAirBlockFrom(ServerWorld world, int x, int y, int z) {
BlockPos pos = new BlockPos(x,y,z); BlockPos pos = new BlockPos(x, y, z);
BlockState state = world.getBlockState(pos); BlockState state = world.getBlockState(pos);
if(state.getMaterial().isReplaceable()){ if (state.getMaterial().isReplaceable()) {
pos = pos.down(); pos = pos.down();
while(world.getBlockState(pos).getMaterial().isReplaceable()){ while (world.getBlockState(pos).getMaterial().isReplaceable()) {
pos = pos.down(); pos = pos.down();
} }
pos = pos.up(); pos = pos.up();
} } else {
else{
pos = pos.up(); pos = pos.up();
while(!world.getBlockState(pos).getMaterial().isReplaceable()){ while (!world.getBlockState(pos).getMaterial().isReplaceable()) {
pos = pos.up(); pos = pos.up();
} }
} }

View File

@ -1,7 +1,6 @@
package com.flemmli97.flan.player; package com.flemmli97.flan.player;
public enum EnumEditMode { public enum EnumEditMode {
DEFAULT, DEFAULT,
SUBCLAIM SUBCLAIM
} }

View File

@ -22,8 +22,6 @@ import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -83,12 +81,10 @@ public class PlayerClaimData {
public boolean canUseClaimBlocks(int amount) { public boolean canUseClaimBlocks(int amount) {
int usedClaimsBlocks = this.usedClaimBlocks(); int usedClaimsBlocks = this.usedClaimBlocks();
if (usedClaimsBlocks + amount > this.claimBlocks + this.additionalClaimBlocks) return usedClaimsBlocks + amount <= this.claimBlocks + this.additionalClaimBlocks;
return false;
return true;
} }
public int usedClaimBlocks(){ public int usedClaimBlocks() {
return this.calculateUsedClaimBlocks(); return this.calculateUsedClaimBlocks();
} }
@ -97,7 +93,7 @@ public class PlayerClaimData {
} }
public void setEditClaim(Claim claim, int height) { public void setEditClaim(Claim claim, int height) {
if(claim!=null) if (claim != null)
this.displayEditing = new ClaimDisplay(claim, EnumDisplayType.EDIT, height); this.displayEditing = new ClaimDisplay(claim, EnumDisplayType.EDIT, height);
else else
this.displayEditing = null; this.displayEditing = null;
@ -106,8 +102,8 @@ public class PlayerClaimData {
public void addDisplayClaim(Claim claim, EnumDisplayType type, int height) { public void addDisplayClaim(Claim claim, EnumDisplayType type, int height) {
this.displayToAdd.add(new ClaimDisplay(claim, type, height)); this.displayToAdd.add(new ClaimDisplay(claim, type, height));
if(type==EnumDisplayType.MAIN) if (type == EnumDisplayType.MAIN)
for(Claim sub : claim.getAllSubclaims()) for (Claim sub : claim.getAllSubclaims())
this.displayToAdd.add(new ClaimDisplay(sub, EnumDisplayType.SUB, height)); this.displayToAdd.add(new ClaimDisplay(sub, EnumDisplayType.SUB, height));
} }
@ -154,9 +150,9 @@ public class PlayerClaimData {
} }
public void tick() { public void tick() {
this.displayToAdd.forEach(add->{ this.displayToAdd.forEach(add -> {
if(!this.claimDisplayList.add(add)){ if (!this.claimDisplayList.add(add)) {
this.claimDisplayList.removeIf(c->c.equals(add) && c.type!=add.type); this.claimDisplayList.removeIf(c -> c.equals(add) && c.type != add.type);
this.claimDisplayList.add(add); this.claimDisplayList.add(add);
} }
}); });
@ -170,7 +166,7 @@ public class PlayerClaimData {
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)); 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) if (--this.confirmTick < 0)
this.confirmDeleteAll = false; this.confirmDeleteAll = false;
if(this.displayEditing!=null) if (this.displayEditing != null)
this.displayEditing.display(this.player); this.displayEditing.display(this.player);
if (this.player.getMainHandStack().getItem() != ConfigHandler.config.claimingItem && this.player.getOffHandStack().getItem() != ConfigHandler.config.claimingItem) { if (this.player.getMainHandStack().getItem() != ConfigHandler.config.claimingItem && this.player.getOffHandStack().getItem() != ConfigHandler.config.claimingItem) {
this.firstCorner = null; this.firstCorner = null;
@ -195,7 +191,7 @@ public class PlayerClaimData {
ConfigHandler.GSON.toJson(obj, writer); ConfigHandler.GSON.toJson(obj, writer);
writer.close(); writer.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace();
} }
} }
@ -213,7 +209,7 @@ public class PlayerClaimData {
this.additionalClaimBlocks = obj.get("AdditionalBlocks").getAsInt(); this.additionalClaimBlocks = obj.get("AdditionalBlocks").getAsInt();
reader.close(); reader.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace();
} }
} }
@ -236,7 +232,7 @@ public class PlayerClaimData {
ConfigHandler.GSON.toJson(obj, writer); ConfigHandler.GSON.toJson(obj, writer);
writer.close(); writer.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace();
} }
} }
@ -285,7 +281,7 @@ public class PlayerClaimData {
} }
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace();
} }
} }
} }

View File

@ -13,7 +13,6 @@
"TurtleEggMixin", "TurtleEggMixin",
"XpEntityMixin", "XpEntityMixin",
"WitherMixin", "WitherMixin",
"ExplosionMixin",
"EnderPearlEntityMixin", "EnderPearlEntityMixin",
"IPersistentProjectileVars", "IPersistentProjectileVars",
"LivingEntityMixin", "LivingEntityMixin",