2014-09-26 14:17:52 +10: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 = Unlink.java >> Generated by: Citymonstret at 2014-08-09 01:41
|
2014-09-26 14:17:52 +10:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2014-09-26 21:38:18 +10:00
|
|
|
import org.bukkit.Bukkit;
|
2014-09-26 14:17:52 +10:00
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import com.intellectualcrafters.plot.C;
|
|
|
|
import com.intellectualcrafters.plot.PlayerFunctions;
|
|
|
|
import com.intellectualcrafters.plot.Plot;
|
|
|
|
import com.intellectualcrafters.plot.PlotId;
|
|
|
|
import com.intellectualcrafters.plot.PlotMain;
|
2014-10-11 00:33:10 -07:00
|
|
|
import com.intellectualcrafters.plot.PlotManager;
|
2014-09-26 21:38:18 +10:00
|
|
|
import com.intellectualcrafters.plot.PlotWorld;
|
2014-09-26 22:21:14 +10:00
|
|
|
import com.intellectualcrafters.plot.SetBlockFast;
|
2014-09-26 14:17:52 +10:00
|
|
|
import com.intellectualcrafters.plot.database.DBFunc;
|
2014-09-26 21:38:18 +10:00
|
|
|
import com.intellectualcrafters.plot.events.PlotUnlinkEvent;
|
2014-09-26 14:17:52 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Citymonstret on 2014-08-01.
|
|
|
|
*/
|
|
|
|
public class Unlink extends SubCommand {
|
|
|
|
|
2014-10-11 00:33:10 -07:00
|
|
|
public Unlink() {
|
2014-10-12 00:37:36 -07:00
|
|
|
super(Command.UNLINK, "Unlink a mega-plot", "unlink", CommandCategory.ACTIONS);
|
2014-10-11 00:33:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean execute(Player plr, String... args) {
|
|
|
|
if (!PlayerFunctions.isInPlot(plr)) {
|
|
|
|
PlayerFunctions.sendMessage(plr, "You're not in a plot.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
2014-10-12 00:37:36 -07:00
|
|
|
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId()))
|
2014-10-11 00:33:10 -07:00
|
|
|
&& !plr.hasPermission("plots.admin")) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-12 00:37:36 -07:00
|
|
|
if (PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) {
|
2014-10-11 00:33:10 -07:00
|
|
|
PlayerFunctions.sendMessage(plr, C.UNLINK_IMPOSSIBLE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
World world = plr.getWorld();
|
|
|
|
PlotId pos1 = PlayerFunctions.getBottomPlot(world, plot).id;
|
|
|
|
PlotId pos2 = PlayerFunctions.getTopPlot(world, plot).id;
|
2014-10-12 00:37:36 -07:00
|
|
|
ArrayList<PlotId> ids = PlayerFunctions.getPlotSelectionIds(world, pos1, pos2);
|
2014-10-11 00:33:10 -07:00
|
|
|
|
|
|
|
PlotUnlinkEvent event = new PlotUnlinkEvent(world, ids);
|
|
|
|
|
|
|
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
PlayerFunctions.sendMessage(plr, "&cUnlink has been cancelled");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PlotId id : ids) {
|
|
|
|
Plot myplot = PlotMain.getPlots(world).get(id);
|
|
|
|
|
|
|
|
if (plot.helpers != null) {
|
|
|
|
myplot.helpers = plot.helpers;
|
|
|
|
}
|
|
|
|
if (plot.denied != null) {
|
|
|
|
myplot.denied = plot.denied;
|
|
|
|
}
|
|
|
|
myplot.deny_entry = plot.deny_entry;
|
2014-10-12 00:37:36 -07:00
|
|
|
myplot.settings.setMerged(new boolean[] { false, false, false, false });
|
|
|
|
DBFunc.setMerged(world.getName(), myplot, myplot.settings.getMerged());
|
2014-10-11 00:33:10 -07:00
|
|
|
}
|
|
|
|
PlotManager manager = PlotMain.getPlotManager(world);
|
|
|
|
PlotWorld plotworld = PlotMain.getWorldSettings(world);
|
|
|
|
for (int x = pos1.x; x <= pos2.x; x++) {
|
|
|
|
for (int y = pos1.y; y <= pos2.y; y++) {
|
|
|
|
boolean lx = x < pos2.x;
|
|
|
|
boolean ly = y < pos2.y;
|
|
|
|
|
|
|
|
new PlotId(x, y);
|
|
|
|
|
|
|
|
if (lx) {
|
2014-10-11 19:05:50 +11:00
|
|
|
manager.createRoadEast(plotworld, plot);
|
2014-10-11 00:33:10 -07:00
|
|
|
|
|
|
|
if (ly) {
|
2014-10-11 19:05:50 +11:00
|
|
|
manager.createRoadSouthEast(plotworld, plot);
|
2014-10-11 00:33:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ly) {
|
2014-10-11 19:05:50 +11:00
|
|
|
manager.createRoadSouth(plotworld, plot);
|
2014-10-11 00:33:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
SetBlockFast.update(plr);
|
2014-10-12 00:37:36 -07:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2014-10-11 00:33:10 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayerFunctions.sendMessage(plr, "&6Plots unlinked successfully!");
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-26 14:17:52 +10:00
|
|
|
}
|