mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-11-29 14:15:13 +01:00
Implements visit/warp actions in top gui
Add 2 new actions for island buttons in TOP GUI: - Visit -> allows to visit island, but it requires Visit Addon - Warp -> allows to warp to island, but it requires Warp Addon Requested via Discord.
This commit is contained in:
parent
90ae98e599
commit
dae3db6c98
16
pom.xml
16
pom.xml
@ -60,6 +60,10 @@
|
|||||||
<!-- More visible way how to change dependency versions -->
|
<!-- More visible way how to change dependency versions -->
|
||||||
<spigot.version>1.16.5-R0.1-SNAPSHOT</spigot.version>
|
<spigot.version>1.16.5-R0.1-SNAPSHOT</spigot.version>
|
||||||
<bentobox.version>1.20.0</bentobox.version>
|
<bentobox.version>1.20.0</bentobox.version>
|
||||||
|
<!-- Warps addon version -->
|
||||||
|
<warps.version>1.12.0</warps.version>
|
||||||
|
<!-- Visit addon version -->
|
||||||
|
<visit.version>1.4.0</visit.version>
|
||||||
<!-- Panel Utils version -->
|
<!-- Panel Utils version -->
|
||||||
<panelutils.version>1.1.0</panelutils.version>
|
<panelutils.version>1.1.0</panelutils.version>
|
||||||
<!-- Revision variable removes warning about dynamic version -->
|
<!-- Revision variable removes warning about dynamic version -->
|
||||||
@ -185,6 +189,18 @@
|
|||||||
<version>${bentobox.version}</version>
|
<version>${bentobox.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>world.bentobox</groupId>
|
||||||
|
<artifactId>warps</artifactId>
|
||||||
|
<version>${warps.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>world.bentobox</groupId>
|
||||||
|
<artifactId>visit</artifactId>
|
||||||
|
<version>${visit.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>lv.id.bonne</groupId>
|
<groupId>lv.id.bonne</groupId>
|
||||||
<artifactId>panelutils</artifactId>
|
<artifactId>panelutils</artifactId>
|
||||||
|
@ -42,6 +42,9 @@ import world.bentobox.level.objects.LevelsData;
|
|||||||
import world.bentobox.level.objects.TopTenData;
|
import world.bentobox.level.objects.TopTenData;
|
||||||
import world.bentobox.level.requests.LevelRequestHandler;
|
import world.bentobox.level.requests.LevelRequestHandler;
|
||||||
import world.bentobox.level.requests.TopTenRequestHandler;
|
import world.bentobox.level.requests.TopTenRequestHandler;
|
||||||
|
import world.bentobox.visit.VisitAddon;
|
||||||
|
import world.bentobox.warps.Warp;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
@ -63,6 +66,17 @@ public class Level extends Addon implements Listener {
|
|||||||
private boolean roseStackersEnabled;
|
private boolean roseStackersEnabled;
|
||||||
private final List<GameModeAddon> registeredGameModes = new ArrayList<>();
|
private final List<GameModeAddon> 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
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
// Save the default config from config.yml
|
// Save the default config from config.yml
|
||||||
@ -125,10 +139,10 @@ public class Level extends Addon implements Listener {
|
|||||||
advChestEnabled = advChest != null;
|
advChestEnabled = advChest != null;
|
||||||
if (advChestEnabled) {
|
if (advChestEnabled) {
|
||||||
// Check version
|
// Check version
|
||||||
if (compareVersions(advChest.getDescription().getVersion(), "14.2") > 0) {
|
if (compareVersions(advChest.getDescription().getVersion(), "23.0") > 0) {
|
||||||
log("Hooked into AdvancedChests.");
|
log("Hooked into AdvancedChests.");
|
||||||
} else {
|
} 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;
|
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
|
* Compares versions
|
||||||
* @param version1
|
* @param version1
|
||||||
@ -507,4 +560,23 @@ public class Level extends Addon implements Listener {
|
|||||||
return roseStackersEnabled;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import java.io.File;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
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.PanelItem;
|
||||||
import world.bentobox.bentobox.api.panels.TemplatedPanel;
|
import world.bentobox.bentobox.api.panels.TemplatedPanel;
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||||
@ -185,24 +186,68 @@ public class TopLevelPanel
|
|||||||
List<ItemTemplateRecord.ActionRecords> activeActions = new ArrayList<>(template.actions());
|
List<ItemTemplateRecord.ActionRecords> activeActions = new ArrayList<>(template.actions());
|
||||||
|
|
||||||
activeActions.removeIf(action ->
|
activeActions.removeIf(action ->
|
||||||
"VIEW".equalsIgnoreCase(action.actionType()) && island.getOwner() == null &&
|
{
|
||||||
island.getMemberSet(RanksManager.MEMBER_RANK).
|
switch (action.actionType().toUpperCase())
|
||||||
contains(this.user.getUniqueId()));
|
{
|
||||||
|
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
|
// Add Click handler
|
||||||
builder.clickHandler((panel, user, clickType, i) ->
|
builder.clickHandler((panel, user, clickType, i) ->
|
||||||
{
|
{
|
||||||
for (ItemTemplateRecord.ActionRecords action : activeActions)
|
for (ItemTemplateRecord.ActionRecords action : activeActions)
|
||||||
{
|
{
|
||||||
if ((clickType == action.clickType() || action.clickType() == ClickType.UNKNOWN) &&
|
if (clickType == action.clickType() || action.clickType() == ClickType.UNKNOWN)
|
||||||
"VIEW".equalsIgnoreCase(action.actionType()))
|
{
|
||||||
|
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?
|
||||||
|
|
||||||
|
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();
|
this.user.closeInventory();
|
||||||
// Open Detailed GUI.
|
// Open Detailed GUI.
|
||||||
|
|
||||||
DetailsPanel.openPanel(this.addon, this.world, this.user);
|
DetailsPanel.openPanel(this.addon, this.world, this.user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -175,6 +175,9 @@ level:
|
|||||||
right-click-to-clear: "&e Right Click &7 to clear."
|
right-click-to-clear: "&e Right Click &7 to clear."
|
||||||
click-to-asc: "&e Click &7 to sort in increasing order."
|
click-to-asc: "&e Click &7 to sort in increasing order."
|
||||||
click-to-desc: "&e Click &7 to sort in decreasing 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:
|
conversations:
|
||||||
# Prefix for messages that are send from server.
|
# Prefix for messages that are send from server.
|
||||||
prefix: "&l&6 [BentoBox]: &r"
|
prefix: "&l&6 [BentoBox]: &r"
|
||||||
|
@ -17,6 +17,13 @@ top_panel:
|
|||||||
data:
|
data:
|
||||||
type: TOP
|
type: TOP
|
||||||
index: 1
|
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:
|
fallback:
|
||||||
icon: LIME_STAINED_GLASS_PANE
|
icon: LIME_STAINED_GLASS_PANE
|
||||||
title: level.gui.buttons.island.empty
|
title: level.gui.buttons.island.empty
|
||||||
@ -28,6 +35,13 @@ top_panel:
|
|||||||
data:
|
data:
|
||||||
type: TOP
|
type: TOP
|
||||||
index: 2
|
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:
|
fallback:
|
||||||
icon: LIME_STAINED_GLASS_PANE
|
icon: LIME_STAINED_GLASS_PANE
|
||||||
title: level.gui.buttons.island.empty
|
title: level.gui.buttons.island.empty
|
||||||
@ -38,6 +52,13 @@ top_panel:
|
|||||||
data:
|
data:
|
||||||
type: TOP
|
type: TOP
|
||||||
index: 3
|
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:
|
fallback:
|
||||||
icon: LIME_STAINED_GLASS_PANE
|
icon: LIME_STAINED_GLASS_PANE
|
||||||
title: level.gui.buttons.island.empty
|
title: level.gui.buttons.island.empty
|
||||||
@ -49,6 +70,13 @@ top_panel:
|
|||||||
data:
|
data:
|
||||||
type: TOP
|
type: TOP
|
||||||
index: 4
|
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:
|
fallback:
|
||||||
icon: LIME_STAINED_GLASS_PANE
|
icon: LIME_STAINED_GLASS_PANE
|
||||||
title: level.gui.buttons.island.empty
|
title: level.gui.buttons.island.empty
|
||||||
@ -59,6 +87,13 @@ top_panel:
|
|||||||
data:
|
data:
|
||||||
type: TOP
|
type: TOP
|
||||||
index: 5
|
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:
|
fallback:
|
||||||
icon: LIME_STAINED_GLASS_PANE
|
icon: LIME_STAINED_GLASS_PANE
|
||||||
title: level.gui.buttons.island.empty
|
title: level.gui.buttons.island.empty
|
||||||
@ -69,6 +104,13 @@ top_panel:
|
|||||||
data:
|
data:
|
||||||
type: TOP
|
type: TOP
|
||||||
index: 6
|
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:
|
fallback:
|
||||||
icon: LIME_STAINED_GLASS_PANE
|
icon: LIME_STAINED_GLASS_PANE
|
||||||
title: level.gui.buttons.island.empty
|
title: level.gui.buttons.island.empty
|
||||||
@ -79,6 +121,13 @@ top_panel:
|
|||||||
data:
|
data:
|
||||||
type: TOP
|
type: TOP
|
||||||
index: 7
|
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:
|
fallback:
|
||||||
icon: LIME_STAINED_GLASS_PANE
|
icon: LIME_STAINED_GLASS_PANE
|
||||||
title: level.gui.buttons.island.empty
|
title: level.gui.buttons.island.empty
|
||||||
@ -89,6 +138,13 @@ top_panel:
|
|||||||
data:
|
data:
|
||||||
type: TOP
|
type: TOP
|
||||||
index: 8
|
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:
|
fallback:
|
||||||
icon: LIME_STAINED_GLASS_PANE
|
icon: LIME_STAINED_GLASS_PANE
|
||||||
title: level.gui.buttons.island.empty
|
title: level.gui.buttons.island.empty
|
||||||
@ -99,6 +155,13 @@ top_panel:
|
|||||||
data:
|
data:
|
||||||
type: TOP
|
type: TOP
|
||||||
index: 9
|
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:
|
fallback:
|
||||||
icon: LIME_STAINED_GLASS_PANE
|
icon: LIME_STAINED_GLASS_PANE
|
||||||
title: level.gui.buttons.island.empty
|
title: level.gui.buttons.island.empty
|
||||||
@ -109,6 +172,13 @@ top_panel:
|
|||||||
data:
|
data:
|
||||||
type: TOP
|
type: TOP
|
||||||
index: 10
|
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:
|
fallback:
|
||||||
icon: LIME_STAINED_GLASS_PANE
|
icon: LIME_STAINED_GLASS_PANE
|
||||||
title: level.gui.buttons.island.empty
|
title: level.gui.buttons.island.empty
|
||||||
|
Loading…
Reference in New Issue
Block a user