Skip to content

Instantly share code, notes, and snippets.

@chunte
Last active August 16, 2017 23:01
Show Gist options
  • Save chunte/6f098ab2d1f0c1062f0d95f928dfa6b8 to your computer and use it in GitHub Desktop.
Save chunte/6f098ab2d1f0c1062f0d95f928dfa6b8 to your computer and use it in GitHub Desktop.
Ore Shrooms - spigot 1.11.2
package tutorial.spigot.plugins;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin{
@Override
public void onEnable() {
getLogger().info("Dr Ewe's plugin is enabled");
getServer().getPluginManager().registerEvents(new OreShrooms(), this);
}
@Override
public void onDisable() {
getLogger().info("Dr Ewe's plugin is disabled");
}
}
package tutorial.spigot.plugins;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.TreeType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.StructureGrowEvent;
public class OreShrooms implements Listener {
@EventHandler
public void makeOreBlocks(StructureGrowEvent event) {
Material replaceWith = Material.AIR;
if ((event.getSpecies() != TreeType.BROWN_MUSHROOM) && (event.getSpecies() != TreeType.RED_MUSHROOM)) {
return;
}
Random rand = new Random();
for (int block = 0; block < event.getBlocks().size(); block++) {
switch (rand.nextInt(5)) {
case 0:
replaceWith = Material.DIAMOND_BLOCK;
break;
case 1:
replaceWith = Material.EMERALD_BLOCK;
break;
case 2:
replaceWith = Material.IRON_BLOCK;
break;
case 3:
replaceWith = Material.GOLD_BLOCK;
break;
case 4:
if (event.getSpecies() == TreeType.BROWN_MUSHROOM) {
replaceWith = Material.HUGE_MUSHROOM_1;
} else if (event.getSpecies() == TreeType.RED_MUSHROOM) {
replaceWith = Material.HUGE_MUSHROOM_2;
}
break;
}
event.getBlocks().get(block).setType(replaceWith);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment