Skip to content

Commit 67f0a4f

Browse files
authored
Added chunk update messages when player config is empty.
1 parent ea61c61 commit 67f0a4f

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

fake-block-api/src/main/java/com/briarcraft/fakeblock/api/data/Group.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,16 @@ public class Group implements Comparable<Group>, ConfigurationSerializable {
4242
@SuppressWarnings("unused")
4343
public static @Nonnull Group deserialize(final @Nonnull Map<String, Object> args) {
4444
val name = (String) args.get(ARG_NAME);
45-
val world = Bukkit.getWorld((String) args.get(ARG_WORLD));
46-
val fakeBlocks = ((List<FakeBlock>) args.get(ARG_BLOCKS)).stream().collect(Collectors.toSet());
45+
val worldName = (String) args.get(ARG_WORLD);
46+
val world = Bukkit.getWorld(worldName);
47+
val fakeBlocks = ((List<?>) args.get(ARG_BLOCKS)).stream()
48+
.filter(FakeBlock.class::isInstance)
49+
.map(FakeBlock.class::cast)
50+
.collect(Collectors.toSet());
4751
val isShowDefault = (Boolean) args.get(ARG_SHOW_DEFAULT);
4852

53+
if (world == null) throw new IllegalStateException("World '" + worldName + "' was not found!");
54+
4955
val group = new Group(name, world, fakeBlocks);
5056
group.setShownByDefault(isShowDefault);
5157
return group;

fake-block/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
id("com.github.johnrengelman.shadow")
77
}
88

9-
version = "2.0.0"
9+
version = "2.0.1"
1010
description = ""
1111

1212
dependencies {

fake-block/src/main/java/com/briarcraft/fakeblock/FakeBlockCommand.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import net.kyori.adventure.text.format.NamedTextColor;
1414
import net.kyori.adventure.text.format.Style;
1515
import org.bukkit.Bukkit;
16-
import org.bukkit.Material;
1716
import org.bukkit.OfflinePlayer;
1817
import org.bukkit.command.*;
1918
import org.bukkit.entity.Player;

fake-block/src/main/java/com/briarcraft/fakeblock/data/PlayerGroup.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import javax.annotation.Nonnull;
99
import java.util.*;
10+
import java.util.stream.Collectors;
1011

1112
@SerializableAs("PlayerGroup")
1213
@Data
@@ -29,7 +30,10 @@ public class PlayerGroup implements Comparable<PlayerGroup>, ConfigurationSerial
2930
@SuppressWarnings("unused")
3031
public static @Nonnull PlayerGroup deserialize(final @Nonnull Map<String, Object> args) {
3132
val playerId = UUID.fromString((String) args.get(ARG_PLAYER_ID));
32-
val groupNames = (Map<String, Boolean>) args.get(ARG_GROUPS);
33+
val groupNames = ((Map<?, ?>) args.get(ARG_GROUPS)).entrySet().stream()
34+
.filter(entry -> entry.getKey() instanceof String)
35+
.filter(entry -> entry.getValue() instanceof Boolean)
36+
.collect(Collectors.toMap(entry -> (String) entry.getKey(), entry -> (Boolean) entry.getValue()));
3337
return new PlayerGroup(playerId, groupNames);
3438
}
3539

fake-block/src/main/java/com/briarcraft/fakeblock/service/PlayerGroupServiceImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ public boolean showGroup(final @Nonnull String groupName, final @Nonnull Offline
8787
newGroups.put(groupName, true);
8888
playerGroups.put(playerId, newGroups);
8989
playerGroupConfig.save(generatePlayerGroups());
90+
91+
if (offlinePlayer instanceof Player player) {
92+
groupService.getChunklets(groupName, player.getWorld())
93+
.forEach(chunklet -> protocolLibService.sendChunklet(player, chunklet));
94+
}
9095
return true;
9196
} else {
9297
var isShown = false;
@@ -127,6 +132,11 @@ public boolean hideGroup(final @Nonnull String groupName, final @Nonnull Offline
127132
newGroups.put(groupName, false);
128133
playerGroups.put(playerId, newGroups);
129134
playerGroupConfig.save(generatePlayerGroups());
135+
136+
if (offlinePlayer instanceof Player player) {
137+
groupService.getChunklets(groupName, player.getWorld())
138+
.forEach(chunklet -> protocolLibService.sendChunklet(player, chunklet, Material.AIR));
139+
}
130140
return true;
131141
} else {
132142
var isHidden = false;

0 commit comments

Comments
 (0)