new command: rename
This commit is contained in:
parent
0fe721b8c0
commit
bf083106d9
@ -23,6 +23,7 @@ import org.mcteam.ancientgates.commands.CommandDelete;
|
|||||||
import org.mcteam.ancientgates.commands.CommandHelp;
|
import org.mcteam.ancientgates.commands.CommandHelp;
|
||||||
import org.mcteam.ancientgates.commands.CommandList;
|
import org.mcteam.ancientgates.commands.CommandList;
|
||||||
import org.mcteam.ancientgates.commands.CommandOpen;
|
import org.mcteam.ancientgates.commands.CommandOpen;
|
||||||
|
import org.mcteam.ancientgates.commands.CommandRename;
|
||||||
import org.mcteam.ancientgates.commands.CommandSetFrom;
|
import org.mcteam.ancientgates.commands.CommandSetFrom;
|
||||||
import org.mcteam.ancientgates.commands.CommandSetTo;
|
import org.mcteam.ancientgates.commands.CommandSetTo;
|
||||||
|
|
||||||
@ -70,6 +71,7 @@ public class Plugin extends JavaPlugin {
|
|||||||
commands.add(new CommandSetFrom());
|
commands.add(new CommandSetFrom());
|
||||||
commands.add(new CommandSetTo());
|
commands.add(new CommandSetTo());
|
||||||
commands.add(new CommandOpen());
|
commands.add(new CommandOpen());
|
||||||
|
commands.add(new CommandRename());
|
||||||
commands.add(new CommandClose());
|
commands.add(new CommandClose());
|
||||||
commands.add(new CommandList());
|
commands.add(new CommandList());
|
||||||
|
|
||||||
|
@ -23,31 +23,44 @@ public class CommandHelp extends BaseCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void perform() {
|
|
||||||
|
public void perform()
|
||||||
|
{
|
||||||
int page = 1;
|
int page = 1;
|
||||||
if (parameters.size() > 0) {
|
|
||||||
try {
|
if (parameters.size() > 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
page = Integer.parseInt(parameters.get(0));
|
page = Integer.parseInt(parameters.get(0));
|
||||||
} catch (NumberFormatException e) {
|
}
|
||||||
|
catch (NumberFormatException e)
|
||||||
|
{
|
||||||
// wasn't an integer
|
// wasn't an integer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(TextUtil.titleize("AncientGates Help ("+page+"/"+helpPages.size()+")"));
|
sendMessage(TextUtil.titleize("AncientGates Help ("+page+"/"+helpPages.size()+")"));
|
||||||
|
|
||||||
page -= 1;
|
page -= 1;
|
||||||
if (page < 0 || page >= helpPages.size()) {
|
if (page < 0 || page >= helpPages.size())
|
||||||
|
{
|
||||||
sendMessage("This page does not exist");
|
sendMessage("This page does not exist");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(helpPages.get(page));
|
sendMessage(helpPages.get(page));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------//
|
//----------------------------------------------//
|
||||||
// Build the help pages
|
// Build the help pages
|
||||||
//----------------------------------------------//
|
//----------------------------------------------//
|
||||||
|
|
||||||
public static ArrayList<ArrayList<String>> helpPages;
|
public static ArrayList<ArrayList<String>> helpPages;
|
||||||
|
|
||||||
static {
|
static
|
||||||
|
{
|
||||||
helpPages = new ArrayList<ArrayList<String>>();
|
helpPages = new ArrayList<ArrayList<String>>();
|
||||||
ArrayList<String> pageLines;
|
ArrayList<String> pageLines;
|
||||||
|
|
||||||
@ -59,6 +72,7 @@ public class CommandHelp extends BaseCommand {
|
|||||||
pageLines.add( new CommandSetFrom().getUseageTemplate(true, true) );
|
pageLines.add( new CommandSetFrom().getUseageTemplate(true, true) );
|
||||||
pageLines.add( new CommandSetTo().getUseageTemplate(true, true) );
|
pageLines.add( new CommandSetTo().getUseageTemplate(true, true) );
|
||||||
pageLines.add( new CommandOpen().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 CommandClose().getUseageTemplate(true, true) );
|
||||||
pageLines.add( new CommandList().getUseageTemplate(true, true) );
|
pageLines.add( new CommandList().getUseageTemplate(true, true) );
|
||||||
helpPages.add(pageLines);
|
helpPages.add(pageLines);
|
||||||
|
40
src/org/mcteam/ancientgates/commands/CommandRename.java
Normal file
40
src/org/mcteam/ancientgates/commands/CommandRename.java
Normal file
@ -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 + ".");
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user