Skip to content

Commit

Permalink
Merge pull request #2467 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Version 2.5.0
  • Loading branch information
tastybento authored Aug 12, 2024
2 parents 037e66f + 5df1965 commit 3ee840f
Show file tree
Hide file tree
Showing 29 changed files with 321 additions and 85 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>2.4.2</build.version>
<build.version>2.5.0</build.version>
<sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<server.jars>${project.basedir}/lib</server.jars>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ void unregisterIsland(User user) {
targetIsland.getMemberSet().forEach(m -> getIslands().removePlayer(targetIsland, m));
// Remove all island players that reference this island
targetIsland.getMembers().clear();
targetIsland.log(new LogEntry.Builder("UNREGISTER").data("player", targetUUID.toString())
.data("admin", user.getUniqueId().toString()).build());
if (user.isPlayer()) {
targetIsland.log(new LogEntry.Builder("UNREGISTER").data("player", targetUUID.toString())
.data("admin", user.getUniqueId().toString()).build());
} else {
targetIsland.log(new LogEntry.Builder("UNREGISTER").data("player", targetUUID.toString())
.data("admin", "console").build());
}
user.sendMessage("commands.admin.unregister.unregistered-island", TextVariables.XYZ, Util.xyz(targetIsland.getCenter().toVector()),
TextVariables.NAME, getPlayers().getName(targetUUID));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void onIslandDeleted(IslandDeletedEvent e) {
*/
Set<String> getOldIslands(int days) {
long currentTimeMillis = System.currentTimeMillis();
double daysInMilliseconds = days * 1000 * 3600 * 24;
long daysInMilliseconds = (long) days * 1000 * 3600 * 24;
Set<String> oldIslands = new HashSet<>();

// Process islands in one pass, logging and adding to the set if applicable
Expand Down
71 changes: 68 additions & 3 deletions src/main/java/world/bentobox/bentobox/api/flags/Flag.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,25 @@ public boolean isGreaterThan(Mode rank) {
}
}

/**
* Options for hiding of sub flags
* @since 2.4.3
*/
public enum HideWhen {
/**
* Never hide sub-flags
*/
NEVER,
/**
* Hide subflags if the setting of the parent flag is true
*/
SETTING_TRUE,
/**
* Hide subflags if the setting of the parent flag is false
*/
SETTING_FALSE
}

private static final String PROTECTION_FLAGS = "protection.flags.";

private final String id;
Expand All @@ -131,6 +150,9 @@ public boolean isGreaterThan(Mode rank) {
private final int cooldown;
private final Mode mode;
private final Set<Flag> subflags;
private final HideWhen hideWhen;
private boolean isSubFlag;
private Flag parentFlag;

private Flag(Builder builder) {
this.id = builder.id;
Expand All @@ -148,6 +170,9 @@ private Flag(Builder builder) {
this.addon = builder.addon;
this.mode = builder.mode;
this.subflags = builder.subflags;
this.hideWhen = builder.hideWhen;
this.isSubFlag = false;
this.parentFlag = null;
}

public String getID() {
Expand Down Expand Up @@ -276,6 +301,28 @@ public Addon getAddon() {
return addon;
}

/**
* Get when sub-flags should be hidden
* @return
*/
public HideWhen getHideWhen() {
return hideWhen;
}

/**
* @return the isSubFlag
*/
public boolean isSubFlag() {
return isSubFlag;
}

/**
* @return the parentFlag
*/
public Flag getParentFlag() {
return parentFlag;
}

/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
Expand Down Expand Up @@ -553,6 +600,9 @@ public static class Builder {
// Subflags
private final Set<Flag> subflags;

// Hide when indicator
private HideWhen hideWhen = HideWhen.NEVER;

/**
* Builder for making flags
* @param id - a unique id that MUST be the same as the enum of the flag
Expand Down Expand Up @@ -679,6 +729,21 @@ public Builder mode(Mode mode) {
*/
public Builder subflags(Flag... flags) {
this.subflags.addAll(Arrays.asList(flags));
for (Flag flag : flags) {
flag.isSubFlag = true;
}
return this;
}

/**
* When should sub-flags be hidden, if ever
* {@see HideWhen}
* @param hideWhen hide when indicator
* @return Builder - flag builder
* @since 2.4.3
*/
public Builder hideWhen(HideWhen hideWhen) {
this.hideWhen = hideWhen;
return this;
}

Expand All @@ -695,9 +760,9 @@ public Flag build() {
default -> new CycleClick(id);
};
}

return new Flag(this);
Flag flag = new Flag(this);
subflags.forEach(subflag -> subflag.parentFlag = flag);
return flag;
}
}

}
16 changes: 12 additions & 4 deletions src/main/java/world/bentobox/bentobox/api/panels/PanelItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,18 @@ public void setGlow(boolean glow) {
return;
}
if (meta != null) {
if (glow) {
meta.addEnchant(Enchantment.LURE, 0, glow);
} else {
meta.removeEnchant(Enchantment.LURE);
try {
meta.setEnchantmentGlintOverride(glow);
} catch (NoSuchMethodError e) {
// Try the old way
if (meta != null) {
if (glow) {
meta.addEnchant(Enchantment.LURE, 0, glow);
} else {
meta.removeEnchant(Enchantment.LURE);
}
icon.setItemMeta(meta);
}
}
icon.setItemMeta(meta);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ public void onPlayerJoin(final PlayerJoinEvent event) {

// Add a player to the bStats cache.
plugin.getMetrics().ifPresent(bStats -> bStats.addPlayer(playerUUID));

// Create onIsland placeholders
plugin.getAddonsManager().getGameModeAddons().forEach(addon -> {
plugin.getPlaceholdersManager()
.registerPlaceholder(addon, "onisland_" + user.getName(), asker -> {
if (asker == null) {
return "";
}
// Get the user who this applies to
User named = User.getInstance(user.getUniqueId());
if (named.isOnline()) {
return plugin.getIslands().getIslands(addon.getOverWorld(), asker).stream()
.filter(island -> island.onIsland(named.getLocation())).findFirst().map(i -> "true")
.orElse("false");
}
return "false";
});
});
}

private void firstTime(User user) {
Expand Down Expand Up @@ -237,6 +255,9 @@ public void onPlayerQuit(final PlayerQuitEvent event) {
});
// Remove any coop associations from the player logging out
plugin.getIslands().clearRank(RanksManager.COOP_RANK, event.getPlayer().getUniqueId());
// Remove any onisland placeholder
plugin.getAddonsManager().getGameModeAddons().forEach(addon -> plugin.getPlaceholdersManager()
.unregisterPlaceholder(addon, "onisland_" + event.getPlayer().getName()));
User.removePlayer(event.getPlayer());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/**
* Common Game Mode Placeholders
* All of these are prefixed with the game mode's name, e.g., bskykblock_
*/
public enum GameModePlaceholder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,15 @@ public void deleteIslandFromCache(@NonNull Island island) {
}

private void removeFromIslandsByUUID(Island island) {
for (Set<String> set : islandsByUUID.values()) {
Iterator<Map.Entry<UUID, Set<String>>> iterator = islandsByUUID.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<UUID, Set<String>> entry = iterator.next();
Set<String> set = entry.getValue();
set.removeIf(island.getUniqueId()::equals);
if (set.isEmpty()) {
// Removes the overall entry if there is nothing left in the set
iterator.remove();
}
}
}

Expand Down Expand Up @@ -538,7 +545,9 @@ public Set<String> getAllIslandIds() {
* @return list of islands
*/
public @NonNull List<Island> getIslands(UUID uniqueId) {
return islandsByUUID.getOrDefault(uniqueId, Collections.emptySet()).stream().map(this::getIslandById).toList();
return islandsByUUID.getOrDefault(uniqueId, Collections.emptySet()).stream().map(this::getIslandById)
.filter(Objects::nonNull) // Filter out null values
.toList();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package world.bentobox.bentobox.nms.v1_21_1_R0_1_SNAPSHOT;

/**
* Same as 1.21
*/
public class PasteHandlerImpl extends world.bentobox.bentobox.nms.v1_21_R0_1_SNAPSHOT.PasteHandlerImpl {
// Do nothing special
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package world.bentobox.bentobox.nms.v1_21_1_R0_1_SNAPSHOT;

/**
* Same as 1.21
*/
public class WorldRegeneratorImpl extends world.bentobox.bentobox.nms.v1_21_R0_1_SNAPSHOT.WorldRegeneratorImpl {
// Do nothing special
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

Expand All @@ -17,6 +19,7 @@

import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.api.flags.Flag.HideWhen;
import world.bentobox.bentobox.api.flags.Flag.Mode;
import world.bentobox.bentobox.api.flags.Flag.Type;
import world.bentobox.bentobox.api.localization.TextVariables;
Expand Down Expand Up @@ -131,10 +134,24 @@ public String getName() {
currentMode.put(user.getUniqueId(), currentMode.getOrDefault(user.getUniqueId(), Mode.BASIC).getNext());
flags = getFlags();
}
// Remove any sub-flags that shouldn't be shown
Set<Flag> toBeRemoved = new HashSet<>();
flags.forEach(flag -> {
if (flag.isSubFlag() && flag.getHideWhen() != HideWhen.NEVER) {
if (!flag.getParentFlag().isSetForWorld(world) && flag.getHideWhen() == HideWhen.SETTING_FALSE) {
toBeRemoved.add(flag);
} else if (flag.getParentFlag().isSetForWorld(world) && flag.getHideWhen() == HideWhen.SETTING_TRUE) {
toBeRemoved.add(flag);
}
}
});
flags.removeAll(toBeRemoved);

List<@Nullable PanelItem> result = flags.stream().map(
(f -> f.toPanelItem(plugin, user, world, island,
plugin.getIWM().getHiddenFlags(world).contains(f.getID()))))
.toList();

return result;
}

Expand Down
21 changes: 8 additions & 13 deletions src/main/java/world/bentobox/bentobox/util/ItemParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*
* @author tastybento, Poslovitch
*/
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public class ItemParser {

private ItemParser() {} // private constructor to hide the implicit public one.
Expand Down Expand Up @@ -333,7 +333,7 @@ private static ItemStack parsePotion(String[] part) {
* @param part String array that contains at least 2 elements.
* @return Banner as item stack.
*/
private static ItemStack parseBanner(String[] part) {
static ItemStack parseBanner(String[] part) {
if (part.length >= 2) {
Material bannerMat = Material.getMaterial(part[0]);
if (bannerMat == null) {
Expand All @@ -345,18 +345,13 @@ private static ItemStack parseBanner(String[] part) {
BannerMeta meta = (BannerMeta) result.getItemMeta();
if (meta != null) {
for (int i = 2; i < part.length; i += 2) {
PatternType pt = Enums.getIfPresent(PatternType.class, part[i]).orNull();
if (pt == null) {
// Try to convert old to new
if (part[i].trim().equals("STRIPE_SMALL")
&& Enums.getIfPresent(PatternType.class, "SMALL_STRIPES").isPresent()) {
pt = PatternType.SMALL_STRIPES;
//if (!Util.inTest()) {
PatternType pt = PatternType.valueOf(part[i]);
DyeColor dc = Enums.getIfPresent(DyeColor.class, part[i + 1]).orNull();
if (dc != null) {
meta.addPattern(new Pattern(dc, pt));
}
}
DyeColor dc = Enums.getIfPresent(DyeColor.class, part[i + 1]).orNull();
if (pt != null && dc != null) {
meta.addPattern(new Pattern(dc, pt));
}
//}
}
result.setItemMeta(meta);
}
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/world/bentobox/bentobox/util/heads/HeadCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ public HeadCache(String userName, UUID userId, PlayerProfile playerProfile)
* @param timestamp of type long
*/
public HeadCache(String userName,
UUID userId,
PlayerProfile playerProfile,
long timestamp)
UUID userId, PlayerProfile playerProfile, long timestamp)
{
this.userName = userName;
this.playerProfile = playerProfile;
Expand Down Expand Up @@ -99,8 +97,12 @@ public ItemStack getPlayerHead()
// Set correct Skull texture
if (meta != null && this.playerProfile != null)
{
meta.setOwnerProfile(this.playerProfile);
item.setItemMeta(meta);
try {
meta.setOwnerProfile(this.playerProfile);
item.setItemMeta(meta);
} catch (Exception e) {
// Do nothing - there was an error getting the head
}
}

return item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@ public enum ServerVersion {
/**
* @since 2.4.0
*/
V1_21(Compatibility.COMPATIBLE);
V1_21(Compatibility.COMPATIBLE),
/**
* @since 2.5.0
*/
V1_21_1(Compatibility.COMPATIBLE);

private final Compatibility compatibility;

Expand Down
Loading

0 comments on commit 3ee840f

Please sign in to comment.