Download Horizon :: Staff Members :: TheTechGame.com :: XboxMB YouTube


Old 02-06-2012   #1 (permalink)
SPEED's Avatar
Join Date: Sep 2010
Location: Chandler, Arizona
Posts: 628
Thanks: 844
Default FixPath - Incomplete Minecraft Plugin Base/Example

So if any of you have been on my server, you'll know that I use plots for a sort of creative mode anti-griefing, management, and neatness system.

Unfortunately, due to a bug in worldguard, players are able to place cobblestone slabs on the pathways, so I had to disable slabs in general (do to another bug/limitation in essentials).

So I had this idea to work on a plugin to block the use of cobblestone slabs while in creative mode. This would allow users to use most slabs in creative mode, and all slabs in survival mode, instead of blocking all slabs in all modes like my current solution does.

Unforunately, due to the way Minecraft processes slabs (specifically the way slabs are joined when two of the same slabs are placed on top of eachother), my solution does not work., and my plugin is therefore useless for what I need it to do.

The other solution I was trying to work with was using the onPlayerInteract method instead of onBlockPlace, that way the function would work as a preprocessor, instead of a postprocessor.

Unfortunately, I don't think onPlayerInteract supports getData(), so there's no way to make sure only the block 44:3 (cobblestone slab) is disabled, only 44 (all slabs) can be disabled (which defeats the purpose of me making this plugin.

If you have any knowledge of bukkit and have an idea to get this working, let me know. I'd appreciate any help I can get

Otherwise, feel free to use this source as a base for a plugin. It has no command support since the plugin I was making doesn't need commands, but it does have permission support. I released the source for one of my other plugins a while ago, and that does support commands, so look it up if you need help

tl;dr
Need help, also releasing source as a base.

FixPath.java
Code:
package com.speed.FixPath;

import java.util.logging.Logger;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

public class FixPath extends JavaPlugin {
	
	
	private static final Logger log = Logger.getLogger("Minecraft");
	private final Listener blockListener = new Listener(this);
	
	@Override
	public void onEnable()
	{
		log.info("[FixPath] - Enabled");
		PluginManager pm = getServer().getPluginManager();
		pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Event.Priority.Normal, this);
	}
	
	@Override
	public void onDisable()
	{
		log.info("[FixPath] - Disabled");
	}
}
Listener.java
Code:
package com.speed.FixPath;

import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockListener;

public class Listener extends BlockListener{

    public final FixPath plugin;

    public Listener(FixPath plugin) {
        this.plugin = plugin;
    }

    public void onBlockPlace(BlockPlaceEvent e){
		Player p = e.getPlayer();
		Block b = e.getBlock();
		if(b.getType().equals(Material.STEP) && b.getData() == 3){
			if (p.getGameMode().equals(GameMode.CREATIVE)) {
				if (!p.hasPermission("FixPath.Bypass") && !p.isOp()) {
					p.sendMessage(ChatColor.RED + "Sorry, this block is not allowed.");
					e.setCancelled(true);
				}
			}
		}
	}
}

Last edited by SPEED; 02-06-2012 at 02:36 PM.
SPEED is offline
Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 09:35 AM.


 

Powered by vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
COPYRIGHT (c) 2010 - 2012 - XboxMB - DESIGN BY:
EDENWEBS.COM