some logging stuff. and option to disable claim blocks
This commit is contained in:
parent
87d3a99908
commit
adc28e46ba
@ -1,3 +1,8 @@
|
|||||||
|
Flan 1.0.8
|
||||||
|
======================
|
||||||
|
- Add some logging stuff. Mostly with read/saving things
|
||||||
|
- Add option to disable the need for claim blocks by setting maxClaimBlocks to -1 in the configs
|
||||||
|
|
||||||
Flan 1.0.8
|
Flan 1.0.8
|
||||||
======================
|
======================
|
||||||
- Changed using wrong tupel
|
- Changed using wrong tupel
|
||||||
|
@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx2G
|
|||||||
loader_version=0.9.1+build.205
|
loader_version=0.9.1+build.205
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.0.8
|
mod_version = 1.0.9
|
||||||
maven_group = com.flemmli97.flan
|
maven_group = com.flemmli97.flan
|
||||||
archives_base_name = flan
|
archives_base_name = flan
|
||||||
|
|
||||||
|
@ -14,9 +14,13 @@ import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
|
|||||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||||
import net.fabricmc.fabric.api.event.player.UseEntityCallback;
|
import net.fabricmc.fabric.api.event.player.UseEntityCallback;
|
||||||
import net.fabricmc.fabric.api.event.player.UseItemCallback;
|
import net.fabricmc.fabric.api.event.player.UseItemCallback;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
public class Flan implements ModInitializer {
|
public class Flan implements ModInitializer {
|
||||||
|
|
||||||
|
public static final Logger logger = LogManager.getLogger("flan");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
PlayerBlockBreakEvents.BEFORE.register(BlockInteractEvents::breakBlocks);
|
PlayerBlockBreakEvents.BEFORE.register(BlockInteractEvents::breakBlocks);
|
||||||
@ -29,4 +33,9 @@ public class Flan implements ModInitializer {
|
|||||||
|
|
||||||
CommandRegistrationCallback.EVENT.register(CommandClaim::register);
|
CommandRegistrationCallback.EVENT.register(CommandClaim::register);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void log(String msg, Object... o){
|
||||||
|
logger.info(msg, o);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -513,7 +513,7 @@ public class Claim {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("Claim:[ID=%s, Owner=%s, from: x=%d; z=%d, to: x=%d, z=%d", this.claimID != null ? this.claimID.toString() : "null", this.owner != null ? this.owner.toString() : "Admin", 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 != null ? this.owner.toString() : "Admin", this.minX, this.minZ, this.maxX, this.maxZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String formattedClaim() {
|
public String formattedClaim() {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.flemmli97.flan.claim;
|
package com.flemmli97.flan.claim;
|
||||||
|
|
||||||
|
import com.flemmli97.flan.Flan;
|
||||||
import com.flemmli97.flan.IClaimData;
|
import com.flemmli97.flan.IClaimData;
|
||||||
import com.flemmli97.flan.config.ConfigHandler;
|
import com.flemmli97.flan.config.ConfigHandler;
|
||||||
import com.flemmli97.flan.player.EnumDisplayType;
|
import com.flemmli97.flan.player.EnumDisplayType;
|
||||||
@ -78,6 +79,7 @@ public class ClaimStorage {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
claim.setClaimID(this.generateUUID());
|
claim.setClaimID(this.generateUUID());
|
||||||
|
Flan.log("Creating new claim {}", claim);
|
||||||
this.addClaim(claim);
|
this.addClaim(claim);
|
||||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.claimCreateSuccess, Formatting.GOLD), false);
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.claimCreateSuccess, Formatting.GOLD), false);
|
||||||
@ -111,6 +113,7 @@ public class ClaimStorage {
|
|||||||
return claim.parentClaim().deleteSubClaim(claim);
|
return claim.parentClaim().deleteSubClaim(claim);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Flan.log("Try deleting claim {}", claim);
|
||||||
if (updateClaim)
|
if (updateClaim)
|
||||||
claim.remove();
|
claim.remove();
|
||||||
int[] pos = getChunkPos(claim);
|
int[] pos = getChunkPos(claim);
|
||||||
@ -129,6 +132,7 @@ public class ClaimStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void toggleAdminClaim(ServerPlayerEntity player, Claim claim, boolean toggle) {
|
public void toggleAdminClaim(ServerPlayerEntity player, Claim claim, boolean toggle) {
|
||||||
|
Flan.log("Set claim {} to an admin claim", claim);
|
||||||
this.deleteClaim(claim, false, EnumEditMode.DEFAULT, player.getServerWorld());
|
this.deleteClaim(claim, false, EnumEditMode.DEFAULT, player.getServerWorld());
|
||||||
claim.toggleAdminClaim(player, toggle);
|
claim.toggleAdminClaim(player, toggle);
|
||||||
this.addClaim(claim);
|
this.addClaim(claim);
|
||||||
@ -147,6 +151,7 @@ public class ClaimStorage {
|
|||||||
PlayerClaimData data = PlayerClaimData.get(player);
|
PlayerClaimData data = PlayerClaimData.get(player);
|
||||||
int diff = newClaim.getPlane() - claim.getPlane();
|
int diff = newClaim.getPlane() - claim.getPlane();
|
||||||
if (data.canUseClaimBlocks(diff)) {
|
if (data.canUseClaimBlocks(diff)) {
|
||||||
|
Flan.log("Resizing claim {}", claim);
|
||||||
this.deleteClaim(claim, false, EnumEditMode.DEFAULT, player.getServerWorld());
|
this.deleteClaim(claim, false, EnumEditMode.DEFAULT, player.getServerWorld());
|
||||||
claim.copySizes(newClaim);
|
claim.copySizes(newClaim);
|
||||||
this.addClaim(claim);
|
this.addClaim(claim);
|
||||||
@ -224,6 +229,7 @@ public class ClaimStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void read(MinecraftServer server, ServerWorld world) {
|
public void read(MinecraftServer server, ServerWorld world) {
|
||||||
|
Flan.log("Loading claim data for world {}", world.getRegistryKey());
|
||||||
File dir = new File(DimensionType.getSaveDirectory(world.getRegistryKey(), server.getSavePath(WorldSavePath.ROOT).toFile()), "/data/claims/");
|
File dir = new File(DimensionType.getSaveDirectory(world.getRegistryKey(), server.getSavePath(WorldSavePath.ROOT).toFile()), "/data/claims/");
|
||||||
if (dir.exists()) {
|
if (dir.exists()) {
|
||||||
try {
|
try {
|
||||||
@ -250,6 +256,7 @@ public class ClaimStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save(MinecraftServer server, RegistryKey<World> reg) {
|
public void save(MinecraftServer server, RegistryKey<World> reg) {
|
||||||
|
Flan.log("Saving claims for world {}", reg);
|
||||||
File dir = new File(DimensionType.getSaveDirectory(reg, server.getSavePath(WorldSavePath.ROOT).toFile()), "/data/claims/");
|
File dir = new File(DimensionType.getSaveDirectory(reg, server.getSavePath(WorldSavePath.ROOT).toFile()), "/data/claims/");
|
||||||
if (!dir.exists())
|
if (!dir.exists())
|
||||||
dir.mkdir();
|
dir.mkdir();
|
||||||
@ -436,9 +443,10 @@ public class ClaimStorage {
|
|||||||
accessors.forEach(s -> claim.setPlayerGroup(UUID.fromString(s), "Accessors", true));
|
accessors.forEach(s -> claim.setPlayerGroup(UUID.fromString(s), "Accessors", true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Pair(world, claim);
|
return new Pair<>(world, claim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private static <T> List<T> readList(Map<String, Object> values, String key) {
|
private static <T> List<T> readList(Map<String, Object> values, String key) {
|
||||||
Object obj = values.get(key);
|
Object obj = values.get(key);
|
||||||
if (obj instanceof List)
|
if (obj instanceof List)
|
||||||
|
@ -44,6 +44,7 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
|
|
||||||
public class CommandClaim {
|
public class CommandClaim {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated) {
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated) {
|
||||||
dispatcher.register(addToMainCommand(CommandManager.literal("flan"),
|
dispatcher.register(addToMainCommand(CommandManager.literal("flan"),
|
||||||
CommandManager.literal("reload").executes(CommandClaim::reloadConfig),
|
CommandManager.literal("reload").executes(CommandClaim::reloadConfig),
|
||||||
@ -283,6 +284,7 @@ public class CommandClaim {
|
|||||||
ClaimStorage storage = ClaimStorage.get(world);
|
ClaimStorage storage = ClaimStorage.get(world);
|
||||||
claims.put(world, storage.allClaimsFromPlayer(player != null ? player.getUuid() : of));
|
claims.put(world, storage.allClaimsFromPlayer(player != null ? player.getUuid() : of));
|
||||||
}
|
}
|
||||||
|
if(ConfigHandler.config.maxClaimBlocks != -1) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PlayerClaimData data = PlayerClaimData.get(player);
|
PlayerClaimData data = PlayerClaimData.get(player);
|
||||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
||||||
@ -292,6 +294,7 @@ public class CommandClaim {
|
|||||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
||||||
data.claimBlocks, data.additionalClaimBlocks, data.getUsedClaimBlocks(server)), Formatting.GOLD), false);
|
data.claimBlocks, data.additionalClaimBlocks, data.getUsedClaimBlocks(server)), Formatting.GOLD), false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.listClaims, Formatting.GOLD), false);
|
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.listClaims, Formatting.GOLD), false);
|
||||||
for (Map.Entry<World, Collection<Claim>> entry : claims.entrySet())
|
for (Map.Entry<World, Collection<Claim>> entry : claims.entrySet())
|
||||||
for (Claim claim : entry.getValue())
|
for (Claim claim : entry.getValue())
|
||||||
|
@ -7,15 +7,12 @@ import net.minecraft.item.Item;
|
|||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.WorldSavePath;
|
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
|
|
||||||
@ -36,6 +33,8 @@ public class Config {
|
|||||||
public int claimDisplayTime = 1000;
|
public int claimDisplayTime = 1000;
|
||||||
public int permissionLevel = 2;
|
public int permissionLevel = 2;
|
||||||
|
|
||||||
|
public boolean log;
|
||||||
|
|
||||||
public Config(MinecraftServer server) {
|
public Config(MinecraftServer server) {
|
||||||
File configDir = FabricLoader.getInstance().getConfigDir().resolve("flan").toFile();
|
File configDir = FabricLoader.getInstance().getConfigDir().resolve("flan").toFile();
|
||||||
//.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile();
|
//.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile();
|
||||||
@ -70,6 +69,7 @@ public class Config {
|
|||||||
this.claimingItem = Registry.ITEM.get(new Identifier((obj.get("claimingItem").getAsString())));
|
this.claimingItem = Registry.ITEM.get(new Identifier((obj.get("claimingItem").getAsString())));
|
||||||
this.inspectionItem = Registry.ITEM.get(new Identifier((obj.get("inspectionItem").getAsString())));
|
this.inspectionItem = Registry.ITEM.get(new Identifier((obj.get("inspectionItem").getAsString())));
|
||||||
this.claimDisplayTime = obj.get("claimDisplayTime").getAsInt();
|
this.claimDisplayTime = obj.get("claimDisplayTime").getAsInt();
|
||||||
|
this.log = obj.has("enableLogs") && obj.get("enableLogs").getAsBoolean();
|
||||||
if (obj.has("permissionLevel"))
|
if (obj.has("permissionLevel"))
|
||||||
this.permissionLevel = obj.get("permissionLevel").getAsInt();
|
this.permissionLevel = obj.get("permissionLevel").getAsInt();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -92,6 +92,7 @@ public class Config {
|
|||||||
obj.addProperty("inspectionItem", Registry.ITEM.getId(this.inspectionItem).toString());
|
obj.addProperty("inspectionItem", Registry.ITEM.getId(this.inspectionItem).toString());
|
||||||
obj.addProperty("claimDisplayTime", this.claimDisplayTime);
|
obj.addProperty("claimDisplayTime", this.claimDisplayTime);
|
||||||
obj.addProperty("permissionLevel", this.permissionLevel);
|
obj.addProperty("permissionLevel", this.permissionLevel);
|
||||||
|
obj.addProperty("enableLogs", this.log);
|
||||||
try {
|
try {
|
||||||
FileWriter writer = new FileWriter(this.config);
|
FileWriter writer = new FileWriter(this.config);
|
||||||
ConfigHandler.GSON.toJson(obj, writer);
|
ConfigHandler.GSON.toJson(obj, writer);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.flemmli97.flan.player;
|
package com.flemmli97.flan.player;
|
||||||
|
|
||||||
|
import com.flemmli97.flan.Flan;
|
||||||
import com.flemmli97.flan.IClaimData;
|
import com.flemmli97.flan.IClaimData;
|
||||||
import com.flemmli97.flan.claim.Claim;
|
import com.flemmli97.flan.claim.Claim;
|
||||||
import com.flemmli97.flan.claim.ClaimStorage;
|
import com.flemmli97.flan.claim.ClaimStorage;
|
||||||
@ -84,6 +85,8 @@ public class PlayerClaimData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean canUseClaimBlocks(int amount) {
|
public boolean canUseClaimBlocks(int amount) {
|
||||||
|
if(ConfigHandler.config.maxClaimBlocks==-1)
|
||||||
|
return true;
|
||||||
int usedClaimsBlocks = this.usedClaimBlocks();
|
int usedClaimsBlocks = this.usedClaimBlocks();
|
||||||
return usedClaimsBlocks + amount <= this.claimBlocks + this.additionalClaimBlocks;
|
return usedClaimsBlocks + amount <= this.claimBlocks + this.additionalClaimBlocks;
|
||||||
}
|
}
|
||||||
@ -198,6 +201,7 @@ public class PlayerClaimData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save(MinecraftServer server) {
|
public void save(MinecraftServer server) {
|
||||||
|
Flan.log("Saving player data for player {} with uuid {}", this.player.getName(), this.player.getUuid());
|
||||||
File dir = new File(server.getSavePath(WorldSavePath.PLAYERDATA).toFile(), "/claimData/");
|
File dir = new File(server.getSavePath(WorldSavePath.PLAYERDATA).toFile(), "/claimData/");
|
||||||
if (!dir.exists())
|
if (!dir.exists())
|
||||||
dir.mkdirs();
|
dir.mkdirs();
|
||||||
@ -219,13 +223,16 @@ public class PlayerClaimData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void read(MinecraftServer server) {
|
public void read(MinecraftServer server) {
|
||||||
|
Flan.log("Reading player data for player {} with uuid {}", this.player.getName(), this.player.getUuid());
|
||||||
File dir = new File(server.getSavePath(WorldSavePath.PLAYERDATA).toFile(), "/claimData/");
|
File dir = new File(server.getSavePath(WorldSavePath.PLAYERDATA).toFile(), "/claimData/");
|
||||||
if (!dir.exists())
|
if (!dir.exists())
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
File file = new File(dir, this.player.getUuid() + ".json");
|
File file = new File(dir, this.player.getUuid() + ".json");
|
||||||
if (!file.exists())
|
if (!file.exists()) {
|
||||||
|
Flan.log("No player data found for player {} with uuid {}", this.player.getName(), this.player.getUuid());
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
FileReader reader = new FileReader(file);
|
FileReader reader = new FileReader(file);
|
||||||
JsonObject obj = ConfigHandler.GSON.fromJson(reader, JsonObject.class);
|
JsonObject obj = ConfigHandler.GSON.fromJson(reader, JsonObject.class);
|
||||||
this.claimBlocks = obj.get("ClaimBlocks").getAsInt();
|
this.claimBlocks = obj.get("ClaimBlocks").getAsInt();
|
||||||
@ -237,6 +244,7 @@ public class PlayerClaimData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void editForOfflinePlayer(MinecraftServer server, UUID uuid, int additionalClaimBlocks) {
|
public static void editForOfflinePlayer(MinecraftServer server, UUID uuid, int additionalClaimBlocks) {
|
||||||
|
Flan.log("Adding {} addional claimblocks for offline player with uuid {}", additionalClaimBlocks, uuid);
|
||||||
File dir = new File(server.getSavePath(WorldSavePath.PLAYERDATA).toFile(), "/claimData/");
|
File dir = new File(server.getSavePath(WorldSavePath.PLAYERDATA).toFile(), "/claimData/");
|
||||||
if (!dir.exists())
|
if (!dir.exists())
|
||||||
dir.mkdirs();
|
dir.mkdirs();
|
||||||
|
Loading…
Reference in New Issue
Block a user