code cleanups
This commit is contained in:
parent
2570e35ef5
commit
e08787ee28
@ -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.UseItemCallback;
|
||||
|
||||
|
||||
public class Flan implements ModInitializer {
|
||||
|
||||
@Override
|
||||
|
@ -16,7 +16,6 @@ import net.minecraft.block.DoorBlock;
|
||||
import net.minecraft.block.FarmlandBlock;
|
||||
import net.minecraft.block.FenceGateBlock;
|
||||
import net.minecraft.block.JukeboxBlock;
|
||||
import net.minecraft.block.LecternBlock;
|
||||
import net.minecraft.block.LeverBlock;
|
||||
import net.minecraft.block.NetherPortalBlock;
|
||||
import net.minecraft.block.NoteBlock;
|
||||
|
@ -86,17 +86,17 @@ public class Claim {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
public Claim parentClaim(){
|
||||
if(this.parent==null)
|
||||
public Claim parentClaim() {
|
||||
if (this.parent == null)
|
||||
return null;
|
||||
if(this.parentClaim==null){
|
||||
if (this.parentClaim == null) {
|
||||
ClaimStorage storage = ClaimStorage.get(this.world);
|
||||
this.parentClaim = storage.claimUUIDMap.get(this.parent);
|
||||
}
|
||||
return this.parentClaim;
|
||||
}
|
||||
|
||||
public void copySizes(Claim claim){
|
||||
public void copySizes(Claim claim) {
|
||||
this.minX = claim.minX;
|
||||
this.maxX = claim.maxX;
|
||||
this.minZ = claim.minZ;
|
||||
@ -105,7 +105,7 @@ public class Claim {
|
||||
this.removed = false;
|
||||
}
|
||||
|
||||
public void setAdminClaim(){
|
||||
public void setAdminClaim() {
|
||||
this.owner = null;
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@ public class Claim {
|
||||
return this.removed;
|
||||
}
|
||||
|
||||
public boolean canInteract(ServerPlayerEntity player, EnumPermission perm, BlockPos pos){
|
||||
public boolean canInteract(ServerPlayerEntity player, EnumPermission perm, BlockPos pos) {
|
||||
return this.canInteract(player, perm, pos, false);
|
||||
}
|
||||
|
||||
@ -152,9 +152,9 @@ public class Claim {
|
||||
return claim.canInteract(player, perm, pos, message);
|
||||
}
|
||||
}
|
||||
if(this.hasPerm(perm))
|
||||
if (this.hasPerm(perm))
|
||||
return true;
|
||||
if(message)
|
||||
if (message)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false);
|
||||
return false;
|
||||
}
|
||||
@ -165,25 +165,25 @@ public class Claim {
|
||||
return true;
|
||||
for (Claim claim : this.subClaims) {
|
||||
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);
|
||||
else if(claim.canInteract(player, perm, pos, message))
|
||||
else if (claim.canInteract(player, perm, pos, message))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (this.playersGroups.containsKey(player.getUuid())) {
|
||||
EnumMap<EnumPermission, Boolean> map = this.permissions.get(this.playersGroups.get(player.getUuid()));
|
||||
if (map != null && map.containsKey(perm)) {
|
||||
if(map.get(perm))
|
||||
if (map.get(perm))
|
||||
return true;
|
||||
if(message)
|
||||
if (message)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(this.hasPerm(perm))
|
||||
if (this.hasPerm(perm))
|
||||
return true;
|
||||
if(message)
|
||||
if (message)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false);
|
||||
return false;
|
||||
}
|
||||
@ -192,21 +192,21 @@ public class Claim {
|
||||
* @return -1 for default, 0 for false, 1 for true
|
||||
*/
|
||||
public int permEnabled(EnumPermission perm) {
|
||||
return !this.globalPerm.containsKey(perm)?-1:this.globalPerm.get(perm)?1:0;
|
||||
return !this.globalPerm.containsKey(perm) ? -1 : this.globalPerm.get(perm) ? 1 : 0;
|
||||
}
|
||||
|
||||
private boolean hasPerm(EnumPermission perm){
|
||||
if(this.parentClaim()==null)
|
||||
private boolean hasPerm(EnumPermission perm) {
|
||||
if (this.parentClaim() == null)
|
||||
return this.permEnabled(perm) == 1;
|
||||
if(this.permEnabled(perm)==-1)
|
||||
return this.parentClaim().permEnabled(perm)==1;
|
||||
if (this.permEnabled(perm) == -1)
|
||||
return this.parentClaim().permEnabled(perm) == 1;
|
||||
return this.permEnabled(perm) == 1;
|
||||
}
|
||||
|
||||
private UUID generateUUID() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
for (Claim claim : this.subClaims)
|
||||
if(claim.claimID.equals(uuid)) {
|
||||
if (claim.claimID.equals(uuid)) {
|
||||
return generateUUID();
|
||||
}
|
||||
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);
|
||||
sub.setClaimID(this.generateUUID());
|
||||
Set<Claim> conflicts = Sets.newHashSet();
|
||||
for(Claim other : this.subClaims)
|
||||
for (Claim other : this.subClaims)
|
||||
if (sub.intersects(other)) {
|
||||
conflicts.add(sub);
|
||||
}
|
||||
if(conflicts.isEmpty()) {
|
||||
if (conflicts.isEmpty()) {
|
||||
sub.parent = this.claimID;
|
||||
sub.parentClaim = this;
|
||||
this.subClaims.add(sub);
|
||||
@ -228,7 +228,7 @@ public class Claim {
|
||||
return conflicts;
|
||||
}
|
||||
|
||||
public void addSubClaimGriefprevention(Claim claim){
|
||||
public void addSubClaimGriefprevention(Claim claim) {
|
||||
claim.setClaimID(this.generateUUID());
|
||||
claim.parent = this.claimID;
|
||||
claim.parentClaim = this;
|
||||
@ -242,36 +242,35 @@ public class Claim {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean deleteSubClaim(Claim claim){
|
||||
public boolean deleteSubClaim(Claim claim) {
|
||||
return this.subClaims.remove(claim);
|
||||
}
|
||||
|
||||
public List<Claim> getAllSubclaims(){
|
||||
public List<Claim> getAllSubclaims() {
|
||||
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();
|
||||
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);
|
||||
Set<Claim> conflicts = Sets.newHashSet();
|
||||
for(Claim other : this.subClaims)
|
||||
for (Claim other : this.subClaims)
|
||||
if (!claim.equals(other) && newClaim.intersects(other))
|
||||
conflicts.add(other);
|
||||
if(conflicts.isEmpty())
|
||||
if (conflicts.isEmpty())
|
||||
claim.copySizes(newClaim);
|
||||
return conflicts;
|
||||
}
|
||||
|
||||
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;
|
||||
if (group == null) {
|
||||
this.playersGroups.remove(player);
|
||||
this.setDirty();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!this.playersGroups.containsKey(player) || force) {
|
||||
this.playersGroups.put(player, group);
|
||||
this.setDirty();
|
||||
@ -377,18 +376,13 @@ public class Claim {
|
||||
this.globalPerm.clear();
|
||||
this.permissions.clear();
|
||||
this.subClaims.clear();
|
||||
if(obj.has("Parent"))
|
||||
if (obj.has("Parent"))
|
||||
this.parent = UUID.fromString(obj.get("Parent").getAsString());
|
||||
if (obj.has("GlobalPerms")) {
|
||||
if(this.parent==null) {
|
||||
obj.getAsJsonArray("GlobalPerms").forEach(perm -> {
|
||||
this.globalPerm.put(EnumPermission.valueOf(perm.getAsString()), true);
|
||||
});
|
||||
}
|
||||
else{
|
||||
obj.getAsJsonObject("GlobalPerms").entrySet().forEach(entry->{
|
||||
this.globalPerm.put(EnumPermission.valueOf(entry.getKey()), entry.getValue().getAsBoolean());
|
||||
});
|
||||
if (this.parent == null) {
|
||||
obj.getAsJsonArray("GlobalPerms").forEach(perm -> this.globalPerm.put(EnumPermission.valueOf(perm.getAsString()), true));
|
||||
} else {
|
||||
obj.getAsJsonObject("GlobalPerms").entrySet().forEach(entry -> this.globalPerm.put(EnumPermission.valueOf(entry.getKey()), entry.getValue().getAsBoolean()));
|
||||
}
|
||||
}
|
||||
if (obj.has("PermGroup")) {
|
||||
@ -418,22 +412,19 @@ public class Claim {
|
||||
pos.add(this.minY);
|
||||
obj.add("PosxXzZY", pos);
|
||||
obj.addProperty("ID", this.claimID.toString());
|
||||
if(this.parent!=null)
|
||||
if (this.parent != null)
|
||||
obj.addProperty("Parent", this.parent.toString());
|
||||
if (!this.globalPerm.isEmpty()) {
|
||||
JsonElement gPerm;
|
||||
if(this.parent==null) {
|
||||
if (this.parent == null) {
|
||||
gPerm = new JsonArray();
|
||||
this.globalPerm.forEach((perm, bool) -> {
|
||||
if (bool)
|
||||
((JsonArray) gPerm).add(perm.toString());
|
||||
});
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
gPerm = new JsonObject();
|
||||
this.globalPerm.forEach((perm, bool) -> {
|
||||
((JsonObject) gPerm).addProperty(perm.toString(), bool);
|
||||
});
|
||||
this.globalPerm.forEach((perm, bool) -> ((JsonObject) gPerm).addProperty(perm.toString(), bool));
|
||||
}
|
||||
obj.add("GlobalPerms", gPerm);
|
||||
}
|
||||
@ -461,7 +452,7 @@ public class Claim {
|
||||
|
||||
@Override
|
||||
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
|
||||
@ -470,9 +461,9 @@ public class Claim {
|
||||
return true;
|
||||
if (obj instanceof Claim) {
|
||||
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());
|
||||
if(this.claimID!=null)
|
||||
if (this.claimID != null)
|
||||
return this.claimID.equals(((Claim) obj).claimID);
|
||||
}
|
||||
return false;
|
||||
@ -480,21 +471,21 @@ public class Claim {
|
||||
|
||||
@Override
|
||||
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() {
|
||||
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());
|
||||
List<Text> l = Lists.newArrayList();
|
||||
l.add(PermHelper.simpleColoredText("=============================================", Formatting.GREEN));
|
||||
GameProfile prof = this.owner!=null?player.getServer().getUserCache().getByUuid(this.owner):null;
|
||||
String ownerName = this.owner==null?"Admin":prof!=null?prof.getName():"<UNKNOWN>";
|
||||
GameProfile prof = this.owner != null ? player.getServer().getUserCache().getByUuid(this.owner) : null;
|
||||
String ownerName = this.owner == null ? "Admin" : prof != null ? prof.getName() : "<UNKNOWN>";
|
||||
l.add(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(ConfigHandler.lang.claimGroupInfoHeader, Formatting.RED));
|
||||
Map<String, List<String>> nameToGroup = Maps.newHashMap();
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.flemmli97.flan.claim;
|
||||
|
||||
import com.flemmli97.flan.IClaimData;
|
||||
import com.flemmli97.flan.config.Config;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.player.EnumDisplayType;
|
||||
import com.flemmli97.flan.player.EnumEditMode;
|
||||
@ -62,7 +61,7 @@ public class ClaimStorage {
|
||||
Set<Claim> conflicts = conflicts(claim, null);
|
||||
if (conflicts.isEmpty()) {
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
@ -77,7 +76,7 @@ public class ClaimStorage {
|
||||
return true;
|
||||
}
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
@ -99,12 +98,12 @@ public class ClaimStorage {
|
||||
}
|
||||
|
||||
public boolean deleteClaim(Claim claim, boolean updateClaim, EnumEditMode mode, ServerWorld world) {
|
||||
if(mode==EnumEditMode.SUBCLAIM){
|
||||
if(claim.parentClaim()!=null)
|
||||
if (mode == EnumEditMode.SUBCLAIM) {
|
||||
if (claim.parentClaim() != null)
|
||||
return claim.parentClaim().deleteSubClaim(claim);
|
||||
return false;
|
||||
}
|
||||
if(updateClaim)
|
||||
if (updateClaim)
|
||||
claim.remove();
|
||||
int[] pos = getChunkPos(claim);
|
||||
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) {
|
||||
int[] dims = claim.getDimensions(); //BlockPos from, BlockPos to
|
||||
BlockPos opposite = new BlockPos(dims[0]==from.getX()?dims[1]:dims[0], dims[4], dims[2]==from.getZ()?dims[3]:dims[2]);
|
||||
int[] dims = claim.getDimensions();
|
||||
BlockPos opposite = new BlockPos(dims[0] == from.getX() ? dims[1] : dims[0], dims[4], dims[2] == from.getZ() ? dims[3] : dims[2]);
|
||||
Claim newClaim = new Claim(opposite, to, player.getUuid(), player.getServerWorld());
|
||||
Set<Claim> conflicts = conflicts(newClaim, claim);
|
||||
if(!conflicts.isEmpty()) {
|
||||
conflicts.forEach(conf->PlayerClaimData.get(player).addDisplayClaim(conf, EnumDisplayType.CONFLICT, player.getBlockPos().getY()));
|
||||
if (!conflicts.isEmpty()) {
|
||||
conflicts.forEach(conf -> PlayerClaimData.get(player).addDisplayClaim(conf, EnumDisplayType.CONFLICT, player.getBlockPos().getY()));
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
|
||||
return false;
|
||||
}
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
int diff = newClaim.getPlane()-claim.getPlane();
|
||||
if(data.canUseClaimBlocks(diff)) {
|
||||
int diff = newClaim.getPlane() - claim.getPlane();
|
||||
if (data.canUseClaimBlocks(diff)) {
|
||||
this.deleteClaim(claim, false, EnumEditMode.DEFAULT, player.getServerWorld());
|
||||
claim.copySizes(newClaim);
|
||||
this.addClaim(claim);
|
||||
@ -206,7 +205,7 @@ public class ClaimStorage {
|
||||
reader.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -225,15 +224,14 @@ public class ClaimStorage {
|
||||
continue;
|
||||
file.createNewFile();
|
||||
dirty = true;
|
||||
}
|
||||
else {
|
||||
for(Claim claim : e.getValue())
|
||||
if(claim.isDirty()) {
|
||||
} else {
|
||||
for (Claim claim : e.getValue())
|
||||
if (claim.isDirty()) {
|
||||
dirty = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(dirty){
|
||||
if (dirty) {
|
||||
FileWriter writer = new FileWriter(file);
|
||||
JsonArray arr = new JsonArray();
|
||||
e.getValue().forEach(claim -> arr.add(claim.toJson(new JsonObject())));
|
||||
@ -242,15 +240,15 @@ public class ClaimStorage {
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void readGriefPreventionData(MinecraftServer server) {
|
||||
public static List<String> readGriefPreventionData(MinecraftServer server) {
|
||||
Yaml yml = new Yaml();
|
||||
File griefPrevention = server.getSavePath(WorldSavePath.ROOT).resolve("plugins/GriefPreventionData/ClaimData").toFile();
|
||||
if (!griefPrevention.exists())
|
||||
return;
|
||||
return null;
|
||||
Map<File, List<File>> subClaimMap = 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()) {
|
||||
Pair<ServerWorld, Claim> parentClaim = parseFromYaml(parent, yml, server);
|
||||
List<File> childs = subClaimMap.get(parent);
|
||||
@ -286,11 +285,18 @@ public class ClaimStorage {
|
||||
for (File childF : childs)
|
||||
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) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Pair<ServerWorld, Claim> parseFromYaml(File file, Yaml yml, MinecraftServer server) throws IOException {
|
||||
|
@ -1,8 +0,0 @@
|
||||
package com.flemmli97.flan.claim;
|
||||
|
||||
public enum EnumClaimRank {
|
||||
|
||||
COOWNER,
|
||||
BUILDER,
|
||||
MANAGER
|
||||
}
|
@ -6,8 +6,8 @@ import net.minecraft.item.Items;
|
||||
|
||||
public enum EnumPermission {
|
||||
|
||||
EDITPERMS(Items.COMMAND_BLOCK),
|
||||
EDITCLAIM(ConfigHandler.config.claimingItem),
|
||||
EDITPERMS(Items.COMMAND_BLOCK),
|
||||
BREAK(Items.DIAMOND_PICKAXE),
|
||||
PLACE(Items.GRASS_BLOCK),
|
||||
OPENCONTAINER(Items.CHEST),
|
||||
|
@ -4,16 +4,16 @@ import net.minecraft.particle.DustParticleEffect;
|
||||
|
||||
public class ParticleIndicators {
|
||||
|
||||
public static final DustParticleEffect CLAIMCORNER = new DustParticleEffect(7/255f, 94/255f, 27/255f, 1);
|
||||
public static final DustParticleEffect CLAIMMIDDLE = new DustParticleEffect(9/255f, 186/255f, 51/255f, 1);
|
||||
public static final DustParticleEffect CLAIMCORNER = new DustParticleEffect(194 / 255f, 130 / 255f, 4 / 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 SUBCLAIMMIDDLE = new DustParticleEffect(20/255f, 186/255f, 175/255f, 1);
|
||||
public static final DustParticleEffect SUBCLAIMCORNER = new DustParticleEffect(125 / 255f, 125 / 255f, 125 / 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 EDITCLAIMMIDDLE = new DustParticleEffect(20/255f, 186/255f, 175/255f, 1);
|
||||
public static final DustParticleEffect EDITCLAIMCORNER = new DustParticleEffect(12 / 255f, 110 / 255f, 103 / 255f, 1);
|
||||
public static final DustParticleEffect EDITCLAIMMIDDLE = new DustParticleEffect(20 / 255f, 186 / 255f, 175 / 255f, 1);
|
||||
|
||||
public static final DustParticleEffect SETCORNER = new DustParticleEffect(18/255f, 38/255f, 150/255f, 1);
|
||||
public static final DustParticleEffect SETCORNER = new DustParticleEffect(18 / 255f, 38 / 255f, 150 / 255f, 1);
|
||||
|
||||
public static final DustParticleEffect OVERLAPCLAIM = DustParticleEffect.RED;
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ import java.util.function.Consumer;
|
||||
|
||||
public class PermHelper {
|
||||
|
||||
public static boolean check(ServerPlayerEntity player, BlockPos pos, Claim claim, EnumPermission perm, Consumer<Optional<Boolean>> cons){
|
||||
if(claim==null) {
|
||||
public static boolean check(ServerPlayerEntity player, BlockPos pos, Claim claim, EnumPermission perm, Consumer<Optional<Boolean>> cons) {
|
||||
if (claim == null) {
|
||||
cons.accept(Optional.empty());
|
||||
return false;
|
||||
}
|
||||
@ -26,23 +26,23 @@ public class PermHelper {
|
||||
public static Claim checkReturn(ServerPlayerEntity player, EnumPermission perm, Consumer<Optional<Boolean>> cons) {
|
||||
BlockPos pos = player.getBlockPos();
|
||||
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(pos);
|
||||
return check(player, pos, claim, perm, cons)?claim:null;
|
||||
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);
|
||||
}
|
||||
|
||||
public static Consumer<Optional<Boolean>> genericNoPermMessage(ServerPlayerEntity player){
|
||||
return (b ->{
|
||||
if(!b.isPresent())
|
||||
public static Consumer<Optional<Boolean>> genericNoPermMessage(ServerPlayerEntity player) {
|
||||
return (b -> {
|
||||
if (!b.isPresent())
|
||||
PermHelper.noClaimMessage(player);
|
||||
else if(!b.get())
|
||||
else if (!b.get())
|
||||
player.sendMessage(simpleColoredText(ConfigHandler.lang.noPermission, Formatting.DARK_RED), false);
|
||||
});
|
||||
}
|
||||
|
||||
public static Text simpleColoredText(String text, Formatting... formatting){
|
||||
return new LiteralText(text).setStyle(formatting!=null?Style.EMPTY.withFormatting(formatting):Style.EMPTY);
|
||||
public static Text simpleColoredText(String text, Formatting... formatting) {
|
||||
return new LiteralText(text).setStyle(formatting != null ? Style.EMPTY.withFormatting(formatting) : Style.EMPTY);
|
||||
}
|
||||
}
|
||||
|
@ -66,17 +66,17 @@ public class CommandClaim {
|
||||
addToMainCommand(CommandManager.literal("players"),
|
||||
CommandManager.literal("add").then(CommandManager.argument("group", StringArgumentType.word()).suggests(CommandClaim::groupSuggestion)
|
||||
.then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()).executes(CommandClaim::addPlayer)
|
||||
.then(CommandManager.literal("overwrite").executes(CommandClaim::forceAddPlayer)))),
|
||||
.then(CommandManager.literal("overwrite").executes(CommandClaim::forceAddPlayer)))),
|
||||
CommandManager.literal("remove").then(CommandManager.argument("group", StringArgumentType.word()).suggests(CommandClaim::groupSuggestion)
|
||||
.then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()).suggests((context, build) -> {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
List<String> list = Lists.newArrayList();
|
||||
ServerCommandSource src = context.getSource();
|
||||
ClaimStorage storage = ClaimStorage.get(src.getWorld());
|
||||
Claim claim = storage.getClaimAt(src.getPlayer().getBlockPos());
|
||||
if (claim != null && claim.canInteract(src.getPlayer(), EnumPermission.EDITCLAIM, src.getPlayer().getBlockPos())) {
|
||||
list = claim.playersFromGroup(player.getServer(), "");
|
||||
}
|
||||
ClaimStorage storage = ClaimStorage.get(src.getWorld());
|
||||
Claim claim = storage.getClaimAt(src.getPlayer().getBlockPos());
|
||||
if (claim != null && claim.canInteract(src.getPlayer(), EnumPermission.EDITCLAIM, src.getPlayer().getBlockPos())) {
|
||||
list = claim.playersFromGroup(player.getServer(), "");
|
||||
}
|
||||
return CommandSource.suggestMatching(list, build);
|
||||
}).executes(CommandClaim::removePlayer))))
|
||||
)));
|
||||
@ -89,7 +89,7 @@ public class CommandClaim {
|
||||
return main;
|
||||
}
|
||||
|
||||
private static int reloadConfig(CommandContext<ServerCommandSource> context){
|
||||
private static int reloadConfig(CommandContext<ServerCommandSource> context) {
|
||||
ConfigHandler.reloadConfigs();
|
||||
context.getSource().sendFeedback(Text.of(ConfigHandler.lang.configReload), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
@ -98,19 +98,18 @@ public class CommandClaim {
|
||||
private static int openMenu(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
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));
|
||||
if (claim == null)
|
||||
return 0;
|
||||
ClaimMenuScreenHandler.openClaimMenu(player, claim);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(player.getBlockPos());
|
||||
Claim sub = claim.getSubClaim(player.getBlockPos());
|
||||
if(sub!=null && (claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos()) ||sub.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())))
|
||||
if (sub != null && (claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos()) || sub.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())))
|
||||
ClaimMenuScreenHandler.openClaimMenu(player, sub);
|
||||
else if(claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos()))
|
||||
else if (claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos()))
|
||||
ClaimMenuScreenHandler.openClaimMenu(player, claim);
|
||||
else
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermission, Formatting.DARK_RED), false);
|
||||
@ -124,9 +123,9 @@ public class CommandClaim {
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if (claim == null)
|
||||
return 0;
|
||||
if(data.getEditMode() == EnumEditMode.SUBCLAIM){
|
||||
if (data.getEditMode() == EnumEditMode.SUBCLAIM) {
|
||||
Claim sub = claim.getSubClaim(player.getBlockPos());
|
||||
if(sub!=null){
|
||||
if (sub != null) {
|
||||
List<Text> info = sub.infoString(player);
|
||||
player.sendMessage(PermHelper.simpleColoredText("==SubclaimInfo==", Formatting.AQUA), false);
|
||||
for (Text text : info)
|
||||
@ -144,10 +143,10 @@ public class CommandClaim {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
Claim claim = storage.getClaimAt(player.getBlockPos());
|
||||
boolean check = PermHelper.check(player, player.getBlockPos(), claim, EnumPermission.EDITCLAIM, b ->{
|
||||
if(!b.isPresent())
|
||||
boolean check = PermHelper.check(player, player.getBlockPos(), claim, EnumPermission.EDITCLAIM, b -> {
|
||||
if (!b.isPresent())
|
||||
PermHelper.noClaimMessage(player);
|
||||
else if(!b.get())
|
||||
else if (!b.get())
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaimError, Formatting.DARK_RED), false);
|
||||
else
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaim, Formatting.DARK_RED), false);
|
||||
@ -164,7 +163,7 @@ public class CommandClaim {
|
||||
if (data.confirmedDeleteAll()) {
|
||||
for (ServerWorld world : player.getServer().getWorlds()) {
|
||||
ClaimStorage storage = ClaimStorage.get(world);
|
||||
storage.allClaimsFromPlayer(player.getUuid()).forEach((claim)->storage.deleteClaim(claim, 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);
|
||||
data.setConfirmDeleteAll(false);
|
||||
@ -179,19 +178,19 @@ public class CommandClaim {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
Claim claim = storage.getClaimAt(player.getBlockPos());
|
||||
if(claim==null) {
|
||||
if (claim == null) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
|
||||
return 0;
|
||||
}
|
||||
Claim sub = claim.getSubClaim(player.getBlockPos());
|
||||
if(sub==null) {
|
||||
if (sub == null) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
|
||||
return 0;
|
||||
}
|
||||
boolean check = PermHelper.check(player, player.getBlockPos(), sub, EnumPermission.EDITCLAIM, b ->{
|
||||
if(!b.isPresent())
|
||||
boolean check = PermHelper.check(player, player.getBlockPos(), sub, EnumPermission.EDITCLAIM, b -> {
|
||||
if (!b.isPresent())
|
||||
PermHelper.noClaimMessage(player);
|
||||
else if(!b.get())
|
||||
else if (!b.get())
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaimError, Formatting.DARK_RED), false);
|
||||
else
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteSubClaim, Formatting.DARK_RED), false);
|
||||
@ -205,7 +204,7 @@ public class CommandClaim {
|
||||
private static int deleteAllSubClaim(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
Claim claim = PermHelper.checkReturn(player, EnumPermission.EDITCLAIM, PermHelper.genericNoPermMessage(player));
|
||||
if(claim==null)
|
||||
if (claim == null)
|
||||
return 0;
|
||||
List<Claim> subs = claim.getAllSubclaims();
|
||||
subs.forEach(claim::deleteSubClaim);
|
||||
@ -213,7 +212,7 @@ public class CommandClaim {
|
||||
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();
|
||||
Map<World, Collection<Claim>> claims = Maps.newHashMap();
|
||||
for (ServerWorld world : player.getServer().getWorlds()) {
|
||||
@ -231,7 +230,7 @@ public class CommandClaim {
|
||||
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();
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
data.setEditMode(data.getEditMode() == EnumEditMode.DEFAULT ? EnumEditMode.SUBCLAIM : EnumEditMode.DEFAULT);
|
||||
@ -239,7 +238,7 @@ public class CommandClaim {
|
||||
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();
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
data.setAdminIgnoreClaim(!data.isAdminIgnoreClaim());
|
||||
@ -247,7 +246,7 @@ public class CommandClaim {
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int adminDelete(CommandContext<ServerCommandSource> context){
|
||||
private static int adminDelete(CommandContext<ServerCommandSource> context) {
|
||||
ServerCommandSource src = context.getSource();
|
||||
ClaimStorage storage = ClaimStorage.get(src.getWorld());
|
||||
Claim claim = storage.getClaimAt(new BlockPos(src.getPosition()));
|
||||
@ -255,10 +254,10 @@ public class CommandClaim {
|
||||
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
|
||||
return 0;
|
||||
}
|
||||
if(src.getEntity() instanceof ServerPlayerEntity){
|
||||
if (src.getEntity() instanceof ServerPlayerEntity) {
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) src.getEntity();
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if(!data.confirmedDeleteAll()) {
|
||||
if (!data.confirmedDeleteAll()) {
|
||||
data.setConfirmDeleteAll(true);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteAllClaimConfirm, Formatting.DARK_RED), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
@ -271,20 +270,20 @@ public class CommandClaim {
|
||||
|
||||
private static int adminDeleteAll(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerCommandSource src = context.getSource();
|
||||
if(src.getEntity() instanceof ServerPlayerEntity){
|
||||
if (src.getEntity() instanceof ServerPlayerEntity) {
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) src.getEntity();
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if(!data.confirmedDeleteAll()) {
|
||||
if (!data.confirmedDeleteAll()) {
|
||||
data.setConfirmDeleteAll(true);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteAllClaimConfirm, Formatting.DARK_RED), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
List<String> players = Lists.newArrayList();
|
||||
for(GameProfile prof : GameProfileArgumentType.getProfileArgument(context, "players")) {
|
||||
for (GameProfile prof : GameProfileArgumentType.getProfileArgument(context, "players")) {
|
||||
for (ServerWorld world : src.getWorld().getServer().getWorlds()) {
|
||||
ClaimStorage storage = ClaimStorage.get(world);
|
||||
storage.allClaimsFromPlayer(prof.getId()).forEach((claim)->storage.deleteClaim(claim, true, EnumEditMode.DEFAULT, world));
|
||||
storage.allClaimsFromPlayer(prof.getId()).forEach((claim) -> storage.deleteClaim(claim, true, EnumEditMode.DEFAULT, world));
|
||||
}
|
||||
players.add(prof.getName());
|
||||
}
|
||||
@ -292,7 +291,7 @@ public class CommandClaim {
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int setAdminClaim(CommandContext<ServerCommandSource> context){
|
||||
private static int setAdminClaim(CommandContext<ServerCommandSource> context) {
|
||||
ServerCommandSource src = context.getSource();
|
||||
ClaimStorage storage = ClaimStorage.get(src.getWorld());
|
||||
Claim claim = storage.getClaimAt(new BlockPos(src.getPosition()));
|
||||
@ -305,12 +304,15 @@ public class CommandClaim {
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int readGriefPreventionData(CommandContext<ServerCommandSource> context){
|
||||
private static int readGriefPreventionData(CommandContext<ServerCommandSource> context) {
|
||||
ServerCommandSource src = context.getSource();
|
||||
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.readGriefpreventionData, Formatting.GOLD), true);
|
||||
ClaimStorage.readGriefPreventionData(src.getMinecraftServer());
|
||||
List<String> errors = ClaimStorage.readGriefPreventionData(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;
|
||||
}
|
||||
|
||||
@ -318,7 +320,7 @@ public class CommandClaim {
|
||||
ServerCommandSource src = context.getSource();
|
||||
List<String> players = Lists.newArrayList();
|
||||
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());
|
||||
if (player != null) {
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
@ -360,20 +362,18 @@ public class CommandClaim {
|
||||
PermHelper.noClaimMessage(player);
|
||||
return 0;
|
||||
}
|
||||
if(remove) {
|
||||
if (remove) {
|
||||
if (claim.removePermGroup(player, group))
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.groupRemove, group), Formatting.GOLD), false);
|
||||
else {
|
||||
PermHelper.genericNoPermMessage(player);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(claim.groups().contains(group)){
|
||||
} else {
|
||||
if (claim.groups().contains(group)) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.groupExist, group), Formatting.RED), false);
|
||||
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);
|
||||
else {
|
||||
PermHelper.genericNoPermMessage(player);
|
||||
@ -405,16 +405,16 @@ public class CommandClaim {
|
||||
PermHelper.noClaimMessage(player);
|
||||
return 0;
|
||||
}
|
||||
if(!claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())){
|
||||
if (!claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())) {
|
||||
PermHelper.genericNoPermMessage(player);
|
||||
return 0;
|
||||
}
|
||||
List<String> modified = Lists.newArrayList();
|
||||
for(GameProfile prof :GameProfileArgumentType.getProfileArgument(context, "players")){
|
||||
if(claim.setPlayerGroup(prof.getId(), group, force))
|
||||
for (GameProfile prof : GameProfileArgumentType.getProfileArgument(context, "players")) {
|
||||
if (claim.setPlayerGroup(prof.getId(), group, force))
|
||||
modified.add(prof.getName());
|
||||
}
|
||||
if(!modified.isEmpty())
|
||||
if (!modified.isEmpty())
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.playerModify, group, modified), Formatting.GOLD), false);
|
||||
else
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.playerModifyNo, group, modified), Formatting.RED), false);
|
||||
|
@ -8,7 +8,6 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.lwjgl.system.CallbackI;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@ -25,7 +24,7 @@ public class Config {
|
||||
public int minClaimsize = 100;
|
||||
public int defaultClaimDepth = 255;
|
||||
|
||||
public String[] blacklistedWorlds = new String[] {"minecraft:the_nether"};
|
||||
public String[] blacklistedWorlds = new String[0];
|
||||
public boolean worldWhitelist;
|
||||
|
||||
public Item claimingItem = Items.GOLDEN_HOE;
|
||||
@ -36,10 +35,10 @@ public class Config {
|
||||
public Config(MinecraftServer server) {
|
||||
File configDir = server.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile();
|
||||
try {
|
||||
if(!configDir.exists())
|
||||
if (!configDir.exists())
|
||||
configDir.mkdirs();
|
||||
this.config = new File(configDir, "flan_config.json");
|
||||
if(!this.config.exists()) {
|
||||
if (!this.config.exists()) {
|
||||
this.config.createNewFile();
|
||||
this.save();
|
||||
}
|
||||
@ -60,7 +59,7 @@ public class Config {
|
||||
this.defaultClaimDepth = obj.get("defaultClaimDepth").getAsInt();
|
||||
JsonArray arr = obj.getAsJsonArray("blacklistedWorlds");
|
||||
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.worldWhitelist = obj.get("worldWhitelist").getAsBoolean();
|
||||
this.claimingItem = Registry.ITEM.get(new Identifier((obj.get("claimingItem").getAsString())));
|
||||
|
@ -17,7 +17,7 @@ public class ConfigHandler {
|
||||
reloadConfigs();
|
||||
}
|
||||
|
||||
public static void reloadConfigs(){
|
||||
public static void reloadConfigs() {
|
||||
config.load();
|
||||
lang.load();
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
package com.flemmli97.flan.config;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
@ -59,6 +57,7 @@ public class LangConfig {
|
||||
public String setAdminClaim = "Claim changed to an Adminclaim";
|
||||
public String readGriefpreventionData = "Reading data from GriefPrevention";
|
||||
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 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) {
|
||||
File configDir = server.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile();
|
||||
try {
|
||||
if(!configDir.exists())
|
||||
if (!configDir.exists())
|
||||
configDir.mkdirs();
|
||||
this.config = new File(configDir, "flan_lang.json");
|
||||
if(!this.config.exists()) {
|
||||
if (!this.config.exists()) {
|
||||
this.config.createNewFile();
|
||||
this.save();
|
||||
}
|
||||
@ -87,8 +86,8 @@ public class LangConfig {
|
||||
FileReader reader = new FileReader(this.config);
|
||||
JsonObject obj = ConfigHandler.GSON.fromJson(reader, JsonObject.class);
|
||||
reader.close();
|
||||
for(Field field : this.getClass().getDeclaredFields()){
|
||||
if(field.getDeclaringClass().equals(String.class)){
|
||||
for (Field field : this.getClass().getDeclaredFields()) {
|
||||
if (field.getDeclaringClass().equals(String.class)) {
|
||||
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();
|
||||
try {
|
||||
for(Field field : this.getClass().getDeclaredFields()){
|
||||
if(field.getType().equals(String.class)){
|
||||
for (Field field : this.getClass().getDeclaredFields()) {
|
||||
if (field.getType().equals(String.class)) {
|
||||
obj.addProperty(field.getName(), (String) field.get(this));
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
package com.flemmli97.flan.event;
|
||||
|
||||
import com.flemmli97.flan.claim.BlockToPermissionMap;
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.EnumPermission;
|
||||
import com.flemmli97.flan.claim.BlockToPermissionMap;
|
||||
import com.flemmli97.flan.claim.PermHelper;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.gui.LockedLecternScreenHandler;
|
||||
import com.flemmli97.flan.player.EnumDisplayType;
|
||||
@ -20,10 +19,7 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.ToolItem;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.ActionResult;
|
||||
@ -74,12 +70,12 @@ public class BlockInteractEvents {
|
||||
BlockEntity blockEntity = world.getBlockEntity(hitResult.getBlockPos());
|
||||
if (blockEntity != null) {
|
||||
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;
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
if(blockEntity instanceof LecternBlockEntity) {
|
||||
if (blockEntity instanceof LecternBlockEntity) {
|
||||
if (claim.canInteract(player, EnumPermission.LECTERNTAKE, hitResult.getBlockPos(), false))
|
||||
return ActionResult.PASS;
|
||||
if (state.get(LecternBlock.HAS_BOOK))
|
||||
@ -89,16 +85,15 @@ public class BlockInteractEvents {
|
||||
}
|
||||
EnumPermission perm = BlockToPermissionMap.getFromBlock(state.getBlock());
|
||||
//Pressureplate handled elsewhere
|
||||
if (perm!=null && perm != EnumPermission.PRESSUREPLATE) {
|
||||
if(claim.canInteract(player, perm, hitResult.getBlockPos(), true))
|
||||
if (perm != null && perm != EnumPermission.PRESSUREPLATE) {
|
||||
if (claim.canInteract(player, perm, hitResult.getBlockPos(), true))
|
||||
return ActionResult.PASS;
|
||||
if(state.getBlock() instanceof DoorBlock){
|
||||
if (state.getBlock() instanceof DoorBlock) {
|
||||
DoubleBlockHalf half = state.get(DoorBlock.HALF);
|
||||
if(half==DoubleBlockHalf.LOWER) {
|
||||
if (half == DoubleBlockHalf.LOWER) {
|
||||
BlockState other = world.getBlockState(hitResult.getBlockPos().up());
|
||||
player.world.updateListeners(hitResult.getBlockPos().up(), other, other, 2);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
BlockState other = world.getBlockState(hitResult.getBlockPos().down());
|
||||
player.world.updateListeners(hitResult.getBlockPos().down(), other, other, 2);
|
||||
}
|
||||
@ -111,7 +106,7 @@ public class BlockInteractEvents {
|
||||
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)
|
||||
return false;
|
||||
if (entity instanceof ServerPlayerEntity) {
|
||||
@ -137,7 +132,7 @@ public class BlockInteractEvents {
|
||||
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)
|
||||
return false;
|
||||
if (entity instanceof ServerPlayerEntity) {
|
||||
@ -159,7 +154,7 @@ public class BlockInteractEvents {
|
||||
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)
|
||||
return false;
|
||||
ServerWorld serverWorld = (ServerWorld) world;
|
||||
|
@ -1,32 +1,27 @@
|
||||
package com.flemmli97.flan.event;
|
||||
|
||||
import com.flemmli97.flan.claim.BlockToPermissionMap;
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.EnumPermission;
|
||||
import com.flemmli97.flan.claim.BlockToPermissionMap;
|
||||
import com.flemmli97.flan.mixin.IPersistentProjectileVars;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.boss.WitherEntity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.damage.EntityDamageSource;
|
||||
import net.minecraft.entity.decoration.ArmorStandEntity;
|
||||
import net.minecraft.entity.decoration.ItemFrameEntity;
|
||||
import net.minecraft.entity.mob.Monster;
|
||||
import net.minecraft.entity.passive.VillagerEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.projectile.ArrowEntity;
|
||||
import net.minecraft.entity.projectile.PersistentProjectileEntity;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
import net.minecraft.entity.projectile.TridentEntity;
|
||||
import net.minecraft.entity.projectile.thrown.EnderPearlEntity;
|
||||
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
|
||||
import net.minecraft.entity.vehicle.BoatEntity;
|
||||
import net.minecraft.entity.vehicle.MinecartEntity;
|
||||
import net.minecraft.entity.vehicle.StorageMinecartEntity;
|
||||
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
|
||||
import net.minecraft.server.ServerTask;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
@ -61,14 +56,13 @@ public class EntityInteractEvents {
|
||||
}
|
||||
|
||||
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;
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
BlockPos pos = entity.getBlockPos();
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
if (claim != null) {
|
||||
//works
|
||||
if (entity instanceof BoatEntity)
|
||||
return claim.canInteract(player, EnumPermission.BOAT, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
if (entity instanceof AbstractMinecartEntity) {
|
||||
@ -80,7 +74,6 @@ public class EntityInteractEvents {
|
||||
return claim.canInteract(player, EnumPermission.TRADING, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
if (entity instanceof ItemFrameEntity)
|
||||
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 ActionResult.PASS;
|
||||
@ -107,7 +100,7 @@ public class EntityInteractEvents {
|
||||
return false;
|
||||
boolean flag = !claim.canInteract(player, perm, pos, true);
|
||||
if (flag) {
|
||||
if(proj instanceof PersistentProjectileEntity) {
|
||||
if (proj instanceof PersistentProjectileEntity) {
|
||||
PersistentProjectileEntity pers = (PersistentProjectileEntity) proj;
|
||||
((IPersistentProjectileVars) pers).setInBlockState(pers.world.getBlockState(pos));
|
||||
Vec3d vec3d = blockRes.getPos().subtract(pers.getX(), pers.getY(), pers.getZ());
|
||||
@ -123,11 +116,12 @@ public class EntityInteractEvents {
|
||||
pers.setShotFromCrossbow(false);
|
||||
((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)));
|
||||
}
|
||||
return flag;
|
||||
} else if (res.getType() == HitResult.Type.ENTITY){
|
||||
if(proj instanceof EnderPearlEntity) {
|
||||
} else if (res.getType() == HitResult.Type.ENTITY) {
|
||||
if (proj instanceof EnderPearlEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) proj.world);
|
||||
Claim claim = storage.getClaimAt(proj.getBlockPos());
|
||||
return claim.canInteract(player, EnumPermission.ENDERPEARL, proj.getBlockPos(), true);
|
||||
@ -138,13 +132,12 @@ public class EntityInteractEvents {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean hurtEntity(LivingEntity entity, DamageSource source){
|
||||
if(source.getAttacker() instanceof ServerPlayerEntity)
|
||||
return attackSimple((ServerPlayerEntity) source.getAttacker(), entity, false)!=ActionResult.PASS;
|
||||
else if(source.isExplosive() && !entity.world.isClient){
|
||||
public static boolean preventDamage(LivingEntity entity, DamageSource source) {
|
||||
if (source.getAttacker() instanceof ServerPlayerEntity)
|
||||
return attackSimple((ServerPlayerEntity) source.getAttacker(), entity, false) != ActionResult.PASS;
|
||||
else if (source.isExplosive() && !entity.world.isClient) {
|
||||
Claim claim = ClaimStorage.get((ServerWorld) entity.world).getClaimAt(entity.getBlockPos());
|
||||
if(claim!=null && !claim.canInteract(null, EnumPermission.EXPLOSIONS, entity.getBlockPos()))
|
||||
return true;
|
||||
return claim != null && !claim.canInteract(null, EnumPermission.EXPLOSIONS, entity.getBlockPos());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -11,18 +11,13 @@ import com.flemmli97.flan.player.PlayerClaimData;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.LecternBlock;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.BucketItem;
|
||||
import net.minecraft.item.EndCrystalItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.ToolItem;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerInteractionManager;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
@ -65,30 +60,31 @@ public class ItemInteractEvents {
|
||||
if (claim == null)
|
||||
return TypedActionResult.pass(stack);
|
||||
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)
|
||||
return claim.canInteract(player, EnumPermission.BUCKET, pos, true) ? TypedActionResult.pass(stack) : TypedActionResult.fail(stack);
|
||||
return TypedActionResult.pass(stack);
|
||||
}
|
||||
|
||||
private static 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())
|
||||
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())
|
||||
return ActionResult.PASS;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) context.getWorld());
|
||||
BlockPos placePos = context.getBlockPos().offset(context.getSide());
|
||||
Claim claim = storage.getClaimAt(placePos);
|
||||
if(claim==null)
|
||||
if (claim == null)
|
||||
return ActionResult.PASS;
|
||||
if(blackListedItems.contains(context.getStack().getItem()))
|
||||
if (blackListedItems.contains(context.getStack().getItem()))
|
||||
return ActionResult.PASS;
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) context.getPlayer();
|
||||
if(context.getStack().getItem() == Items.END_CRYSTAL) {
|
||||
if(claim.canInteract(player, EnumPermission.ENDCRYSTALPLACE, placePos, true))
|
||||
if (context.getStack().getItem() == Items.END_CRYSTAL) {
|
||||
if (claim.canInteract(player, EnumPermission.ENDCRYSTALPLACE, placePos, true))
|
||||
return ActionResult.PASS;
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
if(claim.canInteract(player, EnumPermission.PLACE, placePos, true))
|
||||
if (claim.canInteract(player, EnumPermission.PLACE, placePos, true))
|
||||
return ActionResult.PASS;
|
||||
BlockState other = context.getWorld().getBlockState(placePos.up());
|
||||
player.world.updateListeners(placePos.up(), other, other, 2);
|
||||
@ -96,23 +92,22 @@ public class ItemInteractEvents {
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
|
||||
private static boolean cantClaimInWorld(ServerWorld world){
|
||||
for(String s : ConfigHandler.config.blacklistedWorlds){
|
||||
if(s.equals(world.getRegistryKey().getValue().toString())) {
|
||||
private static boolean cantClaimInWorld(ServerWorld world) {
|
||||
for (String s : ConfigHandler.config.blacklistedWorlds) {
|
||||
if (s.equals(world.getRegistryKey().getValue().toString())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void claimLandHandling(ServerPlayerEntity player, BlockPos target){
|
||||
if(ConfigHandler.config.worldWhitelist){
|
||||
if(!cantClaimInWorld(player.getServerWorld())) {
|
||||
public static void claimLandHandling(ServerPlayerEntity player, BlockPos target) {
|
||||
if (ConfigHandler.config.worldWhitelist) {
|
||||
if (!cantClaimInWorld(player.getServerWorld())) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.landClaimDisabledWorld, Formatting.DARK_RED), false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if(cantClaimInWorld(player.getServerWorld())) {
|
||||
} else if (cantClaimInWorld(player.getServerWorld())) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.landClaimDisabledWorld, Formatting.DARK_RED), false);
|
||||
return;
|
||||
}
|
||||
@ -123,34 +118,31 @@ public class ItemInteractEvents {
|
||||
if (claim.canInteract(player, EnumPermission.EDITCLAIM, target)) {
|
||||
if (data.getEditMode() == EnumEditMode.SUBCLAIM) {
|
||||
Claim subClaim = claim.getSubClaim(target);
|
||||
if (subClaim != null && data.currentEdit()==null) {
|
||||
if (subClaim != null && data.currentEdit() == null) {
|
||||
if (subClaim.isCorner(target)) {
|
||||
data.setEditClaim(subClaim, player.getBlockPos().getY());
|
||||
data.setEditingCorner(target);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeClaim, Formatting.GOLD), false);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, Formatting.RED), false);
|
||||
}
|
||||
} else {
|
||||
if(data.currentEdit()!=null){
|
||||
if (data.currentEdit() != null) {
|
||||
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()));
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
|
||||
}
|
||||
data.setEditClaim(null, 0);
|
||||
data.setEditingCorner(null);
|
||||
}
|
||||
else if (data.editingCorner() != null) {
|
||||
} else if (data.editingCorner() != null) {
|
||||
Set<Claim> fl = claim.tryCreateSubClaim(data.editingCorner(), target);
|
||||
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()));
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.subClaimCreateSuccess, Formatting.GOLD), false);
|
||||
}
|
||||
data.setEditingCorner(null);
|
||||
@ -162,13 +154,11 @@ public class ItemInteractEvents {
|
||||
data.setEditClaim(claim, player.getBlockPos().getY());
|
||||
data.setEditingCorner(target);
|
||||
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);
|
||||
data.setEditClaim(null, 0);
|
||||
data.setEditingCorner(null);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
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());
|
||||
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);
|
||||
}
|
||||
else {
|
||||
if(data.currentEdit()!=null){
|
||||
} else {
|
||||
if (data.currentEdit() != null) {
|
||||
storage.resizeClaim(data.currentEdit(), data.editingCorner(), target, player);
|
||||
data.setEditClaim(null, 0);
|
||||
data.setEditingCorner(null);
|
||||
}
|
||||
else if (data.editingCorner() != null) {
|
||||
} else if (data.editingCorner() != null) {
|
||||
storage.createClaim(data.editingCorner(), target, player);
|
||||
data.setEditingCorner(null);
|
||||
}
|
||||
else
|
||||
} else
|
||||
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);
|
||||
if (claim != null) {
|
||||
String owner = claim.getOwner()==null?"<Admin>":"<UNKOWN>";
|
||||
if(claim.getOwner()!=null) {
|
||||
String owner = claim.getOwner() == null ? "<Admin>" : "<UNKOWN>";
|
||||
if (claim.getOwner() != null) {
|
||||
GameProfile prof = player.getServer().getUserCache().getByUuid(claim.getOwner());
|
||||
if (prof != null && prof.getName() != null)
|
||||
owner = prof.getName();
|
||||
|
@ -3,7 +3,6 @@ package com.flemmli97.flan.gui;
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.player.EnumEditMode;
|
||||
import com.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
@ -30,7 +29,6 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
|
||||
}
|
||||
|
||||
public static void openClaimMenu(ServerPlayerEntity player, Claim claim) {
|
||||
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
@Override
|
||||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
|
||||
@ -39,7 +37,7 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
|
||||
|
||||
@Override
|
||||
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);
|
||||
@ -98,11 +96,20 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
|
||||
break;
|
||||
case 8:
|
||||
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);
|
||||
player.getServer().execute(() -> ConfirmScreenHandler.openConfirmScreen(player, (bool) -> {
|
||||
if (bool) {
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
storage.deleteClaim(this.claim, true, PlayerClaimData.get(player).getEditMode(), player.getServerWorld());
|
||||
player.closeHandledScreen();
|
||||
player.sendMessage(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;
|
||||
}
|
||||
return true;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
package com.flemmli97.flan.gui;
|
||||
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.PermHelper;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.mixin.ILecternBlockValues;
|
||||
import net.minecraft.block.LecternBlock;
|
||||
import net.minecraft.block.entity.LecternBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
@ -27,7 +25,7 @@ public class LockedLecternScreenHandler extends LecternScreenHandler {
|
||||
NamedScreenHandlerFactory fac = new NamedScreenHandlerFactory() {
|
||||
@Override
|
||||
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
|
||||
@ -40,7 +38,7 @@ public class LockedLecternScreenHandler extends LecternScreenHandler {
|
||||
|
||||
@Override
|
||||
public boolean onButtonClick(PlayerEntity player, int id) {
|
||||
if(id==3) {
|
||||
if (id == 3) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false);
|
||||
return false;
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Style;
|
||||
@ -88,7 +87,7 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void flipPage(){
|
||||
private void flipPage() {
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
@ -96,20 +95,19 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
|
||||
this.slots.get(i).setStack(close);
|
||||
} else if (i == 47) {
|
||||
ItemStack stack = ItemStack.EMPTY;
|
||||
if(this.page == 1){
|
||||
stack =new ItemStack(Items.ARROW);
|
||||
if (this.page == 1) {
|
||||
stack = new ItemStack(Items.ARROW);
|
||||
stack.setCustomName(new LiteralText("Prev").setStyle(Style.EMPTY.withFormatting(Formatting.WHITE)));
|
||||
}
|
||||
this.slots.get(i).setStack(stack);
|
||||
} else if (i == 51) {
|
||||
ItemStack stack = ItemStack.EMPTY;
|
||||
if(this.page == 0) {
|
||||
if (this.page == 0) {
|
||||
stack = new ItemStack(Items.ARROW);
|
||||
stack.setCustomName(new LiteralText("Next").setStyle(Style.EMPTY.withFormatting(Formatting.WHITE)));
|
||||
}
|
||||
this.slots.get(i).setStack(stack);
|
||||
}
|
||||
else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
} else if (i < 9 || i > 44 || i % 9 == 0 || i % 9 == 8)
|
||||
this.slots.get(i).setStack(ServerScreenHelper.emptyFiller());
|
||||
else {
|
||||
int row = i / 9 - 1;
|
||||
@ -155,14 +153,13 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
|
||||
return false;
|
||||
}
|
||||
if (this.group == null) {
|
||||
int mode = -1;
|
||||
if(this.claim.parentClaim()==null)
|
||||
mode = this.claim.permEnabled(perm)==1?-1:1;
|
||||
int mode;
|
||||
if (this.claim.parentClaim() == null)
|
||||
mode = this.claim.permEnabled(perm) == 1 ? -1 : 1;
|
||||
else
|
||||
mode = this.claim.permEnabled(perm)+1;
|
||||
mode = this.claim.permEnabled(perm) + 1;
|
||||
this.claim.editGlobalPerms(perm, mode);
|
||||
}
|
||||
else
|
||||
} else
|
||||
this.claim.editPerms(player, this.group, perm, this.claim.groupHasPerm(this.group, perm) + 1);
|
||||
slot.setStack(ServerScreenHelper.fromPermission(this.claim, perm, this.group));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_NOTE_BLOCK_PLING, 1, 1.2f);
|
||||
|
@ -30,7 +30,7 @@ public abstract class ServerOnlyScreenHandler extends ScreenHandler {
|
||||
int m;
|
||||
for (n = 0; n < rows; ++n) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@ import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.text.LiteralText;
|
||||
@ -30,8 +29,8 @@ public class ServerScreenHelper {
|
||||
ListTag lore = new ListTag();
|
||||
String permFlag;
|
||||
if (group == null) {
|
||||
if(claim.parentClaim()==null)
|
||||
permFlag = "" + (claim.permEnabled(perm)==1);
|
||||
if (claim.parentClaim() == null)
|
||||
permFlag = "" + (claim.permEnabled(perm) == 1);
|
||||
else {
|
||||
switch (claim.permEnabled(perm)) {
|
||||
case -1:
|
||||
@ -45,8 +44,7 @@ public class ServerScreenHelper {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
switch (claim.groupHasPerm(group, perm)) {
|
||||
case -1:
|
||||
permFlag = "default";
|
||||
|
@ -17,7 +17,7 @@ public abstract class AbstractBlockStateMixin {
|
||||
|
||||
@Inject(method = "onEntityCollision", at = @At(value = "HEAD"), cancellable = true)
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@ public abstract class FluidMixin {
|
||||
|
||||
@Inject(method = "canFlow", at = @At(value = "HEAD"), cancellable = true)
|
||||
public void crossClaimFlow(BlockView world, BlockPos fluidPos, BlockState fluidBlockState, Direction flowDirection, BlockPos flowTo,
|
||||
BlockState flowToBlockState, FluidState fluidState, Fluid fluid, CallbackInfoReturnable<Boolean> info){
|
||||
if(!WorldEvents.canFlow(fluidBlockState, world, fluidPos, flowDirection)){
|
||||
BlockState flowToBlockState, FluidState fluidState, Fluid fluid, CallbackInfoReturnable<Boolean> info) {
|
||||
if (!WorldEvents.canFlow(fluidBlockState, world, fluidPos, flowDirection)) {
|
||||
info.setReturnValue(false);
|
||||
info.cancel();
|
||||
}
|
||||
|
@ -1,20 +1,17 @@
|
||||
package com.flemmli97.flan.mixin;
|
||||
|
||||
import net.minecraft.block.entity.LecternBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.screen.PropertyDelegate;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(LecternBlockEntity.class)
|
||||
public interface ILecternBlockValues {
|
||||
|
||||
@Accessor("inventory")
|
||||
public Inventory getInv();
|
||||
Inventory getInv();
|
||||
|
||||
@Accessor("propertyDelegate")
|
||||
public PropertyDelegate getProp();
|
||||
PropertyDelegate getProp();
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
public abstract class ItemStackMixin {
|
||||
|
||||
@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);
|
||||
if (result != ActionResult.PASS) {
|
||||
info.setReturnValue(result);
|
||||
|
@ -6,15 +6,14 @@ import net.minecraft.entity.damage.DamageSource;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
public abstract class LivingEntityMixin {
|
||||
|
||||
@Inject(method = "damage", at = @At(value = "HEAD"), cancellable = true)
|
||||
public void onDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> info){
|
||||
if(EntityInteractEvents.hurtEntity((LivingEntity)(Object)this, source)) {
|
||||
public void onDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> info) {
|
||||
if (EntityInteractEvents.preventDamage((LivingEntity) (Object) this, source)) {
|
||||
info.setReturnValue(false);
|
||||
info.cancel();
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.flemmli97.flan.mixin;
|
||||
|
||||
import com.flemmli97.flan.event.WorldEvents;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.PistonBlock;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
@ -16,8 +15,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
public class PistonMixin {
|
||||
|
||||
@Inject(method = "isMovable", at = @At(value = "HEAD"), cancellable = true)
|
||||
private static void checkMovable(BlockState blockState, World world, BlockPos blockPos, Direction direction, boolean canBreak, Direction pistonDir, CallbackInfoReturnable<Boolean> info){
|
||||
if(!WorldEvents.pistonCanPush(blockState, world, blockPos, direction, pistonDir)) {
|
||||
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)) {
|
||||
info.setReturnValue(false);
|
||||
info.cancel();
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public abstract class TurtleEggMixin {
|
||||
|
||||
@Inject(method = "onSteppedOn", at = @At(value = "HEAD"), cancellable = true)
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -9,16 +9,16 @@ import net.minecraft.block.BlockState;
|
||||
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
|
||||
import net.minecraft.particle.DustParticleEffect;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ClaimDisplay {
|
||||
|
||||
private int displayTime, height;
|
||||
private int displayTime;
|
||||
private final int height;
|
||||
private final Claim toDisplay;
|
||||
public final EnumDisplayType type;
|
||||
private int[][] poss;
|
||||
@ -28,13 +28,14 @@ public class ClaimDisplay {
|
||||
private int[] prevDims;
|
||||
|
||||
private final DustParticleEffect corner, middle;
|
||||
|
||||
public ClaimDisplay(Claim claim, EnumDisplayType type, int y) {
|
||||
this.toDisplay = claim;
|
||||
this.displayTime = ConfigHandler.config.claimDisplayTime;
|
||||
this.prevDims = claim.getDimensions();
|
||||
this.type = type;
|
||||
this.height = y;
|
||||
switch (type){
|
||||
switch (type) {
|
||||
case SUB:
|
||||
this.corner = ParticleIndicators.SUBCLAIMCORNER;
|
||||
this.middle = ParticleIndicators.SUBCLAIMMIDDLE;
|
||||
@ -60,16 +61,16 @@ public class ClaimDisplay {
|
||||
if (this.poss == null || this.changed(dims)) {
|
||||
this.middlePoss = calculateDisplayPos(player.getServerWorld(), dims, this.height);
|
||||
this.poss = new int[][]{
|
||||
this.getPosFrom(player.getServerWorld(), dims[0], dims[2], this.height),
|
||||
this.getPosFrom(player.getServerWorld(), dims[1], dims[2], this.height),
|
||||
this.getPosFrom(player.getServerWorld(), dims[0], dims[3], this.height),
|
||||
this.getPosFrom(player.getServerWorld(), dims[1], dims[3], this.height),
|
||||
getPosFrom(player.getServerWorld(), dims[0], dims[2], this.height),
|
||||
getPosFrom(player.getServerWorld(), dims[1], dims[2], this.height),
|
||||
getPosFrom(player.getServerWorld(), dims[0], dims[3], this.height),
|
||||
getPosFrom(player.getServerWorld(), dims[1], dims[3], this.height),
|
||||
};
|
||||
}
|
||||
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));
|
||||
}
|
||||
if(this.middlePoss!=null)
|
||||
if (this.middlePoss != null)
|
||||
for (int[] pos : this.middlePoss) {
|
||||
player.networkHandler.sendPacket(new ParticleS2CPacket(this.middle, true, pos[0] + 0.5, pos[1] + 0.25, pos[2] + 0.5, 0, 0.25f, 0, 0, 1));
|
||||
}
|
||||
@ -88,12 +89,12 @@ public class ClaimDisplay {
|
||||
List<int[]> l = Lists.newArrayList();
|
||||
Set<Integer> xs = Sets.newHashSet();
|
||||
addEvenly(from[0], from[1], 10, xs);
|
||||
xs.add(from[0]+1);
|
||||
xs.add(from[1]-1);
|
||||
xs.add(from[0] + 1);
|
||||
xs.add(from[1] - 1);
|
||||
Set<Integer> zs = Sets.newHashSet();
|
||||
addEvenly(from[2], from[3], 10, zs);
|
||||
zs.add(from[2]+1);
|
||||
zs.add(from[3]-1);
|
||||
zs.add(from[2] + 1);
|
||||
zs.add(from[3] - 1);
|
||||
for (int x : xs) {
|
||||
l.add(getPosFrom(world, x, from[2], height));
|
||||
l.add(getPosFrom(world, x, from[3], height));
|
||||
@ -125,19 +126,18 @@ public class ClaimDisplay {
|
||||
return new int[]{x, y, z};
|
||||
}
|
||||
|
||||
private static int nextAirBlockFrom(ServerWorld world, int x, int y, int z){
|
||||
BlockPos pos = new BlockPos(x,y,z);
|
||||
private static int nextAirBlockFrom(ServerWorld world, int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
BlockState state = world.getBlockState(pos);
|
||||
if(state.getMaterial().isReplaceable()){
|
||||
if (state.getMaterial().isReplaceable()) {
|
||||
pos = pos.down();
|
||||
while(world.getBlockState(pos).getMaterial().isReplaceable()){
|
||||
while (world.getBlockState(pos).getMaterial().isReplaceable()) {
|
||||
pos = pos.down();
|
||||
}
|
||||
pos = pos.up();
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
pos = pos.up();
|
||||
while(!world.getBlockState(pos).getMaterial().isReplaceable()){
|
||||
while (!world.getBlockState(pos).getMaterial().isReplaceable()) {
|
||||
pos = pos.up();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.flemmli97.flan.player;
|
||||
|
||||
public enum EnumEditMode {
|
||||
|
||||
DEFAULT,
|
||||
SUBCLAIM
|
||||
}
|
||||
|
@ -22,8 +22,6 @@ import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -83,12 +81,10 @@ public class PlayerClaimData {
|
||||
|
||||
public boolean canUseClaimBlocks(int amount) {
|
||||
int usedClaimsBlocks = this.usedClaimBlocks();
|
||||
if (usedClaimsBlocks + amount > this.claimBlocks + this.additionalClaimBlocks)
|
||||
return false;
|
||||
return true;
|
||||
return usedClaimsBlocks + amount <= this.claimBlocks + this.additionalClaimBlocks;
|
||||
}
|
||||
|
||||
public int usedClaimBlocks(){
|
||||
public int usedClaimBlocks() {
|
||||
return this.calculateUsedClaimBlocks();
|
||||
}
|
||||
|
||||
@ -97,7 +93,7 @@ public class PlayerClaimData {
|
||||
}
|
||||
|
||||
public void setEditClaim(Claim claim, int height) {
|
||||
if(claim!=null)
|
||||
if (claim != null)
|
||||
this.displayEditing = new ClaimDisplay(claim, EnumDisplayType.EDIT, height);
|
||||
else
|
||||
this.displayEditing = null;
|
||||
@ -106,8 +102,8 @@ public class PlayerClaimData {
|
||||
|
||||
public void addDisplayClaim(Claim claim, EnumDisplayType type, int height) {
|
||||
this.displayToAdd.add(new ClaimDisplay(claim, type, height));
|
||||
if(type==EnumDisplayType.MAIN)
|
||||
for(Claim sub : claim.getAllSubclaims())
|
||||
if (type == EnumDisplayType.MAIN)
|
||||
for (Claim sub : claim.getAllSubclaims())
|
||||
this.displayToAdd.add(new ClaimDisplay(sub, EnumDisplayType.SUB, height));
|
||||
}
|
||||
|
||||
@ -154,9 +150,9 @@ public class PlayerClaimData {
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
this.displayToAdd.forEach(add->{
|
||||
if(!this.claimDisplayList.add(add)){
|
||||
this.claimDisplayList.removeIf(c->c.equals(add) && c.type!=add.type);
|
||||
this.displayToAdd.forEach(add -> {
|
||||
if (!this.claimDisplayList.add(add)) {
|
||||
this.claimDisplayList.removeIf(c -> c.equals(add) && c.type != add.type);
|
||||
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));
|
||||
if (--this.confirmTick < 0)
|
||||
this.confirmDeleteAll = false;
|
||||
if(this.displayEditing!=null)
|
||||
if (this.displayEditing != null)
|
||||
this.displayEditing.display(this.player);
|
||||
if (this.player.getMainHandStack().getItem() != ConfigHandler.config.claimingItem && this.player.getOffHandStack().getItem() != ConfigHandler.config.claimingItem) {
|
||||
this.firstCorner = null;
|
||||
@ -195,7 +191,7 @@ public class PlayerClaimData {
|
||||
ConfigHandler.GSON.toJson(obj, writer);
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,7 +209,7 @@ public class PlayerClaimData {
|
||||
this.additionalClaimBlocks = obj.get("AdditionalBlocks").getAsInt();
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,7 +232,7 @@ public class PlayerClaimData {
|
||||
ConfigHandler.GSON.toJson(obj, writer);
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -285,7 +281,7 @@ public class PlayerClaimData {
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@
|
||||
"TurtleEggMixin",
|
||||
"XpEntityMixin",
|
||||
"WitherMixin",
|
||||
"ExplosionMixin",
|
||||
"EnderPearlEntityMixin",
|
||||
"IPersistentProjectileVars",
|
||||
"LivingEntityMixin",
|
||||
|
Loading…
Reference in New Issue
Block a user