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
|
|
|
|
|
|
|
//
|
2018-07-28 07:11:48 +00:00
|
|
|
private WorldEditPlugin worldeditPlugin = null;
|
2016-03-06 15:56:15 +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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-02-22 23:16:08 +00:00
|
|
|
public WorldEditPlugin getWorldEditPlugin()
|
2018-07-28 07:11:48 +00:00
|
|
|
{
|
|
|
|
if (worldeditPlugin == null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Plugin we = server.getPluginManager().getPlugin("WorldEdit");
|
|
|
|
if (we != null)
|
|
|
|
{
|
|
|
|
if (we instanceof WorldEditPlugin)
|
|
|
|
{
|
2018-07-31 07:01:29 +00:00
|
|
|
worldeditPlugin = (WorldEditPlugin)we;
|
2018-07-28 07:11:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
FLog.severe(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return worldeditPlugin;
|
|
|
|
}
|
|
|
|
|
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++)
|
|
|
|
{
|
2018-12-29 19:41:48 +00:00
|
|
|
com.sk89q.worldedit.entity.Player fuckyou = (com.sk89q.worldedit.entity.Player)bukkitPlayer;
|
|
|
|
session.undo(session.getBlockBag(fuckyou), fuckyou);
|
2016-03-06 15:56:15 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2018-07-26 07:35:31 +00:00
|
|
|
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++)
|
|
|
|
{
|
2018-12-29 19:41:48 +00:00
|
|
|
com.sk89q.worldedit.entity.Player fuckyou = (com.sk89q.worldedit.entity.Player)bukkitPlayer;
|
|
|
|
session.redo(session.getBlockBag(fuckyou), fuckyou);
|
2018-07-26 07:35:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
FLog.severe(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-12-29 19:41:48 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|