Skip to content

Commit

Permalink
Add Denizen.mid
Browse files Browse the repository at this point in the history
Special thanks to Black Coyote -
http://www.youtube.com/user/BlaCoyProductions
  • Loading branch information
mcmonkey4eva committed Oct 5, 2013
1 parent 8fe2e7b commit 56b731d
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 5 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@
<defaultGoal>clean package install</defaultGoal>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>false</filtering>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>*.mid</include>
</includes>
</resource>
<resource>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
<includes>
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/net/aufdemrand/denizen/Denizen.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.aufdemrand.denizen.tags.ObjectFetcher;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.RuntimeCompiler;
import net.aufdemrand.denizen.utilities.Utilities;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.DebugElement;
import net.aufdemrand.denizen.utilities.depends.Depends;
Expand Down Expand Up @@ -163,6 +164,17 @@ public void onEnable() {
saveDefaultConfig();
reloadConfig();

// Ensure the Scripts and Midi folder exist
new File(System.getProperty("user.dir") + "/plugins/Denizen/Scripts").mkdirs();
new File(System.getProperty("user.dir") + "/plugins/Denizen/Midi").mkdirs();

// Ensure the example Denizen.mid sound file is available
if (!new File(System.getProperty("user.dir") + "/plugins/Denizen/Midi/Denizen.mid").exists()) {
String sourceFile = Denizen.class.getProtectionDomain().getCodeSource().getLocation().getFile();
dB.echoDebug("Denizen.mid not found, extracting from " + sourceFile);
Utilities.extractFile(new File(sourceFile), "Denizen.mid", System.getProperty("user.dir") + "/plugins/Denizen/Midi/");
}

// Warn if configuration is outdated / too new
if (!getConfig().isSet("Config.Version") ||
getConfig().getInt("Config.Version", 0) != configVersion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1267,14 +1267,22 @@ public void registerCoreMembers() {
// must be a valid midi file with the extension '.mid'. It will continuously play the song as
// noteblock songs at the given location or group of players until the song ends. If no location or
// entitiy is specified, by default this will play for the attached player.
//
// Also, an example Midi song file has been included: "Denizen" by Black Coyote
// He made it just for us! Check out more of his amazing work at:
// http://www.youtube.com/user/BlaCoyProductions

// @Usage
// Use to play a midi song file on the current player
// - midi file:Denizen

// @Usage
// Use to play a midi song file at a given location
// - midi file:Mysong <player.location>
// - midi file:Denizen <player.location>

// @Usage
// Use to play a midi song file at a given location to the specified player
// - midi file:Mysong <server.list_online_players>
// - midi file:Denizen <server.list_online_players>

// -->
registerCoreMember(MidiCommand.class,
Expand Down
51 changes: 49 additions & 2 deletions src/main/java/net/aufdemrand/denizen/utilities/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
Expand Down Expand Up @@ -451,7 +452,7 @@ public static void setSignRotation(BlockState signState, String direction) {
* Check if a block location equals another location.
* @param block The block location to check for.
* @param location The location to check against.
* @return Whether or not the block location eqauls the location.
* @return Whether or not the block location equals the location.
*/

public static boolean isBlock(Location block, Location location) {
Expand All @@ -468,4 +469,50 @@ public static boolean isBlock(Location block, Location location) {

return true;
}
}

/**
* Extract a file from a zip or jar.
* @param jarFile The zip/jar file to use
* @param fileName Which file to extract
* @param destDir Where to extract it to
*/
public static void extractFile(File jarFile, String fileName, String destDir) {
java.util.jar.JarFile jar = null;
try {
jar = new java.util.jar.JarFile(jarFile);
java.util.Enumeration myEnum = jar.entries();
while (myEnum.hasMoreElements()) {
java.util.jar.JarEntry file = (java.util.jar.JarEntry) myEnum.nextElement();
if (file.getName().equalsIgnoreCase(fileName)) {
java.io.File f = new java.io.File(destDir + "/" + file.getName());
if (file.isDirectory()) {
continue;
}
java.io.InputStream is = jar.getInputStream(file);
java.io.FileOutputStream fos = new java.io.FileOutputStream(f);
while (is.available() > 0)
fos.write(is.read());
fos.close();
is.close();
return;
}
}
dB.echoError(fileName + " not found in the jar!");
}
catch (IOException e) {
if (dB.showStackTraces)
e.printStackTrace();
}
finally {
if (jar != null) {
try {
jar.close();
}
catch (IOException e) {
if (dB.showStackTraces)
e.printStackTrace();
}
}
}
}
}
Binary file added src/main/resources/Denizen.mid
Binary file not shown.

0 comments on commit 56b731d

Please sign in to comment.