mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-07 17:07:36 +01:00
Added WorldSettings options to create island on first login
Implements https://github.com/BentoBoxWorld/BentoBox/issues/889
This commit is contained in:
parent
e5646c72cd
commit
a1b7df19c7
@ -391,4 +391,26 @@ public interface WorldSettings extends ConfigObject {
|
|||||||
*/
|
*/
|
||||||
boolean isKickedKeepInventory();
|
boolean isKickedKeepInventory();
|
||||||
|
|
||||||
|
/* Create island on first login */
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @since 1.9.0
|
||||||
|
*/
|
||||||
|
boolean isCreateIslandOnFirstLoginEnabled();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @since 1.9.0
|
||||||
|
*/
|
||||||
|
int getCreateIslandOnFirstLoginDelay();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @since 1.9.0
|
||||||
|
*/
|
||||||
|
boolean isCreateIslandOnFirstLoginAbortOnLogout();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package world.bentobox.bentobox.listeners;
|
package world.bentobox.bentobox.listeners;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -13,6 +15,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
@ -22,6 +25,7 @@ import world.bentobox.bentobox.api.user.User;
|
|||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.database.objects.Players;
|
import world.bentobox.bentobox.database.objects.Players;
|
||||||
import world.bentobox.bentobox.lists.Flags;
|
import world.bentobox.bentobox.lists.Flags;
|
||||||
|
import world.bentobox.bentobox.managers.BlueprintsManager;
|
||||||
import world.bentobox.bentobox.managers.PlayersManager;
|
import world.bentobox.bentobox.managers.PlayersManager;
|
||||||
import world.bentobox.bentobox.managers.RanksManager;
|
import world.bentobox.bentobox.managers.RanksManager;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
@ -42,12 +46,48 @@ public class JoinLeaveListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||||
User user = User.getInstance(event.getPlayer());
|
User user = User.getInstance(event.getPlayer());
|
||||||
if (user.getUniqueId() == null) {
|
if (user == null || user.getUniqueId() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UUID playerUUID = user.getUniqueId();
|
UUID playerUUID = user.getUniqueId();
|
||||||
// Load player
|
|
||||||
|
// Check if player hasn't joined before
|
||||||
|
if (!players.isKnown(playerUUID)) {
|
||||||
|
// Create a database entry for that player
|
||||||
|
players.addPlayer(playerUUID);
|
||||||
|
|
||||||
|
plugin.getIWM().getOverWorlds().stream()
|
||||||
|
.filter(w -> plugin.getIWM().isCreateIslandOnFirstLoginEnabled(w))
|
||||||
|
.forEach(w -> {
|
||||||
|
// Even if that'd be extremely unlikely, it's better to check if the player doesn't have an already.
|
||||||
|
if (!(plugin.getIslands().hasIsland(w, user) || plugin.getIslands().inTeam(w, user.getUniqueId()))) {
|
||||||
|
int delay = plugin.getIWM().getCreateIslandOnFirstLoginDelay(w);
|
||||||
|
user.sendMessage("commands.island.create.on-first-login",
|
||||||
|
TextVariables.NUMBER, String.valueOf(delay));
|
||||||
|
|
||||||
|
Runnable createIsland = () -> {
|
||||||
|
// should only execute if:
|
||||||
|
// - abort on logout is false
|
||||||
|
// - abort on logout is true && user is online
|
||||||
|
if (!plugin.getIWM().isCreateIslandOnFirstLoginAbortOnLogout(w) || user.isOnline()){
|
||||||
|
plugin.getIWM().getAddon(w).ifPresent(addon -> addon.getPlayerCommand()
|
||||||
|
.map(command -> command.getSubCommand("create").orElse(null))
|
||||||
|
.ifPresent(command -> command.execute(user, "create", Collections.singletonList(BlueprintsManager.DEFAULT_BUNDLE_NAME))));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (delay <= 0) {
|
||||||
|
createIsland.run();
|
||||||
|
} else {
|
||||||
|
plugin.getServer().getScheduler().runTaskLater(plugin, createIsland, delay * 20L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the player is loaded into the cache (doesn't impact performance)
|
||||||
players.addPlayer(playerUUID);
|
players.addPlayer(playerUUID);
|
||||||
|
|
||||||
// Reset island resets if required
|
// Reset island resets if required
|
||||||
plugin.getIWM().getOverWorlds().stream()
|
plugin.getIWM().getOverWorlds().stream()
|
||||||
.filter(w -> event.getPlayer().getLastPlayed() < plugin.getIWM().getResetEpoch(w))
|
.filter(w -> event.getPlayer().getLastPlayed() < plugin.getIWM().getResetEpoch(w))
|
||||||
@ -75,7 +115,7 @@ public class JoinLeaveListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear inventory if required
|
// Clear inventory if required
|
||||||
clearPlayersInventory(Util.getWorld(event.getPlayer().getWorld()), User.getInstance(event.getPlayer()));
|
clearPlayersInventory(Util.getWorld(event.getPlayer().getWorld()), user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -799,4 +799,33 @@ public class IslandWorldManager {
|
|||||||
return !gameModes.containsKey(world) || gameModes.get(world).getWorldSettings().isKickedKeepInventory();
|
return !gameModes.containsKey(world) || gameModes.get(world).getWorldSettings().isKickedKeepInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param world
|
||||||
|
* @return
|
||||||
|
* @since 1.9.0
|
||||||
|
*/
|
||||||
|
public boolean isCreateIslandOnFirstLoginEnabled(@NonNull World world) {
|
||||||
|
return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isCreateIslandOnFirstLoginEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param world
|
||||||
|
* @return
|
||||||
|
* @since 1.9.0
|
||||||
|
*/
|
||||||
|
public int getCreateIslandOnFirstLoginDelay(@NonNull World world) {
|
||||||
|
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getCreateIslandOnFirstLoginDelay() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param world
|
||||||
|
* @return
|
||||||
|
* @since 1.9.0
|
||||||
|
*/
|
||||||
|
public boolean isCreateIslandOnFirstLoginAbortOnLogout(@NonNull World world) {
|
||||||
|
return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isCreateIslandOnFirstLoginAbortOnLogout();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class IslandCreationPanel {
|
|||||||
PanelBuilder pb = new PanelBuilder().name(user.getTranslation("commands.island.create.pick")).user(user);
|
PanelBuilder pb = new PanelBuilder().name(user.getTranslation("commands.island.create.pick")).user(user);
|
||||||
// Get the bundles
|
// Get the bundles
|
||||||
Comparator<BlueprintBundle> sortByDisplayName = (p, o) -> p.getDisplayName().compareToIgnoreCase(o.getDisplayName());
|
Comparator<BlueprintBundle> sortByDisplayName = (p, o) -> p.getDisplayName().compareToIgnoreCase(o.getDisplayName());
|
||||||
List<BlueprintBundle> bbs = plugin.getBlueprintsManager().getBlueprintBundles((@NonNull GameModeAddon) command.getAddon()).values()
|
List<BlueprintBundle> bbs = plugin.getBlueprintsManager().getBlueprintBundles(command.getAddon()).values()
|
||||||
.stream().sorted(sortByDisplayName).collect(Collectors.toList());
|
.stream().sorted(sortByDisplayName).collect(Collectors.toList());
|
||||||
// Loop through them and create items in the panel
|
// Loop through them and create items in the panel
|
||||||
for (BlueprintBundle bb : bbs) {
|
for (BlueprintBundle bb : bbs) {
|
||||||
|
@ -432,6 +432,7 @@ commands:
|
|||||||
done: "&aDone! Your island is ready and waiting for you!"
|
done: "&aDone! Your island is ready and waiting for you!"
|
||||||
pick: "&2Pick an island"
|
pick: "&2Pick an island"
|
||||||
unknown-blueprint: "&cThat blueprint has not been loaded yet."
|
unknown-blueprint: "&cThat blueprint has not been loaded yet."
|
||||||
|
on-first-login: "&aWelcome! We will start preparing your island in a few seconds."
|
||||||
info:
|
info:
|
||||||
description: "display info about your island or the player's island"
|
description: "display info about your island or the player's island"
|
||||||
parameters: "<player>"
|
parameters: "<player>"
|
||||||
|
@ -732,6 +732,21 @@ public class IslandGoCommandTest {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCreateIslandOnFirstLoginEnabled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCreateIslandOnFirstLoginDelay() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCreateIslandOnFirstLoginAbortOnLogout() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull List<String> getOnJoinCommands() {
|
public @NonNull List<String> getOnJoinCommands() {
|
||||||
return null;
|
return null;
|
||||||
|
@ -672,5 +672,20 @@ public class BannedCommandsTest {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCreateIslandOnFirstLoginEnabled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCreateIslandOnFirstLoginDelay() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCreateIslandOnFirstLoginAbortOnLogout() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -633,5 +633,20 @@ public class BlockEndDragonTest {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCreateIslandOnFirstLoginEnabled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCreateIslandOnFirstLoginDelay() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCreateIslandOnFirstLoginAbortOnLogout() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -396,4 +396,19 @@ public class TestWorldSettings implements WorldSettings {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCreateIslandOnFirstLoginEnabled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCreateIslandOnFirstLoginDelay() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCreateIslandOnFirstLoginAbortOnLogout() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user