Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

[Inne] Disco Zbroja - kod dla deweloperów.


Logitech.

Rekomendowane odpowiedzi

Opublikowano

Cześć.

 

Mam dla Was kodzik na "Disco Zbroję" o którą często padają pytania tutaj na forum. Nie jest to takie trudne jakby się mogło wydawać. 

Nie rzucam Wam gotowego pluginu, bo to bezsensu, wklepać tak prosty kodzik do Eclipse, to nic trudnego, a można wszystko sobie dowolnie modyfikować.

Aby zmienić czas zmiany koloru zmieńcie wartość tutaj: }, 0, 1); (1 na inną wartość).
Jest to czas podany w tickach. 20 ticków = 1 sekunda.

public class DiscoArmor extends JavaPlugin {
       
        public void onEnable() {
                Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                        private Random r = new Random();
                       
                        public void run() {
                                Color c = Color.fromRGB(r.nextInt(255), r.nextInt(255), r.nextInt(255));
                               
                                for (Player p : Bukkit.getServer().getOnlinePlayers()) {
                                        if (p.getInventory().getHelmet() != null && p.getInventory().getHelmet().getType() == Material.LEATHER_HELMET) {
                                                p.getInventory().setHelmet(getColorArmor(Material.LEATHER_HELMET, c));
                                        }
                                       
                                        if (p.getInventory().getChestplate() != null && p.getInventory().getChestplate().getType() == Material.LEATHER_CHESTPLATE) {
                                                p.getInventory().setChestplate(getColorArmor(Material.LEATHER_CHESTPLATE, c));
                                        }
                                       
                                        if (p.getInventory().getLeggings() != null && p.getInventory().getLeggings().getType() == Material.LEATHER_LEGGINGS) {
                                                p.getInventory().setLeggings(getColorArmor(Material.LEATHER_LEGGINGS, c));
                                        }
                                       
                                        if (p.getInventory().getBoots() != null && p.getInventory().getBoots().getType() == Material.LEATHER_BOOTS) {
                                                p.getInventory().setBoots(getColorArmor(Material.LEATHER_BOOTS, c));
                                        }
                                }
                        }
                }, 0, 1);
        }
       
        private ItemStack getColorArmor(Material m, Color c) {
                ItemStack i = new ItemStack(m, 1);
                LeatherArmorMeta meta = (LeatherArmorMeta) i.getItemMeta();
                meta.setColor(c);
                i.setItemMeta(meta);
                return i;
        }
}

Gdyby były problemy z code na MPCforum łapcie Gista na GitHub: 

https://gist.githubusercontent.com/anonymous/f54c9b1caa7ee4b21317/raw/6c09ffa11e524ed3b8fe96c63e77da100e004d44/gistfile1.txt 

P.S. dodajcie sobie tam importy, nie dodałem, bo mogą się odrobinę różnić.

Miłego korzystania! ;)

Jakby ktoś nie umiał sobie prowadzić z wyeksportowaniem tego w Eclipse - piszcie PW, podrzucę gotowego JAR'a. 

 

Kod autorstwa jednego z amerykańskich developerów. Link do poradnika: http://www.mpcforum.pl/s/0e1f01c

Opublikowano

Ujdzie, chociaż na tym forum już jest owy tut o "Disco Zbroi".

Wypromuje twój serwer minecraft na mclista :)

* 1000 diamentów w niecałe 24h,

* Twoj serwer znajdzie sie na 1 stronie,

* Po wiecej informacji zapraszam na PW,

¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

Opublikowano

Wypromuje twój serwer minecraft na mclista :)

* 1000 diamentów w niecałe 24h,

* Twoj serwer znajdzie sie na 1 stronie,

* Po wiecej informacji zapraszam na PW,

¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

Opublikowano

powinno być:

r.nextInt(256), r.nextInt(256), r.nextInt(256) 

bo 255 losuje od 0 do 254.

 

 

+ losowe kolory będą wyglądać... po prostu okropnie, oczy tylko zaczną napierdzielać, to musi być jakiś sens, jeden kolor płynie przechodzący w inny, to też może być losowe.

