<commit_before>package com.arckenver.nations;

import java.io.File;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.args.GenericArguments;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.config.DefaultConfig;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.event.service.ChangeServiceProviderEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.service.economy.EconomyService;
import org.spongepowered.api.text.Text;

import com.arckenver.nations.cmdelement.CitizenNameElement;
import com.arckenver.nations.cmdelement.NationNameElement;
import com.arckenver.nations.cmdelement.PlayerNameElement;
import com.arckenver.nations.cmdexecutor.NationAdminExecutor;
import com.arckenver.nations.cmdexecutor.NationAdminSetpresExecutor;
import com.arckenver.nations.cmdexecutor.NationBuyextraExecutor;
import com.arckenver.nations.cmdexecutor.NationCitizenExecutor;
import com.arckenver.nations.cmdexecutor.NationClaimExecutor;
import com.arckenver.nations.cmdexecutor.NationClaimOutpostExecutor;
import com.arckenver.nations.cmdexecutor.NationCreateExecutor;
import com.arckenver.nations.cmdexecutor.NationDelspawnExecutor;
import com.arckenver.nations.cmdexecutor.NationDepositExecutor;
import com.arckenver.nations.cmdexecutor.NationExecutor;
import com.arckenver.nations.cmdexecutor.NationFlagExecutor;
import com.arckenver.nations.cmdexecutor.NationHereExecutor;
import com.arckenver.nations.cmdexecutor.NationInfoExecutor;
import com.arckenver.nations.cmdexecutor.NationInviteExecutor;
import com.arckenver.nations.cmdexecutor.NationJoinExecutor;
import com.arckenver.nations.cmdexecutor.NationKickExecutor;
import com.arckenver.nations.cmdexecutor.NationLeaveExecutor;
import com.arckenver.nations.cmdexecutor.NationListExecutor;
import com.arckenver.nations.cmdexecutor.NationMinisterExecutor;
import com.arckenver.nations.cmdexecutor.NationPermExecutor;
import com.arckenver.nations.cmdexecutor.NationResignExecutor;
import com.arckenver.nations.cmdexecutor.NationSetspawnExecutor;
import com.arckenver.nations.cmdexecutor.NationSpawnExecutor;
import com.arckenver.nations.cmdexecutor.NationUnclaimExecutor;
import com.arckenver.nations.cmdexecutor.NationWithdrawExecutor;
import com.arckenver.nations.cmdexecutor.ZoneBuyExecutor;
import com.arckenver.nations.cmdexecutor.ZoneCoownerExecutor;
import com.arckenver.nations.cmdexecutor.ZoneCreateExecutor;
import com.arckenver.nations.cmdexecutor.ZoneDelownerExecutor;
import com.arckenver.nations.cmdexecutor.ZoneExecutor;
import com.arckenver.nations.cmdexecutor.ZoneFlagExecutor;
import com.arckenver.nations.cmdexecutor.ZoneInfoExecutor;
import com.arckenver.nations.cmdexecutor.ZoneListExecutor;
import com.arckenver.nations.cmdexecutor.ZonePermExecutor;
import com.arckenver.nations.cmdexecutor.ZoneSellExecutor;
import com.arckenver.nations.cmdexecutor.ZoneSetownerExecutor;
import com.arckenver.nations.listener.BuildPermListener;
import com.arckenver.nations.listener.ExplosionListener;
import com.arckenver.nations.listener.FireListener;
import com.arckenver.nations.listener.GoldenAxeListener;
import com.arckenver.nations.listener.InteractPermListener;
import com.arckenver.nations.listener.MobSpawningListener;
import com.arckenver.nations.listener.PlayerConnectionListener;
import com.arckenver.nations.listener.PlayerMoveListener;
import com.arckenver.nations.listener.PvpListener;
import com.arckenver.nations.object.Nation;
import com.arckenver.nations.service.NationsService;
import com.arckenver.nations.task.TaxesCollectRunnable;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;

