2014-11-08 20:27:09 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
|
|
|
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
|
|
|
// /
|
|
|
|
// This program is free software; you can redistribute it and/or modify /
|
|
|
|
// it under the terms of the GNU General Public License as published by /
|
|
|
|
// the Free Software Foundation; either version 3 of the License, or /
|
|
|
|
// (at your option) any later version. /
|
|
|
|
// /
|
|
|
|
// This program is distributed in the hope that it will be useful, /
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
|
|
|
// GNU General Public License for more details. /
|
|
|
|
// /
|
|
|
|
// You should have received a copy of the GNU General Public License /
|
|
|
|
// along with this program; if not, write to the Free Software Foundation, /
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
|
|
|
// /
|
|
|
|
// You can contact us via: support@intellectualsites.com /
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
2014-09-22 13:02:14 +02:00
|
|
|
|
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
import com.intellectualcrafters.plot.PlotMain;
|
|
|
|
import com.intellectualcrafters.plot.config.C;
|
|
|
|
import com.intellectualcrafters.plot.object.Plot;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotId;
|
|
|
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
|
|
|
import com.intellectualcrafters.plot.util.PlotHelper;
|
2014-09-30 13:17:55 +02:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2014-09-22 13:02:14 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2014-11-09 12:51:17 +01:00
|
|
|
|
2014-09-22 13:02:14 +02:00
|
|
|
/**
|
|
|
|
* @author Citymonstret
|
|
|
|
*/
|
|
|
|
public class TP extends SubCommand {
|
2014-09-24 14:21:43 +02:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
public TP() {
|
|
|
|
super(Command.TP, "Teleport to a plot", "tp {alias|id}", CommandCategory.TELEPORT, true);
|
|
|
|
}
|
2014-09-24 14:21:43 +02:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
@Override
|
|
|
|
public boolean execute(final Player plr, final String... args) {
|
|
|
|
if (args.length < 1) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.NEED_PLOT_ID);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final String id = args[0];
|
|
|
|
PlotId plotid;
|
|
|
|
World world = plr.getWorld();
|
|
|
|
if (args.length == 2) {
|
|
|
|
if (Bukkit.getWorld(args[1]) != null) {
|
|
|
|
world = Bukkit.getWorld(args[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!PlotMain.isPlotWorld(world)) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Plot temp;
|
|
|
|
if ((temp = isAlias(world, id)) != null) {
|
|
|
|
PlotMain.teleportPlayer(plr, plr.getLocation(), temp);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-12 01:18:47 +02:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
try {
|
|
|
|
plotid = new PlotId(Integer.parseInt(id.split(";")[0]), Integer.parseInt(id.split(";")[1]));
|
|
|
|
PlotMain.teleportPlayer(plr, plr.getLocation(), PlotHelper.getPlot(world, plotid));
|
|
|
|
return true;
|
2014-11-08 20:27:09 +01:00
|
|
|
} catch (final Exception e) {
|
2014-11-05 04:42:08 +01:00
|
|
|
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-10-12 01:18:47 +02:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
private Plot isAlias(final World world, String a) {
|
|
|
|
int index = 0;
|
|
|
|
if (a.contains(";")) {
|
|
|
|
final String[] split = a.split(";");
|
|
|
|
if ((split[1].length() > 0) && StringUtils.isNumeric(split[1])) {
|
|
|
|
index = Integer.parseInt(split[1]);
|
|
|
|
}
|
|
|
|
a = split[0];
|
|
|
|
}
|
2014-11-09 12:51:17 +01:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-11-05 04:42:08 +01:00
|
|
|
final Player player = Bukkit.getPlayer(a);
|
|
|
|
if (player != null) {
|
2014-11-09 12:51:17 +01:00
|
|
|
final java.util.Set<Plot> plotMainPlots =
|
|
|
|
PlotMain.getPlots(world, player);
|
|
|
|
final Plot[] plots =
|
|
|
|
plotMainPlots.toArray(new Plot[plotMainPlots.size()]);
|
2014-11-05 04:42:08 +01:00
|
|
|
if (plots.length > index) {
|
|
|
|
return plots[index];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
for (final Plot p : PlotMain.getPlots(world).values()) {
|
|
|
|
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|