Skip to content

GH-1031 Add vanish feature. #1048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 49 commits into from
Aug 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
7f19708
init vanish
P1otrulla Jul 13, 2025
7671e1e
update
P1otrulla Jul 13, 2025
58394c5
remove memory-leak, add quit off vanish and others
P1otrulla Jul 14, 2025
fac2d17
Update eternalcore-core/src/main/java/com/eternalcode/core/feature/va…
P1otrulla Jul 14, 2025
10b0419
Update eternalcore-core/src/main/java/com/eternalcode/core/feature/va…
P1otrulla Jul 14, 2025
900f403
Update eternalcore-core/src/main/java/com/eternalcode/core/feature/va…
P1otrulla Jul 14, 2025
057accd
follow smart's review
P1otrulla Jul 14, 2025
a8d52fc
Merge branch 'master' into 2.0/vanish-implementation
P1otrulla Jul 24, 2025
b1f5d60
Merge branch 'master' into 2.0/vanish-implementation
P1otrulla Jul 24, 2025
b430ca0
Added if-checks
P1otrulla Jul 24, 2025
12fc65f
implemented messages and config
P1otrulla Jul 25, 2025
cb80662
add messages and follow suggestions
P1otrulla Aug 1, 2025
6906800
add getVanished players to api and implement reminder task
P1otrulla Aug 1, 2025
e8855a6
some code stylish fixes and removed unused imports
P1otrulla Aug 1, 2025
525ccdd
added missing inject annotation
P1otrulla Aug 1, 2025
f43ae5e
Merge branch 'master' into 2.0/vanish-implementation
P1otrulla Aug 1, 2025
7a7c5ad
follow mądra głowa gemini suggestions
P1otrulla Aug 1, 2025
f6898ca
follow Martin's suggestions
P1otrulla Aug 1, 2025
880e0a0
repair project building failure
P1otrulla Aug 1, 2025
9304ad0
use package-private
Rollczi Aug 2, 2025
3ae571f
use package-private
Rollczi Aug 2, 2025
8170308
follow team member suggestions
P1otrulla Aug 2, 2025
5505d4f
Merge remote-tracking branch 'origin/2.0/vanish-implementation' into …
P1otrulla Aug 3, 2025
59adeb7
fix space
P1otrulla Aug 3, 2025
77de94b
fix codestyle
P1otrulla Aug 3, 2025
3b1f4fc
Merge branch 'master' into 2.0/vanish-implementation
vLuckyyy Aug 3, 2025
f8c3305
Add a less restrictive silent inventory opener
vLuckyyy Aug 3, 2025
80eae83
Fix team removal, improve food key name, improve default actionbar me…
vLuckyyy Aug 3, 2025
5d86f18
fixed event calling logic
P1otrulla Aug 3, 2025
29614d2
Merge remote-tracking branch 'origin/2.0/vanish-implementation' into …
P1otrulla Aug 3, 2025
3d0fd89
Fix.
vLuckyyy Aug 3, 2025
ff3026b
cr
Rollczi Aug 3, 2025
eed8225
Update eternalcore-core/src/main/java/com/eternalcode/core/feature/va…
P1otrulla Aug 4, 2025
1fce077
Update eternalcore-core/src/main/java/com/eternalcode/core/feature/va…
P1otrulla Aug 4, 2025
cffe1db
follow Rollczi suggestions & added EternalReloadEvent
P1otrulla Aug 4, 2025
6665420
Merge remote-tracking branch 'origin/2.0/vanish-implementation' into …
P1otrulla Aug 4, 2025
6ed3286
fix
P1otrulla Aug 4, 2025
cd8f7fe
i was trying...
P1otrulla Aug 4, 2025
cb2b1b2
veni vidi vici
P1otrulla Aug 4, 2025
d62503b
Update eternalcore-core/src/main/java/com/eternalcode/core/publish/ev…
Rollczi Aug 4, 2025
6a62064
Optimize vanished player name complete removal logic.
Rollczi Aug 4, 2025
4af126c
Merge remote-tracking branch 'origin/2.0/vanish-implementation' into …
Rollczi Aug 4, 2025
edc2803
Move Cancellable to AbstractVanishEvent
Rollczi Aug 4, 2025
96629f3
Move Cancellable to AbstractVanishEvent
Rollczi Aug 4, 2025
cda2867
Update eternalcore-core/src/main/java/com/eternalcode/core/configurat…
P1otrulla Aug 4, 2025
44b3a2e
Update eternalcore-core/src/main/java/com/eternalcode/core/feature/va…
P1otrulla Aug 4, 2025
6ce8689
Fix okaeri
Rollczi Aug 4, 2025
0d55747
Follow review feedback, complete using proxy.
vLuckyyy Aug 4, 2025
263c460
config -> settings, removed unused imports
P1otrulla Aug 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.eternalcode.core.feature.vanish;

