SHARE
TWEET

this shit don't work

a guest Aug 25th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package io.github.fhadiel.NoPortalDestroy;
  2.  
  3. import java.util.List;
  4. import java.util.ArrayList;
  5.  
  6. import org.bukkit.Material;
  7. import org.bukkit.block.Block;
  8. import org.bukkit.configuration.file.FileConfiguration;
  9. import org.bukkit.material.Dispenser;
  10. import org.bukkit.event.EventHandler;
  11. import org.bukkit.event.Listener;
  12. import org.bukkit.event.block.BlockDispenseEvent;
  13. import org.bukkit.event.player.PlayerBucketEmptyEvent;
  14. import org.bukkit.inventory.ItemStack;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16.  
  17. public class Main extends JavaPlugin implements Listener {
  18.     ArrayList<Material> preventBlockBreak = new ArrayList<>();
  19.     ArrayList<Material> preventItemDispense = new ArrayList<>();
  20.     FileConfiguration config = getConfig();
  21.     @Override
  22.     public void onEnable() {
  23.         getServer().getPluginManager().registerEvents(this, this);
  24.         saveDefaultConfig();
  25.         updateConfig(getConfig().getStringList("preventbreak"), getConfig().getStringList("preventdispensing"));
  26.         log("Preventing these blocks from breaking: " + preventBlockBreak.toString());
  27.     }
  28.  
  29.     @EventHandler
  30.     public void onPlaceWater(PlayerBucketEmptyEvent e) {
  31.         Block clickedBlock = e.getBlockClicked();
  32.         Block replacedBlock = clickedBlock.getRelative(e.getBlockFace());
  33.         if (isPreventBreakBlock(replacedBlock)) {
  34.             e.setCancelled(true);
  35.             log("Prevented " + e.getPlayer().getName() + " from breaking " + replacedBlock.getType().name() + " using a bucket at " + replacedBlock.getLocation().getBlockX() + " " + replacedBlock.getLocation().getBlockY() + " " + replacedBlock.getLocation().getBlockZ());
  36.         }
  37.     }
  38.  
  39.     @EventHandler
  40.     public void onWaterDispenser(BlockDispenseEvent e) {
  41.         if (e.getBlock().getType().equals(Material.DISPENSER)) {
  42.             Dispenser dispenser = (Dispenser) e.getBlock().getState().getData();
  43.             Block inFrontOfDispenser = e.getBlock().getRelative(dispenser.getFacing());
  44.             ItemStack itemInDispenser = e.getItem();
  45.             if (isPreventBreakBlock(inFrontOfDispenser) && isPreventDispenseItem(itemInDispenser)) {
  46.                 e.setCancelled(true);
  47.                 log("Prevented dispenser from breaking " + inFrontOfDispenser.getType().name() + "using " + itemInDispenser.getType().name() + " at " + inFrontOfDispenser.getLocation().getBlockX() + " " + inFrontOfDispenser.getLocation().getBlockY() + " " + inFrontOfDispenser.getLocation().getBlockZ());
  48.             }
  49.         }
  50.     }
  51.  
  52.     public void updateConfig(List<String> preventBreakBlocks, List<String> preventDispenseItems) {
  53.         ArrayList<Material> preventBreakBlockArray = new ArrayList<>();
  54.         ArrayList<Material> preventDispenseItemsArray = new ArrayList<>();
  55.         for (String block : preventBreakBlocks) {
  56.             Material b = Material.getMaterial(block);
  57.             if (!(b instanceof Material)) {
  58.                 log("There's no block called " + b.name());
  59.             } else {
  60.                 preventBreakBlockArray.add(b);
  61.             }
  62.         }
  63.        
  64.         for (String item : preventDispenseItems) {
  65.             Material b = Material.getMaterial(item);
  66.             if (!(b instanceof Material)) {
  67.                 log("There's no item called " + b.name());
  68.             } else {
  69.                 preventDispenseItemsArray.add(b);
  70.             }
  71.         }
  72.        
  73.         preventBlockBreak = preventBreakBlockArray;
  74.         preventItemDispense = preventDispenseItemsArray;
  75.     }
  76.  
  77.     public boolean isPreventBreakBlock(Block replacedBlock) {
  78.         if (preventBlockBreak.contains(replacedBlock.getType())) {
  79.             return true;
  80.         }
  81.         return false;
  82.     }
  83.    
  84.     public boolean isPreventDispenseItem(ItemStack item) {
  85.         if (preventBlockBreak.contains(item.getType())) {
  86.             return true;
  87.         }
  88.         return false;
  89.     }
  90.    
  91.     public void log(String msg) {
  92.         if(config.getBoolean("logging")) getLogger().info(msg);
  93.     }
  94. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top