Java - Plugin

Technická podpora k herním serverům Minecraft a Tekkit
Message
Autor
kamikatze
Příspěvky: 176
Registrován: 24 zář 2014, 16:33
Reputation: 0

Java - Plugin

#1 Příspěvekod kamikatze » 02 bře 2015, 13:14

Server: 93.91.250.138:27055

Dobrý den, Ahoj !
Zkouším si tak něco v Eclipsu s pluginama a objevil se problém, kde mi to eclipse definuje takto :
"The constructor ItemStack(Material) is undefined"
Kod:

Kód: Vybrat vše

package me.natan;

import me.natan.EventHandle;
import net.minecraft.server.v1_8_R1.ItemStack;

import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.PlayerInventory;

public class PlayerListener implements Listener {

   public PlayerListener(EventHandle plugin) {
      plugin.getServer().getPluginManager().registerEvents(this, plugin);
   }
   
   @EventHandler
   public static void onJoin(org.bukkit.event.player.PlayerJoinEvent event) {
      Player player = event.getPlayer();
      player.sendMessage("Zkouska");
      PlayerInventory inventory = player.getInventory();
      ItemStack itemstack = new ItemStack(Material.WATCH);
   }

}

Uživatelský avatar
Hanakocz
Příspěvky: 3228
Věk: 34
Registrován: 25 črc 2013, 20:53
Reputation: 7
Kontaktovat uživatele:

Re: Java - Plugin

#2 Příspěvekod Hanakocz » 02 bře 2015, 13:39

moc tomu nerozumím, ale nepotřebuješ tam nadefinovat ten materiál?
Industry 2.0 -> 1.7.10 GregTech6 server. Pro připojení stačí napsat.
Člen ligy pro aktualizaci serverů na novější verze a rozšíření modovaného MC.
Discord FH : http://discord.fakaheda.eu/ (sem psát pokud chcete poradit s MC mody akutně)

kamikatze
Příspěvky: 176
Registrován: 24 zář 2014, 16:33
Reputation: 0

Re: Java - Plugin

#3 Příspěvekod kamikatze » 02 bře 2015, 13:49

Zřejmě ano, jenže jak ?

Mike8748
Příspěvky: 823
Registrován: 30 bře 2014, 10:05
Reputation: 28

Re: Java - Plugin

#4 Příspěvekod Mike8748 » 02 bře 2015, 14:21

problém bych videl v tom co importuješ na začátku

Kód: Vybrat vše

import net.minecraft.server.v1_8_R1.ItemStack;

nejspíš nebude to pravý co chceš, spíš

Kód: Vybrat vše

import org.bukkit.inventory.ItemStack

kamikatze
Příspěvky: 176
Registrován: 24 zář 2014, 16:33
Reputation: 0

Re: Java - Plugin

#5 Příspěvekod kamikatze » 02 bře 2015, 16:18

Děkuji, to se vyřešilo, jenže když když to savnu tak zase hláška : "The value of the local variable inventory is not used"
Zkoušel jsem to ignorovat, je to jenom varování, jenže se neudálo co se má stát.. Nenapsalo to nic do chatu, ani mi to nedalo hodiny..
Dávám sem všechny kody co obsahuje ten plugin..
1. - PlayerListener

Kód: Vybrat vše

package me.natan;

import me.natan.EventHandle;
import org.bukkit.inventory.ItemStack;

import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.PlayerInventory;

public class PlayerListener implements Listener {

   public PlayerListener(EventHandle plugin) {
      plugin.getServer().getPluginManager().registerEvents(this, plugin);
   }
   
   @EventHandler
   public static void onJoin(org.bukkit.event.player.PlayerJoinEvent event) {
      Player player = event.getPlayer();
      player.sendMessage("Zkouska");
      PlayerInventory inventory = player.getInventory();
      ItemStack itemstack = new ItemStack(Material.WATCH,1);
   }

}

2. - EventHandle

Kód: Vybrat vše

package me.natan;

import me.natan.PlayerListener;

import org.bukkit.plugin.java.JavaPlugin;

public class EventHandle extends JavaPlugin {

   public void onEnable() {
      new PlayerListener(this);
   }
   
   public void onDisable() {
      getLogger().info("Plugin deaktivován!");
   }

}

3. - plugin.java

Kód: Vybrat vše

