From ccdeb6919b44c5eb12907039ccb02a9176d87fd4 Mon Sep 17 00:00:00 2001 From: sekwah Date: Thu, 22 Feb 2018 13:52:40 +0000 Subject: [PATCH] Updating block data --- .../container/PlayerContainer.java | 5 ++++- .../container/WorldContainer.java | 21 ++++++++++++++++++- .../advancedportals/spigot/Listeners.java | 12 +++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/com/sekwah/advancedportals/coreconnector/container/PlayerContainer.java b/src/com/sekwah/advancedportals/coreconnector/container/PlayerContainer.java index 55f4e67b..dbfdb237 100644 --- a/src/com/sekwah/advancedportals/coreconnector/container/PlayerContainer.java +++ b/src/com/sekwah/advancedportals/coreconnector/container/PlayerContainer.java @@ -1,6 +1,7 @@ package com.sekwah.advancedportals.coreconnector.container; import org.bukkit.Bukkit; +import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -47,7 +48,9 @@ public class PlayerContainer { return this.player.hasPermission(permission); } - public WorldContainer getWorld() {return null;} + public WorldContainer getWorld() { + return new WorldContainer(this.player.getWorld()); + } /** * @param blockPos diff --git a/src/com/sekwah/advancedportals/coreconnector/container/WorldContainer.java b/src/com/sekwah/advancedportals/coreconnector/container/WorldContainer.java index ccc8748f..02aaee42 100644 --- a/src/com/sekwah/advancedportals/coreconnector/container/WorldContainer.java +++ b/src/com/sekwah/advancedportals/coreconnector/container/WorldContainer.java @@ -1,17 +1,36 @@ package com.sekwah.advancedportals.coreconnector.container; import com.sekwah.advancedportals.core.data.PortalLocation; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.BlockFace; +import org.bukkit.material.Directional; +import org.bukkit.material.MaterialData; public class WorldContainer { + private final World world; + + public WorldContainer(World world) { + this.world = world; + } + public void setBlock(PortalLocation location, String material) { + this.world.getBlockAt(location.posX, location.posY, location.posZ).setType(Material.getMaterial(material)); } public void setBlockData(PortalLocation location, byte data) { + MaterialData matData = world.getBlockAt(location.posX, location.posY, location.posZ).getState().getData(); + if(matData instanceof Directional) { + System.out.println("IS DIRECTIONAL"); + Directional dir = (Directional) world.getBlockAt(location.posX, location.posY, location.posZ).getState().getData(); + dir.setFacingDirection(BlockFace.NORTH); + } + } public String getBlock(PortalLocation location) { - return ""; + return this.world.getBlockAt(location.posX, location.posY, location.posZ).getType().toString(); } public byte getBlockData(PortalLocation location) { diff --git a/src/com/sekwah/advancedportals/spigot/Listeners.java b/src/com/sekwah/advancedportals/spigot/Listeners.java index 8d1bae6d..79214b7a 100644 --- a/src/com/sekwah/advancedportals/spigot/Listeners.java +++ b/src/com/sekwah/advancedportals/spigot/Listeners.java @@ -5,8 +5,10 @@ import com.sekwah.advancedportals.core.data.PortalLocation; import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; import org.bukkit.Location; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; @@ -25,6 +27,16 @@ public class Listeners implements Listener { coreListeners.playerJoin(new PlayerContainer(event.getPlayer())); } + @EventHandler(priority = EventPriority.HIGH) + public void onBlockPlace(BlockPlaceEvent event) { + if (!event.isCancelled()) { + Location blockloc = event.getBlock().getLocation(); + this.coreListeners.blockPlace(new PlayerContainer(event.getPlayer()), + new PortalLocation(blockloc.getWorld().getName(), blockloc.getBlockX(), blockloc.getBlockY(), blockloc.getBlockZ()), event.getBlockPlaced().getType().toString(), + event.getItemInHand().getType().toString(), event.getItemInHand().getItemMeta().getDisplayName()); + } + } + @EventHandler public void onItemInteract(PlayerInteractEvent event) { if (!event.isCancelled() && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) && event.getItem() != null) {