Created
December 4, 2014 23:54
-
-
Save SupaHam/3f4c760139a7dfd41ed2 to your computer and use it in GitHub Desktop.
Create a colourful sky. The SkyColors are best rendered during day. These colors were the best I could find without repeating them. This triggers a rain effect (on the client side), so it would be wise to cover their heads with blocks, especially far above so they don't hear the rain sounds. I'd recommend Barrier blocks at level 256 in adjacent …
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.supaham.bukkittesting.protolib; | |
import com.comphenix.protocol.PacketType; | |
import com.comphenix.protocol.ProtocolManager; | |
import com.comphenix.protocol.events.PacketContainer; | |
import com.supaham.bukkittesting.BukkitTesting; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.block.Action; | |
import org.bukkit.event.player.PlayerInteractEvent; | |
import org.bukkit.event.player.PlayerJoinEvent; | |
import org.bukkit.scheduler.BukkitRunnable; | |
import java.lang.reflect.InvocationTargetException; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Random; | |
public class RainbowSky extends ProtoBase { | |
private Random random = new Random(); | |
private Map<Player, SkyColor> last = new HashMap<>(); | |
public RainbowSky(BukkitTesting instance) { | |
super(instance); | |
} | |
@EventHandler | |
public void playerJoin(final PlayerJoinEvent event) { | |
new BukkitRunnable() { | |
@Override | |
public void run() { | |
Player player = event.getPlayer(); | |
SkyColor skyColor = last.get(player); | |
SkyColor rand; | |
do { | |
rand = SkyColor.values()[random.nextInt(SkyColor.values().length)]; | |
if (skyColor != null && rand.equals(skyColor)) { | |
rand = null; | |
} | |
} while(rand == null); | |
try { | |
rand.show(mgr, player); | |
} catch (InvocationTargetException e) { | |
e.printStackTrace(); | |
} | |
last.put(player, rand); | |
} | |
}.runTaskTimer(plugin, 40L, 10L); | |
} | |
public static PacketContainer changeGameState(int reason, float value) { | |
PacketContainer packet = new PacketContainer(PacketType.Play.Server.GAME_STATE_CHANGE); | |
packet.getIntegers().write(0, reason); | |
packet.getFloat().write(0, value); | |
return packet; | |
} | |
public enum SkyColor { | |
DARK_GOLD(2, 0), | |
DARK_RED(3, 0), | |
DARKER_RED(4, 0), | |
DARKEST_RED(5, 0), | |
BLACK(2, 1), | |
DARKER_BLUE(3, 1), | |
DARK_BLUE(4, 1), | |
AQUA(5, 1), | |
LIGHT_BLUE(6, 1), | |
DARK_BLUE_2(3, 2), | |
AQUA_2(4, 2), | |
LIGHT_BLUE_2(5, 2), | |
BLUE_GOLD(3, 3), | |
AQUA_3(4, 3), | |
SEPIA_BLACK(1, 5), | |
SEPIA_DARKER_BLACK(2, 5), | |
SEPIA_DARKEST_BLACK(1, 6), | |
LIGHT_SEPIA_BLACK(2, 6), | |
BLUE_SKY_DARK_TERRAIN(3, 9), | |
; | |
private final float i1; | |
private final float i2; | |
SkyColor(float i1, float i2) { | |
this.i1 = i1; | |
this.i2 = i2; | |
} | |
public void show(ProtocolManager mgr, Player player) throws InvocationTargetException { | |
mgr.sendServerPacket(player, changeGameState(7, i1)); | |
mgr.sendServerPacket(player, changeGameState(8, i2)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment