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-30 16:25:16 +02:00
|
|
|
import java.util.ArrayList;
|
2015-09-15 06:56:23 +02:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashSet;
|
2015-09-12 17:19:39 +02:00
|
|
|
import java.util.Iterator;
|
2015-07-30 16:25:16 +02:00
|
|
|
import java.util.List;
|
2015-09-15 06:56:23 +02:00
|
|
|
import java.util.Set;
|
2015-07-30 16:25:16 +02:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2015-07-03 14:15:20 +02:00
|
|
|
import com.intellectualcrafters.plot.PS;
|
2015-08-04 14:21:12 +02:00
|
|
|
import com.intellectualcrafters.plot.PS.SortType;
|
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-09-15 06:56:23 +02:00
|
|
|
import com.intellectualcrafters.plot.util.MathMan;
|
2015-07-10 16:08:07 +02:00
|
|
|
import com.intellectualcrafters.plot.util.Permissions;
|
2015-07-27 09:26:50 +02:00
|
|
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
2015-07-27 19:50:04 +02:00
|
|
|
import com.plotsquared.general.commands.Argument;
|
|
|
|
import com.plotsquared.general.commands.CommandDeclaration;
|
|
|
|
|
2015-07-26 20:50:54 +02:00
|
|
|
@CommandDeclaration(
|
2015-09-11 12:09:22 +02:00
|
|
|
command = "visit",
|
|
|
|
permission = "plots.visit",
|
|
|
|
description = "Visit someones plot",
|
|
|
|
usage = "/plot visit <player|aliases|world|id> [#]",
|
|
|
|
aliases = { "v" },
|
|
|
|
requiredType = RequiredType.NONE,
|
|
|
|
category = CommandCategory.TELEPORT)
|
2015-09-13 06:04:31 +02:00
|
|
|
public class Visit extends SubCommand {
|
|
|
|
|
|
|
|
public Visit() {
|
|
|
|
requiredArguments = new Argument[] { Argument.String };
|
2015-07-31 20:27:32 +02:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
|
|
|
public List<Plot> getPlots(final UUID uuid) {
|
2014-11-05 04:42:08 +01:00
|
|
|
final List<Plot> plots = new ArrayList<>();
|
2015-09-13 06:04:31 +02:00
|
|
|
for (final Plot p : PS.get().getPlots()) {
|
|
|
|
if (p.hasOwner() && p.isOwner(uuid)) {
|
2014-11-05 04:42:08 +01:00
|
|
|
plots.add(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return plots;
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
@Override
|
2015-09-15 06:56:23 +02:00
|
|
|
public boolean onCommand(final PlotPlayer player, String[] args) {
|
|
|
|
int page = Integer.MIN_VALUE;
|
|
|
|
Collection<Plot> unsorted = null;
|
|
|
|
if (args.length == 1 && args[0].contains(":")) {
|
|
|
|
args = args[0].split(":");
|
2015-06-24 05:31:13 +02:00
|
|
|
}
|
2015-09-15 06:56:23 +02:00
|
|
|
switch (args.length) {
|
|
|
|
case 2: {
|
|
|
|
if (!MathMan.isInteger(args[1])) {
|
|
|
|
sendMessage(player, C.NOT_VALID_NUMBER, "(1, ∞)");
|
|
|
|
sendMessage(player, C.COMMAND_SYNTAX, "/plot visit " + args[0] + " [#]");
|
2015-06-24 05:31:13 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-09-15 06:56:23 +02:00
|
|
|
page = Integer.parseInt(args[1]);
|
|
|
|
}
|
|
|
|
case 1: {
|
|
|
|
if (page == Integer.MIN_VALUE && MathMan.isInteger(args[0])) {
|
|
|
|
page = Integer.parseInt(args[0]);
|
|
|
|
unsorted = PS.get().getPlots(player);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
final UUID user = UUIDHandler.getCachedUUID(args[0], null);
|
|
|
|
if (user != null) {
|
|
|
|
unsorted = PS.get().getPlots(user);
|
|
|
|
} else if (PS.get().isPlotWorld(args[0])) {
|
|
|
|
unsorted = PS.get().getPlotsInWorld(args[0]);
|
|
|
|
} else {
|
|
|
|
final Plot plot = MainUtil.getPlotFromString(player, args[0], true);
|
|
|
|
if (plot != null) {
|
|
|
|
unsorted = new HashSet<>();
|
|
|
|
unsorted.add(plot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0: {
|
|
|
|
page = 1;
|
|
|
|
unsorted = PS.get().getPlots(player);
|
|
|
|
break;
|
2015-06-24 05:31:13 +02:00
|
|
|
}
|
2015-09-15 06:56:23 +02:00
|
|
|
default: {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (page == Integer.MIN_VALUE) {
|
|
|
|
page = 1;
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-09-15 06:56:23 +02:00
|
|
|
if (unsorted == null || unsorted.size() == 0) {
|
|
|
|
sendMessage(player, C.FOUND_NO_PLOTS);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final Iterator<Plot> iter = unsorted.iterator();
|
2015-09-13 06:04:31 +02:00
|
|
|
while (iter.hasNext()) {
|
|
|
|
if (!iter.next().isBasePlot()) {
|
2015-09-12 17:19:39 +02:00
|
|
|
iter.remove();
|
|
|
|
}
|
|
|
|
}
|
2015-09-15 06:56:23 +02:00
|
|
|
if (page < 1 || page > unsorted.size()) {
|
|
|
|
sendMessage(player, C.NOT_VALID_NUMBER, "(1, " + unsorted.size() + ")");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ArrayList<Plot> plots = PS.get().sortPlotsByTemp(unsorted);
|
|
|
|
final Plot plot = plots.get(page - 1);
|
2015-09-13 06:04:31 +02:00
|
|
|
if (!plot.hasOwner()) {
|
2015-09-15 06:56:23 +02:00
|
|
|
if (!Permissions.hasPermission(player, "plots.visit.unowned")) {
|
|
|
|
sendMessage(player, C.NO_PERMISSION, "plots.visit.unowned");
|
2015-06-24 05:31:13 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-09-15 06:56:23 +02:00
|
|
|
} else if (plot.isOwner(player.getUUID())) {
|
|
|
|
if (!Permissions.hasPermission(player, "plots.visit.owned") && !Permissions.hasPermission(player, "plots.home")) {
|
|
|
|
sendMessage(player, C.NO_PERMISSION, "plots.visit.owned, plots.home");
|
2015-06-24 05:31:13 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-09-15 06:56:23 +02:00
|
|
|
} else if (plot.isAdded(player.getUUID())) {
|
|
|
|
if (!Permissions.hasPermission(player, "plots.visit.shared")) {
|
|
|
|
sendMessage(player, C.NO_PERMISSION, "plots.visit.shared");
|
2015-06-24 05:31:13 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
} else {
|
2015-09-15 06:56:23 +02:00
|
|
|
if (!Permissions.hasPermission(player, "plots.visit.other")) {
|
|
|
|
sendMessage(player, C.NO_PERMISSION, "plots.visit.other");
|
2015-06-24 05:31:13 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-09-15 06:56:23 +02:00
|
|
|
MainUtil.teleportPlayer(player, player.getLocation(), plot);
|
2014-11-05 04:42:08 +01:00
|
|
|
return true;
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|