Updating block data

This commit is contained in:
sekwah 2018-02-22 13:52:40 +00:00 committed by Sekwah
parent 85fd6a2b9b
commit ccdeb6919b
3 changed files with 36 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package com.sekwah.advancedportals.coreconnector.container; package com.sekwah.advancedportals.coreconnector.container;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -47,7 +48,9 @@ public class PlayerContainer {
return this.player.hasPermission(permission); return this.player.hasPermission(permission);
} }
public WorldContainer getWorld() {return null;} public WorldContainer getWorld() {
return new WorldContainer(this.player.getWorld());
}
/** /**
* @param blockPos * @param blockPos

View File

@ -1,17 +1,36 @@
package com.sekwah.advancedportals.coreconnector.container; package com.sekwah.advancedportals.coreconnector.container;
import com.sekwah.advancedportals.core.data.PortalLocation; 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 { public class WorldContainer {
private final World world;
public WorldContainer(World world) {
this.world = world;
}
public void setBlock(PortalLocation location, String material) { 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) { 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) { public String getBlock(PortalLocation location) {
return ""; return this.world.getBlockAt(location.posX, location.posY, location.posZ).getType().toString();
} }
public byte getBlockData(PortalLocation location) { public byte getBlockData(PortalLocation location) {

View File

@ -5,8 +5,10 @@ import com.sekwah.advancedportals.core.data.PortalLocation;
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
@ -25,6 +27,16 @@ public class Listeners implements Listener {
coreListeners.playerJoin(new PlayerContainer(event.getPlayer())); 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 @EventHandler
public void onItemInteract(PlayerInteractEvent event) { public void onItemInteract(PlayerInteractEvent event) {
if (!event.isCancelled() && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) && event.getItem() != null) { if (!event.isCancelled() && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) && event.getItem() != null) {