Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some random fixes + README update #71

Merged
merged 7 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ server_context = "global"
| `/speed [speed]` | None | Sets your flyspeed. |
| `/gamemode [mode]` | `/gmc`, `/gmsp` | Sets your gamemode. |
| `/container [type] [power]` | None | Gives you a container (e.g. barrel) which outputs a specified amount of power when used with a comparator. |
| `/redpiler compile` | `/rp c` | Manually starts redpiler compilation. Available flags: --io-only --optimize --export (or in short: -I -O -E) |
| `/redpiler reset` | `/rp r` | Stops redpiler. |
| `/toggleautorp` | None | Toggles automatic redpiler compilation. |
| `/stop` | None | Stops the server. |

### Plot Ownership
Expand All @@ -83,7 +86,7 @@ These are the commands that are currently implemented:
| `/plot auto` | `/p a` | Automatically finds an unclaimed plot and claims. |
| `/plot middle` | None | Teleports you to the center of the plot you are in. |
| `/plot visit [player]` | `/p v` | Teleports you to a player's plot. |
| `/plot tp [x] [z]` | `/p v` | Teleports you to the plot at `[x] [y]`. Supports relative coordinates. |
| `/plot tp [x] [z]` | None | Teleports you to the plot at `[x] [y]`. Supports relative coordinates. |
| `/plot lock` | None | Locks the player into the plot so moving outside of the plot bounds does not transfer you to other plots. |
| `/plot unlock` | None | Reverses the locking done by `/plot lock`. |

