org.bukkit.util.CachedServerIcon Java Examples

The following examples show how to use org.bukkit.util.CachedServerIcon. 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: BukkitPlugin.java    From ServerListPlus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Optional<CachedServerIcon> load(FaviconSource source) throws Exception {
    // Try loading the favicon
    BufferedImage image = FaviconHelper.loadSafely(core, source);
    if (image == null) return Optional.absent(); // Favicon loading failed
    else return Optional.of(getServer().loadServerIcon(image)); // Success!
}
 
Example #2
Source File: SpigotMiscUtils.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public String convertBukkitIconToBase64(CachedServerIcon icon) {
	if (icon == null) {
		return null;
	}
	if (!(icon instanceof CraftIconCache)) {
		throw new IllegalArgumentException(icon + " was not created by " + CraftServer.class);
	}
	return ((CraftIconCache) icon).value;
}
 
Example #3
Source File: ExprServerIcon.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("null")
@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
	PaperServerListPingEvent event = (PaperServerListPingEvent) e;
	switch (mode) {
		case SET:
			event.setServerIcon((CachedServerIcon) delta[0]);
			break;
		case RESET:
			event.setServerIcon(Bukkit.getServerIcon());
	}
}
 
Example #4
Source File: PaperServerListPingEvent.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public PaperServerListPingEvent(@Nonnull StatusClient client, String motd, int numPlayers, int maxPlayers,
                                @Nonnull String version, int protocolVersion, @Nullable CachedServerIcon favicon) {
    super(client.getAddress().getAddress(), motd, numPlayers, maxPlayers);
    this.client = client;
    this.numPlayers = numPlayers;
    this.version = version;
    this.protocolVersion = protocolVersion;
    setServerIcon(favicon);
}
 
Example #5
Source File: ExprServerIcon.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
	if (isServerPingEvent && !isDefault) {
		if (ScriptLoader.hasDelayBefore.isTrue()) {
			Skript.error("Can't change the server icon anymore after the server list ping event has already passed");
			return null;
		}
		if (mode == ChangeMode.SET || mode == ChangeMode.RESET)
			return CollectionUtils.array(CachedServerIcon.class);
	}
	return null;
}
 
Example #6
Source File: PaperServerListPingEvent.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the server icon sent to the client.
 *
 * @param icon The icon to send to the client, or {@code null} for none
 */
@Override
public void setServerIcon(@Nullable CachedServerIcon icon) {
    if (icon != null && icon.isEmpty()) {
        // Represent empty icons as null
        icon = null;
    }

    this.favicon = icon;
}
 
Example #7
Source File: ExprServerIcon.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public CachedServerIcon[] get(Event e) {
	CachedServerIcon icon = null;
	if ((isServerPingEvent && !isDefault) && PAPER_EVENT_EXISTS)
		icon = ((PaperServerListPingEvent) e).getServerIcon();
	else
		icon = Bukkit.getServerIcon();
	if (icon == null || icon.getData() == null)
		return null;
	return CollectionUtils.array(icon);
}
 
Example #8
Source File: AnimationRunnable.java    From PingAPI with MIT License 4 votes vote down vote up
public AnimationRunnable(PingEvent event, String motd, String playerCount, CachedServerIcon icon) {
    this.event = event;
    this.motd = motd;
    this.playerCount = playerCount;
    this.icon = icon;
}
 
