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?
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, -1, 0).getType().equals((Object)Material.AIR) && block.getRelative(0, -BlockListener.this.plugin.clearance, 0).getType() == Material.AIR && player.hasPermission("gravity.apply")) { final MaterialData MatData = new MaterialData(block.getType(), block.getData()); final Location BlockLoc = block.getLocation().clone().add(0.5, 0.0, 0.5); block.getWorld().spawnFallingBlock(BlockLoc, MatData).setDropItem(BlockListener.this.plugin.dropItem); block.setType(Material.AIR); block.getState().update(true); } } }, (long)this.plugin.delay); } } } @EventHandler(ignoreCancelled = true, priority = 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.5, 0.0, 0.5); block.getWorld().spawnFallingBlock(BlockLoc, MatData).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, -1, 0).getType() != Material.AIR || block.getRelative(0, -this.plugin.clearance, 0).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(materialName, this.plugin.blackListBlocks); } if (this.plugin.whitelist && this.containsCaseInsensitive(materialName, this.plugin.whiteListBlocks)) { return true; } } return false; } public boolean containsCaseInsensitive(final String s, final List<String> l) { for (final String string : l) { if (string.equalsIgnoreCase(s)) { return true; } } return false; }} just like that
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.