Skip to content

Commit 18380b5

Browse files
committed
Fix checkstyle errors, s/bstats/mcstats
1 parent 3e62af9 commit 18380b5

File tree

5 files changed

+765
-110
lines changed

5 files changed

+765
-110
lines changed

pom.xml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,6 @@
152152
<url>http://repo1.maven.org/maven2/</url>
153153
</repository>
154154

155-
<repository>
156-
<id>Plugin Metrics</id>
157-
<url>http://repo.mcstats.org/content/repositories/public/</url>
158-
</repository>
159-
160155
<!-- Java Mail -->
161156
<repository>
162157
<id>Java.Net</id>
@@ -365,12 +360,6 @@
365360
</exclusion>
366361
</exclusions>
367362
</dependency>
368-
<dependency>
369-
<groupId>org.mcstats.bukkit</groupId>
370-
<artifactId>metrics</artifactId>
371-
<version>R8-SNAPSHOT</version>
372-
<scope>compile</scope>
373-
</dependency>
374363
<dependency>
375364
<groupId>commons-codec</groupId>
376365
<artifactId>commons-codec</artifactId>
@@ -525,7 +514,6 @@
525514
<include>com.jcraft:jsch:jar:*</include>
526515
<include>org.apache.commons:commons-io:jar:*</include>
527516
<include>org.xerial:sqlite-jdbc:jar:*</include>
528-
<include>org.mcstats.bukkit:metrics:jar:*</include>
529517
<include>net.sourceforge.jchardet:jchardet:jar:*</include>
530518
<include>redis.clients:jedis:jar:*</include>
531519
<include>mysql:mysql-connector-java:jar:*</include>
@@ -574,10 +562,6 @@
574562
<shadedPattern>com.laytonsmith.libs.org.sqlite</shadedPattern>
575563
</relocation>
576564
-->
577-
<relocation>
578-
<pattern>org.mcstats</pattern>
579-
<shadedPattern>com.laytonsmith.libs.org.mcstats</shadedPattern>
580-
</relocation>
581565
<relocation>
582566
<pattern>org.mozilla.intl.chardet</pattern>
583567
<shadedPattern>com.laytonsmith.libs.org.mozilla.intl.chardet</shadedPattern>
@@ -669,12 +653,6 @@
669653
<include>**</include>
670654
</includes>
671655
</filter>
672-
<filter>
673-
<artifact>org.mcstats.bukkit:metrics:jar:*</artifact>
674-
<includes>
675-
<include>**</include>
676-
</includes>
677-
</filter>
678656
<filter>
679657
<artifact>net.sourceforge.jchardet:jchardet:jar:*</artifact>
680658
<includes>

