SHARE
TWEET

Untitled

a guest Nov 8th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package de.dorung.DCmineville.listeners;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.entity.Player;
  5. import org.bukkit.event.EventHandler;
  6. import org.bukkit.event.Listener;
  7. import org.bukkit.event.block.Action;
  8. import org.bukkit.event.inventory.InventoryClickEvent;
  9. import org.bukkit.event.player.PlayerInteractEvent;
  10. import org.bukkit.inventory.ItemStack;
  11.  
  12. import de.dorung.DCmineville.main.Main;
  13. import de.dorung.DCmineville.voting.Voting;
  14.  
  15. public class VotingListener implements Listener {
  16.  
  17.     private Main plugin;
  18.     private Voting voting;
  19.    
  20.     public VotingListener(Main plugin) {
  21.         this.plugin = plugin;
  22.         voting = plugin.getVoting();
  23.     }
  24.    
  25.     @EventHandler
  26.     public void onVotingMenuOpener(PlayerInteractEvent event) {
  27.         if(!(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
  28.         Player player = event.getPlayer();
  29.         ItemStack item = player.getInventory().getItemInMainHand();
  30.         if(item.getItemMeta() == null) return;
  31.         if(item.getItemMeta().getDisplayName().equals(PlayerLobbyConnectionListener.VOTING_ITEM_NAME)) {
  32.             player.openInventory(voting.getVotingInventory());
  33.         }
  34.     }
  35.    
  36.     @EventHandler
  37.     public void onVotingClick(InventoryClickEvent event) {
  38.         if(!(event.getWhoClicked() instanceof Player)) return;
  39.         Player player = (Player) event.getWhoClicked();
  40.         if(!event.getView().getTitle().equals(PlayerLobbyConnectionListener.VOTING_ITEM_NAME)) {
  41.              event.setCancelled(true);
  42.              for(int i = 0; i < voting.getVotingInventoryOlder().length; i++) {
  43.                  if(voting.getVotingInventoryOlder()[i] == event.getSlot()) {
  44.                      voting.vote(player, i);
  45.                  }
  46.              }
  47.         } else {
  48.             return;
  49.         }
  50.     }
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top