Skip to content

Commit

Permalink
Added config (pickup sound + i18n).
Browse files Browse the repository at this point in the history
  • Loading branch information
AmauryCarrade committed Nov 3, 2014
1 parent dcaad87 commit 81d046d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/main/java/eu/carrade/amaury/LightHeads/LightHeads.java
Expand Up @@ -31,10 +31,9 @@

public final class LightHeads extends JavaPlugin {


@Override
public void onEnable() {

this.saveDefaultConfig();
}

@Override
Expand All @@ -51,12 +50,12 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
receiver = (Player) sender;
}
else {
sender.sendMessage(ChatColor.RED + "You are not allowed to do that.");
sender.sendMessage(ChatColor.RED + getConfig().getString("i18n.disallowed"));
return true;
}
}
else {
sender.sendMessage(ChatColor.RED + "This can only be executed as a player.");
sender.sendMessage(ChatColor.RED + getConfig().getString("i18n.onlyAsAPlayer"));
return true;
}
}
Expand All @@ -67,12 +66,12 @@ else if(args.length == 1) { // /head <headOwner>
receiver = (Player) sender;
}
else {
sender.sendMessage(ChatColor.RED + "You are not allowed to do that.");
sender.sendMessage(ChatColor.RED + getConfig().getString("i18n.disallowed"));
return true;
}
}
else {
sender.sendMessage(ChatColor.RED + "This can only be executed as a player.");
sender.sendMessage(ChatColor.RED + getConfig().getString("i18n.onlyAsAPlayer"));
return true;
}
}
Expand All @@ -81,12 +80,12 @@ else if(args.length == 1) { // /head <headOwner>
ownerName = args[0];
receiver = getServer().getPlayer(args[1]);
if(receiver == null) {
sender.sendMessage(ChatColor.RED + "The player " + args[1] + " is not online.");
sender.sendMessage(ChatColor.RED + getConfig().getString("i18n.notOnline").replace("{player}", args[1]));
return true;
}
}
else {
sender.sendMessage(ChatColor.RED + "You are not allowed to do that.");
sender.sendMessage(ChatColor.RED + getConfig().getString("i18n.disallowed"));
return true;
}
}
Expand All @@ -99,10 +98,12 @@ else if(args.length == 1) { // /head <headOwner>
if(receiver.getInventory().addItem(head).size() != 0) {
// Inventory was full
receiver.getWorld().dropItem(receiver.getLocation(), head);
sender.sendMessage(ChatColor.GRAY + "Your inventory is full: the head was dropped at your feets.");
sender.sendMessage(ChatColor.GRAY + getConfig().getString("i18n.inventoryFull"));
}
else {
receiver.playSound(receiver.getLocation(), Sound.ITEM_PICKUP, 0.2f, 1.8f);
if(getConfig().getBoolean("pickupSound")) {
receiver.playSound(receiver.getLocation(), Sound.ITEM_PICKUP, 0.2f, 1.8f);
}
}

return true;
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/config.yml
@@ -0,0 +1,12 @@
# Configuration file of the plugin LightHeads

# Play a pickup sound when the head is given and fit in the inventory?
pickupSound: true

# If you want to translate the plugin.
# Don't translate the values {between braces}.
i18n:
disallowed: "You are not allowed to do that."
onlyAsAPlayer: "This can only be executed as a player."
notOnline: "The player {player} is not online."
inventoryFull: "Your inventory is full: the head was dropped at your feets."

0 comments on commit 81d046d

Please sign in to comment.