Files

Discussion in 'Plugin Development' started by JavaNoob, Sep 7, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    JavaNoob

    Hi! If I wanted to create a plugin that made all blocks have gravity, or all blocks slippery, is there a minecraft file to access within a world to get me the block friction or something?
     
  2. Offline

    Kars

  3. Offline

    JavaNoob

  4. Offline

    Kars

    PHP:
    public class BlockListener implements Listener
    {
        private 
    Gravity plugin;
       
        public 
    BlockListener(final Gravity plugin) {
            
    this.plugin plugin;
            
    plugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)plugin);
        }
       
        @
    EventHandler(priority EventPriority.MONITOR)
        public 
    void onBlockPlace(final BlockPlaceEvent event) {
            if (!
    event.isCancelled()) {
                if (!
    this.plugin.onlyOnPlace) {
                    
    this.drop(event.getBlock());
                    return;
                }
                final 
    Block block event.getBlock();
                if (
    this.shouldEffectBlock(block)) {
                    final 
    Player player event.getPlayer();
                    
    Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, (Runnable)new Runnable() {
                        @
    Override
                        
    public void run() {
                            if (
    block.getRelative(0, -10).getType().equals((Object)Material.AIR) && block.getRelative(0, -BlockListener.this.plugin.clearance0).getType() == Material.AIR && player.hasPermission("gravity.apply")) {
                                final 
    MaterialData MatData = new MaterialData(block.getType(), block.getData());
                                final 
    Location BlockLoc block.getLocation().clone().add(0.50.00.5);
                                
    block.getWorld().spawnFallingBlock(BlockLocMatData).setDropItem(BlockListener.this.plugin.dropItem);
                                
    block.setType(Material.AIR);
                                
    block.getState().update(true);
                            }
                        }
                    }, (
    long)this.plugin.delay);
                }
            }
        }
       
        @
    EventHandler(ignoreCancelled truepriority EventPriority.HIGHEST)
        public 
    void onBlockPhysics(final BlockPhysicsEvent event) {
            if (
    this.plugin.onlyOnPlace) {
                return;
            }
            
    this.drop(event.getBlock());
        }
       
        public 
    void drop(final Block block) {
            if (
    this.shouldEffectBlock(block)) {
                final 
    MaterialData MatData = new MaterialData(block.getType(), block.getData());
                final 
    Location BlockLoc block.getLocation().clone().add(0.50.00.5);
                
    block.getWorld().spawnFallingBlock(BlockLocMatData).setDropItem(this.plugin.dropItem);
                
    block.setType(Material.AIR);
                
    block.getState().update(true);
            }
        }
       
        public 
    boolean shouldEffectBlock(final Block block) {
            if (
    block.getY() > this.plugin.hightLimit) {
                if (!
    this.containsCaseInsensitive(block.getWorld().getName(), this.plugin.enabledWorlds)) {
                    return 
    false;
                }
                if (
    block.getRelative(0, -10).getType() != Material.AIR || block.getRelative(0, -this.plugin.clearance0).getType() != Material.AIR) {
                    return 
    false;
                }
                if (!
    block.getType().isBlock() || block.getType().hasGravity() || block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) {
                    return 
    false;
                }
                if (
    block.getState() instanceof InventoryHolder) {
                    return 
    false;
                }
                final 
    String materialName block.getType().name();
                if (
    this.plugin.blacklist) {
                    return !
    this.containsCaseInsensitive(materialNamethis.plugin.blackListBlocks);
                }
                if (
    this.plugin.whitelist && this.containsCaseInsensitive(materialNamethis.plugin.whiteListBlocks)) {
                    return 
    true;
                }
            }
            return 
    false;
        }
       
        public 
    boolean containsCaseInsensitive(final String s, final List<Stringl) {
            for (final 
    String string l) {
                if (
    string.equalsIgnoreCase(s)) {
                    return 
    true;
                }
            }
            return 
    false;
        }
    }
    just like that
     
  5. Offline

    JavaNoob

    Thank you so much! I really learn a lot from just observing other peoples work. This will help me learn a lot!

    Where did you get the Gravity part? That is one of the things i am still trying to figure out. Is that in another class?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 9, 2020
  6. Offline

    CraftCreeper6

Thread Status:
Not open for further replies.

Share This Page