mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-07-02 04:56:40 +00:00
Change trailer from blocks to particles.
This commit is contained in:
@ -1,28 +1,22 @@
|
||||
package me.totalfreedom.totalfreedommod.fun;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.SplittableRandom;
|
||||
import java.util.UUID;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.api.ShopItem;
|
||||
import me.totalfreedom.totalfreedommod.util.Groups;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
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 Set<UUID> trailPlayers = new HashSet<>(); // player UUID
|
||||
private final Map<UUID, ParticleDisplay> trailPlayers = new HashMap<>(); // player UUID and relative particle instance.
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
@ -46,42 +40,15 @@ public class Trailer extends FreedomService
|
||||
* - The player doesn't have permission to modify blocks in their current world
|
||||
*/
|
||||
if (trailPlayers.isEmpty()
|
||||
|| !trailPlayers.contains(event.getPlayer().getUniqueId())
|
||||
|| !plugin.pl.getData(event.getPlayer()).hasItem(ShopItem.RAINBOW_TRAIL)
|
||||
|| plugin.wr.doRestrict(event.getPlayer())
|
||||
|| !plugin.wgb.canEditCurrentWorld(event.getPlayer()))
|
||||
|| !trailPlayers.containsKey(event.getPlayer().getUniqueId())
|
||||
|| !plugin.pl.getData(event.getPlayer()).hasItem(ShopItem.RAINBOW_TRAIL))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Block fromBlock = event.getFrom().getBlock();
|
||||
if (!fromBlock.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Block toBlock = Objects.requireNonNull(event.getTo()).getBlock();
|
||||
if (fromBlock.equals(toBlock))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Make this particles instead of blocks!
|
||||
fromBlock.setType(Groups.WOOL_COLORS.get(random.nextInt(Groups.WOOL_COLORS.size())));
|
||||
BlockData data = fromBlock.getBlockData();
|
||||
Material material = Material.getMaterial(String.valueOf(fromBlock.getType()));
|
||||
for (int x = -1; x <= 1; x++)
|
||||
{
|
||||
for (int z = -1; z <= 1; z++)
|
||||
{
|
||||
final Location trail_pos;
|
||||
trail_pos = new Location(event.getPlayer().getWorld(), fromBlock.getX() + x, fromBlock.getY(), fromBlock.getZ() + z);
|
||||
if (trailPlayers.contains(event.getPlayer().getUniqueId()) && plugin.cpb.isEnabled())
|
||||
{
|
||||
plugin.cpb.getCoreProtectAPI().logPlacement(event.getPlayer().getName(), trail_pos, material, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
final Player player = event.getPlayer();
|
||||
final ParticleDisplay particleDisplay = trailPlayers.get(player.getUniqueId());
|
||||
particleDisplay.spawnNext(player);
|
||||
}
|
||||
|
||||
public void remove(Player player)
|
||||
@ -91,11 +58,13 @@ public class Trailer extends FreedomService
|
||||
|
||||
public void add(Player player)
|
||||
{
|
||||
trailPlayers.add(player.getUniqueId());
|
||||
if (trailPlayers.containsKey(player.getUniqueId())) return;
|
||||
|
||||
trailPlayers.put(player.getUniqueId(), new ParticleDisplay());
|
||||
}
|
||||
|
||||
public boolean contains(Player player)
|
||||
{
|
||||
return trailPlayers.contains(player.getUniqueId());
|
||||
return trailPlayers.containsKey(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user