Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.bukkit.gemo.FalseBookIC.IC;
- import java.util.ArrayList;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.World;
- import org.bukkit.block.Sign;
- import org.bukkit.entity.Player;
- import org.bukkit.event.block.BlockRedstoneEvent;
- import org.bukkit.event.block.SignChangeEvent;
- import com.bukkit.gemo.FalseBookIC.FalseBookICCore;
- public class MC1208 extends MCBlock {
- // CREATED BY SHOOT
- public MC1208(FalseBookICCore plugin, SignChangeEvent event, boolean creation) {
- super(plugin, event, creation);
- Name = "SET MBLOCK";
- MCName = "[MC1208]";
- if (!event.getBlock().getType().equals(Material.WALL_SIGN)) {
- cancelCreation(event, ChatColor.RED + "There was an internal error while creating this IC.");
- return;
- }
- if (creation) {
- Player player = event.getPlayer();
- if (plugin.playerCanUseCommand(player, "falsebook.ic.worldedit") || plugin.playerCanUseCommand(player, "falsebook.ic." + MCName.toLowerCase().substring(1, MCName.length() - 1)) || plugin.playerCanUseCommand(player, "falsebook.anyic") || plugin.playerCanUseCommand(player, "*")) {
- event.setLine(0, Name);
- event.setLine(1, MCName);
- if (event.getLine(2) == null) {
- cancelCreation(event, "Item not found");
- return;
- }
- String[] lineSplit = event.getLine(2).split("-");
- String[] split = lineSplit[0].split(":");
- try {
- if (!isValidBlock(Integer.valueOf(split[0]))) {
- cancelCreation(event, "Block not found");
- return;
- }
- } catch (Exception e) {
- if (!isValidBlock(getItemIDFromName(split[0]))) {
- cancelCreation(event, "Block not found.");
- return;
- }
- }
- if (lineSplit.length > 1) {
- split = lineSplit[1].split(":");
- try {
- if (!isValidBlock(Integer.valueOf(split[0]))) {
- cancelCreation(event, "Block not found");
- return;
- }
- } catch (Exception e) {
- if (!isValidBlock(split[0])) {
- cancelCreation(event, "Block not found.");
- return;
- }
- }
- }
- if (event.getLine(3).length() > 0) {
- try {
- System.out.println(event.getLine(3));
- String[] splitLineT = event.getLine(3).split(":");
- Integer.valueOf(splitLineT[0]);
- if (splitLineT.length == 2) {
- if (splitLineT[1].equalsIgnoreCase("X")) {
- } else {
- Integer.valueOf(splitLineT[1]);
- }
- }
- } catch (Exception e) {
- cancelCreation(event, "Line 4 must be a number.");
- e.printStackTrace();
- return;
- }
- } else {
- cancelCreation(event, "Line 4 must be a number.");
- return;
- }
- player.sendMessage(ChatColor.GREEN + Name + " created.");
- } else {
- cancelCreation(event, "You are not allowed to build a " + Name + ".");
- return;
- }
- }
- }
- public static void Execute(Sign signBlock, int State, BlockRedstoneEvent event) {
- World w = signBlock.getWorld();
- String[] lineSplit = signBlock.getLine(2).split("-");
- int ItemID = -1;
- int count = 1;
- int pos = 0;
- int secret = 1;
- if (signBlock.getLine(3) != null) {
- String[] splitLineT = signBlock.getLine(3).split(":");
- count = Integer.valueOf(splitLineT[0]);
- if (splitLineT.length == 2) {
- if (splitLineT[1].equalsIgnoreCase("X")) {
- secret = -1;
- pos = 0;
- } else {
- pos = Integer.parseInt(splitLineT[1]);
- if(pos < 0){
- secret = -1;
- }
- }
- }
- }
- Byte ItemData = 0;
- String[] split = lineSplit[0].split(":");
- if (split.length > 1) {
- ItemID = getItemIDFromName(split[0]);
- if (ItemID < 0) {
- try {
- ItemID = Integer.valueOf(split[0]);
- } catch (Exception e) {
- return;
- }
- }
- try {
- ItemData = Byte.valueOf(split[1]);
- } catch (Exception e) {
- return;
- }
- } else {
- // KEINE SUBID ANGEGEBEN
- ItemID = getItemIDFromName(lineSplit[0]);
- if (ItemID < 0) {
- try {
- ItemID = Integer.valueOf(lineSplit[0]);
- } catch (Exception e) {
- return;
- }
- }
- }
- int ItemID2 = 0;
- Byte ItemData2 = 0;
- if (lineSplit.length > 1) {
- split = lineSplit[1].split(":");
- if (split.length > 1) {
- ItemID2 = getItemIDFromName(split[0]);
- if (ItemID2 < 0) {
- try {
- ItemID2 = Integer.valueOf(split[0]);
- } catch (Exception e) {
- return;
- }
- }
- try {
- ItemData2 = Byte.valueOf(split[1]);
- } catch (Exception e) {
- return;
- }
- } else {
- // KEINE SUBID ANGEGEBEN
- ItemID2 = getItemIDFromName(lineSplit[1]);
- if (ItemID2 < 0) {
- try {
- ItemID2 = Integer.valueOf(lineSplit[1]);
- } catch (Exception e) {
- return;
- }
- }
- }
- }
- // keine ItemID gefunden?
- if (ItemID < 0 || ItemID2 < 0) {
- return;
- }
- if ((ItemID < 0 && !isValidBlock(ItemID)) || (!isValidBlock(ItemID2) && ItemID2 > 0)) {
- return;
- }
- // DROP VORBEREITEN
- Location loc = getSignOnBlockPos(signBlock);
- Location[] newBlockLocs = new Location[count];
- //Location newBlockLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + dist, loc.getZ());
- for (int i = 0; i < count; i++) {
- newBlockLocs[i] = new Location(loc.getWorld(), loc.getX(), loc.getY() + ((i*secret) + secret) + pos, loc.getZ());
- }
- // DROP ITEM
- ArrayList<Location> positions = getBlockPositions(signBlock);
- if (!isActivator(signBlock, positions.get(0))) {
- return;
- }
- if (!(LocationEquals(event.getBlock().getLocation(), positions.get(0)))) {
- return;
- }
- if (State > 0 && isLow(signBlock, positions.get(0))) {
- for (Location locc : newBlockLocs) {
- w.getBlockAt(locc).setTypeId(ItemID);
- w.getBlockAt(locc).setData(ItemData);
- switchLever(signBlock, true);
- }
- } else if (State == 0 && isPowered(signBlock, positions.get(0))) {
- for (Location locc : newBlockLocs) {
- w.getBlockAt(locc).setTypeId(ItemID2);
- w.getBlockAt(locc).setData(ItemData2);
- switchLever(signBlock, false);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment