mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-11-27 20:46:19 +01:00
Adds level calculation on login option.
https://github.com/BentoBoxWorld/Level/issues/36
This commit is contained in:
parent
ef81d6c985
commit
d49859bc78
@ -5,6 +5,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
@ -54,7 +55,7 @@ public class Level extends Addon {
|
||||
* @param user - the user who is asking, or null if none
|
||||
* @param playerUUID - the target island member's UUID
|
||||
*/
|
||||
public void calculateIslandLevel(World world, User user, UUID playerUUID) {
|
||||
public void calculateIslandLevel(World world, @Nullable User user, UUID playerUUID) {
|
||||
levelCalc.calculateIslandLevel(world, user, playerUUID);
|
||||
}
|
||||
|
||||
|
@ -41,16 +41,18 @@ class LevelPresenter {
|
||||
targetPlayer = plugin.getIslands().getOwner(world, targetPlayer);
|
||||
inTeam = true;
|
||||
} else {
|
||||
sender.sendMessage("general.errors.player-has-no-island");
|
||||
if (sender != null) sender.sendMessage("general.errors.player-has-no-island");
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Player asking for their own island calc
|
||||
if (inTeam || !sender.isPlayer() || sender.getUniqueId().equals(targetPlayer) || sender.isOp() || sender.hasPermission(permPrefix + "mod.info")) {
|
||||
if (sender == null || inTeam || !sender.isPlayer() || sender.getUniqueId().equals(targetPlayer) || sender.isOp() || sender.hasPermission(permPrefix + "mod.info")) {
|
||||
// Newer better system - uses chunks
|
||||
if (!onLevelWaitTime(sender) || levelWait <= 0 || sender.isOp() || sender.hasPermission(permPrefix + "mod.info")) {
|
||||
sender.sendMessage("island.level.calculating");
|
||||
setLevelWaitTime(sender);
|
||||
if (sender == null || !onLevelWaitTime(sender) || levelWait <= 0 || sender.isOp() || sender.hasPermission(permPrefix + "mod.info")) {
|
||||
if (sender != null) {
|
||||
sender.sendMessage("island.level.calculating");
|
||||
setLevelWaitTime(sender);
|
||||
}
|
||||
new PlayerLevel(addon, plugin.getIslands().getIsland(world, targetPlayer), targetPlayer, sender);
|
||||
} else {
|
||||
// Cooldown
|
||||
|
@ -5,6 +5,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.api.events.addon.AddonEvent;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
@ -34,7 +35,7 @@ public class PlayerLevel {
|
||||
private CalcIslandLevel calc;
|
||||
|
||||
|
||||
public PlayerLevel(final Level addon, final Island island, final UUID targetPlayer, final User asker) {
|
||||
public PlayerLevel(final Level addon, final Island island, final UUID targetPlayer, @Nullable final User asker) {
|
||||
this.addon = addon;
|
||||
this.island = island;
|
||||
this.world = island.getCenter().getWorld();
|
||||
@ -70,7 +71,7 @@ public class PlayerLevel {
|
||||
// Save the results
|
||||
island.getMemberSet().forEach(m -> addon.setIslandLevel(world, m, results.getLevel()));
|
||||
// Display result if event is not cancelled
|
||||
if (!ilce.isCancelled()) {
|
||||
if (!ilce.isCancelled() && asker != null) {
|
||||
informPlayers(results);
|
||||
}
|
||||
}
|
||||
|
@ -13,11 +13,11 @@ import world.bentobox.level.Level;
|
||||
|
||||
public class AdminLevelCommand extends CompositeCommand {
|
||||
|
||||
private final Level levelPlugin;
|
||||
private final Level addon;
|
||||
|
||||
public AdminLevelCommand(Level levelPlugin, CompositeCommand parent) {
|
||||
public AdminLevelCommand(Level addon, CompositeCommand parent) {
|
||||
super(parent, "level");
|
||||
this.levelPlugin = levelPlugin;
|
||||
this.addon = addon;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -38,7 +38,7 @@ public class AdminLevelCommand extends CompositeCommand {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
return true;
|
||||
} else {
|
||||
levelPlugin.calculateIslandLevel(getWorld(), user, playerUUID);
|
||||
addon.calculateIslandLevel(getWorld(), user, playerUUID);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
|
@ -205,4 +205,11 @@ public class Settings {
|
||||
return level.getConfig().getBoolean("end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if level should be calculated on login
|
||||
*/
|
||||
public boolean isLogin() {
|
||||
return level.getConfig().getBoolean("login");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,14 @@ public class JoinLeaveListener implements Listener {
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
// Load player into cache
|
||||
addon.getLevelsData(e.getPlayer().getUniqueId());
|
||||
// If level calc on login is enabled, run through all the worlds and calculate the level
|
||||
if (addon.getSettings().isLogin()) {
|
||||
addon.getPlugin().getAddonsManager().getGameModeAddons().stream()
|
||||
.filter(gm -> addon.getSettings().getGameModes().contains(gm.getDescription().getName()))
|
||||
.forEach(gm -> {
|
||||
addon.calculateIslandLevel(gm.getOverWorld(), null, e.getPlayer().getUniqueId());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
|
@ -14,6 +14,11 @@ game-modes:
|
||||
# Players with the permission askyblock.island.multiplier.# will have their blocks
|
||||
# multiplied in value by that amount.
|
||||
|
||||
# Calculate island level on login
|
||||
# This silently calculates the player's island level when they login
|
||||
# This applies to all islands the player has on the server, e.g., BSkyBlock, AcidIsland
|
||||
login: false
|
||||
|
||||
# Include nether island in level calculations.
|
||||
# Warning: Enabling this mid-game will give players with an island a jump in
|
||||
# island level. New islands will be correctly zeroed.
|
||||
|
Loading…
Reference in New Issue
Block a user