Skip to content

Commit

Permalink
redis
Browse files Browse the repository at this point in the history
  • Loading branch information
Angeschossen committed May 15, 2024
1 parent 8d929d2 commit 2dbf55d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ java {
}

group = "com.github.angeschossen"
version = "1.0.23"
version = "1.0.24"
description = "PluginFrameworkAPI"
java.sourceCompatibility = JavaVersion.VERSION_1_8

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.github.angeschossen.pluginframework.api.blockutil;

import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public interface UnloadedPosition {
boolean isTargetServer();

int getBlockX();

int getBlockY();

int getBlockZ();

int getChunkX();

int getChunkZ();

@Nullable
Location toLocation();

@NotNull
String getWorldName();

double getX();

double getY();

double getZ();

String getServerName();

float getYaw();

float getPitch();

boolean isChunkLoaded();

boolean isWorldLoaded();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.angeschossen.pluginframework.api.blockutil.impl;

import com.github.angeschossen.pluginframework.api.blockutil.UnloadedPosition;
import com.github.angeschossen.pluginframework.api.handler.APIHandler;
import com.google.gson.JsonObject;
import org.bukkit.Bukkit;
Expand All @@ -8,11 +9,12 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class OfflineBlockCoordinate {
public class OfflineBlockCoordinate implements UnloadedPosition {

private String worldName, serverName;
private float yaw, pitch;
private double x, y, z;
private final String worldName;
private final String serverName;
private final float yaw, pitch;
private final double x, y, z;

public OfflineBlockCoordinate(String serverName, String worldName, double x, double y, double z) {
this(serverName, worldName, x, y, z, 0, 0);
Expand All @@ -32,10 +34,7 @@ public OfflineBlockCoordinate(String serverName, String worldName, double x, dou
this.pitch = pitch;
}

public OfflineBlockCoordinate() {

}

@Override
public final boolean isTargetServer() {
return APIHandler.getInstance().getMultiPaperHandler().isTargetServer(serverName);
}
Expand All @@ -56,26 +55,32 @@ public boolean equals(String serverName, World world, int x, int y, int z) {
return x == this.x && y == this.y && z == this.z;
}

@Override
public int getBlockX() {
return (int) x;
}

@Override
public int getBlockY() {
return (int) y;
}

@Override
public int getBlockZ() {
return (int) z;
}

@Override
public int getChunkX() {
return (int) x >> 4;
}

@Override
public int getChunkZ() {
return (int) z >> 4;
}

@Override
@Nullable
public final Location toLocation() {
if (!isTargetServer()) {
Expand All @@ -88,39 +93,51 @@ public final Location toLocation() {

@Nullable
public final World getWorld() {
return Bukkit.getWorld(getWorldName());
return isTargetServer() ? Bukkit.getWorld(getWorldName()) : null;
}

@Override
@NotNull
public String getWorldName() {
return worldName;
}

@Override
public double getX() {
return x;
}

@Override
public double getY() {
return y;
}

@Override
public double getZ() {
return z;
}

@Override
public String getServerName() {
return serverName;
}

@Override
public float getYaw() {
return yaw;
}

@Override
public float getPitch() {
return pitch;
}

@Override
public boolean isChunkLoaded() {
if (!isTargetServer()) {
return false;
}

World world = getWorld();
if (world == null) {
return false;
Expand All @@ -129,7 +146,8 @@ public boolean isChunkLoaded() {
return world.isChunkLoaded(getChunkX(), getChunkZ());
}

public boolean isLoaded() {
@Override
public boolean isWorldLoaded() {
return getWorld() != null;
}

Expand Down

0 comments on commit 2dbf55d

Please sign in to comment.