Files
TotalFreedomMod/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java
2023-03-27 20:35:16 -05:00

71 lines
2.1 KiB
Java

package me.totalfreedom.totalfreedommod.fun;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.api.ShopItem;
import me.totalfreedom.totalfreedommod.util.ParticleDisplay;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerMoveEvent;
import java.util.HashMap;
import java.util.Map;
import java.util.SplittableRandom;
import java.util.UUID;
public class Trailer extends FreedomService
{
private final SplittableRandom random = new SplittableRandom();
private final Map<UUID, ParticleDisplay> trailPlayers = new HashMap<>(); // player UUID and relative particle instance.
@Override
public void onStart()
{
}
@Override
public void onStop()
{
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event)
{
if (plugin.sh == null) return; // Shop is disabled
/* Doesn't continue any further if...
* - The trail list is empty
* - The player doesn't have their trail enabled in the first place
* - The player doesn't have the trail item in the shop at all
* - The player doesn't have permission to modify blocks in their current world
*/
if (trailPlayers.isEmpty()
|| !trailPlayers.containsKey(event.getPlayer().getUniqueId())
|| !plugin.pl.getData(event.getPlayer()).hasItem(ShopItem.RAINBOW_TRAIL))
{
return;
}
final Player player = event.getPlayer();
final ParticleDisplay particleDisplay = trailPlayers.get(player.getUniqueId());
particleDisplay.spawnNext(player);
}
public void remove(Player player)
{
trailPlayers.remove(player.getUniqueId());
}
public void add(Player player)
{
if (trailPlayers.containsKey(player.getUniqueId())) return;
trailPlayers.put(player.getUniqueId(), new ParticleDisplay());
}
public boolean contains(Player player)
{
return trailPlayers.containsKey(player.getUniqueId());
}
}