Skip to content

Commit

Permalink
Merge branch 'develop' into 1.16.5_lts
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jan 8, 2022
1 parent 4683f7f commit 260635e
Show file tree
Hide file tree
Showing 63 changed files with 2,995 additions and 1,671 deletions.
26 changes: 12 additions & 14 deletions src/main/java/world/bentobox/bentobox/BentoBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,7 @@
import world.bentobox.bentobox.listeners.PanelListenerManager;
import world.bentobox.bentobox.listeners.PortalTeleportationListener;
import world.bentobox.bentobox.listeners.StandardSpawnProtectionListener;
import world.bentobox.bentobox.managers.AddonsManager;
import world.bentobox.bentobox.managers.BlueprintsManager;
import world.bentobox.bentobox.managers.CommandsManager;
import world.bentobox.bentobox.managers.FlagsManager;
import world.bentobox.bentobox.managers.HooksManager;
import world.bentobox.bentobox.managers.IslandDeletionManager;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.LocalesManager;
import world.bentobox.bentobox.managers.PlaceholdersManager;
import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.managers.WebManager;
import world.bentobox.bentobox.managers.*;
import world.bentobox.bentobox.util.heads.HeadGetter;
import world.bentobox.bentobox.versions.ServerCompatibility;

Expand All @@ -69,6 +57,7 @@ public class BentoBox extends JavaPlugin {
private HooksManager hooksManager;
private PlaceholdersManager placeholdersManager;
private IslandDeletionManager islandDeletionManager;
private IslandChunkDeletionManager islandChunkDeletionManager;
private WebManager webManager;

// Settings
Expand Down Expand Up @@ -157,7 +146,6 @@ public void onEnable(){

// Load hooks
hooksManager = new HooksManager(this);
hooksManager.registerHook(new VaultHook());

// Load addons. Addons may load worlds, so they must go before islands are loaded.
addonsManager = new AddonsManager(this);
Expand All @@ -177,6 +165,8 @@ public void onEnable(){

private void completeSetup(long loadTime) {
final long enableStart = System.currentTimeMillis();
hooksManager.registerHook(new VaultHook());

hooksManager.registerHook(new PlaceholderAPIHook());
// Setup the Placeholders manager
placeholdersManager = new PlaceholdersManager(this);
Expand Down Expand Up @@ -294,6 +284,7 @@ private void registerListeners() {
// Death counter
manager.registerEvents(new DeathListener(this), this);
// Island Delete Manager
islandChunkDeletionManager = new IslandChunkDeletionManager(this);
islandDeletionManager = new IslandDeletionManager(this);
manager.registerEvents(islandDeletionManager, this);
}
Expand Down Expand Up @@ -523,6 +514,13 @@ public IslandDeletionManager getIslandDeletionManager() {
return islandDeletionManager;
}

/**
* @return the islandChunkDeletionManager
*/
public IslandChunkDeletionManager getIslandChunkDeletionManager() {
return islandChunkDeletionManager;
}

/**
* @return an optional of the Bstats instance
* @since 1.1
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/world/bentobox/bentobox/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,22 @@ public class Settings implements ConfigObject {
@ConfigEntry(path = "island.deletion.keep-previous-island-on-reset", since = "1.13.0")
private boolean keepPreviousIslandOnReset = false;

@ConfigComment("Toggles how the islands are deleted.")
@ConfigComment("* If set to 'false', all islands will be deleted at once.")
@ConfigComment(" This is fast but may cause an impact on the performance")
@ConfigComment(" as it'll load all the chunks of the in-deletion islands.")
@ConfigComment("* If set to 'true', the islands will be deleted one by one.")
@ConfigComment(" This is slower but will not cause any impact on the performance.")
@ConfigEntry(path = "island.deletion.slow-deletion", since = "1.19.1")
private boolean slowDeletion = false;

@ConfigComment("By default, If the destination is not safe, the plugin will try to search for a safe spot around the destination,")
@ConfigComment("then it will try to expand the y-coordinate up and down from the destination.")
@ConfigComment("This setting limits how far the y-coordinate will be expanded.")
@ConfigComment("If set to 0 or lower, the plugin will not expand the y-coordinate.")
@ConfigEntry(path = "island.safe-spot-search-vertical-range", since = "1.19.1")
private int safeSpotSearchVerticalRange = 400;

/* WEB */
@ConfigComment("Toggle whether BentoBox can connect to GitHub to get data about updates and addons.")
@ConfigComment("Disabling this will result in the deactivation of the update checker and of some other")
Expand Down Expand Up @@ -890,4 +906,20 @@ public int getMinPortalSearchRadius() {
public void setMinPortalSearchRadius(int minPortalSearchRadius) {
this.minPortalSearchRadius = minPortalSearchRadius;
}

public int getSafeSpotSearchVerticalRange() {
return safeSpotSearchVerticalRange;
}

public void setSafeSpotSearchVerticalRange(int safeSpotSearchVerticalRange) {
this.safeSpotSearchVerticalRange = safeSpotSearchVerticalRange;
}

public boolean isSlowDeletion() {
return slowDeletion;
}

public void setSlowDeletion(boolean slowDeletion) {
this.slowDeletion = slowDeletion;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package world.bentobox.bentobox.api.commands.admin;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util;

/**
* Deletes all named homes from an island
* @author tastybento
*
*/
public class AdminDeleteHomesCommand extends ConfirmableCommand {

public AdminDeleteHomesCommand(CompositeCommand parent) {
super(parent, "deletehomes");
}

@Override
public void setup() {
setPermission("mod.deletehomes");
setOnlyPlayer(false);
setParametersHelp("commands.admin.deletehomes.parameters");
setDescription("commands.admin.deletehomes.description");
}

@Override
public boolean canExecute(User user, String label, List<String> args) {
if (args.size() != 1) {
showHelp(this, user);
return false;
}
return true;
}

@Override
public boolean execute(User user, String label, List<String> args) {
// Get target player
UUID targetUUID = Util.getUUID(args.get(0));
if (targetUUID == null) {
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
return false;
}
// Get island
Island island = getIslands().getIsland(getWorld(), targetUUID);
if (island == null) {
user.sendMessage("general.errors.player-has-no-island");
return false;
}
// Confirm
askConfirmation(user, user.getTranslation("commands.admin.deletehomes.warning"), () -> deleteHomes(user, targetUUID, island));
return true;
}

private boolean deleteHomes(User user, UUID targetUUID, Island island) {
island.removeHomes();
user.sendMessage("general.success");
return true;
}

@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
if (args.isEmpty()) {
// Don't show every player on the server. Require at least the first letter
return Optional.empty();
}
List<String> options = new ArrayList<>(Util.getOnlinePlayerList(user));
return Optional.of(Util.tabLimit(options, lastArg));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public void setup() {
new AdminSettingsCommand(this);
// Location
new AdminSetProtectionCenterCommand(this);
// Delete homes
new AdminDeleteHomesCommand(this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.bukkit.Location;
import org.bukkit.Particle;

import com.google.common.base.Enums;

import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
Expand All @@ -22,6 +24,8 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
private static final String DISPLAY = "display";
private static final String SHOW = "show";
private static final String HIDE = "hide";
// Since 1.18, the Particle.BARRIER was replaced by BLOCK_MARKER
private static final Particle BARRIER = Enums.getIfPresent(Particle.class, "BARRIER").or(Enums.getIfPresent(Particle.class, "BLOCK_MARKER").or(Particle.LAVA));

// Map of users to which ranges must be displayed
private final Map<User, Integer> displayRanges = new HashMap<>();
Expand All @@ -46,15 +50,15 @@ public boolean execute(User user, String label, List<String> args) {

if (!displayRanges.containsKey(user)) {
switch (label) {
case DISPLAY, SHOW -> showZones(user);
case HIDE -> user.sendMessage("commands.admin.range.display.already-off");
default -> showHelp(this, user);
case DISPLAY, SHOW -> showZones(user);
case HIDE -> user.sendMessage("commands.admin.range.display.already-off");
default -> showHelp(this, user);
}
} else {
switch (label) {
case DISPLAY, HIDE -> hideZones(user);
case SHOW -> user.sendMessage("commands.admin.range.display.already-on");
default -> showHelp(this, user);
case DISPLAY, HIDE -> hideZones(user);
case SHOW -> user.sendMessage("commands.admin.range.display.already-on");
default -> showHelp(this, user);
}
}

Expand All @@ -71,7 +75,7 @@ private void showZones(User user) {

getIslands().getIslandAt(user.getLocation()).ifPresent(island -> {
// Draw the island protected area
drawZone(user, Particle.BARRIER, null, island, island.getProtectionRange());
drawZone(user, BARRIER, null, island, island.getProtectionRange());

// Draw the default protected area if island protected zone is different
if (island.getProtectionRange() != getPlugin().getIWM().getIslandProtectionRange(getWorld())) {
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/world/bentobox/bentobox/api/flags/FlagListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class FlagListener implements Listener {
* Reason for why flag was allowed or disallowed
* Used by admins for debugging player actions
*/
enum Why {
protected enum Why {
UNPROTECTED_WORLD,
OP,
BYPASS_EVERYWHERE,
Expand Down Expand Up @@ -206,7 +206,15 @@ public boolean checkIsland(@NonNull Event e, @Nullable Player player, @Nullable
}
}

private void report(@Nullable User user, @NonNull Event e, @NonNull Location loc, @NonNull Flag flag, @NonNull Why why) {
/**
* Report why something did or did not happen for the admin why command
* @param user user involved
* @param e associated event
* @param loc location
* @param flag flag
* @param why reason enum
*/
protected void report(@Nullable User user, @NonNull Event e, @NonNull Location loc, @NonNull Flag flag, @NonNull Why why) {
// A quick way to debug flag listener unit tests is to add this line here: System.out.println(why.name()); NOSONAR
if (user != null && user.isPlayer() && user.getPlayer().getMetadata(loc.getWorld().getName() + "_why_debug").stream()
.filter(p -> p.getOwningPlugin().equals(getPlugin())).findFirst().map(MetadataValue::asBoolean).orElse(false)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private Map<Integer, PanelItem> populateInventoryPanel()
{
String type = String.valueOf(record.dataMap().get("type"));

int counter = this.typeSlotMap.computeIfAbsent(type, key -> 1);
int counter = this.typeSlotMap.computeIfAbsent(type, key -> 0);
this.typeSlotMap.put(type, counter + 1);
}
}
Expand Down Expand Up @@ -227,7 +227,7 @@ private Map<Integer, PanelItem> populateHopperPanel()
{
String type = String.valueOf(record.dataMap().get("type"));

int counter = this.typeSlotMap.computeIfAbsent(type, key -> 1);
int counter = this.typeSlotMap.computeIfAbsent(type, key -> 0);
this.typeSlotMap.put(type, counter + 1);
}
}
Expand Down Expand Up @@ -290,7 +290,7 @@ private Map<Integer, PanelItem> populateDropperPanel()
{
String type = String.valueOf(record.dataMap().get("type"));

int counter = this.typeSlotMap.computeIfAbsent(type, key -> 1);
int counter = this.typeSlotMap.computeIfAbsent(type, key -> 0);
this.typeSlotMap.put(type, counter + 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
package world.bentobox.bentobox.api.panels.reader;


import java.util.Arrays;
import java.util.Objects;

import org.bukkit.inventory.ItemStack;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
Expand All @@ -28,11 +31,11 @@
* @since 1.17.3
*/
public record PanelTemplateRecord(Panel.Type type,
@Nullable String title,
@Nullable TemplateItem border,
@Nullable TemplateItem background,
boolean[] forcedRows,
@NonNull ItemTemplateRecord[][] content)
@Nullable String title,
@Nullable TemplateItem border,
@Nullable TemplateItem background,
boolean[] forcedRows,
@NonNull ItemTemplateRecord[][] content)
{
/**
* Instantiates a new Panel template record with empty content.
Expand Down Expand Up @@ -76,4 +79,43 @@ public TemplateItem(ItemStack icon)
this(icon, null, null);
}
}


@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.deepHashCode(content);
result = prime * result + Arrays.hashCode(forcedRows);
result = prime * result + Objects.hash(background, border, title, type);
return result;
}


@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof PanelTemplateRecord)) {
return false;
}
PanelTemplateRecord other = (PanelTemplateRecord) obj;
return Objects.equals(background, other.background) && Objects.equals(border, other.border)
&& Arrays.deepEquals(content, other.content) && Arrays.equals(forcedRows, other.forcedRows)
&& Objects.equals(title, other.title) && type == other.type;
}


@Override
public String toString() {
return "PanelTemplateRecord {type=" + type +
", title=" + title +
", border=" + border +
", background=" + background +
", forcedRows=" + Arrays.toString(forcedRows) +
", content=" + Arrays.toString(content) + "}";
}


}

0 comments on commit 260635e

Please sign in to comment.