mirror of
https://github.com/TotalFreedomMC/TotalFreedomMod.git
synced 2025-08-06 04:23:09 +00:00

Lombok implementation removal. I have also gone through and replaced things with inline methods and variables, lambdas, and simplified loops down, removed unnecessary guard clauses, and overall cleaned up every single class. This took a long time, please do remember to follow proper naming conventions, don't include unnecessary guard clauses, follow exception rules and comment rules, and please PLEASE remember to use the DIAMOND OPERATOR rather than just inferring RAW TYPES!!! Thank you!!
84 lines
2.5 KiB
Java
84 lines
2.5 KiB
Java
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
import java.util.List;
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.World;
|
|
import org.bukkit.block.Block;
|
|
import org.bukkit.block.BlockState;
|
|
import org.bukkit.block.data.BlockData;
|
|
import org.bukkit.block.data.type.Switch;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
|
|
@CommandPermissions(level = Rank.NON_OP, 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 FreedomCommand
|
|
{
|
|
|
|
@Override
|
|
public boolean run(CommandSender sender, Player playerSender, 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)
|
|
{
|
|
msg("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)
|
|
{
|
|
msg("Invalid world name.");
|
|
return true;
|
|
}
|
|
|
|
final Location leverLocation = new Location(world, x, y, z);
|
|
|
|
final boolean leverOn = (args[4].trim().equalsIgnoreCase("on") || args[4].trim().equalsIgnoreCase("1"));
|
|
|
|
final Block targetBlock = leverLocation.getBlock();
|
|
|
|
if (targetBlock.getType() == Material.LEVER)
|
|
{
|
|
BlockState state = targetBlock.getState();
|
|
BlockData data = state.getBlockData();
|
|
Switch caster = (Switch)data;
|
|
|
|
caster.setPowered(leverOn);
|
|
state.setBlockData(data);
|
|
state.update();
|
|
}
|
|
else
|
|
{
|
|
msg("Target block " + targetBlock + " is not a lever.");
|
|
return true;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|