Skip to content

Commit

Permalink
True initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Sep 11, 2020
1 parent f992b6a commit 0c2482b
Show file tree
Hide file tree
Showing 7 changed files with 407 additions and 0 deletions.
113 changes: 113 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# User-specific stuff
.idea/

*.iml
*.ipr
*.iws

# IntelliJ
out/

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# 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*

*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

target/

pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next

release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
.flattened-pom.xml

# Common working directory
run/
116 changes: 116 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>com.github.doctormacc</groupId>
<artifactId>GeyserPreventServerSwitch</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>GeyserPreventServerSwitch</name>

<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<repositories>
<repository>
<id>nukkitx-release-repo</id>
<url>https://repo.nukkitx.com/maven-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>nukkitx-snapshot-repo</id>
<url>https://repo.nukkitx.com/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.15-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.9.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>bootstrap-bungeecord</artifactId>
<version>1.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>floodgate-bungee</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.doctormacc.geyserpreventserverswitch;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;

@JsonIgnoreProperties(ignoreUnknown = true)
public class Config {

@Getter
@JsonProperty("prohibited-servers")
private String[] prohibitedServers;

@Getter
@JsonProperty("message")
private String message;

@Getter
@JsonProperty("use-floodgate")
private boolean useFloodgate;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.doctormacc.geyserpreventserverswitch;

import lombok.AllArgsConstructor;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.event.ServerConnectEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;

@AllArgsConstructor
public class Events implements Listener {

private final GeyserPreventServerSwitch plugin;

@EventHandler
public void onServerConnect(ServerConnectEvent event) {
if (plugin.getProhibitedServers().contains(event.getTarget().getName())) {
if (plugin.isBedrockPlayer(event.getPlayer().getUniqueId())) {
if (plugin.getConfig().getMessage() != null && !plugin.getConfig().getMessage().equals("")) {
event.getPlayer().sendMessage(new TextComponent(plugin.getConfig().getMessage()));
}
if (event.getPlayer().getServer() == null) {
// Go to the first fallback server.
if (!event.getPlayer().getPendingConnection().getListener().getServerPriority().isEmpty()) {
event.setTarget(plugin.getProxy().getServers().get(event.getPlayer().getPendingConnection().getListener().getServerPriority().get(0)));
}
} else {
event.setCancelled(true);
}
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.github.doctormacc.geyserpreventserverswitch;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import lombok.Getter;
import net.md_5.bungee.api.plugin.Plugin;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.floodgate.FloodgateAPI;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;

public final class GeyserPreventServerSwitch extends Plugin {

@Getter
private Config config;

/**
* A list of all prohibited servers, in a List.
*/
@Getter
private List<String> prohibitedServers;

@Override
public void onEnable() {

if (!getDataFolder().exists())
getDataFolder().mkdir();

try {
if (!getDataFolder().exists())
getDataFolder().mkdir();
File configFile = new File(getDataFolder(), "config.yml");
if (!configFile.exists()) {
configFile.createNewFile();
FileOutputStream fos = new FileOutputStream(configFile);
InputStream input = GeyserPreventServerSwitch.class.getResourceAsStream("/config.yml"); // resources need leading "/" prefix

byte[] bytes = new byte[input.available()];

input.read(bytes);

for(char c : new String(bytes).toCharArray()) {
fos.write(c);
}

fos.flush();
input.close();
fos.close();
}

ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
config = objectMapper.readValue(configFile, Config.class);
} catch (IOException ex) {
getLogger().log(Level.WARNING, "Failed to read config!", ex);
ex.printStackTrace();
}

if (!config.isUseFloodgate() && getProxy().getPluginManager().getPlugin("Geyser-BungeeCord") == null) {
getLogger().log(Level.SEVERE, "Geyser-BungeeCord not found! Disabling...");
onDisable();
return;
} else if (config.isUseFloodgate() && getProxy().getPluginManager().getPlugin("floodgate-bungee") == null) {
getLogger().log(Level.SEVERE, "Floodgate not found! Disabling...");
onDisable();
return;
}

prohibitedServers = Arrays.asList(config.getProhibitedServers());

getProxy().getPluginManager().registerListener(this, new Events(this));
}

@Override
public void onDisable() {
getProxy().getPluginManager().unregisterListeners(this);
config = null;
prohibitedServers = null;
}

/**
* Determines if a player is from Bedrock
* @param uuid the UUID to determine
* @return true if the player is from Bedrock
*/
public boolean isBedrockPlayer(UUID uuid) {
if (!config.isUseFloodgate()) {
for (GeyserSession session : GeyserConnector.getInstance().getPlayers()) {
if (session.getPlayerEntity().getUuid().equals(uuid)) {
return true;
}
}
} else {
return FloodgateAPI.isBedrockPlayer(uuid);
}
return false;
}
}
Loading

0 comments on commit 0c2482b

Please sign in to comment.