mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-18 05:16:12 +00:00
178 lines
4.1 KiB
Java
178 lines
4.1 KiB
Java
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 org.bukkit.entity.Player;
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
public class WorldEditBridge extends FreedomService
|
|
{
|
|
|
|
//
|
|
private WorldEditPlugin worldeditPlugin = null;
|
|
|
|
@Override
|
|
public void onStart()
|
|
{
|
|
}
|
|
|
|
@Override
|
|
public void onStop()
|
|
{
|
|
}
|
|
|
|
public WorldEditPlugin getWorldEditPlugin()
|
|
{
|
|
if (worldeditPlugin == null)
|
|
{
|
|
try
|
|
{
|
|
Plugin we = server.getPluginManager().getPlugin("WorldEdit");
|
|
if (we != null)
|
|
{
|
|
if (we instanceof WorldEditPlugin)
|
|
{
|
|
worldeditPlugin = (WorldEditPlugin)we;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
FLog.severe(ex);
|
|
}
|
|
}
|
|
|
|
return worldeditPlugin;
|
|
}
|
|
|
|
public void undo(Player player, int count)
|
|
{
|
|
try
|
|
{
|
|
LocalSession session = getPlayerSession(player);
|
|
if (session != null)
|
|
{
|
|
final BukkitPlayer bukkitPlayer = getBukkitPlayer(player);
|
|
if (bukkitPlayer != null)
|
|
{
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
com.sk89q.worldedit.entity.Player fuckyou = (com.sk89q.worldedit.entity.Player)bukkitPlayer;
|
|
session.undo(session.getBlockBag(fuckyou), fuckyou);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
FLog.severe(ex);
|
|
}
|
|
}
|
|
|
|
public void redo(Player player, int count)
|
|
{
|
|
try
|
|
{
|
|
LocalSession session = getPlayerSession(player);
|
|
if (session != null)
|
|
{
|
|
final BukkitPlayer bukkitPlayer = getBukkitPlayer(player);
|
|
if (bukkitPlayer != null)
|
|
{
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
com.sk89q.worldedit.entity.Player fuckyou = (com.sk89q.worldedit.entity.Player)bukkitPlayer;
|
|
session.redo(session.getBlockBag(fuckyou), fuckyou);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
FLog.severe(ex);
|
|
}
|
|
}
|
|
|
|
public void setLimit(Player player, int limit)
|
|
{
|
|
try
|
|
{
|
|
final LocalSession session = getPlayerSession(player);
|
|
if (session != null)
|
|
{
|
|
session.setBlockChangeLimit(limit);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
FLog.severe(ex);
|
|
}
|
|
|
|
}
|
|
|
|
public int getDefaultLimit()
|
|
{
|
|
final WorldEditPlugin wep = getWorldEditPlugin();
|
|
if (wep == null)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return wep.getLocalConfiguration().defaultChangeLimit;
|
|
|
|
}
|
|
|
|
public int getMaxLimit()
|
|
{
|
|
final WorldEditPlugin wep = getWorldEditPlugin();
|
|
if (wep == null)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return wep.getLocalConfiguration().maxChangeLimit;
|
|
|
|
}
|
|
|
|
private LocalSession getPlayerSession(Player player)
|
|
{
|
|
final WorldEditPlugin wep = getWorldEditPlugin();
|
|
if (wep == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
try
|
|
{
|
|
return wep.getSession(player);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
FLog.severe(ex);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private BukkitPlayer getBukkitPlayer(Player player)
|
|
{
|
|
final WorldEditPlugin wep = getWorldEditPlugin();
|
|
if (wep == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
try
|
|
{
|
|
return wep.wrapPlayer(player);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
FLog.severe(ex);
|
|
return null;
|
|
}
|
|
}
|
|
}
|