Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add bypass permission for book open on join #109

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions src/main/java/net/leonardo_dgs/interactivebooks/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.leonardo_dgs.interactivebooks.util.MinecraftVersion;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -24,28 +25,35 @@ public final class PlayerListener implements Listener {
public void onPlayerJoin(PlayerJoinEvent event) {
String openBookId;
List<String> booksToGiveIds;
if (event.getPlayer().hasPlayedBefore()) {
openBookId = ConfigManager.getConfig().getString("open_book_on_join");
booksToGiveIds = ConfigManager.getConfig().getStringList("books_on_join");
} else {
openBookId = ConfigManager.getConfig().getString("open_book_on_first_join");
booksToGiveIds = ConfigManager.getConfig().getStringList("books_on_first_join");
}
if (openBookId != null && !openBookId.equals("")) {
IBook book = InteractiveBooks.getBook(openBookId);
if (book != null) {
if (MC_AFTER_1_14)
book.open(event.getPlayer());
else
Bukkit.getScheduler().runTask(InteractiveBooks.getInstance(), () -> book.open(event.getPlayer()));
Player player = event.getPlayer();

if (!player.hasPermission("interactivebooks.auto-open.bypass")) {

if (player.hasPlayedBefore()) {
openBookId = ConfigManager.getConfig().getString("open_book_on_join");
booksToGiveIds = ConfigManager.getConfig().getStringList("books_on_join");
} else {
openBookId = ConfigManager.getConfig().getString("open_book_on_first_join");
booksToGiveIds = ConfigManager.getConfig().getStringList("books_on_first_join");
}
if (openBookId != null && !openBookId.equals("")) {
IBook book = InteractiveBooks.getBook(openBookId);
if (book != null) {
if (MC_AFTER_1_14)
book.open(player);
else
Bukkit.getScheduler().runTask(InteractiveBooks.getInstance(), () -> book.open(player));
}
}

booksToGiveIds.forEach(id -> {
IBook book = InteractiveBooks.getBook(id);
if (book != null)
player.getInventory().addItem(book.getItem(player));
});

}

booksToGiveIds.forEach(id -> {
IBook book = InteractiveBooks.getBook(id);
if (book != null)
event.getPlayer().getInventory().addItem(book.getItem(event.getPlayer()));
});
}

@EventHandler(priority = EventPriority.HIGHEST)
Expand Down