mirror of
https://github.com/plexusorg/Module-TFMExtras.git
synced 2024-10-31 17:37:09 +00:00
Implemented an event listener that reapplies the effect if the player is orbited and tries to remove it.
This commit is contained in:
parent
477cf48344
commit
7f9c8d217e
@ -13,12 +13,18 @@ import org.bukkit.potion.PotionEffectType;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@CommandParameters(name = "orbit", description = "Accelerates the player at a super fast rate", usage = "/<command> <target> [<<power> | stop>]")
|
@CommandParameters(name = "orbit", description = "Accelerates the player at a super fast rate", usage = "/<command> <target> [<<power> | stop>]")
|
||||||
@CommandPermissions(permission = "plex.tfmextras.orbit")
|
@CommandPermissions(permission = "plex.tfmextras.orbit")
|
||||||
public class OrbitCommand extends PlexCommand
|
public class OrbitCommand extends PlexCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static final Map<UUID, Boolean> isOrbitedMap = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||||
{
|
{
|
||||||
@ -63,9 +69,15 @@ public class OrbitCommand extends PlexCommand
|
|||||||
private void startOrbiting(Player player, int strength) {
|
private void startOrbiting(Player player, int strength) {
|
||||||
player.setGameMode(org.bukkit.GameMode.SURVIVAL);
|
player.setGameMode(org.bukkit.GameMode.SURVIVAL);
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, strength, false, false));
|
player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, strength, false, false));
|
||||||
|
isOrbitedMap.put(player.getUniqueId(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopOrbiting(Player player) {
|
private void stopOrbiting(Player player) {
|
||||||
player.removePotionEffect(PotionEffectType.LEVITATION);
|
player.removePotionEffect(PotionEffectType.LEVITATION);
|
||||||
|
isOrbitedMap.remove(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isPlayerOrbited(UUID playerId) {
|
||||||
|
return isOrbitedMap.getOrDefault(playerId, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
package dev.plex.extras.listener;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.extras.command.OrbitCommand;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import dev.plex.listener.PlexListener;
|
||||||
|
import org.bukkit.event.entity.EntityPotionEffectEvent;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
public class OrbitEffectListener extends PlexListener
|
||||||
|
{
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onPotionEffectRemove(EntityPotionEffectEvent event)
|
||||||
|
{
|
||||||
|
if (event.getEntity() instanceof Player player)
|
||||||
|
{
|
||||||
|
if ((event.getAction() == EntityPotionEffectEvent.Action.CLEARED || event.getAction() == EntityPotionEffectEvent.Action.REMOVED)
|
||||||
|
&& event.getModifiedType() == PotionEffectType.LEVITATION) {
|
||||||
|
if (OrbitCommand.isPlayerOrbited(player.getUniqueId()))
|
||||||
|
{
|
||||||
|
Bukkit.getScheduler().runTaskLater(Plex.get(), () ->
|
||||||
|
player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, 100, false, false)), 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user