Skip to content

Commit

Permalink
Allow left/right-clicking for locations created by /crazycrates set M…
Browse files Browse the repository at this point in the history
…enu.
  • Loading branch information
ryderbelserion committed Jun 14, 2024
1 parent cfd769c commit a54cc51
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
### Fixed:
- Virtual Keys were not being taken from offline players.
### Changes:
- Allow left/right-clicking for locations created by /crazycrates set Menu.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ authors = ["ryderbelserion", "BadBones69", "TDL"]
description = Create unlimited crates with multiple crate types to choose from!
website = https://modrinth.com/plugin/crazycrates

version = 3.1.1
version = 3.1.2
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public CrazyCrates() {

@Override
public void onEnable() {
new VitalPaper(this);

this.instance = new Server(getDataFolder(), getLogger());
this.instance.apply();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,35 @@ public void onLeftClickCrate(PlayerInteractEvent event) {
player.sendRichMessage(Messages.preview_disabled.getMessage(player, "{crate}", crate.getName()));
}
}

@EventHandler
public void onInteract(PlayerInteractEvent event) {
final Player player = event.getPlayer();

final Block clickedBlock = event.getClickedBlock();

if (clickedBlock == null) return;

final CrateLocation crateLocation = this.crateManager.getCrateLocation(clickedBlock.getLocation());

// If location is null, return.
if (crateLocation == null) return;

final Crate crate = crateLocation.getCrate();

event.setCancelled(true);

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 {
player.sendRichMessage(Messages.feature_disabled.getMessage(player));
}
}
}

// 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.
Expand All @@ -117,6 +146,8 @@ public void onRightClick(PlayerInteractEvent event) {

final Crate crate = crateLocation.getCrate();

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

final boolean isKey = event.getHand() == EquipmentSlot.OFF_HAND ? ItemUtils.isSimilar(player.getInventory().getItemInOffHand(), crate) : ItemUtils.isSimilar(player.getInventory().getItemInMainHand(), crate);

if (isKey) {
Expand All @@ -126,19 +157,6 @@ public void onRightClick(PlayerInteractEvent event) {

event.setCancelled(true);

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 {
player.sendRichMessage(Messages.feature_disabled.getMessage(player));
}

return;
}

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

Expand Down

0 comments on commit a54cc51

Please sign in to comment.