refactoring of command create
This commit is contained in:
parent
94404d74c6
commit
5f12bb5d99
@ -0,0 +1,31 @@
|
|||||||
|
package org.mcteam.ancientgates.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
|
public abstract class BaseLocationCommand extends BaseCommand
|
||||||
|
{
|
||||||
|
protected Location getValidPlayerLocation()
|
||||||
|
{
|
||||||
|
// The player might stand in a halfblock or a sign or whatever
|
||||||
|
// Therefore we load som extra locations and blocks
|
||||||
|
Block playerBlock = player.getLocation().getBlock();
|
||||||
|
Block upBlock = playerBlock.getRelative(BlockFace.UP);
|
||||||
|
|
||||||
|
if (playerBlock.getType() == Material.AIR) {
|
||||||
|
return player.getLocation();
|
||||||
|
}
|
||||||
|
else if (upBlock.getType() == Material.AIR) {
|
||||||
|
return new Location(player.getLocation().getWorld(),
|
||||||
|
player.getLocation().getX(),
|
||||||
|
player.getLocation().getY() + 1,
|
||||||
|
player.getLocation().getZ(),
|
||||||
|
player.getLocation().getYaw(),
|
||||||
|
player.getLocation().getPitch());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,11 @@
|
|||||||
package org.mcteam.ancientgates.commands;
|
package org.mcteam.ancientgates.commands;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.Location;
|
||||||
import org.mcteam.ancientgates.Gate;
|
import org.mcteam.ancientgates.Gate;
|
||||||
|
import org.mcteam.ancientgates.Plugin;
|
||||||
|
|
||||||
public class CommandCreate extends BaseCommand
|
|
||||||
|
public class CommandCreate extends BaseLocationCommand
|
||||||
{
|
{
|
||||||
public CommandCreate()
|
public CommandCreate()
|
||||||
{
|
{
|
||||||
@ -16,6 +18,8 @@ public class CommandCreate extends BaseCommand
|
|||||||
hasGateParam = false;
|
hasGateParam = false;
|
||||||
|
|
||||||
helpDescription = "Create a gate";
|
helpDescription = "Create a gate";
|
||||||
|
|
||||||
|
requiredPermission = Plugin.permissionManage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -28,16 +32,20 @@ public class CommandCreate extends BaseCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Gate.create(id);
|
gate = Gate.create(id);
|
||||||
sendMessage("Gate with id \"" + id + "\" was created. Now you should:");
|
|
||||||
|
Location playerLocation = getValidPlayerLocation();
|
||||||
|
|
||||||
|
if (playerLocation != null) {
|
||||||
|
gate.setLocation(playerLocation);
|
||||||
|
|
||||||
|
sendMessage("Gate with id \"" + id + "\" was created.\n The gates location has been set to your current location.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sendMessage("Gate with id \"" + id + "\" was created.\n Now you should build a frame and:");
|
||||||
sendMessage(new CommandSetFrom().getUsageTemplate(true, true));
|
sendMessage(new CommandSetFrom().getUsageTemplate(true, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(CommandSender sender)
|
|
||||||
{
|
|
||||||
return sender.hasPermission(permissionManage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user