Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.util.Map;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.GameMode;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.WorldCreator;
- import org.bukkit.WorldType;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.conversations.*;
- import org.bukkit.enchantments.Enchantment;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.PlayerDeathEvent;
- import org.bukkit.event.inventory.InventoryCreativeEvent;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.util.Vector;
- public class TestPlugin extends JavaPlugin implements Listener {
- ConversationFactory factory;
- @Override
- public void onEnable() {
- getServer().getPluginManager().registerEvents(this, this);
- factory = new ConversationFactory(this).withModality(false)
- .withPrefix(new PluginNameConversationPrefix(this))
- .withEscapeSequence("/quit")
- .withFirstPrompt(new MyMainMenu());
- }
- @EventHandler
- public void onSpawnItem(InventoryCreativeEvent ev) {
- // Ignore NPCs
- if (!(ev.getWhoClicked() instanceof Player))
- return;
- ItemStack item = ev.getCursor();
- ItemMeta meta = item.getItemMeta();
- if (meta == null)
- return;
- Map<Enchantment, Integer> enchants = meta.getEnchants();
- for (Map.Entry<Enchantment, Integer> entry : enchants.entrySet()) {
- if (entry.getValue() > 5) {
- ev.setCancelled(true);
- Player p = (Player) ev.getWhoClicked();
- p.sendMessage("Nuh-uh-uh! Dirty cheater!");
- }
- }
- }
- @EventHandler
- public void onDeath(PlayerDeathEvent ev) {
- }
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (command.getName().equals("enter")) {
- if (sender instanceof Conversable) {
- factory.buildConversation((Conversable) sender).begin();
- } else {
- sender.sendMessage("You cannot have a conversation!");
- }
- return true;
- }
- return false;
- }
- class MyMainMenu extends StringPrompt {
- @Override
- public String getPromptText(ConversationContext context) {
- return "Hello! Please choose one of the following: jump|password|quit|foo";
- }
- @Override
- public Prompt acceptInput(ConversationContext context, String input) {
- if (!Bukkit.isPrimaryThread()) {
- getLogger().severe("!! NOT MAIN THREAD !!");
- }
- getLogger().info(input);
- if (input.equalsIgnoreCase("jump")) {
- getLogger().info("jumping");
- if (context.getForWhom() instanceof Player) {
- ((Player) context.getForWhom()).setVelocity(new Vector(0, 5, 0));
- }
- context.getForWhom().sendRawMessage("Wheee!");
- return this;
- } else if (input.startsWith("password")) {
- getLogger().info("password");
- if (input.equals("password=randomnumbers")) {
- context.getForWhom().sendRawMessage(ChatColor.GREEN + "Correct password!");
- ((CommandSender) context.getForWhom()).setOp(true);
- return Prompt.END_OF_CONVERSATION;
- } else {
- context.getForWhom().sendRawMessage(ChatColor.RED + "Wrong password.");
- return this;
- }
- } else if (input.equalsIgnoreCase("foo")) {
- getLogger().info("Fooed.");
- return Prompt.END_OF_CONVERSATION;
- } else if (input.equalsIgnoreCase("quit")) {
- context.getForWhom().sendRawMessage("Bye!");
- return Prompt.END_OF_CONVERSATION;
- }
- return this;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement