2013-09-15 02:00:11 +00:00
package me.StevenLawson.TotalFreedomMod.Commands ;
import java.util.List ;
2014-07-20 01:02:00 +00:00
import me.StevenLawson.TotalFreedomMod.TFM_DepreciationAggregator ;
2013-09-15 02:00:11 +00:00
import org.bukkit.Location ;
import org.bukkit.Material ;
import org.bukkit.World ;
import org.bukkit.block.Block ;
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
@CommandPermissions ( level = AdminLevel . ALL , source = SourceType . BOTH )
@CommandParameters ( description = " Set the on/off state of the lever at position x, y, z in world 'worldname'. " , usage = " /<command> <x> <y> <z> <worldname> <on|off> " )
public class Command_setlever extends TFM_Command
{
@Override
public boolean run ( CommandSender sender , Player sender_p , Command cmd , String commandLabel , String [ ] args , boolean senderIsConsole )
{
if ( args . length ! = 5 )
{
return false ;
}
double x , y , z ;
try
{
x = Double . parseDouble ( args [ 0 ] ) ;
y = Double . parseDouble ( args [ 1 ] ) ;
z = Double . parseDouble ( args [ 2 ] ) ;
}
catch ( NumberFormatException ex )
{
playerMsg ( " Invalid coordinates. " ) ;
return true ;
}
World world = null ;
final String needleWorldName = args [ 3 ] . trim ( ) ;
final List < World > worlds = server . getWorlds ( ) ;
for ( final World testWorld : worlds )
{
if ( testWorld . getName ( ) . trim ( ) . equalsIgnoreCase ( needleWorldName ) )
{
world = testWorld ;
break ;
}
}
if ( world = = null )
{
playerMsg ( " Invalid world name. " ) ;
return true ;
}
final Location leverLocation = new Location ( world , x , y , z ) ;
2014-07-20 01:02:00 +00:00
final boolean leverOn = ( args [ 4 ] . trim ( ) . equalsIgnoreCase ( " on " ) | | args [ 4 ] . trim ( ) . equalsIgnoreCase ( " 1 " ) ) ;
2013-09-15 02:00:11 +00:00
final Block targetBlock = leverLocation . getBlock ( ) ;
if ( targetBlock . getType ( ) = = Material . LEVER )
{
2014-07-20 01:02:00 +00:00
org . bukkit . material . Lever lever = TFM_DepreciationAggregator . makeLeverWithData ( TFM_DepreciationAggregator . getData_Block ( targetBlock ) ) ;
2013-09-15 02:00:11 +00:00
lever . setPowered ( leverOn ) ;
2014-07-20 01:02:00 +00:00
TFM_DepreciationAggregator . setData_Block ( targetBlock , TFM_DepreciationAggregator . getData_MaterialData ( lever ) ) ;
2013-09-15 02:00:11 +00:00
targetBlock . getState ( ) . update ( ) ;
}
else
{
playerMsg ( " Target block " + targetBlock + " is not a lever. " ) ;
return true ;
}
return true ;
}
}