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

Fix police can drop essential items #169

Merged
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
9 changes: 7 additions & 2 deletions src/main/java/net/tiagofar78/prisonescape/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ public void playerClickInventory(InventoryClickEvent e) {

if (e.getAction() == InventoryAction.DROP_ALL_SLOT || e.getAction() == InventoryAction.DROP_ONE_SLOT) {
int slot = e.getSlot();
game.playerDropItem(player.getName(), slot);
if (game.playerDropItem(player.getName(), slot) == -1) {
e.setCancelled(true);
}
return;
}

Expand Down Expand Up @@ -317,7 +319,10 @@ public void onPlayerDropItem(PlayerDropItemEvent e) {
Player player = e.getPlayer();
int slot = player.getInventory().getHeldItemSlot();

game.playerDropItem(player.getName(), slot);
int return_code = game.playerDropItem(player.getName(), slot);
if (return_code == -1) {
e.setCancelled(true);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ public int playerRejoin(String playerName) {
);
}


return 0;
}

Expand Down Expand Up @@ -698,9 +697,20 @@ private void playerOpenVault(PrisonEscapePlayer player, int vaultIndex, Item ite
vault.open(player);
}

public void playerDropItem(String playerName, int slot) {
/**
* @return 0 if success<br>
* -1 if cannot drop that item
*/
public int playerDropItem(String playerName, int slot) {
PrisonEscapePlayer player = getPrisonEscapePlayer(playerName);
player.removeItem(slot);

int return_code = player.removeItem(slot);
if (return_code == -1) {
MessageLanguageManager messages = MessageLanguageManager.getInstanceByPlayer(playerName);
BukkitMessageSender.sendChatMessage(player, messages.getCannotDropThatItemMessage());
}

return return_code;
}

private void policeSearchVault(PrisonEscapePlayer player, Vault vault, MessageLanguageManager messagesPolice) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,19 @@ public void setItem(int index, Item item) {
BukkitMenu.setItem(_name, index, item);
}

public void removeItem(int slot) {

/**
* @return 0 if success<br>
* -1 if cannot remove item
*/
public int removeItem(int slot) {
int index = BukkitMenu.convertToIndexPlayerInventory(slot);
if (index == -1) {
return;
return -1;
}

_inventory.set(index, new NullItem());
return 0;
}

public boolean hasIllegalItems() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ private static String getPlayerLanguage(String playerName) {
private String _reachedItemLimitMessage;
private String _notEnoughMoneyMessage;
private String _successfullyBoughtItemMessage;
private String _cannotDropThatItemMessage;

// ########################################
// # Announcements #
Expand Down Expand Up @@ -230,6 +231,7 @@ private MessageLanguageManager(String language) {
_reachedItemLimitMessage = createMessage(messages.getString(warningPath + "ReachedItemLimit"));
_notEnoughMoneyMessage = createMessage(messages.getString(warningPath + "NotEnoughMoney"));
_successfullyBoughtItemMessage = createMessage(messages.getString(warningPath + "SuccessfullyBoughtItem"));
_cannotDropThatItemMessage = createMessage(messages.getString(warningPath + "CannotDropThatItem"));

String announcementPath = messagePath + "Announcements.";
_gameStartingAnnouncementMessage = createMessage(messages.getStringList(announcementPath + "GameStarting"));
Expand Down Expand Up @@ -462,6 +464,10 @@ public String getSuccessfullyBoughtItemMessage(int balance) {
return _successfullyBoughtItemMessage.replace("{BALANCE}", Integer.toString(balance));
}

public String getCannotDropThatItemMessage() {
return _cannotDropThatItemMessage;
}

// ########################################
// # Announcements #
// ########################################
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 @@ -108,6 +108,7 @@ Messages:
ReachedItemLimit: "&cSorry, you've already reached the maximum limit for this item."
NotEnoughMoney: "&cYou do not have enough money to buy this item."
SuccessfullyBoughtItem: "&aSuccessfully bought item. Your current balance is: {BALANCE}."
CannotDropThatItem: "&cYou cannot drop that item."
Announcements:
GameStarting:
- "&6==================================="
Expand Down
Loading