Skip to content

Commit

Permalink
* New directional library addition
Browse files Browse the repository at this point in the history
* Optimized inner pagination utility.
  • Loading branch information
Hempfest committed Mar 14, 2021
1 parent 716a55f commit 7a84b07
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 11 deletions.
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.3.8</version>
<version>1.3.9</version>
<packaging>jar</packaging>

<name>Labyrinth</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.github.sanctum.labyrinth.gui.builder;

/**
* Thrown when no loading procedure is presented for the given menu.
*/
public final class IllegalMenuStateException extends Throwable {

public IllegalMenuStateException() {
super();
}

public IllegalMenuStateException(String message) {
super(message);
}

public IllegalMenuStateException(String message, Throwable cause) {
super(message, cause);
}

public IllegalMenuStateException(Throwable cause) {
super(cause);
}

protected IllegalMenuStateException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -157,8 +158,7 @@ public PaginatedBuilder setCloseAction(InventoryClose inventoryClose) {
}

/**
* Create a {@link ProcessElement} to customize each item to be displayed within the collection
* as-well as add any addition {@link ItemStack} elements.
* Create a {@link ProcessElement} to customize each item to be displayed within the collection.
*
* @param inventoryProcess The inventory processing operation.
* @return The same menu builder.
Expand Down Expand Up @@ -421,9 +421,11 @@ protected PaginatedBuilder adjust() {

Schedule.sync(() -> {
inv.addItem(event.getItem());
if (!contents.contains(event.getItem())) {
contents.add(event.getItem());
}
Schedule.sync(() -> {
if (!contents.contains(event.getItem())) {
contents.add(event.getItem());
}
}).debug().wait(1);
if (fill != null) {
Schedule.sync(() -> {
for (int l = 0; l < size; l++) {
Expand Down Expand Up @@ -584,8 +586,21 @@ protected PaginatedListener(PaginatedBuilder builder) {
}

@EventHandler(priority = EventPriority.NORMAL)
public void onProcess(SyncMenuItemPreProcessEvent e) {
builder.inventoryProcess.processEvent(new ProcessElement(e));
public void onProcess(SyncMenuItemPreProcessEvent e) throws IllegalMenuStateException {
if (builder.inventoryProcess == null) {
throw new IllegalMenuStateException("No inventory processing procedure was found for menu '" + ChatColor.stripColor(builder.title) + "'");
} else {
builder.inventoryProcess.processEvent(new ProcessElement(e));
}
}

@EventHandler(priority = EventPriority.NORMAL)
public void onProcess(SyncMenuSwitchPageEvent e) throws IllegalMenuStateException {
if (builder.inventoryProcess == null) {
throw new IllegalMenuStateException("No inventory processing procedure was found for menu '" + ChatColor.stripColor(builder.title) + "'");
} else {
builder.inventoryProcess.processEvent(new ProcessElement(e));
}
}

@EventHandler(priority = EventPriority.NORMAL)
Expand Down Expand Up @@ -625,7 +640,7 @@ public void onClick(InventoryClickEvent e) {
e.setCancelled(true);
return;
}
if (builder.contents.contains(item)) {
if (builder.contents.stream().anyMatch(i -> i.isSimilar(item))) {
builder.actions.get(item).clickEvent(new PaginatedClick(builder, p, e.getView(), item));
e.setCancelled(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
*/
public class ProcessElement {

private final SyncMenuItemPreProcessEvent event;
private SyncMenuItemPreProcessEvent event;

private SyncMenuSwitchPageEvent e;

protected ProcessElement(SyncMenuItemPreProcessEvent event) {
this.event = event;
}

protected ProcessElement(SyncMenuSwitchPageEvent event) {
this.e = event;
}

/**
* Create a lambda expression to formulate and customize primary menu elements.
*
Expand All @@ -22,4 +28,13 @@ public void applyLogic(Consumer<SyncMenuItemPreProcessEvent> syncMenuItemPreProc
syncMenuItemPreProcessEventConsumer.accept(event);
}

/**
* Create a lambda expression to formulate and customize successful page switches.
*
* @param syncMenuSwitchPageEventConsumer The item pre-process event.
*/
public void applyRunningLogic(Consumer<SyncMenuSwitchPageEvent> syncMenuSwitchPageEventConsumer) {
syncMenuSwitchPageEventConsumer.accept(e);
}

}
126 changes: 126 additions & 0 deletions src/main/java/com/github/sanctum/labyrinth/library/DirectivePoint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.github.sanctum.labyrinth.library;

import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;

public enum DirectivePoint {

North_East(226.65f, -1.20f),
North(179.84f, -0.30f),
North_West(135.29f, -1.80f),
West(90.59f, -0.75f),
South_West(43.04f, 0.59f),
South(359.24f, 2.54f),
South_East(318.89f, 1.79f),
East(269.69f, 0.44f);

private final float yaw;

private final float pitch;

DirectivePoint(float yaw, float pitch) {
this.yaw = yaw;
this.pitch = pitch;
}

public float getCenteredYaw() {
return yaw;
}

public float getCenteredPitch() {
return pitch;
}

public Chunk getChunk(Location start, int distanceInChunks) {
int dist = 16 * distanceInChunks;
start.setYaw(getCenteredYaw());
Vector target = start.toVector();
Location finish = start.add(target.multiply(dist));
return finish.getChunk();
}

public Location getLocation(Location start, int distanceInBlocks) {
start.setYaw(getCenteredYaw());
Vector target = start.toVector();
return start.add(target.multiply(distanceInBlocks));
}

public Chunk getChunk(Chunk start, int distanceInChunks) {
int x = start.getX();
int y = 85;
int z = start.getZ();
String world = start.getWorld().getName();
Location center = new Location(Bukkit.getWorld(world), (x << 4), y, (z << 4)).add(7.0D, 0.0D, 7.0D);
int dist = 16 * distanceInChunks;
center.setYaw(getCenteredYaw());
Vector target = center.toVector();
Location finish = center.add(target.multiply(dist));
return finish.getChunk();
}

public static DirectivePoint get(Player p) {
DirectivePoint result = null;
float y = p.getLocation().getYaw();
if (y < 0) {
y += 360;
}
y %= 360;
int i = (int) ((y + 8) / 22.5);
if (i == 0) {
result = DirectivePoint.South;
}
if (i == 1) {
result = DirectivePoint.South_West;
}
if (i == 2) {
result = DirectivePoint.South_West;
}
if (i == 3) {
result = DirectivePoint.South_West;
}
if (i == 4) {
result = DirectivePoint.West;
}
if (i == 5) {
result = DirectivePoint.North_West;
}
if (i == 6) {
result = DirectivePoint.North_West;
}
if (i == 7) {
result = DirectivePoint.North_West;
}
if (i == 8) {
result = DirectivePoint.North;
}
if (i == 9) {
result = DirectivePoint.North_East;
}
if (i == 10) {
result = DirectivePoint.North_East;
}
if (i == 11) {
result = DirectivePoint.North_East;
}
if (i == 12) {
result = DirectivePoint.East;
}
if (i == 13) {
result = DirectivePoint.South_East;
}
if (i == 14) {
result = DirectivePoint.South_East;
}
if (i == 15) {
result = DirectivePoint.South_East;
}
if (result == null) {
result = DirectivePoint.South;
}
return result;
}

}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Labyrinth
version: 1.3.8
version: 1.3.9
main: com.github.sanctum.labyrinth.Labyrinth
prefix: Labyrinth
api-version: 1.13
Expand Down

0 comments on commit 7a84b07

Please sign in to comment.