Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.63 KB | None | 0 0
  1. package me.dadospeedy.myserverseasons.utils;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Random;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.SoundCategory;
  9. import org.bukkit.entity.Player;
  10.  
  11. import me.dadospeedy.myserverseasons.MyServerSeasons;
  12.  
  13. public class SoundLogic {
  14.  
  15.     static short status;
  16.     static boolean currentStatus;
  17.     static List<String> whatIsPlaying = new ArrayList<String>();
  18.     static Random random = new Random();
  19.  
  20.     public static void ambientSounds() {
  21.  
  22.         if (currentStatus) {
  23.             if (status == 0) {
  24.                 seasonAmbienceEnd();
  25.             } else {
  26.                 caveAmbience();
  27.             }
  28.         } else {
  29.             if (status == 1) {
  30.                 if (getCurrentTick() < 12000) {
  31.                     seasonDayCycleAmbienceStartFromSilence();
  32.                 } else {
  33.                     seasonNightCycleAmbienceStartFromSilence();
  34.                 }
  35.             } else {
  36.                 if (getCurrentTick() < 12000) {
  37.                     seasonDayCycleAmbienceMid();
  38.                 } else {
  39.                     seasonNightCycleAmbienceMid();
  40.                 }
  41.             }
  42.         }
  43.     }
  44.  
  45.     private static void broadcast(String msg) {
  46.         for(Player p : Bukkit.getOnlinePlayers()) {
  47.             p.sendMessage(msg);
  48.         }
  49.     }
  50.    
  51.     static void seasonDayCycleAmbienceMid() {
  52.         int size = whatIsPlaying.size();
  53.         seasonDayCycleAmbienceStartFromSilence();
  54.         String season = getSeason();
  55.        
  56.         switch (season) {
  57.         case "spring":
  58.             for (int i = 0; i < size; i++) {
  59.  
  60.                 switch (whatIsPlaying.get(i)) {
  61.  
  62.                 case "S_birds":
  63.                     play("M_birds", "E_birds", 600);
  64.                     break;
  65.  
  66.                 case "M_birds":
  67.                     play("M_birds", "E_birds", 500);
  68.                     break;
  69.  
  70.                 case "S_birds_2":
  71.                     play("M_birds_2", "E_birds_2", 600);
  72.                     break;
  73.  
  74.                 case "M_birds_2":
  75.                     play("M_birds_2", "E_birds_2", 500);
  76.                     break;
  77.  
  78.                 case "S_leaf_breeze_warm":
  79.                     play("M_leaf_breeze_warm", "E_leaf_breeze_warm", 800);
  80.                     break;
  81.  
  82.                 case "M_leaf_breeze_warm":
  83.                     play("M_leaf_breeze_warm", "E_leaf_breeze_warm", 700);
  84.                     break;
  85.  
  86.                 case "S_calm_birds_insects":
  87.                     play("M_calm_birds_insects", "E_calm_birds_insects", 800);
  88.                     break;
  89.  
  90.                 case "M_calm_birds_insects":
  91.                     play("M_calm_birds_insects", "E_calm_birds_insects", 700);
  92.                     break;
  93.  
  94.                 case "S_calm_forest":
  95.                     play("M_calm_forest", "E_calm_forest", 800);
  96.                     break;
  97.  
  98.                 case "M_calm_forest":
  99.                     play("M_calm_forest", "E_calm_forest", 700);
  100.                     break;
  101.  
  102.                 default:
  103.                     playEndSound(whatIsPlaying.get(i));
  104.                 }
  105.             }
  106.             break;
  107.         case "summer":
  108.             for (int i = 0; i < size; i++) {
  109.                 switch (whatIsPlaying.get(i)) {
  110.  
  111.                 case "S_leaf_breeze_warm":
  112.  
  113.                     play("M_leaf_breeze_warm", "E_leaf_breeze_warm", 800);
  114.                     break;
  115.  
  116.                 case "M_leaf_breeze_warm":
  117.  
  118.                     play("M_leaf_breeze_warm", "E_leaf_breeze_warm", 700);
  119.                     break;
  120.  
  121.                 case "S_insect_leaf_breeze_warm":
  122.  
  123.                     play("M_insect_leaf_breeze_warm", "E_insect_leaf_breeze_warm", 800);
  124.                     break;
  125.  
  126.                 case "M_insect_leaf_breeze_warm":
  127.  
  128.                     play("M_insect_leaf_breeze_warm", "E_insect_leaf_breeze_warm", 700);
  129.                     break;
  130.  
  131.                 case "S_calm_forest":
  132.  
  133.                     play("M_calm_forest", "E_calm_forest", 800);
  134.                     break;
  135.  
  136.                 case "M_calm_forest":
  137.  
  138.                     play("M_calm_forest", "E_calm_forest", 700);
  139.                     break;
  140.  
  141.                 case "S_birds_2":
  142.  
  143.                     play("M_birds_2", "E_birds_2", 600);
  144.                     break;
  145.  
  146.                 case "M_birds_2":
  147.  
  148.                     play("M_birds_2", "E_birds_2", 500);
  149.                     break;
  150.  
  151.                 default:
  152.                     playEndSound(whatIsPlaying.get(i));
  153.                 }
  154.             }
  155.             break;
  156.         case "fall":
  157.             for (int i = 0; i < size; i++) {
  158.                 switch (whatIsPlaying.get(i)) {
  159.                 case "S_calm_forest":
  160.  
  161.                     play("M_calm_forest", "E_calm_forest", 800);
  162.                     break;
  163.  
  164.                 case "M_calm_forest":
  165.  
  166.                     play("M_calm_forest", "E_calm_forest", 700);
  167.                     break;
  168.  
  169.                 case "S_calm_birds_insects":
  170.  
  171.                     play("M_calm_birds_insects", "E_calm_birds_insects", 600);
  172.                     break;
  173.  
  174.                 case "M_calm_birds_insects":
  175.  
  176.                     play("M_calm_birds_insects", "E_calm_birds_insects", 500);
  177.                     break;
  178.  
  179.                 case "S_calm_cold_wind":
  180.  
  181.                     play("M_calm_cold_wind", "E_calm_cold_wind", 800);
  182.                     break;
  183.  
  184.                 case "M_calm_cold_wind":
  185.  
  186.                     play("M_calm_cold_wind", "E_calm_cold_wind", 700);
  187.                     break;
  188.  
  189.                 default:
  190.                     playEndSound(whatIsPlaying.get(i));
  191.                 }
  192.             }
  193.             break;
  194.         case "winter":
  195.             for (int i = 0; i < size; i++) {
  196.                 switch (whatIsPlaying.get(i)) {
  197.  
  198.                 case "S_calm_forest":
  199.  
  200.                     play("M_calm_forest", "E_calm_forest", 800);
  201.                     break;
  202.  
  203.                 case "M_calm_forest":
  204.  
  205.                     play("M_calm_forest", "E_calm_forest", 700);
  206.                     break;
  207.  
  208.                 case "S_calm_cold_wind":
  209.  
  210.                     play("M_calm_cold_wind", "E_calm_cold_wind", 800);
  211.                     break;
  212.  
  213.                 case "M_calm_cold_wind":
  214.  
  215.                     play("M_calm_cold_wind", "E_calm_cold_wind", 700);
  216.                     break;
  217.  
  218.                 case "S_cold_wind":
  219.  
  220.                     play("M_cold_wind", "E_cold_wind", 800);
  221.                     break;
  222.  
  223.                 case "M_cold_wind":
  224.  
  225.                     play("M_cold_wind", "E_cold_wind", 700);
  226.                     break;
  227.  
  228.                 case "S_cold_wind_2":
  229.  
  230.                     play("M_cold_wind_2", "E_cold_wind_2", 800);
  231.                     break;
  232.  
  233.                 case "M_cold_wind_2":
  234.  
  235.                     play("M_cold_wind_2", "E_cold_wind_2", 700);
  236.                     break;
  237.  
  238.                 default:
  239.                     playEndSound(whatIsPlaying.get(i));
  240.                 }
  241.             }
  242.             break;
  243.         }
  244.         clearlast(size);
  245.         status = 0;
  246.     }
  247.  
  248.     static void seasonNightCycleAmbienceMid() {
  249.         int size = whatIsPlaying.size();
  250.         seasonNightCycleAmbienceStartFromSilence();
  251.         String season = getSeason();
  252.        
  253.         switch (season) {
  254.         case "spring":
  255.  
  256.             for (int i = 0; i < size; i++) {
  257.  
  258.                 switch (whatIsPlaying.get(i)) {
  259.  
  260.                 case "S_leaf_breeze_warm":
  261.  
  262.                     play("M_leaf_breeze_warm", "E_leaf_breeze_warm", 800);
  263.                     break;
  264.  
  265.                 case "M_leaf_breeze_warm":
  266.  
  267.                     play("M_leaf_breeze_warm", "E_leaf_breeze_warm", 700);
  268.                     break;
  269.  
  270.                 case "S_calm_birds_insects":
  271.  
  272.                     play("M_calm_birds_insects", "E_calm_birds_insects", 600);
  273.                     break;
  274.  
  275.                 case "M_calm_birds_insects":
  276.  
  277.                     play("M_calm_birds_insects", "E_calm_birds_insects", 500);
  278.                     break;
  279.  
  280.                 case "S_calm_forest":
  281.  
  282.                     play("M_calm_forest", "E_calm_forest", 600);
  283.                     break;
  284.  
  285.                 case "M_calm_forest":
  286.  
  287.                     play("M_calm_forest", "E_calm_forest", 500);
  288.                     break;
  289.  
  290.                 case "S_cricket":
  291.  
  292.                     play("M_cricket", "E_cricket", 600);
  293.                     break;
  294.  
  295.                 case "M_cricket":
  296.  
  297.                     play("M_cricket", "E_cricket", 500);
  298.                     break;
  299.  
  300.                 default:
  301.                     playEndSound(whatIsPlaying.get(i));
  302.                 }
  303.             }
  304.             break;
  305.         case "summer":
  306.  
  307.             for (int i = 0; i < size; i++) {
  308.  
  309.                 switch (whatIsPlaying.get(i)) {
  310.  
  311.                 case "S_leaf_breeze_warm":
  312.  
  313.                     play("M_leaf_breeze_warm", "E_leaf_breeze_warm", 800);
  314.                     break;
  315.  
  316.                 case "M_leaf_breeze_warm":
  317.  
  318.                     play("M_leaf_breeze_warm", "E_leaf_breeze_warm", 700);
  319.                     break;
  320.  
  321.                 case "S_calm_birds_insects":
  322.  
  323.                     play("M_calm_birds_insects", "E_calm_birds_insects", 500);
  324.                     break;
  325.  
  326.                 case "M_calm_birds_insects":
  327.  
  328.                     play("M_calm_birds_insects", "E_calm_birds_insects", 500);
  329.                     break;
  330.  
  331.                 case "S_calm_forest":
  332.  
  333.                     play("M_calm_forest", "E_calm_forest", 800);
  334.                     break;
  335.  
  336.                 case "M_calm_forest":
  337.  
  338.                     play("M_calm_forest", "E_calm_forest", 700);
  339.                     break;
  340.  
  341.                 case "S_cricket":
  342.  
  343.                     play("M_cricket", "E_cricket", 600);
  344.                     break;
  345.  
  346.                 case "M_cricket":
  347.  
  348.                     play("M_cricket", "E_cricket", 500);
  349.                     break;
  350.  
  351.                 default:
  352.                     playEndSound(whatIsPlaying.get(i));
  353.                 }
  354.             }
  355.             break;
  356.         case "fall":
  357.  
  358.             for (int i = 0; i < size; i++) {
  359.                 switch (whatIsPlaying.get(i)) {
  360.  
  361.                 case "S_calm_forest":
  362.  
  363.                     play("M_calm_forest", "E_calm_forest", 800);
  364.                     break;
  365.  
  366.                 case "M_calm_forest":
  367.  
  368.                     play("M_calm_forest", "E_calm_forest", 700);
  369.                     break;
  370.  
  371.                 case "S_calm_cold_wind":
  372.  
  373.                     play("M_calm_cold_wind", "E_calm_cold_wind", 500);
  374.                     break;
  375.  
  376.                 case "M_calm_cold_wind":
  377.  
  378.                     play("M_calm_cold_wind", "E_calm_cold_wind", 500);
  379.                     break;
  380.  
  381.                 case "S_cold_wind":
  382.  
  383.                     play("M_cold_wind", "E_cold_wind", 500);
  384.                     break;
  385.  
  386.                 case "M_cold_wind":
  387.  
  388.                     play("M_cold_wind", "E_cold_wind", 500);
  389.                     break;
  390.  
  391.                 default:
  392.                     playEndSound(whatIsPlaying.get(i));
  393.                 }
  394.             }
  395.             break;
  396.         case "winter":
  397.  
  398.             for (int i = 0; i < size; i++) {
  399.  
  400.                 switch (whatIsPlaying.get(i)) {
  401.  
  402.                 case "S_calm_cold_wind":
  403.  
  404.                     play("M_calm_cold_wind", "E_calm_cold_wind", 500);
  405.                     break;
  406.  
  407.                 case "M_calm_cold_wind":
  408.  
  409.                     play("M_calm_cold_wind", "E_calm_cold_wind", 500);
  410.                     break;
  411.  
  412.                 case "S_cold_wind":
  413.  
  414.                     play("M_cold_wind", "E_cold_wind", 500);
  415.                     break;
  416.  
  417.                 case "M_cold_wind":
  418.  
  419.                     play("M_cold_wind", "E_cold_wind", 500);
  420.                     break;
  421.  
  422.                 case "S_cold_wind_2":
  423.  
  424.                     play("M_cold_wind_2", "E_cold_wind_2", 500);
  425.                     break;
  426.  
  427.                 case "M_cold_wind_2":
  428.  
  429.                     play("M_cold_wind_2", "E_cold_wind_2", 500);
  430.                     break;
  431.  
  432.                 default:
  433.                     playEndSound(whatIsPlaying.get(i));
  434.                 }
  435.             }
  436.             break;
  437.         }
  438.         clearlast(size);
  439.         status = 0;
  440.     }
  441.  
  442.     static void seasonDayCycleAmbienceStartFromSilence() {
  443.         String season = getSeason();
  444.  
  445.         switch (season) {
  446.         case "spring":
  447.  
  448.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_birds"))) {
  449.                 play("S_birds", 300);
  450.             }
  451.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_birds_2"))) {
  452.                 play("S_birds_2", 300);
  453.             }
  454.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_leaf_breeze_warm"))) {
  455.                 play("S_leaf_breeze_warm", 300);
  456.             }
  457.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_calm_birds_insects"))) {
  458.                 play("S_calm_birds_insects", 300);
  459.             }
  460.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_calm_forest"))) {
  461.                 play("S_calm_forest", 300);
  462.             }
  463.  
  464.             break;
  465.         case "summer":
  466.  
  467.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_leaf_breeze_warm"))
  468.                     || !whatIsPlaying.stream().anyMatch(n -> n.endsWith("insect_leaf_breeze_warm"))) {
  469.                 play("S_leaf_breeze_warm", 300);
  470.             }
  471.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("insect_leaf_breeze_warm"))
  472.                     || !whatIsPlaying.stream().anyMatch(n -> n.endsWith("_leaf_breeze_warm"))) {
  473.                 play("S_insect_leaf_breeze_warm", 300);
  474.             }
  475.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_birds_2"))) {
  476.                 play("S_birds_2", 300);
  477.             }
  478.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_calm_forest"))) {
  479.                 play("S_calm_forest", 300);
  480.             }
  481.  
  482.             break;
  483.  
  484.         case "fall":
  485.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_calm_forest"))) {
  486.                 play("S_calm_forest", 300);
  487.             }
  488.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_calm_birds_insects"))) {
  489.                 play("S_calm_birds_insects", 300);
  490.             }
  491.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_calm_cold_wind"))) {
  492.                 play("S_calm_cold_wind", 100);
  493.             }
  494.             break;
  495.         case "winter":
  496.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_calm_forest"))) {
  497.                 play("S_calm_forest", 100);
  498.             }
  499.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_calm_cold_wind"))) {
  500.                 play("S_calm_cold_wind", 100);
  501.             }
  502.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_cold_wind"))) {
  503.                 play("S_cold_wind", 50);
  504.             }
  505.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_cold_wind_2"))) {
  506.                 play("S_cold_wind_2", 50);
  507.             }
  508.             break;
  509.  
  510.         }
  511.         status = 0;
  512.     }
  513.  
  514.     static void seasonNightCycleAmbienceStartFromSilence() {
  515.  
  516.         String season = getSeason();
  517.         switch (season) {
  518.         case "spring":
  519.  
  520.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_leaf_breeze_warm"))) {
  521.                 play("S_leaf_breeze_warm", 30);
  522.             }
  523.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_calm_birds_insects"))) {
  524.                 play("S_calm_birds_insects", 50);
  525.             }
  526.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_calm_forest"))) {
  527.                 play("S_calm_forest", 100);
  528.             }
  529.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_cricket"))) {
  530.                 play("S_cricket", 200);
  531.             }
  532.  
  533.             break;
  534.         case "summer":
  535.  
  536.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_leaf_breeze_warm"))) {
  537.                 play("S_leaf_breeze_warm", 30);
  538.             }
  539.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_calm_birds_insects"))) {
  540.                 play("S_calm_birds_insects", 50);
  541.             }
  542.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_calm_forest"))) {
  543.                 play("S_calm_forest", 50);
  544.             }
  545.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_cricket"))) {
  546.                 play("S_cricket", 200);
  547.             }
  548.  
  549.             break;
  550.  
  551.         case "fall":
  552.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_calm_forest"))) {
  553.                 play("S_calm_forest", 30);
  554.             }
  555.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_calm_cold_wind"))) {
  556.                 play("S_calm_cold_wind", 200);
  557.             }
  558.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_cold_wind_2"))) {
  559.                 play("S_cold_wind_2", 50);
  560.             }
  561.             break;
  562.         case "winter":
  563.  
  564.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_calm_cold_wind"))) {
  565.                 play("S_calm_cold_wind", 100);
  566.             }
  567.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_cold_wind"))) {
  568.                 play("S_cold_wind", 50);
  569.             }
  570.             if (!whatIsPlaying.stream().anyMatch(n -> n.endsWith("_cold_wind_2"))) {
  571.                 play("S_cold_wind_2", 50);
  572.             }
  573.             break;
  574.  
  575.         }
  576.  
  577.         status = 0;
  578.  
  579.     }
  580.  
  581.     static void caveAmbience() {
  582.         // -> Spiele sehr selten die zur Jahreszeit gehörigen Cave Tunes (5% maybe?)
  583.         String season = getSeason();
  584.  
  585.         switch (season) {
  586.         case "spring":
  587.             play("SINGLE_spring_cave", 50);
  588.             break;
  589.         case "summer":
  590.             play("SINGLE_summer_cave", 50);
  591.             break;
  592.         case "fall":
  593.             play("SINGLE_fall_cave", 50);
  594.             break;
  595.         case "winter":
  596.             play("SINGLE_winter_cave", 16);
  597.             play("SINGLE_winter_cave_2", 16);
  598.             play("SINGLE_winter_cave_3", 16);
  599.             break;
  600.         }
  601.         status = 1;
  602.     }
  603.  
  604.     private static void playEndSound(String sound) {
  605.         if (sound.startsWith("M_") || sound.startsWith("S_")) {
  606.             play("E_" + sound.substring(2));
  607.         }
  608.     }
  609.  
  610.     static void seasonAmbienceEnd() {
  611.         for (String s : whatIsPlaying) {
  612.             playEndSound(s);
  613.         }
  614.     }
  615.  
  616.     private static long getCurrentTick() {
  617.         return Bukkit.getWorld(MyServerSeasons.currentSeason.getWorld()).getTime();
  618.     }
  619.  
  620.     private static String getSeason() {
  621.         return MyServerSeasons.currentSeason.toString().toLowerCase();
  622.     }
  623.  
  624.     static void play(String name, String name2, int probabilityForTheFirstToPlay) {
  625.         if (random.nextInt(1000) < probabilityForTheFirstToPlay) {
  626.             play(name);
  627.         } else {
  628.             play(name2);
  629.         }
  630.     }
  631.  
  632.     static void play(String name) {
  633.         play(name, 1001);
  634.     }
  635.  
  636.     static void play(String name, int probability) {
  637.         if (random.nextInt(1000) < probability) {
  638.             broadcast("§aNow playing: §6" + name);
  639.             for(Player p : Bukkit.getOnlinePlayers()) {
  640.                 p.playSound(p.getLocation(), "ambient." + name.toLowerCase(), SoundCategory.VOICE, 1000, 1);
  641.             }
  642.             whatIsPlaying.add(name);
  643.         }
  644.     }
  645.  
  646.     static void clearlast(int size) {
  647.         for (int i = 0; i < size; i++) {
  648.             whatIsPlaying.remove(0);
  649.         }
  650.     }
  651.  
  652.     static void setStatus(short status) {
  653.         SoundLogic.status = status;
  654.     }
  655. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement