mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Forward plot home to plot visit
This commit is contained in:
parent
9682e2914c
commit
c948b18239
@ -478,7 +478,8 @@ public class PS {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (final Plot plot : entry.getValue().values()) {
|
||||
for (Entry<PlotId, Plot> entry2: entry.getValue().entrySet()) {
|
||||
Plot plot = entry2.getValue();
|
||||
for (final PlotFilter filter : filters) {
|
||||
if (!filter.allowsPlot(plot)) {
|
||||
continue;
|
||||
@ -1097,8 +1098,16 @@ public class PS {
|
||||
if (map == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
try {
|
||||
return map.values();
|
||||
}
|
||||
catch (Throwable e) {e.printStackTrace();}
|
||||
HashSet<Plot> toReturn = new HashSet<Plot>(map.entrySet().size());
|
||||
for (Entry<PlotId, Plot> entry : map.entrySet()) {
|
||||
toReturn.add(entry.getValue());
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public Plot getPlot(final String world, final PlotId id) {
|
||||
if (world == lastWorld) {
|
||||
|
@ -20,77 +20,14 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(command = "home", aliases = { "h" }, description = "Go to your plot", usage = "/plot home [id|alias]", category = CommandCategory.TELEPORT, requiredType = RequiredType.NONE)
|
||||
public class Home extends SubCommand {
|
||||
|
||||
private Plot isAlias(final String a) {
|
||||
for (final Plot p : PS.get().getPlots()) {
|
||||
if ((p.getSettings().getAlias().length() > 0) && p.getSettings().getAlias().equalsIgnoreCase(a)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer plr, String[] args) {
|
||||
final Set<Plot> all = PS.get().getPlots(plr);
|
||||
final Iterator<Plot> iter = all.iterator();
|
||||
while (iter.hasNext()) {
|
||||
if (!iter.next().isBasePlot()) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
final ArrayList<Plot> plots = PS.get().sortPlotsByTemp(all);
|
||||
if (plots.size() == 1) {
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0));
|
||||
return true;
|
||||
} else if (plots.size() > 1) {
|
||||
if (args.length < 1) {
|
||||
args = new String[] { "1" };
|
||||
}
|
||||
int id = 0;
|
||||
try {
|
||||
id = Integer.parseInt(args[0]);
|
||||
} catch (final Exception e) {
|
||||
Plot temp;
|
||||
if ((temp = isAlias(args[0])) != null) {
|
||||
if (temp.hasOwner()) {
|
||||
if (temp.isOwner(plr.getUUID())) {
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), temp);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.NOT_YOUR_PLOT);
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
|
||||
return true;
|
||||
}
|
||||
if ((id > (plots.size())) || (id < 1)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
|
||||
return false;
|
||||
}
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(id - 1));
|
||||
return true;
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, C.FOUND_NO_PLOTS);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void teleportPlayer(final PlotPlayer player, final Plot plot) {
|
||||
MainUtil.teleportPlayer(player, player.getLocation(), plot);
|
||||
return MainCommand.getInstance().getCommand("visit").onCommand(plr, args);
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,11 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
@ -31,6 +34,7 @@ import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.MathMan;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.general.commands.Argument;
|
||||
@ -61,71 +65,91 @@ public class Visit extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||
ArrayList<Plot> plots = new ArrayList<>();
|
||||
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(":");
|
||||
}
|
||||
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] + " [#]");
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
// do plots by username
|
||||
plots = PS.get().sortPlotsByTemp(PS.get().getPlots(user));
|
||||
unsorted = PS.get().getPlots(user);
|
||||
} else if (PS.get().isPlotWorld(args[0])) {
|
||||
// do plots by world
|
||||
plots = PS.get().sortPlots(PS.get().getPlotsInWorld(args[0]), SortType.DISTANCE_FROM_ORIGIN, null);
|
||||
unsorted = PS.get().getPlotsInWorld(args[0]);
|
||||
} else {
|
||||
final Plot plot = MainUtil.getPlotFromString(plr, args[0], true);
|
||||
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 (final Exception e) {
|
||||
sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
|
||||
sendMessage(plr, C.COMMAND_SYNTAX, "/plot visit " + args[0] + " [#]");
|
||||
return false;
|
||||
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;
|
||||
}
|
||||
default: {
|
||||
|
||||
final Plot plot = plots.get(index);
|
||||
final Iterator<Plot> iter = plots.iterator();
|
||||
}
|
||||
}
|
||||
if (page == Integer.MIN_VALUE) {
|
||||
page = 1;
|
||||
}
|
||||
if (unsorted == null || unsorted.size() == 0) {
|
||||
sendMessage(player, C.FOUND_NO_PLOTS);
|
||||
return false;
|
||||
}
|
||||
final Iterator<Plot> iter = unsorted.iterator();
|
||||
while (iter.hasNext()) {
|
||||
if (!iter.next().isBasePlot()) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
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);
|
||||
if (!plot.hasOwner()) {
|
||||
if (!Permissions.hasPermission(plr, "plots.visit.unowned")) {
|
||||
sendMessage(plr, C.NO_PERMISSION, "plots.visit.unowned");
|
||||
if (!Permissions.hasPermission(player, "plots.visit.unowned")) {
|
||||
sendMessage(player, C.NO_PERMISSION, "plots.visit.unowned");
|
||||
return false;
|
||||
}
|
||||
} else if (plot.isOwner(plr.getUUID())) {
|
||||
if (!Permissions.hasPermission(plr, "plots.visit.owned") && !Permissions.hasPermission(plr, "plots.home")) {
|
||||
sendMessage(plr, C.NO_PERMISSION, "plots.visit.owned, plots.home");
|
||||
} 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");
|
||||
return false;
|
||||
}
|
||||
} else if (plot.isAdded(plr.getUUID())) {
|
||||
if (!Permissions.hasPermission(plr, "plots.visit.shared")) {
|
||||
sendMessage(plr, C.NO_PERMISSION, "plots.visit.shared");
|
||||
} else if (plot.isAdded(player.getUUID())) {
|
||||
if (!Permissions.hasPermission(player, "plots.visit.shared")) {
|
||||
sendMessage(player, C.NO_PERMISSION, "plots.visit.shared");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!Permissions.hasPermission(plr, "plots.visit.other")) {
|
||||
sendMessage(plr, C.NO_PERMISSION, "plots.visit.other");
|
||||
if (!Permissions.hasPermission(player, "plots.visit.other")) {
|
||||
sendMessage(player, C.NO_PERMISSION, "plots.visit.other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(index));
|
||||
MainUtil.teleportPlayer(player, player.getLocation(), plot);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user