2014-09-22 13:02:14 +02:00
|
|
|
/*
|
2014-10-12 00:37:36 -07:00
|
|
|
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute
|
|
|
|
* and/or monetize any of our intellectual property. IntellectualCrafters is not
|
|
|
|
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB.
|
|
|
|
*
|
|
|
|
* >> File = Home.java >> Generated by: Citymonstret at 2014-08-09 01:41
|
2014-09-22 13:02:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2014-09-24 22:21:43 +10:00
|
|
|
import com.intellectualcrafters.plot.C;
|
|
|
|
import com.intellectualcrafters.plot.PlayerFunctions;
|
|
|
|
import com.intellectualcrafters.plot.Plot;
|
|
|
|
import com.intellectualcrafters.plot.PlotMain;
|
2014-09-22 13:02:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Citymonstret
|
|
|
|
*/
|
2014-09-24 22:21:43 +10:00
|
|
|
public class Home extends SubCommand {
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-10-11 00:33:10 -07:00
|
|
|
public Home() {
|
2014-10-18 11:06:29 -07:00
|
|
|
super(Command.HOME, "Go to your plot", "home {id|alias}", CommandCategory.TELEPORT, true);
|
2014-10-11 00:33:10 -07:00
|
|
|
}
|
2014-10-03 12:36:30 +10:00
|
|
|
|
2014-10-11 00:33:10 -07:00
|
|
|
private Plot isAlias(String a) {
|
|
|
|
for (Plot p : PlotMain.getPlots()) {
|
2014-10-12 00:37:36 -07:00
|
|
|
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
|
2014-10-11 00:33:10 -07:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2014-09-24 22:21:43 +10:00
|
|
|
|
2014-10-11 00:33:10 -07:00
|
|
|
@Override
|
|
|
|
public boolean execute(Player plr, String... args) {
|
|
|
|
Plot[] plots = PlotMain.getPlots(plr).toArray(new Plot[0]);
|
|
|
|
if (plots.length == 1) {
|
|
|
|
PlotMain.teleportPlayer(plr, plr.getLocation(), plots[0]);
|
|
|
|
return true;
|
2014-10-12 00:37:36 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (plots.length > 1) {
|
|
|
|
if (args.length < 1) {
|
|
|
|
args = new String[] { "1" };
|
|
|
|
}
|
|
|
|
int id = 0;
|
|
|
|
try {
|
|
|
|
id = Integer.parseInt(args[0]);
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
Plot temp;
|
|
|
|
if ((temp = isAlias(args[0])) != null) {
|
|
|
|
if (temp.hasOwner()) {
|
|
|
|
if (temp.getOwner().equals(plr.getUniqueId())) {
|
|
|
|
PlotMain.teleportPlayer(plr, plr.getLocation(), temp);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-11 00:33:10 -07:00
|
|
|
}
|
2014-10-12 00:37:36 -07:00
|
|
|
PlayerFunctions.sendMessage(plr, C.NOT_YOUR_PLOT);
|
|
|
|
return false;
|
2014-10-11 00:33:10 -07:00
|
|
|
}
|
2014-10-12 00:37:36 -07:00
|
|
|
PlayerFunctions.sendMessage(plr, C.NOT_VALID_NUMBER);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ((id > (plots.length)) || (id < 1)) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.NOT_VALID_NUMBER);
|
2014-10-11 00:33:10 -07:00
|
|
|
return false;
|
|
|
|
}
|
2014-10-12 00:37:36 -07:00
|
|
|
PlotMain.teleportPlayer(plr, plr.getLocation(), plots[id - 1]);
|
2014-10-11 00:33:10 -07:00
|
|
|
return true;
|
|
|
|
}
|
2014-10-12 00:37:36 -07:00
|
|
|
else {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.NO_PLOTS);
|
|
|
|
return true;
|
2014-10-11 00:33:10 -07:00
|
|
|
}
|
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|