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一起使用。
隨時加入我的不和諧尋求幫助。