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

26
RandomTeleport/.classpath Normal file
View File

@ -0,0 +1,26 @@
<?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="var" path="M2_REPO/cz/marwland/mc/MarwCore/0.0.1-SNAPSHOT/MarwCore-0.0.1-SNAPSHOT.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"/>
<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/com/google/guava/guava/17.0/guava-17.0.jar" sourcepath="M2_REPO/com/google/guava/guava/17.0/guava-17.0-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/org/yaml/snakeyaml/1.9/snakeyaml-1.9.jar" sourcepath="M2_REPO/org/yaml/snakeyaml/1.9/snakeyaml-1.9-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/google/code/gson/gson/2.2.4/gson-2.2.4.jar" sourcepath="M2_REPO/com/google/code/gson/gson/2.2.4/gson-2.2.4-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/junit/junit/4.8.1/junit-4.8.1.jar" sourcepath="M2_REPO/junit/junit/4.8.1/junit-4.8.1-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/com/sk89q/worldguard/worldguard-legacy/6.2/worldguard-legacy-6.2.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/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/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
RandomTeleport/.gitignore vendored Normal file
View File

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

18
RandomTeleport/.project Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RandomTeleport</name>
<comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
<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

63
RandomTeleport/pom.xml Normal file
View File

@ -0,0 +1,63 @@
<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>RandomTeleport</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>
<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>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
</repository>
</repositories>
</project>

View File

@ -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<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;
}
}