Compare commits
	
		
			11 Commits
		
	
	
		
			3f73d15a5a
			...
			f03a80cf99
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					f03a80cf99 | ||
| 
						 | 
					51e22f2f9e | ||
| 
						 | 
					3695315d42 | ||
| 
						 | 
					b819fcb9f5 | ||
| 
						 | 
					ddb6525c40 | ||
| 
						 | 
					c0917a1ab6 | ||
| 
						 | 
					3d757a6ccf | ||
| 
						 | 
					a296a190c6 | ||
| 
						 | 
					800032f530 | ||
| 
						 | 
					3df5c9d4ac | ||
| 
						 | 
					d9c95a5e53 | 
@ -2,11 +2,14 @@ package eu.ruekov.ruakij.LinkedBeaconTeleporters;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.World;
 | 
			
		||||
import org.bukkit.block.Block;
 | 
			
		||||
import org.bukkit.util.Vector;
 | 
			
		||||
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.InvalidPropertiesFormatException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Random;
 | 
			
		||||
 | 
			
		||||
public class Function {
 | 
			
		||||
@ -38,4 +41,115 @@ public class Function {
 | 
			
		||||
        }
 | 
			
		||||
        return str;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static List<Material> transparentMaterials = Arrays.asList(
 | 
			
		||||
            Material.AIR,
 | 
			
		||||
            Material.GLASS,
 | 
			
		||||
            Material.GLASS_PANE,
 | 
			
		||||
            Material.BLACK_STAINED_GLASS,
 | 
			
		||||
            Material.BLACK_STAINED_GLASS_PANE,
 | 
			
		||||
            Material.BLUE_STAINED_GLASS,
 | 
			
		||||
            Material.BLUE_STAINED_GLASS_PANE,
 | 
			
		||||
            Material.BROWN_STAINED_GLASS,
 | 
			
		||||
            Material.BROWN_STAINED_GLASS_PANE,
 | 
			
		||||
            Material.CYAN_STAINED_GLASS,
 | 
			
		||||
            Material.CYAN_STAINED_GLASS_PANE,
 | 
			
		||||
            Material.GRAY_STAINED_GLASS,
 | 
			
		||||
            Material.GRAY_STAINED_GLASS_PANE,
 | 
			
		||||
            Material.GREEN_STAINED_GLASS,
 | 
			
		||||
            Material.GREEN_STAINED_GLASS_PANE,
 | 
			
		||||
            Material.LIGHT_BLUE_STAINED_GLASS,
 | 
			
		||||
            Material.LIGHT_BLUE_STAINED_GLASS_PANE,
 | 
			
		||||
            Material.LIGHT_GRAY_STAINED_GLASS,
 | 
			
		||||
            Material.LIGHT_GRAY_STAINED_GLASS_PANE,
 | 
			
		||||
            Material.LIME_STAINED_GLASS,
 | 
			
		||||
            Material.LIME_STAINED_GLASS_PANE,
 | 
			
		||||
            Material.MAGENTA_STAINED_GLASS,
 | 
			
		||||
            Material.MAGENTA_STAINED_GLASS_PANE,
 | 
			
		||||
            Material.ORANGE_STAINED_GLASS,
 | 
			
		||||
            Material.ORANGE_STAINED_GLASS_PANE,
 | 
			
		||||
            Material.PINK_STAINED_GLASS,
 | 
			
		||||
            Material.PINK_STAINED_GLASS_PANE,
 | 
			
		||||
            Material.PURPLE_STAINED_GLASS,
 | 
			
		||||
            Material.PURPLE_STAINED_GLASS_PANE,
 | 
			
		||||
            Material.RED_STAINED_GLASS,
 | 
			
		||||
            Material.RED_STAINED_GLASS_PANE,
 | 
			
		||||
            Material.WHITE_STAINED_GLASS,
 | 
			
		||||
            Material.WHITE_STAINED_GLASS_PANE,
 | 
			
		||||
            Material.YELLOW_STAINED_GLASS,
 | 
			
		||||
            Material.YELLOW_STAINED_GLASS_PANE,
 | 
			
		||||
            Material.PISTON,
 | 
			
		||||
            Material.PISTON_HEAD,
 | 
			
		||||
            Material.MOVING_PISTON,
 | 
			
		||||
            Material.STICKY_PISTON,
 | 
			
		||||
            Material.ACACIA_LEAVES,
 | 
			
		||||
            Material.BIRCH_LEAVES,
 | 
			
		||||
            Material.DARK_OAK_LEAVES,
 | 
			
		||||
            Material.JUNGLE_LEAVES,
 | 
			
		||||
            Material.OAK_LEAVES,
 | 
			
		||||
            Material.SPRUCE_LEAVES,
 | 
			
		||||
            Material.ACACIA_SLAB,
 | 
			
		||||
            Material.ANDESITE_SLAB,
 | 
			
		||||
            Material.BIRCH_SLAB,
 | 
			
		||||
            Material.BLACKSTONE_SLAB,
 | 
			
		||||
            Material.BRICK_SLAB,
 | 
			
		||||
            Material.COBBLESTONE_SLAB,
 | 
			
		||||
            Material.CRIMSON_SLAB,
 | 
			
		||||
            Material.CUT_RED_SANDSTONE_SLAB,
 | 
			
		||||
            Material.CUT_SANDSTONE_SLAB,
 | 
			
		||||
            Material.DARK_OAK_SLAB,
 | 
			
		||||
            Material.DARK_PRISMARINE_SLAB,
 | 
			
		||||
            Material.DIORITE_SLAB,
 | 
			
		||||
            Material.END_STONE_BRICK_SLAB,
 | 
			
		||||
            Material.GRANITE_SLAB,
 | 
			
		||||
            Material.JUNGLE_SLAB,
 | 
			
		||||
            Material.MOSSY_COBBLESTONE_SLAB,
 | 
			
		||||
            Material.MOSSY_STONE_BRICK_SLAB,
 | 
			
		||||
            Material.NETHER_BRICK_SLAB,
 | 
			
		||||
            Material.OAK_SLAB,
 | 
			
		||||
            Material.PETRIFIED_OAK_SLAB,
 | 
			
		||||
            Material.POLISHED_ANDESITE_SLAB,
 | 
			
		||||
            Material.POLISHED_BLACKSTONE_BRICK_SLAB,
 | 
			
		||||
            Material.POLISHED_BLACKSTONE_SLAB,
 | 
			
		||||
            Material.POLISHED_DIORITE_SLAB,
 | 
			
		||||
            Material.POLISHED_GRANITE_SLAB,
 | 
			
		||||
            Material.PRISMARINE_BRICK_SLAB,
 | 
			
		||||
            Material.PRISMARINE_SLAB,
 | 
			
		||||
            Material.PURPUR_SLAB,
 | 
			
		||||
            Material.QUARTZ_SLAB,
 | 
			
		||||
            Material.RED_NETHER_BRICK_SLAB,
 | 
			
		||||
            Material.RED_SANDSTONE_SLAB,
 | 
			
		||||
            Material.SANDSTONE_SLAB,
 | 
			
		||||
            Material.SMOOTH_QUARTZ_SLAB,
 | 
			
		||||
            Material.SMOOTH_RED_SANDSTONE_SLAB,
 | 
			
		||||
            Material.SMOOTH_SANDSTONE_SLAB,
 | 
			
		||||
            Material.SMOOTH_STONE_SLAB,
 | 
			
		||||
            Material.SPRUCE_SLAB,
 | 
			
		||||
            Material.STONE_BRICK_SLAB,
 | 
			
		||||
            Material.STONE_SLAB,
 | 
			
		||||
            Material.WARPED_SLAB
 | 
			
		||||
    );
 | 
			
