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 java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
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;
|
|
|
|
import com.intellectualcrafters.plot.object.Plot;
|
2015-02-21 12:38:44 +01:00
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
2015-02-22 07:06:59 +01:00
|
|
|
import com.intellectualcrafters.plot.util.MainUtil;
|
2015-07-10 16:08:07 +02:00
|
|
|
import com.intellectualcrafters.plot.util.Permissions;
|
2015-07-26 16:51:12 +02:00
|
|
|
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
2014-10-03 04:36:30 +02:00
|
|
|
|
2014-09-24 14:21:43 +02:00
|
|
|
public class Visit extends SubCommand {
|
2014-11-05 04:42:08 +01:00
|
|
|
public Visit() {
|
|
|
|
super("visit", "plots.visit", "Visit someones plot", "visit {player} [#]", "v", CommandCategory.TELEPORT, true);
|
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
public List<Plot> getPlots(final UUID uuid) {
|
|
|
|
final List<Plot> plots = new ArrayList<>();
|
2015-07-03 14:15:20 +02:00
|
|
|
for (final Plot p : PS.get().getPlots()) {
|
2015-03-20 04:00:02 +01:00
|
|
|
if (p.hasOwner() && p.isOwner(uuid)) {
|
2014-11-05 04:42:08 +01:00
|
|
|
plots.add(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return plots;
|
|
|
|
}
|
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-06-24 05:31:13 +02:00
|
|
|
return sendMessage(plr, C.COMMAND_SYNTAX, "/plot visit <player|alias|world|id> [#]");
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-06-24 05:31:13 +02:00
|
|
|
ArrayList<Plot> plots = new ArrayList<>();
|
|
|
|
UUID user = UUIDHandler.getUUID(args[0]);
|
|
|
|
if (user != null ) {
|
|
|
|
// do plots by username
|
2015-07-03 14:15:20 +02:00
|
|
|
plots.addAll(PS.get().getPlots(user));
|
|
|
|
} else if (PS.get().isPlotWorld(args[0])) {
|
2015-06-24 05:31:13 +02:00
|
|
|
// do plots by world
|
2015-07-03 14:15:20 +02:00
|
|
|
plots.addAll(PS.get().getPlots(args[0]).values());
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-06-24 05:31:13 +02:00
|
|
|
else {
|
2015-06-24 22:33:43 +02:00
|
|
|
Plot plot = MainUtil.getPlotFromString(plr, args[0], true);
|
2015-06-24 05:31:13 +02:00
|
|
|
if (plot == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
plots.add(plot);
|
|
|
|
}
|
|
|
|
if (plots.size() == 0) {
|
|
|
|
sendMessage(plr, C.FOUND_NO_PLOTS);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int index = 0;
|
|
|
|
if (args.length == 2) {
|
|
|
|
try {
|
|
|
|
index = Integer.parseInt(args[1]) - 1;
|
|
|
|
if (index < 0 || index >= plots.size()) {
|
|
|
|
sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
|
|
|
|
sendMessage(plr, C.COMMAND_SYNTAX, "/plot visit " + args[0] + " [#]");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
|
|
|
|
sendMessage(plr, C.COMMAND_SYNTAX, "/plot visit " + args[0] + " [#]");
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-06-24 05:31:13 +02:00
|
|
|
|
|
|
|
Plot plot = plots.get(index);
|
|
|
|
if (!plot.hasOwner()) {
|
2015-07-10 16:08:07 +02:00
|
|
|
if (!Permissions.hasPermission(plr, "plots.visit.unowned")) {
|
2015-06-24 05:31:13 +02:00
|
|
|
sendMessage(plr, C.NO_PERMISSION, "plots.visit.unowned");
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-06-24 05:31:13 +02:00
|
|
|
else if (plot.isOwner(plr.getUUID())) {
|
2015-07-10 16:08:07 +02:00
|
|
|
if (!Permissions.hasPermission(plr, "plots.visit.owned") && !Permissions.hasPermission(plr, "plots.home")) {
|
2015-06-24 22:13:32 +02:00
|
|
|
sendMessage(plr, C.NO_PERMISSION, "plots.visit.owned, plots.home");
|
2015-06-24 05:31:13 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (plot.isAdded(plr.getUUID())) {
|
2015-07-10 16:08:07 +02:00
|
|
|
if (!Permissions.hasPermission(plr, "plots.visit.shared")) {
|
2015-06-24 05:31:13 +02:00
|
|
|
sendMessage(plr, C.NO_PERMISSION, "plots.visit.shared");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-07-10 16:08:07 +02:00
|
|
|
if (!Permissions.hasPermission(plr, "plots.visit.other")) {
|
2015-06-24 05:31:13 +02:00
|
|
|
sendMessage(plr, C.NO_PERMISSION, "plots.visit.other");
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-06-24 05:31:13 +02:00
|
|
|
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(index));
|
2014-11-05 04:42:08 +01:00
|
|
|
return true;
|
2015-06-24 05:31:13 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// // from alias
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// id = PlotId.fromString(args[0]);
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// final String username = args[0];
|
|
|
|
// final UUID uuid = UUIDHandler.getUUID(username);
|
|
|
|
// List<Plot> plots = null;
|
|
|
|
// if (uuid != null) {
|
|
|
|
// plots = PlotSquared.sortPlotsByWorld(getPlots(uuid));
|
|
|
|
// }
|
|
|
|
// if ((uuid == null) || plots.isEmpty()) {
|
|
|
|
// return sendMessage(plr, C.FOUND_NO_PLOTS);
|
|
|
|
// }
|
|
|
|
// if (args.length < 2) {
|
|
|
|
// MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0));
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// int i;
|
|
|
|
// try {
|
|
|
|
// i = Integer.parseInt(args[1]);
|
|
|
|
// } catch (final Exception e) {
|
|
|
|
// return sendMessage(plr, C.NOT_VALID_NUMBER);
|
|
|
|
// }
|
|
|
|
// if ((i < 1) || (i > plots.size())) {
|
|
|
|
// return sendMessage(plr, C.NOT_VALID_NUMBER);
|
|
|
|
// }
|
|
|
|
// MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(i - 1));
|
|
|
|
// return true;
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|