mirror of
https://github.com/BentoBoxWorld/Warps.git
synced 2025-02-16 12:21:21 +01:00
Enables warps to operate in any world. Commands can be changed.
https://github.com/BentoBoxWorld/Warps/issues/53 https://github.com/BentoBoxWorld/Warps/issues/54
This commit is contained in:
parent
197957648b
commit
afb03e6d42
@ -78,7 +78,11 @@ public class Warp extends Addon {
|
||||
// Save default config.yml
|
||||
this.saveDefaultConfig();
|
||||
// Load the plugin's config
|
||||
this.loadSettings();
|
||||
if (this.loadSettings()) {
|
||||
// Load the master warp and warps command
|
||||
new WarpCommand(this);
|
||||
new WarpsCommand(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -146,7 +150,7 @@ public class Warp extends Addon {
|
||||
/**
|
||||
* This method loads addon configuration settings in memory.
|
||||
*/
|
||||
private void loadSettings() {
|
||||
private boolean loadSettings() {
|
||||
if (settingsConfig == null) {
|
||||
settingsConfig = new Config<>(this, Settings.class);
|
||||
}
|
||||
@ -155,9 +159,10 @@ public class Warp extends Addon {
|
||||
// Disable
|
||||
this.logError("WelcomeWarp settings could not load! Addon disabled.");
|
||||
this.setState(State.DISABLED);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
settingsConfig.saveConfigObject(settings);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,7 +51,8 @@ public class WarpSignsListener implements Listener {
|
||||
if (!e.getBlock().getType().name().contains("SIGN")) {
|
||||
return;
|
||||
}
|
||||
if (!addon.inRegisteredWorld(b.getWorld())) {
|
||||
if ((addon.getPlugin().getIWM().inWorld(b.getWorld()) && !addon.inRegisteredWorld(b.getWorld()))
|
||||
|| (!addon.getPlugin().getIWM().inWorld(b.getWorld()) && !addon.getSettings().isAllowInOtherWorlds()) ) {
|
||||
return;
|
||||
}
|
||||
User user = User.getInstance(e.getPlayer());
|
||||
@ -87,7 +88,8 @@ public class WarpSignsListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onSignWarpCreate(SignChangeEvent e) {
|
||||
Block b = e.getBlock();
|
||||
if (!addon.inRegisteredWorld(b.getWorld())) {
|
||||
if ((addon.getPlugin().getIWM().inWorld(b.getWorld()) && !addon.inRegisteredWorld(b.getWorld()))
|
||||
|| (!addon.getPlugin().getIWM().inWorld(b.getWorld()) && !addon.getSettings().isAllowInOtherWorlds()) ) {
|
||||
return;
|
||||
}
|
||||
String title = e.getLine(0);
|
||||
@ -100,21 +102,23 @@ public class WarpSignsListener implements Listener {
|
||||
user.sendMessage("general.errors.no-permission", "[permission]", addon.getPermPrefix(b.getWorld()) + "island.addwarp");
|
||||
return;
|
||||
}
|
||||
// Get level if level addon is available
|
||||
Long level = addon.getLevel(Util.getWorld(b.getWorld()), user.getUniqueId());
|
||||
if (level != null && level < addon.getSettings().getWarpLevelRestriction()) {
|
||||
user.sendMessage("warps.error.not-enough-level");
|
||||
user.sendMessage("warps.error.your-level-is",
|
||||
"[level]", String.valueOf(level),
|
||||
"[required]", String.valueOf(addon.getSettings().getWarpLevelRestriction()));
|
||||
return;
|
||||
}
|
||||
if (addon.getPlugin().getIWM().inWorld(b.getWorld())) {
|
||||
// Get level if level addon is available
|
||||
Long level = addon.getLevel(Util.getWorld(b.getWorld()), user.getUniqueId());
|
||||
if (level != null && level < addon.getSettings().getWarpLevelRestriction()) {
|
||||
user.sendMessage("warps.error.not-enough-level");
|
||||
user.sendMessage("warps.error.your-level-is",
|
||||
"[level]", String.valueOf(level),
|
||||
"[required]", String.valueOf(addon.getSettings().getWarpLevelRestriction()));
|
||||
return;
|
||||
}
|
||||
|
||||
// Check that the player is on their island
|
||||
if (!(plugin.getIslands().userIsOnIsland(b.getWorld(), user))) {
|
||||
user.sendMessage("warps.error.not-on-island");
|
||||
e.setLine(0, ChatColor.RED + addon.getSettings().getWelcomeLine());
|
||||
return;
|
||||
// Check that the player is on their island
|
||||
if (!(plugin.getIslands().userIsOnIsland(b.getWorld(), user))) {
|
||||
user.sendMessage("warps.error.not-on-island");
|
||||
e.setLine(0, ChatColor.RED + addon.getSettings().getWelcomeLine());
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Check if the player already has a sign
|
||||
final Location oldSignLoc = addon.getWarpSignsManager().getWarp(b.getWorld(), user.getUniqueId());
|
||||
|
@ -70,7 +70,7 @@ public class WarpSignsManager {
|
||||
public WarpSignsManager(Warp addon, BentoBox plugin) {
|
||||
this.addon = addon;
|
||||
this.plugin = plugin;
|
||||
// Set up the database handler to store and retrieve Island classes
|
||||
// Set up the database handler
|
||||
// Note that these are saved by the BSkyBlock database
|
||||
handler = new Database<>(addon, WarpsData.class);
|
||||
// Load the warps
|
||||
|
@ -6,6 +6,8 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.warps.Warp;
|
||||
@ -19,15 +21,22 @@ import world.bentobox.warps.Warp;
|
||||
public class WarpCommand extends CompositeCommand {
|
||||
|
||||
private Warp addon;
|
||||
private String perm = "island";
|
||||
|
||||
public WarpCommand(Warp addon, CompositeCommand bsbIslandCmd) {
|
||||
super(bsbIslandCmd, "warp");
|
||||
super(bsbIslandCmd, addon.getSettings().getWarpCommand());
|
||||
this.addon = addon;
|
||||
}
|
||||
|
||||
public WarpCommand(Warp addon) {
|
||||
super(addon.getSettings().getWarpCommand());
|
||||
this.addon = addon;
|
||||
perm = "welcomewarpsigns";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
this.setPermission("island.warp");
|
||||
this.setPermission(perm + ".warp");
|
||||
this.setOnlyPlayer(true);
|
||||
this.setParametersHelp("warp.help.parameters");
|
||||
this.setDescription("warp.help.description");
|
||||
@ -35,9 +44,10 @@ public class WarpCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
World world = getWorld() == null ? user.getWorld() : getWorld();
|
||||
if (args.size() == 1) {
|
||||
// Warp somewhere command
|
||||
Set<UUID> warpList = addon.getWarpSignsManager().listWarps(getWorld());
|
||||
Set<UUID> warpList = addon.getWarpSignsManager().listWarps(world);
|
||||
if (warpList.isEmpty()) {
|
||||
user.sendMessage("warps.error.no-warps-yet");
|
||||
user.sendMessage("warps.warpTip", "[text]", addon.getSettings().getWelcomeLine());
|
||||
@ -51,7 +61,7 @@ public class WarpCommand extends CompositeCommand {
|
||||
return false;
|
||||
} else {
|
||||
// Warp exists!
|
||||
addon.getWarpSignsManager().warpPlayer(getWorld(), user, foundWarp);
|
||||
addon.getWarpSignsManager().warpPlayer(world, user, foundWarp);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -62,8 +72,9 @@ public class WarpCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
World world = getWorld() == null ? user.getWorld() : getWorld();
|
||||
List<String> options = new ArrayList<>();
|
||||
final Set<UUID> warpList = addon.getWarpSignsManager().listWarps(getWorld());
|
||||
final Set<UUID> warpList = addon.getWarpSignsManager().listWarps(world);
|
||||
|
||||
for (UUID warp : warpList) {
|
||||
options.add(addon.getPlugin().getPlayers().getName(warp));
|
||||
|
@ -1,33 +1,39 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.warps.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
import world.bentobox.warps.Warp;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
/**
|
||||
* @author ben
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class WarpsCommand extends CompositeCommand {
|
||||
|
||||
private Warp addon;
|
||||
private String perm = "island";
|
||||
|
||||
public WarpsCommand(Warp addon, CompositeCommand bsbIslandCmd) {
|
||||
super(bsbIslandCmd, "warps");
|
||||
super(bsbIslandCmd, addon.getSettings().getWarpsCommand());
|
||||
this.addon = addon;
|
||||
}
|
||||
|
||||
public WarpsCommand(Warp addon) {
|
||||
super(addon.getSettings().getWarpsCommand());
|
||||
this.addon = addon;
|
||||
perm = "welcomewarpsigns";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see us.tastybento.bskyblock.api.commands.BSBCommand#setup()
|
||||
*/
|
||||
@Override
|
||||
public void setup() {
|
||||
this.setPermission("island.warp");
|
||||
this.setPermission(perm + ".warp");
|
||||
this.setOnlyPlayer(true);
|
||||
this.setDescription("warps.help.description");
|
||||
}
|
||||
@ -37,11 +43,12 @@ public class WarpsCommand extends CompositeCommand {
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (addon.getWarpSignsManager().listWarps(getWorld()).isEmpty()) {
|
||||
World world = getWorld() == null ? user.getWorld() : getWorld();
|
||||
if (addon.getWarpSignsManager().listWarps(world).isEmpty()) {
|
||||
user.sendMessage("warps.error.no-warps-yet");
|
||||
user.sendMessage("warps.warpTip", "[text]", addon.getSettings().getWelcomeLine());
|
||||
} else {
|
||||
addon.getWarpPanelManager().showWarpPanel(getWorld(), user,0);
|
||||
addon.getWarpPanelManager().showWarpPanel(world, user,0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class Settings implements ConfigObject
|
||||
@ConfigComment(" - BSkyBlock")
|
||||
@ConfigEntry(path = "disabled-gamemodes")
|
||||
private Set<String> disabledGameModes = new HashSet<>();
|
||||
|
||||
|
||||
@ConfigComment("")
|
||||
@ConfigComment("Warp panel name formatting.")
|
||||
@ConfigComment("Example: &c will make names red. &f is white")
|
||||
@ -56,12 +56,25 @@ public class Settings implements ConfigObject
|
||||
@ConfigComment("Example: &c will make lore red. &f is white")
|
||||
@ConfigEntry(path = "lore-format")
|
||||
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("Allow use in other worlds. Players must have the welcomewarpsigns.warp permission.")
|
||||
@ConfigEntry(path = "allow-in-other-worlds")
|
||||
private boolean allowInOtherWorlds = false;
|
||||
|
||||
@ConfigComment("")
|
||||
@ConfigComment("Warp and warps commands. You can change them if they clash with other addons or plugins.")
|
||||
@ConfigEntry(path = "warp-command")
|
||||
String warpCommand = "warp";
|
||||
@ConfigEntry(path = "warps-command")
|
||||
String warpsCommand = "warps";
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Constructor
|
||||
// ---------------------------------------------------------------------
|
||||
@ -210,4 +223,52 @@ public class Settings implements ConfigObject
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the allowInOtherWorlds
|
||||
*/
|
||||
public boolean isAllowInOtherWorlds() {
|
||||
return allowInOtherWorlds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param allowInOtherWorlds the allowInOtherWorlds to set
|
||||
*/
|
||||
public void setAllowInOtherWorlds(boolean allowInOtherWorlds) {
|
||||
this.allowInOtherWorlds = allowInOtherWorlds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the warpCommand
|
||||
*/
|
||||
public String getWarpCommand() {
|
||||
return warpCommand;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param warpCommand the warpCommand to set
|
||||
*/
|
||||
public void setWarpCommand(String warpCommand) {
|
||||
this.warpCommand = warpCommand;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the warpsCommand
|
||||
*/
|
||||
public String getWarpsCommand() {
|
||||
return warpsCommand;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param warpsCommand the warpsCommand to set
|
||||
*/
|
||||
public void setWarpsCommand(String warpsCommand) {
|
||||
this.warpsCommand = warpsCommand;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -34,4 +34,10 @@ 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-in-other-worlds: false
|
||||
#
|
||||
# Warp and warps commands. You can change them if they clash with other addons or plugins.
|
||||
warp-command: warp
|
||||
warps-command: warps
|
||||
|
@ -10,6 +10,7 @@ import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.anyString;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.never;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -79,6 +80,8 @@ public class WarpSignsListenerTest {
|
||||
private Settings settings;
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
@Mock
|
||||
private IslandWorldManager iwm;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@ -155,9 +158,10 @@ public class WarpSignsListenerTest {
|
||||
// Sufficient level
|
||||
when(addon.getLevel(any(), any())).thenReturn(100L);
|
||||
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
// IWM
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
when(iwm.getAddon(any())).thenReturn(Optional.empty());
|
||||
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
||||
|
||||
// Util
|
||||
PowerMockito.mockStatic(Util.class);
|
||||
@ -190,7 +194,7 @@ public class WarpSignsListenerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnSignBreakWrongWorld() {
|
||||
public void testOnSignNotGameWorld() {
|
||||
WarpSignsListener wsl = new WarpSignsListener(addon);
|
||||
BlockBreakEvent e = new BlockBreakEvent(block, player);
|
||||
when(addon.inRegisteredWorld(any())).thenReturn(false);
|
||||
@ -283,7 +287,7 @@ public class WarpSignsListenerTest {
|
||||
* Sign create
|
||||
*/
|
||||
@Test
|
||||
public void testOnCreateWrongWorld() {
|
||||
public void testOnCreateWrongWorldGameWorld() {
|
||||
when(player.hasPermission(anyString())).thenReturn(true);
|
||||
WarpSignsListener wsl = new WarpSignsListener(addon);
|
||||
SignChangeEvent e = new SignChangeEvent(block, player, lines);
|
||||
@ -292,6 +296,43 @@ public class WarpSignsListenerTest {
|
||||
verify(addon).inRegisteredWorld(Mockito.eq(world));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCreateNotGameWorldAllowed() {
|
||||
when(settings.isAllowInOtherWorlds()).thenReturn(true);
|
||||
when(iwm.inWorld(any(World.class))).thenReturn(false);
|
||||
when(player.hasPermission(anyString())).thenReturn(true);
|
||||
WarpSignsListener wsl = new WarpSignsListener(addon);
|
||||
SignChangeEvent e = new SignChangeEvent(block, player, lines);
|
||||
when(addon.inRegisteredWorld(any())).thenReturn(false);
|
||||
wsl.onSignWarpCreate(e);
|
||||
verify(player).sendMessage("warps.success");
|
||||
assertEquals(ChatColor.GREEN + "[WELCOME]", e.getLine(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCreateNotGameWorldNotAllowed() {
|
||||
when(settings.isAllowInOtherWorlds()).thenReturn(false);
|
||||
when(iwm.inWorld(any(World.class))).thenReturn(false);
|
||||
when(player.hasPermission(anyString())).thenReturn(true);
|
||||
WarpSignsListener wsl = new WarpSignsListener(addon);
|
||||
SignChangeEvent e = new SignChangeEvent(block, player, lines);
|
||||
when(addon.inRegisteredWorld(any())).thenReturn(false);
|
||||
wsl.onSignWarpCreate(e);
|
||||
verify(player, never()).sendMessage("warps.success");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCreateNotGameWorldNoPerm() {
|
||||
when(settings.isAllowInOtherWorlds()).thenReturn(true);
|
||||
when(iwm.inWorld(any(World.class))).thenReturn(false);
|
||||
when(player.hasPermission(anyString())).thenReturn(false);
|
||||
WarpSignsListener wsl = new WarpSignsListener(addon);
|
||||
SignChangeEvent e = new SignChangeEvent(block, player, lines);
|
||||
when(addon.inRegisteredWorld(any())).thenReturn(false);
|
||||
wsl.onSignWarpCreate(e);
|
||||
verify(player).sendMessage("warps.error.no-permission");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCreateWrongText() {
|
||||
when(player.hasPermission(anyString())).thenReturn(true);
|
||||
|
Loading…
Reference in New Issue
Block a user