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

Colored armor to kits #264

Merged
merged 3 commits into from
Jun 17, 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
5 changes: 5 additions & 0 deletions TestServer/plugins/TF_PrisonEscape/languages/english.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Kits:
Prisoner:
ArmorName: "&6Prisoner uniform"
Guard:
ArmorName: "&9Guard uniform"
BossBar:
DayTitle: "&eDay {DAY}"
NightTitle: "&9Night {DAY}"
Expand Down
2 changes: 1 addition & 1 deletion TestServer/server.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Minecraft server properties
#Wed May 22 23:30:13 WEST 2024
#Mon Jun 17 15:38:43 WEST 2024
enable-jmx-monitoring=false
rcon.port=25575
level-seed=
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/net/tiagofar78/prisonescape/kits/Kit.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import java.util.Hashtable;
import java.util.Map.Entry;
Expand All @@ -16,6 +17,10 @@ public abstract class Kit {

protected abstract Hashtable<Integer, Item> getContents();

protected Hashtable<Integer, ItemStack> getVisualContents(MessageLanguageManager messages) {
return new Hashtable<Integer, ItemStack>();
}

public void give(String playerName) {
Player bukkitPlayer = Bukkit.getPlayer(playerName);
if (bukkitPlayer == null || !bukkitPlayer.isOnline()) {
Expand All @@ -30,6 +35,10 @@ public void give(String playerName) {
for (Entry<Integer, Item> entry : getContents().entrySet()) {
inv.setItem(entry.getKey(), entry.getValue().toItemStack(messages));
}

for (Entry<Integer, ItemStack> entry : getVisualContents(messages).entrySet()) {
inv.setItem(entry.getKey(), entry.getValue());
}
}

public void update(String playerName) {
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/net/tiagofar78/prisonescape/kits/PoliceKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
import net.tiagofar78.prisonescape.managers.MessageLanguageManager;

import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta;

import java.util.Hashtable;

Expand All @@ -26,6 +30,10 @@ public class PoliceKit extends Kit {
private static final int MISSIONS_ITEM_INDEX = 7;
private static final int SHOP_ITEM_INDEX = 8;

private static final int CHESTPLATE_INDEX = 38;
private static final int LEGGINGS_INDEX = 37;
private static final int BOOTS_INDEX = 36;

@Override
protected Hashtable<Integer, Item> getContents() {
Hashtable<Integer, Item> items = new Hashtable<>();
Expand All @@ -44,6 +52,29 @@ protected Hashtable<Integer, Item> getContents() {
return items;
}

@Override
public Hashtable<Integer, ItemStack> getVisualContents(MessageLanguageManager messages) {
Hashtable<Integer, ItemStack> items = new Hashtable<>();

String uniformName = messages.getPrisonerUniformName();

items.put(CHESTPLATE_INDEX, createColoredArmor(Material.LEATHER_CHESTPLATE, uniformName));
items.put(LEGGINGS_INDEX, createColoredArmor(Material.LEATHER_LEGGINGS, uniformName));
items.put(BOOTS_INDEX, createColoredArmor(Material.LEATHER_BOOTS, uniformName));

return items;
}

private ItemStack createColoredArmor(Material type, String name) {
ItemStack item = new ItemStack(type);
LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta();
meta.setColor(Color.BLUE);
meta.setDisplayName(name);
item.setItemMeta(meta);

return item;
}

@Override
public void update(String playerName) {
Player bukkitPlayer = Bukkit.getPlayer(playerName);
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/net/tiagofar78/prisonescape/kits/PrisonerKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
import net.tiagofar78.prisonescape.items.CraftingMenuItem;
import net.tiagofar78.prisonescape.items.GlassItem;
import net.tiagofar78.prisonescape.items.Item;
import net.tiagofar78.prisonescape.managers.MessageLanguageManager;

import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta;

import java.util.Hashtable;

Expand All @@ -12,6 +18,10 @@ public class PrisonerKit extends Kit {
private static final int LAST_GLASS_ITEM_INDEX = 35;
private static final int CRAFTING_MENU_INDEX = 8;

private static final int CHESTPLATE_INDEX = 38;
private static final int LEGGINGS_INDEX = 37;
private static final int BOOTS_INDEX = 36;

@Override
public Hashtable<Integer, Item> getContents() {
Hashtable<Integer, Item> items = new Hashtable<>();
Expand All @@ -25,4 +35,27 @@ public Hashtable<Integer, Item> getContents() {

return items;
}

@Override
public Hashtable<Integer, ItemStack> getVisualContents(MessageLanguageManager messages) {
Hashtable<Integer, ItemStack> items = new Hashtable<>();

String uniformName = messages.getPrisonerUniformName();

items.put(CHESTPLATE_INDEX, createColoredArmor(Material.LEATHER_CHESTPLATE, uniformName));
items.put(LEGGINGS_INDEX, createColoredArmor(Material.LEATHER_LEGGINGS, uniformName));
items.put(BOOTS_INDEX, createColoredArmor(Material.LEATHER_BOOTS, uniformName));

return items;
}

private ItemStack createColoredArmor(Material type, String name) {
ItemStack item = new ItemStack(type);
LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta();
meta.setColor(Color.ORANGE);
meta.setDisplayName(name);
item.setItemMeta(meta);

return item;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ private static String getPlayerLanguage(String playerName) {
return ConfigManager.getInstance().getDefaultLanguage();
}

// #######################################
// # Kit #
// #######################################

private String _prisonerUniformName;
private String _guardUniformName;

// #######################################
// # BossBar #
// #######################################
Expand Down Expand Up @@ -219,6 +226,10 @@ private static String getPlayerLanguage(String playerName) {
private MessageLanguageManager(String language) {
YamlConfiguration messages = PEResources.getYamlLanguage(language);

String kitsPath = "Kits.";
_prisonerUniformName = createMessage(messages.getString(kitsPath + "Prisoner.ArmorName"));
_guardUniformName = createMessage(messages.getString(kitsPath + "Guard.ArmorName"));

String bossBarPath = "BossBar.";
_bossBarDayTitle = createMessage(messages.getString(bossBarPath + "DayTitle"));
_bossBarNightTitle = createMessage(messages.getString(bossBarPath + "NightTitle"));
Expand Down Expand Up @@ -389,6 +400,18 @@ private List<String> createMessage(List<String> rawMessage) {
return message;
}

// #######################################
// # Kit #
// #######################################

public String getPrisonerUniformName() {
return _prisonerUniformName;
}

public String getGuardUniformName() {
return _guardUniformName;
}

// #######################################
// # BossBar #
// #######################################
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/languages/english.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Kits:
Prisoner:
ArmorName: "&6Prisoner uniform"
Guard:
ArmorName: "&9Guard uniform"
BossBar:
DayTitle: "&eDay {DAY}"
NightTitle: "&9Night {DAY}"
Expand Down
Loading