Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void executeSet(@Context Player player, @Arg("homeName") String homeName) {
@Execute(name = "teleport")
void executeTeleport(@Context Player player, @Arg("homeName") String homeName) {
Location location = this.homeService.getHome(player.getUniqueId(), homeName)
.map(home -> home.getLocation())
.map(home -> home.getPosition())
.orElse(null);

if (location == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ApiHomeListener(Server server) {

@EventHandler
void onHomeOverride(HomeOverrideEvent event) {
Location location = event.getLocation();
Location location = event.getPosition();

String name = event.getHomeName();
int blockX = location.getBlockX();
Expand All @@ -39,7 +39,7 @@ void onHomeOverride(HomeOverrideEvent event) {

@EventHandler
void onHomeCreate(HomeCreateEvent event) {
Location location = event.getLocation();
Location location = event.getPosition();

String name = event.getHomeName();
int blockX = location.getBlockX();
Expand All @@ -59,7 +59,7 @@ void onHomeCreateTroll(HomeCreateEvent event) {
}

if (player.hasPotionEffect(PotionEffectType.BAD_OMEN)) {
event.setLocation(player.getWorld().getSpawnLocation());
event.setPosition(player.getWorld().getSpawnLocation());
event.setHomeName("bimbimbambam");
System.out.println("Troll: Home location overridden to world spawn.");
}
Expand Down
1 change: 1 addition & 0 deletions eternalcore-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ plugins {

dependencies {
compileOnly("org.spigotmc:spigot-api:${Versions.SPIGOT_API}")
compileOnly("com.eternalcode:eternalcode-commons-bukkit:${Versions.ETERNALCODE_COMMONS}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Position usage in API

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trochę słabo będzie wystawiać API które jest relokowane

api("org.jetbrains:annotations:${Versions.JETBRAINS_ANNOTATIONS}")
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.eternalcode.core.feature.home;

import com.eternalcode.commons.bukkit.position.Position;

import java.util.UUID;
import org.bukkit.Location;

public interface Home {

Location getLocation();
Position getPosition();

String getName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

import com.eternalcode.commons.bukkit.position.Position;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
Expand All @@ -23,7 +25,7 @@ public interface HomeService {
void deleteHome(UUID playerUniqueId, String name);

@Nullable
Home createHome(UUID playerUniqueId, String name, Location location);
Home createHome(UUID playerUniqueId, String name, Position position);

int getHomeLimit(Player player);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.eternalcode.core.feature.home.event;

import java.util.UUID;

import com.eternalcode.commons.bukkit.position.Position;
import org.bukkit.Location;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
Expand All @@ -16,15 +18,16 @@ public class HomeCreateEvent extends Event implements Cancellable {
private final UUID playerUniqueId;
private final UUID homeUniqueId;
private String homeName;
private Location location;
private Position position;
private boolean cancelled;

public HomeCreateEvent(UUID playerUniqueId, String homeName, UUID homeUniqueId, Location location) {
public HomeCreateEvent(UUID playerUniqueId, String homeName, UUID homeUniqueId, Position position) {
super(false);

this.playerUniqueId = playerUniqueId;
this.homeName = homeName;
this.homeUniqueId = homeUniqueId;
this.location = location;
this.position = position;
}

public UUID getHomeUniqueId() {
Expand All @@ -43,12 +46,12 @@ public UUID getPlayerUniqueId() {
return this.playerUniqueId;
}

public Location getLocation() {
return this.location;
public Position getPosition() {
return this.position;
}

public void setLocation(Location location) {
this.location = location;
public void setPosition(Position position) {
this.position = position;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.eternalcode.core.feature.home.event;

import com.eternalcode.core.feature.home.Home;
import com.eternalcode.commons.bukkit.position.Position;

import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.Cancellable;
Expand All @@ -17,16 +18,16 @@ public class HomeOverrideEvent extends Event implements Cancellable {
private final UUID playerUniqueId;
private final UUID homeUniqueId;
private String homeName;
private Location location;
private Position position;
private boolean cancelled;

public HomeOverrideEvent(UUID playerUniqueId, String homeName, UUID homeUniqueId, Location location) {
public HomeOverrideEvent(UUID playerUniqueId, String homeName, UUID homeUniqueId, Position position) {
super(false);

this.playerUniqueId = playerUniqueId;
this.homeName = homeName;
this.homeUniqueId = homeUniqueId;
this.location = location;
this.position = position;
}

public String getHomeName() {
Expand All @@ -45,12 +46,12 @@ public UUID getPlayerUniqueId() {
return this.playerUniqueId;
}

public void setLocation(Location location) {
this.location = location;
public void setPosition(Position position) {
this.position = position;
}

public Location getLocation() {
return this.location;
public Position getPosition() {
return this.position;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.eternalcode.core.feature.home.event;

import com.eternalcode.commons.bukkit.position.Position;
import com.eternalcode.core.feature.home.Home;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
Expand All @@ -16,27 +16,27 @@ public class PreHomeTeleportEvent extends Event implements Cancellable {

private final UUID playerUniqueId;
private final Home home;
private Location location;
private Position position;
private boolean cancelled;

public PreHomeTeleportEvent(UUID playerUniqueId, Home home) {
super(false);

this.playerUniqueId = playerUniqueId;
this.home = home;
this.location = home.getLocation();
this.position = home.getPosition();
}

public Home getHome() {
return this.home;
}

public Location getLocation() {
return this.location;
public Position getPosition() {
return this.position;
}

public void setLocation(Location location) {
this.location = location;
public void setPosition(Position position) {
this.position = position;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.eternalcode.core.feature.jail;

import com.eternalcode.commons.bukkit.position.Position;

import java.time.Duration;
import java.time.Instant;
import java.util.UUID;
Expand All @@ -10,12 +12,14 @@ public class JailedPlayer {
private final Instant detainedAt;
private final Duration prisonTime;
private final String detainedBy;
private final Position lastPosition;

public JailedPlayer(UUID player, Instant detainedAt, Duration prisonTime, String lockedUpBy) {
public JailedPlayer(UUID player, Instant detainedAt, Duration prisonTime, String detainedBy, Position lastPosition) {
this.player = player;
this.detainedAt = detainedAt;
this.prisonTime = prisonTime;
this.detainedBy = lockedUpBy;
this.detainedBy = detainedBy;
this.lastPosition = lastPosition;
}

public UUID getPlayerUniqueId() {
Expand All @@ -34,6 +38,10 @@ public Duration getPrisonTime() {
return this.prisonTime;
}

public Position getLastPosition() {
return this.lastPosition;
}

public boolean isPrisonExpired() {
return this.detainedAt.plus(this.prisonTime).isBefore(Instant.now());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.eternalcode.core.configuration.migrations;

import static eu.okaeri.configs.migrate.ConfigMigrationDsl.move;
import eu.okaeri.configs.migrate.builtin.NamedMigration;

class Migration_0009_Rename_allowed_to_restricted_jail_commands extends NamedMigration {

Migration_0009_Rename_allowed_to_restricted_jail_commands() {
super("Rename allowed to restricted jail commands",
move("jail.allowedCommands", "jail.restrictedCommands")
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.eternalcode.core.configuration.migrations;

import static eu.okaeri.configs.migrate.ConfigMigrationDsl.move;

import eu.okaeri.configs.migrate.builtin.NamedMigration;

public class Migration_0010_Rename_jail_section extends NamedMigration {

Migration_0010_Rename_jail_section() {
super(
"Rename jail section",

move("jailSection.jailLocationSet", "jail.locationSet"),
move("jailSection.jailLocationRemove", "jail.locationRemove"),
move("jailSection.jailLocationNotSet", "jail.locationNotSet"),
move("jailSection.jailLocationOverride", "jail.locationOverride"),

move("jailSection.jailDetainBroadcast", "jail.detainBroadcast"),
move("jailSection.jailDetainPrivate", "jail.detained"),
move("jailSection.jailDetainCountdown", "jail.detainCountdown"),
move("jailSection.jailDetainOverride", "jail.detainOverride"),
move("jailSection.jailDetainAdmin", "jail.detainAdmin"),

move("jailSection.jailReleaseBroadcast", "jail.releaseBroadcast"),
move("jailSection.jailReleasePrivate", "jail.released"),
move("jailSection.jailReleaseAll", "jail.releaseAll"),
move("jailSection.jailReleaseNoPlayers", "jail.releaseNoPlayers"),
move("jailSection.jailIsNotPrisoner", "jail.isNotPrisoner"),

move("jailSection.jailListHeader", "jail.listHeader"),
move("jailSection.jailListEmpty", "jail.listEmpty"),
move("jailSection.jailListPlayerEntry", "jail.listPlayerEntry"),

move("jailSection.jailCannotUseCommand", "jail.cannotUseCommand")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public class Migrations {
new Migration_0003_Move_tprp_to_dedicated_section(),
new Migration_0006_Move_alert_to_broadcast_section(),
new Migration_0007_Move_clear_to_dedicated_section(),
new Migration_0008_Move_repair_to_dedicated_section()
new Migration_0008_Move_repair_to_dedicated_section(),
new Migration_0009_Rename_allowed_to_restricted_jail_commands(),
new Migration_0010_Rename_jail_section()
};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.eternalcode.core.database.persister;

import com.eternalcode.commons.bukkit.position.Position;
import com.eternalcode.commons.bukkit.position.PositionAdapter;
import com.j256.ormlite.field.FieldType;
import com.j256.ormlite.field.SqlType;
import com.j256.ormlite.field.types.BaseDataType;
import com.j256.ormlite.support.DatabaseResults;

import java.sql.SQLException;

public class PositionPersister extends BaseDataType {

private static final PositionPersister instance = new PositionPersister();

private PositionPersister() {
super(SqlType.LONG_STRING, new Class<?>[] {Position.class});
}

@Override
public Object javaToSqlArg(FieldType fieldType, Object javaObject) {
if (javaObject == null) {
return null;
}

if (!(javaObject instanceof Position position)) {
throw new IllegalArgumentException("Invalid object type: " + javaObject.getClass().getName());
}

return position.toString();
}

@Override
public Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos) throws SQLException {
return results.getString(columnPos);
}

@Override
public Object parseDefaultString(FieldType fieldType, String defaultStr) {
return String.valueOf(defaultStr);
}

@Override
public Object sqlArgToJava(FieldType fieldType, Object sqlArg, int columnPos) {
String s = (String) sqlArg;

if (s == null) {
return null;
}

String[] params = s.split("/");

if (params.length != 6) {
throw new IllegalArgumentException("Invalid position format: " + s);
}

return new Position(
Double.parseDouble(params[1]),
Double.parseDouble(params[2]),
Double.parseDouble(params[3]),
Float.parseFloat(params[4]),
Float.parseFloat(params[5]),
params[0]
);
}

public static PositionPersister getSingleton() {
return instance;
}
}
Loading