Merge pull request #46 from Mineplex-LLC/feature/logitech-brand

Branding Billboard System
This commit is contained in:
Conrad 2016-05-01 19:58:56 -04:00
commit 0a340d1789
6 changed files with 438 additions and 53 deletions

View File

@ -0,0 +1,94 @@
package mineplex.core.sponsorbranding;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
import javax.imageio.ImageIO;
import mineplex.core.MiniPlugin;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.plugin.java.JavaPlugin;
/**
*
* Manager for creating billboards with branding logos
*/
public class BrandingManager extends MiniPlugin
{
private ConcurrentHashMap<Integer, BrandingPost> _posts = new ConcurrentHashMap<Integer, BrandingPost>();
private ConcurrentHashMap<String, BufferedImage> _imgCache = new ConcurrentHashMap<String, BufferedImage>();
public BrandingManager(JavaPlugin plugin)
{
super("Branding Manager", plugin);
}
private BufferedImage getImage(String fileName)
{
if (_imgCache.containsKey(fileName))
{
return _imgCache.get(fileName);
}
File folder = new File("../../update");
File f = new File(folder, "logos" + File.separatorChar + fileName);
BufferedImage image = null;
if (!f.exists())
{
return null;
}
try
{
image = ImageIO.read(f);
_imgCache.put(fileName, image);
}
catch (IOException e)
{
e.printStackTrace();
}
return image;
}
/**
* Generates a billboard with a stored logo
* @param location The center of the billboard
* @param facing The BlockFace the logo will appear on
* @param imageFileName The file name of the logo's base image
*/
public void createPost(Location location, BlockFace facing, String imageFileName)
{
BufferedImage img = getImage(imageFileName);
if (img == null)
{
System.out.println("ERROR! Invalid image file name!");
return;
}
BrandingPost bp = new BrandingPost(location, facing, img);
bp.spawn();
_posts.put(_posts.size(), bp);
}
/**
* Clears away all existing billboards
*/
public void reset()
{
disable();
}
@Override
public void disable()
{
for (Integer key : _posts.keySet())
{
_posts.remove(key).despawn();
}
}
}

View File

