diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVPlayerSession.java b/src/main/java/com/onarandombox/MultiverseCore/MVPlayerSession.java index 64056719..40d798ec 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVPlayerSession.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVPlayerSession.java @@ -59,13 +59,14 @@ public class MVPlayerSession { * * @param msg */ - public void message(String msg) { - Long time = (new Date()).getTime(); - if ((time - this.messageLast) > this.config.getInt("messagecooldown", 2000)) { - this.player.sendMessage(msg); - this.messageLast = time; - } - } + // See new class MVMessaging +// public void message(String msg) { +// Long time = (new Date()).getTime(); +// if ((time - this.messageLast) > this.config.getInt("messagecooldown", 2000)) { +// this.player.sendMessage(msg); +// this.messageLast = time; +// } +// } // Commented out bed code, i'll get rid of it soon. // --FF diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVTeleport.java b/src/main/java/com/onarandombox/MultiverseCore/MVTeleport.java index 922e0320..789b6441 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVTeleport.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVTeleport.java @@ -244,12 +244,12 @@ public class MVTeleport { } if (e instanceof Player) { Player p = (Player) e; - p.sendMessage("No safe locations found!"); + this.plugin.getMessaging().sendMessage(p, "No safe locations found!"); this.plugin.log(Level.FINER, "No safe location found for " + p.getName()); } else if (e.getPassenger() instanceof Player) { Player p = (Player) e.getPassenger(); - p.sendMessage("No safe locations found!"); + this.plugin.getMessaging().sendMessage(p, "No safe locations found!"); this.plugin.log(Level.FINER, "No safe location found for " + p.getName()); } this.plugin.log(Level.FINE, "Sorry champ, you're basically trying to teleport into a minefield. I should just kill you now."); @@ -321,12 +321,12 @@ public class MVTeleport { } if (e instanceof Player) { Player p = (Player) e; - p.sendMessage("No safe locations found!"); + this.plugin.getMessaging().sendMessage(p, "No safe locations found!"); this.plugin.log(Level.FINER, "No safe location found for " + p.getName()); } else if (e.getPassenger() instanceof Player) { Player p = (Player) e.getPassenger(); - p.sendMessage("No safe locations found!"); + this.plugin.getMessaging().sendMessage(p, "No safe locations found!"); this.plugin.log(Level.FINER, "No safe location found for " + p.getName()); } this.plugin.log(Level.FINE, "Sorry champ, you're basically trying to teleport into a minefield. I should just kill you now."); diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index dba8a7c4..56f65abe 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -21,6 +21,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import com.onarandombox.MultiverseCore.listeners.*; +import com.onarandombox.utils.*; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.World.Environment; @@ -64,15 +65,6 @@ import com.onarandombox.MultiverseCore.commands.WhoCommand; import com.onarandombox.MultiverseCore.configuration.DefaultConfig; import com.onarandombox.MultiverseCore.configuration.MVConfigMigrator; import com.onarandombox.MultiverseCore.configuration.MVCoreConfigMigrator; -import com.onarandombox.utils.CannonDestination; -import com.onarandombox.utils.DebugLog; -import com.onarandombox.utils.DestinationFactory; -import com.onarandombox.utils.ExactDestination; -import com.onarandombox.utils.PlayerDestination; -import com.onarandombox.utils.PurgeWorlds; -import com.onarandombox.utils.UpdateChecker; -import com.onarandombox.utils.WorldDestination; -import com.onarandombox.utils.WorldManager; import com.pneumaticraft.commandhandler.CommandHandler; public class MultiverseCore extends JavaPlugin implements LoggablePlugin { @@ -116,6 +108,7 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin { private SpoutInterface spoutInterface = null; private double allpayversion = 3; private double chversion = 1; + private MVMessaging messaging; @Override public void onLoad() { @@ -279,6 +272,13 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin { // Setup the Debug option, we'll default to false because this option will not be in the default config. GlobalDebug = this.configMV.getInt("debug", 0); + GlobalDebug = this.configMV.getInt("debug", 0); + this.messaging = new MVMessaging(this); + this.messaging.setCooldown(this.configMV.getInt("messagecooldown", 5000)); + } + + public MVMessaging getMessaging(){ + return this.messaging; } /** @@ -408,7 +408,7 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin { */ @Override public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { - if (this.isEnabled() == false) { + if (!this.isEnabled()) { sender.sendMessage("This plugin is Disabled!"); return true; } diff --git a/src/main/java/com/onarandombox/utils/MVMessaging.java b/src/main/java/com/onarandombox/utils/MVMessaging.java new file mode 100644 index 00000000..d1d1c91f --- /dev/null +++ b/src/main/java/com/onarandombox/utils/MVMessaging.java @@ -0,0 +1,66 @@ +/****************************************************************************** + * Multiverse 2 Copyright (c) the Multiverse Team 2011. * + * Multiverse 2 is licensed under the BSD License. * + * For more information please check the README.md file included * + * with this project. * + ******************************************************************************/ + +package com.onarandombox.utils; + +import com.onarandombox.MultiverseCore.MultiverseCore; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * Multiverse 2 + * + * @author fernferret + */ +public class MVMessaging { + private MultiverseCore plugin; + private Map sentList; + private int cooldown = 0; + + public MVMessaging(MultiverseCore plugin) { + this.plugin = plugin; + this.sentList = new HashMap(); + } + + public void setCooldown(int milliseconds) { + this.cooldown = milliseconds; + } + + /** + * Sends a message to the specified sender if the cooldown has passed. + * @param sender The person/console to send the message to. + * @param message The message to send. + * @param ignoreCooldown If true this message will always be sent. Useful for things like menus + * @return true if the message was sent, false if not. + */ + public boolean sendMessage(CommandSender sender, String message, boolean ignoreCooldown) { + if(!(sender instanceof Player) || ignoreCooldown) { + sender.sendMessage(message); + return true; + } + if(!this.sentList.containsKey(sender.getName())) { + sender.sendMessage(message); + this.sentList.put(sender.getName(), new Date()); + return true; + } else { + if(this.sentList.get(sender.getName()).after(new Date((new Date()).getTime() + this.cooldown))){ + sender.sendMessage(message); + this.sentList.put(sender.getName(), new Date()); + return true; + } + } + return false; + } + + public boolean sendMessage(CommandSender sender, String message) { + return this.sendMessage(sender, message, true); + } +}