-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Opening an chest/inventory now opens all other instances of that inve…
…ntory in game for all players cleanup
- Loading branch information
kyrptonaught
committed
Dec 30, 2019
1 parent
76f14ee
commit 80d5c71
Showing
16 changed files
with
135 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/net/kyrptonaught/linkedstorage/network/ChannelViewers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package net.kyrptonaught.linkedstorage.network; | ||
|
||
import net.fabricmc.fabric.api.event.server.ServerTickCallback; | ||
import net.kyrptonaught.linkedstorage.inventory.LinkedContainer; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.server.MinecraftServer; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.UUID; | ||
|
||
public class ChannelViewers { | ||
private static HashMap<String, HashSet<String>> viewers = new HashMap<>(); | ||
|
||
public static Boolean getViewersFor(String channel) { | ||
if (!viewers.containsKey(channel)) return false; | ||
return viewers.get(channel).size() > 0; | ||
} | ||
|
||
static void addViewerFor(String channel, String uuid) { | ||
if (!viewers.containsKey(channel)) viewers.put(channel, new HashSet<>()); | ||
viewers.get(channel).add(uuid); | ||
} | ||
|
||
public static void addViewerFor(String channel, PlayerEntity player) { | ||
addViewerFor(channel, player.getUuidAsString()); | ||
if (!player.world.isClient) | ||
UpdateViewerList.sendPacket(player.getServer(), channel, player.getUuid(), true); | ||
} | ||
|
||
static void removeViewerFor(String channel, String player) { | ||
viewers.getOrDefault(channel, new HashSet<>()).remove(player); | ||
} | ||
|
||
private static void removeViewerForServer(String channel, String player, MinecraftServer server) { | ||
removeViewerFor(channel, player); | ||
UpdateViewerList.sendPacket(server, channel, UUID.fromString(player), false); | ||
} | ||
|
||
public static void registerChannelWatcher() { | ||
ServerTickCallback.EVENT.register(server -> { | ||
for (String channel : ChannelViewers.viewers.keySet()) | ||
for (String uuid : ChannelViewers.viewers.get(channel)) { | ||
PlayerEntity player = server.getPlayerManager().getPlayer(UUID.fromString(uuid)); | ||
if (player == null || !(player.container instanceof LinkedContainer)) { | ||
removeViewerForServer(channel, uuid, server); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.