Skip to content

Commit

Permalink
* Finished region interface & selection events
Browse files Browse the repository at this point in the history
* Optimized PaginatedList to completely ignore duplicate values
* Added new utility for precise time elapsing
  • Loading branch information
Hempfest committed May 15, 2021
1 parent dbf9250 commit 6ae50c3
Show file tree
Hide file tree
Showing 18 changed files with 220 additions and 32 deletions.
1 change: 0 additions & 1 deletion Labyrinth.iml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.26" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: me.clip:placeholderapi:2.10.6" level="project" />
<orderEntry type="library" name="Maven: com.github.MilkBowl:VaultAPI:1.7" level="project" />
<orderEntry type="library" name="Maven: org.bukkit:bukkit:1.13.1-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.sanctum.Labyrinth</groupId>
<artifactId>Labyrinth</artifactId>
<version>1.5.0</version>
<version>1.5.1</version>
<packaging>jar</packaging>

<name>Labyrinth</name>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/github/sanctum/labyrinth/Labyrinth.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.github.sanctum.labyrinth.data.VaultHook;
import com.github.sanctum.labyrinth.data.container.DataContainer;
import com.github.sanctum.labyrinth.event.CuboidController;
import com.github.sanctum.labyrinth.event.CuboidSelectionEvent;
import com.github.sanctum.labyrinth.event.EventBuilder;
import com.github.sanctum.labyrinth.formatting.string.WrappedComponent;
import com.github.sanctum.labyrinth.library.Applicable;
Expand Down Expand Up @@ -107,6 +108,9 @@ public void onEnable() {

Cuboid.Selection selection = Cuboid.Selection.source(p);

CuboidSelectionEvent event = new CuboidSelectionEvent(selection);
getServer().getPluginManager().callEvent(event);

if (selection.getPos1() != null && selection.getPos2() == null) {
Cuboid.Boundary cube = new Region.Boundary(selection.getPos1().getBlockX(), selection.getPos1().getBlockX(), selection.getPos1().getBlockY(), selection.getPos1().getBlockY(), selection.getPos1().getBlockZ(), selection.getPos1().getBlockZ()).target(p);
cube.deploy(action -> action.getPlayer().spawnParticle(org.bukkit.Particle.REDSTONE, action.getX(), action.getY(), action.getZ(), 1, new Particle.DustOptions(Cuboid.Boundary.Particle.GREEN.toColor(), 2)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ public void onEntityTarget(EntityTargetLivingEntityEvent e) {
@EventHandler
public void onInteract(PlayerInteractEvent e) {
if (e.getAction() == Action.LEFT_CLICK_BLOCK) {

if (Region.match(e.getClickedBlock().getLocation()).isPresent()) {
RegionInteractEvent event = new RegionInteractionEvent(e.getPlayer(), Region.match(e.getClickedBlock().getLocation()).get(), e.getClickedBlock(), RegionInteractionEvent.ClickType.LEFT);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
e.setCancelled(true);
}
}

if (e.getItem() == null)
return;

Expand All @@ -101,6 +110,15 @@ public void onInteract(PlayerInteractEvent e) {
}
}
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {

if (Region.match(e.getClickedBlock().getLocation()).isPresent()) {
RegionInteractEvent event = new RegionInteractionEvent(e.getPlayer(), Region.match(e.getClickedBlock().getLocation()).get(), e.getClickedBlock(), RegionInteractionEvent.ClickType.RIGHT);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
e.setCancelled(true);
}
}

if (e.getItem() == null)
return;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,59 @@
package com.github.sanctum.labyrinth.event;

import org.bukkit.event.Event;
import com.github.sanctum.labyrinth.library.Cuboid;
import java.util.Optional;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

public class CuboidSelectionEvent extends Event {
public class CuboidSelectionEvent extends PlayerEvent {

private static final HandlerList handlers = new HandlerList();

private final Cuboid.Selection selection;

public CuboidSelectionEvent() {

public CuboidSelectionEvent(Cuboid.Selection selection) {
super(selection.getPlayer());
this.selection = selection;
}

@Override
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}

public Optional<Location> getPos1() {
return Optional.ofNullable(selection.getPos1());
}

public Optional<Location> getPos2() {
return Optional.ofNullable(selection.getPos2());
}

public void setPos1(Location loc) {
selection.setPos1(loc);
}

public void setPos2(Location loc) {
selection.setPos2(loc);
}

public ItemStack getWand() {
return selection.getWand();
}

public void expand(Cuboid.Selection.Direction direction) {
selection.expand(direction);
}

public void expand(Cuboid.Selection.Direction direction, int amount) {
selection.expand(direction, amount);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

public class RegionBuildEvent extends RegionInteractEvent {

Expand All @@ -17,7 +18,7 @@ public RegionBuildEvent(Player player, Region region, Block block) {
}

@Override
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return handlers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

public class RegionDestroyEvent extends RegionInteractEvent {

Expand All @@ -17,7 +18,7 @@ public RegionDestroyEvent(Player player, Region region, Block block) {
}

@Override
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return handlers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,33 @@
import com.github.sanctum.labyrinth.data.Region;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;

public abstract class RegionInteractEvent extends Event implements Cancellable {
public abstract class RegionInteractEvent extends PlayerEvent implements Cancellable {

private static final HandlerList handlers = new HandlerList();

private final Region region;
private final Player player;
private final Type type;
private boolean cancelled;

public RegionInteractEvent(Type type, Player player, Region region) {
this.player = player;
super(player);
this.region = region;
this.type = type;
}

@Override
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}

public Player getPlayer() {
return player;
}

public Region getRegion() {
return region;
}
Expand All @@ -53,7 +49,7 @@ public void setCancelled(boolean cancel) {
}

public enum Type {
BUILD, BREAK, PVP
BUILD, BREAK, PVP, LEFT_CLICK, RIGHT_CLICK
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.github.sanctum.labyrinth.event;

import com.github.sanctum.labyrinth.data.Region;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

public class RegionInteractionEvent extends RegionInteractEvent {

private static final HandlerList handlers = new HandlerList();

private final Block block;

private final ClickType clickType;

public RegionInteractionEvent(Player player, Region region, Block block, ClickType type) {
super(type == ClickType.LEFT ? Type.LEFT_CLICK : Type.RIGHT_CLICK, player, region);
this.block = block;
this.clickType = type;
}

@Override
public @NotNull HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}

public ClickType getClickType() {
return clickType;
}

public Block getBlock() {
return block;
}

public enum ClickType {
RIGHT, LEFT
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

public class RegionPVPEvent extends RegionInteractEvent {

Expand All @@ -18,7 +19,7 @@ public RegionPVPEvent(Player player, Player target, Region region) {
}

@Override
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return handlers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.sanctum.labyrinth.data.Region;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

public class RegionTraverseEvent extends Event {

Expand All @@ -15,7 +16,7 @@ public RegionTraverseEvent(Region.Resident resident) {
}

@Override
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return handlers;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.sanctum.labyrinth.formatting;

public interface ComponentCompliment {
public interface ComponentCompliment<T> {

void apply(int page, int max);
void apply(PaginatedList<T> pagination, int page, int max);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.github.sanctum.labyrinth.formatting;

public interface FinishingCompliment<T> extends ComponentCompliment {
public interface FinishingCompliment<T> extends ComponentCompliment<T> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.sanctum.labyrinth.library.MathUtils;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;

Expand All @@ -13,8 +14,8 @@
public class PaginatedList<T> {
private final List<T> typeList;
private Comparator<? super T> comparable;
private ComponentCompliment start;
private ComponentCompliment finish;
private ComponentCompliment<T> start;
private ComponentCompliment<T> finish;
private ComponentDecoration<T> decoration;
private int linesPerPage;

Expand Down Expand Up @@ -104,7 +105,7 @@ public List<T> get(int pageNum) {

int o = linesPerPage;

List<T> tempList = new LinkedList<>(this.typeList);
List<T> tempList = new LinkedList<>(new LinkedHashSet<>(this.typeList));
int totalPageCount = 1;
if ((tempList.size() % o) == 0) {
if (tempList.size() > 0) {
Expand All @@ -117,7 +118,7 @@ public List<T> get(int pageNum) {
if (page <= totalPageCount) {

if (this.start != null) {
this.start.apply(pageNum, totalPageCount);
this.start.apply(this, pageNum, totalPageCount);
}

if (!tempList.isEmpty()) {
Expand All @@ -141,7 +142,7 @@ public List<T> get(int pageNum) {
tempList.remove(value);
}
if (this.finish != null) {
this.finish.apply(pageNum, totalPageCount);
this.finish.apply(this, pageNum, totalPageCount);
}
}
// end line
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.github.sanctum.labyrinth.formatting;

public interface StartingCompliment<T> extends ComponentCompliment {
public interface StartingCompliment<T> extends ComponentCompliment<T> {

}

0 comments on commit 6ae50c3

Please sign in to comment.