mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-10-03 00:57:42 +02:00
Added schem clipboard selection display using particles
This commit is contained in:
parent
3d763bddad
commit
cae214f856
@ -6,14 +6,23 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Particle;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.schems.Clipboard;
|
||||
|
||||
public class AdminSchemCommand extends ConfirmableCommand {
|
||||
// Clipboards
|
||||
private Map<UUID, Clipboard> clipboards;
|
||||
|
||||
// Map containing selection cuboid display tasks
|
||||
private Map<User, Integer> display;
|
||||
private final Particle PARTICLE = Particle.REDSTONE;
|
||||
private final Particle.DustOptions PARTICLE_DUST_OPTIONS = new Particle.DustOptions(Color.RED, 1.0F);
|
||||
|
||||
public AdminSchemCommand(CompositeCommand parent) {
|
||||
super(parent, "schem");
|
||||
}
|
||||
@ -24,7 +33,9 @@ public class AdminSchemCommand extends ConfirmableCommand {
|
||||
setParametersHelp("commands.admin.schem.parameters");
|
||||
setDescription("commands.admin.schem.description");
|
||||
setOnlyPlayer(true);
|
||||
|
||||
clipboards = new HashMap<>();
|
||||
display = new HashMap<>();
|
||||
|
||||
new AdminSchemLoadCommand(this);
|
||||
new AdminSchemPasteCommand(this);
|
||||
@ -45,6 +56,61 @@ public class AdminSchemCommand extends ConfirmableCommand {
|
||||
return clipboards;
|
||||
}
|
||||
|
||||
void showClipboard(User user) {
|
||||
display.putIfAbsent(user, Bukkit.getScheduler().scheduleSyncRepeatingTask(getPlugin(), () -> {
|
||||
if (!user.getPlayer().isOnline()) {
|
||||
hideClipboard(user);
|
||||
}
|
||||
|
||||
if (clipboards.containsKey(user.getUniqueId())) {
|
||||
Clipboard clipboard = clipboards.get(user.getUniqueId());
|
||||
if (clipboard.getPos1() != null && clipboard.getPos2() != null) {
|
||||
int minX = Math.min(clipboard.getPos1().getBlockX(), clipboard.getPos2().getBlockX());
|
||||
int minY = Math.min(clipboard.getPos1().getBlockY(), clipboard.getPos2().getBlockY());
|
||||
int minZ = Math.min(clipboard.getPos1().getBlockZ(), clipboard.getPos2().getBlockZ());
|
||||
int maxX = Math.max(clipboard.getPos1().getBlockX(), clipboard.getPos2().getBlockX());
|
||||
int maxY = Math.max(clipboard.getPos1().getBlockY(), clipboard.getPos2().getBlockY());
|
||||
int maxZ = Math.max(clipboard.getPos1().getBlockZ(), clipboard.getPos2().getBlockZ());
|
||||
|
||||
// Drawing x-axes
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, x, minY, minZ);
|
||||
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, x, maxY, minZ);
|
||||
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, x, minY, maxZ);
|
||||
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, x, maxY, maxZ);
|
||||
}
|
||||
|
||||
// Drawing y-axes
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, minX, y, minZ);
|
||||
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX, y, minZ);
|
||||
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, minX, y, maxZ);
|
||||
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX, y, maxZ);
|
||||
}
|
||||
|
||||
// Drawing z-axes
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, minX, minY, z);
|
||||
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX, minY, z);
|
||||
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, minX, maxY, z);
|
||||
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX, maxY, z);
|
||||
}
|
||||
|
||||
// Drawing origin
|
||||
if (clipboard.getOrigin() != null) {
|
||||
user.spawnParticle(Particle.VILLAGER_HAPPY, null, clipboard.getOrigin().getBlockX() + 0.5, clipboard.getOrigin().getBlockY() + 0.5, clipboard.getOrigin().getBlockZ() + 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}, 20, 20));
|
||||
}
|
||||
|
||||
void hideClipboard(User user) {
|
||||
Bukkit.getScheduler().cancelTask(display.get(user));
|
||||
display.remove(user);
|
||||
}
|
||||
|
||||
File getSchemsFolder() {
|
||||
return new File(getIWM().getDataFolder(getWorld()), "schems");
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ public class AdminSchemPos1Command extends CompositeCommand {
|
||||
clipboard.setPos1(user.getLocation());
|
||||
user.sendMessage("commands.admin.schem.set-pos1", "[vector]", Util.xyz(user.getLocation().toVector()));
|
||||
parent.getClipboards().put(user.getUniqueId(), clipboard);
|
||||
parent.showClipboard(user);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ public class AdminSchemPos2Command extends CompositeCommand {
|
||||
clipboard.setPos2(user.getLocation());
|
||||
user.sendMessage("commands.admin.schem.set-pos2", "[vector]", Util.xyz(user.getLocation().toVector()));
|
||||
parent.getClipboards().put(user.getUniqueId(), clipboard);
|
||||
parent.showClipboard(user);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -33,9 +33,13 @@ public class AdminSchemSaveCommand extends ConfirmableCommand {
|
||||
// Check if file exists
|
||||
File newFile = new File(parent.getSchemsFolder(), args.get(0) + ".schem");
|
||||
if (newFile.exists()) {
|
||||
this.askConfirmation(user, user.getTranslation("commands.admin.schem.file-exists"), () -> clipboard.save(user, args.get(0)));
|
||||
this.askConfirmation(user, user.getTranslation("commands.admin.schem.file-exists"), () -> {
|
||||
parent.hideClipboard(user);
|
||||
clipboard.save(user, args.get(0));
|
||||
});
|
||||
return false;
|
||||
} else {
|
||||
parent.hideClipboard(user);
|
||||
return clipboard.save(user, args.get(0));
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user