SpigotupDateChecker는 플러그인에 완벽하게 작동하는 업데이트 체커를 추가 할 수있는 간단하지만 강력한 라이브러리입니다. Maven Information, Javadocs 및 전체 예제 플러그인을 보려면 바닥까지 모든 것을 스크롤하십시오!
저자 : mfnalex
기고자 : mrnemo64
관련 SpigoTMC 스레드
수동 및 반복 업데이트 확인을 발행하고 결과를 특정 플레이어에게 ingame 메시지로 보낼 수 있습니다. 또는/또는 콘솔에 인쇄 할 수 있습니다.
모든 수표는 비동기 적으로 수행됩니다. 수표가 완료되면 사용자 정의 이벤트가 호출됩니다. 업데이트 검사기 자체는이를 듣고 조인 또는 플레이어의 운영자에게 특정 권한을 자동으로 알릴 수 있습니다.
물론, 새 버전이 감지되면 업데이트 체크 벤트를 직접들을 수 있습니다.
플러그인을 무료 및 유료 버전으로 사용할 수있는 경우 두 개의 다운로드 링크를 정의 할 수 있으며 기부 페이지 및 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
}
}
이제 플러그인의 두 가지 버전이 있다고 상상해보십시오. My Angelchest Free 및 Angelchest Plus 플러그인과 같은 추가 기능이있는 무료 버전과 유료 버전. 두 플러그인이 동일한 코드베이스를 공유하고 프리미엄 기능을 잠금 해제할지 여부 만 런타임 만 결정하면이 작업과 같은 작업을 쉽게 얻을 수 있습니다.
무료 버전의 사용자는 두 버전 모두에 대한 링크를 얻을 수 있으므로 유료 버전의 장점을 볼 수 있지만 이미 유료 버전을 구입 한 사용자에게 무료 버전 링크를 보내고 싶지 않습니다. 업데이트 검사기는 SpigotMC의 프리미엄 리소스 자리 표시자를 사용하여 서버가 유료 버전을 사용하고 있는지 여부를 감지하지만 updateChecker#setUsingPaidVersion (부울)을 사용 하여이 감지를 무시할 수도 있습니다.
이를 달성하려면 다음을 수행 할 수 있습니다.
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 (현재 167 ~ 192 행)에 Maven-Exec-Plugin 부분을 언급하십시오.
Javadocs는 여기에서 확인할 수 있습니다 : https://hub.jeff-media.com/javadocs/spigotupdatechecker/
예제 플러그인 : https://github.com/jeff-media-gbr/spigot-updatechecker-example
내 CustomBlockData 라이브러리는 세계의 모든 블록에 대한 PersistentDatacontainer를 제공합니다. 외부 스토리지가 필요없이 블록 내부에서 원하는 모든 정보를 쉽게 저장하십시오!
Bukkit의 PeristentDatacontainer와 함께 사용할 수있는 수많은 새로운 영구 데이터 타입 을 추가합니다.
내 불화에 가입하여 도움을 받으십시오.