@ -0,0 +1,214 @@
package mineplex.core.sponsorbranding;
import java.awt.image.BufferedImage;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.ItemFrame;
import org.bukkit.inventory.ItemStack;
import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView;
import com.google.common.collect.Lists;
/**
* An instance of a billboard with all its required data
*/
public class BrandingPost
{
private Location _center;
private BlockFace _facing;
private BufferedImage _img;
private Location[] _corners;
private List<ItemFrame> _ents = Lists.newArrayList();
public BrandingPost(Location center, BlockFace facing, BufferedImage image)
{
_center = center;
_facing = facing;
_img = image;
}
@SuppressWarnings("deprecation")
private ItemStack getMapItem(int x, int y, BufferedImage image)
{
ItemStack item = new ItemStack(Material.MAP);
MapView map = Bukkit.getServer().createMap(Bukkit.getServer().getWorlds().get(0));
for (MapRenderer r : map.getRenderers())
{
map.removeRenderer(r);
}
map.addRenderer(new LogoMapRenderer(image, x, y));
item.setDurability(map.getId());
return item;
}
/**
* Generates a billboard using parameters from instance constructor
*/
@SuppressWarnings("deprecation")
public void spawn()
{
Location corner1 = _center.clone();
Location corner2 = _center.clone();
Location corner3 = _center.clone();
Location corner4 = _center.clone();
int width = (int) Math.ceil(_img.getWidth() / 128);
int height = (int) Math.ceil(_img.getHeight() / 128);
switch (_facing)
{
case EAST:
corner1.add(0, 1, -2);
corner2.add(0, -1, 2);
corner3.add(0, 2, -3);
corner4.add(0, -2, 3);
break;
case WEST:
corner1.add(0, 1, -2);
corner2.add(0, -1, 2);
corner3.add(0, 2, -3);
corner4.add(0, -2, 3);
break;
case SOUTH:
corner1.add(-2, 1, 0);
corner2.add(2, -1, 0);
corner3.add(-3, 2, 0);
corner4.add(3, -2, 0);
break;
case NORTH:
corner1.add(-2, 1, 0);
corner2.add(2, -1, 0);
corner3.add(-3, 2, 0);
corner4.add(3, -2, 0);
break;
default:
System.out.println("ERROR! Invalid BlockFace given while loading BrandingPost!");
return;
}
_corners = new Location[] {corner1, corner2, corner3, corner4};
for (int x = Math.max(corner1.getBlockX(), corner2.getBlockX()); x >= Math.min(corner1.getBlockX(), corner2.getBlockX()); x--)
{
for (int y = Math.max(corner1.getBlockY(), corner2.getBlockY()); y >= Math.min(corner1.getBlockY(), corner2.getBlockY()); y--)
{
for (int z = Math.max(corner1.getBlockZ(), corner2.getBlockZ()); z >= Math.min(corner1.getBlockZ(), corner2.getBlockZ()); z--)
{
Location set = new Location(_center.getWorld(), x, y, z);
set.getBlock().setType(Material.STAINED_CLAY);
set.getBlock().setData(DyeColor.LIGHT_BLUE.getWoolData());
}
}
}
int xMod = 0;
int zMod = 0;
switch (_facing)
{
case EAST:
zMod = -1;
break;
case WEST:
zMod = 1;
break;
case SOUTH:
xMod = 1;
break;
case NORTH:
xMod = -1;
break;
default:
break;
}
BufferedImage image = _img;
if (image == null)
{
System.out.println("ERROR! Invalid image given while loading BrandingPost!");
return;
}
Block base = corner1.getBlock().getRelative(_facing);
try
{
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
ItemFrame i = null;
Block block = base.getRelative(x * xMod, -y, x * zMod);
i = block.getWorld().spawn(block.getLocation(), ItemFrame.class);
i.setFacingDirection(_facing, false);
ItemStack item = getMapItem(x, y, _img);
i.setItem(item);
_ents.add(i);
}
}
}
catch (NullPointerException e)
{
Bukkit.broadcastMessage("ERROR! ItemFrame space already occupied!");
return;
}
for (int x = Math.max(corner3.getBlockX(), corner4.getBlockX()); x >= Math.min(corner3.getBlockX(), corner4.getBlockX()); x--)
{
for (int y = Math.max(corner3.getBlockY(), corner4.getBlockY()); y >= Math.min(corner3.getBlockY(), corner4.getBlockY()); y--)
{
for (int z = Math.max(corner3.getBlockZ(), corner4.getBlockZ()); z >= Math.min(corner3.getBlockZ(), corner4.getBlockZ()); z--)
{
Location set = new Location(_center.getWorld(), x, y, z);
if (set.getBlock().getType() == Material.STAINED_CLAY)
continue;
set.getBlock().setType(Material.WOOD);
set.getBlock().setData((byte)1);
}
}
}
}
/**
* Clears away all blocks and ItemFrames generated by this billboard
*/
public void despawn()
{
if (_corners != null)
{
for (int x = Math.max(_corners[2].getBlockX(), _corners[3].getBlockX()); x >= Math.min(_corners[2].getBlockX(), _corners[3].getBlockX()); x--)
{
for (int y = Math.max(_corners[2].getBlockY(), _corners[3].getBlockY()); y >= Math.min(_corners[2].getBlockY(), _corners[3].getBlockY()); y--)
{
for (int z = Math.max(_corners[2].getBlockZ(), _corners[3].getBlockZ()); z >= Math.min(_corners[2].getBlockZ(), _corners[3].getBlockZ()); z--)
{
Location set = new Location(_center.getWorld(), x, y, z);
set.getBlock().setType(Material.AIR);
}
}
}
}
for (ItemFrame it : _ents)
{
it.setItem(new ItemStack(Material.AIR));
it.remove();
}
_ents.clear();
}
}

View File

@ -0,0 +1,51 @@
package mineplex.core.sponsorbranding;
import java.awt.Image;
import java.awt.image.BufferedImage;
import org.bukkit.entity.Player;
import org.bukkit.map.MapCanvas;
import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView;
/**
* Renderer for each map panel of the full billboard logo
*/
public class LogoMapRenderer extends MapRenderer
{
private Image _img;
private boolean _first = true;
public LogoMapRenderer(BufferedImage image, int x1, int y1)
{
recalculateInput(image, x1, y1);
}
private void recalculateInput(BufferedImage input, int x1, int y1)
{
if (x1 > input.getWidth() || y1 > input.getHeight())
{
return;
}
int startX = Math.min(x1 * 128, input.getWidth());
startX = Math.max(input.getMinX(), startX);
int startY = Math.min(y1 * 128, input.getHeight());
startY = Math.max(input.getMinY(), startY);
_img = input.getSubimage(startX, startY, 128, 128);
_first = true;
}
@Override
public void render(MapView view, MapCanvas canvas, Player player)
{
if (_img != null && _first)
{
canvas.drawImage(0, 0, _img);
_first = false;
}
}
}

