Skip to content

Commit 6ae50c3

Browse files
committed
* Finished region interface & selection events
* Optimized PaginatedList to completely ignore duplicate values * Added new utility for precise time elapsing
1 parent dbf9250 commit 6ae50c3

18 files changed

+220
-32
lines changed

Labyrinth.iml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.26" level="project" />
2929
<orderEntry type="library" scope="PROVIDED" name="Maven: me.clip:placeholderapi:2.10.6" level="project" />
3030
<orderEntry type="library" name="Maven: com.github.MilkBowl:VaultAPI:1.7" level="project" />
31-
<orderEntry type="library" name="Maven: org.bukkit:bukkit:1.13.1-R0.1-SNAPSHOT" level="project" />
3231
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
3332
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
3433
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.sanctum.Labyrinth</groupId>
88
<artifactId>Labyrinth</artifactId>
9-
<version>1.5.0</version>
9+
<version>1.5.1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>Labyrinth</name>

src/main/java/com/github/sanctum/labyrinth/Labyrinth.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.github.sanctum.labyrinth.data.VaultHook;
1111
import com.github.sanctum.labyrinth.data.container.DataContainer;
1212
import com.github.sanctum.labyrinth.event.CuboidController;
13+
import com.github.sanctum.labyrinth.event.CuboidSelectionEvent;
1314
import com.github.sanctum.labyrinth.event.EventBuilder;
1415
import com.github.sanctum.labyrinth.formatting.string.WrappedComponent;
1516
import com.github.sanctum.labyrinth.library.Applicable;
@@ -107,6 +108,9 @@ public void onEnable() {
107108

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

111+
CuboidSelectionEvent event = new CuboidSelectionEvent(selection);
112+
getServer().getPluginManager().callEvent(event);
113+
110114
if (selection.getPos1() != null && selection.getPos2() == null) {
111115
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);
112116
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)));