Mój pomysł:

Zaczynasz od jakiegoś tam koloru [r,g,b] np:  (liczy przechowywać w double, a dopiero potem castować na int)

X [20,0,160]

losujesz inny kolor (ale nie ustawiasz):

Y [50,250,100]

 patrzysz na różnice:

[30, 250, -60] 

Potem sumujemy wartości bezwzględne tych różnic 30 + 250 + 60 = 340

dzielimy każdą z różnic przez tę sumę

[0,0882352941176471, 0,7352941176470588, -0,1764705882352941]

i co tick dodajemy to do kolorku X, potem robimy z tego zwykły bukkitowy kolor i nadajemy zbrojce, jak kolorek X będzie już taki jak Y, to losujemy nowy Y.

minusem jest tylko to że z powodu niedokładności double, nie możemy po prostu sprawdzać liczb, ani nawet castować do int i wtedy sprawdzać, tylko trzeba np zobaczyć czy ich różnice są mniejsze od 0.1 i wtedy uznać że to to samo.

To już jest koniec smerfa:


http://www.mpcforum.pl/topic/1323530-info-znikam/


GG: 48522543


PS: Na innych forach i stronach znajdziesz mnie pod nickiem: 


BukkitSmerf

Opublikowano

Taki temat może być, masz rację spam na różnych forach bo znajść nie mogą... A wystarczy użyć "Magicznej wyszukiwarki".

Wypromuje twój serwer minecraft na mclista :)

* 1000 diamentów w niecałe 24h,

* Twoj serwer znajdzie sie na 1 stronie,

* Po wiecej informacji zapraszam na PW,

¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

Opublikowano
public static LinkedHashSet<Color> getColors() {
		LinkedHashSet<Color> colors = new LinkedHashSet<Color>();
		int red = 255;
		int green = 0;
		int blue = 0;
		int add = 1;
		
		for(int i = 1; true; i++) {
			
			colors.add(Color.fromRGB(red, green, blue));
			
			if(red == 255 && blue == 0 && (green >= 0 && green <= 255)) 
		        green += add(add, green);

		    if(green == 255 && blue == 0 && (red > 0 && red <= 255)) 
		        red -= remove(add, red);
		    
		    if(red == 0 && green == 255 && (blue >= 0 && blue < 255)) 
		        blue += add(add, blue);
		    
		    if(red == 0 && blue == 255 && (green > 0 && green <= 255)) 
		        green -= remove(add, green);
		    
		    if(green == 0 && blue == 255 && (red >= 0 && red <= 255)) 
		        red += add(add, red);
		    
		    if(red == 255 && green == 0 && (blue >= 0 && blue <= 255))   
		        blue -= remove(add, blue);
		    
		    if(red == 255 && green == 0 && blue == 0) {
		   	 System.out.println("Liczba kolorow: " + i);
		   	 break;
		    }
		}
		
		return colors;
	}
	
	public static int add(int add, int actual) {
		if(actual + add > 255) {
			return 255 - actual;
		} else {
			return add;
		}
	}
	
	public static int remove(int remove, int actual) {
		if(actual - remove < 0) {
			return actual;
		} else {
			return remove;
		}
	}

Kiedyś się tym bawiłem. Metoda getColors zwraca LinkedHashSet, w onEnalbe ją uruchomić, przypisać Seta do jakiejś zmiennej i potem w swoim tasku pobierasz kolejne elementy

I5 4690 3.5GHz | GeForce GTX 970 | Crucial Ballistix 8GB 1600MHz | SSD Transcend 370 128GB & HDD Seagate 5.4k 500GB | MSI B85-G43 | Corsair CX 500W | Zalman Z3 PLUS

