Skip to content

Commit

Permalink
add item_pre_grindstone, item_pre_smithing; partial fix modify_event …
Browse files Browse the repository at this point in the history
…for item_pre_craft (#1386)
  • Loading branch information
Lildirt authored Jul 14, 2024
1 parent 04ec9ef commit 2a31201
Show file tree
Hide file tree
Showing 10 changed files with 390 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.laytonsmith.abstraction;

public interface MCGrindstoneInventory extends MCInventory {
MCItemStack getUpperItem();
MCItemStack getLowerItem();
MCItemStack getResult();

void setUpperItem(MCItemStack i);
void setLowerItem(MCItemStack i);
void setResult(MCItemStack i);
}
14 changes: 14 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/MCSmithingInventory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.laytonsmith.abstraction;

public interface MCSmithingInventory extends MCInventory {
MCItemStack getInputEquipment();
MCItemStack getInputMaterial();
MCItemStack getInputTemplate();
MCRecipe getRecipe();
MCItemStack getResult();

void setInputEquipment(MCItemStack stack);
void setInputMaterial(MCItemStack stack);
void setInputTemplate(MCItemStack stack);
void setResult(MCItemStack stack);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.laytonsmith.abstraction.bukkit;

import com.laytonsmith.abstraction.MCGrindstoneInventory;
import com.laytonsmith.abstraction.MCItemStack;
import org.bukkit.inventory.GrindstoneInventory;

public class BukkitMCGrindstoneInventory extends BukkitMCInventory implements MCGrindstoneInventory {

GrindstoneInventory gi;

public BukkitMCGrindstoneInventory(GrindstoneInventory inventory) {
super(inventory);
gi = inventory;
}

@Override
public MCItemStack getUpperItem() {
return new BukkitMCItemStack(gi.getItem(0));
}

@Override
public MCItemStack getLowerItem() {
return new BukkitMCItemStack(gi.getItem(1));
}

@Override
public MCItemStack getResult() {
return new BukkitMCItemStack(gi.getItem(2));
}

@Override
public void setUpperItem(MCItemStack stack) {
gi.setItem(0, ((BukkitMCItemStack) stack).asItemStack());
}

@Override
public void setLowerItem(MCItemStack stack) {
gi.setItem(1, ((BukkitMCItemStack) stack).asItemStack());
}

@Override
public void setResult(MCItemStack stack) {
gi.setItem(2, ((BukkitMCItemStack) stack).asItemStack());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.laytonsmith.abstraction.bukkit;

import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.MCRecipe;
import com.laytonsmith.abstraction.MCSmithingInventory;
import org.bukkit.inventory.SmithingInventory;
import org.bukkit.inventory.SmithingRecipe;

public class BukkitMCSmithingInventory extends BukkitMCInventory implements MCSmithingInventory {

SmithingInventory si;

public BukkitMCSmithingInventory(SmithingInventory inventory) {
super(inventory);
si = inventory;
}

@Override
public MCItemStack getInputEquipment() {
return new BukkitMCItemStack(si.getItem(1));
}

@Override
public MCItemStack getInputMaterial() {
return new BukkitMCItemStack(si.getItem(2));
}

@Override
public MCItemStack getInputTemplate() {
return new BukkitMCItemStack(si.getItem(0));
}

@Override
public MCRecipe getRecipe() {
if(si.getRecipe() == null) {
return null;
} else {
return new BukkitMCSmithingRecipe((SmithingRecipe) si.getRecipe());
}
}

@Override
public MCItemStack getResult() {
return new BukkitMCItemStack(si.getResult());
}

@Override
public void setInputEquipment(MCItemStack stack) {
si.setItem(1, ((BukkitMCItemStack) stack).asItemStack());
}

@Override
public void setInputMaterial(MCItemStack stack) {
si.setItem(2, ((BukkitMCItemStack) stack).asItemStack());
}

@Override
public void setInputTemplate(MCItemStack stack) {
si.setItem(0, ((BukkitMCItemStack) stack).asItemStack());
}

@Override
public void setResult(MCItemStack stack) {
si.setResult(((BukkitMCItemStack) stack).asItemStack());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
import com.laytonsmith.abstraction.MCAnvilInventory;
import com.laytonsmith.abstraction.MCCraftingInventory;
import com.laytonsmith.abstraction.MCEnchantmentOffer;
import com.laytonsmith.abstraction.MCGrindstoneInventory;
import com.laytonsmith.abstraction.MCHumanEntity;
import com.laytonsmith.abstraction.MCInventory;
import com.laytonsmith.abstraction.MCInventoryView;
import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.MCPlayer;
import com.laytonsmith.abstraction.MCRecipe;
import com.laytonsmith.abstraction.MCSmithingInventory;
import com.laytonsmith.abstraction.blocks.MCBlock;
import com.laytonsmith.abstraction.bukkit.BukkitConvertor;
import com.laytonsmith.abstraction.bukkit.BukkitMCAnvilInventory;
import com.laytonsmith.abstraction.bukkit.BukkitMCCraftingInventory;
import com.laytonsmith.abstraction.bukkit.BukkitMCEnchantmentOffer;
import com.laytonsmith.abstraction.bukkit.BukkitMCGrindstoneInventory;
import com.laytonsmith.abstraction.bukkit.BukkitMCInventory;
import com.laytonsmith.abstraction.bukkit.BukkitMCInventoryView;
import com.laytonsmith.abstraction.bukkit.BukkitMCItemStack;
import com.laytonsmith.abstraction.bukkit.BukkitMCSmithingInventory;
import com.laytonsmith.abstraction.bukkit.blocks.BukkitMCBlock;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCHumanEntity;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCPlayer;
Expand All @@ -40,8 +44,10 @@
import com.laytonsmith.abstraction.events.MCItemHeldEvent;
import com.laytonsmith.abstraction.events.MCItemSwapEvent;
import com.laytonsmith.abstraction.events.MCPrepareAnvilEvent;
import com.laytonsmith.abstraction.events.MCPrepareGrindstoneEvent;
import com.laytonsmith.abstraction.events.MCPrepareItemCraftEvent;
import com.laytonsmith.abstraction.events.MCPrepareItemEnchantEvent;
import com.laytonsmith.abstraction.events.MCPrepareSmithingEvent;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.enchantments.EnchantmentOffer;
import org.bukkit.entity.HumanEntity;
Expand All @@ -56,7 +62,9 @@
import org.bukkit.event.inventory.InventoryInteractEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.event.inventory.PrepareGrindstoneEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.inventory.PrepareSmithingEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -572,4 +580,52 @@ public MCAnvilInventory getInventory() {
return new BukkitMCAnvilInventory(e.getInventory());
}
}

public static class BukkitMCPrepareSmithingEvent extends BukkitMCInventoryEvent implements MCPrepareSmithingEvent {
PrepareSmithingEvent e;

public BukkitMCPrepareSmithingEvent(PrepareSmithingEvent event) {
super(event);
e = event;
}

@Override
public MCPlayer getPlayer() {
return new BukkitMCPlayer(e.getViewers().get(0));
}

@Override
public void setResult(MCItemStack stack) {
e.setResult(((BukkitMCItemStack) stack).asItemStack());
}

@Override
public MCSmithingInventory getInventory() {
return new BukkitMCSmithingInventory(e.getInventory());
}
}

public static class BukkitMCPrepareGrindstoneEvent extends BukkitMCInventoryEvent implements MCPrepareGrindstoneEvent {
PrepareGrindstoneEvent e;

public BukkitMCPrepareGrindstoneEvent(PrepareGrindstoneEvent event) {
super(event);
e = event;
}

@Override
public MCPlayer getPlayer() {
return new BukkitMCPlayer(e.getViewers().get(0));
}

@Override
public void setResult(MCItemStack stack) {
e.setResult(((BukkitMCItemStack) stack).asItemStack());
}

@Override
public MCGrindstoneInventory getInventory() {
return new BukkitMCGrindstoneInventory(e.getInventory());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import com.laytonsmith.abstraction.bukkit.events.BukkitInventoryEvents.BukkitMCItemHeldEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitInventoryEvents.BukkitMCItemSwapEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitInventoryEvents.BukkitMCPrepareAnvilEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitInventoryEvents.BukkitMCPrepareGrindstoneEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitInventoryEvents.BukkitMCPrepareItemCraftEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitInventoryEvents.BukkitMCPrepareItemEnchantEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitInventoryEvents.BukkitMCPrepareSmithingEvent;
import com.laytonsmith.core.events.Driver;
import com.laytonsmith.core.events.EventUtils;
import org.bukkit.event.EventHandler;
Expand All @@ -23,7 +25,9 @@
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.event.inventory.PrepareGrindstoneEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.inventory.PrepareSmithingEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;

Expand Down Expand Up @@ -88,4 +92,16 @@ public void onPreAnvil(PrepareAnvilEvent event) {
BukkitMCPrepareAnvilEvent pa = new BukkitInventoryEvents.BukkitMCPrepareAnvilEvent(event);
EventUtils.TriggerListener(Driver.ITEM_PRE_ANVIL, "item_pre_anvil", pa);
}

@EventHandler(priority = EventPriority.LOWEST)
public void onPreSmithing(PrepareSmithingEvent event) {
BukkitMCPrepareSmithingEvent ps = new BukkitInventoryEvents.BukkitMCPrepareSmithingEvent(event);
EventUtils.TriggerListener(Driver.ITEM_PRE_SMITHING, "item_pre_smithing", ps);
}

@EventHandler(priority = EventPriority.LOWEST)
public void onPreGrindstone(PrepareGrindstoneEvent event) {
BukkitMCPrepareGrindstoneEvent pg = new BukkitInventoryEvents.BukkitMCPrepareGrindstoneEvent(event);
EventUtils.TriggerListener(Driver.ITEM_PRE_GRINDSTONE, "item_pre_grindstone", pg);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.laytonsmith.abstraction.events;

import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.MCPlayer;

public interface MCPrepareGrindstoneEvent extends MCInventoryEvent {
MCPlayer getPlayer();

void setResult(MCItemStack stack);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.laytonsmith.abstraction.events;

import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.MCPlayer;

public interface MCPrepareSmithingEvent extends MCInventoryEvent {
MCPlayer getPlayer();

void setResult(MCItemStack stack);
}
2 changes: 2 additions & 0 deletions src/main/java/com/laytonsmith/core/events/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public enum Driver {
ITEM_PRE_CRAFT,
ITEM_PRE_ENCHANT,
ITEM_PRE_ANVIL,
ITEM_PRE_SMITHING,
ITEM_PRE_GRINDSTONE,
/**
* Player events
*/
Expand Down
Loading

0 comments on commit 2a31201

Please sign in to comment.