Skip to content

Commit

Permalink
v1.0.37
Browse files Browse the repository at this point in the history
  • Loading branch information
ZombieStriker authored Jul 29, 2018
1 parent 10dc210 commit b900a08
Show file tree
Hide file tree
Showing 6 changed files with 543 additions and 324 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.0.37
Added full 1.13 support

1.0.36
Added support for transparent images. You can now load item icons without having to break the blocks for the transparent pixels
Fixed blocks for custom resourcepacks
Expand Down
3 changes: 2 additions & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
main: me.zombie_striker.pixelprinter.PixelPrinter
version: 1.0.36
version: 1.0.37
name: PixelPrinter
api-version: 1.13
commands:
PixelPrinter:
description: Create images using blocks
Expand Down
157 changes: 110 additions & 47 deletions src/me/zombie_striker/pixelprinter/PixelPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,51 @@

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.*;
import java.util.*;

import javax.imageio.*;

import me.zombie_striker.pixelprinter.data.*;
import me.zombie_striker.pixelprinter.util.*;
import me.zombie_striker.pluginconstructor.*;
import me.zombie_striker.pluginconstructor.RGBBlockColor.Pixel;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.imageio.ImageIO;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.bukkit.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import me.zombie_striker.pixelprinter.data.FileCreatorData;
import me.zombie_striker.pixelprinter.util.AsyncImageHolder;
import me.zombie_striker.pixelprinter.util.GifHolder;
import me.zombie_striker.pixelprinter.util.SkinCreator;
import me.zombie_striker.pluginconstructor.Direction;
import me.zombie_striker.pluginconstructor.MapWallUtil;
import me.zombie_striker.pluginconstructor.MaterialData;
import me.zombie_striker.pluginconstructor.MojangAPI;
import me.zombie_striker.pluginconstructor.PluginConstructorAPI;
import me.zombie_striker.pluginconstructor.RGBBlockColor;
import me.zombie_striker.pluginconstructor.RGBBlockColor.Pixel;
import me.zombie_striker.pluginconstructor.RGBChatColor;
import me.zombie_striker.pluginconstructor.ReflectionUtilREMOVELATEER;

