Skip to content

Commit

Permalink
* New legacy detection method in Labyrinth.java
Browse files Browse the repository at this point in the history
* New temporary storage method in PersistentContainer
* Changed all Region related listener information to Vent abstraction.
* Added new PrintedPaginationBuilder for automatic FinishingCompliment implementation
* Force creation of /Services/ parent folder on start if non existent.
* Removed SkullItem.java Use CustomHead.java instead
* Finished UniformedComponents.accept method
  • Loading branch information
Hempfest committed Jun 29, 2021
1 parent 6378fdf commit 3ea0a0a
Show file tree
Hide file tree
Showing 41 changed files with 339 additions and 720 deletions.
4 changes: 3 additions & 1 deletion Labyrinth.iml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
<root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.16.3-R0.1-SNAPSHOT/spigot-api-1.16.3-R0.1-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.16.3-R0.1-SNAPSHOT/spigot-api-1.16.3-R0.1-SNAPSHOT-sources.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
Expand Down
4 changes: 2 additions & 2 deletions labyrinth-afk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>Labyrinth</artifactId>
<groupId>com.github.sanctum</groupId>
<version>1.5.9</version>
<version>1.6.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -24,7 +24,7 @@
<dependency>
<groupId>com.github.sanctum</groupId>
<artifactId>Labyrinth-plugin</artifactId>
<version>1.5.9</version>
<version>1.6.1</version>
</dependency>
</dependencies>

Expand Down
6 changes: 3 additions & 3 deletions labyrinth-gui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<artifactId>Labyrinth</artifactId>
<groupId>com.github.sanctum</groupId>
<version>1.5.9</version>
<version>1.6.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>Labyrinth-GUI</artifactId>
<version>1.5.9</version>
<version>1.6.1</version>

<!--TODO: determine licensing (likely MIT)-->
<licenses>
Expand All @@ -30,7 +30,7 @@
<dependency>
<groupId>com.github.sanctum</groupId>
<artifactId>Labyrinth-plugin</artifactId>
<version>1.5.9</version>
<version>1.6.1</version>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions labyrinth-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<artifactId>Labyrinth</artifactId>
<groupId>com.github.sanctum</groupId>
<version>1.5.9</version>
<version>1.6.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>Labyrinth-plugin</artifactId>
<version>1.5.9</version>
<version>1.6.1</version>

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import com.github.sanctum.labyrinth.formatting.component.WrappedComponent;
import com.github.sanctum.labyrinth.library.CommandUtils;
import com.github.sanctum.labyrinth.library.Cooldown;
import com.github.sanctum.labyrinth.library.HUID;
import com.github.sanctum.labyrinth.library.Item;
import com.github.sanctum.labyrinth.library.NamespacedKey;
import com.github.sanctum.labyrinth.library.SkullItem;
import com.github.sanctum.labyrinth.library.StringUtils;
import com.github.sanctum.labyrinth.task.Schedule;
import java.io.IOException;
Expand All @@ -24,6 +24,7 @@
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
Expand Down Expand Up @@ -119,9 +120,7 @@ public void onDisable() {
} catch (InterruptedException ignored) {
}

SkullItem.getLog().clear();