Opublikowano
public static LinkedHashSet<Color> getColors() {
		LinkedHashSet<Color> colors = new LinkedHashSet<Color>();
		int red = 255;
		int green = 0;
		int blue = 0;
		int add = 1;
		
		for(int i = 1; true; i++) {
			
			colors.add(Color.fromRGB(red, green, blue));
			
			if(red == 255 && blue == 0 && (green >= 0 && green <= 255)) 
		        green += add(add, green);

		    if(green == 255 && blue == 0 && (red > 0 && red <= 255)) 
		        red -= remove(add, red);
		    
		    if(red == 0 && green == 255 && (blue >= 0 && blue < 255)) 
		        blue += add(add, blue);
		    
		    if(red == 0 && blue == 255 && (green > 0 && green <= 255)) 
		        green -= remove(add, green);
		    
		    if(green == 0 && blue == 255 && (red >= 0 && red <= 255)) 
		        red += add(add, red);
		    
		    if(red == 255 && green == 0 && (blue >= 0 && blue <= 255))   
		        blue -= remove(add, blue);
		    
		    if(red == 255 && green == 0 && blue == 0) {
		   	 System.out.println("Liczba kolorow: " + i);
		   	 break;
		    }
		}
		
		return colors;
	}
	
	public static int add(int add, int actual) {
		if(actual + add > 255) {
			return 255 - actual;
		} else {
			return add;
		}
	}
	
	public static int remove(int remove, int actual) {
		if(actual - remove < 0) {
			return actual;
		} else {
			return remove;
		}
	}

Kiedyś się tym bawiłem. Metoda getColors zwraca LinkedHashSet, w onEnalbe ją uruchomić, przypisać Seta do jakiejś zmiennej i potem w swoim tasku pobierasz kolejne elementy

 

lel, tylko niepotrzebnie pamięc wpierniczasz.

po co tu jakieś sety? o.O


    public class Colors
    {
        private int red   = 255;
        private int green = 0;
        private int blue  = 0;

        public Color getNext()
        {
            if (this.red == 255 && this.blue == 0 && (this.green >= 0 && this.green <= 255))
            {
                this.green += add(this.green);
            }
            if (this.green == 255 && this.blue == 0 && (this.red > 0 && this.red <= 255))
            {
                this.red -= remove(this.red);
            }
            if (this.red == 0 && this.green == 255 && (this.blue >= 0 && this.blue < 255))
            {
                this.blue += add(this.blue);
            }
            if (this.red == 0 && this.blue == 255 && (this.green > 0 && this.green <= 255))
            {
                this.green -= remove(this.green);
            }
            if (this.green == 0 && this.blue == 255 && (this.red >= 0 && this.red <= 255))
            {
                this.red += add(this.red);
            }
            if (this.red == 255 && this.green == 0 && (this.blue >= 0 && this.blue <= 255))
            {
                this.blue -= remove(this.blue);
            }
            return Color.fromRGB(this.red, this.green, this.blue);
        }

        public static int add(final int actual)
        {
            if (actual + 1 > 255)
            {
                return 255 - actual;
            }
            else
            {
                return 1;
            }
        }

        public static int remove(final int actual)
        {
            if (actual - 1 < 0)
            {
                return actual;
            }
            else
            {
                return 1;
            }
        }
    }

To samo, ale lepsze.

 

 

+ mój kodzik:

Prędkość można sobie zmieniać, można tez wywalić 'final' i zmieniać w locie.

Przy 50 już nieźle zapierdziela, przy 10 jest dość przyjemnie, a na 1 lub nawet 0.5 daje taki fajny powolny miły efekt :P

Kolorki są losowe, ale płynne :P

package test;

import java.util.Arrays;
import java.util.Random;

import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.plugin.java.JavaPlugin;

public class Test extends JavaPlugin
{
    private static final double SPEED = 50.0;
    private static final Random rand  = new Random();

    @Override
    public void onEnable()
    {
        final Color3D startColor = Color3D.getRandomColor();
        setArmorColor(Color3D.getRandomColor());
        Bukkit.getScheduler().runTaskTimer/*Asynchronously*/(this, new ColorTask(startColor), 1, 1);
    }