public class PixelPrinter extends JavaPlugin {

private String prefix = ChatColor.DARK_PURPLE + "[PixelPrinter]" + ChatColor.WHITE;
Expand All @@ -50,6 +74,8 @@ public class PixelPrinter extends JavaPlugin {

private static PixelPrinter instance;

public static boolean isAbove113 = false;

private static int skin_creator_delay = 0;

public static PixelPrinter getInstance() {
Expand All @@ -72,8 +98,10 @@ public void onEnable() {
// Download the API dependancy
try {
if (Bukkit.getPluginManager().getPlugin("PluginConstructorAPI") == null)
GithubDependDownloader.autoUpdate(this, new File(getDataFolder().getParentFile(),"PluginConstructorAPI.jar"), "ZombieStriker", "PluginConstructorAPI", "PluginConstructorAPI.jar");
//new DependencyDownloader(this, 276723);
GithubDependDownloader.autoUpdate(this,
new File(getDataFolder().getParentFile(), "PluginConstructorAPI.jar"), "ZombieStriker",
"PluginConstructorAPI", "PluginConstructorAPI.jar");
// new DependencyDownloader(this, 276723);
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -86,8 +114,8 @@ public void run() {
}.runTaskTimer(this, 0, 10);

instance = this;
images = new File(getDataFolder() ,"images");
resoucepackFolder = new File(getDataFolder() ,"custom_textures");
images = new File(getDataFolder(), "images");
resoucepackFolder = new File(getDataFolder(), "custom_textures");

Bukkit.getPluginManager().registerEvents(new PPListener(this), this);
if (!getDataFolder().exists())
Expand All @@ -106,6 +134,7 @@ public void run() {
try {
PluginConstructorAPI.loadCustomTextures(resoucepackFolder);
} catch (NoClassDefFoundError e) {
e.printStackTrace();
}

initHelp();
Expand All @@ -127,8 +156,7 @@ public void run() {
if (!getConfig().contains("whitelistedMaterialsEnabled") || !getConfig().contains("whitelistedMaterials")) {
supportedMaterials = null;
getConfig().set("whitelistedMaterialsEnabled", false);
getConfig().set("whitelistedMaterials",
Arrays.asList(Material.STONE.name(), Material.WOOL.name(), Material.NETHERRACK.name()));
getConfig().set("whitelistedMaterials", Arrays.asList(Material.STONE.name(), Material.NETHERRACK.name()));
List<String> fullanmes = new ArrayList<>();
for (Material m : Material.values()) {
if (m.isBlock())
Expand All @@ -147,6 +175,13 @@ public void run() {
} catch (Error | Exception e) {
}
}
} else {
supportedMaterials = null;
}
try {
isAbove113 = ReflectionUtilREMOVELATEER.isVersionHigherThan(1, 13);
} catch (Error | Exception e45) {

}

// bStats metrics
Expand Down Expand Up @@ -175,37 +210,44 @@ public String call() throws Exception {

public void run() {
for (GifHolder gif : gifs) {
nearPlayers = false;
if (gif == null) {
System.out.println("gif is null");
continue;
}
if (gif.isLoaded()) {
for (Player p : Bukkit.getOnlinePlayers()) {
if (p.getLocation().distance(gif.getMinCorner()) < 300) {
nearPlayers = true;
break;
}
try {
nearPlayers = false;
if (gif == null) {
System.out.println("gif is null");
continue;
}
if (nearPlayers) {
gif.loadFrame();
// gif.loadFrame();
if (gif.isLoaded()) {
for (Player p : Bukkit.getOnlinePlayers()) {
if (p.getLocation().distance(gif.getMinCorner()) < 300) {
nearPlayers = true;
break;
}
}
if (nearPlayers) {
gif.loadFrame();
// gif.loadFrame();
}
}
} catch (Exception e45) {
e45.printStackTrace();
}
}
}
// TODO: Doubling loadframe and the delay so it is less taxing on
// low end computers
}, 10, 8);
}, 10, 4);

/* final Updater updater = new Updater(instance, 98985, getConfig().getBoolean("auto-update"));*/
/*
* final Updater updater = new Updater(instance, 98985,
* getConfig().getBoolean("auto-update"));
*/
/*
* new BukkitRunnable() { public void run() { // TODO: Works well. Make changes
* for the updaters of // PixelPrinter and Music later. if
* (updater.updaterActive) updater.download(false); }
* }.runTaskTimerAsynchronously(this, 20 /* * 60 * /, 20 * 60 * 5);
*/
GithubUpdater.autoUpdate(this, "ZombieStriker", "PixelPrinter","PixelPrinter.jar");
GithubUpdater.autoUpdate(this, "ZombieStriker", "PixelPrinter", "PixelPrinter.jar");
}

public void onDisable() {
Expand Down Expand Up @@ -354,19 +396,39 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String

// ======================================================================DEBUG
else if (args[0].equalsIgnoreCase("debug")) {

// for(int i = 0; i < 20; i ++){
// sender.sendMessage(ChatColor.values()[i]+" :::: MM OO XX $$ CC **
// "+BLACK_BAR+BLACK_BAR);
// }
final Player player = (Player) sender;
new BukkitRunnable() {

@Override
public void run() {
player.sendMessage(RGBBlockColor.getFurthestColor() + "");
StringBuilder sb = new StringBuilder();
List<Material> loaded = new ArrayList<Material>();
for (MaterialData k : RGBBlockColor.materialValue.keySet()) {
if (!loaded.contains(k.getMaterial()))
loaded.add(k.getMaterial());
}
// int color = 0;
List<Material> mat = new ArrayList<Material>();
for (Material m : Material.values()) {
if (m.isBlock() && !m.isLegacy() && !loaded.contains(m) && !m.name().endsWith("SHULKER_BOX")
&& !m.name().endsWith("CORAL_FAN") && !m.name().endsWith("SAPLING")
&& !m.name().endsWith("_BANNER") && !m.name().endsWith("_HEAD")
&& !m.name().endsWith("CARPET") && !m.name().endsWith("STAINED_GLASS")
&& !m.name().endsWith("_TRAPDOOR") && !m.name().endsWith("RAIL")
&& !m.name().startsWith("INFESTED") && !m.name().endsWith("_BED")
&& !m.name().endsWith("_SLAB") && !m.name().endsWith("_STAIRS")
&& !m.name().endsWith("GLASS_PANE") && !m.name().endsWith("FENCE")
&& !m.name().endsWith("FENCE_GATE") && !m.name().endsWith("_BUTTON")
&& !m.name().endsWith("PRESSURE_PLATE") && !m.name().endsWith("_DOOR")) {
mat.add(m);
// sb.append(ccc[color] + m.name() + ", &"+ChatColor.RESET.getChar());
// color = (color+1) % ccc.length;
}
}.runTaskLaterAsynchronously(this, 0);
}
int size = ((mat.size() / 9) + 1) * 9;
if (size > 9 * 14)
size = 9 * 14;
Inventory test = Bukkit.createInventory(null, size);
for (Material a : mat)
test.addItem(new ItemStack(a));
((Player) sender).openInventory(test);
// Bukkit.broadcastMessage("unused " +
// ChatColor.translateAlternateColorCodes('&', sb.toString()));

} else if (args.length > 0 && args[0].equalsIgnoreCase("list")) {
sender.sendMessage(getPrefix() + " All the saved images:");
Expand Down Expand Up @@ -686,6 +748,7 @@ public void run() {
} catch (Exception e) {
sender.sendMessage(
getPrefix() + " Something failed. Please check console for more details.");
e.printStackTrace();
}
}
} catch (Exception e) {
Expand Down Expand Up @@ -838,7 +901,7 @@ public void createMapAnim(Direction dir, Player p, BufferedImage[] bi2, int heig
ItemStack[][] im = MapWallUtil.getMaps(bi2);
for (int x = 0; x < im.length; x++) {
for (int y = 0; y < im[x].length; y++) {
MapWallUtil.setBlockAt(dir, p, y, x, im[x][im[x].length - y - 1]);
MapWallUtil.setBlockAt(dir, p, y, x, im[x][(im[x].length - 1) - y]);
}
}
}
Expand Down
58 changes: 58 additions & 0 deletions src/me/zombie_striker/pixelprinter/data/DataHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package me.zombie_striker.pixelprinter.data;

import java.util.HashMap;
import java.util.Map;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.scheduler.BukkitRunnable;

import me.zombie_striker.pixelprinter.PixelPrinter;
import me.zombie_striker.pluginconstructor.MaterialData;

public class DataHolder implements ConfigurationSerializable {
public MaterialData md;
public Location b;
boolean hasFaces = false;

public DataHolder(Location b2, MaterialData md) {
this.b = b2;
this.md = md;
}
public DataHolder(Location b, MaterialData md, boolean hasFaces) {
this.b = b;
this.md = md;
this.hasFaces = hasFaces;
}

public DataHolder(Map<String, Object> data) {
final Map<String, Object> tempData = data;
new BukkitRunnable() {

@Override
public void run() {
if (Bukkit.getWorld((String) tempData.get("b.w")) != null) {
b = new Location(Bukkit.getWorld((String) tempData.get("b.w")), (int) tempData.get("b.x"),
(int) tempData.get("b.y"), (int) tempData.get("b.z"));
cancel();
}
}
}.runTaskTimer(PixelPrinter.getInstance(), 0, 20);
this.md = (MaterialData) data.get("md");
}

@Override
public Map<String, Object> serialize() {
Map<String, Object> data = new HashMap<String, Object>();
data.put("b.x", this.b.getBlockX());
data.put("b.y", this.b.getBlockY());
data.put("b.z", this.b.getBlockZ());
data.put("b.w", this.b.getWorld().getName());
data.put("md", this.md);
return data;
}
public boolean hasFaces() {
return hasFaces;
}
}
Loading

0 comments on commit b900a08

Please sign in to comment.