Moved features to separate projects

This commit is contained in:
2018-09-24 12:51:02 +02:00
commit 8383a77730
35 changed files with 1009 additions and 0 deletions

18
Borders/.classpath Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src" including="**/*.java"/>
<classpathentry kind="output" path="target/classes"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="/MarwCore"/>
<classpathentry kind="lib" path="/home/erik/Dokumenty/Java/marwland/res/MassiveCore.jar"/>
<classpathentry kind="lib" path="/home/erik/Dokumenty/Java/marwland/res/Factions.jar"/>
<classpathentry kind="var" path="M2_REPO/org/spigotmc/spigot-api/1.12-R0.1-SNAPSHOT/spigot-api-1.12-R0.1-SNAPSHOT.jar" sourcepath="M2_REPO/org/spigotmc/spigot-api/1.12-R0.1-SNAPSHOT/spigot-api-1.12-R0.1-SNAPSHOT-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/commons-lang/commons-lang/2.6/commons-lang-2.6.jar" sourcepath="M2_REPO/commons-lang/commons-lang/2.6/commons-lang-2.6-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/com/googlecode/json-simple/json-simple/1.1.1/json-simple-1.1.1.jar" sourcepath="M2_REPO/com/googlecode/json-simple/json-simple/1.1.1/json-simple-1.1.1-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/junit/junit/4.10/junit-4.10.jar" sourcepath="M2_REPO/junit/junit/4.10/junit-4.10-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar" sourcepath="M2_REPO/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/com/google/guava/guava/21.0/guava-21.0.jar" sourcepath="M2_REPO/com/google/guava/guava/21.0/guava-21.0-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/com/google/code/gson/gson/2.8.0/gson-2.8.0.jar" sourcepath="M2_REPO/com/google/code/gson/gson/2.8.0/gson-2.8.0-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/yaml/snakeyaml/1.18/snakeyaml-1.18.jar" sourcepath="M2_REPO/org/yaml/snakeyaml/1.18/snakeyaml-1.18-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-SNAPSHOT.jar" sourcepath="M2_REPO/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-SNAPSHOT-sources.jar"/>
</classpath>

2
Borders/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/bin/
/target/

20
Borders/.project Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Borders</name>
<comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
<projects>
<project>MarwCore</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,13 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=10
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=10
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=10

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

30
Borders/pom.xml Normal file
View File

@ -0,0 +1,30 @@
<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>cz.marwland.mc.features</groupId>
<artifactId>Borders</artifactId>
<parent>
<groupId>cz.marwland.mc</groupId>
<artifactId>MarwStuff</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../MarwStuff</relativePath>
</parent>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>cz.marwland.mc</groupId>
<artifactId>MarwCore</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,230 @@
package cz.marwland.mc.features;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.util.StringUtil;
import org.bukkit.util.Vector;
import cz.marwland.mc.core.config.ConfigEntry;
import cz.marwland.mc.core.config.EntryManager;
import cz.marwland.mc.core.config.IValueExecuter;
import cz.marwland.mc.core.config.ValueValidator;
import cz.marwland.mc.core.features.Feature;
import net.md_5.bungee.api.ChatColor;
public class Borders extends Feature {
FileConfiguration cfg;
EntryManager emgr = new EntryManager();
public Borders() {
super();
// String name, String description, String usageMessage, List<String> aliases)
this.addCommand(new BukkitCommand(
"worldborder",
"Modify the world's borders",
"/border [world] (key) (value)",
Arrays.asList() ) {
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!permissionMissingCheck(sender, this.getPermission()))
return false;
if (args.length < 2) {
sender.sendMessage(
ChatColor.YELLOW + "Format: " +
ChatColor.GRAY + ChatColor.ITALIC + "/" + commandLabel +
ChatColor.YELLOW + ChatColor.GRAY + " (world) (key) [value]");
return true;
}
World w = Bukkit.getServer().getWorld(args[0]);
if (w == null) {
sender.sendMessage(ChatColor.RED + "Invalid world!");
return true;
}
ConfigEntry<?> entry = emgr.getEntry(args[1]);
if (entry == null) {
sender.sendMessage(
ChatColor.RED + "Invalid key " +
ChatColor.YELLOW + args[1] +
ChatColor.RED + "! Available: " +
ChatColor.GRAY + String.join(", ", emgr.getKeys()));
return true;
}
if (args.length == 2) { // get
if (!cfg.contains(w.getName())) {
sender.sendMessage(
ChatColor.RED + "No border specified for " +
ChatColor.YELLOW + args[0] +
ChatColor.RED + "!");
return true;
}
Object val = entry.getFrom(cfg, w.getName());
sender.sendMessage(
ChatColor.YELLOW + args[1] +
ChatColor.GRAY + " @ " +
ChatColor.AQUA + w.getName() +
ChatColor.GRAY + ": " + (val == null ? ChatColor.ITALIC + "[" + entry.getDefaultValue() + "]": val));
} else { // set
String oldval = "" + entry.getFrom(cfg, w.getName());
String newval = String.join(" ", args).substring(args[0].length() + args[1].length() + 2);
if (entry.setIn(cfg, w.getName(), newval)) {
plugin.getConfigManager().save();
cfg = getConfig("borders.yml");
loadWorlds();
sender.sendMessage(
ChatColor.GREEN + "Changed " +
ChatColor.YELLOW + entry.getSubpath() +
ChatColor.GRAY + " @ " +
ChatColor.AQUA + w.getName() +
ChatColor.GRAY + ": " + oldval +
ChatColor.GOLD + " => " +
ChatColor.GRAY + newval);
} else {
sender.sendMessage(
ChatColor.RED + "Invalid value for " +
ChatColor.YELLOW + args[1] +
ChatColor.RED + ": " +
ChatColor.GRAY + newval);
}
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
ArrayList<String> hints = new ArrayList<String>();
if (!sender.hasPermission(this.getPermission()) || args.length < 1)
return hints;
String lastWord = args[args.length - 1];
if (args.length == 1) {
for (World w : Bukkit.getServer().getWorlds()) {
if (StringUtil.startsWithIgnoreCase(w.getName(), lastWord))
hints.add(w.getName());
}
} else if(args.length == 2) {
for (String key : emgr.getKeys()) {
if (StringUtil.startsWithIgnoreCase(key, lastWord))
hints.add(key);
}
}
Collections.sort(hints, String.CASE_INSENSITIVE_ORDER);
return hints;
}
@Override
public String getPermission() {
return getPermissionPath() + "." + this.getName().toLowerCase();
}
});
emgr.addEntry(new ConfigEntry<>("center", ValueValidator.VECTOR, new Vector(0, 0, 0)));
// emgr.addEntry(new ConfigEntry<>("size", ValueValidator.DOUBLE));
emgr.addEntry(new ConfigEntry<>("radius", ValueValidator.INTEGER, 60000000));
emgr.addEntry(new ConfigEntry<>("warningdist", ValueValidator.INTEGER, 5));
emgr.addEntry(new ConfigEntry<>("warningtime", ValueValidator.INTEGER, 15));
emgr.addEntry(new ConfigEntry<>("damage", ValueValidator.DOUBLE, 0.2d));
emgr.addEntry(new ConfigEntry<>("buffer", ValueValidator.DOUBLE, 5d));
this.registerConfig("borders.yml");
}
@Override
public void onEnable() {
super.onEnable();
cfg = getConfig("borders.yml");
this.loadWorlds();
}
public void loadWorlds() {
for(World w : Bukkit.getServer().getWorlds()) {
final String wname = w.getName();
if (!cfg.contains(wname)) {
w.getWorldBorder().reset();
continue;
}
emgr.getEntry("center").doStuff(cfg, wname, new IValueExecuter<Object>() {
public void doStuff(Object val) {
Vector v = (Vector) val;
w.getWorldBorder().setCenter(v.getX(), v.getZ());
}
});
emgr.getEntry("radius").doStuff(cfg, wname, new IValueExecuter<Object>() {
public void doStuff(Object val) {
w.getWorldBorder().setSize((int) val);
}
});
emgr.getEntry("warningdist").doStuff(cfg, wname, new IValueExecuter<Object>() {
public void doStuff(Object val) {
w.getWorldBorder().setWarningDistance((int) val);
}
});
emgr.getEntry("warningtime").doStuff(cfg, wname, new IValueExecuter<Object>() {
public void doStuff(Object val) {
w.getWorldBorder().setWarningTime((int) val);
}
});
emgr.getEntry("damage").doStuff(cfg, wname, new IValueExecuter<Object>() {
public void doStuff(Object val) {
w.getWorldBorder().setDamageAmount((double) val);
}
});
emgr.getEntry("buffer").doStuff(cfg, wname, new IValueExecuter<Object>() {
public void doStuff(Object val) {
w.getWorldBorder().setDamageBuffer((double) val);
}
});
/*
Region r = new Region();
if (cfg.contains(wname + ".center") && cfg.contains(wname + ".size")) {
plugin.getLogger().info("should i?");
String centerstr = cfg.getString(wname + ".center");
Vector center = LocationUtil.deserializeVector(centerstr);
String sizestr = cfg.getString(wname + ".size");
if (sizestr.indexOf(' ') == -1) {
w.getWorldBorder().setCenter(center.getX(), center.getZ());
w.getWorldBorder().setSize(cfg.getDouble(wname + ".size", 0));
plugin.getLogger().info("set the ghetto way");
} else {
Vector size = LocationUtil.deserializeVector(sizestr);
if (center == null) {
plugin.getLogger().config("[Borders] Invalid center coordinates for " + wname + ": " + centerstr);
} else if (size == null) {
plugin.getLogger().config("[Borders] Invalid size for " + wname + ": " + sizestr);
} else {
size.divide(new Vector(2f, 2f, 2f));
r.setOne(center.add(size));
r.setTwo(center.subtract(size));
}
}
}
if (cfg.contains(wname + ".points")) {
List<String> points = cfg.getStringList(wname + ".points");
for (String pstr : points) {
Vector p = LocationUtil.deserializeVector(pstr);
if (p == null)
continue;
r.ensureInside(p);
}
}
if (r.isValid()) {
Vector c = r.getCenter();
w.getWorldBorder().setCenter(c.getX(), c.getZ());
}
*/
}
}
}