Skip to content

Commit

Permalink
make right click open the menu again
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Aug 14, 2024
1 parent 4f6a2b9 commit 438399a
Showing 1 changed file with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,9 @@ public void onCrateInteract(PlayerInteractEvent event) {
return;
}

final Crate crate = crateLocation.getCrate();

if (crate.getCrateType() == CrateType.menu) {
// this is to stop players in QuadCrate to not be able to try and open a crate set to menu.
if (!this.crateManager.isInOpeningList(player) && this.config.getProperty(ConfigKeys.enable_crate_menu)) {
final CrateMainMenu crateMainMenu = new CrateMainMenu(player, this.config.getProperty(ConfigKeys.inventory_name), this.config.getProperty(ConfigKeys.inventory_size));

player.openInventory(crateMainMenu.build().getInventory());
} else {
Messages.feature_disabled.sendMessage(player);
}
} else {
if (crate.isPreviewEnabled()) {
this.inventoryManager.addViewer(player);
this.inventoryManager.openNewCratePreview(player, crateLocation.getCrate());
} else {
Messages.preview_disabled.sendMessage(player, "{crate}", crate.getName());
}
}
preview(player, crateLocation.getCrate(), false);
}

// This must run as highest, so it doesn't cause other plugins to check
// the items that were added to the players inventory and replaced the item in the player's hand.
// This is only an issue with QuickCrate
Expand All @@ -138,11 +120,15 @@ public void onRightClick(PlayerInteractEvent event) {

final Crate crate = crateLocation.getCrate();

if (crate.getCrateType() == CrateType.menu) return;

event.setUseInteractedBlock(Event.Result.DENY);
event.setUseItemInHand(Event.Result.DENY);

if (crate.getCrateType() == CrateType.menu) {
preview(player, crate, true);

return;
}

final KeyCheckEvent key = new KeyCheckEvent(player, crateLocation);
player.getServer().getPluginManager().callEvent(key);

Expand Down Expand Up @@ -278,7 +264,7 @@ private void lackingKey(final Player player, final Crate crate, final Location l
}};

if (crate.getCrateType() != CrateType.crate_on_the_go) {
if (this.config.getProperty(ConfigKeys.knock_back)) knockBack(player, location);
if (this.config.getProperty(ConfigKeys.knock_back)) knockback(player, location);

if (this.config.getProperty(ConfigKeys.need_key_sound_toggle)) {
net.kyori.adventure.sound.Sound sound = net.kyori.adventure.sound.Sound.sound(Key.key(this.config.getProperty(ConfigKeys.need_key_sound)), Sound.Source.PLAYER, 1f, 1f);
Expand All @@ -289,8 +275,8 @@ private void lackingKey(final Player player, final Crate crate, final Location l
if (sendMessage) Messages.no_keys.sendMessage(player, placeholders);
}
}
private void knockBack(final Player player, final Location location) {

private void knockback(final Player player, final Location location) {
final Vector vector = player.getLocation().toVector().subtract(location.toVector()).normalize().multiply(1).setY(.1);

if (player.isInsideVehicle() && player.getVehicle() != null) {
Expand All @@ -301,4 +287,24 @@ private void knockBack(final Player player, final Location location) {

player.setVelocity(vector);
}

private void preview(final Player player, final Crate crate, boolean skipTypeCheck) {
if (skipTypeCheck || crate.getCrateType() == CrateType.menu) {
// this is to stop players in QuadCrate to not be able to try and open a crate set to menu.
if (!this.crateManager.isInOpeningList(player) && this.config.getProperty(ConfigKeys.enable_crate_menu)) {
final CrateMainMenu crateMainMenu = new CrateMainMenu(player, this.config.getProperty(ConfigKeys.inventory_name), this.config.getProperty(ConfigKeys.inventory_size));

player.openInventory(crateMainMenu.build().getInventory());
} else {
Messages.feature_disabled.sendMessage(player);
}
} else {
if (crate.isPreviewEnabled()) {
this.inventoryManager.addViewer(player);
this.inventoryManager.openNewCratePreview(player, crate);
} else {
Messages.preview_disabled.sendMessage(player, "{crate}", crate.getName());
}
}
}
}

0 comments on commit 438399a

Please sign in to comment.