NEWS: Welcome to my new homepage! <3

Fixed chair bug - poppy - A feature-rich Minecraft plugin which enhances gaming experience

poppy

A feature-rich Minecraft plugin which enhances gaming experience
git clone git://192.168.2.2/poppy
Log | Files | Refs | README

commit 898b3131b4fc43fb31516b767fdb30b62a54c540
parent 6c3d05f9c937d5c2773dbbf0bb29175902e3ba8d
Author: typable <typable.dev@gmail.com>
Date:   Mon, 17 May 2021 23:26:44 +0200

Fixed chair bug

Diffstat:
M.gitignore | 1+
Mbuild.gradle | 22++++++++++++++++++++++
Dbuild.sh | 31-------------------------------
Agradle.properties | 1+
Msrc/de/typable/minecrafthub/event/ChairListener.java | 101+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/de/typable/minecrafthub/util/Util.java | 25+++++++++++++++++++++++++
Dtodo.txt | 7-------
7 files changed, 101 insertions(+), 87 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -6,3 +6,4 @@ *.prefs /build/** /.gradle/** +/.env/** diff --git a/build.gradle b/build.gradle @@ -1,3 +1,7 @@ +plugins { + id 'org.hidetake.ssh' version '2.10.1' +} + apply plugin: 'java' sourceSets { @@ -24,4 +28,22 @@ targetCompatibility = 1.11 dependencies { implementation 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT' implementation 'com.google.code.gson:gson:2.8.6' +} + +remotes { + server { + host = 'mc.typable.dev' + user = 'pi' + identity = file('.env/id_rsa') + } +} + +task deploy { + doLast { + ssh.run { + session(remotes.server) { + put from: project.file('build/libs/MinecraftHub.jar'), into: '/home/pi/host/plugins' + } + } + } } \ No newline at end of file diff --git a/build.sh b/build.sh @@ -1,30 +0,0 @@ -#!/bin/bash - -path=$(pwd) - -if [[ ! -z $1 ]]; then - if [ $1 = "--path" ]; then - if [[ -z $2 ]]; then - echo "Invalid arguments '--path <directory>'!" - exit 0 - fi - path=$2 - fi -fi - -if [ ! -d $path ]; then - echo "Unable to find directory '$path'!" - exit 0 -fi - -if [ ! -f "$(pwd)/plugin.yml" ]; then - echo "Unable to find plugin.yml in '$(pwd)'!" - exit 0 -fi - -jar cf "$path/MinecraftHub.jar" plugin.yml lib/* -C bin . -if [ $? = "0" ]; then - echo "Successfully compile into $path/MinecraftHub.jar" -else - echo "Build failed!" -fi -\ No newline at end of file diff --git a/gradle.properties b/gradle.properties @@ -0,0 +1 @@ +org.gradle.console=plain diff --git a/src/de/typable/minecrafthub/event/ChairListener.java b/src/de/typable/minecrafthub/event/ChairListener.java @@ -7,7 +7,6 @@ import java.util.Map.Entry; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import org.bukkit.block.data.Bisected.Half; import org.bukkit.block.data.type.Stairs; import org.bukkit.entity.ArmorStand; @@ -21,6 +20,8 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.spigotmc.event.entity.EntityDismountEvent; +import de.typable.minecrafthub.util.Util; + public class ChairListener implements Listener { @@ -39,7 +40,15 @@ public class ChairListener implements Listener private Map<Block, ArmorStand> blockMap = new HashMap<>(); - @SuppressWarnings("deprecation") + public void onDisable() + { + for(ArmorStand armorStand : blockMap.values()) + { + armorStand.eject(); + armorStand.remove(); + } + } + @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { @@ -53,7 +62,7 @@ public class ChairListener implements Listener if(isChair(block.getType())) { - if(block.getLocation().add(0.5, 0.5, 0.5).distance(player.getLocation()) > 2) + if(!isInRange(block, player)) { return; } @@ -63,35 +72,18 @@ public class ChairListener implements Listener return; } - Block upperBlock = block.getWorld().getBlockAt(block.getLocation().add(0, 1, 0)); - - if(upperBlock != null && upperBlock.getType() == Material.AIR) + if(isCompatible(block)) { - Stairs stairs = (Stairs) block.getState().getBlockData(); + ArmorStand armorStand = createMountableChair(block, player); - if(isCompatible(stairs)) + if(armorStand == null) { - Float yaw = convertFacingToYaw(stairs.getFacing()); - - if(yaw == null) - { - return; - } - - Location location = block.getLocation().add(0.5, -0.4, 0.5); - location.setYaw(yaw); - - ArmorStand armorStand = (ArmorStand) block.getWorld().spawnEntity(location, EntityType.ARMOR_STAND); - armorStand.setPassenger((Entity) event.getPlayer()); - armorStand.setSmall(true); - armorStand.setGravity(false); - armorStand.setInvulnerable(true); - armorStand.setVisible(false); + return; + } - event.setCancelled(true); + event.setCancelled(true); - blockMap.put(block, armorStand); - } + blockMap.put(block, armorStand); } } } @@ -139,6 +131,11 @@ public class ChairListener implements Listener } } + private boolean isInRange(Block block, Player player) + { + return block.getLocation().add(0.5, 0.5, 0.5).distance(player.getLocation()) <= 2; + } + private boolean isChair(Material material) { for(Material chair : CHAIR_TYPE) @@ -152,8 +149,17 @@ public class ChairListener implements Listener return false; } - private boolean isCompatible(Stairs stairs) + private boolean isCompatible(Block block) { + Block upperBlock = block.getWorld().getBlockAt(block.getLocation().add(0, 1, 0)); + + if(!Util.isAir(upperBlock.getType())) + { + return false; + } + + Stairs stairs = (Stairs) block.getState().getBlockData(); + if(stairs.getHalf() != Half.BOTTOM) { return false; @@ -172,31 +178,28 @@ public class ChairListener implements Listener return true; } - private Float convertFacingToYaw(BlockFace face) + @SuppressWarnings("deprecation") + private ArmorStand createMountableChair(Block block, Player player) { - switch(face) - { - case NORTH: - return 0F; - case EAST: - return 90F; - case SOUTH: - return 180F; - case WEST: - return -90F; - default: - break; - } + Stairs stairs = (Stairs) block.getState().getBlockData(); - return null; - } + Float yaw = Util.convertFacingToYaw(stairs.getFacing()); - public void onDisable() - { - for(ArmorStand armorStand : blockMap.values()) + if(yaw == null) { - armorStand.eject(); - armorStand.remove(); + return null; } + + Location location = block.getLocation().add(0.5, -0.4, 0.5); + location.setYaw(yaw); + + ArmorStand armorStand = (ArmorStand) block.getWorld().spawnEntity(location, EntityType.ARMOR_STAND); + armorStand.setPassenger((Entity) player); + armorStand.setSmall(true); + armorStand.setGravity(false); + armorStand.setInvulnerable(true); + armorStand.setVisible(false); + + return armorStand; } } diff --git a/src/de/typable/minecrafthub/util/Util.java b/src/de/typable/minecrafthub/util/Util.java @@ -2,6 +2,7 @@ package de.typable.minecrafthub.util; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -107,4 +108,28 @@ public class Util } }, 0L, DefaultConstants.TICK); } + + public static Float convertFacingToYaw(BlockFace face) + { + switch(face) + { + case NORTH: + return 0F; + case EAST: + return 90F; + case SOUTH: + return 180F; + case WEST: + return -90F; + default: + break; + } + + return null; + } + + public static boolean isAir(Material material) + { + return material == Material.AIR || material == Material.CAVE_AIR || material == Material.VOID_AIR; + } } diff --git a/todo.txt b/todo.txt @@ -1,7 +0,0 @@ -Legend: -[ ] = Open [?] = Test [X] = Done [-] = Ignore [!] = Stuck [/] = Partial [i] = Clarify - -Syntax: [<state>] <message> -Example: [?] Test latest changes - -----------------------------------------------------------------------------------------------------