Skip to content

Instantly share code, notes, and snippets.

@SpaceManiac
Created February 6, 2014 03:26
Show Gist options
  • Save SpaceManiac/8837964 to your computer and use it in GitHub Desktop.
Save SpaceManiac/8837964 to your computer and use it in GitHub Desktop.
Testing materials for Bukkit Particles PR
package particletest;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.material.MaterialData;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
/**
* Simple test plugin for particles PR.
*/
public class ParticleTestPlugin extends JavaPlugin {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length < 1) {
return false;
}
if (!(sender instanceof Player)) {
sender.sendMessage("Must be player");
return true;
}
String subcmd = args[0];
Player player = (Player) sender;
if (subcmd.equalsIgnoreCase("list")) {
Particle[] vals = Particle.values();
player.sendMessage("Available particles (" + vals.length + "): " + StringUtils.join(vals, ", "));
} else if (subcmd.equalsIgnoreCase("all")) {
int i = 0;
for (Particle particle : Particle.values()) {
if (!particle.usesMaterial()) {
new DoThings(player, particle).runTaskLater(this, i * 40);
++i;
}
}
} else {
Particle particle;
try {
particle = Particle.valueOf(subcmd);
} catch (IllegalArgumentException e) {
player.sendMessage("No such particle " + subcmd + ", try \"list\"");
return true;
}
MaterialData data = null;
if (particle.usesMaterial()) {
if (args.length < 2) {
player.sendMessage("Must provide material");
return true;
}
data = new MaterialData(Material.matchMaterial(args[1]));
}
if (particle.usesData() && args.length < 3) {
if (args.length < 3) {
player.sendMessage("Must provide data");
return true;
}
assert data != null;
data.setData(Byte.valueOf(args[2]));
}
Location loc = player.getLocation().add(0, 3, 0);
getServer().broadcastMessage("Showing particle: " + particle + " with spread 0.3, speed 0.2, count 20, data " + data);
player.getWorld().showParticle(loc, particle, data, 0.3f, 0.3f, 0.3f, 0.2f, 20);
}
return true;
}
private class DoThings extends BukkitRunnable {
private final Player player;
private final Particle particle;
public DoThings(Player player, Particle particle) {
this.player = player;
this.particle = particle;
}
public void run() {
player.sendMessage("Showing particle: " + particle + " with spread 0.3, speed 0.2, count 20");
player.showParticle(player.getLocation().add(0, 3, 0), particle, 0.3f, 0.3f, 0.3f, 0.2f, 20);
}
}
}
name: ParticleTest
main: particletest.ParticleTestPlugin
author: SpaceManiac
version: 1.0
# commands
commands:
particles:
aliases: [ perms, perm ]
description: Commands for manipulating permissions.
usage: |
/<command> all - perform test sequence
/<command> list - show list of particles
/<command> PARTICLE_NAME - play one particle with specified values
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ParticleTest</groupId>
<artifactId>ParticleTest</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>bukkit</id>
<name>Bukkit Artifactory</name>
<layout>default</layout>
<url>http://repo.bukkit.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.7.2-R0.3-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment