Implemented teleporting

master
Ruakij 4 years ago
parent 51e22f2f9e
commit f03a80cf99

@ -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.OnCraftItemEvent;
import eu.ruekov.ruakij.LinkedBeaconTeleporters.listener.OnCustomPlayerMove;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@ -35,6 +37,9 @@ public class Main extends JavaPlugin {
pluginManager.registerEvents(new OnBlockPlace(), this);
pluginManager.registerEvents(new OnCraftItemEvent(), this);
CustomPlayerMoveEventHandler cpmHandler = new CustomPlayerMoveEventHandler(this, true);
cpmHandler.registerListener(new OnCustomPlayerMove());
loadConfigs();
lbtManager = new LinkedBeaconTeleporterManager();

@ -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)
);
}
}
}
Loading…
Cancel
Save