Moved features to separate projects
This commit is contained in:
parent
8c454aa63e
commit
8f065ac91f
@ -17,14 +17,6 @@
|
||||
<classpathentry kind="src" path="/BountifulAPI"/>
|
||||
<classpathentry kind="var" path="M2_REPO/commons-io/commons-io/1.3.2/commons-io-1.3.2.jar" sourcepath="M2_REPO/commons-io/commons-io/1.3.2/commons-io-1.3.2-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/bukkit/bukkit/1.13-R0.1-SNAPSHOT/bukkit-1.13-R0.1-SNAPSHOT.jar" sourcepath="M2_REPO/org/bukkit/bukkit/1.13-R0.1-SNAPSHOT/bukkit-1.13-R0.1-SNAPSHOT-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/com/sk89q/worldedit/worldedit-core/6.0.0-SNAPSHOT/worldedit-core-6.0.0-SNAPSHOT.jar" sourcepath="M2_REPO/com/sk89q/worldedit/worldedit-core/6.0.0-SNAPSHOT/worldedit-core-6.0.0-SNAPSHOT-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/de/schlichtherle/truezip/6.8.3/truezip-6.8.3.jar" sourcepath="M2_REPO/de/schlichtherle/truezip/6.8.3/truezip-6.8.3-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/rhino/js/1.7R2/js-1.7R2.jar" sourcepath="M2_REPO/rhino/js/1.7R2/js-1.7R2-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/com/thoughtworks/paranamer/paranamer/2.6/paranamer-2.6.jar" sourcepath="M2_REPO/com/thoughtworks/paranamer/paranamer/2.6/paranamer-2.6-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/com/sk89q/lib/jlibnoise/1.0.0/jlibnoise-1.0.0.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/com/sk89q/jchronic/0.2.4a/jchronic-0.2.4a.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/com/sk89q/worldguard/worldguard-legacy/6.2/worldguard-legacy-6.2.jar"/>
|
||||
<classpathentry kind="lib" path="/home/erik/Dokumenty/Java/marwland/res/MassiveCore.jar"/>
|
||||
<classpathentry kind="lib" path="/home/erik/Dokumenty/Java/marwland/res/Factions.jar"/>
|
||||
</classpath>
|
61
pom.xml
61
pom.xml
@ -1,19 +1,19 @@
|
||||
<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</groupId>
|
||||
<artifactId>MarwCore</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>MarwCore</name>
|
||||
<description>Core plugin for MarwLand.cz Spigot-based Minecraft servers</description>
|
||||
<url>https://git.lixko.eu/MarwLand/MarwCore</url>
|
||||
<organization>
|
||||
<name>MarwLand</name>
|
||||
<url>https://marwland.cz</url>
|
||||
</organization>
|
||||
<issueManagement>
|
||||
<url>https://git.lixko.eu/MarwLand/MarwCore/issues</url>
|
||||
<system>Gitea Issue Tracker</system>
|
||||
</issueManagement>
|
||||
<parent>
|
||||
<groupId>cz.marwland.mc</groupId>
|
||||
<artifactId>MarwStuff</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../MarwStuff</relativePath>
|
||||
</parent>
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<resources>
|
||||
@ -53,62 +53,13 @@
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-api</artifactId>
|
||||
<version>4.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.connorlinfoot</groupId>
|
||||
<artifactId>BountifulAPI</artifactId>
|
||||
<version>1.6.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-core</artifactId>
|
||||
<version>6.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-legacy</artifactId>
|
||||
<version>6.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.massivecraft.massivecore</groupId>
|
||||
<artifactId>MassiveCore</artifactId>
|
||||
<version>2.14.1-SNAPSHOT</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>/home/erik/Dokumenty/Java/marwland/res/MassiveCore.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.massivecraft.factions</groupId>
|
||||
<artifactId>Factions</artifactId>
|
||||
<version>2.14.1-SNAPSHOT</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>/home/erik/Dokumenty/Java/marwland/res/Factions.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
<url>http://maven.sk89q.com/repo/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
2
resources/config.yml
Normal file
2
resources/config.yml
Normal file
@ -0,0 +1,2 @@
|
||||
#modules:
|
||||
# - cz.marwland.mc.features.Borders
|
@ -6,3 +6,7 @@ author: ericek111
|
||||
website: https://git.lixko.eu/MarwLand/MarwCore
|
||||
depend: [LuckPerms]
|
||||
softdepend: [WorldGuard, Factions]
|
||||
commands:
|
||||
marw:
|
||||
description: Core plugin controls.
|
||||
usage: /marw
|
||||
|
26
src/cz/marwland/mc/core/MarwCommandExecutor.java
Normal file
26
src/cz/marwland/mc/core/MarwCommandExecutor.java
Normal file
@ -0,0 +1,26 @@
|
||||
package cz.marwland.mc.core;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
public class MarwCommandExecutor implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length < 1) {
|
||||
sendHelp(sender);
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
MarwCore.getInstance().reload();
|
||||
sender.sendMessage(ChatColor.GREEN + "Reloaded!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void sendHelp(CommandSender sender) {
|
||||
sender.sendMessage("Available commands:");
|
||||
sender.sendMessage("/marw reload - Reload configs.");
|
||||
}
|
||||
}
|
@ -1,46 +1,43 @@
|
||||
package cz.marwland.mc.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cz.marwland.mc.core.config.ConfigManager;
|
||||
import cz.marwland.mc.core.features.Base;
|
||||
import cz.marwland.mc.core.features.Feature;
|
||||
import cz.marwland.mc.essentials.features.AntiVoid;
|
||||
import cz.marwland.mc.essentials.features.Borders;
|
||||
import cz.marwland.mc.essentials.features.ChatNotifier;
|
||||
import cz.marwland.mc.essentials.features.ChorusLimiter;
|
||||
import cz.marwland.mc.essentials.features.RandomTeleport;
|
||||
import cz.marwland.mc.core.plugins.ModuleClassLoader;
|
||||
|
||||
public class MarwCore extends JavaPlugin {
|
||||
|
||||
private ConfigManager configManager;
|
||||
private HashMap<String, Feature> features = new HashMap<>();
|
||||
private static MarwCore INSTANCE = null;
|
||||
private File modulesFolder = null;
|
||||
private ModuleClassLoader moduleClassLoader;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
INSTANCE = this;
|
||||
//getServer().getPluginManager().registerEvents(new EventListener(this), this);
|
||||
this.getCommand("marw").setExecutor(new MarwCommandExecutor());
|
||||
|
||||
configManager = new ConfigManager(this);
|
||||
configManager.registerConfig("config.yml");
|
||||
configManager.loadConfig("config.yml");
|
||||
|
||||
this.addFeature(new AntiVoid());
|
||||
this.addFeature(new Base());
|
||||
this.addFeature(new Borders());
|
||||
this.addFeature(new ChatNotifier());
|
||||
this.addFeature(new ChorusLimiter());
|
||||
this.addFeature(new RandomTeleport());
|
||||
|
||||
configManager.load();
|
||||
this.features.forEach((k, v) -> v.onEnable());
|
||||
modulesFolder = this.getModulesFolderPath().toFile();
|
||||
modulesFolder.mkdirs();
|
||||
this.loadAndEnableModules();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.features.forEach((k, v) -> v.onDisable());
|
||||
configManager.save();
|
||||
this.configManager.save();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,7 +47,36 @@ public class MarwCore extends JavaPlugin {
|
||||
|
||||
public void reload() {
|
||||
this.reloadConfig();
|
||||
this.features.forEach((k, v) -> v.onReload());
|
||||
this.features.forEach((k, v) -> v.onDisable());
|
||||
this.loadAndEnableModules();
|
||||
}
|
||||
|
||||
public void loadModules() {
|
||||
if (moduleClassLoader != null) {
|
||||
try {
|
||||
moduleClassLoader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
moduleClassLoader = new ModuleClassLoader();
|
||||
moduleClassLoader.addFromDirectory(modulesFolder);
|
||||
|
||||
for (String modClass : configManager.getConfig("config.yml").getStringList("modules")) {
|
||||
Feature f = moduleClassLoader.doConstructor(modClass, this);
|
||||
if (f == null)
|
||||
continue;
|
||||
|
||||
this.addFeature(f);
|
||||
this.getLogger().log(Level.INFO, "Loaded " + f.getName() + " @ " + modClass);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadAndEnableModules() {
|
||||
this.loadModules();
|
||||
configManager.load();
|
||||
this.features.forEach((k, v) -> v.onEnable());
|
||||
}
|
||||
|
||||
public ConfigManager getConfigManager() {
|
||||
@ -73,4 +99,12 @@ public class MarwCore extends JavaPlugin {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public Path getModulesFolderPath() {
|
||||
return this.getDataFolder().toPath().resolve("modules");
|
||||
}
|
||||
|
||||
public ModuleClassLoader getModuleClassLoader() {
|
||||
return this.moduleClassLoader;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,10 @@ public class ConfigManager {
|
||||
configs.put(path, new ConfigFile(plugin, template, path));
|
||||
}
|
||||
|
||||
public void loadConfig(String path) {
|
||||
configs.get(path).load();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
configs.forEach((k, v) -> v.load());
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
package cz.marwland.mc.core.features;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.defaults.BukkitCommand;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import cz.marwland.mc.core.features.Feature;
|
||||
|
||||
|
||||
public class Base extends Feature {
|
||||
|
||||
FileConfiguration cfg;
|
||||
|
||||
public Base() {
|
||||
super("marw");
|
||||
// String name, String description, String usageMessage, List<String> aliases)
|
||||
this.addCommand(new BukkitCommand("marw", "Core plugin controls.", "/marw", Arrays.asList()) {
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
if (args.length < 1) {
|
||||
sendHelp(sender);
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
plugin.reload();
|
||||
sender.sendMessage("Reloaded!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void sendHelp(CommandSender sender) {
|
||||
sender.sendMessage("Available commands:");
|
||||
sender.sendMessage("/marw reload - Reload configs.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -41,6 +41,7 @@ public abstract class Feature implements Listener {
|
||||
public void onEnable() {
|
||||
if (cmap != null) {
|
||||
for (BukkitCommand cmd : commands) {
|
||||
System.out.println("Registering: " + cmd.getName());
|
||||
cmap.register(plugin.getName().toLowerCase(), cmd);
|
||||
}
|
||||
}
|
||||
@ -55,9 +56,6 @@ public abstract class Feature implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public void onReload() {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
87
src/cz/marwland/mc/core/plugins/ModuleClassLoader.java
Normal file
87
src/cz/marwland/mc/core/plugins/ModuleClassLoader.java
Normal file
@ -0,0 +1,87 @@
|
||||
package cz.marwland.mc.core.plugins;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cz.marwland.mc.core.features.Feature;
|
||||
|
||||
public class ModuleClassLoader extends URLClassLoader {
|
||||
|
||||
private ArrayList<JarFile> jars = new ArrayList<>();
|
||||
|
||||
public ModuleClassLoader() {
|
||||
super(new URL[] { }, ModuleClassLoader.class.getClassLoader());
|
||||
}
|
||||
|
||||
public void addFile(File file) throws IOException {
|
||||
this.addURL(file.toURI().toURL());
|
||||
jars.add(new JarFile(file));
|
||||
}
|
||||
|
||||
public void addFromDirectory(File modDir) {
|
||||
if (!modDir.isDirectory())
|
||||
throw new IllegalArgumentException("Provided 'modDir' argument is not a directory: " + modDir.getPath());
|
||||
|
||||
for (File mod : modDir.listFiles()) {
|
||||
if (mod.isDirectory())
|
||||
continue;
|
||||
int lastdot = mod.getName().lastIndexOf('.');
|
||||
if (lastdot < 0)
|
||||
continue;
|
||||
|
||||
if (!mod.getName().substring(lastdot + 1).equalsIgnoreCase("jar"))
|
||||
continue;
|
||||
|
||||
try {
|
||||
this.addFile(mod);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Feature doConstructor(String classPath)
|
||||
throws ClassNotFoundException, ClassCastException, IllegalAccessException, InstantiationException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
Class<?> jarClass;
|
||||
jarClass = Class.forName(classPath, true, this);
|
||||
|
||||
Class<? extends Feature> pluginClass;
|
||||
pluginClass = jarClass.asSubclass(Feature.class);
|
||||
|
||||
return pluginClass.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
public Feature doConstructor(String classPath, JavaPlugin plugin) {
|
||||
try {
|
||||
return this.doConstructor(classPath);
|
||||
} catch (ClassNotFoundException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Cannot find class '" + classPath + "'!");
|
||||
} catch (ClassCastException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Class '" + classPath + "' does not extend Feature!");
|
||||
} catch (IllegalAccessException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "No public constructor in '" + classPath + "'!");
|
||||
} catch (InstantiationException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Cannot instantiate '" + classPath + "'!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Illegal arguments to the constructor of '" + classPath + "'!");
|
||||
} catch (InvocationTargetException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Error occured whilst initializing '" + classPath + "'!");
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Class '" + classPath + "' does not have a public constructor!");
|
||||
} catch (SecurityException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "SecurityException occured whilst initializing '" + classPath + "'!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package cz.marwland.mc.essentials.features;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import cz.marwland.mc.core.features.Feature;
|
||||
|
||||
public class AntiVoid extends Feature {
|
||||
|
||||
private FileConfiguration cfg;
|
||||
private ArrayList<World> allowedWorlds = new ArrayList<>();
|
||||
private double triggery = 0d;
|
||||
|
||||
public AntiVoid() {
|
||||
super();
|
||||
this.registerConfig("antivoid.yml");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
if (p.getLocation().getY() > triggery)
|
||||
return;
|
||||
|
||||
World w = p.getWorld();
|
||||
if (!allowedWorlds.contains(w))
|
||||
return;
|
||||
|
||||
p.teleport(w.getSpawnLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
this.onReload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReload() {
|
||||
super.onReload();
|
||||
cfg = getConfig("antivoid.yml");
|
||||
|
||||
triggery = cfg.getDouble("triggery", 0d);
|
||||
for (String wname : cfg.getStringList("worlds")) {
|
||||
World w = Bukkit.getWorld(wname);
|
||||
|
||||
if (w == null)
|
||||
continue;
|
||||
allowedWorlds.add(w);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,230 +0,0 @@
|
||||
package cz.marwland.mc.essentials.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());
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package cz.marwland.mc.essentials.features;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import com.connorlinfoot.bountifulapi.BountifulAPI;
|
||||
|
||||
import cz.marwland.mc.core.features.Feature;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
public class ChatNotifier extends Feature {
|
||||
|
||||
// TODO: Per-player highlighting
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent e) {
|
||||
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||
String msg = e.getMessage();
|
||||
if (msg.toLowerCase().contains(p.getName().toLowerCase()) && p.getPlayer() != e.getPlayer()) {
|
||||
/*e.getRecipients().remove(p);
|
||||
msg = ChatColor.RED + msg;*/
|
||||
BountifulAPI.sendActionBar(p, ChatColor.RED + "Byl jsi zminen v chatu!");
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 3.0F);
|
||||
}
|
||||
//p.sendMessage(String.format(e.getFormat(), e.getPlayer().getDisplayName(), msg));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package cz.marwland.mc.essentials.features;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||||
|
||||
import com.connorlinfoot.bountifulapi.BountifulAPI;
|
||||
|
||||
import cz.marwland.mc.core.features.Feature;
|
||||
import cz.marwland.mc.core.util.Cooldown;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
public class ChorusLimiter extends Feature {
|
||||
|
||||
private Cooldown chorusCooldown = new Cooldown(this);
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerItemConsume(PlayerItemConsumeEvent e) {
|
||||
if (e.getItem().getType() != Material.CHORUS_FRUIT)
|
||||
return;
|
||||
|
||||
long left = chorusCooldown.timeLeftSeconds(e.getPlayer());
|
||||
if (left > 0) {
|
||||
BountifulAPI.sendActionBar(e.getPlayer(), ChatColor.RED + "Musis pockat jeste " + left + " sekund pro pouziti Chorus Fruitu!");
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
chorusCooldown.resetPlayer(e.getPlayer());
|
||||
}
|
||||
|
||||
}
|
@ -1,169 +0,0 @@
|
||||
package cz.marwland.mc.essentials.features;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.defaults.BukkitCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockCanBuildEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
import cz.marwland.mc.core.features.Feature;
|
||||
import cz.marwland.mc.core.util.Cooldown;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
public class RandomTeleport extends Feature {
|
||||
|
||||
private final int MAX_TRIES = 100;
|
||||
private Cooldown telCooldown = new Cooldown(this);
|
||||
|
||||
private static final Set<Material> INVALID_MATERIALS = new HashSet<>(Arrays.asList(
|
||||
Material.AIR,
|
||||
Material.WATER,
|
||||
Material.STATIONARY_WATER,
|
||||
Material.LAVA,
|
||||
Material.STATIONARY_LAVA,
|
||||
Material.MAGMA,
|
||||
Material.MAGMA_CREAM,
|
||||
Material.FIRE,
|
||||
Material.WEB,
|
||||
Material.CACTUS,
|
||||
Material.ENDER_PORTAL,
|
||||
Material.PORTAL
|
||||
));
|
||||
|
||||
public RandomTeleport() {
|
||||
super();
|
||||
this.addCommand(new BukkitCommand(
|
||||
"rtp",
|
||||
"Teleport player to random location in the current world.",
|
||||
"/rtp [player]",
|
||||
Arrays.asList("randomtp", "randomteleport") ) {
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
if (!permissionMissingCheck(sender, this.getPermission()))
|
||||
return true;
|
||||
|
||||
if (!(sender instanceof Player) && args.length < 1) {
|
||||
sender.sendMessage(ChatColor.RED + "You need to specify the player! " + ChatColor.YELLOW + "/rtp [player] [world]");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
if (args.length >= 1) {
|
||||
p = Bukkit.getServer().getPlayer(args[0]);
|
||||
if (p != sender && !permissionMissingCheck(sender, this.getPermission() + ".others")) {
|
||||
return true;
|
||||
} else if (p == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Player not found!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
World w = p.getWorld();
|
||||
if (args.length >= 2) {
|
||||
w = Bukkit.getServer().getWorld(args[1]);
|
||||
if (w == null) {
|
||||
sender.sendMessage(ChatColor.RED + "World not found!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!sender.hasPermission(this.getPermission() + ".world." + w.getName())) {
|
||||
sender.sendMessage(ChatColor.RED + "V tomhle svete se nemuzes nahodne teleportovat!");
|
||||
return true;
|
||||
}
|
||||
|
||||
long left = telCooldown.timeLeftSeconds(p);
|
||||
if (left > 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Nemuzes se nahodne teleportovat jeste " + ChatColor.YELLOW + left + ChatColor.RED + " sekund" + (left == 1 ? "u!" : (left > 4 ? "!" : "y!")));
|
||||
return true;
|
||||
}
|
||||
|
||||
telCooldown.resetPlayer(p);
|
||||
randomTeleport(w, p);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return getPermissionPath();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void randomTeleport(World w, Player p) {
|
||||
Location loc = null;
|
||||
for (int i = 0; i < MAX_TRIES && loc == null; i++) {
|
||||
loc = generateLoc(w);
|
||||
if (!canTeleportHere(loc, p, false))
|
||||
loc = null;
|
||||
else {
|
||||
loc.add(0.5d, 1d, 0.5d);
|
||||
if (!canTeleportHere(loc, p, true))
|
||||
loc = null;
|
||||
}
|
||||
}
|
||||
if (loc != null) {
|
||||
loc.setYaw((float) (Math.random() * 360f));
|
||||
p.teleport(loc, TeleportCause.COMMAND);
|
||||
} else {
|
||||
p.sendMessage(ChatColor.RED + "V tomhle svete se pro tebe nenaslo bezpecne misto!");
|
||||
}
|
||||
}
|
||||
|
||||
public Location generateLoc(World w) {
|
||||
int wboff = 16;
|
||||
Location loc = w.getWorldBorder().getCenter();
|
||||
int radius = (int) w.getWorldBorder().getSize() / 2;
|
||||
int minx = loc.getBlockX() - radius;
|
||||
int minz = loc.getBlockZ() - radius;
|
||||
int maxx = loc.getBlockX() + radius;
|
||||
int maxz = loc.getBlockZ() + radius;
|
||||
if (wboff >= radius)
|
||||
wboff = 0;
|
||||
int rangex = (maxx - minx) - wboff * 2;
|
||||
int rangez = (maxz - minz) - wboff * 2;
|
||||
int finx = minx + (int) (Math.random() * rangex) + wboff;
|
||||
int finz = minz + (int) (Math.random() * rangez) + wboff;
|
||||
Location targetloc = w.getHighestBlockAt(finx, finz).getLocation();
|
||||
targetloc.subtract(0d, 1d, 0d);
|
||||
return targetloc;
|
||||
}
|
||||
|
||||
public boolean canTeleportHere(Location loc, Player p, boolean allowAir) {
|
||||
Block block = loc.getWorld().getBlockAt(loc);
|
||||
if (INVALID_MATERIALS.contains(block.getType()) && (allowAir ? block.getType() != Material.AIR : true))
|
||||
return false;
|
||||
|
||||
BlockCanBuildEvent canBuildEvent = new BlockCanBuildEvent(block, block.getData(), true);
|
||||
Bukkit.getServer().getPluginManager().callEvent(canBuildEvent);
|
||||
if (!canBuildEvent.isBuildable())
|
||||
return false;
|
||||
|
||||
try {
|
||||
if (!com.sk89q.worldguard.bukkit.WGBukkit.getPlugin().canBuild(p, block)) {
|
||||
return false;
|
||||
}
|
||||
} catch (NoClassDefFoundError e) {
|
||||
}
|
||||
|
||||
try {
|
||||
if (com.massivecraft.factions.entity.BoardColl.get().getFactionAt(com.massivecraft.massivecore.ps.PS.valueOf(loc)) != com.massivecraft.factions.entity.FactionColl.get().getNone()) {
|
||||
return false;
|
||||
}
|
||||
} catch (NoClassDefFoundError e) {
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user