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.util.FLog; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import net.pravian.aero.component.service.AbstractService; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; public class WorldEditBridge extends AbstractService { private static WorldEditPlugin worldEditPlugin = null; public WorldEditBridge(TotalFreedomMod plugin) { super(plugin); } @Override protected void onStart() { } @Override protected void onStop() { } private WorldEditPlugin getWorldEditPlugin() { if (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) { try { final WorldEditPlugin wep = getWorldEditPlugin(); if (wep != null) { return wep.getSession(player); } } catch (Exception ex) { FLog.severe(ex); } return null; } private BukkitPlayer getBukkitPlayer(Player player) { try { final WorldEditPlugin wep = getWorldEditPlugin(); if (wep != null) { return wep.wrapPlayer(player); } } catch (Exception ex) { FLog.severe(ex); } return null; } 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++) { 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); if (session != null) { session.setBlockChangeLimit(limit); } } catch (Exception ex) { FLog.severe(ex); } } }