clean ups

This commit is contained in:
Flemmli97 2020-08-23 15:16:26 +02:00
parent 014f65bc86
commit fdbdd5cfb0
19 changed files with 51 additions and 68 deletions

1
.gitignore vendored
View File

@ -27,3 +27,4 @@ bin/
# fabric
run/
logs/

View File

@ -1,9 +1,3 @@
# Fabric Example Mod
# Flan
## Setup
For setup instructions please see the [fabric wiki page](https://fabricmc.net/wiki/tutorial:setup) that relates to the IDE that you are using.
## License
This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects.
Server side land claiming mod for fabric

View File

@ -205,8 +205,8 @@ public class Claim {
if (player.getUuid().equals(this.owner) || this.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())) {
if (mode > 1)
mode = -1;
boolean has = this.permissions.containsKey(perm);
EnumMap<EnumPermission, Boolean> perms = has ? this.permissions.get(group) : new EnumMap(EnumPermission.class);
boolean has = this.permissions.containsKey(group);
EnumMap<EnumPermission, Boolean> perms = has ? this.permissions.get(group) : new EnumMap<>(EnumPermission.class);
if (mode == -1)
perms.remove(perm);
else
@ -227,7 +227,7 @@ public class Claim {
if (g.equals(group))
toRemove.add(uuid);
});
toRemove.forEach(uuid -> this.playersGroups.remove(uuid));
toRemove.forEach(this.playersGroups::remove);
this.setDirty();
return true;
}
@ -276,7 +276,7 @@ public class Claim {
if (obj.has("PermGroup")) {
JsonObject perms = obj.getAsJsonObject("PermGroup");
perms.entrySet().forEach(key -> {
EnumMap<EnumPermission, Boolean> map = new EnumMap(EnumPermission.class);
EnumMap<EnumPermission, Boolean> map = new EnumMap<>(EnumPermission.class);
JsonObject group = key.getValue().getAsJsonObject();
group.entrySet().forEach(gkey -> map.put(EnumPermission.valueOf(gkey.getKey()), gkey.getValue().getAsBoolean()));
this.permissions.put(key.getKey(), map);
@ -377,7 +377,7 @@ public class Claim {
if (tag.contains("PermGroup")) {
CompoundTag perms = tag.getCompound("PermGroup");
perms.getKeys().forEach(key -> {
EnumMap<EnumPermission, Boolean> map = new EnumMap(EnumPermission.class);
EnumMap<EnumPermission, Boolean> map = new EnumMap<>(EnumPermission.class);
CompoundTag group = perms.getCompound(key);
group.getKeys().forEach(gkey -> map.put(EnumPermission.valueOf(gkey), group.getBoolean(gkey)));
this.permissions.put(key, map);

View File

@ -41,7 +41,7 @@ public class ClaimStorage {
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
public final Long2ObjectArrayMap<List<Claim>> claims = new Long2ObjectArrayMap();
public final Long2ObjectArrayMap<List<Claim>> claims = new Long2ObjectArrayMap<>();
public final Map<UUID, Claim> claimUUIDMap = Maps.newHashMap();
public final Map<UUID, Set<Claim>> playerClaimMap = Maps.newHashMap();
@ -240,7 +240,7 @@ public class ClaimStorage {
if (f.getName().endsWith(".yml")) {
FileReader reader = new FileReader(f);
Map<String, Object> values = yml.load(reader);
if (values.get("Parent Claim ID").equals(Integer.valueOf(-1))) {
if (values.get("Parent Claim ID").equals(-1)) {
intFileMap.put(Integer.valueOf(values.get("Parent Claim ID").toString()), f);
}
}
@ -250,7 +250,7 @@ public class ClaimStorage {
if (f.getName().endsWith(".yml")) {
FileReader reader = new FileReader(f);
Map<String, Object> values = yml.load(reader);
if (!values.get("Parent Claim ID").equals(Integer.valueOf(-1))) {
if (!values.get("Parent Claim ID").equals(-1)) {
subClaimMap.merge(intFileMap.get(Integer.valueOf(values.get("Parent Claim ID").toString()))
, Lists.newArrayList(f), (key, val) -> {
val.add(f);

View File

@ -41,7 +41,7 @@ public enum EnumPermission {
ARMORSTAND(Items.ARMOR_STAND),
BREAKNONLIVING(Items.COMMAND_BLOCK_MINECART);
private Item item;
private final Item item;
EnumPermission(Item item) {
this.item = item;

View File

@ -31,7 +31,7 @@ import java.util.Map;
public class ObjectToPermissionMap {
private static Map<Block, EnumPermission> blockToPermission = Maps.newHashMap();
private static final Map<Block, EnumPermission> blockToPermission = Maps.newHashMap();
public static void reload(MinecraftServer server) {
blockToPermission.clear();

View File

@ -71,7 +71,7 @@ public class CommandClaim {
if (data.confirmedDeleteAll()) {
for (ServerWorld world : src.getWorld().getServer().getWorlds()) {
ClaimStorage storage = ClaimStorage.get(world);
storage.allClaimsFromPlayer(src.getPlayer().getUuid()).forEach(claim -> storage.deleteClaim(claim));
storage.allClaimsFromPlayer(src.getPlayer().getUuid()).forEach(storage::deleteClaim);
}
src.getPlayer().sendMessage(Text.of(ConfigHandler.lang.deleteAllClaim), false);
data.setConfirmDeleteAll(false);
@ -133,7 +133,7 @@ public class CommandClaim {
GameProfile prof = it.next();
for (ServerWorld world : src.getWorld().getServer().getWorlds()) {
ClaimStorage storage = ClaimStorage.get(world);
storage.allClaimsFromPlayer(prof.getId()).forEach(claim -> storage.deleteClaim(claim));
storage.allClaimsFromPlayer(prof.getId()).forEach(storage::deleteClaim);
}
players.add(prof.getName());
}

View File

@ -9,7 +9,7 @@ import java.io.File;
public class Config {
private File configDir;
private final File configDir;
public int startingBlocks = 500;
public int maxClaimBlocks = 5000;

View File

@ -7,7 +7,7 @@ import java.io.File;
public class LangConfig {
private File configDir;
private final File configDir;
public String inspectBlockOwner = "This is %1$s's claim";
public String inspectNoClaim = "Nobody owns this block";

View File

@ -69,7 +69,7 @@ public class BlockInteractEvents {
return false;
if (entity instanceof PlayerEntity) {
EnumPermission perm = ObjectToPermissionMap.getFromBlock(state.getBlock());
if (perm == null || (perm != EnumPermission.PRESSUREPLATE && perm != EnumPermission.PORTAL))
if (perm != EnumPermission.PRESSUREPLATE && perm != EnumPermission.PORTAL)
return false;
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
Claim claim = storage.getClaimAt(pos);
@ -77,7 +77,7 @@ public class BlockInteractEvents {
return !claim.canInteract((PlayerEntity) entity, perm, pos);
} else if (entity instanceof ProjectileEntity) {
EnumPermission perm = ObjectToPermissionMap.getFromBlock(state.getBlock());
if (perm == null || (perm != EnumPermission.PRESSUREPLATE && perm != EnumPermission.BUTTONLEVER))
if (perm != EnumPermission.PRESSUREPLATE && perm != EnumPermission.BUTTONLEVER)
return false;
Entity owner = ((ProjectileEntity) entity).getOwner();
if (owner instanceof PlayerEntity) {
@ -97,7 +97,7 @@ public class BlockInteractEvents {
ClaimStorage storage = ClaimStorage.get((ServerWorld) entity.world);
Claim claim = storage.getClaimAt(landedPosition);
EnumPermission perm = ObjectToPermissionMap.getFromBlock(landedState.getBlock());
if (perm != null && perm == EnumPermission.TRAMPLE)
if (perm == EnumPermission.TRAMPLE)
return !claim.canInteract((PlayerEntity) entity, perm, landedPosition);
} else if (entity instanceof ProjectileEntity) {
Entity owner = ((ProjectileEntity) entity).getOwner();
@ -105,7 +105,7 @@ public class BlockInteractEvents {
ClaimStorage storage = ClaimStorage.get((ServerWorld) entity.world);
Claim claim = storage.getClaimAt(landedPosition);
EnumPermission perm = ObjectToPermissionMap.getFromBlock(landedState.getBlock());
if (perm != null && perm == EnumPermission.TRAMPLE)
if (perm == EnumPermission.TRAMPLE)
return !claim.canInteract((PlayerEntity) owner, perm, landedPosition);
}
}

View File

@ -16,10 +16,10 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.PersistentProjectileEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.entity.projectile.thrown.EnderPearlEntity;
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.entity.vehicle.ChestMinecartEntity;
import net.minecraft.entity.vehicle.HopperMinecartEntity;
import net.minecraft.entity.vehicle.MinecartEntity;
import net.minecraft.entity.vehicle.StorageMinecartEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvents;
@ -61,8 +61,8 @@ public class EntityInteractEvents {
//works
if (entity instanceof BoatEntity)
return claim.canInteract(player, EnumPermission.BOAT, pos) ? ActionResult.PASS : ActionResult.FAIL;
if (entity instanceof MinecartEntity) {
if (entity instanceof HopperMinecartEntity || entity instanceof ChestMinecartEntity)
if (entity instanceof AbstractMinecartEntity) {
if (entity instanceof StorageMinecartEntity)
return claim.canInteract(player, EnumPermission.OPENCONTAINER, pos) ? ActionResult.PASS : ActionResult.FAIL;
return claim.canInteract(player, EnumPermission.MINECART, pos) ? ActionResult.PASS : ActionResult.FAIL;
}
@ -89,7 +89,7 @@ public class EntityInteractEvents {
EnumPermission perm = ObjectToPermissionMap.getFromBlock(state.getBlock());
if (proj instanceof EnderPearlEntity)
perm = EnumPermission.ENDERPEARL;
if (perm == null || (perm != EnumPermission.ENDERPEARL && perm != EnumPermission.TARGETBLOCK && perm != EnumPermission.PROJECTILES))
if (perm != EnumPermission.ENDERPEARL && perm != EnumPermission.TARGETBLOCK && perm != EnumPermission.PROJECTILES)
return false;
ClaimStorage storage = ClaimStorage.get((ServerWorld) proj.world);
Claim claim = storage.getClaimAt(pos);

View File

@ -20,7 +20,7 @@ import net.minecraft.util.Formatting;
public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
private Claim claim;
private final Claim claim;
private ClaimMenuScreenHandler(int syncId, PlayerInventory playerInventory, Claim claim) {
super(syncId, playerInventory, 1);

View File

@ -25,8 +25,8 @@ import java.util.List;
public class GroupPlayerScreenHandler extends ServerOnlyScreenHandler {
private Claim claim;
private String group;
private final Claim claim;
private final String group;
private boolean removeMode;
private GroupPlayerScreenHandler(int syncId, PlayerInventory playerInventory, Claim claim, String group) {

View File

@ -21,7 +21,7 @@ import java.util.List;
public class GroupScreenHandler extends ServerOnlyScreenHandler {
private Claim claim;
private final Claim claim;
private boolean removeMode;
@ -125,12 +125,11 @@ public class GroupScreenHandler extends ServerOnlyScreenHandler {
if (clickType == 1) {
player.closeHandledScreen();
player.getServer().execute(() -> PermissionScreenHandler.openClaimMenu(player, this.claim, name));
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
} else {
player.closeHandledScreen();
player.getServer().execute(() -> GroupPlayerScreenHandler.openPlayerGroupMenu(player, this.claim, name));
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
}
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
}
}
return false;

View File

@ -19,9 +19,9 @@ import net.minecraft.util.Formatting;
public class PermissionScreenHandler extends ServerOnlyScreenHandler {
private Claim claim;
private String group;
private int page;
private final Claim claim;
private final String group;
private final int page;
private PermissionScreenHandler(int syncId, PlayerInventory playerInventory, Claim claim, String group, int page) {
super(syncId, playerInventory, 6, claim, group, page);
@ -62,8 +62,6 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
@Override
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Object... additionalData) {
if (additionalData == null)
return;
for (int i = 0; i < 54; i++) {
int page = (int) additionalData[2];
if (i == 0) {
@ -84,7 +82,7 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
int row = i / 9 - 1;
int id = (i % 9) + row * 7 - 1 + page * 54;
if (id < EnumPermission.values().length)
inv.setStack(i, ServerScreenHelper.fromPermission((Claim) additionalData[0], EnumPermission.values()[id], additionalData.length == 1 ? null : String.valueOf(additionalData[1])));
inv.setStack(i, ServerScreenHelper.fromPermission((Claim) additionalData[0], EnumPermission.values()[id], String.valueOf(additionalData[1])));
}
}
}
@ -95,12 +93,11 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
if (this.group == null) {
player.closeHandledScreen();
player.getServer().execute(() -> ClaimMenuScreenHandler.openClaimMenu(player, this.claim));
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
} else {
player.closeHandledScreen();
player.getServer().execute(() -> GroupScreenHandler.openGroupMenu(player, this.claim));
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
}
ServerScreenHelper.playSongToPlayer(player, SoundEvents.UI_BUTTON_CLICK, 1, 1f);
return true;
}
if (index == 47) {

View File

@ -6,6 +6,7 @@ import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerListener;
import net.minecraft.screen.ScreenHandlerType;
@ -13,7 +14,6 @@ import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.server.network.ServerPlayerEntity;
import java.util.Iterator;
import java.util.List;
public abstract class ServerOnlyScreenHandler extends ScreenHandler {
@ -45,7 +45,7 @@ public abstract class ServerOnlyScreenHandler extends ScreenHandler {
}
}
private static ScreenHandlerType fromRows(int rows) {
private static ScreenHandlerType<GenericContainerScreenHandler> fromRows(int rows) {
switch (rows) {
case 2:
return ScreenHandlerType.GENERIC_9X2;
@ -104,10 +104,8 @@ public abstract class ServerOnlyScreenHandler extends ScreenHandler {
int j;
for (j = 0; j < this.slots.size(); ++j) {
ItemStack itemStack = this.slots.get(j).getStack();
Iterator var5 = this.listeners.iterator();
while (var5.hasNext()) {
ScreenHandlerListener screenHandlerListener = (ScreenHandlerListener) var5.next();
for (ScreenHandlerListener screenHandlerListener : this.listeners) {
screenHandlerListener.onSlotUpdate(this, j, itemStack.copy());
}
}

View File

@ -17,7 +17,6 @@ import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import org.apache.commons.lang3.StringUtils;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
@ -113,10 +112,8 @@ public class StringResultScreenHandler extends AnvilScreenHandler {
int j;
for (j = 0; j < this.slots.size(); ++j) {
ItemStack itemStack = this.slots.get(j).getStack();
Iterator var5 = this.listeners.iterator();
while (var5.hasNext()) {
ScreenHandlerListener screenHandlerListener = (ScreenHandlerListener) var5.next();
for (ScreenHandlerListener screenHandlerListener : this.listeners) {
screenHandlerListener.onSlotUpdate(this, j, itemStack.copy());
}
}

View File

@ -16,7 +16,7 @@ import java.util.Set;
public class ClaimDisplay {
private int displayTime;
private Claim toDisplay;
private final Claim toDisplay;
private int[][] poss;
private int[][] middlePoss;
@ -42,14 +42,12 @@ public class ClaimDisplay {
};
}
if (this.poss != null)
for (int[] pos : this.poss) {
player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleIndicators.CLAIMCORNER, true, pos[0] + 0.5, pos[1] + 0.25, pos[2] + 0.5, 0, 0.25f, 0, 0, 1));
}
if (this.middlePoss != null)
for (int[] pos : this.middlePoss) {
player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleIndicators.CLAIMMIDDLE, true, pos[0] + 0.5, pos[1] + 0.25, pos[2] + 0.5, 0, 0.25f, 0, 0, 1));
}
for (int[] pos : this.poss) {
player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleIndicators.CLAIMCORNER, true, pos[0] + 0.5, pos[1] + 0.25, pos[2] + 0.5, 0, 0.25f, 0, 0, 1));
}
for (int[] pos : this.middlePoss) {
player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleIndicators.CLAIMMIDDLE, true, pos[0] + 0.5, pos[1] + 0.25, pos[2] + 0.5, 0, 0.25f, 0, 0, 1));
}
this.prevDims = dims;
return toDisplay.isRemoved() || displayTime < 0;
}

View File

@ -35,10 +35,10 @@ public class PlayerClaimData {
private BlockPos firstCorner;
private Set<ClaimDisplay> claimDisplayList = Sets.newHashSet();
private Set<ClaimDisplay> displayToAdd = Sets.newHashSet();
private final Set<ClaimDisplay> claimDisplayList = Sets.newHashSet();
private final Set<ClaimDisplay> displayToAdd = Sets.newHashSet();
private ServerPlayerEntity player;
private final ServerPlayerEntity player;
private boolean confirmDeleteAll, adminIgnoreClaim;
private boolean dirty;
@ -141,10 +141,9 @@ public class PlayerClaimData {
}
public void tick() {
ServerPlayerEntity sPlayer = this.player;
this.claimDisplayList.addAll(this.displayToAdd);
this.displayToAdd.clear();
this.claimDisplayList.removeIf(d -> d.display(sPlayer));
this.claimDisplayList.removeIf(d -> d.display(this.player));
if (++this.lastBlockTick > ConfigHandler.config.ticksForNextBlock) {
this.addClaimBlocks(1);
this.lastBlockTick = 0;