diff --git a/src/main/java/org/getspout/testplugin/TestBlock.java b/src/main/java/org/getspout/testplugin/TestBlock.java new file mode 100644 index 0000000..03d7c1e --- /dev/null +++ b/src/main/java/org/getspout/testplugin/TestBlock.java @@ -0,0 +1,20 @@ +package org.getspout.testplugin; + +import org.bukkit.Material; +import org.bukkit.plugin.Plugin; +import org.getspout.spoutapi.SpoutManager; +import org.getspout.spoutapi.inventory.GenericCubeBlockDesign; +import org.getspout.spoutapi.inventory.ItemManager; +import org.getspout.spoutapi.material.block.GenericCubeCustomBlock; + +public class TestBlock extends GenericCubeCustomBlock { + public static int[] faces = new int[]{0,0,0,0,0,0}; + + public TestBlock(Plugin plugin) { + super(plugin, "CustomBlock", new GenericCubeBlockDesign(plugin.getDescription().getName(), "http://dl.dropbox.com/u/40267690/quartz.png", 16, faces), false, 0); + ItemManager im = SpoutManager.getItemManager(); + im.setCustomItemBlock(getCustomId(), getRawId(), (short) 0); + im.setItemTexture(Material.FLINT, (short) getCustomId(), plugin, "http://dl.dropbox.com/u/40267690/quartz.png"); + } + +} diff --git a/src/main/java/org/getspout/testplugin/TestBlockListener.java b/src/main/java/org/getspout/testplugin/TestBlockListener.java new file mode 100644 index 0000000..97bcab4 --- /dev/null +++ b/src/main/java/org/getspout/testplugin/TestBlockListener.java @@ -0,0 +1,28 @@ +package org.getspout.testplugin; + +import org.bukkit.Material; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockListener; +import org.bukkit.inventory.ItemStack; +import org.getspout.spoutapi.SpoutManager; +import org.getspout.spoutapi.block.SpoutBlock; +import org.getspout.spoutapi.inventory.ItemManager; + +public class TestBlockListener extends BlockListener { + + @Override + public void onBlockBreak(BlockBreakEvent event) { + super.onBlockBreak(event); + ItemManager im = SpoutManager.getItemManager(); + + SpoutBlock block = im.getSpoutBlock(event.getBlock()); + + if(block.getType().equals(Material.DIRT)) { + int id = block.getCustomBlockId(); + ItemStack is = im.getCustomItemStack(TestPlugin.testBlock, 1); + if(id == TestPlugin.testBlock.getCustomId()) { + block.getWorld().dropItem(block.getLocation(), is); + } + } + } +} diff --git a/src/main/java/org/getspout/testplugin/TestInputListener.java b/src/main/java/org/getspout/testplugin/TestInputListener.java index cc6732c..dc8d784 100644 --- a/src/main/java/org/getspout/testplugin/TestInputListener.java +++ b/src/main/java/org/getspout/testplugin/TestInputListener.java @@ -6,7 +6,6 @@ import org.getspout.spoutapi.event.input.InputListener; import org.getspout.spoutapi.event.input.KeyPressedEvent; import org.getspout.spoutapi.keyboard.Keyboard; -import org.getspout.spoutapi.player.SpoutPlayer; public class TestInputListener extends InputListener{ @@ -15,7 +14,7 @@ public void onKeyPressedEvent(KeyPressedEvent event) { if (event.getKey() == Keyboard.KEY_L) { SpoutManager.getAppearanceManager().setGlobalSkin(event.getPlayer(), "http://s3.amazonaws.com/MinecraftSkins/Top_Cat.png"); } else if (event.getKey() == Keyboard.KEY_M) { - ((SpoutPlayer) event.getPlayer()).sendNotification(ChatColor.RED + "Party time is now! " + ChatColor.YELLOW + "Oh yeah", "Testing", Material.CAKE); + SpoutManager.getPlayer(event.getPlayer()).sendNotification(ChatColor.RED + "Party time is now! " + ChatColor.YELLOW + "Oh yeah", "Testing", Material.CAKE); } } diff --git a/src/main/java/org/getspout/testplugin/TestPlugin.java b/src/main/java/org/getspout/testplugin/TestPlugin.java index 883306c..51600d3 100644 --- a/src/main/java/org/getspout/testplugin/TestPlugin.java +++ b/src/main/java/org/getspout/testplugin/TestPlugin.java @@ -6,10 +6,13 @@ import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Type; import org.bukkit.plugin.java.JavaPlugin; +import org.getspout.spoutapi.material.CustomBlock; public class TestPlugin extends JavaPlugin { + + public static CustomBlock testBlock; public void onDisable() { @@ -18,9 +21,12 @@ public void onDisable() { public void onEnable() { + testBlock = new TestBlock(this); + getServer().getPluginManager().registerEvent(Type.CUSTOM_EVENT, new TestSpoutListener(), Priority.Normal, this); getServer().getPluginManager().registerEvent(Type.CUSTOM_EVENT, new TestInputListener(), Priority.Normal, this); getServer().getPluginManager().registerEvent(Type.CUSTOM_EVENT, new TestScreenListener(), Priority.Normal, this); + getServer().getPluginManager().registerEvent(Type.BLOCK_BREAK, new TestBlockListener(), Priority.Normal, this); Bukkit.getLogger().log(Level.INFO, "[Spout Test Plugin] Enabled!"); }