Skip to content

Commit

Permalink
Merge pull request #283 from TiagoFar78/fixCamerasBug
Browse files Browse the repository at this point in the history
Fixed bug where players in cameras could use gm 3
  • Loading branch information
iquelli authored Jun 25, 2024
2 parents 2d80163 + 9082424 commit ed0a569
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions TestServer/plugins/TF_PrisonEscape/languages/english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ Messages:
CannotPlaceTrap: "&cYou cannot place a trap there"
NoCamerasPlaced: "&cThere aren't cameras placed. Buy some from the shop."
SneakToLeaveCamera: "&eSneak to leave the camera"
CantJoinCameraSneaking: "&cYou cannot view cameras while sneaking."
SoundDetectorPlaced: "&aSound detector placed sucessfully. Check if there are players walking by in the sidebar."
InvalidSoundDetectorLoc: "&cSound detector can not be placed here. &eTry placing it on directly on the ground."
TradeAlreadyAccepted: "&aYou already accepted the trade, wait for your friend to accept."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.trait.SkinTrait;
import net.tiagofar78.prisonescape.PrisonEscape;
import net.tiagofar78.prisonescape.game.Guard;
import net.tiagofar78.prisonescape.managers.ConfigManager;

Expand All @@ -14,6 +15,8 @@

public class Camera {

private static final int WATCH_CAMERA_DELAY = 3;

private NPC _camera;

public Camera(Location location) {
Expand All @@ -23,7 +26,15 @@ public Camera(Location location) {
public void addWatcher(Guard player) {
Player bukkitPlayer = Bukkit.getPlayer(player.getName());
bukkitPlayer.setGameMode(GameMode.SPECTATOR);
bukkitPlayer.setSpectatorTarget(_camera.getEntity());

bukkitPlayer.teleport(_camera.getStoredLocation());
Bukkit.getScheduler().runTaskLater(PrisonEscape.getPrisonEscape(), new Runnable() {

@Override
public void run() {
bukkitPlayer.setSpectatorTarget(_camera.getEntity());
}
}, WATCH_CAMERA_DELAY);
}

public void delete() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public void use(PlayerInteractEvent e) {
_currentCameraIndex = _currentCameraIndex + 1 == cameras.size() ? 0 : _currentCameraIndex + 1;
guard.getKit().update(playerName);
} else if (action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) {
if (guard.isSneaking()) {
BukkitMessageSender.sendChatMessage(guard, messages.getCantJoinCameraSneakingMessage());
return;
}

Location loc = e.getPlayer().getLocation();

cameras.get(_currentCameraIndex).addWatcher(guard);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ private static String getPlayerLanguage(String playerName) {
private String _cannotPlaceTrapMessage;
private String _noCamerasPlacedMessage;
private String _sneakToLeaveCameraMessage;
private String _cantJoinCameraSneakingMessage;
private String _soundDetectorPlacedMessage;
private String _invalidSoundDetectorLocMessage;
private String _tradeAlreadyAcceptedMessage;
Expand Down Expand Up @@ -336,6 +337,7 @@ private MessageLanguageManager(String language) {
_cannotPlaceTrapMessage = createMessage(messages.getString(warningPath + "CannotPlaceTrap"));
_noCamerasPlacedMessage = createMessage(messages.getString(warningPath + "NoCamerasPlaced"));
_sneakToLeaveCameraMessage = createMessage(messages.getString(warningPath + "SneakToLeaveCamera"));
_cantJoinCameraSneakingMessage = createMessage(messages.getString(warningPath + "CantJoinCameraSneaking"));
_soundDetectorPlacedMessage = createMessage(messages.getString(warningPath + "SoundDetectorPlaced"));
_invalidSoundDetectorLocMessage = createMessage(messages.getString(warningPath + "InvalidSoundDetectorLoc"));
_tradeAlreadyAcceptedMessage = createMessage(messages.getString(warningPath + "TradeAlreadyAccepted"));
Expand Down Expand Up @@ -716,6 +718,10 @@ public String getSneakToLeaveCameraMessage() {
return _sneakToLeaveCameraMessage;
}

public String getCantJoinCameraSneakingMessage() {
return _cantJoinCameraSneakingMessage;
}

public String getSoundDetectorPlacedMessage() {
return _soundDetectorPlacedMessage;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/languages/english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ Messages:
CannotPlaceTrap: "&cYou cannot place a trap there"
NoCamerasPlaced: "&cThere aren't cameras placed. Buy some from the shop."
SneakToLeaveCamera: "&eSneak to leave the camera"
CantJoinCameraSneaking: "&cYou cannot view cameras while sneaking."
SoundDetectorPlaced: "&aSound detector placed sucessfully. Check if there are players walking by in the sidebar."
InvalidSoundDetectorLoc: "&cSound detector can not be placed here. &eTry placing it on directly on the ground."
TradeAlreadyAccepted: "&aYou already accepted the trade, wait for your friend to accept."
Expand Down

0 comments on commit ed0a569

Please sign in to comment.