refactor(commands): from async to sync Part 3
This commit is contained in:
1 parent
5d841d6d3b
commit
66a5f53408
222 files changed
+4326
-5547
No files matched your search
@@ -211,7 +211,7 @@ mod tests {
|
||||
let ec = EnderChestInventory::new();
|
||||
assert_eq!(ec.size(), 27);
|
||||
assert!(ec.is_empty().await);
|
||||
assert!(!ec.has_tracker().await);
|
||||
assert!(!ec.has_tracker());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -323,12 +323,8 @@ impl AnvilChunkData {
|
||||
|
||||
let compression = compression.unwrap_or_else(|| chunk_config.compression.algorithm.into());
|
||||
let level = chunk_config.compression.level;
|
||||
|
||||
// Offload CPU-heavy compression to blocking thread pool
|
||||
let compressed_data =
|
||||
tokio::task::spawn_blocking(move || compression.compress_data(&raw_bytes, level))
|
||||
.await
|
||||
.map_err(|err| ChunkWritingError::IoError(std::io::Error::other(err)))?
|
||||
let compressed_data = compression
|
||||
.compress_data(&raw_bytes, level)
|
||||
.map_err(ChunkWritingError::Compression)?;
|
||||
|
||||
Ok(Self {
|
||||
@@ -793,16 +789,9 @@ impl<S: SingleChunkDataSerializer + 'static> ChunkSerializer for AnvilChunkFile<
|
||||
let is_ok = match &self.chunks_data[index] {
|
||||
None => stream.send(LoadedData::Missing(chunk)).await.is_ok(),
|
||||
Some(chunk_metadata) => {
|
||||
let chunk_data = chunk_metadata.serialized_data.clone();
|
||||
let result =
|
||||
match tokio::task::spawn_blocking(move || chunk_data.to_chunk(chunk)).await
|
||||
{
|
||||
Ok(Ok(chunk_res)) => LoadedData::Loaded(chunk_res),
|
||||
Ok(Err(err)) => LoadedData::Error((chunk, err)),
|
||||
Err(err) => LoadedData::Error((
|
||||
chunk,
|
||||
ChunkReadingError::IoError(std::io::Error::other(err)),
|
||||
)),
|
||||
let result = match chunk_metadata.serialized_data.to_chunk(chunk) {
|
||||
Ok(chunk_res) => LoadedData::Loaded(chunk_res),
|
||||
Err(err) => LoadedData::Error((chunk, err)),
|
||||
};
|
||||
|
||||
stream.send(result).await.is_ok()
|
||||
|
||||
@@ -407,7 +407,6 @@ impl<S: SingleChunkDataSerializer + 'static> ChunkSerializer for LinearV2File<S>
|
||||
let chunks_data = self.chunks_data.clone();
|
||||
let timestamps = self.timestamps;
|
||||
|
||||
let (bucket_entries, compressed_buckets) = tokio::task::spawn_blocking(move || {
|
||||
let mut compressed_buckets: Vec<Box<[u8]>> = Vec::with_capacity(bucket_count);
|
||||
let mut bucket_entries: Vec<BucketSizeEntry> = Vec::with_capacity(bucket_count);
|
||||
|
||||
@@ -423,10 +422,6 @@ impl<S: SingleChunkDataSerializer + 'static> ChunkSerializer for LinearV2File<S>
|
||||
});
|
||||
compressed_buckets.push(compressed);
|
||||
}
|
||||
(bucket_entries, compressed_buckets)
|
||||
})
|
||||
.await
|
||||
.map_err(std::io::Error::other)?;
|
||||
|
||||
let newest_timestamp = self.timestamps.iter().copied().max().unwrap_or(0);
|
||||
|
||||
@@ -598,18 +593,9 @@ impl<S: SingleChunkDataSerializer + 'static> ChunkSerializer for LinearV2File<S>
|
||||
let is_ok = match &self.chunks_data[index] {
|
||||
None => stream.send(LoadedData::Missing(chunk)).await.is_ok(),
|
||||
Some(data) => {
|
||||
let data = data.clone();
|
||||
let result = match tokio::task::spawn_blocking(move || {
|
||||
S::from_bytes(&data, chunk)
|
||||
})
|
||||
.await
|
||||
{
|
||||
Ok(Ok(c)) => LoadedData::Loaded(c),
|
||||
Ok(Err(err)) => LoadedData::Error((chunk, err)),
|
||||
Err(err) => LoadedData::Error((
|
||||
chunk,
|
||||
ChunkReadingError::IoError(std::io::Error::other(err)),
|
||||
)),
|
||||
let result = match S::from_bytes(data, chunk) {
|
||||
Ok(c) => LoadedData::Loaded(c),
|
||||
Err(err) => LoadedData::Error((chunk, err)),
|
||||
};
|
||||
stream.send(result).await.is_ok()
|
||||
}
|
||||
|
||||
@@ -129,8 +129,7 @@ where
|
||||
let index = (rel_x + rel_z * 32) as usize;
|
||||
|
||||
if let Some(chunk_bytes) = self.data.chunks.get(&index.to_string()) {
|
||||
let chunk_bytes = chunk_bytes.clone();
|
||||
let res = tokio::task::spawn_blocking(move || {
|
||||
let res = (|| {
|
||||
let mut decoder = StreamingDecoder::new(&chunk_bytes[..]).map_err(|e| {
|
||||
ChunkReadingError::IoError(std::io::Error::other(e.to_string()))
|
||||
})?;
|
||||
@@ -139,16 +138,11 @@ where
|
||||
.map_err(ChunkReadingError::IoError)?;
|
||||
let bytes = Bytes::from(decompressed);
|
||||
D::from_bytes(&bytes, pos)
|
||||
})
|
||||
.await;
|
||||
})();
|
||||
|
||||
let data_res = match res {
|
||||
Ok(Ok(data)) => LoadedData::Loaded(data),
|
||||
Ok(Err(e)) => LoadedData::Error((pos, e)),
|
||||
Err(e) => LoadedData::Error((
|
||||
pos,
|
||||
ChunkReadingError::IoError(std::io::Error::other(e)),
|
||||
)),
|
||||
Ok(data) => LoadedData::Loaded(data),
|
||||
Err(e) => LoadedData::Error((pos, e)),
|
||||
};
|
||||
|
||||
if stream.send(data_res).await.is_err() {
|
||||
|
||||
@@ -108,9 +108,7 @@ impl<S: ChunkSerializer<WriteBackend = PathBuf> + 'static> ChunkSerializerLazyLo
|
||||
);
|
||||
return Ok(S::default());
|
||||
}
|
||||
let value = tokio::task::spawn_blocking(move || S::read(bytes.into()))
|
||||
.await
|
||||
.map_err(|e| ChunkReadingError::IoError(std::io::Error::other(e)))??;
|
||||
let value = S::read(bytes.into())?;
|
||||
trace!("Successfully read file from disk: {}", self.path.display());
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
@@ -56,6 +56,55 @@ fn needs_relighting(chunk: &crate::chunk::ChunkData, config: LightingEngineConfi
|
||||
!has_complex_light
|
||||
}
|
||||
|
||||
async fn load_proto_chunk(chunk: &Arc<crate::chunk::ChunkData>, level: &Level) -> ProtoChunk {
|
||||
if let Some(pool) = &level.gen_pool {
|
||||
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||
let world_gen = level.world_gen.load();
|
||||
let chunk_clone = chunk.clone();
|
||||
pool.spawn(move || {
|
||||
let p = ProtoChunk::from_chunk_data(&chunk_clone, &world_gen);
|
||||
let _ = tx.send(p);
|
||||
});
|
||||
rx.await
|
||||
.unwrap_or_else(|_| ProtoChunk::from_chunk_data(chunk, &level.world_gen.load()))
|
||||
} else {
|
||||
ProtoChunk::from_chunk_data(chunk, &level.world_gen.load())
|
||||
}
|
||||
}
|
||||
|
||||
async fn process_loaded_chunk(chunk: Arc<crate::chunk::ChunkData>, level: &Level) -> Chunk {
|
||||
let pos = ChunkPos::new(chunk.x, chunk.z);
|
||||
if chunk.status == ChunkStatus::Full {
|
||||
let needs_relight = needs_relighting(&chunk, level.lighting_config);
|
||||
if needs_relight {
|
||||
debug!(
|
||||
"Chunk {pos:?} has uniform lighting, downgrading to Features stage for relighting"
|
||||
);
|
||||
|
||||
let mut proto = load_proto_chunk(&chunk, level).await;
|
||||
|
||||
// Clear all lighting data
|
||||
let section_count = proto.light.sky_light.len();
|
||||
proto.light.sky_light = (0..section_count)
|
||||
.map(|_| LightContainer::new_empty(15))
|
||||
.collect();
|
||||
proto.light.block_light = (0..section_count)
|
||||
.map(|_| LightContainer::new_empty(0))
|
||||
.collect();
|
||||
|
||||
// Set stage to Features
|
||||
proto.stage = StagedChunkEnum::Features;
|
||||
|
||||
Chunk::Proto(Box::new(proto))
|
||||
} else {
|
||||
Chunk::Level(chunk)
|
||||
}
|
||||
} else {
|
||||
let proto = load_proto_chunk(&chunk, level).await;
|
||||
Chunk::Proto(Box::new(proto))
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn io_read_work(
|
||||
recv: crossfire::compat::MAsyncRx<Vec<ChunkPos>>,
|
||||
send: crossfire::compat::MTx<(ChunkPos, RecvChunk)>,
|
||||
@@ -102,55 +151,10 @@ pub async fn io_read_work(
|
||||
match data {
|
||||
Loaded(chunk) => {
|
||||
let pos = ChunkPos::new(chunk.x, chunk.z);
|
||||
if chunk.status == ChunkStatus::Full {
|
||||
// Relighting check
|
||||
let needs_relight = needs_relighting(&chunk, level.lighting_config);
|
||||
|
||||
if needs_relight {
|
||||
debug!(
|
||||
"Chunk {pos:?} has uniform lighting, downgrading to Features stage for relighting"
|
||||
);
|
||||
|
||||
// Create ProtoChunk using the async method
|
||||
let mut proto =
|
||||
ProtoChunk::from_chunk_data(&chunk, &level.world_gen.load());
|
||||
|
||||
// Clear all lighting data
|
||||
let section_count = proto.light.sky_light.len();
|
||||
proto.light.sky_light = (0..section_count)
|
||||
.map(|_| LightContainer::new_empty(15))
|
||||
.collect();
|
||||
proto.light.block_light = (0..section_count)
|
||||
.map(|_| LightContainer::new_empty(0))
|
||||
.collect();
|
||||
|
||||
// Set stage to Features
|
||||
proto.stage = StagedChunkEnum::Features;
|
||||
|
||||
if send
|
||||
.send((pos, RecvChunk::IO(Chunk::Proto(Box::new(proto)))))
|
||||
.is_err()
|
||||
{
|
||||
let processed = process_loaded_chunk(chunk, &level).await;
|
||||
if send.send((pos, RecvChunk::IO(processed))).is_err() {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// Send fully valid chunk
|
||||
if send
|
||||
.send((pos, RecvChunk::IO(Chunk::Level(chunk))))
|
||||
.is_err()
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Standard ProtoChunk handling for non-full chunks
|
||||
let val = RecvChunk::IO(Chunk::Proto(Box::new(
|
||||
ProtoChunk::from_chunk_data(&chunk, &level.world_gen.load()),
|
||||
)));
|
||||
if send.send((pos, val)).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
LoadedData::Missing(pos) | LoadedData::Error((pos, _)) => {
|
||||
if send
|
||||
|
||||
@@ -246,15 +246,13 @@ impl BedBlock {
|
||||
if world.get_block_state(&bed_head_pos.up()).is_solid()
|
||||
|| world.get_block_state(&bed_foot_pos.up()).is_solid()
|
||||
{
|
||||
player
|
||||
.send_system_message_raw(
|
||||
player.send_system_message_raw(
|
||||
&pumpkin_macros::translate_cross!(
|
||||
translation::java::BLOCK_MINECRAFT_BED_OBSTRUCTED,
|
||||
translation::bedrock::TILE_BED_OBSTRUCTED
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
return BlockActionResult::SuccessServer;
|
||||
}
|
||||
|
||||
@@ -262,15 +260,13 @@ impl BedBlock {
|
||||
if bed_props.occupied {
|
||||
// TODO: Wake up villager
|
||||
|
||||
player
|
||||
.send_system_message_raw(
|
||||
player.send_system_message_raw(
|
||||
&pumpkin_macros::translate_cross!(
|
||||
translation::java::BLOCK_MINECRAFT_BED_OCCUPIED,
|
||||
translation::bedrock::TILE_BED_OCCUPIED
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
return BlockActionResult::SuccessServer;
|
||||
}
|
||||
|
||||
@@ -282,48 +278,39 @@ impl BedBlock {
|
||||
.position()
|
||||
.is_within_bounds(bed_foot_pos.to_f64(), 3.0, 3.0, 3.0)
|
||||
{
|
||||
player
|
||||
.send_system_message_raw(
|
||||
player.send_system_message_raw(
|
||||
&pumpkin_macros::translate_cross!(
|
||||
translation::java::BLOCK_MINECRAFT_BED_TOO_FAR_AWAY,
|
||||
translation::bedrock::TILE_BED_TOOFAR
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
return BlockActionResult::SuccessServer;
|
||||
}
|
||||
|
||||
// Set respawn point
|
||||
if player
|
||||
.set_respawn_point(
|
||||
if player.set_respawn_point(
|
||||
world.dimension.clone(),
|
||||
bed_head_pos,
|
||||
player.get_entity().yaw.load(),
|
||||
player.get_entity().pitch.load(),
|
||||
false,
|
||||
)
|
||||
.await
|
||||
{
|
||||
player
|
||||
.send_system_message(&pumpkin_macros::translate_cross!(
|
||||
) {
|
||||
player.send_system_message(&pumpkin_macros::translate_cross!(
|
||||
translation::java::BLOCK_MINECRAFT_SET_SPAWN,
|
||||
translation::bedrock::TILE_BED_RESPAWNSET
|
||||
))
|
||||
.await;
|
||||
));
|
||||
}
|
||||
|
||||
// Make sure the time and weather allows sleep
|
||||
if !can_sleep(world) {
|
||||
player
|
||||
.send_system_message_raw(
|
||||
player.send_system_message_raw(
|
||||
&pumpkin_macros::translate_cross!(
|
||||
translation::java::BLOCK_MINECRAFT_BED_NO_SLEEP,
|
||||
translation::bedrock::TILE_BED_NOSLEEP
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
return BlockActionResult::SuccessServer;
|
||||
}
|
||||
|
||||
@@ -337,15 +324,13 @@ impl BedBlock {
|
||||
if pos.is_within_bounds(bed_head_pos.to_f64(), 8.0, 5.0, 8.0)
|
||||
|| pos.is_within_bounds(bed_foot_pos.to_f64(), 8.0, 5.0, 8.0)
|
||||
{
|
||||
player
|
||||
.send_system_message_raw(
|
||||
player.send_system_message_raw(
|
||||
&pumpkin_macros::translate_cross!(
|
||||
translation::java::BLOCK_MINECRAFT_BED_NOT_SAFE,
|
||||
translation::bedrock::TILE_BED_NOTSAFE
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
return BlockActionResult::SuccessServer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ impl CommandBlock {
|
||||
}
|
||||
}
|
||||
|
||||
async fn execute(
|
||||
fn execute(
|
||||
server: &Arc<Server>,
|
||||
world: Arc<World>,
|
||||
block_entity: Arc<dyn BlockEntity>,
|
||||
@@ -133,24 +133,16 @@ impl CommandBlock {
|
||||
if command.is_empty() {
|
||||
command_entity.success_count.store(0, Ordering::Release);
|
||||
} else {
|
||||
let source = CommandSender::CommandBlock(command_entity, world.clone())
|
||||
.into_source(server)
|
||||
.await;
|
||||
let source = CommandSender::CommandBlock(command_entity, world).into_source(server);
|
||||
|
||||
server
|
||||
.command_dispatcher
|
||||
.load()
|
||||
.handle_command(&source, command)
|
||||
.await;
|
||||
.handle_command(&source, command);
|
||||
}
|
||||
}
|
||||
|
||||
async fn chain_execute(
|
||||
server: &Arc<Server>,
|
||||
world: Arc<World>,
|
||||
start: BlockPos,
|
||||
direction: Facing,
|
||||
) {
|
||||
fn chain_execute(server: &Arc<Server>, world: &Arc<World>, start: BlockPos, direction: Facing) {
|
||||
let mut i = u16::MAX;
|
||||
let mut pos = start;
|
||||
|
||||
@@ -179,7 +171,7 @@ impl CommandBlock {
|
||||
let props = CommandBlockLikeProperties::from_state_id(state_id, block);
|
||||
|
||||
if powered || auto {
|
||||
let conditions_met = Self::conditions_met(&world, &pos, direction);
|
||||
let conditions_met = Self::conditions_met(world, &pos, direction);
|
||||
if conditions_met {
|
||||
let command = command_entity
|
||||
.command
|
||||
@@ -190,7 +182,7 @@ impl CommandBlock {
|
||||
warn!("Command block entity disappeared during execution");
|
||||
break;
|
||||
};
|
||||
Self::execute(server, world.clone(), entity, &command).await;
|
||||
Self::execute(server, world.clone(), entity, &command);
|
||||
} else if props.conditional {
|
||||
command_entity.success_count.store(0, Ordering::Release);
|
||||
}
|
||||
@@ -298,25 +290,20 @@ impl BlockBehaviour for CommandBlock {
|
||||
let entity_clone = block_entity.clone();
|
||||
let position = *args.position;
|
||||
let facing = props.facing;
|
||||
tokio::spawn(async move {
|
||||
let Some(command_entity) = entity_clone.as_any().downcast_ref::<CommandBlockEntity>()
|
||||
else {
|
||||
return;
|
||||
};
|
||||
if let Some(command_entity) = entity_clone.as_any().downcast_ref::<CommandBlockEntity>() {
|
||||
let command = command_entity
|
||||
.command
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.clone();
|
||||
Self::execute(&server, world.clone(), entity_clone, &command).await;
|
||||
Self::execute(&server, world.clone(), entity_clone, &command);
|
||||
Self::chain_execute(
|
||||
&server,
|
||||
world,
|
||||
&world,
|
||||
position.offset(facing.to_block_direction().to_offset()),
|
||||
facing,
|
||||
)
|
||||
.await;
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
let block = args.world.get_block(args.position);
|
||||
let is_auto = command_entity.auto.load(Ordering::Relaxed);
|
||||
|
||||
@@ -294,13 +294,13 @@ impl DispenserBlock {
|
||||
Self::dispense_empty_bucket(ctx, dispenser, item).await;
|
||||
} else if FilledBucketItem::ids().contains(&item.item.id) {
|
||||
// Filled buckets place their fluid in front of the dispenser
|
||||
Self::dispense_filled_bucket(ctx, item).await;
|
||||
Self::dispense_filled_bucket(ctx, item);
|
||||
} else if item.item.id == Item::FLINT_AND_STEEL.id {
|
||||
// Flint and steel light fires and prime TNT
|
||||
Self::dispense_flint_and_steel(ctx, item).await;
|
||||
Self::dispense_flint_and_steel(ctx, item);
|
||||
} else if item.item.id == Item::HONEYCOMB.id {
|
||||
// Honeycombs wax copper blocks
|
||||
Self::dispense_honeycomb(ctx, item).await;
|
||||
Self::dispense_honeycomb(ctx, item);
|
||||
} else if entity_from_egg(item.item.id).is_some() {
|
||||
// Spawn eggs
|
||||
Self::dispense_spawn_egg(ctx, item);
|
||||
@@ -703,7 +703,7 @@ impl DispenserBlock {
|
||||
Some(stack)
|
||||
}
|
||||
|
||||
async fn dispense_filled_bucket(ctx: &DispenseContext<'_>, item: &mut ItemStack) {
|
||||
fn dispense_filled_bucket(ctx: &DispenseContext<'_>, item: &mut ItemStack) {
|
||||
let front = Self::target_position(ctx);
|
||||
|
||||
// TODO: Spawn the stored entity for axolotl/fish/tadpole buckets, like the player path.
|
||||
@@ -727,7 +727,7 @@ impl DispenserBlock {
|
||||
}
|
||||
}
|
||||
|
||||
async fn dispense_flint_and_steel(ctx: &DispenseContext<'_>, item: &mut ItemStack) {
|
||||
fn dispense_flint_and_steel(ctx: &DispenseContext<'_>, item: &mut ItemStack) {
|
||||
let front = Self::target_position(ctx);
|
||||
let front_block = ctx.world.get_block(&front);
|
||||
|
||||
@@ -755,7 +755,7 @@ impl DispenserBlock {
|
||||
}
|
||||
}
|
||||
|
||||
async fn dispense_honeycomb(ctx: &DispenseContext<'_>, item: &mut ItemStack) {
|
||||
fn dispense_honeycomb(ctx: &DispenseContext<'_>, item: &mut ItemStack) {
|
||||
let front = Self::target_position(ctx);
|
||||
let front_block = ctx.world.get_block(&front);
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use pumpkin_data::block_properties::{BlockProperties, RespawnAnchorLikeProperties};
|
||||
use pumpkin_data::dimension::Dimension;
|
||||
use pumpkin_data::item::Item;
|
||||
@@ -61,46 +59,35 @@ impl BlockBehaviour for RespawnAnchorBlock {
|
||||
}
|
||||
|
||||
if props.charges == 0 {
|
||||
let player = Arc::clone(args.player);
|
||||
tokio::spawn(async move {
|
||||
player
|
||||
args.player
|
||||
.send_system_message(&pumpkin_macros::translate_cross!(
|
||||
translation::java::BLOCK_MINECRAFT_BED_NO_SLEEP,
|
||||
translation::bedrock::TILE_BED_NOSLEEP
|
||||
))
|
||||
.await;
|
||||
});
|
||||
));
|
||||
return BlockActionResult::SuccessServer;
|
||||
}
|
||||
|
||||
let player = Arc::clone(args.player);
|
||||
let world = Arc::clone(args.world);
|
||||
let player = args.player;
|
||||
let world = args.world;
|
||||
let pos = *args.position;
|
||||
tokio::spawn(async move {
|
||||
if player
|
||||
.set_respawn_point(
|
||||
if player.set_respawn_point(
|
||||
world.dimension.clone(),
|
||||
pos,
|
||||
player.get_entity().yaw.load(),
|
||||
player.get_entity().pitch.load(),
|
||||
false,
|
||||
)
|
||||
.await
|
||||
{
|
||||
) {
|
||||
world.play_sound(
|
||||
Sound::BlockRespawnAnchorSetSpawn,
|
||||
SoundCategory::Blocks,
|
||||
&pos.to_f64(),
|
||||
);
|
||||
|
||||
player
|
||||
.send_system_message(&pumpkin_macros::translate_cross!(
|
||||
player.send_system_message(&pumpkin_macros::translate_cross!(
|
||||
translation::java::BLOCK_MINECRAFT_SET_SPAWN,
|
||||
translation::bedrock::TILE_BED_RESPAWNSET
|
||||
))
|
||||
.await;
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
BlockActionResult::SuccessServer
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ impl SculkShriekerBlock {
|
||||
show_icon: true,
|
||||
blend: true,
|
||||
};
|
||||
player.send_effect(darkness.clone()).await;
|
||||
player.send_effect(&darkness);
|
||||
player.living_entity.add_effect(darkness);
|
||||
}
|
||||
|
||||
|
||||
@@ -566,8 +566,7 @@ impl BlockRegistry {
|
||||
}
|
||||
|
||||
if location.0.y + face.to_offset().y > world.get_top_y() {
|
||||
player
|
||||
.send_system_message_raw(
|
||||
player.send_system_message_raw(
|
||||
&pumpkin_util::text::TextComponent::translate_cross(
|
||||
pumpkin_data::translation::java::BUILD_TOOHIGH,
|
||||
pumpkin_data::translation::bedrock::BUILD_TOOHIGH,
|
||||
@@ -577,8 +576,7 @@ impl BlockRegistry {
|
||||
)
|
||||
.color_named(pumpkin_util::text::color::NamedColor::Red),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
return Err(BlockPlacingError::BlockOutOfWorld);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,11 +33,7 @@ impl ArgumentConsumer for BlockArgumentConsumer {
|
||||
_server: &'a Server,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let block = args.pop().map(|arg| arg.value);
|
||||
match block {
|
||||
Some(s) => Box::pin(async move { Some(Arg::Block(s)) }),
|
||||
None => Box::pin(async move { None }),
|
||||
}
|
||||
args.pop().map(|arg| Arg::Block(arg.value))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,11 +95,7 @@ impl ArgumentConsumer for BlockPredicateArgumentConsumer {
|
||||
_server: &'a Server,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let block = args.pop().map(|arg| arg.value);
|
||||
match block {
|
||||
Some(s) => Box::pin(async move { Some(Arg::BlockPredicate(s)) }),
|
||||
None => Box::pin(async move { None }),
|
||||
}
|
||||
args.pop().map(|arg| Arg::BlockPredicate(arg.value))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,24 +18,19 @@ impl GetClientSideArgParser for BoolArgConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for BoolArgConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let result: Option<Arg<'a>> = s_opt.map_or_else(
|
||||
|| None,
|
||||
|s| match s {
|
||||
s_opt.and_then(|s| match s {
|
||||
"false" => Some(Arg::Bool(false)),
|
||||
"true" => Some(Arg::Bool(true)),
|
||||
_ => None,
|
||||
},
|
||||
);
|
||||
|
||||
Box::pin(async move { result })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,18 +23,15 @@ impl GetClientSideArgParser for BossbarColorArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for BossbarColorArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let result: Option<Arg<'a>> = s_opt.map_or_else(
|
||||
|| None,
|
||||
|s| {
|
||||
let color = match s {
|
||||
let color = match s_opt? {
|
||||
"blue" => Some(BossbarColor::Blue),
|
||||
"green" => Some(BossbarColor::Green),
|
||||
"pink" => Some(BossbarColor::Pink),
|
||||
@@ -46,26 +43,15 @@ impl ArgumentConsumer for BossbarColorArgumentConsumer {
|
||||
};
|
||||
|
||||
color.map(Arg::BossbarColor)
|
||||
},
|
||||
);
|
||||
|
||||
Box::pin(async move { result })
|
||||
}
|
||||
|
||||
fn suggest<'a>(
|
||||
&'a self,
|
||||
_sender: &CommandSender,
|
||||
_server: &'a Server,
|
||||
_input: &'a str,
|
||||
) -> SuggestResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn suggest(&self, _sender: &CommandSender, _server: &Server, _input: &str) -> SuggestResult {
|
||||
let colors = ["blue", "green", "pink", "purple", "red", "white", "yellow"];
|
||||
let suggestions: Vec<CommandSuggestion> = colors
|
||||
.iter()
|
||||
.map(|color| CommandSuggestion::new((*color).to_string(), None))
|
||||
.collect();
|
||||
Ok(Some(suggestions))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,18 +23,15 @@ impl GetClientSideArgParser for BossbarStyleArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for BossbarStyleArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let result: Option<Arg<'a>> = s_opt.map_or_else(
|
||||
|| None,
|
||||
|s| {
|
||||
let style = match s {
|
||||
let style = match s_opt? {
|
||||
"notched_10" => Some(BossbarDivisions::Notches10),
|
||||
"notched_12" => Some(BossbarDivisions::Notches12),
|
||||
"notched_20" => Some(BossbarDivisions::Notches20),
|
||||
@@ -44,19 +41,9 @@ impl ArgumentConsumer for BossbarStyleArgumentConsumer {
|
||||
};
|
||||
|
||||
style.map(Arg::BossbarStyle)
|
||||
},
|
||||
);
|
||||
|
||||
Box::pin(async move { result })
|
||||
}
|
||||
|
||||
fn suggest<'a>(
|
||||
&'a self,
|
||||
_sender: &CommandSender,
|
||||
_server: &'a Server,
|
||||
_input: &'a str,
|
||||
) -> SuggestResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn suggest(&self, _sender: &CommandSender, _server: &Server, _input: &str) -> SuggestResult {
|
||||
let styles = [
|
||||
"notched_10",
|
||||
"notched_12",
|
||||
@@ -69,7 +56,6 @@ impl ArgumentConsumer for BossbarStyleArgumentConsumer {
|
||||
.map(|style| CommandSuggestion::new((*style).to_string(), None))
|
||||
.collect();
|
||||
Ok(Some(suggestions))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,15 +25,15 @@ impl<T: ToFromNumber> ArgumentConsumer for BoundedNumArgumentConsumer<T>
|
||||
where
|
||||
Self: GetClientSideArgParser,
|
||||
{
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let result: Option<Arg<'a>> = s_opt
|
||||
s_opt
|
||||
// Replace args.pop()?.parse::<T>().ok()?
|
||||
.and_then(|s| s.parse::<T>().ok())
|
||||
.map(|x| {
|
||||
@@ -53,9 +53,7 @@ where
|
||||
|
||||
// Success case
|
||||
Arg::Num(Ok(x.to_number()))
|
||||
});
|
||||
|
||||
Box::pin(async move { result })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,19 +27,14 @@ impl GetClientSideArgParser for CommandTreeArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for CommandTreeArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
let s = args.pop().map(|arg| arg.value)?;
|
||||
|
||||
let Some(s) = s_opt else {
|
||||
return Box::pin(async move { None });
|
||||
};
|
||||
|
||||
Box::pin(async move {
|
||||
let dispatcher = server.command_dispatcher.load();
|
||||
|
||||
dispatcher
|
||||
@@ -47,16 +42,9 @@ impl ArgumentConsumer for CommandTreeArgumentConsumer {
|
||||
.get_tree(s)
|
||||
.ok()
|
||||
.map(|tree| Arg::CommandTree(tree.clone()))
|
||||
})
|
||||
}
|
||||
|
||||
fn suggest<'a>(
|
||||
&'a self,
|
||||
_sender: &CommandSender,
|
||||
server: &'a Server,
|
||||
input: &'a str,
|
||||
) -> SuggestResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn suggest(&self, _sender: &CommandSender, server: &Server, input: &str) -> SuggestResult {
|
||||
let Some(input) = input.split_single_whitespace_including_empty_parts().last() else {
|
||||
return Ok(None);
|
||||
};
|
||||
@@ -70,7 +58,6 @@ impl ArgumentConsumer for CommandTreeArgumentConsumer {
|
||||
.map(|suggestion| CommandSuggestion::new(suggestion.clone(), None))
|
||||
.collect();
|
||||
Ok(Some(suggestions))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,26 +38,16 @@ impl ArgumentConsumer for DifficultyArgumentConsumer {
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let result: Option<Arg<'a>> =
|
||||
s_opt.and_then(|s| Difficulty::from_str(s).map(Arg::Difficulty).ok());
|
||||
|
||||
Box::pin(async move { result })
|
||||
s_opt.and_then(|s| Difficulty::from_str(s).map(Arg::Difficulty).ok())
|
||||
}
|
||||
|
||||
fn suggest<'a>(
|
||||
&'a self,
|
||||
_sender: &CommandSender,
|
||||
_server: &'a Server,
|
||||
_input: &'a str,
|
||||
) -> SuggestResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn suggest(&self, _sender: &CommandSender, _server: &Server, _input: &str) -> SuggestResult {
|
||||
let difficulties = ["easy", "normal", "hard", "peaceful"];
|
||||
let suggestions: Vec<CommandSuggestion> = difficulties
|
||||
.iter()
|
||||
.map(|difficulty| CommandSuggestion::new((*difficulty).to_string(), None))
|
||||
.collect();
|
||||
Ok(Some(suggestions))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -352,33 +352,26 @@ impl GetClientSideArgParser for EntitiesArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for EntitiesArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let Some(s) = s_opt else {
|
||||
return Box::pin(async move { None });
|
||||
};
|
||||
let s = args.pop().map(|arg| arg.value)?;
|
||||
|
||||
let entity_selector = match s.parse::<TargetSelector>() {
|
||||
Ok(selector) => selector,
|
||||
Err(e) => {
|
||||
debug!("Failed to parse target selector '{s}': {e}");
|
||||
return Box::pin(async move { None }); // Return a Future resolving to None
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
Box::pin(async move {
|
||||
// todo: command context
|
||||
// This is the required asynchronous operation.
|
||||
let entities = server.select_entities(&entity_selector, Some(sender));
|
||||
|
||||
Some(Arg::Entities(entities))
|
||||
})
|
||||
}
|
||||
|
||||
fn consume_with_syntax<'a>(
|
||||
@@ -388,18 +381,12 @@ impl ArgumentConsumer for EntitiesArgumentConsumer {
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResultWithSyntax<'a> {
|
||||
let Some(raw_arg) = args.pop() else {
|
||||
return Box::pin(async { Ok(None) });
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let selector = match parse_target_selector_with_context(raw_arg) {
|
||||
Ok(selector) => selector,
|
||||
Err(error) => return Box::pin(async move { Err(error) }),
|
||||
};
|
||||
|
||||
Box::pin(async move {
|
||||
let selector = parse_target_selector_with_context(raw_arg)?;
|
||||
let entities = server.select_entities(&selector, Some(sender));
|
||||
Ok(Some(Arg::Entities(entities)))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,37 +35,31 @@ impl GetClientSideArgParser for EntityArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for EntityArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let Some(s) = s_opt else {
|
||||
return Box::pin(async move { None });
|
||||
};
|
||||
let s = args.pop().map(|arg| arg.value)?;
|
||||
|
||||
let entity_selector = match s.parse::<TargetSelector>() {
|
||||
Ok(selector) => selector,
|
||||
Err(e) => {
|
||||
debug!("Failed to parse target selector '{s}': {e}");
|
||||
return Box::pin(async move { None });
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
if entity_selector.get_limit() > 1 {
|
||||
debug!("Target selector '{s}' has limit > 1, expected single entity");
|
||||
return Box::pin(async move { None });
|
||||
return None;
|
||||
}
|
||||
|
||||
Box::pin(async move {
|
||||
// todo: command context
|
||||
let entities = server.select_entities(&entity_selector, Some(sender));
|
||||
|
||||
entities.into_iter().next().map(Arg::Entity)
|
||||
})
|
||||
}
|
||||
|
||||
fn consume_with_syntax<'a>(
|
||||
@@ -75,22 +69,17 @@ impl ArgumentConsumer for EntityArgumentConsumer {
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResultWithSyntax<'a> {
|
||||
let Some(raw_arg) = args.pop() else {
|
||||
return Box::pin(async { Ok(None) });
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let selector = match parse_target_selector_with_context(raw_arg) {
|
||||
Ok(selector) => selector,
|
||||
Err(error) => return Box::pin(async move { Err(error) }),
|
||||
};
|
||||
let selector = parse_target_selector_with_context(raw_arg)?;
|
||||
|
||||
if selector.get_limit() > 1 {
|
||||
return Box::pin(async { Ok(None) });
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
Box::pin(async move {
|
||||
let entities = server.select_entities(&selector, Some(sender));
|
||||
Ok(entities.into_iter().next().map(Arg::Entity))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,17 +47,15 @@ impl ArgumentConsumer for EntityAnchorArgumentConsumer {
|
||||
_server: &'a Server,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let Some(anchor_str) = args.pop().map(|arg| arg.value) else {
|
||||
return Box::pin(async move { None });
|
||||
};
|
||||
let anchor_str = args.pop().map(|arg| arg.value)?;
|
||||
|
||||
let anchor = match anchor_str.to_lowercase().as_str() {
|
||||
"feet" => EntityAnchor::Feet,
|
||||
"eyes" => EntityAnchor::Eyes,
|
||||
_ => return Box::pin(async move { None }),
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
Box::pin(async move { Some(Arg::EntityAnchor(anchor)) })
|
||||
Some(Arg::EntityAnchor(anchor))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,15 +23,15 @@ impl GetClientSideArgParser for GamemodeArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for GamemodeArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let result: Option<Arg<'a>> = s_opt.and_then(|s| {
|
||||
s_opt.and_then(|s| {
|
||||
if let Ok(id) = s.parse::<i8>()
|
||||
&& let Ok(gamemode) = GameMode::try_from(id)
|
||||
{
|
||||
@@ -39,9 +39,7 @@ impl ArgumentConsumer for GamemodeArgumentConsumer {
|
||||
}
|
||||
|
||||
GameMode::from_str(s).map(Arg::GameMode).ok() // Convert Result to Option<T>
|
||||
});
|
||||
|
||||
Box::pin(async move { result })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,16 +76,11 @@ impl ArgumentConsumer for GameProfilesArgumentConsumer {
|
||||
server: &'a Server,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let Some(raw_arg) = args.pop() else {
|
||||
return Box::pin(async { None });
|
||||
};
|
||||
let raw_arg = args.pop()?;
|
||||
|
||||
Box::pin(async move {
|
||||
resolve_profiles_from_token(sender, server, raw_arg)
|
||||
.await
|
||||
.ok()
|
||||
.map(Arg::GameProfiles)
|
||||
})
|
||||
}
|
||||
|
||||
fn consume_with_syntax<'a>(
|
||||
@@ -95,22 +90,14 @@ impl ArgumentConsumer for GameProfilesArgumentConsumer {
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResultWithSyntax<'a> {
|
||||
let Some(raw_arg) = args.pop() else {
|
||||
return Box::pin(async { Ok(None) });
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
Box::pin(async move {
|
||||
let resolved = resolve_profiles_from_token(sender, server, raw_arg).await?;
|
||||
let resolved = resolve_profiles_from_token(sender, server, raw_arg)?;
|
||||
Ok(Some(Arg::GameProfiles(resolved)))
|
||||
})
|
||||
}
|
||||
|
||||
fn suggest<'a>(
|
||||
&'a self,
|
||||
_sender: &CommandSender,
|
||||
server: &'a Server,
|
||||
_input: &'a str,
|
||||
) -> SuggestResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn suggest(&self, _sender: &CommandSender, server: &Server, _input: &str) -> SuggestResult {
|
||||
let mut suggestions = Vec::new();
|
||||
if self.suggest_selectors {
|
||||
suggestions.extend(selector_suggestions());
|
||||
@@ -124,7 +111,11 @@ impl ArgumentConsumer for GameProfilesArgumentConsumer {
|
||||
}
|
||||
}
|
||||
GameProfileSuggestionMode::NonOpOnlinePlayers => {
|
||||
let ops = server.data.operator_config.read().await;
|
||||
let ops = server
|
||||
.data
|
||||
.operator_config
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
for player in server.get_all_players() {
|
||||
if ops.ops.iter().all(|op| op.uuid != player.gameprofile.id) {
|
||||
push_name_if_missing(&mut names, player.gameprofile.name.clone());
|
||||
@@ -132,19 +123,31 @@ impl ArgumentConsumer for GameProfilesArgumentConsumer {
|
||||
}
|
||||
}
|
||||
GameProfileSuggestionMode::OpNames => {
|
||||
let ops = server.data.operator_config.read().await;
|
||||
let ops = server
|
||||
.data
|
||||
.operator_config
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
for op in &ops.ops {
|
||||
push_name_if_missing(&mut names, op.name.clone());
|
||||
}
|
||||
}
|
||||
GameProfileSuggestionMode::BannedNames => {
|
||||
let banned = server.data.banned_player_list.read().await;
|
||||
let banned = server
|
||||
.data
|
||||
.banned_player_list
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
for entry in &banned.banned_players {
|
||||
push_name_if_missing(&mut names, entry.name.clone());
|
||||
}
|
||||
}
|
||||
GameProfileSuggestionMode::NonWhitelistedOnlinePlayers => {
|
||||
let whitelist = server.data.whitelist_config.read().await;
|
||||
let whitelist = server
|
||||
.data
|
||||
.whitelist_config
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
for player in server.get_all_players() {
|
||||
if !whitelist.is_whitelisted(&player.gameprofile) {
|
||||
push_name_if_missing(&mut names, player.gameprofile.name.clone());
|
||||
@@ -152,7 +155,11 @@ impl ArgumentConsumer for GameProfilesArgumentConsumer {
|
||||
}
|
||||
}
|
||||
GameProfileSuggestionMode::WhitelistedNames => {
|
||||
let whitelist = server.data.whitelist_config.read().await;
|
||||
let whitelist = server
|
||||
.data
|
||||
.whitelist_config
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
for entry in &whitelist.whitelist {
|
||||
push_name_if_missing(&mut names, entry.name.clone());
|
||||
}
|
||||
@@ -166,7 +173,6 @@ impl ArgumentConsumer for GameProfilesArgumentConsumer {
|
||||
);
|
||||
|
||||
Ok(Some(suggestions))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +193,7 @@ impl<'a> FindArg<'a> for GameProfilesArgumentConsumer {
|
||||
}
|
||||
}
|
||||
|
||||
async fn resolve_profiles_from_token(
|
||||
fn resolve_profiles_from_token(
|
||||
sender: &CommandSender,
|
||||
server: &Server,
|
||||
raw_arg: RawArg<'_>,
|
||||
@@ -212,12 +218,17 @@ async fn resolve_profiles_from_token(
|
||||
return Ok(vec![player.gameprofile.clone()]);
|
||||
}
|
||||
|
||||
let cached_entry = server.data.user_cache.write().await.get_by_uuid(uuid);
|
||||
let cached_entry = server
|
||||
.data
|
||||
.user_cache
|
||||
.write()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.get_by_uuid(uuid);
|
||||
if let Some(entry) = cached_entry {
|
||||
return Ok(vec![profile_from_uuid_name(entry.uuid, entry.name)]);
|
||||
}
|
||||
|
||||
if let Some(profile) = resolve_known_profile_by_uuid(server, uuid).await {
|
||||
if let Some(profile) = resolve_known_profile_by_uuid(server, uuid) {
|
||||
return Ok(vec![profile]);
|
||||
}
|
||||
|
||||
@@ -232,13 +243,13 @@ async fn resolve_profiles_from_token(
|
||||
.data
|
||||
.user_cache
|
||||
.write()
|
||||
.await
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.get_by_name(raw_arg.value);
|
||||
if let Some(entry) = cached_entry {
|
||||
return Ok(vec![profile_from_uuid_name(entry.uuid, entry.name)]);
|
||||
}
|
||||
|
||||
if let Some(profile) = resolve_known_profile_by_name(server, raw_arg.value).await {
|
||||
if let Some(profile) = resolve_known_profile_by_name(server, raw_arg.value) {
|
||||
return Ok(vec![profile]);
|
||||
}
|
||||
|
||||
@@ -252,7 +263,7 @@ async fn resolve_profiles_from_token(
|
||||
.data
|
||||
.user_cache
|
||||
.write()
|
||||
.await
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.upsert(uuid, resolved_name.clone());
|
||||
return Ok(vec![profile_from_uuid_name(uuid, resolved_name)]);
|
||||
}
|
||||
@@ -266,7 +277,7 @@ async fn resolve_profiles_from_token(
|
||||
.data
|
||||
.user_cache
|
||||
.write()
|
||||
.await
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.upsert(profile.id, profile.name.clone());
|
||||
return Ok(vec![profile]);
|
||||
}
|
||||
@@ -274,16 +285,24 @@ async fn resolve_profiles_from_token(
|
||||
Err(syntax_player_unknown(raw_arg))
|
||||
}
|
||||
|
||||
async fn resolve_known_profile_by_name(server: &Server, name: &str) -> Option<GameProfile> {
|
||||
fn resolve_known_profile_by_name(server: &Server, name: &str) -> Option<GameProfile> {
|
||||
{
|
||||
let ops = server.data.operator_config.read().await;
|
||||
let ops = server
|
||||
.data
|
||||
.operator_config
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
if let Some(op) = ops.ops.iter().find(|op| op.name.eq_ignore_ascii_case(name)) {
|
||||
return Some(profile_from_uuid_name(op.uuid, op.name.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let banned_players = server.data.banned_player_list.read().await;
|
||||
let banned_players = server
|
||||
.data
|
||||
.banned_player_list
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
if let Some(entry) = banned_players
|
||||
.banned_players
|
||||
.iter()
|
||||
@@ -294,7 +313,11 @@ async fn resolve_known_profile_by_name(server: &Server, name: &str) -> Option<Ga
|
||||
}
|
||||
|
||||
{
|
||||
let whitelist = server.data.whitelist_config.read().await;
|
||||
let whitelist = server
|
||||
.data
|
||||
.whitelist_config
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
if let Some(entry) = whitelist
|
||||
.whitelist
|
||||
.iter()
|
||||
@@ -307,16 +330,24 @@ async fn resolve_known_profile_by_name(server: &Server, name: &str) -> Option<Ga
|
||||
None
|
||||
}
|
||||
|
||||
async fn resolve_known_profile_by_uuid(server: &Server, uuid: Uuid) -> Option<GameProfile> {
|
||||
fn resolve_known_profile_by_uuid(server: &Server, uuid: Uuid) -> Option<GameProfile> {
|
||||
{
|
||||
let ops = server.data.operator_config.read().await;
|
||||
let ops = server
|
||||
.data
|
||||
.operator_config
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
if let Some(op) = ops.ops.iter().find(|op| op.uuid == uuid) {
|
||||
return Some(profile_from_uuid_name(op.uuid, op.name.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let banned_players = server.data.banned_player_list.read().await;
|
||||
let banned_players = server
|
||||
.data
|
||||
.banned_player_list
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
if let Some(entry) = banned_players
|
||||
.banned_players
|
||||
.iter()
|
||||
@@ -327,7 +358,11 @@ async fn resolve_known_profile_by_uuid(server: &Server, uuid: Uuid) -> Option<Ga
|
||||
}
|
||||
|
||||
{
|
||||
let whitelist = server.data.whitelist_config.read().await;
|
||||
let whitelist = server
|
||||
.data
|
||||
.whitelist_config
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
if let Some(entry) = whitelist.whitelist.iter().find(|entry| entry.uuid == uuid) {
|
||||
return Some(profile_from_uuid_name(entry.uuid, entry.name.clone()));
|
||||
}
|
||||
|
||||
@@ -48,17 +48,15 @@ impl GetClientSideArgParser for HexColorArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for HexColorArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let result = s_opt.and_then(|s| parse_hex_color(s).map(Arg::HexColor));
|
||||
|
||||
Box::pin(async move { result })
|
||||
s_opt.and_then(|s| parse_hex_color(s).map(Arg::HexColor))
|
||||
}
|
||||
|
||||
fn consume_with_syntax<'a>(
|
||||
@@ -68,31 +66,24 @@ impl ArgumentConsumer for HexColorArgumentConsumer {
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResultWithSyntax<'a> {
|
||||
let Some(raw_arg) = args.pop() else {
|
||||
return Box::pin(async { Ok(None) });
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let result = parse_hex_color(raw_arg.value)
|
||||
parse_hex_color(raw_arg.value)
|
||||
.map(|color| Some(Arg::HexColor(color)))
|
||||
.ok_or_else(|| {
|
||||
INVALID_HEX_ERROR_TYPE.create_without_context_args_slice(&[TextComponent::text(
|
||||
raw_arg.value.to_string(),
|
||||
)])
|
||||
});
|
||||
|
||||
Box::pin(async move { result })
|
||||
})
|
||||
}
|
||||
|
||||
fn suggest<'a>(
|
||||
&'a self,
|
||||
_sender: &CommandSender,
|
||||
_server: &'a Server,
|
||||
_input: &'a str,
|
||||
) -> SuggestResult<'a> {
|
||||
fn suggest(&self, _sender: &CommandSender, _server: &Server, _input: &str) -> SuggestResult {
|
||||
let suggestions = vec![
|
||||
CommandSuggestion::new("F00".to_string(), None),
|
||||
CommandSuggestion::new("FF0000".to_string(), None),
|
||||
];
|
||||
Box::pin(async move { Ok(Some(suggestions)) })
|
||||
Ok(Some(suggestions))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,19 +35,16 @@ impl ArgumentConsumer for MsgArgConsumer {
|
||||
_server: &'a Server,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let first_word_opt = args.pop();
|
||||
let first_word = args.pop()?;
|
||||
|
||||
let mut msg = match first_word_opt {
|
||||
Some(word) => word.value.to_string(),
|
||||
None => return Box::pin(async { None }),
|
||||
};
|
||||
let mut msg = first_word.value.to_string();
|
||||
|
||||
while let Some(word) = args.pop() {
|
||||
msg.push(' ');
|
||||
msg.push_str(word.value);
|
||||
}
|
||||
|
||||
Box::pin(async move { Some(Arg::Msg(msg)) })
|
||||
Some(Arg::Msg(msg))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use std::pin::Pin;
|
||||
use std::{collections::HashMap, hash::Hash, sync::Arc};
|
||||
|
||||
use bounded_num::{NotInBounds, Number};
|
||||
@@ -60,12 +59,10 @@ pub mod textcomponent;
|
||||
pub mod time;
|
||||
|
||||
/// see [`crate::command::tree::builder::argument`]
|
||||
pub type ConsumeResult<'a> = Pin<Box<dyn Future<Output = Option<Arg<'a>>> + Send + 'a>>;
|
||||
pub type ConsumeResultWithSyntax<'a> =
|
||||
Pin<Box<dyn Future<Output = Result<Option<Arg<'a>>, CommandSyntaxError>> + Send + 'a>>;
|
||||
pub type ConsumeResult<'a> = Option<Arg<'a>>;
|
||||
pub type ConsumeResultWithSyntax<'a> = Result<Option<Arg<'a>>, CommandSyntaxError>;
|
||||
|
||||
pub type SuggestResult<'a> =
|
||||
Pin<Box<dyn Future<Output = Result<Option<Vec<CommandSuggestion>>, CommandError>> + Send + 'a>>;
|
||||
pub type SuggestResult = Result<Option<Vec<CommandSuggestion>>, CommandError>;
|
||||
|
||||
pub trait ArgumentConsumer: Sync + Send + GetClientSideArgParser {
|
||||
fn consume<'a>(
|
||||
@@ -81,20 +78,14 @@ pub trait ArgumentConsumer: Sync + Send + GetClientSideArgParser {
|
||||
server: &'a Server,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResultWithSyntax<'a> {
|
||||
let future = self.consume(sender, server, args);
|
||||
Box::pin(async move { Ok(future.await) })
|
||||
Ok(self.consume(sender, server, args))
|
||||
}
|
||||
|
||||
/// Used for tab completion (but only if argument suggestion type is "`minecraft:ask_server`"!).
|
||||
///
|
||||
/// NOTE: This is called after this consumer's [`ArgumentConsumer::consume`] method returned None, so if args is used here, make sure [`ArgumentConsumer::consume`] never returns None after mutating args.
|
||||
fn suggest<'a>(
|
||||
&'a self,
|
||||
_sender: &CommandSender,
|
||||
_server: &'a Server,
|
||||
_input: &'a str,
|
||||
) -> SuggestResult<'a> {
|
||||
Box::pin(async move { Ok(None) })
|
||||
fn suggest(&self, _sender: &CommandSender, _server: &Server, _input: &str) -> SuggestResult {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,17 +30,13 @@ impl GetClientSideArgParser for PlayersArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for PlayersArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let Some(s) = s_opt else {
|
||||
return Box::pin(async move { None });
|
||||
};
|
||||
let s = args.pop().map(|arg| arg.value)?;
|
||||
|
||||
let sync_result: Option<Vec<Arc<Player>>> = match s {
|
||||
"@s" => match sender {
|
||||
@@ -57,10 +53,9 @@ impl ArgumentConsumer for PlayersArgumentConsumer {
|
||||
};
|
||||
|
||||
if let Some(players) = sync_result {
|
||||
return Box::pin(async move { Some(Arg::Players(players)) });
|
||||
return Some(Arg::Players(players));
|
||||
}
|
||||
|
||||
Box::pin(async move {
|
||||
let players = match s {
|
||||
"@r" => server
|
||||
.get_random_player()
|
||||
@@ -70,7 +65,6 @@ impl ArgumentConsumer for PlayersArgumentConsumer {
|
||||
};
|
||||
|
||||
players.map(Arg::Players)
|
||||
})
|
||||
}
|
||||
|
||||
fn consume_with_syntax<'a>(
|
||||
@@ -80,22 +74,14 @@ impl ArgumentConsumer for PlayersArgumentConsumer {
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResultWithSyntax<'a> {
|
||||
let Some(raw_arg) = args.pop() else {
|
||||
return Box::pin(async { Ok(None) });
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let selector = match parse_target_selector_with_context(raw_arg) {
|
||||
Ok(selector) => selector,
|
||||
Err(error) => return Box::pin(async move { Err(error) }),
|
||||
};
|
||||
let selector = parse_target_selector_with_context(raw_arg)?;
|
||||
ensure_player_only_selector(&selector, raw_arg)?;
|
||||
|
||||
if let Err(error) = ensure_player_only_selector(&selector, raw_arg) {
|
||||
return Box::pin(async move { Err(error) });
|
||||
}
|
||||
|
||||
Box::pin(async move {
|
||||
let players = server.select_players(&selector, Some(sender));
|
||||
Ok(Some(Arg::Players(players)))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,24 +28,18 @@ impl GetClientSideArgParser for Position2DArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for Position2DArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let x_str_opt = args.pop().map(|arg| arg.value);
|
||||
let z_str_opt = args.pop().map(|arg| arg.value);
|
||||
let x_str = args.pop()?.value;
|
||||
let z_str = args.pop()?.value;
|
||||
|
||||
let (Some(x_str), Some(z_str)) = (x_str_opt, z_str_opt) else {
|
||||
return Box::pin(async move { None });
|
||||
};
|
||||
|
||||
let result: Option<Arg<'a>> = MaybeRelativePosition2D::try_new(x_str, z_str)
|
||||
MaybeRelativePosition2D::try_new(x_str, z_str)
|
||||
.and_then(|pos| pos.try_to_absolute(sender.position()))
|
||||
.map(Arg::Pos2D);
|
||||
|
||||
Box::pin(async move { result })
|
||||
.map(Arg::Pos2D)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,25 +25,19 @@ impl GetClientSideArgParser for Position3DArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for Position3DArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let x_str_opt = args.pop().map(|arg| arg.value);
|
||||
let y_str_opt = args.pop().map(|arg| arg.value);
|
||||
let z_str_opt = args.pop().map(|arg| arg.value);
|
||||
let x_str = args.pop()?.value;
|
||||
let y_str = args.pop()?.value;
|
||||
let z_str = args.pop()?.value;
|
||||
|
||||
let (Some(x_str), Some(y_str), Some(z_str)) = (x_str_opt, y_str_opt, z_str_opt) else {
|
||||
return Box::pin(async move { None });
|
||||
};
|
||||
|
||||
let result: Option<Arg<'a>> = MaybeRelativePosition3D::try_new(x_str, y_str, z_str)
|
||||
MaybeRelativePosition3D::try_new(x_str, y_str, z_str)
|
||||
.and_then(|pos| pos.try_to_absolute(sender.position()))
|
||||
.map(Arg::Pos3D);
|
||||
|
||||
Box::pin(async move { result })
|
||||
.map(Arg::Pos3D)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,25 +28,19 @@ impl GetClientSideArgParser for BlockPosArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for BlockPosArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let x_str_opt = args.pop().map(|arg| arg.value);
|
||||
let y_str_opt = args.pop().map(|arg| arg.value);
|
||||
let z_str_opt = args.pop().map(|arg| arg.value);
|
||||
let x_str = args.pop()?.value;
|
||||
let y_str = args.pop()?.value;
|
||||
let z_str = args.pop()?.value;
|
||||
|
||||
let (Some(x_str), Some(y_str), Some(z_str)) = (x_str_opt, y_str_opt, z_str_opt) else {
|
||||
return Box::pin(async move { None });
|
||||
};
|
||||
|
||||
let result: Option<Arg<'a>> = MaybeRelativeBlockPos::try_new(x_str, y_str, z_str)
|
||||
MaybeRelativeBlockPos::try_new(x_str, y_str, z_str)
|
||||
.and_then(|pos| pos.try_to_absolute(sender))
|
||||
.map(Arg::BlockPos);
|
||||
|
||||
Box::pin(async move { result })
|
||||
.map(Arg::BlockPos)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,23 +27,15 @@ impl GetClientSideArgParser for DamageTypeArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for DamageTypeArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let name_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let result: Option<Arg<'a>> = name_opt.map_or_else(
|
||||
|| None,
|
||||
|name| {
|
||||
let name = args.pop().map(|arg| arg.value)?;
|
||||
let name = name.strip_prefix("minecraft:").unwrap_or(name);
|
||||
DamageType::from_name(name).map(Arg::DamageType)
|
||||
},
|
||||
);
|
||||
|
||||
Box::pin(async move { result })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,22 +27,16 @@ impl GetClientSideArgParser for EffectTypeArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for EffectTypeArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let status_effect: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
match status_effect {
|
||||
Some(name) => Box::pin(async move {
|
||||
let name = args.pop().map(|arg| arg.value)?;
|
||||
let status_effect =
|
||||
StatusEffect::from_name(name.strip_prefix("minecraft:").unwrap_or(name))?;
|
||||
Some(Arg::Effect(status_effect))
|
||||
}),
|
||||
None => Box::pin(async move { None }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,19 +27,14 @@ impl GetClientSideArgParser for EnchantmentArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for EnchantmentArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let name_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let result: Option<Arg<'a>> = name_opt.map_or_else(
|
||||
|| None,
|
||||
|name| Enchantment::from_name(name).map(Arg::Enchantment),
|
||||
);
|
||||
Box::pin(async move { result })
|
||||
let name = args.pop().map(|arg| arg.value)?;
|
||||
Enchantment::from_name(name).map(Arg::Enchantment)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,12 +37,7 @@ impl ArgumentConsumer for ItemArgumentConsumer {
|
||||
_server: &'a Server,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let item = args.pop().map(|arg| arg.value);
|
||||
// TODO: When supporting data components in this argument, do it for ItemPredicateArgumentConsumer as well (both tags and items)
|
||||
match item {
|
||||
Some(s) => Box::pin(async move { Some(Arg::Item(s)) }),
|
||||
None => Box::pin(async move { None }),
|
||||
}
|
||||
args.pop().map(|arg| Arg::Item(arg.value))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,11 +177,7 @@ impl ArgumentConsumer for ItemPredicateArgumentConsumer {
|
||||
_server: &'a Server,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let item = args.pop().map(|arg| arg.value);
|
||||
match item {
|
||||
Some(s) => Box::pin(async move { Some(Arg::Item(s)) }),
|
||||
None => Box::pin(async move { None }),
|
||||
}
|
||||
args.pop().map(|arg| Arg::Item(arg.value))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,23 +27,14 @@ impl GetClientSideArgParser for ParticleArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for ParticleArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let name_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let result: Option<Arg<'a>> = name_opt.map_or_else(
|
||||
|| None,
|
||||
|name| {
|
||||
Particle::from_name(name.strip_prefix("minecraft:").unwrap_or(name))
|
||||
.map(Arg::Particle)
|
||||
},
|
||||
);
|
||||
|
||||
Box::pin(async move { result })
|
||||
let name = args.pop().map(|arg| arg.value)?;
|
||||
Particle::from_name(name.strip_prefix("minecraft:").unwrap_or(name)).map(Arg::Particle)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ impl ArgumentConsumer for ResourceLocationArgumentConsumer {
|
||||
) -> ConsumeResult<'a> {
|
||||
let identifier = args.pop().and_then(|arg| Identifier::parse(arg.value).ok());
|
||||
|
||||
Box::pin(async move { identifier.map(Arg::ResourceLocation) })
|
||||
identifier.map(Arg::ResourceLocation)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,26 +45,19 @@ impl GetClientSideArgParser for RotationArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for RotationArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let yaw_str_opt = args.pop().map(|arg| arg.value);
|
||||
let pitch_str_opt = args.pop().map(|arg| arg.value);
|
||||
let yaw_str = args.pop()?.value;
|
||||
let pitch_str = args.pop()?.value;
|
||||
|
||||
let (Some(yaw_str), Some(pitch_str)) = (yaw_str_opt, pitch_str_opt) else {
|
||||
return Box::pin(async move { None });
|
||||
};
|
||||
let (yaw, yaw_rel) = parse_rotation_component(yaw_str)?;
|
||||
let (pitch, pitch_rel) = parse_rotation_component(pitch_str)?;
|
||||
|
||||
let result: Option<Arg<'a>> =
|
||||
parse_rotation_component(yaw_str).and_then(|(yaw, yaw_rel)| {
|
||||
parse_rotation_component(pitch_str)
|
||||
.map(|(pitch, pitch_rel)| Arg::Rotation(yaw, yaw_rel, pitch, pitch_rel))
|
||||
});
|
||||
|
||||
Box::pin(async move { result })
|
||||
Some(Arg::Rotation(yaw, yaw_rel, pitch, pitch_rel))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,15 +29,13 @@ impl GetClientSideArgParser for SimpleArgConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for SimpleArgConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
Box::pin(async move { s_opt.map(Arg::Simple) })
|
||||
args.pop().map(|arg| Arg::Simple(arg.value))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,18 +27,13 @@ impl ArgumentConsumer for SlotArgumentConsumer {
|
||||
_server: &'a Server,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let slot = args.pop().map(|arg| arg.value);
|
||||
match slot {
|
||||
Some(s) => Box::pin(async move {
|
||||
let s = args.pop()?.value;
|
||||
if let Some(range) = get_slot_range(s)
|
||||
&& range.len() == 1
|
||||
{
|
||||
return Some(Arg::Slot(range[0], s.to_string()));
|
||||
}
|
||||
None
|
||||
}),
|
||||
None => Box::pin(async move { None }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,16 +73,11 @@ impl ArgumentConsumer for SlotsArgumentConsumer {
|
||||
_server: &'a Server,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let slots = args.pop().map(|arg| arg.value);
|
||||
match slots {
|
||||
Some(s) => Box::pin(async move {
|
||||
let s = args.pop()?.value;
|
||||
if let Some(range) = get_slot_range(s) {
|
||||
return Some(Arg::Slots(range, s.to_string()));
|
||||
}
|
||||
None
|
||||
}),
|
||||
None => Box::pin(async move { None }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,15 +28,13 @@ impl GetClientSideArgParser for SoundArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for SoundArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
Box::pin(async move { s_opt.map(Arg::Block) })
|
||||
args.pop().map(|arg| Arg::Block(arg.value))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,15 +25,15 @@ impl GetClientSideArgParser for SoundCategoryArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for SoundCategoryArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let result: Option<Arg<'a>> = s_opt.and_then(|s| {
|
||||
s_opt.and_then(|s| {
|
||||
let category = match s.to_lowercase().as_str() {
|
||||
"master" => Some(SoundCategory::Master),
|
||||
"music" => Some(SoundCategory::Music),
|
||||
@@ -50,18 +50,10 @@ impl ArgumentConsumer for SoundCategoryArgumentConsumer {
|
||||
};
|
||||
|
||||
category.map(Arg::SoundCategory)
|
||||
});
|
||||
|
||||
Box::pin(async move { result })
|
||||
})
|
||||
}
|
||||
|
||||
fn suggest<'a>(
|
||||
&'a self,
|
||||
_sender: &CommandSender,
|
||||
_server: &'a Server,
|
||||
_input: &'a str,
|
||||
) -> SuggestResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn suggest(&self, _sender: &CommandSender, _server: &Server, _input: &str) -> SuggestResult {
|
||||
let categories = [
|
||||
"master", "music", "record", "weather", "block", "hostile", "neutral", "player",
|
||||
"ambient", "voice",
|
||||
@@ -71,7 +63,6 @@ impl ArgumentConsumer for SoundCategoryArgumentConsumer {
|
||||
.map(|cat| CommandSuggestion::new((*cat).to_string(), None))
|
||||
.collect();
|
||||
Ok(Some(suggestions))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,15 +28,13 @@ impl GetClientSideArgParser for SummonableEntitiesArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for SummonableEntitiesArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
Box::pin(async move { s_opt.map(Arg::Block) })
|
||||
args.pop().map(|arg| Arg::Block(arg.value))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,17 +50,15 @@ impl GetClientSideArgParser for TeamColorArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for TeamColorArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let result = s_opt.and_then(|s| NamedColor::try_from(s).ok().map(Arg::TeamColor));
|
||||
|
||||
Box::pin(async move { result })
|
||||
s_opt.and_then(|s| NamedColor::try_from(s).ok().map(Arg::TeamColor))
|
||||
}
|
||||
|
||||
fn consume_with_syntax<'a>(
|
||||
@@ -70,32 +68,25 @@ impl ArgumentConsumer for TeamColorArgumentConsumer {
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResultWithSyntax<'a> {
|
||||
let Some(raw_arg) = args.pop() else {
|
||||
return Box::pin(async { Ok(None) });
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let result = NamedColor::try_from(raw_arg.value)
|
||||
NamedColor::try_from(raw_arg.value)
|
||||
.map(|color| Some(Arg::TeamColor(color)))
|
||||
.map_err(|()| {
|
||||
INVALID_COLOR_ERROR_TYPE.create_without_context_args_slice(&[TextComponent::text(
|
||||
raw_arg.value.to_string(),
|
||||
)])
|
||||
});
|
||||
|
||||
Box::pin(async move { result })
|
||||
})
|
||||
}
|
||||
|
||||
fn suggest<'a>(
|
||||
&'a self,
|
||||
_sender: &CommandSender,
|
||||
_server: &'a Server,
|
||||
input: &'a str,
|
||||
) -> SuggestResult<'a> {
|
||||
fn suggest(&self, _sender: &CommandSender, _server: &Server, input: &str) -> SuggestResult {
|
||||
let suggestions: Vec<CommandSuggestion> = TEAM_COLORS
|
||||
.iter()
|
||||
.filter(|color| color.starts_with(input))
|
||||
.map(|color| CommandSuggestion::new((*color).to_string(), None))
|
||||
.collect();
|
||||
Box::pin(async move { Ok(Some(suggestions)) })
|
||||
Ok(Some(suggestions))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,22 +20,18 @@ impl GetClientSideArgParser for TextComponentArgConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for TextComponentArgConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let Some(s) = s_opt else {
|
||||
return Box::pin(async move { None });
|
||||
};
|
||||
let s = args.pop().map(|arg| arg.value)?;
|
||||
|
||||
let text_component_opt = parse_text_component(s);
|
||||
|
||||
// TODO: Allow identifiers (starting with alphabetic or _, then alphanumeric+-_.) as display names
|
||||
let final_arg: Option<Arg<'a>> = text_component_opt.map_or_else(
|
||||
text_component_opt.map_or_else(
|
||||
|| {
|
||||
(s.starts_with('"') && s.ends_with('"')).then(|| {
|
||||
let s_owned = s.replace('"', "");
|
||||
@@ -43,9 +39,7 @@ impl ArgumentConsumer for TextComponentArgConsumer {
|
||||
})
|
||||
},
|
||||
|text_component| Some(Arg::TextComponent(text_component)),
|
||||
);
|
||||
|
||||
Box::pin(async move { final_arg })
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,21 +65,19 @@ impl GetClientSideArgParser for TimeArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for TimeArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let s_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let result: Option<Arg<'a>> = s_opt.and_then(|s| {
|
||||
s_opt.and_then(|s| {
|
||||
let mut reader = StringReader::new(s);
|
||||
let parser = TimeArgumentType::new(self.min);
|
||||
parser.parse(&mut reader).ok().map(Arg::Time)
|
||||
});
|
||||
|
||||
Box::pin(async move { result })
|
||||
})
|
||||
}
|
||||
|
||||
fn consume_with_syntax<'a>(
|
||||
@@ -89,17 +87,15 @@ impl ArgumentConsumer for TimeArgumentConsumer {
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResultWithSyntax<'a> {
|
||||
let Some(raw_arg) = args.pop() else {
|
||||
return Box::pin(async { Ok(None) });
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let mut reader = StringReader::new(raw_arg.value);
|
||||
let parser = TimeArgumentType::new(self.min);
|
||||
let result = parser
|
||||
parser
|
||||
.parse(&mut reader)
|
||||
.map(|ticks| Some(Arg::Time(ticks)))
|
||||
.map_err(|error| map_local_syntax_error(error, raw_arg));
|
||||
|
||||
Box::pin(async move { result })
|
||||
.map_err(|error| map_local_syntax_error(error, raw_arg))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,12 +9,9 @@ use crate::command::{
|
||||
errors::command_syntax_error::CommandSyntaxError, string_reader::StringReader,
|
||||
};
|
||||
use std::any::Any;
|
||||
use std::pin::Pin;
|
||||
|
||||
pub type JavaClientArgumentType = pumpkin_protocol::java::client::play::ArgumentType;
|
||||
pub type ParseWithSourceAnyResult<'a> = Pin<
|
||||
Box<dyn Future<Output = Result<Box<dyn Any + Send + Sync>, CommandSyntaxError>> + Send + 'a>,
|
||||
>;
|
||||
pub type ParseWithSourceAnyResult = Result<Box<dyn Any + Send + Sync>, CommandSyntaxError>;
|
||||
|
||||
/// Represents an argument type that parses a particular type `Item`.
|
||||
pub trait ArgumentType: Send + Sync {
|
||||
@@ -32,27 +29,27 @@ pub trait ArgumentType: Send + Sync {
|
||||
///
|
||||
/// Errors should be propagated using the `?` operator, which will
|
||||
/// replicate Brigadier's behavior of exceptions.
|
||||
fn parse_with_source<'a>(
|
||||
&'a self,
|
||||
reader: &'a mut StringReader,
|
||||
_source: &'a CommandSource,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Self::Item, CommandSyntaxError>> + Send + 'a>> {
|
||||
Box::pin(async move { self.parse(reader) })
|
||||
fn parse_with_source(
|
||||
&self,
|
||||
reader: &mut StringReader,
|
||||
_source: &CommandSource,
|
||||
) -> Result<Self::Item, CommandSyntaxError> {
|
||||
self.parse(reader)
|
||||
}
|
||||
|
||||
/// Provides a list of suggestions from this argument type.
|
||||
#[must_use]
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
_builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move { Suggestions::empty() })
|
||||
) -> Suggestions {
|
||||
Suggestions::empty()
|
||||
}
|
||||
|
||||
/// Returns the Java client-side parser used for this argument type.
|
||||
#[must_use]
|
||||
fn client_side_parser(&'_ self) -> JavaClientArgumentType;
|
||||
fn client_side_parser(&self) -> JavaClientArgumentType;
|
||||
|
||||
/// Overrides the suggestion providers provided from this argument if a [`Some`] containing them
|
||||
/// is returned.
|
||||
@@ -94,23 +91,23 @@ pub trait AnyArgumentType: Sealed + Send + Sync {
|
||||
///
|
||||
/// Errors should be propagated using the `?` operator, which will
|
||||
/// replicate Brigadier's behavior of exceptions.
|
||||
fn parse_with_source<'a>(
|
||||
&'a self,
|
||||
reader: &'a mut StringReader,
|
||||
source: &'a CommandSource,
|
||||
) -> ParseWithSourceAnyResult<'a>;
|
||||
fn parse_with_source(
|
||||
&self,
|
||||
reader: &mut StringReader,
|
||||
source: &CommandSource,
|
||||
) -> ParseWithSourceAnyResult;
|
||||
|
||||
/// Provides a list of suggestions from this argument type.
|
||||
#[must_use]
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>>;
|
||||
) -> Suggestions;
|
||||
|
||||
/// Returns the Java client-side parser used for this argument type.
|
||||
#[must_use]
|
||||
fn client_side_parser(&'_ self) -> JavaClientArgumentType;
|
||||
fn client_side_parser(&self) -> JavaClientArgumentType;
|
||||
|
||||
/// Overrides the suggestion providers provided from this argument if a [`Some`] containing them
|
||||
/// is returned.
|
||||
@@ -145,31 +142,29 @@ impl<U: ArgumentType<Item = T> + 'static, T: Send + Sync + 'static> AnyArgumentT
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_with_source<'a>(
|
||||
&'a self,
|
||||
reader: &'a mut StringReader,
|
||||
source: &'a CommandSource,
|
||||
) -> ParseWithSourceAnyResult<'a> {
|
||||
Box::pin(async move {
|
||||
match self.parse_with_source(reader, source).await {
|
||||
fn parse_with_source(
|
||||
&self,
|
||||
reader: &mut StringReader,
|
||||
source: &CommandSource,
|
||||
) -> ParseWithSourceAnyResult {
|
||||
match self.parse_with_source(reader, source) {
|
||||
Ok(value) => {
|
||||
let value: Box<dyn Any + Send + Sync> = Box::new(value);
|
||||
Ok(value)
|
||||
}
|
||||
Err(error) => Err(error),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
) -> Suggestions {
|
||||
self.list_suggestions(context, builder)
|
||||
}
|
||||
|
||||
fn client_side_parser(&'_ self) -> JavaClientArgumentType {
|
||||
fn client_side_parser(&self) -> JavaClientArgumentType {
|
||||
self.client_side_parser()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::pin::Pin;
|
||||
|
||||
use crate::command::{
|
||||
argument_types::FromStringReader,
|
||||
argument_types::argument_type::{ArgumentType, JavaClientArgumentType},
|
||||
@@ -46,16 +44,14 @@ impl ArgumentType for AttributeArgumentType {
|
||||
}
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move {
|
||||
) -> Suggestions {
|
||||
builder
|
||||
.filter_and_suggest_iter(Attributes::ALL.iter().map(|a| a.name))
|
||||
.build()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::pin::Pin;
|
||||
|
||||
use crate::command::{
|
||||
argument_types::argument_type::{ArgumentType, JavaClientArgumentType},
|
||||
context::command_context::CommandContext,
|
||||
@@ -46,12 +44,12 @@ impl ArgumentType for BlockArgumentType {
|
||||
JavaClientArgumentType::BlockState
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move { builder.build() })
|
||||
) -> Suggestions {
|
||||
builder.build()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::pin::Pin;
|
||||
|
||||
use crate::command::argument_types::argument_type::{ArgumentType, JavaClientArgumentType};
|
||||
use crate::command::argument_types::coordinates::Coordinates;
|
||||
use crate::command::context::command_context::CommandContext;
|
||||
@@ -56,12 +54,11 @@ impl ArgumentType for BlockPosArgumentType {
|
||||
examples!("1 3 5", "-3 ~24 ~-1", "80 80 80", "^ ^9 ^56")
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move {
|
||||
) -> Suggestions {
|
||||
let remainder = builder.remaining();
|
||||
|
||||
let suggested_coordinates = if remainder.bytes().next() == Some(b'^') {
|
||||
@@ -73,7 +70,6 @@ impl ArgumentType for BlockPosArgumentType {
|
||||
builder.suggest_3d_coordinates(suggested_coordinates, |value| {
|
||||
self.parse(&mut StringReader::new(value)).is_ok()
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::pin::Pin;
|
||||
|
||||
use pumpkin_data::translation;
|
||||
use pumpkin_util::math::position::{BlockPos, ColumnPos};
|
||||
use pumpkin_util::math::vector2::Vector2;
|
||||
@@ -48,12 +46,11 @@ impl ArgumentType for ColumnPosArgumentType {
|
||||
}
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move {
|
||||
) -> Suggestions {
|
||||
let remainder = builder.remaining();
|
||||
|
||||
let suggested_coordinates = if remainder.bytes().next() == Some(b'^') {
|
||||
@@ -65,7 +62,6 @@ impl ArgumentType for ColumnPosArgumentType {
|
||||
builder.suggest_2d_coordinates(suggested_coordinates, |value| {
|
||||
self.parse(&mut StringReader::new(value)).is_ok()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn client_side_parser(&'_ self) -> JavaClientArgumentType {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::pin::Pin;
|
||||
|
||||
use crate::command::argument_types::argument_type::{ArgumentType, JavaClientArgumentType};
|
||||
use crate::command::argument_types::coordinates::Coordinates;
|
||||
use crate::command::context::command_context::CommandContext;
|
||||
@@ -60,12 +58,11 @@ impl ArgumentType for Vec3ArgumentType {
|
||||
examples!("1 1 1", "3 ~34 ~-2", "40 50 60", "^ ^4 ^3")
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move {
|
||||
) -> Suggestions {
|
||||
let remainder = builder.remaining();
|
||||
|
||||
let suggestioned_coordinates = if remainder.bytes().next() == Some(b'^') {
|
||||
@@ -77,7 +74,6 @@ impl ArgumentType for Vec3ArgumentType {
|
||||
builder.suggest_3d_coordinates(suggestioned_coordinates, |value| {
|
||||
self.parse(&mut StringReader::new(value)).is_ok()
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ use crate::command::suggestion::suggestions::{Suggestions, SuggestionsBuilder};
|
||||
use crate::entity::EntityBase;
|
||||
use crate::entity::player::Player;
|
||||
use pumpkin_data::translation;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// A [`CommandErrorType`] to tell that no entities could be found.
|
||||
@@ -87,17 +86,12 @@ impl ArgumentType for EntityArgumentType {
|
||||
self.parse_with_allow_selectors(reader, true)
|
||||
}
|
||||
|
||||
fn parse_with_source<'a>(
|
||||
&'a self,
|
||||
reader: &'a mut StringReader,
|
||||
source: &'a CommandSource,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Self::Item, CommandSyntaxError>> + Send + 'a>> {
|
||||
Box::pin(async move {
|
||||
self.parse_with_allow_selectors(
|
||||
reader,
|
||||
source.has_permission(ENTITY_SELECTOR_PERMISSION).await,
|
||||
)
|
||||
})
|
||||
fn parse_with_source(
|
||||
&self,
|
||||
reader: &mut StringReader,
|
||||
source: &CommandSource,
|
||||
) -> Result<Self::Item, CommandSyntaxError> {
|
||||
self.parse_with_allow_selectors(reader, source.has_permission(ENTITY_SELECTOR_PERMISSION))
|
||||
}
|
||||
|
||||
fn client_side_parser(&'_ self) -> JavaClientArgumentType {
|
||||
@@ -118,12 +112,12 @@ impl ArgumentType for EntityArgumentType {
|
||||
)
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
EntitySelectorParserSuggestions::list_suggestions(context, builder)
|
||||
) -> Suggestions {
|
||||
EntitySelectorParserSuggestions::list_suggestions(context, &builder)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,22 +150,21 @@ impl EntityArgumentType {
|
||||
}
|
||||
|
||||
/// Tries to get a single entity from a parsed argument of the provided [`CommandContext`].
|
||||
pub async fn get_entity(
|
||||
pub fn get_entity(
|
||||
context: &CommandContext<'_>,
|
||||
name: &str,
|
||||
) -> Result<Arc<dyn EntityBase>, CommandSyntaxError> {
|
||||
context
|
||||
.get_argument::<EntitySelector>(name)?
|
||||
.find_single_entity(context.source.as_ref())
|
||||
.await
|
||||
}
|
||||
|
||||
/// Tries to get at least 1 entity from a parsed argument of the provided [`CommandContext`].
|
||||
pub async fn get_entities(
|
||||
pub fn get_entities(
|
||||
context: &CommandContext<'_>,
|
||||
name: &str,
|
||||
) -> Result<Vec<Arc<dyn EntityBase>>, CommandSyntaxError> {
|
||||
let entities = Self::get_optional_entities(context, name).await?;
|
||||
let entities = Self::get_optional_entities(context, name)?;
|
||||
if entities.is_empty() {
|
||||
Err(NO_ENTITIES_ERROR_TYPE.create_without_context())
|
||||
} else {
|
||||
@@ -180,33 +173,31 @@ impl EntityArgumentType {
|
||||
}
|
||||
|
||||
/// Tries to get any number of entities from a parsed argument of the provided [`CommandContext`].
|
||||
pub async fn get_optional_entities(
|
||||
pub fn get_optional_entities(
|
||||
context: &CommandContext<'_>,
|
||||
name: &str,
|
||||
) -> Result<Vec<Arc<dyn EntityBase>>, CommandSyntaxError> {
|
||||
context
|
||||
.get_argument::<EntitySelector>(name)?
|
||||
.find_entities(context.source.as_ref())
|
||||
.await
|
||||
}
|
||||
|
||||
/// Tries to get a single player from a parsed argument of the provided [`CommandContext`].
|
||||
pub async fn get_player(
|
||||
pub fn get_player(
|
||||
context: &CommandContext<'_>,
|
||||
name: &str,
|
||||
) -> Result<Arc<Player>, CommandSyntaxError> {
|
||||
context
|
||||
.get_argument::<EntitySelector>(name)?
|
||||
.find_single_player(context.source.as_ref())
|
||||
.await
|
||||
}
|
||||
|
||||
/// Tries to get at least 1 player from a parsed argument of the provided [`CommandContext`].
|
||||
pub async fn get_players(
|
||||
pub fn get_players(
|
||||
context: &CommandContext<'_>,
|
||||
name: &str,
|
||||
) -> Result<Vec<Arc<Player>>, CommandSyntaxError> {
|
||||
let players = Self::get_optional_players(context, name).await?;
|
||||
let players = Self::get_optional_players(context, name)?;
|
||||
if players.is_empty() {
|
||||
Err(NO_PLAYERS_ERROR_TYPE.create_without_context())
|
||||
} else {
|
||||
@@ -215,13 +206,12 @@ impl EntityArgumentType {
|
||||
}
|
||||
|
||||
/// Tries to get any number of players from a parsed argument of the provided [`CommandContext`].
|
||||
pub async fn get_optional_players(
|
||||
pub fn get_optional_players(
|
||||
context: &CommandContext<'_>,
|
||||
name: &str,
|
||||
) -> Result<Vec<Arc<Player>>, CommandSyntaxError> {
|
||||
context
|
||||
.get_argument::<EntitySelector>(name)?
|
||||
.find_players(context.source.as_ref())
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ use crate::entity::Entity;
|
||||
use pumpkin_data::translation;
|
||||
use pumpkin_util::math::vector3::Vector3;
|
||||
use pumpkin_util::text::TextComponent;
|
||||
use std::pin::Pin;
|
||||
|
||||
pub const INVALID_ERROR_TYPE: CommandErrorType<1> = CommandErrorType::new(
|
||||
translation::java::ARGUMENT_ANCHOR_INVALID,
|
||||
@@ -37,12 +36,12 @@ impl ArgumentType for EntityAnchorArgumentType {
|
||||
JavaClientArgumentType::EntityAnchor
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move { builder.filter_and_suggest(&["eyes", "feet"]).build() })
|
||||
) -> Suggestions {
|
||||
builder.filter_and_suggest(&["eyes", "feet"]).build()
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<String> {
|
||||
|
||||
@@ -62,11 +62,8 @@ pub struct EntitySelector {
|
||||
impl EntitySelector {
|
||||
/// Returns an [`Err`] if a [`CommandSource`] does not have permission to use
|
||||
/// this entity selector.
|
||||
pub async fn check_permissions(
|
||||
&self,
|
||||
source: &CommandSource,
|
||||
) -> Result<(), CommandSyntaxError> {
|
||||
if self.uses_selector_variable && !source.has_permission(ENTITY_SELECTOR_PERMISSION).await {
|
||||
pub fn check_permissions(&self, source: &CommandSource) -> Result<(), CommandSyntaxError> {
|
||||
if self.uses_selector_variable && !source.has_permission(ENTITY_SELECTOR_PERMISSION) {
|
||||
Err(SELECTORS_NOT_ALLOWED_ERROR_TYPE.create_without_context())
|
||||
} else {
|
||||
Ok(())
|
||||
@@ -82,11 +79,11 @@ impl EntitySelector {
|
||||
}
|
||||
|
||||
/// Tries to find a single entity represented by this selector.
|
||||
pub async fn find_single_entity(
|
||||
pub fn find_single_entity(
|
||||
&self,
|
||||
source: &CommandSource,
|
||||
) -> Result<Arc<dyn EntityBase>, CommandSyntaxError> {
|
||||
let list = self.find_entities(source).await?;
|
||||
let list = self.find_entities(source)?;
|
||||
match list.as_slice() {
|
||||
[] => Err(entity::NO_ENTITIES_ERROR_TYPE.create_without_context()),
|
||||
[entity] => Ok(entity.clone()),
|
||||
@@ -95,14 +92,13 @@ impl EntitySelector {
|
||||
}
|
||||
|
||||
/// Tries to find any entities represented by this selector. If none are found, an empty `Vec` will still be returned.
|
||||
pub async fn find_entities(
|
||||
pub fn find_entities(
|
||||
&self,
|
||||
source: &CommandSource,
|
||||
) -> Result<Vec<Arc<dyn EntityBase>>, CommandSyntaxError> {
|
||||
self.check_permissions(source).await?;
|
||||
self.check_permissions(source)?;
|
||||
if !self.includes_entities {
|
||||
self.find_players(source)
|
||||
.await
|
||||
.map(|v| v.into_iter().map(|p| p as Arc<dyn EntityBase>).collect())
|
||||
} else if let Some(name) = self.player_name.as_ref() {
|
||||
// Try to get the player by name.
|
||||
@@ -160,11 +156,11 @@ impl EntitySelector {
|
||||
}
|
||||
|
||||
/// Tries to find a single player represented by this selector.
|
||||
pub async fn find_single_player(
|
||||
pub fn find_single_player(
|
||||
&self,
|
||||
source: &CommandSource,
|
||||
) -> Result<Arc<Player>, CommandSyntaxError> {
|
||||
let mut list = self.find_players(source).await?;
|
||||
let mut list = self.find_players(source)?;
|
||||
if list.len() == 1 {
|
||||
list.pop()
|
||||
.ok_or_else(|| entity::NO_PLAYERS_ERROR_TYPE.create_without_context())
|
||||
@@ -174,11 +170,11 @@ impl EntitySelector {
|
||||
}
|
||||
|
||||
/// Tries to find any players represented by this selector.
|
||||
pub async fn find_players(
|
||||
pub fn find_players(
|
||||
&self,
|
||||
source: &CommandSource,
|
||||
) -> Result<Vec<Arc<Player>>, CommandSyntaxError> {
|
||||
self.check_permissions(source).await?;
|
||||
self.check_permissions(source)?;
|
||||
if let Some(name) = self.player_name.as_ref() {
|
||||
// Try to get the player by name.
|
||||
let player = source
|
||||
@@ -529,7 +525,10 @@ impl EntitySelectorPredicate {
|
||||
Self::Team(expected_team, invert) => {
|
||||
let actual_name = entity_actual_name(entity);
|
||||
let world = entity.get_entity().world.load();
|
||||
let scoreboard = world.scoreboard.blocking_lock();
|
||||
let scoreboard = world
|
||||
.scoreboard
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
let has_team = scoreboard.get_teams().iter().any(|(name, team)| {
|
||||
name == expected_team && team.players.contains(&actual_name)
|
||||
});
|
||||
@@ -538,7 +537,10 @@ impl EntitySelectorPredicate {
|
||||
Self::Scores(scores_map) => {
|
||||
let actual_name = entity_actual_name(entity);
|
||||
let world = entity.get_entity().world.load();
|
||||
let scoreboard = world.scoreboard.blocking_lock();
|
||||
let scoreboard = world
|
||||
.scoreboard
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
let entity_scores = scoreboard.get_scores().get(&actual_name);
|
||||
for (objective, bounds) in scores_map {
|
||||
let score_val = entity_scores
|
||||
|
||||
@@ -20,7 +20,6 @@ use pumpkin_util::math::bounds::{DoubleBounds, FloatDegreeBounds, IntBounds};
|
||||
use pumpkin_util::math::vector2::Vector2;
|
||||
use pumpkin_util::math::vector3::Vector3;
|
||||
use pumpkin_util::text::TextComponent;
|
||||
use std::pin::Pin;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub const INVALID_NAME_OR_UUID_ERROR_TYPE: CommandErrorType<0> = CommandErrorType::new(
|
||||
@@ -593,32 +592,26 @@ impl EntitySelectorParserSuggestions {
|
||||
builder
|
||||
}
|
||||
|
||||
pub fn list_suggestions<'a>(
|
||||
context: &'a CommandContext<'_>,
|
||||
suggestions_builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move {
|
||||
pub fn list_suggestions(
|
||||
context: &CommandContext<'_>,
|
||||
suggestions_builder: &SuggestionsBuilder,
|
||||
) -> Suggestions {
|
||||
let mut reader = StringReader::new(suggestions_builder.input.clone());
|
||||
reader.set_cursor(suggestions_builder.start);
|
||||
let mut parser = EntitySelectorParser::new(
|
||||
&mut reader,
|
||||
context
|
||||
.source
|
||||
.has_permission(ENTITY_SELECTOR_PERMISSION)
|
||||
.await,
|
||||
context.source.has_permission(ENTITY_SELECTOR_PERMISSION),
|
||||
);
|
||||
|
||||
let _ = parser.parse();
|
||||
|
||||
parser.fill_suggestions(&suggestions_builder, |mut suggestions| {
|
||||
parser.fill_suggestions(suggestions_builder, |mut suggestions| {
|
||||
for player in context.server().get_all_players() {
|
||||
suggestions =
|
||||
suggestions.filter_and_suggest_one(player.gameprofile.name.clone());
|
||||
suggestions = suggestions.filter_and_suggest_one(player.gameprofile.name.clone());
|
||||
}
|
||||
// ONLY FOR EntityArgumentType: This is server-side, so no other entity will show up.
|
||||
suggestions
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ use crate::net::{GameProfile, offline_uuid};
|
||||
use crate::server::Server;
|
||||
use arc_swap::ArcSwap;
|
||||
use pumpkin_data::translation;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -49,24 +48,26 @@ impl GameProfileResult {
|
||||
/// - `server.data.whitelist_config`
|
||||
///
|
||||
/// Instead, call this method *before* using `write()`/`read()` on a lock.
|
||||
pub async fn resolve(
|
||||
&self,
|
||||
source: &CommandSource,
|
||||
) -> Result<Vec<GameProfile>, CommandSyntaxError> {
|
||||
pub fn resolve(&self, source: &CommandSource) -> Result<Vec<GameProfile>, CommandSyntaxError> {
|
||||
let players = match self {
|
||||
Self::Selector(selector) => selector.find_players(source).await,
|
||||
Self::Selector(selector) => selector.find_players(source),
|
||||
Self::Name(name) => {
|
||||
let server = source.server();
|
||||
if let Some(player) = server.get_player_by_name(name) {
|
||||
return Ok(vec![player.gameprofile.clone()]);
|
||||
}
|
||||
|
||||
let cached_entry = server.data.user_cache.write().await.get_by_name(name);
|
||||
let cached_entry = server
|
||||
.data
|
||||
.user_cache
|
||||
.write()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.get_by_name(name);
|
||||
if let Some(entry) = cached_entry {
|
||||
return Ok(vec![Self::profile_from_uuid_name(entry.uuid, entry.name)]);
|
||||
}
|
||||
|
||||
if let Some(profile) = Self::resolve_known_profile_by_name(server, name).await {
|
||||
if let Some(profile) = Self::resolve_known_profile_by_name(server, name) {
|
||||
return Ok(vec![profile]);
|
||||
}
|
||||
|
||||
@@ -80,7 +81,7 @@ impl GameProfileResult {
|
||||
.data
|
||||
.user_cache
|
||||
.write()
|
||||
.await
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.upsert(uuid, resolved_name.clone());
|
||||
Ok(vec![Self::profile_from_uuid_name(uuid, resolved_name)])
|
||||
}
|
||||
@@ -92,7 +93,7 @@ impl GameProfileResult {
|
||||
.data
|
||||
.user_cache
|
||||
.write()
|
||||
.await
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.upsert(profile.id, profile.name.clone());
|
||||
return Ok(vec![profile]);
|
||||
}
|
||||
@@ -106,12 +107,17 @@ impl GameProfileResult {
|
||||
return Ok(vec![player.gameprofile.clone()]);
|
||||
}
|
||||
|
||||
let cached_entry = server.data.user_cache.write().await.get_by_uuid(*uuid);
|
||||
let cached_entry = server
|
||||
.data
|
||||
.user_cache
|
||||
.write()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.get_by_uuid(*uuid);
|
||||
if let Some(entry) = cached_entry {
|
||||
return Ok(vec![Self::profile_from_uuid_name(entry.uuid, entry.name)]);
|
||||
}
|
||||
|
||||
if let Some(profile) = Self::resolve_known_profile_by_uuid(server, *uuid).await {
|
||||
if let Some(profile) = Self::resolve_known_profile_by_uuid(server, *uuid) {
|
||||
return Ok(vec![profile]);
|
||||
}
|
||||
|
||||
@@ -122,13 +128,21 @@ impl GameProfileResult {
|
||||
Ok(players.iter().map(|p| &p.gameprofile).cloned().collect())
|
||||
}
|
||||
|
||||
async fn resolve_known_profile_by_name(server: &Server, name: &str) -> Option<GameProfile> {
|
||||
let ops = server.data.operator_config.read().await;
|
||||
fn resolve_known_profile_by_name(server: &Server, name: &str) -> Option<GameProfile> {
|
||||
let ops = server
|
||||
.data
|
||||
.operator_config
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
if let Some(op) = ops.ops.iter().find(|op| op.name.eq_ignore_ascii_case(name)) {
|
||||
return Some(Self::profile_from_uuid_name(op.uuid, op.name.clone()));
|
||||
}
|
||||
|
||||
let banned_players = server.data.banned_player_list.read().await;
|
||||
let banned_players = server
|
||||
.data
|
||||
.banned_player_list
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
if let Some(entry) = banned_players
|
||||
.banned_players
|
||||
.iter()
|
||||
@@ -137,7 +151,11 @@ impl GameProfileResult {
|
||||
return Some(Self::profile_from_uuid_name(entry.uuid, entry.name.clone()));
|
||||
}
|
||||
|
||||
let whitelist = server.data.whitelist_config.read().await;
|
||||
let whitelist = server
|
||||
.data
|
||||
.whitelist_config
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
if let Some(entry) = whitelist
|
||||
.whitelist
|
||||
.iter()
|
||||
@@ -149,13 +167,21 @@ impl GameProfileResult {
|
||||
None
|
||||
}
|
||||
|
||||
async fn resolve_known_profile_by_uuid(server: &Server, uuid: Uuid) -> Option<GameProfile> {
|
||||
let ops = server.data.operator_config.read().await;
|
||||
fn resolve_known_profile_by_uuid(server: &Server, uuid: Uuid) -> Option<GameProfile> {
|
||||
let ops = server
|
||||
.data
|
||||
.operator_config
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
if let Some(op) = ops.ops.iter().find(|op| op.uuid == uuid) {
|
||||
return Some(Self::profile_from_uuid_name(op.uuid, op.name.clone()));
|
||||
}
|
||||
|
||||
let banned_players = server.data.banned_player_list.read().await;
|
||||
let banned_players = server
|
||||
.data
|
||||
.banned_player_list
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
if let Some(entry) = banned_players
|
||||
.banned_players
|
||||
.iter()
|
||||
@@ -164,7 +190,11 @@ impl GameProfileResult {
|
||||
return Some(Self::profile_from_uuid_name(entry.uuid, entry.name.clone()));
|
||||
}
|
||||
|
||||
let whitelist = server.data.whitelist_config.read().await;
|
||||
let whitelist = server
|
||||
.data
|
||||
.whitelist_config
|
||||
.read()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
if let Some(entry) = whitelist.whitelist.iter().find(|entry| entry.uuid == uuid) {
|
||||
return Some(Self::profile_from_uuid_name(entry.uuid, entry.name.clone()));
|
||||
}
|
||||
@@ -202,12 +232,12 @@ impl ArgumentType for GameProfileArgumentType {
|
||||
JavaClientArgumentType::GameProfile
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
EntitySelectorParserSuggestions::list_suggestions(context, builder)
|
||||
) -> Suggestions {
|
||||
EntitySelectorParserSuggestions::list_suggestions(context, &builder)
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<String> {
|
||||
@@ -255,13 +285,12 @@ impl GameProfileArgumentType {
|
||||
/// - `server.data.whitelist_config`
|
||||
///
|
||||
/// Instead, call this function *before* using `write()`/`read()` on a lock.
|
||||
pub async fn get(
|
||||
pub fn get(
|
||||
context: &CommandContext<'_>,
|
||||
name: &str,
|
||||
) -> Result<Vec<GameProfile>, CommandSyntaxError> {
|
||||
context
|
||||
.get_argument::<GameProfileResult>(name)?
|
||||
.resolve(context.source.as_ref())
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ use crate::command::suggestion::suggestions::{Suggestions, SuggestionsBuilder};
|
||||
use pumpkin_data::translation;
|
||||
use pumpkin_util::GameMode;
|
||||
use pumpkin_util::text::TextComponent;
|
||||
use std::pin::Pin;
|
||||
use std::str::FromStr;
|
||||
|
||||
pub const INVALID_ERROR_TYPE: CommandErrorType<1> = CommandErrorType::new(
|
||||
@@ -30,17 +29,15 @@ impl ArgumentType for GameModeArgumentType {
|
||||
JavaClientArgumentType::Gamemode
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
mut builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move {
|
||||
) -> Suggestions {
|
||||
for gamemode in GameMode::VALUES {
|
||||
builder = builder.filter_and_suggest_one(gamemode.name());
|
||||
}
|
||||
builder.build()
|
||||
})
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<String> {
|
||||
|
||||
@@ -7,7 +7,6 @@ use crate::command::suggestion::suggestions::{Suggestions, SuggestionsBuilder};
|
||||
use pumpkin_data::translation::java::ARGUMENT_HEXCOLOR_INVALID;
|
||||
use pumpkin_util::text::TextComponent;
|
||||
use pumpkin_util::text::color::RGBColor;
|
||||
use std::pin::Pin;
|
||||
|
||||
pub const INVALID_HEX_ERROR_TYPE: CommandErrorType<1> =
|
||||
CommandErrorType::new(ARGUMENT_HEXCOLOR_INVALID, ARGUMENT_HEXCOLOR_INVALID);
|
||||
@@ -38,12 +37,12 @@ impl ArgumentType for HexColorArgumentType {
|
||||
JavaClientArgumentType::HexColor
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move { builder.filter_and_suggest(&["F00", "FF0000"]).build() })
|
||||
) -> Suggestions {
|
||||
builder.filter_and_suggest(&["F00", "FF0000"]).build()
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<String> {
|
||||
|
||||
@@ -26,12 +26,12 @@ impl ArgumentType for NbtTagArgumentType {
|
||||
JavaClientArgumentType::NbtTag
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> std::pin::Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move { SnbtParser::parse_for_suggestions(builder) })
|
||||
) -> Suggestions {
|
||||
SnbtParser::parse_for_suggestions(builder)
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<String> {
|
||||
|
||||
@@ -5,7 +5,6 @@ use crate::command::{
|
||||
string_reader::StringReader,
|
||||
suggestion::suggestions::{Suggestions, SuggestionsBuilder},
|
||||
};
|
||||
use std::pin::Pin;
|
||||
|
||||
/// Represents an argument type parsing a scoreboard objective name.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
@@ -23,18 +22,20 @@ impl ArgumentType for ObjectiveArgumentType {
|
||||
JavaClientArgumentType::Objective
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
context: &CommandContext,
|
||||
mut builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move {
|
||||
let scoreboard = context.world().scoreboard.lock().await;
|
||||
) -> Suggestions {
|
||||
let scoreboard = context
|
||||
.world()
|
||||
.scoreboard
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
for objective_name in scoreboard.get_objectives().keys() {
|
||||
builder = builder.filter_and_suggest_one(objective_name.as_str());
|
||||
}
|
||||
builder.build()
|
||||
})
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<String> {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::pin::Pin;
|
||||
|
||||
use pumpkin_protocol::java::client::play::SuggestionProviders;
|
||||
use pumpkin_util::identifier::Identifier;
|
||||
|
||||
@@ -19,17 +17,15 @@ impl ArgumentType for PlacedFeatureNameArgumentType {
|
||||
Identifier::from_reader(reader)
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
) -> Suggestions {
|
||||
let names = pumpkin_world::generation::feature::placed_features::all_placed_feature_names();
|
||||
Box::pin(async move {
|
||||
builder
|
||||
.filter_and_suggest_iter(names.iter().copied())
|
||||
.build()
|
||||
})
|
||||
}
|
||||
|
||||
fn client_side_parser(&'_ self) -> JavaClientArgumentType {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::pin::Pin;
|
||||
|
||||
use crate::command::argument_types::FromStringReader;
|
||||
use crate::command::argument_types::argument_type::{ArgumentType, JavaClientArgumentType};
|
||||
use crate::command::context::command_context::CommandContext;
|
||||
@@ -18,17 +16,15 @@ impl ArgumentType for PoolNameArgumentType {
|
||||
Identifier::from_reader(reader)
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
) -> Suggestions {
|
||||
let names = pumpkin_world::generation::structure::template::all_pool_names();
|
||||
Box::pin(async move {
|
||||
builder
|
||||
.filter_and_suggest_iter(names.iter().map(|n| format!("minecraft:{n}")))
|
||||
.build()
|
||||
})
|
||||
}
|
||||
|
||||
fn client_side_parser(&'_ self) -> JavaClientArgumentType {
|
||||
|
||||
@@ -12,7 +12,6 @@ use pumpkin_util::identifier::Identifier;
|
||||
use pumpkin_util::text::TextComponent;
|
||||
use std::any::Any;
|
||||
use std::iter::Iterator;
|
||||
use std::pin::Pin;
|
||||
|
||||
pub static ENTITY_TYPE_REGISTRY: &Identifier = &Identifier::vanilla_static("entity_type");
|
||||
static ERROR_UNKNOWN_RESOURCE: CommandErrorType<2> = CommandErrorType::new(
|
||||
@@ -59,18 +58,16 @@ impl ArgumentType for ResourceArgument {
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
suggestions_builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send>> {
|
||||
) -> Suggestions {
|
||||
if self.0 == ENTITY_TYPE_REGISTRY {
|
||||
Box::pin(async move {
|
||||
let entity_types = EntityType::ALL
|
||||
.iter()
|
||||
.map(|entity_type| format!("minecraft:{}", entity_type.resource_name));
|
||||
suggestions_builder
|
||||
.filter_and_suggest_iter(entity_types)
|
||||
.build()
|
||||
})
|
||||
} else {
|
||||
Box::pin(async move { Suggestions::empty() })
|
||||
Suggestions::empty()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ use pumpkin_data::{Advancement, translation};
|
||||
use pumpkin_util::identifier::Identifier;
|
||||
use pumpkin_util::resource::ResourceKey;
|
||||
use pumpkin_util::text::TextComponent;
|
||||
use std::pin::Pin;
|
||||
use std::string::ToString;
|
||||
|
||||
pub static ADVANCEMENT_REGISTRY: &Identifier = &Identifier::vanilla_static("advancement");
|
||||
@@ -55,23 +54,19 @@ impl ArgumentType for ResourceKeyArgument {
|
||||
&self,
|
||||
context: &CommandContext,
|
||||
suggestions_builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send>> {
|
||||
) -> Suggestions {
|
||||
if self.0 == ADVANCEMENT_REGISTRY {
|
||||
let advancements = context.server().advancement_manager.get_advancements();
|
||||
Box::pin(async move {
|
||||
suggestions_builder
|
||||
.filter_and_suggest_iter(advancements.iter().map(ToString::to_string))
|
||||
.build()
|
||||
})
|
||||
} else if self.0 == BIOME_REGISTRY {
|
||||
Box::pin(async move {
|
||||
let biomes = pumpkin_data::biome::Biome::ALL
|
||||
.iter()
|
||||
.map(|biome| format!("minecraft:{}", biome.registry_id));
|
||||
suggestions_builder.filter_and_suggest_iter(biomes).build()
|
||||
})
|
||||
} else {
|
||||
Box::pin(async move { Suggestions::empty() })
|
||||
Suggestions::empty()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use std::collections::BTreeSet;
|
||||
use std::pin::Pin;
|
||||
|
||||
use pumpkin_data::structures::StructureSet;
|
||||
use pumpkin_data::tag::{self, RegistryKey};
|
||||
@@ -121,12 +120,12 @@ impl ArgumentType for ResourceOrTagKeyArgument {
|
||||
ResourceOrTag::from_string_reader(reader)
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move { suggest_for_registry(&self.0, builder) })
|
||||
) -> Suggestions {
|
||||
suggest_for_registry(&self.0, builder)
|
||||
}
|
||||
|
||||
fn client_side_parser(&'_ self) -> JavaClientArgumentType {
|
||||
@@ -190,12 +189,12 @@ impl ArgumentType for ResourceOrTagArgument {
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move { suggest_for_registry(&self.0, builder) })
|
||||
) -> Suggestions {
|
||||
suggest_for_registry(&self.0, builder)
|
||||
}
|
||||
|
||||
fn client_side_parser(&'_ self) -> JavaClientArgumentType {
|
||||
|
||||
@@ -9,7 +9,6 @@ use pumpkin_data::slot_ranges::{
|
||||
};
|
||||
use pumpkin_data::translation;
|
||||
use pumpkin_util::text::TextComponent;
|
||||
use std::pin::Pin;
|
||||
|
||||
pub const UNKNOWN_SLOT_ERROR_TYPE: CommandErrorType<1> = CommandErrorType::new(
|
||||
translation::java::SLOT_UNKNOWN,
|
||||
@@ -45,16 +44,14 @@ impl ArgumentType for SlotArgumentType {
|
||||
JavaClientArgumentType::ItemSlot
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move {
|
||||
) -> Suggestions {
|
||||
builder
|
||||
.filter_and_suggest(&SLOT_RANGE_SINGLE_SLOT_NAMES)
|
||||
.build()
|
||||
})
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<String> {
|
||||
@@ -84,12 +81,12 @@ impl ArgumentType for SlotsArgumentType {
|
||||
JavaClientArgumentType::ItemSlots
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move { builder.filter_and_suggest(&SLOT_RANGE_ALL_NAMES).build() })
|
||||
) -> Suggestions {
|
||||
builder.filter_and_suggest(&SLOT_RANGE_ALL_NAMES).build()
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<String> {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::pin::Pin;
|
||||
|
||||
use crate::command::argument_types::FromStringReader;
|
||||
use crate::command::argument_types::argument_type::{ArgumentType, JavaClientArgumentType};
|
||||
use crate::command::context::command_context::CommandContext;
|
||||
@@ -18,17 +16,15 @@ impl ArgumentType for StructureNameArgumentType {
|
||||
Identifier::from_reader(reader)
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
) -> Suggestions {
|
||||
let names = pumpkin_world::generation::structure::template::all_structure_names();
|
||||
Box::pin(async move {
|
||||
builder
|
||||
.filter_and_suggest_iter(names.iter().copied())
|
||||
.build()
|
||||
})
|
||||
}
|
||||
|
||||
fn client_side_parser(&'_ self) -> JavaClientArgumentType {
|
||||
|
||||
@@ -5,7 +5,6 @@ use crate::command::{
|
||||
string_reader::StringReader,
|
||||
suggestion::suggestions::{Suggestions, SuggestionsBuilder},
|
||||
};
|
||||
use std::pin::Pin;
|
||||
|
||||
/// Represents an argument type parsing a team name.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
@@ -23,18 +22,20 @@ impl ArgumentType for TeamArgumentType {
|
||||
JavaClientArgumentType::Team
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
context: &CommandContext,
|
||||
mut builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move {
|
||||
let scoreboard = context.world().scoreboard.lock().await;
|
||||
) -> Suggestions {
|
||||
let scoreboard = context
|
||||
.world()
|
||||
.scoreboard
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
for team_name in scoreboard.get_teams().keys() {
|
||||
builder = builder.filter_and_suggest_one(team_name.as_str());
|
||||
}
|
||||
builder.build()
|
||||
})
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<String> {
|
||||
|
||||
@@ -7,7 +7,6 @@ use crate::command::suggestion::suggestions::{Suggestions, SuggestionsBuilder};
|
||||
use pumpkin_data::translation::java::ARGUMENT_COLOR_INVALID;
|
||||
use pumpkin_util::text::TextComponent;
|
||||
use pumpkin_util::text::color::NamedColor;
|
||||
use std::pin::Pin;
|
||||
|
||||
pub const INVALID_VALUE_ERROR_TYPE: CommandErrorType<1> =
|
||||
CommandErrorType::new(ARGUMENT_COLOR_INVALID, ARGUMENT_COLOR_INVALID);
|
||||
@@ -30,12 +29,11 @@ impl ArgumentType for TeamColorArgumentType {
|
||||
JavaClientArgumentType::Color
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move {
|
||||
) -> Suggestions {
|
||||
builder
|
||||
.filter_and_suggest(&[
|
||||
"black",
|
||||
@@ -56,7 +54,6 @@ impl ArgumentType for TeamColorArgumentType {
|
||||
"white",
|
||||
])
|
||||
.build()
|
||||
})
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<String> {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::pin::Pin;
|
||||
|
||||
use crate::command::argument_types::FromStringReader;
|
||||
use crate::command::argument_types::argument_type::{ArgumentType, JavaClientArgumentType};
|
||||
use crate::command::context::command_context::CommandContext;
|
||||
@@ -19,17 +17,15 @@ impl ArgumentType for TemplateNameArgumentType {
|
||||
Ok(identifier.path().to_string())
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
) -> Suggestions {
|
||||
let names = pumpkin_world::generation::structure::template::all_template_names();
|
||||
Box::pin(async move {
|
||||
builder
|
||||
.filter_and_suggest_iter(names.iter().map(|n| format!("minecraft:{n}")))
|
||||
.build()
|
||||
})
|
||||
}
|
||||
|
||||
fn client_side_parser(&'_ self) -> JavaClientArgumentType {
|
||||
|
||||
@@ -6,7 +6,6 @@ use crate::command::string_reader::StringReader;
|
||||
use crate::command::suggestion::suggestions::{Suggestions, SuggestionsBuilder};
|
||||
use pumpkin_data::translation;
|
||||
use pumpkin_util::text::TextComponent;
|
||||
use std::pin::Pin;
|
||||
|
||||
pub const INVALID_UNIT_ERROR_TYPE: CommandErrorType<0> = CommandErrorType::new(
|
||||
translation::java::ARGUMENT_TIME_INVALID_UNIT,
|
||||
@@ -73,12 +72,11 @@ impl ArgumentType for TimeArgumentType {
|
||||
JavaClientArgumentType::Time { min: self.min }
|
||||
}
|
||||
|
||||
fn list_suggestions<'a>(
|
||||
&'a self,
|
||||
_context: &'a CommandContext,
|
||||
fn list_suggestions(
|
||||
&self,
|
||||
_context: &CommandContext,
|
||||
suggestions_builder: SuggestionsBuilder,
|
||||
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
|
||||
Box::pin(async move {
|
||||
) -> Suggestions {
|
||||
let mut reader = StringReader::new(suggestions_builder.remaining());
|
||||
if reader.read_float().is_err() {
|
||||
suggestions_builder.build()
|
||||
@@ -87,7 +85,6 @@ impl ArgumentType for TimeArgumentType {
|
||||
.filter_and_suggest(&["t", "s", "d"])
|
||||
.build()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<String> {
|
||||
|
||||
@@ -21,7 +21,7 @@ use pumpkin_protocol::bedrock::client::available_commands::{
|
||||
use pumpkin_protocol::java::client::play::SuggestionProviders;
|
||||
|
||||
#[expect(clippy::too_many_lines)]
|
||||
pub async fn send_c_commands_packet(
|
||||
pub fn send_c_commands_packet(
|
||||
player: &Arc<Player>,
|
||||
server: &Server,
|
||||
dispatcher: &CommandDispatcher,
|
||||
@@ -50,7 +50,7 @@ pub async fn send_c_commands_packet(
|
||||
continue;
|
||||
};
|
||||
|
||||
if !cmd_src.has_permission(server, permission.as_str()).await {
|
||||
if !cmd_src.has_permission(server, permission.as_str()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ pub async fn send_c_commands_packet(
|
||||
}
|
||||
|
||||
let packet = CCommands::new(proto_nodes.into(), VarInt(root_node_index as i32));
|
||||
player.send_client_packet(&packet).await;
|
||||
player.try_send_client_packet(&packet);
|
||||
}
|
||||
|
||||
fn resolve_node_id(node_id: NodeId, node_id_offset: usize, root_node_index: usize) -> usize {
|
||||
@@ -319,7 +319,7 @@ struct BuilderContext<'a> {
|
||||
}
|
||||
|
||||
#[expect(clippy::too_many_lines)]
|
||||
pub async fn send_bedrock_commands_packet(
|
||||
pub fn send_bedrock_commands_packet(
|
||||
player: &Arc<Player>,
|
||||
server: &Server,
|
||||
dispatcher: &CommandDispatcher,
|
||||
@@ -348,7 +348,7 @@ pub async fn send_bedrock_commands_packet(
|
||||
continue;
|
||||
};
|
||||
|
||||
if !cmd_src.has_permission(server, permission.as_str()).await {
|
||||
if !cmd_src.has_permission(server, permission.as_str()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -441,8 +441,10 @@ pub async fn send_bedrock_commands_packet(
|
||||
constraints: Vec::new(),
|
||||
};
|
||||
|
||||
if let crate::net::ClientPlatform::Bedrock(bedrock_client) = player.client.as_ref() {
|
||||
bedrock_client.send_packet(&packet).await;
|
||||
if let crate::net::ClientPlatform::Bedrock(bedrock_client) = player.client.as_ref()
|
||||
&& let Ok(data) = bedrock_client.serialize_packet(&packet)
|
||||
{
|
||||
bedrock_client.try_enqueue_packet(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ use crate::command::suggestion::suggestions::SuggestionsBuilder;
|
||||
use crate::entity::EntityBase;
|
||||
use crate::entity::player::Player;
|
||||
use crate::entity::player::advancement::PlayerAdvancement;
|
||||
use futures::future::join_all;
|
||||
use pumpkin_data::advancement_data::AdvancementNode;
|
||||
use pumpkin_data::{ADVANCEMENT_TREE, Advancement, translation};
|
||||
use pumpkin_util::PermissionLvl;
|
||||
@@ -141,13 +140,13 @@ impl Action {
|
||||
///
|
||||
/// Returns the number of advancements successfully modified. An advancement is counted as
|
||||
/// successful if [`perform_single_inner`] returns `true`
|
||||
async fn perform(
|
||||
&self,
|
||||
fn perform(
|
||||
self,
|
||||
player: &Arc<Player>,
|
||||
advancements: &[&'static Advancement],
|
||||
show_advancement: bool,
|
||||
) -> i32 {
|
||||
let mut guard = player.advancements.lock().await;
|
||||
let mut guard = player.advancements.blocking_lock();
|
||||
if !show_advancement {
|
||||
guard.flush_dirty(player, true);
|
||||
}
|
||||
@@ -161,13 +160,13 @@ impl Action {
|
||||
count
|
||||
}
|
||||
|
||||
async fn perform_criterion(
|
||||
&self,
|
||||
fn perform_criterion(
|
||||
self,
|
||||
player: &Arc<Player>,
|
||||
advancement: &'static Advancement,
|
||||
criterion: &str,
|
||||
) -> bool {
|
||||
let mut guard = player.advancements.lock().await;
|
||||
let mut guard = player.advancements.blocking_lock();
|
||||
match self {
|
||||
Self::Grant => guard.award(advancement, criterion),
|
||||
Self::Revoke => guard.revoke(advancement, criterion),
|
||||
@@ -261,41 +260,41 @@ fn add_children(parent: &AdvancementNode, output: &mut Vec<&Advancement>) {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
async fn perform_and_show(
|
||||
context: Arc<CommandSource>,
|
||||
fn perform_and_show(
|
||||
context: &CommandSource,
|
||||
players: &[Arc<Player>],
|
||||
action: Action,
|
||||
advancements: &[&'static Advancement],
|
||||
) -> Result<i32, CommandSyntaxError> {
|
||||
perform(context, players, action, advancements, true).await
|
||||
perform(context, players, action, advancements, true)
|
||||
}
|
||||
|
||||
/// Performs a batch action (grant or revoke) on multiple advancements for multiple players.
|
||||
///
|
||||
/// This function iterates through each player and applies the specified action to all provided
|
||||
/// advancements. It automatically handles error messaging based on the number of players and
|
||||
/// advancements involved, as well as the number of successful operations.
|
||||
/// advancements involved.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `context` - The command source context used to send feedback messages to the command executor
|
||||
/// * `targets` - Slice of players who will be affected by the action
|
||||
/// * `context` - The command source context for sending feedback
|
||||
/// * `targets` - The players to apply the action to
|
||||
/// * `action` - The action to perform on each advancement (Grant or Revoke)
|
||||
/// * `advancements` - Slice of advancements to apply the action to
|
||||
/// * `show_advancement` - Whether to show advancement notifications to players (currently unused)
|
||||
/// * `advancements` - A slice of advancements to apply the action to
|
||||
/// * `show_advancement` - Whether to show advancement notifications to players
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns `Ok(i)` with the total count of successful operations if at least one advancement
|
||||
/// was successfully modified for at least one player.
|
||||
/// Returns `Ok(count)` with the total number of advancements successfully granted/revoked across
|
||||
/// all players.
|
||||
///
|
||||
/// Returns `Err` with an appropriate localized error message if no operations succeeded. The
|
||||
/// error message varies based on:
|
||||
/// - Whether one or many players were targeted
|
||||
/// - Whether one or many advancements were involved
|
||||
/// - The type of action (Grant or Revoke)
|
||||
async fn perform(
|
||||
context: Arc<CommandSource>,
|
||||
fn perform(
|
||||
context: &CommandSource,
|
||||
targets: &[Arc<Player>],
|
||||
action: Action,
|
||||
advancements: &[&'static Advancement],
|
||||
@@ -303,7 +302,7 @@ async fn perform(
|
||||
) -> Result<i32, CommandSyntaxError> {
|
||||
let mut i = 0;
|
||||
for player in targets {
|
||||
i += action.perform(player, advancements, show_advancement).await;
|
||||
i += action.perform(player, advancements, show_advancement);
|
||||
}
|
||||
if i == 0 {
|
||||
return if let [first_advancement] = advancements[..] {
|
||||
@@ -378,7 +377,7 @@ async fn perform(
|
||||
],
|
||||
)
|
||||
};
|
||||
context.send_feedback(translate, true).await;
|
||||
context.send_feedback(translate, true);
|
||||
Ok(i)
|
||||
}
|
||||
|
||||
@@ -402,21 +401,17 @@ async fn perform(
|
||||
/// Returns `Err` with an appropriate error message if:
|
||||
/// - The criterion doesn't exist in the advancement
|
||||
/// - No operations succeeded
|
||||
pub async fn perform_criterion(
|
||||
context: Arc<CommandSource>,
|
||||
pub fn perform_criterion(
|
||||
context: &CommandSource,
|
||||
targets: &[Arc<Player>],
|
||||
action: Action,
|
||||
advancement: &'static Advancement,
|
||||
criterion: &str,
|
||||
) -> Result<i32, CommandSyntaxError> {
|
||||
if advancement.criteria.contains(&criterion) {
|
||||
let count = join_all(
|
||||
targets
|
||||
let count = targets
|
||||
.iter()
|
||||
.map(|player| action.perform_criterion(player, advancement, criterion)),
|
||||
)
|
||||
.await
|
||||
.into_iter()
|
||||
.map(|player| action.perform_criterion(player, advancement, criterion))
|
||||
.filter(|&success| success)
|
||||
.count() as i32;
|
||||
if count == 0 {
|
||||
@@ -461,14 +456,16 @@ pub async fn perform_criterion(
|
||||
],
|
||||
)
|
||||
};
|
||||
context.send_feedback(translate, true).await;
|
||||
context.send_feedback(translate, true);
|
||||
Ok(count)
|
||||
}
|
||||
} else {
|
||||
Err(ERROR_CRITERION_NOT_FOUND.create_without_context(
|
||||
Err(
|
||||
ERROR_CRITERION_NOT_FOUND.create_without_context_args_slice(&[
|
||||
advancement.name(),
|
||||
TextComponent::text(criterion.to_owned()),
|
||||
))
|
||||
]),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,18 +475,15 @@ struct OnlyAdvancementCriterionExecutor {
|
||||
}
|
||||
|
||||
impl CommandExecutor for OnlyAdvancementCriterionExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let action = self.action;
|
||||
Box::pin(async move {
|
||||
perform_criterion(
|
||||
context.source.clone(),
|
||||
&EntityArgumentType::get_players(context, ARG_TARGETS).await?,
|
||||
&context.source,
|
||||
&EntityArgumentType::get_players(context, ARG_TARGETS)?,
|
||||
action,
|
||||
ResourceKeyArgument::get_advancement(context, ARG_ADVANCEMENT)?,
|
||||
StringArgumentType::get(context, ARG_CRITERION)?,
|
||||
)
|
||||
.await
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -500,21 +494,18 @@ struct AdvancementExecutor {
|
||||
}
|
||||
|
||||
impl CommandExecutor for AdvancementExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let action = self.action;
|
||||
let mode = self.mode;
|
||||
Box::pin(async move {
|
||||
perform_and_show(
|
||||
context.source.clone(),
|
||||
&EntityArgumentType::get_players(context, ARG_TARGETS).await?,
|
||||
&context.source,
|
||||
&EntityArgumentType::get_players(context, ARG_TARGETS)?,
|
||||
action,
|
||||
&get_advancements(
|
||||
ResourceKeyArgument::get_advancement(context, ARG_ADVANCEMENT)?,
|
||||
mode,
|
||||
),
|
||||
)
|
||||
.await
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,18 +513,18 @@ impl CommandExecutor for AdvancementExecutor {
|
||||
struct CriterionSuggestionProvider;
|
||||
|
||||
impl SuggestionProvider for CriterionSuggestionProvider {
|
||||
fn suggest<'a>(
|
||||
&'a self,
|
||||
context: &'a CommandContext,
|
||||
fn suggest(
|
||||
&self,
|
||||
context: &CommandContext,
|
||||
builder: SuggestionsBuilder,
|
||||
) -> SuggestionProviderResult<'a> {
|
||||
) -> SuggestionProviderResult {
|
||||
let suggestion = ResourceKeyArgument::get_advancement(context, ARG_ADVANCEMENT)
|
||||
.ok()
|
||||
.map(|adv| adv.criteria)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(ToString::to_string);
|
||||
Box::pin(async move { builder.filter_and_suggest_iter(suggestion).build() })
|
||||
builder.filter_and_suggest_iter(suggestion).build()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -543,18 +534,15 @@ struct EveryAdvancementExecutor {
|
||||
}
|
||||
|
||||
impl CommandExecutor for EveryAdvancementExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let action = self.action;
|
||||
Box::pin(async move {
|
||||
perform(
|
||||
context.source.clone(),
|
||||
&EntityArgumentType::get_players(context, ARG_TARGETS).await?,
|
||||
&context.source,
|
||||
&EntityArgumentType::get_players(context, ARG_TARGETS)?,
|
||||
action,
|
||||
&Advancement::get_advancements_list(),
|
||||
false,
|
||||
)
|
||||
.await
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,9 +59,8 @@ struct GetExecutor {
|
||||
}
|
||||
|
||||
impl CommandExecutor for GetExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
let target = EntityArgumentType::get_entity(context, ARG_TARGET).await?;
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let target = EntityArgumentType::get_entity(context, ARG_TARGET)?;
|
||||
let living = target
|
||||
.get_living_entity()
|
||||
.ok_or_else(|| FAILED_ENTITY_ERROR.create_without_context(target.get_name()))?;
|
||||
@@ -89,9 +88,7 @@ impl CommandExecutor for GetExecutor {
|
||||
let base_value = living.get_attribute_base(&attribute);
|
||||
let scaled_value = base_value * scale;
|
||||
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_ATTRIBUTE_BASE_VALUE_GET_SUCCESS,
|
||||
translation::java::COMMANDS_ATTRIBUTE_BASE_VALUE_GET_SUCCESS,
|
||||
@@ -102,17 +99,14 @@ impl CommandExecutor for GetExecutor {
|
||||
],
|
||||
),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
|
||||
Ok(scaled_value as i32)
|
||||
} else {
|
||||
let value = living.get_attribute_value(&attribute);
|
||||
let scaled_value = value * scale;
|
||||
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_ATTRIBUTE_VALUE_GET_SUCCESS,
|
||||
translation::java::COMMANDS_ATTRIBUTE_VALUE_GET_SUCCESS,
|
||||
@@ -123,21 +117,18 @@ impl CommandExecutor for GetExecutor {
|
||||
],
|
||||
),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
|
||||
Ok(scaled_value as i32)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct BaseSetExecutor;
|
||||
|
||||
impl CommandExecutor for BaseSetExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
let target = EntityArgumentType::get_entity(context, ARG_TARGET).await?;
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let target = EntityArgumentType::get_entity(context, ARG_TARGET)?;
|
||||
let living = target
|
||||
.get_living_entity()
|
||||
.ok_or_else(|| FAILED_ENTITY_ERROR.create_without_context(target.get_name()))?;
|
||||
@@ -163,9 +154,7 @@ impl CommandExecutor for BaseSetExecutor {
|
||||
vec![attribute.clone()],
|
||||
);
|
||||
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_ATTRIBUTE_BASE_VALUE_SET_SUCCESS,
|
||||
translation::java::COMMANDS_ATTRIBUTE_BASE_VALUE_SET_SUCCESS,
|
||||
@@ -176,20 +165,17 @@ impl CommandExecutor for BaseSetExecutor {
|
||||
],
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
|
||||
Ok(value as i32)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct BaseResetExecutor;
|
||||
|
||||
impl CommandExecutor for BaseResetExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
let target = EntityArgumentType::get_entity(context, ARG_TARGET).await?;
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let target = EntityArgumentType::get_entity(context, ARG_TARGET)?;
|
||||
let living = target
|
||||
.get_living_entity()
|
||||
.ok_or_else(|| FAILED_ENTITY_ERROR.create_without_context(target.get_name()))?;
|
||||
@@ -215,9 +201,7 @@ impl CommandExecutor for BaseResetExecutor {
|
||||
vec![attribute.clone()],
|
||||
);
|
||||
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_ATTRIBUTE_BASE_VALUE_RESET_SUCCESS,
|
||||
translation::java::COMMANDS_ATTRIBUTE_BASE_VALUE_RESET_SUCCESS,
|
||||
@@ -228,11 +212,9 @@ impl CommandExecutor for BaseResetExecutor {
|
||||
],
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
|
||||
Ok(default_val as i32)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,9 +223,8 @@ struct ModifierAddExecutor {
|
||||
}
|
||||
|
||||
impl CommandExecutor for ModifierAddExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
let target = EntityArgumentType::get_entity(context, ARG_TARGET).await?;
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let target = EntityArgumentType::get_entity(context, ARG_TARGET)?;
|
||||
let living = target
|
||||
.get_living_entity()
|
||||
.ok_or_else(|| FAILED_ENTITY_ERROR.create_without_context(target.get_name()))?;
|
||||
@@ -290,9 +271,7 @@ impl CommandExecutor for ModifierAddExecutor {
|
||||
vec![attribute.clone()],
|
||||
);
|
||||
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_ATTRIBUTE_MODIFIER_ADD_SUCCESS,
|
||||
translation::java::COMMANDS_ATTRIBUTE_MODIFIER_ADD_SUCCESS,
|
||||
@@ -303,20 +282,17 @@ impl CommandExecutor for ModifierAddExecutor {
|
||||
],
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
|
||||
Ok(1)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct ModifierRemoveExecutor;
|
||||
|
||||
impl CommandExecutor for ModifierRemoveExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
let target = EntityArgumentType::get_entity(context, ARG_TARGET).await?;
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let target = EntityArgumentType::get_entity(context, ARG_TARGET)?;
|
||||
let living = target
|
||||
.get_living_entity()
|
||||
.ok_or_else(|| FAILED_ENTITY_ERROR.create_without_context(target.get_name()))?;
|
||||
@@ -361,9 +337,7 @@ impl CommandExecutor for ModifierRemoveExecutor {
|
||||
vec![attribute.clone()],
|
||||
);
|
||||
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_ATTRIBUTE_MODIFIER_REMOVE_SUCCESS,
|
||||
translation::java::COMMANDS_ATTRIBUTE_MODIFIER_REMOVE_SUCCESS,
|
||||
@@ -374,20 +348,17 @@ impl CommandExecutor for ModifierRemoveExecutor {
|
||||
],
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
|
||||
Ok(1)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct ModifierGetExecutor;
|
||||
|
||||
impl CommandExecutor for ModifierGetExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
let target = EntityArgumentType::get_entity(context, ARG_TARGET).await?;
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let target = EntityArgumentType::get_entity(context, ARG_TARGET)?;
|
||||
let living = target
|
||||
.get_living_entity()
|
||||
.ok_or_else(|| FAILED_ENTITY_ERROR.create_without_context(target.get_name()))?;
|
||||
@@ -424,9 +395,7 @@ impl CommandExecutor for ModifierGetExecutor {
|
||||
modifier.amount
|
||||
};
|
||||
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_ATTRIBUTE_MODIFIER_VALUE_GET_SUCCESS,
|
||||
translation::java::COMMANDS_ATTRIBUTE_MODIFIER_VALUE_GET_SUCCESS,
|
||||
@@ -438,11 +407,9 @@ impl CommandExecutor for ModifierGetExecutor {
|
||||
],
|
||||
),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
|
||||
Ok(val as i32)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::command::CommandResult;
|
||||
use crate::{
|
||||
command::{
|
||||
CommandError, CommandExecutor, CommandSender,
|
||||
CommandError, CommandExecutor, CommandResult, CommandSender,
|
||||
args::{
|
||||
Arg, ConsumedArgs,
|
||||
gameprofile::{GameProfileSuggestionMode, GameProfilesArgumentConsumer},
|
||||
@@ -25,32 +24,29 @@ const ARG_REASON: &str = "reason";
|
||||
struct NoReasonExecutor;
|
||||
|
||||
impl CommandExecutor for NoReasonExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let Some(Arg::GameProfiles(targets)) = args.get(&ARG_TARGET) else {
|
||||
return Err(InvalidConsumption(Some(ARG_TARGET.into())));
|
||||
};
|
||||
|
||||
ban_players(sender, server, targets.as_slice(), None).await
|
||||
})
|
||||
ban_players(sender, server, targets.as_slice(), None)
|
||||
}
|
||||
}
|
||||
|
||||
struct ReasonExecutor;
|
||||
|
||||
impl CommandExecutor for ReasonExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let Some(Arg::GameProfiles(targets)) = args.get(&ARG_TARGET) else {
|
||||
return Err(InvalidConsumption(Some(ARG_TARGET.into())));
|
||||
};
|
||||
@@ -59,13 +55,12 @@ impl CommandExecutor for ReasonExecutor {
|
||||
return Err(InvalidConsumption(Some(ARG_REASON.into())));
|
||||
};
|
||||
|
||||
ban_players(sender, server, targets.as_slice(), Some(reason)).await
|
||||
})
|
||||
ban_players(sender, server, targets.as_slice(), Some(reason))
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the number of players successfully banned.
|
||||
async fn ban_players(
|
||||
fn ban_players(
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
targets: &[GameProfile],
|
||||
@@ -73,7 +68,7 @@ async fn ban_players(
|
||||
) -> Result<i32, CommandError> {
|
||||
let mut count: usize = 0;
|
||||
for target in targets {
|
||||
if ban_profile(sender, server, target, reason.cloned()).await {
|
||||
if ban_profile(sender, server, target, reason.cloned()) {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
@@ -90,13 +85,13 @@ async fn ban_players(
|
||||
}
|
||||
|
||||
/// Returns `true` if the player was successfully banned.
|
||||
async fn ban_profile(
|
||||
fn ban_profile(
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
profile: &GameProfile,
|
||||
reason: Option<String>,
|
||||
) -> bool {
|
||||
let mut banned_players = server.data.banned_player_list.write().await;
|
||||
let mut banned_players = server.data.banned_player_list.write().unwrap();
|
||||
|
||||
let reason = reason.unwrap_or_else(|| "Banned by an operator.".to_string());
|
||||
|
||||
@@ -123,28 +118,22 @@ async fn ban_profile(
|
||||
drop(banned_players);
|
||||
|
||||
// Send messages
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BAN_SUCCESS,
|
||||
translation::bedrock::COMMANDS_BAN_SUCCESS,
|
||||
[
|
||||
TextComponent::text(profile.name.clone()),
|
||||
TextComponent::text(reason),
|
||||
],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
|
||||
if let Some(player) = server.get_player_by_uuid(profile.id) {
|
||||
player
|
||||
.kick(
|
||||
DisconnectReason::Kicked,
|
||||
TextComponent::translate_cross(
|
||||
let kick_msg = TextComponent::translate_cross(
|
||||
translation::java::MULTIPLAYER_DISCONNECT_BANNED,
|
||||
translation::bedrock::DISCONNECTIONSCREEN_TITLE_BANNEDBYHOST,
|
||||
[],
|
||||
),
|
||||
)
|
||||
.await;
|
||||
);
|
||||
player.kick(DisconnectReason::Kicked, &kick_msg);
|
||||
}
|
||||
|
||||
true
|
||||
|
||||
@@ -30,32 +30,29 @@ fn parse_ip(target: &str, server: &Server) -> Option<IpAddr> {
|
||||
struct NoReasonExecutor;
|
||||
|
||||
impl CommandExecutor for NoReasonExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let Some(Arg::Simple(target)) = args.get(&ARG_TARGET) else {
|
||||
return Err(InvalidConsumption(Some(ARG_TARGET.into())));
|
||||
};
|
||||
|
||||
ban_ip(sender, server, target, None).await
|
||||
})
|
||||
ban_ip(sender, server, target, None)
|
||||
}
|
||||
}
|
||||
|
||||
struct ReasonExecutor;
|
||||
|
||||
impl CommandExecutor for ReasonExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let Some(Arg::Simple(target)) = args.get(&ARG_TARGET) else {
|
||||
return Err(InvalidConsumption(Some(ARG_TARGET.into())));
|
||||
};
|
||||
@@ -64,12 +61,11 @@ impl CommandExecutor for ReasonExecutor {
|
||||
return Err(InvalidConsumption(Some(ARG_REASON.into())));
|
||||
};
|
||||
|
||||
ban_ip(sender, server, target, Some(reason.clone())).await
|
||||
})
|
||||
ban_ip(sender, server, target, Some(reason.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
async fn ban_ip(
|
||||
fn ban_ip(
|
||||
sender: &CommandSender,
|
||||
server: &Server,
|
||||
target: &str,
|
||||
@@ -85,7 +81,7 @@ async fn ban_ip(
|
||||
)));
|
||||
};
|
||||
|
||||
let mut banned_ips = server.data.banned_ip_list.write().await;
|
||||
let mut banned_ips = server.data.banned_ip_list.write().unwrap();
|
||||
|
||||
if banned_ips.get_entry(&target_ip).is_some() {
|
||||
return Err(CommandError::CommandFailed(TextComponent::translate_cross(
|
||||
@@ -113,40 +109,32 @@ async fn ban_ip(
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ");
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BANIP_SUCCESS,
|
||||
translation::bedrock::COMMANDS_BANIP_SUCCESS,
|
||||
[
|
||||
TextComponent::text(target_ip.to_string()),
|
||||
TextComponent::text(reason),
|
||||
],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BANIP_INFO,
|
||||
translation::java::COMMANDS_BANIP_INFO,
|
||||
[
|
||||
TextComponent::text(affected.len().to_string()),
|
||||
TextComponent::text(names),
|
||||
],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
|
||||
let count = affected.len();
|
||||
for target in affected {
|
||||
target
|
||||
.kick(
|
||||
DisconnectReason::Kicked,
|
||||
TextComponent::translate_cross(
|
||||
let kick_msg = TextComponent::translate_cross(
|
||||
translation::java::MULTIPLAYER_DISCONNECT_IP_BANNED,
|
||||
translation::java::MULTIPLAYER_DISCONNECT_IP_BANNED,
|
||||
[],
|
||||
),
|
||||
)
|
||||
.await;
|
||||
);
|
||||
target.kick(DisconnectReason::Kicked, &kick_msg);
|
||||
}
|
||||
|
||||
Ok(count as i32)
|
||||
|
||||
@@ -23,14 +23,13 @@ struct BanListCommandExecutor {
|
||||
}
|
||||
|
||||
impl CommandExecutor for BanListCommandExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let mut entries = Vec::new();
|
||||
|
||||
let data = &context.server().data;
|
||||
|
||||
if self.players {
|
||||
let lock = data.banned_player_list.read().await;
|
||||
let lock = data.banned_player_list.read().unwrap();
|
||||
for entry in &lock.banned_players {
|
||||
entries.push(BanListEntry {
|
||||
name: entry.name.clone(),
|
||||
@@ -41,7 +40,7 @@ impl CommandExecutor for BanListCommandExecutor {
|
||||
}
|
||||
|
||||
if self.ips {
|
||||
let lock = data.banned_ip_list.read().await;
|
||||
let lock = data.banned_ip_list.read().unwrap();
|
||||
for entry in &lock.banned_ips {
|
||||
entries.push(BanListEntry {
|
||||
name: entry.ip.to_string(),
|
||||
@@ -55,16 +54,14 @@ impl CommandExecutor for BanListCommandExecutor {
|
||||
let source = &context.source;
|
||||
|
||||
if entries.is_empty() {
|
||||
source
|
||||
.send_feedback(
|
||||
source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BANLIST_NONE,
|
||||
translation::java::COMMANDS_BANLIST_NONE,
|
||||
[],
|
||||
),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
} else {
|
||||
let bedrock_list_key = if self.ips && !self.players {
|
||||
translation::bedrock::COMMANDS_BANLIST_IPS
|
||||
@@ -72,20 +69,17 @@ impl CommandExecutor for BanListCommandExecutor {
|
||||
translation::bedrock::COMMANDS_BANLIST_PLAYERS
|
||||
};
|
||||
|
||||
source
|
||||
.send_feedback(
|
||||
source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BANLIST_LIST,
|
||||
bedrock_list_key,
|
||||
[TextComponent::text(entries.len().to_string())],
|
||||
),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
|
||||
for entry in entries {
|
||||
source
|
||||
.send_feedback(
|
||||
source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BANLIST_ENTRY,
|
||||
translation::java::COMMANDS_BANLIST_ENTRY,
|
||||
@@ -96,13 +90,11 @@ impl CommandExecutor for BanListCommandExecutor {
|
||||
],
|
||||
),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(entries_len)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,17 +35,16 @@ const fn autocomplete_consumer() -> ResourceLocationArgumentConsumer {
|
||||
struct BossbarSuggestionProvider;
|
||||
|
||||
impl CommandSuggestionProvider for BossbarSuggestionProvider {
|
||||
fn suggest<'a>(
|
||||
&'a self,
|
||||
_src: &'a CommandSender,
|
||||
server: &'a Server,
|
||||
input: &'a str,
|
||||
fn suggest(
|
||||
&self,
|
||||
_src: &CommandSender,
|
||||
server: &Server,
|
||||
input: &str,
|
||||
start: usize,
|
||||
_end: usize,
|
||||
) -> CommandSuggestionResult<'a> {
|
||||
Box::pin(async move {
|
||||
) -> CommandSuggestionResult {
|
||||
let mut builder = SuggestionsBuilder::new(input, start);
|
||||
let bossbars = server.bossbars.lock().await;
|
||||
let bossbars = server.bossbars.lock().unwrap();
|
||||
let remaining = builder.remaining_lowercase().to_string();
|
||||
for key in bossbars.custom_bossbars.keys() {
|
||||
if key.to_lowercase().starts_with(&remaining) {
|
||||
@@ -53,7 +52,6 @@ impl CommandSuggestionProvider for BossbarSuggestionProvider {
|
||||
}
|
||||
}
|
||||
builder.build()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,83 +75,72 @@ enum CommandValueSet {
|
||||
struct AddExecutor;
|
||||
|
||||
impl CommandExecutor for AddExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let namespace = autocomplete_consumer()
|
||||
.find_arg_default_name(args)?
|
||||
.to_string();
|
||||
|
||||
let text_component = TextComponentArgConsumer::find_arg(args, ARG_NAME)?;
|
||||
|
||||
if server.bossbars.lock().await.has_bossbar(&namespace) {
|
||||
if server.bossbars.lock().unwrap().has_bossbar(&namespace) {
|
||||
return Result::Err(CommandError::CommandFailed(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BOSSBAR_CREATE_FAILED,
|
||||
translation::bedrock::COMMANDS_BOSSBAR_ADD_FAILURE_EXISTS,
|
||||
[TextComponent::text(namespace.clone())],
|
||||
[TextComponent::text(namespace)],
|
||||
)));
|
||||
}
|
||||
|
||||
let bossbar = Bossbar::new(text_component);
|
||||
let mut bossbars = server.bossbars.lock().await;
|
||||
let mut bossbars = server.bossbars.lock().unwrap();
|
||||
|
||||
bossbars.create_bossbar(namespace.clone(), bossbar.clone());
|
||||
let new_size = bossbars.get_bossbars_len();
|
||||
drop(bossbars);
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BOSSBAR_CREATE_SUCCESS,
|
||||
translation::bedrock::COMMANDS_BOSSBAR_ADD_SUCCESS,
|
||||
[bossbar_prefix(bossbar.title.clone(), namespace.clone())],
|
||||
))
|
||||
.await;
|
||||
[bossbar_prefix(bossbar.title, namespace)],
|
||||
));
|
||||
|
||||
Ok(new_size as i32)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct GetExecutor(CommandValueGet);
|
||||
|
||||
impl CommandExecutor for GetExecutor {
|
||||
#[expect(clippy::too_many_lines)]
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let namespace = autocomplete_consumer()
|
||||
.find_arg_default_name(args)?
|
||||
.to_string();
|
||||
|
||||
let Some(bossbar) = server.bossbars.lock().await.get_bossbar(&namespace) else {
|
||||
let Some(bossbar) = server.bossbars.lock().unwrap().get_bossbar(&namespace) else {
|
||||
return Err(handle_bossbar_error(
|
||||
BossbarUpdateError::InvalidResourceLocation(namespace.clone()),
|
||||
BossbarUpdateError::InvalidResourceLocation(namespace),
|
||||
));
|
||||
};
|
||||
|
||||
match self.0 {
|
||||
CommandValueGet::Max => {
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BOSSBAR_GET_MAX,
|
||||
translation::bedrock::COMMANDS_BOSSBAR_GET_MAX,
|
||||
[
|
||||
bossbar_prefix(
|
||||
bossbar.bossbar_data.title.clone(),
|
||||
namespace.clone(),
|
||||
),
|
||||
bossbar_prefix(bossbar.bossbar_data.title.clone(), namespace),
|
||||
TextComponent::text(bossbar.max.to_string()),
|
||||
],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
Ok(bossbar.max)
|
||||
}
|
||||
CommandValueGet::Players => {
|
||||
@@ -166,19 +153,13 @@ impl CommandExecutor for GetExecutor {
|
||||
let count = online_players.len() as i32;
|
||||
|
||||
if count == 0 {
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BOSSBAR_GET_PLAYERS_NONE,
|
||||
translation::bedrock::COMMANDS_BOSSBAR_GET_PLAYERS_NONE,
|
||||
[bossbar_prefix(
|
||||
bossbar.bossbar_data.title.clone(),
|
||||
namespace.clone(),
|
||||
)],
|
||||
))
|
||||
.await;
|
||||
[bossbar_prefix(bossbar.bossbar_data.title, namespace)],
|
||||
));
|
||||
} else {
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BOSSBAR_GET_PLAYERS_SOME,
|
||||
if count == 1 {
|
||||
translation::bedrock::COMMANDS_BOSSBAR_GET_PLAYERS_ONE
|
||||
@@ -186,32 +167,23 @@ impl CommandExecutor for GetExecutor {
|
||||
translation::bedrock::COMMANDS_BOSSBAR_GET_PLAYERS
|
||||
},
|
||||
[
|
||||
bossbar_prefix(
|
||||
bossbar.bossbar_data.title.clone(),
|
||||
namespace.clone(),
|
||||
),
|
||||
bossbar_prefix(bossbar.bossbar_data.title, namespace),
|
||||
TextComponent::text(count.to_string()),
|
||||
TextComponent::text(online_players.join(", ")),
|
||||
],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
}
|
||||
Ok(count)
|
||||
}
|
||||
CommandValueGet::Value => {
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BOSSBAR_GET_VALUE,
|
||||
translation::bedrock::COMMANDS_BOSSBAR_GET_VALUE,
|
||||
[
|
||||
bossbar_prefix(
|
||||
bossbar.bossbar_data.title.clone(),
|
||||
namespace.clone(),
|
||||
),
|
||||
bossbar_prefix(bossbar.bossbar_data.title.clone(), namespace),
|
||||
TextComponent::text(bossbar.value.to_string()),
|
||||
],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
Ok(bossbar.value)
|
||||
}
|
||||
CommandValueGet::Visible => {
|
||||
@@ -226,43 +198,37 @@ impl CommandExecutor for GetExecutor {
|
||||
translation::bedrock::COMMANDS_BOSSBAR_GET_VISIBLE_FALSE,
|
||||
)
|
||||
};
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
java_key,
|
||||
bedrock_key,
|
||||
[bossbar_prefix(
|
||||
bossbar.bossbar_data.title.clone(),
|
||||
namespace.clone(),
|
||||
namespace,
|
||||
)],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
Ok(bossbar.visible as i32)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct ListExecutor;
|
||||
|
||||
impl CommandExecutor for ListExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a crate::server::Server,
|
||||
_args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
let bossbars = server.bossbars.lock().await.get_all_bossbars();
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
_args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let bossbars = server.bossbars.lock().unwrap().get_all_bossbars();
|
||||
|
||||
if bossbars.is_empty() {
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BOSSBAR_LIST_BARS_NONE,
|
||||
translation::bedrock::COMMANDS_BOSSBAR_LIST_NONE,
|
||||
[],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
return Ok(0);
|
||||
}
|
||||
|
||||
@@ -274,72 +240,64 @@ impl CommandExecutor for ListExecutor {
|
||||
bossbar.namespace.clone(),
|
||||
));
|
||||
} else {
|
||||
bossbars_text = bossbars_text.add_child(TextComponent::text(", ").add_child(
|
||||
bossbar_prefix(
|
||||
bossbars_text =
|
||||
bossbars_text.add_child(TextComponent::text(", ").add_child(bossbar_prefix(
|
||||
bossbar.bossbar_data.title.clone(),
|
||||
bossbar.namespace.clone(),
|
||||
),
|
||||
));
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BOSSBAR_LIST_BARS_SOME,
|
||||
translation::bedrock::COMMANDS_BOSSBAR_LIST,
|
||||
[
|
||||
TextComponent::text(bossbars.len().to_string()),
|
||||
bossbars_text,
|
||||
],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
|
||||
Ok(bossbars.len() as i32)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct RemoveExecutor;
|
||||
|
||||
impl CommandExecutor for RemoveExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let namespace = autocomplete_consumer()
|
||||
.find_arg_default_name(args)?
|
||||
.to_string();
|
||||
|
||||
let Some(bossbar) = server.bossbars.lock().await.get_bossbar(&namespace) else {
|
||||
let Some(bossbar) = server.bossbars.lock().unwrap().get_bossbar(&namespace) else {
|
||||
return Err(handle_bossbar_error(
|
||||
BossbarUpdateError::InvalidResourceLocation(namespace),
|
||||
));
|
||||
};
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BOSSBAR_REMOVE_SUCCESS,
|
||||
translation::bedrock::COMMANDS_BOSSBAR_REMOVE,
|
||||
[bossbar_prefix(
|
||||
bossbar.bossbar_data.title.clone(),
|
||||
bossbar.bossbar_data.title,
|
||||
namespace.clone(),
|
||||
)],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
|
||||
let res = server
|
||||
.bossbars
|
||||
.lock()
|
||||
.await
|
||||
.unwrap()
|
||||
.remove_bossbar(server, namespace);
|
||||
match res {
|
||||
Ok(()) => Ok(server.bossbars.lock().await.get_bossbars_len() as i32),
|
||||
Ok(()) => Ok(server.bossbars.lock().unwrap().get_bossbars_len() as i32),
|
||||
Err(error) => Err(handle_bossbar_error(error)),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,18 +305,17 @@ struct SetExecutor(CommandValueSet);
|
||||
|
||||
impl CommandExecutor for SetExecutor {
|
||||
#[expect(clippy::too_many_lines)]
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let namespace = autocomplete_consumer()
|
||||
.find_arg_default_name(args)?
|
||||
.to_string();
|
||||
|
||||
let Some(bossbar) = server.bossbars.lock().await.get_bossbar(&namespace) else {
|
||||
let Some(bossbar) = server.bossbars.lock().unwrap().get_bossbar(&namespace) else {
|
||||
return Err(handle_bossbar_error(
|
||||
BossbarUpdateError::InvalidResourceLocation(namespace),
|
||||
));
|
||||
@@ -371,20 +328,15 @@ impl CommandExecutor for SetExecutor {
|
||||
server
|
||||
.bossbars
|
||||
.lock()
|
||||
.await
|
||||
.unwrap()
|
||||
.update_color(server, &namespace, *color)
|
||||
.map_err(handle_bossbar_error)?;
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BOSSBAR_SET_COLOR_SUCCESS,
|
||||
translation::java::COMMANDS_BOSSBAR_SET_COLOR_SUCCESS,
|
||||
[bossbar_prefix(
|
||||
bossbar.bossbar_data.title.clone(),
|
||||
namespace,
|
||||
)],
|
||||
))
|
||||
.await;
|
||||
[bossbar_prefix(bossbar.bossbar_data.title, namespace)],
|
||||
));
|
||||
|
||||
Ok(0)
|
||||
}
|
||||
@@ -400,20 +352,18 @@ impl CommandExecutor for SetExecutor {
|
||||
server
|
||||
.bossbars
|
||||
.lock()
|
||||
.await
|
||||
.unwrap()
|
||||
.update_max(server, namespace.clone(), max_value)
|
||||
.map_err(handle_bossbar_error)?;
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BOSSBAR_SET_MAX_SUCCESS,
|
||||
translation::java::COMMANDS_BOSSBAR_SET_MAX_SUCCESS,
|
||||
[
|
||||
bossbar_prefix(bossbar.bossbar_data.title.clone(), namespace),
|
||||
bossbar_prefix(bossbar.bossbar_data.title, namespace),
|
||||
TextComponent::text(max_value.to_string()),
|
||||
],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
|
||||
Ok(0)
|
||||
}
|
||||
@@ -422,17 +372,15 @@ impl CommandExecutor for SetExecutor {
|
||||
server
|
||||
.bossbars
|
||||
.lock()
|
||||
.await
|
||||
.unwrap()
|
||||
.update_name(server, &namespace, &name)
|
||||
.map_err(handle_bossbar_error)?;
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BOSSBAR_SET_NAME_SUCCESS,
|
||||
translation::java::COMMANDS_BOSSBAR_SET_NAME_SUCCESS,
|
||||
[bossbar_prefix(name.clone(), namespace)],
|
||||
))
|
||||
.await;
|
||||
[bossbar_prefix(name, namespace)],
|
||||
));
|
||||
|
||||
Ok(0)
|
||||
}
|
||||
@@ -441,20 +389,15 @@ impl CommandExecutor for SetExecutor {
|
||||
server
|
||||
.bossbars
|
||||
.lock()
|
||||
.await
|
||||
.unwrap()
|
||||
.set_players(server, namespace.clone(), vec![])
|
||||
.map_err(handle_bossbar_error)?;
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BOSSBAR_SET_PLAYERS_SUCCESS_NONE,
|
||||
translation::java::COMMANDS_BOSSBAR_SET_PLAYERS_SUCCESS_NONE,
|
||||
[bossbar_prefix(
|
||||
bossbar.bossbar_data.title.clone(),
|
||||
namespace,
|
||||
)],
|
||||
))
|
||||
.await;
|
||||
[bossbar_prefix(bossbar.bossbar_data.title, namespace)],
|
||||
));
|
||||
|
||||
return Ok(0);
|
||||
}
|
||||
@@ -467,7 +410,7 @@ impl CommandExecutor for SetExecutor {
|
||||
server
|
||||
.bossbars
|
||||
.lock()
|
||||
.await
|
||||
.unwrap()
|
||||
.set_players(server, namespace.clone(), players)
|
||||
.map_err(handle_bossbar_error)?;
|
||||
|
||||
@@ -477,17 +420,15 @@ impl CommandExecutor for SetExecutor {
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BOSSBAR_SET_PLAYERS_SUCCESS_SOME,
|
||||
translation::java::COMMANDS_BOSSBAR_SET_PLAYERS_SUCCESS_SOME,
|
||||
[
|
||||
bossbar_prefix(bossbar.bossbar_data.title.clone(), namespace),
|
||||
bossbar_prefix(bossbar.bossbar_data.title, namespace),
|
||||
TextComponent::text(count.to_string()),
|
||||
TextComponent::text(player_names),
|
||||
],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
|
||||
Ok(count as i32)
|
||||
}
|
||||
@@ -496,20 +437,15 @@ impl CommandExecutor for SetExecutor {
|
||||
server
|
||||
.bossbars
|
||||
.lock()
|
||||
.await
|
||||
.unwrap()
|
||||
.update_style(server, &namespace, *style)
|
||||
.map_err(handle_bossbar_error)?;
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BOSSBAR_SET_STYLE_SUCCESS,
|
||||
translation::java::COMMANDS_BOSSBAR_SET_STYLE_SUCCESS,
|
||||
[bossbar_prefix(
|
||||
bossbar.bossbar_data.title.clone(),
|
||||
namespace,
|
||||
)],
|
||||
))
|
||||
.await;
|
||||
[bossbar_prefix(bossbar.bossbar_data.title, namespace)],
|
||||
));
|
||||
Ok(0)
|
||||
}
|
||||
CommandValueSet::Value => {
|
||||
@@ -524,20 +460,18 @@ impl CommandExecutor for SetExecutor {
|
||||
server
|
||||
.bossbars
|
||||
.lock()
|
||||
.await
|
||||
.unwrap()
|
||||
.update_value(server, namespace.clone(), value)
|
||||
.map_err(handle_bossbar_error)?;
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_BOSSBAR_SET_VALUE_SUCCESS,
|
||||
translation::java::COMMANDS_BOSSBAR_SET_VALUE_SUCCESS,
|
||||
[
|
||||
bossbar_prefix(bossbar.bossbar_data.title.clone(), namespace),
|
||||
bossbar_prefix(bossbar.bossbar_data.title, namespace),
|
||||
TextComponent::text(value.to_string()),
|
||||
],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
|
||||
Ok(value)
|
||||
}
|
||||
@@ -547,7 +481,7 @@ impl CommandExecutor for SetExecutor {
|
||||
server
|
||||
.bossbars
|
||||
.lock()
|
||||
.await
|
||||
.unwrap()
|
||||
.update_visibility(server, namespace.clone(), visibility)
|
||||
.map_err(handle_bossbar_error)?;
|
||||
|
||||
@@ -557,21 +491,15 @@ impl CommandExecutor for SetExecutor {
|
||||
translation::java::COMMANDS_BOSSBAR_SET_VISIBLE_SUCCESS_HIDDEN
|
||||
};
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
state,
|
||||
state,
|
||||
[bossbar_prefix(
|
||||
bossbar.bossbar_data.title.clone(),
|
||||
namespace,
|
||||
)],
|
||||
))
|
||||
.await;
|
||||
[bossbar_prefix(bossbar.bossbar_data.title, namespace)],
|
||||
));
|
||||
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,22 +106,22 @@ fn test_and_clear(
|
||||
}
|
||||
}
|
||||
|
||||
async fn command_result(
|
||||
fn command_result(
|
||||
sender: &CommandSender,
|
||||
item_count: i32,
|
||||
max_count: i32,
|
||||
targets: &[Arc<Player>],
|
||||
) -> Result<i32, CommandError> {
|
||||
match clear_command_text_output(item_count, max_count, targets).await {
|
||||
match clear_command_text_output(item_count, max_count, targets) {
|
||||
Ok(success) => {
|
||||
sender.send_message(success).await;
|
||||
sender.send_message(success);
|
||||
Ok(item_count)
|
||||
}
|
||||
Err(failure) => Err(CommandError::CommandFailed(failure)),
|
||||
}
|
||||
}
|
||||
|
||||
async fn clear_command_text_output(
|
||||
fn clear_command_text_output(
|
||||
item_count: i32,
|
||||
max_count: i32,
|
||||
targets: &[Arc<Player>],
|
||||
@@ -179,57 +179,51 @@ const fn count_consumer() -> BoundedNumArgumentConsumer<i32> {
|
||||
struct SelfExecutor;
|
||||
|
||||
impl CommandExecutor for SelfExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
_server: &'a crate::server::Server,
|
||||
_args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
_server: &crate::server::Server,
|
||||
_args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let target = sender.as_player().ok_or(CommandError::InvalidRequirement)?;
|
||||
|
||||
let items_cleared = clear_player(&target, &ItemPredicate::Any, MAX_NO_UPPER_LIMIT);
|
||||
|
||||
command_result(sender, items_cleared, MAX_NO_UPPER_LIMIT, &[target]).await
|
||||
})
|
||||
command_result(sender, items_cleared, MAX_NO_UPPER_LIMIT, &[target])
|
||||
}
|
||||
}
|
||||
|
||||
struct Executor;
|
||||
|
||||
impl CommandExecutor for Executor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
_server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
_server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let Some(Arg::Players(targets)) = args.get(&ARG_TARGETS) else {
|
||||
return Err(InvalidConsumption(Some(ARG_TARGETS.into())));
|
||||
};
|
||||
|
||||
let mut total_items_cleared = 0;
|
||||
for target in targets {
|
||||
total_items_cleared +=
|
||||
clear_player(target, &ItemPredicate::Any, MAX_NO_UPPER_LIMIT);
|
||||
total_items_cleared += clear_player(target, &ItemPredicate::Any, MAX_NO_UPPER_LIMIT);
|
||||
}
|
||||
|
||||
command_result(sender, total_items_cleared, MAX_NO_UPPER_LIMIT, targets).await
|
||||
})
|
||||
command_result(sender, total_items_cleared, MAX_NO_UPPER_LIMIT, targets)
|
||||
}
|
||||
}
|
||||
|
||||
struct ItemExecutor;
|
||||
|
||||
impl CommandExecutor for ItemExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
_server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
_server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let Some(Arg::Players(targets)) = args.get(&ARG_TARGETS) else {
|
||||
return Err(InvalidConsumption(Some(ARG_TARGETS.into())));
|
||||
};
|
||||
@@ -241,21 +235,19 @@ impl CommandExecutor for ItemExecutor {
|
||||
total_items_cleared += clear_player(target, &item, MAX_NO_UPPER_LIMIT);
|
||||
}
|
||||
|
||||
command_result(sender, total_items_cleared, MAX_NO_UPPER_LIMIT, targets).await
|
||||
})
|
||||
command_result(sender, total_items_cleared, MAX_NO_UPPER_LIMIT, targets)
|
||||
}
|
||||
}
|
||||
|
||||
struct ItemCountExecutor;
|
||||
|
||||
impl CommandExecutor for ItemCountExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
_server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
_server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let Some(Arg::Players(targets)) = args.get(&ARG_TARGETS) else {
|
||||
return Err(InvalidConsumption(Some(ARG_TARGETS.into())));
|
||||
};
|
||||
@@ -274,8 +266,7 @@ impl CommandExecutor for ItemCountExecutor {
|
||||
total_items_cleared += clear_player(target, &item, max);
|
||||
}
|
||||
|
||||
command_result(sender, total_items_cleared, max, targets).await
|
||||
})
|
||||
command_result(sender, total_items_cleared, max, targets)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,8 +76,7 @@ struct ClonedBlock {
|
||||
|
||||
impl CommandExecutor for CloneExecutor {
|
||||
#[expect(clippy::too_many_lines)]
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let begin = BlockPosArgumentType::get_block_pos(context, ARG_BEGIN)?;
|
||||
let end = BlockPosArgumentType::get_block_pos(context, ARG_END)?;
|
||||
let dest = BlockPosArgumentType::get_block_pos(context, ARG_DEST)?;
|
||||
@@ -165,8 +164,7 @@ impl CommandExecutor for CloneExecutor {
|
||||
for y in 0..size_y {
|
||||
for z in 0..size_z {
|
||||
let src_pos = BlockPos::new(min_x + x, min_y + y, min_z + z);
|
||||
let dest_pos =
|
||||
BlockPos::new(dest_min_x + x, dest_min_y + y, dest_min_z + z);
|
||||
let dest_pos = BlockPos::new(dest_min_x + x, dest_min_y + y, dest_min_z + z);
|
||||
|
||||
let state_id = world.get_block_state_id(&src_pos);
|
||||
|
||||
@@ -180,14 +178,15 @@ impl CommandExecutor for CloneExecutor {
|
||||
};
|
||||
|
||||
if should_clone {
|
||||
let block_entity_nbt =
|
||||
if let Some(be) = world.get_block_entity(&src_pos) {
|
||||
let block_entity_nbt = world.get_block_entity(&src_pos).map(|be| {
|
||||
let mut nbt = NbtCompound::new();
|
||||
be.write_internal(&mut nbt).await;
|
||||
Some(nbt)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Ok(handle) = tokio::runtime::Handle::try_current() {
|
||||
tokio::task::block_in_place(|| {
|
||||
handle.block_on(be.write_internal(&mut nbt));
|
||||
});
|
||||
}
|
||||
nbt
|
||||
});
|
||||
|
||||
blocks_to_clone.push(ClonedBlock {
|
||||
src_pos,
|
||||
@@ -243,20 +242,16 @@ impl CommandExecutor for CloneExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_CLONE_SUCCESS,
|
||||
translation::bedrock::COMMANDS_CLONE_SUCCESS,
|
||||
[TextComponent::text(count.to_string())],
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
|
||||
Ok(count)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ const fn amount_consumer() -> BoundedNumArgumentConsumer<f32> {
|
||||
struct LocationExecutor;
|
||||
struct EntityExecutor(bool);
|
||||
|
||||
async fn send_damage_result(
|
||||
fn send_damage_result(
|
||||
sender: &CommandSender,
|
||||
success: bool,
|
||||
amount: f32,
|
||||
@@ -46,31 +46,28 @@ async fn send_damage_result(
|
||||
)));
|
||||
}
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_DAMAGE_SUCCESS,
|
||||
translation::bedrock::COMMANDS_DAMAGE_SUCCESS,
|
||||
[TextComponent::text(amount.to_string()), target_name],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
|
||||
Ok(1) // not arbitrary, this is what vanilla does
|
||||
}
|
||||
|
||||
impl CommandExecutor for LocationExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
_server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
_server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let target = EntityArgumentConsumer::find_arg(args, ARG_TARGET)?;
|
||||
|
||||
let amount = BoundedNumArgumentConsumer::<f32>::find_arg(args, ARG_AMOUNT)??;
|
||||
|
||||
let damage_type =
|
||||
args.get(ARG_DAMAGE_TYPE)
|
||||
let damage_type = args
|
||||
.get(ARG_DAMAGE_TYPE)
|
||||
.map_or(DamageType::GENERIC, |arg| match arg {
|
||||
Arg::DamageType(dt) => *dt,
|
||||
_ => DamageType::GENERIC,
|
||||
@@ -78,34 +75,26 @@ impl CommandExecutor for LocationExecutor {
|
||||
|
||||
let location = Position3DArgumentConsumer::find_arg(args, ARG_LOCATION)?;
|
||||
|
||||
let success = target.damage_with_context(
|
||||
&*target,
|
||||
amount,
|
||||
damage_type,
|
||||
Some(location),
|
||||
None,
|
||||
None,
|
||||
);
|
||||
let success =
|
||||
target.damage_with_context(&*target, amount, damage_type, Some(location), None, None);
|
||||
|
||||
send_damage_result(sender, success, amount, target.get_display_name()).await
|
||||
})
|
||||
send_damage_result(sender, success, amount, target.get_display_name())
|
||||
}
|
||||
}
|
||||
|
||||
impl CommandExecutor for EntityExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
_server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
_server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let target = EntityArgumentConsumer::find_arg(args, ARG_TARGET)?;
|
||||
|
||||
let amount = BoundedNumArgumentConsumer::<f32>::find_arg(args, ARG_AMOUNT)??;
|
||||
|
||||
let damage_type =
|
||||
args.get(ARG_DAMAGE_TYPE)
|
||||
let damage_type = args
|
||||
.get(ARG_DAMAGE_TYPE)
|
||||
.map_or(DamageType::GENERIC, |arg| match arg {
|
||||
Arg::DamageType(dt) => *dt,
|
||||
_ => DamageType::GENERIC,
|
||||
@@ -127,8 +116,7 @@ impl CommandExecutor for EntityExecutor {
|
||||
cause.as_ref().map(|e| e.as_ref() as &dyn EntityBase),
|
||||
);
|
||||
|
||||
send_damage_result(sender, success, amount, target.get_display_name()).await
|
||||
})
|
||||
send_damage_result(sender, success, amount, target.get_display_name())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,18 +22,16 @@ const ARG_ENTITY: &str = "entity";
|
||||
struct GetEntityDataExecutor;
|
||||
|
||||
impl CommandExecutor for GetEntityDataExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
_server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
_server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let Some(Arg::Entity(entity)) = args.get(&ARG_ENTITY) else {
|
||||
return Err(InvalidConsumption(Some(ARG_ENTITY.into())));
|
||||
};
|
||||
display_data(entity.as_ref(), entity.get_display_name(), sender).await
|
||||
})
|
||||
display_data(entity.as_ref(), entity.get_display_name(), sender)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,7 +214,7 @@ pub fn snbt_colorful_display(tag: &NbtTag, depth: usize) -> Result<TextComponent
|
||||
}
|
||||
}
|
||||
|
||||
async fn display_data(
|
||||
fn display_data(
|
||||
entity: &dyn EntityBase,
|
||||
target_name: TextComponent,
|
||||
sender: &CommandSender,
|
||||
@@ -228,13 +226,11 @@ async fn display_data(
|
||||
let result = get_i32_result(&tag)?;
|
||||
let display = snbt_colorful_display(&tag, 0)
|
||||
.map_err(|string| CommandError::CommandFailed(TextComponent::text(string)))?;
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_DATA_ENTITY_QUERY,
|
||||
translation::java::COMMANDS_DATA_ENTITY_QUERY,
|
||||
[target_name, display],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
@@ -137,12 +137,11 @@ fn format_pack(name: &str) -> TextComponent {
|
||||
struct AvailablePackSuggestionProvider;
|
||||
|
||||
impl SuggestionProvider for AvailablePackSuggestionProvider {
|
||||
fn suggest<'a>(
|
||||
&'a self,
|
||||
context: &'a CommandContext,
|
||||
fn suggest(
|
||||
&self,
|
||||
context: &CommandContext,
|
||||
mut builder: SuggestionsBuilder,
|
||||
) -> SuggestionProviderResult<'a> {
|
||||
Box::pin(async move {
|
||||
) -> SuggestionProviderResult {
|
||||
let server = context.server();
|
||||
for pack in get_available_packs(server) {
|
||||
if pack.contains(' ') || pack.contains('/') {
|
||||
@@ -159,19 +158,17 @@ impl SuggestionProvider for AvailablePackSuggestionProvider {
|
||||
}
|
||||
}
|
||||
builder.build()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct EnabledPackSuggestionProvider;
|
||||
|
||||
impl SuggestionProvider for EnabledPackSuggestionProvider {
|
||||
fn suggest<'a>(
|
||||
&'a self,
|
||||
context: &'a CommandContext,
|
||||
fn suggest(
|
||||
&self,
|
||||
context: &CommandContext,
|
||||
mut builder: SuggestionsBuilder,
|
||||
) -> SuggestionProviderResult<'a> {
|
||||
Box::pin(async move {
|
||||
) -> SuggestionProviderResult {
|
||||
let server = context.server();
|
||||
for pack in get_enabled_packs(server) {
|
||||
if pack.contains(' ') || pack.contains('/') {
|
||||
@@ -188,7 +185,6 @@ impl SuggestionProvider for EnabledPackSuggestionProvider {
|
||||
}
|
||||
}
|
||||
builder.build()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,50 +198,43 @@ enum ListFilter {
|
||||
struct DatapackListExecutor(ListFilter);
|
||||
|
||||
impl CommandExecutor for DatapackListExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let server = context.server();
|
||||
let enabled = get_enabled_packs(server);
|
||||
let available = get_available_packs(server);
|
||||
|
||||
match self.0 {
|
||||
ListFilter::All => {
|
||||
send_enabled_list(context, &enabled).await;
|
||||
send_available_list(context, &available).await;
|
||||
send_enabled_list(context, &enabled);
|
||||
send_available_list(context, &available);
|
||||
Ok(enabled.len() as i32)
|
||||
}
|
||||
ListFilter::Enabled => {
|
||||
send_enabled_list(context, &enabled).await;
|
||||
send_enabled_list(context, &enabled);
|
||||
Ok(enabled.len() as i32)
|
||||
}
|
||||
ListFilter::Available => {
|
||||
send_available_list(context, &available).await;
|
||||
send_available_list(context, &available);
|
||||
Ok(available.len() as i32)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async fn send_enabled_list(context: &CommandContext<'_>, enabled: &[String]) {
|
||||
fn send_enabled_list(context: &CommandContext<'_>, enabled: &[String]) {
|
||||
if enabled.is_empty() {
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_DATAPACK_LIST_ENABLED_NONE,
|
||||
translation::java::COMMANDS_DATAPACK_LIST_ENABLED_NONE,
|
||||
[],
|
||||
),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
} else {
|
||||
let packs_component =
|
||||
TextComponent::join_with_comma(enabled.iter().map(|p| format_pack(p)).collect());
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_DATAPACK_LIST_ENABLED_SUCCESS,
|
||||
translation::java::COMMANDS_DATAPACK_LIST_ENABLED_SUCCESS,
|
||||
@@ -255,30 +244,24 @@ async fn send_enabled_list(context: &CommandContext<'_>, enabled: &[String]) {
|
||||
],
|
||||
),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async fn send_available_list(context: &CommandContext<'_>, available: &[String]) {
|
||||
fn send_available_list(context: &CommandContext<'_>, available: &[String]) {
|
||||
if available.is_empty() {
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_DATAPACK_LIST_AVAILABLE_NONE,
|
||||
translation::java::COMMANDS_DATAPACK_LIST_AVAILABLE_NONE,
|
||||
[],
|
||||
),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
} else {
|
||||
let packs_component =
|
||||
TextComponent::join_with_comma(available.iter().map(|p| format_pack(p)).collect());
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_DATAPACK_LIST_AVAILABLE_SUCCESS,
|
||||
translation::java::COMMANDS_DATAPACK_LIST_AVAILABLE_SUCCESS,
|
||||
@@ -288,8 +271,7 @@ async fn send_available_list(context: &CommandContext<'_>, available: &[String])
|
||||
],
|
||||
),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,8 +284,7 @@ enum EnablePosition {
|
||||
struct DatapackEnableExecutor(EnablePosition);
|
||||
|
||||
impl CommandExecutor for DatapackEnableExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let name_str = StringArgumentType::get(context, "name")?;
|
||||
let server = context.server();
|
||||
|
||||
@@ -340,22 +321,18 @@ impl CommandExecutor for DatapackEnableExecutor {
|
||||
error!("Failed to save world info: {err}");
|
||||
}
|
||||
|
||||
server.reload_datapacks(server).await;
|
||||
server.reload_datapacks(server);
|
||||
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_DATAPACK_MODIFY_ENABLE,
|
||||
translation::java::COMMANDS_DATAPACK_MODIFY_ENABLE,
|
||||
[format_pack(&resolved_name)],
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
|
||||
Ok(server.level_info.load().data_packs.enabled.len() as i32)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,8 +345,7 @@ enum BeforeOrAfter {
|
||||
struct DatapackEnableExistingExecutor(BeforeOrAfter);
|
||||
|
||||
impl CommandExecutor for DatapackEnableExistingExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let name_str = StringArgumentType::get(context, "name")?;
|
||||
let existing_str = StringArgumentType::get(context, "existing")?;
|
||||
let server = context.server();
|
||||
@@ -398,7 +374,7 @@ impl CommandExecutor for DatapackEnableExistingExecutor {
|
||||
}
|
||||
|
||||
let target = target_pack.clone();
|
||||
let existing = existing_pack.clone();
|
||||
let existing = existing_pack;
|
||||
let before_or_after = self.0;
|
||||
server.level_info.rcu(|level_info| {
|
||||
let mut new_info = (**level_info).clone();
|
||||
@@ -429,30 +405,25 @@ impl CommandExecutor for DatapackEnableExistingExecutor {
|
||||
error!("Failed to save world info: {err}");
|
||||
}
|
||||
|
||||
server.reload_datapacks(server).await;
|
||||
server.reload_datapacks(server);
|
||||
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_DATAPACK_MODIFY_ENABLE,
|
||||
translation::java::COMMANDS_DATAPACK_MODIFY_ENABLE,
|
||||
[format_pack(&target_pack)],
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
|
||||
Ok(server.level_info.load().data_packs.enabled.len() as i32)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct DatapackDisableExecutor;
|
||||
|
||||
impl CommandExecutor for DatapackDisableExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let name_str = StringArgumentType::get(context, "name")?;
|
||||
let server = context.server();
|
||||
|
||||
@@ -486,22 +457,18 @@ impl CommandExecutor for DatapackDisableExecutor {
|
||||
error!("Failed to save world info: {err}");
|
||||
}
|
||||
|
||||
server.reload_datapacks(server).await;
|
||||
server.reload_datapacks(server);
|
||||
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_DATAPACK_MODIFY_DISABLE,
|
||||
translation::java::COMMANDS_DATAPACK_MODIFY_DISABLE,
|
||||
[format_pack(&target_pack)],
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
|
||||
Ok(server.level_info.load().data_packs.enabled.len() as i32)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -518,8 +485,7 @@ fn is_valid_pack_name(name: &str) -> bool {
|
||||
struct DatapackCreateExecutor;
|
||||
|
||||
impl CommandExecutor for DatapackCreateExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let name_str = StringArgumentType::get(context, "name")?;
|
||||
let description = StringArgumentType::get(context, "description").unwrap_or(name_str);
|
||||
|
||||
@@ -567,20 +533,16 @@ impl CommandExecutor for DatapackCreateExecutor {
|
||||
.create_without_context(TextComponent::text(name_str.to_string())));
|
||||
}
|
||||
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_DATAPACK_CREATE_SUCCESS,
|
||||
translation::java::COMMANDS_DATAPACK_CREATE_SUCCESS,
|
||||
[TextComponent::text(name_str.to_string())],
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
|
||||
Ok(1)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,7 @@ const NOT_RUNNING_ERROR_TYPE: CommandErrorType<0> = CommandErrorType::new(
|
||||
struct DebugStartExecutor;
|
||||
|
||||
impl CommandExecutor for DebugStartExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let server = context.server();
|
||||
let current_tick = server.tick_count.load(Ordering::Relaxed);
|
||||
server.debug_profiler.start(current_tick).map_err(
|
||||
@@ -39,28 +38,23 @@ impl CommandExecutor for DebugStartExecutor {
|
||||
},
|
||||
)?;
|
||||
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_DEBUG_STARTED,
|
||||
translation::bedrock::COMMANDS_DEBUG_START,
|
||||
[],
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
|
||||
Ok(1)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct DebugStopExecutor;
|
||||
|
||||
impl CommandExecutor for DebugStopExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let server = context.server();
|
||||
let current_tick = server.tick_count.load(Ordering::Relaxed);
|
||||
let result = server.debug_profiler.stop(current_tick).map_err(
|
||||
@@ -89,10 +83,9 @@ impl CommandExecutor for DebugStopExecutor {
|
||||
result.ticks
|
||||
))
|
||||
};
|
||||
context.source.send_feedback(feedback, true).await;
|
||||
context.source.send_feedback(feedback, true);
|
||||
|
||||
Ok(result.command_result())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,13 +20,12 @@ pub struct DefaultGamemode {
|
||||
struct DefaultGamemodeExecutor;
|
||||
|
||||
impl CommandExecutor for DefaultGamemodeExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let Some(Arg::GameMode(gamemode)) = args.get_cloned(&ARG_GAMEMODE) else {
|
||||
return Err(InvalidConsumption(Some(ARG_GAMEMODE.into())));
|
||||
};
|
||||
@@ -34,7 +33,8 @@ impl CommandExecutor for DefaultGamemodeExecutor {
|
||||
let mut successful_changes: i32 = 0;
|
||||
if server.basic_config.force_gamemode {
|
||||
for player in server.get_all_players() {
|
||||
if player.set_gamemode(gamemode).await {
|
||||
if player.gamemode.load() != gamemode {
|
||||
player.set_gamemode(gamemode);
|
||||
successful_changes += 1;
|
||||
}
|
||||
}
|
||||
@@ -43,8 +43,7 @@ impl CommandExecutor for DefaultGamemodeExecutor {
|
||||
let gamemode_string = format!("{gamemode:?}").to_lowercase();
|
||||
let gamemode_string = format!("gameMode.{gamemode_string}");
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
pumpkin_data::translation::java::COMMANDS_DEFAULTGAMEMODE_SUCCESS,
|
||||
pumpkin_data::translation::bedrock::COMMANDS_DEFAULTGAMEMODE_SUCCESS,
|
||||
[TextComponent::translate_cross(
|
||||
@@ -52,14 +51,12 @@ impl CommandExecutor for DefaultGamemodeExecutor {
|
||||
gamemode_string,
|
||||
[],
|
||||
)],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
|
||||
//Change the default gamemode (not in configuration.toml)
|
||||
server.defaultgamemode.lock().await.gamemode = gamemode;
|
||||
server.defaultgamemode.lock().unwrap().gamemode = gamemode;
|
||||
|
||||
Ok(successful_changes)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,14 +21,13 @@ const ARG_TARGETS: &str = "targets";
|
||||
struct Executor;
|
||||
|
||||
impl CommandExecutor for Executor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
let mut config = server.data.operator_config.write().await;
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let mut config = server.data.operator_config.write().unwrap();
|
||||
|
||||
let Some(Arg::GameProfiles(targets)) = args.get(&ARG_TARGETS) else {
|
||||
return Err(InvalidConsumption(Some(ARG_TARGETS.into())));
|
||||
@@ -40,15 +39,15 @@ impl CommandExecutor for Executor {
|
||||
config.ops.remove(op_index);
|
||||
succeeded_deops += 1;
|
||||
|
||||
if let Some(player) = server.get_player_by_uuid(profile.id) {
|
||||
let command_dispatcher = server.command_dispatcher.load();
|
||||
player
|
||||
.set_permission_lvl(
|
||||
server,
|
||||
if let Some(player) = server.get_player_by_uuid(profile.id)
|
||||
&& let Some(server_arc) = player.world().server.upgrade()
|
||||
{
|
||||
let command_dispatcher = server_arc.command_dispatcher.load();
|
||||
player.set_permission_lvl(
|
||||
&server_arc,
|
||||
pumpkin_util::PermissionLvl::Zero,
|
||||
&command_dispatcher,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
}
|
||||
|
||||
let msg = TextComponent::translate_cross(
|
||||
@@ -56,7 +55,7 @@ impl CommandExecutor for Executor {
|
||||
pumpkin_data::translation::bedrock::COMMANDS_DEOP_SUCCESS,
|
||||
[TextComponent::text(profile.name.clone())],
|
||||
);
|
||||
sender.send_message(msg).await;
|
||||
sender.send_message(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +72,6 @@ impl CommandExecutor for Executor {
|
||||
} else {
|
||||
Ok(succeeded_deops)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,14 +21,13 @@ const ARG_DIALOG: &str = "dialog";
|
||||
struct DialogClearExecutor;
|
||||
|
||||
impl CommandExecutor for DialogClearExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
let targets = EntityArgumentType::get_players(context, ARG_TARGETS).await?;
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let targets = EntityArgumentType::get_players(context, ARG_TARGETS)?;
|
||||
|
||||
let count = targets.len();
|
||||
let packet = CPlayClearDialog::new();
|
||||
for player in &targets {
|
||||
player.send_client_packet(&packet).await;
|
||||
player.try_send_client_packet(&packet);
|
||||
}
|
||||
|
||||
let msg = if count == 1 {
|
||||
@@ -39,10 +38,9 @@ impl CommandExecutor for DialogClearExecutor {
|
||||
} else {
|
||||
TextComponent::text(format!("Cleared dialogs for {count} players"))
|
||||
};
|
||||
context.source.send_feedback(msg, true).await;
|
||||
context.source.send_feedback(msg, true);
|
||||
|
||||
Ok(count as i32)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,9 +51,8 @@ static REGISTRY_ERROR: LiteralCommandErrorType = LiteralCommandErrorType::new(
|
||||
struct DialogShowExecutor;
|
||||
|
||||
impl CommandExecutor for DialogShowExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
let targets = EntityArgumentType::get_players(context, ARG_TARGETS).await?;
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let targets = EntityArgumentType::get_players(context, ARG_TARGETS)?;
|
||||
let dialog_arg = DialogArgumentType::get(context, ARG_DIALOG)?;
|
||||
|
||||
match dialog_arg {
|
||||
@@ -65,24 +62,20 @@ impl CommandExecutor for DialogShowExecutor {
|
||||
let packet = CPlayShowDialog::new(IdOr::Value(dialog_nbt));
|
||||
|
||||
for player in &targets {
|
||||
player.send_client_packet(&packet).await;
|
||||
player.try_send_client_packet(&packet);
|
||||
}
|
||||
|
||||
let msg = if count == 1 {
|
||||
TextComponent::text(format!(
|
||||
"Showed dialog to {}",
|
||||
targets[0].gameprofile.name
|
||||
))
|
||||
TextComponent::text(format!("Showed dialog to {}", targets[0].gameprofile.name))
|
||||
} else {
|
||||
TextComponent::text(format!("Showed dialog to {count} players"))
|
||||
};
|
||||
context.source.send_feedback(msg, true).await;
|
||||
context.source.send_feedback(msg, true);
|
||||
|
||||
Ok(count as i32)
|
||||
}
|
||||
DialogArg::Id(_id) => Err(REGISTRY_ERROR.create_without_context()),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,13 +17,10 @@ const FAILURE_ERROR_TYPE: CommandErrorType<1> =
|
||||
struct DifficultyQueryExecutor;
|
||||
|
||||
impl CommandExecutor for DifficultyQueryExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let difficulty = context.server().get_difficulty();
|
||||
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
"commands.difficulty.query",
|
||||
"commands.difficulty.query",
|
||||
@@ -34,19 +31,16 @@ impl CommandExecutor for DifficultyQueryExecutor {
|
||||
)],
|
||||
),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
|
||||
Ok(difficulty as i32)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct DifficultySetExecutor(Difficulty);
|
||||
|
||||
impl CommandExecutor for DifficultySetExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let difficulty = self.0;
|
||||
let server = context.server();
|
||||
|
||||
@@ -61,9 +55,7 @@ impl CommandExecutor for DifficultySetExecutor {
|
||||
|
||||
server.set_difficulty(difficulty, true);
|
||||
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
pumpkin_data::translation::java::COMMANDS_DIFFICULTY_SUCCESS,
|
||||
pumpkin_data::translation::bedrock::COMMANDS_DIFFICULTY_SUCCESS,
|
||||
@@ -74,11 +66,9 @@ impl CommandExecutor for DifficultySetExecutor {
|
||||
)],
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
|
||||
Ok(0)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,13 +38,12 @@ enum Amplifier {
|
||||
struct GiveExecutor(Time, Amplifier, bool);
|
||||
|
||||
impl CommandExecutor for GiveExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
_server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
_server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let Some(Arg::Players(targets)) = args.get(ARG_TARGET) else {
|
||||
return Err(InvalidConsumption(Some(ARG_TARGET.into())));
|
||||
};
|
||||
@@ -120,41 +119,35 @@ impl CommandExecutor for GiveExecutor {
|
||||
[],
|
||||
)));
|
||||
} else if targets.len() == 1 {
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
"commands.effect.give.success.single",
|
||||
"commands.effect.give.success.single",
|
||||
[translation_name, targets[0].get_display_name()],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
} else {
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
"commands.effect.give.success.multiple",
|
||||
"commands.effect.give.success.multiple",
|
||||
[
|
||||
translation_name,
|
||||
TextComponent::text(targets.len().to_string()),
|
||||
],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
}
|
||||
|
||||
Ok(successes)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct ClearExecutor(bool); //the param -> true = delete every effect, false = only one
|
||||
|
||||
impl CommandExecutor for ClearExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
_server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
_server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let Some(Arg::Players(targets)) = args.get(ARG_TARGET) else {
|
||||
return Err(InvalidConsumption(Some(ARG_TARGET.into())));
|
||||
};
|
||||
@@ -164,7 +157,14 @@ impl CommandExecutor for ClearExecutor {
|
||||
if self.0 {
|
||||
let mut succeeded_clears: i32 = 0;
|
||||
for target in targets {
|
||||
if target.remove_all_effects().await {
|
||||
let has_effects = !target
|
||||
.living_entity
|
||||
.active_effects
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.is_empty();
|
||||
if has_effects {
|
||||
target.remove_all_effects();
|
||||
succeeded_clears += 1;
|
||||
}
|
||||
}
|
||||
@@ -179,21 +179,17 @@ impl CommandExecutor for ClearExecutor {
|
||||
}
|
||||
//a player have at least 1 effect
|
||||
else if targets.len() == 1 {
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
"commands.effect.clear.everything.success.single",
|
||||
"commands.effect.clear.everything.success.single",
|
||||
[targets[0].get_display_name()],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
} else {
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
"commands.effect.clear.everything.success.multiple",
|
||||
"commands.effect.clear.everything.success.multiple",
|
||||
[TextComponent::text(targets.len().to_string())],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
}
|
||||
Ok(succeeded_clears)
|
||||
} else {
|
||||
@@ -206,7 +202,7 @@ impl CommandExecutor for ClearExecutor {
|
||||
let mut succeeded_clears: i32 = 0;
|
||||
for target in targets {
|
||||
if target.living_entity.has_effect(effect) {
|
||||
target.remove_effect(effect).await;
|
||||
target.remove_effect(effect);
|
||||
succeeded_clears += 1;
|
||||
}
|
||||
}
|
||||
@@ -218,8 +214,7 @@ impl CommandExecutor for ClearExecutor {
|
||||
[],
|
||||
)));
|
||||
} else if targets.len() == 1 {
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
"commands.effect.clear.specific.success.single",
|
||||
"commands.effect.clear.specific.success.single",
|
||||
[
|
||||
@@ -230,11 +225,9 @@ impl CommandExecutor for ClearExecutor {
|
||||
),
|
||||
targets[0].get_display_name(),
|
||||
],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
} else {
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
"commands.effect.clear.specific.success.multiple",
|
||||
"commands.effect.clear.specific.success.multiple",
|
||||
[
|
||||
@@ -245,12 +238,10 @@ impl CommandExecutor for ClearExecutor {
|
||||
),
|
||||
TextComponent::text(targets.len().to_string()),
|
||||
],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
}
|
||||
Ok(succeeded_clears)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,13 +18,12 @@ const DESCRIPTION: &str = "Adds an enchantment to a player's selected item, subj
|
||||
struct Executor;
|
||||
|
||||
impl CommandExecutor for Executor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
_server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
_server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let targets = EntitiesArgumentConsumer.find_arg_default_name(args)?;
|
||||
let enchantment = EnchantmentArgumentConsumer.find_arg_default_name(args)?;
|
||||
let level = match enchantment_level_consumer().find_arg_default_name(args) {
|
||||
@@ -69,7 +68,7 @@ impl CommandExecutor for Executor {
|
||||
let mut successful_targets = 0;
|
||||
|
||||
if targets.len() == 1 {
|
||||
return match enchant_target(&targets[0], enchantment, level).await {
|
||||
return match enchant_target(&targets[0], enchantment, level) {
|
||||
Ok(()) => {
|
||||
let msg = TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_ENCHANT_SUCCESS_SINGLE,
|
||||
@@ -79,7 +78,7 @@ impl CommandExecutor for Executor {
|
||||
targets[0].get_display_name(),
|
||||
],
|
||||
);
|
||||
sender.send_message(msg).await;
|
||||
sender.send_message(msg);
|
||||
Ok(1)
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
@@ -87,7 +86,7 @@ impl CommandExecutor for Executor {
|
||||
}
|
||||
|
||||
for target in targets {
|
||||
if enchant_target(target, enchantment, level).await.is_ok() {
|
||||
if enchant_target(target, enchantment, level).is_ok() {
|
||||
successful_targets += 1;
|
||||
}
|
||||
}
|
||||
@@ -104,9 +103,8 @@ impl CommandExecutor for Executor {
|
||||
TextComponent::text(targets.len().to_string()),
|
||||
],
|
||||
);
|
||||
sender.send_message(msg).await;
|
||||
sender.send_message(msg);
|
||||
Ok(successful_targets)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +124,7 @@ fn commands_enchant_failed() -> CommandError {
|
||||
CommandError::CommandFailed(msg)
|
||||
}
|
||||
|
||||
async fn enchant_target(
|
||||
fn enchant_target(
|
||||
target: &Arc<dyn EntityBase>,
|
||||
enchantment: &'static Enchantment,
|
||||
level: i32,
|
||||
|
||||
@@ -31,11 +31,8 @@ static ERROR_INVALID_DIMENSION: CommandErrorType<1> =
|
||||
|
||||
static DIMENSION_REGISTRY: &Identifier = &Identifier::vanilla_static("dimension");
|
||||
|
||||
fn execute_as_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
let targets = EntityArgumentType::get_optional_entities(context, "targets").await?;
|
||||
fn execute_as_modifier(context: &CommandContext) -> crate::command::node::RedirectModifierResult {
|
||||
let targets = EntityArgumentType::get_optional_entities(context, "targets")?;
|
||||
let mut sources = Vec::new();
|
||||
for target in targets {
|
||||
let mut source = context.source.as_ref().clone();
|
||||
@@ -47,14 +44,10 @@ fn execute_as_modifier<'a>(
|
||||
sources.push(Arc::new(source));
|
||||
}
|
||||
Ok(sources)
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_at_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
let targets = EntityArgumentType::get_optional_entities(context, "targets").await?;
|
||||
fn execute_at_modifier(context: &CommandContext) -> crate::command::node::RedirectModifierResult {
|
||||
let targets = EntityArgumentType::get_optional_entities(context, "targets")?;
|
||||
let mut sources = Vec::new();
|
||||
for target in targets {
|
||||
let entity = target.get_entity();
|
||||
@@ -65,13 +58,9 @@ fn execute_at_modifier<'a>(
|
||||
sources.push(Arc::new(source));
|
||||
}
|
||||
Ok(sources)
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_in_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute_in_modifier(context: &CommandContext) -> crate::command::node::RedirectModifierResult {
|
||||
let dimension_key = ResourceKeyArgument::get_registry_key(
|
||||
context,
|
||||
"dimension",
|
||||
@@ -86,35 +75,28 @@ fn execute_in_modifier<'a>(
|
||||
.find(|w| w.dimension.minecraft_name == dimension_name);
|
||||
|
||||
target_world.map_or_else(
|
||||
|| {
|
||||
Err(ERROR_INVALID_DIMENSION
|
||||
.create_without_context(TextComponent::text(dimension_name)))
|
||||
},
|
||||
|| Err(ERROR_INVALID_DIMENSION.create_without_context(TextComponent::text(dimension_name))),
|
||||
|target_world| {
|
||||
let mut source = context.source.as_ref().clone();
|
||||
source.world = Some(target_world.clone());
|
||||
Ok(vec![Arc::new(source)])
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_positioned_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute_positioned_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let pos = Vec3ArgumentType::get_vector3(context, "pos")?;
|
||||
let mut source = context.source.as_ref().clone();
|
||||
source.position = pos;
|
||||
Ok(vec![Arc::new(source)])
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_positioned_as_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
let targets = EntityArgumentType::get_optional_entities(context, "targets").await?;
|
||||
fn execute_positioned_as_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let targets = EntityArgumentType::get_optional_entities(context, "targets")?;
|
||||
let mut sources = Vec::new();
|
||||
for target in targets {
|
||||
let mut source = context.source.as_ref().clone();
|
||||
@@ -122,26 +104,22 @@ fn execute_positioned_as_modifier<'a>(
|
||||
sources.push(Arc::new(source));
|
||||
}
|
||||
Ok(sources)
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_rotated_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute_rotated_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let rot_coords = RotationArgumentType::get(context, "rotation")?;
|
||||
let rot = rot_coords.rotation(&context.source);
|
||||
let mut source = context.source.as_ref().clone();
|
||||
source.rotation = rot;
|
||||
Ok(vec![Arc::new(source)])
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_rotated_as_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
let targets = EntityArgumentType::get_optional_entities(context, "targets").await?;
|
||||
fn execute_rotated_as_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let targets = EntityArgumentType::get_optional_entities(context, "targets")?;
|
||||
let mut sources = Vec::new();
|
||||
for target in targets {
|
||||
let entity = target.get_entity();
|
||||
@@ -150,39 +128,33 @@ fn execute_rotated_as_modifier<'a>(
|
||||
sources.push(Arc::new(source));
|
||||
}
|
||||
Ok(sources)
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_if_entity_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
let targets = EntityArgumentType::get_optional_entities(context, "targets").await?;
|
||||
fn execute_if_entity_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let targets = EntityArgumentType::get_optional_entities(context, "targets")?;
|
||||
if targets.is_empty() {
|
||||
Ok(vec![])
|
||||
} else {
|
||||
Ok(vec![context.source.clone()])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_unless_entity_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
let targets = EntityArgumentType::get_optional_entities(context, "targets").await?;
|
||||
fn execute_unless_entity_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let targets = EntityArgumentType::get_optional_entities(context, "targets")?;
|
||||
if targets.is_empty() {
|
||||
Ok(vec![context.source.clone()])
|
||||
} else {
|
||||
Ok(vec![])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_align_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute_align_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let axes = StringArgumentType::get(context, "axes")?;
|
||||
let mut source = context.source.as_ref().clone();
|
||||
|
||||
@@ -201,24 +173,20 @@ fn execute_align_modifier<'a>(
|
||||
}
|
||||
|
||||
Ok(vec![Arc::new(source)])
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_anchored_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute_anchored_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let anchor = EntityAnchorArgumentType::get(context, "anchor")?;
|
||||
let mut source = context.source.as_ref().clone();
|
||||
source.entity_anchor = anchor;
|
||||
Ok(vec![Arc::new(source)])
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_facing_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute_facing_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let pos = Vec3ArgumentType::get_vector3(context, "pos")?;
|
||||
let mut source = context.source.as_ref().clone();
|
||||
|
||||
@@ -232,14 +200,12 @@ fn execute_facing_modifier<'a>(
|
||||
|
||||
source.rotation = Vector2::new(yaw, pitch);
|
||||
Ok(vec![Arc::new(source)])
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_facing_entity_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
let targets = EntityArgumentType::get_optional_entities(context, "targets").await?;
|
||||
fn execute_facing_entity_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let targets = EntityArgumentType::get_optional_entities(context, "targets")?;
|
||||
let anchor = EntityAnchorArgumentType::get(context, "anchor")?;
|
||||
let mut sources = Vec::new();
|
||||
|
||||
@@ -259,13 +225,11 @@ fn execute_facing_entity_modifier<'a>(
|
||||
sources.push(Arc::new(source));
|
||||
}
|
||||
Ok(sources)
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_if_block_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute_if_block_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let pos = BlockPosArgumentType::get_block_pos(context, "pos")?;
|
||||
let expected_block = BlockArgumentType::get(context, "block")?;
|
||||
|
||||
@@ -276,13 +240,11 @@ fn execute_if_block_modifier<'a>(
|
||||
}
|
||||
}
|
||||
Ok(vec![])
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_unless_block_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute_unless_block_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let pos = BlockPosArgumentType::get_block_pos(context, "pos")?;
|
||||
let expected_block = BlockArgumentType::get(context, "block")?;
|
||||
|
||||
@@ -295,13 +257,11 @@ fn execute_unless_block_modifier<'a>(
|
||||
return Ok(vec![context.source.clone()]);
|
||||
}
|
||||
Ok(vec![])
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_if_loaded_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute_if_loaded_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let pos = BlockPosArgumentType::get_block_pos(context, "pos")?;
|
||||
|
||||
if let Some(ref world) = context.source.world
|
||||
@@ -310,13 +270,11 @@ fn execute_if_loaded_modifier<'a>(
|
||||
return Ok(vec![context.source.clone()]);
|
||||
}
|
||||
Ok(vec![])
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_unless_loaded_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute_unless_loaded_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let pos = BlockPosArgumentType::get_block_pos(context, "pos")?;
|
||||
|
||||
if let Some(ref world) = context.source.world {
|
||||
@@ -327,13 +285,11 @@ fn execute_unless_loaded_modifier<'a>(
|
||||
return Ok(vec![context.source.clone()]);
|
||||
}
|
||||
Ok(vec![])
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_if_dimension_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute_if_dimension_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let dimension_key = ResourceKeyArgument::get_registry_key(
|
||||
context,
|
||||
"dimension",
|
||||
@@ -348,13 +304,11 @@ fn execute_if_dimension_modifier<'a>(
|
||||
return Ok(vec![context.source.clone()]);
|
||||
}
|
||||
Ok(vec![])
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_unless_dimension_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute_unless_dimension_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let dimension_key = ResourceKeyArgument::get_registry_key(
|
||||
context,
|
||||
"dimension",
|
||||
@@ -371,13 +325,11 @@ fn execute_unless_dimension_modifier<'a>(
|
||||
return Ok(vec![context.source.clone()]);
|
||||
}
|
||||
Ok(vec![])
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_summon_modifier<'a>(
|
||||
context: &'a CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute_summon_modifier(
|
||||
context: &CommandContext,
|
||||
) -> crate::command::node::RedirectModifierResult {
|
||||
let entity_type = ResourceArgument::get_summonable_entity_type(context, "entity_type")?;
|
||||
let entity = from_type(
|
||||
entity_type,
|
||||
@@ -389,7 +341,6 @@ fn execute_summon_modifier<'a>(
|
||||
let mut source = context.source.as_ref().clone();
|
||||
source.entity = Some(entity);
|
||||
Ok(vec![Arc::new(source)])
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
|
||||
@@ -45,7 +45,7 @@ struct Executor {
|
||||
}
|
||||
|
||||
impl Executor {
|
||||
async fn handle_query(&self, sender: &CommandSender, target: &Player) -> i32 {
|
||||
fn handle_query(&self, sender: &CommandSender, target: &Player) -> i32 {
|
||||
let (val, translation_key) = match self.exp_type {
|
||||
ExpType::Levels => (
|
||||
target.experience_level.load(Ordering::Relaxed),
|
||||
@@ -57,16 +57,14 @@ impl Executor {
|
||||
),
|
||||
};
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation_key,
|
||||
translation_key,
|
||||
[
|
||||
target.get_display_name(),
|
||||
TextComponent::text(val.to_string()),
|
||||
],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
|
||||
val
|
||||
}
|
||||
@@ -122,7 +120,7 @@ impl Executor {
|
||||
}
|
||||
|
||||
/// Returns `true` if successful. Otherwise, there was a problem setting the points of a player.
|
||||
async fn handle_modify(&self, target: &Arc<Player>, amount: i32) -> bool {
|
||||
fn handle_modify(&self, target: &Arc<Player>, amount: i32) -> bool {
|
||||
match self.exp_type {
|
||||
ExpType::Levels => {
|
||||
if self.mode == Mode::Add {
|
||||
@@ -148,13 +146,12 @@ impl Executor {
|
||||
}
|
||||
|
||||
impl CommandExecutor for Executor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
_server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
_server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let targets = PlayersArgumentConsumer::find_arg(args, ARG_TARGETS)?;
|
||||
|
||||
if self.mode == Mode::Query {
|
||||
@@ -173,7 +170,7 @@ impl CommandExecutor for Executor {
|
||||
[],
|
||||
)));
|
||||
}
|
||||
return Ok(self.handle_query(sender, target).await);
|
||||
return Ok(self.handle_query(sender, target));
|
||||
}
|
||||
|
||||
// Handle Add/Set
|
||||
@@ -181,7 +178,7 @@ impl CommandExecutor for Executor {
|
||||
|
||||
let mut successes = 0;
|
||||
for target in targets {
|
||||
if self.handle_modify(target, amount).await {
|
||||
if self.handle_modify(target, amount) {
|
||||
successes += 1;
|
||||
}
|
||||
}
|
||||
@@ -197,10 +194,9 @@ impl CommandExecutor for Executor {
|
||||
// Safe to access first() because successes > 0
|
||||
let first_name = targets[0].get_display_name();
|
||||
let msg = self.get_success_message(amount, targets, first_name);
|
||||
sender.send_message(msg).await;
|
||||
sender.send_message(msg);
|
||||
|
||||
Ok(successes)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ fn format_clickable_list(items: Vec<TextComponent>) -> TextComponent {
|
||||
root
|
||||
}
|
||||
|
||||
async fn report_resolved_profile(
|
||||
fn report_resolved_profile(
|
||||
source: &CommandSource,
|
||||
profile: &GameProfile,
|
||||
message_id: &'static str,
|
||||
@@ -139,7 +139,7 @@ async fn report_resolved_profile(
|
||||
|
||||
let msg = TextComponent::translate_cross(message_id, message_id, [argument, clickable]);
|
||||
|
||||
source.send_feedback(msg, false).await;
|
||||
source.send_feedback(msg, false);
|
||||
}
|
||||
|
||||
async fn fetch_profile_by_name_helper(server: &Server, name: &str) -> Option<GameProfile> {
|
||||
@@ -147,7 +147,7 @@ async fn fetch_profile_by_name_helper(server: &Server, name: &str) -> Option<Gam
|
||||
return Some(player.gameprofile.clone());
|
||||
}
|
||||
|
||||
let cached_entry = server.data.user_cache.write().await.get_by_name(name);
|
||||
let cached_entry = server.data.user_cache.write().unwrap().get_by_name(name);
|
||||
|
||||
let auth_config = server
|
||||
.advanced_config
|
||||
@@ -169,7 +169,7 @@ async fn fetch_profile_by_name_helper(server: &Server, name: &str) -> Option<Gam
|
||||
.data
|
||||
.user_cache
|
||||
.write()
|
||||
.await
|
||||
.unwrap()
|
||||
.upsert(uuid, resolved_name.clone());
|
||||
let auth_config_clone = server
|
||||
.advanced_config
|
||||
@@ -214,7 +214,7 @@ async fn fetch_profile_by_name_helper(server: &Server, name: &str) -> Option<Gam
|
||||
.data
|
||||
.user_cache
|
||||
.write()
|
||||
.await
|
||||
.unwrap()
|
||||
.upsert(uuid, name.to_string());
|
||||
return Some(profile);
|
||||
}
|
||||
@@ -244,12 +244,12 @@ async fn fetch_profile_by_id_helper(server: &Server, id: Uuid) -> Option<GamePro
|
||||
.data
|
||||
.user_cache
|
||||
.write()
|
||||
.await
|
||||
.unwrap()
|
||||
.upsert(profile.id, profile.name.clone());
|
||||
return Some(profile);
|
||||
}
|
||||
|
||||
let cached_entry = server.data.user_cache.write().await.get_by_uuid(id);
|
||||
let cached_entry = server.data.user_cache.write().unwrap().get_by_uuid(id);
|
||||
if let Some(entry) = cached_entry {
|
||||
return Some(GameProfile {
|
||||
id: entry.uuid,
|
||||
@@ -265,102 +265,84 @@ async fn fetch_profile_by_id_helper(server: &Server, id: Uuid) -> Option<GamePro
|
||||
struct ResolveNameExecutor;
|
||||
|
||||
impl CommandExecutor for ResolveNameExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let name = StringArgumentType::get(context, ARG_NAME)?;
|
||||
let server = context.server().clone();
|
||||
let source = context.source.clone();
|
||||
let server = context.server();
|
||||
let name_owned = name.to_string();
|
||||
|
||||
tokio::spawn(async move {
|
||||
let name_component = TextComponent::text(name_owned.clone());
|
||||
let result = fetch_profile_by_name_helper(&server, &name_owned).await;
|
||||
let result = futures::executor::block_on(fetch_profile_by_name_helper(server, &name_owned));
|
||||
match result {
|
||||
Some(profile) => {
|
||||
report_resolved_profile(
|
||||
&source,
|
||||
&context.source,
|
||||
&profile,
|
||||
translation::java::COMMANDS_FETCHPROFILE_NAME_SUCCESS,
|
||||
name_component,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
}
|
||||
None => {
|
||||
source
|
||||
.send_error(TextComponent::translate_cross(
|
||||
context.source.send_error(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_FETCHPROFILE_NAME_FAILURE,
|
||||
translation::java::COMMANDS_FETCHPROFILE_NAME_FAILURE,
|
||||
[name_component],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(1)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct ResolveIdExecutor;
|
||||
|
||||
impl CommandExecutor for ResolveIdExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let id = UuidArgumentType::get(context, ARG_ID)?;
|
||||
let server = context.server().clone();
|
||||
let source = context.source.clone();
|
||||
let server = context.server();
|
||||
|
||||
tokio::spawn(async move {
|
||||
let id_component = TextComponent::text(id.to_string());
|
||||
let result = fetch_profile_by_id_helper(&server, id).await;
|
||||
let result = futures::executor::block_on(fetch_profile_by_id_helper(server, id));
|
||||
match result {
|
||||
Some(profile) => {
|
||||
report_resolved_profile(
|
||||
&source,
|
||||
&context.source,
|
||||
&profile,
|
||||
translation::java::COMMANDS_FETCHPROFILE_ID_SUCCESS,
|
||||
id_component,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
}
|
||||
None => {
|
||||
source
|
||||
.send_error(TextComponent::translate_cross(
|
||||
context.source.send_error(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_FETCHPROFILE_ID_FAILURE,
|
||||
translation::java::COMMANDS_FETCHPROFILE_ID_FAILURE,
|
||||
[id_component],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(1)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct PrintForEntityExecutor;
|
||||
|
||||
impl CommandExecutor for PrintForEntityExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
let entity = EntityArgumentType::get_entity(context, ARG_ENTITY).await?;
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let entity = EntityArgumentType::get_entity(context, ARG_ENTITY)?;
|
||||
|
||||
if let Some(player) = entity.get_player() {
|
||||
entity.get_player().map_or_else(
|
||||
|| Err(NO_PROFILE_ERROR_TYPE.create_without_context(entity.get_display_name())),
|
||||
|player| {
|
||||
report_resolved_profile(
|
||||
&context.source,
|
||||
&player.gameprofile,
|
||||
translation::java::COMMANDS_FETCHPROFILE_ENTITY_SUCCESS,
|
||||
player.get_display_name(),
|
||||
)
|
||||
.await;
|
||||
);
|
||||
Ok(1)
|
||||
} else {
|
||||
Err(NO_PROFILE_ERROR_TYPE.create_without_context(entity.get_display_name()))
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -236,13 +236,12 @@ impl Filler for StrictFiller {
|
||||
}
|
||||
|
||||
impl CommandExecutor for Executor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let block = BlockArgumentConsumer::find_arg(args, ARG_BLOCK)?;
|
||||
let block_state_id = block.default_state.id;
|
||||
let from = BlockPosArgumentConsumer::find_arg(args, ARG_FROM)?;
|
||||
@@ -316,16 +315,13 @@ impl CommandExecutor for Executor {
|
||||
)));
|
||||
}
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_FILL_SUCCESS,
|
||||
translation::bedrock::COMMANDS_FILL_SUCCESS,
|
||||
[TextComponent::text(context.placed_blocks.to_string())],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
|
||||
Ok(context.placed_blocks)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,7 @@ struct FillBiomeExecutor {
|
||||
|
||||
impl CommandExecutor for FillBiomeExecutor {
|
||||
#[expect(clippy::too_many_lines)]
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let from_pos = BlockPosArgumentType::get_block_pos(context, "from")?;
|
||||
let to_pos = BlockPosArgumentType::get_block_pos(context, "to")?;
|
||||
|
||||
@@ -93,12 +92,12 @@ impl CommandExecutor for FillBiomeExecutor {
|
||||
|
||||
let target_biome_id = target_biome.id;
|
||||
let replace_biome_id = replace_biome.map(|b| b.id);
|
||||
let mut changed_count = 0;
|
||||
let world = context.world().clone();
|
||||
|
||||
let mut changed_count = 0;
|
||||
for (chunk_pos, mods) in chunk_modifications {
|
||||
let (has_replaced, count) = world
|
||||
.level
|
||||
.get_or_fetch_chunk(chunk_pos, |chunk| {
|
||||
let (has_replaced, count) =
|
||||
futures::executor::block_on(world.level.get_or_fetch_chunk(chunk_pos, |chunk| {
|
||||
let mut local_count = 0;
|
||||
let mut modified = false;
|
||||
for &(rel_x, rel_y, rel_z) in &mods {
|
||||
@@ -133,15 +132,15 @@ impl CommandExecutor for FillBiomeExecutor {
|
||||
}
|
||||
}
|
||||
(modified, local_count)
|
||||
})
|
||||
.await;
|
||||
}));
|
||||
|
||||
if has_replaced {
|
||||
changed_count += count;
|
||||
let chunk = world
|
||||
let chunk = futures::executor::block_on(
|
||||
world
|
||||
.level
|
||||
.get_or_fetch_chunk(chunk_pos, std::clone::Clone::clone)
|
||||
.await;
|
||||
.get_or_fetch_chunk(chunk_pos, std::clone::Clone::clone),
|
||||
);
|
||||
world.broadcast_to_chunk_except(chunk_pos, &[], &CChunkData(&chunk));
|
||||
}
|
||||
}
|
||||
@@ -151,10 +150,9 @@ impl CommandExecutor for FillBiomeExecutor {
|
||||
translation::java::COMMANDS_FILLBIOME_SUCCESS_COUNT,
|
||||
[TextComponent::text(changed_count.to_string())],
|
||||
);
|
||||
context.source.send_feedback(msg, true).await;
|
||||
context.source.send_feedback(msg, true);
|
||||
|
||||
Ok(changed_count)
|
||||
})
|
||||
Ok(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,8 +35,7 @@ static ERROR_TOO_MANY: CommandErrorType<2> = CommandErrorType::new(
|
||||
struct ForceloadAddExecutor;
|
||||
|
||||
impl CommandExecutor for ForceloadAddExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let from_pos = ColumnPosArgumentType::get_column_pos(context, "from")?;
|
||||
|
||||
let to_pos = if context.get_argument::<Coordinates>("to").is_ok() {
|
||||
@@ -111,19 +110,16 @@ impl CommandExecutor for ForceloadAddExecutor {
|
||||
};
|
||||
context
|
||||
.source
|
||||
.send_feedback(text.color(Color::Named(NamedColor::Green)), false)
|
||||
.await;
|
||||
.send_feedback(text.color(Color::Named(NamedColor::Green)), false);
|
||||
|
||||
Ok(total_chunks)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct ForceloadRemoveExecutor;
|
||||
|
||||
impl CommandExecutor for ForceloadRemoveExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let from_pos = ColumnPosArgumentType::get_column_pos(context, "from")?;
|
||||
|
||||
let to_pos = if context.get_argument::<Coordinates>("to").is_ok() {
|
||||
@@ -198,19 +194,16 @@ impl CommandExecutor for ForceloadRemoveExecutor {
|
||||
};
|
||||
context
|
||||
.source
|
||||
.send_feedback(text.color(Color::Named(NamedColor::Green)), false)
|
||||
.await;
|
||||
.send_feedback(text.color(Color::Named(NamedColor::Green)), false);
|
||||
|
||||
Ok(total_chunks)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct ForceloadRemoveAllExecutor;
|
||||
|
||||
impl CommandExecutor for ForceloadRemoveAllExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let world = context
|
||||
.source
|
||||
.world
|
||||
@@ -236,19 +229,16 @@ impl CommandExecutor for ForceloadRemoveAllExecutor {
|
||||
);
|
||||
context
|
||||
.source
|
||||
.send_feedback(text.color(Color::Named(NamedColor::Green)), false)
|
||||
.await;
|
||||
.send_feedback(text.color(Color::Named(NamedColor::Green)), false);
|
||||
|
||||
Ok(removed_count as i32)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct ForceloadQueryExecutor;
|
||||
|
||||
impl CommandExecutor for ForceloadQueryExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let world = context
|
||||
.source
|
||||
.world
|
||||
@@ -283,8 +273,7 @@ impl CommandExecutor for ForceloadQueryExecutor {
|
||||
);
|
||||
context
|
||||
.source
|
||||
.send_feedback(text.color(Color::Named(NamedColor::Green)), false)
|
||||
.await;
|
||||
.send_feedback(text.color(Color::Named(NamedColor::Green)), false);
|
||||
} else {
|
||||
let text = TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_FORCELOAD_QUERY_FAILURE,
|
||||
@@ -296,8 +285,7 @@ impl CommandExecutor for ForceloadQueryExecutor {
|
||||
);
|
||||
context
|
||||
.source
|
||||
.send_feedback(text.color(Color::Named(NamedColor::Red)), false)
|
||||
.await;
|
||||
.send_feedback(text.color(Color::Named(NamedColor::Red)), false);
|
||||
}
|
||||
|
||||
let all_forced = {
|
||||
@@ -319,8 +307,7 @@ impl CommandExecutor for ForceloadQueryExecutor {
|
||||
);
|
||||
context
|
||||
.source
|
||||
.send_feedback(text.color(Color::Named(NamedColor::Gray)), false)
|
||||
.await;
|
||||
.send_feedback(text.color(Color::Named(NamedColor::Gray)), false);
|
||||
} else {
|
||||
let list_str = all_forced.join(", ");
|
||||
let text = if all_forced.len() == 1 {
|
||||
@@ -338,12 +325,10 @@ impl CommandExecutor for ForceloadQueryExecutor {
|
||||
};
|
||||
context
|
||||
.source
|
||||
.send_feedback(text.color(Color::Named(NamedColor::Gray)), false)
|
||||
.await;
|
||||
.send_feedback(text.color(Color::Named(NamedColor::Gray)), false);
|
||||
}
|
||||
|
||||
Ok(i32::from(is_forced))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,43 +23,38 @@ static ERROR_UNKNOWN_FUNCTION: CommandErrorType<1> = CommandErrorType::new(
|
||||
struct FunctionSuggestionProvider;
|
||||
|
||||
impl SuggestionProvider for FunctionSuggestionProvider {
|
||||
fn suggest<'a>(
|
||||
&'a self,
|
||||
context: &'a CommandContext,
|
||||
fn suggest(
|
||||
&self,
|
||||
context: &CommandContext,
|
||||
mut builder: SuggestionsBuilder,
|
||||
) -> SuggestionProviderResult<'a> {
|
||||
Box::pin(async move {
|
||||
) -> SuggestionProviderResult {
|
||||
let server = context.server();
|
||||
let function_names = server.datapack_manager.get_function_names().await;
|
||||
let function_names = server.datapack_manager.get_function_names();
|
||||
for name in function_names {
|
||||
builder = builder.suggest(name);
|
||||
}
|
||||
builder.build()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct FunctionExecutor;
|
||||
|
||||
impl CommandExecutor for FunctionExecutor {
|
||||
fn execute<'a>(&'a self, context: &'a CommandContext) -> CommandExecutorResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(&self, context: &CommandContext) -> CommandExecutorResult {
|
||||
let name_str = StringArgumentType::get(context, "name")?;
|
||||
let server = context.server();
|
||||
|
||||
let Ok(executed_count) = server
|
||||
let Ok(executed_count) =
|
||||
server
|
||||
.datapack_manager
|
||||
.execute_function(server, &context.source, name_str)
|
||||
.await
|
||||
else {
|
||||
return Err(ERROR_UNKNOWN_FUNCTION
|
||||
.create_without_context(TextComponent::text(name_str.to_string())));
|
||||
};
|
||||
|
||||
if name_str.starts_with('#') {
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_FUNCTION_SUCCESS_MULTIPLE,
|
||||
translation::java::COMMANDS_FUNCTION_SUCCESS_MULTIPLE,
|
||||
@@ -69,12 +64,9 @@ impl CommandExecutor for FunctionExecutor {
|
||||
],
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
} else {
|
||||
context
|
||||
.source
|
||||
.send_feedback(
|
||||
context.source.send_feedback(
|
||||
TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_FUNCTION_SUCCESS_SINGLE,
|
||||
translation::java::COMMANDS_FUNCTION_SUCCESS_SINGLE,
|
||||
@@ -84,12 +76,10 @@ impl CommandExecutor for FunctionExecutor {
|
||||
],
|
||||
),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
);
|
||||
}
|
||||
|
||||
Ok(executed_count as i32)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,13 +25,12 @@ struct TargetExecutor {
|
||||
}
|
||||
|
||||
impl CommandExecutor for TargetExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let Some(Arg::GameMode(gamemode)) = args.get_cloned(&ARG_GAMEMODE) else {
|
||||
return Err(InvalidConsumption(Some(ARG_GAMEMODE.into())));
|
||||
};
|
||||
@@ -50,7 +49,8 @@ impl CommandExecutor for TargetExecutor {
|
||||
|
||||
let mut succeeded: i32 = 0;
|
||||
for target in targets {
|
||||
if target.set_gamemode(gamemode).await {
|
||||
if target.gamemode.load() != gamemode {
|
||||
target.set_gamemode(gamemode);
|
||||
succeeded += 1;
|
||||
let gamemode_string = format!("{gamemode:?}").to_lowercase();
|
||||
let gamemode_string = format!("gameMode.{gamemode_string}");
|
||||
@@ -61,36 +61,29 @@ impl CommandExecutor for TargetExecutor {
|
||||
[],
|
||||
);
|
||||
if sender.as_player().as_ref() == Some(target) {
|
||||
target
|
||||
.send_system_message(&TextComponent::translate_cross(
|
||||
target.send_system_message(&TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_GAMEMODE_SUCCESS_SELF,
|
||||
translation::bedrock::COMMANDS_GAMEMODE_SUCCESS_SELF,
|
||||
[gamemode_comp],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
} else {
|
||||
if server.level_info.load().game_rules.send_command_feedback {
|
||||
target
|
||||
.send_system_message(&TextComponent::translate_cross(
|
||||
target.send_system_message(&TextComponent::translate_cross(
|
||||
translation::java::GAMEMODE_CHANGED,
|
||||
translation::bedrock::GAMEMODE_CHANGED,
|
||||
[gamemode_comp.clone()],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
}
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
translation::java::COMMANDS_GAMEMODE_SUCCESS_OTHER,
|
||||
translation::bedrock::COMMANDS_GAMEMODE_SUCCESS_OTHER,
|
||||
[target.get_display_name(), gamemode_comp],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(succeeded)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,35 +20,29 @@ const ARG_NAME: &str = "value";
|
||||
struct QueryExecutor(GameRule);
|
||||
|
||||
impl CommandExecutor for QueryExecutor {
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a crate::server::Server,
|
||||
_args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
_args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let key = TextComponent::text(self.0.to_string());
|
||||
let level_info = server.level_info.load();
|
||||
let game_rule = level_info.game_rules.get(&self.0);
|
||||
let game_rule_i32_value = match game_rule {
|
||||
GameRuleValue::Int(value) => {
|
||||
(*value).clamp(i32::MIN as i64, i32::MAX as i64) as i32
|
||||
}
|
||||
GameRuleValue::Int(value) => (*value).clamp(i32::MIN as i64, i32::MAX as i64) as i32,
|
||||
GameRuleValue::Bool(value) => *value as i32,
|
||||
};
|
||||
let value = TextComponent::text(game_rule.to_string());
|
||||
drop(level_info);
|
||||
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
"commands.gamerule.query",
|
||||
"commands.gamerule.query",
|
||||
[key, value],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
|
||||
Ok(game_rule_i32_value)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,13 +50,12 @@ struct SetExecutor(GameRule);
|
||||
|
||||
impl CommandExecutor for SetExecutor {
|
||||
#[expect(unused)]
|
||||
fn execute<'a>(
|
||||
&'a self,
|
||||
sender: &'a CommandSender,
|
||||
server: &'a crate::server::Server,
|
||||
args: &'a ConsumedArgs<'a>,
|
||||
) -> CommandResult<'a> {
|
||||
Box::pin(async move {
|
||||
fn execute(
|
||||
&self,
|
||||
sender: &CommandSender,
|
||||
server: &crate::server::Server,
|
||||
args: &ConsumedArgs,
|
||||
) -> CommandResult {
|
||||
let key = TextComponent::text(self.0.to_string());
|
||||
let current_info = server.level_info.load();
|
||||
|
||||
@@ -93,16 +86,13 @@ impl CommandExecutor for SetExecutor {
|
||||
server.level_info.store(std::sync::Arc::new(new_info));
|
||||
|
||||
let value_component = TextComponent::text(output_value);
|
||||
sender
|
||||
.send_message(TextComponent::translate_cross(
|
||||
sender.send_message(TextComponent::translate_cross(
|
||||
"commands.gamerule.set",
|
||||
"commands.gamerule.set",
|
||||
[key, value_component],
|
||||
))
|
||||
.await;
|
||||
));
|
||||
|
||||
Ok(result_i32)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loaded 100 of 222 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user