import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;

import java.util.Set;
import java.util.UUID;

public interface VanishService {

/**
* Enables vanish for the specified player.
*
* @param player The player to enable vanish for.
*/
void enableVanish(Player player);

/**
* Disables vanish for the specified player.
*
* @param player The player to disable vanish for.
*/
void disableVanish(Player player);

/**
* Checks if the specified player is vanished.
*
* @param player The player to check.
* @return true if the player is vanished, false otherwise.
*/
boolean isVanished(Player player);

default boolean toggleVanish(Player player) {
if (isVanished(player)) {
disableVanish(player);
return false;
}
enableVanish(player);
return true;
}

/**
* Checks if the player with the specified unique ID is vanished.
*
* @param uniqueId The unique ID of the player to check.
* @return true if the player is vanished, false otherwise.
*/
boolean isVanished(UUID uniqueId);

/**
* Hides vanished players from the specified player.
*
* @param observer The player from whom vanished players should be hidden.
*/
@ApiStatus.Internal
void hideVanishedPlayersFrom(Player observer);

/**
* Gets a set of UUIDs of all vanished players.
*
* @return A set containing the unique IDs of all vanished players.
*/
Set<UUID> getVanishedPlayers();

/**
* Gets a set of names of all vanished players.
*
* @return A set containing the names of all vanished players.
*/
Set<String> getVanishedPlayerNames();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.eternalcode.core.feature.vanish.event;

import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.entity.Player;

public abstract class AbstractVanishEvent extends Event implements Cancellable {

private final Player player;
private boolean cancelled = false;

public AbstractVanishEvent(Player player) {
this.player = player;
}

public Player getPlayer() {
return this.player;
}

@Override
public boolean isCancelled() {
return this.cancelled;
}

@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.eternalcode.core.feature.vanish.event;

import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

public class DisableVanishEvent extends AbstractVanishEvent {

private static final HandlerList HANDLERS = new HandlerList();

public DisableVanishEvent(Player player) {
super(player);
}

@Override
public @NotNull HandlerList getHandlers() {
return HANDLERS;
}

public static HandlerList getHandlerList() {
return HANDLERS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.eternalcode.core.feature.vanish.event;

import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

public class EnableVanishEvent extends AbstractVanishEvent {

private static final HandlerList HANDLERS = new HandlerList();

public EnableVanishEvent(Player player) {
super(player);
}

@Override
public @NotNull HandlerList getHandlers() {
return HANDLERS;
}

public static HandlerList getHandlerList() {
return HANDLERS;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.eternalcode.core;

import com.eternalcode.annotations.scan.command.DescriptionDocs;
import com.eternalcode.commons.scheduler.Scheduler;
import com.eternalcode.core.configuration.ConfigurationManager;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.publish.Publisher;
import com.eternalcode.core.publish.event.EternalReloadEvent;
import com.google.common.base.Stopwatch;
import dev.rollczi.litecommands.annotations.async.Async;
import dev.rollczi.litecommands.annotations.context.Context;
Expand All @@ -13,6 +16,7 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

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

private final ConfigurationManager configurationManager;
private final MiniMessage miniMessage;
private final Publisher publisher;

@Inject
EternalCoreCommand(ConfigurationManager configurationManager, MiniMessage miniMessage) {
EternalCoreCommand(ConfigurationManager configurationManager, MiniMessage miniMessage, Publisher publisher) {
this.configurationManager = configurationManager;
this.miniMessage = miniMessage;
this.publisher = publisher;
}

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

private long reload() {
Stopwatch stopwatch = Stopwatch.createStarted();

this.configurationManager.reload();
this.publisher.publish(new EternalReloadEvent());

return stopwatch.elapsed(TimeUnit.MILLISECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.eternalcode.core.bridge.litecommand.argument;

import com.eternalcode.annotations.scan.permission.PermissionDocs;
import com.eternalcode.core.feature.vanish.VanishPermissionConstant;
import com.eternalcode.core.feature.vanish.VanishService;
import com.eternalcode.core.injector.annotations.Inject;
Expand Down Expand Up @@ -70,6 +69,6 @@ private boolean canSee(CommandSender sender, Player player) {
}

private boolean canSeeVanished(CommandSender sender) {
return sender.hasPermission(VanishPermissionConstant.VANISH_SEE_TABULATION_PERMISSION);
return sender.hasPermission(VanishPermissionConstant.VANISH_SEE_PERMISSION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.eternalcode.core.feature.spawn.SpawnJoinConfig;
import com.eternalcode.core.feature.spawn.SpawnSettings;
import com.eternalcode.core.feature.teleportrequest.TeleportRequestConfig;
import com.eternalcode.core.feature.vanish.VanishConfig;
import com.eternalcode.core.feature.vanish.VanishSettings;
import com.eternalcode.core.feature.warp.WarpConfig;
import com.eternalcode.core.injector.annotations.Bean;
import com.eternalcode.core.injector.annotations.component.ConfigurationFile;
Expand Down Expand Up @@ -223,6 +225,12 @@ public static class Items extends OkaeriConfig {
@Comment("# Settings for server link management")
ServerLinksConfig serverLinks = new ServerLinksConfig();

@Bean(proxied = VanishSettings.class)
@Comment("")
@Comment("# Vanish Configuration")
@Comment("# Settings responsible for player vanish functionality")
VanishConfig vanish = new VanishConfig();

@Override
public File getConfigFile(File dataFolder) {
return new File(dataFolder, "config.yml");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.eternalcode.core.feature.vanish;

import com.eternalcode.annotations.scan.command.DescriptionDocs;
import com.eternalcode.core.feature.vanish.messages.VanishMessages;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.notice.NoticeService;
import com.eternalcode.multification.notice.provider.NoticeProvider;
import dev.rollczi.litecommands.annotations.argument.Arg;
import dev.rollczi.litecommands.annotations.command.Command;
import dev.rollczi.litecommands.annotations.context.Context;
import dev.rollczi.litecommands.annotations.execute.Execute;
import dev.rollczi.litecommands.annotations.permission.Permission;
import org.bukkit.entity.Player;

@Command(name = "vanish", aliases = {"v"})
@Permission(VanishPermissionConstant.VANISH_COMMAND_PERMISSION)
class VanishCommand {

private final NoticeService noticeService;
private final VanishService vanishService;

@Inject
public VanishCommand(NoticeService noticeService, VanishService vanishService) {
this.noticeService = noticeService;
this.vanishService = vanishService;
}

@Execute
@DescriptionDocs(description = "Toggle your vanish state")
void vanishSelf(@Context Player player) {
boolean vanished = this.vanishService.toggleVanish(player);
this.sendMessage(player, player, vanished ? VanishMessages::vanishEnabled : VanishMessages::vanishDisabled);
}

@Execute
@Permission(VanishPermissionConstant.VANISH_COMMAND_PERMISSION_OTHER)
@DescriptionDocs(description = "Toggle vanish state for another player")
void vanishOther(@Context Player player, @Arg Player target) {
boolean vanished = this.vanishService.toggleVanish(target);
this.sendMessage(player, target, vanished ? VanishMessages::vanishEnabledOther : VanishMessages::vanishDisabledOther);
}

private void sendMessage(Player sender, Player target, NoticeProvider<VanishMessages> message) {
this.noticeService.create()
.player(sender.getUniqueId())
.placeholder("{PLAYER}", target.getName())
.notice(messages -> message.extract(messages.vanish()))
.send();
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.eternalcode.core.feature.vanish;

import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.annotation.Comment;
import lombok.Getter;
import lombok.experimental.Accessors;
import org.bukkit.ChatColor;

@Getter
@Accessors(fluent = true)
public class VanishConfig extends OkaeriConfig implements VanishSettings {

@Comment("Should players with eternalcore.vanish.join permission join in vanish mode without join message")
public boolean silentJoin = false;

@Comment("Should vanished players be invulnerable to damage from other players")
public boolean godMode = true;

@Comment("Give night vision effect to vanished players")
public boolean nightVision = true;

@Comment("Should vanished players be able to silently view other players' inventories?")
public boolean silentInventoryAccess = true;

@Comment("Should vanished players glow to make them visible to other staff members?")
public boolean glowEffect = true;

@Comment("Color of the glow effect for vanished players")
public ChatColor color = ChatColor.LIGHT_PURPLE;

@Comment("Prevent vanished players from dropping items")
public boolean blockItemDropping = false;

@Comment("Prevent vanished players from picking up items")
public boolean blockItemPickup = true;

@Comment("Prevent vanished players from hunger loss")
public boolean blockHungerLoss = true;

@Comment("Prevent vanished players from using public chat")
public boolean blockChatUsage = false;

@Comment("Prevent vanished players from breaking blocks")
public boolean blockBlockBreaking = false;

@Comment("Prevent vanished players from placing blocks")
public boolean blockBlockPlacing = false;

}
Loading