mirror of
https://github.com/BentoBoxWorld/Warps.git
synced 2024-09-27 14:52:55 +02:00
Compare commits
100 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
26170204f2 | ||
|
9286b79fc9 | ||
|
412ef0e8e3 | ||
|
7853d67f79 | ||
|
aceb15b399 | ||
|
fa0b25769d | ||
|
fe83d097ca | ||
|
87f3ea732b | ||
|
2e13892ab8 | ||
|
623e93ce7c | ||
|
924cb0f9be | ||
|
1f434131af | ||
|
7a55573072 | ||
|
77e345566a | ||
|
0e8ab9c3f9 | ||
|
b7f0b170fa | ||
|
3fa1ddc860 | ||
|
18b63f4e79 | ||
|
4bacbd7c5a | ||
|
7f9f35253d | ||
|
599a6e1d08 | ||
|
1054518831 | ||
|
abd526b06d | ||
|
eeead7fb49 | ||
|
ef81a1c2f0 | ||
|
64f8a4899a | ||
|
0a343219bc | ||
|
0a12a26b06 | ||
|
b860a4dac5 | ||
|
2da0e5e82b | ||
|
a39b6a3f4a | ||
|
d70ee5d755 | ||
|
efc6b795d1 | ||
|
519a2d05fc | ||
|
86c089b694 | ||
|
3417633c4d | ||
|
b16d5102b1 | ||
|
4375eba030 | ||
|
bc1e92ee8d | ||
|
b88497397f | ||
|
b45c88025f | ||
|
3c9515295d | ||
|
82a0630ca3 | ||
|
6dbdb0f8aa | ||
|
a1e03af13a | ||
|
2558d9d1ab | ||
|
d346b7864e | ||
|
0e1cd1353c | ||
|
9657d11af7 | ||
|
ab1a1e203c | ||
|
1a90acb65f | ||
|
ae172b9fdf | ||
|
ecebbcd039 | ||
|
3faed651aa | ||
|
0585fd7f3a | ||
|
2f59225718 | ||
|
9e57851c62 | ||
|
b998b46fd5 | ||
|
cb165e52b0 | ||
|
ebb3f05d78 | ||
|
fe6b020ac8 | ||
|
d2dde61d8b | ||
|
e58010547b | ||
|
5a9f6495ad | ||
|
ff4850d32a | ||
|
7a26acefd9 | ||
|
2be57a66d2 | ||
|
67c5c9f8c3 | ||
|
62f1f2e966 | ||
|
5a37c3da75 | ||
|
94e9208941 | ||
|
225b4d66f8 | ||
|
d3b45396fd | ||
|
d2b9540650 | ||
|
363a628244 | ||
|
8be844b59f | ||
|
b3a36c75bb | ||
|
7dbb5d39ad | ||
|
fb1090717b | ||
|
39b94e09d8 | ||
|
5716214527 | ||
|
153e8be6a0 | ||
|
0dea651274 | ||
|
63b51fb26e | ||
|
15a699037a | ||
|
cbaf6ce16c | ||
|
b12a6dcff9 | ||
|
89bcc54e23 | ||
|
6db80f73f8 | ||
|
87d04302d2 | ||
|
9b0f00f2a0 | ||
|
048f7237da | ||
|
49d461d224 | ||
|
6cfaa0e9c0 | ||
|
9290503be3 | ||
|
079dba0f41 | ||
|
60c427c2a9 | ||
|
6caa652162 | ||
|
4ebaa22f37 | ||
|
f0780d91ba |
12
.github/workflows/build.yml
vendored
12
.github/workflows/build.yml
vendored
@ -11,22 +11,22 @@ jobs:
|
|||||||
name: Build
|
name: Build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
||||||
- name: Set up JDK 16
|
- name: Set up JDK 17
|
||||||
uses: actions/setup-java@v2
|
uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
java-version: '16'
|
java-version: '17'
|
||||||
- name: Cache SonarCloud packages
|
- name: Cache SonarCloud packages
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/.sonar/cache
|
path: ~/.sonar/cache
|
||||||
key: ${{ runner.os }}-sonar
|
key: ${{ runner.os }}-sonar
|
||||||
restore-keys: ${{ runner.os }}-sonar
|
restore-keys: ${{ runner.os }}-sonar
|
||||||
- name: Cache Maven packages
|
- name: Cache Maven packages
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/.m2
|
path: ~/.m2
|
||||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||||
|
@ -3,6 +3,10 @@ Add-on for BentoBox to add personal warp signs for players of BSkyBlock or AcidI
|
|||||||
This add-on will work for all game modes installed on a BentoBox server. Use config settings
|
This add-on will work for all game modes installed on a BentoBox server. Use config settings
|
||||||
to disable use by gamemode.
|
to disable use by gamemode.
|
||||||
|
|
||||||
|
![warps](https://github.com/user-attachments/assets/3454b7ec-d9bf-4631-9e5a-d6e603ac5f15)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
### Note: Java 16 and Minecraft 17, or later are required.
|
### Note: Java 16 and Minecraft 17, or later are required.
|
||||||
|
20
pom.xml
20
pom.xml
@ -54,19 +54,19 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<java.version>16</java.version>
|
<java.version>17</java.version>
|
||||||
<!-- Non-minecraft related dependencies -->
|
<!-- Non-minecraft related dependencies -->
|
||||||
<powermock.version>2.0.9</powermock.version>
|
<powermock.version>2.0.9</powermock.version>
|
||||||
<!-- More visible way how to change dependency versions -->
|
<!-- More visible way how to change dependency versions -->
|
||||||
<spigot.version>1.17-R0.1-SNAPSHOT</spigot.version>
|
<spigot.version>1.19.4-R0.1-SNAPSHOT</spigot.version>
|
||||||
<bentobox.version>1.18.0-SNAPSHOT</bentobox.version>
|
<bentobox.version>2.0.0-SNAPSHOT</bentobox.version>
|
||||||
<level.version>2.7.0-SNAPSHOT</level.version>
|
<level.version>2.7.0-SNAPSHOT</level.version>
|
||||||
<!-- Revision variable removes warning about dynamic version -->
|
<!-- Revision variable removes warning about dynamic version -->
|
||||||
<revision>${build.version}-SNAPSHOT</revision>
|
<revision>${build.version}-SNAPSHOT</revision>
|
||||||
<!-- 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.15.1</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>
|
||||||
@ -229,6 +229,7 @@
|
|||||||
<version>3.0.0-M5</version>
|
<version>3.0.0-M5</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<argLine>
|
<argLine>
|
||||||
|
${argLine}
|
||||||
--add-opens java.base/java.lang=ALL-UNNAMED
|
--add-opens java.base/java.lang=ALL-UNNAMED
|
||||||
--add-opens java.base/java.math=ALL-UNNAMED
|
--add-opens java.base/java.math=ALL-UNNAMED
|
||||||
--add-opens java.base/java.io=ALL-UNNAMED
|
--add-opens java.base/java.io=ALL-UNNAMED
|
||||||
@ -311,7 +312,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.jacoco</groupId>
|
<groupId>org.jacoco</groupId>
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
<version>0.8.3</version>
|
<version>0.8.10</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<append>true</append>
|
<append>true</append>
|
||||||
<excludes>
|
<excludes>
|
||||||
@ -322,16 +323,21 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>pre-unit-test</id>
|
<id>prepare-agent</id>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>prepare-agent</goal>
|
<goal>prepare-agent</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
<execution>
|
<execution>
|
||||||
<id>post-unit-test</id>
|
<id>report</id>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>report</goal>
|
<goal>report</goal>
|
||||||
</goals>
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<formats>
|
||||||
|
<format>XML</format>
|
||||||
|
</formats>
|
||||||
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
@ -7,16 +7,24 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
import world.bentobox.bentobox.api.configuration.Config;
|
import world.bentobox.bentobox.api.configuration.Config;
|
||||||
|
import world.bentobox.bentobox.api.flags.Flag;
|
||||||
|
import world.bentobox.bentobox.api.flags.clicklisteners.CycleClick;
|
||||||
|
import world.bentobox.bentobox.managers.RanksManager;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
import world.bentobox.level.Level;
|
import world.bentobox.level.Level;
|
||||||
|
import world.bentobox.warps.commands.ToggleWarpCommand;
|
||||||
import world.bentobox.warps.commands.WarpCommand;
|
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 +46,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.
|
||||||
*/
|
*/
|
||||||
@ -68,6 +76,11 @@ public class Warp extends Addon {
|
|||||||
*/
|
*/
|
||||||
private Config<Settings> settingsConfig;
|
private Config<Settings> settingsConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Warp Flag
|
||||||
|
*/
|
||||||
|
private Flag createWarpFlag;
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Methods
|
// Section: Methods
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
@ -88,6 +101,7 @@ public class Warp extends Addon {
|
|||||||
// Load the master warp and warps command
|
// Load the master warp and warps command
|
||||||
new WarpCommand(this);
|
new WarpCommand(this);
|
||||||
new WarpsCommand(this);
|
new WarpsCommand(this);
|
||||||
|
new ToggleWarpCommand(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,6 +142,7 @@ public class Warp extends Addon {
|
|||||||
|
|
||||||
new WarpCommand(this, gameModeAddon.getPlayerCommand().get());
|
new WarpCommand(this, gameModeAddon.getPlayerCommand().get());
|
||||||
new WarpsCommand(this, gameModeAddon.getPlayerCommand().get());
|
new WarpsCommand(this, gameModeAddon.getPlayerCommand().get());
|
||||||
|
new ToggleWarpCommand(this, gameModeAddon.getPlayerCommand().get());
|
||||||
this.hooked = true;
|
this.hooked = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -136,13 +151,25 @@ 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 {
|
||||||
logWarning("Addon did not hook into anything and is not running stand-alone");
|
logWarning("Addon did not hook into anything and is not running stand-alone");
|
||||||
this.setState(State.DISABLED);
|
this.setState(State.DISABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.createWarpFlag = new Flag.Builder("PLACE_WARP", Material.OAK_SIGN)
|
||||||
|
.addon(this)
|
||||||
|
.defaultRank(RanksManager.MEMBER_RANK)
|
||||||
|
.clickHandler(new CycleClick("PLACE_WARP",
|
||||||
|
RanksManager.MEMBER_RANK,
|
||||||
|
RanksManager.OWNER_RANK))
|
||||||
|
.defaultSetting(false)
|
||||||
|
.mode(Flag.Mode.EXPERT)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
getPlugin().getFlagsManager().registerFlag(this, this.createWarpFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -169,17 +196,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() {
|
||||||
@ -206,6 +237,13 @@ public class Warp extends Addon {
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the createWarpFlag
|
||||||
|
*/
|
||||||
|
public Flag getCreateWarpFlag() {
|
||||||
|
return createWarpFlag;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the island level
|
* Get the island level
|
||||||
* @param world - world
|
* @param world - world
|
||||||
@ -217,8 +255,11 @@ public class Warp extends Addon {
|
|||||||
String name = this.getPlugin().getIWM().getAddon(world).map(g -> g.getDescription().getName()).orElse("");
|
String name = this.getPlugin().getIWM().getAddon(world).map(g -> g.getDescription().getName()).orElse("");
|
||||||
return this.getPlugin().getAddonsManager().getAddonByName(LEVEL_ADDON_NAME)
|
return this.getPlugin().getAddonsManager().getAddonByName(LEVEL_ADDON_NAME)
|
||||||
.map(l -> {
|
.map(l -> {
|
||||||
if (!name.isEmpty() && ((Level) l).getSettings().getGameModes().contains(name)) {
|
final Level addon = (Level) l;
|
||||||
return ((Level) l).getIslandLevel(world, uniqueId);
|
//getGameModes is a list of gamemodes that Level is DISABLED in,
|
||||||
|
//so we need the opposite of the contains.
|
||||||
|
if (!name.isEmpty() && !addon.getSettings().getGameModes().contains(name)) {
|
||||||
|
return addon.getIslandLevel(world, uniqueId);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}).orElse(null);
|
}).orElse(null);
|
||||||
@ -250,7 +291,7 @@ public class Warp extends Addon {
|
|||||||
}
|
}
|
||||||
return switch (requestLabel) {
|
return switch (requestLabel) {
|
||||||
case "getSortedWarps" -> getWarpSignsManager().getSortedWarps(world);
|
case "getSortedWarps" -> getWarpSignsManager().getSortedWarps(world);
|
||||||
case "getWarp" -> uuid == null ? null : getWarpSignsManager().getWarp(world, uuid);
|
case "getWarp" -> uuid == null ? null : getWarpSignsManager().getWarpLocation(world, uuid);
|
||||||
case "getWarpMap" -> getWarpSignsManager().getWarpMap(world);
|
case "getWarpMap" -> getWarpSignsManager().getWarpMap(world);
|
||||||
case "hasWarp" -> uuid == null ? null : getWarpSignsManager().hasWarp(world, uuid);
|
case "hasWarp" -> uuid == null ? null : getWarpSignsManager().hasWarp(world, uuid);
|
||||||
case "listWarps" -> getWarpSignsManager().listWarps(world);
|
case "listWarps" -> getWarpSignsManager().listWarps(world);
|
||||||
|
@ -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,12 +1,18 @@
|
|||||||
package world.bentobox.warps;
|
package world.bentobox.warps;
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
|
||||||
public class WarpsPladdon extends Pladdon {
|
public class WarpsPladdon extends Pladdon {
|
||||||
|
private Addon addon;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Addon getAddon() {
|
public Addon getAddon() {
|
||||||
return new Warp();
|
if (addon == null) {
|
||||||
|
addon = new Warp();
|
||||||
|
}
|
||||||
|
return addon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
package world.bentobox.warps.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.warps.Warp;
|
||||||
|
import world.bentobox.warps.event.WarpToggleEvent;
|
||||||
|
import world.bentobox.warps.objects.PlayerWarp;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ToggleWarpCommand extends CompositeCommand {
|
||||||
|
|
||||||
|
private final Warp addon;
|
||||||
|
|
||||||
|
public ToggleWarpCommand(Warp addon, CompositeCommand bsbIslandCmd) {
|
||||||
|
super(bsbIslandCmd, addon.getSettings().getToggleWarpCommand());
|
||||||
|
this.addon = addon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ToggleWarpCommand(Warp addon) {
|
||||||
|
super(addon.getSettings().getToggleWarpCommand());
|
||||||
|
this.addon = addon;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setup() {
|
||||||
|
this.setPermission(this.getParent() == null ? Warp.WELCOME_WARP_SIGNS + ".togglewarp" : "island.warp.toggle");
|
||||||
|
this.setOnlyPlayer(true);
|
||||||
|
this.setDescription("togglewarp.help.description");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(User user, String s, List<String> list) {
|
||||||
|
UUID userUUID = user.getUniqueId();
|
||||||
|
World userWorld = user.getWorld();
|
||||||
|
|
||||||
|
// Check if the user has a warp
|
||||||
|
boolean hasWarp = addon.getWarpSignsManager().hasWarp(userWorld, userUUID);
|
||||||
|
|
||||||
|
if (hasWarp) {
|
||||||
|
// If the user has a warp, toggle its visibility
|
||||||
|
PlayerWarp warp = addon.getWarpSignsManager().getPlayerWarp(userWorld, userUUID);
|
||||||
|
// Check extreme case if PlayerWarp is null
|
||||||
|
if (warp == null) {
|
||||||
|
user.sendMessage("togglewarp.error.generic");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
warp.toggle();
|
||||||
|
Bukkit.getPluginManager().callEvent(new WarpToggleEvent(userUUID, warp));
|
||||||
|
String message = warp.isEnabled() ? "togglewarp.enabled" : "togglewarp.disabled";
|
||||||
|
user.sendMessage(message);
|
||||||
|
} else {
|
||||||
|
user.sendMessage("togglewarp.error.no-warp");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -50,12 +50,12 @@ public class WarpCommand extends DelayedTeleportCommand {
|
|||||||
user.sendMessage("warps.warpTip", "[text]", addon.getSettings().getWelcomeLine());
|
user.sendMessage("warps.warpTip", "[text]", addon.getSettings().getWelcomeLine());
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// Attemp to find warp with exact player's name
|
// Attempt to find warp with exact player's name
|
||||||
UUID foundWarp = warpList.stream().filter(u -> getPlayers().getName(u).equalsIgnoreCase(args.get(0))).findFirst().orElse(null);
|
UUID foundWarp = warpList.stream().filter(u -> getPlayers().getName(u).equalsIgnoreCase(args.get(0))).findFirst().orElse(null);
|
||||||
|
|
||||||
if (foundWarp == null) {
|
if (foundWarp == null) {
|
||||||
|
|
||||||
// Atempt to find warp which starts with the given name
|
// Attempt to find warp which starts with the given name
|
||||||
UUID foundAlernativeWarp = warpList.stream().filter(u -> getPlayers().getName(u).toLowerCase().startsWith(args.get(0).toLowerCase())).findFirst().orElse(null);
|
UUID foundAlernativeWarp = warpList.stream().filter(u -> getPlayers().getName(u).toLowerCase().startsWith(args.get(0).toLowerCase())).findFirst().orElse(null);
|
||||||
|
|
||||||
if (foundAlernativeWarp == null) {
|
if (foundAlernativeWarp == null) {
|
||||||
|
@ -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
|
||||||
@ -32,7 +34,7 @@ public class WarpsCommand extends CompositeCommand {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.setPermission(this.getParent() == null ? Warp.WELCOME_WARP_SIGNS + ".warp" : "island.warp");
|
this.setPermission(this.getParent() == null ? Warp.WELCOME_WARP_SIGNS + ".warps" : "island.warps");
|
||||||
this.setOnlyPlayer(true);
|
this.setOnlyPlayer(true);
|
||||||
this.setDescription("warps.help.description");
|
this.setDescription("warps.help.description");
|
||||||
}
|
}
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,20 +23,19 @@ public class Settings implements ConfigObject
|
|||||||
@ConfigEntry(path = "warplevelrestriction")
|
@ConfigEntry(path = "warplevelrestriction")
|
||||||
private int warpLevelRestriction = 10;
|
private int warpLevelRestriction = 10;
|
||||||
|
|
||||||
|
@ConfigComment("")
|
||||||
|
@ConfigComment("Should warps be removed when the island protection settings")
|
||||||
|
@ConfigComment("change, and the owner of the warp does no longer have")
|
||||||
|
@ConfigComment("the correct rank")
|
||||||
|
@ConfigEntry(path = "removeExistingWarpsWhenFlagChanges")
|
||||||
|
private boolean removeExistingWarpsWhenFlagChanges = false;
|
||||||
|
|
||||||
@ConfigComment("")
|
@ConfigComment("")
|
||||||
@ConfigComment("Text that player must put on sign to make it a warp sign")
|
@ConfigComment("Text that player must put on sign to make it a warp sign")
|
||||||
@ConfigComment("Not case sensitive!")
|
@ConfigComment("Not case sensitive!")
|
||||||
@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 +44,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")
|
||||||
@ -73,7 +61,8 @@ public class Settings implements ConfigObject
|
|||||||
String warpCommand = "warp";
|
String warpCommand = "warp";
|
||||||
@ConfigEntry(path = "warps-command")
|
@ConfigEntry(path = "warps-command")
|
||||||
String warpsCommand = "warps";
|
String warpsCommand = "warps";
|
||||||
|
@ConfigEntry(path = "togglewarp-command")
|
||||||
|
String toggleWarpCommand = "togglewarp";
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Constructor
|
// Section: Constructor
|
||||||
@ -155,42 +144,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 +160,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
|
||||||
*/
|
*/
|
||||||
@ -271,4 +208,31 @@ public class Settings implements ConfigObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the toggleWarpCommand
|
||||||
|
*/
|
||||||
|
public String getToggleWarpCommand() {
|
||||||
|
return toggleWarpCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param toggleWarpCommand the toggleWarpCommand to set
|
||||||
|
*/
|
||||||
|
public void setToggleWarpCommand(String toggleWarpCommand) {
|
||||||
|
this.toggleWarpCommand = toggleWarpCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the removeExistingWarpsWhenFlagChanges
|
||||||
|
*/
|
||||||
|
public boolean getRemoveExistingWarpsWhenFlagChanges() {
|
||||||
|
return removeExistingWarpsWhenFlagChanges;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param removeExistingWarpsWhenFlagChanges the removeExistingWarpsWhenFlagChanges to set
|
||||||
|
*/
|
||||||
|
public void setRemoveExistingWarpsWhenFlagChanges(boolean removeExistingWarpsWhenFlagChanges) {
|
||||||
|
this.removeExistingWarpsWhenFlagChanges = removeExistingWarpsWhenFlagChanges;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import world.bentobox.warps.Warp;
|
|||||||
* @author Poslovitch
|
* @author Poslovitch
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class WarpCreateEvent extends Event{
|
public class WarpCreateEvent extends Event {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
private final Location warpLoc;
|
private final Location warpLoc;
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
package world.bentobox.warps.event;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import world.bentobox.warps.objects.PlayerWarp;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event is fired when a warp is toggled
|
||||||
|
* A Listener to this event can use it only to get information. e.g: broadcast something
|
||||||
|
*
|
||||||
|
* @since 1.16.0
|
||||||
|
* @author TreemanKing
|
||||||
|
*/
|
||||||
|
public class WarpToggleEvent extends Event {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private final UUID user;
|
||||||
|
private final PlayerWarp playerWarp;
|
||||||
|
|
||||||
|
public WarpToggleEvent(UUID user, PlayerWarp playerWarp) {
|
||||||
|
this.playerWarp = playerWarp;
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the user who has toggled the warp
|
||||||
|
*
|
||||||
|
* @return the UUID of the player who toggled the warp
|
||||||
|
*/
|
||||||
|
public UUID getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the state of the warp
|
||||||
|
*
|
||||||
|
* @return true if the warp is enabled, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return playerWarp.isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the PlayerWarp object
|
||||||
|
*
|
||||||
|
* @return the PlayerWarp object
|
||||||
|
*/
|
||||||
|
public PlayerWarp getPlayerWarp() {
|
||||||
|
return playerWarp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the location of the toggled warp
|
||||||
|
*
|
||||||
|
* @return the location of the warp
|
||||||
|
*/
|
||||||
|
public Location getLocation() {
|
||||||
|
return playerWarp.getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,7 @@
|
|||||||
package world.bentobox.warps.listeners;
|
package world.bentobox.warps.listeners;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Iterator;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -25,10 +22,13 @@ import org.eclipse.jdt.annotation.Nullable;
|
|||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.events.addon.AddonEvent;
|
import world.bentobox.bentobox.api.events.addon.AddonEvent;
|
||||||
|
import world.bentobox.bentobox.api.events.flags.FlagProtectionChangeEvent;
|
||||||
import world.bentobox.bentobox.api.events.team.TeamKickEvent;
|
import world.bentobox.bentobox.api.events.team.TeamKickEvent;
|
||||||
import world.bentobox.bentobox.api.events.team.TeamLeaveEvent;
|
import world.bentobox.bentobox.api.events.team.TeamLeaveEvent;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
import world.bentobox.warps.objects.PlayerWarp;
|
||||||
import world.bentobox.warps.Warp;
|
import world.bentobox.warps.Warp;
|
||||||
import world.bentobox.warps.event.WarpRemoveEvent;
|
import world.bentobox.warps.event.WarpRemoveEvent;
|
||||||
|
|
||||||
@ -61,18 +61,18 @@ public class WarpSignsListener implements Listener {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
Iterator<Map.Entry<UUID, Location>> iterator =
|
Iterator<Map.Entry<UUID, PlayerWarp>> iterator =
|
||||||
addon.getWarpSignsManager().getWarpMap(event.getWorld()).entrySet().iterator();
|
addon.getWarpSignsManager().getWarpMap(event.getWorld()).entrySet().iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Map.Entry<UUID, Location> entry = iterator.next();
|
Map.Entry<UUID, PlayerWarp> entry = iterator.next();
|
||||||
UUID uuid = entry.getKey();
|
UUID uuid = entry.getKey();
|
||||||
Location location = entry.getValue();
|
Location location = entry.getValue().getLocation();
|
||||||
if (event.getChunk().getX() == location.getBlockX() >> 4
|
if (event.getChunk().getX() == location.getBlockX() >> 4
|
||||||
&& event.getChunk().getZ() == location.getBlockZ() >> 4
|
&& event.getChunk().getZ() == location.getBlockZ() >> 4
|
||||||
&& !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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,7 +114,6 @@ public class WarpSignsListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
User user = User.getInstance(e.getPlayer());
|
User user = User.getInstance(e.getPlayer());
|
||||||
if (user == null) return;
|
|
||||||
UUID owner = addon.getWarpSignsManager().getWarpOwnerUUID(b.getLocation()).orElse(null);
|
UUID owner = addon.getWarpSignsManager().getWarpOwnerUUID(b.getLocation()).orElse(null);
|
||||||
if (isPlayersSign(e.getPlayer(), b, inWorld)) {
|
if (isPlayersSign(e.getPlayer(), b, inWorld)) {
|
||||||
addon.getWarpSignsManager().removeWarp(b.getLocation());
|
addon.getWarpSignsManager().removeWarp(b.getLocation());
|
||||||
@ -128,16 +127,16 @@ public class WarpSignsListener implements Listener {
|
|||||||
|
|
||||||
private boolean isPlayersSign(Player player, Block b, boolean inWorld) {
|
private boolean isPlayersSign(Player player, Block b, boolean inWorld) {
|
||||||
// Welcome sign detected - check to see if it is this player's sign
|
// Welcome sign detected - check to see if it is this player's sign
|
||||||
Map<UUID, Location> list = addon.getWarpSignsManager().getWarpMap(b.getWorld());
|
Map<UUID, PlayerWarp> list = addon.getWarpSignsManager().getWarpMap(b.getWorld());
|
||||||
String reqPerm = inWorld ? addon.getPermPrefix(b.getWorld()) + "mod.removesign" : Warp.WELCOME_WARP_SIGNS + ".mod.removesign";
|
String reqPerm = inWorld ? addon.getPermPrefix(b.getWorld()) + "mod.removesign" : Warp.WELCOME_WARP_SIGNS + ".mod.removesign";
|
||||||
return ((list.containsKey(player.getUniqueId()) && list.get(player.getUniqueId()).equals(b.getLocation()))
|
return ((list.containsKey(player.getUniqueId()) && list.get(player.getUniqueId()).getLocation().equals(b.getLocation()))
|
||||||
|| player.isOp() || player.hasPermission(reqPerm));
|
|| player.isOp() || player.hasPermission(reqPerm));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isWarpSign(Block b) {
|
private boolean isWarpSign(Block b) {
|
||||||
Sign s = (Sign) b.getState();
|
Sign s = (Sign) b.getState();
|
||||||
return s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + addon.getSettings().getWelcomeLine())
|
return s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + addon.getSettings().getWelcomeLine())
|
||||||
&& addon.getWarpSignsManager().getWarpMap(b.getWorld()).containsValue(s.getLocation());
|
&& addon.getWarpSignsManager().getWarpMap(b.getWorld()).values().stream().anyMatch(playerWarp -> playerWarp.getLocation().equals(s.getLocation()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -160,12 +159,24 @@ public class WarpSignsListener implements Listener {
|
|||||||
if (noPerms(user, b.getWorld(), inWorld)) {
|
if (noPerms(user, b.getWorld(), inWorld)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// TODO: These checks are useless if the sign is placed outside a BSB world.
|
||||||
|
// This will mean level and rank requirements are nil in the case of allow-in-other-worlds: true.
|
||||||
|
// I'm not sure if there is a better way around this without adding new API checking for primary
|
||||||
|
// or last island accessed with relevant permissions.
|
||||||
|
// ignored.
|
||||||
if (inWorld && noLevelOrIsland(user, b.getWorld())) {
|
if (inWorld && noLevelOrIsland(user, b.getWorld())) {
|
||||||
e.setLine(0, ChatColor.RED + addon.getSettings().getWelcomeLine());
|
e.setLine(0, ChatColor.RED + addon.getSettings().getWelcomeLine());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (inWorld && !hasCorrectIslandRank(b, user)) {
|
||||||
|
e.setLine(0, ChatColor.RED + addon.getSettings().getWelcomeLine());
|
||||||
|
user.sendMessage("warps.error.not-correct-rank");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the player already has a sign
|
// Check if the player already has a sign
|
||||||
final Location oldSignLoc = addon.getWarpSignsManager().getWarp(b.getWorld(), user.getUniqueId());
|
final Location oldSignLoc = addon.getWarpSignsManager().getWarpLocation(b.getWorld(), user.getUniqueId());
|
||||||
if (oldSignLoc != null) {
|
if (oldSignLoc != null) {
|
||||||
// A sign already exists. Check if it still there and if
|
// A sign already exists. Check if it still there and if
|
||||||
// so,
|
// so,
|
||||||
@ -192,6 +203,46 @@ public class WarpSignsListener implements Listener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasCorrectIslandRank(Block b, User user) {
|
||||||
|
final Optional<Island> islandOpt = plugin.getIslands().getIslandAt(b.getLocation());
|
||||||
|
|
||||||
|
if(islandOpt.isEmpty()) return false;
|
||||||
|
|
||||||
|
final Island island = islandOpt.get();
|
||||||
|
|
||||||
|
final int userRank = island.getRank(user);
|
||||||
|
|
||||||
|
return userRank >= island.getFlag(addon.getCreateWarpFlag());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onFlagChange(FlagProtectionChangeEvent e) {
|
||||||
|
if(!e.getEditedFlag().equals(addon.getCreateWarpFlag())) return;
|
||||||
|
if(!addon.getSettings().getRemoveExistingWarpsWhenFlagChanges()) return;
|
||||||
|
|
||||||
|
final Island island = e.getIsland();
|
||||||
|
|
||||||
|
final Map<UUID, PlayerWarp> islandWarps = addon
|
||||||
|
.getWarpSignsManager()
|
||||||
|
.getWarpMap(island.getWorld())
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.filter(x -> island.inIslandSpace(x.getValue().getLocation()))
|
||||||
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
|
|
||||||
|
for(Map.Entry<UUID, PlayerWarp> entry : islandWarps.entrySet()) {
|
||||||
|
if(island.getRank(entry.getKey()) >= e.getSetTo()) continue;
|
||||||
|
|
||||||
|
//The user has a lower rank than the new set value.
|
||||||
|
//We need to remove the warp.
|
||||||
|
addon.getWarpSignsManager().removeWarp(island.getWorld(), entry.getKey());
|
||||||
|
|
||||||
|
if(Bukkit.getPlayer(entry.getKey()) != null) {
|
||||||
|
Objects.requireNonNull(User.getInstance(entry.getKey())).sendMessage(WARPS_DEACTIVATE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean noLevelOrIsland(User user, World world) {
|
private boolean noLevelOrIsland(User user, World world) {
|
||||||
// Get level if level addon is available
|
// Get level if level addon is available
|
||||||
Long level = addon.getLevel(Util.getWorld(world), user.getUniqueId());
|
Long level = addon.getLevel(Util.getWorld(world), user.getUniqueId());
|
||||||
|
@ -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;
|
||||||
@ -21,13 +21,12 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
@ -38,8 +37,13 @@ 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.objects.PlayerWarp;
|
||||||
|
import world.bentobox.warps.Warp;
|
||||||
|
import world.bentobox.warps.event.WarpCreateEvent;
|
||||||
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
|
||||||
@ -52,7 +56,7 @@ public class WarpSignsManager {
|
|||||||
private static final String WARPS = "warps";
|
private static final String WARPS = "warps";
|
||||||
private final BentoBox plugin;
|
private final BentoBox plugin;
|
||||||
// Map of all warps stored as player, warp sign Location
|
// Map of all warps stored as player, warp sign Location
|
||||||
private Map<World, Map<UUID, Location>> worldsWarpList;
|
private Map<World, Map<UUID, PlayerWarp>> worldsWarpList;
|
||||||
// Database handler for level data
|
// Database handler for level data
|
||||||
private final Database<WarpsData> handler;
|
private final Database<WarpsData> handler;
|
||||||
|
|
||||||
@ -65,7 +69,7 @@ public class WarpSignsManager {
|
|||||||
* @return map of warps
|
* @return map of warps
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public Map<UUID, Location> getWarpMap(@Nullable World world) {
|
public Map<UUID, PlayerWarp> getWarpMap(@Nullable World world) {
|
||||||
return worldsWarpList.computeIfAbsent(Util.getWorld(world), k -> new HashMap<>());
|
return worldsWarpList.computeIfAbsent(Util.getWorld(world), k -> new HashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,13 +101,15 @@ public class WarpSignsManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check for warps placed in a location where there was a warp before
|
// Check for warps placed in a location where there was a warp before
|
||||||
if (getWarpMap(loc.getWorld()).containsValue(loc)) {
|
for (PlayerWarp playerWarp : getWarpMap(loc.getWorld()).values()) {
|
||||||
// remove the warp at this location, then place it
|
if (playerWarp.getLocation().equals(loc)) {
|
||||||
this.removeWarp(loc);
|
this.removeWarp(loc);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
getWarpMap(loc.getWorld()).put(playerUUID, loc);
|
getWarpMap(loc.getWorld()).put(playerUUID, new PlayerWarp(loc, true));
|
||||||
saveWarpList();
|
saveWarpList();
|
||||||
Bukkit.getPluginManager().callEvent(new WarpInitiateEvent(addon, loc, playerUUID));
|
Bukkit.getPluginManager().callEvent(new WarpCreateEvent(addon, loc, playerUUID));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +122,13 @@ public class WarpSignsManager {
|
|||||||
* @return Location of warp or null
|
* @return Location of warp or null
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Location getWarp(World world, UUID playerUUID) {
|
public Location getWarpLocation(World world, UUID playerUUID) {
|
||||||
|
PlayerWarp playerWarp = getWarpMap(world).get(playerUUID);
|
||||||
|
return playerWarp != null ? playerWarp.getLocation() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public PlayerWarp getPlayerWarp(World world, UUID playerUUID) {
|
||||||
return getWarpMap(world).get(playerUUID);
|
return getWarpMap(world).get(playerUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +139,7 @@ public class WarpSignsManager {
|
|||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getWarpOwner(Location location) {
|
public String getWarpOwner(Location location) {
|
||||||
return getWarpMap(location.getWorld()).entrySet().stream().filter(en -> en.getValue().equals(location))
|
return getWarpMap(location.getWorld()).entrySet().stream().filter(en -> en.getValue().getLocation().equals(location))
|
||||||
.findFirst().map(en -> plugin.getPlayers().getName(en.getKey())).orElse("");
|
.findFirst().map(en -> plugin.getPlayers().getName(en.getKey())).orElse("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +149,7 @@ public class WarpSignsManager {
|
|||||||
* @return Optional UUID of warp owner or empty if there is none
|
* @return Optional UUID of warp owner or empty if there is none
|
||||||
*/
|
*/
|
||||||
public Optional<UUID> getWarpOwnerUUID(Location location) {
|
public Optional<UUID> getWarpOwnerUUID(Location location) {
|
||||||
return getWarpMap(location.getWorld()).entrySet().stream().filter(en -> en.getValue().equals(location))
|
return getWarpMap(location.getWorld()).entrySet().stream().filter(en -> en.getValue().getLocation().equals(location))
|
||||||
.findFirst().map(Map.Entry::getKey);
|
.findFirst().map(Map.Entry::getKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,12 +163,16 @@ 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
|
||||||
TreeMap<Long, UUID> map = new TreeMap<>();
|
TreeMap<Long, UUID> map = new TreeMap<>();
|
||||||
getWarpMap(world).forEach((uuid, value) -> {
|
getWarpMap(world).forEach((uuid, value) -> {
|
||||||
|
// If the warp is not enabled, skip this iteration
|
||||||
|
if (!value.isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// If never played, will be zero
|
// If never played, will be zero
|
||||||
long lastPlayed = addon.getServer().getOfflinePlayer(uuid).getLastPlayed();
|
long lastPlayed = addon.getServer().getOfflinePlayer(uuid).getLastPlayed();
|
||||||
// This aims to avoid the chance that players logged off at exactly the same time
|
// This aims to avoid the chance that players logged off at exactly the same time
|
||||||
@ -185,28 +201,33 @@ public class WarpSignsManager {
|
|||||||
public Set<UUID> listWarps(@NonNull World world) {
|
public Set<UUID> listWarps(@NonNull World world) {
|
||||||
// Remove any null locations
|
// Remove any null locations
|
||||||
getWarpMap(world).values().removeIf(Objects::isNull);
|
getWarpMap(world).values().removeIf(Objects::isNull);
|
||||||
return getWarpMap(world).entrySet().stream().filter(e -> Util.sameWorld(world, Objects.requireNonNull(e.getValue().getWorld()))).map(Map.Entry::getKey).collect(Collectors.toSet());
|
// Remove any warps that have not been toggled on
|
||||||
|
Map<UUID, PlayerWarp> enabledWarps = getWarpMap(world).entrySet().stream()
|
||||||
|
.filter(entry -> entry.getValue().isEnabled())
|
||||||
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
|
return enabledWarps.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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)) {
|
||||||
warpsData = handler.loadObject(WARPS);
|
warpsData = handler.loadObject(WARPS);
|
||||||
// Load into map
|
// Load into map
|
||||||
if (warpsData != null) {
|
if (warpsData != null) {
|
||||||
warpsData.getWarpSigns().forEach((k,v) -> {
|
warpsData.getWarpSigns().forEach((pw, uuid) -> {
|
||||||
if (k != null && k.getWorld() != null) {
|
Location location = pw.getLocation();
|
||||||
if (k.getWorld().isChunkLoaded(k.getBlockX() >> 4, k.getBlockZ() >> 4)
|
if (location != null && location.getWorld() != null) {
|
||||||
&& !k.getBlock().getType().name().contains("SIGN")) {
|
if (location.getWorld().isChunkLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4)
|
||||||
|
&& !location.getBlock().getType().name().contains("SIGN")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to map
|
// Add to map
|
||||||
getWarpMap(k.getWorld()).put(v, k);
|
getWarpMap(location.getWorld()).put(uuid, new PlayerWarp(location, true));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -237,16 +258,16 @@ public class WarpSignsManager {
|
|||||||
*/
|
*/
|
||||||
public void removeWarp(Location loc) {
|
public void removeWarp(Location loc) {
|
||||||
popSign(loc);
|
popSign(loc);
|
||||||
Iterator<Entry<UUID, Location>> it = getWarpMap(loc.getWorld()).entrySet().iterator();
|
Iterator<Entry<UUID, PlayerWarp>> it = getWarpMap(loc.getWorld()).entrySet().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Entry<UUID, Location> en = it.next();
|
Entry<UUID, PlayerWarp> en = it.next();
|
||||||
if (en.getValue().equals(loc)) {
|
if (en.getValue().getLocation().equals(loc)) {
|
||||||
// Inform player
|
// Inform player
|
||||||
Optional.ofNullable(addon.getServer().getPlayer(en.getKey()))
|
Optional.ofNullable(addon.getServer().getPlayer(en.getKey()))
|
||||||
.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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -260,12 +281,12 @@ public class WarpSignsManager {
|
|||||||
*/
|
*/
|
||||||
public void removeWarp(World world, UUID uuid) {
|
public void removeWarp(World world, UUID uuid) {
|
||||||
if (getWarpMap(world).containsKey(uuid)) {
|
if (getWarpMap(world).containsKey(uuid)) {
|
||||||
popSign(getWarpMap(world).get(uuid));
|
popSign(getWarpMap(world).get(uuid).getLocation());
|
||||||
getWarpMap(world).remove(uuid);
|
getWarpMap(world).remove(uuid);
|
||||||
|
|
||||||
}
|
}
|
||||||
// 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 +304,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -296,7 +317,7 @@ public class WarpSignsManager {
|
|||||||
@NonNull
|
@NonNull
|
||||||
public SignCacheItem getSignInfo(@NonNull World world, @NonNull UUID uuid) {
|
public SignCacheItem getSignInfo(@NonNull World world, @NonNull UUID uuid) {
|
||||||
//get the sign info
|
//get the sign info
|
||||||
Location signLocation = getWarp(world, uuid);
|
Location signLocation = getWarpLocation(world, uuid);
|
||||||
if (signLocation == null || !signLocation.getBlock().getType().name().contains("SIGN")) {
|
if (signLocation == null || !signLocation.getBlock().getType().name().contains("SIGN")) {
|
||||||
return new SignCacheItem();
|
return new SignCacheItem();
|
||||||
}
|
}
|
||||||
@ -311,7 +332,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 +339,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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -348,21 +369,38 @@ public class WarpSignsManager {
|
|||||||
float yaw = Util.blockFaceToFloat(directionFacing);
|
float yaw = Util.blockFaceToFloat(directionFacing);
|
||||||
final Location actualWarp = new Location(inFront.getWorld(), inFront.getBlockX() + 0.5D, inFront.getBlockY(),
|
final Location actualWarp = new Location(inFront.getWorld(), inFront.getBlockX() + 0.5D, inFront.getBlockY(),
|
||||||
inFront.getBlockZ() + 0.5D, yaw, 30F);
|
inFront.getBlockZ() + 0.5D, yaw, 30F);
|
||||||
Util.teleportAsync(user.getPlayer(), actualWarp, TeleportCause.COMMAND);
|
WarpInitiateEvent e = new WarpInitiateEvent(addon, actualWarp, user.getUniqueId());
|
||||||
User warpOwner = Objects.requireNonNull(User.getInstance(signOwner));
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
// Hide invisible players
|
if (e.isCancelled()) {
|
||||||
if (warpOwner.isOnline() && !warpOwner.getPlayer().canSee(user.getPlayer())) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pvp) {
|
//BentoBox prevents people from teleporting to an island when
|
||||||
user.sendMessage("protection.flags.PVP_OVERWORLD.enabled");
|
//the user is banned from the island for example.
|
||||||
user.getWorld().playSound(Objects.requireNonNull(user.getLocation()), Sound.ENTITY_ARROW_HIT, 1F, 1F);
|
//By checking if the teleport succeeded before sending the messages,
|
||||||
} else {
|
//we prevent issues where no one teleported, but people still
|
||||||
user.getWorld().playSound(Objects.requireNonNull(user.getLocation()), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F);
|
//get messages about it.
|
||||||
}
|
Util.teleportAsync(user.getPlayer(), actualWarp, TeleportCause.COMMAND).thenAccept(tpResult -> {
|
||||||
if (!warpOwner.equals(user)) {
|
if(Boolean.FALSE.equals(tpResult)) return;
|
||||||
warpOwner.sendMessage("warps.player-warped", "[name]", user.getName());
|
|
||||||
}
|
User warpOwner = Objects.requireNonNull(User.getInstance(signOwner));
|
||||||
|
// Hide invisible players
|
||||||
|
if (warpOwner.isOnline() && !warpOwner.getPlayer().canSee(user.getPlayer())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pvp) {
|
||||||
|
user.sendMessage("protection.flags.PVP_OVERWORLD.enabled");
|
||||||
|
user.getWorld().playSound(Objects.requireNonNull(user.getLocation()), Sound.ENTITY_ARROW_HIT, 1F, 1F);
|
||||||
|
} else {
|
||||||
|
user.getWorld().playSound(Objects.requireNonNull(user.getLocation()), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F);
|
||||||
|
}
|
||||||
|
if (!warpOwner.equals(user)) {
|
||||||
|
final String gameMode = BentoBox
|
||||||
|
.getInstance()
|
||||||
|
.getIWM()
|
||||||
|
.getFriendlyName(actualWarp.getWorld());
|
||||||
|
warpOwner.sendMessage("warps.player-warped", "[name]", user.getName(), "[gamemode]", gameMode);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -373,7 +411,7 @@ public class WarpSignsManager {
|
|||||||
* @param owner - owner of the warp
|
* @param owner - owner of the warp
|
||||||
*/
|
*/
|
||||||
public void warpPlayer(@NonNull World world, @NonNull User user, @NonNull UUID owner) {
|
public void warpPlayer(@NonNull World world, @NonNull User user, @NonNull UUID owner) {
|
||||||
final Location warpSpot = getWarp(world, owner);
|
final Location warpSpot = getWarpLocation(world, owner);
|
||||||
// Check if the warp spot is safe
|
// Check if the warp spot is safe
|
||||||
if (warpSpot == null) {
|
if (warpSpot == null) {
|
||||||
user.sendMessage("warps.error.does-not-exist");
|
user.sendMessage("warps.error.does-not-exist");
|
||||||
@ -410,7 +448,7 @@ public class WarpSignsManager {
|
|||||||
}
|
}
|
||||||
// Find out which direction the warp is facing
|
// Find out which direction the warp is facing
|
||||||
Block b = warpSpot.getBlock();
|
Block b = warpSpot.getBlock();
|
||||||
if (b.getType().name().contains("WALL_SIGN")) {
|
if (Tag.WALL_SIGNS.isTagged(b.getType())) {
|
||||||
org.bukkit.block.data.type.WallSign s = (org.bukkit.block.data.type.WallSign) b.getBlockData();
|
org.bukkit.block.data.type.WallSign s = (org.bukkit.block.data.type.WallSign) b.getBlockData();
|
||||||
BlockFace directionFacing = s.getFacing();
|
BlockFace directionFacing = s.getFacing();
|
||||||
Location inFront = b.getRelative(directionFacing).getLocation();
|
Location inFront = b.getRelative(directionFacing).getLocation();
|
||||||
@ -423,7 +461,13 @@ public class WarpSignsManager {
|
|||||||
warpPlayer(user, oneDown, owner, directionFacing, pvp);
|
warpPlayer(user, oneDown, owner, directionFacing, pvp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (b.getType().name().contains("SIGN")) {
|
} else if (Tag.ALL_HANGING_SIGNS.isTagged(b.getType())) {
|
||||||
|
Location below = b.getRelative(BlockFace.DOWN).getRelative(BlockFace.DOWN).getLocation();
|
||||||
|
if ((addon.getIslands().isSafeLocation(below))) {
|
||||||
|
warpPlayer(user, below, owner, BlockFace.DOWN, pvp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (Tag.STANDING_SIGNS.isTagged(b.getType())) {
|
||||||
org.bukkit.block.data.type.Sign s = (org.bukkit.block.data.type.Sign) b.getBlockData();
|
org.bukkit.block.data.type.Sign s = (org.bukkit.block.data.type.Sign) b.getBlockData();
|
||||||
BlockFace directionFacing = s.getRotation();
|
BlockFace directionFacing = s.getRotation();
|
||||||
Location inFront = b.getRelative(directionFacing).getLocation();
|
Location inFront = b.getRelative(directionFacing).getLocation();
|
||||||
@ -460,54 +504,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;
|
|
||||||
}
|
|
||||||
}
|
}
|
32
src/main/java/world/bentobox/warps/objects/PlayerWarp.java
Normal file
32
src/main/java/world/bentobox/warps/objects/PlayerWarp.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package world.bentobox.warps.objects;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class PlayerWarp implements Serializable {
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
private final Location location;
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
private boolean isEnabled;
|
||||||
|
|
||||||
|
public PlayerWarp(Location location, boolean isEnabled) {
|
||||||
|
this.location = location;
|
||||||
|
this.isEnabled = isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggle() {
|
||||||
|
isEnabled = !isEnabled;
|
||||||
|
}
|
||||||
|
}
|
@ -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 {
|
||||||
|
@ -17,9 +17,13 @@ public class WarpsData implements DataObject {
|
|||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
private String uniqueId = "warps";
|
private String uniqueId = "warps";
|
||||||
@Expose
|
|
||||||
|
@Deprecated @Expose
|
||||||
private Map<Location, UUID> warpSigns = new HashMap<>();
|
private Map<Location, UUID> warpSigns = new HashMap<>();
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
private Map<PlayerWarp, UUID> newWarpSigns = new HashMap<>();
|
||||||
|
|
||||||
public WarpsData() {
|
public WarpsData() {
|
||||||
// Required by YAML database
|
// Required by YAML database
|
||||||
}
|
}
|
||||||
@ -34,24 +38,40 @@ public class WarpsData implements DataObject {
|
|||||||
this.uniqueId = uniqueId;
|
this.uniqueId = uniqueId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Location, UUID> getWarpSigns() {
|
public Map<PlayerWarp, UUID> getWarpSigns() {
|
||||||
if (warpSigns == null)
|
convertOldWarpSigns();
|
||||||
|
if (newWarpSigns == null)
|
||||||
return new HashMap<>();
|
return new HashMap<>();
|
||||||
return warpSigns;
|
return newWarpSigns;
|
||||||
}
|
|
||||||
|
|
||||||
public void setWarpSigns(Map<Location, UUID> warpSigns) {
|
|
||||||
this.warpSigns = warpSigns;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puts all the data from the map into this objects ready for saving
|
* Method for converting old warp signs to new warp signs
|
||||||
|
*/
|
||||||
|
public void convertOldWarpSigns() {
|
||||||
|
if (warpSigns == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<Location, UUID> entry : warpSigns.entrySet()) {
|
||||||
|
PlayerWarp playerWarp = new PlayerWarp(entry.getKey(), true);
|
||||||
|
newWarpSigns.put(playerWarp, entry.getValue());
|
||||||
|
}
|
||||||
|
warpSigns = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWarpSigns(Map<PlayerWarp, UUID> warpSigns) {
|
||||||
|
this.newWarpSigns = warpSigns;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Puts all the data from the map into these objects ready for saving
|
||||||
* @param worldsWarpList 2D map of warp locations by world vs UUID
|
* @param worldsWarpList 2D map of warp locations by world vs UUID
|
||||||
* @return this class filled with data
|
* @return this class filled with data
|
||||||
*/
|
*/
|
||||||
public WarpsData save(Map<World, Map<UUID, Location>> worldsWarpList) {
|
public WarpsData save(Map<World, Map<UUID, PlayerWarp>> worldsWarpList) {
|
||||||
getWarpSigns().clear();
|
getWarpSigns().clear();
|
||||||
worldsWarpList.values().forEach(world -> world.forEach((uuid,location) -> warpSigns.put(location, uuid)));
|
worldsWarpList.values().forEach(world -> world.forEach((uuid,playerWarp) -> newWarpSigns.put(playerWarp, uuid)));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)).
|
||||||
|
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();
|
||||||
|
}
|
@ -10,8 +10,14 @@ softdepend: AcidIsland, BSkyBlock, CaveBlock, SkyGrid, AOneBlock
|
|||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
'[gamemode].island.warp':
|
'[gamemode].island.warp':
|
||||||
description: Player can use warp or warps commands
|
description: Player can use warp command
|
||||||
|
default: true
|
||||||
|
'[gamemode].island.warps':
|
||||||
|
description: Player can use the warps command
|
||||||
default: true
|
default: true
|
||||||
'[gamemode].island.addwarp':
|
'[gamemode].island.addwarp':
|
||||||
description: Player can create a welcome warp sign
|
description: Player can create a welcome warp sign
|
||||||
default: true
|
default: true
|
||||||
|
'[gamemode].island.togglewarp':
|
||||||
|
description: Player can toggle a warp sign
|
||||||
|
default: true
|
||||||
|
@ -7,37 +7,30 @@
|
|||||||
# Warp Restriction - needed levels to be able to create a warp
|
# Warp Restriction - needed levels to be able to create a warp
|
||||||
# 0 or negative values will disable this restriction 10 is default
|
# 0 or negative values will disable this restriction 10 is default
|
||||||
warplevelrestriction: 10
|
warplevelrestriction: 10
|
||||||
|
#
|
||||||
|
# Should warps be removed when the island protection settings
|
||||||
|
# change, and the owner of the warp does no longer have
|
||||||
|
# the correct rank
|
||||||
|
removeExistingWarpsWhenFlagChanges: true
|
||||||
#
|
#
|
||||||
# Text that player must put on sign to make it a warp sign
|
# Text that player must put on sign to make it a warp sign
|
||||||
# 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
|
||||||
#
|
#
|
||||||
# Warp and warps commands. You can change them if they clash with other addons or plugins.
|
# Warp and warps commands. You can change them if they clash with other addons or plugins.
|
||||||
warp-command: warp
|
warp-command: warp
|
||||||
warps-command: warps
|
warps-command: warps
|
||||||
|
togglewarp-command: togglewarp
|
||||||
|
@ -1,17 +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: Teleportovat se na warp ceduli hráče
|
||||||
# Translation by: CZghost #
|
parameters: "<player name>"
|
||||||
###########################################################################################
|
warps:
|
||||||
|
|
||||||
warp:
|
|
||||||
help:
|
|
||||||
description: "Teleportovat se na warp ceduli hráče"
|
|
||||||
parameters: <player name>
|
|
||||||
warps:
|
|
||||||
deactivate: "&c Stará warp cedule deaktivována!"
|
deactivate: "&c Stará warp cedule deaktivována!"
|
||||||
error:
|
error:
|
||||||
does-not-exist: "&c Sakra! Tento warp již neexistuje!"
|
does-not-exist: "&c Sakra! Tento warp již neexistuje!"
|
||||||
no-permission: "&c Na toto nemáš oprávnění!"
|
no-permission: "&c Na toto nemáš oprávnění!"
|
||||||
no-remove: "&c Nemůžeš odstranit tuto ceduli!"
|
no-remove: "&c Nemůžeš odstranit tuto ceduli!"
|
||||||
@ -19,17 +13,49 @@ warps:
|
|||||||
not-enough-level: "&c Úroveň tvého ostrova není dostatečně vysoká!"
|
not-enough-level: "&c Úroveň tvého ostrova není dostatečně vysoká!"
|
||||||
not-on-island: "&c K tomuto musíš být na svém ostrově!"
|
not-on-island: "&c K tomuto musíš být na svém ostrově!"
|
||||||
not-safe: "&c Tento warp není bezpečný!"
|
not-safe: "&c Tento warp není bezpečný!"
|
||||||
your-level-is: "&c Úroveň tvého ostrova je jen [level], musí být vyšší než [required]. Spusť příkaz pro úroveň."
|
your-level-is: "&c Úroveň tvého ostrova je jen [level], musí být vyšší než [required].
|
||||||
help:
|
Spusť příkaz pro úroveň."
|
||||||
description: "otevřít panel warpů"
|
not-correct-rank: "&c Nemáte správnou hodnost pro nastavení warpu!"
|
||||||
next: "&6 Další stránka"
|
help:
|
||||||
player-warped: "&2 [name] se teleportoval na tvou warp ceduli!"
|
description: otevřít panel warpů
|
||||||
previous: "&6 Předchozí stránka"
|
player-warped: "&2 [name] se pokřivilo na váš [gamemode] warp znamení!"
|
||||||
random: "&4 Náhodný warp"
|
|
||||||
sign-removed: "&c Warp cedule odstraněna!"
|
sign-removed: "&c Warp cedule odstraněna!"
|
||||||
success: "&a Úspěch!"
|
success: "&a Úspěch!"
|
||||||
title: "Warp cedule"
|
|
||||||
warpTip: "&6 Polož warp ceduli s [text] na vrchu"
|
warpTip: "&6 Polož warp ceduli s [text] na vrchu"
|
||||||
warpToPlayersSign: "&6 Teleportuji tě na ceduli [player]"
|
warpToPlayersSign: "&6 Teleportuji tě na ceduli [player]"
|
||||||
|
gui:
|
||||||
|
titles:
|
||||||
|
warp-title: "&0&l Warp Signs"
|
||||||
|
buttons:
|
||||||
|
previous:
|
||||||
|
name: "&f&l Předchozí stránka"
|
||||||
|
description: "&7 Přepnout na stránku [number]"
|
||||||
|
next:
|
||||||
|
name: "&f&l Další stránka"
|
||||||
|
description: "&7 Přepnout na stránku [number]"
|
||||||
|
warp:
|
||||||
|
name: "&f&l [name]"
|
||||||
|
description: "[sign_text]"
|
||||||
|
random:
|
||||||
|
name: "&f&l Náhodné pokřivení"
|
||||||
|
description: "&7 Hmm, kde se objevím?"
|
||||||
|
tips:
|
||||||
|
click-to-previous: "&e Klepnutím na &7 zobrazíte předchozí stránku."
|
||||||
|
click-to-next: "&e Klepnutím na &7 zobrazíte další stránku."
|
||||||
|
click-to-warp: "&e Klikněte na &7 pro deformaci."
|
||||||
|
conversations:
|
||||||
|
prefix: "&l&6 [BentoBox]: &r"
|
||||||
|
togglewarp:
|
||||||
|
help:
|
||||||
|
description: přepnout znak warp
|
||||||
|
enabled: "&a Vaše warp je nyní viditelný!"
|
||||||
|
disabled: "&c Váš warp je nyní skrytý!"
|
||||||
|
error:
|
||||||
|
no-permission: "&c K tomu nemáte oprávnění!"
|
||||||
|
generic: "&c Při přepínání vašeho warpu došlo k chybě."
|
||||||
|
no-warp: "&c Nemáte warp k přepínání!"
|
||||||
|
protection:
|
||||||
|
flags:
|
||||||
|
PLACE_WARP:
|
||||||
|
name: Umístěte Warp
|
||||||
|
description: Povolit umístění warp znamení
|
||||||
|
@ -1,30 +1,61 @@
|
|||||||
#
|
---
|
||||||
# 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."
|
||||||
|
not-correct-rank: "&c Sie haben nicht den richtigen Rang, um einen Warp einzustellen!"
|
||||||
help:
|
help:
|
||||||
description: Öffnet das Warps Panel
|
description: Öffnet das Warps Panel
|
||||||
next: '&6 Nächste Seite'
|
player-warped: "&2 [name] ist zu deinem [gamemode]-Warp-Zeichen gesprungen!"
|
||||||
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"
|
||||||
|
togglewarp:
|
||||||
|
help:
|
||||||
|
description: das Warp-Zeichen umschalten
|
||||||
|
enabled: "&a Ihr Warp ist jetzt sichtbar!"
|
||||||
|
disabled: "&c Ihr Warp ist jetzt verborgen!"
|
||||||
|
error:
|
||||||
|
no-permission: "&c Sie haben keine Berechtigung, das zu tun!"
|
||||||
|
generic: "&c Beim Umschalten Ihres Warps ist ein Fehler aufgetreten."
|
||||||
|
no-warp: "&c Sie haben keinen Warp zum Umschalten!"
|
||||||
|
protection:
|
||||||
|
flags:
|
||||||
|
PLACE_WARP:
|
||||||
|
name: Warp platzieren
|
||||||
|
description: Platzieren von Warp-Zeichen zulassen
|
||||||
|
@ -18,16 +18,60 @@ warps:
|
|||||||
not-on-island: "&c You must be on your island to do that!"
|
not-on-island: "&c You must be on your island to do that!"
|
||||||
not-safe: "&c That warp is not safe!"
|
not-safe: "&c That warp is not safe!"
|
||||||
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:
|
not-correct-rank: "&c You do not have the correct rank to set a warp!"
|
||||||
|
help:
|
||||||
description: "open the warps panel"
|
description: "open the warps panel"
|
||||||
next: "&6 Next page"
|
player-warped: "&2 [name] warped to your [gamemode] 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"
|
||||||
|
|
||||||
|
togglewarp:
|
||||||
|
help:
|
||||||
|
description: "toggle the warp sign"
|
||||||
|
enabled: "&a Your warp is now visible!"
|
||||||
|
disabled: "&c Your warp is now hidden!"
|
||||||
|
error:
|
||||||
|
no-permission: "&c You do not have permission to do that!"
|
||||||
|
generic: "&c An error occurred while toggling your warp."
|
||||||
|
no-warp: "&c You do not have a warp to toggle!"
|
||||||
|
|
||||||
|
protection:
|
||||||
|
flags:
|
||||||
|
PLACE_WARP:
|
||||||
|
name: Place Warp
|
||||||
|
description: Allow placing warp sign
|
||||||
|
@ -1,31 +1,53 @@
|
|||||||
###########################################################################################################
|
---
|
||||||
# Este es un archivo YML. Tenga cuidado al editar. Revisa tus ediciones en un verificador de YAML como #
|
warp:
|
||||||
# el de http://yaml-online-parser.appspot.com #
|
help:
|
||||||
###########################################################################################################
|
description: Teletransportarte hacia el warp del jugador
|
||||||
|
parameters: "<player name>"
|
||||||
warp:
|
warps:
|
||||||
help:
|
deactivate: "&c ¡Antiguo cartel de teletransportación desactivado!"
|
||||||
description: "Teletransportarte hacia el warp del jugador"
|
error:
|
||||||
parameters: <player name>
|
does-not-exist: "&c ¡Oh, chasquido! ¡Ese teletransporte ya no existe!"
|
||||||
warps:
|
no-permission: "&c ¡No tienes permisos para hacer eso!"
|
||||||
deactivate: "&c¡El cartel viejo ha sido desactivado!"
|
no-remove: "&c ¡No puedes quitar ese cartel!"
|
||||||
error:
|
no-warps-yet: "&c No hay teletransportes disponibles todavía"
|
||||||
does-not-exist: "&c¡Oh vaya! !Ese warp ya no existe!"
|
not-enough-level: "&c ¡Tu nivel de isla no es lo suficientemente alto!"
|
||||||
no-permission: "&c¡No tienes permiso para hacer eso!"
|
not-on-island: "&c ¡Debes estar en tu isla para hacer eso!"
|
||||||
no-remove: "&c¡No puedes quitar ese cartel!"
|
not-safe: "&c ¡Ese teletransporte no es seguro!"
|
||||||
no-warps-yet: "&cNo hay warps disponibles aún"
|
your-level-is: "&c Tu nivel de isla es solo [level] y debe ser mayor que [required].
|
||||||
not-enough-level: "&c¡Tu nivel de isla no es lo suficientemente alto!"
|
Ejecuta el comando de nivel."
|
||||||
not-on-island: "&c¡Debes estar en tu isla para hacer eso!"
|
not-correct-rank: "&c ¡No tienes el rango correcto para crear un teletransporte!"
|
||||||
not-safe: "&c¡Ese warp no es seguro!"
|
help:
|
||||||
your-level-is: "&cTu nivel de isla es solo [level] y debe ser mayor que [required]"
|
description: Abre el panel de warps
|
||||||
help:
|
player-warped: "&2 [name] se ha teletransportado a tu cartel de teletransportación
|
||||||
description: "Abre el panel de warps"
|
de [gamemode]!"
|
||||||
next: "&6Siguiente página"
|
sign-removed: "&c Cartel de teletransportación eliminado!"
|
||||||
player-warped: "&2[name] ¡se ha teletransportado a tu warp!"
|
success: "&a Éxito!"
|
||||||
previous: "&6Página anterior"
|
warpTip: "&6 Coloca un cartel con [text] en la parte superior"
|
||||||
random: "&4Teletransporte aleatorio"
|
warpToPlayersSign: "&6 Teletransportandote al cartel del jugador [player]"
|
||||||
sign-removed: "&c¡Cartel removido!"
|
gui:
|
||||||
success: "&a¡Éxito!"
|
titles:
|
||||||
title: "Carteles de Warps"
|
warp-title: "&0&l Carteles de Teletransporte"
|
||||||
warpTip: "&6Coloca un cartel que contenga el texto [text] arriba"
|
buttons:
|
||||||
warpToPlayersSign: "&6Teletransportandote al warp de [player]"
|
previous:
|
||||||
|
name: "&f&l Página Anterior"
|
||||||
|
description: "&7 Ir a la página [number]"
|
||||||
|
next:
|
||||||
|
name: "&f&l Siguiente Página"
|
||||||
|
description: "&7 Ir a la página [number]"
|
||||||
|
warp:
|
||||||
|
name: "&f&l [name]"
|
||||||
|
description: "[sign_text]"
|
||||||
|
random:
|
||||||
|
name: "&f&l Teletransporte aleatorio"
|
||||||
|
description: "&7 Hmm, ¿Dónde apareceré?"
|
||||||
|
tips:
|
||||||
|
click-to-previous: "&e Clic &7 para ver la página anterior."
|
||||||
|
click-to-next: "&e Clic &7 para ver la página siguiente."
|
||||||
|
click-to-warp: "&e Clic &7 para teletransportarse."
|
||||||
|
conversations:
|
||||||
|
prefix: "&l&6 [BentoBox]: &r"
|
||||||
|
protection:
|
||||||
|
flags:
|
||||||
|
PLACE_WARP:
|
||||||
|
name: Colocar Teletransporte
|
||||||
|
description: Permitir colocar un cartel de teletransporte
|
||||||
|
@ -4,25 +4,59 @@ warp:
|
|||||||
description: te téléporte au Warp d'un autre joueur
|
description: te téléporte au Warp d'un autre joueur
|
||||||
parameters: "<pseudo>"
|
parameters: "<pseudo>"
|
||||||
warps:
|
warps:
|
||||||
deactivate: "&cAncien panneau de Warp désactivé !"
|
deactivate: "&c Ancienne pancarte de warp désactivée !"
|
||||||
error:
|
error:
|
||||||
does-not-exist: "&cCe Warp n'existe plus !"
|
does-not-exist: "&c Oh ! Cette téléportation n'existe plus !"
|
||||||
no-permission: "&cVous n'avez pas la permission pour faire cela !"
|
no-permission: "&c Vous n'avez pas le droit de faire cela !"
|
||||||
no-remove: "&cVous ne pouvez pas supprimer ce panneau !"
|
no-remove: "&c Vous ne pouvez pas enlever cette pancarte !"
|
||||||
not-enough-level: "&cVotre niveau d'île n'est pas assez élevé pour faire cela
|
no-warps-yet: "&c Il n'y a pas encore de téléportation disponible"
|
||||||
!"
|
not-enough-level: "&c Le niveau de votre île n'est pas assez élevé !"
|
||||||
not-on-island: "&cVous devez être sur votre île pour faire cela !"
|
not-on-island: "&c Vous devez être sur votre île pour faire cela !"
|
||||||
not-safe: "&cCe Warp n'est pas sûr!"
|
not-safe: "&c Cette téléportation n'est pas sûre !"
|
||||||
no-warps-yet: "&cIl n'y a encore aucun Warp sur ce serveur."
|
your-level-is: "&c Le niveau de votre île n'est que [level] et doit être supérieur
|
||||||
your-level-is: "&cVotre île est seulement niveau [level] et doit être niveau [required]."
|
à [required]. Exécutez la commande level."
|
||||||
|
not-correct-rank: "&c Vous n'avez pas le grade adéquat pour poser une chaîne !"
|
||||||
help:
|
help:
|
||||||
description: Ouvre le menu des Warps
|
description: Ouvre le menu des Warps
|
||||||
next: "&6Page suivante"
|
player-warped: "&2 [name] s'est rendu à votre pancarte de téléportation [gamemode]
|
||||||
player-warped: "&2[name] s'est téléporté sur votre île !"
|
!"
|
||||||
previous: "&6Page précédente"
|
sign-removed: "&c Panneau de téléportation enlevé !"
|
||||||
sign-removed: "&cPanneau de Warp supprimé !"
|
success: "&a Succès !"
|
||||||
success: "&aSuccès !"
|
warpTip: "&6 Placer une pancarte de téléportation avec [text] sur le dessus"
|
||||||
title: Panneau Warp
|
warpToPlayersSign: "&6 Téléportation a la pancarte de [player]"
|
||||||
warpTip: "&6Placez un panneau et écrivez [text] sur la première ligne."
|
gui:
|
||||||
warpToPlayersSign: "&6Téléportation sur l'île de [player]..."
|
titles:
|
||||||
random: "&4Warp aléatoire"
|
warp-title: "&0&l Pancarte de téléportation"
|
||||||
|
buttons:
|
||||||
|
previous:
|
||||||
|
name: "&f&l Page précédente"
|
||||||
|
description: "&7 Aller à la page [numéro]."
|
||||||
|
next:
|
||||||
|
name: "&f&l Page suivante"
|
||||||
|
description: "&7 Passer à la page [numéro]."
|
||||||
|
warp:
|
||||||
|
name: "&f&l [name]"
|
||||||
|
description: "[sign_text]"
|
||||||
|
random:
|
||||||
|
name: "&f&l Téléportation aléatoire"
|
||||||
|
description: "&7 Hmm, où vais-je apparaître ?"
|
||||||
|
tips:
|
||||||
|
click-to-previous: "&e Cliquez sur &7 pour afficher la page précédente."
|
||||||
|
click-to-next: "&e Cliquez sur &7 pour afficher la page suivante."
|
||||||
|
click-to-warp: "&e Cliquez sur &7 pour te téléporter."
|
||||||
|
conversations:
|
||||||
|
prefix: "&l&6 [BentoBox]: &r"
|
||||||
|
togglewarp:
|
||||||
|
help:
|
||||||
|
description: basculer le signe de distorsion
|
||||||
|
enabled: "&a Votre chaîne est maintenant visible !"
|
||||||
|
disabled: "&c Votre chaîne est maintenant cachée !"
|
||||||
|
error:
|
||||||
|
no-permission: "&c Vous n'avez pas la permission de faire ça !"
|
||||||
|
generic: "&c Une erreur s'est produite lors du basculement de votre chaîne."
|
||||||
|
no-warp: "&c Vous n'avez pas de chaîne à activer !"
|
||||||
|
protection:
|
||||||
|
flags:
|
||||||
|
PLACE_WARP:
|
||||||
|
name: Place téléportation
|
||||||
|
description: Autoriser le placement d'un panneau téléportation
|
||||||
|
@ -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"
|
||||||
|
|
||||||
|
|
||||||
|
52
src/main/resources/locales/id.yml
Normal file
52
src/main/resources/locales/id.yml
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
---
|
||||||
|
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 Kamu tidak punya izin untuk melakukan itu!"
|
||||||
|
no-remove: "&c Kamu tidak bisa 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 Kamu harus berada di pulaumu untuk melakukan itu!"
|
||||||
|
not-safe: "&c Warp itu tidak aman!"
|
||||||
|
your-level-is: "&c Level pulau Anda hanya [level] dan harus lebih tinggi dari
|
||||||
|
[required]. Jalankan perintah level."
|
||||||
|
not-correct-rank: "&c Kamu tidak punya rank yang benar untuk mengatur warp!"
|
||||||
|
help:
|
||||||
|
description: buka panel warps
|
||||||
|
player-warped: "&2 [name] nge-warp ke tanda warp [gamemode] kamu!"
|
||||||
|
sign-removed: "&c Tanda warp dihilangkan!"
|
||||||
|
success: "&a Sukses!"
|
||||||
|
warpTip: "&6 Tempatkan tanda warp dengan [text] di atas\n"
|
||||||
|
warpToPlayersSign: "&6 Pergi ke tanda [player]"
|
||||||
|
gui:
|
||||||
|
titles:
|
||||||
|
warp-title: "&0&l Tanda Warp"
|
||||||
|
buttons:
|
||||||
|
previous:
|
||||||
|
name: "&f&l Halaman Sebelumnya"
|
||||||
|
description: "&7 Beralih ke halaman [number]"
|
||||||
|
next:
|
||||||
|
name: "&f&l Halaman Selanjutnya"
|
||||||
|
description: "&7 Beralih ke halaman [number]"
|
||||||
|
warp:
|
||||||
|
name: "&f&l [name]"
|
||||||
|
description: "[sign_text]"
|
||||||
|
random:
|
||||||
|
name: "&f&l Warp Acak"
|
||||||
|
description: "&7 Hmm, di mana aku akan muncul?"
|
||||||
|
tips:
|
||||||
|
click-to-previous: "&e Klik &7 untuk melihat halaman sebelumnya."
|
||||||
|
click-to-next: "&e Klik &7 untuk melihat halaman selanjutnya."
|
||||||
|
click-to-warp: "&e Klik &7 untuk warp."
|
||||||
|
conversations:
|
||||||
|
prefix: "&l&6 [BentoBox]: &r"
|
||||||
|
protection:
|
||||||
|
flags:
|
||||||
|
PLACE_WARP:
|
||||||
|
name: Tempatkan Warp
|
||||||
|
description: Izinkan menempatkan tanda warp
|
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]"
|
@ -1,32 +1,60 @@
|
|||||||
###########################################################################################
|
---
|
||||||
# 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: プレイヤーのワープサインにワープする
|
||||||
|
parameters: "<名>"
|
||||||
warp:
|
warps:
|
||||||
help:
|
deactivate: "&c 古いワープサインが無効になりました!"
|
||||||
description: "プレイヤーのワープサインにワープする"
|
error:
|
||||||
parameters: <名>
|
does-not-exist: "&c ああ、やられた!そのワープはもう存在しない!"
|
||||||
warps:
|
no-permission: "&c あなたにはそれを実行する権限がありません!"
|
||||||
deactivate: "&c前のワープサインが無効になりました!"
|
no-remove: "&c その標識は削除できません!"
|
||||||
error:
|
no-warps-yet: "&c ワープはまだ利用できません"
|
||||||
does-not-exist: "&cそのワープはもう存在しません!"
|
not-enough-level: "&c あなたの島のレベルは十分に高くありません!"
|
||||||
no-permission: "&C許可がありません!"
|
not-on-island: "&c それを実行するには、自分の島にいる必要があります。"
|
||||||
no-remove: "&Cワープサインは外せません!"
|
not-safe: "&c そのワープは安全ではありません!"
|
||||||
no-warps-yet: "&C利用可能なワープはまだありません"
|
your-level-is: "&c あなたの島のレベルは [level] のみで、[required] より高くなければなりません。level コマンドを実行してください。"
|
||||||
not-enough-level: "&C島のレベルは十分に高くありません!"
|
not-correct-rank: "&c ワープを設定するための適切なランクがありません。"
|
||||||
not-on-island: "&Cあなたの島にいなければなりません!"
|
help:
|
||||||
not-safe: "&cワープは安全ではありません。!"
|
description: ワープパネルを開く
|
||||||
your-level-is: "&c島レベルはわずか[level]で、[required]より高くなければなりません"
|
player-warped: "&2 [name] があなたの [gamemode] ワープサインにワープしました!"
|
||||||
help:
|
sign-removed: "&c ワープサインが削除されました!"
|
||||||
description: "ワープパネルを開く"
|
success: "&a 成功しました!"
|
||||||
next: "&6次のページ"
|
warpTip: "&6 [text]を上部に記したワープサインを配置する"
|
||||||
player-warped: "&2[name]はあなたのワープサインに反った!"
|
warpToPlayersSign: "&6 [player]のサインにワープ"
|
||||||
previous: "&6前のページ"
|
gui:
|
||||||
sign-removed: "&Cワープサインを削除!"
|
titles:
|
||||||
success: "&A完了!"
|
warp-title: "&0&l ワープサイン"
|
||||||
title: "ワープサイン"
|
buttons:
|
||||||
warpTip: "&6最初の行に[text]と一緒にワープサインを置きます"
|
previous:
|
||||||
warpToPlayersSign: "&6[player]のサインに反っている"
|
name: "&f&l 前のページ"
|
||||||
|
description: "&7 [number] ページに切り替える"
|
||||||
|
next:
|
||||||
|
name: "&f&l 次のページ"
|
||||||
|
description: "&7 [number]ページに切り替える"
|
||||||
|
warp:
|
||||||
|
name: "&f&l [name]"
|
||||||
|
description: "[sign_text]"
|
||||||
|
random:
|
||||||
|
name: "&f&l ランダムワープ"
|
||||||
|
description: "&7 うーん、どこに現れるんだろう?"
|
||||||
|
tips:
|
||||||
|
click-to-previous: "&e 前のページを表示するには &7 をクリックします。"
|
||||||
|
click-to-next: "&e 次のページを表示するには &7 をクリックします。"
|
||||||
|
click-to-warp: "&e ワープするには &7 をクリックします。"
|
||||||
|
conversations:
|
||||||
|
prefix: "&l&6 [弁当箱]: &r"
|
||||||
|
togglewarp:
|
||||||
|
help:
|
||||||
|
description: ワープサインを切り替える
|
||||||
|
enabled: "&a ワープが見えるようになりました!"
|
||||||
|
disabled: "&c ワープが非表示になりました!"
|
||||||
|
error:
|
||||||
|
no-permission: "&c あなたにはそれを実行する権限がありません!"
|
||||||
|
generic: "&c ワープの切り替え中にエラーが発生しました。"
|
||||||
|
no-warp: "&c 切り替えるワープがありません!"
|
||||||
|
protection:
|
||||||
|
flags:
|
||||||
|
PLACE_WARP:
|
||||||
|
name: ワープを配置
|
||||||
|
description: ワープサインの設置を許可する
|
||||||
|
52
src/main/resources/locales/nl.yml
Normal file
52
src/main/resources/locales/nl.yml
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
---
|
||||||
|
warp:
|
||||||
|
help:
|
||||||
|
description: teleporteer naar een speler zijn warp bord
|
||||||
|
parameters: "<speler>"
|
||||||
|
warps:
|
||||||
|
deactivate: "&c Oude warp bord is gedeactiveerd!"
|
||||||
|
error:
|
||||||
|
does-not-exist: "&c Oh nee! Deze warp bestaat niet meer!"
|
||||||
|
no-permission: "&c Je hebt geen permissies om dit te doen!"
|
||||||
|
no-remove: "&c Je kan dit bord niet weghalen!"
|
||||||
|
no-warps-yet: "&c Er bestaan nog geen warps op dit moment"
|
||||||
|
not-enough-level: "&c Je eiland level is nog niet hoog genoeg!"
|
||||||
|
not-on-island: "&c Je moet een eiland hebben om dit te doen!"
|
||||||
|
not-safe: "&c Deze warp is niet veilig!"
|
||||||
|
your-level-is: "&c Je eiland level is [level], maar het moet op zijn minst [required]
|
||||||
|
zijn. Gebruik het level commando."
|
||||||
|
not-correct-rank: "&c Je hebt niet de correcte rank om een warp te maken!"
|
||||||
|
help:
|
||||||
|
description: open het warp paneel
|
||||||
|
player-warped: "&2 [name] teleporteerde naar jou [gamemode] warp!"
|
||||||
|
sign-removed: "&c Warp bord verwijderd!"
|
||||||
|
success: "&a Geslaagd!"
|
||||||
|
warpTip: "&6 Plaats een warp bord met [text] op de eerste regel"
|
||||||
|
warpToPlayersSign: "&6 Teleporteren naar [player]'s warp"
|
||||||
|
gui:
|
||||||
|
titles:
|
||||||
|
warp-title: "&0&l Warp Borden"
|
||||||
|
buttons:
|
||||||
|
previous:
|
||||||
|
name: "&f&l Vorige pagina"
|
||||||
|
description: "&7 Ga naar pagina [number]"
|
||||||
|
next:
|
||||||
|
name: "&f&l Volgende pagina"
|
||||||
|
description: "&7 Ga naar pagina [number]"
|
||||||
|
warp:
|
||||||
|
name: "&f&l [name]"
|
||||||
|
description: "[sign_text]"
|
||||||
|
random:
|
||||||
|
name: "&f&l Willekeurige Warp"
|
||||||
|
description: "&7 Hmm, waar ga ik heen?"
|
||||||
|
tips:
|
||||||
|
click-to-previous: "&e Klik &7 om naar de vorige pagina te gaan."
|
||||||
|
click-to-next: "&e Klik &7 om naar de volgende pagina te gaan."
|
||||||
|
click-to-warp: "&e Klik &7 om te teleporteren."
|
||||||
|
conversations:
|
||||||
|
prefix: "&l&6 [BentoBox]: &r"
|
||||||
|
protection:
|
||||||
|
flags:
|
||||||
|
PLACE_WARP:
|
||||||
|
name: Plaats warp
|
||||||
|
description: Staat het toe om een warp bord te plaatsen
|
@ -1,27 +1,46 @@
|
|||||||
|
---
|
||||||
warp:
|
warp:
|
||||||
help:
|
help:
|
||||||
description: teleportuje cię do tabliczki innego gracza
|
description: teleportuje cię do tabliczki innego gracza
|
||||||
parameters: <gracz>
|
parameters: "<gracz>"
|
||||||
warps:
|
warps:
|
||||||
deactivate: '&c Stary teleport zdezaktywowany!'
|
deactivate: "&c Stary teleport został zdezaktywowany!"
|
||||||
error:
|
error:
|
||||||
does-not-exist: '&c Ten teleport nie istnieje.'
|
does-not-exist: "&c Ten teleport nie istnieje."
|
||||||
no-permission: '&c Brak uprawnień!'
|
no-permission: "&c Brak uprawnień!"
|
||||||
no-remove: '&c Nie możesz usunąć tej tabliczki!'
|
no-remove: "&c Nie możesz usunąć tej tabliczki!"
|
||||||
no-warps-yet: '&c Nie ma jeszcze teleportów.'
|
no-warps-yet: "&c Nie ma jeszcze stworzonych teleportów."
|
||||||
not-enough-level: '&c Twój poziom wyspy nie jest wystarczająco wysoki!'
|
not-enough-level: "&c Twój poziom wyspy nie jest wystarczająco wysoki!"
|
||||||
not-on-island: '&c Musisz być na wyspie, by to zrobić.'
|
not-on-island: "&c Musisz być na wyspie, by to zrobić."
|
||||||
not-safe: '&c Ten teleport nie jest bezpieczny!'
|
not-safe: "&c Ten teleport nie jest bezpieczny!"
|
||||||
your-level-is: '&c Twój poziom wyspy to [level], a musi wynosić co namniej [required].
|
your-level-is: "&c Twój poziom wyspy to [level], a musi wynosić co najmniej [required].
|
||||||
Użyj komendy /is level.'
|
Użyj komendy /is level."
|
||||||
help:
|
help:
|
||||||
description: otwiera panel warpów
|
description: otwiera panel warpów
|
||||||
next: '&6 Następna strona'
|
player-warped: "&2 [name] teleportował się do twojej tabliczki!"
|
||||||
player-warped: '&2 [name] teleportował się do twojej tabliczki!'
|
sign-removed: "&c Usunięto tabliczkę!"
|
||||||
previous: '&6 Poprzednia strona'
|
success: "&a Sukces!"
|
||||||
random: '&4 Losowy teleport'
|
warpTip: "&6 Postaw tabliczkę z napisem [text]"
|
||||||
sign-removed: '&c Usunięto tabliczkę!'
|
warpToPlayersSign: "&6 Teleportowanie do tabliczki gracza [player]"
|
||||||
success: '&a Sukces!'
|
gui:
|
||||||
title: Tabliczki teleportacyjne
|
titles:
|
||||||
warpTip: '&6 Postaw tabliczkę z napisem [text]'
|
warp-title: "&0&l Lista dostępnych wysp"
|
||||||
warpToPlayersSign: '&6 Teleportowanie do tabliczki gracza [player]'
|
buttons:
|
||||||
|
previous:
|
||||||
|
name: "&f&l Poprzednia strona"
|
||||||
|
description: "&7 Przełącz na stronę [number]"
|
||||||
|
next:
|
||||||
|
name: "&f&l następna strona"
|
||||||
|
description: "&7 Przełącz na stronę [number]"
|
||||||
|
warp:
|
||||||
|
name: "&f&l [name]"
|
||||||
|
description: "[sign_text]"
|
||||||
|
random:
|
||||||
|
name: "&f&l Losowa wyspa"
|
||||||
|
description: "&7 Hmm, gdzie się pojawię?"
|
||||||
|
tips:
|
||||||
|
click-to-previous: "&e Kliknij &7, aby wyświetlić poprzednią stronę."
|
||||||
|
click-to-next: "&e Kliknij &7, aby wyświetlić następną stronę."
|
||||||
|
click-to-warp: "&e Kliknij &7, aby przenieść."
|
||||||
|
conversations:
|
||||||
|
prefix: "&l&6 [BentoBox]: &r"
|
||||||
|
@ -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!"
|
|
||||||
|
52
src/main/resources/locales/uk.yml
Normal file
52
src/main/resources/locales/uk.yml
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
---
|
||||||
|
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]. Виконайте команду рівня."
|
||||||
|
not-correct-rank: "&c Ви не маєте належного рангу, щоб встановити варп!"
|
||||||
|
help:
|
||||||
|
description: відкрити панель варпів
|
||||||
|
player-warped: "&2 [name] телепортовано до вашого знака варпу [gamemode]!"
|
||||||
|
sign-removed: "&c Знак варпу видалено!"
|
||||||
|
success: "&a Успіх!"
|
||||||
|
warpTip: "&6 Розмістіть знак варпу з [text] угорі"
|
||||||
|
warpToPlayersSign: "&6 Телепортація на знак [player]."
|
||||||
|
gui:
|
||||||
|
titles:
|
||||||
|
warp-title: "&0&l Знаки варпів"
|
||||||
|
buttons:
|
||||||
|
previous:
|
||||||
|
name: "&f&l Попередня сторінка"
|
||||||
|
description: "&7 Перейти на сторінку [number]."
|
||||||
|
next:
|
||||||
|
name: "&f&l Наступна сторінка"
|
||||||
|
description: "&7 Перейти на сторінку [number]."
|
||||||
|
warp:
|
||||||
|
name: "&f&l [name]"
|
||||||
|
description: "[sign_text]"
|
||||||
|
random:
|
||||||
|
name: "&f&l Випадковий варп"
|
||||||
|
description: "&7 Хм, а де я з'явлюся?"
|
||||||
|
tips:
|
||||||
|
click-to-previous: "&e Натисніть &7, щоб переглянути попередню сторінку."
|
||||||
|
click-to-next: "&e Натисніть &7, щоб переглянути наступну сторінку."
|
||||||
|
click-to-warp: "&e Натисніть &7, щоб деформувати."
|
||||||
|
conversations:
|
||||||
|
prefix: "&l&6 [BentoBox]: &r"
|
||||||
|
protection:
|
||||||
|
flags:
|
||||||
|
PLACE_WARP:
|
||||||
|
name: Розмістіть варп
|
||||||
|
description: Дозволити розміщення варпів
|
@ -1,27 +1,60 @@
|
|||||||
---
|
---
|
||||||
warp:
|
warp:
|
||||||
help:
|
help:
|
||||||
description: 传送到该玩家的传送木牌处
|
description: 传送至对应玩家的坐标告示牌
|
||||||
parameters: "<player name>"
|
parameters: "<player name>"
|
||||||
warps:
|
warps:
|
||||||
help:
|
deactivate: "&c检测到不活跃的坐标告示牌!"
|
||||||
description: 打开传送面板
|
|
||||||
title: 传送木牌
|
|
||||||
deactivate: "&c 旧传送牌已停用!"
|
|
||||||
error:
|
error:
|
||||||
does-not-exist: "&c 哦不!那个传送点已经没了!"
|
does-not-exist: "&c啊哦! 那个传送点已经不存在了!"
|
||||||
no-permission: "&c 你无权那样做!"
|
no-permission: "&c你没有权限做这件事!"
|
||||||
no-remove: "&c 你拿不掉那个牌子的!"
|
no-remove: "&c你不能移除该告示牌!"
|
||||||
no-warps-yet: "&c 暂无可用传送点"
|
no-warps-yet: "&c尚无可用传送点."
|
||||||
not-enough-level: "&c 你的岛等级不够高!"
|
not-enough-level: "&c你空岛的等级还不够高!"
|
||||||
not-on-island: "&c 你得在自己的岛屿上操作!"
|
not-on-island: "&c你必须在自己的空岛上做这件事!"
|
||||||
not-safe: "&c 目标传送点不安全!"
|
not-safe: "&c该传送点不安全!"
|
||||||
your-level-is: "&c 你的岛现在 [level] 级,需要 [required] 级。 试试岛屿等级命令吧。"
|
your-level-is: "&c你空岛的等级只有[level], 但必须高于[required]. 使用/is level查看等级."
|
||||||
next: "&6 次页"
|
not-correct-rank: "&c你在团队中的地位不足以让你设立传送点!"
|
||||||
player-warped: "&2 [name] 传送到了你的传送牌!"
|
help:
|
||||||
previous: "&6 前页"
|
description: 打开传送点面板
|
||||||
random: "&4 随机传送"
|
player-warped: "&2 [name]传送到了你[gamemode]的坐标告示牌!"
|
||||||
sign-removed: "&c 拆掉传送牌了!"
|
sign-removed: "&c坐标告示牌已移除!"
|
||||||
success: "&a 成了!"
|
success: "&a成功!"
|
||||||
warpTip: "&6 放个牌子第一行写 [text]"
|
warpTip: "&6放置一个顶部为[text]的坐标告示牌"
|
||||||
warpToPlayersSign: "&6 正传送到 [player] 的牌子"
|
warpToPlayersSign: "&6正在传送至[player]的坐标告示牌"
|
||||||
|
gui:
|
||||||
|
titles:
|
||||||
|
warp-title: "&0&l坐标告示牌"
|
||||||
|
buttons:
|
||||||
|
previous:
|
||||||
|
name: "&f&l上一页"
|
||||||
|
description: "&7跳转到第[number]页"
|
||||||
|
next:
|
||||||
|
name: "&f&l下一页"
|
||||||
|
description: "&7跳转到第[number]页"
|
||||||
|
warp:
|
||||||
|
name: "&f&l [name]"
|
||||||
|
description: "[sign_text]"
|
||||||
|
random:
|
||||||
|
name: "&f&l随机传送"
|
||||||
|
description: "&7嗯...我会出现在哪里?"
|
||||||
|
tips:
|
||||||
|
click-to-previous: "&e点击&7 查看上一页."
|
||||||
|
click-to-next: "&e点击&7 查看下一页."
|
||||||
|
click-to-warp: "&e点击&7 进行传送."
|
||||||
|
conversations:
|
||||||
|
prefix: "&l&6 [BentoBox]: &r"
|
||||||
|
togglewarp:
|
||||||
|
help:
|
||||||
|
description: 切换扭曲符号
|
||||||
|
enabled: "&a 你的扭曲现在可见了!"
|
||||||
|
disabled: "&c 你的扭曲现已隐藏!"
|
||||||
|
error:
|
||||||
|
no-permission: "&c您没有权限这么做!"
|
||||||
|
generic: "&c 切换扭曲时发生错误。"
|
||||||
|
no-warp: "&c 您没有可切换的扭曲!"
|
||||||
|
protection:
|
||||||
|
flags:
|
||||||
|
PLACE_WARP:
|
||||||
|
name: 放置传送点
|
||||||
|
description: 允许放置坐标告示牌
|
||||||
|
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{CustomPotionColor:11546150}
|
||||||
|
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{CustomPotionColor:8439583}
|
||||||
|
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 +1,9 @@
|
|||||||
name: Pladdon
|
name: BentoBox-Warps
|
||||||
main: world.bentobox.warps.WarpsPladdon
|
main: world.bentobox.warps.WarpsPladdon
|
||||||
version: ${version}
|
version: ${project.version}${build.number}
|
||||||
api-version: 1.16
|
api-version: "1.17"
|
||||||
description: A Warp Pladdon for BentoBox
|
|
||||||
author: tastybento
|
authors: [tastybento]
|
||||||
depend:
|
contributors: ["The BentoBoxWorld Community"]
|
||||||
- BentoBox
|
website: https://bentobox.world
|
||||||
|
description: ${project.description}
|
||||||
|
@ -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));
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,7 +8,9 @@ import static org.mockito.ArgumentMatchers.any;
|
|||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@ -21,11 +23,11 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -40,6 +42,7 @@ import org.junit.Before;
|
|||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
@ -60,15 +63,20 @@ import world.bentobox.bentobox.managers.PlaceholdersManager;
|
|||||||
import world.bentobox.bentobox.managers.PlayersManager;
|
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.WarpCreateEvent;
|
||||||
import world.bentobox.warps.event.WarpInitiateEvent;
|
import world.bentobox.warps.event.WarpInitiateEvent;
|
||||||
|
import world.bentobox.warps.managers.SignCacheManager;
|
||||||
|
import world.bentobox.warps.managers.WarpSignsManager;
|
||||||
|
import world.bentobox.warps.objects.PlayerWarp;
|
||||||
import world.bentobox.warps.objects.WarpsData;
|
import world.bentobox.warps.objects.WarpsData;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({Bukkit.class, Util.class, DatabaseSetup.class, ChatColor.class})
|
@PrepareForTest({Bukkit.class, Util.class, DatabaseSetup.class})
|
||||||
public class WarpSignsManagerTest {
|
public class WarpSignsManagerTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
@ -98,7 +106,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
|
||||||
@ -136,12 +144,15 @@ public class WarpSignsManagerTest {
|
|||||||
|
|
||||||
// Player
|
// Player
|
||||||
when(player.getUniqueId()).thenReturn(uuid);
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
|
when(player.isOnline()).thenReturn(true);
|
||||||
|
when(player.canSee(any(Player.class))).thenReturn(true);
|
||||||
User.setPlugin(plugin);
|
User.setPlugin(plugin);
|
||||||
User.getInstance(player);
|
User.getInstance(player);
|
||||||
|
|
||||||
// Locales
|
// Locales
|
||||||
LocalesManager lm = mock(LocalesManager.class);
|
LocalesManager lm = mock(LocalesManager.class);
|
||||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn(null);
|
when(lm.getAvailablePrefixes(any())).thenReturn(Collections.emptySet());
|
||||||
|
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
// Return the same string
|
// Return the same string
|
||||||
PlaceholdersManager phm = mock(PlaceholdersManager.class);
|
PlaceholdersManager phm = mock(PlaceholdersManager.class);
|
||||||
@ -185,7 +196,7 @@ public class WarpSignsManagerTest {
|
|||||||
|
|
||||||
// Handler
|
// Handler
|
||||||
when(handler.objectExists("warps")).thenReturn(true);
|
when(handler.objectExists("warps")).thenReturn(true);
|
||||||
Map<Location, UUID> warpMap = Collections.singletonMap(location, uuid);
|
Map<PlayerWarp, UUID> warpMap = Collections.singletonMap(new PlayerWarp(location, true), uuid);
|
||||||
when(load.getWarpSigns()).thenReturn(warpMap);
|
when(load.getWarpSigns()).thenReturn(warpMap);
|
||||||
when(handler.loadObject(anyString())).thenReturn(load);
|
when(handler.loadObject(anyString())).thenReturn(load);
|
||||||
|
|
||||||
@ -193,12 +204,14 @@ 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);
|
||||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
|
// Tags
|
||||||
|
when(Tag.STANDING_SIGNS.isTagged(Material.ACACIA_SIGN)).thenReturn(true);
|
||||||
|
|
||||||
// Players Manager
|
// Players Manager
|
||||||
when(plugin.getPlayers()).thenReturn(pm);
|
when(plugin.getPlayers()).thenReturn(pm);
|
||||||
when(pm.getName(uuid)).thenReturn("tastybento");
|
when(pm.getName(uuid)).thenReturn("tastybento");
|
||||||
@ -210,6 +223,7 @@ public class WarpSignsManagerTest {
|
|||||||
// IWM
|
// IWM
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
when(iwm.getPermissionPrefix(any())).thenReturn("bskyblock.");
|
when(iwm.getPermissionPrefix(any())).thenReturn("bskyblock.");
|
||||||
|
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||||
|
|
||||||
// Island Manager
|
// Island Manager
|
||||||
when(addon.getIslands()).thenReturn(im);
|
when(addon.getIslands()).thenReturn(im);
|
||||||
@ -217,7 +231,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 +244,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 +252,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 +262,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,18 +272,19 @@ 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() {
|
||||||
Map<Location, UUID> warpMap = Collections.singletonMap(null, uuid);
|
PlayerWarp playerWarp = new PlayerWarp(null, true);
|
||||||
|
Map<PlayerWarp, UUID> warpMap = Collections.singletonMap(playerWarp, uuid);
|
||||||
when(load.getWarpSigns()).thenReturn(warpMap);
|
when(load.getWarpSigns()).thenReturn(warpMap);
|
||||||
wsm = new WarpSignsManager(addon, plugin);
|
wsm = new WarpSignsManager(addon, plugin);
|
||||||
assertTrue("Map is not empty", wsm.getWarpMap(world).isEmpty());
|
assertTrue("Map is not empty", wsm.getWarpMap(world).isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 +295,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 +305,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 +315,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 +323,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 +331,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 +340,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,33 +349,33 @@ 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() {
|
||||||
Location loc = mock(Location.class);
|
Location loc = mock(Location.class);
|
||||||
assertTrue(wsm.addWarp(uuid, loc));
|
assertTrue(wsm.addWarp(uuid, loc));
|
||||||
verify(pim).callEvent(any(WarpInitiateEvent.class));
|
verify(pim).callEvent(any(WarpCreateEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#getWarp(org.bukkit.World, java.util.UUID)}.
|
* Test method for {@link WarpSignsManager#getWarpLocation(org.bukkit.World, java.util.UUID)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetWarpWorldWorld() {
|
public void testGetWarpWorldWorld() {
|
||||||
assertNull(wsm.getWarp(mock(World.class), uuid));
|
assertNull(wsm.getWarpLocation(mock(World.class), uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.warps.WarpSignsManager#getWarp(org.bukkit.World, java.util.UUID)}.
|
* Test method for {@link WarpSignsManager#getWarpLocation(org.bukkit.World, java.util.UUID)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetWarp() {
|
public void testGetWarp() {
|
||||||
assertEquals(location, wsm.getWarp(world, uuid));
|
assertEquals(location, wsm.getWarpLocation(world, uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 +383,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 +392,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 +401,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 +410,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 +419,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 +429,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() {
|
||||||
@ -432,16 +438,51 @@ public class WarpSignsManagerTest {
|
|||||||
when(p.getWorld()).thenReturn(world);
|
when(p.getWorld()).thenReturn(world);
|
||||||
when(p.getName()).thenReturn("tastybento");
|
when(p.getName()).thenReturn("tastybento");
|
||||||
when(p.getLocation()).thenReturn(location);
|
when(p.getLocation()).thenReturn(location);
|
||||||
|
when(p.isOnline()).thenReturn(true);
|
||||||
|
when(p.canSee(any(Player.class))).thenReturn(true);
|
||||||
@Nullable
|
@Nullable
|
||||||
User u = User.getInstance(p);
|
User u = User.getInstance(p);
|
||||||
|
PowerMockito.when(Util.teleportAsync(any(), any(), any())).thenReturn(CompletableFuture.completedFuture(true));
|
||||||
wsm.warpPlayer(world, u, uuid);
|
wsm.warpPlayer(world, u, uuid);
|
||||||
PowerMockito.verifyStatic(Util.class);
|
PowerMockito.verifyStatic(Util.class);
|
||||||
Util.teleportAsync(eq(p), any(), eq(TeleportCause.COMMAND));
|
Util.teleportAsync(eq(p), any(), eq(TeleportCause.COMMAND));
|
||||||
verify(player).sendMessage("warps.player-warped");
|
verify(player).sendMessage(anyString());
|
||||||
|
verify(pim).callEvent(any(WarpInitiateEvent.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link WarpSignsManager#warpPlayer(org.bukkit.World, world.bentobox.bentobox.api.user.User, java.util.UUID)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testWarpPlayerEventCancelled() {
|
||||||
|
// Capture the event passed to callEvent
|
||||||
|
ArgumentCaptor<WarpInitiateEvent> eventCaptor = ArgumentCaptor.forClass(WarpInitiateEvent.class);
|
||||||
|
|
||||||
|
// Simulate the event being called and cancelled
|
||||||
|
doAnswer(invocation -> {
|
||||||
|
WarpInitiateEvent event = (WarpInitiateEvent) invocation.getArgument(0);
|
||||||
|
event.setCancelled(true);
|
||||||
|
return null;
|
||||||
|
}).when(pim).callEvent(eventCaptor.capture());
|
||||||
|
|
||||||
|
Player p = mock(Player.class);
|
||||||
|
when(p.getUniqueId()).thenReturn(UUID.randomUUID());
|
||||||
|
when(p.getWorld()).thenReturn(world);
|
||||||
|
when(p.getName()).thenReturn("tastybento");
|
||||||
|
when(p.getLocation()).thenReturn(location);
|
||||||
|
when(p.isOnline()).thenReturn(true);
|
||||||
|
when(p.canSee(any(Player.class))).thenReturn(true);
|
||||||
|
@Nullable
|
||||||
|
User u = User.getInstance(p);
|
||||||
|
PowerMockito.when(Util.teleportAsync(any(), any(), any())).thenReturn(CompletableFuture.completedFuture(true));
|
||||||
|
wsm.warpPlayer(world, u, uuid);
|
||||||
|
PowerMockito.verifyStatic(Util.class, never());
|
||||||
|
Util.teleportAsync(eq(p), any(), eq(TeleportCause.COMMAND));
|
||||||
|
verify(player, never()).sendMessage(anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 +492,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 +507,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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +123,7 @@ public class WarpsCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testSetupWarpCompositeCommand() {
|
public void testSetupWarpCompositeCommand() {
|
||||||
warpCommandWarpsCompositeCommand();
|
warpCommandWarpsCompositeCommand();
|
||||||
assertEquals("bskyblock.island.warp", wc.getPermission());
|
assertEquals("bskyblock.island.warps", wc.getPermission());
|
||||||
assertTrue(wc.isOnlyPlayer());
|
assertTrue(wc.isOnlyPlayer());
|
||||||
assertEquals("warps.help.description", wc.getDescription());
|
assertEquals("warps.help.description", wc.getDescription());
|
||||||
}
|
}
|
||||||
@ -131,7 +134,7 @@ public class WarpsCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testSetupWarp() {
|
public void testSetupWarp() {
|
||||||
warpCommandWarps();
|
warpCommandWarps();
|
||||||
assertEquals(Warp.WELCOME_WARP_SIGNS + ".warp", wc.getPermission());
|
assertEquals(Warp.WELCOME_WARP_SIGNS + ".warps", wc.getPermission());
|
||||||
assertTrue(wc.isOnlyPlayer());
|
assertTrue(wc.isOnlyPlayer());
|
||||||
assertEquals("warps.help.description", wc.getDescription());
|
assertEquals("warps.help.description", wc.getDescription());
|
||||||
}
|
}
|
||||||
@ -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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,7 @@ import static org.junit.Assert.assertTrue;
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -44,14 +41,18 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
|||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
import world.bentobox.bentobox.api.events.flags.FlagProtectionChangeEvent;
|
||||||
|
import world.bentobox.bentobox.api.flags.Flag;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.IslandsManager;
|
import world.bentobox.bentobox.managers.IslandsManager;
|
||||||
import world.bentobox.bentobox.managers.LocalesManager;
|
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.objects.PlayerWarp;
|
||||||
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,6 +84,8 @@ public class WarpSignsListenerTest {
|
|||||||
private IslandsManager im;
|
private IslandsManager im;
|
||||||
@Mock
|
@Mock
|
||||||
private IslandWorldManager iwm;
|
private IslandWorldManager iwm;
|
||||||
|
@Mock
|
||||||
|
private Island island;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@ -121,16 +124,16 @@ public class WarpSignsListenerTest {
|
|||||||
when(block.getState()).thenReturn(s);
|
when(block.getState()).thenReturn(s);
|
||||||
// warp signs manager
|
// warp signs manager
|
||||||
when(addon.getWarpSignsManager()).thenReturn(wsm);
|
when(addon.getWarpSignsManager()).thenReturn(wsm);
|
||||||
Map<UUID, Location> list = new HashMap<>();
|
Map<UUID, PlayerWarp> list = new HashMap<>();
|
||||||
Location location = mock(Location.class);
|
Location location = mock(Location.class);
|
||||||
when(location.getBlock()).thenReturn(block);
|
when(location.getBlock()).thenReturn(block);
|
||||||
when(s.getLocation()).thenReturn(location);
|
when(s.getLocation()).thenReturn(location);
|
||||||
when(block.getLocation()).thenReturn(location);
|
when(block.getLocation()).thenReturn(location);
|
||||||
list.put(uuid, location);
|
list.put(uuid, new PlayerWarp(location, true));
|
||||||
// Player is in world
|
// Player is in world
|
||||||
when(wsm.getWarpMap(world)).thenReturn(list);
|
when(wsm.getWarpMap(world)).thenReturn(list);
|
||||||
//Player has a warp sign already here
|
//Player has a warp sign already here
|
||||||
when(wsm.getWarp(any(), any())).thenReturn(location);
|
when(wsm.getWarpLocation(any(), any())).thenReturn(location);
|
||||||
// Unique spot
|
// Unique spot
|
||||||
when(wsm.addWarp(any(), any())).thenReturn(true);
|
when(wsm.addWarp(any(), any())).thenReturn(true);
|
||||||
// Bentobox
|
// Bentobox
|
||||||
@ -148,6 +151,9 @@ public class WarpSignsListenerTest {
|
|||||||
when(settings.getWelcomeLine()).thenReturn("[WELCOME]");
|
when(settings.getWelcomeLine()).thenReturn("[WELCOME]");
|
||||||
when(addon.getSettings()).thenReturn(settings);
|
when(addon.getSettings()).thenReturn(settings);
|
||||||
|
|
||||||
|
island = mock(Island.class);
|
||||||
|
when(im.getIslandAt(any())).thenReturn(Optional.of(island));
|
||||||
|
|
||||||
// On island
|
// On island
|
||||||
when(plugin.getIslands()).thenReturn(im);
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
when(im.userIsOnIsland(any(World.class), any(User.class))).thenReturn(true);
|
when(im.userIsOnIsland(any(World.class), any(User.class))).thenReturn(true);
|
||||||
@ -299,6 +305,54 @@ public class WarpSignsListenerTest {
|
|||||||
assertEquals(ChatColor.GREEN + "[WELCOME]", e.getLine(0));
|
assertEquals(ChatColor.GREEN + "[WELCOME]", e.getLine(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnCreateWithoutCorrectRankNotAllowed() {
|
||||||
|
WarpSignsListener wsl = new WarpSignsListener(addon);
|
||||||
|
SignChangeEvent e = new SignChangeEvent(block, player, lines);
|
||||||
|
when(player.hasPermission(anyString())).thenReturn(true);
|
||||||
|
when(addon.inRegisteredWorld(any())).thenReturn(true);
|
||||||
|
when(island.getRank(player.getUniqueId())).thenReturn(0);
|
||||||
|
when(island.getFlag(any())).thenReturn(1000);
|
||||||
|
wsl.onSignWarpCreate(e);
|
||||||
|
verify(player).sendMessage("warps.error.not-correct-rank");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnFlagChangeWhenSettingIsOffNothingHappens() {
|
||||||
|
Flag flag = mock(Flag.class);
|
||||||
|
|
||||||
|
when(addon.getCreateWarpFlag()).thenReturn(flag);
|
||||||
|
when(settings.getRemoveExistingWarpsWhenFlagChanges()).thenReturn(false);
|
||||||
|
WarpSignsListener wsl = new WarpSignsListener(addon);
|
||||||
|
|
||||||
|
FlagProtectionChangeEvent e = new FlagProtectionChangeEvent(island, player.getUniqueId(), flag, 1000);
|
||||||
|
|
||||||
|
wsl.onFlagChange(e);
|
||||||
|
|
||||||
|
verifyNoInteractions(island);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnFlagChangeWhenSettingIsOnWarpGetsRemoved() {
|
||||||
|
Flag flag = mock(Flag.class);
|
||||||
|
|
||||||
|
when(addon.getCreateWarpFlag()).thenReturn(flag);
|
||||||
|
when(settings.getRemoveExistingWarpsWhenFlagChanges()).thenReturn(true);
|
||||||
|
WarpSignsListener wsl = new WarpSignsListener(addon);
|
||||||
|
|
||||||
|
Map<UUID, PlayerWarp> warps = Map.of(
|
||||||
|
player.getUniqueId(), new PlayerWarp(block.getLocation(), true)
|
||||||
|
);
|
||||||
|
|
||||||
|
when(wsm.getWarpMap(any())).thenReturn(warps);
|
||||||
|
when(island.inIslandSpace(any(Location.class))).thenReturn(true);
|
||||||
|
|
||||||
|
FlagProtectionChangeEvent e = new FlagProtectionChangeEvent(island, player.getUniqueId(), flag, 1000);
|
||||||
|
|
||||||
|
wsl.onFlagChange(e);
|
||||||
|
verify(addon.getWarpSignsManager()).removeWarp(any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnCreateNotGameWorldNotAllowed() {
|
public void testOnCreateNotGameWorldNotAllowed() {
|
||||||
when(settings.isAllowInOtherWorlds()).thenReturn(false);
|
when(settings.isAllowInOtherWorlds()).thenReturn(false);
|
||||||
@ -367,7 +421,7 @@ public class WarpSignsListenerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateNoSignAlreadyUniqueSpot() {
|
public void testCreateNoSignAlreadyUniqueSpot() {
|
||||||
when(wsm.getWarp(any(), any())).thenReturn(null);
|
when(wsm.getWarpLocation(any(), any())).thenReturn(null);
|
||||||
when(player.hasPermission(anyString())).thenReturn(true);
|
when(player.hasPermission(anyString())).thenReturn(true);
|
||||||
WarpSignsListener wsl = new WarpSignsListener(addon);
|
WarpSignsListener wsl = new WarpSignsListener(addon);
|
||||||
SignChangeEvent e = new SignChangeEvent(block, player, lines);
|
SignChangeEvent e = new SignChangeEvent(block, player, lines);
|
||||||
|
Loading…
Reference in New Issue
Block a user