New "/mv version"-system.

This commit is contained in:
main() 2012-01-01 21:10:51 +01:00
parent 426a3bf252
commit a5650f1f35
6 changed files with 92 additions and 32 deletions

View File

@ -61,7 +61,9 @@
</module>
<module name="IllegalImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports"/>
<module name="UnusedImports">
<property name="processJavadoc" value="true"/>
</module>
<module name="MethodLength"/>
<module name="ParameterNumber"/>
<module name="EmptyForIteratorPad"/>

View File

@ -21,6 +21,7 @@ import com.onarandombox.MultiverseCore.destination.DestinationFactory;
import com.onarandombox.MultiverseCore.destination.ExactDestination;
import com.onarandombox.MultiverseCore.destination.PlayerDestination;
import com.onarandombox.MultiverseCore.destination.WorldDestination;
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
@ -111,9 +112,14 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
return "The Multiverse-Core Plugin";
}
/**
* {@inheritDoc}
* @deprecated This is now deprecated, nobody needs it any longer.
* All version info-dumping is now done with {@link MVVersionEvent}.
*/
@Override
@Deprecated
public String dumpVersionInfo(String buffer) {
// I'm kinda cheating on this one, since we call the init event.
return buffer;
}

View File

@ -8,6 +8,7 @@
package com.onarandombox.MultiverseCore.api;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
/**
* This interface is implemented by every official Multiverse-plugin.
@ -19,7 +20,11 @@ public interface MVPlugin extends LoggablePlugin {
* @param buffer The string that contains Core and all other MV plugins' versions.
*
* @return A modified buffer that contains this MVPlugin's version information.
*
* @deprecated This is now deprecated, nobody needs it any longer.
* All version info-dumping is now done with {@link MVVersionEvent}.
*/
@Deprecated
String dumpVersionInfo(String buffer);
/**

View File

@ -8,7 +8,7 @@
package com.onarandombox.MultiverseCore.commands;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.event.MVVersionRequestEvent;
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
import com.onarandombox.MultiverseCore.utils.webpaste.PasteFailedException;
import com.onarandombox.MultiverseCore.utils.webpaste.PasteService;
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceFactory;
@ -38,8 +38,6 @@ public class VersionCommand extends MultiverseCommand {
"Dumps version info to the console, optionally to pastie.org with -p or pastebin.com with a -b.", PermissionDefault.TRUE);
}
private String pasteBinBuffer = "";
@Override
public void runCommand(CommandSender sender, List<String> args) {
// Check if the command was sent from a Player.
@ -47,33 +45,41 @@ public class VersionCommand extends MultiverseCommand {
sender.sendMessage("Version info dumped to console. Please check your server logs.");
}
logAndAddToPasteBinBuffer("Multiverse-Core Version: " + this.plugin.getDescription().getVersion());
logAndAddToPasteBinBuffer("Bukkit Version: " + this.plugin.getServer().getVersion());
logAndAddToPasteBinBuffer("Loaded Worlds: " + this.plugin.getMVWorldManager().getMVWorlds().size());
logAndAddToPasteBinBuffer("Multiverse Plugins Loaded: " + this.plugin.getPluginCount());
logAndAddToPasteBinBuffer("Economy being used: " + this.plugin.getBank().getEconUsed());
logAndAddToPasteBinBuffer("Permissions Plugin: " + this.plugin.getMVPerms().getType());
logAndAddToPasteBinBuffer("Dumping Config Values: (version " + this.plugin.getMVConfiguration().getString("version", "NOT SET") + ")");
logAndAddToPasteBinBuffer("messagecooldown: " + "Not yet IMPLEMENTED");
logAndAddToPasteBinBuffer("teleportcooldown: " + "Not yet IMPLEMENTED");
logAndAddToPasteBinBuffer("worldnameprefix: " + MultiverseCore.PrefixChat);
logAndAddToPasteBinBuffer("enforceaccess: " + MultiverseCore.EnforceAccess);
logAndAddToPasteBinBuffer("enforcegamemodes: " + MultiverseCore.EnforceGameModes);
logAndAddToPasteBinBuffer("displaypermerrors: " + MultiverseCore.DisplayPermErrors);
logAndAddToPasteBinBuffer("teleportintercept: " + MultiverseCore.TeleportIntercept);
logAndAddToPasteBinBuffer("debug: " + MultiverseCore.GlobalDebug);
logAndAddToPasteBinBuffer("Special Code: FRN002");
StringBuilder buffer = new StringBuilder();
buffer.append("[Multiverse-Core] Multiverse-Core Version: ").append(this.plugin.getDescription().getVersion()).append('\n');
buffer.append("[Multiverse-Core] Bukkit Version: ").append(this.plugin.getServer().getVersion()).append('\n');
buffer.append("[Multiverse-Core] Loaded Worlds: ").append(this.plugin.getMVWorldManager().getMVWorlds().size()).append('\n');
buffer.append("[Multiverse-Core] Multiverse Plugins Loaded: ").append(this.plugin.getPluginCount()).append('\n');
buffer.append("[Multiverse-Core] Economy being used: ").append(this.plugin.getBank().getEconUsed()).append('\n');
buffer.append("[Multiverse-Core] Permissions Plugin: ").append(this.plugin.getMVPerms().getType()).append('\n');
buffer.append("[Multiverse-Core] Dumping Config Values: (version ")
.append(this.plugin.getMVConfiguration().getString("version", "NOT SET")).append(")").append('\n');
buffer.append("[Multiverse-Core] messagecooldown: ").append("Not yet IMPLEMENTED").append('\n');
buffer.append("[Multiverse-Core] teleportcooldown: ").append("Not yet IMPLEMENTED").append('\n');
buffer.append("[Multiverse-Core] worldnameprefix: ").append(MultiverseCore.PrefixChat).append('\n');
buffer.append("[Multiverse-Core] enforceaccess: ").append(MultiverseCore.EnforceAccess).append('\n');
buffer.append("[Multiverse-Core] enforcegamemodes: ").append(MultiverseCore.EnforceGameModes).append('\n');
buffer.append("[Multiverse-Core] displaypermerrors: ").append(MultiverseCore.DisplayPermErrors).append('\n');
buffer.append("[Multiverse-Core] teleportintercept: ").append(MultiverseCore.TeleportIntercept).append('\n');
buffer.append("[Multiverse-Core] debug: ").append(MultiverseCore.GlobalDebug).append('\n');
buffer.append("[Multiverse-Core] Special Code: FRN002").append('\n');
MVVersionRequestEvent versionEvent = new MVVersionRequestEvent(pasteBinBuffer);
MVVersionEvent versionEvent = new MVVersionEvent(buffer.toString());
this.plugin.getServer().getPluginManager().callEvent(versionEvent);
pasteBinBuffer = versionEvent.getPasteBinBuffer();
// log to console
String data = versionEvent.getVersionInfo();
String[] lines = data.split("\n");
for (String line : lines) {
this.plugin.log(Level.INFO, line);
}
if (args.size() == 1) {
String pasteUrl = "";
if (args.get(0).equalsIgnoreCase("-p")) {
pasteUrl = this.postToService(PasteServiceType.PASTIE, true); // private post to pastie
pasteUrl = postToService(PasteServiceType.PASTIE, true, data); // private post to pastie
} else if (args.get(0).equalsIgnoreCase("-b")) {
pasteUrl = this.postToService(PasteServiceType.PASTEBIN, true); // private post to pastie
pasteUrl = postToService(PasteServiceType.PASTEBIN, true, data); // private post to pastie
} else {
return;
}
@ -83,11 +89,6 @@ public class VersionCommand extends MultiverseCommand {
}
}
private void logAndAddToPasteBinBuffer(String string) {
this.pasteBinBuffer += "[Multiverse-Core] " + string + "\n";
this.plugin.log(Level.INFO, string);
}
/**
* Send the current contents of this.pasteBinBuffer to a web service.
*
@ -95,10 +96,10 @@ public class VersionCommand extends MultiverseCommand {
* @param isPrivate Should the paste be marked as private.
* @return URL of visible paste
*/
private String postToService(PasteServiceType type, boolean isPrivate) {
private static String postToService(PasteServiceType type, boolean isPrivate, String pasteData) {
PasteService ps = PasteServiceFactory.getService(type, isPrivate);
try {
return ps.postData(ps.encodeData(this.pasteBinBuffer), ps.getPostURL());
return ps.postData(ps.encodeData(pasteData), ps.getPostURL());
} catch (PasteFailedException e) {
System.out.print(e);
return "Error posting to service";

View File

@ -0,0 +1,32 @@
package com.onarandombox.MultiverseCore.event;
import org.bukkit.event.Event;
/**
* Called when somebody requests version information about Multiverse.
*/
public class MVVersionEvent extends Event {
private final StringBuilder versionInfoBuilder;
public MVVersionEvent(String versionInfo) {
super("MVVersionEvent");
versionInfoBuilder = new StringBuilder(versionInfo);
}
/**
* Gets the version-info currently saved in this event.
* @return The version-info.
*/
public String getVersionInfo() {
return versionInfoBuilder.toString();
}
/**
* Appends more version-info to the version-info currently saved in this event.
* @param moreVersionInfo The version-info to add. Should end with '\n'.
*/
public void appendVersionInfo(String moreVersionInfo) {
versionInfoBuilder.append(moreVersionInfo);
}
}

View File

@ -11,7 +11,9 @@ import org.bukkit.event.Event;
/**
* Called when somebody requests version information about Multiverse.
* @deprecated Use {@link MVVersionEvent} instead.
*/
@Deprecated
public class MVVersionRequestEvent extends Event {
private String pasteBinBuffer;
@ -21,10 +23,22 @@ public class MVVersionRequestEvent extends Event {
this.pasteBinBuffer = pasteBinBuffer;
}
/**
* Gets the pasteBinBuffer.
* @return The pasteBinBuffer.
* @deprecated Use {@link MVVersionEvent} instead.
*/
@Deprecated
public String getPasteBinBuffer() {
return this.pasteBinBuffer;
}
/**
* Sets the pasteBinBuffer.
* @param buffer The new pasteBinBuffer.
* @deprecated Use {@link MVVersionEvent} instead.
*/
@Deprecated
public void setPasteBinBuffer(String buffer) {
this.pasteBinBuffer = buffer;
}