Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Add ability to translate ores and format messages
Browse files Browse the repository at this point in the history
Fixes #2, #3
  • Loading branch information
bendem committed Jan 22, 2014
1 parent aa1d980 commit 8898631
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>be.bendem.OreBroadcast</groupId>
<artifactId>OreBroadcast</artifactId>
<version>1.0.3-BETA</version>
<version>1.1</version>
<packaging>jar</packaging>

<name>OreBroadcast</name>
Expand Down
30 changes: 20 additions & 10 deletions src/main/java/be/bendem/OreBroadcast/BlockBreakListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void onBlockBreak(BlockBreakEvent event) {
plugin.logger.finer("Event duration : " + (System.currentTimeMillis() - timer) + "ms");
}

public final int getVeinSize(Block block) {
private final int getVeinSize(Block block) {
HashSet<Block> vein = new HashSet<Block>();
vein.add(block);
vein = getVein(block, vein);
Expand All @@ -78,7 +78,7 @@ public final int getVeinSize(Block block) {
return vein.size();
}

public final HashSet<Block> getVein(Block block, HashSet<Block> vein) {
private final HashSet<Block> getVein(Block block, HashSet<Block> vein) {
int i, j, k;
for (i = -1; i < 2; ++i) {
for (j = -1; j < 2; ++j) {
Expand All @@ -98,26 +98,36 @@ public final HashSet<Block> getVein(Block block, HashSet<Block> vein) {
return vein;
}

public boolean compare(Block block1, Block block2) {
private boolean compare(Block block1, Block block2) {
return block1.getType().equals(block2.getType())
|| block1.getType() == Material.GLOWING_REDSTONE_ORE && block2.getType() == Material.REDSTONE_ORE
|| block1.getType() == Material.REDSTONE_ORE && block2.getType() == Material.GLOWING_REDSTONE_ORE;
}

public void broadcast(String message) {
private void broadcast(String message) {
for (Player player : plugin.getServer().getOnlinePlayers()) {
if(player.hasPermission("ob.receive")) {
player.sendMessage(message);
}
}
}

public final String format(String msg, String player, String count, String ore, String color, boolean plural) {
return msg
.replace("{player}", ChatFormatter.bold(player))
.replace("{count}", ChatFormatter.bold(count))
.replace("{ore}", ChatFormatter.format(ChatFormatter.bold(ore), ChatColor.valueOf(color)))
.replace("{plural}", plural ? plugin.getConfig().getString("plural", "s") : "");
private final String format(String msg, String player, String count, String ore, String color, boolean plural) {
return colorize(msg
.replace("{player}", player)
.replace("{count}", count)
.replace("{ore}", translateOre(ore, color))
.replace("{plural}", plural ? plugin.getConfig().getString("plural", "s") : ""));
}

private final String translateOre(String ore, String color) {
return "&" + ChatColor.valueOf(color).getChar()
+ plugin.getConfig().getString("ore-translations." + ore, ore)
+ "&" + ChatColor.RESET.getChar();
}

private final String colorize(String msg) {
return ChatColor.translateAlternateColorCodes('&', msg);
}

}
48 changes: 47 additions & 1 deletion src/main/ressources/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# A list of the ores which will be broadcasted when found
ores:
- coal
- iron
Expand All @@ -7,6 +8,9 @@ ores:
- quartz
- diamond
- emerald

# The colors to use to color the ores in the broadcast message.
# See the end of the file for a list of available colors
colors:
coal: dark_gray
iron: gray
Expand All @@ -17,5 +21,47 @@ colors:
diamond: aqua
emerald: green

message: "{player} just found {count} block{plural} of {ore}"
# The message to be broadcasted (you can use the tags {player}, {count}, {plural} and {ore})
# You can use colors by using &colorcode
# Note that the {ore} will be replaced by &colorcode{ore}&reset
# See the end of the file for a list of available color codes
message: "&l{player}&r just found &l{count}&r block{plural} of [&l&k{ore}&r]"
# The text to add when more than one ore is found
# (Will be used by the tag {plural})
plural: s

# The ore translation to use in the message
ore-translations:
coal: coal
iron: iron
gold: gold
lapis: lapis
redstone: redstone
quartz: quartz
diamond: diamond
emerald: emerald

# Colors and color codes available :
# Use the colors for the ore list and the color codes for the message
# black : 0
# dark_blue : 1
# dark_green : 2
# dark_aqua : 3
# dark_red : 4
# dark_purple : 5
# gold : 6
# gray : 7
# dark_gray : 8
# blue : 9
# green : a
# aqua : b
# red : c
# light_purple : d
# yellow : e
# white : f
# magic : k
# bold : l
# strikethrough : m
# underline : n
# italic : o
# reset : r

0 comments on commit 8898631

Please sign in to comment.