Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // IPRestrict.java
- package com.wolfy9247.iprestrict;
- import java.util.logging.Logger;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.plugin.PluginDescriptionFile;
- import org.bukkit.plugin.java.JavaPlugin;
- public class IPRestrict extends JavaPlugin {
- public static IPRestrict instance;
- protected FileConfiguration config;
- public final Logger log = Logger.getLogger("Minecraft");
- public static String logTag = "[AdminIP] ";
- @Override
- public void onDisable() {
- PluginDescriptionFile pdfFile = this.getDescription();
- log.info(logTag + pdfFile.getName() + " v" + pdfFile.getVersion() + " disabled!");
- }
- @Override
- public void onEnable() {
- instance = this;
- PluginDescriptionFile pdfFile = this.getDescription();
- getConfig().options().copyDefaults(true);
- saveConfig();
- new IPRestrictJoinListener(this);
- registerCommands();
- log.info(logTag + pdfFile.getName() + " v" + pdfFile.getVersion() + " enabled!");
- }
- private void registerCommands() {
- }
- public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
- if(!cmd.isRegistered()) {
- return false;
- }
- else if(commandLabel.equalsIgnoreCase("ipr")) {
- for(int i = 0; i < 3; i++) {
- if(args[i].isEmpty()) {
- return false;
- }
- }
- if(args[0] == "set") {
- if(Bukkit.getPlayer(args[1]) == null) {
- sender.sendMessage(ChatColor.RED + "The player you have entered is invalid!");
- return false;
- }
- Object[] playerIPs = getConfig().getList(instance + "." + sender.getName()).toArray();
- int lastIndex = playerIPs.length + 1;
- getConfig().set(instance + "." + sender.getName(), args[2]); // Need to figure out how to set next line "-";
- return true;
- }
- else if(args[0] == "remove") {
- if(Bukkit.getPlayer(args[1]) == null) {
- sender.sendMessage(ChatColor.RED + "The player you have entered is invalid!");
- return false;
- }
- // Figure out how to remove a line if found.
- }
- return false;
- }
- return true;
- }
- }
- // IPRestrictJoinListener.java
- package com.wolfy9247.iprestrict;
- import java.net.InetSocketAddress;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerJoinEvent;
- public class IPRestrictJoinListener implements Listener {
- public static IPRestrict plugin;
- public IPRestrictJoinListener(IPRestrict plugin) {
- plugin.getServer().getPluginManager().registerEvents(this, plugin);
- }
- @EventHandler
- void onPlayerJoin(PlayerJoinEvent event) {
- Player player = event.getPlayer();
- InetSocketAddress joinIP = event.getPlayer().getAddress();
- Object[] playerIPs = plugin.getConfig().getList(plugin + "." + player.getName()).toArray();
- for(int i = 0; i < playerIPs.length; i++) {
- if(joinIP != playerIPs[i]) {
- if(player.isOp()) {
- return;
- }
- else {
- player.kickPlayer(plugin.getConfig().getString("IPRestrict.Kick Message"));
- }
- }
- else {
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement