├── src └── main │ ├── resources │ ├── lang │ │ └── lusiiclaimchunk │ │ │ └── en_US.lang │ ├── icon.png │ ├── lusiiclaimchunk.mixins.json │ └── fabric.mod.json │ └── java │ └── lusii │ └── lusiiclaimchunks │ ├── commands │ ├── TrustAllCommand.java │ ├── UnTrustAllCommand.java │ ├── ListClaims.java │ ├── OPUnTrustCommand.java │ ├── OPTrustCommand.java │ ├── TrustCommand.java │ ├── UnTrustCommand.java │ ├── DelClaimCommand.java │ ├── DeleteAllClaimsCommand.java │ ├── TrustedCommand.java │ ├── OPDelClaimCommand.java │ ├── OPClaimCommand.java │ └── ClaimCommand.java │ ├── mixins │ ├── BlockFluidMixin.java │ ├── ExplosionMixin.java │ ├── CommandsMixin.java │ ├── ItemBucketMixin.java │ ├── ItemBucketEmptyMixin.java │ └── NetServerHandlerMixin.java │ └── LusiiClaimChunks.java ├── .gitignore ├── README.md ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── settings.gradle ├── .editorconfig ├── gradlew.bat ├── gradlew └── LICENSE /src/main/resources/lang/lusiiclaimchunk/en_US.lang: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /run/ 2 | /.gradle/ 3 | /.idea/ 4 | /build/ 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A claim plugin(mod) for the Better than Adventure! mod for b1.7.3! 2 | -------------------------------------------------------------------------------- /src/main/resources/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/preprocessor/LusiiClaimPluginBTA/main/src/main/resources/icon.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/preprocessor/LusiiClaimPluginBTA/main/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx2G 2 | 3 | # BTA 4 | bta_version=7.1-pre2a 5 | 6 | # Loader 7 | loader_version=0.15.6-babric.4-bta 8 | 9 | # HalpLibe 10 | halplibe_version=3.4.16 11 | 12 | # Mod 13 | mod_version=1.3 14 | mod_group=lusii 15 | mod_name=lusiiclaimchunk-useless 16 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | maven { 4 | name = 'Fabric' 5 | url = 'https://maven.fabricmc.net/' 6 | } 7 | gradlePluginPortal() 8 | maven { 9 | name = 'Jitpack' 10 | url = 'https://jitpack.io' 11 | } 12 | maven { 13 | name = 'Babric' 14 | url = 'https://maven.glass-launcher.net/babric' 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /src/main/resources/lusiiclaimchunk.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "minVersion": "0.8", 4 | "package": "lusii.lusiiclaimchunks.mixins", 5 | "compatibilityLevel": "JAVA_8", 6 | "mixins": [ 7 | "NetServerHandlerMixin", 8 | "CommandsMixin", 9 | "ExplosionMixin", 10 | "BlockFluidMixin", 11 | "ItemBucketEmptyMixin", 12 | "ItemBucketMixin" 13 | ], 14 | "client": [ 15 | ], 16 | "injectors": { 17 | "defaultRequire": 1 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | tab_width = 4 8 | trim_trailing_whitespace = true 9 | 10 | [*.md] 11 | trim_trailing_whitespace = false 12 | 13 | [*.gradle] 14 | indent_style = tab 15 | 16 | [*.java] 17 | indent_style = tab 18 | 19 | [*.json] 20 | indent_style = space 21 | indent_size = 2 22 | 23 | [fabric.mod.json] 24 | indent_style = tab 25 | tab_width = 2 26 | 27 | [*.properties] 28 | indent_style = space 29 | indent_size = 2 30 | -------------------------------------------------------------------------------- /src/main/resources/fabric.mod.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "id": "lusiiclaimchunk", 4 | "version": "${version}", 5 | 6 | "name": "Claim Chunks", 7 | "description": "Claim chunks to prevent griefs", 8 | "authors": [ 9 | "Lusii", 10 | "Useless", 11 | "Wyspr" 12 | ], 13 | "contact": { 14 | "homepage": "", 15 | "sources": "" 16 | }, 17 | 18 | "icon": "icon.png", 19 | "license": "CC0-1.0", 20 | 21 | "environment": "*", 22 | "entrypoints": { 23 | "main": [ 24 | "lusii.lusiiclaimchunks.LusiiClaimChunks" 25 | ] 26 | }, 27 | "mixins": [ 28 | "lusiiclaimchunk.mixins.json" 29 | ], 30 | 31 | "depends": { 32 | "minecraft": "~7.1-beta.1", 33 | "fabricloader": ">=0.13.3" 34 | }, 35 | "suggests": { 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/commands/TrustAllCommand.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.commands; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.net.command.Command; 5 | import net.minecraft.core.net.command.CommandHandler; 6 | import net.minecraft.core.net.command.CommandSender; 7 | 8 | public class TrustAllCommand extends Command { 9 | public TrustAllCommand() { 10 | super("trustall","claimtrustall"); 11 | } 12 | // 13 | public boolean execute(CommandHandler handler, CommandSender sender, String[] args) { 14 | String username = sender.getPlayer().username; 15 | String player; 16 | if (args.length == 0) { 17 | return false; 18 | } 19 | player = args[0]; 20 | LusiiClaimChunks.addPlayerToChunkAll(username, player); 21 | sender.sendMessage("§3Player §r"+ player + " §3trusted in all your claims."); 22 | return true; 23 | } 24 | // 25 | public boolean opRequired(String[] args) { 26 | return false; 27 | } 28 | // 29 | public void sendCommandSyntax(CommandHandler handler, CommandSender sender) { 30 | sender.sendMessage("/trustall "); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/commands/UnTrustAllCommand.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.commands; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.net.command.Command; 5 | import net.minecraft.core.net.command.CommandHandler; 6 | import net.minecraft.core.net.command.CommandSender; 7 | 8 | public class UnTrustAllCommand extends Command { 9 | public UnTrustAllCommand() { 10 | super("untrustall","claimuntrustall"); 11 | } 12 | // 13 | public boolean execute(CommandHandler handler, CommandSender sender, String[] args) { 14 | String username = sender.getPlayer().username; 15 | String player; 16 | if (args.length == 0) { 17 | return false; 18 | } 19 | player = args[0]; 20 | LusiiClaimChunks.removePlayerFromChunkAll(username, player); 21 | sender.sendMessage("§3Player §r"+ player + " §3untrusted in all your claims."); 22 | return true; 23 | } 24 | // 25 | public boolean opRequired(String[] args) { 26 | return false; 27 | } 28 | // 29 | public void sendCommandSyntax(CommandHandler handler, CommandSender sender) { 30 | sender.sendMessage("/untrustall "); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/commands/ListClaims.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.commands; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.net.command.Command; 5 | import net.minecraft.core.net.command.CommandHandler; 6 | import net.minecraft.core.net.command.CommandSender; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Objects; 10 | 11 | import static lusii.lusiiclaimchunks.LusiiClaimChunks.deleteAllClaimedChunks; 12 | 13 | public class ListClaims extends Command { 14 | public ListClaims() { 15 | super("listclaims","claims", "claimlist", "listclaim"); 16 | } 17 | // 18 | public boolean execute(CommandHandler handler, CommandSender sender, String[] args) { 19 | String theResults = LusiiClaimChunks.listClaimedChunks(sender.getPlayer().username).toString(); 20 | theResults = theResults.replace(" , ", ", "); 21 | theResults = theResults.replace("[", ""); 22 | theResults = theResults.replace("]", ""); 23 | sender.sendMessage("§3Your claims: §4"+theResults); 24 | 25 | 26 | return true; 27 | } 28 | // 29 | public boolean opRequired(String[] args) { 30 | return false; 31 | } 32 | // 33 | public void sendCommandSyntax(CommandHandler handler, CommandSender sender) { 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/mixins/BlockFluidMixin.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.mixins; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.block.Block; 5 | import net.minecraft.core.block.BlockFluid; 6 | import net.minecraft.core.block.material.Material; 7 | import net.minecraft.core.world.World; 8 | import net.minecraft.core.world.chunk.Chunk; 9 | import org.spongepowered.asm.mixin.Mixin; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.Inject; 12 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 13 | 14 | @Mixin(value = BlockFluid.class, remap = false) 15 | public class BlockFluidMixin extends Block { 16 | public BlockFluidMixin(String key, int id, Material material) { 17 | super(key, id, material); 18 | } 19 | //@Inject(method = "checkForHarden", at = @At("HEAD"), cancellable = true) 20 | //private void checkForHarden(World world, int x, int y, int z, CallbackInfo ci) { 21 | // 22 | // Chunk chunk = world.getChunkFromBlockCoords(x,z); 23 | // int cx = chunk.xPosition; 24 | // int cz = chunk.zPosition; 25 | // if (LusiiClaimChunks.map.get(new LusiiClaimChunks.IntPair(cx, cz)) != null) { 26 | // ci.cancel(); 27 | // return; 28 | // } 29 | //} 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/mixins/ExplosionMixin.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.mixins; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.world.Explosion; 5 | import net.minecraft.core.world.World; 6 | import net.minecraft.core.world.chunk.ChunkPosition; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.Shadow; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Redirect; 11 | 12 | import java.util.Set; 13 | 14 | @Mixin(value = Explosion.class, remap = false) 15 | public class ExplosionMixin { 16 | @Shadow 17 | protected World worldObj; 18 | 19 | @Redirect(method = "calculateBlocksToDestroy()V", at = @At(value = "INVOKE", target = "Ljava/util/Set;add(Ljava/lang/Object;)Z")) 20 | private boolean preventClaimedDestruction(Set instance, Object e){ 21 | ChunkPosition position = (ChunkPosition)e; 22 | LusiiClaimChunks.IntPair intPair = new LusiiClaimChunks.IntPair(worldObj.getChunkFromBlockCoords(position.x,position.z).xPosition,worldObj.getChunkFromBlockCoords(position.x,position.z).zPosition); 23 | if (!LusiiClaimChunks.isChunkClaimed(intPair) || worldObj.dimension.id != 0) { 24 | instance.add(e); 25 | return true; 26 | } 27 | return false; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/commands/OPUnTrustCommand.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.commands; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.net.command.Command; 5 | import net.minecraft.core.net.command.CommandHandler; 6 | import net.minecraft.core.net.command.CommandSender; 7 | 8 | public class OPUnTrustCommand extends Command { 9 | public OPUnTrustCommand() { 10 | super("opuntrust","opclaimuntrust"); 11 | } 12 | // 13 | public boolean execute(CommandHandler handler, CommandSender sender, String[] args) { 14 | int cx = sender.getPlayer().chunkCoordX; 15 | int cz = sender.getPlayer().chunkCoordZ; 16 | LusiiClaimChunks.IntPair intPair = new LusiiClaimChunks.IntPair(cx,cz); 17 | if (args.length == 0) { 18 | return false; 19 | } 20 | if (!LusiiClaimChunks.isChunkClaimed(intPair)) { 21 | sender.sendMessage("§3No one owns this chunk!"); 22 | return true; 23 | } 24 | LusiiClaimChunks.removedPlayerFromChunk(intPair, args[0]); 25 | sender.sendMessage("§ePlayer §r"+ args[0] + " §euntrusted via Operator."); 26 | return true; 27 | } 28 | // 29 | public boolean opRequired(String[] args) { 30 | return true; 31 | } 32 | // 33 | public void sendCommandSyntax(CommandHandler handler, CommandSender sender) { 34 | sender.sendMessage("/opuntrust "); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/commands/OPTrustCommand.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.commands; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.net.command.Command; 5 | import net.minecraft.core.net.command.CommandHandler; 6 | import net.minecraft.core.net.command.CommandSender; 7 | 8 | public class OPTrustCommand extends Command { 9 | public OPTrustCommand() { 10 | super("optrust","opclaimtrust"); 11 | } 12 | // 13 | public boolean execute(CommandHandler handler, CommandSender sender, String[] args) { 14 | int cx = sender.getPlayer().chunkCoordX; 15 | int cz = sender.getPlayer().chunkCoordZ; 16 | LusiiClaimChunks.IntPair intPair = new LusiiClaimChunks.IntPair(cx,cz); 17 | String player; 18 | if (args.length == 0) { 19 | return false; 20 | } 21 | player = args[0]; 22 | if (!LusiiClaimChunks.isChunkClaimed(intPair)) { 23 | sender.sendMessage("§3No one owns this chunk!"); 24 | return true; 25 | } 26 | LusiiClaimChunks.addTrustedPlayerToChunk(intPair, player); 27 | sender.sendMessage("§ePlayer §r"+ player + " §etrusted via Operator."); 28 | return true; 29 | } 30 | // 31 | public boolean opRequired(String[] args) { 32 | return true; 33 | } 34 | // 35 | public void sendCommandSyntax(CommandHandler handler, CommandSender sender) { 36 | sender.sendMessage("/optrust "); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/mixins/CommandsMixin.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.mixins; 2 | 3 | 4 | import lusii.lusiiclaimchunks.commands.*; 5 | import net.minecraft.core.net.command.Command; 6 | import net.minecraft.core.net.command.Commands; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.Shadow; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Inject; 11 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 12 | 13 | import java.util.List; 14 | 15 | @Mixin(value = Commands.class, remap = false) 16 | public final class CommandsMixin { 17 | @Shadow 18 | public static List commands; 19 | @Inject(method = "initCommands", at = @At("TAIL")) 20 | private static void initCommands(CallbackInfo ci) { 21 | commands.add(new ClaimCommand()); 22 | commands.add(new TrustCommand()); 23 | commands.add(new DelClaimCommand()); 24 | commands.add(new UnTrustCommand()); 25 | commands.add(new OPClaimCommand()); 26 | commands.add(new OPDelClaimCommand()); 27 | commands.add(new OPTrustCommand()); 28 | commands.add(new OPUnTrustCommand()); 29 | commands.add(new TrustedCommand()); 30 | commands.add(new DeleteAllClaimsCommand()); 31 | commands.add(new ListClaims()); 32 | commands.add(new UnTrustAllCommand()); 33 | commands.add(new TrustAllCommand()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/commands/TrustCommand.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.commands; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.net.command.Command; 5 | import net.minecraft.core.net.command.CommandHandler; 6 | import net.minecraft.core.net.command.CommandSender; 7 | 8 | public class TrustCommand extends Command { 9 | public TrustCommand() { 10 | super("trust","claimtrust"); 11 | } 12 | // 13 | public boolean execute(CommandHandler handler, CommandSender sender, String[] args) { 14 | int cx = sender.getPlayer().chunkCoordX; 15 | int cz = sender.getPlayer().chunkCoordZ; 16 | LusiiClaimChunks.IntPair intPair = new LusiiClaimChunks.IntPair(cx,cz); 17 | String username = sender.getPlayer().username; 18 | String player; 19 | if (args.length == 0) { 20 | return false; 21 | } 22 | player = args[0]; 23 | if (!LusiiClaimChunks.isChunkClaimed(intPair)) { 24 | sender.sendMessage("§3No one owns this chunk!"); 25 | return true; 26 | } 27 | if (!LusiiClaimChunks.isPlayerOwner(new LusiiClaimChunks.IntPair(cx, cz), username)) { 28 | sender.sendMessage("§eYou do not own this chunk!"); 29 | } else { 30 | LusiiClaimChunks.addTrustedPlayerToChunk(intPair, player); 31 | sender.sendMessage("§3Player §r" + player + " §3trusted."); 32 | } 33 | return true; 34 | } 35 | // 36 | public boolean opRequired(String[] args) { 37 | return false; 38 | } 39 | // 40 | public void sendCommandSyntax(CommandHandler handler, CommandSender sender) { 41 | sender.sendMessage("/trust "); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/commands/UnTrustCommand.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.commands; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.net.command.Command; 5 | import net.minecraft.core.net.command.CommandHandler; 6 | import net.minecraft.core.net.command.CommandSender; 7 | 8 | public class UnTrustCommand extends Command { 9 | public UnTrustCommand() { 10 | super("untrust","claimuntrust"); 11 | } 12 | // 13 | public boolean execute(CommandHandler handler, CommandSender sender, String[] args) { 14 | int cx = sender.getPlayer().chunkCoordX; 15 | int cz = sender.getPlayer().chunkCoordZ; 16 | LusiiClaimChunks.IntPair intPair = new LusiiClaimChunks.IntPair(cx,cz); 17 | String username = sender.getPlayer().username; 18 | String player; 19 | if (args.length == 0) { 20 | return false; 21 | } 22 | player = args[0]; 23 | if (!LusiiClaimChunks.isChunkClaimed(intPair)) { 24 | sender.sendMessage("§3No one owns this chunk!"); 25 | return true; 26 | } 27 | if (!LusiiClaimChunks.isPlayerOwner(new LusiiClaimChunks.IntPair(cx, cz), username)) { 28 | sender.sendMessage("§eYou do not own this chunk!"); 29 | } else { 30 | LusiiClaimChunks.removedPlayerFromChunk(intPair, player); 31 | sender.sendMessage("§3Player §r" + player + " §3untrusted."); 32 | } 33 | return true; 34 | } 35 | // 36 | public boolean opRequired(String[] args) { 37 | return false; 38 | } 39 | // 40 | public void sendCommandSyntax(CommandHandler handler, CommandSender sender) { 41 | sender.sendMessage("/untrust "); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/commands/DelClaimCommand.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.commands; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.net.command.Command; 5 | import net.minecraft.core.net.command.CommandHandler; 6 | import net.minecraft.core.net.command.CommandSender; 7 | 8 | public class DelClaimCommand extends Command { 9 | public DelClaimCommand() { 10 | super("delclaim","unclaim"); 11 | } 12 | // 13 | public boolean execute(CommandHandler handler, CommandSender sender, String[] args) { 14 | int cx = sender.getPlayer().chunkCoordX; 15 | int cz = sender.getPlayer().chunkCoordZ; 16 | LusiiClaimChunks.IntPair intPair = new LusiiClaimChunks.IntPair(cx,cz); 17 | String username = sender.getPlayer().username; 18 | if (!LusiiClaimChunks.isChunkClaimed(intPair)) { 19 | sender.sendMessage("§3No one owns this chunk!"); 20 | return true; 21 | } 22 | if (!LusiiClaimChunks.getTrustedPlayersInChunk(new LusiiClaimChunks.IntPair(cx, cz)).get(0).equals(username)) { 23 | sender.sendMessage("§3You do not own this chunk!"); 24 | } else { 25 | LusiiClaimChunks.deleteClaim(intPair); 26 | int refund = LusiiClaimChunks.getRefund(username); 27 | sender.getPlayer().score += refund; 28 | sender.sendMessage("§4Claim removed!"); 29 | sender.sendMessage("§1Refunded §4" + refund + "§1 points."); 30 | 31 | } 32 | return true; 33 | } 34 | // 35 | public boolean opRequired(String[] args) { 36 | return false; 37 | } 38 | // 39 | public void sendCommandSyntax(CommandHandler handler, CommandSender sender) { 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/commands/DeleteAllClaimsCommand.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.commands; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.net.command.Command; 5 | import net.minecraft.core.net.command.CommandHandler; 6 | import net.minecraft.core.net.command.CommandSender; 7 | 8 | import java.util.Objects; 9 | 10 | import static lusii.lusiiclaimchunks.LusiiClaimChunks.deleteAllClaimedChunks; 11 | 12 | public class DeleteAllClaimsCommand extends Command { 13 | public DeleteAllClaimsCommand() { 14 | super("unclaimall","delclaimsall"); 15 | } 16 | // 17 | public boolean execute(CommandHandler handler, CommandSender sender, String[] args) { 18 | if (args.length > 0) { 19 | if (Objects.equals(args[0].toLowerCase(), "confirm")) { 20 | int delCount = deleteAllClaimedChunks(sender.getPlayer().username); 21 | int fullRefund = LusiiClaimChunks.getFullRefund(delCount); 22 | sender.getPlayer().score += fullRefund; 23 | 24 | // sender.sendMessage("§3All of your claims have been erased."); 25 | sender.sendMessage("§eUnclaimed §4" + delCount + "§e chunks."); 26 | sender.sendMessage("§1Refunded §4" + fullRefund + "§1 points."); 27 | 28 | return true; 29 | } 30 | } 31 | sender.sendMessage("§e§lTHIS COMMAND IS DANGEROUS!"); 32 | sender.sendMessage("§eRerun the command with 'confirm' if you're absolutely sure!"); 33 | return true; 34 | } 35 | // 36 | public boolean opRequired(String[] args) { 37 | return false; 38 | } 39 | // 40 | public void sendCommandSyntax(CommandHandler handler, CommandSender sender) { 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/commands/TrustedCommand.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.commands; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.net.command.Command; 5 | import net.minecraft.core.net.command.CommandHandler; 6 | import net.minecraft.core.net.command.CommandSender; 7 | 8 | import java.util.Objects; 9 | 10 | public class TrustedCommand extends Command { 11 | public TrustedCommand() { 12 | super("trusted","claimtrusted","claimwho"); 13 | } 14 | // 15 | public boolean execute(CommandHandler handler, CommandSender sender, String[] args) { 16 | int cx = sender.getPlayer().chunkCoordX; 17 | int cz = sender.getPlayer().chunkCoordZ; 18 | LusiiClaimChunks.IntPair intPair = new LusiiClaimChunks.IntPair(cx,cz); 19 | if (!LusiiClaimChunks.isChunkClaimed(intPair)) { 20 | sender.sendMessage("§eNo one owns this chunk!"); 21 | return true; 22 | } 23 | String owner = Objects.requireNonNull(LusiiClaimChunks.getTrustedPlayersInChunk(intPair)).get(0); 24 | String theResults = Objects.requireNonNull(LusiiClaimChunks.getTrustedPlayersInChunk(intPair)).toString().replace(" , ", ", "); 25 | theResults = theResults.replaceFirst(", ", ""); 26 | theResults = theResults.replace("[", ""); 27 | theResults = theResults.replace("]", ""); 28 | theResults = theResults.replaceFirst(owner, ""); 29 | 30 | sender.sendMessage("§3Chunk owner: §r" + owner); 31 | sender.sendMessage("§3Trusted players: §r" + theResults); 32 | 33 | return true; 34 | 35 | } 36 | // 37 | public boolean opRequired(String[] args) { 38 | return false; 39 | } 40 | // 41 | public void sendCommandSyntax(CommandHandler handler, CommandSender sender) { 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/commands/OPDelClaimCommand.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.commands; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.entity.player.EntityPlayer; 5 | import net.minecraft.core.net.command.Command; 6 | import net.minecraft.core.net.command.CommandHandler; 7 | import net.minecraft.core.net.command.CommandSender; 8 | 9 | public class OPDelClaimCommand extends Command { 10 | public OPDelClaimCommand() { 11 | super("opdelclaim","opunclaim"); 12 | } 13 | 14 | public boolean execute(CommandHandler handler, CommandSender sender, String[] args) { 15 | int cx = sender.getPlayer().chunkCoordX; 16 | int cz = sender.getPlayer().chunkCoordZ; 17 | LusiiClaimChunks.IntPair intPair = new LusiiClaimChunks.IntPair(cx,cz); 18 | if (!LusiiClaimChunks.isChunkClaimed(intPair)) { 19 | sender.sendMessage("§3No one owns this chunk!"); 20 | return true; 21 | } 22 | String oldOwner = LusiiClaimChunks.getTrustedPlayersInChunk(intPair).get(0); 23 | int refund = LusiiClaimChunks.getOPRefund(oldOwner); 24 | EntityPlayer player = handler.getPlayer(oldOwner); 25 | player.score += refund; 26 | if (LusiiClaimChunks.notifyOPClaim) { 27 | String posString = "(" + cx + ", " + cz + ")"; 28 | handler.sendMessageToPlayer(player, "§1Claim at §4" + posString + "§1 was deleted by an Operator"); 29 | handler.sendMessageToPlayer(player, "§1You have been refunded §4" + refund + "§1 points."); 30 | } 31 | 32 | LusiiClaimChunks.deleteClaim(intPair); 33 | sender.sendMessage("§eClaim deleted via Operator"); 34 | return true; 35 | } 36 | // 37 | public boolean opRequired(String[] args) { 38 | return true; 39 | } 40 | // 41 | public void sendCommandSyntax(CommandHandler handler, CommandSender sender) { 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/commands/OPClaimCommand.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.commands; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.entity.player.EntityPlayer; 5 | import net.minecraft.core.net.command.Command; 6 | import net.minecraft.core.net.command.CommandHandler; 7 | import net.minecraft.core.net.command.CommandSender; 8 | 9 | public class OPClaimCommand extends Command { 10 | public OPClaimCommand() { 11 | super("opclaim"); 12 | } 13 | // 14 | public boolean execute(CommandHandler handler, CommandSender sender, String[] args) { 15 | int cx = sender.getPlayer().chunkCoordX; 16 | int cz = sender.getPlayer().chunkCoordZ; 17 | LusiiClaimChunks.IntPair intPair = new LusiiClaimChunks.IntPair(cx,cz); 18 | String username; 19 | if (args.length == 0) { 20 | username = sender.getPlayer().username; 21 | } else { 22 | username = args[0]; 23 | } 24 | 25 | if (LusiiClaimChunks.isChunkClaimed(intPair)) { 26 | String oldOwner = LusiiClaimChunks.getTrustedPlayersInChunk(intPair).get(0); 27 | int refund = LusiiClaimChunks.getOPRefund(oldOwner); 28 | EntityPlayer player = handler.getPlayer(oldOwner); 29 | player.score += refund; 30 | if (LusiiClaimChunks.notifyOPClaim) { 31 | String posString = "(" + cx + ", " + cz + ")"; 32 | handler.sendMessageToPlayer(player, "§1Claim at §4" + posString + "§1 was claimed by an Operator"); 33 | handler.sendMessageToPlayer(player, "§1You have been refunded §4" + refund + "§1 points."); 34 | 35 | } 36 | } 37 | 38 | LusiiClaimChunks.setOwnerToChunk(intPair, username); 39 | sender.sendMessage("§eClaimed via Operator"); 40 | return true; 41 | } 42 | // 43 | public boolean opRequired(String[] args) { 44 | return true; 45 | } 46 | // 47 | public void sendCommandSyntax(CommandHandler handler, CommandSender sender) { 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/commands/ClaimCommand.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.commands; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.net.command.Command; 5 | import net.minecraft.core.net.command.CommandHandler; 6 | import net.minecraft.core.net.command.CommandSender; 7 | 8 | import static lusii.lusiiclaimchunks.LusiiClaimChunks.claimedChunksMap; 9 | 10 | public class ClaimCommand extends Command { 11 | public ClaimCommand() { 12 | super("claim"); 13 | } 14 | // 15 | public boolean execute(CommandHandler handler, CommandSender sender, String[] args) { 16 | if (sender.getPlayer().score < LusiiClaimChunks.getCost(sender.getPlayer().username)) { 17 | sender.sendMessage("§eInsufficient funds! Need at least " + LusiiClaimChunks.getCost(sender.getPlayer().username) + " to claim!"); 18 | return true; 19 | } 20 | if (sender.getPlayer().dimension != 0) { 21 | sender.sendMessage("§eOverworld only!"); 22 | return true; 23 | } 24 | if (claimedChunksMap.getOrDefault(sender.getPlayer().username, 0) >= LusiiClaimChunks.maxClaims && LusiiClaimChunks.maxClaims > 0) { 25 | sender.sendMessage("§eYou've reached the max amount of claims!"); 26 | return true; 27 | } 28 | int cx = sender.getPlayer().chunkCoordX; 29 | int cz = sender.getPlayer().chunkCoordZ; 30 | LusiiClaimChunks.IntPair intPair = new LusiiClaimChunks.IntPair(cx,cz); 31 | String username = sender.getPlayer().username; 32 | if (LusiiClaimChunks.getTrustedPlayersInChunk(intPair) == null) { 33 | sender.getPlayer().score -= LusiiClaimChunks.getCost(sender.getPlayer().username); 34 | LusiiClaimChunks.addTrustedPlayerToChunk(intPair, username); 35 | sender.sendMessage("§4Chunk claimed!"); 36 | } else { 37 | sender.sendMessage("§eThis chunk is already claimed by §r" + LusiiClaimChunks.getTrustedPlayersInChunk(intPair).get(0) +"!"); 38 | } 39 | return true; 40 | } 41 | // 42 | public boolean opRequired(String[] args) { 43 | return false; 44 | } 45 | // 46 | public void sendCommandSyntax(CommandHandler handler, CommandSender sender) { 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/mixins/ItemBucketMixin.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.mixins; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.HitResult; 5 | import net.minecraft.core.entity.player.EntityPlayer; 6 | import net.minecraft.core.item.Item; 7 | import net.minecraft.core.item.ItemBucket; 8 | import net.minecraft.core.item.ItemStack; 9 | import net.minecraft.core.util.phys.Vec3d; 10 | import net.minecraft.core.world.World; 11 | import net.minecraft.core.world.chunk.Chunk; 12 | import org.spongepowered.asm.mixin.Mixin; 13 | import org.spongepowered.asm.mixin.injection.At; 14 | import org.spongepowered.asm.mixin.injection.Inject; 15 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 16 | import org.spongepowered.asm.mixin.injection.callback.LocalCapture; 17 | 18 | @Mixin(value = ItemBucket.class, remap = false) 19 | public class ItemBucketMixin extends Item { 20 | public ItemBucketMixin(int id) { 21 | super(id); 22 | } 23 | 24 | @Inject(method = "onItemRightClick(Lnet/minecraft/core/item/ItemStack;Lnet/minecraft/core/world/World;Lnet/minecraft/core/entity/player/EntityPlayer;)Lnet/minecraft/core/item/ItemStack;", 25 | at = @At(value = "INVOKE", target = "Lnet/minecraft/core/world/World;checkBlockCollisionBetweenPoints(Lnet/minecraft/core/util/phys/Vec3d;Lnet/minecraft/core/util/phys/Vec3d;Z)Lnet/minecraft/core/HitResult;", shift = At.Shift.AFTER, by = 1), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) 26 | private void bucketProtect(ItemStack itemstack, World world, EntityPlayer entityplayer, CallbackInfoReturnable cir, float f, float f1, float f2, double d, double d1, double d2, Vec3d vec3d, float f3, float f4, float f5, float f6, float f7, float f8, float f9, double d3, Vec3d vec3d1){ 27 | HitResult movingobjectposition = world.checkBlockCollisionBetweenPoints(vec3d, vec3d1, true); 28 | if (movingobjectposition != null &&movingobjectposition.hitType == HitResult.HitType.TILE){ 29 | int i = movingobjectposition.x; 30 | int k = movingobjectposition.z; 31 | Chunk chunk = world.getChunkFromBlockCoords(i,k); 32 | int cx = chunk.xPosition; 33 | int cz = chunk.zPosition; 34 | LusiiClaimChunks.IntPair intPair = new LusiiClaimChunks.IntPair(cx,cz); 35 | if (entityplayer.dimension == 0 && LusiiClaimChunks.isChunkClaimed(intPair) && !LusiiClaimChunks.isPlayerTrusted(intPair, entityplayer.username)) { 36 | cir.setReturnValue(itemstack); 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/mixins/ItemBucketEmptyMixin.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.mixins; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.HitResult; 5 | import net.minecraft.core.entity.player.EntityPlayer; 6 | import net.minecraft.core.item.Item; 7 | import net.minecraft.core.item.ItemBucketEmpty; 8 | import net.minecraft.core.item.ItemStack; 9 | import net.minecraft.core.util.phys.Vec3d; 10 | import net.minecraft.core.world.World; 11 | import net.minecraft.core.world.chunk.Chunk; 12 | import org.spongepowered.asm.mixin.Mixin; 13 | import org.spongepowered.asm.mixin.injection.At; 14 | import org.spongepowered.asm.mixin.injection.Inject; 15 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 16 | import org.spongepowered.asm.mixin.injection.callback.LocalCapture; 17 | 18 | @Mixin(value = ItemBucketEmpty.class, remap = false) 19 | public class ItemBucketEmptyMixin extends Item { 20 | public ItemBucketEmptyMixin(int id) { 21 | super(id); 22 | } 23 | 24 | @Inject(method = "onItemRightClick(Lnet/minecraft/core/item/ItemStack;Lnet/minecraft/core/world/World;Lnet/minecraft/core/entity/player/EntityPlayer;)Lnet/minecraft/core/item/ItemStack;", 25 | at = @At(value = "INVOKE", target = "Lnet/minecraft/core/world/World;checkBlockCollisionBetweenPoints(Lnet/minecraft/core/util/phys/Vec3d;Lnet/minecraft/core/util/phys/Vec3d;Z)Lnet/minecraft/core/HitResult;", shift = At.Shift.AFTER, by = 1), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) 26 | private void bucketProtect(ItemStack itemstack, World world, EntityPlayer entityplayer, CallbackInfoReturnable cir, float f, float f1, float f2, double d, double d1, double d2, Vec3d vec3d, float f3, float f4, float f5, float f6, float f7, float f8, float f9, double d3, Vec3d vec3d1){ 27 | HitResult movingobjectposition = world.checkBlockCollisionBetweenPoints(vec3d, vec3d1, true); 28 | if (movingobjectposition != null &&movingobjectposition.hitType == HitResult.HitType.TILE){ 29 | int i = movingobjectposition.x; 30 | int k = movingobjectposition.z; 31 | Chunk chunk = world.getChunkFromBlockCoords(i,k); 32 | int cx = chunk.xPosition; 33 | int cz = chunk.zPosition; 34 | LusiiClaimChunks.IntPair intPair = new LusiiClaimChunks.IntPair(cx,cz); 35 | if (entityplayer.dimension == 0 && LusiiClaimChunks.isChunkClaimed(intPair) && !LusiiClaimChunks.isPlayerTrusted(intPair, entityplayer.username)) { 36 | cir.setReturnValue(itemstack); 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MSYS* | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/mixins/NetServerHandlerMixin.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks.mixins; 2 | 3 | import lusii.lusiiclaimchunks.LusiiClaimChunks; 4 | import net.minecraft.core.block.Block; 5 | import net.minecraft.core.net.ICommandListener; 6 | import net.minecraft.core.net.handler.NetHandler; 7 | import net.minecraft.core.net.packet.Packet10Flying; 8 | import net.minecraft.core.net.packet.Packet14BlockDig; 9 | import net.minecraft.core.net.packet.Packet15Place; 10 | import net.minecraft.core.net.packet.Packet53BlockChange; 11 | import net.minecraft.core.player.gamemode.Gamemode; 12 | import net.minecraft.core.util.helper.Direction; 13 | import net.minecraft.core.world.chunk.Chunk; 14 | import net.minecraft.server.MinecraftServer; 15 | import net.minecraft.server.entity.player.EntityPlayerMP; 16 | import net.minecraft.server.net.handler.NetServerHandler; 17 | import net.minecraft.server.world.WorldServer; 18 | import org.spongepowered.asm.mixin.Mixin; 19 | import org.spongepowered.asm.mixin.Shadow; 20 | import org.spongepowered.asm.mixin.injection.At; 21 | import org.spongepowered.asm.mixin.injection.Inject; 22 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 23 | 24 | import static java.lang.Math.floor; 25 | 26 | @Mixin(value = NetServerHandler.class,remap = false,priority = 0) 27 | public class NetServerHandlerMixin extends NetHandler implements ICommandListener { 28 | @Shadow 29 | private MinecraftServer mcServer; 30 | @Shadow 31 | private EntityPlayerMP playerEntity; 32 | @Shadow 33 | private boolean hasMoved = true; 34 | 35 | @Inject(method = "handleFlying", at = @At("HEAD")) 36 | public void handleFlyingClaimChunk(Packet10Flying packet, CallbackInfo ci) { 37 | int newPosXClaimChunks = (int) floor(packet.xPosition); 38 | int newPosZClaimChunks = (int) floor(packet.zPosition); 39 | int oldPosXClaimChunks = (int) floor(this.playerEntity.x); 40 | int oldPosZClaimChunks = (int) floor(this.playerEntity.z); 41 | Chunk chunk = this.mcServer.getDimensionWorld(this.playerEntity.dimension).getChunkFromBlockCoords(oldPosXClaimChunks, oldPosZClaimChunks); 42 | Chunk chunkNew = this.mcServer.getDimensionWorld(this.playerEntity.dimension).getChunkFromBlockCoords(newPosXClaimChunks, newPosZClaimChunks); 43 | LusiiClaimChunks.IntPair intPair = new LusiiClaimChunks.IntPair(chunk.xPosition,chunk.zPosition); 44 | LusiiClaimChunks.IntPair intPairNew = new LusiiClaimChunks.IntPair(chunkNew.xPosition,chunkNew.zPosition); 45 | if (this.playerEntity.dimension == 0 && !this.playerEntity.isPassenger()){ 46 | if (LusiiClaimChunks.getTrustedPlayersInChunk(intPair) == null && LusiiClaimChunks.getTrustedPlayersInChunk(intPairNew) != null && packet.moving && this.hasMoved) { 47 | this.mcServer.playerList.sendChatMessageToPlayer(this.playerEntity.username, "§3Now entering §r" + LusiiClaimChunks.getTrustedPlayersInChunk(intPairNew).get(0) + "'s §3claim."); 48 | } else if (LusiiClaimChunks.getTrustedPlayersInChunk(intPair) != null && LusiiClaimChunks.getTrustedPlayersInChunk(intPairNew) == null && packet.moving && this.hasMoved) { 49 | this.mcServer.playerList.sendChatMessageToPlayer(this.playerEntity.username, "§3Now entering §dWilderness§3."); 50 | } else if (LusiiClaimChunks.getTrustedPlayersInChunk(intPair) != null && LusiiClaimChunks.getTrustedPlayersInChunk(intPairNew) != null && packet.moving && this.hasMoved) { 51 | if (!LusiiClaimChunks.getTrustedPlayersInChunk(intPair).get(0).equals(LusiiClaimChunks.getTrustedPlayersInChunk(intPairNew).get(0))) { 52 | this.mcServer.playerList.sendChatMessageToPlayer(this.playerEntity.username, "§3Now entering §r" + LusiiClaimChunks.getTrustedPlayersInChunk(intPairNew).get(0) + "'s §3claim."); 53 | } 54 | } 55 | } 56 | } 57 | 58 | @Inject(method = "handleBlockDig", at = @At("HEAD"), cancellable = true) 59 | public void handleBlockDigClaimChunk(Packet14BlockDig packet, CallbackInfo ci) { 60 | WorldServer worldserver = this.mcServer.getDimensionWorld(this.playerEntity.dimension); 61 | Block block = worldserver.getBlock(packet.xPosition,packet.yPosition,packet.zPosition); 62 | LusiiClaimChunks.IntPair intPair = new LusiiClaimChunks.IntPair(this.mcServer.getDimensionWorld(this.playerEntity.dimension).getChunkFromBlockCoords(packet.xPosition,packet.zPosition).xPosition,this.mcServer.getDimensionWorld(this.playerEntity.dimension).getChunkFromBlockCoords(packet.xPosition,packet.zPosition).zPosition); 63 | if (block != null){ 64 | if (this.playerEntity.dimension == 0 & packet.status == 2 || this.playerEntity.dimension == 0 & (this.playerEntity.gamemode == Gamemode.creative || this.playerEntity.getCurrentPlayerStrVsBlock(block) >= 1.0) & packet.status == 0) { 65 | if (!LusiiClaimChunks.isPlayerTrusted(intPair, playerEntity.username) && LusiiClaimChunks.isChunkClaimed(intPair)) { 66 | this.mcServer.playerList.sendChatMessageToPlayer(this.playerEntity.username, "§e§lHey!§r This chunk does not belong to you!"); 67 | this.playerEntity.playerNetServerHandler.sendPacket(new Packet53BlockChange(packet.xPosition, packet.yPosition, packet.zPosition, worldserver)); 68 | ci.cancel(); 69 | } 70 | } 71 | } 72 | } 73 | @Inject(method = "handlePlace", at = @At("HEAD"), cancellable = true) 74 | public void handlePlaceChunkClaim(Packet15Place packet, CallbackInfo ci) { 75 | int x = packet.xPosition; 76 | int y = packet.yPosition; 77 | int z = packet.zPosition; 78 | Direction direction = packet.direction; 79 | x += direction.getOffsetX(); 80 | y += direction.getOffsetY(); 81 | z += direction.getOffsetZ(); 82 | 83 | LusiiClaimChunks.IntPair intPair2 = new LusiiClaimChunks.IntPair(this.mcServer.getDimensionWorld(this.playerEntity.dimension).getChunkFromBlockCoords(x,z).xPosition,this.mcServer.getDimensionWorld(this.playerEntity.dimension).getChunkFromBlockCoords(x,z).zPosition); 84 | if (this.playerEntity.dimension == 0 && LusiiClaimChunks.isChunkClaimed(intPair2) && !LusiiClaimChunks.isPlayerTrusted(intPair2, playerEntity.username)) { 85 | this.mcServer.playerList.sendChatMessageToPlayer(this.playerEntity.username, "§e§lHey!§r This chunk does not belong to you!"); 86 | WorldServer worldserver = this.mcServer.getDimensionWorld(this.playerEntity.dimension); 87 | this.playerEntity.playerNetServerHandler.sendPacket(new Packet53BlockChange(x, y, z, worldserver)); 88 | this.playerEntity.playerNetServerHandler.sendPacket(new Packet53BlockChange(x, y, z, worldserver)); 89 | this.playerEntity.craftingInventory.updateInventory(); 90 | ci.cancel(); 91 | } 92 | } 93 | 94 | 95 | 96 | @Shadow 97 | public void log(String string) { 98 | 99 | } 100 | 101 | @Shadow 102 | public String getUsername() { 103 | return null; 104 | } 105 | 106 | @Shadow 107 | public boolean isServerHandler() { 108 | return false; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /src/main/java/lusii/lusiiclaimchunks/LusiiClaimChunks.java: -------------------------------------------------------------------------------- 1 | package lusii.lusiiclaimchunks; 2 | 3 | import net.fabricmc.api.ModInitializer; 4 | import net.minecraft.core.world.chunk.ChunkPosition; 5 | import org.jetbrains.annotations.NotNull; 6 | import org.lwjgl.Sys; 7 | import org.mariuszgromada.math.mxparser.Argument; 8 | import org.mariuszgromada.math.mxparser.Expression; 9 | import org.mariuszgromada.math.mxparser.License; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import turniplabs.halplibe.util.TomlConfigHandler; 13 | import turniplabs.halplibe.util.toml.Toml; 14 | 15 | import javax.annotation.Nullable; 16 | import java.io.FileInputStream; 17 | import java.io.FileOutputStream; 18 | import java.io.IOException; 19 | import java.io.ObjectInputStream; 20 | import java.io.ObjectOutputStream; 21 | import java.io.Serializable; 22 | import java.util.*; 23 | 24 | 25 | public class LusiiClaimChunks implements ModInitializer { 26 | public static final String MOD_ID = "lusiiclaimchunk"; 27 | public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); 28 | private static HashMap> chunkTrustedMap = new HashMap<>(); 29 | public static HashMap claimedChunksMap = new HashMap<>(); 30 | 31 | public static final TomlConfigHandler CONFIG; 32 | static { 33 | Toml toml = new Toml() 34 | .addEntry("cost", "Cost per chunk (In points), parameter x being the number of chunks already claimed by the player", "100 * x") 35 | .addEntry("maxClaims", "Max claims a user is allowed to have. 0 = no limit", 25) 36 | .addEntry("refundRatio", "Amount refunded (1.0 = 100%)", 0.75f) 37 | .addEntry("OPRefundRatio", "Amount refunded when an admin claims from a player (1.0 = 100%)", 1.0f) 38 | .addEntry("notifyOPClaim", "Notify a player when an admin claims their chunk", false); 39 | 40 | 41 | CONFIG = new TomlConfigHandler(MOD_ID, toml); 42 | 43 | costEquation = CONFIG.getString("cost"); 44 | maxClaims = CONFIG.getInt("maxClaims"); 45 | refundRatio = CONFIG.getFloat("refundRatio"); 46 | adminRefundRatio = CONFIG.getFloat("OPRefundRatio"); 47 | notifyOPClaim = CONFIG.getBoolean("notifyOPClaim"); 48 | 49 | License.iConfirmNonCommercialUse("UselessBullets"); 50 | } 51 | private static String costEquation; 52 | public static int maxClaims; 53 | public static float refundRatio; 54 | public static float adminRefundRatio; 55 | public static boolean notifyOPClaim; 56 | 57 | public static int getCost(String username){ 58 | Argument x = new Argument("x = " + claimedChunksMap.getOrDefault(username, 0)); 59 | Expression expression = new Expression(costEquation, x); 60 | return (int) expression.calculate(); 61 | } 62 | 63 | public static int getRefund(String username) { 64 | int lastChunkCost = getCost(username); 65 | 66 | return (int) (refundRatio * (float) lastChunkCost); 67 | } 68 | 69 | public static int getFullRefund(int ownedChunks) { // Don't ever talk to me or son ever again 70 | int totalRefund = 0; 71 | 72 | for (int i = 0; i < ownedChunks; i++) { 73 | Argument x = new Argument("x = " + i); 74 | Expression expression = new Expression(costEquation, x); 75 | 76 | totalRefund += (int) expression.calculate(); 77 | } 78 | 79 | return (int) (refundRatio * (float) totalRefund); 80 | 81 | } 82 | 83 | public static int getOPRefund(String username) { 84 | int lastChunkCost = getCost(username); 85 | 86 | return (int) (adminRefundRatio * (float) lastChunkCost); 87 | } 88 | 89 | @Override 90 | public void onInitialize() { 91 | 92 | try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream("LusiiChunksClaim.ser"))) { 93 | HashMap> reopenedMap = (HashMap>) ois.readObject(); 94 | 95 | chunkTrustedMap = reopenedMap; 96 | System.out.println("LusiiChunksClaim reopened from disk:"); 97 | System.out.println(reopenedMap); 98 | } catch (IOException | ClassNotFoundException ignored) { 99 | } 100 | calculateClaimedChunks(); 101 | LOGGER.info("LusiiClaimChunks initialized."); 102 | } 103 | 104 | protected static void saveHashMap() { 105 | calculateClaimedChunks(); 106 | try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("LusiiChunksClaim.ser"))) { 107 | oos.writeObject(chunkTrustedMap); 108 | //System.out.println("HashMap saved to disk."); 109 | } catch (IOException ignored) { 110 | LOGGER.warn("Chunk claims failed to save to disk! This is a major issue if you do not want griefing!"); 111 | } 112 | } 113 | protected static void calculateClaimedChunks(){ 114 | claimedChunksMap.clear(); 115 | for (IntPair pair : chunkTrustedMap.keySet()){ 116 | String owner = chunkTrustedMap.get(pair).get(0); 117 | int val = claimedChunksMap.getOrDefault(owner, 0); 118 | val++; 119 | claimedChunksMap.put(owner, val); 120 | } 121 | } 122 | public static @NotNull ArrayList listClaimedChunks(String username){ 123 | ArrayList claimedChunksList = new ArrayList<>(); 124 | for (IntPair pair : chunkTrustedMap.keySet()){ 125 | String owner = chunkTrustedMap.get(pair).get(0); 126 | if (Objects.equals(owner, username)) { 127 | claimedChunksList.add("(" + pair.x + "," + pair.y + ")"); 128 | } 129 | } 130 | return claimedChunksList; 131 | } 132 | 133 | public static void addPlayerToChunkAll(String player, String trusted) { 134 | Iterator iterator = chunkTrustedMap.keySet().iterator(); 135 | while (iterator.hasNext()) { 136 | IntPair pair = iterator.next(); 137 | if (Objects.equals(chunkTrustedMap.get(pair).get(0), player) && !chunkTrustedMap.get(pair).contains(trusted)) { 138 | chunkTrustedMap.putIfAbsent(pair, new ArrayList<>()); 139 | chunkTrustedMap.get(pair).add(trusted); 140 | } 141 | } 142 | LusiiClaimChunks.saveHashMap(); 143 | } 144 | 145 | public static void removePlayerFromChunkAll(String player, String victim) { 146 | Iterator iterator = chunkTrustedMap.keySet().iterator(); 147 | while (iterator.hasNext()) { 148 | IntPair pair = iterator.next(); 149 | if (Objects.equals(chunkTrustedMap.get(pair).get(0), player)) { 150 | chunkTrustedMap.get(pair).remove(victim); 151 | } 152 | } 153 | LusiiClaimChunks.saveHashMap(); 154 | } 155 | 156 | // Deletes all chunks owned by a user and returns the amount of chunks deleted 157 | public static int deleteAllClaimedChunks(String username) { 158 | int count = 0; 159 | Iterator iterator = chunkTrustedMap.keySet().iterator(); // This method is used because i would get ConcurrentModificationException if i tried a for loop. 160 | while (iterator.hasNext()) { 161 | IntPair pair = iterator.next(); 162 | String owner = chunkTrustedMap.get(pair).get(0); 163 | if (Objects.equals(owner, username)) { 164 | iterator.remove(); 165 | count++; 166 | deleteClaim(pair); 167 | } 168 | } 169 | LusiiClaimChunks.saveHashMap(); 170 | 171 | return count; 172 | } 173 | @Nullable 174 | public static List getTrustedPlayersInChunk(IntPair chunkCoords){ 175 | return chunkTrustedMap.get(chunkCoords); 176 | } 177 | public static void addTrustedPlayerToChunk(IntPair chunkCoords, String username){ 178 | chunkTrustedMap.putIfAbsent(chunkCoords, new ArrayList<>()); 179 | if (!chunkTrustedMap.get(chunkCoords).contains(username)){ 180 | chunkTrustedMap.get(chunkCoords).add(username); 181 | } 182 | LusiiClaimChunks.saveHashMap(); 183 | } 184 | public static void setOwnerToChunk(IntPair chunkCoords, String username){ 185 | chunkTrustedMap.putIfAbsent(chunkCoords, new ArrayList<>()); 186 | if (chunkTrustedMap.get(chunkCoords).contains(username)){ 187 | chunkTrustedMap.get(chunkCoords).remove(username); 188 | chunkTrustedMap.get(chunkCoords).add(0, username); 189 | } else { 190 | chunkTrustedMap.get(chunkCoords).add(0, username); 191 | } 192 | LusiiClaimChunks.saveHashMap(); 193 | } 194 | public static void removedPlayerFromChunk(IntPair chunkCoords, String username){ 195 | if (!chunkTrustedMap.containsKey(chunkCoords)) return; 196 | chunkTrustedMap.get(chunkCoords).remove(username); 197 | LusiiClaimChunks.saveHashMap(); 198 | } 199 | public static void deleteClaim(IntPair chunkCoords){ 200 | chunkTrustedMap.remove(chunkCoords); 201 | LusiiClaimChunks.saveHashMap(); 202 | } 203 | public static boolean isPlayerTrusted(IntPair chunkCoords, String username){ 204 | if (isChunkClaimed(chunkCoords)){ 205 | List trustedNames = getTrustedPlayersInChunk(chunkCoords); 206 | return trustedNames.contains(username); 207 | } 208 | return false; 209 | } 210 | public static boolean isPlayerOwner(IntPair chunkCoords, String username){ 211 | if (isChunkClaimed(chunkCoords)){ 212 | return getTrustedPlayersInChunk(chunkCoords).get(0).equals(username); 213 | } 214 | return false; 215 | } 216 | public static boolean isChunkClaimed(IntPair chunkCoords){ 217 | return chunkTrustedMap.containsKey(chunkCoords); 218 | } 219 | 220 | 221 | public static class IntPair implements Serializable { 222 | private static final long serialVersionUID = 1L; // Ensures version compatibility during deserialization 223 | private int x; 224 | private int y; 225 | 226 | public IntPair(int x, int y) { 227 | this.x = x; 228 | this.y = y; 229 | } 230 | 231 | // Override hashCode and equals methods for proper functioning in HashMap 232 | @Override 233 | public int hashCode() { 234 | final int prime = 31; 235 | int result = 1; 236 | result = prime * result + x; 237 | result = prime * result + y; 238 | return result; 239 | } 240 | 241 | @Override 242 | public boolean equals(Object obj) { 243 | if (this == obj) 244 | return true; 245 | if (obj == null) 246 | return false; 247 | if (getClass() != obj.getClass()) 248 | return false; 249 | IntPair other = (IntPair) obj; 250 | if (x != other.x) 251 | return false; 252 | if (y != other.y) 253 | return false; 254 | return true; 255 | } 256 | } 257 | } 258 | --------------------------------------------------------------------------------