Skip to content

Commit

Permalink
Test custom blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Olloth committed Oct 3, 2011
1 parent 1f5c0ae commit fb06417
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/main/java/org/getspout/testplugin/TestBlock.java
Original file line number Diff line number Diff line change
@@ -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");
}

}
28 changes: 28 additions & 0 deletions src/main/java/org/getspout/testplugin/TestBlockListener.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
3 changes: 1 addition & 2 deletions src/main/java/org/getspout/testplugin/TestInputListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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{

Expand All @@ -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);
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/getspout/testplugin/TestPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -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!");
}
Expand Down

0 comments on commit fb06417

Please sign in to comment.