2014-09-22 13:02:14 +02:00
|
|
|
/*
|
2014-10-12 00:37:36 -07:00
|
|
|
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute
|
|
|
|
* and/or monetize any of our intellectual property. IntellectualCrafters is not
|
|
|
|
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB.
|
|
|
|
*
|
|
|
|
* >> File = Visit.java >> Generated by: Citymonstret at 2014-08-09 01:42
|
2014-09-22 13:02:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
2014-10-03 12:36:30 +10:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2014-09-24 22:21:43 +10:00
|
|
|
import com.intellectualcrafters.plot.C;
|
|
|
|
import com.intellectualcrafters.plot.PlayerFunctions;
|
|
|
|
import com.intellectualcrafters.plot.Plot;
|
|
|
|
import com.intellectualcrafters.plot.PlotMain;
|
2014-10-22 19:46:41 +11:00
|
|
|
import com.intellectualcrafters.plot.UUIDHandler;
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-09-24 22:21:43 +10:00
|
|
|
public class Visit extends SubCommand {
|
2014-10-11 00:33:10 -07:00
|
|
|
public Visit() {
|
2014-10-18 11:06:29 -07:00
|
|
|
super("visit", "plots.visit", "Visit someones plot", "visit {player} [#]", "v", CommandCategory.TELEPORT, true);
|
2014-10-11 00:33:10 -07:00
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-10-11 00:33:10 -07:00
|
|
|
public List<Plot> getPlots(UUID uuid) {
|
|
|
|
List<Plot> plots = new ArrayList<>();
|
|
|
|
for (Plot p : PlotMain.getPlots()) {
|
|
|
|
if (p.owner.equals(uuid)) {
|
|
|
|
plots.add(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return plots;
|
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-10-11 00:33:10 -07:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
@Override
|
|
|
|
public boolean execute(Player plr, String... args) {
|
|
|
|
if (args.length < 1) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.NEED_USER);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
String username = args[0];
|
2014-10-22 19:46:41 +11:00
|
|
|
|
|
|
|
UUID uuid = UUIDHandler.getUUID(username);
|
|
|
|
List<Plot> plots = null;
|
|
|
|
if (uuid!=null) {
|
|
|
|
plots = getPlots(uuid);
|
|
|
|
}
|
|
|
|
if (uuid==null || plots.isEmpty()) {
|
2014-10-11 00:33:10 -07:00
|
|
|
PlayerFunctions.sendMessage(plr, C.FOUND_NO_PLOTS);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (args.length < 2) {
|
|
|
|
Plot plot = plots.get(0);
|
|
|
|
PlotMain.teleportPlayer(plr, plr.getLocation(), plot);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
int i;
|
|
|
|
try {
|
|
|
|
i = Integer.parseInt(args[1]);
|
2014-10-12 00:37:36 -07:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2014-10-11 00:33:10 -07:00
|
|
|
PlayerFunctions.sendMessage(plr, C.NOT_VALID_NUMBER);
|
|
|
|
return true;
|
|
|
|
}
|
2014-11-01 09:29:08 +11:00
|
|
|
if ((i < 0) || (i >= plots.size())) {
|
2014-10-11 00:33:10 -07:00
|
|
|
PlayerFunctions.sendMessage(plr, C.NOT_VALID_NUMBER);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Plot plot = plots.get(i);
|
|
|
|
PlotMain.teleportPlayer(plr, plr.getLocation(), plot);
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|