ChatColor.stripColor -> Inventory Click Event

Pokec o čemkoliv ostatním
Message
Autor
kamikatze
Příspěvky: 176
Registrován: 24 zář 2014, 16:33
Reputation: 0

ChatColor.stripColor -> Inventory Click Event

#1 Příspěvekod kamikatze » 04 čer 2015, 22:22

IP: 93.91.250.125:27389
Dobrý den, chtěl bych pomoc s pluginem, zde je kod:

Kód: Vybrat vše

   @EventHandler
   public void onInventoryClick(InventoryClickEvent e) {
      if(!ChatColor.stripColor(e.getInventory().getName().equalsIgnoreCase("Seznam ukolu")))
      return;
      Player p = (Player) e.getWhoClicked();
      e.setCancelled(true);
      
      if(e.getCurrentItem() == null || e.getCurrentItem().getType()==Material.AIR || !e.getCurrentItem().hasItemMeta()) {
         p.closeInventory();
      }
   }   

Chtěl bych se ještě zeptat na toto: hlásí mi chybu "if(!ChatColor.stripColor(e.getInventory().getName().equalsIgnoreCase("Seznam ukolu")))"

Chyba: The method stripColor(String) in the type ChatColor isn't applicable for the arguments (boolean)

Uživatelský avatar
Arcas
Příspěvky: 1406
Věk: 26
Registrován: 13 bře 2012, 19:15
Reputation: 0

Re: ChatColor.stripColor -> Inventory Click Event

#2 Příspěvekod Arcas » 05 čer 2015, 08:15

Totální kravina - smazáno...
Naposledy upravil(a) Arcas dne 05 čer 2015, 10:20, celkem upraveno 1 x.
Čeština a jiné jazyky jsou Freeware, ale ne Opensource!!! To znamená, že s nimi můžete nakládat jak chcete, ale nesmíte je upravovat...

// no comment

Uranus-Portal.com
Obrázek

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

Re: ChatColor.stripColor -> Inventory Click Event

#3 Příspěvekod Mike8748 » 05 čer 2015, 08:21

máš blbě závorky

Kód: Vybrat vše

if(!ChatColor.stripColor(e.getInventory().getName()).equalsIgnoreCase("Seznam ukolu"))

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

Re: ChatColor.stripColor -> Inventory Click Event

#4 Příspěvekod kamikatze » 05 čer 2015, 15:31

Chtěl bych se ještě zeptat (Díky za radu funguje to), ale jak rozpoznám na jakou knihu klikl, jelikož bych chtěl kdyby klikli na Written book s DisplayName: Quest1 a jak to rozpozná když kliknou na knihu s questem Quest2
Code:

Kód: Vybrat vše

package me.nathan.listener;

import me.nathan.plugin.Main;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public class InventoryGUI implements Listener {
   
   public Main plugin;
   public InventoryGUI(Main instance) {
      plugin = instance;
   }
   
   private void openGUI(Player player) {
      Inventory inv = Bukkit.createInventory(null, 70, ChatColor.GREEN + plugin.getConfig().getString("questy_nadpis"));
      
      ItemStack quest1 = new ItemStack(Material.WRITTEN_BOOK);
      ItemMeta quest1Meta = quest1.getItemMeta();
      ItemStack quest2 = new ItemStack(Material.WRITTEN_BOOK);
      ItemMeta quest2Meta = quest1.getItemMeta();
      ItemStack quest3 = new ItemStack(Material.WRITTEN_BOOK);
      ItemMeta quest3Meta = quest1.getItemMeta();
      ItemStack quest4 = new ItemStack(Material.WRITTEN_BOOK);
      ItemMeta quest4Meta = quest1.getItemMeta();
      
      quest1Meta.setDisplayName(ChatColor.GOLD + plugin.getConfig().getString("quest1_nadpis"));
      quest1.setItemMeta(quest1Meta);
      
      quest2Meta.setDisplayName(ChatColor.GOLD + plugin.getConfig().getString("quest2_nadpis"));
      quest2.setItemMeta(quest2Meta);
      
      quest3Meta.setDisplayName(ChatColor.GOLD + plugin.getConfig().getString("quest3_nadpis"));
      quest1.setItemMeta(quest3Meta);
      
      quest4Meta.setDisplayName(ChatColor.GOLD + plugin.getConfig().getString("quest4_nadpis"));
      quest1.setItemMeta(quest4Meta);
      
      inv.setItem(1, quest1);
      inv.setItem(2, quest2);
      inv.setItem(3, quest3);
      inv.setItem(4, quest4);
      
      player.openInventory(inv);
   }
   @EventHandler
   public void onInventoryClick(InventoryClickEvent e) {
      if(!ChatColor.stripColor(e.getInventory().getName()).equalsIgnoreCase("Seznam ukolu"))
      return;
      Player p = (Player) e.getWhoClicked();
      e.setCancelled(true);
      
      if(e.getCurrentItem() == null || e.getCurrentItem().getType()==Material.AIR || !e.getCurrentItem().hasItemMeta()) {
         p.closeInventory();
         
         switch (e.getCurrentItem().getType()) {
         case Material.WRITTEN_BOOK
         }
      }
   }   
   @EventHandler
   public void onPlayerJoin(PlayerJoinEvent e) {
      e.getPlayer().getInventory().addItem(new ItemStack(Material.WRITTEN_BOOK));
   }
   
   @EventHandler
   public void onPlayerInteract(PlayerInteractEvent e) {
      Action a = e.getAction();
      ItemStack is = e.getItem();
      
      if (a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
         return;
         
      if (is.getType() == Material.WRITTEN_BOOK);
      openGUI(e.getPlayer());
   }
}

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

Re: ChatColor.stripColor -> Inventory Click Event

#5 Příspěvekod Hanakocz » 05 čer 2015, 18:26

čistě teoreticky bych ty knihy rozlišoval podle jejich NBT. Nicméně nečekoval bych jen název knihy, ale i autora (jen tak máš jistotu, že mají tu správnou knihu a ne vlastní přejmenovanou)
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ě)

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

Re: ChatColor.stripColor -> Inventory Click Event

#6 Příspěvekod DenOwq » 05 čer 2015, 19:46

if (is.getType() == Material.WRITTEN_BOOK);
u IFU prostě + nejde používat! Furt se ptáš a přitom ti to každý říká.l
Muhahha.


Zpět na „Off topic“

Kdo je online

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