use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.
the class LocationTrieSet method contains.
@Override
public boolean contains(Object o) {
if (o instanceof MovecraftLocation) {
MovecraftLocation location = (MovecraftLocation) o;
long packed = location.pack();
return contains(packed);
}
return false;
}
use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.
the class CruiseSign method onCraftDetect.
@EventHandler
public void onCraftDetect(CraftDetectEvent event) {
World world = event.getCraft().getWorld();
for (MovecraftLocation location : event.getCraft().getHitBox()) {
var block = location.toBukkit(world).getBlock();
if (!Tag.SIGNS.isTagged(block.getType())) {
continue;
}
BlockState state = block.getState();
if (state instanceof Sign) {
Sign sign = (Sign) state;
if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("Cruise: ON")) {
sign.setLine(0, "Cruise: OFF");
sign.update();
}
}
}
}
use of net.countercraft.movecraft.MovecraftLocation 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;
}
}
}
use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.
the class RemoteSign method onSignClick.
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSignClick(@NotNull PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) {
return;
}
BlockState state = event.getClickedBlock().getState();
if (!(state instanceof Sign)) {
return;
}
Sign sign = (Sign) state;
if (!ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase(HEADER)) {
return;
}
Craft foundCraft = null;
for (PlayerCraft tcraft : CraftManager.getInstance().getPlayerCraftsInWorld(event.getClickedBlock().getWorld())) {
if (MathUtils.locationInHitBox(tcraft.getHitBox(), event.getClickedBlock().getLocation())) {
// don't use a craft with a null player. This is
// mostly to avoid trying to use subcrafts
foundCraft = tcraft;
break;
}
}
if (foundCraft == null) {
event.getPlayer().sendMessage(ERROR_PREFIX + I18nSupport.getInternationalisedString("Remote Sign - Must be a part of a piloted craft"));
return;
}
if (!foundCraft.getType().getBoolProperty(CraftType.ALLOW_REMOTE_SIGN)) {
event.getPlayer().sendMessage(ERROR_PREFIX + I18nSupport.getInternationalisedString("Remote Sign - Not allowed on this craft"));
return;
}
String targetText = ChatColor.stripColor(sign.getLine(1));
if (targetText.equalsIgnoreCase(HEADER)) {
event.getPlayer().sendMessage(ERROR_PREFIX + I18nSupport.getInternationalisedString("Remote Sign - Cannot remote another Remote Sign"));
return;
}
if (targetText.equalsIgnoreCase("")) {
event.getPlayer().sendMessage("Remote Sign - Cannot be blank");
return;
}
LinkedList<MovecraftLocation> foundLocations = new LinkedList<MovecraftLocation>();
boolean firstError = true;
for (MovecraftLocation tloc : foundCraft.getHitBox()) {
BlockState tstate = event.getClickedBlock().getWorld().getBlockAt(tloc.getX(), tloc.getY(), tloc.getZ()).getState();
if (!(tstate instanceof Sign)) {
continue;
}
Sign ts = (Sign) tstate;
if (isEqualSign(ts, targetText)) {
if (isForbidden(ts)) {
if (firstError) {
event.getPlayer().sendMessage(I18nSupport.getInternationalisedString("Remote Sign - Forbidden string found"));
firstError = false;
}
event.getPlayer().sendMessage(" - ".concat(tloc.toString()).concat(" : ").concat(ts.getLine(0)));
} else {
foundLocations.add(tloc);
}
}
}
if (!firstError) {
return;
} else if (foundLocations.isEmpty()) {
event.getPlayer().sendMessage(I18nSupport.getInternationalisedString("Remote Sign - Could not find target sign"));
return;
}
if (Settings.MaxRemoteSigns > -1) {
int foundLocCount = foundLocations.size();
if (foundLocCount > Settings.MaxRemoteSigns) {
event.getPlayer().sendMessage(String.format(I18nSupport.getInternationalisedString("Remote Sign - Exceeding maximum allowed"), foundLocCount, Settings.MaxRemoteSigns));
return;
}
}
for (MovecraftLocation foundLoc : foundLocations) {
Block newBlock = event.getClickedBlock().getWorld().getBlockAt(foundLoc.getX(), foundLoc.getY(), foundLoc.getZ());
PlayerInteractEvent newEvent = new PlayerInteractEvent(event.getPlayer(), event.getAction(), event.getItem(), newBlock, event.getBlockFace());
// TODO: DON'T DO THIS
Bukkit.getServer().getPluginManager().callEvent(newEvent);
}
event.setCancelled(true);
}
use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.
the class TranslationTask method get.
@Override
public Effect get() {
var preTranslationResult = preTranslationValidators.stream().reduce(MonadicPredicate::and).orElseThrow().validate(craft);
if (!preTranslationResult.isSucess()) {
return () -> craft.getAudience().sendMessage(Component.text(preTranslationResult.getMessage()));
}
var preTranslateEvent = WorldManager.INSTANCE.executeMain(() -> {
var event = new CraftPreTranslateEvent(craft, translation.getX(), translation.getY(), translation.getZ(), craft.getWorld());
Bukkit.getServer().getPluginManager().callEvent(event);
return event;
});
if (preTranslateEvent.isCancelled()) {
return () -> craft.getAudience().sendMessage(Component.text(preTranslateEvent.getFailMessage()));
}
translation = new MovecraftLocation(preTranslateEvent.getDx(), preTranslateEvent.getDy(), preTranslateEvent.getDz());
destinationWorld = CachedMovecraftWorld.of(preTranslateEvent.getWorld());
// TODO: Portal movement
// TODO: Gravity
var destinationLocations = new SetHitBox();
var collisions = new SetHitBox();
var phaseLocations = new SetHitBox();
var harvestLocations = new SetHitBox();
var fuelSources = new ArrayList<FurnaceInventory>();
for (var originLocation : craft.getHitBox()) {
var originMaterial = craft.getMovecraftWorld().getMaterial(originLocation);
// Remove air from hitboxes
if (originMaterial.isAir())
continue;
if (Tags.FURNACES.contains(originMaterial)) {
var state = craft.getMovecraftWorld().getState(originLocation);
if (state instanceof FurnaceInventory)
fuelSources.add((FurnaceInventory) state);
}
var destination = originLocation.add(translation);
destinationLocations.add(destination);
// previous locations cannot collide
if (craft.getMovecraftWorld().equals(destinationWorld) && craft.getHitBox().contains(destination)) {
continue;
}
var destinationMaterial = destinationWorld.getMaterial(destination);
if (craft.getType().getMaterialSetProperty(CraftType.PASSTHROUGH_BLOCKS).contains(destinationMaterial)) {
phaseLocations.add(destination);
continue;
}
if (craft.getType().getMaterialSetProperty(CraftType.HARVEST_BLOCKS).contains(destinationMaterial) && craft.getType().getMaterialSetProperty(CraftType.HARVESTER_BLADE_BLOCKS).contains(originMaterial)) {
harvestLocations.add(destination);
continue;
}
collisions.add(destination);
}
double fuelBurnRate = (double) craft.getType().getPerWorldProperty(CraftType.PER_WORLD_FUEL_BURN_RATE, preTranslateEvent.getWorld());
Effect fuelBurnEffect;
if (craft.getBurningFuel() >= fuelBurnRate) {
// call event
final FuelBurnEvent event = new FuelBurnEvent(craft, craft.getBurningFuel(), fuelBurnRate);
submitEvent(event);
fuelBurnEffect = () -> craft.setBurningFuel(event.getBurningFuel() - event.getFuelBurnRate());
} else {
var fuelSource = findFuelHolders(craft.getType(), fuelSources);
if (fuelSource == null) {
return () -> craft.getAudience().sendMessage(I18nSupport.getInternationalisedComponent("Translation - Failed Craft out of fuel"));
}
callFuelEvent(craft, findFuelStack(craft.getType(), fuelSource));
// TODO: Take Fuel
fuelBurnEffect = () -> Bukkit.getLogger().info("This is where we'd take ur fuel, if we had some");
}
var translationResult = translationValidators.stream().reduce(TetradicPredicate::and).orElseThrow().validate(translation, destinationWorld, destinationLocations, craft.getType());
if (!translationResult.isSucess()) {
return () -> craft.getAudience().sendMessage(Component.text(translationResult.getMessage()));
}
// Direct float comparison due to check for statically initialized value
callCollisionEvent(craft, collisions, preTranslateEvent.getWorld());
if (craft.getType().getFloatProperty(CraftType.COLLISION_EXPLOSION) <= 0F && !collisions.isEmpty()) {
// TODO: collision highlights
return () -> craft.getAudience().sendMessage(Component.text(String.format(I18nSupport.getInternationalisedString("Translation - Failed Craft is obstructed") + " @ %d,%d,%d,%s", 0, 0, 0, "not_implemented")));
}
Effect fluidBoxEffect = fluidBox(craft, translation);
var translateEvent = callTranslateEvent(craft, destinationLocations, preTranslateEvent.getWorld());
// TODO: Sinking?
// TODO: Collision explosion
// TODO: phase blocks
Effect movementEffect = moveCraft();
// TODO: un-phase blocks
Effect teleportEffect = new TeleportationEffect(craft, translation, translateEvent.getWorld());
return fuelBurnEffect.andThen(fluidBoxEffect).andThen(movementEffect).andThen(teleportEffect);
}
Aggregations