Initial commit for Gitea

java
Etzelia 2018-09-12 11:01:20 -05:00 committed by John Olheiser
commit 20b2c7891b
7 changed files with 384 additions and 0 deletions

4
.gitignore vendored 100644
View File

@ -0,0 +1,4 @@
.idea/
*.iml
target/
dependency-reduced-pom.xml

137
pom.xml 100644
View File

@ -0,0 +1,137 @@
<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>xyz.etztech</groupId>
<artifactId>CommandListener</artifactId>
<!-- Version is used in plugin.yml -->
<version>1.4</version>
<packaging>jar</packaging>
<!-- Plugin Information -->
<!-- Name, Description, and URL are used in plugin.yml -->
<name>CommandListener</name>
<description>A plugin that listens on a designated socket for command input.</description>
<url>http://www.etztech.xyz</url>
<licenses>
<license>
<name>Zlib License</name>
<url>http://opensource.org/licenses/Zlib</url>
<comments>Copyright (c) 2017 EtzTech
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.</comments>
</license>
</licenses>
<developers>
<developer>
<name>EtzTech</name>
<url>http://www.etztech.xyz</url>
</developer>
</developers>
<properties>
<!-- Author and MainClass are used in plugin.yml -->
<author>EtzTech</author>
<mainClass>xyz.etztech.commandlistener.CommandListener</mainClass>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.1-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>mvn-repo</id>
<url>https://mvnrepository.com/artifact/</url>
</repository>
<repository> <!-- This repo fixes issues with transitive dependencies -->
<id>jcenter</id>
<url>http://jcenter.bintray.com</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<defaultGoal>clean install</defaultGoal>
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- Keeping filtering at true here reduces plugin.yml redundancy! -->
<filtering>true</filtering>
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<!-- Keep filtering at false for other resources to prevent bad magic -->
<filtering>false</filtering>
<excludes>
<exclude>**/*.java</exclude>
<exclude>plugin.yml</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>xyz.etztech.commandlistener.CommandListener</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,59 @@
package xyz.etztech.commandlistener;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import xyz.etztech.commandlistener.command.CommandMain;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
public class CommandListener extends JavaPlugin {
private static CommandListener instance;
public static FileConfiguration config;
private Logger log = Logger.getLogger( "Minecraft" );
private List<String> hookCommands = new ArrayList<>();
@Override
public void onEnable() {
instance = this;
saveDefaultConfig();
loadConfig();
if (isEnabled()) {
CommandMain cmdMain = new CommandMain(this);
this.getCommand("commandlistener").setExecutor(cmdMain);
cmdMain.startThread();
Bukkit.getConsoleSender().sendMessage("Command Listener has started successfully.");
}
}
@Override
public void onDisable() {
}
public void loadConfig() {
config = Bukkit.getPluginManager().getPlugin("CommandListener").getConfig();
}
@Override
public void reloadConfig() {
super.reloadConfig();
loadConfig();
}
public void log(String message) {
log.info( "[CommandListener]: " + message );
}
}

View File

@ -0,0 +1,68 @@
package xyz.etztech.commandlistener;
import org.bukkit.Bukkit;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class CommandListenerThread extends Thread {
private boolean running = true;
private CommandListener plugin;
public CommandListenerThread(CommandListener plugin) {this.plugin = plugin;}
public boolean getRunning() {
return running;
}
public void setRunning(boolean running) {
this.running = running;
}
public void run() {
List<String> commands = this.plugin.getConfig().getStringList("commands");
try {
ServerSocket cmdSock = new ServerSocket(this.plugin.getConfig().getInt("port"), 0, InetAddress.getByName(null));
while (getRunning()) {
Socket data = cmdSock.accept();
BufferedReader myInput = new BufferedReader(new InputStreamReader(data.getInputStream()));
String buf = myInput.readLine();
if (buf != null) {
String[] input = buf.split(" ");
String base = input[0];
ArrayList<String> args = new ArrayList<>();
if (input.length > 1) {
args = new ArrayList<>(Arrays.asList(buf.split(" ")));
args.remove(0);
}
if (this.plugin.getConfig().getBoolean("verbose")) {
Bukkit.getConsoleSender().sendMessage("Received input '" + buf + "'");
Bukkit.getConsoleSender().sendMessage("Base Command '" + base + "'");
Bukkit.getConsoleSender().sendMessage("Arguments '" + args.toString() + "'");
}
if (commands.contains(base)) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), buf);
} else if (this.plugin.getConfig().getBoolean("verbose")){
Bukkit.getConsoleSender().sendMessage("Input not recognized, ignoring.");
}
}
}
Bukkit.getConsoleSender().sendMessage("Closing CommandListener on Port " + this.plugin.getConfig().get("port"));
cmdSock.close();
} catch (Exception ex) {
Bukkit.getConsoleSender().sendMessage("Error: " + ex.getMessage());
}
}
}

View File

@ -0,0 +1,87 @@
package xyz.etztech.commandlistener.command;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import xyz.etztech.commandlistener.CommandListener;
import xyz.etztech.commandlistener.CommandListenerThread;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
public class CommandMain implements CommandExecutor {
CommandListener plugin;
private CommandListenerThread cmdThread;
public CommandMain(CommandListener plugin) {
this.plugin = plugin;
this.cmdThread = new CommandListenerThread(plugin);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String base, String[] args) {
if (sender.hasPermission("commandlistener.use")) {
if (args.length == 0) {
String version = Bukkit.getPluginManager().getPlugin("CommandListener").getDescription().getVersion();
sender.sendMessage(ChatColor.GOLD + "----- CommandListener v" + version + " -----");
sender.sendMessage(ChatColor.YELLOW + "Developed by EtzTech for 24CarrotCraft");
} else if (args.length == 1) {
switch (args[0]) {
case "help":
sender.sendMessage(ChatColor.GOLD + "----- CommandListener Commands -----");
sender.sendMessage(ChatColor.YELLOW + "/cl reload - Reload the config");
sender.sendMessage(ChatColor.YELLOW + "/cl port - Display the port CommandListener is on");
break;
case "port":
sender.sendMessage("CommandListener is listening on port " + plugin.getConfig().getInt("port"));
break;
case "reload":
try {
stopThread();
Thread.sleep(1000);
this.plugin.reloadConfig();
Thread.sleep(1000);
startThread();
sender.sendMessage("CommandListener reloaded.");
} catch (Exception ex) {
sender.sendMessage("CommandListener reload was interrupted.");
}
break;
}
} else {
return false;
}
} else {
sender.sendMessage(ChatColor.RED + "You do not have permission to use CommandListener.");
return false;
}
return true;
}
public void startThread() {
Bukkit.getConsoleSender().sendMessage("Starting Command Listener on Port " + plugin.getConfig().get("port"));
cmdThread.setRunning(true);
Thread th = new Thread(cmdThread);
th.start();
}
public void stopThread() {
cmdThread.setRunning(false);
try {
Socket trashSock = new Socket("127.0.0.1", plugin.getConfig().getInt("port"));
DataOutputStream trashStream = new DataOutputStream(trashSock.getOutputStream());
trashStream.writeUTF("trash");
trashStream.flush();
trashStream.close();
} catch (IOException ex) {
Bukkit.getConsoleSender().sendMessage("Error: " + ex.getMessage());
}
}
}

View File

@ -0,0 +1,15 @@
# The port to listen for commands on
port: 8888
# A list of commands that can be used with CommandListner
# Any command sent to the above port that is not in this list will be discarded
commands:
- commandlistener
- cl
hooks:
carrotchat: false
# Whether to print extra to the console
# Mostly useful for debugging
verbose: false

View File

@ -0,0 +1,14 @@
name: ${name}
version: ${version}
description: ${description}
author: ${author}
website: ${url}
main: ${mainClass}
softdepend: [CarrotChat]
commands:
commandlistener:
aliases: [cl]
permissions:
commandlistener.use:
description: Allows use of CommandListener commands
default: op