package me.natan;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class plugin extends JavaPlugin {
   
   public void onEnable() {
      System.out.println("Plugin Lobby aktivovany!");
   }
   public void onDisable() {
      System.out.println("Plugin Lobby deaktivovany!");
   }
   
   public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args ) {
      if (cmd.getName().equalsIgnoreCase("lobby") && sender instanceof Player) {
         Player player = (Player) sender;
         player.sendMessage(ChatColor.BLUE + "Teleportuji te na lobby");
         player.setHealth(20);
         player.setFoodLevel(20);
         return true;
      }
      return false;
   }
}

4. - plugin.yml (Kdyby náhodou to dělala i tato "prkotina"

Kód: Vybrat vše

name: Lobby
main: me.natan.plugin
version: 1.0
commands:
   lobby:
      description: Blank description.
      usage: /<command>

Uživatelský avatar
Dart
Příspěvky: 93
Registrován: 20 led 2013, 01:32
Reputation: 20

Re: Java - Plugin

#6 Příspěvekod Dart » 02 bře 2015, 17:29

1) Problem co vidim je ten ze neregistrujes eventy.
Obrázek

kamikatze
Příspěvky: 176
Registrován: 24 zář 2014, 16:33
Reputation: 0

Re: Java - Plugin

#7 Příspěvekod kamikatze » 02 bře 2015, 17:31

Registruji..

Kód: Vybrat vše

      plugin.getServer().getPluginManager().registerEvents(this, plugin);

Nebo jak se to myslí ?

Uživatelský avatar
Dart
Příspěvky: 93
Registrován: 20 led 2013, 01:32
Reputation: 20

Re: Java - Plugin

#8 Příspěvekod Dart » 02 bře 2015, 17:38

Oh, sorry nevsiml sem si, ze to mas v tom listeneru a pak v OnEnable vytvaris instanci. Doporucujito zjednodusit tak, ze to das do OnEnable pro jednoduchost pokud to takhle nemas schvalne a pri Disable zase eventy odregistrovat.

Kdybych byl doma kouknul bych do sveho IDE kde je chyba. Zkusil bych to zjednodusit mas to takove zvlastne napsane.
Obrázek

Uživatelský avatar
DenOwq
Příspěvky: 2703
Věk: 28
Registrován: 06 bře 2014, 21:26
Reputation: 2

Re: Java - Plugin

#9 Příspěvekod DenOwq » 02 bře 2015, 17:41

plugin.java

Kód: Vybrat vše

package me.natan;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class plugin extends JavaPlugin {
   
   public void onEnable() {
      this.getPluginManager().registerEvents(new PlayerListener());
      System.out.println("Plugin Lobby aktivovany!");
   }
   public void onDisable() {
      System.out.println("Plugin Lobby deaktivovany!");
   }
   
   public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args ) {
      if (cmd.getName().equalsIgnoreCase("lobby") && sender instanceof Player) {
         Player player = (Player) sender;
         player.sendMessage(ChatColor.BLUE + "Teleportuji te na lobby");
         player.setHealth(20);
         player.setFoodLevel(20);
         return true;
      }
      return false;
   }
}

PlayerListener.java

Kód: Vybrat vše

package me.natan;

import me.natan.EventHandle;
import org.bukkit.inventory.ItemStack;

import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.PlayerInventory;

public class PlayerListener implements Listener {
   
   @EventHandler
   public static void onJoin(org.bukkit.event.player.PlayerJoinEvent event) {
      Player player = event.getPlayer();
      player.sendMessage("Zkouska");
      PlayerInventory inventory = player.getInventory();
      ItemStack itemstack = new ItemStack(Material.WATCH,1);
   }

}

EventHandler.java - vymazej

!! REJPÁNÍ !!
PS: v javě se nepíší malé názvy tříd.
PSS: server vidí packages jako složky, když v každém pluginu použiješ me.natan tak ti plugin hodí chybu, používej me.natan.<jmenoPlugonu>
Muhahha.

Uživatelský avatar
Dart
Příspěvky: 93
Registrován: 20 led 2013, 01:32
Reputation: 20

Re: Java - Plugin

#10 Příspěvekod Dart » 02 bře 2015, 17:48

A pokud chces aby to dalo hodiny nemuzes tam jen vytvaret ItemStack musis jeste pridat item do inventare.
https://hub.spigotmc.org/javadocs/bukki ... ntory.html
Obrázek


Zpět na „Minecraft, Tekkit“

Kdo je online

Uživatelé prohlížející si toto fórum: Žádní registrovaní uživatelé a 25 hostů