Skip to content

Commit

Permalink
Merge pull request #395 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Release 1.17.0
  • Loading branch information
tastybento authored Jul 5, 2024
2 parents 14b10b4 + 76c5214 commit bac04f0
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 38 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@
<powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>2.0.0-SNAPSHOT</bentobox.version>
<bentobox.version>2.3.0-SNAPSHOT</bentobox.version>
<level.version>2.6.2</level.version>
<bank.version>1.3.0</bank.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.16.0</build.version>
<build.version>1.17.0</build.version>
<!-- SonarCloud -->
<sonar.projectKey>BentoBoxWorld_AOneBlock</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
Expand Down
68 changes: 62 additions & 6 deletions src/main/java/world/bentobox/aoneblock/AOneBlockPlaceholders.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package world.bentobox.aoneblock;

import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;

import org.bukkit.Material;

import world.bentobox.aoneblock.dataobjects.OneBlockIslands;
import world.bentobox.aoneblock.panels.PhasesPanel;
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.hooks.LangUtilsHook;
import world.bentobox.bentobox.util.Util;

public class AOneBlockPlaceholders {

Expand Down Expand Up @@ -46,6 +54,54 @@ public AOneBlockPlaceholders(AOneBlock addon,
// Since 1.10
placeholdersManager.registerPlaceholder(addon, "visited_island_lifetime_count", this::getLifetimeByLocation);
placeholdersManager.registerPlaceholder(addon, "my_island_lifetime_count", this::getLifetime);

placeholdersManager.registerPlaceholder(addon, "visited_island_phase_block_list",
this::getPhaseBlocksNamesByLocation);
placeholdersManager.registerPlaceholder(addon, "my_island_phase_block_list", this::getPhaseBlocksNames);

}

public String getPhaseBlocksNames(User user) {
if (user == null || user.getUniqueId() == null)
return "";
Island i = addon.getIslands().getIsland(addon.getOverWorld(), user);
if (i == null) {
return "";
}
return getPhaseBlocksForIsland(user, i);
}

private String getPhaseBlocksForIsland(User user, Island i) {
String phaseName = addon.getOneBlocksIsland(i).getPhaseName();
Set<Material> set = addon.getOneBlockManager().getPhase(phaseName).map(phase -> phase.getBlocks().keySet())
.orElse(null);
if (set == null) {
return "";
}

String result = set.stream().map(m -> getMaterialName(user, m))
.map(string -> user.getTranslation(PhasesPanel.REFERENCE + "blocks", TextVariables.NAME,
string))
.collect(Collectors.joining());
// Removing the last newline character or comma if it exists
result = result.trim();
if (result.endsWith("\n") || result.endsWith(",")) {
result = result.substring(0, result.length() - 1);
}

return result;

}

private String getMaterialName(User user, Material m) {
return addon.getPlugin().getHooks().getHook("LangUtils").map(hook -> LangUtilsHook.getMaterialName(m, user))
.orElse(Util.prettifyText(m.name()));
}

public String getPhaseBlocksNamesByLocation(User user) {
if (user == null || user.getUniqueId() == null || !addon.inWorld(user.getWorld()))
return "";
return addon.getIslands().getIslandAt(user.getLocation()).map(i -> getPhaseBlocksForIsland(user, i)).orElse("");
}

/**
Expand All @@ -68,7 +124,7 @@ public String getPhaseByLocation(User user) {
* @return String of count
*/
public String getCountByLocation(User user) {
if (user == null || user.getUniqueId() == null)
if (user == null || user.getUniqueId() == null || !addon.inWorld(user.getWorld()))
return "";
return addon.getIslands().getProtectedIslandAt(Objects.requireNonNull(user.getLocation()))
.map(addon::getOneBlocksIsland).map(OneBlockIslands::getBlockNumber).map(String::valueOf).orElse("");
Expand Down Expand Up @@ -107,7 +163,7 @@ public String getCount(User user) {
* @return next phase
*/
public String getNextPhaseByLocation(User user) {
if (user == null || user.getUniqueId() == null)
if (user == null || user.getUniqueId() == null || !addon.inWorld(user.getWorld()))
return "";
return addon.getIslands().getProtectedIslandAt(Objects.requireNonNull(user.getLocation()))
.map(addon::getOneBlocksIsland).map(addon.getOneBlockManager()::getNextPhase).orElse("");
Expand All @@ -133,7 +189,7 @@ public String getNextPhase(User user) {
* @return string number of blocks
*/
public String getNextPhaseBlocksByLocation(User user) {
if (user == null || user.getUniqueId() == null)
if (user == null || user.getUniqueId() == null || !addon.inWorld(user.getWorld()))
return "";
return addon.getIslands().getProtectedIslandAt(Objects.requireNonNull(user.getLocation()))
.map(addon::getOneBlocksIsland).map(addon.getOneBlockManager()::getNextPhaseBlocks)
Expand Down Expand Up @@ -181,7 +237,7 @@ public String getPhaseBlocks(User user) {
* @return string percentage
*/
public String getPercentDoneByLocation(User user) {
if (user == null || user.getUniqueId() == null)
if (user == null || user.getUniqueId() == null || !addon.inWorld(user.getWorld()))
return "";
return addon.getIslands().getProtectedIslandAt(Objects.requireNonNull(user.getLocation()))
.map(addon::getOneBlocksIsland).map(addon.getOneBlockManager()::getPercentageDone)
Expand Down Expand Up @@ -212,7 +268,7 @@ public String getPercentDone(User user) {
* @return colored scale
*/
public String getDoneScaleByLocation(User user) {
if (user == null || user.getUniqueId() == null)
if (user == null || user.getUniqueId() == null || !addon.inWorld(user.getWorld()))
return "";
return addon.getIslands().getProtectedIslandAt(Objects.requireNonNull(user.getLocation()))
.map(addon::getOneBlocksIsland).map(addon.getOneBlockManager()::getPercentageDone)
Expand Down Expand Up @@ -259,7 +315,7 @@ public String getLifetime(User user) {
* @return String of Lifetime
*/
public String getLifetimeByLocation(User user) {
if (user == null || user.getUniqueId() == null)
if (user == null || user.getUniqueId() == null || !addon.inWorld(user.getWorld()))
return "";

return this.addon.getIslands().getProtectedIslandAt(Objects.requireNonNull(user.getLocation()))
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/world/bentobox/aoneblock/AOneBlockPladdon.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@

public class AOneBlockPladdon extends Pladdon {

private Addon addon;

@Override
public Addon getAddon() {
return new AOneBlock();
if (addon == null) {
addon = new AOneBlock();
}

return addon;
}
}
37 changes: 37 additions & 0 deletions src/main/java/world/bentobox/aoneblock/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public class Settings implements WorldSettings {
@ConfigEntry(path = "world.holograms")
private boolean useHolograms = true;

@ConfigComment("Hologram position - the offset to the magic block where holograms will appear")
@ConfigEntry(path = "world.hologram-offset")
private String offset = "0.5, 1.1, 0.5";

@ConfigComment("Duration in seconds that phase holograms will exist after being displayed, if used.")
@ConfigComment("If set to 0, then holograms will persist until cleared some other way.")
@ConfigEntry(path = "world.hologram-duration")
Expand Down Expand Up @@ -192,6 +196,10 @@ public class Settings implements WorldSettings {
@ConfigEntry(path = "world.island-height")
private int islandHeight = 120;

@ConfigComment("Disallow team members from having their own islands.")
@ConfigEntry(path = "world.disallow-team-member-islands")
private boolean disallowTeamMemberIslands = false;

@ConfigComment("Use your own world generator for this world.")
@ConfigComment("In this case, the plugin will not generate anything.")
@ConfigComment("If used, you must specify the world name and generator in the bukkit.yml file.")
Expand Down Expand Up @@ -2176,4 +2184,33 @@ public String getClickType() {
public void setClickType(String clickType) {
this.clickType = clickType;
}

/**
* @return the disallowTeamMemberIslands
*/
@Override
public boolean isDisallowTeamMemberIslands() {
return disallowTeamMemberIslands;
}

/**
* @param disallowTeamMemberIslands the disallowTeamMemberIslands to set
*/
public void setDisallowTeamMemberIslands(boolean disallowTeamMemberIslands) {
this.disallowTeamMemberIslands = disallowTeamMemberIslands;
}

/**
* @return the offset
*/
public String getOffset() {
return offset;
}

/**
* @param offset the offset to set
*/
public void setOffset(String offset) {
this.offset = offset;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ protected boolean phaseRequirementsFail(@Nullable Player player, @NonNull Island
return false;
}

if (player == null) {
// Minions cannot fulfill requirements
return true;
}
return phase.getRequirements().stream()
.anyMatch(r -> checkRequirement(r, User.getInstance(player), i, is, world));
}
Expand Down Expand Up @@ -206,7 +210,8 @@ List<String> replacePlaceholders(@Nullable Player player, @NonNull String phaseN
.map(l -> ((Level) l).getIslandLevel(addon.getOverWorld(), i.getOwner())).orElse(0L);
double balance = addon.getAddonByName("Bank").map(b -> ((Bank) b).getBankManager().getBalance(i).getValue())
.orElse(0D);
double ecoBalance = addon.getPlugin().getVault()
double ecoBalance = player == null ? 0D
: addon.getPlugin().getVault()
.map(v -> v.getBalance(User.getInstance(player), addon.getOverWorld())).orElse(0D);

return c.replace("[island]", i.getName() == null ? "" : i.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull;

import world.bentobox.aoneblock.AOneBlock;
Expand Down Expand Up @@ -50,7 +51,7 @@ private Optional<TextDisplay> getHologram(Island island) {
}

private TextDisplay createHologram(Island island) {
Location pos = island.getCenter().clone().add(0.5, 1.1, 0.5);
Location pos = island.getCenter().clone().add(parseVector(addon.getSettings().getOffset()));
World world = pos.getWorld();
assert world != null;

Expand All @@ -63,6 +64,25 @@ private TextDisplay createHologram(Island island) {
return newDisplay;
}

private static Vector parseVector(String str) {
if (str == null) {
return new Vector(0.5, 1.1, 0.5);
}
String[] parts = str.split(",");
if (parts.length != 3) {
return new Vector(0.5, 1.1, 0.5);
}

try {
double x = Double.parseDouble(parts[0].trim());
double y = Double.parseDouble(parts[1].trim());
double z = Double.parseDouble(parts[2].trim());
return new Vector(x, y, z);
} catch (NumberFormatException e) {
return new Vector(0.5, 1.1, 0.5);
}
}

private void clearIfInitialized(TextDisplay hologram) {
if (hologram.isValid()) {
hologram.remove();
Expand Down
Loading

0 comments on commit bac04f0

Please sign in to comment.