Skip to content

Commit

Permalink
Merge pull request #29 from josemmo/develop
Browse files Browse the repository at this point in the history
v1.2.2
  • Loading branch information
josemmo authored Jan 29, 2022
2 parents 9048795 + 038f3c8 commit e7dfc2e
Show file tree
Hide file tree
Showing 10 changed files with 385 additions and 192 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ jobs:
fail-fast: false
matrix:
flavor: ['bukkit', 'spigot', 'paper', 'purpur']
version: ['1.18', '1.17.1', '1.17', '1.16.5', '1.16.4', '1.16.3', '1.16.2', '1.16.1']
continue-on-error: ${{ matrix.version == '1.18' }}
version: ['1.18.1', '1.18', '1.17.1', '1.17', '1.16.5', '1.16.4', '1.16.3', '1.16.2', '1.16.1']
steps:
# Download code from repository
- name: Checkout code
Expand Down
503 changes: 338 additions & 165 deletions automata/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion automata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"start": "node index.js"
},
"dependencies": {
"mineflayer": "^3.11.0",
"mineflayer": "^3.15.0",
"rcon-client": "^4.2.3"
}
}
3 changes: 3 additions & 0 deletions automata/src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export function startBot() {
})
}

/**
* @param {mineflayer.Bot} bot Bot instance
*/
export function placeBlockOnTheFloor(bot) {
bot._client.write('block_place', {
location: bot.entity.position.offset(0, -1, 0),
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.josemmo.bukkit.plugin</groupId>
<artifactId>YamipaPlugin</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public static void downloadImage(@NotNull CommandSender sender, @NotNull String
sender.sendMessage(ChatColor.RED + "The remote URL is not valid");
} catch (IOException e) {
sender.sendMessage(ChatColor.RED + "An error occurred trying to download the remote file");
plugin.warning("Failed to download file from \"" + url + "\": " + e.getClass().getName());
}
});
}
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/io/josemmo/bukkit/plugin/renderer/ImageRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,12 @@ public int size() {
Set<Player> players = new HashSet<>();
for (Map.Entry<UUID, WorldAreaId> entry : playersLocation.entrySet()) {
if (neighborhood.contains(entry.getValue())) {
Player player = Bukkit.getPlayer(entry.getKey());
UUID uuid = entry.getKey();
Player player = Bukkit.getPlayer(uuid);
if (player == null) {
plugin.warning("Failed to get online player with UUID " + uuid);
continue;
}
players.add(player);
}
}
Expand Down Expand Up @@ -420,16 +425,16 @@ public void onPlayerRespawn(@NotNull PlayerRespawnEvent event) {
onPlayerLocationChange(event.getPlayer(), event.getPlayer().getLocation());
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerChangedWorld(@NotNull PlayerChangedWorldEvent event) {
onPlayerLocationChange(event.getPlayer(), event.getPlayer().getLocation());
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerTeleport(@NotNull PlayerTeleportEvent event) {
if (event.getTo() == null) return;
if (event.getFrom().getChunk().equals(event.getTo().getChunk())) return;
onPlayerLocationChange(event.getPlayer(), event.getTo());

// Wait until next server tick before handling location change
// This is necessary as teleport events get fired *before* teleporting the player
Bukkit.getScheduler().runTask(plugin, () -> {
onPlayerLocationChange(event.getPlayer(), event.getTo());
});
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/josemmo/bukkit/plugin/storage/ImageFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ protected ImageFile(@NotNull String name, @NotNull String path) {
int originalHeight = reader.getHeight(0);
BufferedImage tmpImage = new BufferedImage(originalWidth, originalHeight, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D tmpGraphics = tmpImage.createGraphics();
tmpGraphics.setBackground(new Color(0, 0, 0, 0));

// Create temporary scaled canvas (for resizing)
BufferedImage tmpScaledImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D tmpScaledGraphics = tmpScaledImage.createGraphics();
tmpScaledGraphics.setBackground(new Color(0, 0, 0, 0));

// Read images from file
byte[][] renderedImages = new byte[numOfSteps][width*height];
Expand All @@ -99,6 +101,7 @@ protected ImageFile(@NotNull String name, @NotNull String path) {
// Extract step metadata
int imageLeft = 0;
int imageTop = 0;
boolean disposePrevious = false;
if (format.equalsIgnoreCase("gif")) {
IIOMetadata metadata = reader.getImageMetadata(step);
IIOMetadataNode metadataRoot = (IIOMetadataNode) metadata.getAsTree(metadata.getNativeMetadataFormatName());
Expand All @@ -112,10 +115,17 @@ protected ImageFile(@NotNull String name, @NotNull String path) {
IIOMetadataNode controlExtensionNode = (IIOMetadataNode) metadataRoot.item(i);
int delay = Integer.parseInt(controlExtensionNode.getAttribute("delayTime"));
delays.compute(delay, (__, count) -> (count == null) ? 1 : count+1);
disposePrevious = controlExtensionNode.getAttribute("disposalMethod").startsWith("restore");
}
}
}

// Clear temporary canvases (if needed)
if (disposePrevious) {
tmpGraphics.clearRect(0, 0, originalWidth, originalHeight);
tmpScaledGraphics.clearRect(0, 0, width, height);
}

// Paint step image over temporary canvas
BufferedImage image = reader.read(step);
tmpGraphics.drawImage(image, imageLeft, imageTop, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public final void onPacketReceiving(@NotNull PacketEvent event) {
List<Block> lastTwoTargetBlocks = player.getLastTwoTargetBlocks(null, MAX_BLOCK_DISTANCE);
if (lastTwoTargetBlocks.size() != 2) return;
Block targetBlock = lastTwoTargetBlocks.get(1);
if (!targetBlock.getType().isOccluding()) return;
if (!targetBlock.getType().isSolid()) return;

// Get target block face
Block adjacentBlock = lastTwoTargetBlocks.get(0);
Expand Down
32 changes: 17 additions & 15 deletions src/main/java/io/josemmo/bukkit/plugin/utils/SelectBlockTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,17 @@ public void onBlockInteraction(@NotNull PlayerInteractEvent event) {
if (block == null) return;
BlockFace face = event.getBlockFace();

// Handle failure event
// Handle event
boolean allowEvent = true;
if (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) {
event.setCancelled(true);
handle(player, null, null);
return;
allowEvent = handle(player, null, null);
} else if (action == Action.RIGHT_CLICK_BLOCK) {
allowEvent = handle(player, block, face);
}

// Handle success event
if (action == Action.RIGHT_CLICK_BLOCK) {
// Cancel event (if needed)
if (!allowEvent) {
event.setCancelled(true);
handle(player, block, face);
}
}

Expand All @@ -149,7 +149,10 @@ public void onArmSwing(@NotNull PlayerAnimationEvent event) {
// Sanity check, vanilla Minecraft does not have any other player animation type
return;
}
handle(event.getPlayer(), null, null);
boolean allowEvent = handle(event.getPlayer(), null, null);
if (!allowEvent) {
event.setCancelled(true);
}
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
Expand All @@ -163,21 +166,19 @@ public void onPlayerQuit(@NotNull PlayerQuitEvent event) {

@Override
public boolean onAttack(@NotNull Player player, @NotNull Block block, @NotNull BlockFace face) {
handle(player, null, null);
return false;
return handle(player, null, null);
}

@Override
public boolean onInteract(@NotNull Player player, @NotNull Block block, @NotNull BlockFace face) {
handle(player, block, face);
return false;
return handle(player, block, face);
}

private void handle(@NotNull Player player, @Nullable Block block, @Nullable BlockFace face) {
private boolean handle(@NotNull Player player, @Nullable Block block, @Nullable BlockFace face) {
// Get task responsible for handling this event
UUID uuid = player.getUniqueId();
SelectBlockTask task = instances.get(uuid);
if (task == null) return;
if (task == null) return true;

// Cancel task
task.cancel();
Expand All @@ -187,13 +188,14 @@ private void handle(@NotNull Player player, @Nullable Block block, @Nullable Blo
if (task.failure != null) {
task.failure.run();
}
return;
return false;
}

// Notify success listener
if (task.success != null) {
task.success.accept(block.getLocation(), face);
}
return false;
}
}
}

0 comments on commit e7dfc2e

Please sign in to comment.