Create systems to automatically create and destroy branding boards, as well as implement the Logitech branding

This commit is contained in:
AlexTheCoder 2016-04-30 19:26:16 -04:00
parent 01bc9e9e6b
commit 070326e72d
6 changed files with 403 additions and 53 deletions

View File

@ -0,0 +1,80 @@
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;
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;
}
public void createPost(Location location, BlockFace facing, String imageFileName)
{
BufferedImage img = getImage(imageFileName);
if (img == null)
{
System.out.println("ERROR! Invalid image file name!");
}
BrandingPost bp = new BrandingPost(location, facing, img);
bp.spawn();
_posts.put(_posts.size(), bp);
}
public void reset()
{
disable();
}
@Override
public void disable()
{
for (Integer key : _posts.keySet())
{
_posts.remove(key).despawn();
}
}
}

View File

@ -0,0 +1,188 @@
package mineplex.core.sponsorbranding;
import java.awt.image.BufferedImage;
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;
public class BrandingPost
{
private Location _center;
private BlockFace _facing;
private BufferedImage _img;
private Location[] _corners;
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;
}
@SuppressWarnings("deprecation")
public void spawn()
{
Location corner1 = _center.clone();
Location corner2 = _center.clone();
Location corner3 = _center.clone();
Location corner4 = _center.clone();
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());
}
}
}
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);
}
}
}
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:
System.out.println("ERROR! Invalid BlockFace given while loading BrandingPost!");
return;
}
Block centerspawn = corner1.getBlock().getRelative(_facing);
int width = (int) Math.ceil(_img.getWidth() / 128);
int height = (int) Math.ceil(_img.getHeight() / 128);
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
if (!centerspawn.getRelative(x * xMod, -y, x * zMod).getType().isSolid())
return;
if (centerspawn.getRelative(x * xMod - zMod, -y, x * zMod + xMod).getType().isSolid())
return;
}
}
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
Block spawn = centerspawn.getRelative(x * xMod, -y, x * zMod);
ItemFrame ent = spawn.getWorld().spawn(spawn.getLocation(), ItemFrame.class);
ent.setFacingDirection(_facing, false);
ItemStack map = getMapItem(x * 128, y * 128, _img);
ent.setItem(map);
}
}
}
public void despawn()
{
Bukkit.broadcastMessage("CLEAR START");
if (_corners != null)
{
Bukkit.broadcastMessage("CLEAR APPROVED");
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].getBlockY(), _corners[3].getBlockY()); z >= Math.min(_corners[2].getBlockY(), _corners[3].getBlockY()); z--)
{
Location set = new Location(_center.getWorld(), x, y, z);
set.getBlock().setType(Material.AIR);
}
}
}
}
}
}

View File

@ -0,0 +1,56 @@
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;
public class LogoMapRenderer extends MapRenderer
{
private Image _img;
private boolean _first = true;
public LogoMapRenderer(BufferedImage image, int x1, int y1)
{
recalculateInput(image, x1, y1);
}
public void recalculateInput(BufferedImage input, int x1, int y1)
{
int x2 = 128;
int y2 = 128;
if (x1 > input.getWidth() || y1 > input.getHeight())
{
return;
}
if (x1 + x2 >= input.getWidth())
{
x2 = input.getWidth() - x1;
}
if (y1 + y2 >= input.getHeight())
{
y2 = input.getHeight() - y1;
}
_img = input.getSubimage(x1, y1, x2, y2);
_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; 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.CustomTagFix;
import mineplex.core.PacketsInteractionFix; import mineplex.core.PacketsInteractionFix;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
@ -46,12 +42,12 @@ import mineplex.core.punish.Punish;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.resourcepack.ResourcePackManager; import mineplex.core.resourcepack.ResourcePackManager;
import mineplex.core.serverConfig.ServerConfiguration; import mineplex.core.serverConfig.ServerConfiguration;
import mineplex.core.sponsorbranding.BrandingManager;
import mineplex.core.stats.StatsManager; import mineplex.core.stats.StatsManager;
import mineplex.core.status.ServerStatusManager; import mineplex.core.status.ServerStatusManager;
import mineplex.core.task.TaskManager; import mineplex.core.task.TaskManager;
import mineplex.core.teleport.Teleport; import mineplex.core.teleport.Teleport;
import mineplex.core.titangiveaway.TitanGiveawayManager; import mineplex.core.titangiveaway.TitanGiveawayManager;
import mineplex.core.tournament.TournamentManager;
import mineplex.core.updater.FileUpdater; import mineplex.core.updater.FileUpdater;
import mineplex.core.updater.Updater; import mineplex.core.updater.Updater;
import mineplex.core.velocity.VelocityFix; 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.damage.DamageManager;
import mineplex.minecraft.game.core.fire.Fire; 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 public class Hub extends JavaPlugin implements IRelation
{ {
private String WEB_CONFIG = "webServer"; private String WEB_CONFIG = "webServer";
@ -190,6 +192,9 @@ public class Hub extends JavaPlugin implements IRelation
//Updates //Updates
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1); 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 @Override

View File

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

View File

@ -5,52 +5,6 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map.Entry; 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.Rank;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
@ -93,6 +47,53 @@ import nautilus.game.arcade.managers.chat.ChatStatData;
import nautilus.game.arcade.stats.BlockPlaceStatTracker; import nautilus.game.arcade.stats.BlockPlaceStatTracker;
import net.minecraft.server.v1_8_R3.PacketPlayOutGameStateChange; 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 public class SpeedBuilders extends SoloGame
{ {
private static final String GUARDIAN_NAME = "Gwen the Guardian"; private static final String GUARDIAN_NAME = "Gwen the Guardian";
@ -181,6 +182,9 @@ public class SpeedBuilders extends SoloGame
InventoryClick = true; InventoryClick = true;
manager.getBrandingManager().reset();
manager.getBrandingManager().createPost(new Location(Bukkit.getWorld("world"), 17, 103, -11), BlockFace.WEST, "logitech.jpg");
registerStatTrackers( registerStatTrackers(
new DependableTracker(this), new DependableTracker(this),
new FirstBuildTracker(this), new FirstBuildTracker(this),
@ -195,6 +199,15 @@ public class SpeedBuilders extends SoloGame
); );
} }
@EventHandler
public void onEnd(GameStateChangeEvent event)
{
if (event.GetState() == GameState.End || event.GetState() == GameState.Dead)
{
Manager.getBrandingManager().reset();
}
}
@Override @Override
public void ParseData() public void ParseData()
{ {