@Plugin(id = "com.arckenver.nations", name = "Nations", version = "0.1", description = "A towny-like worldguard-like zone managment plugin.")
public class NationsPlugin
{
	private File rootDir;

	private static NationsPlugin plugin;

	@Inject
	private Logger logger;

	@Inject
	@DefaultConfig(sharedRoot = true)
	private File configFile;

	private EconomyService economyService = null;

	@Listener
	public void onInit(GameInitializationEvent event)
	{
		plugin = this;

		rootDir = new File(configFile.getParentFile(), "nations");

		ConfigHandler.init(logger, rootDir);
		LanguageHandler.init(logger, rootDir);
		DataHandler.init(logger, rootDir);

		Sponge.getServiceManager().setProvider(this, NationsService.class, new NationsService());
	}

	@Listener
	public void onStart(GameStartedServerEvent event)
	{
		LanguageHandler.load();
		DataHandler.load();

		CommandSpec nationAdminSetpresCmd = CommandSpec.builder()
				.description(Text.of(""))
				.permission("nations.command.nationadmin.setpres")
				.arguments(
						GenericArguments.optional(new NationNameElement(Text.of("nation"))),
						GenericArguments.optional(new PlayerNameElement(Text.of("president"))))
				.executor(new NationAdminSetpresExecutor())
				.build();

		CommandSpec nationAdminSetnameCmd = CommandSpec.builder()
				.description(Text.of(""))
				.permission("nations.command.nationadmin.setname")
				.arguments(
						GenericArguments.optional(new NationNameElement(Text.of("oldname"))),
						GenericArguments.optional(GenericArguments.string(Text.of("newname"))))
				.executor(new NationAdminSetpresExecutor())
				.build();<commit_msg>Get economy service if present<commit_after>package com.arckenver.nations;

import java.io.File;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.args.GenericArguments;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.config.DefaultConfig;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.event.service.ChangeServiceProviderEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.service.economy.EconomyService;
import org.spongepowered.api.text.Text;

import com.arckenver.nations.cmdelement.CitizenNameElement;
import com.arckenver.nations.cmdelement.NationNameElement;
import com.arckenver.nations.cmdelement.PlayerNameElement;
import com.arckenver.nations.cmdexecutor.NationAdminExecutor;
import com.arckenver.nations.cmdexecutor.NationAdminSetpresExecutor;
import com.arckenver.nations.cmdexecutor.NationBuyextraExecutor;
import com.arckenver.nations.cmdexecutor.NationCitizenExecutor;
import com.arckenver.nations.cmdexecutor.NationClaimExecutor;
import com.arckenver.nations.cmdexecutor.NationClaimOutpostExecutor;
import com.arckenver.nations.cmdexecutor.NationCreateExecutor;
import com.arckenver.nations.cmdexecutor.NationDelspawnExecutor;
import com.arckenver.nations.cmdexecutor.NationDepositExecutor;
import com.arckenver.nations.cmdexecutor.NationExecutor;
import com.arckenver.nations.cmdexecutor.NationFlagExecutor;
import com.arckenver.nations.cmdexecutor.NationHereExecutor;
import com.arckenver.nations.cmdexecutor.NationInfoExecutor;
import com.arckenver.nations.cmdexecutor.NationInviteExecutor;
import com.arckenver.nations.cmdexecutor.NationJoinExecutor;
import com.arckenver.nations.cmdexecutor.NationKickExecutor;
import com.arckenver.nations.cmdexecutor.NationLeaveExecutor;
import com.arckenver.nations.cmdexecutor.NationListExecutor;
import com.arckenver.nations.cmdexecutor.NationMinisterExecutor;
import com.arckenver.nations.cmdexecutor.NationPermExecutor;
import com.arckenver.nations.cmdexecutor.NationResignExecutor;
import com.arckenver.nations.cmdexecutor.NationSetspawnExecutor;
import com.arckenver.nations.cmdexecutor.NationSpawnExecutor;
import com.arckenver.nations.cmdexecutor.NationUnclaimExecutor;
import com.arckenver.nations.cmdexecutor.NationWithdrawExecutor;
import com.arckenver.nations.cmdexecutor.ZoneBuyExecutor;
import com.arckenver.nations.cmdexecutor.ZoneCoownerExecutor;
import com.arckenver.nations.cmdexecutor.ZoneCreateExecutor;
import com.arckenver.nations.cmdexecutor.ZoneDelownerExecutor;
import com.arckenver.nations.cmdexecutor.ZoneExecutor;
import com.arckenver.nations.cmdexecutor.ZoneFlagExecutor;
import com.arckenver.nations.cmdexecutor.ZoneInfoExecutor;
import com.arckenver.nations.cmdexecutor.ZoneListExecutor;
import com.arckenver.nations.cmdexecutor.ZonePermExecutor;
import com.arckenver.nations.cmdexecutor.ZoneSellExecutor;
import com.arckenver.nations.cmdexecutor.ZoneSetownerExecutor;
import com.arckenver.nations.listener.BuildPermListener;
import com.arckenver.nations.listener.ExplosionListener;
import com.arckenver.nations.listener.FireListener;
import com.arckenver.nations.listener.GoldenAxeListener;
import com.arckenver.nations.listener.InteractPermListener;
import com.arckenver.nations.listener.MobSpawningListener;
import com.arckenver.nations.listener.PlayerConnectionListener;
import com.arckenver.nations.listener.PlayerMoveListener;
import com.arckenver.nations.listener.PvpListener;
import com.arckenver.nations.object.Nation;
import com.arckenver.nations.service.NationsService;
import com.arckenver.nations.task.TaxesCollectRunnable;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;

@Plugin(id = "com.arckenver.nations", name = "Nations", version = "0.1", description = "A towny-like worldguard-like zone managment plugin.")
public class NationsPlugin
{
	private File rootDir;

	private static NationsPlugin plugin;

	@Inject
	private Logger logger;

	@Inject
	@DefaultConfig(sharedRoot = true)
	private File configFile;

	private EconomyService economyService = null;

	@Listener
	public void onInit(GameInitializationEvent event)
	{
		plugin = this;

		rootDir = new File(configFile.getParentFile(), "nations");

		ConfigHandler.init(logger, rootDir);
		LanguageHandler.init(logger, rootDir);
		DataHandler.init(logger, rootDir);

		Sponge.getServiceManager().setProvider(this, NationsService.class, new NationsService());
	}

	@Listener
	public void onStart(GameStartedServerEvent event)
	{
		LanguageHandler.load();
		DataHandler.load();
		
		Sponge.getServiceManager()
				.getRegistration(EconomyService.class)
				.ifPresent(prov -> economyService = prov.getProvider());
		
		CommandSpec nationAdminSetpresCmd = CommandSpec.builder()
				.description(Text.of(""))
				.permission("nations.command.nationadmin.setpres")
				.arguments(
						GenericArguments.optional(new NationNameElement(Text.of("nation"))),
						GenericArguments.optional(new PlayerNameElement(Text.of("president"))))
				.executor(new NationAdminSetpresExecutor())
				.build();

		CommandSpec nationAdminSetnameCmd = CommandSpec.builder()
				.description(Text.of(""))
				.permission("nations.command.nationadmin.setname")
				.arguments(
						GenericArguments.optional(new NationNameElement(Text.of("oldname"))),
						GenericArguments.optional(GenericArguments.string(Text.of("newname"))))
				.executor(new NationAdminSetpresExecutor())
				.build();
{'fraction_non_alphanumeric': 0.0986970961423827, 'fraction_numerical': 0.0005109426892616878, 'mean_word_length': 7.149895905621096, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7585752', 'n_tokens_mistral': 3936, 'n_tokens_neox': 3840, 'n_words': 488}