2015-07-18 19:18:15 +02:00
package com.intellectualcrafters.plot.commands ;
2015-07-30 16:25:16 +02:00
import java.io.File ;
import java.io.IOException ;
2015-07-18 19:18:15 +02:00
import com.intellectualcrafters.plot.PS ;
import com.intellectualcrafters.plot.config.C ;
2016-02-10 19:59:51 +01:00
import com.intellectualcrafters.plot.config.Settings ;
2015-07-18 19:18:15 +02:00
import com.intellectualcrafters.plot.object.PlotPlayer ;
import com.intellectualcrafters.plot.util.HastebinUtility ;
2016-02-10 19:59:51 +01:00
import com.intellectualcrafters.plot.util.MainUtil ;
2015-07-18 19:18:15 +02:00
import com.intellectualcrafters.plot.util.TaskManager ;
2016-02-10 19:59:51 +01:00
import com.intellectualcrafters.plot.util.UUIDHandler ;
2015-07-27 19:50:04 +02:00
import com.plotsquared.general.commands.CommandDeclaration ;
2015-07-18 19:18:15 +02:00
2015-07-27 00:26:19 +02:00
@CommandDeclaration (
2015-09-11 12:09:22 +02:00
command = " debugpaste " ,
aliases = { " dp " } ,
usage = " /plot debugpaste " ,
2016-02-05 00:45:50 +01:00
description = " Upload settings.yml & latest.log to HasteBin " ,
2015-09-11 12:09:22 +02:00
permission = " plots.debugpaste " ,
category = CommandCategory . DEBUG )
2015-09-13 06:04:31 +02:00
public class DebugPaste extends SubCommand {
2015-07-18 19:18:15 +02:00
@Override
2015-09-13 06:04:31 +02:00
public boolean onCommand ( final PlotPlayer plr , final String [ ] args ) {
TaskManager . runTaskAsync ( new Runnable ( ) {
2015-07-18 19:18:15 +02:00
@Override
2015-09-13 06:04:31 +02:00
public void run ( ) {
try {
2015-09-11 12:09:22 +02:00
final String settingsYML = HastebinUtility . upload ( PS . get ( ) . configFile ) ;
2015-07-26 13:40:48 +02:00
String latestLOG ;
2015-09-13 06:04:31 +02:00
try {
2016-02-10 19:59:51 +01:00
latestLOG = HastebinUtility . upload ( new File ( PS . get ( ) . IMP . getDirectory ( ) , " ../../logs/latest.log " ) ) ;
2015-09-13 06:04:31 +02:00
} catch ( final Exception e ) {
2016-02-10 19:59:51 +01:00
MainUtil . sendMessage ( plr , " &clatest.log is too big to be pasted, will ignore " ) ;
2015-07-26 13:40:48 +02:00
latestLOG = " too big :( " ;
}
2015-09-11 12:09:22 +02:00
final StringBuilder b = new StringBuilder ( ) ;
2015-07-19 16:18:46 +02:00
b . append ( " # Welcome to this paste \ n# It is meant to provide us at IntellectualSites with better information about your problem \ n \ n# We will start with some informational files \ n " ) ;
b . append ( " links.settings_yml: ' " ) . append ( settingsYML ) . append ( " ' \ n " ) ;
b . append ( " links.latest_log: ' " ) . append ( latestLOG ) . append ( " ' \ n " ) ;
b . append ( " \ n# YAAAS! Now let us move on to the server info \ n " ) ;
2016-02-10 19:59:51 +01:00
b . append ( " version.server: ' " ) . append ( PS . get ( ) . IMP . getServerVersion ( ) ) . append ( " ' \ n " ) ;
b . append ( " online_mode: " ) . append ( UUIDHandler . getUUIDWrapper ( ) + " ; " + ! Settings . OFFLINE_MODE ) . append ( " \ n " ) ;
2015-07-19 16:18:46 +02:00
b . append ( " plugins: " ) ;
2016-02-10 19:59:51 +01:00
for ( String id : PS . get ( ) . IMP . getPluginIds ( ) ) {
String [ ] split = id . split ( " : " ) ;
String [ ] split2 = split [ 0 ] . split ( " ; " ) ;
String enabled = split . length = = 2 ? split [ 1 ] : " unknown " ;
String name = split2 [ 0 ] ;
String version = split2 . length = = 2 ? split2 [ 1 ] : " unknown " ;
b . append ( " \ n " ) . append ( name ) . append ( " : \ n " ) . append ( " version: ' " ) . append ( version ) . append ( " ' " ) . append ( " \ n enabled: " ) . append ( enabled ) ;
2015-07-19 16:18:46 +02:00
}
b . append ( " \ n \ n# YAY! Now, let's see what we can find in your JVM \ n " ) ;
2015-09-11 12:09:22 +02:00
final Runtime runtime = Runtime . getRuntime ( ) ;
2015-07-19 16:18:46 +02:00
b . append ( " memory.free: " ) . append ( runtime . freeMemory ( ) ) . append ( " \ n " ) ;
b . append ( " memory.max: " ) . append ( runtime . maxMemory ( ) ) . append ( " \ n " ) ;
b . append ( " java.specification.version: ' " ) . append ( System . getProperty ( " java.specification.version " ) ) . append ( " ' \ n " ) ;
b . append ( " java.vendor: ' " ) . append ( System . getProperty ( " java.vendor " ) ) . append ( " ' \ n " ) ;
b . append ( " java.version: ' " ) . append ( System . getProperty ( " java.version " ) ) . append ( " ' \ n " ) ;
b . append ( " os.arch: ' " ) . append ( System . getProperty ( " os.arch " ) ) . append ( " ' \ n " ) ;
b . append ( " os.name: ' " ) . append ( System . getProperty ( " os.name " ) ) . append ( " ' \ n " ) ;
b . append ( " os.version: ' " ) . append ( System . getProperty ( " os.version " ) ) . append ( " ' \ n \ n " ) ;
b . append ( " # Okay :D Great. You are now ready to create your bug report! " ) ;
b . append ( " \ n# You can do so at https://github.com/IntellectualSites/PlotSquared/issues " ) ;
2015-09-13 06:04:31 +02:00
2015-09-11 12:09:22 +02:00
final String link = HastebinUtility . upload ( b . toString ( ) ) ;
2015-07-27 15:10:14 +02:00
plr . sendMessage ( C . DEBUG_REPORT_CREATED . s ( ) . replace ( " %url% " , link ) ) ;
2015-09-13 06:04:31 +02:00
} catch ( final IOException e ) {
2015-07-18 19:18:15 +02:00
e . printStackTrace ( ) ;
}
}
} ) ;
return true ;
}
}