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>
<module name="IllegalImport"/> <module name="IllegalImport"/>
<module name="RedundantImport"/> <module name="RedundantImport"/>
<module name="UnusedImports"/> <module name="UnusedImports">
<property name="processJavadoc" value="true"/>
</module>
<module name="MethodLength"/> <module name="MethodLength"/>
<module name="ParameterNumber"/> <module name="ParameterNumber"/>
<module name="EmptyForIteratorPad"/> <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.ExactDestination;
import com.onarandombox.MultiverseCore.destination.PlayerDestination; import com.onarandombox.MultiverseCore.destination.PlayerDestination;
import com.onarandombox.MultiverseCore.destination.WorldDestination; import com.onarandombox.MultiverseCore.destination.WorldDestination;
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
import com.onarandombox.MultiverseCore.listeners.MVEntityListener; import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener; import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
import com.onarandombox.MultiverseCore.listeners.MVPluginListener; import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
@ -111,9 +112,14 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
return "The Multiverse-Core Plugin"; 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 @Override
@Deprecated
public String dumpVersionInfo(String buffer) { public String dumpVersionInfo(String buffer) {
// I'm kinda cheating on this one, since we call the init event.
return buffer; return buffer;
} }

View File

@ -8,6 +8,7 @@
package com.onarandombox.MultiverseCore.api; package com.onarandombox.MultiverseCore.api;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
/** /**
* This interface is implemented by every official Multiverse-plugin. * 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. * @param buffer The string that contains Core and all other MV plugins' versions.
* *
* @return A modified buffer that contains this MVPlugin's version information. * @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); String dumpVersionInfo(String buffer);
/** /**

View File

@ -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.event.MVVersionRequestEvent; import com.onarandombox.MultiverseCore.event.MVVersionEvent;
import com.onarandombox.MultiverseCore.utils.webpaste.PasteFailedException; import com.onarandombox.MultiverseCore.utils.webpaste.PasteFailedException;
import com.onarandombox.MultiverseCore.utils.webpaste.PasteService; import com.onarandombox.MultiverseCore.utils.webpaste.PasteService;
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceFactory; 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); "Dumps version info to the console, optionally to pastie.org with -p or pastebin.com with a -b.", PermissionDefault.TRUE);
} }
private String pasteBinBuffer = "";
@Override @Override
public void runCommand(CommandSender sender, List<String> args) { public void runCommand(CommandSender sender, List<String> args) {
// Check if the command was sent from a Player. // 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."); sender.sendMessage("Version info dumped to console. Please check your server logs.");
} }
logAndAddToPasteBinBuffer("Multiverse-Core Version: " + this.plugin.getDescription().getVersion()); StringBuilder buffer = new StringBuilder();
logAndAddToPasteBinBuffer("Bukkit Version: " + this.plugin.getServer().getVersion()); buffer.append("[Multiverse-Core] Multiverse-Core Version: ").append(this.plugin.getDescription().getVersion()).append('\n');
logAndAddToPasteBinBuffer("Loaded Worlds: " + this.plugin.getMVWorldManager().getMVWorlds().size()); buffer.append("[Multiverse-Core] Bukkit Version: ").append(this.plugin.getServer().getVersion()).append('\n');
logAndAddToPasteBinBuffer("Multiverse Plugins Loaded: " + this.plugin.getPluginCount()); buffer.append("[Multiverse-Core] Loaded Worlds: ").append(this.plugin.getMVWorldManager().getMVWorlds().size()).append('\n');
logAndAddToPasteBinBuffer("Economy being used: " + this.plugin.getBank().getEconUsed()); buffer.append("[Multiverse-Core] Multiverse Plugins Loaded: ").append(this.plugin.getPluginCount()).append('\n');
logAndAddToPasteBinBuffer("Permissions Plugin: " + this.plugin.getMVPerms().getType()); buffer.append("[Multiverse-Core] Economy being used: ").append(this.plugin.getBank().getEconUsed()).append('\n');
logAndAddToPasteBinBuffer("Dumping Config Values: (version " + this.plugin.getMVConfiguration().getString("version", "NOT SET") + ")"); buffer.append("[Multiverse-Core] Permissions Plugin: ").append(this.plugin.getMVPerms().getType()).append('\n');
logAndAddToPasteBinBuffer("messagecooldown: " + "Not yet IMPLEMENTED"); buffer.append("[Multiverse-Core] Dumping Config Values: (version ")
logAndAddToPasteBinBuffer("teleportcooldown: " + "Not yet IMPLEMENTED"); .append(this.plugin.getMVConfiguration().getString("version", "NOT SET")).append(")").append('\n');
logAndAddToPasteBinBuffer("worldnameprefix: " + MultiverseCore.PrefixChat); buffer.append("[Multiverse-Core] messagecooldown: ").append("Not yet IMPLEMENTED").append('\n');
logAndAddToPasteBinBuffer("enforceaccess: " + MultiverseCore.EnforceAccess); buffer.append("[Multiverse-Core] teleportcooldown: ").append("Not yet IMPLEMENTED").append('\n');
logAndAddToPasteBinBuffer("enforcegamemodes: " + MultiverseCore.EnforceGameModes); buffer.append("[Multiverse-Core] worldnameprefix: ").append(MultiverseCore.PrefixChat).append('\n');
logAndAddToPasteBinBuffer("displaypermerrors: " + MultiverseCore.DisplayPermErrors); buffer.append("[Multiverse-Core] enforceaccess: ").append(MultiverseCore.EnforceAccess).append('\n');
logAndAddToPasteBinBuffer("teleportintercept: " + MultiverseCore.TeleportIntercept); buffer.append("[Multiverse-Core] enforcegamemodes: ").append(MultiverseCore.EnforceGameModes).append('\n');
logAndAddToPasteBinBuffer("debug: " + MultiverseCore.GlobalDebug); buffer.append("[Multiverse-Core] displaypermerrors: ").append(MultiverseCore.DisplayPermErrors).append('\n');
logAndAddToPasteBinBuffer("Special Code: FRN002"); 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); 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) { if (args.size() == 1) {
String pasteUrl = ""; String pasteUrl = "";
if (args.get(0).equalsIgnoreCase("-p")) { 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")) { } 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 { } else {
return; 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. * 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. * @param isPrivate Should the paste be marked as private.
* @return URL of visible paste * @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); PasteService ps = PasteServiceFactory.getService(type, isPrivate);
try { try {
return ps.postData(ps.encodeData(this.pasteBinBuffer), ps.getPostURL()); return ps.postData(ps.encodeData(pasteData), ps.getPostURL());
} catch (PasteFailedException e) { } catch (PasteFailedException e) {
System.out.print(e); System.out.print(e);
return "Error posting to service"; 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. * Called when somebody requests version information about Multiverse.
* @deprecated Use {@link MVVersionEvent} instead.
*/ */
@Deprecated
public class MVVersionRequestEvent extends Event { public class MVVersionRequestEvent extends Event {
private String pasteBinBuffer; private String pasteBinBuffer;
@ -21,10 +23,22 @@ public class MVVersionRequestEvent extends Event {
this.pasteBinBuffer = pasteBinBuffer; this.pasteBinBuffer = pasteBinBuffer;
} }
/**
* Gets the pasteBinBuffer.
* @return The pasteBinBuffer.
* @deprecated Use {@link MVVersionEvent} instead.
*/
@Deprecated
public String getPasteBinBuffer() { public String getPasteBinBuffer() {
return this.pasteBinBuffer; return this.pasteBinBuffer;
} }
/**
* Sets the pasteBinBuffer.
* @param buffer The new pasteBinBuffer.
* @deprecated Use {@link MVVersionEvent} instead.
*/
@Deprecated
public void setPasteBinBuffer(String buffer) { public void setPasteBinBuffer(String buffer) {
this.pasteBinBuffer = buffer; this.pasteBinBuffer = buffer;
} }