diff --git a/pom.xml b/pom.xml
index d49376f..c36d67d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -60,6 +60,10 @@
1.16.5-R0.1-SNAPSHOT
1.20.0
+
+ 1.12.0
+
+ 1.4.0
1.1.0
@@ -185,6 +189,18 @@
${bentobox.version}
provided
+
+ world.bentobox
+ warps
+ ${warps.version}
+ provided
+
+
+ world.bentobox
+ visit
+ ${visit.version}
+ provided
+
lv.id.bonne
panelutils
diff --git a/src/main/java/world/bentobox/level/Level.java b/src/main/java/world/bentobox/level/Level.java
index 33c76a0..b1e65df 100644
--- a/src/main/java/world/bentobox/level/Level.java
+++ b/src/main/java/world/bentobox/level/Level.java
@@ -42,6 +42,9 @@ import world.bentobox.level.objects.LevelsData;
import world.bentobox.level.objects.TopTenData;
import world.bentobox.level.requests.LevelRequestHandler;
import world.bentobox.level.requests.TopTenRequestHandler;
+import world.bentobox.visit.VisitAddon;
+import world.bentobox.warps.Warp;
+
/**
* @author tastybento
@@ -63,6 +66,17 @@ public class Level extends Addon implements Listener {
private boolean roseStackersEnabled;
private final List registeredGameModes = new ArrayList<>();
+ /**
+ * Local variable that stores if warpHook is present.
+ */
+ private Warp warpHook;
+
+ /**
+ * Local variable that stores if visitHook is present.
+ */
+ private VisitAddon visitHook;
+
+
@Override
public void onLoad() {
// Save the default config from config.yml
@@ -125,10 +139,10 @@ public class Level extends Addon implements Listener {
advChestEnabled = advChest != null;
if (advChestEnabled) {
// Check version
- if (compareVersions(advChest.getDescription().getVersion(), "14.2") > 0) {
+ if (compareVersions(advChest.getDescription().getVersion(), "23.0") > 0) {
log("Hooked into AdvancedChests.");
} else {
- logError("Could not hook into AdvancedChests " + advChest.getDescription().getVersion() + " - requires version 14.3 or later");
+ logError("Could not hook into AdvancedChests " + advChest.getDescription().getVersion() + " - requires version 23.0 or later");
advChestEnabled = false;
}
}
@@ -139,6 +153,45 @@ public class Level extends Addon implements Listener {
}
}
+ @Override
+ public void allLoaded()
+ {
+ super.allLoaded();
+
+ if (this.isEnabled())
+ {
+ this.hookExtensions();
+ }
+ }
+
+
+ /**
+ * This method tries to hook into addons and plugins
+ */
+ private void hookExtensions()
+ {
+ // Try to find Visit addon and if it does not exist, display a warning
+ this.getAddonByName("Visit").ifPresentOrElse(addon ->
+ {
+ this.visitHook = (VisitAddon) addon;
+ this.log("Likes Addon hooked into Visit addon.");
+ }, () ->
+ {
+ this.visitHook = null;
+ });
+
+ // Try to find Warps addon and if it does not exist, display a warning
+ this.getAddonByName("Warps").ifPresentOrElse(addon ->
+ {
+ this.warpHook = (Warp) addon;
+ this.log("Likes Addon hooked into Warps addon.");
+ }, () ->
+ {
+ this.warpHook = null;
+ });
+ }
+
+
/**
* Compares versions
* @param version1
@@ -507,4 +560,23 @@ public class Level extends Addon implements Listener {
return roseStackersEnabled;
}
+ /**
+ * Method Level#getVisitHook returns the visitHook of this object.
+ *
+ * @return {@code Visit} of this object, {@code null} otherwise.
+ */
+ public VisitAddon getVisitHook()
+ {
+ return this.visitHook;
+ }
+
+ /**
+ * Method Level#getWarpHook returns the warpHook of this object.
+ *
+ * @return {@code Warp} of this object, {@code null} otherwise.
+ */
+ public Warp getWarpHook()
+ {
+ return this.warpHook;
+ }
}
diff --git a/src/main/java/world/bentobox/level/panels/TopLevelPanel.java b/src/main/java/world/bentobox/level/panels/TopLevelPanel.java
index 23c313a..937de87 100644
--- a/src/main/java/world/bentobox/level/panels/TopLevelPanel.java
+++ b/src/main/java/world/bentobox/level/panels/TopLevelPanel.java
@@ -13,6 +13,7 @@ import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
+import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.TemplatedPanel;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
@@ -185,22 +186,66 @@ public class TopLevelPanel
List activeActions = new ArrayList<>(template.actions());
activeActions.removeIf(action ->
- "VIEW".equalsIgnoreCase(action.actionType()) && island.getOwner() == null &&
- island.getMemberSet(RanksManager.MEMBER_RANK).
- contains(this.user.getUniqueId()));
+ {
+ switch (action.actionType().toUpperCase())
+ {
+ case "WARP" -> {
+ return island.getOwner() == null ||
+ this.addon.getWarpHook() == null ||
+ !this.addon.getWarpHook().getWarpSignsManager().hasWarp(this.world, island.getOwner());
+ }
+ case "VISIT" -> {
+ return island.getOwner() == null ||
+ this.addon.getVisitHook() == null ||
+ !this.addon.getVisitHook().getAddonManager().preprocessTeleportation(this.user, island);
+ }
+ case "VIEW" -> {
+ return island.getOwner() == null ||
+ !island.getMemberSet(RanksManager.MEMBER_RANK).contains(this.user.getUniqueId());
+ }
+ default -> {
+ return false;
+ }
+ }
+ });
// Add Click handler
builder.clickHandler((panel, user, clickType, i) ->
{
for (ItemTemplateRecord.ActionRecords action : activeActions)
{
- if ((clickType == action.clickType() || action.clickType() == ClickType.UNKNOWN) &&
- "VIEW".equalsIgnoreCase(action.actionType()))
+ if (clickType == action.clickType() || action.clickType() == ClickType.UNKNOWN)
{
- this.user.closeInventory();
- // Open Detailed GUI.
+ switch (action.actionType().toUpperCase())
+ {
+ case "WARP" -> {
+ this.user.closeInventory();
+ this.addon.getWarpHook().getWarpSignsManager().warpPlayer(this.world, this.user, island.getOwner());
+ }
+ case "VISIT" -> {
+ // The command call implementation solves necessity to check for all visits options,
+ // like cool down, confirmation and preprocess in single go. Would it be better to write
+ // all logic here?
- DetailsPanel.openPanel(this.addon, this.world, this.user);
+ this.addon.getPlugin().getIWM().getAddon(this.world).
+ flatMap(GameModeAddon::getPlayerCommand).ifPresent(command ->
+ {
+ String mainCommand =
+ this.addon.getVisitHook().getSettings().getPlayerMainCommand();
+
+ if (!mainCommand.isBlank())
+ {
+ this.user.closeInventory();
+ this.user.performCommand(command.getTopLabel() + " " + mainCommand + " " + island.getOwner());
+ }
+ });
+ }
+ case "VIEW" -> {
+ this.user.closeInventory();
+ // Open Detailed GUI.
+ DetailsPanel.openPanel(this.addon, this.world, this.user);
+ }
+ }
}
}
diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml
index af9d584..6456818 100755
--- a/src/main/resources/locales/en-US.yml
+++ b/src/main/resources/locales/en-US.yml
@@ -175,6 +175,9 @@ level:
right-click-to-clear: "&e Right Click &7 to clear."
click-to-asc: "&e Click &7 to sort in increasing order."
click-to-desc: "&e Click &7 to sort in decreasing order."
+ click-to-warp: "&e Click &7 to warp."
+ click-to-visit: "&e Click &7 to visit."
+ right-click-to-visit: "&e Right Click &7 to visit."
conversations:
# Prefix for messages that are send from server.
prefix: "&l&6 [BentoBox]: &r"
diff --git a/src/main/resources/panels/top_panel.yml b/src/main/resources/panels/top_panel.yml
index 2260c3a..3b80784 100644
--- a/src/main/resources/panels/top_panel.yml
+++ b/src/main/resources/panels/top_panel.yml
@@ -17,6 +17,13 @@ top_panel:
data:
type: TOP
index: 1
+ actions:
+ warp:
+ click-type: LEFT
+ tooltip: level.gui.tips.click-to-warp
+ visit:
+ click-type: RIGHT
+ tooltip: level.gui.tips.right-click-to-visit
fallback:
icon: LIME_STAINED_GLASS_PANE
title: level.gui.buttons.island.empty
@@ -28,6 +35,13 @@ top_panel:
data:
type: TOP
index: 2
+ actions:
+ warp:
+ click-type: LEFT
+ tooltip: level.gui.tips.click-to-warp
+ visit:
+ click-type: RIGHT
+ tooltip: level.gui.tips.right-click-to-visit
fallback:
icon: LIME_STAINED_GLASS_PANE
title: level.gui.buttons.island.empty
@@ -38,6 +52,13 @@ top_panel:
data:
type: TOP
index: 3
+ actions:
+ warp:
+ click-type: LEFT
+ tooltip: level.gui.tips.click-to-warp
+ visit:
+ click-type: RIGHT
+ tooltip: level.gui.tips.right-click-to-visit
fallback:
icon: LIME_STAINED_GLASS_PANE
title: level.gui.buttons.island.empty
@@ -49,6 +70,13 @@ top_panel:
data:
type: TOP
index: 4
+ actions:
+ warp:
+ click-type: LEFT
+ tooltip: level.gui.tips.click-to-warp
+ visit:
+ click-type: RIGHT
+ tooltip: level.gui.tips.right-click-to-visit
fallback:
icon: LIME_STAINED_GLASS_PANE
title: level.gui.buttons.island.empty
@@ -59,6 +87,13 @@ top_panel:
data:
type: TOP
index: 5
+ actions:
+ warp:
+ click-type: LEFT
+ tooltip: level.gui.tips.click-to-warp
+ visit:
+ click-type: RIGHT
+ tooltip: level.gui.tips.right-click-to-visit
fallback:
icon: LIME_STAINED_GLASS_PANE
title: level.gui.buttons.island.empty
@@ -69,6 +104,13 @@ top_panel:
data:
type: TOP
index: 6
+ actions:
+ warp:
+ click-type: LEFT
+ tooltip: level.gui.tips.click-to-warp
+ visit:
+ click-type: RIGHT
+ tooltip: level.gui.tips.right-click-to-visit
fallback:
icon: LIME_STAINED_GLASS_PANE
title: level.gui.buttons.island.empty
@@ -79,6 +121,13 @@ top_panel:
data:
type: TOP
index: 7
+ actions:
+ warp:
+ click-type: LEFT
+ tooltip: level.gui.tips.click-to-warp
+ visit:
+ click-type: RIGHT
+ tooltip: level.gui.tips.right-click-to-visit
fallback:
icon: LIME_STAINED_GLASS_PANE
title: level.gui.buttons.island.empty
@@ -89,6 +138,13 @@ top_panel:
data:
type: TOP
index: 8
+ actions:
+ warp:
+ click-type: LEFT
+ tooltip: level.gui.tips.click-to-warp
+ visit:
+ click-type: RIGHT
+ tooltip: level.gui.tips.right-click-to-visit
fallback:
icon: LIME_STAINED_GLASS_PANE
title: level.gui.buttons.island.empty
@@ -99,6 +155,13 @@ top_panel:
data:
type: TOP
index: 9
+ actions:
+ warp:
+ click-type: LEFT
+ tooltip: level.gui.tips.click-to-warp
+ visit:
+ click-type: RIGHT
+ tooltip: level.gui.tips.right-click-to-visit
fallback:
icon: LIME_STAINED_GLASS_PANE
title: level.gui.buttons.island.empty
@@ -109,6 +172,13 @@ top_panel:
data:
type: TOP
index: 10
+ actions:
+ warp:
+ click-type: LEFT
+ tooltip: level.gui.tips.click-to-warp
+ visit:
+ click-type: RIGHT
+ tooltip: level.gui.tips.right-click-to-visit
fallback:
icon: LIME_STAINED_GLASS_PANE
title: level.gui.buttons.island.empty