Core/src/main/java/eu/univento/core/listeners/WeaponEvents.java

43 lines
1.5 KiB
Java

/*
* Copyright (c) 2017 univento.eu - All rights reserved
* You are not allowed to use, distribute or modify this code
*/
package eu.univento.core.listeners;
import eu.univento.core.api.customitems.swords.CustomSwordManager;
import eu.univento.core.api.customitems.swords.CustomSword;
import eu.univento.core.api.player.CustomPlayer;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
/**
* @author joethei
* @version 1.0
*/
public class WeaponEvents implements Listener {
@EventHandler
public void onInteract(PlayerInteractEvent e) {
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
if (CustomSwordManager.valueOf(e.getItem()) != null) {
CustomSword sword = CustomSwordManager.valueOf(e.getItem());
assert sword != null;
if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
sword.primaryAttack();
}
if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
sword.secondaryAttack();
}
if(e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR) {
if(p.isSneaking()) sword.sneakingAttack();
}
if(e.getAction() == Action.LEFT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_AIR) {
if(p.isSneaking()) sword.sneakingAttack();
}
}
}
}