TF-PlotSquared/PlotSquared/src/com/intellectualcrafters/plot/commands/Auto.java

87 lines
2.8 KiB
Java
Raw Normal View History

2014-09-22 13:02:14 +02: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 = Auto.java
* >> Generated by: Citymonstret at 2014-08-09 01:40
*/
package com.intellectualcrafters.plot.commands;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
2014-09-22 13:02:14 +02:00
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
@SuppressWarnings("deprecation")
public class Auto extends SubCommand {
public Auto() {
super("auto", "plots.auto", "Claim the nearest plot", "auto", "a", CommandCategory.CLAIMING);
}
@Override
public boolean execute(Player plr, String... args) {
2014-09-22 13:02:14 +02:00
World world;
if (PlotMain.getPlotWorlds().length == 1) {
2014-09-22 21:43:53 +10:00
world = Bukkit.getWorld(PlotMain.getPlotWorlds()[0]);
} else {
if (PlotMain.isPlotWorld(plr.getWorld())) {
2014-09-22 13:02:14 +02:00
world = plr.getWorld();
} else {
if (args.length == 1) {
2014-09-22 21:43:53 +10:00
world = Bukkit.getWorld(args[0]);
if (world != null) {
2014-09-22 21:43:53 +10:00
if (!PlotMain.isPlotWorld(world)) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
return true;
}
} else {
2014-09-22 21:43:53 +10:00
PlayerFunctions.sendMessage(plr, C.NOT_VALID_WORLD);
return true;
}
} else {
2014-09-22 21:43:53 +10:00
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return true;
}
2014-09-22 13:02:14 +02:00
}
2014-09-22 13:02:14 +02:00
}
if (PlayerFunctions.getPlayerPlotCount(world, plr) >= PlayerFunctions.getAllowedPlots(plr)) {
2014-09-22 13:02:14 +02:00
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
return true;
}
boolean br = false;
int x = 0, z = 0, q = 100;
PlotId id;
while (!br) {
id = new PlotId(x, z);
if (PlotHelper.getPlot(world, id).owner == null) {
2014-09-22 13:02:14 +02:00
Plot plot = PlotHelper.getPlot(world, id);
2014-09-23 15:28:26 +10:00
boolean result = Claim.claimPlot(plr, plot, true);
br = !result;
}
if ((z < q) && ((z - x) < q)) {
z++;
} else if (x < q) {
x++;
z = q - 100;
} else {
q += 100;
x = q;
z = q;
}
2014-09-22 13:02:14 +02:00
}
return true;
}
}