Finalize the mv info command

This commit is contained in:
Eric Stokes 2011-07-31 18:24:09 -06:00
parent 1a938c8ce8
commit 1e9a826999
3 changed files with 125 additions and 68 deletions

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
@ -17,103 +18,136 @@ import com.onarandombox.utils.FancyText;
public class InfoCommand extends MultiverseCommand { public class InfoCommand extends MultiverseCommand {
private static final int CMDS_PER_PAGE = 9;
private List<String> monsterNames = new ArrayList<String>();
private List<String> animalNames = new ArrayList<String>();
public InfoCommand(MultiverseCore plugin) { public InfoCommand(MultiverseCore plugin) {
super(plugin); super(plugin);
this.setName("World Information"); this.setName("World Information");
this.setCommandUsage("/mv info" + ChatColor.GOLD + "[PAGE] [WORLD]"); this.setCommandUsage("/mv info" + ChatColor.GOLD + " [WORLD] [PAGE]");
this.setArgRange(0, 1); this.setArgRange(0, 2);
this.addKey("mvinfo"); this.addKey("mvinfo");
this.addKey("mvi"); this.addKey("mvi");
this.addKey("mv info"); this.addKey("mv info");
this.setPermission("multiverse.core.info", "Returns detailed information on the world.", PermissionDefault.OP); this.setPermission("multiverse.core.info", "Returns detailed information on the world.", PermissionDefault.OP);
this.generateNames();
}
private void generateNames() {
monsterNames.add("Wolf");
monsterNames.add("Creeper");
monsterNames.add("Skeleton");
monsterNames.add("Spider");
monsterNames.add("Slime");
monsterNames.add("Spider Jockey");
monsterNames.add("Ghast");
monsterNames.add("Zombie");
monsterNames.add("Zombie Pigman");
animalNames.add("Pig");
animalNames.add("Sheep");
animalNames.add("Cow");
animalNames.add("Chicken");
animalNames.add("Squid");
} }
@Override @Override
public void runCommand(CommandSender sender, List<String> args) { public void runCommand(CommandSender sender, List<String> args) {
// Check if the command was sent from a Player. // Check if the command was sent from a Player.
String worldName = ""; String worldName = "";
if (sender instanceof Player && args.size() == 0) { int pageNum = 0;
worldName = ((Player) sender).getWorld().getName();
} else if (args.size() == 0) { if (args.size() == 0) {
sender.sendMessage("You must enter a" + ChatColor.GOLD + " world" + ChatColor.WHITE + " from the console!"); if (sender instanceof Player) {
return; Player p = (Player) sender;
} else { worldName = p.getWorld().getName();
worldName = args.get(0); } else {
sender.sendMessage("You must enter a" + ChatColor.LIGHT_PURPLE + " world" + ChatColor.WHITE + " from the console!");
return;
}
} }
else if (args.size() == 1) {
if (this.plugin.getMVWorld(args.get(0)) != null) {
// then we have a world!
worldName = args.get(0);
} else {
if (sender instanceof Player) {
Player p = (Player) sender;
worldName = p.getWorld().getName();
try {
pageNum = Integer.parseInt(args.get(0)) - 1;
} catch (NumberFormatException e) {
pageNum = 0;
}
} else {
sender.sendMessage("You must enter a" + ChatColor.LIGHT_PURPLE + " world" + ChatColor.WHITE + " from the console!");
return;
}
}
}
else if (args.size() == 2) {
worldName = args.get(0);
try {
pageNum = Integer.parseInt(args.get(1)) - 1;
} catch (NumberFormatException e) {
pageNum = 0;
}
}
if (this.plugin.isMVWorld(worldName)) { if (this.plugin.isMVWorld(worldName)) {
showPage(1, sender, this.buildEntireCommand(this.plugin.getMVWorld(worldName))); showPage(pageNum, sender, this.buildEntireCommand(this.plugin.getMVWorld(worldName)));
} else if (this.plugin.getServer().getWorld(worldName) != null) { } else if (this.plugin.getServer().getWorld(worldName) != null) {
sender.sendMessage("That world exists, but multiverse does not know about it!"); sender.sendMessage("That world exists, but multiverse does not know about it!");
sender.sendMessage("You can import it with" + ChatColor.AQUA + "/mv import " + ChatColor.GREEN + worldName + ChatColor.LIGHT_PURPLE + "{ENV}"); sender.sendMessage("You can import it with" + ChatColor.AQUA + "/mv import " + ChatColor.GREEN + worldName + ChatColor.LIGHT_PURPLE + "{ENV}");
sender.sendMessage("For available environments type " + ChatColor.GREEN + "/mv env"); sender.sendMessage("For available environments type " + ChatColor.GREEN + "/mv env");
} }
// Leaving this in so we can have a laugh about it.
// else {
// sender.sendMessage("That world does not exist!");
// sender.sendMessage("You can create it with" + ChatColor.AQUA + "/mv create " + ChatColor.GREEN + worldName + ChatColor.LIGHT_PURPLE + "{ENV}");
// sender.sendMessage("For available environments type " + ChatColor.GREEN + "/mv env");
// }
} }
private List<FancyText> buildEntireCommand(MVWorld world) { private List<List<FancyText>> buildEntireCommand(MVWorld world) {
List<FancyText> message = new ArrayList<FancyText>(); List<FancyText> message = new ArrayList<FancyText>();
// World Name: 1 List<List<FancyText>> worldInfo = new ArrayList<List<FancyText>>();
// Page 1
FancyColorScheme colors = new FancyColorScheme(ChatColor.AQUA, ChatColor.AQUA, ChatColor.GOLD, ChatColor.WHITE); FancyColorScheme colors = new FancyColorScheme(ChatColor.AQUA, ChatColor.AQUA, ChatColor.GOLD, ChatColor.WHITE);
message.add(new FancyHeader("General Info", colors)); message.add(new FancyHeader("General Info", colors));
message.add(new FancyMessage("World Name: ", world.getName(), colors)); message.add(new FancyMessage("World Name: ", world.getName(), colors));
message.add(new FancyMessage("World Alias: ", world.getColoredWorldString(), colors)); message.add(new FancyMessage("World Alias: ", world.getColoredWorldString(), colors));
message.add(new FancyMessage("Seed: ", world.getCBWorld().getSeed() + "", colors));
Location spawn = world.getCBWorld().getSpawnLocation();
message.add(new FancyMessage("Spawn Location: ", "(" + spawn.getBlockX() + ", " + spawn.getBlockY() + ", " + spawn.getBlockZ() + ")", colors));
message.add(new FancyMessage("World Scale: ", world.getScaling().toString(), colors)); message.add(new FancyMessage("World Scale: ", world.getScaling().toString(), colors));
if (world.getPrice() > 0) {
message.add(new FancyMessage("Price to enter this world: ", this.plugin.getBank().getFormattedAmount(world.getPrice(), world.getCurrency()), colors));
} else {
message.add(new FancyMessage("Price to enter this world: ", ChatColor.GREEN + "FREE!", colors));
}
if (world.getRespawnToWorld() != null) {
message.add(new FancyMessage("Players will respawn in: ", world.getColoredWorldString(), colors));
}
worldInfo.add(message);
// Page 2
message = new ArrayList<FancyText>();
message.add(new FancyHeader("PVP Settings", colors)); message.add(new FancyHeader("PVP Settings", colors));
message.add(new FancyMessage("Multiverse Setting: ", world.getPvp().toString(), colors)); message.add(new FancyMessage("Multiverse Setting: ", world.getPvp().toString(), colors));
message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getPVP() + "", colors)); message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getPVP() + "", colors));
message.add(new FancyMessage("Fake PVP Enabled: ", world.getFakePVP() + "", colors)); message.add(new FancyMessage("Fake PVP Enabled: ", world.getFakePVP() + "", colors));
// Next is a blank worldInfo.add(message);
message.add(new FancyMessage(" ", "", colors)); // Page 3
message.add(new FancyMessage(ChatColor.DARK_PURPLE + "X more pages", "", colors)); message = new ArrayList<FancyText>();
message.add(new FancyHeader("Monster Settings", colors)); message.add(new FancyHeader("Monster Settings", colors));
message.add(new FancyMessage("Multiverse Setting: ", world.allowMonsterSpawning().toString(), colors)); message.add(new FancyMessage("Multiverse Setting: ", world.allowMonsterSpawning().toString(), colors));
message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getAllowMonsters() + "", colors)); message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getAllowMonsters() + "", colors));
boolean warnings = false;
if (MultiverseCore.MobsDisabledInDefaultWorld) { if (MultiverseCore.MobsDisabledInDefaultWorld) {
message.add(new FancyMessage(ChatColor.RED + "WARNING: ", "Monsters WILL NOT SPAWN IN THIS WORLD.", colors)); message.add(new FancyMessage(ChatColor.RED + "WARNING: ", "Monsters WILL NOT SPAWN IN THIS WORLD.", colors));
message.add(new FancyMessage(ChatColor.RED + "WARNING: ", "Check your server log for more details.", colors)); message.add(new FancyMessage(ChatColor.RED + "WARNING: ", "Check your server log for more details.", colors));
} }
if (world.getMonsterList().size() > 0) { if (world.getMonsterList().size() > 0) {
if (world.allowMonsterSpawning()) { if (world.allowMonsterSpawning()) {
message.add(new FancyMessage("Monsters That" + ChatColor.RED + " CAN NOT " + ChatColor.GREEN + "spawn: ", toCommaSeperated(world.getMonsterList()), colors)); message.add(new FancyMessage("Monsters that" + ChatColor.RED + " CAN NOT " + ChatColor.GREEN + "spawn: ", toCommaSeperated(world.getMonsterList()), colors));
} else { } else {
message.add(new FancyMessage("Monsters That" + ChatColor.GREEN + " CAN SPAWN: ", toCommaSeperated(world.getMonsterList()), colors)); message.add(new FancyMessage("Monsters that" + ChatColor.GREEN + " CAN SPAWN: ", toCommaSeperated(world.getMonsterList()), colors));
} }
} else { } else {
message.add(new FancyMessage("Monsters That CAN spawn: ", world.allowMonsterSpawning() ? "ALL" : "NONE", colors)); message.add(new FancyMessage("Monsters that CAN spawn: ", world.allowMonsterSpawning() ? "ALL" : "NONE", colors));
} }
worldInfo.add(message);
return message; // Page 4
message = new ArrayList<FancyText>();
message.add(new FancyHeader("Animal Settings", colors));
message.add(new FancyMessage("Multiverse Setting: ", world.allowAnimalSpawning().toString(), colors));
message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getAllowAnimals() + "", colors));
if (world.getMonsterList().size() > 0) {
if (world.allowMonsterSpawning()) {
message.add(new FancyMessage("Animals that" + ChatColor.RED + " CAN NOT " + ChatColor.GREEN + "spawn: ", toCommaSeperated(world.getMonsterList()), colors));
} else {
message.add(new FancyMessage("Animals that" + ChatColor.GREEN + " CAN SPAWN: ", toCommaSeperated(world.getMonsterList()), colors));
}
} else {
message.add(new FancyMessage("Animals that CAN spawn: ", world.allowMonsterSpawning() ? "ALL" : "NONE", colors));
}
worldInfo.add(message);
return worldInfo;
} }
private String toCommaSeperated(List<String> list) { private String toCommaSeperated(List<String> list) {
@ -130,27 +164,49 @@ public class InfoCommand extends MultiverseCommand {
return positive ? ChatColor.GREEN : ChatColor.RED; return positive ? ChatColor.GREEN : ChatColor.RED;
} }
private void showPage(int page, CommandSender sender, List<FancyText> messages) { private void showPage(int page, CommandSender sender, List<List<FancyText>> doc) {
int start = (sender instanceof Player) ? (page - 1) * CMDS_PER_PAGE : 0; page = page < 0 ? 0 : page;
int end = (sender instanceof Player) ? start + CMDS_PER_PAGE : messages.size(); page = page > doc.size() - 1 ? doc.size() - 1 : page;
boolean altColor = false; boolean altColor = false;
for (int i = start; i < end; i++) { boolean appendedPageNum = false;
// For consistancy, print some extra lines if it's a player: if (sender instanceof Player) {
if (i < messages.size()) { List<FancyText> list = doc.get(page);
for (FancyText fancyT : list) {
if (messages.get(i) instanceof FancyMessage) { if (fancyT instanceof FancyMessage) {
FancyMessage text = (FancyMessage) messages.get(i); FancyMessage text = (FancyMessage) fancyT;
text.setAltColor(altColor); text.setAltColor(altColor);
altColor = !altColor; altColor = !altColor;
sender.sendMessage(text.getFancyText()); sender.sendMessage(text.getFancyText());
} else { } else if (fancyT instanceof FancyHeader) {
FancyText text = messages.get(i); FancyHeader text = (FancyHeader) fancyT;
if (!appendedPageNum) {
text.appendText(ChatColor.DARK_PURPLE + " [ Page " + (page + 1) + " of " + doc.size() + " ]");
appendedPageNum = true;
}
sender.sendMessage(text.getFancyText()); sender.sendMessage(text.getFancyText());
altColor = false; altColor = false;
} }
}
} else if (sender instanceof Player) { } else {
sender.sendMessage(" "); for (List<FancyText> list : doc) {
for (FancyText fancyT : list) {
if (fancyT instanceof FancyMessage) {
FancyMessage text = (FancyMessage) fancyT;
text.setAltColor(altColor);
altColor = !altColor;
sender.sendMessage(text.getFancyText());
} else {
FancyText text = fancyT;
if (appendedPageNum) {
sender.sendMessage(" ");
} else {
appendedPageNum = true;
}
sender.sendMessage(text.getFancyText());
altColor = false;
}
}
} }
} }
} }

View File

@ -1,10 +1,7 @@
package com.onarandombox.MultiverseCore.commands; package com.onarandombox.MultiverseCore.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;

View File

@ -12,7 +12,11 @@ public class FancyHeader implements FancyText {
@Override @Override
public String getFancyText() { public String getFancyText() {
return colors.getHeader() + "--- " + text + " ---"; return colors.getHeader() + "--- " + text + colors.getHeader() + " ---";
}
public void appendText(String string) {
this.text += string;
} }
} }