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;
|
2016-03-01 16:47:01 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
2013-07-03 20:11:57 +00:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class WorldEditBridge extends FreedomService
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
|
|
|
|
private final WorldEditListener listener;
|
|
|
|
//
|
|
|
|
private WorldEditPlugin worldedit = null;
|
|
|
|
|
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);
|
2016-03-06 15:56:15 +00:00
|
|
|
listener = new WorldEditListener(plugin);
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
@Override
|
|
|
|
protected void onStart()
|
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
listener.register();
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop()
|
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
listener.unregister();
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
public void undo(Player player, int count)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
try
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
LocalSession session = getPlayerSession(player);
|
|
|
|
if (session != null)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
final BukkitPlayer bukkitPlayer = getBukkitPlayer(player);
|
|
|
|
if (bukkitPlayer != null)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
session.undo(session.getBlockBag(bukkitPlayer), bukkitPlayer);
|
|
|
|
}
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-02 19:28:01 +00:00
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
FLog.severe(ex);
|
|
|
|
}
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
private WorldEditPlugin getWorldEditPlugin()
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
if (worldedit == null)
|
2016-03-02 19:28:01 +00:00
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Plugin we = server.getPluginManager().getPlugin("WorldEdit");
|
|
|
|
if (we != null)
|
|
|
|
{
|
|
|
|
if (we instanceof WorldEditPlugin)
|
|
|
|
{
|
|
|
|
worldedit = (WorldEditPlugin) we;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
FLog.severe(ex);
|
|
|
|
}
|
2016-03-02 19:28:01 +00:00
|
|
|
}
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
return worldedit;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLimit(Player player, int limit)
|
|
|
|
{
|
2013-07-12 00:35:09 +00:00
|
|
|
try
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
final LocalSession session = getPlayerSession(player);
|
|
|
|
if (session != null)
|
|
|
|
{
|
|
|
|
session.setBlockChangeLimit(limit);
|
|
|
|
}
|
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
|
|
|
}
|
2016-03-06 15:56:15 +00:00
|
|
|
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
private LocalSession getPlayerSession(Player player)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
final WorldEditPlugin wep = getWorldEditPlugin();
|
|
|
|
if (wep == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-07-12 00:35:09 +00:00
|
|
|
try
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2016-03-06 15:56:15 +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
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2016-03-02 19:28:01 +00:00
|
|
|
return null;
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
private BukkitPlayer getBukkitPlayer(Player player)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
final WorldEditPlugin wep = getWorldEditPlugin();
|
|
|
|
if (wep == null)
|
2013-07-03 20:11:57 +00:00
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
return null;
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2016-03-06 15:56:15 +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);
|
2016-03-06 15:56:15 +00:00
|
|
|
return null;
|
2013-07-03 20:11:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|