Compare commits
4 Commits
153a968776
...
859733e3dd
Author | SHA1 | Date | |
---|---|---|---|
859733e3dd | |||
d94bbb7417 | |||
639d06b01d | |||
9f49f44075 |
@ -0,0 +1,55 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.joinProtection;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.core.Main;
|
||||||
|
import eu.mhsl.craftattack.core.appliance.Appliance;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.util.Ticks;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class JoinProtection extends Appliance {
|
||||||
|
private static final int resistanceDuration = 10;
|
||||||
|
|
||||||
|
static final class Options {
|
||||||
|
public boolean wasOnGround = false;
|
||||||
|
}
|
||||||
|
private final Map<UUID, Options> protectedPlayers = new HashMap<>();
|
||||||
|
|
||||||
|
public void addProtection(Player player) {
|
||||||
|
this.protectedPlayers.put(player.getUniqueId(), new Options());
|
||||||
|
PotionEffect resistance = new PotionEffect(PotionEffectType.RESISTANCE, Ticks.TICKS_PER_SECOND * resistanceDuration, 1);
|
||||||
|
PotionEffect blindness = new PotionEffect(PotionEffectType.DARKNESS, Ticks.TICKS_PER_SECOND * 3, 1);
|
||||||
|
player.addPotionEffects(List.of(resistance, blindness));
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskLater(
|
||||||
|
Main.instance(),
|
||||||
|
() -> this.protectedPlayers.remove(player.getUniqueId()),
|
||||||
|
Ticks.TICKS_PER_SECOND * resistanceDuration
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable Options getOptions(Player player) {
|
||||||
|
return this.protectedPlayers.get(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancelEvent(Player player, Cancellable event) {
|
||||||
|
if(!this.protectedPlayers.containsKey(player.getUniqueId())) return;
|
||||||
|
event.setCancelled(true);
|
||||||
|
player.sendActionBar(
|
||||||
|
Component.text("Du befindest dich in der %s Sekündigen")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull List<Listener> listeners() {
|
||||||
|
return List.of(new JoinProtectionListener());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.joinProtection;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.core.appliance.ApplianceListener;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.event.player.*;
|
||||||
|
|
||||||
|
public class JoinProtectionListener extends ApplianceListener<JoinProtection> {
|
||||||
|
@EventHandler
|
||||||
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
|
this.getAppliance().addProtection(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onDamage(EntityDamageEvent event) {
|
||||||
|
if(!(event.getEntity() instanceof Player player)) return;
|
||||||
|
if(event.getCause().equals(EntityDamageEvent.DamageCause.FALL)) return;
|
||||||
|
this.getAppliance().cancelEvent(player, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onConsume(PlayerItemConsumeEvent event) {
|
||||||
|
this.getAppliance().cancelEvent(event.getPlayer(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onMove(PlayerMoveEvent event) {
|
||||||
|
if(!event.hasChangedPosition()) return;
|
||||||
|
JoinProtection.Options option = this.getAppliance().getOptions(event.getPlayer());
|
||||||
|
if(option == null) return;
|
||||||
|
if(!option.wasOnGround) {
|
||||||
|
option.wasOnGround = ((LivingEntity) event.getPlayer()).isOnGround();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getAppliance().cancelEvent(event.getPlayer(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInteract(PlayerInteractEvent event) {
|
||||||
|
this.getAppliance().cancelEvent(event.getPlayer(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
|
this.getAppliance().cancelEvent(event.getPlayer(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
|
this.getAppliance().cancelEvent(event.getPlayer(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onFlightChange(PlayerToggleFlightEvent event) {
|
||||||
|
this.getAppliance().cancelEvent(event.getPlayer(), event);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user