<commit_before>/*
 * Copyright 2016 <NAME> <<EMAIL>>
 * and other copyright owners as documented in the project's IP log.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.basinmc.sink;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.nio.file.Path;
import java.nio.file.Paths;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.dedicated.DedicatedPlayerList;
import net.minecraft.server.dedicated.DedicatedServer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.basinmc.faucet.Handled;
import org.basinmc.faucet.Server;
import org.springframework.stereotype.Service;

/**
 * Abstracts access to the server configuration and state.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
@Service
public class SinkServer implements Server, Handled<DedicatedServer> {

  private static final Logger logger = LogManager.getFormatterLogger(SinkServer.class);

  private final DedicatedServer server;
  private final Configuration configuration = new Configuration();

  public SinkServer(@NonNull DedicatedServer server) {
    this.server = server;
    logger.debug("Faucet services are ready for consumption");
  }

  /**
   * {@inheritDoc}
   */
  @NonNull
  @Override
  public String getVersion() {
    return this.server.getMinecraftVersion();
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public boolean isOnlineMode() {
    return this.server.isServerInOnlineMode();
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public void shutdown(@Nullable String reason) {
    // TODO Fire shutdown event here, once I add it. :)
    this.server.logInfo("Server Shutdown: " + reason);

    DedicatedPlayerList playerList = this.server.getPlayerList();
    playerList.getPlayers().forEach(EntityPlayerMP::disconnect); // TODO: Restore reason

    this.server.stopServer();
  }

  /**
   * {@inheritDoc}
   */
  @NonNull
  @Override
  public Path getBaseDirectory() {
    // TODO: Add support for a variable base directory since this might be useful in order to share jars
    return Paths.get(".");
  }

  /**
   * {@inheritDoc}
   */
  @NonNull
  @Override
  public Server.Configuration getConfiguration() {
    return this.configuration;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public int getLifeTime() {
    return this.server.getTickCounter();
  }

  /**
   * {@inheritDoc}
   */
  @NonNull
  @Override
  public DedicatedServer getHandle() {
    return this.server;
  }

  private class Configuration implements Server.Configuration {

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean areCommandBlocksEnabled() {
      return SinkServer.this.server.isCommandBlockEnabled();
    }

    /**
     * {@inheritDoc}
     */
    @NonNull
    @Override
    public String getHostname() {
      return SinkServer.this.server.getServerHostname();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getMaximumConcurrentPlayers() {
      return SinkServer.this.server.getMaxPlayers();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getMaximumBuildHeight() {
      return SinkServer.this.server.getBuildLimit();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public long getMaximumTickTime() {
      return SinkServer.this.server.getMaxTickTime();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getNetworkCompressionThreshold() {
      return SinkServer.this.server.getNetworkCompressionThreshold();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getOperatorPermissionLevel() {
      return SinkServer.this.server.getOpPermissionLevel();
    }

    /**
     * {@inheritDoc}
     */<commit_msg>Added compatibility for the integrated server implementation.<commit_after>/*
 * Copyright 2016 <NAME> <<EMAIL>>
 * and other copyright owners as documented in the project's IP log.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.basinmc.sink;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.nio.file.Path;
import java.nio.file.Paths;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.basinmc.faucet.Handled;
import org.basinmc.faucet.Server;
import org.springframework.stereotype.Service;

/**
 * Abstracts access to the server configuration and state.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
@Service
public class SinkServer implements Server, Handled<MinecraftServer> {

  private static final Logger logger = LogManager.getFormatterLogger(SinkServer.class);

  private final MinecraftServer server;
  private final Configuration configuration = new Configuration();

  public SinkServer(@NonNull MinecraftServer server) {
    this.server = server;
    logger.debug("Faucet services are ready for consumption");
  }

  /**
   * {@inheritDoc}
   */
  @NonNull
  @Override
  public String getVersion() {
    return this.server.getMinecraftVersion();
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public boolean isOnlineMode() {
    return this.server.isServerInOnlineMode();
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public void shutdown(@Nullable String reason) {
    // TODO Fire shutdown event here, once I add it. :)
    this.server.logInfo("Server Shutdown: " + reason);

    var playerList = this.server.getPlayerList();
    playerList.getPlayers().forEach(EntityPlayerMP::disconnect); // TODO: Restore reason

    this.server.stopServer();
  }

  /**
   * {@inheritDoc}
   */
  @NonNull
  @Override
  public Path getBaseDirectory() {
    // TODO: Add support for a variable base directory since this might be useful in order to share jars
    return Paths.get(".");
  }

  /**
   * {@inheritDoc}
   */
  @NonNull
  @Override
  public Server.Configuration getConfiguration() {
    return this.configuration;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public int getLifeTime() {
    return this.server.getTickCounter();
  }

  /**
   * {@inheritDoc}
   */
  @NonNull
  @Override
  public MinecraftServer getHandle() {
    return this.server;
  }

  private class Configuration implements Server.Configuration {

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean areCommandBlocksEnabled() {
      return SinkServer.this.server.isCommandBlockEnabled();
    }

    /**
     * {@inheritDoc}
     */
    @NonNull
    @Override
    public String getHostname() {
      return SinkServer.this.server.getServerHostname();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getMaximumConcurrentPlayers() {
      return SinkServer.this.server.getMaxPlayers();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getMaximumBuildHeight() {
      return SinkServer.this.server.getBuildLimit();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public long getMaximumTickTime() {
      return 0;
//      return SinkServer.this.server.getMaxTickTime();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getNetworkCompressionThreshold() {
      return SinkServer.this.server.getNetworkCompressionThreshold();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getOperatorPermissionLevel() {
      return SinkServer.this.server.getOpPermissionLevel();
    }

    /**
     * {@inheritDoc}
     */
{'fraction_non_alphanumeric': 0.11416539946192537, 'fraction_numerical': 0.0024564276523570006, 'mean_word_length': 3.1324311261478974, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6075126', 'n_tokens_mistral': 2523, 'n_tokens_neox': 2459, 'n_words': 632}