Expand All @@ -105,7 +108,7 @@ These are the commands that are currently implemented:
| `//paste` | `//v` | Paste the clipboard's contents |
| `//undo` | None | Undoes the last action (from history) |
| `//redo` | None | Redoes the last action (from history) |
| `//rstack` | None | Stack with more options, Refer to [RedstoneTools](https://github.com/paulikauro/RedstoneTools) |
| `//rstack` | `//rs` | Stack with more options, Refer to [RedstoneTools](https://github.com/paulikauro/RedstoneTools) |
| `//stack` | `//s` | Repeat the contents of the selection |
| `//move` | None | Move the contents of the selection |
| `//count` | None | Counts the number of blocks matching a mask |
Expand Down
2 changes: 1 addition & 1 deletion benches/chungus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn init_compiler() -> (PlotWorld, Compiler) {
let mut compiler: Compiler = Default::default();

let options = CompilerOptions::parse("-O");
compiler.compile(&mut world, options, None, None, Vec::new());
compiler.compile(&mut world, options, Vec::new());
compiler.on_use_block(&mut world, START_BUTTON);
(world, compiler)
}
Expand Down
8 changes: 4 additions & 4 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ pub enum ChatColor {
#[serde(rename_all = "snake_case")]
enum ClickEventType {
OpenUrl,
RunCommand,
SuggestCommand,
// RunCommand,
// SuggestCommand,
StackDoubleFlow marked this conversation as resolved.
Show resolved Hide resolved
}

#[derive(Serialize, Debug, Clone)]
Expand Down Expand Up @@ -116,10 +116,10 @@ impl ChatComponentBuilder {
Self { component }
}

pub fn color(mut self, color: ChatColor) -> Self {
/* pub fn color(mut self, color: ChatColor) -> Self {
self.component.color = Some(color);
self
}
} */

StackDoubleFlow marked this conversation as resolved.
Show resolved Hide resolved
pub fn color_code(mut self, color: ColorCode) -> Self {
self.component.color = Some(ChatColor::ColorCode(color));
Expand Down
6 changes: 4 additions & 2 deletions src/items.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use serde::{Deserialize, Serialize};

use crate::blocks::{Block, BlockColorVariant, BlockDirection, BlockFace, BlockPos, ContainerType};
use crate::config::CONFIG;
use crate::network::packets::clientbound::{COpenSignEditor, ClientBoundPacket};
use crate::plot::Plot;
use crate::world::World;
use crate::config::CONFIG;

#[derive(PartialEq, Eq, Copy, Clone)]
pub enum ActionResult {
Expand Down Expand Up @@ -102,7 +102,9 @@ impl ItemStack {
let block_pos = context.block_pos.offset(context.block_face);
let mut top_pos = plot.players[context.player_idx].pos.block_pos();
top_pos.y += 1;
if (block_pos == plot.players[context.player_idx].pos.block_pos() || block_pos == top_pos) && !CONFIG.block_in_hitbox {
if (block_pos == plot.players[context.player_idx].pos.block_pos() || block_pos == top_pos)
&& !CONFIG.block_in_hitbox
{
return false;
}
let can_place =
Expand Down
13 changes: 13 additions & 0 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ impl Player {
self.send_keep_alive();
}

// Prevent from locking player position at Infinity or NaN
if !self.pos.x.is_finite() || !self.pos.y.is_finite() || !self.pos.z.is_finite() {
self.pos.x = 128.0;
self.pos.y = 128.0;
self.pos.z = 128.0;
}

let (chunk_x, chunk_z) = self.pos.chunk_pos();
chunk_x != self.last_chunk_x || chunk_z != self.last_chunk_z
}
Expand Down Expand Up @@ -357,6 +364,12 @@ impl Player {
}

pub fn teleport(&mut self, pos: PlayerPos) {
// Prevent from teleporting to Infinity or NaN
if !pos.x.is_finite() || !pos.y.is_finite() || !pos.z.is_finite() {
self.send_error_message("We just saved you from a game crash, don't try it again!");
return;
}

let player_position_and_look = CPlayerPositionAndLook {
x: pos.x,
y: pos.y,
Expand Down
26 changes: 23 additions & 3 deletions src/plot/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,11 @@ impl Plot {
"/toggleautorp" => {
self.auto_redpiler = !self.auto_redpiler;
if self.auto_redpiler {
self.players[player].send_system_message("Automatic redpiler compilation has been enabled.");
self.players[player]
.send_system_message("Automatic redpiler compilation has been enabled.");
} else {
self.players[player].send_system_message("Automatic redpiler compilation has been disabled.");
self.players[player]
.send_system_message("Automatic redpiler compilation has been disabled.");
}
}
"/teleport" | "/tp" => {
Expand Down Expand Up @@ -399,7 +401,18 @@ impl Plot {
if let Ok(speed_arg) = args[0].parse::<f32>() {
if speed_arg < 0.0 {
self.players[player]
.send_error_message("Silly child, you can't have a negative flyspeed");
.send_error_message("Silly child, you can't have a negative flyspeed!");
return false;
}
if speed_arg > 10.0 {
self.players[player].send_error_message(
"For performance reasons player speed cannot be higher than 10.",
);
return false;
}
if speed_arg.is_nan() {
self.players[player]
.send_error_message("You can't set your speed to NaN or -NaN.");
return false;
}
self.players[player].fly_speed = speed_arg;
Expand Down Expand Up @@ -454,6 +467,13 @@ impl Plot {
}
};

if power > 15 || power < 1 {
self.players[player].send_error_message(
"Container power must be greater than 0 and lower than 15!",
);
return false;
}

let item = ItemStack::container_with_ss(container_ty, power);
let slot = 36 + self.players[player].selected_slot;
self.players[player].set_inventory_slot(slot, Some(item));
Expand Down
10 changes: 6 additions & 4 deletions src/plot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub struct Plot {
/// If true, the plot will remain running even if no players are on for a long time.
always_running: bool,
auto_redpiler: bool,

owner: Option<u128>,
async_rt: Runtime,
scoreboard: Scoreboard,
Expand Down Expand Up @@ -790,7 +790,10 @@ impl Plot {
self.last_update_time = Instant::now();
let mut ticks = 0;
while self.lag_time >= dur_per_tick {
if self.timings.is_running_behind() && !self.redpiler.is_active() && self.auto_redpiler {
if self.timings.is_running_behind()
&& !self.redpiler.is_active()
&& self.auto_redpiler
{
self.start_redpiler(Default::default());
}
self.tick();
Expand All @@ -806,8 +809,7 @@ impl Plot {
self.start_redpiler(Default::default());
}
self.last_update_time = Instant::now();
let batch_size =
WORLD_SEND_RATE.as_nanos() / self.last_nspt.as_nanos();
let batch_size = WORLD_SEND_RATE.as_nanos() / self.last_nspt.as_nanos();
let batch_size = batch_size.min(50000).max(1) as u32;
for _ in 0..batch_size {
self.tick();
Expand Down
4 changes: 2 additions & 2 deletions src/plot/worldedit/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ pub(super) fn execute_load(mut ctx: CommandExecuteContext<'_>) {
ctx.player.send_error_message("Filename is invalid");
return;
}

if CONFIG.schemati {
let prefix = HyphenatedUUID(ctx.player.uuid).to_string() + "/";
file_name.insert_str(0, &prefix);
Expand Down Expand Up @@ -301,7 +301,7 @@ pub(super) fn execute_save(ctx: CommandExecuteContext<'_>) {
ctx.player.send_error_message("Filename is invalid");
return;
}

if CONFIG.schemati {
let prefix = HyphenatedUUID(ctx.player.uuid).to_string() + "/";
file_name.insert_str(0, &prefix);
Expand Down
2 changes: 1 addition & 1 deletion src/redpiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ impl CompilerOptions {
let options = str.split_whitespace();
for option in options {
match option {
"--no-wires" | "-O" => co.optimize = true,
"--optimize" | "-O" => co.optimize = true,
"--export" | "-E" => co.export = true,
"--io-only" | "-I" => co.io_only = true,
// FIXME: use actual error handling
Expand Down