Siffar sandar aikin aika wani muhimmin al'amari ne na Spigot, babban aikin sabar Minecraft da ake amfani da shi sosai. Wannan fasalin yana ba masu haษaka damar nuna saฦonnin al'ada da bayanai ga mai kunnawa ta hanyar mashaya mai aiki, yanki na musamman a cikin UI na wasan. A cikin wannan labarin, za mu zurfafa zurfin fahimtar yadda ake aika sandunan aiki a Spigot ta amfani da Java, mai da hankali kan mahimman ษakunan karatu da ayyukan da ke cikin aikin. Bugu da ฦari, za mu bincika wasu aikace-aikace na ainihi na wannan fasalin. Don haka, bari mu fara tafiya mai ban sha'awa don haษaka ฦwarewar ci gaban ku na Spigot.
Maganin Matsala
Don aika sandar aiki a cikin Spigot, kuna buฦatar ฦirฦirar plugin ษin da ke amfani da API ษin da aka bayar don nuna saฦon al'ada akan sandar aikin. Wannan tsari gabaษaya ya ฦunshi matakai na farko guda uku: saita plugin ษin, ฦirฦirar mai sarrafa umarni, da aiwatar da hanyar mashaya aikin aika.
Bayanin mataki-mataki na Code
- Saita plugin: Da farko, ฦirฦiri sabon aikin plugin, kuma ฦara Spigot azaman abin dogaro a cikin ginin ku. Yawancin lokaci, ana yin wannan a cikin fayil ษin build.gradle (ko pom.xml don Maven).
dependencies { compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT' }
Na gaba, ฦirฦiri sabon aji wanda zai tsawaita JavaPlugin kuma ya soke aikin โonEnable()โ. Wannan shine babban ajin plugin ษin ku.
public class ActionBarPlugin extends JavaPlugin { @Override public void onEnable() { // Your plugin initialization code here } }
ฦara fayil ษin plugin.yml ษin ku, wanda ya ฦunshi mahimman bayanai game da plugin ษin ku, kamar sunansa, sigarsa, da babban aji.
name: ActionBarPlugin version: 1.0 main: com.example.ActionBarPlugin api-version: "1.13"
- ฦirฦirar mai sarrafa umarni: ฦirฦiri sabon aji mai haษaka "CommandExecutor," wanda zai kula da umarnin da mai kunnawa ya aiwatar.
public class ActionBarCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { // Your command handling code here return false; } }
Yanzu, yi rajistar umarni a cikin aikin โonEnable()โ na babban ajin plugin ษin ku.
@Override public void onEnable() { getCommand("actionbar").setExecutor(new ActionBarCommand()); }
- Aiwatar da hanyar bar aika aika: A cikin aji na ActionBarCommand, ฦirฦiri aikin da ake kira "sendActionBar()" wanda ke karษar ษan wasa da kirtani azaman muhawara.
private void sendActionBar(Player player, String message) { player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)); }
Sa'an nan, yi amfani da wannan aikin a cikin hanyar "onCommand()" don nuna saฦon al'ada lokacin da mai kunnawa ya aiwatar da umarnin "actionbar".
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (sender instanceof Player) { Player player = (Player) sender; if (args.length > 0) { String message = String.join(" ", args); sendActionBar(player, message); return true; } } return false; }
API ษin Spigot
API ษin Spigot ฦaฦฦarfan ษakin karatu ne mai cike da fasali, wanda aka tsara musamman don ฦirฦirar plugins na Minecraft. Wannan ษakin karatu yana ba masu haษaka kayan aiki da ayyuka waษanda ke daidaita haษakar plugin ษin da kuma isar da ingantaccen ฦwarewar caca ga ฦดan wasa. Wasu fitattun abubuwan haษin gwiwar Spigot API sun haษa da sarrafa taron, rajistar umarni, sarrafa tsari, da sarrafa kaya.
Fahimtar hanyar sendActionBar().
Yana da mahimmanci a fahimci yadda hanyar "sendActionBar()" ke aiki don samun mafi yawan fasalin aikin bar na Spigot. Na farko, ana amfani da abun Player don samun dama ga takamaiman ayyuka na Spigot API; a wannan yanayin, aikin "sendMessage()". Wannan aikin yana ษaukar gardama guda biyu: ChatMessageType, wanda aka saita zuwa ACTION_BAR a cikin aikace-aikacenmu, da kuma saฦon kansa, wanda aka rarraba ta hanyar "TextComponent.fromLegacyText()".
Yin amfani da waษannan hanyoyin da ayyuka a cikin juzu'i, zaku iya ฦirฦira abubuwan wasa masu kayatarwa da nishadantarwa ta hanyar haษa sandunan aiki na al'ada a cikin sabar Spigot ku. Tare da ingantaccen tushe a cikin ci gaban Spigot da kayan aikin da ake buฦata a hannun ku, yuwuwar abubuwan plugins ษin ku na Minecraft kusan ba su da iyaka.