Skip to content

Commit

Permalink
Added translation options for Torch name and lore. Switched to Persis…
Browse files Browse the repository at this point in the history
…tendDataHolder for identifying a HaroTorch before placement
  • Loading branch information
TheDutchMC committed Nov 12, 2020
1 parent ffa5495 commit f0b18cb
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pluginVersion = 2.1.4
pluginVersion = 2.1.5
pluginGroup = nl.thedutchmc.harotorch
pluginName = HaroTorch
2 changes: 1 addition & 1 deletion src/main/java/nl/thedutchmc/harotorch/HaroTorch.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void onEnable() {

//Minecraft events
Bukkit.getPluginManager().registerEvents(new BlockBreakEventListener(), this);
Bukkit.getPluginManager().registerEvents(new BlockPlaceEventListener(), this);
Bukkit.getPluginManager().registerEvents(new BlockPlaceEventListener(this), this);
Bukkit.getPluginManager().registerEvents(new CreatureSpawnEventListener(), this);
Bukkit.getPluginManager().registerEvents(new BlockFromToEventListener(), this);
Bukkit.getPluginManager().registerEvents(new BlockExplodeEventListener(), this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package nl.thedutchmc.harotorch.events;

import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;

import net.md_5.bungee.api.ChatColor;
import nl.thedutchmc.harotorch.HaroTorch;
Expand All @@ -14,6 +16,12 @@

public class BlockPlaceEventListener implements Listener {

private HaroTorch plugin;

public BlockPlaceEventListener(HaroTorch plugin) {
this.plugin = plugin;
}

@SuppressWarnings("deprecation")
@EventHandler
public void onBlockPlaceEvent(BlockPlaceEvent event) {
Expand All @@ -22,7 +30,11 @@ public void onBlockPlaceEvent(BlockPlaceEvent event) {

if(!blockPlacing.hasItemMeta()) return;

if(blockPlacing.getItemMeta().getDisplayName().equals(ChatColor.AQUA + "HaroTorch")) {
NamespacedKey key = new NamespacedKey(plugin, "haro_torch");

if(!blockPlacing.getItemMeta().getPersistentDataContainer().has(key, PersistentDataType.INTEGER)) return;

if(blockPlacing.getItemMeta().getPersistentDataContainer().get(key, PersistentDataType.INTEGER).equals(1)) {

Location l = event.getBlock().getLocation();
TorchHandler.addTorch(new Torch(event.getPlayer().getUniqueId(), l));
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/nl/thedutchmc/harotorch/lang/LangHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.apache.commons.io.FileUtils;

import net.md_5.bungee.api.ChatColor;
import nl.thedutchmc.harotorch.HaroTorch;

public class LangHandler {
Expand Down Expand Up @@ -85,7 +86,16 @@ private void readLang(String lang) {
langMap.put(key, value);
}

activeLang= new Language(lang, langMap);
activeLang = new Language(lang, langMap);

//These checks are here because new keys are added over time
if(!activeLang.getLangMessages().containsKey("torchTitle")) {
activeLang.getLangMessages().put("torchTitle", ChatColor.AQUA + "HaroTorch");
}

if(!activeLang.getLangMessages().containsKey("torchLore")) {
activeLang.getLangMessages().put("torchLore", "Blocks mob spawns in a configurable radius");
}
}

private List<String> discover() {
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/nl/thedutchmc/harotorch/torch/TorchHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;

import net.md_5.bungee.api.ChatColor;
import nl.thedutchmc.harotorch.HaroTorch;
import nl.thedutchmc.harotorch.lang.LangHandler;

public class TorchHandler {

private HaroTorch plugin;
private static HaroTorch plugin;

private static HashMap<Location, Torch> torches = new HashMap<>();
private static StorageHandler STORAGE;

public TorchHandler(HaroTorch plugin) {
this.plugin = plugin;
TorchHandler.plugin = plugin;
}

public void setup() {
Expand Down Expand Up @@ -84,14 +87,17 @@ public static Location getLocation(Torch torch) {

public static ItemStack getTorch(int count) {

ItemStack stack = new ItemStack(Material.matchMaterial(HaroTorch.getConfigHandler().torchBlock));
ItemStack stack = new ItemStack(Material.matchMaterial(HaroTorch.getConfigHandler().torchBlock));
ItemMeta meta = stack.getItemMeta();

List<String> lore = new ArrayList<>();
lore.add("Prevent monsters from spawning in a " + HaroTorch.getConfigHandler().torchRange + " block radius");
lore.add(LangHandler.activeLang.getLangMessages().get("torchLore").replaceAll("%TORCH_RADIUS%", String.valueOf(HaroTorch.getConfigHandler().torchRange)));

meta.setLore(lore);
meta.setDisplayName(ChatColor.AQUA + "HaroTorch");
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', LangHandler.activeLang.getLangMessages().get("torchTitle")));

NamespacedKey key = new NamespacedKey(plugin, "haro_torch");
meta.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, 1);

stack.setItemMeta(meta);
stack.addUnsafeEnchantment(Enchantment.MENDING, 1);
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ torchPlaced=Torch placed successfully!
helpMenuTitle=HaroTorch Help Menu
helpHelp=Shows you this page.
helpHighlight=Highlight all nearby torches.
helpGive=Highlight all nearby torches.
helpGive=Gives you a HaroTorch
helpConvert=Convert v1 torches to v2 torches.
helpVersion=Get the HaroTorch and NMS version number.
helpAoe=Show the Area of Effect of all nearby torches using particles
helpAoe=Show the Area of Effect of all nearby torches using particles

#The Torch itself
torchTitle=&bHaroTorch
torchLore=Blocks mob spawns in a %TORCH_RADIUS% block radius!

0 comments on commit f0b18cb

Please sign in to comment.