use of net.countercraft.movecraft.events.CraftDetectEvent in project Movecraft by APDevTeam.
the class DetectionTask method get.
@Override
public Effect get() {
frontier();
if (!illegal.isEmpty())
return null;
var result = COMPLETION_VALIDATORS.stream().reduce(DetectionPredicate::and).orElse((a, b, c, d) -> Result.fail()).validate(materials, type, movecraftWorld, player);
result = result.isSucess() ? VISITED_VALIDATORS.stream().reduce(DetectionPredicate::and).orElse((a, b, c, d) -> Result.fail()).validate(visitedMaterials, type, movecraftWorld, player) : result;
if (!result.isSucess()) {
String message = result.getMessage();
return () -> audience.sendMessage(Component.text(message));
}
var hitbox = new BitmapHitBox(legal);
var parents = findParents(hitbox);
var supplied = supplier.apply(type, world, player, parents);
result = supplied.getLeft();
Craft craft = supplied.getRight();
if (type.getBoolProperty(CraftType.MUST_BE_SUBCRAFT) && !(craft instanceof SubCraft)) {
result = Result.failWithMessage(I18nSupport.getInternationalisedString("Detection - Must Be Subcraft"));
}
if (!result.isSucess()) {
String message = result.getMessage();
return () -> audience.sendMessage(Component.text(message));
}
craft.setAudience(audience);
craft.setHitBox(hitbox);
craft.setFluidLocations(new BitmapHitBox(fluid));
craft.setOrigBlockCount(craft.getHitBox().size());
final CraftDetectEvent event = new CraftDetectEvent(craft, startLocation);
WorldManager.INSTANCE.executeMain(() -> Bukkit.getPluginManager().callEvent(event));
if (event.isCancelled())
return () -> craft.getAudience().sendMessage(Component.text(event.getFailMessage()));
return ((Effect) () -> {
// Notify player and console
craft.getAudience().sendMessage(Component.text(String.format("%s Size: %s", I18nSupport.getInternationalisedString("Detection - Successfully piloted craft"), craft.getHitBox().size())));
Movecraft.getInstance().getLogger().info(String.format(I18nSupport.getInternationalisedString("Detection - Success - Log Output"), player == null ? "null" : player.getName(), craft.getType().getStringProperty(CraftType.NAME), craft.getHitBox().size(), craft.getHitBox().getMinX(), craft.getHitBox().getMinZ()));
}).andThen(// TODO: Remove
water(craft)).andThen(// Fire off pilot event
() -> Bukkit.getServer().getPluginManager().callEvent(new CraftPilotEvent(craft, CraftPilotEvent.Reason.PLAYER))).andThen(// Apply post detection effect
postDetection.apply(craft)).andThen(// Add craft to CraftManager
() -> CraftManager.getInstance().add(craft));
}
use of net.countercraft.movecraft.events.CraftDetectEvent in project Movecraft by APDevTeam.
the class NameSign method onCraftDetect.
@EventHandler
public void onCraftDetect(@NotNull CraftDetectEvent event) {
Craft c = event.getCraft();
if (c instanceof PilotedCraft) {
PilotedCraft pilotedCraft = (PilotedCraft) c;
if (Settings.RequireNamePerm && !pilotedCraft.getPilot().hasPermission("movecraft.name.place"))
return;
}
World w = c.getWorld();
for (MovecraftLocation location : c.getHitBox()) {
var block = location.toBukkit(w).getBlock();
if (!Tag.SIGNS.isTagged(block.getType())) {
continue;
}
BlockState state = block.getState();
if (!(state instanceof Sign)) {
return;
}
Sign sign = (Sign) state;
if (sign.getLine(0).equalsIgnoreCase(HEADER)) {
String name = Arrays.stream(sign.getLines()).skip(1).filter(f -> f != null && !f.trim().isEmpty()).collect(Collectors.joining(" "));
c.setName(name);
return;
}
}
}
Aggregations