		||||
    public static Block searchForMaterial(Location startLoc, Vector searchDirection, Material searchMaterial, List<Material> ignoreMaterials){
 | 
			
		||||
        Location loc = new Location(startLoc.getWorld(), startLoc.getBlockX(), startLoc.getBlockY(), startLoc.getBlockZ());
 | 
			
		||||
        for(int i=0; loc.getBlockY()>=0 && loc.getBlockY()<=255; loc.add(searchDirection)){
 | 
			
		||||
            Block block = loc.getBlock();
 | 
			
		||||
 | 
			
		||||
            // Check for correct material
 | 
			
		||||
            if(block.getType() == searchMaterial) return block;
 | 
			
		||||
 | 
			
		||||
            // Check for non-ignore-block
 | 
			
		||||
            boolean found = false;
 | 
			
		||||
            for(Material ignoreMaterial : ignoreMaterials){
 | 
			
		||||
                if(block.getType() == ignoreMaterial){
 | 
			
		||||
                    found = true;
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            // If not found, searchMaterial not found
 | 
			
		||||
            if(!found) return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Reached 0 or 255, searchMaterial not found
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,9 +1,11 @@
 | 
			
		||||
package eu.ruekov.ruakij.LinkedBeaconTeleporters;
 | 
			
		||||
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.customPlayerMoveEvent.CustomPlayerMoveEventHandler;
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterManager;
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.listener.OnBlockBreak;
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.listener.OnBlockPlace;
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.listener.OnPrepareItemCraftEvent;
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.listener.OnCraftItemEvent;
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.listener.OnCustomPlayerMove;
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.configuration.file.FileConfiguration;
 | 
			
		||||
import org.bukkit.configuration.file.YamlConfiguration;
 | 
			
		||||
@ -33,7 +35,10 @@ public class Main extends JavaPlugin {
 | 
			
		||||
        PluginManager pluginManager = Bukkit.getPluginManager();
 | 
			
		||||
        pluginManager.registerEvents(new OnBlockBreak(), this);
 | 
			
		||||
        pluginManager.registerEvents(new OnBlockPlace(), this);
 | 
			
		||||
        pluginManager.registerEvents(new OnPrepareItemCraftEvent(), this);
 | 
			
		||||
        pluginManager.registerEvents(new OnCraftItemEvent(), this);
 | 
			
		||||
 | 
			
		||||
        CustomPlayerMoveEventHandler cpmHandler = new CustomPlayerMoveEventHandler(this, true);
 | 
			
		||||
        cpmHandler.registerListener(new OnCustomPlayerMove());
 | 
			
		||||
 | 
			
		||||
        loadConfigs();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,35 @@
 | 
			
		||||
package eu.ruekov.ruakij.LinkedBeaconTeleporters.customPlayerMoveEvent;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import java.io.InvalidObjectException;
 | 
			
		||||
 | 
			
		||||
public class CustomPlayerMoveEvent {
 | 
			
		||||
 | 
			
		||||
    Player p;
 | 
			
		||||
    Location loc;
 | 
			
		||||
    Location oldLoc;
 | 
			
		||||
    protected double distance;
 | 
			
		||||
    public CustomPlayerMoveEvent(Player p, Location loc, Location oldLoc){
 | 
			
		||||
        this.p = p;
 | 
			
		||||
        this.loc = loc;
 | 
			
		||||
        this.oldLoc = oldLoc;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Player player(){
 | 
			
		||||
        return p;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Location location(){
 | 
			
		||||
        return loc;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Location oldLocation(){
 | 
			
		||||
        return oldLoc;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public double distance(){
 | 
			
		||||
        return distance;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,89 @@
 | 
			
		||||
package eu.ruekov.ruakij.LinkedBeaconTeleporters.customPlayerMoveEvent;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.plugin.Plugin;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
public class CustomPlayerMoveEventHandler {
 | 
			
		||||
 | 
			
		||||
    List<CustomPlayerMoveEventListener> listeners = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
    HashMap<UUID, Location> oldPlayerLoc = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
    boolean locationChangeOnBlockChange;
 | 
			
		||||
    public CustomPlayerMoveEventHandler(Plugin plugin, boolean locationChangeOnBlockChange){
 | 
			
		||||
        this.locationChangeOnBlockChange = locationChangeOnBlockChange;
 | 
			
		||||
 | 
			
		||||
        startRunnable(plugin);
 | 
			
		||||
    }
 | 
			
		||||
    public CustomPlayerMoveEventHandler(Plugin plugin){
 | 
			
		||||
        this(plugin, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void startRunnable(Plugin plugin){
 | 
			
		||||
 | 
			
		||||
        Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
 | 
			
		||||
            // Dont do anything without listeners
 | 
			
		||||
            if(listeners.size() == 0) return;
 | 
			
		||||
 | 
			
		||||
            // Check all players
 | 
			
		||||
            for(Player p : Bukkit.getOnlinePlayers()){
 | 
			
		||||
                UUID uuid = p.getUniqueId();
 | 
			
		||||
                Location loc = p.getLocation();
 | 
			
		||||
 | 
			
		||||
                // Get old-location
 | 
			
		||||
                Location oldLoc = oldPlayerLoc.get(uuid);
 | 
			
		||||
 | 
			
		||||
                // Create data-obj
 | 
			
		||||
                CustomPlayerMoveEvent e = new CustomPlayerMoveEvent(p, loc, oldLoc);
 | 
			
		||||
 | 
			
		||||
                // When player has an old-location
 | 
			
		||||
                if(oldLoc != null){
 | 
			
		||||
                    if(!locationChangeOnBlockChange){
 | 
			
		||||
                        double distance = loc.distance(oldLoc);
 | 
			
		||||
                        e.distance = distance;
 | 
			
		||||
 | 
			
		||||
                        if(distance > 0)
 | 
			
		||||
                            locationChangeListeners(e);
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                        locationChangeListeners(e);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                tickListeners(e);
 | 
			
		||||
 | 
			
		||||
                // Save old location
 | 
			
		||||
                oldPlayerLoc.put(uuid, loc);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        }, 20, 10);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    boolean blockLocationChanged(Location loc, Location oldLoc){
 | 
			
		||||
        return  loc.getBlockX() != oldLoc.getBlockX() ||
 | 
			
		||||
                loc.getBlockY() != oldLoc.getBlockY() ||
 | 
			
		||||
                loc.getBlockZ() != oldLoc.getBlockZ();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void tickListeners(CustomPlayerMoveEvent e){
 | 
			
		||||
        for(CustomPlayerMoveEventListener listener : listeners){
 | 
			
		||||
            listener.tick(e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    void locationChangeListeners(CustomPlayerMoveEvent e){
 | 
			
		||||
        for(CustomPlayerMoveEventListener listener : listeners){
 | 
			
		||||
            listener.locationChange(e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public void registerListener(CustomPlayerMoveEventListener listener){
 | 
			
		||||
        listeners.add(listener);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,10 @@
 | 
			
		||||
package eu.ruekov.ruakij.LinkedBeaconTeleporters.customPlayerMoveEvent;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
public interface CustomPlayerMoveEventListener {
 | 
			
		||||
 | 
			
		||||
    void tick(CustomPlayerMoveEvent e);
 | 
			
		||||
 | 
			
		||||
    void locationChange(CustomPlayerMoveEvent e);
 | 
			
		||||
}
 | 
			
		||||
@ -13,17 +13,22 @@ public class LinkedBeaconTeleporterItem extends LinkedBeaconTeleporter {
 | 
			
		||||
    // INFO: Safe to store as its always cloned by bukkit
 | 
			
		||||
    ItemStack item;
 | 
			
		||||
 | 
			
		||||
    public LinkedBeaconTeleporterItem(ItemStack item){
 | 
			
		||||
    public LinkedBeaconTeleporterItem(){
 | 
			
		||||
        // Create a new LinkedBeaconTeleporter
 | 
			
		||||
        super();
 | 
			
		||||
 | 
			
		||||
        this.item = item;
 | 
			
		||||
        this.item = Main.lbtManager.getItemStackFromData(this.teleporterId);
 | 
			
		||||
    }
 | 
			
		||||
    public LinkedBeaconTeleporterItem(String teleporterId, ItemStack item) {
 | 
			
		||||
        super(teleporterId);
 | 
			
		||||
 | 
			
		||||
        this.item = item;
 | 
			
		||||
    }
 | 
			
		||||
    public LinkedBeaconTeleporterItem(String teleporterId){
 | 
			
		||||
        super(teleporterId);
 | 
			
		||||
 | 
			
		||||
        this.item = Main.lbtManager.getItemStackFromData(teleporterId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ItemStack item(){
 | 
			
		||||
        return item;
 | 
			
		||||
@ -31,9 +36,6 @@ public class LinkedBeaconTeleporterItem extends LinkedBeaconTeleporter {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // Conversion methods
 | 
			
		||||
    public ItemStack toItemStack(){
 | 
			
		||||
        return Main.lbtManager.getItemStackFromLbtItem(this);
 | 
			
		||||
    }
 | 
			
		||||
    public static LinkedBeaconTeleporterItem getFromItemStack(ItemStack itemStack){
 | 
			
		||||
        return Main.lbtManager.getLbtItemFromItemStack(itemStack);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -2,11 +2,14 @@ package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter;
 | 
			
		||||
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.Function;
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main;
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.NamespacedKey;
 | 
			
		||||
import org.bukkit.block.Block;
 | 
			
		||||
import org.bukkit.configuration.ConfigurationSection;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
import org.bukkit.inventory.ShapelessRecipe;
 | 
			
		||||
import org.bukkit.inventory.meta.ItemMeta;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
@ -31,6 +34,9 @@ public class LinkedBeaconTeleporterManager {
 | 
			
		||||
                Main.config.getStringList("item.lore")
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        // Construct & add crafting-receipes
 | 
			
		||||
       constructAndAddRecipes();
 | 
			
		||||
 | 
			
		||||
        // Load teleporters
 | 
			
		||||
        for(String teleporterId : Main.data.getKeys(false)){
 | 
			
		||||
            ConfigurationSection teleportersData = Main.data.getConfigurationSection(teleporterId);
 | 
			
		||||
@ -76,8 +82,69 @@ public class LinkedBeaconTeleporterManager {
 | 
			
		||||
        Main.log.info("All done!");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public LinkedBeaconTeleporterBlock placeLbtItem(LinkedBeaconTeleporterItem lbtItem, Block block){
 | 
			
		||||
        // Check if id already exists
 | 
			
		||||
        List<LinkedBeaconTeleporterBlock> lbtBlocks = linkedBeaconTeleporterById.get(lbtItem.teleporterId());
 | 
			
		||||
        if(lbtBlocks == null){
 | 
			
		||||
            // Create empty if not found
 | 
			
		||||
            lbtBlocks = new ArrayList<>();
 | 
			
		||||
            linkedBeaconTeleporterById.put(lbtItem.teleporterId(), lbtBlocks);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Block from item
 | 
			
		||||
        LinkedBeaconTeleporterBlock lbtBlock = new LinkedBeaconTeleporterBlock(lbtItem.teleporterId(), block);
 | 
			
		||||
 | 
			
		||||
        // Add to list
 | 
			
		||||
        lbtBlocks.add(lbtBlock);
 | 
			
		||||
        // Add to location
 | 
			
		||||
        linkedBeaconTeleporterByLoc.put(
 | 
			
		||||
                Function.serialiseBlockLocation(block.getLocation()),
 | 
			
		||||
                lbtBlock
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        return lbtBlock;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public LinkedBeaconTeleporterItem breakLbtBlock(LinkedBeaconTeleporterBlock lbtBlock){
 | 
			
		||||
        // Get list by id
 | 
			
		||||
        List<LinkedBeaconTeleporterBlock> lbtBlocks = linkedBeaconTeleporterById.get(lbtBlock.teleporterId());
 | 
			
		||||
 | 
			
		||||
        // Remove from list
 | 
			
		||||
        lbtBlocks.remove(lbtBlock);
 | 
			
		||||
        // Remove from location
 | 
			
		||||
        linkedBeaconTeleporterByLoc.remove(
 | 
			
		||||
                Function.serialiseBlockLocation(lbtBlock.block().getLocation())
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        // Item from block
 | 
			
		||||
        LinkedBeaconTeleporterItem lbtItem = new LinkedBeaconTeleporterItem(lbtBlock.teleporterId());
 | 
			
		||||
 | 
			
		||||
        return lbtItem;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void constructAndAddRecipes(){
 | 
			
		||||
        // Create result-item
 | 
			
		||||
        ItemStack item = getItemStackFromData("-");
 | 
			
		||||
        item.setAmount(2);
 | 
			
		||||
 | 
			
		||||
        // Create recipe
 | 
			
		||||
        ShapelessRecipe recipe = new ShapelessRecipe(
 | 
			
		||||
                new NamespacedKey(Main.plugin, "linked_beacon_teleporter")
 | 
			
		||||
                , item);
 | 
			
		||||
        recipe.addIngredient(2, Material.BEACON);
 | 
			
		||||
        Bukkit.addRecipe(recipe);
 | 
			
		||||
 | 
			
		||||
        // Empty recipe to reset beacon
 | 
			
		||||
        ShapelessRecipe recipe2 = new ShapelessRecipe(
 | 
			
		||||
                new NamespacedKey(Main.plugin, "linked_beacon_teleporter_reset"),
 | 
			
		||||
                new ItemStack(Material.BEACON)
 | 
			
		||||
                );
 | 
			
		||||
        recipe2.addIngredient(1, Material.BEACON);
 | 
			
		||||
        Bukkit.addRecipe(recipe2);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Conversion-methods
 | 
			
		||||
    public ItemStack getItemStackFromLbtItem(LinkedBeaconTeleporterItem lbtItem){
 | 
			
		||||
    public ItemStack getItemStackFromData(String teleporterId){
 | 
			
		||||
        ItemStack item = new ItemStack(Material.BEACON);
 | 
			
		||||
        ItemMeta itemMeta = item.getItemMeta();
 | 
			
		||||
 | 
			
		||||
@ -86,10 +153,10 @@ public class LinkedBeaconTeleporterManager {
 | 
			
		||||
        List<String> lore = Main.config.getStringList("item.lore");
 | 
			
		||||
 | 
			
		||||
        // Replace parameters
 | 
			
		||||
        name = name.replace("%id%", lbtItem.teleporterId);
 | 
			
		||||
        name = name.replace("%id%", teleporterId);
 | 
			
		||||
        for(int i=0; i<lore.size(); i++){
 | 
			
		||||
            lore.set(i,
 | 
			
		||||
                    lore.get(i).replace("%id%", lbtItem.teleporterId)
 | 
			
		||||
                    lore.get(i).replace("%id%", teleporterId)
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,11 +0,0 @@
 | 
			
		||||
package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener;
 | 
			
		||||
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterBlock;
 | 
			
		||||
import org.bukkit.event.block.BlockBreakEvent;
 | 
			
		||||
 | 
			
		||||
public class OnBlockBreak {
 | 
			
		||||
 | 
			
		||||
    public static void onBlockBreakEvent(BlockBreakEvent e, LinkedBeaconTeleporterBlock lbtBlock){
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,11 +0,0 @@
 | 
			
		||||
package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener;
 | 
			
		||||
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterItem;
 | 
			
		||||
import org.bukkit.event.block.BlockPlaceEvent;
 | 
			
		||||
 | 
			
		||||
public class OnBlockPlace {
 | 
			
		||||
 | 
			
		||||
    public static void onBlockPlaceEvent(BlockPlaceEvent e, LinkedBeaconTeleporterItem lbtItem){
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,39 +0,0 @@
 | 
			
		||||
package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener;
 | 
			
		||||
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterItem;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
 | 
			
		||||
import org.bukkit.inventory.CraftingInventory;
 | 
			
		||||
import org.bukkit.inventory.InventoryView;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
 | 
			
		||||
public class OnPrepareItemCraftEvent {
 | 
			
		||||
 | 
			
		||||
    public static void onPrepareItemCraftEvent(PrepareItemCraftEvent e){
 | 
			
		||||
        ItemStack[] matrix = e.getInventory().getMatrix();
 | 
			
		||||
 | 
			
		||||
        // Check if one of provided items is already LinkedBeaconTeleporterItem and use first if found
 | 
			
		||||
        LinkedBeaconTeleporterItem lbtItem = null;
 | 
			
		||||
 | 
			
		||||
        /*for (ItemStack item : matrix) {
 | 
			
		||||
            if(item == null) continue;
 | 
			
		||||
            lbtItem = LinkedBeaconTeleporterItem.getFromItemStack(item);
 | 
			
		||||
            if(lbtItem != null) break;
 | 
			
		||||
        }*/
 | 
			
		||||
 | 
			
		||||
        if(lbtItem == null){
 | 
			
		||||
            // If none is found, create new LinkedBeaconTeleporterItem and set as crafting-result
 | 
			
		||||
            ItemStack item = new ItemStack(Material.BEACON);
 | 
			
		||||
            lbtItem = new LinkedBeaconTeleporterItem(item);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Generate ItemStack
 | 
			
		||||
        ItemStack item = lbtItem.toItemStack();
 | 
			
		||||
 | 
			
		||||
        // Exactly 2
 | 
			
		||||
        item.setAmount(2);
 | 
			
		||||
 | 
			
		||||
        // Set as crafting-result
 | 
			
		||||
        e.getInventory().setResult(item);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -2,6 +2,8 @@ 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 org.bukkit.GameMode;
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.block.Block;
 | 
			
		||||
@ -21,9 +23,21 @@ public class OnBlockBreak implements Listener {
 | 
			
		||||
            // Check if this beacon is a LinkedBeaconTeleporter
 | 
			
		||||
            LinkedBeaconTeleporterBlock lbtBlock = LinkedBeaconTeleporterBlock.getFromLocation(loc);
 | 
			
		||||
 | 
			
		||||
            if(lbtBlock != null){
 | 
			
		||||
                eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener.OnBlockBreak.onBlockBreakEvent(e, lbtBlock);
 | 
			
		||||
            }
 | 
			
		||||
            // Ignore if not found
 | 
			
		||||
            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;
 | 
			
		||||
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main;
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterBlock;
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterItem;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.block.Block;
 | 
			
		||||
@ -20,9 +22,11 @@ public class OnBlockPlace implements Listener {
 | 
			
		||||
            // Check if this beacon is a LinkedBeaconTeleporter
 | 
			
		||||
            LinkedBeaconTeleporterItem lbtItem = LinkedBeaconTeleporterItem.getFromItemStack(item);
 | 
			
		||||
 | 
			
		||||
            if(lbtItem != null){
 | 
			
		||||
                eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener.OnBlockPlace.onBlockPlaceEvent(e, lbtItem);
 | 
			
		||||
            }
 | 
			
		||||
            // Ignore if not found
 | 
			
		||||
            if(lbtItem == null) return;
 | 
			
		||||
 | 
			
		||||
            Block block = e.getBlock();
 | 
			
		||||
            LinkedBeaconTeleporterBlock lbtBlock = Main.lbtManager.placeLbtItem(lbtItem, block);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,40 @@
 | 
			
		||||
package eu.ruekov.ruakij.LinkedBeaconTeleporters.listener;
 | 
			
		||||
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main;
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterItem;
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.event.EventHandler;
 | 
			
		||||
import org.bukkit.event.EventPriority;
 | 
			
		||||
import org.bukkit.event.Listener;
 | 
			
		||||
import org.bukkit.event.inventory.CraftItemEvent;
 | 
			
		||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
import org.bukkit.inventory.Recipe;
 | 
			
		||||
 | 
			
		||||
public class OnCraftItemEvent implements Listener {
 | 
			
		||||
 | 
			
		||||
    @EventHandler(priority = EventPriority.LOW)
 | 
			
		||||
    public void onCraftItemEvent(CraftItemEvent e){
 | 
			
		||||
 | 
			
		||||
        Recipe recipe = e.getRecipe();
 | 
			
		||||
        ItemStack itemResult = recipe.getResult();
 | 
			
		||||
 | 
			
		||||
        // Check if it has LinkedBeaconTeleporter-Data
 | 
			
		||||
        LinkedBeaconTeleporterItem lbtItem = Main.lbtManager.getLbtItemFromItemStack(itemResult);
 | 
			
		||||
 | 
			
		||||
        // 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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,82 @@
 | 
			
		||||
package eu.ruekov.ruakij.LinkedBeaconTeleporters.listener;
 | 
			
		||||
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.Function;
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main;
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.customPlayerMoveEvent.CustomPlayerMoveEvent;
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.customPlayerMoveEvent.CustomPlayerMoveEventListener;
 | 
			
		||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterBlock;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.block.Block;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.util.Vector;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
public class OnCustomPlayerMove implements CustomPlayerMoveEventListener {
 | 
			
		||||
 | 
			
		||||
    static HashMap<UUID, LinkedBeaconTeleporterBlock> playerBeaconLocation = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void tick(CustomPlayerMoveEvent e) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void locationChange(CustomPlayerMoveEvent e) {
 | 
			
		||||
 | 
			
		||||
        Player p = e.player();
 | 
			
		||||
        UUID uuid = p.getUniqueId();
 | 
			
		||||
 | 
			
		||||
        // If player found in ignoreList, remove
 | 
			
		||||
        if(playerBeaconLocation.containsKey(uuid))
 | 
			
		||||
            playerBeaconLocation.remove(uuid);
 | 
			
		||||
 | 
			
		||||
        // Check if player is on-top of a beacon
 | 
			
		||||
        Block block = Function.searchForMaterial(
 | 
			
		||||
                p.getLocation().add(0, -1, 0),
 | 
			
		||||
                new Vector(0, -1, 0),
 | 
			
		||||
                Material.BEACON,
 | 
			
		||||
                Function.transparentMaterials
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        // Skip if not found
 | 
			
		||||
        if(block == null) return;
 | 
			
		||||
 | 
			
		||||
        // TODO: Check if beacon is active
 | 
			
		||||
 | 
			
		||||
        // Check if beacon is a LinkedBeaconTeleporter
 | 
			
		||||
        LinkedBeaconTeleporterBlock lbtBlock = Main.lbtManager.getLbtBlockFromLocation(block.getLocation());
 | 
			
		||||
 | 
			
		||||
        // Ignore if not found
 | 
			
		||||
        if(lbtBlock == null) return;
 | 
			
		||||
 | 
			
		||||
        // Check if player should be ignored on this LinkedBeaconTeleporter
 | 
			
		||||
        if(playerBeaconLocation.get(uuid) != null && playerBeaconLocation.get(uuid) == lbtBlock) return;
 | 
			
		||||
 | 
			
		||||
        // Find partnering Beacon
 | 
			
		||||
        List<LinkedBeaconTeleporterBlock> lbtBlocks = Main.lbtManager.getLbtBlocksFromTeleportId(lbtBlock.teleporterId());
 | 
			
		||||
        if(lbtBlocks == null) return;
 | 
			
		||||
 | 
			
		||||
        // Get first partner thats not our current-block
 | 
			
		||||
        LinkedBeaconTeleporterBlock lbtBlockPartner = null;
 | 
			
		||||
        for(LinkedBeaconTeleporterBlock lbtBlockTmp: lbtBlocks){
 | 
			
		||||
            if(lbtBlockTmp != lbtBlocks){
 | 
			
		||||
                lbtBlockPartner = lbtBlockTmp;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if(lbtBlockPartner == null){
 | 
			
		||||
            // No other partner
 | 
			
		||||
        }
 | 
			
		||||
        else{
 | 
			
		||||
            // Set player as ignored on target-LinkedBeaconTeleporter (so he wont trigger the teleport again)
 | 
			
		||||
            playerBeaconLocation.put(uuid, lbtBlockPartner);
 | 
			
		||||
 | 
			
		||||
            // Teleport
 | 
			
		||||
            e.player().teleport(
 | 
			
		||||
                    lbtBlockPartner.block().getLocation().add(0, 1, 0)
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,31 +0,0 @@
 | 
			
		||||
package eu.ruekov.ruakij.LinkedBeaconTeleporters.listener;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.event.EventHandler;
 | 
			
		||||
import org.bukkit.event.EventPriority;
 | 
			
		||||
import org.bukkit.event.Listener;
 | 
			
		||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
 | 
			
		||||
import org.bukkit.inventory.CraftingInventory;
 | 
			
		||||
import org.bukkit.inventory.InventoryView;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
 | 
			
		||||
public class OnPrepareItemCraftEvent implements Listener {
 | 
			
		||||
 | 
			
		||||
    @EventHandler(priority = EventPriority.LOW)
 | 
			
		||||
    public void onPrepareItemCraftEvent(PrepareItemCraftEvent e){
 | 
			
		||||
 | 
			
		||||
        ItemStack[] matrix = e.getInventory().getMatrix();
 | 
			
		||||
 | 
			
		||||
        // Check if 2 beacons are in the crafting-slots
 | 
			
		||||
        int beaconCount = 0;
 | 
			
		||||
        for (ItemStack item : matrix) {
 | 
			
		||||
            if(item == null) continue;
 | 
			
		||||
            if(item.getType() == Material.BEACON)
 | 
			
		||||
                beaconCount++;
 | 
			
		||||
        }
 | 
			
		||||
        if(beaconCount == 2){
 | 
			
		||||
            // Exactly 2 beacons found
 | 
			
		||||
            eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener.OnPrepareItemCraftEvent.onPrepareItemCraftEvent(e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,4 +1,5 @@
 | 
			
		||||
name: ${artifactId}
 | 
			
		||||
version: ${version}
 | 
			
		||||
author: ${author}
 | 
			
		||||
main: ${groupId}.${artifactId}.Main
 | 
			
		||||
main: ${groupId}.${artifactId}.Main
 | 
			
		||||
api-version: 1.16
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user