mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-07 03:11:02 +01:00
(Re)designed MVMessaging for extension.
This commit is contained in:
parent
ee715b13b0
commit
da6e6145f2
@ -14,6 +14,7 @@ import com.onarandombox.MultiverseCore.api.Core;
|
||||
import com.onarandombox.MultiverseCore.api.LocationManipulation;
|
||||
import com.onarandombox.MultiverseCore.api.MVPlugin;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commands.*;
|
||||
import com.onarandombox.MultiverseCore.destination.AnchorDestination;
|
||||
@ -169,7 +170,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
private SpoutInterface spoutInterface = null;
|
||||
private static final double ALLPAY_VERSION = 3;
|
||||
private static final double CH_VERSION = 4;
|
||||
private MVMessaging messaging;
|
||||
private MultiverseMessaging messaging;
|
||||
private BlockSafety blockSafety;
|
||||
private LocationManipulation locationManipulation;
|
||||
|
||||
@ -400,7 +401,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public MVMessaging getMessaging() {
|
||||
public MultiverseMessaging getMessaging() {
|
||||
return this.messaging;
|
||||
}
|
||||
|
||||
|
@ -46,9 +46,9 @@ public interface Core {
|
||||
* Gets the Multiverse message system. This allows you to send messages
|
||||
* to users at specified intervals.
|
||||
*
|
||||
* @return The loaded {@link MVMessaging}.
|
||||
* @return The loaded {@link MultiverseMessaging}.
|
||||
*/
|
||||
MVMessaging getMessaging();
|
||||
MultiverseMessaging getMessaging();
|
||||
|
||||
/**
|
||||
* Gets the {@link MVPlayerSession} for the given player.
|
||||
|
@ -0,0 +1,56 @@
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Multiverse-messaging.
|
||||
*/
|
||||
public interface MultiverseMessaging {
|
||||
/**
|
||||
* Sets the message-cooldown.
|
||||
* @param milliseconds The new message-cooldown in milliseconds.
|
||||
*/
|
||||
void setCooldown(int 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.
|
||||
*/
|
||||
boolean sendMessage(CommandSender sender, String message, boolean ignoreCooldown);
|
||||
|
||||
/**
|
||||
* Sends a group of messages to the specified sender if the cooldown has passed.
|
||||
* This method is needed, since sending many messages in quick succession would violate
|
||||
* the cooldown.
|
||||
*
|
||||
* @param sender The person/console to send the message to.
|
||||
* @param messages The messages to send.
|
||||
* @param ignoreCooldown If true these messages will always be sent. Useful for things like menus
|
||||
* @return true if the message was sent, false if not.
|
||||
*/
|
||||
boolean sendMessages(CommandSender sender, String[] messages, boolean ignoreCooldown);
|
||||
|
||||
/**
|
||||
* Sends a group of messages to the specified sender if the cooldown has passed.
|
||||
* This method is needed, since sending many messages in quick succession would violate
|
||||
* the cooldown.
|
||||
*
|
||||
* @param sender The person/console to send the message to.
|
||||
* @param messages The messages to send.
|
||||
* @param ignoreCooldown If true these messages will always be sent. Useful for things like menus
|
||||
* @return true if the message was sent, false if not.
|
||||
*/
|
||||
boolean sendMessages(CommandSender sender, Collection<String> messages, boolean ignoreCooldown);
|
||||
|
||||
/**
|
||||
* Gets the message-cooldown.
|
||||
* @return The message-cooldown.
|
||||
*/
|
||||
int getCooldown();
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.utils.MVMessaging;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
|
||||
import com.pneumaticraft.commandhandler.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@ -24,9 +24,9 @@ public abstract class MultiverseCommand extends Command {
|
||||
*/
|
||||
protected MultiverseCore plugin;
|
||||
/**
|
||||
* The reference to {@link MVMessaging}.
|
||||
* The reference to {@link MultiverseMessaging}.
|
||||
*/
|
||||
protected MVMessaging messaging;
|
||||
protected MultiverseMessaging messaging;
|
||||
|
||||
public MultiverseCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
|
@ -10,14 +10,16 @@ package com.onarandombox.MultiverseCore.utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Utility-class for messaging.
|
||||
* The default-implementation of {@link MultiverseMessaging}.
|
||||
*/
|
||||
public class MVMessaging {
|
||||
public class MVMessaging implements MultiverseMessaging {
|
||||
private Map<String, Long> sentList;
|
||||
private int cooldown;
|
||||
|
||||
@ -27,35 +29,25 @@ public class MVMessaging {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the message-cooldown.
|
||||
* @param milliseconds The new message-cooldown in milliseconds.
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
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.
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean sendMessage(CommandSender sender, String message, boolean ignoreCooldown) {
|
||||
return this.sendMessages(sender, new String[]{ message }, ignoreCooldown);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a group of messages to the specified sender if the cooldown has passed.
|
||||
* This method is needed, since sending many messages in quick succession would violate
|
||||
* the cooldown.
|
||||
*
|
||||
* @param sender The person/console to send the message to.
|
||||
* @param messages The messages to send.
|
||||
* @param ignoreCooldown If true these messages will always be sent. Useful for things like menus
|
||||
* @return true if the message was sent, false if not.
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean sendMessages(CommandSender sender, String[] messages, boolean ignoreCooldown) {
|
||||
if (!(sender instanceof Player) || ignoreCooldown) {
|
||||
|
||||
@ -78,15 +70,9 @@ public class MVMessaging {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a group of messages to the specified sender if the cooldown has passed.
|
||||
* This method is needed, since sending many messages in quick succession would violate
|
||||
* the cooldown.
|
||||
*
|
||||
* @param sender The person/console to send the message to.
|
||||
* @param messages The messages to send.
|
||||
* @param ignoreCooldown If true these messages will always be sent. Useful for things like menus
|
||||
* @return true if the message was sent, false if not.
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean sendMessages(CommandSender sender, Collection<String> messages, boolean ignoreCooldown) {
|
||||
return this.sendMessages(sender, messages.toArray(new String[0]), ignoreCooldown);
|
||||
}
|
||||
@ -98,9 +84,9 @@ public class MVMessaging {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message-cooldown.
|
||||
* @return The message-cooldown.
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getCooldown() {
|
||||
return cooldown;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user