Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added colors and fixed invisible armor stand problem #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ authors: [Dumbo52]
commands:
stand:
description: StandMaster9000 commands
aliases: [sm, standmaster]
aliases: [sm, standmaster, standmaster9000]
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.michaelelin</groupId>
<artifactId>StandMaster9000</artifactId>
<version>0.0.3</version>
<version>0.0.4</version>
<name>StandMaster9000</name>
<url>https://github.com/Dumbo52/StandMaster9000</url>
<build>
Expand Down Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8-R0.1-SNAPSHOT</version>
<version>1.8.7-R0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<description>Allows in-game editing of armor stand data.</description>
Expand Down
6 changes: 5 additions & 1 deletion src/com/michaelelin/standmaster/CommandTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.michaelelin.standmaster.command.PresetCommand;
import com.michaelelin.standmaster.command.PresetRemoveCommand;
import com.michaelelin.standmaster.command.ReloadCommand;
import com.michaelelin.standmaster.command.RemoveInvisibileCommand;
import com.michaelelin.standmaster.command.RotationCommand;
import com.michaelelin.standmaster.command.StandMasterCommand;
import com.michaelelin.standmaster.config.Configuration;
Expand All @@ -30,6 +31,8 @@ public class CommandTree {
private StandMasterCommand commandBase = new ParentCommand("stand", "Armor stand commands")
.addSubcommand(new ReloadCommand("reload", "Reloads the plugin's configuration")
.setPermission("standmaster.reload"))
.addSubcommand(new RemoveInvisibileCommand("removeinvisible", "Remove all invisible armor stands in a specified radius")
.setPermission("standmaster.removeinvisible"))
.addSubcommand(new PersistCommand("persist", "Prevents your modifier list from clearing")
.setPermission("standmaster.persist"))
.addSubcommand(new PresetCommand("preset", "Loads a modifier preset")
Expand Down Expand Up @@ -95,7 +98,8 @@ protected Configuration getConfig(Player sender) {
.addSubcommand(new ModifierCommand("small", "Makes the stand smaller")
.setPermission("standmaster.stand.small"))
.addAlias("sm")
.addAlias("standmaster");
.addAlias("standmaster")
.addAlias("standmaster9000");

/**
* Run a command from the given sender with the given arguments.
Expand Down
3 changes: 2 additions & 1 deletion src/com/michaelelin/standmaster/ModifierTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.HashMap;
import java.util.Map;

import org.bukkit.ChatColor;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.util.EulerAngle;
Expand Down Expand Up @@ -59,7 +60,7 @@ public void addDefaults() {
DataType.STRING, EntityType.ARMOR_STAND) {
@Override
protected void execute(ArmorStand object, StringData value) {
object.setCustomName(value.value);
object.setCustomName(ChatColor.translateAlternateColorCodes('&', value.value));
object.setCustomNameVisible(true);
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.michaelelin.standmaster.command;

import java.util.Deque;

import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

import com.michaelelin.standmaster.StandMasterException;

public class RemoveInvisibileCommand extends AbstractCommand {


/**
* Construct a command to remove all nearby invisible armor stands
*
* @param name the command's name
* @param description the command's description
*/
public RemoveInvisibileCommand(String name, String description) {
super(name, description);
}

@Override
public void execute(CommandSender sender, Deque<String> context, Deque<String> args) {
if (!(sender instanceof Player)) {
throw new StandMasterException("That command can't be run from console.");
}

// Parse the arguments
if (args.size() != 1) {
throw new StandMasterException(
String.format("USAGE: standmaster9000 %s RADIUS", this.getName()));
}
double radius = 0.0;
try {
radius = Double.parseDouble(args.pop());
} catch (NumberFormatException e) {
StandMasterException sme = new StandMasterException("The radius must be a number.");
sme.addSuppressed(e);
throw sme;
}
if (radius > 25.0 || radius < 0.0) {
throw new StandMasterException("Remove all armor stands in a radius of " + radius + "? LOL. No.");
}

Player player = (Player) sender;
World world = player.getWorld();
Location loc = player.getLocation();
double radius2 = radius * radius;

// Loop through ALL the entities in the entire world and find the closest ones
// (Maybe this is over kill, but this seems to be the best but bukkit API has to offer
for (Entity e : world.getEntities()) {
if (e instanceof ArmorStand) {
ArmorStand a = (ArmorStand)e;
if (!a.isVisible()) {
if (a.getLocation().distanceSquared(loc) < radius2) {
a.remove();
}
}
}
}
}
}