mirror of
https://github.com/BentoBoxWorld/Warps.git
synced 2024-11-22 10:35:52 +01:00
Merge into master
This commit is contained in:
commit
076b71ce9b
7
pom.xml
7
pom.xml
@ -66,7 +66,7 @@
|
|||||||
<!-- Do not change unless you want different name for local builds. -->
|
<!-- Do not change unless you want different name for local builds. -->
|
||||||
<build.number>-LOCAL</build.number>
|
<build.number>-LOCAL</build.number>
|
||||||
<!-- This allows to change between versions. -->
|
<!-- This allows to change between versions. -->
|
||||||
<build.version>1.11.2</build.version>
|
<build.version>1.12.0</build.version>
|
||||||
<!-- Sonar Cloud -->
|
<!-- Sonar Cloud -->
|
||||||
<sonar.projectKey>BentoBoxWorld_Warps</sonar.projectKey>
|
<sonar.projectKey>BentoBoxWorld_Warps</sonar.projectKey>
|
||||||
<sonar.organization>bentobox-world</sonar.organization>
|
<sonar.organization>bentobox-world</sonar.organization>
|
||||||
@ -138,6 +138,11 @@
|
|||||||
<version>${spigot.version}</version>
|
<version>${spigot.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>plugin-annotations</artifactId>
|
||||||
|
<version>1.2.3-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
<!-- Mockito (Unit testing) -->
|
<!-- Mockito (Unit testing) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
|
@ -17,6 +17,9 @@ import world.bentobox.warps.commands.WarpCommand;
|
|||||||
import world.bentobox.warps.commands.WarpsCommand;
|
import world.bentobox.warps.commands.WarpsCommand;
|
||||||
import world.bentobox.warps.config.Settings;
|
import world.bentobox.warps.config.Settings;
|
||||||
import world.bentobox.warps.listeners.WarpSignsListener;
|
import world.bentobox.warps.listeners.WarpSignsListener;
|
||||||
|
import world.bentobox.warps.managers.SignCacheManager;
|
||||||
|
import world.bentobox.warps.managers.WarpSignsManager;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Addin to BentoBox that enables welcome warp signs
|
* Addin to BentoBox that enables welcome warp signs
|
||||||
@ -38,16 +41,16 @@ public class Warp extends Addon {
|
|||||||
*/
|
*/
|
||||||
public static final String WELCOME_WARP_SIGNS = "welcomewarpsigns";
|
public static final String WELCOME_WARP_SIGNS = "welcomewarpsigns";
|
||||||
|
|
||||||
/**
|
|
||||||
* Warp panel Manager
|
|
||||||
*/
|
|
||||||
private WarpPanelManager warpPanelManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Worlds Sign manager.
|
* Worlds Sign manager.
|
||||||
*/
|
*/
|
||||||
private WarpSignsManager warpSignsManager;
|
private WarpSignsManager warpSignsManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sign Cache Manager
|
||||||
|
*/
|
||||||
|
private SignCacheManager signCacheManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This variable stores in which worlds this addon is working.
|
* This variable stores in which worlds this addon is working.
|
||||||
*/
|
*/
|
||||||
@ -136,7 +139,7 @@ public class Warp extends Addon {
|
|||||||
{
|
{
|
||||||
// Start warp signs
|
// Start warp signs
|
||||||
warpSignsManager = new WarpSignsManager(this, this.getPlugin());
|
warpSignsManager = new WarpSignsManager(this, this.getPlugin());
|
||||||
warpPanelManager = new WarpPanelManager(this);
|
signCacheManager = new SignCacheManager(this);
|
||||||
// Load the listener
|
// Load the listener
|
||||||
this.registerListener(new WarpSignsListener(this));
|
this.registerListener(new WarpSignsListener(this));
|
||||||
} else {
|
} else {
|
||||||
@ -169,17 +172,21 @@ public class Warp extends Addon {
|
|||||||
this.setState(State.DISABLED);
|
this.setState(State.DISABLED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save existing panels.
|
||||||
|
this.saveResource("panels/warps_panel.yml", false);
|
||||||
|
|
||||||
settingsConfig.saveConfigObject(settings);
|
settingsConfig.saveConfigObject(settings);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get warp panel manager
|
* Get sign cache manager
|
||||||
* @return Warp Panel Manager
|
* @return Sign Cache Manager
|
||||||
*/
|
*/
|
||||||
public WarpPanelManager getWarpPanelManager() {
|
public SignCacheManager getSignCacheManager() {
|
||||||
return warpPanelManager;
|
return signCacheManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WarpSignsManager getWarpSignsManager() {
|
public WarpSignsManager getWarpSignsManager() {
|
||||||
|
@ -1,187 +0,0 @@
|
|||||||
package world.bentobox.warps;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
|
||||||
import world.bentobox.bentobox.api.user.User;
|
|
||||||
|
|
||||||
public class WarpPanelManager {
|
|
||||||
|
|
||||||
private static final int PANEL_MAX_SIZE = 52;
|
|
||||||
private final Warp addon;
|
|
||||||
// This is a cache of signs
|
|
||||||
private final SignCacheManager signCacheManager;
|
|
||||||
|
|
||||||
public WarpPanelManager(Warp addon) {
|
|
||||||
this.addon = addon;
|
|
||||||
signCacheManager = new SignCacheManager(addon);
|
|
||||||
}
|
|
||||||
|
|
||||||
private PanelItem getPanelItem(World world, UUID warpOwner, SignCacheItem sign) {
|
|
||||||
|
|
||||||
PanelItemBuilder pib = new PanelItemBuilder()
|
|
||||||
.name(addon.getSettings().getNameFormat() + addon.getPlugin().getPlayers().getName(warpOwner))
|
|
||||||
.description(sign.getSignText())
|
|
||||||
.clickHandler((panel, clicker, click, slot) -> hander(world, clicker, warpOwner));
|
|
||||||
Material icon = sign.getType();
|
|
||||||
if (icon.equals(Material.PLAYER_HEAD)) {
|
|
||||||
return pib.icon(addon.getPlayers().getName(warpOwner)).build();
|
|
||||||
} else {
|
|
||||||
return pib.icon(icon).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hander(World world, User clicker, UUID warpOwner) {
|
|
||||||
clicker.closeInventory();
|
|
||||||
String playerCommand = addon.getPlugin().getIWM().getAddon(world).map(gm -> gm.getPlayerCommand().map(Command::getLabel).orElse("")).orElse("");
|
|
||||||
String command = addon.getSettings().getWarpCommand() + " " + addon.getPlayers().getName(warpOwner);
|
|
||||||
clicker.getPlayer().performCommand((playerCommand.isEmpty() ? "" : playerCommand + " ") + command);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private PanelItem getRandomButton(World world, User user, UUID warpOwner) {
|
|
||||||
return new PanelItemBuilder()
|
|
||||||
.name(addon.getSettings().getNameFormat() + user.getTranslation("warps.random"))
|
|
||||||
.clickHandler((panel, clicker, click, slot) -> hander(world, clicker, warpOwner))
|
|
||||||
.icon(Material.END_CRYSTAL).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the warp panel for the user
|
|
||||||
* @param world - world
|
|
||||||
* @param user - user
|
|
||||||
* @param index - page to show - 0 is first
|
|
||||||
*/
|
|
||||||
public void showWarpPanel(World world, User user, int index) {
|
|
||||||
|
|
||||||
PanelBuilder panelBuilder = new PanelBuilder()
|
|
||||||
.user(user)
|
|
||||||
.name(user.getTranslation("warps.title") + " " + (index + 1));
|
|
||||||
|
|
||||||
buildPanel(panelBuilder, user, index, world).thenRun(panelBuilder::build);
|
|
||||||
}
|
|
||||||
|
|
||||||
CompletableFuture<Void> buildPanel(PanelBuilder panelBuilder, User user, int index, World world) {
|
|
||||||
CompletableFuture<Void> r = new CompletableFuture<>();
|
|
||||||
processSigns(r, panelBuilder, user, index, world);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
void processSigns(CompletableFuture<Void> r, PanelBuilder panelBuilder, User user, int index, World world) {
|
|
||||||
addon.getWarpSignsManager().getSortedWarps(world).thenAccept(warps -> {
|
|
||||||
// Cache and clean the signs
|
|
||||||
Iterator<UUID> it = warps.iterator();
|
|
||||||
while(it.hasNext()) {
|
|
||||||
UUID warpOwner = it.next();
|
|
||||||
@NonNull
|
|
||||||
SignCacheItem sign = signCacheManager.getSignItem(world, warpOwner);
|
|
||||||
if (!sign.isReal()) {
|
|
||||||
it.remove();
|
|
||||||
addon.getWarpSignsManager().removeWarpFromMap(world, warpOwner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Add random warp
|
|
||||||
getRandomWarp(warps);
|
|
||||||
// Build the main body
|
|
||||||
int i = buildMainBody(panelBuilder, user, index, world, warps);
|
|
||||||
// Add navigation
|
|
||||||
addNavigation(panelBuilder, user, world, i, index, warps.size());
|
|
||||||
r.complete(null);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getRandomWarp(List<UUID> warps) {
|
|
||||||
// Add random warp
|
|
||||||
if (!warps.isEmpty() && addon.getSettings().isRandomAllowed()) {
|
|
||||||
warps.add(0, warps.get(new Random().nextInt(warps.size())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int buildMainBody(PanelBuilder panelBuilder, User user, int index, World world, List<UUID> warps) {
|
|
||||||
if (index < 0) {
|
|
||||||
index = 0;
|
|
||||||
} else if (index > (warps.size() / PANEL_MAX_SIZE)) {
|
|
||||||
index = warps.size() / PANEL_MAX_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
int i = index * PANEL_MAX_SIZE;
|
|
||||||
for (; panelBuilder.getItems().size() < PANEL_MAX_SIZE && i < warps.size(); i++) {
|
|
||||||
UUID warpOwner = warps.get(i);
|
|
||||||
if (addon.getSettings().isRandomAllowed() && i == 0) {
|
|
||||||
panelBuilder.item(getRandomButton(world, user, warpOwner));
|
|
||||||
} else {
|
|
||||||
@NonNull
|
|
||||||
SignCacheItem sign = signCacheManager.getSignItem(world, warpOwner);
|
|
||||||
if (sign.isReal()) {
|
|
||||||
panelBuilder.item(getPanelItem(world, warpOwner, sign));
|
|
||||||
} else {
|
|
||||||
addon.getWarpSignsManager().removeWarpFromMap(world, warpOwner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add Next and Previous icons to navigate
|
|
||||||
* @param panelBuilder - the panel builder
|
|
||||||
* @param user - user
|
|
||||||
* @param world - world
|
|
||||||
* @param numOfItems - number of items shown so far including in previous panels
|
|
||||||
* @param panelNum - panel number (page)
|
|
||||||
* @param totalNum - total number of items in the list
|
|
||||||
*/
|
|
||||||
void addNavigation(PanelBuilder panelBuilder, User user, World world, int numOfItems, int panelNum, int totalNum) {
|
|
||||||
// Previous
|
|
||||||
if (panelNum > 0 && numOfItems > PANEL_MAX_SIZE) {
|
|
||||||
// Previous
|
|
||||||
panelBuilder.item(new PanelItemBuilder()
|
|
||||||
.name(user.getTranslation("warps.previous"))
|
|
||||||
.icon(new ItemStack(Material.COBBLESTONE))
|
|
||||||
.clickHandler((panel, clicker, click, slot) -> {
|
|
||||||
user.closeInventory();
|
|
||||||
showWarpPanel(world, user, panelNum-1);
|
|
||||||
return true;
|
|
||||||
}).build());
|
|
||||||
}
|
|
||||||
// Next
|
|
||||||
if (numOfItems < totalNum) {
|
|
||||||
// Next
|
|
||||||
panelBuilder.item(new PanelItemBuilder()
|
|
||||||
.name(user.getTranslation("warps.next"))
|
|
||||||
.icon(new ItemStack(Material.STONE))
|
|
||||||
.clickHandler((panel, clicker, click, slot) -> {
|
|
||||||
user.closeInventory();
|
|
||||||
showWarpPanel(world, user, panelNum+1);
|
|
||||||
return true;
|
|
||||||
}).build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes sign text from the cache
|
|
||||||
* @param world - world
|
|
||||||
* @param key - uuid of owner
|
|
||||||
* @return true if the item was removed from the cache
|
|
||||||
*/
|
|
||||||
public boolean removeWarp(World world, UUID key) {
|
|
||||||
return signCacheManager.removeWarp(world, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveCache() {
|
|
||||||
signCacheManager.saveCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,8 +1,15 @@
|
|||||||
package world.bentobox.warps;
|
package world.bentobox.warps;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.java.annotation.dependency.Dependency;
|
||||||
|
import org.bukkit.plugin.java.annotation.plugin.ApiVersion;
|
||||||
|
import org.bukkit.plugin.java.annotation.plugin.Plugin;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
import world.bentobox.bentobox.api.addons.Pladdon;
|
import world.bentobox.bentobox.api.addons.Pladdon;
|
||||||
|
|
||||||
|
@Plugin(name="Pladdon", version="1.0")
|
||||||
|
@ApiVersion(ApiVersion.Target.v1_16)
|
||||||
|
@Dependency(value = "BentoBox")
|
||||||
public class WarpsPladdon extends Pladdon {
|
public class WarpsPladdon extends Pladdon {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,6 +7,8 @@ import org.bukkit.World;
|
|||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.warps.Warp;
|
import world.bentobox.warps.Warp;
|
||||||
|
import world.bentobox.warps.panels.WarpsPanel;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the warps command
|
* Handles the warps command
|
||||||
@ -51,7 +53,9 @@ public class WarpsCommand extends CompositeCommand {
|
|||||||
user.sendMessage("warps.warpTip", "[text]", addon.getSettings().getWelcomeLine());
|
user.sendMessage("warps.warpTip", "[text]", addon.getSettings().getWelcomeLine());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
addon.getWarpPanelManager().showWarpPanel(world, user, 0);
|
|
||||||
|
WarpsPanel.openPanel(this.addon, world, user);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,14 +29,6 @@ public class Settings implements ConfigObject
|
|||||||
@ConfigEntry(path = "welcomeLine")
|
@ConfigEntry(path = "welcomeLine")
|
||||||
private String welcomeLine = "[Welcome]";
|
private String welcomeLine = "[Welcome]";
|
||||||
|
|
||||||
@ConfigComment("")
|
|
||||||
@ConfigComment("Icon that will be displayed in Warps list. SIGN counts for any kind of sign and the type of")
|
|
||||||
@ConfigComment("wood used will be reflected in the panel if the server supports it.")
|
|
||||||
@ConfigComment("It uses native Minecraft material strings, but using string 'PLAYER_HEAD', it is possible to")
|
|
||||||
@ConfigComment("use player heads instead. Beware that Mojang API rate limiting may prevent heads from loading.")
|
|
||||||
@ConfigEntry(path = "icon")
|
|
||||||
private String icon = "SIGN";
|
|
||||||
|
|
||||||
@ConfigComment("")
|
@ConfigComment("")
|
||||||
@ConfigComment("This list stores GameModes in which Level addon should not work.")
|
@ConfigComment("This list stores GameModes in which Level addon should not work.")
|
||||||
@ConfigComment("To disable addon it is necessary to write its name in new line that starts with -. Example:")
|
@ConfigComment("To disable addon it is necessary to write its name in new line that starts with -. Example:")
|
||||||
@ -45,23 +37,12 @@ public class Settings implements ConfigObject
|
|||||||
@ConfigEntry(path = "disabled-gamemodes")
|
@ConfigEntry(path = "disabled-gamemodes")
|
||||||
private Set<String> disabledGameModes = new HashSet<>();
|
private Set<String> disabledGameModes = new HashSet<>();
|
||||||
|
|
||||||
@ConfigComment("")
|
|
||||||
@ConfigComment("Warp panel name formatting.")
|
|
||||||
@ConfigComment("Example: &c will make names red. &f is white")
|
|
||||||
@ConfigEntry(path = "name-format")
|
|
||||||
private String nameFormat = "&f";
|
|
||||||
|
|
||||||
@ConfigComment("")
|
@ConfigComment("")
|
||||||
@ConfigComment("Warp panel default lore formatting.")
|
@ConfigComment("Warp panel default lore formatting.")
|
||||||
@ConfigComment("Example: &c will make lore red. &f is white")
|
@ConfigComment("Example: &c will make lore red. &f is white")
|
||||||
@ConfigEntry(path = "lore-format")
|
@ConfigEntry(path = "lore-format")
|
||||||
private String loreFormat = "&f";
|
private String loreFormat = "&f";
|
||||||
|
|
||||||
@ConfigComment("")
|
|
||||||
@ConfigComment("Allow random teleport - adds a button to the warp panel that goes to a random warp sign")
|
|
||||||
@ConfigEntry(path = "random-allowed")
|
|
||||||
private boolean randomAllowed = true;
|
|
||||||
|
|
||||||
@ConfigComment("")
|
@ConfigComment("")
|
||||||
@ConfigComment("Allow use in other worlds. Players must have the welcomewarpsigns.warp permission.")
|
@ConfigComment("Allow use in other worlds. Players must have the welcomewarpsigns.warp permission.")
|
||||||
@ConfigEntry(path = "allow-in-other-worlds")
|
@ConfigEntry(path = "allow-in-other-worlds")
|
||||||
@ -155,42 +136,6 @@ public class Settings implements ConfigObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method returns the icon object.
|
|
||||||
* @return the icon object.
|
|
||||||
*/
|
|
||||||
public String getIcon()
|
|
||||||
{
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method sets the icon object value.
|
|
||||||
* @param icon the icon object new value.
|
|
||||||
*/
|
|
||||||
public void setIcon(String icon)
|
|
||||||
{
|
|
||||||
this.icon = icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the nameFormat
|
|
||||||
*/
|
|
||||||
public String getNameFormat() {
|
|
||||||
return nameFormat;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param nameFormat the nameFormat to set
|
|
||||||
*/
|
|
||||||
public void setNameFormat(String nameFormat) {
|
|
||||||
this.nameFormat = nameFormat;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the loreFormat
|
* @return the loreFormat
|
||||||
*/
|
*/
|
||||||
@ -207,22 +152,6 @@ public class Settings implements ConfigObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the randomAllowed
|
|
||||||
*/
|
|
||||||
public boolean isRandomAllowed() {
|
|
||||||
return randomAllowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param randomAllowed the randomAllowed to set
|
|
||||||
*/
|
|
||||||
public void setRandomAllowed(boolean randomAllowed) {
|
|
||||||
this.randomAllowed = randomAllowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the allowInOtherWorlds
|
* @return the allowInOtherWorlds
|
||||||
*/
|
*/
|
||||||
@ -269,6 +198,4 @@ public class Settings implements ConfigObject
|
|||||||
public void setWarpsCommand(String warpsCommand) {
|
public void setWarpsCommand(String warpsCommand) {
|
||||||
this.warpsCommand = warpsCommand;
|
this.warpsCommand = warpsCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ public class WarpSignsListener implements Listener {
|
|||||||
&& !Tag.SIGNS.isTagged(location.getBlock().getType())) {
|
&& !Tag.SIGNS.isTagged(location.getBlock().getType())) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
// Remove sign from warp panel cache
|
// Remove sign from warp panel cache
|
||||||
addon.getWarpPanelManager().removeWarp(event.getWorld(), uuid);
|
addon.getSignCacheManager().removeWarp(event.getWorld(), uuid);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package world.bentobox.warps;
|
package world.bentobox.warps.managers;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package world.bentobox.warps;
|
package world.bentobox.warps.managers;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -10,6 +10,7 @@ import org.bukkit.World;
|
|||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
|
|
||||||
import world.bentobox.bentobox.database.Database;
|
import world.bentobox.bentobox.database.Database;
|
||||||
|
import world.bentobox.warps.Warp;
|
||||||
import world.bentobox.warps.objects.SignCache;
|
import world.bentobox.warps.objects.SignCache;
|
||||||
|
|
||||||
public class SignCacheManager {
|
public class SignCacheManager {
|
||||||
@ -36,7 +37,7 @@ public class SignCacheManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveCache() {
|
public void saveCache() {
|
||||||
cachedSigns.forEach((w, m) -> handler.saveObjectAsync(new SignCache(w, m)));
|
cachedSigns.forEach((w, m) -> handler.saveObjectAsync(new SignCache(w, m)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ public class SignCacheManager {
|
|||||||
* @return SignCacheItem
|
* @return SignCacheItem
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
SignCacheItem getSignItem(World world, UUID warpOwner) {
|
public SignCacheItem getSignItem(World world, UUID warpOwner) {
|
||||||
// Add the worlds if we haven't seen this before
|
// Add the worlds if we haven't seen this before
|
||||||
cachedSigns.putIfAbsent(world, new HashMap<>());
|
cachedSigns.putIfAbsent(world, new HashMap<>());
|
||||||
// Get from cache if available
|
// Get from cache if available
|
||||||
@ -70,7 +71,7 @@ public class SignCacheManager {
|
|||||||
* @param key - uuid of owner
|
* @param key - uuid of owner
|
||||||
* @return true if item is removed from cache
|
* @return true if item is removed from cache
|
||||||
*/
|
*/
|
||||||
boolean removeWarp(World world, UUID key) {
|
public boolean removeWarp(World world, UUID key) {
|
||||||
if (cachedSigns.containsKey(world)) {
|
if (cachedSigns.containsKey(world)) {
|
||||||
return cachedSigns.get(world).remove(key) != null;
|
return cachedSigns.get(world).remove(key) != null;
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package world.bentobox.warps;
|
package world.bentobox.warps.managers;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -38,8 +38,11 @@ import world.bentobox.bentobox.database.Database;
|
|||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.lists.Flags;
|
import world.bentobox.bentobox.lists.Flags;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
import world.bentobox.warps.Warp;
|
||||||
import world.bentobox.warps.event.WarpInitiateEvent;
|
import world.bentobox.warps.event.WarpInitiateEvent;
|
||||||
import world.bentobox.warps.objects.WarpsData;
|
import world.bentobox.warps.objects.WarpsData;
|
||||||
|
import world.bentobox.warps.panels.Utils;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles warping. Players can add one sign
|
* Handles warping. Players can add one sign
|
||||||
@ -151,7 +154,7 @@ public class WarpSignsManager {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<UUID> processWarpMap(CompletableFuture<List<UUID>> r, @NonNull World world) {
|
public List<UUID> processWarpMap(CompletableFuture<List<UUID>> r, @NonNull World world) {
|
||||||
// Remove any null locations - this can happen if an admin changes the name of the world and signs point to old locations
|
// Remove any null locations - this can happen if an admin changes the name of the world and signs point to old locations
|
||||||
getWarpMap(world).values().removeIf(Objects::isNull);
|
getWarpMap(world).values().removeIf(Objects::isNull);
|
||||||
// Bigger value of time means a more recent login
|
// Bigger value of time means a more recent login
|
||||||
@ -191,7 +194,7 @@ public class WarpSignsManager {
|
|||||||
/**
|
/**
|
||||||
* Load the warps and check if they still exist
|
* Load the warps and check if they still exist
|
||||||
*/
|
*/
|
||||||
void loadWarpList() {
|
public void loadWarpList() {
|
||||||
addon.log("Loading warps...");
|
addon.log("Loading warps...");
|
||||||
worldsWarpList = new HashMap<>();
|
worldsWarpList = new HashMap<>();
|
||||||
if (handler.objectExists(WARPS)) {
|
if (handler.objectExists(WARPS)) {
|
||||||
@ -246,7 +249,7 @@ public class WarpSignsManager {
|
|||||||
.map(User::getInstance)
|
.map(User::getInstance)
|
||||||
.ifPresent(user -> user.sendMessage("warps.sign-removed"));
|
.ifPresent(user -> user.sendMessage("warps.sign-removed"));
|
||||||
// Remove sign from warp panel cache
|
// Remove sign from warp panel cache
|
||||||
addon.getWarpPanelManager().removeWarp(loc.getWorld(), en.getKey());
|
addon.getSignCacheManager().removeWarp(loc.getWorld(), en.getKey());
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,7 +268,7 @@ public class WarpSignsManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
// Remove sign from warp panel cache
|
// Remove sign from warp panel cache
|
||||||
addon.getWarpPanelManager().removeWarp(world, uuid);
|
addon.getSignCacheManager().removeWarp(world, uuid);
|
||||||
saveWarpList();
|
saveWarpList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,7 +286,7 @@ public class WarpSignsManager {
|
|||||||
*/
|
*/
|
||||||
public void saveWarpList() {
|
public void saveWarpList() {
|
||||||
handler.saveObjectAsync(warpsData.save(worldsWarpList));
|
handler.saveObjectAsync(warpsData.save(worldsWarpList));
|
||||||
addon.getWarpPanelManager().saveCache();
|
addon.getSignCacheManager().saveCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -311,7 +314,6 @@ public class WarpSignsManager {
|
|||||||
result.set(i, ChatColor.translateAlternateColorCodes('&', addon.getSettings().getLoreFormat()) + result.get(i));
|
result.set(i, ChatColor.translateAlternateColorCodes('&', addon.getSettings().getLoreFormat()) + result.get(i));
|
||||||
}
|
}
|
||||||
// Get the sign type
|
// Get the sign type
|
||||||
|
|
||||||
String prefix = plugin.getIWM().getAddon(world).map(Addon::getPermissionPrefix).orElse("");
|
String prefix = plugin.getIWM().getAddon(world).map(Addon::getPermissionPrefix).orElse("");
|
||||||
|
|
||||||
Material icon;
|
Material icon;
|
||||||
@ -319,20 +321,21 @@ public class WarpSignsManager {
|
|||||||
if (!prefix.isEmpty())
|
if (!prefix.isEmpty())
|
||||||
{
|
{
|
||||||
icon = Material.matchMaterial(
|
icon = Material.matchMaterial(
|
||||||
this.getPermissionValue(Objects.requireNonNull(User.getInstance(uuid)),
|
Utils.getPermissionValue(User.getInstance(uuid), prefix + "island.warp",
|
||||||
prefix + "island.warp",
|
Material.OAK_SIGN.name()));
|
||||||
this.addon.getSettings().getIcon()));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
icon = Material.matchMaterial(this.addon.getSettings().getIcon());
|
icon = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (icon == null || icon.name().contains("SIGN")) {
|
if (icon != null && icon.name().contains("SIGN")) {
|
||||||
return new SignCacheItem(result, Material.valueOf(sign.getType().name().replace("WALL_", "")));
|
return new SignCacheItem(result, Material.valueOf(sign.getType().name().replace("WALL_", "")));
|
||||||
}
|
}
|
||||||
return new SignCacheItem(result, icon);
|
else
|
||||||
|
{
|
||||||
|
return new SignCacheItem(result, icon);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -460,54 +463,4 @@ public class WarpSignsManager {
|
|||||||
public boolean hasWarp(@NonNull World world, @NonNull UUID playerUUID) {
|
public boolean hasWarp(@NonNull World world, @NonNull UUID playerUUID) {
|
||||||
return getWarpMap(world).containsKey(playerUUID);
|
return getWarpMap(world).containsKey(playerUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
// Section: Other methods
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method gets string value of given permission prefix. If user does not have
|
|
||||||
* given permission or it have all (*), then return default value.
|
|
||||||
* @param user User who's permission should be checked.
|
|
||||||
* @param permissionPrefix Prefix that need to be found.
|
|
||||||
* @param defaultValue Default value that will be returned if permission not found.
|
|
||||||
* @return String value that follows permissionPrefix.
|
|
||||||
*/
|
|
||||||
private String getPermissionValue(@NonNull User user, @NonNull String permissionPrefix, @NonNull String defaultValue)
|
|
||||||
{
|
|
||||||
if (user.isPlayer())
|
|
||||||
{
|
|
||||||
if (permissionPrefix.endsWith("."))
|
|
||||||
{
|
|
||||||
permissionPrefix = permissionPrefix.substring(0, permissionPrefix.length() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
String permPrefix = permissionPrefix + ".";
|
|
||||||
|
|
||||||
List<String> permissions = user.getEffectivePermissions().stream()
|
|
||||||
.map(PermissionAttachmentInfo::getPermission)
|
|
||||||
.filter(permission -> permission.startsWith(permPrefix))
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
for (String permission : permissions)
|
|
||||||
{
|
|
||||||
if (permission.contains(permPrefix + "*"))
|
|
||||||
{
|
|
||||||
// * means all. So continue to search more specific.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] parts = permission.split(permPrefix);
|
|
||||||
|
|
||||||
if (parts.length > 1)
|
|
||||||
{
|
|
||||||
return parts[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -10,7 +10,7 @@ import com.google.gson.annotations.Expose;
|
|||||||
|
|
||||||
import world.bentobox.bentobox.database.objects.DataObject;
|
import world.bentobox.bentobox.database.objects.DataObject;
|
||||||
import world.bentobox.bentobox.database.objects.Table;
|
import world.bentobox.bentobox.database.objects.Table;
|
||||||
import world.bentobox.warps.SignCacheItem;
|
import world.bentobox.warps.managers.SignCacheItem;
|
||||||
|
|
||||||
@Table(name = "WarpSignCache")
|
@Table(name = "WarpSignCache")
|
||||||
public class SignCache implements DataObject {
|
public class SignCache implements DataObject {
|
||||||
|
76
src/main/java/world/bentobox/warps/panels/Utils.java
Normal file
76
src/main/java/world/bentobox/warps/panels/Utils.java
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
//
|
||||||
|
// Created by BONNe
|
||||||
|
// Copyright - 2021
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
package world.bentobox.warps.panels;
|
||||||
|
|
||||||
|
|
||||||
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
|
||||||
|
|
||||||
|
public class Utils
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* This method sends a message to the user with appended "prefix" text before message.
|
||||||
|
* @param user User who receives message.
|
||||||
|
* @param translationText Translation text of the message.
|
||||||
|
* @param parameters Parameters for the translation text.
|
||||||
|
*/
|
||||||
|
public static void sendMessage(User user, String translationText, String... parameters)
|
||||||
|
{
|
||||||
|
user.sendMessage(user.getTranslation( "warps.conversations.prefix") +
|
||||||
|
user.getTranslation( translationText, parameters));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets string value of given permission prefix. If user does not have given permission or it have all
|
||||||
|
* (*), then return default value.
|
||||||
|
*
|
||||||
|
* @param user User who's permission should be checked.
|
||||||
|
* @param permissionPrefix Prefix that need to be found.
|
||||||
|
* @param defaultValue Default value that will be returned if permission not found.
|
||||||
|
* @return String value that follows permissionPrefix.
|
||||||
|
*/
|
||||||
|
public static String getPermissionValue(User user, String permissionPrefix, String defaultValue)
|
||||||
|
{
|
||||||
|
if (user.isPlayer())
|
||||||
|
{
|
||||||
|
if (permissionPrefix.endsWith("."))
|
||||||
|
{
|
||||||
|
permissionPrefix = permissionPrefix.substring(0, permissionPrefix.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
String permPrefix = permissionPrefix + ".";
|
||||||
|
|
||||||
|
List<String> permissions = user.getEffectivePermissions().stream().
|
||||||
|
map(PermissionAttachmentInfo::getPermission).
|
||||||
|
filter(permission -> permission.startsWith(permPrefix)).
|
||||||
|
collect(Collectors.toList());
|
||||||
|
|
||||||
|
for (String permission : permissions)
|
||||||
|
{
|
||||||
|
if (permission.contains(permPrefix + "*"))
|
||||||
|
{
|
||||||
|
// * means all. So continue to search more specific.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] parts = permission.split(permPrefix);
|
||||||
|
|
||||||
|
if (parts.length > 1)
|
||||||
|
{
|
||||||
|
return parts[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
598
src/main/java/world/bentobox/warps/panels/WarpsPanel.java
Normal file
598
src/main/java/world/bentobox/warps/panels/WarpsPanel.java
Normal file
@ -0,0 +1,598 @@
|
|||||||
|
//
|
||||||
|
// Created by BONNe
|
||||||
|
// Copyright - 2021
|
||||||
|
//
|
||||||
|
|
||||||
|
package world.bentobox.warps.panels;
|
||||||
|
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
|
import world.bentobox.bentobox.api.panels.TemplatedPanel;
|
||||||
|
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||||
|
import world.bentobox.bentobox.api.panels.builders.TemplatedPanelBuilder;
|
||||||
|
import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord;
|
||||||
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.warps.managers.SignCacheItem;
|
||||||
|
import world.bentobox.warps.managers.SignCacheManager;
|
||||||
|
import world.bentobox.warps.Warp;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class shows how to set up easy panel by using BentoBox PanelBuilder API
|
||||||
|
*/
|
||||||
|
public class WarpsPanel
|
||||||
|
{
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Section: Constructor
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is internal constructor. It is used internally in current class to avoid creating objects everywhere.
|
||||||
|
*
|
||||||
|
* @param addon VisitAddon object
|
||||||
|
* @param world World where user will be teleported
|
||||||
|
* @param user User who opens panel
|
||||||
|
*/
|
||||||
|
private WarpsPanel(Warp addon,
|
||||||
|
World world,
|
||||||
|
User user)
|
||||||
|
{
|
||||||
|
this.addon = addon;
|
||||||
|
this.manager = this.addon.getSignCacheManager();
|
||||||
|
this.user = user;
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Section: Methods
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method collects and validates sign warps that could be displayed in GUI.
|
||||||
|
* @param completed CompletableFeature that triggers panel opening.
|
||||||
|
*/
|
||||||
|
private void collectValidWarps(CompletableFuture<Boolean> completed)
|
||||||
|
{
|
||||||
|
this.addon.getWarpSignsManager().getSortedWarps(this.world).
|
||||||
|
thenAccept(warps ->
|
||||||
|
{
|
||||||
|
// Cache and clean the signs
|
||||||
|
Iterator<UUID> iterator = warps.iterator();
|
||||||
|
|
||||||
|
while (iterator.hasNext())
|
||||||
|
{
|
||||||
|
UUID warpOwner = iterator.next();
|
||||||
|
@NonNull
|
||||||
|
SignCacheItem sign = this.manager.getSignItem(this.world, warpOwner);
|
||||||
|
|
||||||
|
if (!sign.isReal())
|
||||||
|
{
|
||||||
|
iterator.remove();
|
||||||
|
this.addon.getWarpSignsManager().removeWarpFromMap(this.world, warpOwner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assign warps to element list.
|
||||||
|
this.elementList = warps;
|
||||||
|
|
||||||
|
// Build the main body
|
||||||
|
completed.complete(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is wrapper around builder to trigger main GUI building.
|
||||||
|
*/
|
||||||
|
private void initBuild()
|
||||||
|
{
|
||||||
|
CompletableFuture<Boolean> collectWarps = new CompletableFuture<>();
|
||||||
|
this.collectValidWarps(collectWarps);
|
||||||
|
collectWarps.thenAccept(done -> {
|
||||||
|
if (done)
|
||||||
|
{
|
||||||
|
this.build();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build method manages current panel opening. It uses BentoBox PanelAPI that is easy to use and users can get nice
|
||||||
|
* panels.
|
||||||
|
*/
|
||||||
|
private void build()
|
||||||
|
{
|
||||||
|
// Do not open gui if there is no magic sticks.
|
||||||
|
if (this.elementList.isEmpty())
|
||||||
|
{
|
||||||
|
this.addon.logError("There are no available islands for visiting!");
|
||||||
|
Utils.sendMessage(this.user, "warps.error.no-warps-yet",
|
||||||
|
"[gamemode]", this.addon.getPlugin().getIWM().getAddon(this.world).
|
||||||
|
map(gamemode -> gamemode.getDescription().getName()).
|
||||||
|
orElse(""));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start building panel.
|
||||||
|
TemplatedPanelBuilder panelBuilder = new TemplatedPanelBuilder();
|
||||||
|
|
||||||
|
// Set main template.
|
||||||
|
panelBuilder.template("warps_panel", new File(this.addon.getDataFolder(), "panels"));
|
||||||
|
panelBuilder.user(this.user);
|
||||||
|
panelBuilder.world(this.user.getWorld());
|
||||||
|
|
||||||
|
// Register button builders
|
||||||
|
panelBuilder.registerTypeBuilder("WARP", this::createWarpButton);
|
||||||
|
panelBuilder.registerTypeBuilder("RANDOM", this::createRandomButton);
|
||||||
|
|
||||||
|
// Register next and previous builders
|
||||||
|
panelBuilder.registerTypeBuilder("NEXT", this::createNextButton);
|
||||||
|
panelBuilder.registerTypeBuilder("PREVIOUS", this::createPreviousButton);
|
||||||
|
|
||||||
|
// Register unknown type builder.
|
||||||
|
panelBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Section: Buttons
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create next button panel item.
|
||||||
|
*
|
||||||
|
* @param template the template
|
||||||
|
* @param slot the slot
|
||||||
|
* @return the panel item
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
private PanelItem createNextButton(@NonNull ItemTemplateRecord template, TemplatedPanel.ItemSlot slot)
|
||||||
|
{
|
||||||
|
int size = this.elementList.size();
|
||||||
|
|
||||||
|
if (size <= slot.amountMap().getOrDefault("WARP", 1) ||
|
||||||
|
1.0 * size / slot.amountMap().getOrDefault("WARP", 1) <= this.pageIndex + 1)
|
||||||
|
{
|
||||||
|
// There are no next elements
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nextPageIndex = this.pageIndex + 2;
|
||||||
|
|
||||||
|
PanelItemBuilder builder = new PanelItemBuilder();
|
||||||
|
|
||||||
|
if (template.icon() != null)
|
||||||
|
{
|
||||||
|
ItemStack clone = template.icon().clone();
|
||||||
|
|
||||||
|
if ((Boolean) template.dataMap().getOrDefault("indexing", false))
|
||||||
|
{
|
||||||
|
clone.setAmount(nextPageIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.icon(clone);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (template.title() != null)
|
||||||
|
{
|
||||||
|
builder.name(this.user.getTranslation(this.world, template.title()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (template.description() != null)
|
||||||
|
{
|
||||||
|
builder.description(this.user.getTranslation(this.world, template.description(),
|
||||||
|
"[number]", String.valueOf(nextPageIndex)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add ClickHandler
|
||||||
|
builder.clickHandler((panel, user, clickType, i) ->
|
||||||
|
{
|
||||||
|
template.actions().forEach(action -> {
|
||||||
|
if (clickType == action.clickType() || action.clickType() == ClickType.UNKNOWN)
|
||||||
|
{
|
||||||
|
if ("NEXT".equalsIgnoreCase(action.actionType()))
|
||||||
|
{
|
||||||
|
// Next button ignores click type currently.
|
||||||
|
this.pageIndex++;
|
||||||
|
this.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Always return true.
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Collect tooltips.
|
||||||
|
List<String> tooltips = template.actions().stream().
|
||||||
|
filter(action -> action.tooltip() != null).
|
||||||
|
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
||||||
|
filter(text -> !text.isBlank()).
|
||||||
|
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
||||||
|
|
||||||
|
// Add tooltips.
|
||||||
|
if (!tooltips.isEmpty())
|
||||||
|
{
|
||||||
|
// Empty line and tooltips.
|
||||||
|
builder.description("");
|
||||||
|
builder.description(tooltips);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create previous button panel item.
|
||||||
|
*
|
||||||
|
* @param template the template
|
||||||
|
* @param slot the slot
|
||||||
|
* @return the panel item
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
private PanelItem createPreviousButton(@NonNull ItemTemplateRecord template, TemplatedPanel.ItemSlot slot)
|
||||||
|
{
|
||||||
|
if (this.pageIndex == 0)
|
||||||
|
{
|
||||||
|
// There are no next elements
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int previousPageIndex = this.pageIndex;
|
||||||
|
|
||||||
|
PanelItemBuilder builder = new PanelItemBuilder();
|
||||||
|
|
||||||
|
if (template.icon() != null)
|
||||||
|
{
|
||||||
|
ItemStack clone = template.icon().clone();
|
||||||
|
|
||||||
|
if ((Boolean) template.dataMap().getOrDefault("indexing", false))
|
||||||
|
{
|
||||||
|
clone.setAmount(previousPageIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.icon(clone);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (template.title() != null)
|
||||||
|
{
|
||||||
|
builder.name(this.user.getTranslation(this.world, template.title()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (template.description() != null)
|
||||||
|
{
|
||||||
|
builder.description(this.user.getTranslation(this.world, template.description(),
|
||||||
|
"[number]", String.valueOf(previousPageIndex)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add ClickHandler
|
||||||
|
// Add ClickHandler
|
||||||
|
builder.clickHandler((panel, user, clickType, i) ->
|
||||||
|
{
|
||||||
|
template.actions().forEach(action -> {
|
||||||
|
if (clickType == action.clickType() || action.clickType() == ClickType.UNKNOWN)
|
||||||
|
{
|
||||||
|
if ("PREVIOUS".equalsIgnoreCase(action.actionType()))
|
||||||
|
{
|
||||||
|
// Next button ignores click type currently.
|
||||||
|
this.pageIndex--;
|
||||||
|
this.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Always return true.
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Collect tooltips.
|
||||||
|
List<String> tooltips = template.actions().stream().
|
||||||
|
filter(action -> action.tooltip() != null).
|
||||||
|
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
||||||
|
filter(text -> !text.isBlank()).
|
||||||
|
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
||||||
|
|
||||||
|
// Add tooltips.
|
||||||
|
if (!tooltips.isEmpty())
|
||||||
|
{
|
||||||
|
// Empty line and tooltips.
|
||||||
|
builder.description("");
|
||||||
|
builder.description(tooltips);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method creates and returns warp button.
|
||||||
|
*
|
||||||
|
* @return PanelItem that represents warp button.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
private PanelItem createWarpButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot)
|
||||||
|
{
|
||||||
|
if (this.elementList.isEmpty())
|
||||||
|
{
|
||||||
|
// Does not contain any sticks.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int index = this.pageIndex * slot.amountMap().getOrDefault("WARP", 1) + slot.slot();
|
||||||
|
|
||||||
|
if (index >= this.elementList.size())
|
||||||
|
{
|
||||||
|
// Out of index.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.createWarpButton(template, this.elementList.get(index), "warp");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method creates and returns random warp button.
|
||||||
|
*
|
||||||
|
* @return PanelItem that represents random warp button.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
private PanelItem createRandomButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot)
|
||||||
|
{
|
||||||
|
if (this.elementList.size() < 2)
|
||||||
|
{
|
||||||
|
// Does not contain any sticks.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int index = random.nextInt(this.elementList.size());
|
||||||
|
return this.createWarpButton(template, this.elementList.get(index), "random");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Section: Other methods
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method creates and returns button that switch to next page in view mode.
|
||||||
|
*
|
||||||
|
* @return PanelItem that allows to select next owner view page.
|
||||||
|
*/
|
||||||
|
private PanelItem createWarpButton(ItemTemplateRecord template, UUID ownerUUID, String type)
|
||||||
|
{
|
||||||
|
if (ownerUUID == null)
|
||||||
|
{
|
||||||
|
// return as owner has no owner. Empty button will be created.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
SignCacheItem signCache = this.manager.getSignItem(this.world, ownerUUID);
|
||||||
|
|
||||||
|
if (!signCache.isReal())
|
||||||
|
{
|
||||||
|
this.addon.getWarpSignsManager().removeWarpFromMap(this.world, ownerUUID);
|
||||||
|
// return as signCache is not real anymore.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String reference = "warps.gui.buttons." + type + ".";
|
||||||
|
|
||||||
|
String ownerName = addon.getPlugin().getPlayers().getName(ownerUUID);
|
||||||
|
|
||||||
|
// Get settings for owner.
|
||||||
|
PanelItemBuilder builder = new PanelItemBuilder();
|
||||||
|
|
||||||
|
if (template.icon() != null)
|
||||||
|
{
|
||||||
|
if (template.icon().getType().equals(Material.PLAYER_HEAD))
|
||||||
|
{
|
||||||
|
builder.icon(ownerName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
builder.icon(template.icon().clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Check owner for a specific icon
|
||||||
|
Material material = signCache.getType();
|
||||||
|
|
||||||
|
if (material == null)
|
||||||
|
{
|
||||||
|
// Set oak sign as icon was not specified.
|
||||||
|
material = Material.OAK_SIGN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (material == Material.PLAYER_HEAD)
|
||||||
|
{
|
||||||
|
builder.icon(ownerName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
builder.icon(material);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (template.title() != null)
|
||||||
|
{
|
||||||
|
builder.name(this.user.getTranslation(this.world, template.title(),
|
||||||
|
"[name]", ownerName));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
builder.name(this.user.getTranslation(reference + "name",
|
||||||
|
"[name]", ownerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process Description of the button.
|
||||||
|
// Generate [sign_text] text
|
||||||
|
|
||||||
|
String descriptionText;
|
||||||
|
|
||||||
|
if (template.description() != null)
|
||||||
|
{
|
||||||
|
descriptionText = this.user.getTranslationOrNothing(template.description(),
|
||||||
|
"[name]", ownerName,
|
||||||
|
"[sign_text]", String.join("\n", signCache.getSignText())).
|
||||||
|
replaceAll("(?m)^[ \\t]*\\r?\\n", "").
|
||||||
|
replaceAll("(?<!\\\\)\\|", "\n").
|
||||||
|
replaceAll("\\\\\\|", "|");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
descriptionText = this.user.getTranslationOrNothing(reference + "description",
|
||||||
|
"[name]", ownerName,
|
||||||
|
"[sign_text]", String.join("|", signCache.getSignText()));
|
||||||
|
|
||||||
|
// Clean up description text and split it into parts.
|
||||||
|
descriptionText = descriptionText.replaceAll("(?m)^[ \\t]*\\r?\\n", "").
|
||||||
|
replaceAll("(?<!\\\\)\\|", "\n").
|
||||||
|
replaceAll("\\\\\\|", "|");
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.description(descriptionText);
|
||||||
|
|
||||||
|
// Add ClickHandler
|
||||||
|
builder.clickHandler((panel, user, clickType, i) ->
|
||||||
|
{
|
||||||
|
template.actions().forEach(action -> {
|
||||||
|
if (clickType == action.clickType() || action.clickType() == ClickType.UNKNOWN)
|
||||||
|
{
|
||||||
|
if ("WARP".equalsIgnoreCase(action.actionType()))
|
||||||
|
{
|
||||||
|
this.runCommandCall(ownerName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Always return true.
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Collect tooltips.
|
||||||
|
List<String> tooltips = template.actions().stream().
|
||||||
|
filter(action -> action.tooltip() != null).
|
||||||
|
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
||||||
|
filter(text -> !text.isBlank()).
|
||||||
|
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
||||||
|
|
||||||
|
// Add tooltips.
|
||||||
|
if (!tooltips.isEmpty())
|
||||||
|
{
|
||||||
|
// Empty line and tooltips.
|
||||||
|
builder.description("");
|
||||||
|
builder.description(tooltips);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method runs command call that allows player to visit clicked island.
|
||||||
|
*/
|
||||||
|
private void runCommandCall(String ownerName)
|
||||||
|
{
|
||||||
|
// Get first player command label.
|
||||||
|
String command = this.addon.getSettings().getWarpCommand().split(" ")[0];
|
||||||
|
|
||||||
|
String gamemodeCommand = this.addon.getPlugin().getIWM().getAddon(this.world).
|
||||||
|
map(gamemode -> gamemode.getPlayerCommand().map(Command::getLabel).orElse("")).
|
||||||
|
orElse("");
|
||||||
|
|
||||||
|
if (gamemodeCommand.isEmpty())
|
||||||
|
{
|
||||||
|
this.addon.log(this.user.getName() + " called: `" + command + " " + ownerName + "`");
|
||||||
|
this.user.performCommand(command + " " + ownerName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.addon.log(this.user.getName() + " called: `" + gamemodeCommand + " " + command + " " + ownerName + "`");
|
||||||
|
this.user.performCommand(gamemodeCommand + " " + command + " " + ownerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close inventory
|
||||||
|
this.user.closeInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Section: Static methods
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to open UserPanel outside this class. It will be much easier to open panel with single method
|
||||||
|
* call then initializing new object.
|
||||||
|
*
|
||||||
|
* @param addon Warps object
|
||||||
|
* @param world World where user will be teleported
|
||||||
|
* @param user User who opens panel
|
||||||
|
*/
|
||||||
|
public static void openPanel(Warp addon,
|
||||||
|
World world,
|
||||||
|
User user)
|
||||||
|
{
|
||||||
|
new WarpsPanel(addon, world, user).initBuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Section: Variables
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This variable allows to access addon object.
|
||||||
|
*/
|
||||||
|
private final Warp addon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This variable allows to access addon manager object.
|
||||||
|
*/
|
||||||
|
private final SignCacheManager manager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This variable holds user who opens panel. Without it panel cannot be opened.
|
||||||
|
*/
|
||||||
|
private final User user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This variable holds world where panel is opened. Without it panel cannot be opened.
|
||||||
|
*/
|
||||||
|
private final World world;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This variable stores filtered elements.
|
||||||
|
*/
|
||||||
|
private List<UUID> elementList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This variable holds current pageIndex for multi-page island choosing.
|
||||||
|
*/
|
||||||
|
private int pageIndex;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Random for finding random warp.
|
||||||
|
*/
|
||||||
|
private static final Random random = new Random();
|
||||||
|
}
|
@ -12,29 +12,16 @@ warplevelrestriction: 10
|
|||||||
# Not case sensitive!
|
# Not case sensitive!
|
||||||
welcomeLine: '[Welcome]'
|
welcomeLine: '[Welcome]'
|
||||||
#
|
#
|
||||||
# Icon that will be displayed in Warps list. SIGN counts for any kind of sign and the type of
|
|
||||||
# wood used will be reflected in the panel if the server supports it.
|
|
||||||
# It uses native Minecraft material strings, but using string 'PLAYER_HEAD', it is possible to
|
|
||||||
# use player heads instead. Beware that Mojang API rate limiting may prevent heads from loading.
|
|
||||||
icon: 'SIGN'
|
|
||||||
#
|
|
||||||
# This list stores GameModes in which Level addon should not work.
|
# This list stores GameModes in which Level addon should not work.
|
||||||
# To disable addon it is necessary to write its name in new line that starts with -. Example:
|
# To disable addon it is necessary to write its name in new line that starts with -. Example:
|
||||||
# disabled-gamemodes:
|
# disabled-gamemodes:
|
||||||
# - BSkyBlock
|
# - BSkyBlock
|
||||||
disabled-gamemodes: []
|
disabled-gamemodes: []
|
||||||
#
|
#
|
||||||
# Warp panel name formatting.
|
|
||||||
# Example: &c will make names red, &f is white
|
|
||||||
name-format: "&f"
|
|
||||||
#
|
|
||||||
# Warp panel default lore formatting.
|
# Warp panel default lore formatting.
|
||||||
# Example: &c will make lore red. &f is white
|
# Example: &c will make lore red. &f is white
|
||||||
lore-format: "&f"
|
lore-format: "&f"
|
||||||
#
|
#
|
||||||
# Allow random teleport - adds a button to the warp panel that goes to a random warp sign
|
|
||||||
random-allowed: true
|
|
||||||
#
|
|
||||||
# Allow use in other worlds. Players must have the welcomewarpsigns.warp permission.
|
# Allow use in other worlds. Players must have the welcomewarpsigns.warp permission.
|
||||||
allow-in-other-worlds: false
|
allow-in-other-worlds: false
|
||||||
#
|
#
|
||||||
|
@ -1,30 +1,46 @@
|
|||||||
#
|
---
|
||||||
# This is a YML file. Be careful when editing. Check your edits in a YAML checker like #
|
|
||||||
# the one at http://yaml-online-parser.appspot.com #
|
|
||||||
warp:
|
warp:
|
||||||
help:
|
help:
|
||||||
description: Warpt dich zu dem Warp Schild von dem Spieler
|
description: Warpt dich zu dem Warp Schild von dem Spieler
|
||||||
parameters: <Spielername>
|
parameters: "<player name>"
|
||||||
warps:
|
warps:
|
||||||
deactivate: '&c Altes Warp Schild deaktiviert!'
|
deactivate: "&c Altes Warp Schild deaktiviert!"
|
||||||
error:
|
error:
|
||||||
does-not-exist: '&c Oh nein! Dieser Warp existiert nicht mehr!'
|
does-not-exist: "&c Oh nein! Dieser Warp existiert nicht mehr!"
|
||||||
no-permission: '&c Hierfür hast du keine Rechte!'
|
no-permission: "&c Hierfür hast du keine Rechte!"
|
||||||
no-remove: '&c Du kannst dieses Schild nicht entfernen!'
|
no-remove: "&c Du kannst dieses Schild nicht entfernen!"
|
||||||
no-warps-yet: '&c Es sind noch keine Warps verfügbar'
|
no-warps-yet: "&c Es sind noch keine Warps verfügbar"
|
||||||
not-enough-level: '&c Dein Insel-Level ist nicht hoch gneug!'
|
not-enough-level: "&c Dein Insel-Level ist nicht hoch gneug!"
|
||||||
not-on-island: '&c Dafür musst du auf deiner Insel sein!'
|
not-on-island: "&c Dafür musst du auf deiner Insel sein!"
|
||||||
not-safe: '&c Dieser Warp ist nicht sicher!'
|
not-safe: "&c Dieser Warp ist nicht sicher!"
|
||||||
your-level-is: '&c Dein Insel-Level ist erst [level] und muss höher als [required] sein.
|
your-level-is: "&c Dein Insel-Level ist erst [level] und muss höher als [required]
|
||||||
Nutze das Level Kommando.'
|
sein. Nutze das Level Kommando."
|
||||||
help:
|
help:
|
||||||
description: Öffnet das Warps Panel
|
description: Öffnet das Warps Panel
|
||||||
next: '&6 Nächste Seite'
|
player-warped: "&2 [name] hat sich zu deinem Warp Schild gewarpt!"
|
||||||
player-warped: '&2 [name] hat sich zu deinem Warp Schild gewarpt!'
|
sign-removed: "&c Warp Schild entfernt!"
|
||||||
previous: '&6 Vorherige Seite'
|
success: "&a Erfolg!"
|
||||||
random: '&4 Zufälliger Warp'
|
warpTip: "&6 Platziere ein Warp Schild mit [text] in der ersten Zeile"
|
||||||
sign-removed: '&c Warp Schild entfernt!'
|
warpToPlayersSign: "&6 Warpe zu [player]'s Schild"
|
||||||
success: '&a Erfolg!'
|
gui:
|
||||||
title: Warp Schilder
|
titles:
|
||||||
warpTip: '&6 Platziere ein Warp Schild mit [text] in der ersten Zeile'
|
warp-title: "&0&l Warp-Schild"
|
||||||
warpToPlayersSign: '&6 Warpe zu [player]''s Schild'
|
buttons:
|
||||||
|
previous:
|
||||||
|
name: "&f&l Vorherige Seite"
|
||||||
|
description: "&7 Zur Seite [number] wechseln"
|
||||||
|
next:
|
||||||
|
name: "&f&l Nächste Seite"
|
||||||
|
description: "&7 Zur Seite [number] wechseln"
|
||||||
|
warp:
|
||||||
|
name: "&f&l [name]"
|
||||||
|
description: "[sign_text]"
|
||||||
|
random:
|
||||||
|
name: "&f&l Random Warp"
|
||||||
|
description: "&7 Hmm, wo werde ich erscheinen?"
|
||||||
|
tips:
|
||||||
|
click-to-previous: "&e Klicken &7, um die vorherige Seite anzuzeigen."
|
||||||
|
click-to-next: "&e Klicken &7, um die nächste Seite anzuzeigen."
|
||||||
|
click-to-warp: "&e Zum Warpen &7 klicken."
|
||||||
|
conversations:
|
||||||
|
prefix: "&l&6 [BentoBox]: &r"
|
||||||
|
@ -20,14 +20,43 @@ warps:
|
|||||||
your-level-is: "&c Your island level is only [level] and must be higher than [required]. Run the level command."
|
your-level-is: "&c Your island level is only [level] and must be higher than [required]. Run the level command."
|
||||||
help:
|
help:
|
||||||
description: "open the warps panel"
|
description: "open the warps panel"
|
||||||
next: "&6 Next page"
|
|
||||||
player-warped: "&2 [name] warped to your warp sign!"
|
player-warped: "&2 [name] warped to your warp sign!"
|
||||||
previous: "&6 Previous page"
|
|
||||||
random: "&4 Random Warp"
|
|
||||||
sign-removed: "&c Warp sign removed!"
|
sign-removed: "&c Warp sign removed!"
|
||||||
success: "&a Success!"
|
success: "&a Success!"
|
||||||
title: "Warp Signs"
|
|
||||||
warpTip: "&6 Place a warp sign with [text] on the top"
|
warpTip: "&6 Place a warp sign with [text] on the top"
|
||||||
warpToPlayersSign: "&6 Warping to [player]'s sign"
|
warpToPlayersSign: "&6 Warping to [player]'s sign"
|
||||||
|
|
||||||
|
gui:
|
||||||
|
titles:
|
||||||
|
# The title of warp panel
|
||||||
|
warp-title: '&0&l Warp Signs'
|
||||||
|
buttons:
|
||||||
|
# Button that is used in multi-page GUIs which allows to return to previous page.
|
||||||
|
previous:
|
||||||
|
name: "&f&l Previous Page"
|
||||||
|
description: |-
|
||||||
|
&7 Switch to [number] page
|
||||||
|
# Button that is used in multi-page GUIs which allows to go to next page.
|
||||||
|
next:
|
||||||
|
name: "&f&l Next Page"
|
||||||
|
description: |-
|
||||||
|
&7 Switch to [number] page
|
||||||
|
# Button for a warp
|
||||||
|
warp:
|
||||||
|
name: "&f&l [name]"
|
||||||
|
description: |-
|
||||||
|
[sign_text]
|
||||||
|
# Button for a random warp
|
||||||
|
random:
|
||||||
|
name: "&f&l Random Warp"
|
||||||
|
description: |-
|
||||||
|
&7 Hmm, where will I appear?
|
||||||
|
tips:
|
||||||
|
click-to-previous: "&e Click &7 to view previous page."
|
||||||
|
click-to-next: "&e Click &7 to view next page."
|
||||||
|
click-to-warp: "&e Click &7 to warp."
|
||||||
|
conversations:
|
||||||
|
# Prefix for messages that are send from server.
|
||||||
|
prefix: "&l&6 [BentoBox]: &r"
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,20 +9,20 @@ warps:
|
|||||||
does-not-exist: "&cCe Warp n'existe plus !"
|
does-not-exist: "&cCe Warp n'existe plus !"
|
||||||
no-permission: "&cVous n'avez pas la permission pour faire cela !"
|
no-permission: "&cVous n'avez pas la permission pour faire cela !"
|
||||||
no-remove: "&cVous ne pouvez pas supprimer ce panneau !"
|
no-remove: "&cVous ne pouvez pas supprimer ce panneau !"
|
||||||
|
no-warps-yet: "&cIl n'y a encore aucun Warp sur ce serveur."
|
||||||
not-enough-level: "&cVotre niveau d'île n'est pas assez élevé pour faire cela
|
not-enough-level: "&cVotre niveau d'île n'est pas assez élevé pour faire cela
|
||||||
!"
|
!"
|
||||||
not-on-island: "&cVous devez être sur votre île pour faire cela !"
|
not-on-island: "&cVous devez être sur votre île pour faire cela !"
|
||||||
not-safe: "&cCe Warp n'est pas sûr!"
|
not-safe: "&cCe Warp n'est pas sûr!"
|
||||||
no-warps-yet: "&cIl n'y a encore aucun Warp sur ce serveur."
|
|
||||||
your-level-is: "&cVotre île est seulement niveau [level] et doit être niveau [required]."
|
your-level-is: "&cVotre île est seulement niveau [level] et doit être niveau [required]."
|
||||||
help:
|
help:
|
||||||
description: Ouvre le menu des Warps
|
description: Ouvre le menu des Warps
|
||||||
next: "&6Page suivante"
|
next: "&6Page suivante"
|
||||||
player-warped: "&2[name] s'est téléporté sur votre île !"
|
player-warped: "& 2 [pseudo] s'est téléporté à votre panneau Warp !"
|
||||||
previous: "&6Page précédente"
|
previous: "&6Page précédente"
|
||||||
|
random: "&4 Warp aléatoire "
|
||||||
sign-removed: "&cPanneau de Warp supprimé !"
|
sign-removed: "&cPanneau de Warp supprimé !"
|
||||||
success: "&aSuccès !"
|
success: "&aSuccès !"
|
||||||
title: Panneau Warp
|
title: Panneau Warp
|
||||||
warpTip: "&6Placez un panneau et écrivez [text] sur la première ligne."
|
warpTip: "&6Placez un panneau et écrivez [text] sur la première ligne."
|
||||||
warpToPlayersSign: "&6Téléportation sur l'île de [player]..."
|
warpToPlayersSign: "&6 Téléportation vers le panneau de [pseudo]"
|
||||||
random: "&4Warp aléatoire"
|
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
###########################################################################################
|
---
|
||||||
# This is a YML file. Be careful when editing. Check your edits in a YAML checker like #
|
warp:
|
||||||
# the one at http://yaml-online-parser.appspot.com #
|
help:
|
||||||
###########################################################################################
|
description: Teleportálás a játékos teleport táblájához
|
||||||
|
parameters: "<játékosnév>"
|
||||||
warp:
|
warps:
|
||||||
help:
|
|
||||||
description: "Teleportálás a játékos teleport táblájához"
|
|
||||||
parameters: <player name>
|
|
||||||
warps:
|
|
||||||
deactivate: "&cRégi teleport tábla deaktiválva!"
|
deactivate: "&cRégi teleport tábla deaktiválva!"
|
||||||
error:
|
error:
|
||||||
does-not-exist: "&cAjjaj! Ez a teleport nem létezik!"
|
does-not-exist: "&cAjjaj! Ez a teleport nem létezik!"
|
||||||
no-permission: "&cNincs jogod ehhez!"
|
no-permission: "&cNincs jogod ehhez!"
|
||||||
no-remove: "&cNem törölheted ezt a táblát!"
|
no-remove: "&cNem törölheted ezt a táblát!"
|
||||||
@ -17,17 +13,16 @@ warps:
|
|||||||
not-enough-level: "&cA szigeted szintje nem elég magas!"
|
not-enough-level: "&cA szigeted szintje nem elég magas!"
|
||||||
not-on-island: "&cEhhez szigeten kell lenned!"
|
not-on-island: "&cEhhez szigeten kell lenned!"
|
||||||
not-safe: "&cEz a teleport nem biztonságos!"
|
not-safe: "&cEz a teleport nem biztonságos!"
|
||||||
your-level-is: "&cJelenleg a sziget szinted [level], és nagyobbnak kell lennie, mint [required]."
|
your-level-is: "&cJelenleg a sziget szinted [level], és nagyobbnak kell lennie,
|
||||||
help:
|
mint [required]."
|
||||||
description: "Teleportok panel megnyitása"
|
help:
|
||||||
|
description: Teleportok panel megnyitása
|
||||||
next: "&6Következő oldal"
|
next: "&6Következő oldal"
|
||||||
player-warped: "&2[name] teleportált a teleport tábládhoz!"
|
player-warped: "&2[name] teleportált a teleport tábládhoz!"
|
||||||
previous: "&6Előző oldal"
|
previous: "&6Előző oldal"
|
||||||
random: "&4Véletlenszerű Teleport"
|
random: "&4Véletlenszerű Teleport"
|
||||||
sign-removed: "&cTeleport tábla törölve!"
|
sign-removed: "&cTeleport tábla törölve!"
|
||||||
success: "&aSikeres!"
|
success: "&aSikeres!"
|
||||||
title: "Teleport Táblák"
|
title: Teleport Táblák
|
||||||
warpTip: "&6Helyezz le egy teleport táblát a következő szöveggel [text] a tetején"
|
warpTip: "&6Helyezz le egy teleport táblát a következő szöveggel [text] a tetején"
|
||||||
warpToPlayersSign: "&6Teleportálás [player] táblájához"
|
warpToPlayersSign: "&6Teleportálás [player] táblájához"
|
||||||
|
|
||||||
|
|
||||||
|
28
src/main/resources/locales/id.yml
Normal file
28
src/main/resources/locales/id.yml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
---
|
||||||
|
warp:
|
||||||
|
help:
|
||||||
|
description: warp ke tanda warp pemain
|
||||||
|
parameters: "<player name>"
|
||||||
|
warps:
|
||||||
|
deactivate: "&c Tanda warp lama dinonaktifkan!"
|
||||||
|
error:
|
||||||
|
does-not-exist: "&c Oh! Warp itu tidak ada lagi!"
|
||||||
|
no-permission: "&c Anda tidak memiliki izin untuk melakukan itu!"
|
||||||
|
no-remove: "&c Anda tidak dapat menghapus tanda itu!"
|
||||||
|
no-warps-yet: "&c Belum ada warps yang tersedia"
|
||||||
|
not-enough-level: "&c Level pulaumu tidak cukup tinggi!"
|
||||||
|
not-on-island: "&c Anda harus berada di pulau Anda untuk melakukan itu!"
|
||||||
|
not-safe: "&c Lengkungan itu tidak aman!"
|
||||||
|
your-level-is: "&c Level pulau Anda hanya [level] dan harus lebih tinggi dari
|
||||||
|
[required]. Jalankan perintah level."
|
||||||
|
help:
|
||||||
|
description: buka panel warps
|
||||||
|
next: "&6 Halaman berikutnya"
|
||||||
|
player-warped: "&2 [name] mengunjungi tanda warp Anda!"
|
||||||
|
previous: "&6 Halaman sebelumnya"
|
||||||
|
random: "&4 Warp Acak"
|
||||||
|
sign-removed: "&c Tanda warp dihilangkan!"
|
||||||
|
success: "&a Sukses!"
|
||||||
|
title: Tanda Warp
|
||||||
|
warpTip: "&6 Tempatkan tanda warp dengan [text] di atas\n"
|
||||||
|
warpToPlayersSign: "&6 Pergi ke tanda [player]'s"
|
29
src/main/resources/locales/it.yml
Normal file
29
src/main/resources/locales/it.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
warp:
|
||||||
|
help:
|
||||||
|
description: teletrasporto al cartello Warp del giocatore
|
||||||
|
parameters: "<nome giocatore>"
|
||||||
|
warps:
|
||||||
|
deactivate: "&c Vecchio cartello Warp disattivato!"
|
||||||
|
error:
|
||||||
|
does-not-exist: "&c Quel cartello Warp non esiste più!"
|
||||||
|
no-permission: "&c Non hai i permessi per farlo!"
|
||||||
|
no-remove: "&c Non puoi rimuovere quel cartello!"
|
||||||
|
no-warps-yet: "&c Non ci sono ancora Warp disponibili"
|
||||||
|
not-enough-level: "&c Il tuo livello dell'isola non è abbastanza alto!"
|
||||||
|
not-on-island: "&c Devi essere nella tua isola per farlo!"
|
||||||
|
not-safe: "&c Il Warp non è sicuro!"
|
||||||
|
your-level-is: "&c Il tuo livello dell''isola è solo di [level] e deve essere
|
||||||
|
maggiore di [required]. Esegui il comando del calcolo dei livelli per aggiornare
|
||||||
|
il livello."
|
||||||
|
help:
|
||||||
|
description: apri il pannello dei Warp
|
||||||
|
next: "&6 Pagina Successiva"
|
||||||
|
player-warped: "&2 [name] teletrasportato al tuo cartello Warp!"
|
||||||
|
previous: "&6 Pagina Precedente"
|
||||||
|
random: "&4 Warp Random"
|
||||||
|
sign-removed: "&c Cartello Warp rimosso!"
|
||||||
|
success: "&a Successo!"
|
||||||
|
title: Cartelli Warp
|
||||||
|
warpTip: "&6 Piazza un cartello Warp con [text] scritto nella prima riga"
|
||||||
|
warpToPlayersSign: "&6 Teletrasporto al cartello Warp di [player]"
|
@ -8,20 +8,19 @@ warps:
|
|||||||
error:
|
error:
|
||||||
does-not-exist: "&cÜzgünüm. Böyle bir bölge artık yok!"
|
does-not-exist: "&cÜzgünüm. Böyle bir bölge artık yok!"
|
||||||
no-permission: "&4Buna yetkin yok!"
|
no-permission: "&4Buna yetkin yok!"
|
||||||
not-safe: "&4Ada bölgesi güvenli değil!"
|
|
||||||
no-remove: "&4Bu tabelayı kıramazsın!"
|
no-remove: "&4Bu tabelayı kıramazsın!"
|
||||||
no-warps-yet: "&4Böyle bir bölge henüz yok."
|
no-warps-yet: "&4Böyle bir bölge henüz yok."
|
||||||
not-enough-level: "&4Bunu koyman için daha fazla ada leveline ihtiyacın var."
|
not-enough-level: "&4Bunu koyman için daha fazla ada leveline ihtiyacın var."
|
||||||
not-on-island: "&4Adanda değilsin."
|
not-on-island: "&4Adanda değilsin."
|
||||||
|
not-safe: "&4Ada bölgesi güvenli değil!"
|
||||||
your-level-is: "&9Ada levelin &e[level] &9ve &e[required]&9'den fazla olması gerek!"
|
your-level-is: "&9Ada levelin &e[level] &9ve &e[required]&9'den fazla olması gerek!"
|
||||||
help:
|
help:
|
||||||
description: Bölge panelini açar.
|
description: Bölge panelini açar.
|
||||||
|
next: "&6Sonraki Sayfa"
|
||||||
player-warped: "&d[name] &9ada bölgene ışınlandı!"
|
player-warped: "&d[name] &9ada bölgene ışınlandı!"
|
||||||
|
previous: "&6Önceki sayfa"
|
||||||
|
random: "&4Rastgele bölgeye git!"
|
||||||
sign-removed: "&4Ada tabelası kaldırıldı!"
|
sign-removed: "&4Ada tabelası kaldırıldı!"
|
||||||
success: "&aBaşarılı!"
|
|
||||||
title: "&dOyuncu bölgeleri &8- &5"
|
title: "&dOyuncu bölgeleri &8- &5"
|
||||||
warpTip: "&6Ada bölgesi açmak için tabelanın en üstüne &a[text] &9yaz!"
|
warpTip: "&6Ada bölgesi açmak için tabelanın en üstüne &a[text] &9yaz!"
|
||||||
warpToPlayersSign: "&d[player] &9bölgesine gidiliyor!"
|
warpToPlayersSign: "&d[player] &9bölgesine gidiliyor!"
|
||||||
next: "&6Sonraki Sayfa"
|
|
||||||
previous: "&6Önceki sayfa"
|
|
||||||
random: "&4Rastgele bölgeye git!"
|
|
||||||
|
27
src/main/resources/locales/zh-TW.yml
Normal file
27
src/main/resources/locales/zh-TW.yml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
warp:
|
||||||
|
help:
|
||||||
|
description: 傳送到該玩家的傳送木牌處
|
||||||
|
parameters: "<player name>"
|
||||||
|
warps:
|
||||||
|
deactivate: "&c 舊傳送牌已停用!"
|
||||||
|
error:
|
||||||
|
does-not-exist: "&c 哦不!那個傳送點已經沒了!"
|
||||||
|
no-permission: "&c 你沒有權限這樣做!"
|
||||||
|
no-remove: "&c 你拿不掉那個牌子的!"
|
||||||
|
no-warps-yet: "&c 暫無可用傳送點"
|
||||||
|
not-enough-level: "&c 你的島嶼等級不夠高!"
|
||||||
|
not-on-island: "&c 你得在自己的島嶼上操作!"
|
||||||
|
not-safe: "&c 目標傳送點不安全!"
|
||||||
|
your-level-is: "&c 你的島嶼現在 [level] 級,需要 [required] 級。 試試島嶼等級命令吧。"
|
||||||
|
help:
|
||||||
|
description: 打開傳送面板
|
||||||
|
next: "&6 下一頁"
|
||||||
|
player-warped: "&2 [name] 傳送到了你的傳送牌!"
|
||||||
|
previous: "&6 上一頁"
|
||||||
|
random: "&4 隨機傳送"
|
||||||
|
sign-removed: "&c 拆掉傳送牌了!"
|
||||||
|
success: "&成功!"
|
||||||
|
title: 傳送告示牌
|
||||||
|
warpTip: "&6 放個牌子第一行寫 [text] "
|
||||||
|
warpToPlayersSign: "&6 正傳送到 [player] 的牌子"
|
79
src/main/resources/panels/warps_panel.yml
Normal file
79
src/main/resources/panels/warps_panel.yml
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
warps_panel:
|
||||||
|
title: warps.gui.titles.warp-title
|
||||||
|
type: INVENTORY
|
||||||
|
background:
|
||||||
|
icon: BLACK_STAINED_GLASS_PANE
|
||||||
|
title: "&b&r" # Empty text
|
||||||
|
border:
|
||||||
|
icon: BLACK_STAINED_GLASS_PANE
|
||||||
|
title: "&b&r" # Empty text
|
||||||
|
force-shown: []
|
||||||
|
content:
|
||||||
|
2:
|
||||||
|
2: warp_button
|
||||||
|
3: warp_button
|
||||||
|
4: warp_button
|
||||||
|
5: warp_button
|
||||||
|
6: warp_button
|
||||||
|
7: warp_button
|
||||||
|
8: warp_button
|
||||||
|
3:
|
||||||
|
1:
|
||||||
|
icon: TIPPED_ARROW:INSTANT_HEAL::::1
|
||||||
|
title: warps.gui.buttons.previous.name
|
||||||
|
description: warps.gui.buttons.previous.description
|
||||||
|
data:
|
||||||
|
type: PREVIOUS
|
||||||
|
indexing: true
|
||||||
|
actions:
|
||||||
|
left:
|
||||||
|
type: PREVIOUS
|
||||||
|
tooltip: warps.gui.tips.click-to-previous
|
||||||
|
2: warp_button
|
||||||
|
3: warp_button
|
||||||
|
4: warp_button
|
||||||
|
5: warp_button
|
||||||
|
6: warp_button
|
||||||
|
7: warp_button
|
||||||
|
8: warp_button
|
||||||
|
9:
|
||||||
|
icon: TIPPED_ARROW:JUMP::::1
|
||||||
|
title: warps.gui.buttons.next.name
|
||||||
|
description: warps.gui.buttons.next.description
|
||||||
|
data:
|
||||||
|
type: NEXT
|
||||||
|
indexing: true
|
||||||
|
actions:
|
||||||
|
left:
|
||||||
|
type: NEXT
|
||||||
|
tooltip: warps.gui.tips.click-to-next
|
||||||
|
4:
|
||||||
|
2: warp_button
|
||||||
|
3: warp_button
|
||||||
|
4: warp_button
|
||||||
|
5: warp_button
|
||||||
|
6: warp_button
|
||||||
|
7: warp_button
|
||||||
|
8: warp_button
|
||||||
|
6:
|
||||||
|
5:
|
||||||
|
icon: DROPPER
|
||||||
|
title: warps.gui.buttons.random.name
|
||||||
|
description: warps.gui.buttons.random.description
|
||||||
|
data:
|
||||||
|
type: RANDOM
|
||||||
|
actions:
|
||||||
|
warp:
|
||||||
|
click-type: left
|
||||||
|
tooltip: warps.gui.tips.click-to-warp
|
||||||
|
reusable:
|
||||||
|
warp_button:
|
||||||
|
icon: PLAYER_HEAD
|
||||||
|
title: warps.gui.buttons.warp.name
|
||||||
|
description: warps.gui.buttons.warp.description
|
||||||
|
data:
|
||||||
|
type: WARP
|
||||||
|
actions:
|
||||||
|
warp:
|
||||||
|
click-type: left
|
||||||
|
tooltip: warps.gui.tips.click-to-warp
|
@ -1,8 +0,0 @@
|
|||||||
name: Pladdon
|
|
||||||
main: world.bentobox.warps.WarpsPladdon
|
|
||||||
version: ${version}
|
|
||||||
api-version: 1.16
|
|
||||||
description: A Warp Pladdon for BentoBox
|
|
||||||
author: tastybento
|
|
||||||
depend:
|
|
||||||
- BentoBox
|
|
@ -1,329 +0,0 @@
|
|||||||
package world.bentobox.warps;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemFactory;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.mockito.stubbing.Answer;
|
|
||||||
import org.powermock.api.mockito.PowerMockito;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
|
||||||
import world.bentobox.bentobox.api.user.User;
|
|
||||||
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
|
|
||||||
import world.bentobox.bentobox.database.DatabaseSetup;
|
|
||||||
import world.bentobox.bentobox.managers.PlayersManager;
|
|
||||||
import world.bentobox.warps.config.Settings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author tastybento
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({Bukkit.class, DatabaseSetup.class})
|
|
||||||
public class WarpPanelManagerTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private WarpSignsManager wsm;
|
|
||||||
@Mock
|
|
||||||
private Warp addon;
|
|
||||||
@Mock
|
|
||||||
private Player player;
|
|
||||||
@Mock
|
|
||||||
private User user;
|
|
||||||
@Mock
|
|
||||||
private World world;
|
|
||||||
@Mock
|
|
||||||
private Inventory top;
|
|
||||||
@Mock
|
|
||||||
private Settings settings;
|
|
||||||
@Mock
|
|
||||||
private static AbstractDatabaseHandler<Object> handler;
|
|
||||||
@Mock
|
|
||||||
private BukkitScheduler scheduler;
|
|
||||||
private List<UUID> list;
|
|
||||||
|
|
||||||
// Class under test
|
|
||||||
private WarpPanelManager wpm;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@BeforeClass
|
|
||||||
public static void beforeClass() {
|
|
||||||
// This has to be done beforeClass otherwise the tests will interfere with each other
|
|
||||||
handler = mock(AbstractDatabaseHandler.class);
|
|
||||||
// Database
|
|
||||||
PowerMockito.mockStatic(DatabaseSetup.class);
|
|
||||||
DatabaseSetup dbSetup = mock(DatabaseSetup.class);
|
|
||||||
when(DatabaseSetup.getDatabase()).thenReturn(dbSetup);
|
|
||||||
when(dbSetup.getHandler(any())).thenReturn(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
when(addon.getWarpSignsManager()).thenReturn(wsm);
|
|
||||||
// Fill with 200 fake warps (I'm banking on them all being different, but there could be a clash)
|
|
||||||
list = new ArrayList<>();
|
|
||||||
for (int i = 0; i< 200; i++) {
|
|
||||||
list.add(UUID.randomUUID());
|
|
||||||
}
|
|
||||||
// One final one
|
|
||||||
UUID uuid = UUID.randomUUID();
|
|
||||||
list.add(uuid);
|
|
||||||
|
|
||||||
when(wsm.getSortedWarps(any())).thenReturn(CompletableFuture.completedFuture(list));
|
|
||||||
|
|
||||||
// User and player
|
|
||||||
when(user.getPlayer()).thenReturn(player);
|
|
||||||
when(user.getTranslation(any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
|
||||||
|
|
||||||
|
|
||||||
// BentoBox
|
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
|
||||||
PlayersManager pm = mock(PlayersManager.class);
|
|
||||||
when(pm.getName(any())).thenReturn("name");
|
|
||||||
when(plugin.getPlayers()).thenReturn(pm);
|
|
||||||
when(addon.getPlugin()).thenReturn(plugin);
|
|
||||||
|
|
||||||
// Bukkit
|
|
||||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
|
||||||
ItemFactory itemF = mock(ItemFactory.class);
|
|
||||||
ItemMeta imeta = mock(ItemMeta.class);
|
|
||||||
when(itemF.getItemMeta(any())).thenReturn(imeta);
|
|
||||||
when(Bukkit.getItemFactory()).thenReturn(itemF);
|
|
||||||
when(Bukkit.getScheduler()).thenReturn(scheduler);
|
|
||||||
|
|
||||||
// Inventory
|
|
||||||
when(top.getSize()).thenReturn(9);
|
|
||||||
|
|
||||||
when(Bukkit.createInventory(any(), anyInt(), any())).thenReturn(top);
|
|
||||||
|
|
||||||
when(settings.getIcon()).thenReturn("SIGN");
|
|
||||||
when(addon.getSettings()).thenReturn(settings);
|
|
||||||
|
|
||||||
Location location = mock(Location.class);
|
|
||||||
Block block = mock(Block.class);
|
|
||||||
Material signType;
|
|
||||||
try {
|
|
||||||
signType = Material.valueOf("SIGN");
|
|
||||||
} catch (Exception e) {
|
|
||||||
signType = Material.valueOf("OAK_SIGN");
|
|
||||||
}
|
|
||||||
when(block.getType()).thenReturn(signType);
|
|
||||||
when(location.getBlock()).thenReturn(block);
|
|
||||||
// Sign block
|
|
||||||
when(wsm.getWarp(any(), any())).thenReturn(location);
|
|
||||||
|
|
||||||
// Sign cache
|
|
||||||
|
|
||||||
SignCacheItem sc = new SignCacheItem(Collections.singletonList("[welcome]"), signType);
|
|
||||||
when(wsm.getSignInfo(any(), any())).thenReturn(sc);
|
|
||||||
|
|
||||||
// Class under test
|
|
||||||
wpm = new WarpPanelManager(addon);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#processSigns(CompletableFuture, PanelBuilder, User, int, World)}.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testShowWarpPanelTestCache() {
|
|
||||||
PanelBuilder pb = mock(PanelBuilder.class);
|
|
||||||
// Do initial lookups of sign text
|
|
||||||
wpm.processSigns(new CompletableFuture<>(), pb, user, 3, world);
|
|
||||||
// Get the panel again
|
|
||||||
wpm.processSigns(new CompletableFuture<>(), pb, user, 3, world);
|
|
||||||
// Should only check this 201 times in total because the sign text is cached
|
|
||||||
verify(wsm, times(201)).getSignInfo(any(), any());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#removeWarp(org.bukkit.World, java.util.UUID)}.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testRemoveWarp() {
|
|
||||||
assertFalse(wpm.removeWarp(world, UUID.randomUUID()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#buildPanel(PanelBuilder, User, int, World)}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testBuildPanel() {
|
|
||||||
PanelBuilder pb = mock(PanelBuilder.class);
|
|
||||||
wpm.buildPanel(pb, user, 3, world);
|
|
||||||
// Removing the UUID should force a refresh and therefore 201 lookups
|
|
||||||
verify(wsm, times(201)).getSignInfo(any(), any());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#addNavigation(PanelBuilder, User, World, int, int, int)}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testAddNavigationNoNav() {
|
|
||||||
PanelBuilder pb = mock(PanelBuilder.class);
|
|
||||||
wpm.addNavigation(pb, user, world, 0, 0, 0);
|
|
||||||
verify(pb, never()).item(any());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#addNavigation(PanelBuilder, User, World, int, int, int)}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testAddNavigationNoNavNext() {
|
|
||||||
PanelBuilder pb = mock(PanelBuilder.class);
|
|
||||||
wpm.addNavigation(pb, user, world, 0, 0, 100);
|
|
||||||
verify(pb).item(any());
|
|
||||||
verify(user).getTranslation("warps.next");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#addNavigation(PanelBuilder, User, World, int, int, int)}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testAddNavigationNoNavPrev() {
|
|
||||||
PanelBuilder pb = mock(PanelBuilder.class);
|
|
||||||
wpm.addNavigation(pb, user, world, 60, 2, 20);
|
|
||||||
verify(pb).item(any());
|
|
||||||
verify(user).getTranslation("warps.previous");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#addNavigation(PanelBuilder, User, World, int, int, int)}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testAddNavigationNoNavNextAndPrev() {
|
|
||||||
PanelBuilder pb = mock(PanelBuilder.class);
|
|
||||||
wpm.addNavigation(pb, user, world, 60, 2, 100);
|
|
||||||
verify(pb, times(2)).item(any());
|
|
||||||
verify(user).getTranslation("warps.previous");
|
|
||||||
verify(user).getTranslation("warps.next");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private int mainBod(int page, int j, boolean random) {
|
|
||||||
when(settings.isRandomAllowed()).thenReturn(random);
|
|
||||||
PanelBuilder pb = mock(PanelBuilder.class);
|
|
||||||
int r = wpm.buildMainBody(pb, user, page, world, list);
|
|
||||||
verify(pb, times(j)).item(any());
|
|
||||||
if (random && page <= 0) {
|
|
||||||
verify(user).getTranslation("warps.random");
|
|
||||||
} else {
|
|
||||||
verify(user, never()).getTranslation("warps.random");
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#buildMainBody(PanelBuilder, User, int, World, List, boolean)}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testBuildMainBodyNoRandomPage0() {
|
|
||||||
assertEquals(201, mainBod(0, 201, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#buildMainBody(PanelBuilder, User, int, World, List, boolean)}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testBuildMainBodyNoRandomPage1() {
|
|
||||||
assertEquals(201, mainBod(1, 149, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#buildMainBody(PanelBuilder, User, int, World, List, boolean)}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testBuildMainBodyNoRandomPage2() {
|
|
||||||
assertEquals(201, mainBod(2, 97, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#buildMainBody(PanelBuilder, User, int, World, List, boolean)}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testBuildMainBodyNoRandomPage3() {
|
|
||||||
assertEquals(201, mainBod(3, 45, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#buildMainBody(PanelBuilder, User, int, World, List, boolean)}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testBuildMainBodyNoRandomPageMinus1() {
|
|
||||||
assertEquals(201, mainBod(-1, 201, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#buildMainBody(PanelBuilder, User, int, World, List, boolean)}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testBuildMainBodyRandomPage0() {
|
|
||||||
assertEquals(201, mainBod(0, 201, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#buildMainBody(PanelBuilder, User, int, World, List, boolean)}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testBuildMainBodyRandomPage1() {
|
|
||||||
assertEquals(201, mainBod(1, 149, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#buildMainBody(PanelBuilder, User, int, World, List, boolean)}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testBuildMainBodyRandomPage2() {
|
|
||||||
assertEquals(201, mainBod(2, 97, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#buildMainBody(PanelBuilder, User, int, World, List, boolean)}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testBuildMainBodyRandomPage3() {
|
|
||||||
assertEquals(201, mainBod(3, 45, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link WarpPanelManager#buildMainBody(PanelBuilder, User, int, World, List, boolean)}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testBuildMainBodyRandomPageMinus1() {
|
|
||||||
assertEquals(201, mainBod(-1, 201, true));
|
|
||||||
}
|
|
||||||
}
|
|
@ -61,8 +61,12 @@ import world.bentobox.bentobox.managers.PlayersManager;
|
|||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
import world.bentobox.warps.config.Settings;
|
import world.bentobox.warps.config.Settings;
|
||||||
import world.bentobox.warps.event.WarpInitiateEvent;
|
import world.bentobox.warps.event.WarpInitiateEvent;
|
||||||
|
import world.bentobox.warps.managers.SignCacheItem;
|
||||||
|
import world.bentobox.warps.managers.SignCacheManager;
|
||||||
|
import world.bentobox.warps.managers.WarpSignsManager;
|
||||||
import world.bentobox.warps.objects.WarpsData;
|
import world.bentobox.warps.objects.WarpsData;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
*
|
*
|
||||||
@ -98,7 +102,7 @@ public class WarpSignsManagerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private Player player;
|
private Player player;
|
||||||
@Mock
|
@Mock
|
||||||
private WarpPanelManager wpm;
|
private SignCacheManager wpm;
|
||||||
@Mock
|
@Mock
|
||||||
private PlayersManager pm;
|
private PlayersManager pm;
|
||||||
@Mock
|
@Mock
|
||||||
@ -193,7 +197,6 @@ public class WarpSignsManagerTest {
|
|||||||
when(addon.getSettings()).thenReturn(settings);
|
when(addon.getSettings()).thenReturn(settings);
|
||||||
when(settings.getWelcomeLine()).thenReturn("[Welcome]");
|
when(settings.getWelcomeLine()).thenReturn("[Welcome]");
|
||||||
when(settings.getLoreFormat()).thenReturn("&f");
|
when(settings.getLoreFormat()).thenReturn("&f");
|
||||||
when(settings.getIcon()).thenReturn("SIGN");
|
|
||||||
|
|
||||||
// Bukkit
|
// Bukkit
|
||||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||||
@ -217,7 +220,7 @@ public class WarpSignsManagerTest {
|
|||||||
when(im.isSafeLocation(any())).thenReturn(true);
|
when(im.isSafeLocation(any())).thenReturn(true);
|
||||||
|
|
||||||
// WarpPanelManager
|
// WarpPanelManager
|
||||||
when(addon.getWarpPanelManager()).thenReturn(wpm);
|
when(addon.getSignCacheManager()).thenReturn(wpm);
|
||||||
|
|
||||||
wsm = new WarpSignsManager(addon, plugin);
|
wsm = new WarpSignsManager(addon, plugin);
|
||||||
}
|
}
|
||||||
@ -230,7 +233,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#getWarpMap(org.bukkit.World)}.
|
* Test method for {@link WarpSignsManager#getWarpMap(org.bukkit.World)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetWarpMap() {
|
public void testGetWarpMap() {
|
||||||
@ -238,7 +241,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#getWarpMap(org.bukkit.World)}.
|
* Test method for {@link WarpSignsManager#getWarpMap(org.bukkit.World)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetWarpMapNullWorld() {
|
public void testGetWarpMapNullWorld() {
|
||||||
@ -248,7 +251,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#getWarpMap(org.bukkit.World)}.
|
* Test method for {@link WarpSignsManager#getWarpMap(org.bukkit.World)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetWarpMapWrongBlockType() {
|
public void testGetWarpMapWrongBlockType() {
|
||||||
@ -258,7 +261,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#getWarpMap(org.bukkit.World)}.
|
* Test method for {@link WarpSignsManager#getWarpMap(org.bukkit.World)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetWarpMapNullLocation() {
|
public void testGetWarpMapNullLocation() {
|
||||||
@ -269,7 +272,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#getWarpMap(org.bukkit.World)}.
|
* Test method for {@link WarpSignsManager#getWarpMap(org.bukkit.World)}.
|
||||||
* @throws Exception exception
|
* @throws Exception exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@ -280,7 +283,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#getWarpMap(org.bukkit.World)}.
|
* Test method for {@link WarpSignsManager#getWarpMap(org.bukkit.World)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetWarpMapNothingInDatabase() {
|
public void testGetWarpMapNothingInDatabase() {
|
||||||
@ -290,7 +293,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#WarpSignsManager(world.bentobox.warps.Warp, world.bentobox.bentobox.BentoBox)}.
|
* Test method for {@link WarpSignsManager#WarpSignsManager(world.bentobox.warps.Warp, world.bentobox.bentobox.BentoBox)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testWarpSignsManager() {
|
public void testWarpSignsManager() {
|
||||||
@ -300,7 +303,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#addWarp(java.util.UUID, org.bukkit.Location)}.
|
* Test method for {@link WarpSignsManager#addWarp(java.util.UUID, org.bukkit.Location)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testAddWarpNullPlayer() {
|
public void testAddWarpNullPlayer() {
|
||||||
@ -308,7 +311,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#addWarp(java.util.UUID, org.bukkit.Location)}.
|
* Test method for {@link WarpSignsManager#addWarp(java.util.UUID, org.bukkit.Location)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testAddWarpNullLocation() {
|
public void testAddWarpNullLocation() {
|
||||||
@ -316,7 +319,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#addWarp(java.util.UUID, org.bukkit.Location)}.
|
* Test method for {@link WarpSignsManager#addWarp(java.util.UUID, org.bukkit.Location)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testAddWarpReplaceOldSign() {
|
public void testAddWarpReplaceOldSign() {
|
||||||
@ -325,7 +328,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#addWarp(java.util.UUID, org.bukkit.Location)}.
|
* Test method for {@link WarpSignsManager#addWarp(java.util.UUID, org.bukkit.Location)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testAddWarpReplaceOldSignDifferentPlayer() {
|
public void testAddWarpReplaceOldSignDifferentPlayer() {
|
||||||
@ -334,7 +337,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#addWarp(java.util.UUID, org.bukkit.Location)}.
|
* Test method for {@link WarpSignsManager#addWarp(java.util.UUID, org.bukkit.Location)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testAddWarp() {
|
public void testAddWarp() {
|
||||||
@ -344,7 +347,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#getWarp(org.bukkit.World, java.util.UUID)}.
|
* Test method for {@link WarpSignsManager#getWarp(org.bukkit.World, java.util.UUID)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetWarpWorldWorld() {
|
public void testGetWarpWorldWorld() {
|
||||||
@ -352,7 +355,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#getWarp(org.bukkit.World, java.util.UUID)}.
|
* Test method for {@link WarpSignsManager#getWarp(org.bukkit.World, java.util.UUID)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetWarp() {
|
public void testGetWarp() {
|
||||||
@ -360,7 +363,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#getWarpOwner(org.bukkit.Location)}.
|
* Test method for {@link WarpSignsManager#getWarpOwner(org.bukkit.Location)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetWarpOwner() {
|
public void testGetWarpOwner() {
|
||||||
@ -368,7 +371,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#getSortedWarps(org.bukkit.World)}.
|
* Test method for {@link WarpSignsManager#getSortedWarps(org.bukkit.World)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetSortedWarps() {
|
public void testGetSortedWarps() {
|
||||||
@ -377,7 +380,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#listWarps(org.bukkit.World)}.
|
* Test method for {@link WarpSignsManager#listWarps(org.bukkit.World)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testListWarps() {
|
public void testListWarps() {
|
||||||
@ -386,7 +389,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#removeWarp(org.bukkit.Location)}.
|
* Test method for {@link WarpSignsManager#removeWarp(org.bukkit.Location)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveWarpLocation() {
|
public void testRemoveWarpLocation() {
|
||||||
@ -395,7 +398,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#removeWarp(org.bukkit.World, java.util.UUID)}.
|
* Test method for {@link WarpSignsManager#removeWarp(org.bukkit.World, java.util.UUID)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveWarpWorldUUID() {
|
public void testRemoveWarpWorldUUID() {
|
||||||
@ -404,7 +407,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#saveWarpList()}.
|
* Test method for {@link WarpSignsManager#saveWarpList()}.
|
||||||
* @throws Exception general exception
|
* @throws Exception general exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@ -414,16 +417,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#getSignInfo(org.bukkit.World, java.util.UUID)}.
|
* Test method for {@link WarpSignsManager#warpPlayer(org.bukkit.World, world.bentobox.bentobox.api.user.User, java.util.UUID)}.
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGetSignInfo() {
|
|
||||||
SignCacheItem sc = wsm.getSignInfo(world, uuid);
|
|
||||||
assertEquals(Material.ACACIA_SIGN, sc.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#warpPlayer(org.bukkit.World, world.bentobox.bentobox.api.user.User, java.util.UUID)}.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testWarpPlayer() {
|
public void testWarpPlayer() {
|
||||||
@ -441,7 +435,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#hasWarp(org.bukkit.World, java.util.UUID)}.
|
* Test method for {@link WarpSignsManager#hasWarp(org.bukkit.World, java.util.UUID)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testHasWarp() {
|
public void testHasWarp() {
|
||||||
@ -451,7 +445,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#loadWarpList()}.
|
* Test method for {@link WarpSignsManager#loadWarpList()}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testLoadWarpListNoWarpTable() {
|
public void testLoadWarpListNoWarpTable() {
|
||||||
@ -466,7 +460,7 @@ public class WarpSignsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#loadWarpList()}.
|
* Test method for {@link WarpSignsManager#loadWarpList()}.
|
||||||
* @throws Exception exception
|
* @throws Exception exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
|
@ -38,7 +38,7 @@ import world.bentobox.bentobox.managers.CommandsManager;
|
|||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.PlayersManager;
|
import world.bentobox.bentobox.managers.PlayersManager;
|
||||||
import world.bentobox.warps.Warp;
|
import world.bentobox.warps.Warp;
|
||||||
import world.bentobox.warps.WarpSignsManager;
|
import world.bentobox.warps.managers.WarpSignsManager;
|
||||||
import world.bentobox.warps.config.Settings;
|
import world.bentobox.warps.config.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,10 +7,8 @@ import static org.mockito.Mockito.mock;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -29,9 +27,9 @@ import world.bentobox.bentobox.api.user.User;
|
|||||||
import world.bentobox.bentobox.managers.CommandsManager;
|
import world.bentobox.bentobox.managers.CommandsManager;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.PlayersManager;
|
import world.bentobox.bentobox.managers.PlayersManager;
|
||||||
|
import world.bentobox.warps.managers.SignCacheManager;
|
||||||
import world.bentobox.warps.Warp;
|
import world.bentobox.warps.Warp;
|
||||||
import world.bentobox.warps.WarpPanelManager;
|
import world.bentobox.warps.managers.WarpSignsManager;
|
||||||
import world.bentobox.warps.WarpSignsManager;
|
|
||||||
import world.bentobox.warps.config.Settings;
|
import world.bentobox.warps.config.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,7 +60,7 @@ public class WarpsCommandTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private PlayersManager pm;
|
private PlayersManager pm;
|
||||||
@Mock
|
@Mock
|
||||||
private WarpPanelManager wpm;
|
private SignCacheManager wpm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@ -99,8 +97,13 @@ public class WarpsCommandTest {
|
|||||||
set.add(UUID.randomUUID());
|
set.add(UUID.randomUUID());
|
||||||
when(wsm.listWarps(world)).thenReturn(set);
|
when(wsm.listWarps(world)).thenReturn(set);
|
||||||
|
|
||||||
|
CompletableFuture<List<UUID>> warps = new CompletableFuture<>();
|
||||||
|
warps.complete(set.stream().toList());
|
||||||
|
|
||||||
|
when(wsm.getSortedWarps(world)).thenReturn(warps);
|
||||||
|
|
||||||
// Warp Panel Manager
|
// Warp Panel Manager
|
||||||
when(addon.getWarpPanelManager()).thenReturn(wpm);
|
when(addon.getSignCacheManager()).thenReturn(wpm);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +171,6 @@ public class WarpsCommandTest {
|
|||||||
public void testExecuteUserStringListOfString() {
|
public void testExecuteUserStringListOfString() {
|
||||||
warpCommandWarpsCompositeCommand();
|
warpCommandWarpsCompositeCommand();
|
||||||
assertTrue(wc.execute(user, "warps", Collections.emptyList()));
|
assertTrue(wc.execute(user, "warps", Collections.emptyList()));
|
||||||
verify(wpm).showWarpPanel(world, user, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -178,7 +180,6 @@ public class WarpsCommandTest {
|
|||||||
public void testExecuteUserStringListOfStringNoAddon() {
|
public void testExecuteUserStringListOfStringNoAddon() {
|
||||||
warpCommandWarps();
|
warpCommandWarps();
|
||||||
assertTrue(wc.execute(user, "warps", Collections.emptyList()));
|
assertTrue(wc.execute(user, "warps", Collections.emptyList()));
|
||||||
verify(wpm).showWarpPanel(world, user, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ import world.bentobox.bentobox.managers.LocalesManager;
|
|||||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
import world.bentobox.warps.Warp;
|
import world.bentobox.warps.Warp;
|
||||||
import world.bentobox.warps.WarpSignsManager;
|
import world.bentobox.warps.managers.WarpSignsManager;
|
||||||
import world.bentobox.warps.config.Settings;
|
import world.bentobox.warps.config.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user