Compare commits

...

8 Commits

Author SHA1 Message Date
Ruakij
51c9ee0716 Fix first placed block having a different list leading to new linked-blocks being out-of-sync
(teleport not working and breaking leading to unexpected and undesired states)
2021-05-11 11:03:44 +02:00
Ruakij
e10eaf9b66 Fix system trying to gather non-existent data to display message 2021-05-11 11:02:30 +02:00
Ruakij
686ad312c5 Removed upcasting, check is done on reference-layer anyways 2021-05-11 09:53:57 +02:00
Ruakij
973897cc3e Notify player when teleport could not succeed 2021-05-11 09:53:30 +02:00
Ruakij
1eb472b576 Added check when no safe-location could be found 2021-05-11 09:52:22 +02:00
Ruakij
c41ab95baf Added comments 2021-05-11 09:45:50 +02:00
Ruakij
5e22456f61 Fixed empty-space search not working, because of missing ignore 2021-05-11 09:45:25 +02:00
Ruakij
2bda948c8f Fixed CustomMoveEvent firing all the time instead of only on Block-change 2021-05-11 09:37:10 +02:00
4 changed files with 23 additions and 7 deletions

View File

@ -52,7 +52,9 @@ public class CustomPlayerMoveEventHandler {
if(distance > 0) if(distance > 0)
locationChangeListeners(e); locationChangeListeners(e);
} }
else else if(loc.getBlockX() != oldLoc.getBlockX() ||
loc.getBlockY() != oldLoc.getBlockY() ||
loc.getBlockZ() != oldLoc.getBlockZ())
locationChangeListeners(e); locationChangeListeners(e);
} }

View File

@ -32,7 +32,7 @@ public class LinkedBeaconTeleporterBlock extends LinkedBeaconTeleporter {
e.setExpToDrop(0); e.setExpToDrop(0);
// Notify Player when link was destroyed // Notify Player when link was destroyed
if(this.linkedBeaconTeleporters.size()-1 != 2){ if(this.linkedBeaconTeleporters.size() == 2){
e.getPlayer().sendMessage("§cConnection to Teleporter with id §7"+ this.teleporterId +" §e("+ e.getPlayer().sendMessage("§cConnection to Teleporter with id §7"+ this.teleporterId +" §e("+
(int)((LinkedBeaconTeleporterBlock)this.linkedBeaconTeleporters.get(0)).block.getLocation().distance( (int)((LinkedBeaconTeleporterBlock)this.linkedBeaconTeleporters.get(0)).block.getLocation().distance(
((LinkedBeaconTeleporterBlock)this.linkedBeaconTeleporters.get(1)).block().getLocation() ((LinkedBeaconTeleporterBlock)this.linkedBeaconTeleporters.get(1)).block().getLocation()

View File

@ -56,6 +56,10 @@ public class LinkedBeaconTeleporterItem extends LinkedBeaconTeleporter {
// Block from item // Block from item
LinkedBeaconTeleporterBlock lbtBlock = new LinkedBeaconTeleporterBlock(this.teleporterId(), block); LinkedBeaconTeleporterBlock lbtBlock = new LinkedBeaconTeleporterBlock(this.teleporterId(), block);
// Both objects have different lists (as both are new), overwrite block-list with item-list
// FIXME: This seems like a bad design.. maybe only create the list when necessary? (e.g. keep null if no linked objects found)
lbtBlock.linkedBeaconTeleporters = this.linkedBeaconTeleporters;
// Add to list // Add to list
this.linkedBeaconTeleporters.add(lbtBlock); this.linkedBeaconTeleporters.add(lbtBlock);

View File

@ -69,29 +69,39 @@ public class OnCustomPlayerMove implements CustomPlayerMoveEventListener {
// Get first partner thats not our current-block // Get first partner thats not our current-block
LinkedBeaconTeleporterBlock lbtBlockPartner = null; LinkedBeaconTeleporterBlock lbtBlockPartner = null;
for(LinkedBeaconTeleporter lbtBlockTmp: lbtBlock.linkedBeaconTeleporters()){ for(LinkedBeaconTeleporter lbtBlockTmp: lbtBlock.linkedBeaconTeleporters()){
// Upcast as linked-Teleporters are only blocks anyways if(lbtBlockTmp != lbtBlock){
if((LinkedBeaconTeleporterBlock)lbtBlockTmp != lbtBlock){
lbtBlockPartner = (LinkedBeaconTeleporterBlock)lbtBlockTmp; lbtBlockPartner = (LinkedBeaconTeleporterBlock)lbtBlockTmp;
break; break;
} }
} }
if(lbtBlockPartner == null){ if(lbtBlockPartner == null){
// No other partner // No other partner
p.sendMessage("§cNo linked beacon found with id §7"+ lbtBlock.teleporterId());
// Set player as ignored on this LinkedBeaconTeleporter (so he wont trigger the checks again) // Set player as ignored on this LinkedBeaconTeleporter (so he wont trigger the checks again)
playerBeaconLocation.put(uuid, lbtBlock); playerBeaconLocation.put(uuid, lbtBlock);
} }
else{ else{
// Set player as ignored on target-LinkedBeaconTeleporter (so he wont trigger the teleport again) // TODO: Check if beacon is active
playerBeaconLocation.put(uuid, lbtBlockPartner);
// Get safe-location on top of other beacon // Get safe-location on top of other beacon
Block safeBlock = Function.searchForMaterial( Block safeBlock = Function.searchForMaterial(
lbtBlockPartner.block().getLocation().add(0, 1, 0), lbtBlockPartner.block().getLocation().add(0, 1, 0),
new Vector(0, 1, 0), new Vector(0, 1, 0),
Material.AIR Material.AIR,
Function.transparentMaterials
); );
if(safeBlock == null){
// No safe location found
p.sendMessage("§cNo safe-location found at target teleporter");
return;
}
// TODO: Check if there is enough space for a player
// Set player as ignored on target-LinkedBeaconTeleporter (so he wont trigger the teleport again)
playerBeaconLocation.put(uuid, lbtBlockPartner);
// Teleport // Teleport
e.player().teleport( e.player().teleport(
safeBlock.getLocation().add(0.5, 0, 0.5) safeBlock.getLocation().add(0.5, 0, 0.5)