commit 8383a777308382c8d96272cc58ab2d9573a24e5e Author: Erik Bročko Date: Mon Sep 24 12:51:02 2018 +0200 Moved features to separate projects diff --git a/AntiVoid/.classpath b/AntiVoid/.classpath new file mode 100644 index 0000000..1973b1b --- /dev/null +++ b/AntiVoid/.classpath @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AntiVoid/.gitignore b/AntiVoid/.gitignore new file mode 100644 index 0000000..09e3bc9 --- /dev/null +++ b/AntiVoid/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/target/ diff --git a/AntiVoid/.project b/AntiVoid/.project new file mode 100644 index 0000000..cfeafff --- /dev/null +++ b/AntiVoid/.project @@ -0,0 +1,20 @@ + + + AntiVoid + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + + MarwCore + + + + org.eclipse.jdt.core.javabuilder + + + org.eclipse.m2e.core.maven2Builder + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + \ No newline at end of file diff --git a/AntiVoid/.settings/org.eclipse.jdt.core.prefs b/AntiVoid/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..43c686f --- /dev/null +++ b/AntiVoid/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/AntiVoid/.settings/org.eclipse.m2e.core.prefs b/AntiVoid/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/AntiVoid/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/AntiVoid/pom.xml b/AntiVoid/pom.xml new file mode 100644 index 0000000..9345b17 --- /dev/null +++ b/AntiVoid/pom.xml @@ -0,0 +1,30 @@ + + 4.0.0 + cz.marwland.mc.features + AntiVoid + + cz.marwland.mc + MarwStuff + 0.0.1-SNAPSHOT + MarwStuff + + + src + + + maven-compiler-plugin + 3.7.0 + + 10 + + + + + + + cz.marwland.mc + MarwCore + ${project.parent.version} + + + \ No newline at end of file diff --git a/AntiVoid/src/cz/marwland/mc/features/AntiVoid.java b/AntiVoid/src/cz/marwland/mc/features/AntiVoid.java new file mode 100644 index 0000000..ca8505e --- /dev/null +++ b/AntiVoid/src/cz/marwland/mc/features/AntiVoid.java @@ -0,0 +1,56 @@ +package cz.marwland.mc.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; +import cz.marwland.mc.core.util.Cooldown; + +public class AntiVoid extends Feature { + + private FileConfiguration cfg; + private ArrayList allowedWorlds = new ArrayList<>(); + private double triggery = 0d; + + public AntiVoid() { + super(); + this.registerConfig("antivoid.yml"); + Cooldown xd = new Cooldown(this); + } + + @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(); + cfg = getConfig("antivoid.yml"); + + triggery = cfg.getDouble("triggery", 0d); + allowedWorlds = new ArrayList<>(); + for (String wname : cfg.getStringList("worlds")) { + World w = Bukkit.getWorld(wname); + + if (w == null) + continue; + allowedWorlds.add(w); + } + } + +} diff --git a/Borders/.classpath b/Borders/.classpath new file mode 100644 index 0000000..1973b1b --- /dev/null +++ b/Borders/.classpath @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Borders/.gitignore b/Borders/.gitignore new file mode 100644 index 0000000..09e3bc9 --- /dev/null +++ b/Borders/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/target/ diff --git a/Borders/.project b/Borders/.project new file mode 100644 index 0000000..e365984 --- /dev/null +++ b/Borders/.project @@ -0,0 +1,20 @@ + + + Borders + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + + MarwCore + + + + org.eclipse.jdt.core.javabuilder + + + org.eclipse.m2e.core.maven2Builder + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + \ No newline at end of file diff --git a/Borders/.settings/org.eclipse.jdt.core.prefs b/Borders/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..43c686f --- /dev/null +++ b/Borders/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/Borders/.settings/org.eclipse.m2e.core.prefs b/Borders/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/Borders/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/Borders/pom.xml b/Borders/pom.xml new file mode 100644 index 0000000..3497ce7 --- /dev/null +++ b/Borders/pom.xml @@ -0,0 +1,30 @@ + + 4.0.0 + cz.marwland.mc.features + Borders + + cz.marwland.mc + MarwStuff + 0.0.1-SNAPSHOT + ../../MarwStuff + + + src + + + maven-compiler-plugin + 3.7.0 + + 10 + + + + + + + cz.marwland.mc + MarwCore + ${project.parent.version} + + + \ No newline at end of file diff --git a/Borders/src/cz/marwland/mc/features/Borders.java b/Borders/src/cz/marwland/mc/features/Borders.java new file mode 100644 index 0000000..e598862 --- /dev/null +++ b/Borders/src/cz/marwland/mc/features/Borders.java @@ -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 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 tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { + ArrayList hints = new ArrayList(); + 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() { + public void doStuff(Object val) { + Vector v = (Vector) val; + w.getWorldBorder().setCenter(v.getX(), v.getZ()); + } + }); + emgr.getEntry("radius").doStuff(cfg, wname, new IValueExecuter() { + public void doStuff(Object val) { + w.getWorldBorder().setSize((int) val); + } + }); + emgr.getEntry("warningdist").doStuff(cfg, wname, new IValueExecuter() { + public void doStuff(Object val) { + w.getWorldBorder().setWarningDistance((int) val); + } + }); + emgr.getEntry("warningtime").doStuff(cfg, wname, new IValueExecuter() { + public void doStuff(Object val) { + w.getWorldBorder().setWarningTime((int) val); + } + }); + emgr.getEntry("damage").doStuff(cfg, wname, new IValueExecuter() { + public void doStuff(Object val) { + w.getWorldBorder().setDamageAmount((double) val); + } + }); + emgr.getEntry("buffer").doStuff(cfg, wname, new IValueExecuter() { + 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 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()); + } + */ + } + } + +} diff --git a/ChatNotifier/.classpath b/ChatNotifier/.classpath new file mode 100644 index 0000000..4413367 --- /dev/null +++ b/ChatNotifier/.classpath @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/ChatNotifier/.gitignore b/ChatNotifier/.gitignore new file mode 100644 index 0000000..09e3bc9 --- /dev/null +++ b/ChatNotifier/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/target/ diff --git a/ChatNotifier/.project b/ChatNotifier/.project new file mode 100644 index 0000000..98ff97f --- /dev/null +++ b/ChatNotifier/.project @@ -0,0 +1,23 @@ + + + ChatNotifier + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/ChatNotifier/.settings/org.eclipse.jdt.core.prefs b/ChatNotifier/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..43c686f --- /dev/null +++ b/ChatNotifier/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/ChatNotifier/.settings/org.eclipse.m2e.core.prefs b/ChatNotifier/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/ChatNotifier/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/ChatNotifier/pom.xml b/ChatNotifier/pom.xml new file mode 100644 index 0000000..3d06ac1 --- /dev/null +++ b/ChatNotifier/pom.xml @@ -0,0 +1,34 @@ + + 4.0.0 + cz.marwland.mc.features + ChatNotifier + + cz.marwland.mc + MarwStuff + 0.0.1-SNAPSHOT + ../../MarwStuff + + + src + + + maven-compiler-plugin + 3.7.0 + + 10 + + + + + + + cz.marwland.mc + MarwCore + ${project.parent.version} + + + com.connorlinfoot + BountifulAPI + + + \ No newline at end of file diff --git a/ChatNotifier/src/cz/marwland/mc/features/ChatNotifier.java b/ChatNotifier/src/cz/marwland/mc/features/ChatNotifier.java new file mode 100644 index 0000000..ac80019 --- /dev/null +++ b/ChatNotifier/src/cz/marwland/mc/features/ChatNotifier.java @@ -0,0 +1,31 @@ +package cz.marwland.mc.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)); + } + } + +} diff --git a/ChorusLimiter/.classpath b/ChorusLimiter/.classpath new file mode 100644 index 0000000..4413367 --- /dev/null +++ b/ChorusLimiter/.classpath @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/ChorusLimiter/.gitignore b/ChorusLimiter/.gitignore new file mode 100644 index 0000000..09e3bc9 --- /dev/null +++ b/ChorusLimiter/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/target/ diff --git a/ChorusLimiter/.project b/ChorusLimiter/.project new file mode 100644 index 0000000..0d200f9 --- /dev/null +++ b/ChorusLimiter/.project @@ -0,0 +1,23 @@ + + + ChorusLimiter + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/ChorusLimiter/.settings/org.eclipse.jdt.core.prefs b/ChorusLimiter/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..43c686f --- /dev/null +++ b/ChorusLimiter/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/ChorusLimiter/.settings/org.eclipse.m2e.core.prefs b/ChorusLimiter/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/ChorusLimiter/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/ChorusLimiter/pom.xml b/ChorusLimiter/pom.xml new file mode 100644 index 0000000..6aece71 --- /dev/null +++ b/ChorusLimiter/pom.xml @@ -0,0 +1,34 @@ + + 4.0.0 + cz.marwland.mc.features + ChorusLimiter + + cz.marwland.mc + MarwStuff + 0.0.1-SNAPSHOT + ../../MarwStuff + + + src + + + maven-compiler-plugin + 3.7.0 + + 10 + + + + + + + cz.marwland.mc + MarwCore + ${project.parent.version} + + + com.connorlinfoot + BountifulAPI + + + \ No newline at end of file diff --git a/ChorusLimiter/src/cz/marwland/mc/features/ChorusLimiter.java b/ChorusLimiter/src/cz/marwland/mc/features/ChorusLimiter.java new file mode 100644 index 0000000..7aff632 --- /dev/null +++ b/ChorusLimiter/src/cz/marwland/mc/features/ChorusLimiter.java @@ -0,0 +1,31 @@ +package cz.marwland.mc.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()); + } + +} diff --git a/RandomTeleport/.classpath b/RandomTeleport/.classpath new file mode 100644 index 0000000..6e13b65 --- /dev/null +++ b/RandomTeleport/.classpath @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RandomTeleport/.gitignore b/RandomTeleport/.gitignore new file mode 100644 index 0000000..09e3bc9 --- /dev/null +++ b/RandomTeleport/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/target/ diff --git a/RandomTeleport/.project b/RandomTeleport/.project new file mode 100644 index 0000000..0d01c79 --- /dev/null +++ b/RandomTeleport/.project @@ -0,0 +1,18 @@ + + + RandomTeleport + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + + + + org.eclipse.jdt.core.javabuilder + + + org.eclipse.m2e.core.maven2Builder + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + \ No newline at end of file diff --git a/RandomTeleport/.settings/org.eclipse.jdt.core.prefs b/RandomTeleport/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..43c686f --- /dev/null +++ b/RandomTeleport/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/RandomTeleport/.settings/org.eclipse.m2e.core.prefs b/RandomTeleport/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/RandomTeleport/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/RandomTeleport/pom.xml b/RandomTeleport/pom.xml new file mode 100644 index 0000000..1af4069 --- /dev/null +++ b/RandomTeleport/pom.xml @@ -0,0 +1,63 @@ + + 4.0.0 + cz.marwland.mc.features + RandomTeleport + + cz.marwland.mc + MarwStuff + 0.0.1-SNAPSHOT + ../../MarwStuff + + + src + + + maven-compiler-plugin + 3.7.0 + + 10 + + + + + + + cz.marwland.mc + MarwCore + ${project.parent.version} + + + com.sk89q.worldedit + worldedit-core + 6.0.0-SNAPSHOT + provided + + + com.sk89q.worldguard + worldguard-legacy + 6.2 + provided + + + com.massivecraft.massivecore + MassiveCore + 2.14.1-SNAPSHOT + system + /home/erik/Dokumenty/Java/marwland/res/MassiveCore.jar + + + com.massivecraft.factions + Factions + 2.14.1-SNAPSHOT + system + /home/erik/Dokumenty/Java/marwland/res/Factions.jar + + + + + + sk89q-repo + http://maven.sk89q.com/repo/ + + + \ No newline at end of file diff --git a/RandomTeleport/src/cz/marwland/mc/features/RandomTeleport.java b/RandomTeleport/src/cz/marwland/mc/features/RandomTeleport.java new file mode 100644 index 0000000..0970398 --- /dev/null +++ b/RandomTeleport/src/cz/marwland/mc/features/RandomTeleport.java @@ -0,0 +1,169 @@ +package cz.marwland.mc.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 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; + } + +}