Skip to content

Commit bac04f0

Browse files
authored
Merge pull request #395 from BentoBoxWorld/develop
Release 1.17.0
2 parents 14b10b4 + 76c5214 commit bac04f0

File tree

12 files changed

+291
-38
lines changed

12 files changed

+291
-38
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@
5959
<powermock.version>2.0.9</powermock.version>
6060
<!-- More visible way how to change dependency versions -->
6161
<spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version>
62-
<bentobox.version>2.0.0-SNAPSHOT</bentobox.version>
62+
<bentobox.version>2.3.0-SNAPSHOT</bentobox.version>
6363
<level.version>2.6.2</level.version>
6464
<bank.version>1.3.0</bank.version>
6565
<!-- Revision variable removes warning about dynamic version -->
6666
<revision>${build.version}-SNAPSHOT</revision>
6767
<!-- Do not change unless you want different name for local builds. -->
6868
<build.number>-LOCAL</build.number>
6969
<!-- This allows to change between versions. -->
70-
<build.version>1.16.0</build.version>
70+
<build.version>1.17.0</build.version>
7171
<!-- SonarCloud -->
7272
<sonar.projectKey>BentoBoxWorld_AOneBlock</sonar.projectKey>
7373
<sonar.organization>bentobox-world</sonar.organization>

src/main/java/world/bentobox/aoneblock/AOneBlockPlaceholders.java

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
package world.bentobox.aoneblock;
22

33
import java.util.Objects;
4+
import java.util.Set;
45
import java.util.TreeMap;
6+
import java.util.stream.Collectors;
7+
8+
import org.bukkit.Material;
59

610
import world.bentobox.aoneblock.dataobjects.OneBlockIslands;
11+
import world.bentobox.aoneblock.panels.PhasesPanel;
12+
import world.bentobox.bentobox.api.localization.TextVariables;
713
import world.bentobox.bentobox.api.user.User;
814
import world.bentobox.bentobox.database.objects.Island;
15+
import world.bentobox.bentobox.hooks.LangUtilsHook;
16+
import world.bentobox.bentobox.util.Util;
917

