Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
fix #4
Browse files Browse the repository at this point in the history
  • Loading branch information
ReinWD committed Jun 9, 2019
1 parent 902fdbc commit 51cc8a6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/main/java/cat/nyaa/saika/Configure.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class Configure extends PluginConfigure {
@Serializable(name = "sound.success")
public SoundConf successSound = new SoundConf();


@Serializable(name = "sound.fail")
public SoundConf failSound = new SoundConf();

Expand Down Expand Up @@ -91,9 +90,13 @@ public class Configure extends PluginConfigure {

@Serializable(name = "forge.lowEfficiency.multiplier")
public double lowEfficiencyMultiplier = 1.5;

@Serializable(name = "log.enabled")
public boolean logEnabled = false;

@Serializable(name = "directInteract")
public boolean directInteractEnabled = false;


public static class SoundConf implements ISerializable {
@Serializable
Expand Down
1 change: 1 addition & 0 deletions src/main/java/cat/nyaa/saika/forge/ui/ForgeUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public void updateValidation() {
}

public ForgeableItem onForge() {
this.updateValidation();
ForgeManager forgeManager = ForgeManager.getForgeManager();
if (validation.equals(RecipieValidation.VALID)) {
ForgeableItem item = forgeManager.forgeItem(getRecipe());
Expand Down
51 changes: 41 additions & 10 deletions src/main/java/cat/nyaa/saika/forge/ui/ForgeUiEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
import cat.nyaa.saika.forge.roll.ForgeRecipe;
import cat.nyaa.saika.log.Logger;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.*;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -58,15 +61,6 @@ public static void registerRepulse(Inventory inventory, RepulseUi repulseUi) {
repulseUiList.put(inventory, repulseUi);
}

@EventHandler
public void onInventoryClose(InventoryCloseEvent ev) {
Inventory inventory = ev.getInventory();
giveItemBack(ev, inventory, forgeUiList);
giveItemBack(ev, inventory, enchantUiList);
giveItemBack(ev, inventory, recycleUiList);
giveItemBack(ev, inventory, repulseUiList);
}

private void giveItemBack(InventoryCloseEvent ev, Inventory inventory, Map<Inventory, ? extends InventoryHolder> enchantUiList) {
if (enchantUiList.remove(inventory) != null) {
for (int i = 0; i < 3; i++) {
Expand All @@ -85,6 +79,43 @@ private void giveItemBack(InventoryCloseEvent ev, Inventory inventory, Map<Inven
}
}

@EventHandler
public void onDirectInteract(PlayerInteractEvent event){
Configure configure = plugin.getConfigure();
if (!configure.directInteractEnabled) {
return;
}
if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
Player player = event.getPlayer();
Block clickedBlock = event.getClickedBlock();
if (clickedBlock != null){
if (player.isSneaking()){
return;
}
Material forgeBlock = configure.getForgeBlock();
Material enchantBlock = configure.getEnchantBlock();
if (clickedBlock.getType().equals(forgeBlock)){
event.setCancelled(true);
new ForgeUi().openInventory(player);
return;
}else if (clickedBlock.getType().equals(enchantBlock)){
event.setCancelled(true);
new EnchantUi().openInventory(player);
return;
}
}
}
}

@EventHandler
public void onInventoryClose(InventoryCloseEvent ev) {
Inventory inventory = ev.getInventory();
giveItemBack(ev, inventory, forgeUiList);
giveItemBack(ev, inventory, enchantUiList);
giveItemBack(ev, inventory, recycleUiList);
giveItemBack(ev, inventory, repulseUiList);
}

@EventHandler
public void onInventoryDrag(InventoryDragEvent ev) {
Inventory clickedInventory = ev.getView().getTopInventory();
Expand Down Expand Up @@ -255,8 +286,8 @@ private void forgeUiClicked(InventoryClickEvent ev, Inventory clickedInventory)
if (currentItem != null && currentItem.getItemMeta() != null) {
if (currentItem.getItemMeta().getCustomTagContainer().hasCustomTag(INDICATOR, ItemTagType.STRING)) {
forgeUi.updateValidation();
ForgeRecipe recipe = forgeUi.getRecipe();
ForgeableItem item = forgeUi.onForge();
ForgeRecipe recipe = forgeUi.getRecipe();
if (item != null) {
ItemStack itemStack = item.getItemStack().clone();
String level = item.getLevel();
Expand Down

0 comments on commit 51cc8a6

Please sign in to comment.