From 4537a5caa3a105513bc7658797e0650c7372d6ea Mon Sep 17 00:00:00 2001 From: cnaude Date: Sat, 23 Mar 2013 22:50:17 -0700 Subject: [PATCH] Add configurable messages. --- src/config.yml | 9 ++++++++ src/net/spoothie/chairs/ChairWatcher.java | 4 ++-- src/net/spoothie/chairs/Chairs.java | 17 +++++++++++---- src/net/spoothie/chairs/ChairsCommand.java | 25 ++++++++++++++++------ src/net/spoothie/chairs/EventListener.java | 13 +++++------ src/plugin.yml | 2 +- 6 files changed, 50 insertions(+), 20 deletions(-) diff --git a/src/config.yml b/src/config.yml index 3f36584..0a42264 100644 --- a/src/config.yml +++ b/src/config.yml @@ -49,3 +49,12 @@ sit-effects: healing: amount: 1 max-percent: 100 +messages: + sitting: '&7You are now sitting.' + standing: '&7You are no longer sitting.' + occupied: '&7This seat is occupied by &6%PLAYER%&7!' + reloaded: 'Chairs configuration reloaded.' + no-permission: '&cYou do not have permission to do this!' + enabled: '&7You have enabled chairs for yourself!' + disabled: '&7You have disabled chairs for yourself!' + \ No newline at end of file diff --git a/src/net/spoothie/chairs/ChairWatcher.java b/src/net/spoothie/chairs/ChairWatcher.java index 93b4ca6..0ca1799 100644 --- a/src/net/spoothie/chairs/ChairWatcher.java +++ b/src/net/spoothie/chairs/ChairWatcher.java @@ -5,8 +5,8 @@ package net.spoothie.chairs; import java.util.ArrayList; -import net.minecraft.server.v1_5_R1.DataWatcher; -import net.minecraft.server.v1_5_R1.WatchableObject; +import net.minecraft.server.v1_5_R2.DataWatcher; +import net.minecraft.server.v1_5_R2.WatchableObject; /** diff --git a/src/net/spoothie/chairs/Chairs.java b/src/net/spoothie/chairs/Chairs.java index ff63905..53dd854 100644 --- a/src/net/spoothie/chairs/Chairs.java +++ b/src/net/spoothie/chairs/Chairs.java @@ -6,12 +6,12 @@ import java.util.HashMap; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import net.minecraft.server.v1_5_R1.Packet40EntityMetadata; +import net.minecraft.server.v1_5_R2.Packet40EntityMetadata; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_5_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; @@ -40,6 +40,7 @@ public class Chairs extends JavaPlugin { static final Logger log = Logger.getLogger("Minecraft"); public PluginManager pm; public static ChairsIgnoreList ignoreList; + public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled; @Override public void onEnable() { @@ -113,6 +114,14 @@ public class Chairs extends JavaPlugin { sitEffectInterval = getConfig().getInt("sit-effects.interval",20); sitMaxHealth = getConfig().getInt("sit-effects.healing.max-percent",100); sitHealthPerInterval = getConfig().getInt("sit-effects.healing.amount",1); + + msgSitting = ChatColor.translateAlternateColorCodes('&',getConfig().getString("messages.sitting")); + msgStanding = ChatColor.translateAlternateColorCodes('&',getConfig().getString("messages.standing")); + msgOccupied = ChatColor.translateAlternateColorCodes('&',getConfig().getString("messages.occupied")); + msgNoPerm = ChatColor.translateAlternateColorCodes('&',getConfig().getString("messages.no-permission")); + msgEnabled = ChatColor.translateAlternateColorCodes('&',getConfig().getString("messages.enabled")); + msgDisabled = ChatColor.translateAlternateColorCodes('&',getConfig().getString("messages.disabled")); + msgReloaded = ChatColor.translateAlternateColorCodes('&',getConfig().getString("messages.reloaded")); for (String s : getConfig().getStringList("allowed-blocks")) { String type; @@ -199,8 +208,8 @@ public class Chairs extends JavaPlugin { // Send stand packet to all online players public void sendStand(Player p) { if (sit.containsKey(p.getName())) { - if (notifyplayer) { - p.sendMessage(ChatColor.GRAY + "You are no longer sitting."); + if (notifyplayer && !msgStanding.isEmpty()) { + p.sendMessage(msgStanding); } sit.remove(p.getName()); } diff --git a/src/net/spoothie/chairs/ChairsCommand.java b/src/net/spoothie/chairs/ChairsCommand.java index cc29c66..0f41e1f 100644 --- a/src/net/spoothie/chairs/ChairsCommand.java +++ b/src/net/spoothie/chairs/ChairsCommand.java @@ -4,7 +4,6 @@ */ package net.spoothie.chairs; -import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -34,9 +33,13 @@ public class ChairsCommand implements CommandExecutor { plugin.reloadConfig(); plugin.loadConfig(); plugin.restartEffectsTask(); - sender.sendMessage("Chairs configuration file reloaded."); + if (!plugin.msgReloaded.isEmpty()) { + sender.sendMessage(plugin.msgReloaded); + } } else { - sender.sendMessage(ChatColor.GRAY + "No permission to do this!"); + if (!plugin.msgNoPerm.isEmpty()) { + sender.sendMessage(plugin.msgNoPerm); + } } } if (sender instanceof Player) { @@ -44,17 +47,25 @@ public class ChairsCommand implements CommandExecutor { if (args[0].equalsIgnoreCase("on")) { if (p.hasPermission("chairs.self") || !plugin.permissions) { ignoreList.removePlayer(p.getName()); - p.sendMessage(ChatColor.GRAY + "You have enabled chairs for yourself!"); + if (!plugin.msgEnabled.isEmpty()) { + p.sendMessage(plugin.msgEnabled); + } } else { - p.sendMessage(ChatColor.GRAY + "No permission to do this!"); + if (!plugin.msgNoPerm.isEmpty()) { + p.sendMessage(plugin.msgNoPerm); + } } } if (args[0].equalsIgnoreCase("off")) { if (p.hasPermission("chairs.self") || !plugin.permissions) { ignoreList.addPlayer(p.getName()); - p.sendMessage(ChatColor.GRAY + "You have disabled chairs for yourself!"); + if (!plugin.msgDisabled.isEmpty()) { + p.sendMessage(plugin.msgDisabled); + } } else { - p.sendMessage(ChatColor.GRAY + "No permission to do this!"); + if (!plugin.msgNoPerm.isEmpty()) { + p.sendMessage(plugin.msgNoPerm); + } } } } diff --git a/src/net/spoothie/chairs/EventListener.java b/src/net/spoothie/chairs/EventListener.java index f808777..b8b4cfb 100644 --- a/src/net/spoothie/chairs/EventListener.java +++ b/src/net/spoothie/chairs/EventListener.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Timer; import java.util.TimerTask; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -175,8 +174,8 @@ public class EventListener implements Listener { if (plugin.sit.containsKey(event.getPlayer().getName())) { plugin.sit.remove(player.getName()); event.setCancelled(true); - if (plugin.notifyplayer) { - player.sendMessage(ChatColor.GRAY + "You are no longer sitting."); + if (plugin.notifyplayer && !plugin.msgStanding.isEmpty()) { + player.sendMessage(plugin.msgStanding); } plugin.sendStand(player); return; @@ -237,7 +236,9 @@ public class EventListener implements Listener { if (!plugin.sit.isEmpty()) { for (String s : plugin.sit.keySet()) { if (plugin.sit.get(s).equals(block.getLocation())) { - player.sendMessage(ChatColor.GRAY + "This seat is occupied by " + s + "!"); + if (!plugin.msgOccupied.isEmpty()) { + player.sendMessage(plugin.msgOccupied.replaceAll("%PLAYER%", s)); + } return; } } @@ -272,8 +273,8 @@ public class EventListener implements Listener { player.teleport(plocation.add(0.5D, (sh - 0.5D), 0.5D)); } player.setSneaking(true); - if (plugin.notifyplayer) { - player.sendMessage(ChatColor.GRAY + "You are now sitting."); + if (plugin.notifyplayer && !plugin.msgSitting.isEmpty()) { + player.sendMessage(plugin.msgSitting); } plugin.sit.put(player.getName(), block.getLocation()); event.setUseInteractedBlock(Result.DENY); diff --git a/src/plugin.yml b/src/plugin.yml index 62667de..de2700e 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,5 +1,5 @@ name: Chairs -version: 1.20.0 +version: 1.21.0 description: Let players sit on blocks. authors: - spoothie