Compare commits
No commits in common. "859733e3dd64b1171f20d0b868b53c2fcb5d1891" and "153a9687761756cdf62b40912f6b308121095f6e" have entirely different histories.
859733e3dd
...
153a968776
@ -1,55 +0,0 @@
|
|||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
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