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;
}
use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.
the class PlayerListener method onPlayerMove.
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Player p = event.getPlayer();
final Craft c = CraftManager.getInstance().getCraftByPlayer(p);
if (c == null) {
return;
}
highlights.computeIfAbsent(c, (craft) -> new LinkedList<>());
if (MathUtils.locationNearHitBox(c.getHitBox(), p.getLocation(), 2)) {
timeToReleaseAfter.remove(c);
clearHighlights(c, p);
return;
}
if (timeToReleaseAfter.containsKey(c) && timeToReleaseAfter.get(c) < System.currentTimeMillis()) {
CraftManager.getInstance().release(c, CraftReleaseEvent.Reason.PLAYER, false);
timeToReleaseAfter.remove(c);
clearHighlights(c, p);
return;
}
if (c.isNotProcessing() && c.getType().getBoolProperty(CraftType.MOVE_ENTITIES) && !timeToReleaseAfter.containsKey(c)) {
if (Settings.ManOverboardTimeout != 0) {
c.getAudience().sendActionBar(I18nSupport.getInternationalisedComponent("Manoverboard - Player has left craft"));
CraftManager.getInstance().addOverboard(p);
} else {
p.sendMessage(I18nSupport.getInternationalisedString("Release - Player has left craft"));
}
var mergePoints = checkCraftBorders(c);
if (!mergePoints.isEmpty())
p.sendMessage(I18nSupport.getInternationalisedString("Manoverboard - Craft May Merge"));
for (var location : mergePoints) {
highlights.get(c).add(BlockHighlight.highlightBlockAt(location, p));
}
timeToReleaseAfter.put(c, System.currentTimeMillis() + c.getType().getIntProperty(CraftType.RELEASE_TIMEOUT) * 1000L);
}
}
use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.
the class AscendSign method onSignClickEvent.
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSignClickEvent(@NotNull PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Block block = event.getClickedBlock();
if (!(block.getState() instanceof Sign)) {
return;
}
Sign sign = (Sign) event.getClickedBlock().getState();
if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("Ascend: OFF")) {
if (CraftManager.getInstance().getCraftByPlayer(event.getPlayer()) == null) {
return;
}
Craft c = CraftManager.getInstance().getCraftByPlayer(event.getPlayer());
if (!c.getType().getBoolProperty(CraftType.CAN_CRUISE)) {
return;
}
// c.resetSigns(true, false, true);
sign.setLine(0, "Ascend: ON");
sign.update(true);
c.setCruiseDirection(CruiseDirection.UP);
c.setLastCruiseUpdate(System.currentTimeMillis());
c.setCruising(true);
c.resetSigns(sign);
if (!c.getType().getBoolProperty(CraftType.MOVE_ENTITIES)) {
CraftManager.getInstance().addReleaseTask(c);
}
return;
}
if (!ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("Ascend: ON")) {
return;
}
Craft c = CraftManager.getInstance().getCraftByPlayer(event.getPlayer());
if (c == null || !c.getType().getBoolProperty(CraftType.CAN_CRUISE)) {
return;
}
sign.setLine(0, "Ascend: OFF");
sign.update(true);
c.setCruising(false);
c.resetSigns(sign);
}
use of net.countercraft.movecraft.craft.Craft in project Movecraft by APDevTeam.
the class ContactsSign method onSignTranslateEvent.
@EventHandler
public final void onSignTranslateEvent(SignTranslateEvent event) {
String[] lines = event.getLines();
Craft craft = event.getCraft();
if (!ChatColor.stripColor(lines[0]).equalsIgnoreCase("Contacts:")) {
return;
}
int signLine = 1;
for (Craft tcraft : craft.getContacts()) {
MovecraftLocation center = craft.getHitBox().getMidPoint();
MovecraftLocation tcenter = tcraft.getHitBox().getMidPoint();
int distsquared = center.distanceSquared(tcenter);
// craft has been detected
String notification = ChatColor.BLUE + tcraft.getType().getStringProperty(CraftType.NAME);
if (notification.length() > 9) {
notification = notification.substring(0, 7);
}
notification += " " + (int) Math.sqrt(distsquared);
int diffx = center.getX() - tcenter.getX();
int diffz = center.getZ() - tcenter.getZ();
if (Math.abs(diffx) > Math.abs(diffz)) {
if (diffx < 0) {
notification += " E";
} else {
notification += " W";
}
} else {
if (diffz < 0) {
notification += " S";
} else {
notification += " N";
}
}
lines[signLine++] = notification;
if (signLine >= 4) {
break;
}
}
if (signLine < 4) {
for (int i = signLine; i < 4; i++) {
lines[signLine] = "";
}
}
}
Aggregations