cool stuff i think

This commit is contained in:
Piecuuu 2026-02-22 16:40:44 +01:00
parent 849cb399a6
commit 14fffaeff1

View file

@ -1,5 +1,8 @@
package pl.piecuu.invisninja;
import java.util.Random;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -11,11 +14,55 @@ import org.bukkit.potion.PotionEffectType;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextReplacementConfig;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.util.HSVLike;
public class InvisNinja extends JavaPlugin implements Listener {
private long bootSeed = 0L;
public long getBootSeed() {
return this.bootSeed;
}
private static long fmix64(long k) {
k ^= k >>> 33;
k *= 0xff51afd7ed558ccdL;
k ^= k >>> 33;
k *= 0xc4ceb9fe1a85ec53L;
k ^= k >>> 33;
return k;
}
private static long combineMurmur(long a, long b, long c) {
long h = a;
h = h * 0x9E3779B97F4A7C15L + b;
h = fmix64(h ^ c);
return h;
}
public static long getPerPlayerSeed(UUID playerUniqueId, long seed) {
final long lower = playerUniqueId.getLeastSignificantBits();
final long higher = playerUniqueId.getMostSignificantBits();
return combineMurmur(lower, higher, seed);
}
private static HSVLike hsvFromLong(long seed) {
long mix = seed ^ (seed >>> 32);
int hueDeg = (int)Math.floorMod(mix, 360L);
int b1 = (int)((mix >>> 8) & 0xFF);
int b2 = (int)((mix >>> 16) & 0xFF);
float hue = hueDeg / 360f;
float sat = 0.6f + (b1 / 255f) * 0.35f;
float val = 0.75f + (b2 / 255f) * 0.25f;
return HSVLike.hsvLike(hue, sat, val);
}
@Override
public void onEnable() {
this.bootSeed = new java.security.SecureRandom().nextLong();
Bukkit.getPluginManager().registerEvents(this, this);
}
@ -24,11 +71,22 @@ public class InvisNinja extends JavaPlugin implements Listener {
Entity en = e.getDamageSource().getCausingEntity();
if(!(en instanceof Player p)) return;
if(!isPlayerInvisible(p)) return;
long seed = InvisNinja.getPerPlayerSeed(p.getUniqueId(), this.getBootSeed());
Random rand = new Random(seed);
final int max = 16;
final int min = 5;
final int randomNameLength = rand.nextInt((max - min) + 1) + min; // 5-16
Component newMessage = e.deathMessage()
.replaceText(TextReplacementConfig.builder()
.match(p.getName())
.replacement(Component.text("aaaaaaaaaaaaa").decoration(TextDecoration.OBFUSCATED, true))
.replacement(
Component.text("a".repeat(randomNameLength))
.decoration(TextDecoration.OBFUSCATED, true)
.color(TextColor.color(InvisNinja.hsvFromLong(seed)))
)
.build()
);
e.deathMessage(newMessage);