diff --git a/.classpath b/.classpath deleted file mode 100644 index caa85aa..0000000 --- a/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/.gitignore b/.gitignore index 96374c4..bb82262 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,10 @@ $RECYCLE.BIN/ Network Trash Folder Temporary Items .apdisk +.idea/** +SketchMap-FULL.iml +SketchMap/SketchMap.iml +target/ +.classpath +.project +.settings \ No newline at end of file diff --git a/.project b/.project deleted file mode 100644 index eadb333..0000000 --- a/.project +++ /dev/null @@ -1,24 +0,0 @@ - - - SketchMap-FULL - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - - - plugin.yml - 1 - C:/build-path/plugin.yml - - - diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index a698e59..0000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3fd61cd --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +language: java +jdk: +- oraclejdk8 +sudo: false +addons: + apt: + packages: + - oracle-java8-installer +deploy: + provider: releases + api_key: + secure: n9m/falG9fjo2HyQv/4Tiy13sWG+zXSySt4pE1MHXkTMuyR3SqCKoKcSwNVpgCkF5dnZpCiWAd19JSkjUUDDoE5vVTqFC8yB4cO8IIdF7Z0gowOA5Pgs7idSFGrut8o/gUCJdHLoHE2tNQlKcTWXNWaEke9mqmCFiEbhy1Dak62qd0mS90il/9r4fmVcXlPT/COayBbLqFcVZQg7ppVhexoBWjy8VO7UYrl1xmiWu8aM4fO4gta38/5h7T6b3hfRKHJN3hJ4nnMwW0F26d0k2K3OYzojkWlY6i5xwxTIwDhGaXID89slUkAfQZ4At9yMsCbI+dj7jc2uz791AUookWTxcMhZ01O7y3dCRRSMOQ7CCnJftJ1Wx9BntyTGPP5H4144LtD8+kzf5A/jr0mcEYvALo6gfMjJ22XI7NnPk6dRpHoP3A8v5/m0Za+DfcmezBTfXDDMB2afzVVAdDaK1WbfFZeR8GRB5DfOqL9oEidxp3QZejKLAHRUCYATIqAWSRinyBNH+5aJTk8t2/++TurDpSOGCKuO986VoNe0bOX6TYIweKYC3b9vSQkCL3eD6px0lr3xvTaV3RvrVm1QXPVVwX89IIHgyTzCOLyZVwaBXdUqjTuLjqU2wAGlV/z1/lktixfkqaIxfX87BdxtvRPPl6xEgvnNYaxvHK4kGSk= + file: + - "./target/SketchMap.jar" + skip_cleanup: true + overwrite: true + on: + tags: true + repo: Craftstuebchen/SketchMap diff --git a/bin/com/mcplugindev/slipswhitley/sketchmap/SketchMapAPI.class b/bin/com/mcplugindev/slipswhitley/sketchmap/SketchMapAPI.class deleted file mode 100644 index 2c60bcd..0000000 Binary files a/bin/com/mcplugindev/slipswhitley/sketchmap/SketchMapAPI.class and /dev/null differ diff --git a/bin/com/mcplugindev/slipswhitley/sketchmap/SketchMapUtils.class b/bin/com/mcplugindev/slipswhitley/sketchmap/SketchMapUtils.class deleted file mode 100644 index 130d4a4..0000000 Binary files a/bin/com/mcplugindev/slipswhitley/sketchmap/SketchMapUtils.class and /dev/null differ diff --git a/bin/com/mcplugindev/slipswhitley/sketchmap/listener/PlayerListener.class b/bin/com/mcplugindev/slipswhitley/sketchmap/listener/PlayerListener.class deleted file mode 100644 index 842b370..0000000 Binary files a/bin/com/mcplugindev/slipswhitley/sketchmap/listener/PlayerListener.class and /dev/null differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d943ee1 --- /dev/null +++ b/pom.xml @@ -0,0 +1,63 @@ + + 4.0.0 + io.github.ebaldino + SketchMap + 3.3 + + UTF-8 + + + ${artifactId} + clean package install + + + maven-resources-plugin + 2.7 + + + maven-compiler-plugin + 3.5 + + 1.8 + 1.8 + + + + + + + + bukkit-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + vault-repo + http://nexus.hc.to/content/repositories/pub_releases + + + commons-io-repo + https://mvnrepository.com/artifact/commons-io/commons-io + + + + + commons-io + commons-io + 2.5 + provided + + + org.bukkit + bukkit + 1.12.2-R0.1-SNAPSHOT + provided + + + net.milkbowl.vault + VaultAPI + LATEST + provided + + + + diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/SketchMapAPI.java b/src/main/java/io/github/ebaldino/SketchMap/SketchMapAPI.java similarity index 79% rename from src/com/mcplugindev/slipswhitley/sketchmap/SketchMapAPI.java rename to src/main/java/io/github/ebaldino/SketchMap/SketchMapAPI.java index b90f379..0087ee5 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/SketchMapAPI.java +++ b/src/main/java/io/github/ebaldino/SketchMap/SketchMapAPI.java @@ -1,4 +1,9 @@ -package com.mcplugindev.slipswhitley.sketchmap; +package io.github.ebaldino.SketchMap; + +import io.github.ebaldino.SketchMap.file.SketchMapFileException; +import io.github.ebaldino.SketchMap.map.RelativeLocation; +import io.github.ebaldino.SketchMap.map.SketchMap; +import io.github.ebaldino.SketchMap.map.SketchMap.BaseFormat; import java.awt.image.BufferedImage; import java.io.File; @@ -14,11 +19,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import com.mcplugindev.slipswhitley.sketchmap.file.SketchMapFileException; -import com.mcplugindev.slipswhitley.sketchmap.map.RelativeLocation; -import com.mcplugindev.slipswhitley.sketchmap.map.SketchMap; -import com.mcplugindev.slipswhitley.sketchmap.map.SketchMap.BaseFormat; - public class SketchMapAPI { public static SketchMap getMapByID(String id) { @@ -64,10 +64,16 @@ public static List getOrderedItemSet(SketchMap map) { return items; } + /** + * loadSketchMapFromFile + * @param file + * @return + * @throws SketchMapFileException + */ public static SketchMap loadSketchMapFromFile(File file) throws SketchMapFileException { YamlConfiguration config = null; - try { + try { config = YamlConfiguration.loadConfiguration(file); } catch (Exception ex) { @@ -83,8 +89,7 @@ public static SketchMap loadSketchMapFromFile(File file) throws SketchMapFileExc "map-image", }; - - + for(String field : fieldSet) { if(!config.isSet(field)) { throw new SketchMapFileException("Unable to load SketchMap file \"" + file.getName() @@ -118,8 +123,10 @@ public static SketchMap loadSketchMapFromFile(File file) throws SketchMapFileExc + "\" invalid field \"map-collection\""); } + // All fields present, create new map Map mapCollection = new HashMap(); + // Load map from file, each pane is called a "map" here, so we're iterating through the panes in map-collection for(String map : mapList) { String[] split = map.split(" "); if(split.length != 2) { @@ -127,26 +134,30 @@ public static SketchMap loadSketchMapFromFile(File file) throws SketchMapFileExc + "\" cannot parse field in \"map-colection\""); } + // Get the location of the pane in the image's grid (matrix) RelativeLocation loc = RelativeLocation.fromString(split[0]); if(loc == null) { throw new SketchMapFileException("Unable to load SketchMap file \"" + file.getName() - + "\" cannot parse field in \"map-colection\""); + + "\" cannot parse field [0] in \"map-colection\""); } + // Get the pane's ID from file - this is the Minecraft map id for that map Short id = null; try { id = Short.parseShort(split[1]); } catch(Exception ex) { throw new SketchMapFileException("Unable to load SketchMap file \"" + file.getName() - + "\" cannot parse field in \"map-colection\""); + + "\" cannot parse field [1] in \"map-colection\""); } + // Save id and location mapCollection.put(id, loc); } + // Get base format (png, jpg) BaseFormat format = null; try { format = BaseFormat.valueOf(config.getString("base-format")); @@ -156,6 +167,7 @@ public static SketchMap loadSketchMapFromFile(File file) throws SketchMapFileExc + "\" cannot parse BaseFormat from field \"base-format\""); } + // Get the image in base64 string format, then decode to image String b64Img = config.getString("map-image"); if(b64Img == null) { throw new SketchMapFileException("Unable to load SketchMap file \"" + file.getName() @@ -172,13 +184,16 @@ public static SketchMap loadSketchMapFromFile(File file) throws SketchMapFileExc + "\" parse image from field \"map-image\""); } + // Get the first part of the filename to use as imageID (its name) String imageID = file.getName().substring(0, file.getName().lastIndexOf(".")); if(getMapByID(imageID) != null) { throw new SketchMapFileException("Unable to load SketchMap file \"" + file.getName() + "\" A SketchMap by that ID already exists."); } - return new SketchMap(image, imageID, yPanes, yPanes, publicProtected, format); + // Create the SketchMap - there was a bug here, 'yPanes, yPanes' instead of 'xPanes, yPanes' + // - AND it was missing the mapCollection parameter at the end, which caused to to use the wrong map creation method + return new SketchMap(image, imageID, xPanes, yPanes, publicProtected, format, mapCollection); } } diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/SketchMapPlugin.java b/src/main/java/io/github/ebaldino/SketchMap/SketchMapPlugin.java similarity index 83% rename from src/com/mcplugindev/slipswhitley/sketchmap/SketchMapPlugin.java rename to src/main/java/io/github/ebaldino/SketchMap/SketchMapPlugin.java index 8f9e0e0..bd0f83d 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/SketchMapPlugin.java +++ b/src/main/java/io/github/ebaldino/SketchMap/SketchMapPlugin.java @@ -1,12 +1,12 @@ -package com.mcplugindev.slipswhitley.sketchmap; +package io.github.ebaldino.SketchMap; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.plugin.java.JavaPlugin; -import com.mcplugindev.slipswhitley.sketchmap.command.SketchMapCommand; -import com.mcplugindev.slipswhitley.sketchmap.file.SketchMapLoader; -import com.mcplugindev.slipswhitley.sketchmap.listener.PlayerListener; +import io.github.ebaldino.SketchMap.command.SketchMapCommand; +import io.github.ebaldino.SketchMap.file.SketchMapLoader; +import io.github.ebaldino.SketchMap.listener.PlayerListener; public class SketchMapPlugin extends JavaPlugin { diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/SketchMapUtils.java b/src/main/java/io/github/ebaldino/SketchMap/SketchMapUtils.java similarity index 78% rename from src/com/mcplugindev/slipswhitley/sketchmap/SketchMapUtils.java rename to src/main/java/io/github/ebaldino/SketchMap/SketchMapUtils.java index c7058e4..41ad985 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/SketchMapUtils.java +++ b/src/main/java/io/github/ebaldino/SketchMap/SketchMapUtils.java @@ -1,21 +1,9 @@ -package com.mcplugindev.slipswhitley.sketchmap; - -import java.awt.Graphics2D; -import java.awt.Image; -import java.awt.image.BufferedImage; -import java.awt.image.RenderedImage; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.charset.StandardCharsets; -import java.util.Base64; - -import javax.imageio.ImageIO; +package io.github.ebaldino.SketchMap; import net.milkbowl.vault.permission.Permission; - import org.apache.commons.io.output.ByteArrayOutputStream; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.command.ConsoleCommandSender; @@ -23,6 +11,17 @@ import org.bukkit.map.MapView; import org.bukkit.plugin.RegisteredServiceProvider; +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.awt.image.RenderedImage; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.HashSet; + public class SketchMapUtils { /** @@ -50,11 +49,15 @@ public static BufferedImage resize(Image img, Integer width, Integer height) { } - public static String imgToBase64String(final RenderedImage img, final String formatName) { + public static String imgToBase64String(final RenderedImage img, final String formatName) { + final ByteArrayOutputStream os = new ByteArrayOutputStream(); try { ImageIO.write(img, formatName, Base64.getEncoder().wrap(os)); return os.toString(StandardCharsets.ISO_8859_1.name()); + // Alternatively: + //ImageIO.write(img, formatName, os); + //return Base64.getEncoder().encodeToString(os.toByteArray()); } catch (final IOException ioe) { throw new UncheckedIOException(ioe); } @@ -67,14 +70,32 @@ public static BufferedImage base64StringToImg(final String base64String) { throw new UncheckedIOException(ioe); } } + + /** + * + * Deal with transparcy issue in jpg images + * + */ + public static BufferedImage fillTransparentPixels( BufferedImage image, Color fillColor ) { + int w = image.getWidth(); + int h = image.getHeight(); + BufferedImage image2 = new BufferedImage(w, h, + BufferedImage.TYPE_INT_RGB); + Graphics2D g = image2.createGraphics(); + g.setColor(fillColor); + g.fillRect(0,0,w,h); + g.drawRenderedImage(image, null); + g.dispose(); + return image2; + } + /** * * Permissions / Vault * - */ - + */ private static Permission permission; @@ -104,6 +125,18 @@ public static boolean hasPermission(Player player, String permission) { } + public static Block getTargetBlock(Player player, int i) { + return player.getTargetBlock((HashSet)null, i); + } + + + /** + * + */ + + public static World getDefaultWorld() { + return Bukkit.getWorlds().get(0); + } /** * Deprecated Methods Here :'c @@ -123,21 +156,8 @@ public static MapView getMapView(short id) { return Bukkit.createMap(getDefaultWorld()); } - - @SuppressWarnings("deprecation") - public static Block getTargetBlock(Player player, int i) { - return player.getTargetBlock(null, i); - } - - - /** - * - */ - - public static World getDefaultWorld() { - return Bukkit.getWorlds().get(0); - } + diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/command/SketchMapCommand.java b/src/main/java/io/github/ebaldino/SketchMap/command/SketchMapCommand.java similarity index 90% rename from src/com/mcplugindev/slipswhitley/sketchmap/command/SketchMapCommand.java rename to src/main/java/io/github/ebaldino/SketchMap/command/SketchMapCommand.java index 1366b56..07bed1d 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/command/SketchMapCommand.java +++ b/src/main/java/io/github/ebaldino/SketchMap/command/SketchMapCommand.java @@ -1,4 +1,4 @@ -package com.mcplugindev.slipswhitley.sketchmap.command; +package io.github.ebaldino.SketchMap.command; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -6,7 +6,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import com.mcplugindev.slipswhitley.sketchmap.SketchMapUtils; +import io.github.ebaldino.SketchMap.SketchMapUtils; public class SketchMapCommand implements CommandExecutor{ @@ -14,7 +14,6 @@ public SketchMapCommand() { SketchMapSubCommand.loadCommands(); } - @Override public boolean onCommand(CommandSender sender, Command cmd, String lable, String[] args) { diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/command/SketchMapSubCommand.java b/src/main/java/io/github/ebaldino/SketchMap/command/SketchMapSubCommand.java similarity index 62% rename from src/com/mcplugindev/slipswhitley/sketchmap/command/SketchMapSubCommand.java rename to src/main/java/io/github/ebaldino/SketchMap/command/SketchMapSubCommand.java index 020ce84..f78e437 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/command/SketchMapSubCommand.java +++ b/src/main/java/io/github/ebaldino/SketchMap/command/SketchMapSubCommand.java @@ -1,17 +1,17 @@ -package com.mcplugindev.slipswhitley.sketchmap.command; +package io.github.ebaldino.SketchMap.command; import java.util.ArrayList; import java.util.List; import org.bukkit.command.CommandSender; -import com.mcplugindev.slipswhitley.sketchmap.command.sub.SubCommandCreate; -import com.mcplugindev.slipswhitley.sketchmap.command.sub.SubCommandDelete; -import com.mcplugindev.slipswhitley.sketchmap.command.sub.SubCommandGet; -import com.mcplugindev.slipswhitley.sketchmap.command.sub.SubCommandHelp; -import com.mcplugindev.slipswhitley.sketchmap.command.sub.SubCommandImport; -import com.mcplugindev.slipswhitley.sketchmap.command.sub.SubCommandList; -import com.mcplugindev.slipswhitley.sketchmap.command.sub.SubCommandPlace; +import io.github.ebaldino.SketchMap.command.sub.SubCommandCreate; +import io.github.ebaldino.SketchMap.command.sub.SubCommandDelete; +import io.github.ebaldino.SketchMap.command.sub.SubCommandGet; +import io.github.ebaldino.SketchMap.command.sub.SubCommandHelp; +import io.github.ebaldino.SketchMap.command.sub.SubCommandImport; +import io.github.ebaldino.SketchMap.command.sub.SubCommandList; +import io.github.ebaldino.SketchMap.command.sub.SubCommandPlace; public abstract class SketchMapSubCommand { diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandCreate.java b/src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandCreate.java similarity index 92% rename from src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandCreate.java rename to src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandCreate.java index c114a41..8faf285 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandCreate.java +++ b/src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandCreate.java @@ -1,4 +1,4 @@ -package com.mcplugindev.slipswhitley.sketchmap.command.sub; +package io.github.ebaldino.SketchMap.command.sub; import java.awt.image.BufferedImage; import java.io.IOException; @@ -12,10 +12,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import com.mcplugindev.slipswhitley.sketchmap.SketchMapAPI; -import com.mcplugindev.slipswhitley.sketchmap.command.SketchMapSubCommand; -import com.mcplugindev.slipswhitley.sketchmap.map.SketchMap; -import com.mcplugindev.slipswhitley.sketchmap.map.SketchMap.BaseFormat; +import io.github.ebaldino.SketchMap.SketchMapAPI; +import io.github.ebaldino.SketchMap.command.SketchMapSubCommand; +import io.github.ebaldino.SketchMap.map.SketchMap; +import io.github.ebaldino.SketchMap.map.SketchMap.BaseFormat; public class SubCommandCreate extends SketchMapSubCommand { diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandDelete.java b/src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandDelete.java similarity index 82% rename from src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandDelete.java rename to src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandDelete.java index 2f720a3..4187c56 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandDelete.java +++ b/src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandDelete.java @@ -1,11 +1,11 @@ -package com.mcplugindev.slipswhitley.sketchmap.command.sub; +package io.github.ebaldino.SketchMap.command.sub; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import com.mcplugindev.slipswhitley.sketchmap.SketchMapAPI; -import com.mcplugindev.slipswhitley.sketchmap.command.SketchMapSubCommand; -import com.mcplugindev.slipswhitley.sketchmap.map.SketchMap; +import io.github.ebaldino.SketchMap.SketchMapAPI; +import io.github.ebaldino.SketchMap.command.SketchMapSubCommand; +import io.github.ebaldino.SketchMap.map.SketchMap; public class SubCommandDelete extends SketchMapSubCommand { diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandGet.java b/src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandGet.java similarity index 88% rename from src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandGet.java rename to src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandGet.java index 215ca76..d2f485f 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandGet.java +++ b/src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandGet.java @@ -1,4 +1,4 @@ -package com.mcplugindev.slipswhitley.sketchmap.command.sub; +package io.github.ebaldino.SketchMap.command.sub; import java.util.List; @@ -9,9 +9,9 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import com.mcplugindev.slipswhitley.sketchmap.SketchMapAPI; -import com.mcplugindev.slipswhitley.sketchmap.command.SketchMapSubCommand; -import com.mcplugindev.slipswhitley.sketchmap.map.SketchMap; +import io.github.ebaldino.SketchMap.SketchMapAPI; +import io.github.ebaldino.SketchMap.command.SketchMapSubCommand; +import io.github.ebaldino.SketchMap.map.SketchMap; public class SubCommandGet extends SketchMapSubCommand { diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandHelp.java b/src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandHelp.java similarity index 87% rename from src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandHelp.java rename to src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandHelp.java index 6178364..b2b7793 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandHelp.java +++ b/src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandHelp.java @@ -1,10 +1,10 @@ -package com.mcplugindev.slipswhitley.sketchmap.command.sub; +package io.github.ebaldino.SketchMap.command.sub; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import com.mcplugindev.slipswhitley.sketchmap.SketchMapPlugin; -import com.mcplugindev.slipswhitley.sketchmap.command.SketchMapSubCommand; +import io.github.ebaldino.SketchMap.SketchMapPlugin; +import io.github.ebaldino.SketchMap.command.SketchMapSubCommand; public class SubCommandHelp extends SketchMapSubCommand { diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandImport.java b/src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandImport.java similarity index 90% rename from src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandImport.java rename to src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandImport.java index 332a108..2d8d24a 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandImport.java +++ b/src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandImport.java @@ -1,4 +1,4 @@ -package com.mcplugindev.slipswhitley.sketchmap.command.sub; +package io.github.ebaldino.SketchMap.command.sub; import java.awt.image.BufferedImage; import java.io.File; @@ -11,11 +11,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import com.mcplugindev.slipswhitley.sketchmap.SketchMapAPI; -import com.mcplugindev.slipswhitley.sketchmap.command.SketchMapSubCommand; -import com.mcplugindev.slipswhitley.sketchmap.file.SketchMapLoader; -import com.mcplugindev.slipswhitley.sketchmap.map.SketchMap; -import com.mcplugindev.slipswhitley.sketchmap.map.SketchMap.BaseFormat; +import io.github.ebaldino.SketchMap.SketchMapAPI; +import io.github.ebaldino.SketchMap.command.SketchMapSubCommand; +import io.github.ebaldino.SketchMap.file.SketchMapLoader; +import io.github.ebaldino.SketchMap.map.SketchMap; +import io.github.ebaldino.SketchMap.map.SketchMap.BaseFormat; public class SubCommandImport extends SketchMapSubCommand { @@ -78,7 +78,7 @@ public void onCommand(CommandSender sender, String[] args, String prefix) { File file = new File(SketchMapLoader.getDataFolder().toString() + "/" + args[2]); if(!file.exists()) { player.sendMessage(ChatColor.RED + prefix + "Could not find specified image file. " - + "Insure that you have typed the entire file name (Case sensitive including extension) correctly. " + + "Ensure that you have typed the entire file name (Case sensitive including extension) correctly. " + "This file should be located in the SketchMap plugin directory."); return; } diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandList.java b/src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandList.java similarity index 85% rename from src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandList.java rename to src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandList.java index b22efde..de22bcc 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandList.java +++ b/src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandList.java @@ -1,4 +1,4 @@ -package com.mcplugindev.slipswhitley.sketchmap.command.sub; +package io.github.ebaldino.SketchMap.command.sub; import java.util.ArrayList; import java.util.Collections; @@ -7,8 +7,8 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import com.mcplugindev.slipswhitley.sketchmap.command.SketchMapSubCommand; -import com.mcplugindev.slipswhitley.sketchmap.map.SketchMap; +import io.github.ebaldino.SketchMap.command.SketchMapSubCommand; +import io.github.ebaldino.SketchMap.map.SketchMap; public class SubCommandList extends SketchMapSubCommand { diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandPlace.java b/src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandPlace.java similarity index 92% rename from src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandPlace.java rename to src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandPlace.java index 314f659..c7523f5 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/command/sub/SubCommandPlace.java +++ b/src/main/java/io/github/ebaldino/SketchMap/command/sub/SubCommandPlace.java @@ -1,4 +1,4 @@ -package com.mcplugindev.slipswhitley.sketchmap.command.sub; +package io.github.ebaldino.SketchMap.command.sub; import java.util.HashSet; import java.util.Map; @@ -17,11 +17,11 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.map.MapView; -import com.mcplugindev.slipswhitley.sketchmap.SketchMapAPI; -import com.mcplugindev.slipswhitley.sketchmap.SketchMapUtils; -import com.mcplugindev.slipswhitley.sketchmap.command.SketchMapSubCommand; -import com.mcplugindev.slipswhitley.sketchmap.map.RelativeLocation; -import com.mcplugindev.slipswhitley.sketchmap.map.SketchMap; +import io.github.ebaldino.SketchMap.SketchMapAPI; +import io.github.ebaldino.SketchMap.SketchMapUtils; +import io.github.ebaldino.SketchMap.command.SketchMapSubCommand; +import io.github.ebaldino.SketchMap.map.RelativeLocation; +import io.github.ebaldino.SketchMap.map.SketchMap; public class SubCommandPlace extends SketchMapSubCommand { diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/file/FileManager.java b/src/main/java/io/github/ebaldino/SketchMap/file/FileManager.java similarity index 66% rename from src/com/mcplugindev/slipswhitley/sketchmap/file/FileManager.java rename to src/main/java/io/github/ebaldino/SketchMap/file/FileManager.java index cdbb0eb..d1c9b76 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/file/FileManager.java +++ b/src/main/java/io/github/ebaldino/SketchMap/file/FileManager.java @@ -1,5 +1,8 @@ -package com.mcplugindev.slipswhitley.sketchmap.file; +package io.github.ebaldino.SketchMap.file; +import java.awt.Color; +import java.awt.Transparency; +import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -7,11 +10,12 @@ import java.util.logging.Level; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.configuration.file.YamlConfiguration; -import com.mcplugindev.slipswhitley.sketchmap.SketchMapUtils; -import com.mcplugindev.slipswhitley.sketchmap.map.RelativeLocation; -import com.mcplugindev.slipswhitley.sketchmap.map.SketchMap; +import io.github.ebaldino.SketchMap.SketchMapUtils; +import io.github.ebaldino.SketchMap.map.RelativeLocation; +import io.github.ebaldino.SketchMap.map.SketchMap; public class FileManager { @@ -21,10 +25,10 @@ public class FileManager { private YamlConfiguration mapConfig; public FileManager(SketchMap sketchMap) { - this.sketchMap = sketchMap; - - mapFile = new File(SketchMapLoader.getMapsDirectory() + "/" + sketchMap.getID() + ".sketchmap"); + this.sketchMap = sketchMap; + mapFile = new File(SketchMapLoader.getMapsDirectory() + "/" + sketchMap.getID() + ".sketchmap"); + if(!mapFile.exists()) { try { mapFile.createNewFile(); @@ -35,8 +39,9 @@ public FileManager(SketchMap sketchMap) { return; } } - + try { + SketchMapUtils.sendColoredConsoleMessage(ChatColor.GREEN + "Loading map file: " + mapFile); mapConfig = YamlConfiguration.loadConfiguration(mapFile); } catch (Exception ex) { @@ -46,6 +51,7 @@ public FileManager(SketchMap sketchMap) { } public void save() { + // save() is quick if(mapConfig == null) { return; @@ -56,14 +62,20 @@ public void save() { mapConfig.set("public-protected", sketchMap.isPublicProtected()); List mapCollection = new ArrayList(); - for(RelativeLocation loc : sketchMap.getMapCollection().keySet()) { mapCollection.add(loc.toString() + " " + SketchMapUtils.getMapID(sketchMap.getMapCollection().get(loc))); } - + mapConfig.set("map-collection", mapCollection); mapConfig.set("base-format", sketchMap.getBaseFormat().toString()); - mapConfig.set("map-image", SketchMapUtils.imgToBase64String(sketchMap.getImage(), sketchMap.getBaseFormat().getExtension())); + + // First make sure the image doesn't have any transparent pixels + BufferedImage img = sketchMap.getImage(); + if( img.getColorModel().getTransparency() != Transparency.OPAQUE) { + img = SketchMapUtils.fillTransparentPixels(img, Color.WHITE); + } + mapConfig.set("map-image", SketchMapUtils.imgToBase64String(img, sketchMap.getBaseFormat().getExtension())); + //mapConfig.set("map-image", SketchMapUtils.imgToBase64String(sketchMap.getImage(), sketchMap.getBaseFormat().getExtension())); try { mapConfig.save(mapFile); @@ -71,6 +83,7 @@ public void save() { Bukkit.getLogger().log(Level.WARNING, "[SketchMap] Unable to save SketchMap file \"" + mapFile.getName() + "\" in SketchMaps folder.", e); } + } public void deleteFile() { diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/file/SketchMapFileException.java b/src/main/java/io/github/ebaldino/SketchMap/file/SketchMapFileException.java similarity index 78% rename from src/com/mcplugindev/slipswhitley/sketchmap/file/SketchMapFileException.java rename to src/main/java/io/github/ebaldino/SketchMap/file/SketchMapFileException.java index ab385e7..9869216 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/file/SketchMapFileException.java +++ b/src/main/java/io/github/ebaldino/SketchMap/file/SketchMapFileException.java @@ -1,4 +1,4 @@ -package com.mcplugindev.slipswhitley.sketchmap.file; +package io.github.ebaldino.SketchMap.file; public class SketchMapFileException extends Exception { diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/file/SketchMapLoader.java b/src/main/java/io/github/ebaldino/SketchMap/file/SketchMapLoader.java similarity index 86% rename from src/com/mcplugindev/slipswhitley/sketchmap/file/SketchMapLoader.java rename to src/main/java/io/github/ebaldino/SketchMap/file/SketchMapLoader.java index f8ba626..40478a6 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/file/SketchMapLoader.java +++ b/src/main/java/io/github/ebaldino/SketchMap/file/SketchMapLoader.java @@ -1,12 +1,10 @@ -package com.mcplugindev.slipswhitley.sketchmap.file; +package io.github.ebaldino.SketchMap.file; import java.io.File; import java.util.logging.Level; - import org.bukkit.Bukkit; - -import com.mcplugindev.slipswhitley.sketchmap.SketchMapAPI; -import com.mcplugindev.slipswhitley.sketchmap.SketchMapPlugin; +import io.github.ebaldino.SketchMap.SketchMapAPI; +import io.github.ebaldino.SketchMap.SketchMapPlugin; public class SketchMapLoader { diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/listener/PlayerListener.java b/src/main/java/io/github/ebaldino/SketchMap/listener/PlayerListener.java similarity index 75% rename from src/com/mcplugindev/slipswhitley/sketchmap/listener/PlayerListener.java rename to src/main/java/io/github/ebaldino/SketchMap/listener/PlayerListener.java index 2a267de..5aa5efa 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/listener/PlayerListener.java +++ b/src/main/java/io/github/ebaldino/SketchMap/listener/PlayerListener.java @@ -1,4 +1,4 @@ -package com.mcplugindev.slipswhitley.sketchmap.listener; +package io.github.ebaldino.SketchMap.listener; import org.bukkit.ChatColor; import org.bukkit.GameMode; @@ -12,21 +12,28 @@ import org.bukkit.inventory.meta.ItemMeta; public class PlayerListener implements Listener { - + @EventHandler public void onPlayerInteract(PlayerInteractEntityEvent event) { + + // If the player clicks on an emtpy fram with SkatchMap map in hand, + // the frame must receive the map's lore (id) + if(!(event.getRightClicked() instanceof ItemFrame)) { return; } ItemFrame iFrame = (ItemFrame) event.getRightClicked(); - ItemStack iHand = event.getPlayer().getItemInHand(); + ItemStack iHand = event.getPlayer().getInventory().getItemInMainHand(); if(iHand.getType() != Material.MAP) { return; } - String lore = iHand.getItemMeta().getLore().get(0); + String lore = null; + try { + lore = iHand.getItemMeta().getLore().get(0); + } catch (Exception e) {}; if(!ChatColor.stripColor(lore).startsWith("SketchMap ID:")) { return; @@ -58,7 +65,7 @@ public void onPlayerInteract(PlayerInteractEntityEvent event) { } if(iHand.getAmount() == 1) { - player.getInventory().setItemInHand(new ItemStack(Material.AIR)); + player.getInventory().setItemInMainHand(new ItemStack(Material.AIR)); return; } diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/map/ImageRenderer.java b/src/main/java/io/github/ebaldino/SketchMap/map/ImageRenderer.java similarity index 91% rename from src/com/mcplugindev/slipswhitley/sketchmap/map/ImageRenderer.java rename to src/main/java/io/github/ebaldino/SketchMap/map/ImageRenderer.java index decf6dc..a25aab2 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/map/ImageRenderer.java +++ b/src/main/java/io/github/ebaldino/SketchMap/map/ImageRenderer.java @@ -1,4 +1,4 @@ -package com.mcplugindev.slipswhitley.sketchmap.map; +package io.github.ebaldino.SketchMap.map; import java.awt.image.BufferedImage; diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/map/RelativeLocation.java b/src/main/java/io/github/ebaldino/SketchMap/map/RelativeLocation.java similarity index 92% rename from src/com/mcplugindev/slipswhitley/sketchmap/map/RelativeLocation.java rename to src/main/java/io/github/ebaldino/SketchMap/map/RelativeLocation.java index 2030b3a..6b21700 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/map/RelativeLocation.java +++ b/src/main/java/io/github/ebaldino/SketchMap/map/RelativeLocation.java @@ -1,4 +1,4 @@ -package com.mcplugindev.slipswhitley.sketchmap.map; +package io.github.ebaldino.SketchMap.map; public class RelativeLocation { diff --git a/src/com/mcplugindev/slipswhitley/sketchmap/map/SketchMap.java b/src/main/java/io/github/ebaldino/SketchMap/map/SketchMap.java similarity index 94% rename from src/com/mcplugindev/slipswhitley/sketchmap/map/SketchMap.java rename to src/main/java/io/github/ebaldino/SketchMap/map/SketchMap.java index 5b876e7..0d72880 100644 --- a/src/com/mcplugindev/slipswhitley/sketchmap/map/SketchMap.java +++ b/src/main/java/io/github/ebaldino/SketchMap/map/SketchMap.java @@ -1,4 +1,4 @@ -package com.mcplugindev.slipswhitley.sketchmap.map; +package io.github.ebaldino.SketchMap.map; import java.awt.image.BufferedImage; import java.util.HashMap; @@ -9,8 +9,8 @@ import org.bukkit.Bukkit; import org.bukkit.map.MapView; -import com.mcplugindev.slipswhitley.sketchmap.SketchMapUtils; -import com.mcplugindev.slipswhitley.sketchmap.file.FileManager; +import io.github.ebaldino.SketchMap.SketchMapUtils; +import io.github.ebaldino.SketchMap.file.FileManager; public class SketchMap { @@ -68,7 +68,6 @@ private void loadSketchMap() { public SketchMap(BufferedImage image, String mapID, int xPanes, int yPanes, boolean publicProtected, BaseFormat format, Map mapCollection) { - this.image = SketchMapUtils.resize(image, xPanes * 128, yPanes * 128); this.mapID = mapID; this.xPanes = xPanes; @@ -78,7 +77,7 @@ public SketchMap(BufferedImage image, String mapID, int xPanes, int yPanes, bool this.mapCollection = new HashMap(); this.fileManager = new FileManager(this); - + getLoadedMaps().add(this); loadSketchMap(mapCollection); @@ -105,7 +104,7 @@ private void initMap(int x, int y, MapView mapView) { mapView.getRenderers().clear(); mapView.addRenderer(new ImageRenderer(subImage)); - mapCollection.put(new RelativeLocation(x, y), mapView); + mapCollection.put(new RelativeLocation(x, y), mapView); } /** diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..89b474d --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,7 @@ +name: SketchMap +version: 3.3 +main: io.github.ebaldino.SketchMap.SketchMapPlugin +commands: + sketchmap: + description: SketchMap Core Command + usage: /sketchmap help