View File

@ -1,9 +1,5 @@
package mineplex.hub;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.CustomTagFix;
import mineplex.core.PacketsInteractionFix;
import mineplex.core.account.CoreClientManager;
@ -46,12 +42,12 @@ import mineplex.core.punish.Punish;
import mineplex.core.recharge.Recharge;
import mineplex.core.resourcepack.ResourcePackManager;
import mineplex.core.serverConfig.ServerConfiguration;
import mineplex.core.sponsorbranding.BrandingManager;
import mineplex.core.stats.StatsManager;
import mineplex.core.status.ServerStatusManager;
import mineplex.core.task.TaskManager;
import mineplex.core.teleport.Teleport;
import mineplex.core.titangiveaway.TitanGiveawayManager;
import mineplex.core.tournament.TournamentManager;
import mineplex.core.updater.FileUpdater;
import mineplex.core.updater.Updater;
import mineplex.core.velocity.VelocityFix;
@ -70,6 +66,12 @@ import mineplex.minecraft.game.core.combat.CombatManager;
import mineplex.minecraft.game.core.damage.DamageManager;
import mineplex.minecraft.game.core.fire.Fire;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Hub extends JavaPlugin implements IRelation
{
private String WEB_CONFIG = "webServer";
@ -190,6 +192,9 @@ public class Hub extends JavaPlugin implements IRelation
//Updates
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
BrandingManager brandingManager = new BrandingManager(this);
brandingManager.createPost(new Location(Bukkit.getWorld("world"), -2, 77, -33), BlockFace.SOUTH, "logitech.jpg");
}
@Override
@ -215,4 +220,4 @@ public class Hub extends JavaPlugin implements IRelation
{
return true;
}
}
}

View File

@ -53,6 +53,7 @@ import mineplex.core.reward.RewardData;
import mineplex.core.reward.RewardManager;
import mineplex.core.reward.RewardRarity;
import mineplex.core.reward.rewards.PetReward;
import mineplex.core.sponsorbranding.BrandingManager;
import mineplex.core.stats.StatsManager;
import mineplex.core.status.ServerStatusManager;
import mineplex.core.task.TaskManager;
@ -136,7 +137,6 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.util.Vector;
import net.minecraft.server.v1_8_R3.EntityLiving;
public class ArcadeManager extends MiniPlugin implements IRelation
{
@ -192,6 +192,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
private ResourcePackManager _resourcePackManager;
private CustomDataManager _customDataManager;
private Punish _punishmentManager;
private BrandingManager _brandingManager;
private IncognitoManager _incognitoManager;
@ -241,6 +242,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_explosionManager.SetDebris(false);
_conditionManager = new SkillConditionManager(plugin);
_brandingManager = new BrandingManager(plugin);
//Dont see a reason to ever just use the normal one
// if (serverConfig.GameList.contains(GameType.ChampionsDominate)
@ -484,6 +487,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
{
return _punishmentManager;
}
public BrandingManager getBrandingManager()
{
return _brandingManager;
}
public Portal GetPortal()
{

View File

@ -5,52 +5,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.ItemMergeEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.material.Bed;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
@ -93,6 +47,53 @@ import nautilus.game.arcade.managers.chat.ChatStatData;
import nautilus.game.arcade.stats.BlockPlaceStatTracker;
import net.minecraft.server.v1_8_R3.PacketPlayOutGameStateChange;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.ItemMergeEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.material.Bed;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
public class SpeedBuilders extends SoloGame
{
private static final String GUARDIAN_NAME = "Gwen the Guardian";
@ -181,6 +182,9 @@ public class SpeedBuilders extends SoloGame
InventoryClick = true;
manager.getBrandingManager().reset();
manager.getBrandingManager().createPost(new Location(Bukkit.getWorld("world"), 17, 103, -11), BlockFace.WEST, "logitech.jpg");
registerStatTrackers(
new DependableTracker(this),
new FirstBuildTracker(this),
@ -194,6 +198,15 @@ public class SpeedBuilders extends SoloGame
new ChatStatData("BlocksBroken", "Blocks Broken", true)
);
}
@EventHandler
public void onEnd(GameStateChangeEvent event)
{
if (event.GetState() == GameState.End || event.GetState() == GameState.Dead)
{
Manager.getBrandingManager().reset();
}
}
@Override
public void ParseData()