-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
219 additions
and
14 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
40 changes: 40 additions & 0 deletions
40
src/main/java/de/myzelyam/supervanish/features/HideAdvancementMessages.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,40 @@ | ||
package de.myzelyam.supervanish.features; | ||
|
||
import de.myzelyam.supervanish.SuperVanish; | ||
import net.kyori.adventure.text.Component; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.player.PlayerAdvancementDoneEvent; | ||
|
||
// This feature is paper-only because the PlayerAdvancementDoneEvent#message() method doesn't exist in Spigot | ||
public class HideAdvancementMessages extends Feature { | ||
|
||
private boolean suppressErrors = false; | ||
|
||
public HideAdvancementMessages(SuperVanish plugin) { | ||
super(plugin); | ||
} | ||
|
||
@EventHandler | ||
public void onAdvancementDone(PlayerAdvancementDoneEvent e) { | ||
try { | ||
Player p = e.getPlayer(); | ||
Component message = e.message(); | ||
if (message == null) return; | ||
if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) return; | ||
if (e.message() == null) return; | ||
e.message(null); | ||
p.sendMessage(message); | ||
} catch (Exception er) { | ||
if (!suppressErrors) { | ||
plugin.logException(er); | ||
suppressErrors = true; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return plugin.getSettings().getBoolean("MessageOptions.HideAdvancementMessages", true); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/main/java/de/myzelyam/supervanish/features/NoMobSpawn.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,96 @@ | ||
package de.myzelyam.supervanish.features; | ||
|
||
import com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent; | ||
import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent; | ||
import com.destroystokyo.paper.event.entity.SkeletonHorseTrapEvent; | ||
import de.myzelyam.supervanish.SuperVanish; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.GameMode; | ||
import org.bukkit.entity.HumanEntity; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public class NoMobSpawn extends Feature { | ||
|
||
private boolean suppressErrors = false; | ||
|
||
public NoMobSpawn(SuperVanish plugin) { | ||
super(plugin); | ||
} | ||
|
||
@EventHandler | ||
public void onSkeletonHorseTrap(SkeletonHorseTrapEvent e) { | ||
try { | ||
List<HumanEntity> humans = e.getEligibleHumans(); | ||
int humansCount = humans.size(); | ||
for (HumanEntity human : humans) { | ||
if (human instanceof Player) { | ||
Player p = (Player) human; | ||
if (plugin.getVanishStateMgr().isVanished(p.getUniqueId())) { | ||
humansCount--; | ||
} | ||
} | ||
} | ||
if (humansCount == 0) | ||
e.setCancelled(true); | ||
} catch (Exception er) { | ||
if (!suppressErrors) { | ||
plugin.logException(er); | ||
suppressErrors = true; | ||
} | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onEntitySpawn(PlayerNaturallySpawnCreaturesEvent e) { | ||
try { | ||
if (plugin.getVanishStateMgr().isVanished(e.getPlayer().getUniqueId())) | ||
e.setCancelled(true); | ||
} catch (Exception er) { | ||
if (!suppressErrors) { | ||
plugin.logException(er); | ||
suppressErrors = true; | ||
} | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onEntitySpawnerSpawn(PreSpawnerSpawnEvent e) { | ||
try { | ||
// First check if a non-spectator vanished player is in range | ||
boolean vanishedPlayerInRange = false; | ||
for (UUID vanishedUUID : plugin.getVanishStateMgr().getOnlineVanishedPlayers()) { | ||
Player p = Bukkit.getPlayer(vanishedUUID); | ||
if (p == null) continue; | ||
if (p.getWorld().equals(e.getSpawnerLocation().getWorld()) && | ||
p.getLocation().distanceSquared(e.getSpawnerLocation()) <= 256 && | ||
p.getGameMode() != GameMode.SPECTATOR) | ||
vanishedPlayerInRange = true; | ||
} | ||
if (!vanishedPlayerInRange) return; | ||
|
||
// If so, only cancel if no non-vanished player is in range | ||
for (Player p : Bukkit.getOnlinePlayers()) { | ||
if (p.getWorld().equals(e.getSpawnerLocation().getWorld()) && | ||
p.getLocation().distanceSquared(e.getSpawnerLocation()) <= 256 && | ||
p.getGameMode() != GameMode.SPECTATOR && | ||
!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) | ||
return; | ||
} | ||
e.setCancelled(true); | ||
} catch (Exception er) { | ||
if (!suppressErrors) { | ||
plugin.logException(er); | ||
suppressErrors = true; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return plugin.getSettings().getBoolean("InvisibilityFeatures.PreventMobSpawning", true); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/de/myzelyam/supervanish/visibility/PaperServerPingListener.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 de.myzelyam.supervanish.visibility; | ||
|
||
import com.destroystokyo.paper.event.server.PaperServerListPingEvent; | ||
import com.destroystokyo.paper.profile.PlayerProfile; | ||
import de.myzelyam.supervanish.SuperVanish; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public class PaperServerPingListener implements Listener { | ||
|
||
private boolean errorLogged = false; | ||
|
||
private final SuperVanish plugin; | ||
|
||
public PaperServerPingListener(SuperVanish plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGH) | ||
public void onServerListPing(PaperServerListPingEvent e) { | ||
try { | ||
final FileConfiguration settings = plugin.getSettings(); | ||
if (!settings.getBoolean("ExternalInvisibility.ServerList.AdjustAmountOfOnlinePlayers") | ||
&& !settings.getBoolean("ExternalInvisibility.ServerList.AdjustListOfLoggedInPlayers")) | ||
return; | ||
Collection<UUID> onlineVanishedPlayers = plugin.getVanishStateMgr().getOnlineVanishedPlayers(); | ||
int vanishedPlayersCount = onlineVanishedPlayers.size(), | ||
playerCount = Bukkit.getOnlinePlayers().size(); | ||
if (settings.getBoolean("ExternalInvisibility.ServerList.AdjustAmountOfOnlinePlayers")) { | ||
e.setNumPlayers(playerCount - vanishedPlayersCount); | ||
} | ||
if (settings.getBoolean("ExternalInvisibility.ServerList.AdjustListOfLoggedInPlayers")) { | ||
List<PlayerProfile> playerSample = e.getPlayerSample(); | ||
|
||
playerSample.removeIf(profile -> onlineVanishedPlayers.contains(profile.getId())); | ||
} | ||
} catch (Exception er) { | ||
if (!errorLogged) { | ||
plugin.logException(er); | ||
errorLogged = true; | ||
} | ||
} | ||
} | ||
} |
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