2022-03-20 12:35:43 +00:00
package me.StevenLawson.TotalFreedomMod.commands ;
2013-09-14 22:00:11 -04:00
2022-03-20 12:35:43 +00:00
import me.StevenLawson.TotalFreedomMod.util.DeprecationUtil ;
2013-09-14 22:00:11 -04: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 ;
2022-03-20 12:35:43 +00:00
import java.util.List ;
2013-09-14 22:00:11 -04:00
@CommandPermissions ( level = AdminLevel . ALL , source = SourceType . BOTH )
2022-03-21 17:29:19 +00:00
@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> " )
2022-03-20 12:35:43 +00:00
public class Command_setlever extends FreedomCommand {
2013-09-14 22:00:11 -04:00
@Override
2022-03-20 12:35:43 +00:00
public boolean run ( CommandSender sender , org . bukkit . entity . Player sender_p , Command cmd , String commandLabel , String [ ] args , boolean senderIsConsole ) {
if ( args . length ! = 5 ) {
2013-09-14 22:00:11 -04:00
return false ;
}
double x , y , z ;
2022-03-20 12:35:43 +00:00
try {
2013-09-14 22:00:11 -04:00
x = Double . parseDouble ( args [ 0 ] ) ;
y = Double . parseDouble ( args [ 1 ] ) ;
z = Double . parseDouble ( args [ 2 ] ) ;
}
catch ( NumberFormatException ex )
{
2022-03-21 17:29:19 +00:00
playerMsg ( " Invalid coordinates. " ) ;
2013-09-14 22:00:11 -04:00
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 )
{
2022-03-21 17:29:19 +00:00
playerMsg ( " Invalid world name. " ) ;
2013-09-14 22:00:11 -04:00
return true ;
}
final Location leverLocation = new Location ( world , x , y , z ) ;
2014-07-19 21:02:00 -04:00
final boolean leverOn = ( args [ 4 ] . trim ( ) . equalsIgnoreCase ( " on " ) | | args [ 4 ] . trim ( ) . equalsIgnoreCase ( " 1 " ) ) ;
2013-09-14 22:00:11 -04:00
final Block targetBlock = leverLocation . getBlock ( ) ;
if ( targetBlock . getType ( ) = = Material . LEVER )
{
2022-03-20 12:35:43 +00:00
org . bukkit . material . Lever lever = DeprecationUtil . makeLeverWithData ( DeprecationUtil . getData_Block ( targetBlock ) ) ;
2013-09-14 22:00:11 -04:00
lever . setPowered ( leverOn ) ;
2022-03-20 12:35:43 +00:00
DeprecationUtil . setData_Block ( targetBlock , DeprecationUtil . getData_MaterialData ( lever ) ) ;
2013-09-14 22:00:11 -04:00
targetBlock . getState ( ) . update ( ) ;
}
else
{
2022-03-21 17:29:19 +00:00
playerMsg ( " Target block " + targetBlock + " is not a lever. " ) ;
2013-09-14 22:00:11 -04:00
return true ;
}
return true ;
}
}