mirror of
https://github.com/SydMontague/ImageMaps.git
synced 2024-10-31 16:00:00 +01:00
Added ImagePlaceEvent
This commit is contained in:
parent
1d44dea49e
commit
0fc7586df3
@ -15,6 +15,7 @@ import java.util.logging.Level;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -79,7 +80,7 @@ public class ImageMaps extends JavaPlugin implements Listener {
|
||||
placing.put(p.getUniqueId(), new PlacingCacheEntry(image, fastsend, scale));
|
||||
}
|
||||
|
||||
public boolean placeImage(Block block, BlockFace face, PlacingCacheEntry cache) {
|
||||
public boolean placeImage(Player player, Block block, BlockFace face, PlacingCacheEntry cache) {
|
||||
int xMod = 0;
|
||||
int zMod = 0;
|
||||
|
||||
@ -113,6 +114,11 @@ public class ImageMaps extends JavaPlugin implements Listener {
|
||||
int width = (int) Math.ceil((double) image.getWidth() / (double) MAP_WIDTH * cache.getScale() - 0.0001);
|
||||
int height = (int) Math.ceil((double) image.getHeight() / (double) MAP_HEIGHT * cache.getScale() - 0.0001);
|
||||
|
||||
ImagePlaceEvent event = new ImagePlaceEvent(player, block, face, width, height, cache);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if(event.isCancelled())
|
||||
return false;
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
for (int y = 0; y < height; y++) {
|
||||
if (!block.getRelative(x * xMod, -y, x * zMod).getType().isSolid())
|
||||
@ -151,7 +157,7 @@ public class ImageMaps extends JavaPlugin implements Listener {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||
return;
|
||||
|
||||
if (!placeImage(e.getClickedBlock(), e.getBlockFace(), placing.get(e.getPlayer().getUniqueId())))
|
||||
if (!placeImage(e.getPlayer(), e.getClickedBlock(), e.getBlockFace(), placing.get(e.getPlayer().getUniqueId())))
|
||||
e.getPlayer().sendMessage(ChatColor.RED + "Can't place the image here!\nMake sure the area is large enough, unobstructed and without pre-existing hanging entities.");
|
||||
else
|
||||
saveMaps();
|
||||
|
74
src/main/java/de/craftlancer/imagemaps/ImagePlaceEvent.java
Normal file
74
src/main/java/de/craftlancer/imagemaps/ImagePlaceEvent.java
Normal file
@ -0,0 +1,74 @@
|
||||
package de.craftlancer.imagemaps;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class ImagePlaceEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final Player player;
|
||||
private final Block block;
|
||||
private final BlockFace face;
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final PlacingCacheEntry cache;
|
||||
|
||||
private boolean cancelled;
|
||||
|
||||
public ImagePlaceEvent(Player player, Block block, BlockFace face, int width, int height, PlacingCacheEntry cache) {
|
||||
this.player = player;
|
||||
this.block = block;
|
||||
this.face = face;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public BlockFace getFace() {
|
||||
return face;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public PlacingCacheEntry getCacheEntry() {
|
||||
return cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return getHandlerList();
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -2,9 +2,9 @@ package de.craftlancer.imagemaps;
|
||||
|
||||
public class PlacingCacheEntry
|
||||
{
|
||||
private String image;
|
||||
private boolean fastsend;
|
||||
private double scale;
|
||||
private final String image;
|
||||
private final boolean fastsend;
|
||||
private final double scale;
|
||||
|
||||
public PlacingCacheEntry(String image, boolean fastsend, double scale)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user