-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathInfoAction.java
More file actions
44 lines (37 loc) · 1.76 KB
/
InfoAction.java
File metadata and controls
44 lines (37 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.github.fabricservertools.htm.interactions;
import com.github.fabricservertools.htm.HTM;
import com.github.fabricservertools.htm.lock.HTMContainerLock;
import com.github.fabricservertools.htm.HTMComponents;
import com.github.fabricservertools.htm.Utility;
import com.github.fabricservertools.htm.api.LockInteraction;
import com.github.fabricservertools.htm.api.LockableObject;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.NameAndId;
import java.util.Optional;
import java.util.stream.Collectors;
public class InfoAction implements LockInteraction {
@Override
public void execute(MinecraftServer server, ServerPlayer player, BlockPos pos, LockableObject object, HTMContainerLock lock) {
Optional<NameAndId> owner = server.services().nameToIdCache().get(lock.owner());
if (owner.isEmpty()) {
HTM.LOGGER.error("Can't find lock owner: {}", lock.owner());
return;
}
player.sendSystemMessage(HTMComponents.DIVIDER);
player.sendSystemMessage(HTMComponents.CONTAINER_LOCK_TYPE.apply(lock.lockData().displayName()));
player.sendSystemMessage(HTMComponents.CONTAINER_OWNER.apply(Component.literal(owner.get().name()).withStyle(ChatFormatting.WHITE)));
if (lock.isOwner(player)) {
String trustedList = lock.trusted()
.stream()
.map(uuid -> Utility.getNameFromUUID(uuid, server))
.collect(Collectors.joining(", "));
player.sendSystemMessage(HTMComponents.CONTAINER_TRUSTED.apply(Component.literal(trustedList).withStyle(ChatFormatting.WHITE)));
lock.lockData().onInfo(player, lock);
}
player.sendSystemMessage(HTMComponents.DIVIDER);
}
}