Why not switch the block behind the sign when the server is online or offline?

Discussion in 'Plugin Development' started by ToldiIII, Aug 14, 2017.

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

    ToldiIII

    So, as in the title, why not change the block behind the sign?
    Here is the code:
    HTML:
        public void updateSign() {
            if (plugin.getConfig().getString("options.background").equalsIgnoreCase("wool")) {
                updateBackground(Material.WOOL, getStartingColor(motd));
              } else if (plugin.getConfig().getString("options.background").equalsIgnoreCase("glass")) {
                updateBackground(Material.STAINED_GLASS, getStartingColor(motd));
              } else if (plugin.getConfig().getString("options.background").equalsIgnoreCase("clay")) {
                updateBackground(Material.STAINED_CLAY, getStartingColor(motd));
              }
        }
    
          private int getStartingColor(String s) {
            if (s.length() > 1) {
              if (s.toCharArray()[0] == 'ยง') {
                switch (s.toCharArray()[1]) {
                case '0':
                  return 15;
                case '1':
                  return 11;
                case '2':
                  return 13;
                case '3':
                  return 9;
                case '4':
                  return 14;
                case '5':
                  return 10;
                case '6':
                  return 1;
                case '7':
                  return 8;
                case '8':
                  return 7;
                case '9':
                  return 3;
                case 'a':
                  return 5;
                case 'b':
                  return 9;
                case 'c':
                  return 14;
                case 'd':
                  return 2;
                case 'e':
                  return 4;
                case 'f':
                  return 0;
                }
                return 0;
              }
              return 0;
            }
            return 0;
          }
    
          private void updateBackground(Material mat, int color) {
              try {
            Location loc3 = this.getLocation();
            Sign s = (Sign) loc3.getBlock().getState();
            if (s.getType() == Material.WALL_SIGN) {
              BlockFace bf = ((Directional)s.getData()).getFacing();
              Location loc2 = new Location(loc3.getWorld(), loc3.getBlockX() - bf.getModX(), loc3.getBlockY() - bf.getModY(), loc3.getBlockZ() - bf.getModZ());
              Block wall = loc2.getBlock();
              wall.setType(mat);
              wall.setData((byte) color);
            }
              } catch (ClassCastException e) {
                  e.printStackTrace();
                  plugin.logConsole(Level.WARNING, "[Signs] Error: " + e);
              }
          }
    Here is the config:
    Open! (open)
    options:
    background: glass

    Images:
    Open! (open)
    Online sign:
    [​IMG]
    Offline sign:
    [​IMG]
     
    Last edited: Aug 14, 2017
  2. Offline

    timtower Administrator Administrator Moderator

    @ToldiIII can't the player just add it to the server list?
     
  3. Offline

    ToldiIII

    @timtower
    No.
     
  4. Offline

    timtower Administrator Administrator Moderator

    Bungeecord?
     
  5. Offline

    ToldiIII

    @timtower
    Yes and bukkit + spigot. (1.8)
     
  6. Offline

    timtower Administrator Administrator Moderator

    Locked
    Bungeecord requires offline mode
    Offline mode is not supported by Bukkit
     
Thread Status:
Not open for further replies.

Share This Page