diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..0b9e6d1 --- /dev/null +++ b/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..bdb0cab --- /dev/null +++ b/.gitattributes @@ -0,0 +1,17 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.project b/.project new file mode 100644 index 0000000..a9acf5a --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + detour + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..a698e59 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +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.source=1.8 diff --git a/bin/plugin.yml b/bin/plugin.yml new file mode 100644 index 0000000..009bc22 --- /dev/null +++ b/bin/plugin.yml @@ -0,0 +1,20 @@ +name: Detour +version: 1.2.2 +author: AlphaCH1337 +main: ru.alphach1337.detour.Main +commands: + detour: + description: Начинает(При повторном использовани отменят) обход + usage: /detour + next: + description: Переходит к следующему игроку + usage: /next + join: + description: Добавляет в обход. + usage: /join + find: + description: Телепортирует к текущему игроку в обходе + usage: /find + savepos: + description: Сохраняет позицию игрока, если он выйдет + usage: /savepos \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml new file mode 100644 index 0000000..009bc22 --- /dev/null +++ b/src/plugin.yml @@ -0,0 +1,20 @@ +name: Detour +version: 1.2.2 +author: AlphaCH1337 +main: ru.alphach1337.detour.Main +commands: + detour: + description: Начинает(При повторном использовани отменят) обход + usage: /detour + next: + description: Переходит к следующему игроку + usage: /next + join: + description: Добавляет в обход. + usage: /join + find: + description: Телепортирует к текущему игроку в обходе + usage: /find + savepos: + description: Сохраняет позицию игрока, если он выйдет + usage: /savepos \ No newline at end of file diff --git a/src/ru/alphach1337/detour/Main.java b/src/ru/alphach1337/detour/Main.java new file mode 100644 index 0000000..53a25c0 --- /dev/null +++ b/src/ru/alphach1337/detour/Main.java @@ -0,0 +1,294 @@ +package ru.alphach1337.detour; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import net.md_5.bungee.api.ChatColor; +import ru.alphach1337.detour.settings; +import java.util.UUID; + +public class Main extends JavaPlugin implements Listener { + public Map playersLocations = new HashMap(); + public Map playersUniqueIds = new HashMap(); + public ArrayList playersJoined = new ArrayList(); + public ArrayList doNotDelete = new ArrayList(); + int last = 0; + public boolean isDetour = false; + + @Override + public void onEnable() { + Bukkit.getPluginManager().registerEvents(this, this); + + } + + @Override + public void onDisable() { + + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onQuit(PlayerQuitEvent event) { + boolean isFound = false; + if (findDoNotDelete(event.getPlayer().getName())) { + isFound = true; + return; + } + if (!isFound) { + delete(event.getPlayer().getName()); + return; + } + + } + + // Delete player by username from detour if not in doNotDelete HashMap + public boolean delete(String player) { + playersLocations.remove(player); + for (int i = 0; i < playersJoined.size(); i++) { + if (playersJoined.get(i) == player) { + playersJoined.remove(i); + } + } + return false; + } + + public boolean next(CommandSender sender) { + if (playersJoined.isEmpty()) { + sender.sendMessage(settings.noPeoples); + return false; + } + + if (last < playersJoined.size()) { + + try { + if (Bukkit.getPlayer(playersJoined.get(last)).isOnline()) { + teleport(sender.getName(), playersJoined.get(last)); + sender.sendMessage(ChatColor.YELLOW + " " + ChatColor.BLUE + playersJoined.get(last - 1) + + ChatColor.AQUA + " (" + last + " " + playersJoined.size() + ")"); + return true; + } + } catch (Exception e) { + teleport(sender.getName(), playersLocations.get(playersJoined.get(last))); + sender.sendMessage(ChatColor.YELLOW + " " + ChatColor.BLUE + playersJoined.get(last - 1) + + ChatColor.AQUA + " (" + last + " " + playersJoined.size() + ")"); + + } + } else { + reset(); + return false; + } + + return false; + + } + + public int findOnlinePlayer(String player) { + boolean isFound1 = false; + boolean isFound2 = false; + for (Map.Entry pair : playersLocations.entrySet()) { + if (pair.getKey() == player) + isFound1 = true; + } + for (int i = 0; i < doNotDelete.size(); i++) { + isFound2 = true; + } + if (isFound1 && isFound2) { + return 2; + } else if (isFound1) { + return 1; + } else { + return 0; + } + } + + public boolean findDoNotDelete(String player) { + for (int i = 0; i < doNotDelete.size(); i++) { + if (doNotDelete.get(i) == player) { + return true; + } + } + return false; + } + + public void reset() { + isDetour = false; + playersJoined.clear(); + last = 0; + playersLocations.clear(); + playersUniqueIds.clear(); + doNotDelete.clear(); + Bukkit.broadcastMessage(settings.stopDetour); + } + + /////////////////////// + public boolean startDetour() { + isDetour = !isDetour; + Bukkit.broadcastMessage(settings.Started1); + Bukkit.broadcastMessage(settings.Started2); + return true; + } + + public boolean stopDetour() { + reset(); + return true; + } + /////////////////////// + + /* + * Teleport to OnlinePlayer + */ + public boolean teleport(String owner, String target) { + try { + Bukkit.getPlayer(owner).teleport(Bukkit.getPlayer(target)); + last++; + } catch (Exception e) { + return false; + } + return true; + } + + /* + * Teleport to OfflinePlayer + */ + public boolean teleport(String owner, Location target) { + try { + Bukkit.getPlayer(owner).teleport(target); + last++; + + } catch (Exception e) { + return false; + } + return true; + } + + public boolean onCommand(CommandSender sender, Command cmd, String lbl, String[] args) { + boolean isAdmin = sender.isOp(); + switch (cmd.getName()) { + + case "detour": + if (!isAdmin) { + sender.sendMessage(settings.hasNoPermission); + } else if (!isDetour) { + startDetour(); + } else { + + stopDetour(); + } + break; + case "next": + if (!isAdmin) { + sender.sendMessage(settings.hasNoPermission); + break; + } else if (!isDetour) { + sender.sendMessage(settings.notStarted); + break; + } else { + next(sender); + } + break; + case "join": + if (!isDetour) { + sender.sendMessage(settings.notStarted); + break; + } + if (playersJoined.isEmpty() && playersLocations.isEmpty()) { + playersLocations.put(sender.getName(), Bukkit.getPlayer(sender.getName()).getLocation()); + playersJoined.add(sender.getName()); + + sender.sendMessage(settings.addedToList); + break; + } + boolean isFound2 = false; + for (Map.Entry pair : playersLocations.entrySet()) { + if (pair.getKey() == sender.getName()) { + for (int i = 0; i < playersJoined.size(); i++) { + if (playersJoined.get(i) == sender.getName()) { + isFound2 = true; + break; + } + } + sender.sendMessage(settings.alreadyInTheList); + break; + } else { + for (int i = 0; i < playersJoined.size(); i++) { + if (playersJoined.get(i) == sender.getName()) { + isFound2 = true; + break; + } + } + if (isFound2) { + sender.sendMessage(settings.alreadyInTheList); + break; + } + playersLocations.put(sender.getName(), Bukkit.getPlayer(sender.getName()).getLocation()); + playersJoined.add(sender.getName()); + playersUniqueIds.put(sender.getName(), Bukkit.getPlayer(sender.getName()).getUniqueId()); + sender.sendMessage(settings.addedToList); + break; + + } + } + break; + case "savepos": + boolean isFound3 = false; + if (!isDetour) { + sender.sendMessage(settings.notStarted); + break; + } + for (int i = 0; i < playersJoined.size(); i++) { + if (playersJoined.get(i) == sender.getName()) { + isFound3 = true; + } + } + if (findDoNotDelete(sender.getName())) { + sender.sendMessage(settings.alreadySaved); + } + if (!isFound3) { + break; + } + if (isFound3) { + doNotDelete.add(sender.getName()); + sender.sendMessage(settings.savepos1); + sender.sendMessage(settings.savepos2); + } + break; + case "find": + if (!isAdmin) { + sender.sendMessage(settings.hasNoPermission); + break; + } else if (!isDetour) { + sender.sendMessage(settings.notStarted); + break; + } else { + if (playersJoined.isEmpty()) { + sender.sendMessage(settings.noPeoples); + break; + } else if (last == 0) { + sender.sendMessage(settings.plsUseNext1); + sender.sendMessage(settings.plsUseNext2); + break; + } + try { + if (Bukkit.getPlayer(playersJoined.get(last - 1)).isOnline()) { + Bukkit.getPlayer(sender.getName()).teleport(Bukkit.getPlayer(playersJoined.get(last - 1))); + return true; + } + } catch (Exception e) { + Bukkit.getPlayer(sender.getName()).teleport(playersLocations.get(playersJoined.get(last - 1))); + } + } + break; + } + return true; + } +} \ No newline at end of file diff --git a/src/ru/alphach1337/detour/settings.java b/src/ru/alphach1337/detour/settings.java new file mode 100644 index 0000000..37c5b8d --- /dev/null +++ b/src/ru/alphach1337/detour/settings.java @@ -0,0 +1,24 @@ +package ru.alphach1337.detour; + +import org.bukkit.ChatColor; + +public class settings { + public static String hasNoPermission = ChatColor.RED + " "; + public static String notStarted = ChatColor.RED + " !"; + public static String stopDetour = ChatColor.RED + " !"; + public static String Started1 = ChatColor.GREEN + " !"; + public static String Started2 = ChatColor.YELLOW + " " + ChatColor.LIGHT_PURPLE + "/join" + ChatColor.YELLOW + + ", "; + public static String alreadyInTheList = ChatColor.RED + " !"; + public static String addedToList = ChatColor.GREEN + " ! ."; + public static String noPeoples = ChatColor.RED + " !"; + public static String savepos1 = ChatColor.GREEN + + " !"; + public static String savepos2 = ChatColor.GREEN + + " ."; + public static String plsUseNext1 = ChatColor.RED + " !"; + public static String plsUseNext2 = ChatColor.RED + " " + ChatColor.LIGHT_PURPLE + "/next"; + public static String alreadySaved = ChatColor.RED + " "; + public static String notJoined = ChatColor.RED + " !"; + +}