Last active
August 29, 2015 14:05
-
-
Save LaxWasHere/6b2498b4f06598bb46ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.awesomepowered.snowman; | |
import java.util.ArrayList; | |
import org.bukkit.Bukkit; | |
import org.bukkit.ChatColor; | |
import org.bukkit.Location; | |
import org.bukkit.Material; | |
import org.bukkit.entity.Entity; | |
import org.bukkit.entity.EntityType; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.block.EntityBlockFormEvent; | |
import org.bukkit.event.player.AsyncPlayerChatEvent; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import org.bukkit.scheduler.BukkitRunnable; | |
public class Snowman extends JavaPlugin implements Listener { | |
public ArrayList<Player> coolppl = new ArrayList(); | |
public void onEnable() { | |
Bukkit.getPluginManager().registerEvents(this, this); | |
} | |
@EventHandler | |
public void onChat(AsyncPlayerChatEvent ev) { | |
Player p = ev.getPlayer(); | |
String m = ev.getMessage(); | |
if (!coolppl.contains(p)) { | |
p.sendMessage(ChatColor.GREEN + "Do you wanna build a snowman?"); | |
p.sendMessage(ChatColor.BLUE + "\"Yes\" or \"No\"?"); | |
ev.setCancelled(true); | |
if (m.equalsIgnoreCase("yes")) { | |
coolppl.add(p); | |
spawnSnowman(p.getLocation()); | |
p.sendMessage(ChatColor.RED + "Cool!"); | |
} | |
} | |
} | |
public void spawnSnowman(final Location loc) { | |
new BukkitRunnable() { | |
public void run() { | |
loc.getWorld().spawnEntity(loc, EntityType.SNOWMAN); | |
} | |
}.runTaskLater(this, 20); | |
} | |
@EventHandler | |
public void onBlockForm(EntityBlockFormEvent ev) { | |
Material mat = ev.getNewState().getType(); | |
if (mat == Material.SNOW) { | |
ev.setCancelled(true); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment