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;
|
|
|
|
|
2015-07-05 17:44:10 +02:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
2015-07-03 14:15:20 +02:00
|
|
|
import com.intellectualcrafters.plot.PS;
|
2014-11-16 10:48:18 +01:00
|
|
|
import com.intellectualcrafters.plot.config.C;
|
2015-02-22 13:51:02 +01:00
|
|
|
import com.intellectualcrafters.plot.object.Location;
|
2014-11-16 10:48:18 +01:00
|
|
|
import com.intellectualcrafters.plot.object.Plot;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotId;
|
2015-02-21 12:38:44 +01:00
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
2015-02-22 13:51:02 +01:00
|
|
|
import com.intellectualcrafters.plot.util.BlockManager;
|
2015-02-20 12:23:48 +01:00
|
|
|
import com.intellectualcrafters.plot.util.MainUtil;
|
2015-02-22 13:51:02 +01:00
|
|
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
2014-11-09 12:51:17 +01:00
|
|
|
|
2014-09-22 13:02:14 +02:00
|
|
|
/**
|
|
|
|
* @author Citymonstret
|
|
|
|
*/
|
|
|
|
public class TP extends SubCommand {
|
2014-11-05 04:42:08 +01:00
|
|
|
public TP() {
|
|
|
|
super(Command.TP, "Teleport to a plot", "tp {alias|id}", CommandCategory.TELEPORT, true);
|
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
@Override
|
2015-02-21 08:30:55 +01:00
|
|
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
2014-11-05 04:42:08 +01:00
|
|
|
if (args.length < 1) {
|
2015-02-21 12:24:46 +01:00
|
|
|
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
|
2014-11-05 04:42:08 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final String id = args[0];
|
|
|
|
PlotId plotid;
|
2015-02-23 02:32:27 +01:00
|
|
|
final Location loc = plr.getLocation();
|
|
|
|
final String pworld = loc.getWorld();
|
2015-02-22 13:51:02 +01:00
|
|
|
String world = pworld;
|
2014-11-05 04:42:08 +01:00
|
|
|
if (args.length == 2) {
|
2015-02-22 13:51:02 +01:00
|
|
|
if (BlockManager.manager.isWorld(args[1])) {
|
|
|
|
world = args[1];
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
|
|
|
}
|
2015-07-03 14:15:20 +02:00
|
|
|
if (!PS.get().isPlotWorld(world)) {
|
2015-02-21 12:24:46 +01:00
|
|
|
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
2014-11-05 04:42:08 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Plot temp;
|
|
|
|
if ((temp = isAlias(world, id)) != null) {
|
2015-02-21 15:13:34 +01:00
|
|
|
MainUtil.teleportPlayer(plr, plr.getLocation(), temp);
|
2014-11-05 04:42:08 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
plotid = new PlotId(Integer.parseInt(id.split(";")[0]), Integer.parseInt(id.split(";")[1]));
|
2015-02-21 15:13:34 +01:00
|
|
|
MainUtil.teleportPlayer(plr, plr.getLocation(), MainUtil.getPlot(world, plotid));
|
2014-11-05 04:42:08 +01:00
|
|
|
return true;
|
2014-12-18 03:15:11 +01:00
|
|
|
} catch (final Exception e) {
|
2015-02-21 12:24:46 +01:00
|
|
|
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2015-02-22 13:51:02 +01:00
|
|
|
private Plot isAlias(final String world, String a) {
|
2014-11-05 04:42:08 +01:00
|
|
|
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];
|
|
|
|
}
|
2015-02-22 13:51:02 +01:00
|
|
|
final PlotPlayer player = UUIDHandler.getPlayer(a);
|
2014-11-05 04:42:08 +01:00
|
|
|
if (player != null) {
|
2015-07-03 14:15:20 +02:00
|
|
|
final java.util.Set<Plot> plotMainPlots = PS.get().getPlots(world, player);
|
2014-12-16 06:03:20 +01:00
|
|
|
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;
|
|
|
|
}
|
2015-07-03 14:15:20 +02:00
|
|
|
for (final Plot p : PS.get().getPlots(world).values()) {
|
2015-07-21 20:31:12 +02:00
|
|
|
if ((p.getSettings().getAlias().length() > 0) && p.getSettings().getAlias().equalsIgnoreCase(a)) {
|
2014-11-05 04:42:08 +01:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|