src/main/java/com/github/sanctum/labyrinth/event/CuboidController.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ public void onEntityTarget(EntityTargetLivingEntityEvent e) {
7575
@EventHandler
7676
public void onInteract(PlayerInteractEvent e) {
7777
if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
78+
79+
if (Region.match(e.getClickedBlock().getLocation()).isPresent()) {
80+
RegionInteractEvent event = new RegionInteractionEvent(e.getPlayer(), Region.match(e.getClickedBlock().getLocation()).get(), e.getClickedBlock(), RegionInteractionEvent.ClickType.LEFT);
81+
Bukkit.getPluginManager().callEvent(event);
82+
if (event.isCancelled()) {
83+
e.setCancelled(true);
84+
}
85+
}
86+
7887
if (e.getItem() == null)
7988
return;
8089

@@ -101,6 +110,15 @@ public void onInteract(PlayerInteractEvent e) {
101110
}
102111
}
103112
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
113+
114+
if (Region.match(e.getClickedBlock().getLocation()).isPresent()) {
115+
RegionInteractEvent event = new RegionInteractionEvent(e.getPlayer(), Region.match(e.getClickedBlock().getLocation()).get(), e.getClickedBlock(), RegionInteractionEvent.ClickType.RIGHT);
116+
Bukkit.getPluginManager().callEvent(event);
117+
if (event.isCancelled()) {
118+
e.setCancelled(true);
119+
}
120+
}
121+
104122
if (e.getItem() == null)
105123
return;
106124

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,59 @@
11
package com.github.sanctum.labyrinth.event;
22

3-
import org.bukkit.event.Event;
3+
import com.github.sanctum.labyrinth.library.Cuboid;
4+
import java.util.Optional;
5+
import org.bukkit.Location;
46
import org.bukkit.event.HandlerList;
7+
import org.bukkit.event.player.PlayerEvent;
8+
import org.bukkit.inventory.ItemStack;
9+
import org.jetbrains.annotations.NotNull;
510

6-
public class CuboidSelectionEvent extends Event {
11+
public class CuboidSelectionEvent extends PlayerEvent {
712

813
private static final HandlerList handlers = new HandlerList();
914

15+
private final Cuboid.Selection selection;
1016

11-
public CuboidSelectionEvent() {
12-
17+
public CuboidSelectionEvent(Cuboid.Selection selection) {
18+
super(selection.getPlayer());
19+
this.selection = selection;
1320
}
1421

1522
@Override
16-
public HandlerList getHandlers() {
23+
public @NotNull HandlerList getHandlers() {
1724
return handlers;
1825
}
1926

2027
public static HandlerList getHandlerList() {
2128
return handlers;
2229
}
2330

31+
public Optional<Location> getPos1() {
32+
return Optional.ofNullable(selection.getPos1());
33+
}
34+
35+
public Optional<Location> getPos2() {
36+
return Optional.ofNullable(selection.getPos2());
37+
}
38+
39+
public void setPos1(Location loc) {
40+
selection.setPos1(loc);
41+
}
42+
43+
public void setPos2(Location loc) {
44+
selection.setPos2(loc);
45+
}
46+
47+
public ItemStack getWand() {
48+
return selection.getWand();
49+
}
50+
51+
public void expand(Cuboid.Selection.Direction direction) {
52+
selection.expand(direction);
53+
}
54+
55+
public void expand(Cuboid.Selection.Direction direction, int amount) {
56+
selection.expand(direction, amount);
57+
}
2458

2559
}

src/main/java/com/github/sanctum/labyrinth/event/RegionBuildEvent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.bukkit.block.Block;
55
import org.bukkit.entity.Player;
66
import org.bukkit.event.HandlerList;
7+
import org.jetbrains.annotations.NotNull;
78

89
public class RegionBuildEvent extends RegionInteractEvent {
910

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

1920
@Override
20-
public HandlerList getHandlers() {
21+
public @NotNull HandlerList getHandlers() {
2122
return handlers;
2223
}
2324

src/main/java/com/github/sanctum/labyrinth/event/RegionDestroyEvent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.bukkit.block.Block;
55
import org.bukkit.entity.Player;
66
import org.bukkit.event.HandlerList;
7+
import org.jetbrains.annotations.NotNull;
78

89
public class RegionDestroyEvent extends RegionInteractEvent {
910

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

1920
@Override
20-
public HandlerList getHandlers() {
21+
public @NotNull HandlerList getHandlers() {
2122
return handlers;
2223
}
2324

src/main/java/com/github/sanctum/labyrinth/event/RegionInteractEvent.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,33 @@
33
import com.github.sanctum.labyrinth.data.Region;
44
import org.bukkit.entity.Player;
55
import org.bukkit.event.Cancellable;
6-
import org.bukkit.event.Event;
76
import org.bukkit.event.HandlerList;
7+
import org.bukkit.event.player.PlayerEvent;
8+
import org.jetbrains.annotations.NotNull;
89

9-
public abstract class RegionInteractEvent extends Event implements Cancellable {
10+
public abstract class RegionInteractEvent extends PlayerEvent implements Cancellable {
1011

1112
private static final HandlerList handlers = new HandlerList();
1213

1314
private final Region region;
14-
private final Player player;
1515
private final Type type;
1616
private boolean cancelled;
1717

1818
public RegionInteractEvent(Type type, Player player, Region region) {
19-
this.player = player;
19+
super(player);
2020
this.region = region;
2121
this.type = type;
2222
}
2323

2424
@Override
25-
public HandlerList getHandlers() {
25+
public @NotNull HandlerList getHandlers() {
2626
return handlers;
2727
}
2828

2929
public static HandlerList getHandlerList() {
3030
return handlers;
3131
}
3232

33-
public Player getPlayer() {
34-
return player;
35-
}
36-
3733
public Region getRegion() {
3834
return region;
3935
}
@@ -53,7 +49,7 @@ public void setCancelled(boolean cancel) {
5349
}
5450

5551
public enum Type {
56-
BUILD, BREAK, PVP
52+
BUILD, BREAK, PVP, LEFT_CLICK, RIGHT_CLICK
5753
}
5854

5955

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.github.sanctum.labyrinth.event;
2+
3+
import com.github.sanctum.labyrinth.data.Region;
4+
import org.bukkit.block.Block;
5+
import org.bukkit.entity.Player;
6+
import org.bukkit.event.HandlerList;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
public class RegionInteractionEvent extends RegionInteractEvent {
10+
11+
private static final HandlerList handlers = new HandlerList();
12+
13+
private final Block block;
14+
15+
private final ClickType clickType;
16+
17+
public RegionInteractionEvent(Player player, Region region, Block block, ClickType type) {
18+
super(type == ClickType.LEFT ? Type.LEFT_CLICK : Type.RIGHT_CLICK, player, region);
19+
this.block = block;
20+
this.clickType = type;
21+
}
22+
23+
@Override
24+
public @NotNull HandlerList getHandlers() {
25+
return handlers;
26+
}
27+
28+
public static HandlerList getHandlerList() {
29+
return handlers;
30+
}
31+
32+
public ClickType getClickType() {
33+
return clickType;
34+
}
35+
36+
public Block getBlock() {
37+
return block;
38+
}
39+
40+
public enum ClickType {
41+
RIGHT, LEFT
42+
}
43+
44+
}

src/main/java/com/github/sanctum/labyrinth/event/RegionPVPEvent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.bukkit.entity.Player;
66
import org.bukkit.event.HandlerList;
77
import org.bukkit.inventory.ItemStack;
8+
import org.jetbrains.annotations.NotNull;
89

910
public class RegionPVPEvent extends RegionInteractEvent {
1011

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

2021
@Override
21-
public HandlerList getHandlers() {
22+
public @NotNull HandlerList getHandlers() {
2223
return handlers;
2324
}
2425

src/main/java/com/github/sanctum/labyrinth/event/RegionTraverseEvent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.github.sanctum.labyrinth.data.Region;
44
import org.bukkit.event.Event;
55
import org.bukkit.event.HandlerList;
6+
import org.jetbrains.annotations.NotNull;
67

78
public class RegionTraverseEvent extends Event {
89

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

1718
@Override
18-
public HandlerList getHandlers() {
19+
public @NotNull HandlerList getHandlers() {
1920
return handlers;
2021
}
2122

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.sanctum.labyrinth.formatting;
22

3-
public interface ComponentCompliment {
3+
public interface ComponentCompliment<T> {
44

5-
void apply(int page, int max);
5+
void apply(PaginatedList<T> pagination, int page, int max);
66

77
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.github.sanctum.labyrinth.formatting;
22

3-
public interface FinishingCompliment<T> extends ComponentCompliment {
3+
public interface FinishingCompliment<T> extends ComponentCompliment<T> {
44

55
}

src/main/java/com/github/sanctum/labyrinth/formatting/PaginatedList.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.github.sanctum.labyrinth.library.MathUtils;
44
import java.util.Comparator;
5+
import java.util.LinkedHashSet;
56
import java.util.LinkedList;
67
import java.util.List;
78

@@ -13,8 +14,8 @@
1314
public class PaginatedList<T> {
1415
private final List<T> typeList;
1516
private Comparator<? super T> comparable;
16-
private ComponentCompliment start;
17-
private ComponentCompliment finish;
17+
private ComponentCompliment<T> start;
18+
private ComponentCompliment<T> finish;
1819
private ComponentDecoration<T> decoration;
1920
private int linesPerPage;
2021

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

105106
int o = linesPerPage;
106107

107-
List<T> tempList = new LinkedList<>(this.typeList);
108+
List<T> tempList = new LinkedList<>(new LinkedHashSet<>(this.typeList));
108109
int totalPageCount = 1;
109110
if ((tempList.size() % o) == 0) {
110111
if (tempList.size() > 0) {
@@ -117,7 +118,7 @@ public List<T> get(int pageNum) {
117118
if (page <= totalPageCount) {
118119

119120
if (this.start != null) {
120-
this.start.apply(pageNum, totalPageCount);
121+
this.start.apply(this, pageNum, totalPageCount);
121122
}
122123

123124
if (!tempList.isEmpty()) {
@@ -141,7 +142,7 @@ public List<T> get(int pageNum) {
141142
tempList.remove(value);
142143
}
143144
if (this.finish != null) {
144-
this.finish.apply(pageNum, totalPageCount);
145+
this.finish.apply(this, pageNum, totalPageCount);
145146
}
146147
}
147148
// end line
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.github.sanctum.labyrinth.formatting;
22

3-
public interface StartingCompliment<T> extends ComponentCompliment {
3+
public interface StartingCompliment<T> extends ComponentCompliment<T> {
44

55
}

0 commit comments

Comments
 (0)