Forward plot home to plot visit

This commit is contained in:
boy0001 2015-09-15 14:56:23 +10:00
parent 9682e2914c
commit c948b18239
5 changed files with 80 additions and 110 deletions

View File

@ -478,7 +478,8 @@ public class PS {
continue; 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) { for (final PlotFilter filter : filters) {
if (!filter.allowsPlot(plot)) { if (!filter.allowsPlot(plot)) {
continue; continue;
@ -1097,8 +1098,16 @@ public class PS {
if (map == null) { if (map == null) {
return new HashSet<>(); return new HashSet<>();
} }
try {
return map.values(); 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) { public Plot getPlot(final String world, final PlotId id) {
if (world == lastWorld) { if (world == lastWorld) {

View File

@ -20,77 +20,14 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; 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.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration; 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) @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 { 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 @Override
public boolean onCommand(final PlotPlayer plr, String[] args) { public boolean onCommand(final PlotPlayer plr, String[] args) {
final Set<Plot> all = PS.get().getPlots(plr); return MainCommand.getInstance().getCommand("visit").onCommand(plr, args);
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);
} }
} }

View File

@ -21,8 +21,11 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import com.intellectualcrafters.plot.PS; 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.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.Argument;
@ -61,71 +65,91 @@ public class Visit extends SubCommand {
} }
@Override @Override
public boolean onCommand(final PlotPlayer plr, final String[] args) { public boolean onCommand(final PlotPlayer player, String[] args) {
ArrayList<Plot> plots = new ArrayList<>(); 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); final UUID user = UUIDHandler.getCachedUUID(args[0], null);
if (user != null) { if (user != null) {
// do plots by username unsorted = PS.get().getPlots(user);
plots = PS.get().sortPlotsByTemp(PS.get().getPlots(user));
} else if (PS.get().isPlotWorld(args[0])) { } else if (PS.get().isPlotWorld(args[0])) {
// do plots by world unsorted = PS.get().getPlotsInWorld(args[0]);
plots = PS.get().sortPlots(PS.get().getPlotsInWorld(args[0]), SortType.DISTANCE_FROM_ORIGIN, null);
} else { } else {
final Plot plot = MainUtil.getPlotFromString(plr, args[0], true); final Plot plot = MainUtil.getPlotFromString(player, args[0], true);
if (plot == null) { if (plot != null) {
return false; unsorted = new HashSet<>();
} unsorted.add(plot);
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;
} }
} }
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()) { while (iter.hasNext()) {
if (!iter.next().isBasePlot()) { if (!iter.next().isBasePlot()) {
iter.remove(); 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 (!plot.hasOwner()) {
if (!Permissions.hasPermission(plr, "plots.visit.unowned")) { if (!Permissions.hasPermission(player, "plots.visit.unowned")) {
sendMessage(plr, C.NO_PERMISSION, "plots.visit.unowned"); sendMessage(player, C.NO_PERMISSION, "plots.visit.unowned");
return false; return false;
} }
} else if (plot.isOwner(plr.getUUID())) { } else if (plot.isOwner(player.getUUID())) {
if (!Permissions.hasPermission(plr, "plots.visit.owned") && !Permissions.hasPermission(plr, "plots.home")) { if (!Permissions.hasPermission(player, "plots.visit.owned") && !Permissions.hasPermission(player, "plots.home")) {
sendMessage(plr, C.NO_PERMISSION, "plots.visit.owned, plots.home"); sendMessage(player, C.NO_PERMISSION, "plots.visit.owned, plots.home");
return false; return false;
} }
} else if (plot.isAdded(plr.getUUID())) { } else if (plot.isAdded(player.getUUID())) {
if (!Permissions.hasPermission(plr, "plots.visit.shared")) { if (!Permissions.hasPermission(player, "plots.visit.shared")) {
sendMessage(plr, C.NO_PERMISSION, "plots.visit.shared"); sendMessage(player, C.NO_PERMISSION, "plots.visit.shared");
return false; return false;
} }
} else { } else {
if (!Permissions.hasPermission(plr, "plots.visit.other")) { if (!Permissions.hasPermission(player, "plots.visit.other")) {
sendMessage(plr, C.NO_PERMISSION, "plots.visit.other"); sendMessage(player, C.NO_PERMISSION, "plots.visit.other");
return false; return false;
} }
} }
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(index)); MainUtil.teleportPlayer(player, player.getLocation(), plot);
return true; return true;
} }

Binary file not shown.

Binary file not shown.