Example #9
Source File: MockServer.java    From Chimera with MIT License 4 votes vote down vote up
@Override
public CachedServerIcon loadServerIcon(BufferedImage image) throws IllegalArgumentException, Exception {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
 
Example #10
Source File: MockServer.java    From SaneEconomy with GNU General Public License v3.0 4 votes vote down vote up
@Override
public CachedServerIcon getServerIcon() {
    return null;
}
 
Example #11
Source File: MockServer.java    From SaneEconomy with GNU General Public License v3.0 4 votes vote down vote up
@Override
public CachedServerIcon loadServerIcon(File file) {
    return null;
}
 
Example #12
Source File: MockServer.java    From SaneEconomy with GNU General Public License v3.0 4 votes vote down vote up
@Override
public CachedServerIcon loadServerIcon(BufferedImage bufferedImage) {
    return null;
}
 
Example #13
Source File: MyListener.java    From PingAPI with MIT License 4 votes vote down vote up
@Override
public void onPing(PingEvent event) {
	try {
	PingReply reply = event.getReply();
	if(config.getBoolean("Enabled")) {
		event.cancelPong(true);
		event.setCancelled(true);
		if(config.getBoolean("MOTD.Enabled")) {
			reply.setMOTD(ChatColor.translateAlternateColorCodes('&', this.defaultMOTD));
		}
		if(config.getBoolean("PlayerCount.Enabled")) {
			reply.setProtocolVersion(-1);
			reply.setProtocolName(ChatColor.translateAlternateColorCodes('&', this.defaultPlayerCount));
		}
		event.createNewPacket(reply).send();
		
		String lastMotd = (motds.isEmpty()) ? this.replaceVars(motds.get(motds.size() - 1)) : defaultMOTD;
		String lastPlayerCount = (!playerCounts.isEmpty()) ? this.replaceVars(playerCounts.get(playerCounts.size() - 1)) : defaultPlayerCount;
		CachedServerIcon lastIcon = (!icons.isEmpty()) ? Bukkit.loadServerIcon(new File(this.plugin.getDataFolder() + icons.get(icons.size() - 1))) : Bukkit.getServerIcon();
		
		int largest = Collections.max(Arrays.asList(motds.size(), playerCounts.size(), icons.size()));
		event.createNewPacket(reply).send();
		for(int i = 0; i < largest; i++) {
			String motd = null;
			String playerCount = null;
			CachedServerIcon icon = Bukkit.getServerIcon();
			if(config.getBoolean("MOTD.Enabled")) {
				motd = (motds.size() > i) ? this.replaceVars(motds.get(i)) : lastMotd;
			}
			if(config.getBoolean("PlayerCount.Enabled")) {
				playerCount = (playerCounts.size() > i) ? this.replaceVars(playerCounts.get(i)) : lastPlayerCount;
			}
			if(config.getBoolean("Icon.Enabled")) {
				icon = (icons.size() > i) ? Bukkit.loadServerIcon(new File(this.plugin.getDataFolder() + icons.get(i))) : lastIcon;
			}
			new AnimationRunnable(event, motd, playerCount, icon).runTaskLater(plugin, i * ticks);
        }
		new PongRunnable(event).runTaskLater(plugin, largest * ticks);
	}
	} catch(Exception e) {
		e.printStackTrace();
	}
}
 
Example #14
Source File: MockServer.java    From Chimera with MIT License 4 votes vote down vote up
@Override
public CachedServerIcon loadServerIcon(File file) throws IllegalArgumentException, Exception {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
 
Example #15
Source File: SpigotPingResponseHandler.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public CachedServerIcon getIcon() {
	return icon;
}
 
Example #16
Source File: SpigotPingResponseHandler.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void setServerIcon(CachedServerIcon icon) {
	this.icon = icon;
}
 
Example #17
Source File: BukkitPlugin.java    From ServerListPlus with GNU General Public License v3.0 4 votes vote down vote up
public CachedServerIcon getFavicon(FaviconSource source) {
    Optional<CachedServerIcon> result = faviconCache.getUnchecked(source);
    return result.isPresent() ? result.get() : null;
}
 
Example #18
Source File: BukkitPlugin.java    From ServerListPlus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public LoadingCache<FaviconSource, Optional<CachedServerIcon>> getFaviconCache() {
    return faviconCache;
}
 
Example #19
Source File: BukkitEventHandler.java    From ServerListPlus with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onServerListPing(final ServerListPingEvent event) {
    if (bukkit.getCore() == null) return; // Too early, we haven't finished initializing yet
    StatusResponse response = bukkit.getCore().createRequest(event.getAddress()).createResponse(
            bukkit.getCore().getStatus(), new ResponseFetcher() {
                @Override
                public Integer getOnlinePlayers() {
                    return event.getNumPlayers();
                }

                @Override
                public Integer getMaxPlayers() {
                    return event.getMaxPlayers();
                }

                @Override
                public int getProtocolVersion() {
                    return -1;
                }
            });

    // Description
    String message = response.getDescription();
    if (message != null)
        event.setMotd(message);

    // Max players
    Integer max = response.getMaxPlayers();
    if (max != null)
        event.setMaxPlayers(max);

    // Favicon
    FaviconSource favicon = response.getFavicon();
    if (favicon != null) {
        CachedServerIcon icon = bukkit.getFavicon(favicon);
        if (icon != null)
            try {
                event.setServerIcon(icon);
            } catch (UnsupportedOperationException ignored) {}
    }
}
 
Example #20
Source File: PaperEventHandler.java    From ServerListPlus with GNU General Public License v3.0 4 votes vote down vote up
private void handlePaperServerListPing(final PaperServerListPingEvent event) {
    if (bukkit.getCore() == null) return; // Too early, we haven't finished initializing yet

    StatusRequest request = bukkit.getCore().createRequest(event.getAddress());
    request.setProtocolVersion(event.getClient().getProtocolVersion());
    InetSocketAddress host = event.getClient().getVirtualHost();
    if (host != null) {
        request.setTarget(host);
    }

    StatusResponse response = request.createResponse(bukkit.getCore().getStatus(),
            // Return unknown player counts if it has been hidden
            new ResponseFetcher() {
                @Override
                public Integer getOnlinePlayers() {
                    return event.shouldHidePlayers() ? null : event.getNumPlayers();
                }

                @Override
                public Integer getMaxPlayers() {
                    return event.shouldHidePlayers() ? null : event.getMaxPlayers();
                }

                @Override
                public int getProtocolVersion() {
                    return event.getProtocolVersion();
                }
            }
    );

    // Description
    String message = response.getDescription();
    if (message != null) event.setMotd(message);

    // Version name
    message = response.getVersion();
    if (message != null) event.setVersion(message);
    // Protocol version
    Integer protocol = response.getProtocolVersion();
    if (protocol != null) event.setProtocolVersion(protocol);

    if (response.hidePlayers()) {
        event.setHidePlayers(true);
    } else {
        // Online players
        Integer count = response.getOnlinePlayers();
        if (count != null) event.setNumPlayers(count);
        // Max players
        count = response.getMaxPlayers();
        if (count != null) event.setMaxPlayers(count);

        // Player hover
        message = response.getPlayerHover();
        if (message != null) {
            List<PlayerProfile> profiles = event.getPlayerSample();
            profiles.clear();

            if (!message.isEmpty()) {
                if (response.useMultipleSamples()) {
                    count = response.getDynamicSamples();
                    List<String> lines = count != null ? Helper.splitLinesCached(message, count) :
                            Helper.splitLinesCached(message);

                    for (String line : lines) {
                        profiles.add(bukkit.getServer().createProfile(line));
                    }
                } else {
                    profiles.add(bukkit.getServer().createProfile(message));
                }
            }
        }
    }

    // Favicon
    FaviconSource favicon = response.getFavicon();
    if (favicon != null) {
        CachedServerIcon icon = bukkit.getFavicon(favicon);
        if (icon != null)
            try {
                event.setServerIcon(icon);
            } catch (UnsupportedOperationException ignored) {}
    }
}
 
Example #21
Source File: MockServer.java    From Chimera with MIT License 4 votes vote down vote up
@Override
public CachedServerIcon getServerIcon() {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
 
Example #22
Source File: ExprLastLoadedServerIcon.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Class<? extends CachedServerIcon> getReturnType() {
	return CachedServerIcon.class;
}
 
Example #23
Source File: ExprLastLoadedServerIcon.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
@Nullable
public CachedServerIcon[] get(Event e) {
	return CollectionUtils.array(EffLoadServerIcon.lastLoaded);
}
 
Example #24
Source File: ExprServerIcon.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Class<? extends CachedServerIcon> getReturnType() {
	return CachedServerIcon.class;
}
 
Example #25
Source File: GeyserBukkitPingPassthrough.java    From Geyser with MIT License 4 votes vote down vote up
@Override
public void setServerIcon(CachedServerIcon icon) throws IllegalArgumentException, UnsupportedOperationException {
}
 
Example #26
Source File: PaperServerListPingEventImpl.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
PaperServerListPingEventImpl(MinecraftServer server, StatusClient client, int protocolVersion, @Nullable CachedServerIcon icon) {
    super(client, server.getMOTD(), server.getCurrentPlayerCount(), server.getMaxPlayers(),
            server.getServerModName() + ' ' + server.getMinecraftVersion(), protocolVersion, icon);
    this.server = server;
}
 
Example #27
Source File: Server.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets an instance of the server's default server-icon.
 *
 * @return the default server-icon; null values may be used by the
 * implementation to indicate no defined icon, but this behavior is
 * not guaranteed
 */
CachedServerIcon getServerIcon();
 
Example #28
Source File: Server.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Loads an image from a file, and returns a cached image for the specific
 * server-icon.
 * <p>
 * Size and type are implementation defined. An incompatible file is
 * guaranteed to throw an implementation-defined {@link Exception}.
 *
 * @param file the file to load the from
 * @return a cached server-icon that can be used for a {@link
 * ServerListPingEvent#setServerIcon(CachedServerIcon)}
 * @throws IllegalArgumentException if image is null
 * @throws Exception                if the image does not meet current server server-icon
 *                                  specifications
 */
CachedServerIcon loadServerIcon(File file) throws IllegalArgumentException, Exception;
 
Example #29
Source File: Server.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates a cached server-icon for the specific image.
 * <p>
 * Size and type are implementation defined. An incompatible file is
 * guaranteed to throw an implementation-defined {@link Exception}.
 *
 * @param image the image to use
 * @return a cached server-icon that can be used for a {@link
 * ServerListPingEvent#setServerIcon(CachedServerIcon)}
 * @throws IllegalArgumentException if image is null
 * @throws Exception                if the image does not meet current server
 *                                  server-icon specifications
 */
CachedServerIcon loadServerIcon(BufferedImage image) throws IllegalArgumentException, Exception;
 
Example #30
Source File: ServerListPingEvent.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets the server-icon sent to the client.
 *
 * @param icon the icon to send to the client
 * @throws IllegalArgumentException      if the {@link CachedServerIcon} is not
 *                                       created by the caller of this event; null may be accepted for some
 *                                       implementations
 * @throws UnsupportedOperationException if the caller of this event does
 *                                       not support setting the server icon
 */
public void setServerIcon(CachedServerIcon icon) throws IllegalArgumentException, UnsupportedOperationException {
    throw new UnsupportedOperationException();
}