Initial commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package de.craftix.randomtp.commands;
|
||||
|
||||
import de.craftix.randomtp.general.Main;
|
||||
import de.craftix.randomtp.save.Config;
|
||||
import de.craftix.randomtp.save.Positions;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AddLocCmd implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||
if (sender instanceof Player){
|
||||
if (sender.hasPermission("rtp.admin")){
|
||||
if (args.length == 0){
|
||||
Player p = (Player)sender;
|
||||
Main.getPlugin().reloadConfig();
|
||||
FileConfiguration config = Main.getPlugin().getConfig();
|
||||
boolean stop = false;
|
||||
Main.loccount = 0;
|
||||
while (!stop){
|
||||
int id = Main.loccount + 1;
|
||||
if (config.contains(id + ".World")) Main.loccount++;
|
||||
else stop = true;
|
||||
}
|
||||
Positions pos = new Positions(p.getLocation(), Main.loccount + 1);
|
||||
Config.save(pos);
|
||||
p.sendMessage("§aNeue RTP Location gespeichert!");
|
||||
}else {
|
||||
sender.sendMessage("§6Usage: §7/addloc");
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage("§cHierzu hast du keine Rechte!");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package de.craftix.randomtp.commands;
|
||||
|
||||
import de.craftix.randomtp.general.Main;
|
||||
import de.craftix.randomtp.save.Config;
|
||||
import de.craftix.randomtp.save.Positions;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class RtpCmd implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||
if (sender instanceof Player){
|
||||
if (args.length == 0){
|
||||
Player p = (Player)sender;
|
||||
FileConfiguration config = Main.getPlugin().getConfig();
|
||||
boolean stop = false;
|
||||
Main.loccount = 0;
|
||||
while (!stop){
|
||||
int id = Main.loccount + 1;
|
||||
if (config.contains(id + ".World")) Main.loccount++;
|
||||
else stop = true;
|
||||
}
|
||||
if (Main.loccount == 0){
|
||||
p.sendMessage("§cEs existieren noch keine RTP's!");
|
||||
return true;
|
||||
}
|
||||
Random rand = new Random();
|
||||
int id = rand.nextInt((Main.loccount - 1) + 1) + 1;
|
||||
Positions pos = Config.load(id);
|
||||
p.teleport(pos.loc);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package de.craftix.randomtp.general;
|
||||
|
||||
import de.craftix.randomtp.commands.RtpCmd;
|
||||
import de.craftix.randomtp.commands.AddLocCmd;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
|
||||
private static Main plugin;
|
||||
public static int loccount;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
loccount = 0;
|
||||
|
||||
getCommand("rtp").setExecutor(new RtpCmd());
|
||||
getCommand("addloc").setExecutor(new AddLocCmd());
|
||||
|
||||
System.out.println("[RandomTP] Plugin wurde geladen!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
System.out.println("[RandomTP] Plugin wurde entladen!");
|
||||
}
|
||||
|
||||
public static Main getPlugin(){
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package de.craftix.randomtp.save;
|
||||
|
||||
import de.craftix.randomtp.general.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class Config {
|
||||
|
||||
public static void save(Positions pos){
|
||||
FileConfiguration config = Main.getPlugin().getConfig();
|
||||
config.set(pos.id + ".World", pos.loc.getWorld().getName());
|
||||
config.set(pos.id + ".X", pos.loc.getX());
|
||||
config.set(pos.id + ".Y", pos.loc.getY());
|
||||
config.set(pos.id + ".Z", pos.loc.getZ());
|
||||
config.set(pos.id + ".Yaw", pos.loc.getYaw());
|
||||
config.set(pos.id + ".Pitch", pos.loc.getPitch());
|
||||
Main.getPlugin().saveConfig();
|
||||
}
|
||||
|
||||
public static Positions load(int id){
|
||||
Main.getPlugin().reloadConfig();
|
||||
FileConfiguration config = Main.getPlugin().getConfig();
|
||||
World world = Bukkit.getWorld(config.getString(id + ".World"));
|
||||
double x = config.getDouble(id + ".X");
|
||||
double y = config.getDouble(id + ".Y");
|
||||
double z = config.getDouble(id + ".Z");
|
||||
float yaw = (float) config.getDouble(id + ".Yaw");
|
||||
float pitch = (float) config.getDouble(id + ".Pitch");
|
||||
Location loc = new Location(world, x, y, z, yaw, pitch);
|
||||
Positions pos = new Positions(loc, id);
|
||||
return pos;
|
||||
}
|
||||
|
||||
public static boolean test(int id){
|
||||
Main.getPlugin().reloadConfig();
|
||||
FileConfiguration config = Main.getPlugin().getConfig();
|
||||
if (config.contains(id + ".World")) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package de.craftix.randomtp.save;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class Positions {
|
||||
public Location loc;
|
||||
public int id;
|
||||
|
||||
public Positions(Location loc, int id){
|
||||
this.loc = loc;
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
8
Plugins/Old/RandomTP/src/plugin.yml
Normal file
8
Plugins/Old/RandomTP/src/plugin.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
name: RandomTP
|
||||
version: 1.12.2
|
||||
main: de.craftix.randomtp.general.Main
|
||||
api-version: 1.12
|
||||
|
||||
commands:
|
||||
rtp:
|
||||
addloc:
|
||||
Reference in New Issue
Block a user