SpigoTupDateChecker是一个简单但功能强大的库,可在插件中添加完美工作的更新检查器。一直滚动到底部以获取Maven信息,Javadocs和一个完整的示例插件!
作者:Mfnalex
贡献者:mrnemo64
相关的SPIGOTMC线程
您可以发布手册和重复更新检查,并将结果作为Ingame消息发送给特定玩家,并将其打印到控制台。
所有检查都不同步。检查完成后,将调用自定义事件。更新Checker本身会听到它,并可以自动通知Join或具有特定权限的玩家的操作员。
当然,您也可以听取UpdateCheckevent的方式,一旦检测到新版本,就可以做任何您喜欢的事情。
如果您的插件可作为免费版本和付费版本,则可以定义两个下载链接,并且您可以将链接添加到捐赠页面和ChangElog。
您可以提供所有这些链接,包括您自己检查最新版本的API端点,或者仅提供插件的SpigoTMC资源ID作为更新检查器,以自动获取这些链接。
支持的API端点以检索版本信息:
我的公共存储库中可用updatechecker:
< repositories >
< repository >
< id >jeff-media-public</ id >
< url >https://repo.jeff-media.com/public/</ url >
</ repository >
</ repositories >
< dependencies >
< dependency >
< groupId >com.jeff_media</ groupId >
< artifactId >SpigotUpdateChecker</ artifactId >
< version >3.0.3</ version >
< scope >compile</ scope >
</ dependency >
</ dependencies >
请注意,您还必须遮蔽并将UpdateChecker重新放置到您的.jar文件中:
< build >
...
< plugins >
...
< plugin >
< groupId >org.apache.maven.plugins</ groupId >
< artifactId >maven-shade-plugin</ artifactId >
< version >3.3.0</ version >
< configuration >
< relocations >
<!-- Using the maven-shade-plugin to shade and relocate the UpdateChecker -->
<!-- Replace "your.package" with your plugin's package name -->
< relocation >
< pattern >com.jeff_media.updatechecker</ pattern >
< shadedPattern >your.package.updatechecker</ shadedPattern >
</ relocation >
</ relocations >
</ configuration >
< executions >
< execution >
< phase >package</ phase >
< goals >
< goal >shade</ goal >
</ goals >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build >
plugins {
id( " com.github.johnrengelman.shadow " ) version " x.x.x " // Used for shading
}
repositories {
maven(url = " https://repo.jeff-media.com/public/ " )
}
dependencies {
implementation( " com.jeff_media:SpigotUpdateChecker:3.0.3 " )
}
tasks.named< ShadowJar >( " shadowJar " ) {
dependencies {
relocate( " com.jeff_media " , " your.package.lib " ) {
include(dependency( " com.jeff_media: " ))
}
}
}
无法重新安置该包将使UpdateChecker抛出异常,因此请将其重新定位!
为了获得一个工作的UpdateChecker,这已经足够了:
public class MyPlugin extends JavaPlugin {
// To get the Resource ID, look at the number at the end of the URL of your plugin's SpigotMC page
private static final String SPIGOT_RESOURCE_ID = "59773" ;
@ Override
public void onEnable () {
new UpdateChecker ( this , UpdateCheckSource . SPIGOT , SPIGOT_RESOURCE_ID ) // You can also use Spiget instead of Spigot - Spiget's API is usually much faster up to date.
. checkEveryXHours ( 24 ) // Check every 24 hours
. checkNow (); // And check right now
}
}
一旦可用新版本,上面的代码将在控制台上打印一条消息,并向加入服务器的每个OP发送消息。如果找不到新版本,则不会发送消息。
当然,您可以使用更多选项。例如:
import com . jeff_media . updatechecker . UpdateCheckSource ;
public class MyPlugin extends JavaPlugin {
private static final String SPIGOT_RESOURCE_ID = "59773" ;
@ Override
public void onEnable () {
new UpdateChecker ( this , UpdateCheckSource . CUSTOM_URL , "https://api.jeff-media.de/chestsort/latest-version.txt" ) // A link to a URL that contains the latest version as String
. setDownloadLink ( "https://www.chestsort.de" ) // You can either use a custom URL or the Spigot Resource ID
. setDonationLink ( "https://paypal.me/mfnalex" )
. setChangelogLink ( SPIGOT_RESOURCE_ID ) // Same as for the Download link: URL or Spigot Resource ID
. setNotifyOpsOnJoin ( true ) // Notify OPs on Join when a new version is found (default)
. setNotifyByPermissionOnJoin ( "myplugin.updatechecker" ) // Also notify people on join with this permission
. setUserAgent ( new UserAgentBuilder (). addPluginNameAndVersion ())
. checkEveryXHours ( 0.5 ) // Check every 30 minutes
. checkNow (); // And check right now
}
}
现在想象一下您的插件有两个版本。一个免费版本和一个带有额外功能的付费版本,例如我的Angelchest Free和Angelchest Plus插件。如果两个插件共享相同的代码库,并且仅决定是否要解锁Premium功能,则可以轻松地获得此类工作:
免费版本的用户将获得两个版本的链接,因此他们可以看到您的付费版本的优势,而我们不想将免费版本链接发送给已经购买了付费版本的用户。更新Checker使用SpigoTMC的高级资源占位持有人来检测服务器是否正在使用付费版本,但是您也可以使用UpdateChecker#SetatusingPaidVersion(Boolean)覆盖此检测。
为了实现这一目标,您可以做到这一点:
import com . jeff_media . updatechecker . UpdateCheckSource ;
public class MyPlugin extends JavaPlugin {
private static final int ANGELCHEST_FREE = 60383 ;
private static final int ANGELCHEST_PLUS = 88214 ;
private final boolean usingPaidVersion = howEverYouDetectIt ();
@ Override
public void onEnable () {
new UpdateChecker ( this , UpdateCheckSource . CUSTOM_URL , "https://api.jeff-media.de/angelchest/latest-version.txt" )
. setFreeDownloadLink ( ANGELCHEST_FREE )
. setPaidDownloadLink ( ANGELCHEST_PLUS )
. setNameFreeVersion ( "Free" ) // Optional. It's the suffix for the download links
. setNamePaidVersion ( "Plus" ) // when both links are shown.
. checkNow ();
}
}
免费版本的用户现在将看到两个链接:
但是,付费版本的用户将只能获得付费版本的下载链接,就像在顶部的屏幕截图中一样。
您可以使用消费者来更改更新检查器的行为。
import com . jeff_media . updatechecker . UpdateCheckSource ;
public class MyPlugin extends JavaPlugin {
@ Override
public void onEnable () {
new UpdateChecker ( this , UpdateCheckSource . CUSTOM_URL , "https://api.jeff-media.de/angelchest/latest-version.txt" )
. setDownloadLink ( "https://www.chestsort.de" )
. onSuccess (( commandSenders , latestVersion ) -> {
for ( CommandSender sender : commandSenders ) {
sender . sendMessage ( "This code will run after the update check was successfull." );
}
})
. onFail (( commandSenders , exception ) -> {
for ( CommandSender sender : commandSenders ) {
sender . sendMessage ( "This code will run after the update check failed." );
}
})
. setNotifyRequesters ( false ) // Do not show the default messages, instead only run our custom consumers
. checkNow ();
}
}
在我的公共存储库中发布的.JAR已通过Allatori运行,以将文件大小降低约30%。它不会以任何负面的方式影响性能。免费的和付费插件都允许在SpigoTMC上使用所使用的混淆设置。
如果您想自己构建它,只需在您的pom.xml中评论Maven-Exec-Plugin部分(目前167至192行)即可。
Javadocs可在此处提供:https://hub.jeff-media.com/javadocs/spigotupdatechecker/
示例插件:https://github.com/jeff-media-gbr/spigot-updatechecker-example
我的CustomBlockData库为您的世界上每个块提供了一个持久的DataContainer-轻松保存您喜欢的内部块,而无需任何外部存储!
添加了大量新的PersistentDatatypes,可与Bukkit的PersistentDataContainer一起使用。
随时加入我的不和谐寻求帮助。