Skip to content

Commit

Permalink
added type parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
NonSwag committed Mar 30, 2024
1 parent 26078a3 commit 1c954f4
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package net.thenextlvl.protect.event;

import com.sk89q.worldedit.regions.Region;
import lombok.Getter;
import lombok.Setter;
import net.thenextlvl.protect.area.Area;
import net.thenextlvl.protect.area.RegionizedArea;
import org.bukkit.event.Cancellable;

/**
Expand All @@ -13,10 +14,10 @@
*/
@Getter
@Setter
public class AreaDeleteEvent extends AreaEvent implements Cancellable {
public class AreaDeleteEvent<T extends Region> extends AreaEvent<RegionizedArea<T>> implements Cancellable {
private boolean cancelled;

public AreaDeleteEvent(Area area) {
public AreaDeleteEvent(RegionizedArea<T> area) {
super(area);
}
}
4 changes: 2 additions & 2 deletions api/src/main/java/net/thenextlvl/protect/event/AreaEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*/
@Getter
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
public abstract class AreaEvent extends Event {
public abstract class AreaEvent<T extends Area> extends Event {
private static final @Getter HandlerList handlerList = new HandlerList();
private final Area area;
private final T area;

@Override
public HandlerList getHandlers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*/
@Getter
@Setter
public class AreaRedefineEvent<T extends Region> extends AreaEvent implements Cancellable {
private final T region;
public class AreaRedefineEvent<T extends Region> extends AreaEvent<RegionizedArea<T>> implements Cancellable {
private boolean cancelled;
private final T region;

public AreaRedefineEvent(RegionizedArea<T> area, T region) {
super(area);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package net.thenextlvl.protect.event;

import com.sk89q.worldedit.regions.Region;
import lombok.Getter;
import lombok.Setter;
import net.thenextlvl.protect.area.Area;
import net.thenextlvl.protect.area.RegionizedArea;
import org.bukkit.event.Cancellable;

/**
Expand All @@ -13,10 +14,10 @@
*/
@Getter
@Setter
public class AreaSchematicDeleteEvent extends AreaEvent implements Cancellable {
public class AreaSchematicDeleteEvent<T extends Region> extends AreaEvent<RegionizedArea<T>> implements Cancellable {
private boolean cancelled;

public AreaSchematicDeleteEvent(Area area) {
public AreaSchematicDeleteEvent(RegionizedArea<T> area) {
super(area);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package net.thenextlvl.protect.event;

import com.sk89q.worldedit.regions.Region;
import lombok.Getter;
import net.thenextlvl.protect.area.Area;
import net.thenextlvl.protect.area.RegionizedArea;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -14,10 +15,10 @@
* @param <T> The type of region associated with the area.
*/
@Getter
public class AreaSchematicLoadEvent extends AreaEvent {
private final List<Consumer<Area>> successListeners = new ArrayList<>();
public class AreaSchematicLoadEvent<T extends Region> extends AreaEvent<RegionizedArea<T>> {
private final List<Consumer<RegionizedArea<T>>> successListeners = new ArrayList<>();

public AreaSchematicLoadEvent(Area area) {
public AreaSchematicLoadEvent(RegionizedArea<T> area) {
super(area);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
@Getter
@Setter
public class PlayerAreaEnterEvent extends PlayerAreaEvent implements Cancellable {
public class PlayerAreaEnterEvent extends PlayerAreaEvent<Area> implements Cancellable {
private boolean cancelled;

public PlayerAreaEnterEvent(Player player, Area area) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
* @param <T> The type of the area associated with the event.
*/
@Getter
public abstract class PlayerAreaEvent extends PlayerEvent {
public abstract class PlayerAreaEvent<T extends Area> extends PlayerEvent {
private static final @Getter HandlerList handlerList = new HandlerList();
private final Area area;
private final T area;

public PlayerAreaEvent(Player player, Area area) {
public PlayerAreaEvent(Player player, T area) {
super(player);
this.area = area;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
@Getter
@Setter
public class PlayerAreaLeaveEvent extends PlayerAreaEvent implements Cancellable {
public class PlayerAreaLeaveEvent extends PlayerAreaEvent<Area> implements Cancellable {
private boolean cancelled;

public PlayerAreaLeaveEvent(Player player, Area area) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
@Getter
@Setter
public class PlayerAreaTransitionEvent extends PlayerAreaEvent implements Cancellable {
public class PlayerAreaTransitionEvent extends PlayerAreaEvent<Area> implements Cancellable {
private final Area previous;
private boolean cancelled;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public CuboidArea create(@NamePattern String name, World world, BlockVector3 pos
public CuboidArea create(@NamePattern String name, World world, CuboidRegion region) {
var area = new CraftCuboidArea(plugin, name, world, region.clone(), 0);
plugin.loadAreas(area.getWorld()).getRoot().add(area);
new AreaCreateEvent(area).callEvent();
new AreaCreateEvent<>(area).callEvent();
return area;
}

@Override
public <T extends Region> boolean delete(RegionizedArea<T> area) {
if (!new AreaDeleteEvent(area).callEvent()) return false;
if (!new AreaDeleteEvent<>(area).callEvent()) return false;
var remove = plugin.loadAreas(area.getWorld()).getRoot().remove(area);
if (remove) handlePostRemove(area);
return remove;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public boolean isTooBig() {

@Override
public boolean deleteSchematic() {
return getSchematic().exists() && (new AreaSchematicDeleteEvent(this).callEvent() && getSchematic().delete());
return getSchematic().exists() && (new AreaSchematicDeleteEvent<>(this).callEvent() && getSchematic().delete());
}

@Override
Expand All @@ -113,7 +113,7 @@ public void saveSchematic() throws IOException, WorldEditException {
@Override
public boolean loadSchematic() throws IOException, WorldEditException {
if (!getSchematic().isFile()) return false;
var event = new AreaSchematicLoadEvent(CraftRegionizedArea.this);
var event = new AreaSchematicLoadEvent<>(CraftRegionizedArea.this);
if (!event.callEvent()) return false;
var world = new BukkitWorld(getWorld());
try (EditSession editSession = WorldEdit.getInstance().newEditSession(world)) {
Expand Down

0 comments on commit 1c954f4

Please sign in to comment.