This repository has been archived by the owner on Mar 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
k-egor-smirnov
committed
Aug 6, 2016
1 parent
c1b4c91
commit 4e8a0a8
Showing
8 changed files
with
411 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="lib" path="C:/Users/kegor/Documents/Workspace/detour/src/Spigot.jar"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>detour</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, Location> playersLocations = new HashMap<String, Location>(); | ||
public Map<String, UUID> playersUniqueIds = new HashMap<String, UUID>(); | ||
public ArrayList<String> playersJoined = new ArrayList<String>(); | ||
public ArrayList<String> doNotDelete = new ArrayList<String>(); | ||
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<String, Location> 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<String, Location> 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; | ||
} | ||
} |
Oops, something went wrong.