2014-04-11 15:24:44 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod.Bridge;
|
2013-07-03 20:11:57 +00:00
|
|
|
|
2013-09-04 22:20:52 +00:00
|
|
|
import com.sk89q.worldedit.IncompleteRegionException;
|
2013-07-03 20:11:57 +00:00
|
|
|
import com.sk89q.worldedit.LocalSession;
|
2013-09-04 19:17:22 +00:00
|
|
|
import com.sk89q.worldedit.LocalWorld;
|
2013-07-03 20:11:57 +00:00
|
|
|
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
|
|
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
2013-09-04 19:17:22 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
2014-04-11 15:24:44 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
2013-07-03 20:11:57 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2013-09-04 22:20:52 +00:00
|
|
|
import org.bukkit.ChatColor;
|
2013-07-03 20:11:57 +00:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
2013-09-04 22:20:52 +00:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
2013-07-03 20:11:57 +00:00
|
|
|
|
|
|
|
public class TFM_WorldEditBridge
|
|
|
|
{
|
|
|
|
private WorldEditPlugin worldEditPlugin = null;
|
|
|
|
|
|
|
|
private TFM_WorldEditBridge()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public WorldEditPlugin getWorldEditPlugin()
|
|
|
|
{
|
|
|
|
if (this.worldEditPlugin == null)
|
|
|
|
{
|
2013-07-12 00:35:09 +00:00
|
|
|
try
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2013-07-12 00:35:09 +00:00
|
|
|
Plugin we = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
|
|
|
if (we != null)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2013-07-12 00:35:09 +00:00
|
|
|
if (we instanceof WorldEditPlugin)
|
|
|
|
{
|
|
|
|
this.worldEditPlugin = (WorldEditPlugin) we;
|
|
|
|
}
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (Exception ex)
|
2013-07-12 00:35:09 +00:00
|
|
|
{
|
2013-08-14 13:28:19 +00:00
|
|
|
TFM_Log.severe(ex);
|
2013-07-12 00:35:09 +00:00
|
|
|
}
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
return this.worldEditPlugin;
|
|
|
|
}
|
|
|
|
|
2013-08-14 14:01:42 +00:00
|
|
|
public BukkitPlayer getBukkitPlayer(Player player)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2013-07-12 00:35:09 +00:00
|
|
|
try
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2013-07-12 00:35:09 +00:00
|
|
|
WorldEditPlugin wep = this.getWorldEditPlugin();
|
2013-07-03 20:11:57 +00:00
|
|
|
if (wep != null)
|
|
|
|
{
|
2013-08-14 14:01:42 +00:00
|
|
|
return wep.wrapPlayer(player);
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (Exception ex)
|
2013-07-12 00:35:09 +00:00
|
|
|
{
|
2013-08-14 13:28:19 +00:00
|
|
|
TFM_Log.severe(ex);
|
2013-07-12 00:35:09 +00:00
|
|
|
}
|
|
|
|
return null;
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 14:01:42 +00:00
|
|
|
public LocalSession getPlayerSession(Player player)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2013-07-12 00:35:09 +00:00
|
|
|
try
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
|
|
|
WorldEditPlugin wep = this.getWorldEditPlugin();
|
|
|
|
if (wep != null)
|
|
|
|
{
|
2013-08-14 14:01:42 +00:00
|
|
|
return wep.getSession(player);
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (Exception ex)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2013-08-14 13:28:19 +00:00
|
|
|
TFM_Log.severe(ex);
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-08-14 14:01:42 +00:00
|
|
|
public void undo(Player player, int count)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-08-14 14:01:42 +00:00
|
|
|
LocalSession session = getPlayerSession(player);
|
2013-07-12 00:35:09 +00:00
|
|
|
if (session != null)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2013-08-14 14:01:42 +00:00
|
|
|
BukkitPlayer bukkitPlayer = this.getBukkitPlayer(player);
|
2013-07-12 00:35:09 +00:00
|
|
|
if (bukkitPlayer != null)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
session.undo(session.getBlockBag(bukkitPlayer), bukkitPlayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (Exception ex)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2013-08-14 13:28:19 +00:00
|
|
|
TFM_Log.severe(ex);
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-14 14:01:42 +00:00
|
|
|
public void setLimit(Player player, int limit)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-08-14 14:01:42 +00:00
|
|
|
LocalSession session = getPlayerSession(player);
|
2013-07-12 00:35:09 +00:00
|
|
|
if (session != null)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2013-07-12 00:35:09 +00:00
|
|
|
session.setBlockChangeLimit(limit);
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (Exception ex)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2013-08-14 13:28:19 +00:00
|
|
|
TFM_Log.severe(ex);
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-04 22:20:52 +00:00
|
|
|
public void validateSelection(final Player player)
|
2013-09-04 19:17:22 +00:00
|
|
|
{
|
2014-04-09 20:33:03 +00:00
|
|
|
if (TFM_AdminList.isSuperAdmin(player))
|
2013-09-04 22:20:52 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-04 19:17:22 +00:00
|
|
|
try
|
|
|
|
{
|
2013-09-04 22:20:52 +00:00
|
|
|
final LocalSession session = getPlayerSession(player);
|
2013-09-04 19:17:22 +00:00
|
|
|
if (session != null)
|
|
|
|
{
|
2013-09-04 22:20:52 +00:00
|
|
|
final LocalWorld selectionWorld = session.getSelectionWorld();
|
|
|
|
final Region selection = session.getSelection(selectionWorld);
|
2013-09-04 19:17:22 +00:00
|
|
|
if (TFM_ProtectedArea.isInProtectedArea(
|
|
|
|
getBukkitVector(selection.getMinimumPoint()),
|
|
|
|
getBukkitVector(selection.getMaximumPoint()),
|
|
|
|
selectionWorld.getName()))
|
|
|
|
{
|
2013-09-04 22:20:52 +00:00
|
|
|
new BukkitRunnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
player.sendMessage(ChatColor.RED + "The region that you selected contained a protected area. Selection cleared.");
|
|
|
|
session.getRegionSelector(selectionWorld).clear();
|
|
|
|
}
|
|
|
|
}.runTaskLater(TotalFreedomMod.plugin, 1L);
|
2013-09-04 19:17:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-04 22:20:52 +00:00
|
|
|
catch (IncompleteRegionException ex)
|
|
|
|
{
|
|
|
|
}
|
2013-09-04 19:17:22 +00:00
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
TFM_Log.severe(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static org.bukkit.util.Vector getBukkitVector(com.sk89q.worldedit.Vector worldEditVector)
|
|
|
|
{
|
|
|
|
return new org.bukkit.util.Vector(worldEditVector.getX(), worldEditVector.getY(), worldEditVector.getZ());
|
|
|
|
}
|
|
|
|
|
2013-07-03 20:11:57 +00:00
|
|
|
public static TFM_WorldEditBridge getInstance()
|
|
|
|
{
|
|
|
|
return TFM_WorldEditBridgeHolder.INSTANCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class TFM_WorldEditBridgeHolder
|
|
|
|
{
|
|
|
|
private static final TFM_WorldEditBridge INSTANCE = new TFM_WorldEditBridge();
|
|
|
|
}
|
|
|
|
}
|