Skip to content

Commit 2666498

Browse files
P1otrullacoderabbitai[bot]RollczivLuckyyy
authored
GH-1031 Add vanish feature. (#1048)
* init vanish * update * remove memory-leak, add quit off vanish and others * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/vanish/controller/TabComplateController.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/vanish/controller/PlayerJoinController.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/vanish/VanishInvisibleServiceImpl.java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * follow smart's review * Added if-checks * implemented messages and config * add messages and follow suggestions * add getVanished players to api and implement reminder task * some code stylish fixes and removed unused imports * added missing inject annotation * follow mądra głowa gemini suggestions * follow Martin's suggestions * repair project building failure * use package-private * use package-private * follow team member suggestions * fix space * fix codestyle * Add a less restrictive silent inventory opener * Fix team removal, improve food key name, improve default actionbar message, improve default config. * fixed event calling logic * Fix. * cr * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/vanish/VanishConfiguration.java Co-authored-by: Norbert Dejlich <[email protected]> * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/vanish/controller/GlowingController.java Co-authored-by: Norbert Dejlich <[email protected]> * follow Rollczi suggestions & added EternalReloadEvent * fix * i was trying... * veni vidi vici * Update eternalcore-core/src/main/java/com/eternalcode/core/publish/event/EternalReloadEvent.java * Optimize vanished player name complete removal logic. * Move Cancellable to AbstractVanishEvent * Move Cancellable to AbstractVanishEvent * Update eternalcore-core/src/main/java/com/eternalcode/core/configuration/ConfigurationManager.java Co-authored-by: Norbert Dejlich <[email protected]> * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/vanish/controller/GlowingController.java Co-authored-by: Norbert Dejlich <[email protected]> * Fix okaeri * Follow review feedback, complete using proxy. * config -> settings, removed unused imports --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Rollczi <[email protected]> Co-authored-by: vLuckyyy <[email protected]>
1 parent f7c2593 commit 2666498

36 files changed

+1371
-34
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.eternalcode.core.feature.vanish;
2+
3+
import org.bukkit.entity.Player;
4+
import org.jetbrains.annotations.ApiStatus;
5+
6+
import java.util.Set;
7+
import java.util.UUID;
8+
9+
public interface VanishService {
10+
11+
/**
12+
* Enables vanish for the specified player.
13+
*
14+
* @param player The player to enable vanish for.
15+
*/
16+
void enableVanish(Player player);
17+
18+
/**
19+
* Disables vanish for the specified player.
20+
*
21+
* @param player The player to disable vanish for.
22+
*/
23+
void disableVanish(Player player);
24+
25+
/**
26+
* Checks if the specified player is vanished.
27+
*
28+
* @param player The player to check.
29+
* @return true if the player is vanished, false otherwise.
30+
*/
31+
boolean isVanished(Player player);
32+
33+
default boolean toggleVanish(Player player) {
34+
if (isVanished(player)) {
35+
disableVanish(player);
36+
return false;
37+
}
38+
enableVanish(player);
39+
return true;
40+
}
41+
42+
/**
43+
* Checks if the player with the specified unique ID is vanished.
44+
*
45+
* @param uniqueId The unique ID of the player to check.
46+
* @return true if the player is vanished, false otherwise.
47+
*/
48+
boolean isVanished(UUID uniqueId);
49+
50+
/**
51+
* Hides vanished players from the specified player.
52+
*
53+
* @param observer The player from whom vanished players should be hidden.
54+
*/
55+
@ApiStatus.Internal
56+
void hideVanishedPlayersFrom(Player observer);
57+
58+
/**
59+
* Gets a set of UUIDs of all vanished players.
60+
*
61+
* @return A set containing the unique IDs of all vanished players.
62+
*/
63+
Set<UUID> getVanishedPlayers();
64+
65+
/**
66+
* Gets a set of names of all vanished players.
67+
*
68+
* @return A set containing the names of all vanished players.
69+
*/
70+
Set<String> getVanishedPlayerNames();
71+
72+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.eternalcode.core.feature.vanish.event;
2+
3+
import org.bukkit.event.Cancellable;
4+
import org.bukkit.event.Event;
5+
import org.bukkit.entity.Player;
6+
7+
public abstract class AbstractVanishEvent extends Event implements Cancellable {
8+
9+
private final Player player;
10+
private boolean cancelled = false;
11+
12+
public AbstractVanishEvent(Player player) {
13+
this.player = player;
14+
}
15+
16+
public Player getPlayer() {
17+
return this.player;
18+
}
19+
20+
@Override
21+
public boolean isCancelled() {
22+
return this.cancelled;
23+
}
24+
25+
@Override
26+
public void setCancelled(boolean cancel) {
27+
this.cancelled = cancel;
28+
}
29+
30+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.eternalcode.core.feature.vanish.event;
2+
3+
import org.bukkit.entity.Player;
4+
import org.bukkit.event.HandlerList;
5+
import org.jetbrains.annotations.NotNull;
6+
7+
public class DisableVanishEvent extends AbstractVanishEvent {
8+
9+
private static final HandlerList HANDLERS = new HandlerList();
10+
11+
public DisableVanishEvent(Player player) {
12+
super(player);
13+
}
14+
15+
@Override
16+
public @NotNull HandlerList getHandlers() {
17+
return HANDLERS;
18+
}
19+
20+
public static HandlerList getHandlerList() {
21+
return HANDLERS;
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.eternalcode.core.feature.vanish.event;
2+
3+
import org.bukkit.entity.Player;
4+
import org.bukkit.event.HandlerList;
5+
import org.jetbrains.annotations.NotNull;
6+
7+
public class EnableVanishEvent extends AbstractVanishEvent {
8+
9+
private static final HandlerList HANDLERS = new HandlerList();
10+
11+
public EnableVanishEvent(Player player) {
12+
super(player);
13+
}
14+
15+
@Override
16+
public @NotNull HandlerList getHandlers() {
17+
return HANDLERS;
18+
}
19+
20+
public static HandlerList getHandlerList() {
21+
return HANDLERS;
22+
}
23+
}

eternalcore-core/src/main/java/com/eternalcode/core/EternalCoreCommand.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.eternalcode.core;
22

33
import com.eternalcode.annotations.scan.command.DescriptionDocs;
4+
import com.eternalcode.commons.scheduler.Scheduler;
45
import com.eternalcode.core.configuration.ConfigurationManager;
56
import com.eternalcode.core.injector.annotations.Inject;
7+
import com.eternalcode.core.publish.Publisher;
8+
import com.eternalcode.core.publish.event.EternalReloadEvent;
69
import com.google.common.base.Stopwatch;
710
import dev.rollczi.litecommands.annotations.async.Async;
811
import dev.rollczi.litecommands.annotations.context.Context;
@@ -13,6 +16,7 @@
1316
import net.kyori.adventure.text.Component;
1417
import net.kyori.adventure.text.minimessage.MiniMessage;
1518

19+
import java.time.Duration;
1620
import java.util.concurrent.TimeUnit;
1721

1822
@Command(name = "eternalcore")
@@ -23,11 +27,13 @@ class EternalCoreCommand {
2327

2428
private final ConfigurationManager configurationManager;
2529
private final MiniMessage miniMessage;
30+
private final Publisher publisher;
2631

2732
@Inject
28-
EternalCoreCommand(ConfigurationManager configurationManager, MiniMessage miniMessage) {
33+
EternalCoreCommand(ConfigurationManager configurationManager, MiniMessage miniMessage, Publisher publisher) {
2934
this.configurationManager = configurationManager;
3035
this.miniMessage = miniMessage;
36+
this.publisher = publisher;
3137
}
3238

3339
@Async
@@ -42,7 +48,9 @@ void reload(@Context Audience audience) {
4248

4349
private long reload() {
4450
Stopwatch stopwatch = Stopwatch.createStarted();
51+
4552
this.configurationManager.reload();
53+
this.publisher.publish(new EternalReloadEvent());
4654

4755
return stopwatch.elapsed(TimeUnit.MILLISECONDS);
4856
}

eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/PlayerArgument.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.eternalcode.core.bridge.litecommand.argument;
22

3-
import com.eternalcode.annotations.scan.permission.PermissionDocs;
43
import com.eternalcode.core.feature.vanish.VanishPermissionConstant;
54
import com.eternalcode.core.feature.vanish.VanishService;
65
import com.eternalcode.core.injector.annotations.Inject;
@@ -70,6 +69,6 @@ private boolean canSee(CommandSender sender, Player player) {
7069
}
7170

7271
private boolean canSeeVanished(CommandSender sender) {
73-
return sender.hasPermission(VanishPermissionConstant.VANISH_SEE_TABULATION_PERMISSION);
72+
return sender.hasPermission(VanishPermissionConstant.VANISH_SEE_PERMISSION);
7473
}
7574
}

eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import com.eternalcode.core.feature.spawn.SpawnJoinConfig;
1717
import com.eternalcode.core.feature.spawn.SpawnSettings;
1818
import com.eternalcode.core.feature.teleportrequest.TeleportRequestConfig;
19+
import com.eternalcode.core.feature.vanish.VanishConfig;
20+
import com.eternalcode.core.feature.vanish.VanishSettings;
1921
import com.eternalcode.core.feature.warp.WarpConfig;
2022
import com.eternalcode.core.injector.annotations.Bean;
2123
import com.eternalcode.core.injector.annotations.component.ConfigurationFile;
@@ -216,6 +218,12 @@ public static class Items extends OkaeriConfig {
216218
@Comment("# Settings for server link management")
217219
ServerLinksConfig serverLinks = new ServerLinksConfig();
218220

221+
@Bean(proxied = VanishSettings.class)
222+
@Comment("")
223+
@Comment("# Vanish Configuration")
224+
@Comment("# Settings responsible for player vanish functionality")
225+
VanishConfig vanish = new VanishConfig();
226+
219227
@Override
220228
public File getConfigFile(File dataFolder) {
221229
return new File(dataFolder, "config.yml");
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.eternalcode.core.feature.vanish;
2+
3+
import com.eternalcode.annotations.scan.command.DescriptionDocs;
4+
import com.eternalcode.core.feature.vanish.messages.VanishMessages;
5+
import com.eternalcode.core.injector.annotations.Inject;
6+
import com.eternalcode.core.notice.NoticeService;
7+
import com.eternalcode.multification.notice.provider.NoticeProvider;
8+
import dev.rollczi.litecommands.annotations.argument.Arg;
9+
import dev.rollczi.litecommands.annotations.command.Command;
10+
import dev.rollczi.litecommands.annotations.context.Context;
11+
import dev.rollczi.litecommands.annotations.execute.Execute;
12+
import dev.rollczi.litecommands.annotations.permission.Permission;
13+
import org.bukkit.entity.Player;
14+
15+
@Command(name = "vanish", aliases = {"v"})
16+
@Permission(VanishPermissionConstant.VANISH_COMMAND_PERMISSION)
17+
class VanishCommand {
18+
19+
private final NoticeService noticeService;
20+
private final VanishService vanishService;
21+
22+
@Inject
23+
public VanishCommand(NoticeService noticeService, VanishService vanishService) {
24+
this.noticeService = noticeService;
25+
this.vanishService = vanishService;
26+
}
27+
28+
@Execute
29+
@DescriptionDocs(description = "Toggle your vanish state")
30+
void vanishSelf(@Context Player player) {
31+
boolean vanished = this.vanishService.toggleVanish(player);
32+
this.sendMessage(player, player, vanished ? VanishMessages::vanishEnabled : VanishMessages::vanishDisabled);
33+
}
34+
35+
@Execute
36+
@Permission(VanishPermissionConstant.VANISH_COMMAND_PERMISSION_OTHER)
37+
@DescriptionDocs(description = "Toggle vanish state for another player")
38+
void vanishOther(@Context Player player, @Arg Player target) {
39+
boolean vanished = this.vanishService.toggleVanish(target);
40+
this.sendMessage(player, target, vanished ? VanishMessages::vanishEnabledOther : VanishMessages::vanishDisabledOther);
41+
}
42+
43+
private void sendMessage(Player sender, Player target, NoticeProvider<VanishMessages> message) {
44+
this.noticeService.create()
45+
.player(sender.getUniqueId())
46+
.placeholder("{PLAYER}", target.getName())
47+
.notice(messages -> message.extract(messages.vanish()))
48+
.send();
49+
}
50+
51+
}
52+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.eternalcode.core.feature.vanish;
2+
3+
import eu.okaeri.configs.OkaeriConfig;
4+
import eu.okaeri.configs.annotation.Comment;
5+
import lombok.Getter;
6+
import lombok.experimental.Accessors;
7+
import org.bukkit.ChatColor;
8+
9+
@Getter
10+
@Accessors(fluent = true)
11+
public class VanishConfig extends OkaeriConfig implements VanishSettings {
12+
13+
@Comment("Should players with eternalcore.vanish.join permission join in vanish mode without join message")
14+
public boolean silentJoin = false;
15+
16+
@Comment("Should vanished players be invulnerable to damage from other players")
17+
public boolean godMode = true;
18+
19+
@Comment("Give night vision effect to vanished players")
20+
public boolean nightVision = true;
21+
22+
@Comment("Should vanished players be able to silently view other players' inventories?")
23+
public boolean silentInventoryAccess = true;
24+
25+
@Comment("Should vanished players glow to make them visible to other staff members?")
26+
public boolean glowEffect = true;
27+
28+
@Comment("Color of the glow effect for vanished players")
29+
public ChatColor color = ChatColor.LIGHT_PURPLE;
30+
31+
@Comment("Prevent vanished players from dropping items")
32+
public boolean blockItemDropping = false;
33+
34+
@Comment("Prevent vanished players from picking up items")
35+
public boolean blockItemPickup = true;
36+
37+
@Comment("Prevent vanished players from hunger loss")
38+
public boolean blockHungerLoss = true;
39+
40+
@Comment("Prevent vanished players from using public chat")
41+
public boolean blockChatUsage = false;
42+
43+
@Comment("Prevent vanished players from breaking blocks")
44+
public boolean blockBlockBreaking = false;
45+
46+
@Comment("Prevent vanished players from placing blocks")
47+
public boolean blockBlockPlacing = false;
48+
49+
}

0 commit comments

Comments
 (0)