Work around setFlying() throwing exceptions

This commit is contained in:
JeromSar 2015-05-12 20:17:38 +02:00
parent 68f972c562
commit b18aeb2d38
6 changed files with 32 additions and 28 deletions

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Tue May 12 17:17:52 CEST 2015 #Tue May 12 20:14:59 CEST 2015
build.number=1015 build.number=1022

View File

@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -67,7 +68,7 @@ public class Command_expel extends TFM_Command
if (inRange) if (inRange)
{ {
player.getWorld().createExplosion(targetPos, 0.0f, false); player.getWorld().createExplosion(targetPos, 0.0f, false);
player.setFlying(false); TFM_Util.setFlying(player, false);
player.setVelocity(targetPosVec.subtract(senderPos).normalize().multiply(strength)); player.setVelocity(targetPosVec.subtract(senderPos).normalize().multiply(strength));
pushedPlayers.add(player.getName()); pushedPlayers.add(player.getName());
} }

View File

@ -325,7 +325,7 @@ public class TFM_PlayerListener implements Listener
{ {
if (targetPosVec.distanceSquared(playerLocVec) < (RADIUS_HIT * RADIUS_HIT)) if (targetPosVec.distanceSquared(playerLocVec) < (RADIUS_HIT * RADIUS_HIT))
{ {
target.setFlying(false); TFM_Util.setFlying(player, false);
target.setVelocity(targetPosVec.subtract(playerLocVec).normalize().multiply(STRENGTH)); target.setVelocity(targetPosVec.subtract(playerLocVec).normalize().multiply(STRENGTH));
didHit = true; didHit = true;
} }
@ -389,7 +389,7 @@ public class TFM_PlayerListener implements Listener
if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen()) if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen())
{ {
player.setFlying(true); TFM_Util.setFlying(player, true);
event.setTo(playerdata.getFreezeLocation()); event.setTo(playerdata.getFreezeLocation());
return; // Don't process adminworld validation return; // Don't process adminworld validation
} }
@ -456,7 +456,7 @@ public class TFM_PlayerListener implements Listener
// Freeze // Freeze
if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen()) if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen())
{ {
player.setFlying(true); TFM_Util.setFlying(player, true);
event.setTo(playerdata.getFreezeLocation()); event.setTo(playerdata.getFreezeLocation());
} }
@ -710,7 +710,7 @@ public class TFM_PlayerListener implements Listener
} }
// Blocked commands // Blocked commands
if (TFM_CommandBlocker.isCommandBlocked(command, event.getPlayer(), true)) if (TFM_CommandBlocker.isCommandBlocked(command, player, true))
{ {
// CommandBlocker handles messages and broadcasts // CommandBlocker handles messages and broadcasts
event.setCancelled(true); event.setCancelled(true);
@ -885,8 +885,6 @@ public class TFM_PlayerListener implements Listener
{ {
} }
player.setAllowFlight(true);
new BukkitRunnable() new BukkitRunnable()
{ {
@Override @Override

View File

@ -223,27 +223,27 @@ public class TFM_CommandBlocker
public static CommandBlockerRank fromSender(CommandSender sender) public static CommandBlockerRank fromSender(CommandSender sender)
{ {
if (!TFM_AdminList.isSuperAdmin(sender))
{
if (sender.isOp())
{
return OP;
}
return ANYONE;
}
if (TFM_AdminList.isSeniorAdmin(sender))
{
return SENIOR;
}
if (!(sender instanceof Player)) if (!(sender instanceof Player))
{ {
return TELNET; return TELNET;
} }
return SUPER; if (TFM_AdminList.isSuperAdmin(sender))
{
if (TFM_AdminList.isSeniorAdmin(sender))
{
return SENIOR;
}
return SUPER;
}
if (sender.isOp())
{
return OP;
}
return ANYONE;
} }
public static CommandBlockerRank fromToken(String token) public static CommandBlockerRank fromToken(String token)

View File

@ -218,7 +218,7 @@ public class TFM_PlayerData
if (player.getGameMode() != GameMode.CREATIVE) if (player.getGameMode() != GameMode.CREATIVE)
{ {
player.setFlying(false); TFM_Util.setFlying(player, false);
} }
if (!freeze) if (!freeze)
@ -227,7 +227,7 @@ public class TFM_PlayerData
} }
freezeLocation = player.getLocation(); // Blockify location freezeLocation = player.getLocation(); // Blockify location
player.setFlying(true); // Avoid infinite falling TFM_Util.setFlying(player, true); // Avoid infinite falling
unfreezeTask = new BukkitRunnable() unfreezeTask = new BukkitRunnable()
{ {
@ -410,7 +410,7 @@ public class TFM_PlayerData
{ {
player.setOp(false); player.setOp(false);
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
player.setFlying(false); TFM_Util.setFlying(player, false);
TFM_EssentialsBridge.setNickname(player.getName(), player.getName()); TFM_EssentialsBridge.setNickname(player.getName(), player.getName());
player.closeInventory(); player.closeInventory();
player.setTotalExperience(0); player.setTotalExperience(0);

View File

@ -142,6 +142,11 @@ public class TFM_Util
TFM_Util.playerMsg(sender, message, ChatColor.GRAY); TFM_Util.playerMsg(sender, message, ChatColor.GRAY);
} }
public static void setFlying(Player player, boolean flying) {
player.setAllowFlight(true);
player.setFlying(flying);
}
public static void adminAction(String adminName, String action, boolean isRed) public static void adminAction(String adminName, String action, boolean isRed)
{ {
TFM_Util.bcastMsg(adminName + " - " + action, (isRed ? ChatColor.RED : ChatColor.AQUA)); TFM_Util.bcastMsg(adminName + " - " + action, (isRed ? ChatColor.RED : ChatColor.AQUA));