Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prison teleports implemented #14

Merged
merged 2 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import org.bukkit.entity.Player;

import net.tiagofar78.prisonescape.PrisonEscape;
import net.tiagofar78.prisonescape.game.phases.Finished;
import net.tiagofar78.prisonescape.game.phases.Ongoing;
import net.tiagofar78.prisonescape.game.phases.Phase;
import net.tiagofar78.prisonescape.game.phases.Waiting;
import net.tiagofar78.prisonescape.game.prisonbuilding.PrisonBuilding;
import net.tiagofar78.prisonescape.game.prisonbuilding.PrisonEscapeLocation;
import net.tiagofar78.prisonescape.managers.ConfigManager;
import net.tiagofar78.prisonescape.managers.TeleportManager;

public class PrisonEscapeGame {

Expand Down Expand Up @@ -202,7 +202,7 @@ public void playerEscaped(String playerName) {
}
}

public void playerMove(String playerName, Location loc) {
public void playerMove(String playerName, PrisonEscapeLocation loc) {
PrisonEscapePlayer player = getPrisonEscapePlayer(playerName);
if (player == null) {
return;
Expand Down Expand Up @@ -256,7 +256,7 @@ else if (item == PrisonEscapeItem.SEARCH) {
// ########################################

private void arrestPlayer(PrisonEscapePlayer arrested, PrisonEscapePlayer arrester) {
_prison.sendPlayerToSolitary(arrested);
TeleportManager.teleport(arrested, _prison.getSolitaryLocation());

// TODO warn players

Expand All @@ -273,10 +273,11 @@ public void run() {
// TODO warn arrested

if (_dayPeriod == DayPeriod.DAY) {
_prison.takePlayerFromSolitary(arrested);
TeleportManager.teleport(arrested, _prison.getSolitaryExitLocation());
}
else if (_dayPeriod == DayPeriod.NIGHT) {
_prison.sendPlayerToCell(arrested);
int playerIndex = _prisionersTeam.getPlayerIndex(arrested);
TeleportManager.teleport(arrested, _prison.getPlayerCellLocation(playerIndex));
}
}
}, TICKS_PER_SECOND * _settings.getSecondsInSolitary());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ public void addMember(PrisonEscapePlayer player) {
_players.add(player);
}

public int getPlayerIndex(PrisonEscapePlayer player) {
for (int i = 0; i < _players.size(); i++) {
if (_players.get(i).equals(player)) {
return i;
}
}
return -1;
}

public boolean isOnTeam(PrisonEscapePlayer player) {
return _players.contains(player);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,95 @@
package net.tiagofar78.prisonescape.game.prisonbuilding;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import org.bukkit.Location;
import java.util.Map.Entry;

import net.tiagofar78.prisonescape.game.PrisonEscapeItem;
import net.tiagofar78.prisonescape.game.PrisonEscapePlayer;
import net.tiagofar78.prisonescape.managers.ConfigManager;

public class PrisonBuilding {

private PrisonEscapeLocation _prisonTopLeftCorner;
private PrisonEscapeLocation _prisonBottomRightCorner;
private List<PrisonEscapeLocation> _prisionersSpawnLocations;
private List<PrisonEscapeLocation> _policeSpawnLocations;
private PrisonEscapeLocation _solitaryLocation;
private PrisonEscapeLocation _solitaryExitLocation;
private Hashtable<PrisonEscapeLocation, PrisonEscapeLocation> _prisionersSecretPassageLocations;
private Hashtable<PrisonEscapeLocation, PrisonEscapeLocation> _policeSecretPassageLocations;

private List<Chest> _chests;
private List<Location> _metalDetectorsLocations;
private List<PrisonEscapeLocation> _metalDetectorsLocations;

public boolean isOutsidePrison(Location loc) {
return true;
public PrisonBuilding(PrisonEscapeLocation reference) {
ConfigManager config = ConfigManager.getInstance();

_prisonTopLeftCorner = addReferenceLocation(reference, config.getPrisonTopLeftCornerLocation());
_prisonBottomRightCorner = addReferenceLocation(reference, config.getPrisonBottomRightCornerLocation());

_prisionersSpawnLocations = new ArrayList<>();
for (PrisonEscapeLocation loc : config.getPrisionersSpawnLocations()) {
_prisionersSpawnLocations.add(addReferenceLocation(reference, loc));
}

_policeSpawnLocations = new ArrayList<>();
for (PrisonEscapeLocation loc : config.getPoliceSpawnLocations()) {
_policeSpawnLocations.add(addReferenceLocation(reference, loc));
}

_solitaryLocation = addReferenceLocation(reference, config.getSolitaryLocation());
_solitaryExitLocation = addReferenceLocation(reference, config.getSolitaryExitLocation());

_prisionersSecretPassageLocations = new Hashtable<>();
for (Entry<PrisonEscapeLocation, PrisonEscapeLocation> entry : config.getPrisionersSecretPassageLocations().entrySet()) {
_prisionersSecretPassageLocations.put(addReferenceLocation(reference, entry.getKey()),
addReferenceLocation(reference, entry.getValue()));
}

_policeSecretPassageLocations = new Hashtable<>();
for (Entry<PrisonEscapeLocation, PrisonEscapeLocation> entry : config.getPoliceSecretPassageLocations().entrySet()) {
_policeSecretPassageLocations.put(addReferenceLocation(reference, entry.getKey()),
addReferenceLocation(reference, entry.getValue()));
}
}

public void sendPlayerToSolitary(PrisonEscapePlayer player) {

private PrisonEscapeLocation addReferenceLocation(PrisonEscapeLocation reference, PrisonEscapeLocation loc) {
return new PrisonEscapeLocation(loc.getX() + reference.getX(),
loc.getY() + reference.getX(),
loc.getZ() + reference.getZ());
}

public void sendPlayerToCell(PrisonEscapePlayer player) {

public boolean isOutsidePrison(PrisonEscapeLocation loc) {
return loc.getX() > _prisonTopLeftCorner.getX() || _prisonBottomRightCorner.getX() < loc.getX() ||
loc.getY() > _prisonTopLeftCorner.getY() || _prisonBottomRightCorner.getY() < loc.getY() ||
loc.getZ() > _prisonTopLeftCorner.getZ() || _prisonBottomRightCorner.getZ() < loc.getZ();
}

public PrisonEscapeLocation getPoliceSpawnLocation(int index) {
return _policeSpawnLocations.get(index);
}

public PrisonEscapeLocation getPlayerCellLocation(int index) {
return _prisionersSpawnLocations.get(index);
}

public void takePlayerFromSolitary(PrisonEscapePlayer player) {
// TODO should just send the player to the front of the solitary door and anything else.
public PrisonEscapeLocation getSolitaryLocation() {
return _solitaryLocation;
}

public PrisonEscapeLocation getSolitaryExitLocation() {
return _solitaryExitLocation;
}

public PrisonEscapeLocation getSecretPassageDestinationLocation(PrisonEscapeLocation entranceBlock, boolean isPrisioner) {
Hashtable<PrisonEscapeLocation, PrisonEscapeLocation> secretPassageLocations =
isPrisioner ? _prisionersSecretPassageLocations : _policeSecretPassageLocations;

return secretPassageLocations.get(entranceBlock);
}

public boolean checkIfMetalDetectorTriggered(Location location, List<PrisonEscapeItem> playerItems) {
public boolean checkIfMetalDetectorTriggered(PrisonEscapeLocation location, List<PrisonEscapeItem> playerItems) {
if (_metalDetectorsLocations.contains(location)) {
for (PrisonEscapeItem item : playerItems) {
if (item.isMetal()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package net.tiagofar78.prisonescape.managers;

import java.util.Hashtable;
import java.util.List;

import net.tiagofar78.prisonescape.game.prisonbuilding.PrisonEscapeLocation;

public class ConfigManager {

private static ConfigManager instance = new ConfigManager();
Expand Down Expand Up @@ -33,4 +36,41 @@ public String getWorldName() {
public List<String> getAvailableLanguages() {
return null; // TODO
}

@Deprecated
public PrisonEscapeLocation getReferenceBlock() {
return null; // TODO
}

public PrisonEscapeLocation getPrisonTopLeftCornerLocation() {
return null; // TODO
}

public PrisonEscapeLocation getPrisonBottomRightCornerLocation() {
return null; // TODO
}

public List<PrisonEscapeLocation> getPrisionersSpawnLocations() {
return null; // TODO
}

public List<PrisonEscapeLocation> getPoliceSpawnLocations() {
return null; // TODO
}

public PrisonEscapeLocation getSolitaryLocation() {
return null; // TODO
}

public PrisonEscapeLocation getSolitaryExitLocation() {
return null; // TODO
}

public Hashtable<PrisonEscapeLocation, PrisonEscapeLocation> getPrisionersSecretPassageLocations() {
return null; // TODO
}

public Hashtable<PrisonEscapeLocation, PrisonEscapeLocation> getPoliceSecretPassageLocations() {
return null; // TODO
}
}