2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.bridge;
|
2013-07-03 20:11:57 +00:00
|
|
|
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
|
|
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
|
|
|
import net.pravian.aero.component.service.AbstractService;
|
2013-07-03 20:11:57 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public class WorldEditBridge extends AbstractService<TotalFreedomMod>
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2014-05-19 17:32:25 +00:00
|
|
|
private static WorldEditPlugin worldEditPlugin = null;
|
2013-07-03 20:11:57 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public WorldEditBridge(TotalFreedomMod plugin)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
super(plugin);
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
@Override
|
|
|
|
protected void onStart()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private WorldEditPlugin getWorldEditPlugin()
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2014-05-19 17:32:25 +00:00
|
|
|
if (worldEditPlugin == null)
|
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
|
|
|
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)
|
|
|
|
{
|
2014-05-19 17:32:25 +00:00
|
|
|
worldEditPlugin = (WorldEditPlugin) we;
|
2013-07-12 00:35:09 +00:00
|
|
|
}
|
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
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2013-07-12 00:35:09 +00:00
|
|
|
}
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
2014-05-19 17:32:25 +00:00
|
|
|
return worldEditPlugin;
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
private 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
|
|
|
{
|
2014-05-19 17:32:25 +00:00
|
|
|
final WorldEditPlugin wep = getWorldEditPlugin();
|
2013-07-03 20:11:57 +00:00
|
|
|
if (wep != null)
|
|
|
|
{
|
2015-03-07 16:32:27 +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-12 00:35:09 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2013-07-12 00:35:09 +00:00
|
|
|
}
|
|
|
|
return null;
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
private 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
|
|
|
{
|
2014-05-19 17:32:25 +00:00
|
|
|
final WorldEditPlugin wep = getWorldEditPlugin();
|
2013-07-03 20:11:57 +00:00
|
|
|
if (wep != null)
|
|
|
|
{
|
2015-03-07 16:32:27 +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-03 20:11:57 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +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
|
|
|
{
|
2014-05-19 17:32:25 +00:00
|
|
|
final BukkitPlayer bukkitPlayer = 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
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public void setLimit(Player player, int limit)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-05-19 17:32:25 +00:00
|
|
|
final 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
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|