Merge pull request #2 from xartuu/master

Fixed interactions with kit blocks
This commit is contained in:
Christian Koop 2023-08-25 14:53:56 +02:00 committed by GitHub
commit e438efa4d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 27 deletions

View File

@ -21,6 +21,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import com.songoda.ultimatekits.settings.Settings;
public class InteractListeners implements Listener {
@ -48,50 +49,64 @@ public class InteractListeners implements Listener {
Kit kit = kitBlockData.getKit();
Player player = event.getPlayer();
Material itemInHand = player.getItemInHand().getType();
Material keyMaterial = Settings.KEY_MATERIAL.getMaterial().getItem().getType();
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
if (player.isSneaking()) return;
event.setCancelled(true);
if (player.getItemInHand().getType() == Material.TRIPWIRE_HOOK) {
event.setCancelled(true);
kit.processKeyUse(player);
if (player.isSneaking()) {
return;
}
if (kitBlockData.getType() != KitType.PREVIEW) {
event.setCancelled(true);
if (kitBlockData.getType() == KitType.PREVIEW) {
kit.display(player, guiManager, null);
} else if(kitBlockData.getType() == KitType.CRATE) {
if (itemInHand == keyMaterial) {
kit.processKeyUse(player);
} else {
plugin.getLocale().getMessage("event.crate.needkey").sendPrefixedMessage(player);
return;
}
} else if (kitBlockData.getType() == KitType.CLAIM) {
if (!kit.hasPermissionToClaim(player)) {
plugin.getLocale().getMessage("command.general.noperms").sendPrefixedMessage(player);
return;
}
if (kit.getNextUse(player) <= 0) {
kit.processGenericUse(player, false);
kit.updateDelay(player);
} else {
if (kit.getNextUse(player) > 0) {
long time = kit.getNextUse(player);
plugin.getLocale().getMessage("event.crate.notyet").processPlaceholder("time",
Methods.makeReadable(time)).sendPrefixedMessage(player);
plugin.getLocale().getMessage("event.crate.notyet").processPlaceholder("time", Methods.makeReadable(time)).sendPrefixedMessage(player);
return;
}
} else if (kit.getLink() != null || kit.getPrice() != 0) {
kit.buy(player, guiManager);
} else {
kit.display(player, guiManager, null);
}
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (block.getState() instanceof InventoryHolder || block.getType() == Material.ENDER_CHEST) {
event.setCancelled(true);
if (kit.getLink() != null || kit.getPrice() != 0) {
kit.buy(player, guiManager);
} else {
kit.processGenericUse(player, false);
}
kit.updateDelay(player);
}
}
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
event.setCancelled(true);
if (player.isSneaking() && player.hasPermission("ultimatekits.admin")) {
guiManager.showGUI(player, new BlockEditorGui(plugin, kitBlockData));
return;
}
if (player.getItemInHand().getType() == Material.TRIPWIRE_HOOK) {
event.setCancelled(true);
kit.processKeyUse(player);
return;
}
kit.display(player, guiManager, null);
kit.display(player, guiManager, null);
}
}

View File

@ -187,6 +187,7 @@ event:
wrongkey: '&cThis key doesn''t belong to this kit..'
success: '&9Successfully opened a crate.'
given: '&9You have received a %crate% %kit% crate.'
needkey: '&cYou need the right key to get this kit'
claim:
cannotafford: '&9You cannot afford to buy kit &7%kit%&9.'
nottwice: '&9You can only receive this kit once.'