commit 6c3d05f9c937d5c2773dbbf0bb29175902e3ba8d
parent a5e09fcc8a17ebab2b6a0b843351e3d3ded9286d
Author: typable <typable.dev@gmail.com>
Date: Sun, 16 May 2021 17:15:27 +0200
Added Gradle & Improved chairs
Diffstat:
7 files changed, 133 insertions(+), 35 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -4,3 +4,5 @@
.classpath
.project
*.prefs
+/build/**
+/.gradle/**
diff --git a/.vscode/settings.json b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "java.configuration.updateBuildConfiguration": "automatic"
+}
+\ No newline at end of file
diff --git a/build.gradle b/build.gradle
@@ -0,0 +1,27 @@
+apply plugin: 'java'
+
+sourceSets {
+ main {
+ java {
+ srcDirs 'src'
+ }
+ resources {
+ srcDirs 'res'
+ }
+ }
+}
+
+repositories {
+ mavenCentral()
+ maven {
+ url = 'https://hub.spigotmc.org/nexus/content/repositories/public/'
+ }
+}
+
+sourceCompatibility = 1.11
+targetCompatibility = 1.11
+
+dependencies {
+ implementation 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT'
+ implementation 'com.google.code.gson:gson:2.8.6'
+}
+\ No newline at end of file
diff --git a/plugin.yml b/plugin.yml
@@ -1,12 +0,0 @@
-main: de.typable.minecrafthub.Main
-name: MinecraftHub
-version: 0.0.1
-author: typable
-api-version: 1.16
-commands:
- shutdown:
- head:
- skull:
- usage: /skull <player>
- standby:
- usage: /standby <true, false>
-\ No newline at end of file
diff --git a/res/plugin.yml b/res/plugin.yml
@@ -0,0 +1,12 @@
+main: de.typable.minecrafthub.Main
+name: MinecraftHub
+version: 0.0.1
+author: typable
+api-version: 1.16
+commands:
+ shutdown:
+ head:
+ skull:
+ usage: /skull <player>
+ standby:
+ usage: /standby <true, false>
+\ No newline at end of file
diff --git a/src/de/typable/minecrafthub/Main.java b/src/de/typable/minecrafthub/Main.java
@@ -2,6 +2,7 @@ package de.typable.minecrafthub;
import java.io.File;
import java.io.IOException;
+import java.net.BindException;
import java.net.ServerSocket;
import java.net.Socket;
@@ -17,6 +18,7 @@ import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.scheduler.BukkitTask;
import de.typable.minecrafthub.constant.DefaultConstants;
import de.typable.minecrafthub.event.AutoWorkbenchListener;
@@ -37,6 +39,7 @@ public class Main extends JavaPlugin
private EventListener eventListener;
private Plugin plugin;
+ private BukkitTask task;
@Override
public void onEnable()
@@ -60,7 +63,7 @@ public class Main extends JavaPlugin
eventListener = new EventListener();
pluginManager.registerEvents(eventListener, this);
- Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable()
+ task = Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable()
{
@Override
public void run()
@@ -88,6 +91,10 @@ public class Main extends JavaPlugin
socket.close();
}
}
+ catch(BindException ex)
+ {
+ // ignore
+ }
catch(IOException ex)
{
ex.printStackTrace();
@@ -96,6 +103,17 @@ public class Main extends JavaPlugin
});
}
+ @Override
+ public void onDisable()
+ {
+ if(task != null && task.isCancelled())
+ {
+ task.cancel();
+ }
+
+ chairListener.onDisable();
+ }
+
@SuppressWarnings("deprecation")
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
diff --git a/src/de/typable/minecrafthub/event/ChairListener.java b/src/de/typable/minecrafthub/event/ChairListener.java
@@ -7,26 +7,37 @@ 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.AbstractArrow.PickupStatus;
-import org.bukkit.entity.Arrow;
+import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
+import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerInteractEvent;
-import org.bukkit.util.Vector;
import org.spigotmc.event.entity.EntityDismountEvent;
public class ChairListener implements Listener
{
- private static final Material[] CHAIR_TYPE = new Material[] { Material.OAK_STAIRS, Material.SPRUCE_STAIRS, Material.BIRCH_STAIRS, Material.JUNGLE_STAIRS, Material.ACACIA_STAIRS, Material.DARK_OAK_STAIRS, Material.ACACIA_STAIRS, Material.CRIMSON_STAIRS, Material.WARPED_STAIRS };
-
- private Map<Block, Arrow> blockMap = new HashMap<>();
+ private static final Material[] CHAIR_TYPE = new Material[]
+ {
+ Material.OAK_STAIRS,
+ Material.SPRUCE_STAIRS,
+ Material.BIRCH_STAIRS,
+ Material.JUNGLE_STAIRS,
+ Material.ACACIA_STAIRS,
+ Material.DARK_OAK_STAIRS,
+ Material.ACACIA_STAIRS,
+ Material.CRIMSON_STAIRS,
+ Material.WARPED_STAIRS
+ };
+
+ private Map<Block, ArmorStand> blockMap = new HashMap<>();
@SuppressWarnings("deprecation")
@EventHandler
@@ -60,18 +71,26 @@ public class ChairListener implements Listener
if(isCompatible(stairs))
{
- Location location = block.getLocation().add(0.5, 0, 0.5);
- Arrow arrow = (Arrow) block.getWorld()
- .spawnArrow(location, new Vector(), 0F, 0F);
- arrow.setGravity(false);
- arrow.setInvulnerable(true);
- arrow.setPickupStatus(PickupStatus.DISALLOWED);
- arrow.setPassenger((Entity) event.getPlayer());
- arrow.setTicksLived(0);
+ 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);
event.setCancelled(true);
- blockMap.put(block, arrow);
+ blockMap.put(block, armorStand);
}
}
}
@@ -86,11 +105,11 @@ public class ChairListener implements Listener
{
Entity entity = event.getDismounted();
- if(entity != null && entity instanceof Arrow)
+ if(entity != null && entity instanceof ArmorStand)
{
if(blockMap.containsValue(entity))
{
- for(Entry<Block, Arrow> entry : blockMap.entrySet())
+ for(Entry<Block, ArmorStand> entry : blockMap.entrySet())
{
if(entry.getValue() == entity)
{
@@ -113,8 +132,8 @@ public class ChairListener implements Listener
if(blockMap.containsKey(block))
{
- Arrow arrow = blockMap.get(block);
- arrow.eject();
+ ArmorStand armorStand = blockMap.get(block);
+ armorStand.eject();
blockMap.remove(block);
}
@@ -145,12 +164,39 @@ public class ChairListener implements Listener
return false;
}
- if(stairs.getShape() == Stairs.Shape.INNER_RIGHT || stairs
- .getShape() == Stairs.Shape.INNER_LEFT)
+ if(stairs.getShape() == Stairs.Shape.INNER_RIGHT || stairs.getShape() == Stairs.Shape.INNER_LEFT)
{
return false;
}
return true;
}
+
+ private 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 void onDisable()
+ {
+ for(ArmorStand armorStand : blockMap.values())
+ {
+ armorStand.eject();
+ armorStand.remove();
+ }
+ }
}