Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package IB;
- import java.util.ArrayList;
- import java.util.List;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.block.Block;
- import org.bukkit.block.BlockFace;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.player.PlayerBucketEmptyEvent;
- import org.bukkit.event.player.PlayerBucketFillEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.java.JavaPlugin;
- public class InfinityBucket extends JavaPlugin implements Listener{
- FileConfiguration conf = getConfig();
- public ItemStack shit;
- Player p;
- public void onEnable() {
- getServer().getPluginManager().registerEvents(this, this);
- }
- public void onDisable() {
- super.onDisable();
- }
- @EventHandler
- public void useIB(PlayerInteractEvent e){
- Player p=e.getPlayer();
- if(e.getItem().getItemMeta().getDisplayName().equalsIgnoreCase("IB")
- && (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)
- || e.getAction().equals(Action.RIGHT_CLICK_AIR) )){
- shit = e.getItem();
- }
- if(e.getItem().getItemMeta().getDisplayName().equalsIgnoreCase("IB") && p.isSneaking() && e.getAction().equals(Action.LEFT_CLICK_AIR)){
- switchMode(p);
- }
- }
- @EventHandler
- public void outBucket(PlayerBucketEmptyEvent e){
- p = e.getPlayer();
- if(p.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals("IB")){
- Block bl=magic(e.getBlockClicked(), e.getBlockFace());
- ItemMeta meta = shit.getItemMeta();
- e.setCancelled(true);
- List<String> lore = meta.getLore();
- if(Integer.parseInt(lore.get(3))!=0 || Integer.parseInt(lore.get(1))!=0){
- if(e.getBucket().equals(Material.LAVA_BUCKET) && Integer.parseInt(lore.get(3))!=0){
- lore.set(3,""+( Integer.parseInt(lore.get(3))-1));
- bl.setType(Material.LAVA);
- }else if(e.getBucket().equals(Material.WATER_BUCKET) && Integer.parseInt(lore.get(1))!=0 && !p.getWorld().getName().equals(conf.get("Nether"))){
- lore.set(1,""+( Integer.parseInt(lore.get(1))-1));
- bl.setType(Material.WATER);
- }
- meta.setLore(lore);
- shit.setItemMeta(meta);
- p.getInventory().setItemInMainHand(shit);
- }
- }
- }
- @EventHandler
- public void fillBucket(PlayerBucketFillEvent e){
- p = e.getPlayer();
- if(p.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals("IB")){
- Block bl=magic(e.getBlockClicked(), e.getBlockFace());
- ItemMeta meta = shit.getItemMeta();
- e.setCancelled(true);
- List<String> lore = meta.getLore();
- if(bl.getType().equals(Material.STATIONARY_LAVA) || bl.getType().equals(Material.LAVA)){
- lore.set(3,""+( Integer.parseInt(lore.get(3))+1));
- }else if(bl.getType().equals(Material.STATIONARY_WATER) || bl.getType().equals(Material.WATER)){
- lore.set(1,""+( Integer.parseInt(lore.get(1))+1));
- }
- bl.setType(Material.AIR);
- meta.setLore(lore);
- shit.setItemMeta(meta);
- p.getInventory().setItemInMainHand(shit);
- }
- }
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if(!(sender instanceof Player)) return false;
- p=(Player) sender;
- if(!p.isOp()) return false;
- switch(command.getName()){
- case "ib": p.getInventory().addItem(MyBucket.giveBucket()); break;
- case "ibNETHER": conf.set("Nether", p.getWorld().getName()); saveConfig(); break;
- }
- return true;
- }
- public Block magic(Block b, BlockFace bf){
- Location loc=b.getLocation();
- switch(bf){
- case UP: loc.setY(loc.getY()+1); break;
- case DOWN: loc.setY(loc.getY()-1); break;
- case NORTH: loc.setZ(loc.getZ()-1); break;
- case SOUTH: loc.setZ(loc.getZ()+1); break;
- case WEST: loc.setX(loc.getX()-1); break;
- case EAST: loc.setX(loc.getX()+1); break;
- default: break;
- }
- return loc.getBlock();
- }
- public void switchMode(Player p){
- ItemStack item = p.getInventory().getItemInMainHand();
- ItemMeta meta = item.getItemMeta();
- List<String> lore = meta.getLore();
- switch(lore.get(5)){
- case "insert":
- lore.set(5, "lava");
- item.setType(Material.LAVA_BUCKET);
- break;
- case "lava":
- lore.set(5, "water");
- item.setType(Material.WATER_BUCKET);
- break;
- case "water":
- lore.set(5, "insert");
- item.setType(Material.BUCKET);
- break;
- }
- meta.setLore(lore);
- item.setItemMeta(meta);
- p.getInventory().setItemInMainHand(item);
- }
- }
- class MyBucket extends ItemStack{
- ItemStack bucket = new ItemStack(Material.BUCKET);
- ItemMeta meta = bucket.getItemMeta();
- List<String> lore = new ArrayList<String>();
- public MyBucket(){
- lore.add("Water: ");
- lore.add(""+0);
- lore.add("Lava: ");
- lore.add(""+0);
- lore.add("Mode:");
- lore.add("insert");
- meta.setLore(lore);
- meta.setDisplayName("IB");
- bucket.setItemMeta(meta);
- }
- public static ItemStack giveBucket(){
- return new MyBucket().bucket;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement