Updated to new WorldEdit API

TF-WorldEdit doesn't depend on TFM anymore. It's event-based now.
Moved TFM_TelnetListener to the Bridge subpackage
This commit is contained in:
JeromSar 2015-03-07 17:32:27 +01:00
parent 73ee1f3624
commit f4aa0c324c
7 changed files with 82 additions and 75 deletions

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Mon Feb 16 16:40:10 CET 2015 #Fri Feb 20 15:08:04 CET 2015
build.number=982 build.number=984

View File

@ -48,10 +48,10 @@ jar.archive.disabled=${jnlp.enabled}
jar.compress=false jar.compress=false
jar.index=${jnlp.enabled} jar.index=${jnlp.enabled}
javac.classpath=\ javac.classpath=\
${libs.WorldEdit.classpath}:\ ${libs.SpigotServer.classpath}:\
${libs.Essentials.classpath}:\
${libs.BukkitTelnet.classpath}:\ ${libs.BukkitTelnet.classpath}:\
${libs.SpigotServer.classpath} ${libs.TF-WorldEdit.classpath}:\
${libs.Essentials.classpath}
# Space-separated list of extra javac options # Space-separated list of extra javac options
javac.compilerargs=-Xlint:unchecked -Xlint:deprecation javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
javac.deprecation=false javac.deprecation=false

View File

@ -1,11 +1,10 @@
package me.StevenLawson.TotalFreedomMod.Listener; package me.StevenLawson.TotalFreedomMod.Bridge;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import me.StevenLawson.BukkitTelnet.api.TelnetCommandEvent; import me.StevenLawson.BukkitTelnet.api.TelnetCommandEvent;
import me.StevenLawson.BukkitTelnet.api.TelnetPreLoginEvent; import me.StevenLawson.BukkitTelnet.api.TelnetPreLoginEvent;
import me.StevenLawson.BukkitTelnet.api.TelnetRequestDataTagsEvent; import me.StevenLawson.BukkitTelnet.api.TelnetRequestDataTagsEvent;
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_EssentialsBridge;
import me.StevenLawson.TotalFreedomMod.TFM_Admin; import me.StevenLawson.TotalFreedomMod.TFM_Admin;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker; import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker;
@ -15,7 +14,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
public class TFM_TelnetListener implements Listener public class TFM_BukkitTelnetListener implements Listener
{ {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onTelnetPreLogin(TelnetPreLoginEvent event) public void onTelnetPreLogin(TelnetPreLoginEvent event)

View File

@ -1,20 +1,12 @@
package me.StevenLawson.TotalFreedomMod.Bridge; package me.StevenLawson.TotalFreedomMod.Bridge;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.bukkit.BukkitPlayer; import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.World;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_Log; import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
public class TFM_WorldEditBridge public class TFM_WorldEditBridge
{ {
@ -25,7 +17,7 @@ public class TFM_WorldEditBridge
throw new AssertionError(); throw new AssertionError();
} }
public static WorldEditPlugin getWorldEditPlugin() private static WorldEditPlugin getWorldEditPlugin()
{ {
if (worldEditPlugin == null) if (worldEditPlugin == null)
{ {
@ -48,14 +40,14 @@ public class TFM_WorldEditBridge
return worldEditPlugin; return worldEditPlugin;
} }
public static BukkitPlayer getBukkitPlayer(Player player) private static LocalSession getPlayerSession(Player player)
{ {
try try
{ {
final WorldEditPlugin wep = getWorldEditPlugin(); final WorldEditPlugin wep = getWorldEditPlugin();
if (wep != null) if (wep != null)
{ {
return wep.wrapPlayer(player); return wep.getSession(player);
} }
} }
catch (Exception ex) catch (Exception ex)
@ -65,14 +57,14 @@ public class TFM_WorldEditBridge
return null; return null;
} }
public static LocalSession getPlayerSession(Player player) private static BukkitPlayer getBukkitPlayer(Player player)
{ {
try try
{ {
final WorldEditPlugin wep = getWorldEditPlugin(); final WorldEditPlugin wep = getWorldEditPlugin();
if (wep != null) if (wep != null)
{ {
return wep.getSession(player); return wep.wrapPlayer(player);
} }
} }
catch (Exception ex) catch (Exception ex)
@ -120,54 +112,4 @@ public class TFM_WorldEditBridge
TFM_Log.severe(ex); TFM_Log.severe(ex);
} }
} }
public static void validateSelection(final Player player)
{
if (TFM_AdminList.isSuperAdmin(player))
{
return;
}
try
{
final LocalSession session = getPlayerSession(player);
if (session == null)
{
return;
}
final World selectionWorld = session.getSelectionWorld();
final Region selection = session.getSelection(selectionWorld);
if (TFM_ProtectedArea.isInProtectedArea(
getBukkitVector(selection.getMinimumPoint()),
getBukkitVector(selection.getMaximumPoint()),
selectionWorld.getName()))
{
new BukkitRunnable()
{
@Override
public void run()
{
player.sendMessage(ChatColor.RED + "The region that you selected contained a protected area. Selection cleared.");
session.getRegionSelector(selectionWorld).clear();
}
}.runTask(TotalFreedomMod.plugin);
}
}
catch (IncompleteRegionException ex)
{
}
catch (Exception ex)
{
TFM_Log.severe(ex);
}
}
private static org.bukkit.util.Vector getBukkitVector(com.sk89q.worldedit.Vector worldEditVector)
{
return new org.bukkit.util.Vector(worldEditVector.getX(), worldEditVector.getY(), worldEditVector.getZ());
}
} }

