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

Enchant items on select team #322

Merged
merged 1 commit into from
Jul 18, 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
1 change: 1 addition & 0 deletions src/main/java/net/tiagofar78/prisonescape/game/PEGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ public void updateTeamPreference(String playerName, String message, TeamPreferen
BukkitMessageSender.sendChatMessage(player, message);

updatePreferenceTabListDisplay(playerName, teamName);
player.getKit().update(playerName);
}

private void updatePreferenceTabListDisplay(String playerName, String teamName) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/net/tiagofar78/prisonescape/items/Item.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.tiagofar78.prisonescape.items;

import net.tiagofar78.prisonescape.bukkit.BukkitItems;
import net.tiagofar78.prisonescape.game.PEPlayer;
import net.tiagofar78.prisonescape.managers.MessageLanguageManager;

import org.bukkit.Material;
Expand Down Expand Up @@ -44,6 +45,11 @@ public List<String> getLore(MessageLanguageManager messages) {
return messages.getItemLore(getConfigName());
}

public ItemStack toItemStack(PEPlayer player) {
MessageLanguageManager messages = MessageLanguageManager.getInstanceByPlayer(player.getName());
return toItemStack(messages);
}

public ItemStack toItemStack(MessageLanguageManager messages) {
ItemStack item = BukkitItems.createItemStack(getMaterial());
BukkitItems.setName(item, getDisplayName(messages));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package net.tiagofar78.prisonescape.items;

import net.tiagofar78.prisonescape.game.PEGame;
import net.tiagofar78.prisonescape.game.PEPlayer;
import net.tiagofar78.prisonescape.game.TeamPreference;
import net.tiagofar78.prisonescape.game.WaitingPlayer;
import net.tiagofar78.prisonescape.managers.GameManager;
import net.tiagofar78.prisonescape.managers.MessageLanguageManager;

import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;

public class SelectNoneTeamItem extends FunctionalItem {

Expand All @@ -25,6 +29,20 @@ public Material getMaterial() {
return Material.GRAY_WOOL;
}

@Override
public ItemStack toItemStack(PEPlayer player) {
WaitingPlayer waitingPlayer = (WaitingPlayer) player;
ItemStack item = super.toItemStack(player);

if (waitingPlayer.getPreference() == TeamPreference.RANDOM) {
item.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
} else {
item.removeEnchantment(Enchantment.DURABILITY);
}

return item;
}

@Override
public void use(PlayerInteractEvent e) {
PEGame game = GameManager.getGame();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package net.tiagofar78.prisonescape.items;

import net.tiagofar78.prisonescape.game.PEGame;
import net.tiagofar78.prisonescape.game.PEPlayer;
import net.tiagofar78.prisonescape.game.TeamPreference;
import net.tiagofar78.prisonescape.game.WaitingPlayer;
import net.tiagofar78.prisonescape.managers.GameManager;
import net.tiagofar78.prisonescape.managers.MessageLanguageManager;

import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;

public class SelectPoliceTeamItem extends FunctionalItem {

Expand All @@ -25,6 +29,20 @@ public Material getMaterial() {
return Material.BLUE_WOOL;
}

@Override
public ItemStack toItemStack(PEPlayer player) {
WaitingPlayer waitingPlayer = (WaitingPlayer) player;
ItemStack item = super.toItemStack(player);

if (waitingPlayer.getPreference() == TeamPreference.POLICE) {
item.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
} else {
item.removeEnchantment(Enchantment.DURABILITY);
}

return item;
}

@Override
public void use(PlayerInteractEvent e) {
PEGame game = GameManager.getGame();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package net.tiagofar78.prisonescape.items;

import net.tiagofar78.prisonescape.game.PEGame;
import net.tiagofar78.prisonescape.game.PEPlayer;
import net.tiagofar78.prisonescape.game.TeamPreference;
import net.tiagofar78.prisonescape.game.WaitingPlayer;
import net.tiagofar78.prisonescape.managers.GameManager;
import net.tiagofar78.prisonescape.managers.MessageLanguageManager;

import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;

public class SelectPrisonerTeamItem extends FunctionalItem {

Expand All @@ -25,6 +29,20 @@ public Material getMaterial() {
return Material.ORANGE_WOOL;
}

@Override
public ItemStack toItemStack(PEPlayer player) {
WaitingPlayer waitingPlayer = (WaitingPlayer) player;
ItemStack item = super.toItemStack(player);

if (waitingPlayer.getPreference() == TeamPreference.PRISIONERS) {
item.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
} else {
item.removeEnchantment(Enchantment.DURABILITY);
}

return item;
}

@Override
public void use(PlayerInteractEvent e) {
PEGame game = GameManager.getGame();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,55 @@
package net.tiagofar78.prisonescape.kits;

import net.tiagofar78.prisonescape.game.PEGame;
import net.tiagofar78.prisonescape.game.WaitingPlayer;
import net.tiagofar78.prisonescape.items.Item;
import net.tiagofar78.prisonescape.items.SelectNoneTeamItem;
import net.tiagofar78.prisonescape.items.SelectPoliceTeamItem;
import net.tiagofar78.prisonescape.items.SelectPrisonerTeamItem;
import net.tiagofar78.prisonescape.managers.GameManager;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import java.util.Hashtable;

public class TeamSelectorKit extends Kit {

private static final int SELECT_PRISIONER_ITEM_INDEX = 1;
private static final int SELECT_POLICE_ITEM_INDEX = 7;
private static final int SELECT_GUARD_ITEM_INDEX = 7;
private static final int SELECT_NONE_ITEM_INDEX = 4;

@Override
protected Hashtable<Integer, Item> getContents() {
Hashtable<Integer, Item> items = new Hashtable<>();

items.put(SELECT_PRISIONER_ITEM_INDEX, new SelectPrisonerTeamItem());
items.put(SELECT_POLICE_ITEM_INDEX, new SelectPoliceTeamItem());
items.put(SELECT_GUARD_ITEM_INDEX, new SelectPoliceTeamItem());
items.put(SELECT_NONE_ITEM_INDEX, new SelectNoneTeamItem());

return items;
}

@Override
public void update(String playerName) {
Player bukkitPlayer = Bukkit.getPlayer(playerName);
if (bukkitPlayer == null || !bukkitPlayer.isOnline()) {
return;
}

PEGame game = GameManager.getGame();
WaitingPlayer player = (WaitingPlayer) game.getPEPlayer(playerName);

ItemStack selectPrsionerItem = getItemAt(SELECT_PRISIONER_ITEM_INDEX).toItemStack(player);
ItemStack selectGuardItem = getItemAt(SELECT_GUARD_ITEM_INDEX).toItemStack(player);
ItemStack selectNoneItem = getItemAt(SELECT_NONE_ITEM_INDEX).toItemStack(player);

Inventory inv = bukkitPlayer.getInventory();
inv.setItem(SELECT_PRISIONER_ITEM_INDEX, selectPrsionerItem);
inv.setItem(SELECT_GUARD_ITEM_INDEX, selectGuardItem);
inv.setItem(SELECT_NONE_ITEM_INDEX, selectNoneItem);
}

}
Loading