Skip to content

Commit

Permalink
Version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RhysB committed Jan 4, 2023
1 parent 768755b commit cd950ce
Show file tree
Hide file tree
Showing 7 changed files with 1,096 additions and 0 deletions.
222 changes: 222 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@

# Created by https://www.gitignore.io/api/java,intellij,intellij+all,intellij+iml
# Edit at https://www.gitignore.io/?templates=java,intellij,intellij+all,intellij+iml

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
.idea/**/sonarlint/

# SonarQube Plugin
.idea/**/sonarIssues.xml

# Markdown Navigator plugin
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator/

### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff

# Generated files

# Sensitive or high-churn files

# Gradle

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake

# Mongo Explorer plugin

# File-based project format

# IntelliJ

# mpeltonen/sbt-idea plugin

# JIRA plugin

# Cursive Clojure plugin

# Crashlytics plugin (for Android Studio and IntelliJ)

# Editor-based Rest Client

# Android studio 3.1+ serialized cache file

### Intellij+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360

.idea/

# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

*.iml
modules.xml
.idea/misc.xml
*.ipr

# Sonarlint plugin
.idea/sonarlint

### Intellij+iml ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff

# Generated files

# Sensitive or high-churn files

# Gradle

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake

# Mongo Explorer plugin

# File-based project format

# IntelliJ

# mpeltonen/sbt-idea plugin

# JIRA plugin

# Cursive Clojure plugin

# Crashlytics plugin (for Android Studio and IntelliJ)

# Editor-based Rest Client

# Android studio 3.1+ serialized cache file

### Intellij+iml Patch ###
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023


### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# End of https://www.gitignore.io/api/java,intellij,intellij+all,intellij+iml
65 changes: 65 additions & 0 deletions src/com/johnymuffin/beta/jdetector/JDetector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.johnymuffin.beta.jdetector;

import com.johnymuffin.beta.jdetector.utils.BetaEvolutionsUtils;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

public class JDetector extends JavaPlugin {

//Basic Plugin Info
private static JDetector plugin;
private Logger log;
private String pluginName;
private PluginDescriptionFile pdf;

//IPCache
private JIPCache JIPCache;

private JSettings jSettings;

private HashMap<String, BetaEvolutionsUtils.VerificationResults> betaEVOVerificationResults = new HashMap<>();


@Override
public void onEnable() {
plugin = this;
log = this.getServer().getLogger();
pdf = this.getDescription();
pluginName = pdf.getName();
log.info("[" + pluginName + "] Is Loading, Version: " + pdf.getVersion());

this.JIPCache = new JIPCache(plugin);
this.jSettings = new JSettings(new File(this.getDataFolder(), "config.yml"));

JListener jListener = new JListener(this);
Bukkit.getPluginManager().registerEvents(jListener, this);
}

@Override
public void onDisable() {
log.info("[" + pluginName + "] Is Disabling, Version: " + pdf.getVersion());
JIPCache.saveData();
}

public JSettings getjSettings() {
return jSettings;
}

public HashMap<String, BetaEvolutionsUtils.VerificationResults> getBetaEVOVerificationResults() {
return betaEVOVerificationResults;
}

public com.johnymuffin.beta.jdetector.JIPCache getJIPCache() {
return JIPCache;
}

public void logger(Level level, String message) {
Bukkit.getLogger().log(level, "[" + pluginName + "] " + message);
}
}
90 changes: 90 additions & 0 deletions src/com/johnymuffin/beta/jdetector/JIPCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.johnymuffin.beta.jdetector;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;

public class JIPCache {
private JDetector plugin;
private JSONObject ipCacheJSON;
private File cacheFile;
private boolean memoryOnly = false;

public JIPCache(JDetector plugin) {
this.plugin = plugin;
cacheFile = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + "ipCache.json");
boolean isNew = false;
if (!cacheFile.exists()) {
cacheFile.getParentFile().mkdirs();
try {
FileWriter file = new FileWriter(cacheFile);
plugin.logger(Level.INFO, "Generating ipCache.json file");
ipCacheJSON = new JSONObject();
file.write(ipCacheJSON.toJSONString());
file.flush();
} catch (IOException e) {
e.printStackTrace();
}
isNew = true;
}

try {
plugin.logger(Level.INFO, "Reading ipCache.json file");
JSONParser parser = new JSONParser();
ipCacheJSON = (JSONObject) parser.parse(new FileReader(cacheFile));
} catch (ParseException e) {
plugin.logger(Level.WARNING, "ipCache.json file is corrupt, resetting file: " + e + " : " + e.getMessage());
ipCacheJSON = new JSONObject();
} catch (Exception e) {
plugin.logger(Level.WARNING, "ipCache.json file is corrupt, changing to memory only mode.");
memoryOnly = true;
ipCacheJSON = new JSONObject();
}
saveData();

}

public void saveIPData(String ip, boolean vpn) {
JSONObject ipData = new JSONObject();
ipData.put("vpn", vpn);
ipData.put("lastChecked", (System.currentTimeMillis()/1000L));
ipCacheJSON.put(ip, ipData);
this.saveData();
}

public boolean isIPSaved(String ip) {
return ipCacheJSON.containsKey(ip);
}

public boolean isVPN(String ip) {
return Boolean.valueOf(String.valueOf(((JSONObject) ipCacheJSON.get(ip)).get("vpn")));
}

public long getLastChecked(String ip) {
return Long.valueOf(String.valueOf(((JSONObject) ipCacheJSON.get(ip)).get("lastChecked")));
}

public void saveData() {
saveJsonArray();
}

private void saveJsonArray() {
if (memoryOnly) {
return;
}
try (FileWriter file = new FileWriter(cacheFile)) {
plugin.logger(Level.INFO, "Saving ipCache.json");
file.write(ipCacheJSON.toJSONString());
file.flush();
} catch (IOException e) {
plugin.logger(Level.WARNING, "Error saving ipCache.json: " + e + " : " + e.getMessage());
}
}

}
Loading

0 comments on commit cd950ce

Please sign in to comment.