Skip to content

Commit

Permalink
Band-aid fix for Mohist not clearing slots properly on a cancelled dr…
Browse files Browse the repository at this point in the history
…ag event
  • Loading branch information
Travja committed Jun 27, 2024
1 parent 1c4d17b commit 6ad5108
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package studio.magemonkey.divinity.manager.listener.object;

import studio.magemonkey.codex.manager.IListener;
import studio.magemonkey.codex.util.ItemUT;
import studio.magemonkey.divinity.Divinity;
import studio.magemonkey.divinity.stats.items.ItemStats;
import studio.magemonkey.divinity.stats.items.attributes.HandAttribute;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.inventory.InventoryClickEvent;
Expand All @@ -18,6 +15,11 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import studio.magemonkey.codex.manager.IListener;
import studio.magemonkey.codex.util.ItemUT;
import studio.magemonkey.divinity.Divinity;
import studio.magemonkey.divinity.stats.items.ItemStats;
import studio.magemonkey.divinity.stats.items.attributes.HandAttribute;

import java.util.Set;

Expand Down Expand Up @@ -78,6 +80,13 @@ public void onHandDrag(InventoryDragEvent e) {
if (slots.contains(45)) { // Offhand
plugin.lang().Module_Item_Interact_Error_Hand.send(player);
e.setCancelled(true);
e.setResult(Event.Result.DENY);
String server = Bukkit.getServer().getName();
if (server.contains("Mohist")) {
// Mohist is dumb... and doesn't properly reset slots
// after the event is cancelled
player.getInventory().setItemInOffHand(null);
}
}
}

Expand All @@ -97,6 +106,7 @@ public void onHandClose(InventoryCloseEvent e) {

ItemUT.addItem(player, new ItemStack(off));
player.getInventory().setItemInOffHand(null);
player.updateInventory();
plugin.lang().Module_Item_Interact_Error_Hand.send(player);
}
}
Expand All @@ -115,13 +125,13 @@ public void onHandHoldOffClick(InventoryClickEvent e) {
if (handAtt != null && handAtt.getType() == HandAttribute.Type.TWO) {
plugin.lang().Module_Item_Interact_Error_Hand.send(player);
e.setCancelled(true);
return;
} else {
if (this.holdMainTwo(player)) {
plugin.lang().Module_Item_Interact_Error_Hand.send(player);
e.setCancelled(true);
}
}
player.updateInventory();
}
}

Expand Down

0 comments on commit 6ad5108

Please sign in to comment.