use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.
the class MathUtils method fastNearestCraftToLoc.
@Nullable
public static Craft fastNearestCraftToLoc(@NotNull Set<Craft> crafts, @NotNull Location loc) {
Craft result = null;
long closestDistSquared = Long.MAX_VALUE;
for (Craft i : crafts) {
if (i.getHitBox().isEmpty())
continue;
int midX = (i.getHitBox().getMaxX() + i.getHitBox().getMinX()) >> 1;
// don't check Y because it is slow
int midZ = (i.getHitBox().getMaxZ() + i.getHitBox().getMinZ()) >> 1;
long distSquared = (long) (Math.pow(midX - loc.getX(), 2) + Math.pow(midZ - (int) loc.getZ(), 2));
if (distSquared < closestDistSquared) {
closestDistSquared = distSquared;
result = i;
}
}
return result;
}
use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.
the class ContactsCommand method onCommand.
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if (!command.getName().equalsIgnoreCase("contacts")) {
return false;
}
if (!(commandSender instanceof Player)) {
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Contacts - Must Be Player"));
return true;
}
Player player = (Player) commandSender;
if (CraftManager.getInstance().getCraftByPlayer(player) == null) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("You must be piloting a craft"));
return true;
}
int page;
try {
if (args.length == 0)
page = 1;
else
page = Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Paginator - Invalid Page") + " \"" + args[0] + "\"");
return true;
}
TopicPaginator pageinator = new TopicPaginator(I18nSupport.getInternationalisedString("Contacts"));
Craft ccraft = CraftManager.getInstance().getCraftByPlayer(player);
HitBox hitBox = ccraft.getHitBox();
MovecraftLocation center = hitBox.getMidPoint();
for (Craft tcraft : ccraft.getContacts()) {
HitBox tHitBox = tcraft.getHitBox();
if (tHitBox.isEmpty())
continue;
MovecraftLocation tCenter = tHitBox.getMidPoint();
int distsquared = center.distanceSquared(tCenter);
String notification = I18nSupport.getInternationalisedString("Contact");
notification += ": ";
notification += tcraft instanceof SinkingCraft ? ChatColor.RED : tcraft.getDisabled() ? ChatColor.BLUE : "";
notification += tcraft.getName().length() >= 1 ? tcraft.getName() + " (" : "";
notification += tcraft.getType().getStringProperty(CraftType.NAME);
notification += tcraft.getName().length() >= 1 ? ") " : " ";
notification += ChatColor.RESET;
notification += I18nSupport.getInternationalisedString("Contact - Commanded By") + ", ";
notification += tcraft instanceof PilotedCraft ? ((PilotedCraft) tcraft).getPilot().getDisplayName() : "null";
notification += " ";
notification += I18nSupport.getInternationalisedString("Contact - Size") + " ";
notification += tcraft.getOrigBlockCount();
notification += ", " + I18nSupport.getInternationalisedString("Contact - Range") + " ";
notification += (int) Math.sqrt(distsquared);
notification += " " + I18nSupport.getInternationalisedString("Contact - To The");
int diffx = center.getX() - tCenter.getX();
int diffz = center.getZ() - tCenter.getZ();
if (Math.abs(diffx) > Math.abs(diffz))
if (diffx < 0)
notification += " " + I18nSupport.getInternationalisedString("Contact/Subcraft Rotate - East") + ".";
else
notification += " " + I18nSupport.getInternationalisedString("Contact/Subcraft Rotate - West") + ".";
else if (diffz < 0)
notification += " " + I18nSupport.getInternationalisedString("Contact/Subcraft Rotate - South") + ".";
else
notification += " " + I18nSupport.getInternationalisedString("Contact/Subcraft Rotate - North") + ".";
pageinator.addLine(notification);
}
if (pageinator.isEmpty()) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Contacts - None Found"));
return true;
}
if (!pageinator.isInBounds(page)) {
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Paginator - Invalid page") + "\"" + page + "\"");
return true;
}
for (String line : pageinator.getPage(page)) commandSender.sendMessage(line);
return true;
}
use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.
the class CruiseCommand method onCommand.
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if (!command.getName().equalsIgnoreCase("cruise")) {
return false;
}
if (!(commandSender instanceof Player)) {
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Cruise - Must Be Player"));
return true;
}
Player player = (Player) commandSender;
if (args.length < 1) {
final Craft craft = CraftManager.getInstance().getCraftByPlayerName(player.getName());
if (craft == null) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("You must be piloting a craft"));
return true;
}
if (!player.hasPermission("movecraft.commands") || !player.hasPermission("movecraft.commands.cruise")) {
craft.setCruising(false);
return true;
}
if (craft.getCruising()) {
craft.setCruising(false);
return true;
}
// Normalize yaw from [-360, 360] to [0, 360]
float yaw = (player.getLocation().getYaw() + 360.0f);
if (yaw >= 360.0f) {
yaw %= 360.0f;
}
if (yaw >= 45 && yaw < 135) {
// west
craft.setCruiseDirection(CruiseDirection.WEST);
} else if (yaw >= 135 && yaw < 225) {
// north
craft.setCruiseDirection(CruiseDirection.NORTH);
} else if (yaw >= 225 && yaw <= 315) {
// east
craft.setCruiseDirection(CruiseDirection.EAST);
} else {
// default south
craft.setCruiseDirection(CruiseDirection.SOUTH);
}
craft.setCruising(true);
return true;
}
if (args[0].equalsIgnoreCase("off")) {
// This goes before because players can sometimes freeze while cruising
final Craft craft = CraftManager.getInstance().getCraftByPlayerName(player.getName());
if (craft == null) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("You must be piloting a craft"));
return true;
}
craft.setCruising(false);
return true;
}
if (!player.hasPermission("movecraft.commands") || !player.hasPermission("movecraft.commands.cruise")) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions"));
return true;
}
final Craft craft = CraftManager.getInstance().getCraftByPlayerName(player.getName());
if (craft == null) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("You must be piloting a craft"));
return true;
}
if (!player.hasPermission("movecraft." + craft.getType().getStringProperty(CraftType.NAME) + ".move")) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions"));
return true;
}
if (!craft.getType().getBoolProperty(CraftType.CAN_CRUISE)) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Cruise - Craft Cannot Cruise"));
return true;
}
if (args[0].equalsIgnoreCase("on")) {
float yaw = (player.getLocation().getYaw() + 360.0f);
if (yaw >= 360.0f) {
yaw %= 360.0f;
}
if (yaw >= 45 && yaw < 135) {
// west
craft.setCruiseDirection(CruiseDirection.WEST);
} else if (yaw >= 135 && yaw < 225) {
// north
craft.setCruiseDirection(CruiseDirection.NORTH);
} else if (yaw >= 225 && yaw <= 315) {
// east
craft.setCruiseDirection(CruiseDirection.EAST);
} else {
// default south
craft.setCruiseDirection(CruiseDirection.SOUTH);
}
craft.setCruising(true);
return true;
}
if (args[0].equalsIgnoreCase("north") || args[0].equalsIgnoreCase("n")) {
craft.setCruiseDirection(CruiseDirection.NORTH);
craft.setCruising(true);
return true;
}
if (args[0].equalsIgnoreCase("south") || args[0].equalsIgnoreCase("s")) {
craft.setCruiseDirection(CruiseDirection.SOUTH);
craft.setCruising(true);
return true;
}
if (args[0].equalsIgnoreCase("east") || args[0].equalsIgnoreCase("e")) {
craft.setCruiseDirection(CruiseDirection.EAST);
craft.setCruising(true);
return true;
}
if (args[0].equalsIgnoreCase("west") || args[0].equalsIgnoreCase("w")) {
craft.setCruiseDirection(CruiseDirection.WEST);
craft.setCruising(true);
return true;
}
if (args[0].equalsIgnoreCase("up") || args[0].equalsIgnoreCase("u")) {
craft.setCruiseDirection(CruiseDirection.UP);
craft.setCruising(true);
return true;
}
if (args[0].equalsIgnoreCase("down") || args[0].equalsIgnoreCase("d")) {
craft.setCruiseDirection(CruiseDirection.DOWN);
craft.setCruising(true);
return true;
}
return false;
}
use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.
the class ManOverboardCommand method onCommand.
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
if (!command.getName().equalsIgnoreCase("manOverBoard"))
return false;
if (!(commandSender instanceof Player)) {
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("ManOverboard - Must Be Player"));
return true;
}
Player player = (Player) commandSender;
Craft craft = CraftManager.getInstance().getCraftByPlayerName(player.getName());
if (craft == null) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("ManOverboard - No Craft Found"));
return true;
}
Location telPoint = getCraftTeleportPoint(craft);
if (craft.getWorld() != player.getWorld()) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("ManOverboard - Other World"));
return true;
}
if ((System.currentTimeMillis() - CraftManager.getInstance().getTimeFromOverboard(player)) / 1_000 > Settings.ManOverboardTimeout && !MathUtils.locIsNearCraftFast(craft, MathUtils.bukkit2MovecraftLoc(player.getLocation()))) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("ManOverboard - Timed Out"));
return true;
}
if (telPoint.distanceSquared(player.getLocation()) > Settings.ManOverboardDistSquared) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("ManOverboard - Distance Too Far"));
return true;
}
if (craft.getDisabled() || craft instanceof SinkingCraft) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("ManOverboard - Disabled"));
return true;
}
ManOverboardEvent event = new ManOverboardEvent(craft, telPoint);
Bukkit.getServer().getPluginManager().callEvent(event);
player.setVelocity(new Vector(0, 0, 0));
player.setFallDistance(0);
player.teleport(telPoint);
return true;
}
use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.
the class PilotCommand method onCommand.
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if (!command.getName().equalsIgnoreCase("pilot"))
return false;
if (!(commandSender instanceof Player)) {
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Pilot - Must Be Player"));
return true;
}
Player player = (Player) commandSender;
if (!player.hasPermission("movecraft.commands") || !player.hasPermission("movecraft.commands.pilot")) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions"));
return true;
}
if (args.length < 1) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Pilot - No Craft Type"));
return true;
}
if (!player.hasPermission("movecraft." + args[0] + ".pilot")) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions"));
return true;
}
CraftType craftType = CraftManager.getInstance().getCraftTypeFromString(args[0]);
if (craftType == null) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Pilot - Invalid Craft Type"));
return true;
}
final World world = player.getWorld();
MovecraftLocation startPoint = MathUtils.bukkit2MovecraftLoc(player.getLocation());
CraftManager.getInstance().detect(startPoint, craftType, (type, w, p, parents) -> {
// Note: This only passes in a non-null player.
assert p != null;
if (parents.size() > 0)
return new Pair<>(Result.failWithMessage(I18nSupport.getInternationalisedString("Detection - Failed - Already commanding a craft")), null);
return new Pair<>(Result.succeed(), new PlayerCraftImpl(type, w, p));
}, world, player, Movecraft.getAdventure().player(player), craft -> () -> {
// Release old craft if it exists
Craft oldCraft = CraftManager.getInstance().getCraftByPlayer(player);
if (oldCraft != null)
CraftManager.getInstance().release(oldCraft, CraftReleaseEvent.Reason.PLAYER, false);
});
return true;
}
Aggregations