use of org.bukkit.material.Sign in project AreaShop by NLthijs48.
the class AddsignCommand method execute.
@Override
public void execute(CommandSender sender, String[] args) {
if (!sender.hasPermission("areashop.addsign")) {
plugin.message(sender, "addsign-noPermission");
return;
}
if (!(sender instanceof Player)) {
plugin.message(sender, "cmd-onlyByPlayer");
return;
}
Player player = (Player) sender;
// Get the sign
Block block = null;
BlockIterator blockIterator = new BlockIterator(player, 100);
while (blockIterator.hasNext() && block == null) {
Block next = blockIterator.next();
if (next.getType() != Material.AIR) {
block = next;
}
}
if (block == null || !(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)) {
plugin.message(sender, "addsign-noSign");
return;
}
GeneralRegion region;
if (args.length > 1) {
// Get region by argument
region = plugin.getFileManager().getRegion(args[1]);
if (region == null) {
plugin.message(sender, "cmd-notRegistered", args[1]);
return;
}
} else {
// Get region by sign position
List<GeneralRegion> regions = Utils.getRegionsInSelection(new CuboidSelection(block.getWorld(), block.getLocation(), block.getLocation()));
if (regions.isEmpty()) {
plugin.message(sender, "addsign-noRegions");
return;
} else if (regions.size() > 1) {
plugin.message(sender, "addsign-couldNotDetect", regions.get(0).getName(), regions.get(1).getName());
return;
}
region = regions.get(0);
}
Sign sign = (Sign) block.getState().getData();
String profile = null;
if (args.length > 2) {
profile = args[2];
Set<String> profiles = plugin.getConfig().getConfigurationSection("signProfiles").getKeys(false);
if (!profiles.contains(profile)) {
plugin.message(sender, "addsign-wrongProfile", Utils.createCommaSeparatedList(profiles), region);
return;
}
}
RegionSign regionSign = SignsFeature.getSignByLocation(block.getLocation());
if (regionSign != null) {
plugin.message(sender, "addsign-alreadyRegistered", regionSign.getRegion());
return;
}
region.getSignsFeature().addSign(block.getLocation(), block.getType(), sign.getFacing(), profile);
if (profile == null) {
plugin.message(sender, "addsign-success", region);
} else {
plugin.message(sender, "addsign-successProfile", profile, region);
}
region.update();
}
use of org.bukkit.material.Sign in project Glowstone by GlowstoneMC.
the class BlockHopper method pullItems.
private void pullItems(GlowBlock block, HopperEntity hopper) {
GlowBlock source = block.getRelative(BlockFace.UP);
MaterialData data = source.getState().getData();
if (!source.getType().isSolid() || (data instanceof Step && !((Step) data).isInverted()) || (data instanceof WoodenStep && !((WoodenStep) data).isInverted()) || (data instanceof Sign) || (data instanceof Rails)) {
GlowItem item = getFirstDroppedItem(source.getLocation());
if (item == null) {
return;
}
ItemStack stack = item.getItemStack();
HashMap<Integer, ItemStack> add = hopper.getInventory().addItem(stack);
if (add.size() > 0) {
item.setItemStack(add.get(0));
} else {
item.remove();
}
} else if (source.getBlockEntity() != null && source.getBlockEntity() instanceof ContainerEntity) {
ContainerEntity sourceContainer = (ContainerEntity) source.getBlockEntity();
if (sourceContainer.getInventory() == null || sourceContainer.getInventory().getContents().length == 0) {
return;
}
ItemStack item = getFirstItem(sourceContainer);
if (item == null) {
return;
}
ItemStack clone = item.clone();
clone.setAmount(1);
if (hopper.getInventory().addItem(clone).size() > 0) {
return;
}
if (item.getAmount() - 1 == 0) {
sourceContainer.getInventory().remove(item);
} else {
item.setAmount(item.getAmount() - 1);
}
}
}
use of org.bukkit.material.Sign in project Glowstone by GlowstoneMC.
the class BlockSign method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
state.setType(getMaterial());
if (!(state.getData() instanceof Sign)) {
warnMaterialData(Sign.class, state.getData());
return;
}
Sign sign = (Sign) state.getData();
sign.setFacingDirection(sign.isWallSign() ? face : player.getFacing().getOppositeFace());
}
use of org.bukkit.material.Sign in project AreaShop by NLthijs48.
the class SignLinkerManager method onPlayerInteract.
/**
* On player interactions.
* @param event The PlayerInteractEvent
*/
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
if (isInSignLinkMode(event.getPlayer())) {
event.setCancelled(true);
Player player = event.getPlayer();
SignLinker linker = signLinkers.get(event.getPlayer().getUniqueId());
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
// Get the region
BlockIterator blockIterator = new BlockIterator(player, 100);
while (blockIterator.hasNext()) {
Block next = blockIterator.next();
List<GeneralRegion> regions = Utils.getRegions(next.getLocation());
if (regions.size() == 1) {
linker.setRegion(regions.get(0));
return;
} else if (regions.size() > 1) {
Set<String> names = new HashSet<>();
for (GeneralRegion region : regions) {
names.add(region.getName());
}
plugin.message(player, "linksigns-multipleRegions", Utils.createCommaSeparatedList(names));
plugin.message(player, "linksigns-multipleRegionsAdvice");
return;
}
}
// No regions found within the maximum range
plugin.message(player, "linksigns-noRegions");
} else if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
Block block = null;
BlockIterator blockIterator = new BlockIterator(player, 100);
while (blockIterator.hasNext() && block == null) {
Block next = blockIterator.next();
if (next.getType() != Material.AIR) {
block = next;
}
}
if (block == null || !(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)) {
plugin.message(player, "linksigns-noSign");
return;
}
RegionSign regionSign = SignsFeature.getSignByLocation(block.getLocation());
if (regionSign != null) {
plugin.message(player, "linksigns-alreadyRegistered", regionSign.getRegion());
return;
}
Sign sign = (Sign) block.getState().getData();
linker.setSign(block.getLocation(), block.getType(), sign.getFacing());
}
}
}
Aggregations