1018
public class AOneBlockPlaceholders {
1119

@@ -46,6 +54,54 @@ public AOneBlockPlaceholders(AOneBlock addon,
4654
// Since 1.10
4755
placeholdersManager.registerPlaceholder(addon, "visited_island_lifetime_count", this::getLifetimeByLocation);
4856
placeholdersManager.registerPlaceholder(addon, "my_island_lifetime_count", this::getLifetime);
57+
58+
placeholdersManager.registerPlaceholder(addon, "visited_island_phase_block_list",
59+
this::getPhaseBlocksNamesByLocation);
60+
placeholdersManager.registerPlaceholder(addon, "my_island_phase_block_list", this::getPhaseBlocksNames);
61+
62+
}
63+
64+
public String getPhaseBlocksNames(User user) {
65+
if (user == null || user.getUniqueId() == null)
66+
return "";
67+
Island i = addon.getIslands().getIsland(addon.getOverWorld(), user);
68+
if (i == null) {
69+
return "";
70+
}
71+
return getPhaseBlocksForIsland(user, i);
72+
}
73+
74+
private String getPhaseBlocksForIsland(User user, Island i) {
75+
String phaseName = addon.getOneBlocksIsland(i).getPhaseName();
76+
Set<Material> set = addon.getOneBlockManager().getPhase(phaseName).map(phase -> phase.getBlocks().keySet())
77+
.orElse(null);
78+
if (set == null) {
79+
return "";
80+
}
81+
82+
String result = set.stream().map(m -> getMaterialName(user, m))
83+
.map(string -> user.getTranslation(PhasesPanel.REFERENCE + "blocks", TextVariables.NAME,
84+
string))
85+
.collect(Collectors.joining());
86+
// Removing the last newline character or comma if it exists
87+
result = result.trim();
88+
if (result.endsWith("\n") || result.endsWith(",")) {
89+
result = result.substring(0, result.length() - 1);
90+
}
91+
92+
return result;
93+
94+
}
95+
96+
private String getMaterialName(User user, Material m) {
97+
return addon.getPlugin().getHooks().getHook("LangUtils").map(hook -> LangUtilsHook.getMaterialName(m, user))
98+
.orElse(Util.prettifyText(m.name()));
99+
}
100+
101+
public String getPhaseBlocksNamesByLocation(User user) {
102+
if (user == null || user.getUniqueId() == null || !addon.inWorld(user.getWorld()))
103+
return "";
104+
return addon.getIslands().getIslandAt(user.getLocation()).map(i -> getPhaseBlocksForIsland(user, i)).orElse("");
49105
}
50106

51107
/**
@@ -68,7 +124,7 @@ public String getPhaseByLocation(User user) {
68124
* @return String of count
69125
*/
70126
public String getCountByLocation(User user) {
71-
if (user == null || user.getUniqueId() == null)
127+
if (user == null || user.getUniqueId() == null || !addon.inWorld(user.getWorld()))
72128
return "";
73129
return addon.getIslands().getProtectedIslandAt(Objects.requireNonNull(user.getLocation()))
74130
.map(addon::getOneBlocksIsland).map(OneBlockIslands::getBlockNumber).map(String::valueOf).orElse("");
@@ -107,7 +163,7 @@ public String getCount(User user) {
107163
* @return next phase
108164
*/
109165
public String getNextPhaseByLocation(User user) {
110-
if (user == null || user.getUniqueId() == null)
166+
if (user == null || user.getUniqueId() == null || !addon.inWorld(user.getWorld()))
111167
return "";
112168
return addon.getIslands().getProtectedIslandAt(Objects.requireNonNull(user.getLocation()))
113169
.map(addon::getOneBlocksIsland).map(addon.getOneBlockManager()::getNextPhase).orElse("");
@@ -133,7 +189,7 @@ public String getNextPhase(User user) {
133189
* @return string number of blocks
134190
*/
135191
public String getNextPhaseBlocksByLocation(User user) {
136-
if (user == null || user.getUniqueId() == null)
192+
if (user == null || user.getUniqueId() == null || !addon.inWorld(user.getWorld()))
137193
return "";
138194
return addon.getIslands().getProtectedIslandAt(Objects.requireNonNull(user.getLocation()))
139195
.map(addon::getOneBlocksIsland).map(addon.getOneBlockManager()::getNextPhaseBlocks)
@@ -181,7 +237,7 @@ public String getPhaseBlocks(User user) {
181237
* @return string percentage
182238
*/
183239
public String getPercentDoneByLocation(User user) {
184-
if (user == null || user.getUniqueId() == null)
240+
if (user == null || user.getUniqueId() == null || !addon.inWorld(user.getWorld()))
185241
return "";
186242
return addon.getIslands().getProtectedIslandAt(Objects.requireNonNull(user.getLocation()))
187243
.map(addon::getOneBlocksIsland).map(addon.getOneBlockManager()::getPercentageDone)
@@ -212,7 +268,7 @@ public String getPercentDone(User user) {
212268
* @return colored scale
213269
*/
214270
public String getDoneScaleByLocation(User user) {
215-
if (user == null || user.getUniqueId() == null)
271+
if (user == null || user.getUniqueId() == null || !addon.inWorld(user.getWorld()))
216272
return "";
217273
return addon.getIslands().getProtectedIslandAt(Objects.requireNonNull(user.getLocation()))
218274
.map(addon::getOneBlocksIsland).map(addon.getOneBlockManager()::getPercentageDone)
@@ -259,7 +315,7 @@ public String getLifetime(User user) {
259315
* @return String of Lifetime
260316
*/
261317
public String getLifetimeByLocation(User user) {
262-
if (user == null || user.getUniqueId() == null)
318+
if (user == null || user.getUniqueId() == null || !addon.inWorld(user.getWorld()))
263319
return "";
264320

265321
return this.addon.getIslands().getProtectedIslandAt(Objects.requireNonNull(user.getLocation()))

src/main/java/world/bentobox/aoneblock/AOneBlockPladdon.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55

66
public class AOneBlockPladdon extends Pladdon {
77

8+
private Addon addon;
9+
810
@Override
911
public Addon getAddon() {
10-
return new AOneBlock();
12+
if (addon == null) {
13+
addon = new AOneBlock();
14+
}
15+
16+
return addon;
1117
}
1218
}

src/main/java/world/bentobox/aoneblock/Settings.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ public class Settings implements WorldSettings {
107107
@ConfigEntry(path = "world.holograms")
108108
private boolean useHolograms = true;
109109

110+
@ConfigComment("Hologram position - the offset to the magic block where holograms will appear")
111+
@ConfigEntry(path = "world.hologram-offset")
112+
private String offset = "0.5, 1.1, 0.5";
113+
110114
@ConfigComment("Duration in seconds that phase holograms will exist after being displayed, if used.")
111115
@ConfigComment("If set to 0, then holograms will persist until cleared some other way.")
112116
@ConfigEntry(path = "world.hologram-duration")
@@ -192,6 +196,10 @@ public class Settings implements WorldSettings {
192196
@ConfigEntry(path = "world.island-height")
193197
private int islandHeight = 120;
194198

199+
@ConfigComment("Disallow team members from having their own islands.")
200+
@ConfigEntry(path = "world.disallow-team-member-islands")
201+
private boolean disallowTeamMemberIslands = false;
202+
195203
@ConfigComment("Use your own world generator for this world.")
196204
@ConfigComment("In this case, the plugin will not generate anything.")
197205
@ConfigComment("If used, you must specify the world name and generator in the bukkit.yml file.")
@@ -2176,4 +2184,33 @@ public String getClickType() {
21762184
public void setClickType(String clickType) {
21772185
this.clickType = clickType;
21782186
}
2187+
2188+
/**
2189+
* @return the disallowTeamMemberIslands
2190+
*/
2191+
@Override
2192+
public boolean isDisallowTeamMemberIslands() {
2193+
return disallowTeamMemberIslands;
2194+
}
2195+
2196+
/**
2197+
* @param disallowTeamMemberIslands the disallowTeamMemberIslands to set
2198+
*/
2199+
public void setDisallowTeamMemberIslands(boolean disallowTeamMemberIslands) {
2200+
this.disallowTeamMemberIslands = disallowTeamMemberIslands;
2201+
}
2202+
2203+
/**
2204+
* @return the offset
2205+
*/
2206+
public String getOffset() {
2207+
return offset;
2208+
}
2209+
2210+
/**
2211+
* @param offset the offset to set
2212+
*/
2213+
public void setOffset(String offset) {
2214+
this.offset = offset;
2215+
}
21792216
}

src/main/java/world/bentobox/aoneblock/listeners/CheckPhase.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ protected boolean phaseRequirementsFail(@Nullable Player player, @NonNull Island
108108
return false;
109109
}
110110

111+
if (player == null) {
112+
// Minions cannot fulfill requirements
113+
return true;
114+
}
111115
return phase.getRequirements().stream()
112116
.anyMatch(r -> checkRequirement(r, User.getInstance(player), i, is, world));
113117
}
@@ -206,7 +210,8 @@ List<String> replacePlaceholders(@Nullable Player player, @NonNull String phaseN
206210
.map(l -> ((Level) l).getIslandLevel(addon.getOverWorld(), i.getOwner())).orElse(0L);
207211
double balance = addon.getAddonByName("Bank").map(b -> ((Bank) b).getBankManager().getBalance(i).getValue())
208212
.orElse(0D);
209-
double ecoBalance = addon.getPlugin().getVault()
213+
double ecoBalance = player == null ? 0D
214+
: addon.getPlugin().getVault()
210215
.map(v -> v.getBalance(User.getInstance(player), addon.getOverWorld())).orElse(0D);
211216

212217
return c.replace("[island]", i.getName() == null ? "" : i.getName())

src/main/java/world/bentobox/aoneblock/listeners/HoloListener.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.bukkit.event.EventHandler;
1414
import org.bukkit.event.EventPriority;
1515
import org.bukkit.event.Listener;
16+
import org.bukkit.util.Vector;
1617
import org.eclipse.jdt.annotation.NonNull;
1718

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

5253
private TextDisplay createHologram(Island island) {
53-
Location pos = island.getCenter().clone().add(0.5, 1.1, 0.5);
54+
Location pos = island.getCenter().clone().add(parseVector(addon.getSettings().getOffset()));
5455
World world = pos.getWorld();
5556
assert world != null;
5657

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

67+
private static Vector parseVector(String str) {
68+
if (str == null) {
69+
return new Vector(0.5, 1.1, 0.5);
70+
}
71+
String[] parts = str.split(",");
72+
if (parts.length != 3) {
73+
return new Vector(0.5, 1.1, 0.5);
74+
}
75+
76+
try {
77+
double x = Double.parseDouble(parts[0].trim());
78+
double y = Double.parseDouble(parts[1].trim());
79+
double z = Double.parseDouble(parts[2].trim());
80+
return new Vector(x, y, z);
81+
} catch (NumberFormatException e) {
82+
return new Vector(0.5, 1.1, 0.5);
83+
}
84+
}
85+
6686
private void clearIfInitialized(TextDisplay hologram) {
6787
if (hologram.isValid()) {
6888
hologram.remove();

0 commit comments

Comments
 (0)