bentobox/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java

334 lines
13 KiB
Java
Raw Normal View History

package world.bentobox.bentobox.blueprints;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
Implemeted Blueprint bundles and blueprints (#672) * A prototype for Blueprint bundles and blueprints This stores blueprints inside bundles. Each bundle can have up to 3 blueprints defines by the World.Environment. This is not a finished manager. It just handles all the saving and loading side of things. I thought this would help you so you can then concentrate on the UI. * WIP: Copy blocks to Blueprint done. * WIP Pasting done. * WIP: Added BlueprintsManager to ultimately replace SchemsManager. * Moved blueprint suffix and changed to .blu * Fixed unit test. * Now tested and working. Integrated with new island and resetting island. If there are no blueprint bundles or blueprints then a default bedrock set will be made and put in the game mode addon's blueprints folder. Still to do: enable schems to be loaded and pasted for legacy support. Add blueprints and a bundle to GameModeAddons like BSkyBlock. * Renamed most of the classes * Cleaned up clipboard and paster. * Further cleanup on blueprint clipboard and paster. * Merged blueprint classes into one package. * Put Blueprint data objects in their own package. Isolated schems classes for later removal. * Renamed admin command classes and changed locale files. * More clean up to remove schems * Schem to blueprints converter done. Converts schems to blueprint bundles and sets up a default set. Tested the happy-path. Need to do more testing on edge cases. * Added basic UI for development. Fixed bug with schem conversion. * Adds permissions into the blueprints. Fixes tests, cleans up some naming * Added IslandCreationPanel and created BlueprintManagementPanel * Fixed JSONDatabaseHandler's constructor being public * Made the Blueprints button in ManagementPanel open the Blueprint management panel * Fixed tests and ignored one (NPE)
2019-05-15 20:16:41 +02:00
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBlock;
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.nms.PasteHandler;
import world.bentobox.bentobox.util.Util;
/**
* This class pastes the clipboard it is given
* @author tastybento
*
*/
Implemeted Blueprint bundles and blueprints (#672) * A prototype for Blueprint bundles and blueprints This stores blueprints inside bundles. Each bundle can have up to 3 blueprints defines by the World.Environment. This is not a finished manager. It just handles all the saving and loading side of things. I thought this would help you so you can then concentrate on the UI. * WIP: Copy blocks to Blueprint done. * WIP Pasting done. * WIP: Added BlueprintsManager to ultimately replace SchemsManager. * Moved blueprint suffix and changed to .blu * Fixed unit test. * Now tested and working. Integrated with new island and resetting island. If there are no blueprint bundles or blueprints then a default bedrock set will be made and put in the game mode addon's blueprints folder. Still to do: enable schems to be loaded and pasted for legacy support. Add blueprints and a bundle to GameModeAddons like BSkyBlock. * Renamed most of the classes * Cleaned up clipboard and paster. * Further cleanup on blueprint clipboard and paster. * Merged blueprint classes into one package. * Put Blueprint data objects in their own package. Isolated schems classes for later removal. * Renamed admin command classes and changed locale files. * More clean up to remove schems * Schem to blueprints converter done. Converts schems to blueprint bundles and sets up a default set. Tested the happy-path. Need to do more testing on edge cases. * Added basic UI for development. Fixed bug with schem conversion. * Adds permissions into the blueprints. Fixes tests, cleans up some naming * Added IslandCreationPanel and created BlueprintManagementPanel * Fixed JSONDatabaseHandler's constructor being public * Made the Blueprints button in ManagementPanel open the Blueprint management panel * Fixed tests and ignored one (NPE)
2019-05-15 20:16:41 +02:00
public class BlueprintPaster {
2024-02-19 19:55:15 +01:00
/**
* This tracks the stages of pasting from loading the chunk, pasting blocks, attachments, entities and then finishing.
*/
enum PasteState {
CHUNK_LOAD,
CHUNK_LOADING,
BLOCKS,
ATTACHMENTS,
ENTITIES,
DONE,
CANCEL
}
/**
* Longest chunk loading time experienced when pasting an island.
* It is used to fine-tune the estimated pasting time.
* @since 1.11.1
*/
2020-02-11 11:28:15 +01:00
private static long chunkLoadTime = 0;
private final BentoBox plugin;
private final PasteHandler paster = Util.getPasteHandler();
2024-02-24 06:56:32 +01:00
private final PasteHandler fallback = new world.bentobox.bentobox.nms.fallback.PasteHandlerImpl();
private final World world;
// The minimum block position (x,y,z)
private Location pos1;
// The maximum block position (x,y,z)
private Location pos2;
private PasteState pasteState;
private BukkitTask pastingTask;
Implemeted Blueprint bundles and blueprints (#672) * A prototype for Blueprint bundles and blueprints This stores blueprints inside bundles. Each bundle can have up to 3 blueprints defines by the World.Environment. This is not a finished manager. It just handles all the saving and loading side of things. I thought this would help you so you can then concentrate on the UI. * WIP: Copy blocks to Blueprint done. * WIP Pasting done. * WIP: Added BlueprintsManager to ultimately replace SchemsManager. * Moved blueprint suffix and changed to .blu * Fixed unit test. * Now tested and working. Integrated with new island and resetting island. If there are no blueprint bundles or blueprints then a default bedrock set will be made and put in the game mode addon's blueprints folder. Still to do: enable schems to be loaded and pasted for legacy support. Add blueprints and a bundle to GameModeAddons like BSkyBlock. * Renamed most of the classes * Cleaned up clipboard and paster. * Further cleanup on blueprint clipboard and paster. * Merged blueprint classes into one package. * Put Blueprint data objects in their own package. Isolated schems classes for later removal. * Renamed admin command classes and changed locale files. * More clean up to remove schems * Schem to blueprints converter done. Converts schems to blueprint bundles and sets up a default set. Tested the happy-path. Need to do more testing on edge cases. * Added basic UI for development. Fixed bug with schem conversion. * Adds permissions into the blueprints. Fixes tests, cleans up some naming * Added IslandCreationPanel and created BlueprintManagementPanel * Fixed JSONDatabaseHandler's constructor being public * Made the Blueprints button in ManagementPanel open the Blueprint management panel * Fixed tests and ignored one (NPE)
2019-05-15 20:16:41 +02:00
private BlueprintClipboard clipboard;
private CompletableFuture<Void> currentTask = CompletableFuture.completedFuture(null);
/**
* The Blueprint to paste.
*/
@NonNull
private final Blueprint blueprint;
/**
* The Location to paste to.
*/
@NonNull
private final Location location;
/**
* Island related to this paste, may be null.
*/
@Nullable
private final Island island;
/**
* Paste a clipboard to a location. Run {@link #paste()} to paste
* @param plugin - BentoBox
* @param clipboard - clipboard to paste
* @param location - location to which to paste
*/
public BlueprintPaster(@NonNull BentoBox plugin, @NonNull BlueprintClipboard clipboard, @NonNull Location location) {
this.plugin = plugin;
Implemeted Blueprint bundles and blueprints (#672) * A prototype for Blueprint bundles and blueprints This stores blueprints inside bundles. Each bundle can have up to 3 blueprints defines by the World.Environment. This is not a finished manager. It just handles all the saving and loading side of things. I thought this would help you so you can then concentrate on the UI. * WIP: Copy blocks to Blueprint done. * WIP Pasting done. * WIP: Added BlueprintsManager to ultimately replace SchemsManager. * Moved blueprint suffix and changed to .blu * Fixed unit test. * Now tested and working. Integrated with new island and resetting island. If there are no blueprint bundles or blueprints then a default bedrock set will be made and put in the game mode addon's blueprints folder. Still to do: enable schems to be loaded and pasted for legacy support. Add blueprints and a bundle to GameModeAddons like BSkyBlock. * Renamed most of the classes * Cleaned up clipboard and paster. * Further cleanup on blueprint clipboard and paster. * Merged blueprint classes into one package. * Put Blueprint data objects in their own package. Isolated schems classes for later removal. * Renamed admin command classes and changed locale files. * More clean up to remove schems * Schem to blueprints converter done. Converts schems to blueprint bundles and sets up a default set. Tested the happy-path. Need to do more testing on edge cases. * Added basic UI for development. Fixed bug with schem conversion. * Adds permissions into the blueprints. Fixes tests, cleans up some naming * Added IslandCreationPanel and created BlueprintManagementPanel * Fixed JSONDatabaseHandler's constructor being public * Made the Blueprints button in ManagementPanel open the Blueprint management panel * Fixed tests and ignored one (NPE)
2019-05-15 20:16:41 +02:00
this.clipboard = clipboard;
// Calculate location for pasting
2021-10-09 20:40:15 +02:00
this.blueprint = Objects.requireNonNull(clipboard.getBlueprint(), "Clipboard cannot have a null Blueprint");
this.location = location;
this.world = location.getWorld();
this.island = null;
}
/**
Implemeted Blueprint bundles and blueprints (#672) * A prototype for Blueprint bundles and blueprints This stores blueprints inside bundles. Each bundle can have up to 3 blueprints defines by the World.Environment. This is not a finished manager. It just handles all the saving and loading side of things. I thought this would help you so you can then concentrate on the UI. * WIP: Copy blocks to Blueprint done. * WIP Pasting done. * WIP: Added BlueprintsManager to ultimately replace SchemsManager. * Moved blueprint suffix and changed to .blu * Fixed unit test. * Now tested and working. Integrated with new island and resetting island. If there are no blueprint bundles or blueprints then a default bedrock set will be made and put in the game mode addon's blueprints folder. Still to do: enable schems to be loaded and pasted for legacy support. Add blueprints and a bundle to GameModeAddons like BSkyBlock. * Renamed most of the classes * Cleaned up clipboard and paster. * Further cleanup on blueprint clipboard and paster. * Merged blueprint classes into one package. * Put Blueprint data objects in their own package. Isolated schems classes for later removal. * Renamed admin command classes and changed locale files. * More clean up to remove schems * Schem to blueprints converter done. Converts schems to blueprint bundles and sets up a default set. Tested the happy-path. Need to do more testing on edge cases. * Added basic UI for development. Fixed bug with schem conversion. * Adds permissions into the blueprints. Fixes tests, cleans up some naming * Added IslandCreationPanel and created BlueprintManagementPanel * Fixed JSONDatabaseHandler's constructor being public * Made the Blueprints button in ManagementPanel open the Blueprint management panel * Fixed tests and ignored one (NPE)
2019-05-15 20:16:41 +02:00
* Pastes a blueprint to an island
* @param plugin - BentoBox
Implemeted Blueprint bundles and blueprints (#672) * A prototype for Blueprint bundles and blueprints This stores blueprints inside bundles. Each bundle can have up to 3 blueprints defines by the World.Environment. This is not a finished manager. It just handles all the saving and loading side of things. I thought this would help you so you can then concentrate on the UI. * WIP: Copy blocks to Blueprint done. * WIP Pasting done. * WIP: Added BlueprintsManager to ultimately replace SchemsManager. * Moved blueprint suffix and changed to .blu * Fixed unit test. * Now tested and working. Integrated with new island and resetting island. If there are no blueprint bundles or blueprints then a default bedrock set will be made and put in the game mode addon's blueprints folder. Still to do: enable schems to be loaded and pasted for legacy support. Add blueprints and a bundle to GameModeAddons like BSkyBlock. * Renamed most of the classes * Cleaned up clipboard and paster. * Further cleanup on blueprint clipboard and paster. * Merged blueprint classes into one package. * Put Blueprint data objects in their own package. Isolated schems classes for later removal. * Renamed admin command classes and changed locale files. * More clean up to remove schems * Schem to blueprints converter done. Converts schems to blueprint bundles and sets up a default set. Tested the happy-path. Need to do more testing on edge cases. * Added basic UI for development. Fixed bug with schem conversion. * Adds permissions into the blueprints. Fixes tests, cleans up some naming * Added IslandCreationPanel and created BlueprintManagementPanel * Fixed JSONDatabaseHandler's constructor being public * Made the Blueprints button in ManagementPanel open the Blueprint management panel * Fixed tests and ignored one (NPE)
2019-05-15 20:16:41 +02:00
* @param bp - blueprint to paste
* @param world - world to paste to
* @param island - island related to this paste
*/
public BlueprintPaster(@NonNull BentoBox plugin, @NonNull Blueprint bp, World world, @NonNull Island island) {
this.plugin = plugin;
this.blueprint = bp;
this.island = island;
this.world = world;
// Offset due to bedrock
Implemeted Blueprint bundles and blueprints (#672) * A prototype for Blueprint bundles and blueprints This stores blueprints inside bundles. Each bundle can have up to 3 blueprints defines by the World.Environment. This is not a finished manager. It just handles all the saving and loading side of things. I thought this would help you so you can then concentrate on the UI. * WIP: Copy blocks to Blueprint done. * WIP Pasting done. * WIP: Added BlueprintsManager to ultimately replace SchemsManager. * Moved blueprint suffix and changed to .blu * Fixed unit test. * Now tested and working. Integrated with new island and resetting island. If there are no blueprint bundles or blueprints then a default bedrock set will be made and put in the game mode addon's blueprints folder. Still to do: enable schems to be loaded and pasted for legacy support. Add blueprints and a bundle to GameModeAddons like BSkyBlock. * Renamed most of the classes * Cleaned up clipboard and paster. * Further cleanup on blueprint clipboard and paster. * Merged blueprint classes into one package. * Put Blueprint data objects in their own package. Isolated schems classes for later removal. * Renamed admin command classes and changed locale files. * More clean up to remove schems * Schem to blueprints converter done. Converts schems to blueprint bundles and sets up a default set. Tested the happy-path. Need to do more testing on edge cases. * Added basic UI for development. Fixed bug with schem conversion. * Adds permissions into the blueprints. Fixes tests, cleans up some naming * Added IslandCreationPanel and created BlueprintManagementPanel * Fixed JSONDatabaseHandler's constructor being public * Made the Blueprints button in ManagementPanel open the Blueprint management panel * Fixed tests and ignored one (NPE)
2019-05-15 20:16:41 +02:00
Vector off = bp.getBedrock() != null ? bp.getBedrock() : new Vector(0,0,0);
// Calculate location for pasting
this.location = island.getProtectionCenter().toVector().subtract(off).toLocation(world);
}
Version 1.20.1 (#1966) * Version 1.20.1 * Added name of the addon causing the issue. https://github.com/BentoBoxWorld/BentoBox/issues/1944 * Use world min-height for island bounding box. * Fixes a bug when fallback could not use reusable There was an issue in PanelItemTemplate that prevented fallback buttons to be "reusable" things. The issue was that reusable items were not passed to the panel item reader. * Adjusted test to try to avoid errors * Fix for random test failures. * Added 1.18.2 support * Address unnecessary PVP reports on each teleport (#1948) If a player is teleporting on the same island in the same dimension, it keeps spamming that PVP is enabled in dimension. It should be enough with sending messages when the player teleports to the island. Fixes #1885 * Fixes bug with Safe Spot Teleport (#1951) There was a bug that prevented finding a safe spot if all valid blocks were in height with the `startY` location. Reported via discord. * Fix Exception error reported by IDE I am not sure why Eclipse is saying this is an error. * Fix for kicking offline players https://github.com/BentoBoxWorld/BentoBox/issues/1950 * Add an option in SafeSpotTeleport to cancel if fail (#1952) There was no option to cancel teleportation if SafeSpotTeleport could not find a valid spot. This option could be used to avoid creating "backup" blocks in situations when teleportation is avoidable, f.e. visiting an island. * Replace peplaceAll with replace It does the same thing if the first argument is not a regex. * Use constants for common strings * Use constants for common strings * Go back to replaceAll This is required. * Clearer paster (#1953) * WIP - make easier to understand. * Small refactor of paster to make it easier to understand * Fix tabs to spaces. Sorry - new editor! * Fix tabs to spaces * Fix tab to spaces * Improve team kick command (#1957) The kick command has an unnecessary owner check. As command should be configurable by island owners, then limiting it to an owner is wrong. Add a code that allows kicking only lower-ranked players. Add message that shows who kicked from the island. Add message that shows that rank does not allow to kick. * Solve crashes with Addon#allLoaded call (#1959) If some addon has code in Addon#allLoaded that crashes the call, then it did not disable addon as well as did not call allLoaded for every other addon that was left in the list. This should be solved by adding an extra try-catch. * using java 16 syntax (#1958) * Fixes kick command (#1960) PR #1957 broke kick command and noone could kick players from teams. This should fix it. * Fixes a bug with blueprint height (#1961) Blueprint clipboard was preventing setting Y below 0 or above 255. The code was not adjusted to 1.18 changes. Reported via discord. * Fixes Lava Duplication Glitch (#1964) Due to the fact, that Obsidian Scooping uses one tick delay to remove obsidian, a player with a bucket in hand and offhand duplicated lava. To avoid that, added an extra check that ignores the interact event if a player holds a bucket in both hands, and interacted hand is offhand. Fixes #1963 * Fixes failures in obsidian cooping listener. (#1965) Failures happened after implementing #1964 Co-authored-by: BONNe <bonne@bonne.id.lv> Co-authored-by: Invvk <70810073+Invvk@users.noreply.github.com>
2022-04-17 18:04:37 +02:00
private record Bits(Map<Vector, BlueprintBlock> blocks,
Map<Vector, BlueprintBlock> attached,
Map<Vector, List<BlueprintEntity>> entities,
Iterator<Entry<Vector, BlueprintBlock>> it,
Iterator<Entry<Vector, BlueprintBlock>> it2,
Iterator<Entry<Vector, List<BlueprintEntity>>> it3,
int pasteSpeed) {}
2024-02-24 06:56:32 +01:00
Implemeted Blueprint bundles and blueprints (#672) * A prototype for Blueprint bundles and blueprints This stores blueprints inside bundles. Each bundle can have up to 3 blueprints defines by the World.Environment. This is not a finished manager. It just handles all the saving and loading side of things. I thought this would help you so you can then concentrate on the UI. * WIP: Copy blocks to Blueprint done. * WIP Pasting done. * WIP: Added BlueprintsManager to ultimately replace SchemsManager. * Moved blueprint suffix and changed to .blu * Fixed unit test. * Now tested and working. Integrated with new island and resetting island. If there are no blueprint bundles or blueprints then a default bedrock set will be made and put in the game mode addon's blueprints folder. Still to do: enable schems to be loaded and pasted for legacy support. Add blueprints and a bundle to GameModeAddons like BSkyBlock. * Renamed most of the classes * Cleaned up clipboard and paster. * Further cleanup on blueprint clipboard and paster. * Merged blueprint classes into one package. * Put Blueprint data objects in their own package. Isolated schems classes for later removal. * Renamed admin command classes and changed locale files. * More clean up to remove schems * Schem to blueprints converter done. Converts schems to blueprint bundles and sets up a default set. Tested the happy-path. Need to do more testing on edge cases. * Added basic UI for development. Fixed bug with schem conversion. * Adds permissions into the blueprints. Fixes tests, cleans up some naming * Added IslandCreationPanel and created BlueprintManagementPanel * Fixed JSONDatabaseHandler's constructor being public * Made the Blueprints button in ManagementPanel open the Blueprint management panel * Fixed tests and ignored one (NPE)
2019-05-15 20:16:41 +02:00
/**
* The main pasting method
*/
public CompletableFuture<Boolean> paste() {
2024-02-24 07:05:32 +01:00
return this.paste(true);
2024-02-24 06:56:32 +01:00
}
/**
* Paste the clipboard
* @param useNMS if true, NMS pasting will be used, otherwise Bukkit API
* @return Future boolean where true is success
*/
public CompletableFuture<Boolean> paste(boolean useNMS) {
CompletableFuture<Boolean> result = new CompletableFuture<>();
Implemeted Blueprint bundles and blueprints (#672) * A prototype for Blueprint bundles and blueprints This stores blueprints inside bundles. Each bundle can have up to 3 blueprints defines by the World.Environment. This is not a finished manager. It just handles all the saving and loading side of things. I thought this would help you so you can then concentrate on the UI. * WIP: Copy blocks to Blueprint done. * WIP Pasting done. * WIP: Added BlueprintsManager to ultimately replace SchemsManager. * Moved blueprint suffix and changed to .blu * Fixed unit test. * Now tested and working. Integrated with new island and resetting island. If there are no blueprint bundles or blueprints then a default bedrock set will be made and put in the game mode addon's blueprints folder. Still to do: enable schems to be loaded and pasted for legacy support. Add blueprints and a bundle to GameModeAddons like BSkyBlock. * Renamed most of the classes * Cleaned up clipboard and paster. * Further cleanup on blueprint clipboard and paster. * Merged blueprint classes into one package. * Put Blueprint data objects in their own package. Isolated schems classes for later removal. * Renamed admin command classes and changed locale files. * More clean up to remove schems * Schem to blueprints converter done. Converts schems to blueprint bundles and sets up a default set. Tested the happy-path. Need to do more testing on edge cases. * Added basic UI for development. Fixed bug with schem conversion. * Adds permissions into the blueprints. Fixes tests, cleans up some naming * Added IslandCreationPanel and created BlueprintManagementPanel * Fixed JSONDatabaseHandler's constructor being public * Made the Blueprints button in ManagementPanel open the Blueprint management panel * Fixed tests and ignored one (NPE)
2019-05-15 20:16:41 +02:00
// Iterators for the various maps to paste
Version 1.20.1 (#1966) * Version 1.20.1 * Added name of the addon causing the issue. https://github.com/BentoBoxWorld/BentoBox/issues/1944 * Use world min-height for island bounding box. * Fixes a bug when fallback could not use reusable There was an issue in PanelItemTemplate that prevented fallback buttons to be "reusable" things. The issue was that reusable items were not passed to the panel item reader. * Adjusted test to try to avoid errors * Fix for random test failures. * Added 1.18.2 support * Address unnecessary PVP reports on each teleport (#1948) If a player is teleporting on the same island in the same dimension, it keeps spamming that PVP is enabled in dimension. It should be enough with sending messages when the player teleports to the island. Fixes #1885 * Fixes bug with Safe Spot Teleport (#1951) There was a bug that prevented finding a safe spot if all valid blocks were in height with the `startY` location. Reported via discord. * Fix Exception error reported by IDE I am not sure why Eclipse is saying this is an error. * Fix for kicking offline players https://github.com/BentoBoxWorld/BentoBox/issues/1950 * Add an option in SafeSpotTeleport to cancel if fail (#1952) There was no option to cancel teleportation if SafeSpotTeleport could not find a valid spot. This option could be used to avoid creating "backup" blocks in situations when teleportation is avoidable, f.e. visiting an island. * Replace peplaceAll with replace It does the same thing if the first argument is not a regex. * Use constants for common strings * Use constants for common strings * Go back to replaceAll This is required. * Clearer paster (#1953) * WIP - make easier to understand. * Small refactor of paster to make it easier to understand * Fix tabs to spaces. Sorry - new editor! * Fix tabs to spaces * Fix tab to spaces * Improve team kick command (#1957) The kick command has an unnecessary owner check. As command should be configurable by island owners, then limiting it to an owner is wrong. Add a code that allows kicking only lower-ranked players. Add message that shows who kicked from the island. Add message that shows that rank does not allow to kick. * Solve crashes with Addon#allLoaded call (#1959) If some addon has code in Addon#allLoaded that crashes the call, then it did not disable addon as well as did not call allLoaded for every other addon that was left in the list. This should be solved by adding an extra try-catch. * using java 16 syntax (#1958) * Fixes kick command (#1960) PR #1957 broke kick command and noone could kick players from teams. This should fix it. * Fixes a bug with blueprint height (#1961) Blueprint clipboard was preventing setting Y below 0 or above 255. The code was not adjusted to 1.18 changes. Reported via discord. * Fixes Lava Duplication Glitch (#1964) Due to the fact, that Obsidian Scooping uses one tick delay to remove obsidian, a player with a bucket in hand and offhand duplicated lava. To avoid that, added an extra check that ignores the interact event if a player holds a bucket in both hands, and interacted hand is offhand. Fixes #1963 * Fixes failures in obsidian cooping listener. (#1965) Failures happened after implementing #1964 Co-authored-by: BONNe <bonne@bonne.id.lv> Co-authored-by: Invvk <70810073+Invvk@users.noreply.github.com>
2022-04-17 18:04:37 +02:00
final Map<Vector, BlueprintBlock> blocks = blueprint.getBlocks() == null ? Collections.emptyMap() : blueprint.getBlocks();
final Map<Vector, BlueprintBlock> attached = blueprint.getAttached() == null ? Collections.emptyMap() : blueprint.getAttached();
final Map<Vector, List<BlueprintEntity>> entities = blueprint.getEntities() == null ? Collections.emptyMap() : blueprint.getEntities();
// Initial state & speed
pasteState = PasteState.CHUNK_LOAD;
// If this is an island OVERWORLD paste, get the island owner.
final Optional<User> owner = Optional.ofNullable(island).map(i -> User.getInstance(i.getOwner()));
2023-02-05 04:08:09 +01:00
// Tell the owner we're pasting blocks and how much time it might take
Version 1.20.1 (#1966) * Version 1.20.1 * Added name of the addon causing the issue. https://github.com/BentoBoxWorld/BentoBox/issues/1944 * Use world min-height for island bounding box. * Fixes a bug when fallback could not use reusable There was an issue in PanelItemTemplate that prevented fallback buttons to be "reusable" things. The issue was that reusable items were not passed to the panel item reader. * Adjusted test to try to avoid errors * Fix for random test failures. * Added 1.18.2 support * Address unnecessary PVP reports on each teleport (#1948) If a player is teleporting on the same island in the same dimension, it keeps spamming that PVP is enabled in dimension. It should be enough with sending messages when the player teleports to the island. Fixes #1885 * Fixes bug with Safe Spot Teleport (#1951) There was a bug that prevented finding a safe spot if all valid blocks were in height with the `startY` location. Reported via discord. * Fix Exception error reported by IDE I am not sure why Eclipse is saying this is an error. * Fix for kicking offline players https://github.com/BentoBoxWorld/BentoBox/issues/1950 * Add an option in SafeSpotTeleport to cancel if fail (#1952) There was no option to cancel teleportation if SafeSpotTeleport could not find a valid spot. This option could be used to avoid creating "backup" blocks in situations when teleportation is avoidable, f.e. visiting an island. * Replace peplaceAll with replace It does the same thing if the first argument is not a regex. * Use constants for common strings * Use constants for common strings * Go back to replaceAll This is required. * Clearer paster (#1953) * WIP - make easier to understand. * Small refactor of paster to make it easier to understand * Fix tabs to spaces. Sorry - new editor! * Fix tabs to spaces * Fix tab to spaces * Improve team kick command (#1957) The kick command has an unnecessary owner check. As command should be configurable by island owners, then limiting it to an owner is wrong. Add a code that allows kicking only lower-ranked players. Add message that shows who kicked from the island. Add message that shows that rank does not allow to kick. * Solve crashes with Addon#allLoaded call (#1959) If some addon has code in Addon#allLoaded that crashes the call, then it did not disable addon as well as did not call allLoaded for every other addon that was left in the list. This should be solved by adding an extra try-catch. * using java 16 syntax (#1958) * Fixes kick command (#1960) PR #1957 broke kick command and noone could kick players from teams. This should fix it. * Fixes a bug with blueprint height (#1961) Blueprint clipboard was preventing setting Y below 0 or above 255. The code was not adjusted to 1.18 changes. Reported via discord. * Fixes Lava Duplication Glitch (#1964) Due to the fact, that Obsidian Scooping uses one tick delay to remove obsidian, a player with a bucket in hand and offhand duplicated lava. To avoid that, added an extra check that ignores the interact event if a player holds a bucket in both hands, and interacted hand is offhand. Fixes #1963 * Fixes failures in obsidian cooping listener. (#1965) Failures happened after implementing #1964 Co-authored-by: BONNe <bonne@bonne.id.lv> Co-authored-by: Invvk <70810073+Invvk@users.noreply.github.com>
2022-04-17 18:04:37 +02:00
owner.ifPresent(user -> tellOwner(user, blocks.size(), attached.size(), entities.size(), plugin.getSettings().getPasteSpeed()));
Bits bits = new Bits(blocks, attached, entities,
blocks.entrySet().iterator(), attached.entrySet().iterator(), entities.entrySet().iterator(),
Version 1.20.1 (#1966) * Version 1.20.1 * Added name of the addon causing the issue. https://github.com/BentoBoxWorld/BentoBox/issues/1944 * Use world min-height for island bounding box. * Fixes a bug when fallback could not use reusable There was an issue in PanelItemTemplate that prevented fallback buttons to be "reusable" things. The issue was that reusable items were not passed to the panel item reader. * Adjusted test to try to avoid errors * Fix for random test failures. * Added 1.18.2 support * Address unnecessary PVP reports on each teleport (#1948) If a player is teleporting on the same island in the same dimension, it keeps spamming that PVP is enabled in dimension. It should be enough with sending messages when the player teleports to the island. Fixes #1885 * Fixes bug with Safe Spot Teleport (#1951) There was a bug that prevented finding a safe spot if all valid blocks were in height with the `startY` location. Reported via discord. * Fix Exception error reported by IDE I am not sure why Eclipse is saying this is an error. * Fix for kicking offline players https://github.com/BentoBoxWorld/BentoBox/issues/1950 * Add an option in SafeSpotTeleport to cancel if fail (#1952) There was no option to cancel teleportation if SafeSpotTeleport could not find a valid spot. This option could be used to avoid creating "backup" blocks in situations when teleportation is avoidable, f.e. visiting an island. * Replace peplaceAll with replace It does the same thing if the first argument is not a regex. * Use constants for common strings * Use constants for common strings * Go back to replaceAll This is required. * Clearer paster (#1953) * WIP - make easier to understand. * Small refactor of paster to make it easier to understand * Fix tabs to spaces. Sorry - new editor! * Fix tabs to spaces * Fix tab to spaces * Improve team kick command (#1957) The kick command has an unnecessary owner check. As command should be configurable by island owners, then limiting it to an owner is wrong. Add a code that allows kicking only lower-ranked players. Add message that shows who kicked from the island. Add message that shows that rank does not allow to kick. * Solve crashes with Addon#allLoaded call (#1959) If some addon has code in Addon#allLoaded that crashes the call, then it did not disable addon as well as did not call allLoaded for every other addon that was left in the list. This should be solved by adding an extra try-catch. * using java 16 syntax (#1958) * Fixes kick command (#1960) PR #1957 broke kick command and noone could kick players from teams. This should fix it. * Fixes a bug with blueprint height (#1961) Blueprint clipboard was preventing setting Y below 0 or above 255. The code was not adjusted to 1.18 changes. Reported via discord. * Fixes Lava Duplication Glitch (#1964) Due to the fact, that Obsidian Scooping uses one tick delay to remove obsidian, a player with a bucket in hand and offhand duplicated lava. To avoid that, added an extra check that ignores the interact event if a player holds a bucket in both hands, and interacted hand is offhand. Fixes #1963 * Fixes failures in obsidian cooping listener. (#1965) Failures happened after implementing #1964 Co-authored-by: BONNe <bonne@bonne.id.lv> Co-authored-by: Invvk <70810073+Invvk@users.noreply.github.com>
2022-04-17 18:04:37 +02:00
plugin.getSettings().getPasteSpeed());
2024-02-24 06:56:32 +01:00
pastingTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> pasterTask(result, owner, bits, useNMS), 0L, 1L);
Version 1.20.1 (#1966) * Version 1.20.1 * Added name of the addon causing the issue. https://github.com/BentoBoxWorld/BentoBox/issues/1944 * Use world min-height for island bounding box. * Fixes a bug when fallback could not use reusable There was an issue in PanelItemTemplate that prevented fallback buttons to be "reusable" things. The issue was that reusable items were not passed to the panel item reader. * Adjusted test to try to avoid errors * Fix for random test failures. * Added 1.18.2 support * Address unnecessary PVP reports on each teleport (#1948) If a player is teleporting on the same island in the same dimension, it keeps spamming that PVP is enabled in dimension. It should be enough with sending messages when the player teleports to the island. Fixes #1885 * Fixes bug with Safe Spot Teleport (#1951) There was a bug that prevented finding a safe spot if all valid blocks were in height with the `startY` location. Reported via discord. * Fix Exception error reported by IDE I am not sure why Eclipse is saying this is an error. * Fix for kicking offline players https://github.com/BentoBoxWorld/BentoBox/issues/1950 * Add an option in SafeSpotTeleport to cancel if fail (#1952) There was no option to cancel teleportation if SafeSpotTeleport could not find a valid spot. This option could be used to avoid creating "backup" blocks in situations when teleportation is avoidable, f.e. visiting an island. * Replace peplaceAll with replace It does the same thing if the first argument is not a regex. * Use constants for common strings * Use constants for common strings * Go back to replaceAll This is required. * Clearer paster (#1953) * WIP - make easier to understand. * Small refactor of paster to make it easier to understand * Fix tabs to spaces. Sorry - new editor! * Fix tabs to spaces * Fix tab to spaces * Improve team kick command (#1957) The kick command has an unnecessary owner check. As command should be configurable by island owners, then limiting it to an owner is wrong. Add a code that allows kicking only lower-ranked players. Add message that shows who kicked from the island. Add message that shows that rank does not allow to kick. * Solve crashes with Addon#allLoaded call (#1959) If some addon has code in Addon#allLoaded that crashes the call, then it did not disable addon as well as did not call allLoaded for every other addon that was left in the list. This should be solved by adding an extra try-catch. * using java 16 syntax (#1958) * Fixes kick command (#1960) PR #1957 broke kick command and noone could kick players from teams. This should fix it. * Fixes a bug with blueprint height (#1961) Blueprint clipboard was preventing setting Y below 0 or above 255. The code was not adjusted to 1.18 changes. Reported via discord. * Fixes Lava Duplication Glitch (#1964) Due to the fact, that Obsidian Scooping uses one tick delay to remove obsidian, a player with a bucket in hand and offhand duplicated lava. To avoid that, added an extra check that ignores the interact event if a player holds a bucket in both hands, and interacted hand is offhand. Fixes #1963 * Fixes failures in obsidian cooping listener. (#1965) Failures happened after implementing #1964 Co-authored-by: BONNe <bonne@bonne.id.lv> Co-authored-by: Invvk <70810073+Invvk@users.noreply.github.com>
2022-04-17 18:04:37 +02:00
return result;
}
2024-02-24 06:56:32 +01:00
private void pasterTask(CompletableFuture<Boolean> result, Optional<User> owner, Bits bits, boolean useNMS) {
if (!currentTask.isDone()) return;
Version 1.20.1 (#1966) * Version 1.20.1 * Added name of the addon causing the issue. https://github.com/BentoBoxWorld/BentoBox/issues/1944 * Use world min-height for island bounding box. * Fixes a bug when fallback could not use reusable There was an issue in PanelItemTemplate that prevented fallback buttons to be "reusable" things. The issue was that reusable items were not passed to the panel item reader. * Adjusted test to try to avoid errors * Fix for random test failures. * Added 1.18.2 support * Address unnecessary PVP reports on each teleport (#1948) If a player is teleporting on the same island in the same dimension, it keeps spamming that PVP is enabled in dimension. It should be enough with sending messages when the player teleports to the island. Fixes #1885 * Fixes bug with Safe Spot Teleport (#1951) There was a bug that prevented finding a safe spot if all valid blocks were in height with the `startY` location. Reported via discord. * Fix Exception error reported by IDE I am not sure why Eclipse is saying this is an error. * Fix for kicking offline players https://github.com/BentoBoxWorld/BentoBox/issues/1950 * Add an option in SafeSpotTeleport to cancel if fail (#1952) There was no option to cancel teleportation if SafeSpotTeleport could not find a valid spot. This option could be used to avoid creating "backup" blocks in situations when teleportation is avoidable, f.e. visiting an island. * Replace peplaceAll with replace It does the same thing if the first argument is not a regex. * Use constants for common strings * Use constants for common strings * Go back to replaceAll This is required. * Clearer paster (#1953) * WIP - make easier to understand. * Small refactor of paster to make it easier to understand * Fix tabs to spaces. Sorry - new editor! * Fix tabs to spaces * Fix tab to spaces * Improve team kick command (#1957) The kick command has an unnecessary owner check. As command should be configurable by island owners, then limiting it to an owner is wrong. Add a code that allows kicking only lower-ranked players. Add message that shows who kicked from the island. Add message that shows that rank does not allow to kick. * Solve crashes with Addon#allLoaded call (#1959) If some addon has code in Addon#allLoaded that crashes the call, then it did not disable addon as well as did not call allLoaded for every other addon that was left in the list. This should be solved by adding an extra try-catch. * using java 16 syntax (#1958) * Fixes kick command (#1960) PR #1957 broke kick command and noone could kick players from teams. This should fix it. * Fixes a bug with blueprint height (#1961) Blueprint clipboard was preventing setting Y below 0 or above 255. The code was not adjusted to 1.18 changes. Reported via discord. * Fixes Lava Duplication Glitch (#1964) Due to the fact, that Obsidian Scooping uses one tick delay to remove obsidian, a player with a bucket in hand and offhand duplicated lava. To avoid that, added an extra check that ignores the interact event if a player holds a bucket in both hands, and interacted hand is offhand. Fixes #1963 * Fixes failures in obsidian cooping listener. (#1965) Failures happened after implementing #1964 Co-authored-by: BONNe <bonne@bonne.id.lv> Co-authored-by: Invvk <70810073+Invvk@users.noreply.github.com>
2022-04-17 18:04:37 +02:00
final int pasteSpeed = plugin.getSettings().getPasteSpeed();
int count = 0;
if (pasteState.equals(PasteState.CHUNK_LOAD)) {
2023-02-05 04:08:09 +01:00
loadChunk();
Version 1.20.1 (#1966) * Version 1.20.1 * Added name of the addon causing the issue. https://github.com/BentoBoxWorld/BentoBox/issues/1944 * Use world min-height for island bounding box. * Fixes a bug when fallback could not use reusable There was an issue in PanelItemTemplate that prevented fallback buttons to be "reusable" things. The issue was that reusable items were not passed to the panel item reader. * Adjusted test to try to avoid errors * Fix for random test failures. * Added 1.18.2 support * Address unnecessary PVP reports on each teleport (#1948) If a player is teleporting on the same island in the same dimension, it keeps spamming that PVP is enabled in dimension. It should be enough with sending messages when the player teleports to the island. Fixes #1885 * Fixes bug with Safe Spot Teleport (#1951) There was a bug that prevented finding a safe spot if all valid blocks were in height with the `startY` location. Reported via discord. * Fix Exception error reported by IDE I am not sure why Eclipse is saying this is an error. * Fix for kicking offline players https://github.com/BentoBoxWorld/BentoBox/issues/1950 * Add an option in SafeSpotTeleport to cancel if fail (#1952) There was no option to cancel teleportation if SafeSpotTeleport could not find a valid spot. This option could be used to avoid creating "backup" blocks in situations when teleportation is avoidable, f.e. visiting an island. * Replace peplaceAll with replace It does the same thing if the first argument is not a regex. * Use constants for common strings * Use constants for common strings * Go back to replaceAll This is required. * Clearer paster (#1953) * WIP - make easier to understand. * Small refactor of paster to make it easier to understand * Fix tabs to spaces. Sorry - new editor! * Fix tabs to spaces * Fix tab to spaces * Improve team kick command (#1957) The kick command has an unnecessary owner check. As command should be configurable by island owners, then limiting it to an owner is wrong. Add a code that allows kicking only lower-ranked players. Add message that shows who kicked from the island. Add message that shows that rank does not allow to kick. * Solve crashes with Addon#allLoaded call (#1959) If some addon has code in Addon#allLoaded that crashes the call, then it did not disable addon as well as did not call allLoaded for every other addon that was left in the list. This should be solved by adding an extra try-catch. * using java 16 syntax (#1958) * Fixes kick command (#1960) PR #1957 broke kick command and noone could kick players from teams. This should fix it. * Fixes a bug with blueprint height (#1961) Blueprint clipboard was preventing setting Y below 0 or above 255. The code was not adjusted to 1.18 changes. Reported via discord. * Fixes Lava Duplication Glitch (#1964) Due to the fact, that Obsidian Scooping uses one tick delay to remove obsidian, a player with a bucket in hand and offhand duplicated lava. To avoid that, added an extra check that ignores the interact event if a player holds a bucket in both hands, and interacted hand is offhand. Fixes #1963 * Fixes failures in obsidian cooping listener. (#1965) Failures happened after implementing #1964 Co-authored-by: BONNe <bonne@bonne.id.lv> Co-authored-by: Invvk <70810073+Invvk@users.noreply.github.com>
2022-04-17 18:04:37 +02:00
}
else if (pasteState.equals(PasteState.BLOCKS) || pasteState.equals(PasteState.ATTACHMENTS)) {
2024-02-24 06:56:32 +01:00
pasteBlocks(bits, count, owner, pasteSpeed, useNMS);
Version 1.20.1 (#1966) * Version 1.20.1 * Added name of the addon causing the issue. https://github.com/BentoBoxWorld/BentoBox/issues/1944 * Use world min-height for island bounding box. * Fixes a bug when fallback could not use reusable There was an issue in PanelItemTemplate that prevented fallback buttons to be "reusable" things. The issue was that reusable items were not passed to the panel item reader. * Adjusted test to try to avoid errors * Fix for random test failures. * Added 1.18.2 support * Address unnecessary PVP reports on each teleport (#1948) If a player is teleporting on the same island in the same dimension, it keeps spamming that PVP is enabled in dimension. It should be enough with sending messages when the player teleports to the island. Fixes #1885 * Fixes bug with Safe Spot Teleport (#1951) There was a bug that prevented finding a safe spot if all valid blocks were in height with the `startY` location. Reported via discord. * Fix Exception error reported by IDE I am not sure why Eclipse is saying this is an error. * Fix for kicking offline players https://github.com/BentoBoxWorld/BentoBox/issues/1950 * Add an option in SafeSpotTeleport to cancel if fail (#1952) There was no option to cancel teleportation if SafeSpotTeleport could not find a valid spot. This option could be used to avoid creating "backup" blocks in situations when teleportation is avoidable, f.e. visiting an island. * Replace peplaceAll with replace It does the same thing if the first argument is not a regex. * Use constants for common strings * Use constants for common strings * Go back to replaceAll This is required. * Clearer paster (#1953) * WIP - make easier to understand. * Small refactor of paster to make it easier to understand * Fix tabs to spaces. Sorry - new editor! * Fix tabs to spaces * Fix tab to spaces * Improve team kick command (#1957) The kick command has an unnecessary owner check. As command should be configurable by island owners, then limiting it to an owner is wrong. Add a code that allows kicking only lower-ranked players. Add message that shows who kicked from the island. Add message that shows that rank does not allow to kick. * Solve crashes with Addon#allLoaded call (#1959) If some addon has code in Addon#allLoaded that crashes the call, then it did not disable addon as well as did not call allLoaded for every other addon that was left in the list. This should be solved by adding an extra try-catch. * using java 16 syntax (#1958) * Fixes kick command (#1960) PR #1957 broke kick command and noone could kick players from teams. This should fix it. * Fixes a bug with blueprint height (#1961) Blueprint clipboard was preventing setting Y below 0 or above 255. The code was not adjusted to 1.18 changes. Reported via discord. * Fixes Lava Duplication Glitch (#1964) Due to the fact, that Obsidian Scooping uses one tick delay to remove obsidian, a player with a bucket in hand and offhand duplicated lava. To avoid that, added an extra check that ignores the interact event if a player holds a bucket in both hands, and interacted hand is offhand. Fixes #1963 * Fixes failures in obsidian cooping listener. (#1965) Failures happened after implementing #1964 Co-authored-by: BONNe <bonne@bonne.id.lv> Co-authored-by: Invvk <70810073+Invvk@users.noreply.github.com>
2022-04-17 18:04:37 +02:00
}
else if (pasteState.equals(PasteState.ENTITIES)) {
2024-02-24 06:56:32 +01:00
pasteEntities(bits, count, owner, pasteSpeed, useNMS);
Version 1.20.1 (#1966) * Version 1.20.1 * Added name of the addon causing the issue. https://github.com/BentoBoxWorld/BentoBox/issues/1944 * Use world min-height for island bounding box. * Fixes a bug when fallback could not use reusable There was an issue in PanelItemTemplate that prevented fallback buttons to be "reusable" things. The issue was that reusable items were not passed to the panel item reader. * Adjusted test to try to avoid errors * Fix for random test failures. * Added 1.18.2 support * Address unnecessary PVP reports on each teleport (#1948) If a player is teleporting on the same island in the same dimension, it keeps spamming that PVP is enabled in dimension. It should be enough with sending messages when the player teleports to the island. Fixes #1885 * Fixes bug with Safe Spot Teleport (#1951) There was a bug that prevented finding a safe spot if all valid blocks were in height with the `startY` location. Reported via discord. * Fix Exception error reported by IDE I am not sure why Eclipse is saying this is an error. * Fix for kicking offline players https://github.com/BentoBoxWorld/BentoBox/issues/1950 * Add an option in SafeSpotTeleport to cancel if fail (#1952) There was no option to cancel teleportation if SafeSpotTeleport could not find a valid spot. This option could be used to avoid creating "backup" blocks in situations when teleportation is avoidable, f.e. visiting an island. * Replace peplaceAll with replace It does the same thing if the first argument is not a regex. * Use constants for common strings * Use constants for common strings * Go back to replaceAll This is required. * Clearer paster (#1953) * WIP - make easier to understand. * Small refactor of paster to make it easier to understand * Fix tabs to spaces. Sorry - new editor! * Fix tabs to spaces * Fix tab to spaces * Improve team kick command (#1957) The kick command has an unnecessary owner check. As command should be configurable by island owners, then limiting it to an owner is wrong. Add a code that allows kicking only lower-ranked players. Add message that shows who kicked from the island. Add message that shows that rank does not allow to kick. * Solve crashes with Addon#allLoaded call (#1959) If some addon has code in Addon#allLoaded that crashes the call, then it did not disable addon as well as did not call allLoaded for every other addon that was left in the list. This should be solved by adding an extra try-catch. * using java 16 syntax (#1958) * Fixes kick command (#1960) PR #1957 broke kick command and noone could kick players from teams. This should fix it. * Fixes a bug with blueprint height (#1961) Blueprint clipboard was preventing setting Y below 0 or above 255. The code was not adjusted to 1.18 changes. Reported via discord. * Fixes Lava Duplication Glitch (#1964) Due to the fact, that Obsidian Scooping uses one tick delay to remove obsidian, a player with a bucket in hand and offhand duplicated lava. To avoid that, added an extra check that ignores the interact event if a player holds a bucket in both hands, and interacted hand is offhand. Fixes #1963 * Fixes failures in obsidian cooping listener. (#1965) Failures happened after implementing #1964 Co-authored-by: BONNe <bonne@bonne.id.lv> Co-authored-by: Invvk <70810073+Invvk@users.noreply.github.com>
2022-04-17 18:04:37 +02:00
}
else if (pasteState.equals(PasteState.DONE)) {
// All done. Cancel task
2023-02-05 04:08:09 +01:00
cancelTask(result);
Version 1.20.1 (#1966) * Version 1.20.1 * Added name of the addon causing the issue. https://github.com/BentoBoxWorld/BentoBox/issues/1944 * Use world min-height for island bounding box. * Fixes a bug when fallback could not use reusable There was an issue in PanelItemTemplate that prevented fallback buttons to be "reusable" things. The issue was that reusable items were not passed to the panel item reader. * Adjusted test to try to avoid errors * Fix for random test failures. * Added 1.18.2 support * Address unnecessary PVP reports on each teleport (#1948) If a player is teleporting on the same island in the same dimension, it keeps spamming that PVP is enabled in dimension. It should be enough with sending messages when the player teleports to the island. Fixes #1885 * Fixes bug with Safe Spot Teleport (#1951) There was a bug that prevented finding a safe spot if all valid blocks were in height with the `startY` location. Reported via discord. * Fix Exception error reported by IDE I am not sure why Eclipse is saying this is an error. * Fix for kicking offline players https://github.com/BentoBoxWorld/BentoBox/issues/1950 * Add an option in SafeSpotTeleport to cancel if fail (#1952) There was no option to cancel teleportation if SafeSpotTeleport could not find a valid spot. This option could be used to avoid creating "backup" blocks in situations when teleportation is avoidable, f.e. visiting an island. * Replace peplaceAll with replace It does the same thing if the first argument is not a regex. * Use constants for common strings * Use constants for common strings * Go back to replaceAll This is required. * Clearer paster (#1953) * WIP - make easier to understand. * Small refactor of paster to make it easier to understand * Fix tabs to spaces. Sorry - new editor! * Fix tabs to spaces * Fix tab to spaces * Improve team kick command (#1957) The kick command has an unnecessary owner check. As command should be configurable by island owners, then limiting it to an owner is wrong. Add a code that allows kicking only lower-ranked players. Add message that shows who kicked from the island. Add message that shows that rank does not allow to kick. * Solve crashes with Addon#allLoaded call (#1959) If some addon has code in Addon#allLoaded that crashes the call, then it did not disable addon as well as did not call allLoaded for every other addon that was left in the list. This should be solved by adding an extra try-catch. * using java 16 syntax (#1958) * Fixes kick command (#1960) PR #1957 broke kick command and noone could kick players from teams. This should fix it. * Fixes a bug with blueprint height (#1961) Blueprint clipboard was preventing setting Y below 0 or above 255. The code was not adjusted to 1.18 changes. Reported via discord. * Fixes Lava Duplication Glitch (#1964) Due to the fact, that Obsidian Scooping uses one tick delay to remove obsidian, a player with a bucket in hand and offhand duplicated lava. To avoid that, added an extra check that ignores the interact event if a player holds a bucket in both hands, and interacted hand is offhand. Fixes #1963 * Fixes failures in obsidian cooping listener. (#1965) Failures happened after implementing #1964 Co-authored-by: BONNe <bonne@bonne.id.lv> Co-authored-by: Invvk <70810073+Invvk@users.noreply.github.com>
2022-04-17 18:04:37 +02:00
} else if (pasteState.equals(PasteState.CANCEL)) {
// This state makes sure the follow-on task only ever runs once
pastingTask.cancel();
result.complete(true);
}
}
2023-02-05 04:08:09 +01:00
private void cancelTask(CompletableFuture<Boolean> result) {
// Set pos1 and 2 if this was a clipboard paste
if (island == null && clipboard != null) {
clipboard.setPos1(pos1);
clipboard.setPos2(pos2);
}
pasteState = PasteState.CANCEL;
result.complete(true);
}
2024-02-24 06:56:32 +01:00
private void pasteEntities(Bits bits, int count, Optional<User> owner, int pasteSpeed, boolean useNMS) {
2023-02-05 04:08:09 +01:00
if (bits.it3().hasNext()) {
Map<Location, List<BlueprintEntity>> entityMap = new HashMap<>();
// Paste entities
while (count < pasteSpeed) {
if (!bits.it3().hasNext()) {
break;
}
Entry<Vector, List<BlueprintEntity>> entry = bits.it3().next();
int x = location.getBlockX() + entry.getKey().getBlockX();
int y = location.getBlockY() + entry.getKey().getBlockY();
int z = location.getBlockZ() + entry.getKey().getBlockZ();
Location center = new Location(world, x, y, z).add(new Vector(0.5, 0.5, 0.5));
List<BlueprintEntity> entities = entry.getValue();
entityMap.put(center, entities);
count++;
}
if (!entityMap.isEmpty()) {
2024-02-24 06:56:32 +01:00
currentTask = useNMS ? paster.pasteEntities(island, world, entityMap)
: fallback.pasteEntities(island, world, entityMap);
2023-02-05 04:08:09 +01:00
}
} else {
pasteState = PasteState.DONE;
String dimensionType = switch (location.getWorld().getEnvironment()) {
case NETHER -> owner.map(user -> user.getTranslation("general.worlds.nether")).orElse("");
case THE_END -> owner.map(user -> user.getTranslation("general.worlds.the-end")).orElse("");
default -> owner.map(user -> user.getTranslation("general.worlds.overworld")).orElse("");
};
owner.ifPresent(user -> user.sendMessage("commands.island.create.pasting.dimension-done", "[world]", dimensionType));
}
}
2024-02-24 06:56:32 +01:00
private void pasteBlocks(Bits bits, int count, Optional<User> owner, int pasteSpeed, boolean useNMS) {
2023-02-05 04:08:09 +01:00
Iterator<Entry<Vector, BlueprintBlock>> it = pasteState.equals(PasteState.BLOCKS) ? bits.it : bits.it2;
if (it.hasNext()) {
2024-03-16 02:49:20 +01:00
pasteBlocksNow(it, count, pasteSpeed, useNMS);
2023-02-05 04:08:09 +01:00
} else {
if (pasteState.equals(PasteState.BLOCKS)) {
// Blocks done
// Next paste attachments
pasteState = PasteState.ATTACHMENTS;
} else {
// Attachments done. Next paste entities
pasteState = PasteState.ENTITIES;
if (bits.entities.size() != 0) {
owner.ifPresent(user -> user.sendMessage("commands.island.create.pasting.entities", TextVariables.NUMBER, String.valueOf(bits.entities.size())));
}
}
}
}
2024-03-16 02:49:20 +01:00
private void pasteBlocksNow(Iterator<Entry<Vector, BlueprintBlock>> it, int count, int pasteSpeed, boolean useNMS) {
Map<Location, BlueprintBlock> blockMap = new HashMap<>();
// Paste blocks
while (count < pasteSpeed) {
if (!it.hasNext()) {
break;
}
Entry<Vector, BlueprintBlock> entry = it.next();
Location pasteTo = location.clone().add(entry.getKey());
// pos1 and pos2 update
updatePos(pasteTo);
BlueprintBlock block = entry.getValue();
blockMap.put(pasteTo, block);
count++;
}
if (!blockMap.isEmpty()) {
currentTask = useNMS ? paster.pasteBlocks(island, world, blockMap)
: fallback.pasteBlocks(island, world, blockMap);
}
}
2023-02-05 04:08:09 +01:00
private void loadChunk() {
long timer = System.currentTimeMillis();
pasteState = PasteState.CHUNK_LOADING;
// Load chunk
currentTask = Util.getChunkAtAsync(location).thenRun(() -> {
pasteState = PasteState.BLOCKS;
long duration = System.currentTimeMillis() - timer;
if (duration > chunkLoadTime) {
chunkLoadTime = duration;
}
});
}
private void tellOwner(User user, int blocksSize, int attachedSize, int entitiesSize, int pasteSpeed) {
Version 1.20.1 (#1966) * Version 1.20.1 * Added name of the addon causing the issue. https://github.com/BentoBoxWorld/BentoBox/issues/1944 * Use world min-height for island bounding box. * Fixes a bug when fallback could not use reusable There was an issue in PanelItemTemplate that prevented fallback buttons to be "reusable" things. The issue was that reusable items were not passed to the panel item reader. * Adjusted test to try to avoid errors * Fix for random test failures. * Added 1.18.2 support * Address unnecessary PVP reports on each teleport (#1948) If a player is teleporting on the same island in the same dimension, it keeps spamming that PVP is enabled in dimension. It should be enough with sending messages when the player teleports to the island. Fixes #1885 * Fixes bug with Safe Spot Teleport (#1951) There was a bug that prevented finding a safe spot if all valid blocks were in height with the `startY` location. Reported via discord. * Fix Exception error reported by IDE I am not sure why Eclipse is saying this is an error. * Fix for kicking offline players https://github.com/BentoBoxWorld/BentoBox/issues/1950 * Add an option in SafeSpotTeleport to cancel if fail (#1952) There was no option to cancel teleportation if SafeSpotTeleport could not find a valid spot. This option could be used to avoid creating "backup" blocks in situations when teleportation is avoidable, f.e. visiting an island. * Replace peplaceAll with replace It does the same thing if the first argument is not a regex. * Use constants for common strings * Use constants for common strings * Go back to replaceAll This is required. * Clearer paster (#1953) * WIP - make easier to understand. * Small refactor of paster to make it easier to understand * Fix tabs to spaces. Sorry - new editor! * Fix tabs to spaces * Fix tab to spaces * Improve team kick command (#1957) The kick command has an unnecessary owner check. As command should be configurable by island owners, then limiting it to an owner is wrong. Add a code that allows kicking only lower-ranked players. Add message that shows who kicked from the island. Add message that shows that rank does not allow to kick. * Solve crashes with Addon#allLoaded call (#1959) If some addon has code in Addon#allLoaded that crashes the call, then it did not disable addon as well as did not call allLoaded for every other addon that was left in the list. This should be solved by adding an extra try-catch. * using java 16 syntax (#1958) * Fixes kick command (#1960) PR #1957 broke kick command and noone could kick players from teams. This should fix it. * Fixes a bug with blueprint height (#1961) Blueprint clipboard was preventing setting Y below 0 or above 255. The code was not adjusted to 1.18 changes. Reported via discord. * Fixes Lava Duplication Glitch (#1964) Due to the fact, that Obsidian Scooping uses one tick delay to remove obsidian, a player with a bucket in hand and offhand duplicated lava. To avoid that, added an extra check that ignores the interact event if a player holds a bucket in both hands, and interacted hand is offhand. Fixes #1963 * Fixes failures in obsidian cooping listener. (#1965) Failures happened after implementing #1964 Co-authored-by: BONNe <bonne@bonne.id.lv> Co-authored-by: Invvk <70810073+Invvk@users.noreply.github.com>
2022-04-17 18:04:37 +02:00
// Estimated time:
double total = (double) blocksSize + attachedSize + entitiesSize;
BigDecimal time = BigDecimal.valueOf(total / (pasteSpeed * 20.0D) + (chunkLoadTime / 1000.0D)).setScale(1, RoundingMode.UP);
user.sendMessage("commands.island.create.pasting.estimated-time", TextVariables.NUMBER, String.valueOf(time.doubleValue()));
// We're pasting blocks!
user.sendMessage("commands.island.create.pasting.blocks", TextVariables.NUMBER, String.valueOf(blocksSize + attachedSize));
}
/**
* Tracks the minimum and maximum block positions
* @param l - location of block pasted
*/
private void updatePos(Location l) {
if (pos1 == null) {
pos1 = l.clone();
}
if (pos2 == null) {
pos2 = l.clone();
}
if (l.getBlockX() < pos1.getBlockX()) {
pos1.setX(l.getBlockX());
}
if (l.getBlockX() > pos2.getBlockX()) {
pos2.setX(l.getBlockX());
}
if (l.getBlockY() < pos1.getBlockY()) {
pos1.setY(l.getBlockY());
}
if (l.getBlockY() > pos2.getBlockY()) {
pos2.setY(l.getBlockY());
}
if (l.getBlockZ() < pos1.getBlockZ()) {
pos1.setZ(l.getBlockZ());
}
if (l.getBlockZ() > pos2.getBlockZ()) {
pos2.setZ(l.getBlockZ());
}
}
}