mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-07 11:20:32 +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.LocationManipulation;
|
||||||
import com.onarandombox.MultiverseCore.api.MVPlugin;
|
import com.onarandombox.MultiverseCore.api.MVPlugin;
|
||||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||||
|
import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
|
||||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||||
import com.onarandombox.MultiverseCore.commands.*;
|
import com.onarandombox.MultiverseCore.commands.*;
|
||||||
import com.onarandombox.MultiverseCore.destination.AnchorDestination;
|
import com.onarandombox.MultiverseCore.destination.AnchorDestination;
|
||||||
@ -169,7 +170,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
|||||||
private SpoutInterface spoutInterface = null;
|
private SpoutInterface spoutInterface = null;
|
||||||
private static final double ALLPAY_VERSION = 3;
|
private static final double ALLPAY_VERSION = 3;
|
||||||
private static final double CH_VERSION = 4;
|
private static final double CH_VERSION = 4;
|
||||||
private MVMessaging messaging;
|
private MultiverseMessaging messaging;
|
||||||
private BlockSafety blockSafety;
|
private BlockSafety blockSafety;
|
||||||
private LocationManipulation locationManipulation;
|
private LocationManipulation locationManipulation;
|
||||||
|
|
||||||
@ -400,7 +401,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public MVMessaging getMessaging() {
|
public MultiverseMessaging getMessaging() {
|
||||||
return this.messaging;
|
return this.messaging;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,9 +46,9 @@ public interface Core {
|
|||||||
* Gets the Multiverse message system. This allows you to send messages
|
* Gets the Multiverse message system. This allows you to send messages
|
||||||
* to users at specified intervals.
|
* 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.
|
* 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;
|
package com.onarandombox.MultiverseCore.commands;
|
||||||
|
|
||||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
import com.onarandombox.MultiverseCore.utils.MVMessaging;
|
import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
|
||||||
import com.pneumaticraft.commandhandler.Command;
|
import com.pneumaticraft.commandhandler.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
@ -24,9 +24,9 @@ public abstract class MultiverseCommand extends Command {
|
|||||||
*/
|
*/
|
||||||
protected MultiverseCore plugin;
|
protected MultiverseCore plugin;
|
||||||
/**
|
/**
|
||||||
* The reference to {@link MVMessaging}.
|
* The reference to {@link MultiverseMessaging}.
|
||||||
*/
|
*/
|
||||||
protected MVMessaging messaging;
|
protected MultiverseMessaging messaging;
|
||||||
|
|
||||||
public MultiverseCommand(MultiverseCore plugin) {
|
public MultiverseCommand(MultiverseCore plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
|
@ -10,14 +10,16 @@ package com.onarandombox.MultiverseCore.utils;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
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 Map<String, Long> sentList;
|
||||||
private int cooldown;
|
private int cooldown;
|
||||||
|
|
||||||
@ -27,35 +29,25 @@ public class MVMessaging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the message-cooldown.
|
* {@inheritDoc}
|
||||||
* @param milliseconds The new message-cooldown in milliseconds.
|
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void setCooldown(int milliseconds) {
|
public void setCooldown(int milliseconds) {
|
||||||
this.cooldown = milliseconds;
|
this.cooldown = milliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message to the specified sender if the cooldown has passed.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @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.
|
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean sendMessage(CommandSender sender, String message, boolean ignoreCooldown) {
|
public boolean sendMessage(CommandSender sender, String message, boolean ignoreCooldown) {
|
||||||
return this.sendMessages(sender, new String[]{ message }, ignoreCooldown);
|
return this.sendMessages(sender, new String[]{ message }, ignoreCooldown);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a group of messages to the specified sender if the cooldown has passed.
|
* {@inheritDoc}
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean sendMessages(CommandSender sender, String[] messages, boolean ignoreCooldown) {
|
public boolean sendMessages(CommandSender sender, String[] messages, boolean ignoreCooldown) {
|
||||||
if (!(sender instanceof Player) || 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.
|
* {@inheritDoc}
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean sendMessages(CommandSender sender, Collection<String> messages, boolean ignoreCooldown) {
|
public boolean sendMessages(CommandSender sender, Collection<String> messages, boolean ignoreCooldown) {
|
||||||
return this.sendMessages(sender, messages.toArray(new String[0]), ignoreCooldown);
|
return this.sendMessages(sender, messages.toArray(new String[0]), ignoreCooldown);
|
||||||
}
|
}
|
||||||
@ -98,9 +84,9 @@ public class MVMessaging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the message-cooldown.
|
* {@inheritDoc}
|
||||||
* @return The message-cooldown.
|
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int getCooldown() {
|
public int getCooldown() {
|
||||||
return cooldown;
|
return cooldown;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user