View File

@ -0,0 +1,62 @@
package me.StevenLawson.TotalFreedomMod.Bridge;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.worldedit.LimitChangedEvent;
import me.StevenLawson.worldedit.SelectionChangedEvent;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class TFM_WorldEditListener implements Listener
{
@EventHandler
public void onSelectionChange(final SelectionChangedEvent event)
{
final Player player = event.getPlayer();
if (TFM_AdminList.isSuperAdmin(player))
{
return;
}
if (TFM_ProtectedArea.isInProtectedArea(
event.getMinVector(),
event.getMaxVector(),
event.getWorld().getName()))
{
player.sendMessage(ChatColor.RED + "The region that you selected contained a protected area. Selection cleared.");
event.setCancelled(true);
}
}
@EventHandler
public void onLimitChanged(LimitChangedEvent event)
{
final Player player = event.getPlayer();
if (TFM_AdminList.isSuperAdmin(player))
{
return;
}
if (!event.getPlayer().equals(event.getTarget()))
{
player.sendMessage(ChatColor.RED + "Only admins can change the limit for other players!");
event.setCancelled(true);
}
if (event.getLimit() < 0 || event.getLimit() > 10000)
{
player.setOp(false);
TFM_Util.bcastMsg(event.getPlayer().getName() + " tried to set their WorldEdit limit to " + event.getLimit() + " and has been de-opped", ChatColor.RED);
event.setCancelled(true);
player.sendMessage(ChatColor.RED + "You cannot set your limit higher than 10000 or to -1!");
}
}
}

View File

@ -13,10 +13,10 @@ public class Command_setl extends TFM_Command
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
TFM_Util.adminAction(sender.getName(), "Setting everyone's Worldedit block modification limit to 500.", true); TFM_Util.adminAction(sender.getName(), "Setting everyone's Worldedit block modification limit to 2500.", true);
for (final Player player : server.getOnlinePlayers()) for (final Player player : server.getOnlinePlayers())
{ {
TFM_WorldEditBridge.setLimit(player, 500); TFM_WorldEditBridge.setLimit(player, 2500);
} }
return true; return true;
} }

View File

@ -8,6 +8,8 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_BukkitTelnetListener;
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_WorldEditListener;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandHandler; import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandHandler;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader; import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
@ -16,7 +18,6 @@ import me.StevenLawson.TotalFreedomMod.Listener.TFM_BlockListener;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_EntityListener; import me.StevenLawson.TotalFreedomMod.Listener.TFM_EntityListener;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_PlayerListener; import me.StevenLawson.TotalFreedomMod.Listener.TFM_PlayerListener;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_ServerListener; import me.StevenLawson.TotalFreedomMod.Listener.TFM_ServerListener;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_TelnetListener;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_WeatherListener; import me.StevenLawson.TotalFreedomMod.Listener.TFM_WeatherListener;
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld; import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
import me.StevenLawson.TotalFreedomMod.World.TFM_Flatlands; import me.StevenLawson.TotalFreedomMod.World.TFM_Flatlands;
@ -122,7 +123,10 @@ public class TotalFreedomMod extends JavaPlugin
pm.registerEvents(new TFM_PlayerListener(), plugin); pm.registerEvents(new TFM_PlayerListener(), plugin);
pm.registerEvents(new TFM_WeatherListener(), plugin); pm.registerEvents(new TFM_WeatherListener(), plugin);
pm.registerEvents(new TFM_ServerListener(), plugin); pm.registerEvents(new TFM_ServerListener(), plugin);
pm.registerEvents(new TFM_TelnetListener(), plugin);
// Bridge
pm.registerEvents(new TFM_BukkitTelnetListener(), plugin);
pm.registerEvents(new TFM_WorldEditListener(), plugin);
try try
{ {