use of net.countercraft.movecraft.craft.PilotedCraft 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.PilotedCraft in project Movecraft by APDevTeam.
the class ReleaseCommand method onCommand.
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if (!command.getName().equalsIgnoreCase("release"))
return false;
if (!commandSender.hasPermission("movecraft.commands") && !commandSender.hasPermission("movecraft.commands.release")) {
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions"));
return true;
}
if (args.length == 0) {
if (!(commandSender instanceof Player)) {
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Player- Error - You do not have a craft to release!"));
return true;
}
Player player = (Player) commandSender;
final Craft pCraft = CraftManager.getInstance().getCraftByPlayerName(player.getName());
if (pCraft == null) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Player- Error - You do not have a craft to release!"));
return true;
}
CraftManager.getInstance().release(pCraft, CraftReleaseEvent.Reason.PLAYER, false);
return true;
}
if (!commandSender.hasPermission("movecraft.commands.release.others")) {
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Release - No Force Release"));
return true;
}
if (args[0].equalsIgnoreCase("-p")) {
for (Player p : Bukkit.getOnlinePlayers()) {
String name = p.getName();
final Craft pCraft = CraftManager.getInstance().getCraftByPlayerName(name);
if (pCraft != null)
CraftManager.getInstance().release(pCraft, CraftReleaseEvent.Reason.FORCE, false);
}
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Release - Released All Player Crafts"));
return true;
}
if (args[0].equalsIgnoreCase("-a")) {
final List<Craft> craftsToRelease = new ArrayList<>(CraftManager.getInstance().getCrafts());
for (Craft craft : craftsToRelease) {
CraftManager.getInstance().release(craft, CraftReleaseEvent.Reason.FORCE, false);
}
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Release - Released All Crafts"));
return true;
}
if (args[0].equalsIgnoreCase("-n")) {
final List<Craft> craftsToRelease = new ArrayList<>(CraftManager.getInstance().getCrafts());
for (Craft craft : craftsToRelease) {
if (!(craft instanceof PilotedCraft))
CraftManager.getInstance().release(craft, CraftReleaseEvent.Reason.FORCE, false);
}
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Release - Released All Null Crafts"));
return true;
}
Player target = Bukkit.getPlayer(args[0]);
if (target == null) {
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Player - Not Found"));
return true;
}
final Craft pCraft = CraftManager.getInstance().getCraftByPlayerName(args[0]);
if (pCraft != null) {
CraftManager.getInstance().release(pCraft, CraftReleaseEvent.Reason.FORCE, false);
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Release - Successful Force Release"));
return true;
}
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Player - Not Piloting"));
return true;
}
use of net.countercraft.movecraft.craft.PilotedCraft in project Movecraft by APDevTeam.
the class AsyncManager method run.
public void run() {
clearAll();
processCruise();
detectSinking();
processSinking();
processFadingBlocks();
processDetection();
processAlgorithmQueue();
// but have no pilot or are still processing
for (Craft craft : CraftManager.getInstance()) {
if (!(craft instanceof PilotedCraft)) {
if (craft.getLastCruiseUpdate() < System.currentTimeMillis() - 60000)
CraftManager.getInstance().release(craft, CraftReleaseEvent.Reason.INACTIVE, true);
}
if (!craft.isNotProcessing()) {
if (craft.getCruising()) {
if (craft.getLastCruiseUpdate() < System.currentTimeMillis() - 5000)
craft.setProcessing(false);
}
}
}
}
use of net.countercraft.movecraft.craft.PilotedCraft in project Movecraft by APDevTeam.
the class AsyncManager method processDetection.
private void processDetection() {
long ticksElapsed = (System.currentTimeMillis() - lastContactCheck) / 50;
if (ticksElapsed > 21) {
for (World w : Bukkit.getWorlds()) {
if (w == null)
continue;
for (Craft craft : CraftManager.getInstance().getPlayerCraftsInWorld(w)) {
if (!recentContactTracking.containsKey(craft))
recentContactTracking.put(craft, new HashMap<>());
for (Craft target : craft.getContacts()) {
MovecraftLocation craftCenter = craft.getHitBox().getMidPoint();
MovecraftLocation targetCenter = target.getHitBox().getMidPoint();
int diffx = craftCenter.getX() - targetCenter.getX();
int diffz = craftCenter.getZ() - targetCenter.getZ();
int distsquared = craftCenter.distanceSquared(targetCenter);
// minute, or is completely new?
if (System.currentTimeMillis() - recentContactTracking.get(craft).getOrDefault(target, 0L) <= 60000)
continue;
Component notification = I18nSupport.getInternationalisedComponent("Contact - New Contact").append(Component.text(": "));
if (target.getName().length() >= 1)
notification = notification.append(Component.text(target.getName() + " ("));
notification = notification.append(Component.text(target.getType().getStringProperty(CraftType.NAME)));
if (target.getName().length() >= 1)
notification = notification.append(Component.text(")"));
notification = notification.append(Component.text(" ")).append(I18nSupport.getInternationalisedComponent("Contact - Commanded By")).append(Component.text(" "));
if (target instanceof PilotedCraft)
notification = notification.append(Component.text(((PilotedCraft) target).getPilot().getDisplayName()));
else
notification = notification.append(Component.text("NULL"));
notification = notification.append(Component.text(", ")).append(I18nSupport.getInternationalisedComponent("Contact - Size")).append(Component.text(": ")).append(Component.text(target.getOrigBlockCount())).append(Component.text(", ")).append(I18nSupport.getInternationalisedComponent("Contact - Range")).append(Component.text(": ")).append(Component.text((int) Math.sqrt(distsquared))).append(Component.text(" ")).append(I18nSupport.getInternationalisedComponent("Contact - To The")).append(Component.text(" "));
if (Math.abs(diffx) > Math.abs(diffz)) {
if (diffx < 0)
notification = notification.append(I18nSupport.getInternationalisedComponent("Contact/Subcraft Rotate - East"));
else
notification = notification.append(I18nSupport.getInternationalisedComponent("Contact/Subcraft Rotate - West"));
} else if (diffz < 0)
notification = notification.append(I18nSupport.getInternationalisedComponent("Contact/Subcraft Rotate - South"));
else
notification = notification.append(I18nSupport.getInternationalisedComponent("Contact/Subcraft Rotate - North"));
notification = notification.append(Component.text("."));
craft.getAudience().sendMessage(notification);
var object = craft.getType().getObjectProperty(CraftType.COLLISION_SOUND);
if (!(object instanceof Sound))
throw new IllegalStateException("COLLISION_SOUND must be of type Sound");
craft.getAudience().playSound((Sound) object);
long timestamp = System.currentTimeMillis();
recentContactTracking.get(craft).put(target, timestamp);
}
}
}
lastContactCheck = System.currentTimeMillis();
}
}
use of net.countercraft.movecraft.craft.PilotedCraft in project Movecraft by APDevTeam.
the class CraftReportCommand method onCommand.
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if (commandSender.getName().equalsIgnoreCase("craftreport"))
return false;
if (!commandSender.hasPermission("movecraft.commands") && !commandSender.hasPermission("movecraft.commands.craftreport")) {
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions"));
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;
}
if (CraftManager.getInstance().isEmpty()) {
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Craft Report - None Found"));
return true;
}
TopicPaginator paginator = new TopicPaginator(I18nSupport.getInternationalisedString("Craft Report"));
for (Craft craft : CraftManager.getInstance()) {
HitBox hitBox = craft.getHitBox();
paginator.addLine((craft instanceof SinkingCraft ? ChatColor.RED : craft.getDisabled() ? ChatColor.BLUE : "") + craft.getType().getStringProperty(CraftType.NAME) + " " + ChatColor.RESET + (craft instanceof PilotedCraft ? ((PilotedCraft) craft).getPilot().getName() : I18nSupport.getInternationalisedString("None")) + " " + hitBox.size() + " @ " + hitBox.getMinX() + "," + hitBox.getMinY() + "," + hitBox.getMinZ() + " - " + String.format("%.2f", 1000 * craft.getMeanCruiseTime()) + "ms");
}
if (!paginator.isInBounds(page)) {
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Paginator - Invalid page") + "\"" + page + "\"");
return true;
}
for (String line : paginator.getPage(page)) commandSender.sendMessage(line);
return true;
}
Aggregations