Content from the web displayed in minecraft

Discussion in 'Spigot Plugin Help' started by LacoDev, Mar 17, 2020.

Thread Status:
Not open for further replies.
  1. Hey guys,
    I have a little problem and I hope you can help me fix it.

    I want to get the content from a simple html document on my webserver.

    I currently have this:
    Code (Java):

    package de.lacodev.globalshop.commands;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.URL;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.libs.org.apache.commons.io.IOUtils;
    import org.bukkit.entity.Player;
    import de.lacodev.globalshop.Main;
    import de.lacodev.globalshop.mysql.MySQL;
    import de.lacodev.globalshop.utils.GlobalShop;
    public class CMD_GlobalShop implements CommandExecutor {
     
     public String status;
     @Override
     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
      if(sender instanceof Player) {
       
       Player p = (Player)sender;
       
       
       // StatusCodes:
       // Webservice is defined as the ShopDashboard at https://www.lacodev.de/globalshop/
       // 1 : Webservice stable
       // 2 : Webservice maintained
       // 3 : Webservice disabled
       
       // /globalshop - Opens Interface of MainMenu
       // /globalshop status - Gives the administrators info about current serverstatus
       // /globalshop createwebaccount - Creates an temporarily account with an random password to access the shop dashboard
       if(args.length == 0) {
        GlobalShop.openMainMenu(p);
       } else if(args.length == 1) {
        if(args[0].toLowerCase().equalsIgnoreCase("status")) {
         if(p.hasPermission("globalshop.status")) {
          try {
           checkForStatus(new URL("https://www.lacodev.de/globalshop/status/index.html"));
          } catch (IOException e) {
           e.printStackTrace();
           p.sendMessage(Main.getPrefix() + "§7Our webservice is experiencing some issues! please try again later!");
          }
         
          if(status == "Status-Code: 1") {
           p.sendMessage(Main.getPrefix() + "§7Webservice §8» §aOnline");
           if(MySQL.isConnected()) {
            p.sendMessage(Main.getPrefix() + "§7Database-Service §8» §aOnline");
           } else {
            p.sendMessage(Main.getPrefix() + "§7Database-Service §8» §cOffline");
           }
          } else if(status == "Status-Code: 2") {
           p.sendMessage(Main.getPrefix() + "§7Webservice §8» §6Maintained");
           if(MySQL.isConnected()) {
            p.sendMessage(Main.getPrefix() + "§7Database-Service §8» §aOnline");
           } else {
            p.sendMessage(Main.getPrefix() + "§7Database-Service §8» §cOffline");
           }
          } else if(status == "Status-Code: 3") {
           p.sendMessage(Main.getPrefix() + "§7Webservice §8» §cDisabled");
           if(MySQL.isConnected()) {
            p.sendMessage(Main.getPrefix() + "§7Database-Service §8» §aOnline");
           } else {
            p.sendMessage(Main.getPrefix() + "§7Database-Service §8» §cOffline");
           }
          }
         }
        }
       }
       
      } else {
       sender.sendMessage(Main.getPrefix() + "You have to be a player!");
      }
      return false;
     }
     
     
     private void checkForStatus(URL url) throws IOException {
      BufferedReader reader = null;
      StringBuilder build = new StringBuilder(128000);
      try {
       reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
       int count;
       char[]data = new char[5000];
       while((count = reader.read(data)) != -1) {
        build.append(data, 0, count);
       }
      }finally {
       IOUtils.closeQuietly(reader);
      }
      status = build.toString();
     }
    }
     
    but it does not work...

    Every help is highly appreciated
     
  2. SteelPhoenix

    Moderator

    1) Why are you doing I/O sync?
    2) Why are you not using the ChatColor enum?
    3) Why do you have 4 million nested if statements?
    4) Why do your StringBuilder and char buffer have such gigantic capacities?
    5) What's with all the static?
    6) Why are you comparing String (reference type) objects using ==?

    And are there any errors etc?
     
  3. I actually found the error through this thanks alot
     
Thread Status:
Not open for further replies.