コード例 #1
0
  /**
   * If name isn't null. Make sure that the name doesn't see any other disguise. Else if name is
   * null. Make sure that the observers in the disguise don't see any other disguise.
   */
  public static void checkConflicts(TargetedDisguise disguise, String name) {
    // If the disguise is being used.. Else we may accidentally undisguise something else
    if (DisguiseAPI.isDisguiseInUse(disguise)) {
      Iterator<TargetedDisguise> disguiseItel =
          getDisguises().get(disguise.getEntity().getUniqueId()).iterator();
      // Iterate through the disguises
      while (disguiseItel.hasNext()) {
        TargetedDisguise d = disguiseItel.next();
        // Make sure the disguise isn't the same thing
        if (d != disguise) {
          // If the loop'd disguise is hiding the disguise to everyone in its list
          if (d.getDisguiseTarget() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
            // If player is a observer in the loop
            if (disguise.getDisguiseTarget()
                == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
              // If player is a observer in the disguise
              // Remove them from the loop
              if (name != null) {
                d.removePlayer(name);
              } else {
                for (String playername : disguise.getObservers()) {
                  d.silentlyRemovePlayer(playername);
                }
              }
            } else if (disguise.getDisguiseTarget()
                == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
              // If player is not a observer in the loop
              if (name != null) {
                if (!disguise.getObservers().contains(name)) {
                  d.removePlayer(name);
                }
              } else {
                for (String playername : new ArrayList<String>(d.getObservers())) {
                  if (!disguise.getObservers().contains(playername)) {
                    d.silentlyRemovePlayer(playername);
                  }
                }
              }
            }
          } else if (d.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
            // Here you add it to the loop if they see the disguise
            if (disguise.getDisguiseTarget()
                == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
              // Everyone who is in the disguise needs to be added to the loop
              if (name != null) {
                d.addPlayer(name);
              } else {
                for (String playername : disguise.getObservers()) {
                  d.silentlyAddPlayer(playername);
                }
              }
            } else if (disguise.getDisguiseTarget()
                == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
              // This here is a paradox.
              // If fed a name. I can do this.
              // But the rest of the time.. Its going to conflict.
              // The below is debug output. Most people wouldn't care for it.

              // System.out.print("Cannot set more than one " +
              // TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS
              // + " on a entity. Removed the old disguise.");

              disguiseItel.remove();
              d.removeDisguise();
            }
          }
        }
      }
    }
  }