From bf083106d98ed7f7d0e502bd3fff8740739f5228 Mon Sep 17 00:00:00 2001 From: Tobias Ottenweller Date: Tue, 28 Feb 2012 13:41:47 +0100 Subject: [PATCH] new command: rename --- src/org/mcteam/ancientgates/Plugin.java | 2 + .../ancientgates/commands/CommandHelp.java | 26 +++++++++--- .../ancientgates/commands/CommandRename.java | 40 +++++++++++++++++++ 3 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 src/org/mcteam/ancientgates/commands/CommandRename.java diff --git a/src/org/mcteam/ancientgates/Plugin.java b/src/org/mcteam/ancientgates/Plugin.java index b5419df..3b3546d 100644 --- a/src/org/mcteam/ancientgates/Plugin.java +++ b/src/org/mcteam/ancientgates/Plugin.java @@ -23,6 +23,7 @@ import org.mcteam.ancientgates.commands.CommandDelete; import org.mcteam.ancientgates.commands.CommandHelp; import org.mcteam.ancientgates.commands.CommandList; import org.mcteam.ancientgates.commands.CommandOpen; +import org.mcteam.ancientgates.commands.CommandRename; import org.mcteam.ancientgates.commands.CommandSetFrom; import org.mcteam.ancientgates.commands.CommandSetTo; @@ -70,6 +71,7 @@ public class Plugin extends JavaPlugin { commands.add(new CommandSetFrom()); commands.add(new CommandSetTo()); commands.add(new CommandOpen()); + commands.add(new CommandRename()); commands.add(new CommandClose()); commands.add(new CommandList()); diff --git a/src/org/mcteam/ancientgates/commands/CommandHelp.java b/src/org/mcteam/ancientgates/commands/CommandHelp.java index 266fe1d..53560f4 100644 --- a/src/org/mcteam/ancientgates/commands/CommandHelp.java +++ b/src/org/mcteam/ancientgates/commands/CommandHelp.java @@ -23,31 +23,44 @@ public class CommandHelp extends BaseCommand { return true; } - public void perform() { + + public void perform() + { int page = 1; - if (parameters.size() > 0) { - try { + + if (parameters.size() > 0) + { + try + { page = Integer.parseInt(parameters.get(0)); - } catch (NumberFormatException e) { + } + catch (NumberFormatException e) + { // wasn't an integer } } + sendMessage(TextUtil.titleize("AncientGates Help ("+page+"/"+helpPages.size()+")")); + page -= 1; - if (page < 0 || page >= helpPages.size()) { + if (page < 0 || page >= helpPages.size()) + { sendMessage("This page does not exist"); return; } + sendMessage(helpPages.get(page)); } + //----------------------------------------------// // Build the help pages //----------------------------------------------// public static ArrayList> helpPages; - static { + static + { helpPages = new ArrayList>(); ArrayList pageLines; @@ -59,6 +72,7 @@ public class CommandHelp extends BaseCommand { pageLines.add( new CommandSetFrom().getUseageTemplate(true, true) ); pageLines.add( new CommandSetTo().getUseageTemplate(true, true) ); pageLines.add( new CommandOpen().getUseageTemplate(true, true) ); + pageLines.add( new CommandRename().getUseageTemplate(true, true) ); pageLines.add( new CommandClose().getUseageTemplate(true, true) ); pageLines.add( new CommandList().getUseageTemplate(true, true) ); helpPages.add(pageLines); diff --git a/src/org/mcteam/ancientgates/commands/CommandRename.java b/src/org/mcteam/ancientgates/commands/CommandRename.java new file mode 100644 index 0000000..53a58f1 --- /dev/null +++ b/src/org/mcteam/ancientgates/commands/CommandRename.java @@ -0,0 +1,40 @@ +package org.mcteam.ancientgates.commands; + +import org.mcteam.ancientgates.Gate; + + + +public class CommandRename extends BaseCommand +{ + public CommandRename() + { + aliases.add("rename"); + aliases.add("changename"); + aliases.add("cn"); + + hasGateParam = true; + senderMustBePlayer = false; + + requiredParameters.add("current name"); + requiredParameters.add("new name"); + + helpDescription = "Change the name of a gate"; + } + + + public void perform() + { + String newId = parameters.get(1); + String oldId = gate.getId(); + + if (Gate.exists(newId)) + { + sendMessage("Cannot rename " + oldId + ". There is already a gate named " + newId + "."); + return; + } + + Gate.rename(gate, newId); + + sendMessage("Gate " + oldId + " is now known as " + newId + "."); + } +}