mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-21 18:15:26 +01:00
Remove old non-async chat event and its config option.
This commit is contained in:
parent
035f3644ad
commit
64d9f0797f
@ -77,11 +77,9 @@ import com.onarandombox.MultiverseCore.destination.PlayerDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.WorldDestination;
|
||||
import com.onarandombox.MultiverseCore.event.MVDebugModeEvent;
|
||||
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVAsyncPlayerChatListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVChatListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVMapListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPlayerChatListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPortalListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
|
||||
@ -220,7 +218,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
private final MVWeatherListener weatherListener = new MVWeatherListener(this);
|
||||
private final MVPortalListener portalListener = new MVPortalListener(this);
|
||||
private final MVWorldListener worldListener = new MVWorldListener(this);
|
||||
private MVChatListener chatListener;
|
||||
private MVChatListener chatListener = new MVChatListener(this, this.playerListener);
|
||||
|
||||
// HashMap to contain information relating to the Players.
|
||||
private HashMap<String, MVPlayerSession> playerSessions;
|
||||
@ -318,17 +316,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
// A test that had no worlds loaded was being run. This should never happen in production
|
||||
}
|
||||
this.saveMVConfig();
|
||||
// Register async or sync player chat according to config
|
||||
try {
|
||||
Class.forName("org.bukkit.event.player.AsyncPlayerChatEvent");
|
||||
} catch (ClassNotFoundException e) {
|
||||
getMVConfig().setUseAsyncChat(false);
|
||||
}
|
||||
if (getMVConfig().getUseAsyncChat()) {
|
||||
this.chatListener = new MVAsyncPlayerChatListener(this, this.playerListener);
|
||||
} else {
|
||||
this.chatListener = new MVPlayerChatListener(this, this.playerListener);
|
||||
}
|
||||
getServer().getPluginManager().registerEvents(this.chatListener, this);
|
||||
|
||||
this.initializeBuscript();
|
||||
@ -380,6 +367,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
private void registerEvents() {
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvents(this.playerListener, this);
|
||||
pm.registerEvents(this.chatListener, this);
|
||||
pm.registerEvents(this.entityListener, this);
|
||||
pm.registerEvents(this.weatherListener, this);
|
||||
pm.registerEvents(this.portalListener, this);
|
||||
|
@ -48,8 +48,6 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
@Property
|
||||
private volatile String prefixchatformat;
|
||||
@Property
|
||||
private volatile boolean useasyncchat;
|
||||
@Property
|
||||
private volatile boolean teleportintercept;
|
||||
@Property
|
||||
private volatile boolean firstspawnoverride;
|
||||
@ -93,7 +91,6 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
protected void setDefaults() {
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
enforceaccess = false;
|
||||
useasyncchat = true;
|
||||
prefixchat = true;
|
||||
prefixchatformat = "[%world%]%chat%";
|
||||
teleportintercept = true;
|
||||
@ -303,16 +300,6 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
this.teleportcooldown = teleportCooldown;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseAsyncChat(boolean useAsyncChat) {
|
||||
this.useasyncchat = useAsyncChat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getUseAsyncChat() {
|
||||
return this.useasyncchat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSilentStart(boolean silentStart) {
|
||||
Logging.setShowingConfig(!silentStart);
|
||||
|
@ -146,18 +146,6 @@ public interface MultiverseCoreConfig extends ConfigurationSerializable {
|
||||
*/
|
||||
boolean getEnforceAccess();
|
||||
|
||||
/**
|
||||
* Sets useasyncchat.
|
||||
* @param useAsyncChat The new value.
|
||||
*/
|
||||
void setUseAsyncChat(boolean useAsyncChat);
|
||||
|
||||
/**
|
||||
* Gets useasyncchat.
|
||||
* @return useasyncchat.
|
||||
*/
|
||||
boolean getUseAsyncChat();
|
||||
|
||||
/**
|
||||
* Sets whether to suppress startup messages.
|
||||
*
|
||||
|
@ -60,7 +60,6 @@ public class VersionCommand extends MultiverseCommand {
|
||||
+ "[Multiverse-Core] enforceaccess: " + plugin.getMVConfig().getEnforceAccess() + '\n'
|
||||
+ "[Multiverse-Core] prefixchat: " + plugin.getMVConfig().getPrefixChat() + '\n'
|
||||
+ "[Multiverse-Core] prefixchatformat: " + plugin.getMVConfig().getPrefixChatFormat() + '\n'
|
||||
+ "[Multiverse-Core] useasyncchat: " + plugin.getMVConfig().getUseAsyncChat() + '\n'
|
||||
+ "[Multiverse-Core] teleportintercept: " + plugin.getMVConfig().getTeleportIntercept() + '\n'
|
||||
+ "[Multiverse-Core] firstspawnoverride: " + plugin.getMVConfig().getFirstSpawnOverride() + '\n'
|
||||
+ "[Multiverse-Core] displaypermerrors: " + plugin.getMVConfig().getDisplayPermErrors() + '\n'
|
||||
|
@ -1,35 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
/**
|
||||
* A wrapper for the {@link AsyncPlayerChatEvent}.
|
||||
*/
|
||||
public class AsyncChatEvent implements ChatEvent {
|
||||
private final AsyncPlayerChatEvent event;
|
||||
|
||||
public AsyncChatEvent(AsyncPlayerChatEvent event) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return event.isCancelled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormat() {
|
||||
return event.getFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFormat(String s) {
|
||||
event.setFormat(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return event.getPlayer();
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* A wrapper for the two chat-events in Bukkit.
|
||||
*/
|
||||
public interface ChatEvent {
|
||||
/**
|
||||
* @return Whether this event is cancelled.
|
||||
*/
|
||||
boolean isCancelled();
|
||||
|
||||
/**
|
||||
* @return The format.
|
||||
*/
|
||||
String getFormat();
|
||||
|
||||
/**
|
||||
* Sets the format.
|
||||
* @param s The new format.
|
||||
*/
|
||||
void setFormat(String s);
|
||||
|
||||
/**
|
||||
* @return The player.
|
||||
*/
|
||||
Player getPlayer();
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 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.MultiverseCore.listeners;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
|
||||
/**
|
||||
* Multiverse's {@link org.bukkit.event.Listener} for players.
|
||||
*/
|
||||
public class MVAsyncPlayerChatListener extends MVChatListener {
|
||||
public MVAsyncPlayerChatListener(MultiverseCore plugin, MVPlayerListener playerListener) {
|
||||
super(plugin, playerListener);
|
||||
Logging.fine("Created AsyncPlayerChatEvent listener.");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a player wants to chat.
|
||||
* @param event The Event that was fired.
|
||||
*/
|
||||
@EventHandler
|
||||
public void playerChat(AsyncPlayerChatEvent event) {
|
||||
this.playerChat(new AsyncChatEvent(event));
|
||||
}
|
||||
}
|
@ -5,12 +5,14 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
/**
|
||||
* Multiverse's {@link org.bukkit.event.Listener} for players.
|
||||
*/
|
||||
public abstract class MVChatListener implements Listener {
|
||||
public class MVChatListener implements Listener {
|
||||
private final MultiverseCore plugin;
|
||||
private final MVWorldManager worldManager;
|
||||
private final MVPlayerListener playerListener;
|
||||
@ -22,10 +24,11 @@ public abstract class MVChatListener implements Listener {
|
||||
}
|
||||
|
||||
/**
|
||||
* This handles a {@link ChatEvent}.
|
||||
* @param event The {@link ChatEvent}.
|
||||
* This method is called when an a player sends a chat message.
|
||||
* @param event The Event that was fired.
|
||||
*/
|
||||
public void playerChat(ChatEvent event) {
|
||||
@EventHandler
|
||||
public void playerChat(AsyncPlayerChatEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,36 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 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.MultiverseCore.listeners;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
|
||||
/**
|
||||
* Multiverse's {@link org.bukkit.event.Listener} for players.
|
||||
*/
|
||||
@SuppressWarnings("deprecation") // this exists only for downwards compatibility
|
||||
public class MVPlayerChatListener extends MVChatListener {
|
||||
public MVPlayerChatListener(MultiverseCore plugin, MVPlayerListener playerListener) {
|
||||
super(plugin, playerListener);
|
||||
Logging.fine("Registered PlayerChatEvent listener.");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a player wants to chat.
|
||||
* @param event The Event that was fired.
|
||||
*/
|
||||
@EventHandler
|
||||
public void playerChat(PlayerChatEvent event) {
|
||||
this.playerChat(new NormalChatEvent(event));
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
|
||||
/**
|
||||
* A wrapper for the {@link PlayerChatEvent}.
|
||||
* @deprecated This is deprecated like the {@link PlayerChatEvent}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class NormalChatEvent implements ChatEvent {
|
||||
private final PlayerChatEvent event;
|
||||
|
||||
public NormalChatEvent(PlayerChatEvent event) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return event.isCancelled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormat() {
|
||||
return event.getFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFormat(String s) {
|
||||
event.setFormat(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return event.getPlayer();
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ package com.onarandombox.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.configuration.SpawnLocation;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVAsyncPlayerChatListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVChatListener;
|
||||
import com.onarandombox.MultiverseCore.utils.MockWorldFactory;
|
||||
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
@ -187,10 +187,10 @@ public class TestWorldProperties {
|
||||
|
||||
// call player chat event
|
||||
core.getMVConfig().setPrefixChat(true);
|
||||
((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent);
|
||||
core.getChatListener().playerChat(playerChatEvent);
|
||||
verify(playerChatEvent).setFormat("[" + mvWorld.getColoredWorldString() + "]" + "format");
|
||||
core.getMVConfig().setPrefixChat(false);
|
||||
((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent);
|
||||
core.getChatListener().playerChat(playerChatEvent);
|
||||
verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!)
|
||||
|
||||
// call player join events
|
||||
@ -281,15 +281,15 @@ public class TestWorldProperties {
|
||||
|
||||
// call player chat event
|
||||
core.getMVConfig().setPrefixChat(true);
|
||||
((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent);
|
||||
core.getChatListener().playerChat(playerChatEvent);
|
||||
// never because it's hidden!
|
||||
verify(playerChatEvent, never()).setFormat(
|
||||
"[" + mvWorld.getColoredWorldString() + "]" + "format");
|
||||
mvWorld.setHidden(false);
|
||||
((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent);
|
||||
core.getChatListener().playerChat(playerChatEvent);
|
||||
verify(playerChatEvent).setFormat("[" + mvWorld.getColoredWorldString() + "]" + "format");
|
||||
core.getMVConfig().setPrefixChat(false);
|
||||
((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent);
|
||||
core.getChatListener().playerChat(playerChatEvent);
|
||||
verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!)
|
||||
mvWorld.setHidden(true); // reset hidden-state
|
||||
|
||||
|
@ -10,6 +10,7 @@ package com.onarandombox.MultiverseCore.utils;
|
||||
import buscript.Buscript;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVChatListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
|
||||
@ -244,6 +245,12 @@ public class TestInstanceCreator {
|
||||
weatherlistenerfield.setAccessible(true);
|
||||
weatherlistenerfield.set(core, wl);
|
||||
|
||||
// Set weatherListener
|
||||
MVChatListener cl = PowerMockito.spy(new MVChatListener(core, pl));
|
||||
Field chatlistenerfield = MultiverseCore.class.getDeclaredField("chatListener");
|
||||
chatlistenerfield.setAccessible(true);
|
||||
chatlistenerfield.set(core, cl);
|
||||
|
||||
// Init our command sender
|
||||
final Logger commandSenderLogger = Logger.getLogger("CommandSender");
|
||||
commandSenderLogger.setParent(Util.logger);
|
||||
|
Loading…
Reference in New Issue
Block a user