Skip to content

Commit

Permalink
added search item behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
TiagoFar78 committed Apr 11, 2024
1 parent 3c06ca9 commit 1e3ef92
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,32 @@ public void policeHandcuffedPrisioner(String policeName, String prisionerName) {
}
}

public void policeInspectedPrisioner(String policeName, String prisionerName) {
PrisonEscapePlayer police = getPrisonEscapePlayer(policeName);
PrisonEscapePlayer prisioner = getPrisonEscapePlayer(prisionerName);
if (police == null || prisioner == null) {
return;
}

if (_phase.isClockStopped()) {
return;
}

if (!_prisionersTeam.isOnTeam(prisioner) || !_policeTeam.isOnTeam(police)) {
return;
}

if (prisioner.hasIllegalItems()) {
prisioner.setWanted();
} else {
MessageLanguageManager prisionerMessages = MessageLanguageManager.getInstanceByPlayer(prisionerName);
BukkitMessageSender.sendChatMessage(prisionerName, prisionerMessages.getPrisionerInspectedMessage());

MessageLanguageManager policeMessages = MessageLanguageManager.getInstanceByPlayer(policeName);
BukkitMessageSender.sendChatMessage(policeName, policeMessages.getPoliceInspectedMessage(prisionerName));
}
}

// ########################################
// # Util #
// ########################################
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/net/tiagofar78/prisonescape/items/SearchItem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package net.tiagofar78.prisonescape.items;

import net.tiagofar78.prisonescape.game.PrisonEscapeGame;
import net.tiagofar78.prisonescape.managers.GameManager;

import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerInteractEntityEvent;

public class SearchItem extends FunctionalItem {
Expand All @@ -22,7 +27,17 @@ public Material getMaterial() {

@Override
public void use(PlayerInteractEntityEvent e) {
// TODO add search interaction to player
PrisonEscapeGame game = GameManager.getGame();
if (game == null) {
return;
}

Entity prisioner = e.getRightClicked();
if (!(prisioner instanceof Player)) {
return;
}

game.policeInspectedPrisioner(e.getPlayer().getName(), prisioner.getName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ private static String getPlayerLanguage(String playerName) {
private String _chestAlreadyOpenedMessage;
private String _fullInventoryMessage;
private String _notWantedPlayerMessage;
private String _policeInspectedMessage;
private String _prisionerInspectedMessage;

// ########################################
// # Announcements #
Expand Down Expand Up @@ -221,6 +223,8 @@ private MessageLanguageManager(String language) {
_chestAlreadyOpenedMessage = createMessage(messages.getString(warningPath + "ChestAlreadyOpened"));
_fullInventoryMessage = createMessage(messages.getString(warningPath + "FullInventory"));
_notWantedPlayerMessage = createMessage(messages.getString(warningPath + "NotWantedPlayer"));
_policeInspectedMessage = createMessage(messages.getString(warningPath + "PoliceInspected"));
_prisionerInspectedMessage = createMessage(messages.getString(warningPath + "PrisionerInspected"));

String announcementPath = messagePath + "Announcements.";
_gameStartingAnnouncementMessage = createMessage(messages.getStringList(announcementPath + "GameStarting"));
Expand Down Expand Up @@ -438,6 +442,14 @@ public String getNotWantedPlayerMessage() {
return _notWantedPlayerMessage;
}

public String getPoliceInspectedMessage(String playerName) {
return _policeInspectedMessage.replace("{PLAYER}", playerName);
}

public String getPrisionerInspectedMessage() {
return _prisionerInspectedMessage;
}

// ########################################
// # Announcements #
// ########################################
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/languages/english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ Messages:
ChestAlreadyOpened: "&eSomeone is accessing that container already."
FullInventory: "&cYour inventory is full."
NotWantedPlayer: "&cYou can only send to solitary wanted players."
PrisionerInspected: "&aA police inspected your inventory, but no illegal items were found."
PoliceInspected: "&a{PLAYER} don't have any illegal items."
Announcements:
GameStarting:
- "&6==================================="
Expand Down

0 comments on commit 1e3ef92

Please sign in to comment.