Change Render distance while server is running?

Discussion in 'Plugin Development' started by Meatiex, Oct 4, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Meatiex

    You know the view-distance property in every server's server.proprty file?
    Does anyone know how to edit this while the server is running? (like via command)

    Outdated...
    dev.bukkit.org/bukkit-plugins/dynamic-view-distance/
    uhh...
    dev.bukkit.org/bukkit-plugins/maxtps/files/6-max-tps-1-2-4/

    Any help is awesome :D
     
  2. Offline

    EvilWitchdoctor

    You probably already know this, but the view-distance setting in the .properties file does not actually change a player's view distance, it just sets the maximum that the server will load from where the player is standing (or something like that I believe)

    I can think of only 2 ways to do this, the first would be to have your code load and edit the server.properties file then reload the server, the second would be to use NMS and dig into the actual craftbukkit for a way to change it, and that would involve some research before I could offer much help with it.
    Aside from the point, what do you plan to use this for? :)
     
    Meatiex likes this.
  3. Offline

    Meatiex

    basically a rave in minecraft, I have put together some cool effects: strobe light and uh.... effect
    If you have any ssuggestionsto make the code below better feel free to tell me :D

    I see that mcp is out for minecraft 1.7.10, meaning that i'll probably just make a optional mod for my players to use for the fog to update.
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. if (sender instanceof Player) {
    3. Player player = (Player) sender;
    4. if (args.length == 1) {
    5. if (args[0].equals("strobe")) {
    6. rave("strobe", player);
    7. }
    8. if (args[0].equals("fade")) {
    9. rave("fade", player);
    10. }
    11. if (args[0].equals("all")) {
    12. rave("strobe", player);
    13. rave("fade", player);
    14. }
    15. } else {player.sendMessage(ChatColor.GREEN + "/rave " + ChatColor.GRAY + "strobe, fade, all");}
    16. }
    17. return true;
    18. }
    19. public void rave(String msg, Player player) {
    20. if (msg == "fade") {
    21. if (fade == true) {
    22. fade = false;
    23. } else {
    24. fade = true;
    25. fade();
    26. }
    27. } else if (msg == "strobe") {
    28. if (strobe == true) {
    29. strobe = false;
    30. } else {
    31. strobe = true;
    32. strobe();
    33. }
    34. }
    35. }
    36. public void fade() {
    37. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    38. @Override
    39. public void run() {
    40. if (fade == true) {
    41. for (Player p : Bukkit.getOnlinePlayers()) {
    42. p.removePotionEffect(PotionEffectType.BLINDNESS);
    43. p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1));
    44. }
    45.  
    46. if (fade_count == 40) {
    47. fade = false;
    48. for (Player p : Bukkit.getOnlinePlayers())
    49. p.removePotionEffect(PotionEffectType.BLINDNESS);
    50. fade_count = 0;
    51. } else {
    52. fade_count = fade_count + 1;
    53. fade();
    54. }
    55. }
    56. }
    57. }, 15L);
    58. }
    59. public void strobe() {
    60. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    61. @Override
    62. public void run() {
    63. if (strobe == true) {
    64. if (time <= 3) {
    65. time = time + 1;
    66. Bukkit.getWorld("World").setTime(18000);
    67. } else {
    68. time = 0;
    69. Bukkit.getWorld("World").setTime(6000);
    70. }
    71. if (count == 40) {
    72. strobe = false;
    73. Bukkit.getWorld("World").setTime(18000);
    74. count = 0;
    75. } else {
    76. count = count + 1;
    77. strobe();
    78. }
    79. }
    80. }
    81. }, 1L);
    82. }
     
  4. Offline

    EvilWitchdoctor

    Meatiex It looks good to me. :D
    One thing that you could do is use an enum (similar to bukkit itself) for RaveType.
    Here's how I probably would have approached it: (BTW ignore the enum not being indented here)

    Code:java
    1. enum RaveType{FADE,STROBE,ALL};
    2.  
    3. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    4. if(!(sender instanceof Player)) return false;
    5.  
    6. if(cmd.getName().equalsIgnoreCase("rave")){
    7. Player player = (Player) sender;
    8.  
    9. if(args.length > 0) {
    10. int duration = 100;
    11. if(args.length >= 2) duration = Integer.parseInt(args[1]);
    12.  
    13. if(args[0].equals("strobe")) rave(RaveType.STROBE, player, duration);
    14.  
    15. else if(args[0].equals("fade")) rave(RaveType.FADE, player, duration);
    16.  
    17. else if(args[0].equals("all")) rave(RaveType.ALL, player, duration);
    18.  
    19. else{
    20. player.sendMessage(ChatColor.RED + "Unknown rave type!");
    21. player.sendMessage(ChatColor.GREEN + "/rave " + ChatColor.GRAY + "strobe, fade, all");
    22. }
    23. }
    24. return true;
    25. }
    26. return false;
    27. }
    28.  
    29. public void rave(RaveType type, Player player, int duration) {
    30. switch(type){
    31. case FADE:
    32. if(fade == true) fade = false;
    33. else{
    34. fade = true;
    35. fade(duration);
    36. }
    37. break;
    38.  
    39. case STROBE:
    40. if(strobe == true) strobe = false;
    41. else{
    42. strobe = true;
    43. strobe(duration);
    44. }
    45. break;
    46.  
    47. case ALL:
    48. rave(RaveType.FADE, player, duration);
    49. rave(RaveType.STROBE, player, duration);
    50. break;
    51. }
    52. }
    53.  
    54. public void fade(final int duration) {
    55. getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    56. @Override
    57. public void run() {
    58. if (fade == true) {
    59. for (Player p : getServer().getOnlinePlayers()) {
    60. p.removePotionEffect(PotionEffectType.BLINDNESS);
    61. p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1));//blindness 2 for 1 second
    62. }
    63.  
    64. if (fade_count == duration/15) {
    65. fade = false;
    66. fade_count = 0;
    67. }
    68. else {
    69. fade_count++;
    70. fade(duration);
    71. }
    72. }
    73. }
    74. }, 15L);
    75. }
    76.  
    77. public void strobe(final int duration) {
    78. getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    79. @Override
    80. public void run() {
    81. if (strobe == true) {
    82. if (strobe_count % 2 == 0) {// when strobe count is even/odd
    83. getServer().getWorlds().get(0).setTime(18000);
    84. }
    85. else{
    86. getServer().getWorlds().get(0).setTime(6000);
    87. }
    88. if (strobe_count == duration) {
    89. strobe = false;
    90. // ends with night
    91. getServer().getWorlds().get(0).setTime(18000);
    92. strobe_count = 0;
    93. }
    94. else {
    95. strobe_count++;
    96. strobe(duration);
    97. }
    98. }
    99. }
    100. }, 1L);
    101. }
     
    Meatiex likes this.
  5. Offline

    Meatiex

  6. Offline

    _Filip

    Meatiex likes this.
  7. Offline

    mazentheamazin

    EvilWitchdoctor
    1. Okay, how is Bukkit an enum? Clearly you are not aware of how Bukkit works or what an enum actually is
    2. On the Bukkit Forums, if you're going to give code at all, make sure if follows or is similar to Oracle's conventions. Just some food for though.
    3. This isn't the 'Code Spoonfeed' section, this is the 'Plugin Development' section where users ask for help.
    4. The fuck is '== true'? Seriously, the redundancy. If you're going to provide help at all, the least you can do is make sure that you're experienced in the area.
    5. The code here physically hurts me, learn some Java before coming onto any form of large API.
     
    Meatiex likes this.
  8. Offline

    Opacification

    That's the best code i've seen in my life, redundancy is redundant.
    Code:java
    1. private omg yes;
    2. yes = omg;
    3. //best java code n/a
     
    Meatiex likes this.
  9. Offline

    Meatiex

    @Burrito
    The code simply does this:
    Code:java
    1. //If fade = true, make it false
    2. if(fade == true) fade = false;
    3. //if fade = false, make it true
    4. else {
    5. fade = true;
    6. //if fade = false, run the function
    7. fade(duration);
    8. //This simply turns fade on and off with /rave fade
    9. }


    Please try to read code a little more carefully before you jump to conclusions next time.
    PS: the code works great.
    @mazentheamazin
    As for bukkit being like an enum I think he was referring to the variables like Material.SAND and Entity.ZOMBIE, I understood it, but I can see how their could have been some confusion.
     
  10. Offline

    EvilWitchdoctor

    Firstly sorry for being offline for a couple days
    @mazentheamazin @Meatiex Yes, I misused the world "enum" when comparing to to the way bukkit manages types, but I think most of you got what I meant (my bad there).
    As for the redundancies, I had simply copied the original code and modified parts of it (not rewritten it all), and I chose to leave in things like if(something = true) to help make it more readable to developers.
    And yes, if you've look at some of my other code on bukkit, I usually do use boolValue = !boolValue; or some other method to switch booleans, but once again I'll say that is reader-friendly (less like English, comparable to if you didn't comment any of your code!)
     
    Meatiex likes this.
  11. EvilWitchdoctor I'd actually say that most would argue that that approach is actually less readable. For example, if(player.isSneaking()) is more readable than if(player.isSneaking() == true)
     
    Meatiex likes this.
  12. Offline

    EvilWitchdoctor

    That's very true, I guess it depends on the situation and the variables.
    "if(fade)" is less readable then "if(fadeActive)" or "if(fade == true)", unless the reader knows about the fade variable
     
    Meatiex and ferrybig like this.
Thread Status:
Not open for further replies.

Share This Page