if (Bukkit.getVersion().contains("1.14") || Bukkit.getVersion().contains("1.15") || Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.17")) {
if (!isLegacy()) {
if (Item.getCache().size() > 0) {
for (Item i : Item.getCache()) {
Item.removeEntry(i);
Expand All @@ -135,14 +134,29 @@ public VentMap getEventMap() {
return eventMap;
}

/**
* Get a queued list of running task id's
*
* @return A list of most running task id's
*/
public static ConcurrentLinkedQueue<Integer> getTasks() {
return TASKS;
}

/**
* Get all pre-cached cooldowns.
*
* @return A list of all cached cooldowns.
*/
public static LinkedList<Cooldown> getCooldowns() {
return COOLDOWNS;
}

/**
* Get all action wrapped text components.
*
* @return A list of all cached text components.
*/
public static LinkedList<WrappedComponent> getComponents() {
return COMPONENTS;
}
Expand Down Expand Up @@ -174,6 +188,15 @@ public static PersistentContainer getContainer(NamespacedKey key) {
return component;
}

/**
* @return true if the given server version is legacy only or false if its pro-1.13
*/
public static boolean isLegacy() {
return Bukkit.getVersion().contains("1.8") || Bukkit.getVersion().contains("1.9")
|| Bukkit.getVersion().contains("1.10") || Bukkit.getVersion().contains("1.11")
|| Bukkit.getVersion().contains("1.12") || Bukkit.getVersion().contains("1.13");
}

/**
* Auxiliary <strong>library</strong> instance.
*/
Expand All @@ -182,7 +205,7 @@ public static Plugin getInstance() {
}


static class ComponentListener implements Listener {
public static class ComponentListener implements Listener {
@EventHandler
public void onCommandNote(PlayerCommandPreprocessEvent e) {
for (WrappedComponent component : COMPONENTS) {
Expand All @@ -193,6 +216,11 @@ public void onCommandNote(PlayerCommandPreprocessEvent e) {
Schedule.sync(component::remove).waitReal(200);
}
e.setCancelled(true);
} else {
if (HUID.fromString(e.getMessage().replace("/", "")) != null) {
e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.ENTITY_VILLAGER_NO, 10, 1);
e.setCancelled(true);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.github.sanctum.labyrinth.data;

import com.github.sanctum.labyrinth.event.custom.Vent;
import com.github.sanctum.labyrinth.library.Cuboid;
import com.github.sanctum.labyrinth.task.Schedule;
import org.bukkit.plugin.Plugin;

public class RegionFlag extends Cuboid.Flag {

public static class Builder {

private final Plugin plugin;
private RegionService service;
private Vent.Subscription<?> subscription;
private String id;
private String message;

Expand All @@ -26,8 +26,13 @@ public Builder label(String id) {
return this;
}

@Deprecated
public Builder envelope(RegionService service) {
this.service = service;
return this;
}

public Builder envelope(Vent.Subscription<?> subscription) {
this.subscription = subscription;
return this;
}

Expand All @@ -37,7 +42,8 @@ public Builder receive(String message) {
}

public Cuboid.Flag finish() {
Schedule.sync(() -> RegionServicesManager.getInstance().load(service)).wait(1);
//Schedule.sync(() -> RegionServicesManager.getInstance().load(service)).wait(1);
Vent.subscribe(subscription);
return new RegionFlag(this.plugin, this.id, this.message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

import org.bukkit.event.Listener;

@Deprecated
public interface RegionService extends Listener {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.github.sanctum.labyrinth.library.Message;
import com.github.sanctum.labyrinth.task.Schedule;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -71,14 +70,21 @@ public boolean register(Cuboid.Flag flag) {

public boolean load(Cuboid.Flag flag) {
Bukkit.getPluginManager().registerEvents(flag, Labyrinth.getInstance());
return SERVICES.add(flag) && getFlagManager().getFlags().add(flag);
return getFlagManager().getFlags().add(flag);
}

public boolean load(Vent.Subscription<?> subscription) {
Vent.subscribe(subscription);
return true;
}

@Deprecated
public boolean load(RegionService service) {
Bukkit.getPluginManager().registerEvents(service, Labyrinth.getInstance());
return SERVICES.add(service);
}

@Deprecated
public boolean unload(RegionService service) {
HandlerList.unregisterAll(service);
return SERVICES.remove(service);
Expand Down Expand Up @@ -204,10 +210,7 @@ public static void start(Labyrinth instance) {

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

Schedule.sync(() -> {
CuboidSelectionEvent event = new CuboidSelectionEvent(selection);
instance.getServer().getPluginManager().callEvent(event);
}).run();
Schedule.sync(() -> new Vent.Call<>(new CuboidSelectionEvent(selection)).run()).run();

}

Expand All @@ -217,8 +220,7 @@ public static void start(Labyrinth instance) {

Optional<Region> r = CompletableFuture.supplyAsync(() -> Region.match(e.getBlock().getLocation())).join();
if (r.isPresent()) {
RegionDestroyEvent event = new RegionDestroyEvent(e.getPlayer(), r.get(), e.getBlock());
Bukkit.getPluginManager().callEvent(event);
RegionDestroyEvent event = new Vent.Call<>(new RegionDestroyEvent(e.getPlayer(), r.get(), e.getBlock())).run();
if (event.isCancelled()) {
e.setCancelled(true);
}
Expand All @@ -230,8 +232,7 @@ public static void start(Labyrinth instance) {

Optional<Region> r = CompletableFuture.supplyAsync(() -> Region.match(e.getBlock().getLocation())).join();
if (r.isPresent()) {
RegionBuildEvent event = new RegionBuildEvent(e.getPlayer(), r.get(), e.getBlock());
Bukkit.getPluginManager().callEvent(event);
RegionBuildEvent event = new Vent.Call<>(new RegionBuildEvent(e.getPlayer(), r.get(), e.getBlock())).run();
if (event.isCancelled()) {
e.setCancelled(true);
}
Expand Down Expand Up @@ -261,8 +262,7 @@ public static void start(Labyrinth instance) {
if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
Optional<Region> r = CompletableFuture.supplyAsync(() -> Region.match(e.getBlock().get().getLocation())).join();
if (r.isPresent()) {
RegionInteractionEvent event = new RegionInteractionEvent(e.getPlayer(), r.get(), e.getBlock().get(), RegionInteractionEvent.ClickType.LEFT);
Bukkit.getPluginManager().callEvent(event);
RegionInteractionEvent event = new Vent.Call<>(new RegionInteractionEvent(e.getPlayer(), r.get(), e.getBlock().get(), RegionInteractionEvent.ClickType.LEFT)).run();
if (event.isCancelled()) {
e.setCancelled(true);
}
Expand All @@ -274,7 +274,7 @@ public static void start(Labyrinth instance) {
if (!e.getPlayer().hasPermission("labyrinth.selection"))
return;

boolean isNew = Arrays.stream(Material.values()).anyMatch(m -> m.name().equals("WOODEN_AXE"));
boolean isNew = Labyrinth.isLegacy();

Material mat = Items.getMaterial("WOODEN_AXE");

Expand All @@ -290,16 +290,14 @@ public static void start(Labyrinth instance) {

selection.setPos1(e.getBlock().get().getLocation());

CuboidCreationEvent event = new CuboidCreationEvent(selection);
Bukkit.getPluginManager().callEvent(event);
new Vent.Call<>(new CuboidCreationEvent(selection)).run();

}
}
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
Optional<Region> r = CompletableFuture.supplyAsync(() -> Region.match(e.getBlock().get().getLocation())).join();
if (r.isPresent()) {
RegionInteractionEvent event = new RegionInteractionEvent(e.getPlayer(), r.get(), e.getBlock().get(), RegionInteractionEvent.ClickType.RIGHT);
Bukkit.getPluginManager().callEvent(event);
RegionInteractionEvent event = new Vent.Call<>(new RegionInteractionEvent(e.getPlayer(), r.get(), e.getBlock().get(), RegionInteractionEvent.ClickType.RIGHT)).run();
if (event.isCancelled()) {
e.setCancelled(true);
}
Expand All @@ -311,7 +309,7 @@ public static void start(Labyrinth instance) {
if (!e.getPlayer().hasPermission("labyrinth.selection"))
return;

boolean isNew = Arrays.stream(Material.values()).anyMatch(m -> m.name().equals("WOODEN_AXE"));
boolean isNew = Labyrinth.isLegacy();

Material mat = Items.getMaterial("WOODEN_AXE");

Expand All @@ -327,8 +325,7 @@ public static void start(Labyrinth instance) {

selection.setPos2(e.getBlock().get().getLocation());

CuboidCreationEvent event = new CuboidCreationEvent(selection);
Bukkit.getPluginManager().callEvent(event);
new Vent.Call<>(new CuboidCreationEvent(selection)).run();
}
}

Expand All @@ -346,8 +343,7 @@ public static void start(Labyrinth instance) {
if (r.getRegion().isPresent()) {
Region region = r.getRegion().get();

RegionPVPEvent e = new RegionPVPEvent(p, target, region);
Bukkit.getPluginManager().callEvent(e);
RegionPVPEvent e = new Vent.Call<>(new RegionPVPEvent(p, target, region)).run();

if (e.isCancelled()) {
event.setCancelled(true);
Expand All @@ -356,8 +352,6 @@ public static void start(Labyrinth instance) {

if (region instanceof Region.Spawn) {

Region.Spawn spawn = (Region.Spawn) region;

Region.Resident o = Region.Resident.get(p);

Region.Resident t = Region.Resident.get(target);
Expand All @@ -379,8 +373,7 @@ public static void start(Labyrinth instance) {
if (r.getRegion().isPresent()) {
Region region = r.getRegion().get();

RegionPVPEvent e = new RegionPVPEvent(p, target, region);
Bukkit.getPluginManager().callEvent(e);
RegionPVPEvent e = new Vent.Call<>(new RegionPVPEvent(p, target, region)).run();

if (e.isCancelled()) {
event.setCancelled(true);
Expand Down

0 comments on commit 3ea0a0a

Please sign in to comment.