Moved code to normal listeners

master
Ruakij 4 years ago
parent 3695315d42
commit 51e22f2f9e

@ -1,26 +0,0 @@
package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener;
import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main;
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterBlock;
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterItem;
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterManager;
import org.bukkit.GameMode;
import org.bukkit.event.block.BlockBreakEvent;
public class OnBlockBreak {
public static void onBlockBreakEvent(BlockBreakEvent e, LinkedBeaconTeleporterBlock lbtBlock){
LinkedBeaconTeleporterItem lbtItem = Main.lbtManager.breakLbtBlock(lbtBlock);
// Dont drop anything
e.setDropItems(false);
e.setExpToDrop(0);
// Drop custom-item
if(e.getPlayer().getGameMode() != GameMode.CREATIVE)
lbtBlock.block().getLocation().getWorld().dropItemNaturally(
lbtBlock.block().getLocation(),
lbtItem.item()
);
}
}

@ -1,16 +0,0 @@
package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener;
import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main;
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterBlock;
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterItem;
import org.bukkit.block.Block;
import org.bukkit.event.block.BlockPlaceEvent;
public class OnBlockPlace {
public static void onBlockPlaceEvent(BlockPlaceEvent e, LinkedBeaconTeleporterItem lbtItem){
Block block = e.getBlock();
LinkedBeaconTeleporterBlock lbtBlock = Main.lbtManager.placeLbtItem(lbtItem, block);
}
}

@ -1,27 +0,0 @@
package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener;
import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main;
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterItem;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
public class OnCraftItemEvent {
public static void onCraftItemEvent(CraftItemEvent e, LinkedBeaconTeleporterItem lbtItem){
// Create new LinkedBeaconTeleporterItem
lbtItem = new LinkedBeaconTeleporterItem();
ItemStack item = lbtItem.item();
// Exactly 2
item.setAmount(2);
// FIXME: Changing the just-crafted-item only works for a single item, bulk-crafting (e.g. Shift-Click) will result in default-items getting crafted!
e.setCurrentItem(item);
}
}

@ -2,6 +2,8 @@ package eu.ruekov.ruakij.LinkedBeaconTeleporters.listener;
import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main; import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main;
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterBlock; import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterBlock;
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterItem;
import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -21,9 +23,21 @@ public class OnBlockBreak implements Listener {
// Check if this beacon is a LinkedBeaconTeleporter // Check if this beacon is a LinkedBeaconTeleporter
LinkedBeaconTeleporterBlock lbtBlock = LinkedBeaconTeleporterBlock.getFromLocation(loc); LinkedBeaconTeleporterBlock lbtBlock = LinkedBeaconTeleporterBlock.getFromLocation(loc);
if(lbtBlock != null){ // Ignore if not found
eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener.OnBlockBreak.onBlockBreakEvent(e, lbtBlock); if(lbtBlock == null) return;
}
LinkedBeaconTeleporterItem lbtItem = Main.lbtManager.breakLbtBlock(lbtBlock);
// Dont drop anything
e.setDropItems(false);
e.setExpToDrop(0);
// Drop custom-item
if(e.getPlayer().getGameMode() != GameMode.CREATIVE)
lbtBlock.block().getLocation().getWorld().dropItemNaturally(
lbtBlock.block().getLocation(),
lbtItem.item()
);
} }
} }
} }

@ -1,5 +1,7 @@
package eu.ruekov.ruakij.LinkedBeaconTeleporters.listener; package eu.ruekov.ruakij.LinkedBeaconTeleporters.listener;
import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main;
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterBlock;
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterItem; import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterItem;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -20,9 +22,11 @@ public class OnBlockPlace implements Listener {
// Check if this beacon is a LinkedBeaconTeleporter // Check if this beacon is a LinkedBeaconTeleporter
LinkedBeaconTeleporterItem lbtItem = LinkedBeaconTeleporterItem.getFromItemStack(item); LinkedBeaconTeleporterItem lbtItem = LinkedBeaconTeleporterItem.getFromItemStack(item);
if(lbtItem != null){ // Ignore if not found
eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener.OnBlockPlace.onBlockPlaceEvent(e, lbtItem); if(lbtItem == null) return;
}
Block block = e.getBlock();
LinkedBeaconTeleporterBlock lbtBlock = Main.lbtManager.placeLbtItem(lbtItem, block);
} }
} }
} }

@ -22,8 +22,19 @@ public class OnCraftItemEvent implements Listener {
// Check if it has LinkedBeaconTeleporter-Data // Check if it has LinkedBeaconTeleporter-Data
LinkedBeaconTeleporterItem lbtItem = Main.lbtManager.getLbtItemFromItemStack(itemResult); LinkedBeaconTeleporterItem lbtItem = Main.lbtManager.getLbtItemFromItemStack(itemResult);
if(lbtItem != null){
eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener.OnCraftItemEvent.onCraftItemEvent(e, lbtItem); // Ignore if not found
} if(lbtItem == null) return;
// Create new LinkedBeaconTeleporterItem
lbtItem = new LinkedBeaconTeleporterItem();
ItemStack item = lbtItem.item();
// Exactly 2
item.setAmount(2);
// FIXME: Changing the just-crafted-item only works for a single item, bulk-crafting (e.g. Shift-Click) will result in default-items getting crafted!
e.setCurrentItem(item);
} }
} }

Loading…
Cancel
Save