Skip to content

Commit

Permalink
Technical Update (v0.6.0) (#17)
Browse files Browse the repository at this point in the history
# Introductory notes
- **This update is recommended because it contains many improvements and bug fixes.**
- The update is backward compatible with **v0.5.x**
- If you are already using BedcoreProtect **v0.5.x** and you upgrade to **v0.6.0, you will notice a message of database upgrading**. Don't worry, that's normal. It's the patch manager process that updates the database tables for the new version. **If during the process you got a crash, please open a issue [here](https://github.com/matcracker/BedcoreProtect/issues/new/choose)!**

# Changelog (Last update: 08/05/2020)
The update is not finished yet and the changelog could be updated in any time.

## Features
- Added /bcp undo command _(Permission: bcp.subcommand.undo)_. Allows to undo the last rollback/restore.
- Now block restrictions works. So, is now possible to include/exclude certain blocks during a rollback or a lookup.
- When a player spawn an entity through a spawn egg is now logged.
- When a entity dies due to a block (e.g. fire, lava, etc...) is now logged.
- When a player ignites a TNT is now logged.
- Code analyzed with PHPStan level 8.

## Improvements
- With SQLite the data will be saved every 5 minutes (same as worlds) instead of 5 hours.
- Re-wrote query execution code getting a speed up!
- Most of queries when executed are now scheduled in order by preventing missing or wrong logs.
- Improved the QueryGenerator execution.
- Improved painting break tracking.
- Removed tiles when rollback placed blocks.
- General minor improvements.

## Changes
- The patch manager is now able to patch a different numbers of patches for each database type.
- From now in the database version of status command (/bcp status) will be applied a suffix indicating if the current database version is backward compatible. 
_(e.g. - Database version: v0.6.1 (Backward Compatible))_
- Default SQLite database file name is now **logs.db**. (This change is backward compatible)

## Bug fixes
- Fixed #9 
- Fixed #12 
- Fixed an issue not allowing inspector to getting logs of the replaced block.
- Fixed crash during the rollback of entities.
- Fixed possible issue with command permission check order.
- Fixed order of plugin data folder creation.
- Fixed wrong position calculation of liquid tracking.
- Fixed correct meta value (damage) when placing block.
- Fixed wrong restore of bed and doors when placed.
- Fixed duplicated door log when breaking.
- Fixed block burning rollback not correctly working some times.
- Fixed purge command not correctly working on SQLite.
- Fixed excessive log during inventory transaction.
- Fixed database file creation on start-up not taking the choosed file name in the config.
- Fixed possibles crashes relative to null values while tracking.
- When rollback an area containing blocks with light source, the light will try to be updated. (This avoid empty light areas)
- Don't log anymore players when they die. It causes a crash while rollback.
  • Loading branch information
matcracker authored May 8, 2020
1 parent fed38e1 commit af4634d
Show file tree
Hide file tree
Showing 58 changed files with 2,854 additions and 1,621 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.idea
/src/poggit
/src/JackMD
/vendor/pocketmine
/libs
/scripts
/.php_cs.cache
TODO
12 changes: 6 additions & 6 deletions .poggit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ projects:
icon: resources/bedcoreprotect_logo.png
libs:
- src: poggit/libasynql/libasynql
version: 3.2.0
version: ~3.3.0
- src: SOF3/await-generator/await-generator
version: ~2.3.0
- src: JackMD/UpdateNotifier/UpdateNotifier
version: 1.0.0
version: ~2.0.0
- src: matcracker/FormLib/FormLib
version: 1.1.0
- src: SOF3/await-generator/await-generator
version: 2.2.0
...
version: ~1.1.0
...
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![](https://poggit.pmmp.io/shield.dl.total/BedcoreProtect)](https://poggit.pmmp.io/p/BedcoreProtect)
[![](https://poggit.pmmp.io/shield.state/BedcoreProtect)](https://poggit.pmmp.io/p/BedcoreProtect)
[![](https://poggit.pmmp.io/shield.api/BedcoreProtect)](https://poggit.pmmp.io/p/BedcoreProtect)
[![Discord](https://img.shields.io/discord/620519017148579841.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/eAePyeb)
Expand Down Expand Up @@ -79,6 +80,7 @@ The main command is **/bedcoreprotect** but it accepts the folllowing aliases: *

**Shortcut commands:**
- **/bcp near \[value]**: _Performs a lookup with radius (default 5)_ (**Permission:** _bcp.subcommand.near_)
- **/bcp undo**: _Revert a rollback/restore via the opposite action_ (**Permission:** _bcp.subcommand.undo_)
---
**Advanced command overview:**
> **/bcp help**<br>
Expand Down
20 changes: 20 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
parameters:
level: max
checkMissingIterableValueType: false
paths:
- /source/src
autoload_files:
- phar:///pocketmine/PocketMine-MP.phar/vendor/autoload.php
autoload_directories:
- /source/src
- /deps
ignoreErrors:
-
message: "#^Method matcracker\\\\BedcoreProtect\\\\enums\\\\Action\\:\\:getAll\\(\\) should return array\\<matcracker\\\\BedcoreProtect\\\\enums\\\\Action\\> but returns array\\<object\\>\\.$#"
count: 1
path: /source/src/matcracker/BedcoreProtect/enums/Action.php

-
message: "#^Method matcracker\\\\BedcoreProtect\\\\enums\\\\Action\\:\\:fromString\\(\\) should return matcracker\\\\BedcoreProtect\\\\enums\\\\Action but returns object\\.$#"
count: 1
path: /source/src/matcracker/BedcoreProtect/enums/Action.php
27 changes: 13 additions & 14 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
---
name: BedcoreProtect
main: matcracker\BedcoreProtect\Main
version: 0.5.7
version: 0.6.0
api: [3.4.0]
mcpe-protcol:
- 354
- 361

softdepend: BlockSniper
load: POSTWORLD
Expand All @@ -19,22 +16,24 @@ permissions:
children:
bcp.subcommand.help:
description: "Allows the user to run the sub-command /bedcoreprotect help"
bcp.subcommand.reload:
description: "Allows the user to run the sub-command /bedcoreprotect reload"
bcp.subcommand.status:
description: "Allows the user to run the sub-command /bedcoreprotect status"
bcp.subcommand.inspect:
description: "Allows the user to run the sub-command /bedcoreprotect inspect"
bcp.subcommand.near:
description: "Allows the user to run the sub-command /bedcoreprotect near"
bcp.subcommand.lookup:
description: "Allows the user to run the sub-command /bedcoreprotect lookup"
bcp.subcommand.menu:
description: "Allows the user to run the sub-command /bedcoreprotect menu"
bcp.subcommand.near:
description: "Allows the user to run the sub-command /bedcoreprotect near"
bcp.subcommand.purge:
description: "Allows the user to run the sub-command /bedcoreprotect purge"
bcp.subcommand.rollback:
description: "Allows the user to run the sub-command /bedcoreprotect rollback"
bcp.subcommand.reload:
description: "Allows the user to run the sub-command /bedcoreprotect reload"
bcp.subcommand.restore:
description: "Allows the user to run the sub-command /bedcoreprotect restore"
bcp.subcommand.purge:
description: "Allows the user to run the sub-command /bedcoreprotect purge"
bcp.subcommand.menu:
description: "Allows the user to run the sub-command /bedcoreprotect menu"
bcp.subcommand.status:
description: "Allows the user to run the sub-command /bedcoreprotect status"
bcp.subcommand.undo:
description: "Allows the user to run the sub-command /bedcoreprotect undo"
...
6 changes: 4 additions & 2 deletions resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
# Plugin language
language: eng

Expand All @@ -10,15 +11,15 @@ database:
sqlite:
# The file name of the database in the plugin data folder.
# You can also put an absolute path here.
file: bedcore_database.db
file: logs.db
# Edit these settings only if you choose "mysql".
mysql:
host: 127.0.0.1
# Avoid using the "root" user for security reasons.
username: root
password: ""
# The database name where plugin stores data.
schema:
schema: ""
# The maximum number of simultaneous SQL queries
# Recommended: 1 for sqlite, 2 for MySQL. You may want to further increase this value if your MySQL connection is very slow.
worker-limit: 1
Expand Down Expand Up @@ -117,3 +118,4 @@ player-interactions: true

# Logs changes made via the plugin "BlockSniper" if it's in use on your server.
blocksniper-hook: false
...
7 changes: 7 additions & 0 deletions resources/languages/eng.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ command.usage = Usage: /bcp help to display commands list
command.no-permission = You don't have permission to run this command.
command.reload.success = Plugin configuration reloaded.
command.reload.no-success = Plugin configuration not reloaded due to some errors. Check your console to see the errors. Until you fix them, it will be used the old configuration.
command.status.bc = Backward-Compatible
command.status.version = Version: §f{%0}
command.status.database-connection = Database connection: §f{%0}
command.status.database-version = Database version: §f{%0}
Expand Down Expand Up @@ -65,7 +66,9 @@ command.help.examples = Examples
command.help.shortcut = Command shortcut.
command.help.block-names = Block names
command.help.info-not-found = Information for command "/bcp help {%0}" not found.
command.undo.not-found = No previous rollback/restore found.
database.version.higher = Your database is running a higher version than BedcoreProtect. Please update the plugin if you want to use it.
database.version.upgrading = Upgrading your database to v{%0}, please wait...
database.version.updated = Your database is now updated from v{%0} to v{%1}.
database.connection.fail = Could not connect to the database! Check your connection, database settings or plugin configuration file.
form.menu.title = Main Menu
Expand All @@ -88,13 +91,15 @@ form.input-menu.exclude-blocks = Exclude blocks (accepts ID:meta)
general.action = Action
general.rollback = Rollback
general.restore = Restore
general.undo = Undo
general.lookup = Lookup
generic.yes = Yes
generic.no = No
inspector.no-data = No block data found for this location.
inspector.more-lines = The lines number must be greater than 1.
inspector.page-not-exist = The page §6{%0}§c does not exist!
inspector.page = Page {%0}/{%1}
inspector.corrupted-data = The current log data may be damaged due to some database operations, please try again later. In the event of a continuous error, please report the problem.
inspector.view-old-data = View older data by typing
language.name = English
parser.few-many-parameters = You are using too few or too many parameters (Max: {%0})
Expand All @@ -108,9 +113,11 @@ parser.invalid-action = Please specify a valid action.
parser.invalid-block-include = Invalid block "{%0}" to include.
parser.invalid-block-exclude = Invalid block "{%0}" to exclude.
parser.missing-parameters = You are missing one of the following parameters: {%0}
rollback.report = Report
rollback.completed = Rollback completed for {%0}.
rollback.date = Rolled back {%0}.
rollback.radius = Radius: {%0} block(s).
rollback.no-changes = No changes have been made.
rollback.blocks = Approx. {%0} block(s) changed.
rollback.items = Approx. {%0} item(s) changed.
rollback.entities = Approx. {%0} entities(s) changed.
Expand Down
7 changes: 7 additions & 0 deletions resources/languages/ita.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ command.usage = Usa: /bcp help per mostrare la lista di comandi
command.no-permission = Non hai il permesso di eseguire questo comando.
command.reload.success = Configurazione del plugin ricaricate.
command.reload.no-success = Configurazione del plugin non ricaricata a causa di alcuni errori. Controlla la console per vederli. Finchè non li sistemerai, verrà usata la vecchia configurazione.
command.status.bc = Retrocompatibile
command.status.version = Versione: §f{%0}
command.status.database-connection = Connessione database: §f{%0}
command.status.database-version = Versione database: §f{%0}
Expand Down Expand Up @@ -65,7 +66,9 @@ command.help.examples = Esempi
command.help.shortcut = Scorciatoia del comando.
command.help.block-names = Nomi dei blocchi
command.help.info-not-found = Informazioni per il comando "/bcp help {%0}" non trovate.
command.undo.not-found = Non è stato trovato nessun rollback/ripristino precedente.
database.version.higher = Il tuo database sta eseguendo una versione più aggiornata di BedcoreProtect. Per favore aggiorna il tuo plugin se vuoi usarlo.
database.version.upgrading = Aggiornamento del database alla v{%0}, attendere prego...
database.version.updated = Il tuo database è stato aggiornato dalla versione v{%0} alla v{%1}.
database.connection.fail = Impossibile connettersi al database! Controlla la tua connessione, impostazioni del database o la configurazione del plugin.
form.menu.title = Menu principale
Expand All @@ -88,13 +91,15 @@ form.input-menu.exclude-blocks = Escludi blocchi (accetta ID:meta)
general.action = Azione
general.rollback = Rollback
general.restore = Ripristino
general.undo = Annulla
general.lookup = Consulta
generic.yes = Si
generic.no = No
inspector.no-data = Nessun dato trovato in questa posizione.
inspector.more-lines = Il numero di linee deve essere più grande di 1.
inspector.page-not-exist = La pagina §6{%0}§c non esiste!
inspector.page = Pagina {%0}/{%1}
inspector.corrupted-data = I dati del registro corrente potrebbero essere danneggiati a causa di alcune operazioni del database, si prega di riprovare più tardi. In caso di errore continuo, si prega di segnalare il problema.
inspector.view-old-data = Vedi i dati vecchi scrivendo
language.name = Italiano
parser.few-many-parameters = You are using too few or too many parameters (Max: {%0})
Expand All @@ -108,9 +113,11 @@ parser.invalid-action = Per favore specifica un'azione valida.
parser.invalid-block-include = Blocco "{%0}" invalido da includere.
parser.invalid-block-exclude = Blocco "{%0}" invalido da escludere.
parser.missing-parameters = Stai dimenticando uno dei seguenti paramentri: {%0}
rollback.report = Rapporto
rollback.completed = Rollback completato per {%0}.
rollback.date = Rolled back {%0}.
rollback.radius = Raggio: {%0} block(s).
rollback.no-changes = Non è stato fatto nessun cambiamento.
rollback.blocks = Circa {%0} blocco/hi cambiato/i.
rollback.items = Circa. {%0} oggetto/i cambiato/i.
rollback.entities = Circa {%0} entità cambiate.
Expand Down
File renamed without changes.
54 changes: 26 additions & 28 deletions resources/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,37 @@ CREATE TABLE IF NOT EXISTS entities
-- # {log_history
CREATE TABLE IF NOT EXISTS log_history
(
log_id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
who VARCHAR(36) NOT NULL,
x BIGINT NOT NULL,
y TINYINT UNSIGNED NOT NULL,
z BIGINT NOT NULL,
world_name VARCHAR(255) NOT NULL,
action TINYINT UNSIGNED NOT NULL,
time TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP NOT NULL,
rollback BOOLEAN DEFAULT FALSE NOT NULL,
log_id BIGINT UNSIGNED UNIQUE AUTO_INCREMENT PRIMARY KEY NOT NULL,
who VARCHAR(36) NOT NULL,
x BIGINT NOT NULL,
y TINYINT UNSIGNED NOT NULL,
z BIGINT NOT NULL,
world_name VARCHAR(255) NOT NULL,
action TINYINT UNSIGNED NOT NULL,
time TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP NOT NULL,
rollback BOOLEAN DEFAULT FALSE NOT NULL,
FOREIGN KEY (who) REFERENCES entities (uuid)
);
-- # }
-- # {blocks_log
CREATE TABLE IF NOT EXISTS blocks_log
(
history_id BIGINT UNSIGNED NOT NULL,
old_id INTEGER UNSIGNED NOT NULL,
old_meta TINYINT(2) UNSIGNED NOT NULL,
history_id BIGINT UNSIGNED UNIQUE NOT NULL,
old_id INTEGER UNSIGNED NOT NULL,
old_meta TINYINT(2) UNSIGNED NOT NULL,
old_nbt LONGBLOB DEFAULT NULL,
new_id INTEGER UNSIGNED NOT NULL,
new_meta TINYINT(2) UNSIGNED NOT NULL,
new_id INTEGER UNSIGNED NOT NULL,
new_meta TINYINT(2) UNSIGNED NOT NULL,
new_nbt LONGBLOB DEFAULT NULL,
FOREIGN KEY (history_id) REFERENCES log_history (log_id) ON DELETE CASCADE
);
-- # }
-- # {entities_log
CREATE TABLE IF NOT EXISTS entities_log
(
history_id BIGINT UNSIGNED NOT NULL,
entityfrom_uuid VARCHAR(36) NOT NULL,
entityfrom_id INTEGER UNSIGNED NOT NULL,
history_id BIGINT UNSIGNED UNIQUE NOT NULL,
entityfrom_uuid VARCHAR(36) NOT NULL,
entityfrom_id INTEGER UNSIGNED NOT NULL,
entityfrom_nbt LONGBLOB DEFAULT NULL,
FOREIGN KEY (history_id) REFERENCES log_history (log_id) ON DELETE CASCADE,
FOREIGN KEY (entityfrom_uuid) REFERENCES entities (uuid)
Expand All @@ -52,7 +52,7 @@ CREATE TABLE IF NOT EXISTS entities_log
-- # {inventories_log
CREATE TABLE IF NOT EXISTS inventories_log
(
history_id BIGINT UNSIGNED NOT NULL,
history_id BIGINT UNSIGNED UNIQUE NOT NULL,
slot TINYINT UNSIGNED NOT NULL,
old_id INTEGER UNSIGNED DEFAULT 0 NOT NULL,
old_meta TINYINT(2) UNSIGNED DEFAULT 0 NOT NULL,
Expand Down Expand Up @@ -104,6 +104,7 @@ INSERT INTO log_history(who, x, y, z, world_name,
VALUES ((SELECT uuid FROM entities WHERE uuid = :uuid), :x, :y, :z, :world_name, :action);
-- # }
-- # {block
-- # :log_id int
-- # :old_id int
-- # :old_meta int
-- # :old_nbt ?string
Expand All @@ -112,17 +113,18 @@ VALUES ((SELECT uuid FROM entities WHERE uuid = :uuid), :x, :y, :z, :world_name,
-- # :new_nbt ?string
INSERT INTO blocks_log(history_id, old_id, old_meta, old_nbt, new_id, new_meta,
new_nbt)
VALUES (LAST_INSERT_ID(), :old_id, :old_meta, :old_nbt, :new_id, :new_meta,
:new_nbt);
VALUES (:log_id, :old_id, :old_meta, :old_nbt, :new_id, :new_meta, :new_nbt);
-- # }
-- # {entity
-- # :log_id int
-- # :uuid string
-- # :id int
-- # :nbt ?string
INSERT INTO entities_log(history_id, entityfrom_uuid, entityfrom_id, entityfrom_nbt)
VALUES (LAST_INSERT_ID(), (SELECT uuid FROM entities WHERE uuid = :uuid), :id, :nbt);
VALUES (:log_id, (SELECT uuid FROM entities WHERE uuid = :uuid), :id, :nbt);
-- # }
-- # {inventory
-- # :log_id int
-- # :slot int
-- # :old_id int 0
-- # :old_meta int 0
Expand All @@ -134,8 +136,7 @@ VALUES (LAST_INSERT_ID(), (SELECT uuid FROM entities WHERE uuid = :uuid), :id, :
-- # :new_amount int 0
INSERT INTO inventories_log(history_id, slot, old_id, old_meta, old_nbt, old_amount, new_id,
new_meta, new_nbt, new_amount)
VALUES (LAST_INSERT_ID(), :slot, :old_id, :old_meta, :old_nbt, :old_amount, :new_id,
:new_meta, :new_nbt, :new_amount);
VALUES (:log_id, :slot, :old_id, :old_meta, :old_nbt, :old_amount, :new_id, :new_meta, :new_nbt, :new_amount);
-- # }
-- # }
-- # }
Expand Down Expand Up @@ -169,10 +170,6 @@ FROM status
LIMIT 1;
-- # }
-- # {log
-- # {last_id
SELECT MAX(log_id) AS lastId
FROM log_history;
-- # }
-- # {old_blocks
-- # :log_ids list:int
SELECT history_id,
Expand Down Expand Up @@ -233,7 +230,8 @@ WHERE log_id IN :log_ids;
-- # }
-- # {entities
-- # :log_ids list:int
SELECT e.entity_classpath,
SELECT log_id,
e.entity_classpath,
el.entityfrom_id,
el.entityfrom_nbt,
x,
Expand Down
8 changes: 8 additions & 0 deletions resources/patches/.patches
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
---
# !!! DON'T EDIT THIS FILE !!!
# --- YAML Patch format ---
# [VERSION]:
# sqlite: [NUMBER_OF_PATCHES] (For SQLite)
# mysql: [NUMBER_OF_PATCHES] (For MySQL)
# -------------------------
0.6.0:
sqlite: 16
mysql: 4
...
14 changes: 14 additions & 0 deletions resources/patches/mysql_patch.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
-- #!mysql
-- #{patch
-- # {0.6.0
-- # {1
ALTER TABLE log_history ADD UNIQUE(log_id);
-- # }
-- # {2
ALTER TABLE blocks_log ADD UNIQUE(history_id);
-- # }
-- # {3
ALTER TABLE entities_log ADD UNIQUE(history_id);
-- # }
-- # {4
ALTER TABLE inventories_log ADD UNIQUE(history_id);
-- # }
-- # }
-- #}
Loading

0 comments on commit af4634d

Please sign in to comment.