    private static void setArmorColor(final Color3D color)
    {
        Bukkit.getOnlinePlayers().stream().forEach(player -> {
            final PlayerInventory inventory = player.getInventory();
            Arrays.stream(inventory.getArmorContents()).filter(armor -> (armor != null) && (armor.getItemMeta() != null) && (armor.getItemMeta() instanceof LeatherArmorMeta)).forEach(armor -> {
                LeatherArmorMeta meta = (LeatherArmorMeta) armor.getItemMeta();
                meta.setColor(color.getBukkitColor());
                armor.setItemMeta(meta);
            });
        });
    }

    private static Color3D getDeltaColor(final Color3D from, final Color3D to)
    {
        final double deltaRed = to.getRed() - from.getRed();
        final double deltaGreen = to.getGreen() - from.getGreen();
        final double deltaBlue = to.getBlue() - from.getBlue();
        final double sum = (Math.abs(deltaRed) + Math.abs(deltaGreen) + Math.abs(deltaBlue)) / SPEED;
        return new Color3D(deltaRed / sum, deltaGreen / sum, deltaBlue / sum);
    }

    private static class ColorTask implements Runnable
    {
        private static final DoubleTriPredicate check = (cur, target, last) -> (cur >= target && last <= target) || (last >= target && cur <= target);
        private Color3D color;
        private Color3D targetColor;
        private Color3D deltaColor;

        private ColorTask(final Color3D startColor)
        {
            this.targetColor = startColor;
            this.updateTarget();
        }

        private void updateTarget()
        {
            this.color = this.targetColor;
            this.targetColor = Color3D.getRandomColor();
            this.updateDelta();
        }

        private boolean isTarget(final Color3D last)
        {
            return this.check.test(last.getRed(), this.targetColor.getRed(), this.color.getRed()) || this.check.test(last.getGreen(), this.targetColor.getGreen(), this.color.getGreen()) || this.check.test(last.getBlue(), this.targetColor.getBlue(), this.color.getBlue());
        }

        private void updateDelta()
        {
            this.deltaColor = getDeltaColor(this.color, this.targetColor);
        }

        private Color3D getNextColor()
        {
            final Color3D last = this.color;
            this.color = this.color.add(this.deltaColor);
            if (this.isTarget(last))
            {
                this.updateTarget();
            }
            return this.color;
        }

        @Override
        public void run()
        {
            setArmorColor(this.getNextColor());
        }

    }

    private static class Color3D
    {
        private final double r, g, b;

        private Color3D(final double r, final double g, final double 
        {
            this.r = r;
            this.g = g;
            this.b = b;
        }

        private Color3D add(final Color3D color)
        {
            return new Color3D(this.r + color.r, this.g + color.g, this.b + color.;
        }

        private double getRed()
        {
            return this.r;
        }

        private double getGreen()
        {
            return this.g;
        }

        private double getBlue()
        {
            return this.b;
        }

        private Color getBukkitColor()
        {
            return Color.fromRGB((int) this.r, (int) this.g, (int) this.;
        }

        private static Color3D getRandomColor()
        {
            return new Color3D(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
        }
    }

    @FunctionalInterface
    private interface DoubleTriPredicate
    {
        boolean test(double a, double b, double c);
    }
}

To już jest koniec smerfa:


http://www.mpcforum.pl/topic/1323530-info-znikam/


GG: 48522543


PS: Na innych forach i stronach znajdziesz mnie pod nickiem: 


BukkitSmerf

Opublikowano

Co do tematu to chyba nie wiesz jak disco zbroja dziala... Disco zbroja inni ja tylko widza a my widzimy ja jak shiftujemy. Oczywiscie pod spodem normalnego seta diamentowego mamy. Pakiety...

a27BfZc.jpg


#Typowo_na_MPC

Opublikowano

Co do tematu to chyba nie wiesz jak disco zbroja dziala... Disco zbroja inni ja tylko widza a my widzimy ja jak shiftujemy. Oczywiscie pod spodem normalnego seta diamentowego mamy. Pakiety...

packety nie sa konieczne ale 

chyba najlepsze 

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...