Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update v0.1.0 #172

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Here are some plugins that either have addons for or integrations with ClaimChun

Building [![Build Status](https://travis-ci.com/cjburkey01/ClaimChunk.svg?branch=master)](https://travis-ci.com/cjburkey01/ClaimChunk)
--------
[![Version Info](https://img.shields.io/static/v1?label=Repository%20Version&message=0.0.23-prev4&color=ff5555&style=for-the-badge)](https://github.com/cjburkey01/ClaimChunk/archive/master.zip)
[![Version Info](https://img.shields.io/static/v1?label=Repository%20Version&message=0.1.0-SNAPSHOT&color=ff5555&style=for-the-badge)](https://github.com/cjburkey01/ClaimChunk/archive/refs/heads/v0.1.0.zip)

If you want to obtain a version of the plugin that isn't available yet (like a snapshot), you can do so by asking on the Discord or building it yourself. Here's how to build it yourself:

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {

// Plugin information
group 'com.cjburkey'
version '0.0.23-prev4'
version '0.1.0-SNAPSHOT'
project.ext.liveVersion = '0.0.22'
project.archivesBaseName = 'claimchunk'
project.ext.pluginName = 'ClaimChunk'
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/cjburkey/claimchunk/ClaimChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Objects;
import java.util.Collection;

// TODO: Split this plugin up into services that users can use
// Services:
Expand Down Expand Up @@ -454,12 +454,12 @@ private void handleAutoUnclaim() {

if (playerJoinedSinceTimeRecordUpdate && playerBeenOfflineTooLong) {
// Get a list of all the player's chunks
ChunkPos[] claimedChunks = chunkHandler.getClaimedChunks(player.player);
Collection<ChunkPos> claimedChunks = chunkHandler.getClaimedChunks(player.player);

if (claimedChunks.length > 0) {
if (!claimedChunks.isEmpty()) {
// Unclaim all of the player's chunks
for (ChunkPos chunk : claimedChunks) {
chunkHandler.unclaimChunk(getServer().getWorld(chunk.getWorld()), chunk.getX(), chunk.getZ());
chunkHandler.setOwner(chunk, null);
}

Utils.log("Unclaimed all chunks of player \"%s\" (%s)", player.lastIgn, player.player);
Expand Down
94 changes: 79 additions & 15 deletions src/main/java/com/cjburkey/claimchunk/chunk/ChunkHandler.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.cjburkey.claimchunk.chunk;

import com.cjburkey.claimchunk.ClaimChunk;
import com.cjburkey.claimchunk.data.hyperdrive.chunk.ICCChunkHandler;
import com.cjburkey.claimchunk.data.newdata.IClaimChunkDataHandler;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.*;

import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nonnull;

public final class ChunkHandler {
public final class ChunkHandler implements ICCChunkHandler {

private final IClaimChunkDataHandler dataHandler;
private final ClaimChunk claimChunk;
Expand All @@ -29,8 +33,10 @@ public ChunkHandler(IClaimChunkDataHandler dataHandler, ClaimChunk claimChunk) {
* @param x The chunk x-coord.
* @param z The chunk z-coord.
* @param player The player for whom to claim the chunk.
* @return The chunk position variable or {@code null} if the chuk is already claimed
* @return The chunk position variable or {@code null} if the chunk is already claimed
* @deprecated Use methods defined in {@link com.cjburkey.claimchunk.data.hyperdrive.chunk.ICCChunkHandler}
*/
@Deprecated
public ChunkPos claimChunk(String world, int x, int z, UUID player) {
if (isClaimed(world, x, z)) {
// If the chunk is already claimed, return null
Expand All @@ -57,8 +63,10 @@ public ChunkPos claimChunk(String world, int x, int z, UUID player) {
* @param x The chunk x-coord.
* @param z The chunk z-coord.
* @param player The player for whom to claim the chunk.
* @return The chunk position variable or {@code null} if the chuk is already claimed
* @return The chunk position variable or {@code null} if the chunk is already claimed
* @deprecated Use methods defined in {@link com.cjburkey.claimchunk.data.hyperdrive.chunk.ICCChunkHandler}
*/
@Deprecated
public ChunkPos claimChunk(World world, int x, int z, UUID player) {
return claimChunk(world.getName(), x, z, player);
}
Expand All @@ -72,7 +80,9 @@ public ChunkPos claimChunk(World world, int x, int z, UUID player) {
* @param world The current world.
* @param x The chunk x-coord.
* @param z The chunk z-coord.
* @deprecated Use methods defined in {@link com.cjburkey.claimchunk.data.hyperdrive.chunk.ICCChunkHandler}
*/
@Deprecated
public void unclaimChunk(World world, int x, int z) {
if (isClaimed(world, x, z)) {
// If the chunk is claimed, remove it from the claimed chunks list
Expand All @@ -89,7 +99,10 @@ public void unclaimChunk(World world, int x, int z) {
* @param world The current world name.
* @param x The chunk x-coord.
* @param z The chunk z-coord.
* @deprecated Use methods defined in {@link com.cjburkey.claimchunk.data.hyperdrive.chunk.ICCChunkHandler}
*/
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
public void unclaimChunk(String world, int x, int z) {
if (isClaimed(world, x, z)) {
// If the chunk is claimed, remove it from the claimed chunks list
Expand All @@ -102,7 +115,10 @@ public void unclaimChunk(String world, int x, int z) {
*
* @param ply The UUID of the player.
* @return The integer count of chunks this player has claimed in total across worlds.
* @deprecated Use methods defined in {@link com.cjburkey.claimchunk.data.hyperdrive.chunk.ICCChunkHandler}
*/
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
public int getClaimed(UUID ply) {
int count = 0;

Expand All @@ -115,24 +131,46 @@ public int getClaimed(UUID ply) {
return count;
}

/**
* Creates an array with all claimed chunks that the provided player has.
*
* @param ply The UUID of the player.
* @return An array containing chunk positions for all this player's claimed chunks.
*/
public ChunkPos[] getClaimedChunks(UUID ply) {
// Fucky business until I implement the new data handlers

@Override
public @Nonnull Optional<UUID> setOwner(@Nonnull ChunkPos chunkPos, @Nullable UUID newOwner) {
Optional<UUID> oldOwner = getOwner(chunkPos);
if (oldOwner.isPresent()) unclaimChunk(chunkPos.getWorld(), chunkPos.getX(), chunkPos.getZ());
if (newOwner != null) claimChunk(chunkPos.getWorld(), chunkPos.getX(), chunkPos.getZ(), newOwner);
return oldOwner;
}

@Override
public boolean getHasOwner(@Nonnull ChunkPos chunkPos) {
return getOwner(chunkPos).isPresent();
}

@Override
public @Nonnull Optional<UUID> getOwner(@Nonnull ChunkPos chunkPos) {
return Optional.ofNullable(getOwner(Objects.requireNonNull(Bukkit.getWorld(chunkPos.getWorld())),
chunkPos.getX(),
chunkPos.getZ()));
}

@Override
public int getClaimedChunksCount(@Nonnull UUID owner) {
return getClaimed(owner);
}

@Override
public @Nonnull Collection<ChunkPos> getClaimedChunks(@Nonnull UUID ply) {
// Create a set for the chunks
Set<ChunkPos> chunks = new HashSet<>();

// Loop throug all chunks
// Loop through all chunks
for (DataChunk chunk : dataHandler.getClaimedChunks()) {
// Add chunks that are owned by this player
if (chunk.player.equals(ply)) chunks.add(chunk.chunk);
}

// Convert the set into an array
return chunks.toArray(new ChunkPos[0]);
return chunks;
}

/**
Expand Down Expand Up @@ -184,7 +222,9 @@ public boolean getHasAllFreeChunks(UUID ply, int count) {
* @param x The x-coordinate (in chunk coordinates) of the chunk.
* @param z The z-coordinate (in chunk coordinates) of the chunk.
* @return Whether this chunk is currently claimed.
* @deprecated Use methods defined in {@link com.cjburkey.claimchunk.data.hyperdrive.chunk.ICCChunkHandler}
*/
@Deprecated
public boolean isClaimed(World world, int x, int z) {
return dataHandler.isChunkClaimed(new ChunkPos(world.getName(), x, z));
}
Expand All @@ -196,7 +236,9 @@ public boolean isClaimed(World world, int x, int z) {
* @param x The x-coordinate (in chunk coordinates) of the chunk.
* @param z The z-coordinate (in chunk coordinates) of the chunk.
* @return Whether this chunk is currently claimed.
* @deprecated Use methods defined in {@link com.cjburkey.claimchunk.data.hyperdrive.chunk.ICCChunkHandler}
*/
@Deprecated
public boolean isClaimed(String world, int x, int z) {
return dataHandler.isChunkClaimed(new ChunkPos(world, x, z));
}
Expand All @@ -206,7 +248,9 @@ public boolean isClaimed(String world, int x, int z) {
*
* @param chunk The Spigot chunk position.
* @return Whether this chunk is currently claimed.
* @deprecated Use methods defined in {@link com.cjburkey.claimchunk.data.hyperdrive.chunk.ICCChunkHandler}
*/
@Deprecated
public boolean isClaimed(Chunk chunk) {
return isClaimed(chunk.getWorld(), chunk.getX(), chunk.getZ());
}
Expand All @@ -219,7 +263,9 @@ public boolean isClaimed(Chunk chunk) {
* @param z The z-coordinate (in chunk coordinates) of the chunk.
* @param ply The UUID of the player.
* @return Whether this player owns this chunk.
* @deprecated Use methods defined in {@link com.cjburkey.claimchunk.data.hyperdrive.chunk.ICCChunkHandler}
*/
@Deprecated
public boolean isOwner(World world, int x, int z, UUID ply) {
ChunkPos pos = new ChunkPos(world.getName(), x, z);
UUID owner = dataHandler.getChunkOwner(pos);
Expand All @@ -234,7 +280,9 @@ public boolean isOwner(World world, int x, int z, UUID ply) {
* @param z The z-coordinate (in chunk coordinates) of the chunk.
* @param ply The player.
* @return Whether this player owns this chunk.
* @deprecated Use methods defined in {@link com.cjburkey.claimchunk.data.hyperdrive.chunk.ICCChunkHandler}
*/
@Deprecated
public boolean isOwner(World world, int x, int z, Player ply) {
return isOwner(world, x, z, ply.getUniqueId());
}
Expand All @@ -245,7 +293,9 @@ public boolean isOwner(World world, int x, int z, Player ply) {
* @param chunk The Spigot chunk position.
* @param ply The UUID of the player.
* @return Whether this player owns this chunk.
* @deprecated Use methods defined in {@link com.cjburkey.claimchunk.data.hyperdrive.chunk.ICCChunkHandler}
*/
@Deprecated
public boolean isOwner(Chunk chunk, UUID ply) {
return isOwner(chunk.getWorld(), chunk.getX(), chunk.getZ(), ply);
}
Expand All @@ -256,7 +306,9 @@ public boolean isOwner(Chunk chunk, UUID ply) {
* @param chunk The Spigot chunk position.
* @param ply The player.
* @return Whether this player owns this chunk.
* @deprecated Use methods defined in {@link com.cjburkey.claimchunk.data.hyperdrive.chunk.ICCChunkHandler}
*/
@Deprecated
public boolean isOwner(Chunk chunk, Player ply) {
return isOwner(chunk.getWorld(), chunk.getX(), chunk.getZ(), ply);
}
Expand All @@ -268,7 +320,10 @@ public boolean isOwner(Chunk chunk, Player ply) {
* @param x The x-coordinate (in chunk coordinates) of the chunk.
* @param z The z-coordinate (in chunk coordinates) of the chunk.
* @return The UUID of the owner of this chunk.
* @deprecated Use methods defined in {@link com.cjburkey.claimchunk.data.hyperdrive.chunk.ICCChunkHandler}
*/
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
public UUID getOwner(World world, int x, int z) {
ChunkPos pos = new ChunkPos(world.getName(), x, z);
return !dataHandler.isChunkClaimed(pos) ? null : dataHandler.getChunkOwner(pos);
Expand All @@ -280,18 +335,25 @@ public UUID getOwner(World world, int x, int z) {
*
* @param chunk The Spigot chunk position.
* @return The UUID of the owner of this chunk.
* @deprecated Use methods defined in {@link com.cjburkey.claimchunk.data.hyperdrive.chunk.ICCChunkHandler}
*/
@Deprecated
public UUID getOwner(Chunk chunk) {
ChunkPos pos = new ChunkPos(chunk);
return !dataHandler.isChunkClaimed(pos) ? null : dataHandler.getChunkOwner(pos);
}

// TODO: MOVE TNT TO PER-PLAYER/PER-CHUNK SETTING HANDLER WHEN THAT COMES
// TO FRUITION.

/**
* Toggles whether TNT is enabled in the provided chunk.
*
* @param chunk The Spigot chunk position.
* @return Whether TNT is now (after the toggle) enabled in this chunk.
* @deprecated TODO
*/
@Deprecated
public boolean toggleTnt(Chunk chunk) {
return dataHandler.toggleTnt(new ChunkPos(chunk));
}
Expand All @@ -301,7 +363,9 @@ public boolean toggleTnt(Chunk chunk) {
*
* @param chunk The Spigot chunk position.
* @return Whether TNT is currently enabled in this chunk.
* @deprecated TODO
*/
@Deprecated
public boolean isTntEnabled(Chunk chunk) {
return dataHandler.isTntEnabled(new ChunkPos(chunk));
}
Expand Down
31 changes: 24 additions & 7 deletions src/main/java/com/cjburkey/claimchunk/chunk/ChunkPos.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,26 @@
import java.util.Objects;
import org.bukkit.Chunk;

import javax.annotation.Nonnull;

/**
* A class representing the position of some chunk in a given world.
*/
public final class ChunkPos {

/**
* The name of the world that contains this chunk
*/
private final String world;

/**
* The x-coordinate (in chunk coordinates) of this chunk.
*/
private final int x;

/**
* The z-coordinate (in chunk coordinates) of this chunk.
*/
private final int z;

/**
Expand All @@ -16,7 +32,7 @@ public final class ChunkPos {
* @param x The x-coordinate of this chunk (in chunk coordinates).
* @param z The y-coordinate of this chunk (in chunk coordinates).
*/
public ChunkPos(String world, int x, int z) {
public ChunkPos(@Nonnull String world, int x, int z) {
this.world = world;
this.x = x;
this.z = z;
Expand All @@ -28,12 +44,13 @@ public ChunkPos(String world, int x, int z) {
*
* @param chunk The Spigot chunk representation.
*/
public ChunkPos(Chunk chunk) {
this(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
public ChunkPos(@Nonnull Chunk chunk) {
// Make sure
this(Objects.requireNonNull(chunk.getWorld()).getName(), chunk.getX(), chunk.getZ());
}

/**
* Get the name of the world that this chunk is in.
* Get the name of the world that contains this chunk.
*
* @return The world name of this chunk.
*/
Expand All @@ -42,7 +59,7 @@ public String getWorld() {
}

/**
* Get the x-coordinate of this chunk.
* Get the x-coordinate of this chunk in chunk coordinates.
*
* @return The x-coordinate of this chunk (in chunk coordinates).
*/
Expand All @@ -51,7 +68,7 @@ public int getX() {
}

/**
* Get the y-coordinate of this chunk.
* Get the y-coordinate of this chunk in chunk coordinates.
*
* @return The y-coordinate of this chunk (in chunk coordinates).
*/
Expand All @@ -61,7 +78,7 @@ public int getZ() {

@Override
public String toString() {
return String.format("%s, %s in %s", x, z, world);
return String.format("Chunk { %s,%s in %s }", x, z, world);
}

@Override
Expand Down
Loading