Skip to content

Commit

Permalink
Fixes #754
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Jul 20, 2024
1 parent 20d0e1f commit 8232601
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

### Changes:
- Updated migrator command format.
- Updated invalid argument output to just describe it better.
- Updated invalid argument output to just describe it better.
- Play knockback/sound if they don't meet the required keys to open a crate
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public void onRightClick(PlayerInteractEvent event) {

player.sendRichMessage(Messages.required_keys.getMessage(player, placeholders));

lackingKey(crate, clickedBlock, player, false);

key.setCancelled(true);

return;
Expand Down Expand Up @@ -215,25 +217,7 @@ public void onRightClick(PlayerInteractEvent event) {
return;
}

final String keyName = crate.getKeyName();

final Map<String, String> placeholders = new HashMap<>() {{
put("{crate}", crate.getName());
put("{key}", keyName);
}};

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

//todo() convert this to a bean property!
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);

player.playSound(sound);
}

player.sendRichMessage(Messages.no_keys.getMessage(player, placeholders));
}
lackingKey(crate, clickedBlock, player, true);

key.setCancelled(true);
}
Expand Down Expand Up @@ -278,6 +262,27 @@ public void onPlayerQuit(PlayerQuitEvent event) {

if (this.crateManager.isInOpeningList(player)) this.crateManager.removePlayerFromOpeningList(player);
}

private void lackingKey(final Crate crate, final Block clickedBlock, final Player player, final boolean sendMessage) {
final String keyName = crate.getKeyName();

final Map<String, String> placeholders = new HashMap<>() {{
put("{crate}", crate.getName());
put("{key}", keyName);
}};

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

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);

player.playSound(sound);
}

if (sendMessage) player.sendRichMessage(Messages.no_keys.getMessage(player, placeholders));
}
}

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

0 comments on commit 8232601

Please sign in to comment.