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

Fixed small bugs #323

Merged
merged 6 commits into from
Jul 21, 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
7 changes: 6 additions & 1 deletion src/main/java/net/tiagofar78/prisonescape/game/Guard.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ private boolean canBuyItem(Buyable item) {
return true;
}

return _itemsBought.get(item.getClass().getSimpleName()) < item.getLimit();
Integer bought = _itemsBought.get(item.getClass().getSimpleName());
if (bought == null) {
bought = 0;
}

return bought < item.getLimit();
}

private void updateItemCount(String itemName, int amount) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/tiagofar78/prisonescape/game/PEGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private void addPlayerToStartedGame(PEPlayer player, Kit kit, Location location,

public void removePlayerFromGame(PEPlayer player) {
player.removeScoreboard();
_bossBar.removePlayer(player.getBukkitPlayer());
player.removeBossBar(_bossBar);
teleportToLeavingLocation(player);
}

Expand Down Expand Up @@ -480,6 +480,7 @@ public void playerEscaped(Prisoner player) {
}

public void arrestPlayer(Prisoner arrested, Guard arrester) {
arrested.allowMovement();
teleportToSolitary(arrested);
arrested.clearInventory();

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/tiagofar78/prisonescape/game/PEPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,13 @@ public void setBossBar(BossBar bossBar) {
}
}

public void removeBossBar(BossBar bossBar) {
Player player = getBukkitPlayer();
if (player != null) {
bossBar.removePlayer(player);
}
}

public void setEffect(PotionEffectType effect, int seconds, int level) {
Player player = Bukkit.getPlayer(getName());
if (player == null || !player.isOnline()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,7 @@ public void checkIfWalkedOverTrap(Location location, PEPlayer player, List<Guard
int locZ = location.getBlockZ();

for (Trap trap : _traps) {
Location trapLocation = trap.getLocation();
int trapX = trapLocation.getBlockX();
int trapY = trapLocation.getBlockY();
int trapZ = trapLocation.getBlockZ();

if (trapX == locX && (trapY - 1 <= locY || locY <= trapY) && trapZ == locZ) {
if (trap.isOnTrap(locX, locY, locZ)) {
trap.triggerTrap(guards, player);
_traps.remove(trap);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class Camera {

private static final int WATCH_CAMERA_DELAY = 3;
private static final int WATCH_CAMERA_DELAY = 10;

private NPC _camera;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,12 @@ public void run() {
}, trapDuration * TICKS_PER_SECOND);
}

public boolean isOnTrap(int x, int y, int z) {
int trapX = _location.getBlockX();
int trapY = _location.getBlockY();
int trapZ = _location.getBlockZ();

return trapX == x && (trapY - 1 <= y && y <= trapY + 1) && trapZ == z;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ private void onInteract(String guardName, String prisonerName) {
}

Prisoner prisoner = (Prisoner) playerPrisoner;
if (prisoner.hasEscaped()) {
return;
}

Guard guard = (Guard) game.getPEPlayer(guardName);

if (prisoner.canBeArrested()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ private void use(String guardName, String prisonerName, int heldItemSlot) {
MessageLanguageManager guardMessages = MessageLanguageManager.getInstanceByPlayer(guardName);

Prisoner prisoner = (Prisoner) playerPrisoner;
if (prisoner.hasEscaped()) {
return;
}

if (prisoner.isWanted()) {
BukkitMessageSender.sendChatMessage(guardName, guardMessages.getAlreadyWantedPlayerMessage());
} else if (prisoner.hasIllegalItems()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ private boolean interactWithPrison(PEGame game, PEPlayer player, Location blockL

int vaultIndex = prison.getVaultIndex(blockLocation);
if (vaultIndex != -1) {
interactWithVault(game, player, prison, vaultIndex, item);
int index = player.convertToInventoryIndex(itemSlot);
interactWithVault(game, player, prison, vaultIndex, item, index);
return false;
}

Expand Down Expand Up @@ -336,7 +337,14 @@ private boolean interactWithPrison(PEGame game, PEPlayer player, Location blockL
return true;
}

private void interactWithVault(PEGame game, PEPlayer player, PrisonBuilding prison, int vaultIndex, Item item) {
private void interactWithVault(
PEGame game,
PEPlayer player,
PrisonBuilding prison,
int vaultIndex,
Item item,
int index
) {
MessageLanguageManager messages = MessageLanguageManager.getInstanceByPlayer(player.getName());

Vault vault = prison.getVault(vaultIndex);
Expand All @@ -347,7 +355,7 @@ private void interactWithVault(PEGame game, PEPlayer player, PrisonBuilding pris
return;
}

policeSearchVault(game, (Guard) player, vault, messages);
policeSearchVault(game, (Guard) player, vault, messages, index);
return;
}

Expand All @@ -359,7 +367,13 @@ private void interactWithVault(PEGame game, PEPlayer player, PrisonBuilding pris
player.openMenu(vault);
}

private void policeSearchVault(PEGame game, Guard guard, Vault vault, MessageLanguageManager messagesPolice) {
private void policeSearchVault(
PEGame game,
Guard guard,
Vault vault,
MessageLanguageManager messagesPolice,
int index
) {
Prisoner vaultOwner = vault.getOwner();
MessageLanguageManager messagesPrisoner = MessageLanguageManager.getInstanceByPlayer(vaultOwner.getName());

Expand All @@ -376,6 +390,7 @@ private void policeSearchVault(PEGame game, Guard guard, Vault vault, MessageLan
BukkitMessageSender.sendChatMessage(guard, messagesPolice.getPoliceNoIllegalItemsFoundMessage());
BukkitMessageSender.sendChatMessage(vaultOwner, messagesPrisoner.getPrisonerNoIllegalItemsFoundMessage());
guard.usedSearch();
guard.removeItemIndex(index);
}

return;
Expand Down
Loading