mirror of
https://github.com/SydMontague/ImageMaps.git
synced 2024-11-01 08:19:46 +01:00
added /imagemap <file> reload functionality
This commit is contained in:
parent
d823720b1c
commit
9c862aeed5
@ -1,7 +1,9 @@
|
||||
package de.craftlancer.imagemaps;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
@ -14,7 +16,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class FastSendTask extends BukkitRunnable implements Listener
|
||||
{
|
||||
private Map<UUID, Integer> status = new HashMap<UUID, Integer>();
|
||||
private Map<UUID, Queue<Short>> status = new HashMap<UUID, Queue<Short>>();
|
||||
private final ImageMaps plugin;
|
||||
private final int mapsPerRun;
|
||||
|
||||
@ -33,28 +35,17 @@ public class FastSendTask extends BukkitRunnable implements Listener
|
||||
|
||||
for (Player p : plugin.getServer().getOnlinePlayers())
|
||||
{
|
||||
int state = getStatus(p);
|
||||
Queue<Short> state = getStatus(p);
|
||||
|
||||
if (state >= plugin.getFastSendList().size())
|
||||
continue;
|
||||
for (int i = 0; i < mapsPerRun && !state.isEmpty(); i++)
|
||||
p.sendMap(plugin.getServer().getMap(state.poll()));
|
||||
}
|
||||
}
|
||||
|
||||
int i = mapsPerRun;
|
||||
|
||||
do
|
||||
private Queue<Short> getStatus(Player p)
|
||||
{
|
||||
p.sendMap(plugin.getServer().getMap(plugin.getFastSendList().get(state)));
|
||||
state++;
|
||||
}
|
||||
while (--i > 0 && state < plugin.getFastSendList().size());
|
||||
|
||||
status.put(p.getUniqueId(), state);
|
||||
}
|
||||
}
|
||||
|
||||
private int getStatus(Player p)
|
||||
{
|
||||
if(!status.containsKey(p.getUniqueId()))
|
||||
status.put(p.getUniqueId(), 0);
|
||||
if (!status.containsKey(p.getUniqueId()))
|
||||
status.put(p.getUniqueId(), new LinkedList<Short>(plugin.getFastSendList()));
|
||||
|
||||
return status.get(p.getUniqueId());
|
||||
}
|
||||
@ -62,7 +53,7 @@ public class FastSendTask extends BukkitRunnable implements Listener
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent e)
|
||||
{
|
||||
status.put(e.getPlayer().getUniqueId(), 0);
|
||||
status.put(e.getPlayer().getUniqueId(), new LinkedList<Short>(plugin.getFastSendList()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@ -70,4 +61,11 @@ public class FastSendTask extends BukkitRunnable implements Listener
|
||||
{
|
||||
status.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
public void addToQueue(short mapId)
|
||||
{
|
||||
for(Queue<Short> queue : status.values())
|
||||
queue.add(mapId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,6 +39,13 @@ public class ImageMapCommand implements TabExecutor
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
|
||||
if(args.length >= 2 && args[1].equalsIgnoreCase("reload"))
|
||||
{
|
||||
plugin.reloadImage(args[0]);
|
||||
sender.sendMessage("Image " + args[0] + " reloaded!");
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean fastsend = args.length >= 2 ? Boolean.parseBoolean(args[1]) : false;
|
||||
|
||||
plugin.startPlacing((Player) sender, args[0], fastsend);
|
||||
@ -51,10 +58,8 @@ public class ImageMapCommand implements TabExecutor
|
||||
/**
|
||||
* Get all values of a String array which start with a given String
|
||||
*
|
||||
* @param value
|
||||
* the given String
|
||||
* @param list
|
||||
* the array
|
||||
* @param value the given String
|
||||
* @param list the array
|
||||
* @return a List of all matches
|
||||
*/
|
||||
public static List<String> getMatches(String value, String[] list)
|
||||
|
@ -15,19 +15,26 @@ public class ImageMapRenderer extends MapRenderer
|
||||
|
||||
public ImageMapRenderer(BufferedImage image, int x1, int y1)
|
||||
{
|
||||
int x2 = 128;
|
||||
int y2 = 128;
|
||||
recalculateInput(image, x1, y1);
|
||||
}
|
||||
|
||||
if (x1 > image.getWidth() || y1 > image.getHeight())
|
||||
public void recalculateInput(BufferedImage input, int x1, int y1)
|
||||
{
|
||||
int x2 = ImageMaps.MAP_WIDTH;
|
||||
int y2 = ImageMaps.MAP_HEIGHT;
|
||||
|
||||
if (x1 > input.getWidth() || y1 > input.getHeight())
|
||||
return;
|
||||
|
||||
if (x1 + x2 >= image.getWidth())
|
||||
x2 = image.getWidth() - x1;
|
||||
if (x1 + x2 >= input.getWidth())
|
||||
x2 = input.getWidth() - x1;
|
||||
|
||||
if (y1 + y2 >= image.getHeight())
|
||||
y2 = image.getHeight() - y1;
|
||||
if (y1 + y2 >= input.getHeight())
|
||||
y2 = input.getHeight() - y1;
|
||||
|
||||
this.image = image.getSubimage(x1, y1, x2, y2);
|
||||
this.image = input.getSubimage(x1, y1, x2, y2);
|
||||
|
||||
first = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -29,9 +29,11 @@ import org.bukkit.map.MapView;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.mcstats.Metrics;
|
||||
|
||||
// TODO change whole images to fastsend/slowsend
|
||||
public class ImageMaps extends JavaPlugin implements Listener
|
||||
{
|
||||
public static final int MAP_WIDTH = 128;
|
||||
public static final int MAP_HEIGHT = 128;
|
||||
|
||||
private Map<String, PlacingCacheEntry> placing = new HashMap<String, PlacingCacheEntry>();
|
||||
private Map<Short, ImageMap> maps = new HashMap<Short, ImageMap>();
|
||||
private Map<String, BufferedImage> images = new HashMap<String, BufferedImage>();
|
||||
@ -116,8 +118,8 @@ public class ImageMaps extends JavaPlugin implements Listener
|
||||
|
||||
Block b = block.getRelative(face);
|
||||
|
||||
int width = (int) Math.ceil((double) image.getWidth() / (double) 128);
|
||||
int height = (int) Math.ceil((double) image.getHeight() / (double) 128);
|
||||
int width = (int) Math.ceil((double) image.getWidth() / (double) MAP_WIDTH);
|
||||
int height = (int) Math.ceil((double) image.getHeight() / (double) MAP_HEIGHT);
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
for (int y = 0; y < height; y++)
|
||||
@ -126,7 +128,7 @@ public class ImageMaps extends JavaPlugin implements Listener
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
for (int y = 0; y < height; y++)
|
||||
setItemFrame(b.getRelative(x * xMod, -y, x * zMod), image, face, x * 128, y * 128, cache);
|
||||
setItemFrame(b.getRelative(x * xMod, -y, x * zMod), image, face, x * MAP_WIDTH, y * MAP_HEIGHT, cache);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -162,10 +164,15 @@ public class ImageMaps extends JavaPlugin implements Listener
|
||||
ItemStack item = getMapItem(cache.getImage(), x, y, image);
|
||||
i.setItem(item);
|
||||
|
||||
if (cache.isFastSend() && !sendList.contains(item.getDurability()))
|
||||
sendList.add(item.getDurability());
|
||||
short id = item.getDurability();
|
||||
|
||||
maps.put(item.getDurability(), new ImageMap(cache.getImage(), x, y, sendList.contains(item.getDurability())));
|
||||
if (cache.isFastSend() && !sendList.contains(id))
|
||||
{
|
||||
sendList.add(id);
|
||||
sendTask.addToQueue(id);
|
||||
}
|
||||
|
||||
maps.put(id, new ImageMap(cache.getImage(), x, y, sendList.contains(id)));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -277,4 +284,28 @@ public class ImageMaps extends JavaPlugin implements Listener
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void reloadImage(String file)
|
||||
{
|
||||
images.remove(file);
|
||||
BufferedImage image = loadImage(file);
|
||||
|
||||
int width = (int) Math.ceil((double) image.getWidth() / (double) MAP_WIDTH);
|
||||
int height = (int) Math.ceil((double) image.getHeight() / (double) MAP_HEIGHT);
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
short id = getMapItem(file, x * MAP_WIDTH, y * MAP_HEIGHT, image).getDurability();
|
||||
MapView map = getServer().getMap(id);
|
||||
|
||||
for (MapRenderer renderer : map.getRenderers())
|
||||
if (renderer instanceof ImageMapRenderer)
|
||||
((ImageMapRenderer) renderer).recalculateInput(image, x * MAP_WIDTH, y * MAP_HEIGHT);
|
||||
|
||||
sendTask.addToQueue(id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,9 @@ version: ${project.version}
|
||||
name: ImageMaps
|
||||
commands:
|
||||
imagemap:
|
||||
usage: "/imagemap <file> - then rightlick on a block"
|
||||
usage: |
|
||||
/imagemap <file> <fastsend> - then rightlick on a block, fastsend is either true or false
|
||||
/imagemap <file> reload - reloads the imagefile
|
||||
permission: imagemaps.use
|
||||
permissions:
|
||||
imagemaps.use:
|
||||
|
Loading…
Reference in New Issue
Block a user