org.inventivetalent.mapmanager.manager.MapManager Java Examples

The following examples show how to use org.inventivetalent.mapmanager.manager.MapManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MapSender.java    From MapManager with MIT License 6 votes vote down vote up
protected static void runSender() {
	if (Bukkit.getScheduler().isQueued(senderID) || Bukkit.getScheduler().isCurrentlyRunning(senderID) || sendQueue.size() == 0) { return; }

	senderID = Bukkit.getScheduler().scheduleSyncRepeatingTask(MapManagerPlugin.instance, new Runnable() {

		@Override
		public void run() {
			if (sendQueue.isEmpty()) { return; }
			for (int i = 0; i < Math.min(sendQueue.size(), MapManager.Options.Sender.AMOUNT + 1); i++) {
				QueuedMap current = sendQueue.get(0);
				if (current == null) { return; }
				sendMap(current.id, current.image, current.player);
				if (!sendQueue.isEmpty()) {
					sendQueue.remove(0);
				}
			}
		}
	}, 0, MapManager.Options.Sender.DELAY);
}
 
Example #2
Source File: DefaultMapWrapper.java    From MapManager with MIT License 6 votes vote down vote up
@Override
public void update(ArrayImage content) {
	MapContentUpdateEvent event = new MapContentUpdateEvent(DefaultMapWrapper.this, content);
	Bukkit.getPluginManager().callEvent(event);

	if (event.getContent() != null) {
		if (MapManager.Options.CHECK_DUPLICATES) {
			MapWrapper duplicate = ((DefaultMapManager) ((MapManagerPlugin) Bukkit.getPluginManager().getPlugin("MapManager")).getMapManager()).getDuplicate(event.getContent());
			if (duplicate != null) {
				DefaultMapWrapper.this.content = duplicate.getContent();
				return;
			}
		}
		DefaultMapWrapper.this.content = event.getContent();
	}

	if (event.isSendContent()) {
		for (UUID id : viewers.keySet()) {
			sendContent(Bukkit.getPlayer(id));
		}
	}
}
 
Example #3
Source File: MapListener.java    From MapManager with MIT License 5 votes vote down vote up
@EventHandler
public void onMapInitialize(MapInitializeEvent event) {
	if (MapManager.Options.ALLOW_VANILLA) {
		short id = event.getMap().getId();
		if (id > MapManager.Options.FORCED_OFFSET) {
			if (MapManager.Options.FORCED_OFFSET > 0) {
				plugin.getLogger().warning("The configured forcedOffset has been exceeded. Increase the number in the config to keep future IDs from being overwritten.");
			}
			plugin.getLogger().finer("Adding new Map #" + id + " to occupied IDs.");
			plugin.getMapManager().registerOccupiedID(id);
		}
	}
}
 
Example #4
Source File: CreativeInventoryMapUpdateEvent.java    From MapManager with MIT License 5 votes vote down vote up
/**
 * @return the {@link MapWrapper} of the item
 */
public MapWrapper getMapWrapper() {
	if (this.mapWrapper != null) { return this.mapWrapper; }
	if (getItemStack() == null) { return null; }
	if (getItemStack().getType() != Material.MAP) { return null; }
	MapManager mapManager = ((MapManagerPlugin) Bukkit.getPluginManager().getPlugin("MapManager")).getMapManager();
	return this.mapWrapper = mapManager.getWrapperForId(getPlayer(), getItemStack().getDurability());
}
 
Example #5
Source File: MapSender.java    From MapManager with MIT License 5 votes vote down vote up
protected static void sendMap(final int id0, final ArrayImage image, final Player receiver) {
	if (MapManager.Options.Sender.TIMINGS) { TimingsHelper.startTiming("MapManager:sender:sendMap"); }
	if (receiver == null || !receiver.isOnline()) {

		List<QueuedMap> toRemove = new ArrayList<>();
		for (QueuedMap qMap : sendQueue) {
			if (qMap == null) { continue; }
			if (qMap.player == null || !qMap.player.isOnline()) {
				toRemove.add(qMap);
			}
		}
		Bukkit.getScheduler().cancelTask(senderID);
		sendQueue.removeAll(toRemove);

		if (MapManager.Options.Sender.TIMINGS) { TimingsHelper.stopTiming("MapManager:sender:sendMap"); }
		return;
	}

	final int id = -id0;

	Bukkit.getScheduler().runTaskAsynchronously(MapManagerPlugin.instance, new Runnable() {
		@Override
		public void run() {
			try {
				Object packet = constructPacket(id, image);
				sendPacket(packet, receiver);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	});
	TimingsHelper.stopTiming("MapManager:sender:sendMap");
}
 
Example #6
Source File: DefaultMapWrapper.java    From MapManager with MIT License 5 votes vote down vote up
@Override
public void sendContent(Player player, boolean withoutQueue) {
	if (!isViewing(player)) { return; }
	int id = getMapId(player);
	if (withoutQueue && MapManager.Options.Sender.ALLOW_QUEUE_BYPASS) {
		MapSender.sendMap(id, DefaultMapWrapper.this.content, player);
	} else {
		MapSender.addToQueue(id, DefaultMapWrapper.this.content, player);
	}
}
 
Example #7
Source File: MapManagerPlugin.java    From MapManager with MIT License 4 votes vote down vote up
/**
 * @return The {@link MapManager} instance
 */
public MapManager getMapManager() {
	if (mapManagerInstance == null) { throw new IllegalStateException("Manager not yet initialized"); }
	return mapManagerInstance;
}
 
Example #8
Source File: MapCancelEvent.java    From MapManager with MIT License 4 votes vote down vote up
public boolean isAllowVanilla() {
	return MapManager.Options.ALLOW_VANILLA;
}