Skip to content

Commit

Permalink
GH-744 Refactor warp system & api. (#744)
Browse files Browse the repository at this point in the history
* Refactor Warp Api.

* Fix merge things

* Update eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/event/PreWarpTeleportEvent.java

Co-authored-by: Michał Wojtas <[email protected]>

* Update eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/event/WarpTeleportEvent.java

Co-authored-by: Michał Wojtas <[email protected]>

* Update eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/event/PreWarpTeleportEvent.java

Co-authored-by: Michał Wojtas <[email protected]>

* Follow @imDMK Feedback.

* Follow mr. Norbert feedback.

Signed-off-by: Martin <[email protected]>

* Use WarpService interface to communicate in command.

---------

Signed-off-by: Martin <[email protected]>
Co-authored-by: Michał Wojtas <[email protected]>
  • Loading branch information
vLuckyyy and CitralFlo authored Apr 8, 2024
1 parent 3c65d0f commit 3c150fa
Show file tree
Hide file tree
Showing 18 changed files with 389 additions and 213 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.eternalcode.core.feature.warp.event;

import com.eternalcode.core.feature.warp.Warp;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

/**
* Called before teleportation to warp.
*/
public class PreWarpTeleportEvent extends Event implements Cancellable {

private static final HandlerList HANDLER_LIST = new HandlerList();

private final Player player;
private Warp warp;
private boolean cancelled;

public PreWarpTeleportEvent(Player player, Warp warp) {
super(false);

this.player = player;
this.warp = warp;
}

public Player getPlayer() {
return this.player;
}

public Warp getWarp() {
return this.warp;
}

public void setWarp(Warp warp) {
this.warp = warp;
}

@Override
public boolean isCancelled() {
return this.cancelled;
}

@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}

@Override
public HandlerList getHandlers() {
return HANDLER_LIST;
}

public static HandlerList getHandlerList() {
return HANDLER_LIST;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

public class WarpTeleportEvent extends Event implements Cancellable {
/**
* Called after teleportation to warp
*/
public class WarpTeleportEvent extends Event {

private static final HandlerList HANDLER_LIST = new HandlerList();

private final Player player;
private final Warp warp;
private boolean cancelled;

public WarpTeleportEvent(Player player, Warp warp) {
super(false);
Expand All @@ -34,16 +36,6 @@ public HandlerList getHandlers() {
return HANDLER_LIST;
}

@Override
public boolean isCancelled() {
return this.cancelled;
}

@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}

public static HandlerList getHandlerList() {
return HANDLER_LIST;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ public static class Items {

@Contextual
public static class Warp {
@Description("# Time of teleportation to warp's")
public Duration teleportTimeToWarp = Duration.ofSeconds(5);

@Description("# Warp inventory should be enabled?")
public boolean inventoryEnabled = true;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.eternalcode.core.feature.warp;

import com.eternalcode.commons.bukkit.position.Position;
import com.eternalcode.commons.bukkit.position.PositionAdapter;
import com.eternalcode.core.configuration.ConfigurationManager;
import com.eternalcode.core.configuration.implementation.LocationsConfiguration;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.injector.annotations.component.Service;
import com.eternalcode.commons.bukkit.position.Position;
import com.eternalcode.commons.bukkit.position.PositionAdapter;
import panda.std.Option;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import panda.std.Option;

@Service
class WarpConfigRepository implements WarpRepository {
Expand Down Expand Up @@ -43,13 +43,13 @@ private void edit(Consumer<Map<String, Position>> editor) {
editor.accept(warps);

this.locationsConfiguration.warps = warps;

this.configurationManager.save(this.locationsConfiguration);
}

@Override
public CompletableFuture<Option<Warp>> getWarp(String name) {
return CompletableFuture.completedFuture(Option.of(this.locationsConfiguration.warps.get(name)).map(location -> new WarpImpl(name, location)));
public CompletableFuture<Optional<Warp>> getWarp(String name) {
return CompletableFuture.completedFuture(Optional.of(this.locationsConfiguration.warps.get(name))
.map(location -> new WarpImpl(name, location)));
}

@Override
Expand All @@ -58,5 +58,4 @@ public CompletableFuture<List<Warp>> getWarps() {
.map(entry -> new WarpImpl(entry.getKey(), entry.getValue()))
.collect(Collectors.toList()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ public String getName() {
public Location getLocation() {
return PositionAdapter.convert(this.position);
}

}
Loading

0 comments on commit 3c150fa

Please sign in to comment.