Java Code Examples for org.bukkit.event.player.PlayerEditBookEvent

The following are top voted examples for showing how to use org.bukkit.event.player.PlayerEditBookEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Kineticraft   File: ItemInputBook.java   View source code 5 votes vote down vote up
@EventHandler
public void onBookEdit(PlayerEditBookEvent event) {
    ItemWrapper item = ItemManager.constructItem(event.getPlayer().getInventory().getItem(event.getSlot()));
    if (item == null || !(item instanceof ItemInputBook))
        return;

    ItemInputBook book = (ItemInputBook) item;
    event.setCancelled(true);
    event.getPlayer().getInventory().setItem(event.getSlot(), null); // Remove book from inventory.
    book.setMeta(event.getNewBookMeta()); // Update meta.
    book.onUpdate(event.getPlayer());
}
 
Example 2
Project: BeeLogin   File: EventCanceler.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerEditBook(PlayerEditBookEvent evt) {
	if (!usingBeeLoginMod)
		return;
	Player player = evt.getPlayer();
	if (!loginStatus.get(player.getName().toLowerCase())) {
		evt.setCancelled(true);
	}
}
 
Example 3
Project: SimpleFreeze   File: PlayerEditBookListener.java   View source code 5 votes vote down vote up
@EventHandler
public void onBookEdit(PlayerEditBookEvent e) {
    if (this.playerManager.isFrozen(e.getPlayer()) && !this.plugin.getConfig().getBoolean("book-editing")) {
        e.setCancelled(true);
        for (String msg : this.plugin.getConfig().getStringList("book-edit-message")) {
            e.getPlayer().sendMessage(this.plugin.placeholders(msg));
        }
    }
}
 
Example 4
Project: Magix-Plugin   File: CommandHandler.java   View source code 5 votes vote down vote up
@EventHandler
public void onEditBook(PlayerEditBookEvent event) {
    if (event.isSigning()) {
        ItemStack book = new ItemStack(Material.WRITTEN_BOOK);
        book.setItemMeta(event.getNewBookMeta());
        check(event.getPlayer(), book);
    }
}
 
Example 5
Project: BukkitLTI   File: BukkitLTIListener.java   View source code 5 votes vote down vote up
@EventHandler
public void handle(PlayerEditBookEvent event) {
  Player player = event.getPlayer();
  User user = User.byUuid(player.getUniqueId());
  if (user == null) {return;}
  String contents = Joiner.on("\n\n").join(event.getNewBookMeta().getPages());
  if (user.submitResult(contents)) {
    plugin.sendPlayerMessage(player, "Submitted book contents.");
  }
}
 
Example 6
Project: Bytecraft   File: BookShelfListener.java   View source code 5 votes vote down vote up
@EventHandler
public void onSignBook(PlayerEditBookEvent event)
{
    BytecraftPlayer player = plugin.getPlayer(event.getPlayer());
    if(event.isSigning()){
        BookMeta meta = event.getNewBookMeta();
        meta.setAuthor(player.getNameColor() + player.getName());
        event.setNewBookMeta(meta);
    }
}
 
Example 7
Project: Wayward   File: PlayerEditBookListener.java   View source code 5 votes vote down vote up
@EventHandler
public void onPlayerEditBook(PlayerEditBookEvent event) {
    if (event.isSigning()) {
        BookMeta meta = event.getNewBookMeta();
        meta.setAuthor(plugin.getActiveCharacter(event.getPlayer()).getName());
        event.setNewBookMeta(meta);
    }
}
 
Example 8
Project: xEssentials-deprecated-bukkit   File: AntiAddvertiseEvent.java   View source code 5 votes vote down vote up
@EventHandler
public void createBook(PlayerEditBookEvent e) {
	if(!e.isSigning()) {
		if(!e.getPreviousBookMeta().hasAuthor()) {
			BookMeta meta = e.getNewBookMeta();
			meta.setAuthor(e.getPlayer().getName());
			e.setNewBookMeta(meta);
			e.setSigning(true);
			sendMessage(e.getPlayer(), ChatColor.GREEN + "book automatic signed, by anti addvertise system!");
		}
	}
}
 