src/main/java/com/laytonsmith/PureUtilities/ZipReader.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ private void initList() throws IOException {
339339
}
340340
if(this.zipEntries == null) {
341341
zipEntries = new ArrayList<>();
342-
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(topZip))) {
342+
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(topZip))){
343343
ZipEntry entry;
344344
while((entry = zis.getNextEntry()) != null) {
345345
File f = new File(topZip, entry.getName());
@@ -367,7 +367,7 @@ public String getName() {
367367

368368
/**
369369
* Returns a list of File objects that are subfiles or directories in this directory. This method does not
370-
* recurse, to match the behavior of
370+
* recurse, to match the behavior of
371371
*
372372
* @return
373373
* @throws IOException
@@ -440,8 +440,8 @@ public void recursiveCopy(File dstFolder, boolean create) throws IOException {
440440
} else {
441441
File newFile = new File(dstFolder, r.file.getName());
442442
newFile.getParentFile().mkdir();
443-
try (FileOutputStream fos = new FileOutputStream(newFile, false);
444-
InputStream fis = r.getInputStream()) {
443+
try (FileOutputStream fos = new FileOutputStream(newFile, false);
444+
InputStream fis = r.getInputStream()){
445445
StreamUtils.Copy(fis, fos);
446446
}
447447
}

src/main/java/com/laytonsmith/commandhelper/CommandHelperPlugin.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,13 @@
7474
import org.bukkit.plugin.RegisteredListener;
7575
import org.bukkit.plugin.TimedRegisteredListener;
7676
import org.bukkit.plugin.java.JavaPlugin;
77-
import org.mcstats.Metrics;
77+
import org.bstats.bukkit.Metrics;
7878

7979
import java.io.File;
8080
import java.io.IOException;
8181
import java.lang.reflect.InvocationTargetException;
8282
import java.util.List;
83+
import java.util.concurrent.Callable;
8384
import java.util.concurrent.ConcurrentHashMap;
8485
import java.util.concurrent.ExecutorService;
8586
import java.util.concurrent.Executors;
@@ -325,21 +326,13 @@ public void onEnable() {
325326
BukkitMCSound.build();
326327

327328
//Metrics
328-
try {
329-
Metrics m = new Metrics(this);
330-
Metrics.Graph graph = m.createGraph("Player count");
331-
graph.addPlotter(new Metrics.Plotter("Player count") {
332-
333-
@Override
334-
public int getValue() {
335-
return Static.getServer().getOnlinePlayers().size();
336-
}
337-
});
338-
m.addGraph(graph);
339-
m.start();
340-
} catch (IOException e) {
341-
// Failed to submit the stats :-(
342-
}
329+
Metrics m = new Metrics(this);
330+
m.addCustomChart(new Metrics.SingleLineChart("player_count", new Callable<Integer>() {
331+
@Override
332+
public Integer call() throws Exception {
333+
return Static.getServer().getOnlinePlayers().size();
334+
}
335+
}));
343336

344337
try {
345338
//This may seem redundant, but on a /reload, we want to refresh these

src/main/java/com/laytonsmith/tools/Interpreter.java

Lines changed: 82 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.laytonsmith.PureUtilities.CommandExecutor;
55
import com.laytonsmith.PureUtilities.Common.FileUtil;
66
import com.laytonsmith.PureUtilities.Common.MutableObject;
7+
import com.laytonsmith.PureUtilities.Common.OSUtils;
78
import com.laytonsmith.PureUtilities.Common.StreamUtils;
89
import com.laytonsmith.PureUtilities.Common.StringUtils;
910
import com.laytonsmith.PureUtilities.Common.WinRegistry;
@@ -846,66 +847,71 @@ public boolean doBuiltin(String script) {
846847
}
847848

848849
public static void install() {
849-
if(TermColors.SYSTEM == TermColors.SYS.UNIX) {
850-
try {
851-
URL jar = Interpreter.class.getProtectionDomain().getCodeSource().getLocation();
852-
File exe = new File(INTERPRETER_INSTALLATION_LOCATION);
853-
String bashScript = Static.GetStringResource("/interpreter-helpers/bash.sh");
850+
if(null == OSUtils.GetOS()) {
851+
StreamUtils.GetSystemErr().println("Cmdline MethodScript is only supported on Unix and Windows");
852+
return;
853+
} else switch(OSUtils.GetOS()) {
854+
case LINUX:
855+
case MAC:
854856
try {
855-
bashScript = bashScript.replaceAll("%%LOCATION%%", jar.toURI().getPath());
856-
} catch (URISyntaxException ex) {
857-
ex.printStackTrace();
858-
}
859-
exe.createNewFile();
860-
if(!exe.canWrite()) {
861-
throw new IOException();
862-
}
863-
FileUtil.write(bashScript, exe);
864-
exe.setExecutable(true, false);
865-
File manDir = new File("/usr/local/man/man1");
866-
if(manDir.exists()) {
867-
//Don't do this installation if the man pages aren't already there.
868-
String manPage = Static.GetStringResource("/interpreter-helpers/manpage");
857+
URL jar = Interpreter.class.getProtectionDomain().getCodeSource().getLocation();
858+
File exe = new File(INTERPRETER_INSTALLATION_LOCATION);
859+
String bashScript = Static.GetStringResource("/interpreter-helpers/bash.sh");
869860
try {
870-
manPage = DocGenTemplates.DoTemplateReplacement(manPage, DocGenTemplates.GetGenerators());
871-
File manPageFile = new File(manDir, "mscript.1");
872-
FileUtil.write(manPage, manPageFile);
873-
} catch (DocGenTemplates.Generator.GenerateException ex) {
874-
Logger.getLogger(Interpreter.class.getName()).log(Level.SEVERE, null, ex);
861+
bashScript = bashScript.replaceAll("%%LOCATION%%", jar.toURI().getPath());
862+
} catch (URISyntaxException ex) {
863+
ex.printStackTrace();
875864
}
876-
}
877-
} catch (IOException e) {
878-
StreamUtils.GetSystemErr().println("Cannot install. You must run the command with sudo for it to succeed, however, did you do that?");
879-
return;
880-
}
881-
} else {
882-
Path tmp = null;
883-
try {
884-
// 1. Unpack the csharp installer program in a temporary directory
885-
File root = new File(Interpreter.class.getResource("/interpreter-helpers/csharp").toExternalForm());
886-
ZipReader zReader = new ZipReader(root);
887-
tmp = Files.createTempDirectory("methodscript-installer", new FileAttribute[]{});
888-
zReader.recursiveCopy(tmp.toFile(), false);
889-
890-
// 2. Write the location of this jar to the registry
891-
String me = ClassDiscovery.GetClassContainer(Interpreter.class).toExternalForm().substring(6);
892-
String keyName = "Software\\MethodScript";
893-
WinRegistry.createKey(WinRegistry.HKEY_CURRENT_USER, keyName);
894-
WinRegistry.writeStringValue(WinRegistry.HKEY_CURRENT_USER, keyName, "JarLocation", me);
895-
896-
// 3. Execute the setup.exe file
897-
File setup = new File(tmp.toFile(), "setup.exe");
898-
int setupResult = new CommandExecutor(new String[]{setup.getAbsolutePath()}).start().waitFor();
899-
if(setupResult != 0) {
900-
StreamUtils.GetSystemErr().println("Setup failed to complete successfully (exit code " + setupResult + ")");
901-
System.exit(setupResult);
902-
} else {
903-
StreamUtils.GetSystemOut().println("Setup has begun. Finish the installation in the GUI.");
904-
}
905-
} catch(IOException | InterruptedException | IllegalAccessException | InvocationTargetException ex) {
906-
ex.printStackTrace(StreamUtils.GetSystemErr());
907-
System.exit(1);
908-
}
865+
exe.createNewFile();
866+
if(!exe.canWrite()) {
867+
throw new IOException();
868+
}
869+
FileUtil.write(bashScript, exe);
870+
exe.setExecutable(true, false);
871+
File manDir = new File("/usr/local/man/man1");
872+
if(manDir.exists()) {
873+
//Don't do this installation if the man pages aren't already there.
874+
String manPage = Static.GetStringResource("/interpreter-helpers/manpage");
875+
try {
876+
manPage = DocGenTemplates.DoTemplateReplacement(manPage, DocGenTemplates.GetGenerators());
877+
File manPageFile = new File(manDir, "mscript.1");
878+
FileUtil.write(manPage, manPageFile);
879+
} catch (DocGenTemplates.Generator.GenerateException ex) {
880+
Logger.getLogger(Interpreter.class.getName()).log(Level.SEVERE, null, ex);
881+
}
882+
}
883+
} catch (IOException e) {
884+
StreamUtils.GetSystemErr().println("Cannot install. You must run the command with sudo for it to succeed, however, did you do that?");
885+
return;
886+
} break;
887+
case WINDOWS:
888+
Path tmp = null;
889+
try {
890+
// 1. Unpack the csharp installer program in a temporary directory
891+
File root = new File(Interpreter.class.getResource("/interpreter-helpers/csharp").toExternalForm());
892+
ZipReader zReader = new ZipReader(root);
893+
tmp = Files.createTempDirectory("methodscript-installer", new FileAttribute[]{});
894+
zReader.recursiveCopy(tmp.toFile(), false);
895+
896+
// 2. Write the location of this jar to the registry
897+
String me = ClassDiscovery.GetClassContainer(Interpreter.class).toExternalForm().substring(6);
898+
String keyName = "Software\\MethodScript";
899+
WinRegistry.createKey(WinRegistry.HKEY_CURRENT_USER, keyName);
900+
WinRegistry.writeStringValue(WinRegistry.HKEY_CURRENT_USER, keyName, "JarLocation", me);
901+
902+
// 3. Execute the setup.exe file
903+
File setup = new File(tmp.toFile(), "setup.exe");
904+
int setupResult = new CommandExecutor(new String[]{setup.getAbsolutePath()}).start().waitFor();
905+
if(setupResult != 0) {
906+
StreamUtils.GetSystemErr().println("Setup failed to complete successfully (exit code " + setupResult + ")");
907+
System.exit(setupResult);
908+
} else {
909+
StreamUtils.GetSystemOut().println("Setup has begun. Finish the installation in the GUI.");
910+
}
911+
} catch(IOException | InterruptedException | IllegalAccessException | InvocationTargetException ex) {
912+
ex.printStackTrace(StreamUtils.GetSystemErr());
913+
System.exit(1);
914+
} break;
909915
}
910916
StreamUtils.GetSystemOut().println("MethodScript has successfully been installed on your system. Note that you may need to rerun the install command"
911917
+ " if you change locations of the jar, or rename it. Be sure to put \"#!" + INTERPRETER_INSTALLATION_LOCATION + "\" at the top of all your scripts,"
@@ -915,19 +921,27 @@ public static void install() {
915921
}
916922

917923
public static void uninstall() {
918-
if(TermColors.SYSTEM == TermColors.SYS.UNIX) {
919-
try {
920-
File exe = new File(INTERPRETER_INSTALLATION_LOCATION);
921-
if(!exe.delete()) {
922-
throw new IOException();
923-
}
924-
} catch (IOException e) {
925-
StreamUtils.GetSystemErr().println("Cannot uninstall. You must run the command with sudo for it to succeed, however, did you do that?");
926-
return;
927-
}
928-
} else {
924+
if(null == OSUtils.GetOS()) {
929925
StreamUtils.GetSystemErr().println("Sorry, cmdline functionality is currently only supported on unix systems! Check back soon though!");
930926
return;
927+
} else switch(OSUtils.GetOS()) {
928+
case LINUX:
929+
case MAC:
930+
try {
931+
File exe = new File(INTERPRETER_INSTALLATION_LOCATION);
932+
if(!exe.delete()) {
933+
throw new IOException();
934+
}
935+
} catch (IOException e) {
936+
StreamUtils.GetSystemErr().println("Cannot uninstall. You must run the command with sudo for it to succeed, however, did you do that?");
937+
return;
938+
} break;
939+
case WINDOWS:
940+
StreamUtils.GetSystemOut().println("To uninstall on windows, please uninstall from the Add or Remove Programs application.");
941+
return;
942+
default:
943+
StreamUtils.GetSystemErr().println("Sorry, cmdline functionality is currently only supported on unix systems! Check back soon though!");
944+
return;
931945
}
932946
StreamUtils.GetSystemOut().println("MethodScript has been uninstalled from this system.");
933947
}

0 commit comments

Comments
 (0)