Updating block data

This commit is contained in:
sekwah 2018-02-22 13:52:40 +00:00
parent e6a3632ef3
commit 69bafe7582
3 changed files with 45 additions and 3 deletions

View File

@ -3,11 +3,13 @@ package com.sekwah.advancedportals.coreconnector.container;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.core.data.PortalLocation;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.Wool;
import java.util.Arrays;
import java.util.UUID;
@ -52,7 +54,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
@ -72,7 +76,14 @@ public class PlayerContainer {
}
public void giveWool(String dyeColor, String itemName, String... itemDescription) {}
public void giveWool(String dyeColor, String itemName, String... itemDescription) {
ItemStack regionselector = new Wool(DyeColor.valueOf(dyeColor)).toItemStack(1);
ItemMeta selectorname = regionselector.getItemMeta();
selectorname.setDisplayName(itemName);
selectorname.setLore(Arrays.asList(itemDescription));
regionselector.setItemMeta(selectorname);
this.player.getInventory().addItem(regionselector);
}
public void giveItem(String material, String itemName, String... itemDescription) {
ItemStack regionselector = new ItemStack(Material.getMaterial(material));

View File

@ -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) {

View File

@ -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) {