-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add visualizations of regions, borders and chunks
- Loading branch information
Showing
27 changed files
with
350 additions
and
482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
bukkit-utils/src/main/java/dk/lockfuglsang/minecraft/animation/Animation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dk.lockfuglsang.minecraft.animation; | ||
|
||
import org.bukkit.entity.Player; | ||
|
||
/** | ||
* Common interface for animations | ||
*/ | ||
public interface Animation { | ||
boolean show(); | ||
|
||
boolean hide(); | ||
|
||
Player getPlayer(); | ||
} |
90 changes: 90 additions & 0 deletions
90
bukkit-utils/src/main/java/dk/lockfuglsang/minecraft/animation/AnimationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package dk.lockfuglsang.minecraft.animation; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.Plugin; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
|
||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* Handles particles and per-player block-animations | ||
*/ | ||
public class AnimationHandler { | ||
private final Map<UUID, Set<Animation>> animations = new ConcurrentHashMap<>(); | ||
private final Plugin plugin; | ||
private AnimationTask animationTask; | ||
|
||
private int animTick; | ||
|
||
public AnimationHandler(Plugin plugin) { | ||
this.plugin = plugin; | ||
animTick = plugin.getConfig().getInt("animations.tick", 20); | ||
} | ||
|
||
public void setAnimTick(int animTick) { | ||
this.animTick = animTick; | ||
plugin.getConfig().set("animations.tick", animTick); | ||
} | ||
|
||
public synchronized void addAnimation(Animation animation) { | ||
if (!animations.containsKey(animation.getPlayer().getUniqueId())) { | ||
animations.put(animation.getPlayer().getUniqueId(), new HashSet<Animation>()); | ||
} | ||
animations.get(animation.getPlayer().getUniqueId()).add(animation); | ||
start(); | ||
} | ||
|
||
public synchronized boolean removeAnimations(Player player) { | ||
Set<Animation> animSet = animations.remove(player.getUniqueId()); | ||
if (animSet == null) { | ||
return false; | ||
} | ||
for (Animation animation : animSet) { | ||
animation.hide(); | ||
} | ||
return true; | ||
} | ||
|
||
public synchronized void start() { | ||
if (animationTask == null && !animations.isEmpty()) { | ||
animationTask = new AnimationTask(); | ||
animationTask.runTaskTimerAsynchronously(plugin, 0, animTick); | ||
} | ||
} | ||
|
||
public synchronized void stop() { | ||
if (animationTask != null) { | ||
animationTask.cancel(); | ||
animationTask = null; | ||
} | ||
Collection<Set<Animation>> anims = animations.values(); | ||
for (Set<Animation> animSet : anims) { | ||
for (Animation animation : animSet) { | ||
animation.hide(); | ||
} | ||
} | ||
} | ||
|
||
private class AnimationTask extends BukkitRunnable { | ||
@Override | ||
public void run() { | ||
Collection<Set<Animation>> anims = animations.values(); | ||
for (Set<Animation> animSet : anims) { | ||
for (Animation animation : animSet) { | ||
if (!animation.show()) { | ||
UUID uuid = animation.getPlayer().getUniqueId(); | ||
animations.get(uuid).remove(animation); | ||
if (animations.get(uuid).isEmpty()) { | ||
animations.remove(uuid); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
bukkit-utils/src/main/java/dk/lockfuglsang/minecraft/animation/BlockAnimation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package dk.lockfuglsang.minecraft.animation; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.Material; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Sends (bogus) block-info to the player | ||
*/ | ||
public class BlockAnimation implements Animation { | ||
private final Player player; | ||
private final List<Location> points; | ||
private final Material material; | ||
private final byte data; | ||
private volatile boolean shown; | ||
|
||
public BlockAnimation(Player player, List<Location> points, Material material, byte data) { | ||
this.player = player; | ||
this.points = points; | ||
this.material = material; | ||
this.data = data; | ||
shown = false; | ||
} | ||
|
||
@Override | ||
public boolean show() { | ||
if (!player.isOnline()) { | ||
return false; | ||
} | ||
if (shown) { | ||
return true; | ||
} | ||
for (Location loc : points) { | ||
if (!PlayerHandler.sendBlockChange(player, loc, material, data)) { | ||
return false; | ||
} | ||
} | ||
shown = true; | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean hide() { | ||
try { | ||
if (shown) { | ||
for (Location loc : points) { | ||
if (!PlayerHandler.sendBlockChange(player, loc, loc.getBlock().getType(), loc.getBlock().getData())) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
return false; | ||
} finally { | ||
shown = false; | ||
} | ||
} | ||
|
||
@Override | ||
public Player getPlayer() { | ||
return player; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
bukkit-utils/src/main/java/dk/lockfuglsang/minecraft/animation/ParticleAnimation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package dk.lockfuglsang.minecraft.animation; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.Particle; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* An animation using particles (requires refreshes). | ||
*/ | ||
public class ParticleAnimation implements Animation { | ||
private final Player player; | ||
private final Particle particle; | ||
private final List<Location> points; | ||
private final int animCount; | ||
|
||
public ParticleAnimation(Player player, List<Location> points, Particle particle, int animCount) { | ||
this.player = player; | ||
this.particle = particle; | ||
this.points = points; | ||
this.animCount = animCount; | ||
} | ||
|
||
@Override | ||
public boolean show() { | ||
if (!player.isOnline()) { | ||
return false; | ||
} | ||
for (Location loc : points) { | ||
if (!PlayerHandler.spawnParticle(player, particle, loc, animCount)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean hide() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Player getPlayer() { | ||
return player; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.