Example 9
Project: AntiAd   File: ADListener.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onEditBook(PlayerEditBookEvent bookEdit) {
    Check check = new Check(plugin, bookEdit.getPlayer());
    for (String page : bookEdit.getNewBookMeta().getPages()) {
        if (check.check(page, 4, true)) {
            bookEdit.setCancelled(true);
            break;
        }
    }
}
 
Example 10
Project: EscapeLag   File: CheatBookBlocker.java   View source code 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBookEdit(PlayerEditBookEvent evt) {
    if (!noCheatBook) return;
    
    BookMeta prev = evt.getPreviousBookMeta();
    BookMeta meta = evt.getNewBookMeta();
    if (prev.equals(meta)) return;
    
    // Illegally modify lore
    if (prev.hasLore()) {
        if (!meta.hasLore() || !prev.getLore().equals(meta.getLore())) {
            meta.setLore(prev.getLore());
        }
    } else if (meta.hasLore()) {
        meta.setLore(null);
    }
    
    // Illegally modify enchants
    if (prev.hasEnchants()) {
        if (!meta.hasEnchants()) {
            addEnchantFrom(prev, meta);
        } else if (!prev.getLore().equals(meta.getLore())) {
            clearEnchant(meta);
            addEnchantFrom(prev, meta);
        }
    } else if (meta.hasEnchants()) {
        clearEnchant(meta);
    }
    
    // They cannot change title by edit it!
    String title = prev.getTitle();
    if (!title.equals(meta.getTitle())) {
        meta.setTitle(title);
    }
    
    // Book and quill doesn't has a generation!
    if (meta.getGeneration() != null) meta.setGeneration(null);
    
    // Book and quill doesn't has an author!
    if (meta.getAuthor() != null) meta.setAuthor(null);
    
    evt.setNewBookMeta(meta);
    
    AzureAPI.log(evt.getPlayer(), messageCheatBook);
}
 
Example 11
Project: QuestManager   File: QuestPlayer.java   View source code 4 votes vote down vote up
@EventHandler
public void onPlayerRuinJournal(PlayerEditBookEvent e) {
	if (!getPlayer().isOnline()) {
		return;
	}
	
	if (!e.getPlayer().equals(getPlayer().getPlayer())) {
		return;
	}
	
	BookMeta oldMeta = e.getPreviousBookMeta(),
			newMeta = e.getNewBookMeta();
	
	if (oldMeta.hasTitle() && oldMeta.getTitle().equals("Journal")
		&& oldMeta.hasAuthor() && oldMeta.getAuthor().equals(e.getPlayer().getName())
		&& oldMeta.getEnchantLevel(Enchantment.LUCK) == 5) {
		//grab the player notes
		int pageNum;
		String page;
		for (pageNum = 1; pageNum <= newMeta.getPageCount(); pageNum++) {
			page = newMeta.getPage(pageNum);
			if (page.contains("  Player Notes")) {
				break;
			}
		}
		pageNum++;
		this.journalNotes.clear();
		if (pageNum > newMeta.getPageCount()) {
			//we went beyond what we have
		} else {
			//save their notes
			for (; pageNum <= newMeta.getPageCount(); pageNum++) {
				journalNotes.add(newMeta.getPage(pageNum));
			}
		}
		
		e.setCancelled(true);
		QuestJournal.updateQuestJournal(this, true);
		
	}
}
 
Example 12
Project: NPlugins   File: LoggedOutUserHandler.java   View source code 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerEditBook(final PlayerEditBookEvent event) {
    if (this.loggedOutPlayers.containsKey(event.getPlayer().getUniqueId())) {
        event.setCancelled(true);
    }
}
 
Example 13
Project: AuthMeReloaded   File: PlayerListener16.java   View source code 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerEditBook(PlayerEditBookEvent event) {
    if (listenerService.shouldCancelEvent(event)) {
        event.setCancelled(true);
    }
}
 
Example 14
Project: AuthMeReloaded   File: PlayerListener16Test.java   View source code 4 votes vote down vote up
@Test
public void shouldCancelEvent() {
    withServiceMock(listenerService)
        .check(listener::onPlayerEditBook, PlayerEditBookEvent.class);
}