SteamWar/BauSystem2.0
Archiviert
12
0

Add global NightVisionCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-08-05 21:18:18 +02:00
Ursprung 5283bd5697
Commit c4e7c84348

Datei anzeigen

@ -20,16 +20,22 @@
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.configplayer.Config;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.command.SWCommand;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import yapion.hierarchy.types.YAPIONObject;
@Linked(LinkageType.COMMAND)
public class NightVisionCommand extends SWCommand {
@Linked(LinkageType.LISTENER)
public class NightVisionCommand extends SWCommand implements Listener {
public NightVisionCommand() {
super("nightvision", "nv", "light");
@ -37,12 +43,24 @@ public class NightVisionCommand extends SWCommand {
@Register(description = "NIGHT_VISION_HELP")
public void genericCommand(Player p) {
if (p.hasPotionEffect(PotionEffectType.NIGHT_VISION)) {
YAPIONObject yapionObject = Config.getInstance().get(p);
boolean value = !yapionObject.getBooleanOrDefault("nightvision", false);
yapionObject.put("nightvision", value);
setNightVision(p, value);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
setNightVision(event.getPlayer(), Config.getInstance().get(event.getPlayer()).getBooleanOrDefault("nightvision", false));
}
private void setNightVision(Player p, boolean value) {
if (p.hasPotionEffect(PotionEffectType.NIGHT_VISION) && !value) {
p.removePotionEffect(PotionEffectType.NIGHT_VISION);
BauSystem.MESSAGE.sendPrefixless("NIGHT_VISION_OFF", p, ChatMessageType.ACTION_BAR);
return;
} else if (!p.hasPotionEffect(PotionEffectType.NIGHT_VISION) && value) {
p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 1000000, 255, false, false));
BauSystem.MESSAGE.sendPrefixless("NIGHT_VISION_ON", p, ChatMessageType.ACTION_BAR);
}
p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 1000000, 255, false, false));
BauSystem.MESSAGE.sendPrefixless("NIGHT_VISION_ON", p, ChatMessageType.ACTION_BAR);
}
}