TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java

130 lines
2.9 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.bridge;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class WorldEditBridge extends FreedomService
{
public WorldEditBridge(TotalFreedomMod plugin)
{
super(plugin);
}
@Override
protected void onStart()
{
}
@Override
protected void onStop()
{
}
private WorldEditPlugin getWorldEditPlugin()
{
WorldEditPlugin worldEditPlugin = null;
try
{
Plugin we = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
if (we != null)
{
if (we instanceof WorldEditPlugin)
{
worldEditPlugin = (WorldEditPlugin) we;
}
}
}
catch (Exception ex)
{
FLog.severe(ex);
}
return worldEditPlugin;
}
private LocalSession getPlayerSession(Player player)
{
final WorldEditPlugin wep = getWorldEditPlugin();
if (wep == null)
{
return null;
}
2013-07-12 00:35:09 +00:00
try
{
return wep.getSession(player);
}
catch (Exception ex)
2013-07-12 00:35:09 +00:00
{
FLog.severe(ex);
return null;
2013-07-12 00:35:09 +00:00
}
}
private BukkitPlayer getBukkitPlayer(Player player)
{
final WorldEditPlugin wep = getWorldEditPlugin();
if (wep == null)
{
return null;
}
2013-07-12 00:35:09 +00:00
try
{
return wep.wrapPlayer(player);
}
catch (Exception ex)
{
FLog.severe(ex);
return null;
}
}
public void undo(Player player, int count)
{
try
{
2013-08-14 14:01:42 +00:00
LocalSession session = getPlayerSession(player);
2013-07-12 00:35:09 +00:00
if (session != null)
{
final BukkitPlayer bukkitPlayer = getBukkitPlayer(player);
2013-07-12 00:35:09 +00:00
if (bukkitPlayer != null)
{
for (int i = 0; i < count; i++)
{
session.undo(session.getBlockBag(bukkitPlayer), bukkitPlayer);
}
}
}
}
catch (Exception ex)
{
FLog.severe(ex);
}
}
public void setLimit(Player player, int limit)
{
try
{
final LocalSession session = getPlayerSession(player);
2013-07-12 00:35:09 +00:00
if (session != null)
{
2013-07-12 00:35:09 +00:00
session.setBlockChangeLimit(limit);
}
}
catch (Exception ex)
{
FLog.severe(ex);
}
}
}