Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MeMyselfMC committed Jan 12, 2018
0 parents commit d8850c8
Show file tree
Hide file tree
Showing 10 changed files with 1,087 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: java
jdk:
- oraclejdk8
notifications:
email: true
sudo: false
Binary file added dependencies/geoipAPI.jar
Binary file not shown.
54 changes: 54 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.memyself</groupId>
<artifactId>addresswhitelist</artifactId>
<version>1.0</version>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>eu.theindra</groupId>
<artifactId>geoip</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/dependencies/geoipAPI.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<finalName>AddressWhitelist</finalName>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
66 changes: 66 additions & 0 deletions src/main/java/io/memyself/addresswhitelist/AddressWhitelist.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package io.memyself.addresswhitelist;

import java.io.File;

import org.bukkit.ChatColor;

import org.bukkit.entity.Player;

import org.bukkit.plugin.java.JavaPlugin;

import io.memyself.addresswhitelist.bstats.MetricsLite;

public class AddressWhitelist
extends JavaPlugin {

@Override
public void onEnable() {
if(!new File(getDataFolder(), "config.yml").exists()) {
saveDefaultConfig();

reloadConfig();
}
new Utilities(this);

getServer().getPluginManager().registerEvents(new EventListener(this), this);

getCommand("addresswhitelist").setExecutor(new CommandManager(this));

if(getConfig().getBoolean("options.metrics")) {
if(getConfig().getBoolean("options.debug")) getLogger().info("[DEBUG] Will be attempting to submit statistics to bStats.org.");

new MetricsLite(this);
}

getLogger().info("AddressWhitelist v" + getDescription().getVersion() + " has been enabled!");

int kickCount = 0;

for(Player player : getServer().getOnlinePlayers()) {
if(!getConfig().getBoolean("options.inverted")) {
if(!getConfig().getStringList("list").contains(player.getAddress().getHostString())) {
player.kickPlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("locale.kick-messages.not-in-whitelist")));

kickCount++;
}
} else {
if(getConfig().getStringList("list").contains(player.getAddress().getHostString())) {
player.kickPlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("locale.kick-messages.in-blacklist")));

kickCount++;
}
}
}

if(kickCount > 0) {
if(kickCount == 1) if(getConfig().getBoolean("options.debug")) getLogger().info("[DEBUG] 1 player was kicked because their IP address was " + (!getConfig().getBoolean("options.inverted") ? "not whitelisted." : "blacklisted."));
else if(getConfig().getBoolean("options.debug")) getLogger().info("[DEBUG] " + kickCount + " players were kicked because their IP addresses were " + (!getConfig().getBoolean("options.inverted") ? "not whitelisted." : "blacklisted."));
}
}

@Override
public void onDisable() {
getLogger().info("AddressWhitelist v" + getDescription().getVersion() + " has been disabled.");
}

}
Loading

0 comments on commit d8850c8

Please sign in to comment.