switch ");
64 | return true;
65 | }
66 |
67 | int to;
68 | try{
69 | to = Integer.parseInt(args[3]);
70 | } catch (Exception ex){
71 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint switch ");
72 | return true;
73 | }
74 |
75 | ServerTutorialPoint point = serverTutorial.points.get(index - 1);
76 | serverTutorial.points.set(index - 1, serverTutorial.points.get(to - 1));
77 | serverTutorial.points.set(to - 1, point);
78 | sender.sendMessage(Lang.COMMAND_SWITCH_SUCCESSFUL.toString().replace("%1%", (index - 1) + "").replace("%2&", to + ""));
79 | return true;
80 | }
81 |
82 | if(args[2].equalsIgnoreCase("infront")){
83 | if(args.length < 4){
84 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint infront
");
85 | return true;
86 | }
87 |
88 | int to;
89 | try{
90 | to = Integer.parseInt(args[3]);
91 | } catch (Exception ex){
92 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint infront
");
93 | return true;
94 | }
95 |
96 | ServerTutorialPoint point = serverTutorial.points.get(index - 1);
97 | serverTutorial.points.remove(index - 1);
98 | serverTutorial.points.add(to - 1, point);
99 | sender.sendMessage(Lang.COMMAND_MOVE_INFRONT_SUCCESFULL.toString().replace("%1%", (index - 1) + "").replace("%2&", to + ""));
100 | return true;
101 | }
102 |
103 |
104 | PointEditor pointEditor = PointEditor.getPointeditor(tutorialPoint);
105 | pointEditor.execute(serverTutorial, tutorialPoint, sender, args);
106 | return true;
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/commands/sub/points/PlayPointCommand.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.commands.sub.points;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.helpers.PluginUtils;
5 | import nl.martenm.servertutorialplus.helpers.dataholders.OldValuesPlayer;
6 | import nl.martenm.servertutorialplus.language.Lang;
7 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
8 | import nl.martenm.servertutorialplus.points.IPlayPoint;
9 | import nl.martenm.servertutorialplus.points.IPointCallBack;
10 | import nl.martenm.simplecommands.SimpleCommand;
11 | import org.bukkit.command.Command;
12 | import org.bukkit.command.CommandSender;
13 | import org.bukkit.entity.Player;
14 | import org.bukkit.scheduler.BukkitRunnable;
15 |
16 | public class PlayPointCommand extends SimpleCommand {
17 |
18 | public PlayPointCommand() {
19 | super("playpoint", Lang.HELP_PLAYPOINT.toString(), "+playpoint", true);
20 | }
21 |
22 | @Override
23 | public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
24 | ServerTutorialPlus plugin = ServerTutorialPlus.getInstance();
25 |
26 | if(args.length < 2){
27 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st playpoint ");
28 | return true;
29 | }
30 |
31 | if(plugin.blockPlayers.contains(((Player) sender).getUniqueId())){
32 | sender.sendMessage(Lang.ERROR_WAIT_TO_END.toString());
33 | return true;
34 | }
35 |
36 | ServerTutorial serverTutorial = PluginUtils.getTutorial(plugin, args[0]);
37 | if(serverTutorial == null){
38 | sender.sendMessage(Lang.TUTORIAL_ID_NOT_FOUND.toString());
39 | return true;
40 | }
41 |
42 | int index;
43 | try{
44 | index = Integer.parseInt(args[1]);
45 | } catch (Exception e){
46 | sender.sendMessage(Lang.ERROR_INVALID_INDEX.toString());
47 | return true;
48 | }
49 |
50 | if(index > serverTutorial.points.size() || index <= 0){
51 | sender.sendMessage(Lang.ERROR_INVALID_POINT.toString());
52 | return true;
53 | }
54 |
55 | Player player = (Player) sender;
56 |
57 | if(plugin.inTutorial.containsKey(player.getUniqueId())){
58 | player.sendMessage(Lang.ERROR_WAIT_TO_END_TUTORIAL.toString());
59 | return true;
60 | }
61 |
62 | plugin.blockPlayers.add(player.getUniqueId());
63 | new BukkitRunnable() {
64 | @Override
65 | public void run() {
66 | plugin.blockPlayers.remove(player.getUniqueId());
67 | }
68 | }.runTaskLater(plugin, (long) serverTutorial.points.get(index - 1).getTime() * 20 + 6);
69 |
70 | OldValuesPlayer oldValuesPlayer = new OldValuesPlayer(player);
71 |
72 | IPointCallBack callBack = () -> {
73 | plugin.lockedPlayers.remove(player.getUniqueId());
74 | plugin.lockedViews.remove(player.getUniqueId());
75 | player.setFlySpeed(oldValuesPlayer.getOriginal_flySpeed());
76 | player.setWalkSpeed(oldValuesPlayer.getOriginal_walkSpeed());
77 | player.setFlying(oldValuesPlayer.getFlying());
78 | };
79 | IPlayPoint handler = serverTutorial.points.get(index - 1).createPlay(player, oldValuesPlayer, callBack);
80 | handler.start();
81 | return true;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/commands/sub/points/RemovePointCommand.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.commands.sub.points;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.language.Lang;
5 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
6 | import nl.martenm.simplecommands.SimpleCommand;
7 | import org.bukkit.command.Command;
8 | import org.bukkit.command.CommandSender;
9 |
10 | public class RemovePointCommand extends SimpleCommand {
11 |
12 | public RemovePointCommand() {
13 | super("removepoint", Lang.HELP_REMOVEPOINT.toString(), "+removepoint", false);
14 | }
15 |
16 | @Override
17 | public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
18 | ServerTutorialPlus plugin = ServerTutorialPlus.getInstance();
19 |
20 | if(args.length < 2){
21 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st removepoint ");
22 | return true;
23 | }
24 |
25 | ServerTutorial serverTutorial = null;
26 | for(ServerTutorial st : plugin.serverTutorials){
27 | if(st.getId().equalsIgnoreCase(args[0])){
28 | serverTutorial = st;
29 | break;
30 | }
31 | }
32 |
33 | if(serverTutorial == null){
34 | sender.sendMessage(Lang.TUTORIAL_ID_NOT_FOUND.toString());
35 | return true;
36 | }
37 |
38 | int index;
39 | try{
40 | index = Integer.valueOf(args[1]);
41 | }
42 | catch (Exception e){
43 | sender.sendMessage(Lang.COMMAND_HASTOBE_NUMBER.toString());
44 | return true;
45 | }
46 |
47 | if(index - 1 < 0 || index > serverTutorial.points.size() ){
48 | sender.sendMessage(Lang.COMMAND_INVALID_INDEX.toString());
49 | return true;
50 | }
51 |
52 | serverTutorial.points.remove(index - 1);
53 | sender.sendMessage(Lang.POINT_REMOVED.toString().replace("%id%", args[0]));
54 | return true;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/commands/sub/tutorials/CreateTutorialCommand.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.commands.sub.tutorials;
2 |
3 | import net.md_5.bungee.api.ChatColor;
4 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
5 | import nl.martenm.servertutorialplus.language.Lang;
6 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
7 | import nl.martenm.simplecommands.SimpleCommand;
8 | import org.bukkit.command.Command;
9 | import org.bukkit.command.CommandSender;
10 |
11 | public class CreateTutorialCommand extends SimpleCommand {
12 |
13 |
14 | public CreateTutorialCommand() {
15 | super("create", Lang.HELP_CREATE.toString(),"+create", false);
16 | }
17 |
18 | @Override
19 | public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
20 | ServerTutorialPlus plugin = ServerTutorialPlus.getInstance();
21 |
22 | if(args.length == 0){
23 | sender.sendMessage(ChatColor.RED + "Wrong usage. Use the command like this: /st create ");
24 | return true;
25 | }
26 |
27 | String id = args[0];
28 | for(ServerTutorial st : plugin.serverTutorials){
29 | if(st.getId().equalsIgnoreCase(id)){
30 | sender.sendMessage(ChatColor.RED + "There already exists a server tutorial with that ID!");
31 | return true;
32 | }
33 | }
34 | ServerTutorial st = new ServerTutorial(id);
35 | plugin.serverTutorials.add(st);
36 | sender.sendMessage(Lang.TUTORIAL_CREATED.toString().replace("%id%", id));
37 | return true;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/commands/sub/tutorials/InfoCommand.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.commands.sub.tutorials;
2 |
3 | import net.md_5.bungee.api.ChatColor;
4 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
5 | import nl.martenm.servertutorialplus.language.Lang;
6 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
7 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
8 | import nl.martenm.simplecommands.SimpleCommand;
9 | import org.bukkit.Location;
10 | import org.bukkit.command.Command;
11 | import org.bukkit.command.CommandSender;
12 |
13 | public class InfoCommand extends SimpleCommand {
14 |
15 | public InfoCommand() {
16 | super("info", Lang.HELP_INFO.toString(), "+info", false);
17 | }
18 |
19 | @Override
20 | public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
21 | ServerTutorialPlus plugin = ServerTutorialPlus.getInstance();
22 |
23 | if(args.length == 0){
24 | sender.sendMessage(ChatColor.DARK_GRAY + "+──────────┤ " + ChatColor.GREEN + ChatColor.BOLD + "Info" + ChatColor.DARK_GRAY + "├──────────+");
25 | sender.sendMessage(" ");
26 | if(plugin.serverTutorials.size() == 0){
27 | sender.sendMessage(" " + Lang.INFO_NONE_EXISTING);
28 | } else{
29 | for(ServerTutorial st : plugin.serverTutorials){
30 | sender.sendMessage(ChatColor.GREEN + " " + st.getId());
31 | }
32 | }
33 | sender.sendMessage(" ");
34 | sender.sendMessage(" " + Lang.INFO_MORE_INFO);
35 | sender.sendMessage(ChatColor.DARK_GRAY + "+─────────────────────────+");
36 | return true;
37 | }
38 |
39 | if(plugin.serverTutorials.size() == 0){
40 | sender.sendMessage(Lang.INFO_NONE_EXISTING.toString());
41 | return true;
42 | }
43 |
44 | ServerTutorial serverTutorial = null;
45 | for(ServerTutorial st : plugin.serverTutorials){
46 | if(st.getId().equalsIgnoreCase(args[0])){
47 | serverTutorial = st;
48 | break;
49 | }
50 | }
51 |
52 | if(serverTutorial == null){
53 | sender.sendMessage(Lang.TUTORIAL_ID_NOT_FOUND.toString());
54 | return true;
55 | }
56 |
57 | sender.sendMessage(ChatColor.DARK_GRAY + "+──────────┤ " + ChatColor.GREEN + ChatColor.BOLD + "Info" + ChatColor.DARK_GRAY + "├──────────+");
58 | sender.sendMessage(" ");
59 | sender.sendMessage(formatInfo(Lang.ID.toString(), serverTutorial.getId()));
60 | sender.sendMessage(formatInfo(Lang.INVISIBLE.toString(), (serverTutorial.invisiblePlayer ? ChatColor.DARK_GREEN.toString() : ChatColor.RED.toString()) + serverTutorial.invisiblePlayer + ""));
61 | sender.sendMessage(formatInfo(Lang.PERMISSION.toString(), (serverTutorial.getNeedsPermission() ? ChatColor.DARK_GREEN.toString() : ChatColor.RED.toString()) + serverTutorial.getNeedsPermission() + ""));
62 | sender.sendMessage(formatInfo(Lang.CHAT_BLOCKED.toString(), (serverTutorial.isChatBlocked() ? ChatColor.DARK_GREEN.toString() : ChatColor.RED.toString()) + serverTutorial.isChatBlocked() + ""));
63 | sender.sendMessage(formatInfo(Lang.TIMES_PLAYED.toString(), String.valueOf(serverTutorial.plays)));
64 | sender.sendMessage(formatInfo(Lang.AMOUNT_OF_POINTS.toString() , (serverTutorial.points.size()) + ""));
65 | sender.sendMessage(" ");
66 | sender.sendMessage(formatInfo(Lang.BLOCKS_COMMANDS.toString(), (serverTutorial.isBlockingCommands() ? ChatColor.DARK_GREEN.toString() : ChatColor.RED.toString()) + serverTutorial.isBlockingCommands() + ""));
67 | sender.sendMessage(formatCommand(Lang.WHITELISTED_COMMANDS.toString(), ""));
68 | if(serverTutorial.getCommandWhiteList().size() == 0)
69 | sender.sendMessage(" " + ChatColor.YELLOW + Lang.NONE.toString());
70 | else {
71 | for(String white : serverTutorial.getCommandWhiteList()) {
72 | sender.sendMessage(" " + ChatColor.GRAY + "-" + ChatColor.YELLOW + white);
73 | }
74 | }
75 | sender.sendMessage(" ");
76 | for(int i = 0; i < serverTutorial.points.size(); i++){
77 | ServerTutorialPoint point = serverTutorial.points.get(i);
78 | Location loc = point.getLoc().clone();
79 | //Location
80 | sender.sendMessage(" " + ChatColor.GREEN + ChatColor.BOLD.toString() + (i + 1) + ChatColor.GRAY + " - " + ChatColor.YELLOW + loc.getWorld().getName() + " " + loc.getBlockX() + " " + loc.getBlockY() + " " + loc.getBlockZ());
81 | //Time
82 | sender.sendMessage(" " + ChatColor.GREEN + Lang.TIME + ": " + ChatColor.YELLOW + point.getTime() + " " + Lang.SECONDS);
83 | //Actionbar
84 | if(point.getMessage_actionBar() != null && !point.getMessage_actionBar().equalsIgnoreCase("")) sender.sendMessage(" " + ChatColor.GREEN + "Actionbar: " + ChatColor.YELLOW + point.getMessage_actionBar());
85 | //Title
86 | if(point.getTitleInfo() != null){
87 | if(!point.getTitleInfo().title.equalsIgnoreCase("")) sender.sendMessage(" " + ChatColor.GREEN + "Title: " + ChatColor.YELLOW + ChatColor.translateAlternateColorCodes('&', point.getTitleInfo().title));
88 | if(!point.getTitleInfo().subtitle.equalsIgnoreCase("")) sender.sendMessage(" " + ChatColor.GREEN + "Sub Title: " + ChatColor.YELLOW + ChatColor.translateAlternateColorCodes('&', point.getTitleInfo().subtitle));
89 | }
90 |
91 | if(point.getMessage_chat() != null){
92 | if(point.getMessage_chat().size() > 0){
93 | sender.sendMessage(" " + ChatColor.GREEN + Lang.CHAT_MESSAGES + ": ");
94 | for(int index = 0; index < point.getMessage_chat().size(); index++){
95 | sender.sendMessage(" " + ChatColor.BLUE + (index + 1) + ": " + ChatColor.YELLOW + ChatColor.translateAlternateColorCodes('&', point.getMessage_chat().get(index)));
96 | }
97 | }
98 | }
99 |
100 | if(point.getCommands() != null){
101 | if(point.getCommands().size() > 0){
102 | sender.sendMessage(" " + ChatColor.GREEN + "Commands: ");
103 | for(int index = 0; index < point.getCommands().size(); index++){
104 | sender.sendMessage(" " + ChatColor.BLUE + (index + 1) + ": " + ChatColor.YELLOW + ChatColor.translateAlternateColorCodes('&', point.getCommands().get(index)));
105 | }
106 | }
107 | }
108 |
109 | sender.sendMessage(" ");
110 | }
111 | sender.sendMessage(ChatColor.DARK_GRAY + "+─────────────────────────+");
112 | return true;
113 | }
114 |
115 | private String formatCommand(String command, String description){
116 | return ChatColor.GREEN + " " + command + ChatColor.DARK_GRAY + " - " + ChatColor.YELLOW + description;
117 | }
118 |
119 | private String formatInfo(String command, String description){
120 | return ChatColor.GREEN + " " + command + ChatColor.DARK_GRAY + " : " + ChatColor.YELLOW + description;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/commands/sub/tutorials/PlayTutorialCommand.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.commands.sub.tutorials;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.helpers.PluginUtils;
5 | import nl.martenm.servertutorialplus.language.Lang;
6 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
7 | import nl.martenm.servertutorialplus.objects.TutorialController;
8 | import nl.martenm.simplecommands.SimpleCommand;
9 | import org.bukkit.Bukkit;
10 | import org.bukkit.command.Command;
11 | import org.bukkit.command.CommandSender;
12 | import org.bukkit.entity.Player;
13 |
14 | public class PlayTutorialCommand extends SimpleCommand {
15 |
16 | public PlayTutorialCommand() {
17 | super("play", Lang.HELP_PLAY.toString(), "+play", false);
18 | }
19 |
20 | @Override
21 | public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
22 | ServerTutorialPlus plugin = ServerTutorialPlus.getInstance();
23 |
24 | if(args.length < 1){
25 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st play ");
26 | return true;
27 | }
28 |
29 | ServerTutorial serverTutorial = PluginUtils.getTutorial(plugin, args[0]);
30 | if(serverTutorial == null){
31 | sender.sendMessage(Lang.TUTORIAL_ID_NOT_FOUND.toString());
32 | return true;
33 | }
34 |
35 | Player target = null;
36 | if(args.length != 1) {
37 | if(!sender.hasPermission(getFullPermission() + ".others")) {
38 | sender.sendMessage(Lang.NO_PERMS.toString());
39 | return true;
40 | }
41 |
42 | target = Bukkit.getPlayer(args[1]);
43 | if(target == null){
44 | sender.sendMessage(Lang.ERROR_PLAYER_OFFLINE.toString());
45 | return true;
46 | }
47 |
48 | if(plugin.blockPlayers.contains((target).getUniqueId())){
49 | sender.sendMessage(Lang.ERROR_WAIT_TO_END.toString());
50 | return true;
51 | }
52 |
53 | TutorialController controller = plugin.inTutorial.get(target.getUniqueId());
54 | if(controller != null){
55 | controller.cancel(true, false);
56 | sender.sendMessage(Lang.WARNING_TUTORIAL_OTHER_CANCELLED.toString()
57 | .replace("%username%", target.getName())
58 | .replace("%tutorial%", serverTutorial.getId()));
59 | }
60 |
61 | } else {
62 | if(!(sender instanceof Player)){
63 | sender.sendMessage(Lang.PLAYER_ONLY_COMMAND.toString());
64 | return true;
65 | }
66 |
67 | Player player = (Player) sender;
68 |
69 | target = player;
70 |
71 | if(plugin.inTutorial.containsKey(player.getUniqueId())){
72 | player.sendMessage(Lang.ERROR_WAIT_TO_END_TUTORIAL.toString());
73 | return true;
74 | }
75 | }
76 |
77 | if(!plugin.enabled){
78 | return true;
79 | }
80 |
81 | TutorialController tutorialController = new TutorialController(plugin, target, serverTutorial);
82 | tutorialController.start();
83 | return true;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/commands/sub/tutorials/QuitTutorialCommand.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.commands.sub.tutorials;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.language.Lang;
5 | import nl.martenm.servertutorialplus.objects.TutorialController;
6 | import nl.martenm.simplecommands.SimpleCommand;
7 | import org.bukkit.command.Command;
8 | import org.bukkit.command.CommandSender;
9 | import org.bukkit.entity.Player;
10 |
11 | public class QuitTutorialCommand extends SimpleCommand {
12 |
13 | public QuitTutorialCommand() {
14 | super("quit", Lang.HELP_QUIT.toString(), "+quit", true);
15 | }
16 |
17 | @Override
18 | public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
19 | ServerTutorialPlus plugin = ServerTutorialPlus.getInstance();
20 |
21 | Player player = (Player) sender;
22 |
23 | if(plugin.inTutorial.containsKey(player.getUniqueId())){
24 | TutorialController tc = plugin.inTutorial.get(player.getUniqueId());
25 | tc.cancel(true);
26 | player.sendMessage(Lang.COMMAND_SUCCESFULLY_LEFT.toString());
27 | return true;
28 | }
29 |
30 | player.sendMessage(Lang.COMMAND_QUIT_NOTIN.toString());
31 | return true;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/commands/sub/tutorials/RemoveTutorialCommand.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.commands.sub.tutorials;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.language.Lang;
5 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
6 | import nl.martenm.simplecommands.SimpleCommand;
7 | import org.bukkit.command.Command;
8 | import org.bukkit.command.CommandSender;
9 |
10 | public class RemoveTutorialCommand extends SimpleCommand {
11 |
12 | public RemoveTutorialCommand() {
13 | super("remove", Lang.HELP_REMOVE.toString(), "+remove", false);
14 | }
15 |
16 | @Override
17 | public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
18 | ServerTutorialPlus plugin = ServerTutorialPlus.getInstance();
19 |
20 | if(args.length == 0){
21 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st remove ");
22 | return true;
23 | }
24 |
25 | for(ServerTutorial st : plugin.serverTutorials){
26 | if(st.getId().equalsIgnoreCase(args[0])){
27 | plugin.serverTutorials.remove(st);
28 | sender.sendMessage(Lang.TUTORIAL_REMOVED.toString().replace("%id%", args[0]));
29 | plugin.tutorialSaves.set("tutorials." + st.getId(), null);
30 | plugin.tutorialSaves.save();
31 | return true;
32 | }
33 | }
34 |
35 | sender.sendMessage(Lang.SAVE_SUCCES.toString());
36 | return true;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/data/DataSource.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.data;
2 |
3 | import java.util.List;
4 | import java.util.UUID;
5 |
6 | /**
7 | * Custom data source object for Server Tutorial Plus.
8 | * @author MartenM
9 | * @since 24-12-2017.
10 | */
11 | public interface DataSource {
12 |
13 | List getPlayedTutorials(UUID uuid);
14 |
15 | boolean addPlayedTutorial(UUID uuid, String id);
16 |
17 | boolean removePlayedTutorial(UUID uuid, String id);
18 |
19 | boolean hasPlayedTutorial(UUID uuid, String id);
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/data/FlatDataSource.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.data;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import org.json.simple.JSONObject;
5 | import org.json.simple.parser.JSONParser;
6 |
7 | import java.io.File;
8 | import java.io.FileReader;
9 | import java.io.FileWriter;
10 | import java.io.IOException;
11 | import java.util.ArrayList;
12 | import java.util.List;
13 | import java.util.UUID;
14 |
15 | /**
16 | * @author MartenM
17 | * @since 24-12-2017.
18 | */
19 | public class FlatDataSource implements DataSource {
20 |
21 | private ServerTutorialPlus plugin;
22 | public FlatDataSource(ServerTutorialPlus plugin){
23 | this.plugin = plugin;
24 | }
25 |
26 | @Override
27 | public List getPlayedTutorials(UUID uuid) {
28 | File hostlocation = new File(plugin.getDataFolder() + "/data/playerdata");
29 | hostlocation.mkdirs();
30 |
31 | File file = new File(plugin.getDataFolder() + "/data/playerdata/" + uuid + ".json");
32 | if(file.exists()){
33 | JSONParser parser = new JSONParser();
34 | JSONObject data = null;
35 | FileReader reader = null;
36 |
37 | try{
38 | reader = new FileReader(file.getPath());
39 | Object obj = parser.parse(reader);
40 | data = (JSONObject) obj;
41 | } catch (Exception ex){
42 | ex.printStackTrace();
43 |
44 | } finally {
45 | if(reader != null){
46 | try {
47 | reader.close();
48 | } catch (IOException e) {
49 | e.printStackTrace();
50 | }
51 | }
52 | }
53 |
54 | return (List) data.get("tutorials");
55 | }
56 | else{
57 | return new ArrayList<>();
58 | }
59 | }
60 |
61 | @Override
62 | public boolean addPlayedTutorial(UUID uuid, String id) {
63 | List played = getPlayedTutorials(uuid);
64 | played.add(id);
65 |
66 | File hostlocation = new File(plugin.getDataFolder() + "/data/playerdata/");
67 | hostlocation.mkdirs();
68 |
69 | JSONObject data = new JSONObject();
70 | data.put("tutorials", played);
71 |
72 | File file = new File(plugin.getDataFolder() + "/data/playerdata/" + uuid + ".json");
73 |
74 | FileWriter writer = null;
75 | try{
76 | writer = new FileWriter(file);
77 | writer.write(data.toJSONString());
78 | } catch (Exception ex){
79 | ex.printStackTrace();
80 | return false;
81 | } finally {
82 | if(writer != null){
83 | try {
84 | writer.flush();
85 | writer.close();
86 | } catch (Exception ex){
87 | ex.printStackTrace();
88 | }
89 | }
90 | }
91 |
92 | return true;
93 | }
94 |
95 | @Override
96 | public boolean removePlayedTutorial(UUID uuid, String id) {
97 | List played = getPlayedTutorials(uuid);
98 | played.remove(id);
99 |
100 | File hostlocation = new File(plugin.getDataFolder() + "/data/playerdata/");
101 | hostlocation.mkdirs();
102 |
103 | JSONObject data = new JSONObject();
104 | data.put("tutorials", played);
105 |
106 | File file = new File(plugin.getDataFolder() + "/data/playerdata/" + uuid + ".json");
107 |
108 | FileWriter writer = null;
109 | try{
110 | writer = new FileWriter(file);
111 | writer.write(data.toJSONString());
112 | } catch (Exception ex){
113 | ex.printStackTrace();
114 | return false;
115 | } finally {
116 | if(writer != null){
117 | try {
118 | writer.flush();
119 | writer.close();
120 | } catch (Exception ex){
121 | ex.printStackTrace();
122 | }
123 | }
124 | }
125 |
126 | return true;
127 | }
128 |
129 | @Override
130 | public boolean hasPlayedTutorial(UUID uuid, String id) {
131 | return getPlayedTutorials(uuid).contains(id);
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/data/MySqlDataSource.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.data;
2 |
3 | import com.zaxxer.hikari.HikariConfig;
4 | import com.zaxxer.hikari.HikariDataSource;
5 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
6 |
7 | import java.sql.Connection;
8 | import java.sql.ResultSet;
9 | import java.sql.SQLException;
10 | import java.sql.Statement;
11 | import java.util.ArrayList;
12 | import java.util.List;
13 | import java.util.UUID;
14 |
15 | /**
16 | * @author MartenM
17 | * @since 24-12-2017.
18 | */
19 | public class MySqlDataSource implements DataSource {
20 |
21 | private ServerTutorialPlus plugin;
22 | private HikariConfig config = new HikariConfig();
23 | private HikariDataSource mySql;
24 |
25 | public MySqlDataSource(ServerTutorialPlus plugin){
26 | this.plugin = plugin;
27 | setup();
28 | }
29 |
30 |
31 | public boolean setup() {
32 | String host = plugin.getConfig().getString("datasource.mysql.host");
33 | String database = plugin.getConfig().getString("datasource.mysql.database");
34 | int port = plugin.getConfig().getInt("datasource.mysql.port");
35 |
36 | config = new HikariConfig();
37 | config.setUsername(plugin.getConfig().getString("datasource.mysql.username"));
38 | config.setPassword(plugin.getConfig().getString("datasource.mysql.password"));
39 |
40 | config.setJdbcUrl(String.format("jdbc:mysql://%s:%s/%s", host, port, database));
41 |
42 | config.addDataSourceProperty("cachePrepStmts", "true");
43 | config.addDataSourceProperty("prepStmtCacheSize", "250");
44 | config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
45 |
46 | mySql = new HikariDataSource(config);
47 |
48 | plugin.getLogger().info("Creating Tutorial_Players table.");
49 | if(!simpleSqlUpdate("CREATE TABLE IF NOT EXISTS Tutorial_Players " +
50 | "(uuid VARCHAR(64) not NULL, " +
51 | " tutorial VARCHAR(255), " +
52 | " PRIMARY KEY ( uuid, tutorial))" )){
53 | return false;
54 | }
55 |
56 | return true;
57 | }
58 |
59 | public boolean simpleSqlUpdate(String sql)
60 | {
61 | Connection connection = null;
62 | Statement statement = null;
63 |
64 | try{
65 | connection = mySql.getConnection();
66 |
67 | statement = connection.createStatement();
68 | statement.executeUpdate(sql);
69 |
70 | } catch (Exception ex){
71 | plugin.getLogger().warning("[!!!] Error while performing an SQL query!");
72 | ex.printStackTrace();
73 | return false;
74 | } finally {
75 | if(connection != null){
76 | try {
77 | connection.close();
78 | } catch (SQLException e) {
79 | e.printStackTrace();
80 | }
81 | }
82 |
83 | if(statement != null){
84 | try {
85 | statement.close();
86 | } catch (SQLException e) {
87 | e.printStackTrace();
88 | }
89 | }
90 | }
91 | return true;
92 | }
93 |
94 | @Override
95 | public List getPlayedTutorials(UUID uuid) {
96 | List tutorials = new ArrayList<>();
97 |
98 | Connection connection = null;
99 | Statement statement = null;
100 | ResultSet result = null;
101 |
102 | try{
103 | connection = mySql.getConnection();
104 | statement = connection.createStatement();
105 |
106 | result = statement.executeQuery("select distinct tutorial from Tutorial_Players where uuid='" + uuid + "'");
107 |
108 | while (result.next()){
109 | tutorials.add(result.getString(1));
110 | }
111 |
112 | } catch (Exception ex){
113 | plugin.getLogger().warning("[!!!] An error occurred while to get a players played tutorials...");
114 | ex.printStackTrace();
115 | return null;
116 | } finally {
117 | if(connection != null){
118 | try {
119 | connection.close();
120 | } catch (SQLException e) {
121 | e.printStackTrace();
122 | }
123 | }
124 |
125 | if(statement != null){
126 | try {
127 | statement.close();
128 | } catch (SQLException e) {
129 | e.printStackTrace();
130 | }
131 | }
132 |
133 | if(result != null){
134 | try {
135 | result.close();
136 | } catch (SQLException e) {
137 | e.printStackTrace();
138 | }
139 | }
140 | }
141 |
142 | return tutorials;
143 | }
144 |
145 | @Override
146 | public boolean addPlayedTutorial(UUID uuid, String id) {
147 | return simpleSqlUpdate("insert into Tutorial_Players (uuid, tutorial) VALUES " + String.format("('%s', '%s')", uuid, id));
148 | }
149 |
150 | @Override
151 | public boolean removePlayedTutorial(UUID uuid, String id) {
152 | return simpleSqlUpdate("delete from tutorial_players where uuid='" + uuid + "' AND tutorial='" + id + "'");
153 | }
154 |
155 | @Override
156 | public boolean hasPlayedTutorial(UUID uuid, String id) {
157 | List tutorials = getPlayedTutorials(uuid);
158 | if(tutorials == null){
159 | //Replay later for the rewards!
160 | return true;
161 | }
162 |
163 | return tutorials.contains(id);
164 | }
165 | }
166 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/events/ChatEventListener.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.events;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.objects.TutorialController;
5 | import org.bukkit.event.EventHandler;
6 | import org.bukkit.event.Listener;
7 | import org.bukkit.event.player.AsyncPlayerChatEvent;
8 |
9 | /**
10 | * @author MartenM
11 | * @since 24-10-2018.
12 | */
13 | public class ChatEventListener implements Listener {
14 |
15 | private ServerTutorialPlus plugin;
16 |
17 | public ChatEventListener(ServerTutorialPlus plugin) {
18 | this.plugin = plugin;
19 | }
20 |
21 | @EventHandler
22 | public void onChatEvent(AsyncPlayerChatEvent event) {
23 | event.getRecipients().removeIf(player -> {
24 | TutorialController controller = plugin.inTutorial.get(player.getUniqueId());
25 | if(controller != null) {
26 | return controller.getTutorial().isChatBlocked();
27 | }
28 | return false;
29 | });
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/events/OnBlockBreakEvent.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.events;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.language.Lang;
5 | import nl.martenm.servertutorialplus.objects.TutorialSign;
6 | import org.bukkit.event.EventHandler;
7 | import org.bukkit.event.Listener;
8 | import org.bukkit.event.block.BlockBreakEvent;
9 |
10 | /**
11 | * Handles block break events. Used to remove click-able blocks.
12 | * @author MartenM
13 | */
14 | public class OnBlockBreakEvent implements Listener {
15 |
16 | private ServerTutorialPlus plugin;
17 | public OnBlockBreakEvent(ServerTutorialPlus plugin){
18 | this.plugin = plugin;
19 | }
20 |
21 | @EventHandler
22 | public void onBlockBreakEvent(BlockBreakEvent event){
23 |
24 | for(TutorialSign ts : plugin.tutorialSigns){
25 | if(ts.block.getLocation().equals(event.getBlock().getLocation())){
26 | if(!event.getPlayer().hasPermission("servertutorial.action.removeblock")){
27 | event.getPlayer().sendMessage(Lang.EVENT_BLOCK_REMOVE_PERMISSION.toString());
28 | event.setCancelled(true);
29 | return;
30 | }
31 | plugin.tutorialSigns.remove(ts);
32 | event.getPlayer().sendMessage(Lang.EVENT_BLOCK_REMOVED.toString());
33 | break;
34 | }
35 | }
36 |
37 |
38 |
39 |
40 |
41 |
42 | }
43 |
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/events/OnCommandPreprocessEvent.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.events;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.language.Lang;
5 | import nl.martenm.servertutorialplus.objects.TutorialController;
6 | import org.bukkit.entity.Player;
7 | import org.bukkit.event.EventHandler;
8 | import org.bukkit.event.Listener;
9 | import org.bukkit.event.player.PlayerCommandPreprocessEvent;
10 |
11 | /**
12 | * @author MartenM
13 | * @since 30-5-2018.
14 | */
15 | public class OnCommandPreprocessEvent implements Listener {
16 |
17 | public ServerTutorialPlus plugin;
18 |
19 | public OnCommandPreprocessEvent(ServerTutorialPlus plugin) {
20 | this.plugin = plugin;
21 | }
22 |
23 | @EventHandler
24 | public void onCommandProcessEvent(PlayerCommandPreprocessEvent event) {
25 |
26 | Player player = event.getPlayer();
27 | if (!plugin.inTutorial.containsKey(player.getUniqueId())) {
28 | return;
29 | }
30 |
31 | TutorialController controller = plugin.inTutorial.get(player.getUniqueId());
32 | if (!controller.getTutorial().isBlockingCommands()) {
33 | return;
34 | }
35 |
36 | if (player.hasPermission("servertutorial.tutorial.bypass")) {
37 | return;
38 | }
39 |
40 | // Remove the / from the command using substring.
41 | String commandString = event.getMessage().substring(1);
42 | String[] args = commandString.split(" ");
43 |
44 | if (args.length < 1) {
45 | // We are not supposed to hit this, but it doesn't hurt to check either.
46 | return;
47 | }
48 |
49 | if (commandString.startsWith("st") || commandString.startsWith("servertutorial")) {
50 | return;
51 | }
52 |
53 | for (String arg : controller.getTutorial().getCommandWhiteList()) {
54 | if (arg.equalsIgnoreCase(args[0])) {
55 | // This matches the whitelist.
56 | // Nothing is supposed to happen so return.
57 | return;
58 | }
59 | }
60 |
61 | for (String arg : plugin.getConfig().getStringList("command-whitelist")) {
62 | if (arg.equalsIgnoreCase(args[0])) {
63 | // This matches the whitelist.
64 | // Nothing is supposed to happen so return.
65 | return;
66 | }
67 | }
68 |
69 | // All checks passed. Block the command and send the player a message.
70 | event.setCancelled(true);
71 | player.sendMessage(Lang.ERROR_COMMAND_BLOCKED.toString());
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/events/OnEntityDeathEvent.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.events;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.objects.NPCInfo;
5 | import org.bukkit.event.EventHandler;
6 | import org.bukkit.event.Listener;
7 | import org.bukkit.event.entity.EntityDeathEvent;
8 |
9 | public class OnEntityDeathEvent implements Listener {
10 |
11 | private ServerTutorialPlus plugin;
12 |
13 | public OnEntityDeathEvent(ServerTutorialPlus plugin) {
14 | this.plugin = plugin;
15 | }
16 |
17 | @EventHandler
18 | public void onDeathEvent(EntityDeathEvent event) {
19 | NPCInfo info = plugin.getNpcManager().getByUUID(event.getEntity().getUniqueId());
20 | if(info == null) return;
21 |
22 | plugin.getLogger().warning("[!!!] An NPC has been killed! It has been removed from the NPC list.");
23 | plugin.getNpcManager().deleteNPC(info);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/events/OnPlayerInteractEntityEvent.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.events;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.helpers.PluginUtils;
5 | import nl.martenm.servertutorialplus.language.Lang;
6 | import nl.martenm.servertutorialplus.objects.NPCInfo;
7 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
8 | import nl.martenm.servertutorialplus.objects.TutorialController;
9 | import org.bukkit.event.EventHandler;
10 | import org.bukkit.event.Listener;
11 | import org.bukkit.event.player.PlayerInteractEntityEvent;
12 | import org.bukkit.inventory.EquipmentSlot;
13 |
14 | /**
15 | * Player interact entity event for mc versions > 1.8
16 | * Used to check if player clicks a NPC.
17 | * @author MartenM
18 | */
19 | public class OnPlayerInteractEntityEvent implements Listener {
20 |
21 | private ServerTutorialPlus plugin;
22 |
23 | public OnPlayerInteractEntityEvent(ServerTutorialPlus plugin) {
24 | this.plugin = plugin;
25 | }
26 |
27 | @EventHandler(ignoreCancelled = true)
28 | public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
29 | // Pass to the clickmanager.
30 | plugin.getClickManager().handleClickAction(event);
31 |
32 | if (event.getHand() != EquipmentSlot.HAND) {
33 | return;
34 | }
35 |
36 | if (!plugin.selectingNpc.isEmpty()) {
37 | if (plugin.selectingNpc.containsKey(event.getPlayer().getUniqueId())) {
38 | plugin.selectingNpc.get(event.getPlayer().getUniqueId()).create(plugin, event);
39 | }
40 | return;
41 | }
42 |
43 | NPCInfo info = plugin.getNpcManager().getByUUID(event.getRightClicked().getUniqueId());
44 | if (info == null) return;
45 |
46 | event.setCancelled(true);
47 |
48 | ServerTutorial serverTutorial = PluginUtils.getTutorial(plugin, info.getServerTutorialID());
49 | if (serverTutorial == null) {
50 | event.getPlayer().sendMessage(Lang.ERROR_FAILED_FINDING_TUTORIAL_ADMIN.toString().replace("&id&", info.getServerTutorialID()));
51 | return;
52 | }
53 | if (plugin.inTutorial.containsKey(event.getPlayer().getUniqueId())) {
54 | event.getPlayer().sendMessage(Lang.ERROR_WAIT_TO_END_TUTORIAL.toString());
55 | return;
56 | }
57 |
58 | TutorialController tutorialController = new TutorialController(plugin, event.getPlayer(), serverTutorial);
59 | tutorialController.start();
60 | event.setCancelled(true);
61 | }
62 | }
63 |
64 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/events/OnPlayerInteractEntityEventV1_8.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.events;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.helpers.PluginUtils;
5 | import nl.martenm.servertutorialplus.language.Lang;
6 | import nl.martenm.servertutorialplus.objects.NPCInfo;
7 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
8 | import nl.martenm.servertutorialplus.objects.TutorialController;
9 | import org.bukkit.event.EventHandler;
10 | import org.bukkit.event.Listener;
11 | import org.bukkit.event.player.PlayerInteractEntityEvent;
12 |
13 | /**
14 | * Player interact entity event for mc versions = 1.8
15 | * Used to check if player clicks a NPC.
16 | * @author MartenM
17 | */
18 | public class OnPlayerInteractEntityEventV1_8 implements Listener {
19 |
20 | private ServerTutorialPlus plugin;
21 |
22 | public OnPlayerInteractEntityEventV1_8(ServerTutorialPlus plugin) {
23 | this.plugin = plugin;
24 | }
25 |
26 | @EventHandler(ignoreCancelled = true)
27 | public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
28 |
29 | plugin.getClickManager().handleClickAction(event);
30 |
31 | NPCInfo info = plugin.getNpcManager().getByUUID(event.getRightClicked().getUniqueId());
32 | if (info == null) return;
33 |
34 | event.setCancelled(true);
35 |
36 | ServerTutorial serverTutorial = PluginUtils.getTutorial(plugin, info.getServerTutorialID());
37 | if (serverTutorial == null) {
38 | event.getPlayer().sendMessage(Lang.ERROR_FAILED_FINDING_TUTORIAL_ADMIN.toString().replace("&id&", info.getServerTutorialID()));
39 | return;
40 | }
41 | if (plugin.inTutorial.containsKey(event.getPlayer().getUniqueId())) {
42 | event.getPlayer().sendMessage(Lang.ERROR_WAIT_TO_END_TUTORIAL.toString());
43 | return;
44 | }
45 |
46 | TutorialController tutorialController = new TutorialController(plugin, event.getPlayer(), serverTutorial);
47 | tutorialController.start();
48 | event.setCancelled(true);
49 |
50 | }
51 | }
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/events/OnPlayerInteractEvent.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.events;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.helpers.PluginUtils;
5 | import nl.martenm.servertutorialplus.language.Lang;
6 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
7 | import nl.martenm.servertutorialplus.objects.TutorialController;
8 | import nl.martenm.servertutorialplus.objects.TutorialSign;
9 | import org.bukkit.event.EventHandler;
10 | import org.bukkit.event.Listener;
11 | import org.bukkit.event.block.Action;
12 | import org.bukkit.event.player.PlayerInteractEvent;
13 | import org.bukkit.inventory.EquipmentSlot;
14 |
15 | /**
16 | * Player interact event for versions > 1.8
17 | * Used for clickable blocks and signs.
18 | * @author MartenM
19 | */
20 | public class OnPlayerInteractEvent implements Listener{
21 |
22 | private ServerTutorialPlus plugin;
23 | public OnPlayerInteractEvent(ServerTutorialPlus plugin){
24 | this.plugin = plugin;
25 | }
26 |
27 | @EventHandler
28 | public void onPlayerInteractEvent(PlayerInteractEvent event){
29 | // Pass message to clickhandler.
30 | plugin.getClickManager().handleClickAction(event);
31 |
32 | if(event.getClickedBlock() == null || event.getAction() == Action.LEFT_CLICK_BLOCK){
33 | return;
34 | }
35 |
36 | if(event.getHand() != EquipmentSlot.HAND){
37 | return;
38 | }
39 |
40 | if(!plugin.enabled){
41 | return;
42 | }
43 |
44 | for(TutorialSign ts : plugin.tutorialSigns){
45 | if(!ts.block.equals(event.getClickedBlock())){
46 | continue;
47 | }
48 | ServerTutorial serverTutorial = PluginUtils.getTutorial(plugin, ts.ServerTutorialId);
49 |
50 | if(serverTutorial == null){
51 | // Just in here to fix stuff but PluginUtils... Whyyyyyy ;-;
52 | event.getPlayer().sendMessage(Lang.ERROR_FAILED_FINDING_TUTORIAL_ADMIN.toString().replace("%id%", ts.ServerTutorialId));
53 | return;
54 | }
55 |
56 | if(plugin.inTutorial.containsKey(event.getPlayer().getUniqueId())){
57 | event.getPlayer().sendMessage(Lang.ERROR_WAIT_TO_END_TUTORIAL.toString());
58 | return;
59 | }
60 |
61 | TutorialController tutorialController = new TutorialController(plugin, event.getPlayer(), serverTutorial);
62 | tutorialController.start();
63 | event.setCancelled(true);
64 | break;
65 | }
66 | }
67 |
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/events/OnPlayerInteractEventV1_8.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.events;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.helpers.PluginUtils;
5 | import nl.martenm.servertutorialplus.language.Lang;
6 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
7 | import nl.martenm.servertutorialplus.objects.TutorialController;
8 | import nl.martenm.servertutorialplus.objects.TutorialSign;
9 | import org.bukkit.event.EventHandler;
10 | import org.bukkit.event.Listener;
11 | import org.bukkit.event.block.Action;
12 | import org.bukkit.event.player.PlayerInteractEvent;
13 | /**
14 | * Player interact event for versions = 1.8
15 | * Used for clickable blocks and signs.
16 | * @author MartenM
17 | */
18 | public class OnPlayerInteractEventV1_8 implements Listener {
19 |
20 | private ServerTutorialPlus plugin;
21 | public OnPlayerInteractEventV1_8(ServerTutorialPlus plugin){
22 | this.plugin = plugin;
23 | }
24 |
25 | @EventHandler
26 | public void onPlayerInteractEvent(PlayerInteractEvent event){
27 |
28 | plugin.getClickManager().handleClickAction(event);
29 |
30 | if(event.getClickedBlock() == null || event.getAction() == Action.LEFT_CLICK_BLOCK){
31 | return;
32 | }
33 |
34 | if(!plugin.enabled){
35 | return;
36 | }
37 |
38 | for(TutorialSign ts : plugin.tutorialSigns){
39 | if(!ts.block.equals(event.getClickedBlock())){
40 | continue;
41 | }
42 | ServerTutorial serverTutorial = PluginUtils.getTutorial(plugin, ts.ServerTutorialId);
43 | if(serverTutorial == null){
44 | event.getPlayer().sendMessage(Lang.ERROR_FAILED_FINDING_TUTORIAL_ADMIN.toString().replace("%id%", serverTutorial.getId()));
45 | return;
46 | }
47 | if(plugin.inTutorial.containsKey(event.getPlayer().getUniqueId())){
48 | event.getPlayer().sendMessage(Lang.ERROR_WAIT_TO_END_TUTORIAL.toString());
49 | return;
50 | }
51 |
52 | TutorialController tutorialController = new TutorialController(plugin, event.getPlayer(), serverTutorial);
53 | tutorialController.start();
54 | event.setCancelled(true);
55 | break;
56 | }
57 | }
58 |
59 |
60 | }
61 |
62 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/events/OnPlayerJoinEvent.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.events;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.helpers.PluginUtils;
5 | import nl.martenm.servertutorialplus.managers.FlatFileManager;
6 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
7 | import nl.martenm.servertutorialplus.objects.TutorialController;
8 | import org.bukkit.entity.Player;
9 | import org.bukkit.event.EventHandler;
10 | import org.bukkit.event.Listener;
11 | import org.bukkit.event.player.PlayerJoinEvent;
12 | import org.bukkit.scheduler.BukkitRunnable;
13 | import org.json.simple.JSONObject;
14 |
15 | /**
16 | * Player join event listener.
17 | * Will start the first-join-tutorial if set and the user is new on the server.
18 | * This class will check if a player should have his old properties back (saved in player quit event).
19 | * @author MartenM
20 | */
21 | // TODO: Make it so that it checks the datasource (if mysql) instead of the .hasPlayedBefore();
22 | public class OnPlayerJoinEvent implements Listener{
23 |
24 | private ServerTutorialPlus plugin;
25 | public OnPlayerJoinEvent(ServerTutorialPlus plugin){
26 | this.plugin = plugin;
27 | }
28 |
29 | @EventHandler
30 | public void onPlayerJoinEvent(PlayerJoinEvent event){
31 |
32 | plugin.inTutorial.keySet().stream().forEach(uuid -> {
33 | Player toHide = plugin.getServer().getPlayer(uuid);
34 | if(toHide == null) return;
35 |
36 | event.getPlayer().hidePlayer(plugin.getServer().getPlayer(uuid));
37 | });
38 |
39 | if(!event.getPlayer().hasPlayedBefore()) {
40 | if(plugin.getConfig().getBoolean("enable first join tutorial")){
41 | ServerTutorial st = PluginUtils.getTutorial(plugin, plugin.getConfig().getString("first join tutorial id"));
42 | if(st == null){
43 | return;
44 | }
45 |
46 | // Delay this such that other plugins can handle the spawn of the player first.
47 | plugin.getLogger().info("Starting tutorial for player " + event.getPlayer().getName() + " [First Join]");
48 | new BukkitRunnable() {
49 | @Override
50 | public void run() {
51 | TutorialController tutorialController = new TutorialController(plugin, event.getPlayer(), st);
52 | tutorialController.start();
53 | }
54 | }.runTaskLater(plugin, 20);
55 |
56 | return;
57 | }
58 | return;
59 | }
60 |
61 | new BukkitRunnable(){
62 | @Override
63 | public void run() {
64 | JSONObject object = FlatFileManager.getPlayerData(plugin, event.getPlayer().getUniqueId());
65 | if(object == null){
66 | this.cancel();
67 | return;
68 | }
69 | FlatFileManager.setPlayerData(plugin, event.getPlayer(), object);
70 | FlatFileManager.deleteFile(plugin, event.getPlayer().getUniqueId());
71 | }
72 | }.runTaskAsynchronously(plugin);
73 | }
74 |
75 |
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/events/OnPlayerQuitEvent.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.events;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.helpers.dataholders.OldValuesPlayer;
5 | import nl.martenm.servertutorialplus.objects.TutorialController;
6 | import org.bukkit.event.EventHandler;
7 | import org.bukkit.event.Listener;
8 | import org.bukkit.event.player.PlayerQuitEvent;
9 |
10 | /**
11 | * Player quit event listener.
12 | * Save the old state of a player if he leaves while in a tutorial. This makes sure we actually restore the properties of the player on the next join.
13 | * @author MartenM
14 | */
15 | public class OnPlayerQuitEvent implements Listener {
16 |
17 | private ServerTutorialPlus plugin;
18 | public OnPlayerQuitEvent(ServerTutorialPlus plugin){
19 | this.plugin = plugin;
20 | }
21 |
22 | @EventHandler
23 | public void onPlayerQuit(PlayerQuitEvent event){
24 | if(plugin.inTutorial.containsKey(event.getPlayer().getUniqueId())){
25 | TutorialController tc = plugin.inTutorial.get(event.getPlayer().getUniqueId());
26 | tc.cancel(true);
27 |
28 | OldValuesPlayer oldValuesPlayer = tc.getOldValuesPlayer();
29 | oldValuesPlayer.restore(event.getPlayer());
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/events/OnPlayerToggleFlight.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.events;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import org.bukkit.event.EventHandler;
5 | import org.bukkit.event.Listener;
6 | import org.bukkit.event.player.PlayerToggleFlightEvent;
7 |
8 | /**
9 | * Player toggle flight listener.
10 | * Cancel toggle when locked flight.
11 | * @author MartenM
12 | */
13 | public class OnPlayerToggleFlight implements Listener{
14 |
15 | private ServerTutorialPlus plugin;
16 | public OnPlayerToggleFlight(ServerTutorialPlus plugin){
17 | this.plugin = plugin;
18 | }
19 |
20 | @EventHandler
21 | public void OnPlayerToggleFlightEvent(PlayerToggleFlightEvent event){
22 | if(plugin.lockedPlayers.contains(event.getPlayer().getUniqueId())){
23 | event.setCancelled(true);
24 | }
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/events/onPlayerMoveEvent.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.events;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import org.bukkit.event.EventHandler;
5 | import org.bukkit.event.Listener;
6 | import org.bukkit.event.player.PlayerMoveEvent;
7 |
8 | /**
9 | * Listener for the player move event.
10 | * Used to block movement if a player has been locked.
11 | * @author MartenM
12 | */
13 | public class onPlayerMoveEvent implements Listener {
14 |
15 | private ServerTutorialPlus plugin;
16 | public onPlayerMoveEvent(ServerTutorialPlus plugin){
17 | this.plugin = plugin;
18 | }
19 |
20 | @EventHandler
21 | public void playerMoveEvent(PlayerMoveEvent event){
22 | if(plugin.lockedPlayers.contains(event.getPlayer().getUniqueId())){
23 | if(event.getFrom().getX() != event.getTo().getX() || event.getFrom().getY() != event.getTo().getY() || event.getFrom().getZ() != event.getTo().getZ()){
24 | //Player moved!
25 | event.setCancelled(true);
26 | }
27 | }
28 |
29 | if(plugin.lockedViews.contains(event.getPlayer().getUniqueId())){
30 | if(event.getFrom().getYaw() != event.getTo().getYaw() || event.getFrom().getPitch() != event.getTo().getPitch()){
31 | //Player moved!
32 | event.setCancelled(true);
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/helpers/BukkitVersion.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.helpers;
2 |
3 | import org.bukkit.Bukkit;
4 |
5 | /**
6 | * Utility class to determine the server version and activate code based on this.
7 | */
8 | public class BukkitVersion {
9 |
10 | int majorVersion;
11 | int minorVersion;
12 | int patchVersion;
13 |
14 | private static BukkitVersion instance;
15 | private BukkitVersion() {
16 | String versionString = Bukkit.getBukkitVersion();
17 | String[] split = versionString.split("-")[0].split("\\.");
18 | majorVersion = Integer.parseInt(split[0]);
19 | minorVersion = Integer.parseInt(split[1]);
20 |
21 | // 1.10 1.11 1.12, they don't have a patch version.
22 | if (split.length > 2) patchVersion = Integer.parseInt(split[2]);
23 | else patchVersion = 0;
24 |
25 | Bukkit.getLogger().info(String.format("Bukkit API version: %s.%s.%s", majorVersion, minorVersion, patchVersion));
26 | }
27 |
28 | public static BukkitVersion getInstance() {
29 | if(instance == null) {
30 | instance = new BukkitVersion();
31 | }
32 | return instance;
33 | }
34 |
35 | public boolean versionEqualOrHigher(int majorVersion) {
36 | return this.majorVersion >= majorVersion;
37 | }
38 |
39 | public boolean versionEqualOrHigher(int majorVersion, int minorVersion) {
40 | if(!versionEqualOrHigher(majorVersion)) return false;
41 | return this.minorVersion >= minorVersion;
42 | }
43 |
44 | public boolean versionEqualOrHigher(int majorVersion, int minorVersion, int patchVersion) {
45 | if(!versionEqualOrHigher(majorVersion, minorVersion)) return false;
46 | return this.patchVersion >= patchVersion;
47 | }
48 |
49 | public boolean versionEqualOrLower(int majorVersion) {
50 | return this.majorVersion <= majorVersion;
51 | }
52 |
53 | public boolean versionEqualOrLower(int majorVersion, int minorVersion) {
54 | if(!versionEqualOrLower(majorVersion)) return false;
55 | return this.minorVersion <= minorVersion;
56 | }
57 |
58 | public boolean versionEqualOrLower(int majorVersion, int minorVersion, int patchVersion) {
59 | if(!versionEqualOrLower(majorVersion, minorVersion)) return false;
60 | return this.patchVersion <= patchVersion;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/helpers/Color.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.helpers;
2 |
3 | /**
4 | * Simple colour class for particle colours.
5 | * @author MartenM
6 | * @since 27-11-2017.
7 | */
8 |
9 | public class Color{
10 | private int red;
11 | private int green;
12 | private int blue;
13 |
14 | public Color(int red, int green, int blue){
15 | if(red == 0){
16 | this.red = 1;
17 | } else this.red = red;
18 |
19 | this.green = green;
20 | this.blue = blue;
21 | }
22 |
23 | public int getRed() {
24 | return red;
25 | }
26 |
27 | public void setRed(int red) {
28 | if(red == 0){
29 | this.red = 1;
30 | } else this.red = red;
31 | }
32 |
33 | public int getGreen() {
34 | return green;
35 | }
36 |
37 | public void setGreen(int green) {
38 | this.green = green;
39 | }
40 |
41 | public int getBlue() {
42 | return blue;
43 | }
44 |
45 | public void setBlue(int blue) {
46 | this.blue = blue;
47 | }
48 |
49 | public void set(int red, int green, int blue){
50 | setRed(red);
51 | setGreen(green);
52 | setBlue(blue);
53 | }
54 |
55 | @Override
56 | public String toString() {
57 | return red + " " + green + " " + blue;
58 | }
59 |
60 | public static Color fromString(String input){
61 | try{
62 | String[] data = input.split(" ");
63 | return new Color(Integer.parseInt(data[0]), Integer.parseInt(data[1]),Integer.parseInt(data[2]));
64 | } catch (Exception ex){
65 | ex.printStackTrace();
66 | System.out.println("[!!] Invalid colour from string!");
67 | return new Color(255, 0, 0);
68 | }
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/helpers/Config.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.helpers;
2 | import java.io.File;
3 |
4 | import org.bukkit.configuration.file.YamlConfiguration;
5 | import org.bukkit.plugin.java.JavaPlugin;
6 |
7 | public class Config extends YamlConfiguration{
8 |
9 | private JavaPlugin plugin;
10 | private String fileName;
11 |
12 | public Config(JavaPlugin plugin, String fileName){
13 | this.plugin = plugin;
14 | this.fileName = fileName + (fileName.endsWith(".yml") ? "" : ".yml");
15 | createFile();
16 | }
17 |
18 | private void createFile() {
19 | try {
20 | File file = new File(plugin.getDataFolder(), fileName);
21 | if (!file.exists()){
22 | if (plugin.getResource(fileName) != null){
23 | plugin.saveResource(fileName, false);
24 | }else{
25 | save(file);
26 | }
27 | }else{
28 | load(file);
29 | save(file);
30 | }
31 | } catch (Exception ex) {
32 | ex.printStackTrace();
33 | }
34 | }
35 |
36 | public void save(){
37 | try {
38 | save(new File(plugin.getDataFolder(), fileName));
39 | } catch (Exception ex) {
40 | ex.printStackTrace();
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/helpers/Messages.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.helpers;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import net.md_5.bungee.api.ChatColor;
5 |
6 | /**
7 | * Created by Marten on 5-3-2017.
8 | */
9 | public class Messages {
10 |
11 | public static String noPermissionTutorial(ServerTutorialPlus plugin){
12 | return ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("no permission tutorial"));
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/helpers/NeedsReflection.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.helpers;
2 |
3 | import org.bukkit.Bukkit;
4 | import org.bukkit.ChatColor;
5 | import org.bukkit.entity.Player;
6 |
7 | import java.lang.reflect.Constructor;
8 | /**
9 | * Class for reflection for certain methods.
10 | * Credits to: bramhaag.
11 | */
12 | public class NeedsReflection {
13 |
14 | /**
15 | * Send a title to player
16 | * @param player Player to send the title to
17 | * @param text The text displayed in the title
18 | * @param fadeInTime The time the title takes to fade in
19 | * @param showTime The time the title is displayed
20 | * @param fadeOutTime The time the title takes to fade out
21 | * @param color The color of the title
22 | */
23 | public static void sendTitle(Player player, String text, int fadeInTime, int showTime, int fadeOutTime, ChatColor color)
24 | {
25 | try
26 | {
27 | String title_text = net.md_5.bungee.api.ChatColor.translateAlternateColorCodes('&', text);
28 |
29 | Constructor timeConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(int.class, int.class, int.class);
30 |
31 | Object enumTitle = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TITLE").get(null);
32 | Object title = getNMSClass("IChatBaseComponent$ChatSerializer").getMethod("a", String.class).invoke(null, "{\"text\": \"" + title_text +"\"}");
33 | Constructor titleConstuctor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle$EnumTitleAction"), getNMSClass("IChatBaseComponent"), int.class, int.class, int.class);
34 | Object packet = titleConstuctor.newInstance(enumTitle, title, fadeInTime, showTime, fadeOutTime);
35 |
36 | Object packetTimes = timeConstructor.newInstance(fadeInTime, showTime, fadeOutTime);
37 |
38 | sendPacket(player, packetTimes);
39 | sendPacket(player, packet);
40 | }
41 |
42 | catch (Exception ex)
43 | {
44 | ex.printStackTrace(); //Do something
45 | }
46 | }
47 |
48 | public static void sendSubTitle(Player player, String text, int fadeInTime, int showTime, int fadeOutTime, ChatColor color)
49 | {
50 | try
51 | {
52 | String title_text = net.md_5.bungee.api.ChatColor.translateAlternateColorCodes('&', text);
53 |
54 | Object enumTitle = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("SUBTITLE").get(null);
55 | Object title = getNMSClass("IChatBaseComponent$ChatSerializer").getMethod("a", String.class).invoke(null, "{\"text\": \"" + title_text +"\"}");
56 |
57 | Constructor titleConstuctor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle$EnumTitleAction"), getNMSClass("IChatBaseComponent"), int.class, int.class, int.class);
58 | Object packet = titleConstuctor.newInstance(enumTitle, title, fadeInTime, showTime, fadeOutTime);
59 | sendPacket(player, packet);
60 | }
61 |
62 | catch (Exception ex)
63 | {
64 | ex.printStackTrace(); //Do something
65 | }
66 | }
67 |
68 | public static void sendActionBar(Player player, String text)
69 | {
70 | try
71 | {
72 | String title_text = net.md_5.bungee.api.ChatColor.translateAlternateColorCodes('&', text);
73 |
74 | Object enumTitle = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("ACTIONBAR").get(null);
75 | Object title = getNMSClass("IChatBaseComponent$ChatSerializer").getMethod("a", String.class).invoke(null, "{\"text\": \"" + title_text +"\"}");
76 |
77 | Constructor titleConstuctor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle$EnumTitleAction"), getNMSClass("IChatBaseComponent"));
78 | Object packet = titleConstuctor.newInstance(enumTitle, title);
79 | sendPacket(player, packet);
80 | }
81 |
82 | catch (Exception ex)
83 | {
84 | ex.printStackTrace(); //Do something
85 | }
86 | }
87 |
88 | private static void sendPacket(Player player, Object packet)
89 | {
90 | try
91 | {
92 | Object handle = player.getClass().getMethod("getHandle").invoke(player);
93 | Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
94 | playerConnection.getClass().getMethod("sendPacket", getNMSClass("Packet")).invoke(playerConnection, packet);
95 | }
96 | catch(Exception ex)
97 | {
98 | //Do something
99 | }
100 | }
101 |
102 | /**
103 | * Get NMS class using reflection
104 | * @param name Name of the class
105 | * @return Class
106 | */
107 | private static Class> getNMSClass(String name) {
108 | try
109 | {
110 | return Class.forName("net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + "." + name);
111 | } catch (ClassNotFoundException ex) {
112 | //Do something
113 | System.out.println(ex.toString());
114 | return null;
115 | }
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/helpers/PluginUtils.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.helpers;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
5 | import me.clip.placeholderapi.PlaceholderAPI;
6 | import org.bukkit.ChatColor;
7 | import org.bukkit.Location;
8 | import org.bukkit.World;
9 | import org.bukkit.entity.*;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 | import java.util.regex.Matcher;
14 | import java.util.regex.Pattern;
15 |
16 | import static org.bukkit.ChatColor.COLOR_CHAR;
17 |
18 | /**
19 | * Created by Marten on 7-3-2017.
20 | */
21 | public abstract class PluginUtils {
22 |
23 | public static String translateHexColorCodes(String startTag, String endTag, String message)
24 | {
25 | final Pattern hexPattern = Pattern.compile(startTag + "([A-Fa-f0-9]{6})" + endTag);
26 | Matcher matcher = hexPattern.matcher(message);
27 | StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
28 | while (matcher.find())
29 | {
30 | String group = matcher.group(1);
31 | matcher.appendReplacement(buffer, COLOR_CHAR + "x"
32 | + COLOR_CHAR + group.charAt(0) + COLOR_CHAR + group.charAt(1)
33 | + COLOR_CHAR + group.charAt(2) + COLOR_CHAR + group.charAt(3)
34 | + COLOR_CHAR + group.charAt(4) + COLOR_CHAR + group.charAt(5)
35 | );
36 | }
37 | return matcher.appendTail(buffer).toString();
38 | }
39 |
40 | public static ServerTutorial getTutorial(ServerTutorialPlus plugin, String ID) {
41 | if (ID == null) return null;
42 | for (ServerTutorial serverTutorial : plugin.serverTutorials) {
43 | if (serverTutorial.getId().equalsIgnoreCase(ID)) {
44 | return serverTutorial;
45 | }
46 | }
47 |
48 | //Nothing found!
49 | return null;
50 | }
51 |
52 | public static List getHollowCube(Location corner1, Location corner2, double particleDistance) {
53 | List result = new ArrayList<>();
54 | World world = corner1.getWorld();
55 | double minX = Math.min(corner1.getX(), corner2.getX());
56 | double minY = Math.min(corner1.getY(), corner2.getY());
57 | double minZ = Math.min(corner1.getZ(), corner2.getZ());
58 | double maxX = Math.max(corner1.getX(), corner2.getX());
59 | double maxY = Math.max(corner1.getY(), corner2.getY());
60 | double maxZ = Math.max(corner1.getZ(), corner2.getZ());
61 |
62 | for (double x = minX; x <= maxX; x += particleDistance) {
63 | for (double y = minY; y <= maxY; y += particleDistance) {
64 | for (double z = minZ; z <= maxZ; z += particleDistance) {
65 | int components = 0;
66 | if (x == minX || x == maxX) components++;
67 | if (y == minY || y == maxY) components++;
68 | if (z == minZ || z == maxZ) components++;
69 | if (components >= 2) {
70 | result.add(new Location(world, x, y, z));
71 | }
72 | }
73 | }
74 | }
75 |
76 | return result;
77 | }
78 |
79 | public static Location fromString(ServerTutorialPlus plugin, String message) {
80 | String[] data = message.split(" ");
81 | String world = data[0];
82 | double x = Double.parseDouble(data[1]);
83 | double y = Double.parseDouble(data[2]);
84 | double z = Double.parseDouble(data[3]);
85 | float yaw = Float.parseFloat(data[4]);
86 | float pitch = Float.parseFloat(data[5]);
87 | return new Location(plugin.getServer().getWorld(world), x, y, z, yaw, pitch);
88 |
89 | }
90 |
91 | public static String fromLocation(Location loc) {
92 | return loc.getWorld().getName() + " " +
93 | loc.getX() + " " +
94 | loc.getY() + " " +
95 | loc.getZ() + " " +
96 | loc.getYaw() + " " +
97 | loc.getPitch();
98 | }
99 |
100 | public static String replaceVariables(boolean PlaceHolders, Player player, String message) {
101 | String withoutColours;
102 |
103 | if (PlaceHolders) {
104 | withoutColours = PlaceholderAPI.setPlaceholders(player, replaceIntern(player, message));
105 | } else {
106 | withoutColours = replaceIntern(player, message);
107 | }
108 |
109 | withoutColours = translateHexColorCodes("", "", withoutColours);
110 | return ChatColor.translateAlternateColorCodes('&', withoutColours);
111 | }
112 |
113 | private static String replaceIntern(Player player, String message) {
114 | return message
115 | .replace("{player_name}", player.getName())
116 | .replaceAll("%user_?name%", player.getName());
117 | }
118 |
119 | public static String allMobs() {
120 | return "VILLAGER, ZOMBIE, HUSK, WITCH, SPIDER, SLIME, SKELETON, CREEPER, PIG_ZOMBIE, BLAZE, CAVE_SPIDER, ENDERMAN, BAT, MAGMA_CUBE, WITHER, RABBIT, PIG, COW, SHEEP, CHICKEN, WOLF, ENDERMITE, BLAZE, GUARDIAN, HORSE, POLAR_BEAR";
121 | }
122 |
123 | }
124 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/helpers/SpigotUtils.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.helpers;
2 |
3 | import org.bukkit.Bukkit;
4 | import org.bukkit.World;
5 | import org.bukkit.entity.Entity;
6 |
7 | import java.util.UUID;
8 |
9 | /**
10 | * Created by Marten on 4-6-2017.
11 | */
12 | public class SpigotUtils {
13 |
14 | private SpigotUtils(){
15 | //Empty constructor.
16 | }
17 |
18 | public static Entity getEntity(UUID uuid){
19 | if(Bukkit.getVersion().contains("1.8") || Bukkit.getVersion().contains("1.9") || Bukkit.getVersion().contains("1.10")){
20 | for(World world : Bukkit.getServer().getWorlds()){
21 | for(Entity entity : world.getEntities()){
22 | if(entity.getUniqueId().equals(uuid)){
23 | return entity;
24 | }
25 | }
26 | }
27 | return null;
28 | }
29 | return Bukkit.getEntity(uuid);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/helpers/dataholders/FireWorkInfo.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.helpers.dataholders;
2 |
3 | import org.bukkit.Location;
4 | import org.bukkit.inventory.meta.FireworkMeta;
5 |
6 | /**
7 | * Created by Marten on 19-3-2017.
8 | */
9 | public class FireWorkInfo {
10 |
11 | private Location location;
12 | private FireworkMeta fireworkMeta;
13 |
14 | public FireWorkInfo(Location location, FireworkMeta fireworkMeta){
15 | this.fireworkMeta = fireworkMeta;
16 | this.location = location;
17 | }
18 |
19 | public Location getLoc() {
20 | return location;
21 | }
22 |
23 | public FireworkMeta getFireworkMeta() {
24 | return fireworkMeta;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/helpers/dataholders/OldValuesPlayer.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.helpers.dataholders;
2 |
3 | import org.bukkit.GameMode;
4 | import org.bukkit.Location;
5 | import org.bukkit.entity.Player;
6 |
7 | import java.util.UUID;
8 |
9 | /**
10 | * Created by Marten on 15-3-2017.
11 | */
12 | public class OldValuesPlayer {
13 |
14 | private UUID uuid;
15 | private float original_flySpeed;
16 | private float original_walkSpeed;
17 | private boolean flying;
18 | private boolean allowFlight;
19 | private Location loc;
20 | private GameMode gamemode;
21 |
22 | public OldValuesPlayer(Player player){
23 | this.uuid = player.getUniqueId();
24 | this.original_flySpeed = player.getFlySpeed();
25 | this.original_walkSpeed = player.getWalkSpeed();
26 | this.flying = player.isFlying();
27 | this.allowFlight = player.getAllowFlight();
28 | this.loc = player.getLocation();
29 | this.gamemode = player.getGameMode();
30 | }
31 |
32 |
33 | public float getOriginal_flySpeed() {
34 | return original_flySpeed;
35 | }
36 |
37 | public float getOriginal_walkSpeed() {
38 | return original_walkSpeed;
39 | }
40 |
41 | public UUID getUuid() {
42 | return uuid;
43 | }
44 |
45 | public boolean getFlying() {
46 | return flying;
47 | }
48 |
49 | public boolean isAllowFlight() {
50 | return allowFlight;
51 | }
52 |
53 | public Location getLoc() {
54 | return loc;
55 | }
56 |
57 | public GameMode getGamemode() {
58 | return gamemode;
59 | }
60 |
61 | public void restore(Player player) {
62 | player.setFlySpeed(getOriginal_flySpeed());
63 | player.setWalkSpeed(getOriginal_walkSpeed());
64 | player.setAllowFlight(isAllowFlight());
65 | player.setFlying(getFlying());
66 | player.setGameMode(getGamemode());
67 | player.teleport(getLoc());
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/helpers/dataholders/PlayerSound.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.helpers.dataholders;
2 |
3 | import org.bukkit.Sound;
4 |
5 | /**
6 | * Created by Marten on 5-3-2017.
7 | */
8 | public class PlayerSound {
9 |
10 | public PlayerSound(Sound sound, float pitch, float volume){
11 | this.sound = sound;
12 | this.pitch = pitch;
13 | this.volume = volume;
14 | }
15 |
16 | public Sound sound;
17 | public float pitch;
18 | public float volume;
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/helpers/dataholders/PlayerTitle.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.helpers.dataholders;
2 |
3 | /**
4 | * Created by Marten on 5-3-2017.
5 | */
6 | public class PlayerTitle {
7 |
8 | public PlayerTitle(String title, String subtitle, int fadeIn, int time, int fadeOut){
9 | this.title = title;
10 | this.subtitle = subtitle;
11 | this.time = time;
12 | this.fadeIn = fadeIn;
13 | this.fadeOut = fadeOut;
14 | }
15 |
16 | public PlayerTitle(){
17 | this.title = "";
18 | this.subtitle = "";
19 | this.fadeIn = 20;
20 | this.fadeOut = 20;
21 | this.time = 40;
22 | }
23 |
24 | public String title;
25 | public String subtitle;
26 | public int time;
27 | public int fadeIn;
28 | public int fadeOut;
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/managers/AbstractManager.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.managers;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 |
5 | import java.util.logging.Logger;
6 |
7 | public abstract class AbstractManager {
8 |
9 | protected ServerTutorialPlus plugin;
10 | protected Logger logger;
11 |
12 | public AbstractManager(ServerTutorialPlus plugin) {
13 | this.plugin = plugin;
14 | this.logger = plugin.getLogger();
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/managers/FlatFileManager.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.managers;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.helpers.PluginUtils;
5 | import nl.martenm.servertutorialplus.helpers.dataholders.OldValuesPlayer;
6 | import org.bukkit.GameMode;
7 | import org.bukkit.entity.Player;
8 | import org.bukkit.scheduler.BukkitRunnable;
9 | import org.json.simple.JSONObject;
10 | import org.json.simple.parser.JSONParser;
11 |
12 | import java.io.File;
13 | import java.io.FileReader;
14 | import java.io.FileWriter;
15 | import java.util.UUID;
16 |
17 | /**
18 | * Created by Marten on 7-6-2017.
19 | */
20 | @SuppressWarnings("ALL")
21 | public class FlatFileManager{
22 |
23 | public static JSONObject getPlayerData(ServerTutorialPlus plugin, UUID uuid){
24 | File hostlocation = new File(plugin.getDataFolder() + "/playerdata");
25 | hostlocation.mkdirs();
26 |
27 | File file = new File(plugin.getDataFolder() + "/playerdata/" + uuid + ".json");
28 | if(file.exists()){
29 | JSONParser parser = new JSONParser();
30 | JSONObject data = null;
31 | try{
32 | FileReader reader = new FileReader(file.getPath());
33 | Object obj = parser.parse(reader);
34 | data = (JSONObject) obj;
35 | reader.close();
36 | } catch (Exception ex){
37 | ex.printStackTrace();
38 | return null;
39 | }
40 | return data;
41 | }
42 | else{
43 | //Nothing we only get data that exists ;p
44 | }
45 | return null;
46 | }
47 |
48 | public static void setPlayerData(ServerTutorialPlus plugin, Player player, JSONObject object){
49 | if(object == null) return;
50 | new BukkitRunnable(){
51 | @Override
52 | public void run() {
53 | plugin.getLogger().info("Restoring player status for player: " + player.getName());
54 | Double dd = (Double) object.get("walkspeed");
55 | player.setWalkSpeed(dd.floatValue());
56 | player.setAllowFlight((Boolean) object.get("isAllowedFlight"));
57 | player.setFlying((boolean) object.get("isFlying"));
58 | Double ff = (Double) object.get("flyspeed");
59 | player.setFlySpeed(ff.floatValue());
60 | player.teleport(PluginUtils.fromString(plugin, (String) object.get("location")));
61 | player.setGameMode(GameMode.valueOf(object.get("gamemode").toString()));
62 | }
63 | }.runTask(plugin);
64 | }
65 |
66 | public static void deleteFile(ServerTutorialPlus plugin, UUID uuid){
67 | File file = new File(plugin.getDataFolder() + "/playerdata/" + uuid + ".json");
68 | if(file.exists()){
69 | file.delete();
70 | } else{
71 | System.out.println("[Server Tutorial Plus] Error, file not found.");
72 | }
73 | }
74 |
75 | public static void saveJson(ServerTutorialPlus plugin, OldValuesPlayer info){
76 | File hostlocation = new File(plugin.getDataFolder() + "/playerdata");
77 | hostlocation.mkdirs();
78 |
79 | JSONObject data = new JSONObject();
80 | data.put("isFlying", info.getFlying());
81 | data.put("isAllowedFlight", info.isAllowFlight());
82 | data.put("flyspeed", info.getOriginal_flySpeed());
83 | data.put("walkspeed", info.getOriginal_walkSpeed());
84 | data.put("location", PluginUtils.fromLocation(info.getLoc()));
85 | data.put("gamemode", info.getGamemode().toString());
86 |
87 | File file = new File(plugin.getDataFolder() + "/playerdata/" + info.getUuid() + ".json");
88 |
89 | FileWriter writer = null;
90 | try{
91 | writer = new FileWriter(file);
92 | writer.write(data.toJSONString());
93 | System.out.println("[Server Tutorial Plus] A player left while in the tutorial. Old data has been saved.");
94 | } catch (Exception ex){
95 | ex.printStackTrace();
96 | } finally {
97 | if(writer != null){
98 | try {
99 | writer.flush();
100 | writer.close();
101 | } catch (Exception ex){
102 | ex.printStackTrace();
103 | }
104 | }
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/managers/clickactions/ClickManager.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.managers.clickactions;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import org.bukkit.event.player.PlayerInteractEntityEvent;
5 | import org.bukkit.event.player.PlayerInteractEvent;
6 |
7 | import java.util.HashMap;
8 | import java.util.Map;
9 | import java.util.UUID;
10 |
11 | /**
12 | * The ClickAction manager handles all events that could have some sort of click action.
13 | * This includes PlayerInteractEvent and PlayerInteractEntityEvent. Both these events can get caught here and handled as they should be.
14 | * @author MartenM
15 | * @since 17-1-2018.
16 | */
17 | public class ClickManager {
18 |
19 | private Map clickActions;
20 |
21 | private ServerTutorialPlus plugin;
22 | public ClickManager(ServerTutorialPlus plugin){
23 | this.plugin = plugin;
24 | this.clickActions = new HashMap<>();
25 | }
26 |
27 | public boolean registerClickAction(UUID uuid, IClickAction action){
28 | if(hasClickaction(uuid)) return false;
29 | clickActions.put(uuid, action);
30 | return true;
31 | }
32 |
33 | public void removeClickaction(UUID uuid){
34 | clickActions.remove(uuid);
35 | }
36 |
37 | public boolean hasClickaction(UUID uuid){
38 | return clickActions.containsKey(uuid);
39 | }
40 |
41 | public void handleClickAction(PlayerInteractEvent event){
42 | if(!hasClickaction(event.getPlayer().getUniqueId())) return;
43 | clickActions.get(event.getPlayer().getUniqueId()).run(event);
44 | }
45 |
46 | public void handleClickAction(PlayerInteractEntityEvent event){
47 | if(!hasClickaction(event.getPlayer().getUniqueId())) return;
48 | clickActions.get(event.getPlayer().getUniqueId()).run(event);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/managers/clickactions/IClickAction.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.managers.clickactions;
2 |
3 | import org.bukkit.event.player.PlayerInteractEntityEvent;
4 | import org.bukkit.event.player.PlayerInteractEvent;
5 |
6 | /**
7 | * Interface that can be used for the ClickManager.
8 | * Allows for both playerInteract events with and without entities.
9 | * @author MartenM
10 | * @since 17-1-2018.
11 | */
12 | public interface IClickAction {
13 | void run(PlayerInteractEvent event);
14 |
15 | void run(PlayerInteractEntityEvent event);
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/objects/NPCInfo.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.objects;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.helpers.SpigotUtils;
5 | import org.bukkit.Location;
6 |
7 | import java.util.UUID;
8 |
9 | /**
10 | * This class holds info about NPCs.
11 | * It also contains the UUIDs of the armorstands (holograms)
12 | * @author MartenM
13 | */
14 | public class NPCInfo {
15 |
16 | private ServerTutorialPlus plugin;
17 |
18 | private String id;
19 |
20 | private UUID npcId;
21 | private UUID[] armorstandIDs;
22 | private String serverTutorialID;
23 |
24 | private Location location;
25 |
26 | public NPCInfo(ServerTutorialPlus plugin, String id, UUID npcId, UUID[] armorstandIDs, String serverTutorialID){
27 | this.plugin = plugin;
28 | this.id = id;
29 | this.npcId = npcId;
30 | this.armorstandIDs = armorstandIDs;
31 | this.serverTutorialID = serverTutorialID;
32 |
33 | try{
34 | location = SpigotUtils.getEntity(npcId).getLocation();
35 | } catch (Exception ex){
36 | System.out.println(ex.getStackTrace());
37 | //Welp what happend!
38 | }
39 | }
40 |
41 | public NPCInfo(ServerTutorialPlus plugin, String id, UUID npcId, UUID[] armorstandIDs, String serverTutorialID, Location location){
42 | this.plugin = plugin;
43 | this.id = id;
44 | this.npcId = npcId;
45 | this.armorstandIDs = armorstandIDs;
46 | this.serverTutorialID = serverTutorialID;
47 |
48 | this.location = location;
49 | }
50 |
51 | public String getId() {
52 | return id;
53 | }
54 |
55 | public UUID getNpcId() {
56 | return npcId;
57 | }
58 |
59 | public UUID[] getArmorstandIDs() {
60 | return armorstandIDs;
61 | }
62 |
63 | public void setArmorstandIDs(UUID[] armorstandIDs) {
64 | this.armorstandIDs = armorstandIDs;
65 | }
66 |
67 | public String getServerTutorialID() {
68 | return serverTutorialID;
69 | }
70 |
71 | public Location getLocation() {
72 | return location;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/objects/ServerTutorial.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.objects;
2 |
3 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | /**
9 | * The ServerTutorial class represents a single sever tutorial. It contains all the data about the tutorial.
10 | * The object contains a List which contains TutorialPoints. These points store the unique data for each point.
11 | * @author MartenM
12 | * @since 5-3-2017.
13 | */
14 | public class ServerTutorial {
15 |
16 | public ServerTutorial(String id){
17 | this.id = id;
18 | this.points = new ArrayList<>();
19 | this.rewards = new ArrayList<>();
20 | this.commandWhiteList = new ArrayList<>();
21 | }
22 |
23 | public ServerTutorial(String id, List points){
24 | this.id = id;
25 | this.points = points;
26 | this.rewards = new ArrayList<>();
27 | this.commandWhiteList = new ArrayList<>();
28 | }
29 |
30 | public ServerTutorial(String id, List points, List rewards){
31 | this.id = id;
32 | this.points = points;
33 | this.rewards = rewards;
34 | this.commandWhiteList = new ArrayList<>();
35 | }
36 |
37 |
38 | private String id;
39 |
40 | /**
41 | * Public variable for tracking plays.
42 | */
43 | public int plays;
44 |
45 | public boolean invisiblePlayer;
46 |
47 | private boolean blocksCommands;
48 |
49 | private List commandWhiteList;
50 |
51 | /**
52 | * The list of TutorialPoints for this tutorial.
53 | */
54 | public List points;
55 |
56 | /**
57 | * List of rewards that are given when the tutorial is completed for the first time.
58 | */
59 | private List rewards;
60 |
61 | /**
62 | * If the user should have the permission 'servertutorialplus.tutorial.ID to play this tutorial.
63 | */
64 | private boolean needsPermission;
65 |
66 | /**
67 | * If set to true the incoming chat messages to the player will be blocked.
68 | */
69 | private boolean blockChat;
70 |
71 | /**
72 | * The unique id of the server tutorial.
73 | * @return id
74 | */
75 | public String getId() {
76 | return id;
77 | }
78 |
79 | /**
80 | * Sets the unique id of a server tutorial.
81 | * USE WITH CAUTION!
82 | * @param id The new ID.
83 | */
84 | public void setId(String id) {
85 | this.id = id;
86 | }
87 |
88 | public List getRewards() {
89 | return rewards;
90 | }
91 |
92 | public void setRewards(List rewards) {
93 | if(rewards == null) this.rewards = new ArrayList<>();
94 |
95 | this.rewards = rewards;
96 | }
97 |
98 | /**
99 | * Gets if you need permission to play this tutorial.
100 | * @return If permission is needed.
101 | */
102 | public boolean getNeedsPermission() {
103 | return needsPermission;
104 | }
105 |
106 | /**
107 | * Sets if you need permission to play this tutorial.
108 | * @param needsPermission true means permission is needed.
109 | */
110 | public void setNeedsPermission(boolean needsPermission) {
111 | this.needsPermission = needsPermission;
112 | }
113 |
114 | /**
115 | * Get whether this tutorial blocks commands by other plugins and Bukkit/Spigot it self.
116 | * @return true if blocks commands
117 | */
118 | public boolean isBlockingCommands() {
119 | return blocksCommands;
120 | }
121 |
122 | /**
123 | * Set whether this servertutorial blocks commands from the player.
124 | */
125 | public void setBlocksCommands(boolean blocksCommands) {
126 | this.blocksCommands = blocksCommands;
127 | }
128 |
129 | public List getCommandWhiteList() {
130 | return commandWhiteList;
131 | }
132 |
133 | public void setCommandWhiteList(List commandWhiteList) {
134 | if(commandWhiteList == null) this.commandWhiteList = new ArrayList<>();
135 | this.commandWhiteList = commandWhiteList;
136 | }
137 |
138 | /**
139 | * Wheter the player is receiving chat messages or not while in the tutorial.
140 | */
141 | public boolean isChatBlocked() {
142 | return blockChat;
143 | }
144 |
145 | /**
146 | * Set if the player should not receive chat messages from other players.
147 | */
148 | public void setChatBlocked(boolean blockChat) {
149 | this.blockChat = blockChat;
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/objects/TutorialController.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.objects;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import net.md_5.bungee.api.ChatColor;
5 | import nl.martenm.servertutorialplus.api.events.TutorialEndEvent;
6 | import nl.martenm.servertutorialplus.api.events.TutorialStartEvent;
7 | import nl.martenm.servertutorialplus.helpers.Messages;
8 | import nl.martenm.servertutorialplus.helpers.PluginUtils;
9 | import nl.martenm.servertutorialplus.helpers.dataholders.OldValuesPlayer;
10 | import nl.martenm.servertutorialplus.points.IPlayPoint;
11 | import org.bukkit.Bukkit;
12 | import org.bukkit.entity.Player;
13 | import org.bukkit.scheduler.BukkitRunnable;
14 |
15 | /**
16 | * The tutorial controller has all the logic to play a ServerTutorial.
17 | * It contains the main loop for the tutorial and it has methods like start() and cancel().
18 | * @author MartenM
19 | * @since 7-3-2017
20 | */
21 | public class TutorialController {
22 |
23 | private ServerTutorialPlus plugin;
24 | private Player player;
25 | private ServerTutorial serverTutorial;
26 | private boolean running = true;
27 |
28 | private int current = 0;
29 | private IPlayPoint playedPoint;
30 |
31 | private OldValuesPlayer oldValuesPlayer;
32 |
33 | public TutorialController(ServerTutorialPlus plugin, Player player, ServerTutorial serverTutorial){
34 | this.plugin = plugin;
35 | this.player = player;
36 | this.serverTutorial = serverTutorial;
37 | this.oldValuesPlayer = new OldValuesPlayer(player);
38 | }
39 |
40 | /**
41 | * Starts a tutorial.
42 | */
43 | public void start(){
44 | if(serverTutorial.getNeedsPermission()){
45 | if(!player.hasPermission("servertutorialplus.tutorials." + serverTutorial.getId())){
46 | stopController(true);
47 |
48 | player.sendMessage(Messages.noPermissionTutorial(plugin));
49 | return;
50 | }
51 | }
52 |
53 | //FIRE event!
54 | TutorialStartEvent event = new TutorialStartEvent(serverTutorial, player);
55 | plugin.getServer().getPluginManager().callEvent(event);
56 | if(event.isCancelled()){
57 | plugin.inTutorial.remove(player.getUniqueId());
58 | plugin.lockedPlayers.remove(player.getUniqueId());
59 | plugin.lockedViews.remove(player.getUniqueId());
60 | return;
61 | }
62 |
63 | if(serverTutorial.points.size() == 0){
64 | player.sendMessage(ChatColor.RED + "Tutorial cancelled. No points to be played.");
65 | cancel(true);
66 | return;
67 | }
68 |
69 | //Hide player from other players.
70 | if(serverTutorial.invisiblePlayer){
71 | plugin.getServer().getOnlinePlayers().stream().forEach(p -> p.hidePlayer(player));
72 | }
73 |
74 | plugin.inTutorial.put(player.getUniqueId(), this);
75 | serverTutorial.plays += 1;
76 |
77 | playedPoint = serverTutorial.points.get(current).createPlay(player, oldValuesPlayer, this::finishPoint);
78 | playedPoint.start();
79 | }
80 |
81 | /**
82 | * Cancels / stops the current the tutorial.
83 | * @param cancelled - Identifies if a tutorial was cancelled, or just stopped.
84 | */
85 | public void cancel(boolean cancelled) {
86 | cancel(cancelled, cancelled);
87 | }
88 |
89 | public void cancel(boolean cancelled, boolean originalLocation) {
90 | // Fire event!
91 | plugin.getServer().getPluginManager().callEvent(new TutorialEndEvent(serverTutorial, player, cancelled));
92 |
93 | stopController(cancelled);
94 | restorePlayer(originalLocation);
95 | }
96 |
97 | private void restorePlayer(boolean originalLocation){
98 | if(plugin.enabled) {
99 | // plugin.getServer().getScheduler().runTask(plugin, () -> {
100 | player.setFlySpeed(oldValuesPlayer.getOriginal_flySpeed());
101 | player.setWalkSpeed(oldValuesPlayer.getOriginal_walkSpeed());
102 | player.setAllowFlight(oldValuesPlayer.isAllowFlight());
103 | player.setFlying(oldValuesPlayer.getFlying());
104 | player.setGameMode(oldValuesPlayer.getGamemode());
105 | if (originalLocation) {
106 | player.teleport(oldValuesPlayer.getLoc());
107 | }
108 | // });
109 | }
110 | }
111 |
112 | private void stopController(boolean cancelled){
113 | if(cancelled){
114 | if(playedPoint != null) {
115 | playedPoint.stop();
116 | }
117 | }
118 |
119 | //Show player again
120 | if (serverTutorial.invisiblePlayer && plugin.enabled) {
121 | new BukkitRunnable() {
122 | @Override
123 | public void run() {
124 | plugin.getServer().getOnlinePlayers().stream().forEach(p -> p.showPlayer(player));
125 | }
126 | }.runTask(plugin);
127 | }
128 |
129 | plugin.inTutorial.remove(player.getUniqueId());
130 | plugin.lockedPlayers.remove(player.getUniqueId());
131 | plugin.lockedViews.remove(player.getUniqueId());
132 | running = false;
133 | }
134 |
135 | private void finishPoint(){
136 | if(current == serverTutorial.points.size() - 1){
137 | //Tutorial has been finished!
138 | finish();
139 | } else{
140 | current++;
141 | playedPoint = serverTutorial.points.get(current).createPlay(player, oldValuesPlayer, this::finishPoint);
142 | playedPoint.start();
143 | }
144 | }
145 |
146 | /**
147 | * Used to execute code that should only be executed if the tutorial has been fairly completed.
148 | */
149 | public void finish(){
150 | //Cancel tutorial to make everything stop and set back old values.
151 | cancel(false);
152 |
153 | //Run additional commands for (first) completion
154 | new BukkitRunnable(){
155 | @Override
156 | public void run() {
157 | boolean playedBefore = plugin.getDataSource().hasPlayedTutorial(player.getUniqueId(), serverTutorial.getId());
158 |
159 | if(!playedBefore) {
160 | //HAS NOT PLAYED THIS TUTORIAL BEFORE!
161 | // If query is return true (succes) make played before false to give rewards.
162 | playedBefore = !plugin.getDataSource().addPlayedTutorial(player.getUniqueId(), serverTutorial.getId());
163 | }
164 |
165 | final boolean result = playedBefore;
166 | new BukkitRunnable(){
167 | @Override
168 | public void run() {
169 | giveRewards(result);
170 | }
171 | }.runTask(plugin);
172 | }
173 | }.runTaskAsynchronously(plugin);
174 | }
175 |
176 | /**
177 | * Executes the commands that are used when a tutorial has been finished.
178 | * Executes as fast as the last point has been played.
179 | * @param playedBefore True if the player does the tutorial for the first time.
180 | */
181 | public void giveRewards(boolean playedBefore){
182 | if(!playedBefore) {
183 | for (String command : serverTutorial.getRewards()) {
184 | Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), PluginUtils.replaceVariables(plugin.placeholderAPI, player, command));
185 | }
186 | }
187 | }
188 |
189 | /**
190 | * Gets the player associated with this TutorialController.
191 | * @return Player
192 | */
193 | public Player getPlayer(){
194 | return this.player;
195 | }
196 |
197 | /**
198 | * Gets the old values for a player, used to restore the players state before starting the tutorial.
199 | * @return Old values of a player.
200 | */
201 | public OldValuesPlayer getOldValuesPlayer(){
202 | return oldValuesPlayer;
203 | }
204 |
205 | /**
206 | * Gets the tutorial this controller is playing.
207 | * @return Server Tutorial.
208 | */
209 | public ServerTutorial getTutorial(){
210 | return serverTutorial;
211 | }
212 |
213 | /**
214 | * Gets whether the tutorial is being played.
215 | * @return Boolean that identifies if the tutorial controller is currently running a tutorial.
216 | */
217 | public boolean isRunning(){
218 | return this.running;
219 | }
220 |
221 | /**
222 | * Get which point are beeing playing
223 | * @return Integer that represent point index of the current point
224 | */
225 | public Integer getCurrentPoint() {
226 | return current;
227 | }
228 | }
229 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/objects/TutorialEntitySelector.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.objects;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.language.Lang;
5 | import org.bukkit.entity.*;
6 | import org.bukkit.event.player.PlayerInteractEntityEvent;
7 |
8 | /**
9 | * This object is used to hold certain data when a player is trying to bind an entity as NPC.
10 | * @author MartenM
11 | */
12 | public class TutorialEntitySelector {
13 |
14 | private Player player;
15 | private String npcId;
16 | private ServerTutorial tutorial;
17 |
18 | public TutorialEntitySelector(Player player, ServerTutorial tutorial, String npcId){
19 | this.player = player;
20 | this.npcId = npcId;
21 | this.tutorial = tutorial;
22 | }
23 |
24 | public Player getPlayer() {
25 | return player;
26 | }
27 |
28 | public String getNpcId() {
29 | return npcId;
30 | }
31 |
32 | public ServerTutorial getTutorial() {
33 | return tutorial;
34 | }
35 |
36 | public void create(ServerTutorialPlus plugin, PlayerInteractEntityEvent event){
37 |
38 | if(!(event.getRightClicked() instanceof LivingEntity)){
39 | player.sendMessage(Lang.NPC_INVALID_ENTITY.toString());
40 | return;
41 | }
42 |
43 | if(event.getRightClicked() instanceof HumanEntity){
44 | HumanEntity humanEntity = (HumanEntity) event.getRightClicked();
45 |
46 | Player target = plugin.getServer().getPlayer(event.getRightClicked().getUniqueId());
47 | if(target != null){
48 | player.sendMessage(Lang.NPC_PLAYER_SELECTED.toString());
49 | return;
50 | }
51 | }
52 |
53 | LivingEntity npc = (LivingEntity) event.getRightClicked();
54 | npc.setAI(false);
55 | npc.setCanPickupItems(false);
56 | npc.setGravity(false);
57 | npc.setCollidable(false);
58 |
59 | plugin.getNpcManager().createNPC(npc, npc.getLocation(), npcId, tutorial.getId());
60 | plugin.selectingNpc.remove(player.getUniqueId());
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/objects/TutorialSign.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.objects;
2 |
3 | import org.bukkit.block.Block;
4 |
5 | /**
6 | * Represents a tutorial sign.
7 | * Created by Marten on 10-3-2017.
8 | */
9 | public class TutorialSign {
10 |
11 | public Block block;
12 | public String ServerTutorialId;
13 |
14 | public TutorialSign(Block block, String serverTutorialId){
15 | this.block = block;
16 | this.ServerTutorialId = serverTutorialId;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/IPlayPoint.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points;
2 |
3 | /**
4 | * Play point interface.
5 | * @author MartenM
6 | * @since 22-11-2017.
7 | */
8 | public interface IPlayPoint{
9 |
10 | void start();
11 |
12 | void stop();
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/IPointCallBack.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points;
2 |
3 | /**
4 | * Point callback. Parsed to the points to give them the ability to finish the point.
5 | * The ServerTutorialController will handle this and start the next point.
6 | * @author MartenM
7 | * @since 23-11-2017.
8 | */
9 | public interface IPointCallBack {
10 | void finish();
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/PointType.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points;
2 |
3 | /**
4 | * Enum for all the point types.
5 | * @author MartenM
6 | * @since 24-11-2017.
7 | */
8 | //TODO: Make it so that points are identified by an type String so other people could possible create addons (as seperate points).
9 | public enum PointType {
10 | TIMED,
11 | CHECKPOINT,
12 | CLICK_BLOCK,
13 | COMMAND,
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/custom/CommandPoint.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.custom;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.helpers.dataholders.OldValuesPlayer;
5 | import nl.martenm.servertutorialplus.points.IPlayPoint;
6 | import nl.martenm.servertutorialplus.points.IPointCallBack;
7 | import nl.martenm.servertutorialplus.points.PointType;
8 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
9 | import org.bukkit.Location;
10 | import org.bukkit.entity.Player;
11 |
12 | import java.util.Map;
13 | import java.util.UUID;
14 | import java.util.WeakHashMap;
15 |
16 | /**
17 | * A point that is finished when the command /st next is used.
18 | * @author MartenM
19 | * @since 22-6-2018.
20 | */
21 | public class CommandPoint extends ServerTutorialPoint {
22 |
23 | private static Map waiting = new WeakHashMap<>();
24 |
25 | public CommandPoint(ServerTutorialPlus plugin, Location loc) {
26 | super(plugin, loc, PointType.COMMAND);
27 | }
28 |
29 | @Override
30 | public IPlayPoint createPlay(Player player, OldValuesPlayer oldValuesPlayer, IPointCallBack callBack) {
31 | return new IPlayPoint() {
32 | @Override
33 | public void start() {
34 | waiting.put(player.getUniqueId(), callBack);
35 | playDefault(player, oldValuesPlayer, true);
36 | }
37 |
38 | @Override
39 | public void stop() {
40 | waiting.remove(player.getUniqueId(), callBack);
41 | }
42 | };
43 | }
44 |
45 | public static void handle(UUID uuid) {
46 | IPointCallBack callBack = waiting.get(uuid);
47 | if(callBack != null) {
48 | callBack.finish();
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/custom/TimedPoint.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.custom;
2 |
3 | import nl.martenm.servertutorialplus.ServerTutorialPlus;
4 | import nl.martenm.servertutorialplus.points.PointType;
5 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
6 | import org.bukkit.Location;
7 |
8 | /**
9 | * @author MartenM
10 | * @since 22-11-2017.
11 | */
12 | public class TimedPoint extends ServerTutorialPoint {
13 |
14 | public TimedPoint(ServerTutorialPlus plugin, Location loc) {
15 | super(plugin, loc, PointType.TIMED);
16 | }
17 |
18 | //Timed point is basically just a default point without additions.
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/editor/IPointArg.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.editor;
2 |
3 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
4 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
5 | import org.bukkit.command.CommandSender;
6 |
7 | /**
8 | * @author MartenM
9 | * @since 29-11-2017.
10 | */
11 | public interface IPointArg {
12 |
13 | boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, CommandSender sender, String[] args);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/editor/PointArg.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.editor;
2 |
3 | import nl.martenm.servertutorialplus.points.editor.IPointArg;
4 |
5 | /**
6 | * @author MartenM
7 | * @since 29-11-2017.
8 | */
9 | public abstract class PointArg implements IPointArg {
10 |
11 | private String name;
12 |
13 | private String[] aliases;
14 |
15 | public PointArg(String name){
16 | this.name = name;
17 | this.aliases = new String[] {};
18 | }
19 |
20 | public PointArg(String name, String[] aliases){
21 | this.name = name;
22 | this.aliases = aliases;
23 | }
24 |
25 | public boolean isAlias(String string){
26 | for(String alias : aliases){
27 | if(string.equalsIgnoreCase(alias)){
28 | return true;
29 | }
30 | }
31 | return false;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/editor/PointEditor.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.editor;
2 |
3 | import nl.martenm.servertutorialplus.language.Lang;
4 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
5 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
6 | import org.bukkit.command.CommandSender;
7 |
8 | import java.util.ArrayList;
9 | import java.util.Arrays;
10 | import java.util.List;
11 |
12 | /**
13 | * @author MartenM
14 | * @since 29-11-2017.
15 | */
16 | public class PointEditor {
17 |
18 | private List arguments;
19 |
20 | private PointEditor(){
21 | arguments = new ArrayList<>();
22 | }
23 |
24 | public boolean execute(ServerTutorial tutorial, ServerTutorialPoint point, CommandSender sender, String[] args){
25 |
26 | for(PointArg argument : arguments) {
27 | if (argument.getName().equalsIgnoreCase(args[2]) || argument.isAlias(args[2])) {
28 |
29 | String[] editorArgs = Arrays.copyOfRange(args, 3, args.length);
30 | if(argument.run(tutorial, point, sender, editorArgs)){
31 | sender.sendMessage(Lang.SETTING_EDITED.toString().replace("%setting%", argument.getName()));
32 | return true;
33 | } else{
34 | return false;
35 | }
36 | }
37 | }
38 |
39 | String possible = "";
40 | for (PointArg argument : arguments) {
41 | possible += argument.getName() + ", ";
42 | }
43 | possible = point.getArgsString();
44 |
45 | sender.sendMessage(Lang.UNKOWN_ARGUMENT + possible);
46 | return false;
47 | }
48 |
49 | public static PointEditor getPointeditor(ServerTutorialPoint point){
50 | PointEditor editor = new PointEditor();
51 | editor.arguments.addAll(point.getArgs());
52 |
53 |
54 | return editor;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/editor/args/ActionbarArg.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.editor.args;
2 |
3 | import nl.martenm.servertutorialplus.language.Lang;
4 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
5 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
6 | import nl.martenm.servertutorialplus.points.editor.PointArg;
7 | import org.apache.commons.lang3.StringUtils;
8 | import org.bukkit.command.CommandSender;
9 |
10 | /**
11 | * @author MartenM
12 | * @since 29-11-2017.
13 | */
14 | public class ActionbarArg extends PointArg {
15 |
16 | public ActionbarArg() {
17 | super("actionbar");
18 | }
19 |
20 | @Override
21 | public boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, CommandSender sender, String[] args) {
22 | if(args.length < 1){
23 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint actionbar ");
24 | return false;
25 | }
26 |
27 | switch (args[0]) {
28 | case "clear":
29 | point.setMessage_actionBar(null);
30 | break;
31 | case "set":
32 | if (args.length < 2) {
33 | sender.sendMessage(Lang.ERROR_ATLEAST_ONE_WORD.toString());
34 | return false;
35 | }
36 |
37 | String message = StringUtils.join(args, ' ', 1, args.length);
38 | point.setMessage_actionBar(message);
39 | break;
40 |
41 | default:
42 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint actionbar ");
43 | return false;
44 | }
45 | return true;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/editor/args/CommandsArg.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.editor.args;
2 |
3 | import nl.martenm.servertutorialplus.language.Lang;
4 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
5 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
6 | import nl.martenm.servertutorialplus.points.editor.PointArg;
7 | import net.md_5.bungee.api.ChatColor;
8 | import org.apache.commons.lang3.StringUtils;
9 | import org.bukkit.command.CommandSender;
10 |
11 | /**
12 | * @author MartenM
13 | * @since 29-11-2017.
14 | */
15 | public class CommandsArg extends PointArg {
16 |
17 | public CommandsArg() {
18 | super("commands");
19 | }
20 |
21 | @Override
22 | public boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, CommandSender sender, String[] args) {
23 |
24 | if(args.length < 1){
25 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT.toString() + "/st editpoint commands ");
26 | return false;
27 | }
28 |
29 | switch (args[0]) {
30 | case "clear":
31 | point.getCommands().clear();
32 | break;
33 |
34 | case "add":
35 | if (args.length < 2) {
36 | sender.sendMessage(Lang.ERROR_ATLEAST_ONE_WORD.toString());
37 | return false;
38 | }
39 |
40 | String message = StringUtils.join(args, ' ', 1, args.length);
41 | point.getCommands().add(message);
42 | break;
43 |
44 | case "remove":
45 | if (args.length < 2) {
46 | sender.sendMessage(Lang.ERROR_INVALID_INDEX.toString());
47 | return false;
48 | }
49 |
50 | try {
51 | point.getCommands().remove(Integer.parseInt(args[1]) - 1);
52 | } catch (NumberFormatException ex) {
53 | sender.sendMessage(Lang.ERROR_INVALID_NUMBNER.toString());
54 | return false;
55 | } catch (IndexOutOfBoundsException ex) {
56 | sender.sendMessage(Lang.ERROR_NOTEXISTING_INDEX.toString());
57 | return false;
58 | }
59 | break;
60 |
61 | case "list":
62 | sender.sendMessage(ChatColor.GRAY + "[ " + ChatColor.YELLOW + "Commands");
63 | for (int i = 0; i < point.getCommands().size(); i++) {
64 | sender.sendMessage(ChatColor.GRAY + "[ " + ChatColor.GREEN + (i + 1) + ChatColor.YELLOW + " " + point.getCommands().get(i));
65 | }
66 | return false;
67 |
68 | default:
69 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint commands ");
70 | return false;
71 | }
72 | return true;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/editor/args/FireworkArg.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.editor.args;
2 |
3 | import nl.martenm.servertutorialplus.helpers.dataholders.FireWorkInfo;
4 | import nl.martenm.servertutorialplus.language.Lang;
5 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
6 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
7 | import nl.martenm.servertutorialplus.points.editor.PointArg;
8 | import org.bukkit.Material;
9 | import org.bukkit.command.CommandSender;
10 | import org.bukkit.entity.Player;
11 | import org.bukkit.inventory.ItemStack;
12 | import org.bukkit.inventory.meta.FireworkMeta;
13 |
14 | /**
15 | * @author MartenM
16 | * @since 29-11-2017.
17 | */
18 | public class FireworkArg extends PointArg {
19 |
20 | public FireworkArg() {
21 | super("firework");
22 | }
23 |
24 | @Override
25 | public boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, CommandSender sender, String[] args) {
26 |
27 | if(args.length < 1){
28 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint firework ");
29 | return false;
30 | }
31 |
32 | switch (args[0]){
33 | case "clear":
34 | point.setFireworks(null);
35 | break;
36 |
37 | case "remove":
38 | if(!(sender instanceof Player)){
39 | sender.sendMessage(Lang.PLAYER_ONLY_COMMAND.toString());
40 | return false;
41 | }
42 |
43 | if(args.length > 1){
44 | sender.sendMessage(Lang.FIREWORK_REMOVE_INFO.toString());
45 | return false;
46 | }
47 |
48 | Player player = (Player) sender;
49 |
50 | FireWorkInfo fw = null;
51 | double distance = 1000;
52 |
53 | for(FireWorkInfo info : point.getFireworks()){
54 | if(info.getLoc().distance(player.getLocation()) < distance){
55 | fw = info;
56 | distance = info.getLoc().distance(player.getLocation());
57 | }
58 | }
59 |
60 | if(fw == null){
61 | sender.sendMessage(Lang.FIREWORK_REMOVE_FAILED.toString());
62 | return false;
63 | }
64 |
65 |
66 | point.getFireworks().remove(fw);
67 | break;
68 |
69 | case "add":
70 | if(!(sender instanceof Player)){
71 | sender.sendMessage(Lang.PLAYER_ONLY_COMMAND.toString());
72 | return false;
73 | }
74 |
75 | player = (Player) sender;
76 | if(player.getInventory().getItemInMainHand().getType() == Material.FIREWORK_ROCKET){
77 | ItemStack firework = player.getInventory().getItemInMainHand();
78 |
79 | if(!(firework.getItemMeta() instanceof FireworkMeta)){
80 | sender.sendMessage(Lang.FIREWORK_ADD_WRONGUSAGE.toString());
81 | return false;
82 | }
83 |
84 | FireworkMeta fireworkMeta = (FireworkMeta) firework.getItemMeta();
85 | point.getFireworks().add(new FireWorkInfo(player.getLocation(), fireworkMeta));
86 | }
87 | else{
88 | sender.sendMessage(Lang.FIREWORK_ADD_WRONGUSAGE.toString());
89 | return false;
90 | }
91 | break;
92 |
93 | default:
94 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint firework ");
95 | return false;
96 | }
97 | return true;
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/editor/args/FlyArg.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.editor.args;
2 |
3 | import nl.martenm.servertutorialplus.language.Lang;
4 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
5 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
6 | import nl.martenm.servertutorialplus.points.editor.PointArg;
7 | import org.bukkit.command.CommandSender;
8 |
9 | /**
10 | * @author MartenM
11 | * @since 30-11-2017.
12 | */
13 | public class FlyArg extends PointArg {
14 |
15 |
16 | public FlyArg() {
17 | super("fly");
18 | }
19 |
20 | @Override
21 | public boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, CommandSender sender, String[] args) {
22 |
23 | if(args.length < 1){
24 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint fly ");
25 | return false;
26 | }
27 |
28 | try{
29 | point.setFlying(Boolean.parseBoolean(args[0]));
30 | } catch (Exception ex){
31 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint fly ");
32 | return false;
33 | }
34 | return true;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/editor/args/LocationArg.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.editor.args;
2 |
3 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
4 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
5 | import nl.martenm.servertutorialplus.points.editor.PointArg;
6 | import org.bukkit.command.CommandSender;
7 | import org.bukkit.entity.Player;
8 |
9 | /**
10 | * Argument to change the point location.
11 | * @author MartenM
12 | * @since 29-11-2017.
13 | */
14 | public class LocationArg extends PointArg {
15 |
16 | public LocationArg() {
17 | super("location");
18 | }
19 |
20 | @Override
21 | public boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, CommandSender sender, String[] args) {
22 |
23 | if(!(sender instanceof Player)){
24 | return false;
25 | }
26 |
27 | Player player = (Player) sender;
28 |
29 | point.setLoc(player.getLocation());
30 | return true;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/editor/args/LockPlayerArg.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.editor.args;
2 |
3 | import nl.martenm.servertutorialplus.language.Lang;
4 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
5 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
6 | import nl.martenm.servertutorialplus.points.editor.PointArg;
7 | import org.bukkit.command.CommandSender;
8 |
9 | /**
10 | * @author MartenM
11 | * @since 30-11-2017.
12 | */
13 | public class LockPlayerArg extends PointArg {
14 |
15 | public LockPlayerArg() {
16 | super("lockplayer");
17 | }
18 |
19 | @Override
20 | public boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, CommandSender sender, String[] args) {
21 |
22 | if(args.length < 1){
23 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint lockplayer ");
24 | return false;
25 | }
26 |
27 | try{
28 | point.setLockPlayer(Boolean.parseBoolean(args[0]));
29 | } catch (Exception ex){
30 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint lockplayer ");
31 | return false;
32 | }
33 | return true;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/editor/args/LockViewArg.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.editor.args;
2 |
3 | import nl.martenm.servertutorialplus.language.Lang;
4 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
5 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
6 | import nl.martenm.servertutorialplus.points.editor.PointArg;
7 | import org.bukkit.command.CommandSender;
8 |
9 | /**
10 | * @author MartenM
11 | * @since 30-11-2017.
12 | */
13 | public class LockViewArg extends PointArg {
14 |
15 | public LockViewArg() {
16 | super("lockview");
17 | }
18 |
19 | @Override
20 | public boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, CommandSender sender, String[] args) {
21 |
22 | if(args.length < 1){
23 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint lockview ");
24 | return false;
25 | }
26 |
27 | try{
28 | point.setLockView(Boolean.parseBoolean(args[0]));
29 | } catch (Exception ex){
30 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint lockview ");
31 | return false;
32 | }
33 | return true;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/editor/args/MessagesArg.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.editor.args;
2 |
3 | import nl.martenm.servertutorialplus.language.Lang;
4 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
5 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
6 | import nl.martenm.servertutorialplus.points.editor.PointArg;
7 | import net.md_5.bungee.api.ChatColor;
8 | import org.apache.commons.lang3.StringUtils;
9 | import org.bukkit.command.CommandSender;
10 |
11 | /**
12 | * @author MartenM
13 | * @since 29-11-2017.
14 | */
15 | public class MessagesArg extends PointArg {
16 |
17 | public MessagesArg() {
18 | super("messages");
19 | }
20 |
21 | @Override
22 | public boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, CommandSender sender, String[] args) {
23 |
24 | if(args.length < 1){
25 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint messages ");
26 | return false;
27 | }
28 |
29 | switch (args[0]) {
30 | case "clear":
31 | point.getMessage_chat().clear();
32 | break;
33 |
34 | case "add":
35 | if (args.length < 2) {
36 | sender.sendMessage(Lang.ERROR_ATLEAST_ONE_WORD.toString());
37 | return false;
38 | }
39 |
40 | String message = StringUtils.join(args, ' ', 1, args.length);
41 | point.getMessage_chat().add(message);
42 | break;
43 |
44 | case "remove":
45 | if (args.length < 2) {
46 | sender.sendMessage(Lang.ERROR_NO_INDEX.toString());
47 | return false;
48 | }
49 |
50 | try {
51 | point.getMessage_chat().remove(Integer.parseInt(args[1]) - 1);
52 | } catch (NumberFormatException ex) {
53 | sender.sendMessage(Lang.ERROR_INVALID_NUMBNER.toString());
54 | return false;
55 | } catch (IndexOutOfBoundsException ex) {
56 | sender.sendMessage(Lang.ERROR_NOTEXISTING_INDEX.toString());
57 | return false;
58 | }
59 | break;
60 |
61 | case "list":
62 | sender.sendMessage(ChatColor.GRAY + "[ " + ChatColor.YELLOW + "Messages");
63 | for (int i = 0; i < point.getMessage_chat().size(); i++) {
64 | sender.sendMessage(ChatColor.GRAY + "[ " + ChatColor.GREEN + (i + 1) + ChatColor.YELLOW + " " + ChatColor.translateAlternateColorCodes('&', point.getMessage_chat().get(i))
65 | );
66 | }
67 | return false;
68 |
69 | default:
70 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint messages ");
71 | return false;
72 |
73 | }
74 | return true;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/editor/args/PotionEffectArg.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.editor.args;
2 |
3 | import nl.martenm.servertutorialplus.language.Lang;
4 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
5 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
6 | import nl.martenm.servertutorialplus.points.editor.PointArg;
7 | import net.md_5.bungee.api.ChatColor;
8 | import org.bukkit.command.CommandSender;
9 | import org.bukkit.entity.Player;
10 | import org.bukkit.inventory.ItemStack;
11 | import org.bukkit.inventory.meta.PotionMeta;
12 | import org.bukkit.potion.PotionEffect;
13 | import org.bukkit.potion.PotionEffectType;
14 |
15 | /**
16 | * @author MartenM
17 | * @since 30-11-2017.
18 | */
19 | public class PotionEffectArg extends PointArg {
20 |
21 | public PotionEffectArg() {
22 | super("potion");
23 | }
24 |
25 | @Override
26 | public boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, CommandSender sender, String[] args) {
27 |
28 | if(args.length < 1){
29 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint potion ");
30 | return false;
31 | }
32 |
33 | switch (args[0]){
34 | case "clear":
35 | point.getPointionEffects().clear();
36 | break;
37 |
38 | case "list":
39 | sender.sendMessage(ChatColor.GRAY + "[ " + ChatColor.YELLOW + "Potion effects");
40 | for(int i = 0; i < point.getPointionEffects().size(); i++){
41 | PotionEffect effect = point.getPointionEffects().get(i);
42 | sender.sendMessage(ChatColor.GRAY + "[ " + ChatColor.GREEN + (i + 1) + ChatColor.YELLOW + " " + effect.getType().getName() + " Time:" + effect.getDuration());
43 | }
44 | break;
45 |
46 | case "remove":
47 | if (args.length < 2) {
48 | sender.sendMessage(Lang.ERROR_NO_INDEX.toString());
49 | return false;
50 | }
51 |
52 | try {
53 | point.getPointionEffects().remove(Integer.parseInt(args[1]) - 1);
54 | } catch (NumberFormatException ex) {
55 | sender.sendMessage(Lang.ERROR_INVALID_NUMBNER.toString());
56 | return false;
57 | } catch (IndexOutOfBoundsException ex) {
58 | sender.sendMessage(Lang.ERROR_NOTEXISTING_INDEX.toString());
59 | return false;
60 | }
61 | break;
62 |
63 | case "add":
64 | if(!(sender instanceof Player)){
65 | sender.sendMessage(Lang.PLAYER_ONLY_COMMAND.toString());
66 | return false;
67 | }
68 | Player player = (Player) sender;
69 | ItemStack inhand = player.getInventory().getItemInMainHand();
70 |
71 | int time;
72 | int amplifier = 1;
73 | boolean isAmbient = true;
74 | boolean hasParticles = false;
75 | PotionEffectType type = null;
76 |
77 | if(args.length == 4){
78 | try{
79 | type = PotionEffectType.getByName(args[1]);
80 | if(type == null){
81 | throw new Exception(Lang.ERROR_INVALID_EFFECT.toString());
82 | }
83 | } catch (Exception ex){
84 | player.sendMessage(Lang.ERROR_INVALID_EFFECT.toString());
85 | return false;
86 | }
87 | }
88 |
89 | if(args.length >= 2 + (type == null ? 0 : 1)){
90 | try {
91 | time = Integer.parseInt(args[1 + (type == null ? 0 : 1)]) * 20;
92 | player.sendMessage(Lang.POTIONEFFECT_TIME.toString()
93 | .replace("%ticks%", time + "")
94 | .replace("%seconds%", args[1 + (type == null ? 0 : 1)]));
95 | } catch (Exception ex){
96 | player.sendMessage(Lang.ERROR_INVALID_TIME.toString());
97 | return false;
98 | }
99 | } else{
100 | time = (int) point.getTime() * 20;
101 | player.sendMessage(Lang.POTIONEFFECT_NOTIME.toString());
102 | }
103 |
104 | if(args.length >= 3 + (type == null ? 0 : 1)){
105 | try {
106 | amplifier = Integer.parseInt(args[2 + (type == null ? 0 : 1)]);
107 | player.sendMessage(Lang.POTIONEFFECT_AMPLIFIER.toString().replace("%amp%", amplifier + ""));
108 | } catch (Exception ex){
109 | player.sendMessage(Lang.ERROR_INVALID_AMPLIFIER.toString());
110 | return false;
111 | }
112 | }
113 |
114 |
115 | if(type == null){
116 | if(inhand == null){
117 | player.sendMessage(Lang.POTIONEFFECT_WRONGUSAGE_1.toString());
118 | player.sendMessage(Lang.POTIONEFFECT_WRONGUSAGE_2.toString());
119 | return false;
120 | }
121 |
122 | if(!(inhand.getItemMeta() instanceof PotionMeta)){
123 | player.sendMessage(Lang.POTIONEFFECT_WRONGUSAGE_1.toString());
124 | player.sendMessage(Lang.POTIONEFFECT_WRONGUSAGE_2.toString());
125 | return false;
126 | }
127 |
128 | PotionMeta meta = (PotionMeta) inhand.getItemMeta();
129 | type = meta.getBasePotionData().getType().getEffectType();
130 | }
131 |
132 | point.getPointionEffects().add(new PotionEffect(type, time, amplifier, isAmbient, hasParticles));
133 | break;
134 | }
135 |
136 | return true;
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/editor/args/SoundArg.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.editor.args;
2 |
3 | import nl.martenm.servertutorialplus.helpers.dataholders.PlayerSound;
4 | import nl.martenm.servertutorialplus.language.Lang;
5 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
6 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
7 | import nl.martenm.servertutorialplus.points.editor.PointArg;
8 | import net.md_5.bungee.api.ChatColor;
9 | import org.bukkit.Sound;
10 | import org.bukkit.command.CommandSender;
11 |
12 | /**
13 | * @author MartenM
14 | * @since 29-11-2017.
15 | */
16 | public class SoundArg extends PointArg {
17 |
18 | public SoundArg() {
19 | super("sound");
20 | }
21 |
22 | @Override
23 | public boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, CommandSender sender, String[] args) {
24 | if(args.length < 1){
25 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint sound (Sound, volume, pitch");
26 | return false;
27 | }
28 |
29 | switch (args[0]) {
30 | case "clear":
31 | point.setSoundInfo(null);
32 | break;
33 | case "set":
34 | if (args.length < 4) {
35 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint sound (Sound, volume, pitch");
36 | return false;
37 | }
38 |
39 | Sound sound = null;
40 |
41 | try {
42 | // loc, sound, volume, pitch <-- I forget that all the damm time.
43 | sound = Sound.valueOf(args[1].toUpperCase());
44 | float volume = Float.parseFloat(args[2]);
45 | float pitch = Float.parseFloat(args[3]);
46 |
47 | PlayerSound soundInfo = new PlayerSound(sound, pitch, volume);
48 | point.setSoundInfo(soundInfo);
49 | } catch (IllegalArgumentException ex) {
50 | if(sound == null) {
51 | sender.sendMessage(ChatColor.RED + "Unknown enum type for SOUND. Did you mean this?");
52 | StringBuilder builder = new StringBuilder();
53 | for(Sound s : Sound.values()) {
54 | if(s.toString().contains(args[1].toUpperCase())) {
55 | builder.append(s.toString());
56 | builder.append(" ");
57 | }
58 | }
59 | sender.sendMessage(builder.toString());
60 | }
61 | else {
62 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint sound (Sound, volume, pitch");
63 | return false;
64 | }
65 | }
66 | catch (Exception ex) {
67 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint sound (Sound, volume, pitch");
68 | return false;
69 | }
70 | break;
71 |
72 | default:
73 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint sound (Sound, volume, pitch");
74 | return false;
75 | }
76 | return true;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/editor/args/TimeArg.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.editor.args;
2 |
3 | import nl.martenm.servertutorialplus.language.Lang;
4 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
5 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
6 | import nl.martenm.servertutorialplus.points.editor.PointArg;
7 | import org.bukkit.command.CommandSender;
8 |
9 | /**
10 | * @author MartenM
11 | * @since 30-11-2017.
12 | */
13 | public class TimeArg extends PointArg {
14 |
15 | public TimeArg() {
16 | super("time");
17 | }
18 |
19 | @Override
20 | public boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, CommandSender sender, String[] args) {
21 |
22 | if(args.length < 1){
23 | sender.sendMessage(Lang.TIME_CURRENT.toString().replace("%time%", point.getTime() + ""));
24 | return true;
25 | }
26 |
27 | try {
28 | point.setTime(Integer.parseInt(args[0]));
29 | } catch (NumberFormatException ex){
30 | sender.sendMessage(Lang.ERROR_INVALID_NUMBNER.toString());
31 | return false;
32 | }
33 |
34 | return true;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/points/editor/args/TitleArg.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.points.editor.args;
2 |
3 | import nl.martenm.servertutorialplus.helpers.dataholders.PlayerTitle;
4 | import nl.martenm.servertutorialplus.language.Lang;
5 | import nl.martenm.servertutorialplus.objects.ServerTutorial;
6 | import nl.martenm.servertutorialplus.points.ServerTutorialPoint;
7 | import nl.martenm.servertutorialplus.points.editor.PointArg;
8 | import net.md_5.bungee.api.ChatColor;
9 | import org.apache.commons.lang3.StringUtils;
10 | import org.bukkit.command.CommandSender;
11 |
12 | /**
13 | * @author MartenM
14 | * @since 29-11-2017.
15 | */
16 | public class TitleArg extends PointArg {
17 |
18 | public TitleArg() {
19 | super("title");
20 | }
21 |
22 | @Override
23 | public boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, CommandSender sender, String[] args) {
24 |
25 | if(args.length < 1){
26 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint title
");
27 | return false;
28 | }
29 |
30 | switch (args[0]) {
31 | case "reset":
32 | point.setTitleInfo(null);
33 | break;
34 |
35 | case "title":
36 | if (args.length < 2) {
37 | point.getTitleInfo().title = "";
38 | return true;
39 | }
40 |
41 | if(point.getTitleInfo() == null){
42 | point.setTitleInfo(new PlayerTitle());
43 | }
44 |
45 | String message = StringUtils.join(args, ' ', 1, args.length);
46 | point.getTitleInfo().title = message;
47 | break;
48 |
49 | case "subtitle":
50 | if (args.length < 2) {
51 | point.getTitleInfo().subtitle = "";
52 | return true;
53 | }
54 |
55 | if(point.getTitleInfo() == null){
56 | point.setTitleInfo(new PlayerTitle());
57 | }
58 |
59 | message = StringUtils.join(args, ' ', 1, args.length);
60 | point.getTitleInfo().subtitle = message;
61 | break;
62 |
63 | case "fadein":
64 | int time;
65 |
66 | if(point.getTitleInfo() == null){
67 | sender.sendMessage(Lang.TITLE_NOTITLE_SET.toString());
68 | return false;
69 | }
70 |
71 | if(args.length < 2){
72 | sender.sendMessage(Lang.TITLE_CURRENT.toString().replace("%type%", args[0]).replace("%ticks%", point.getTitleInfo().fadeIn + ""));
73 | return false;
74 | }
75 |
76 | try {
77 | time = Integer.parseInt(args[1]);
78 | } catch (NumberFormatException ex) {
79 | sender.sendMessage(Lang.ERROR_INVALID_TIME.toString());
80 | return false;
81 | }
82 |
83 | if(point.getTitleInfo() == null){
84 | point.setTitleInfo(new PlayerTitle());
85 | }
86 |
87 | point.getTitleInfo().fadeIn = time;
88 | break;
89 |
90 | case "fadeout":
91 | if(point.getTitleInfo() == null){
92 | sender.sendMessage(Lang.TITLE_NOTITLE_SET.toString());
93 | return false;
94 | }
95 |
96 | if(args.length < 2){
97 | sender.sendMessage(Lang.TITLE_CURRENT.toString().replace("%type%", args[0]).replace("%ticks%", point.getTitleInfo().fadeOut + ""));
98 | return false;
99 | }
100 |
101 | try {
102 | time = Integer.parseInt(args[1]);
103 | } catch (NumberFormatException ex) {
104 | sender.sendMessage(ChatColor.RED + "Invalid time.");
105 | return false;
106 | }
107 |
108 | if(point.getTitleInfo() == null){
109 | point.setTitleInfo(new PlayerTitle());
110 | }
111 |
112 | point.getTitleInfo().fadeOut = time;
113 | break;
114 |
115 | case "stay":
116 |
117 | if(point.getTitleInfo() == null){
118 | sender.sendMessage(Lang.TITLE_NOTITLE_SET.toString());
119 | return false;
120 | }
121 |
122 | if(args.length < 2){
123 | sender.sendMessage(Lang.TITLE_CURRENT.toString().replace("%type%", args[0]).replace("%ticks%", point.getTitleInfo().time + ""));
124 | return false;
125 | }
126 |
127 |
128 | try {
129 | time = Integer.parseInt(args[1]);
130 | } catch (NumberFormatException ex) {
131 | sender.sendMessage(Lang.ERROR_INVALID_TIME.toString());
132 | return false;
133 | }
134 |
135 | if(point.getTitleInfo() == null){
136 | point.setTitleInfo(new PlayerTitle());
137 | }
138 |
139 | point.getTitleInfo().time = time;
140 | break;
141 |
142 | default:
143 | sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint title
");
144 | return false;
145 | }
146 | return true;
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/reflection/IProtocol.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.reflection;
2 |
3 | import nl.martenm.servertutorialplus.helpers.Color;
4 | import org.bukkit.Location;
5 | import org.bukkit.entity.Player;
6 |
7 | /**
8 | * This class helps to provide support for multiple versions.
9 | * @author MartenM
10 | * @since 27-8-2018.
11 | */
12 | public interface IProtocol {
13 |
14 | void playRedstoneParticle(Player player, Location location, Color color);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/reflection/V1_13/Protocol_1_13_V1.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.reflection.V1_13;
2 |
3 | import nl.martenm.servertutorialplus.helpers.Color;
4 | import nl.martenm.servertutorialplus.reflection.IProtocol;
5 | import org.bukkit.Location;
6 | import org.bukkit.Particle;
7 | import org.bukkit.entity.Player;
8 |
9 | import java.lang.reflect.Constructor;
10 | import java.lang.reflect.InvocationTargetException;
11 |
12 | /**
13 | * @author MartenM
14 | * @since 27-8-2018.
15 | */
16 | public class Protocol_1_13_V1 implements IProtocol {
17 |
18 | private static Class> dustOptions;
19 | private static Constructor> dustConstructor;
20 |
21 | @Override
22 | public void playRedstoneParticle(Player player, Location location, Color color) {
23 | if(dustConstructor == null) {
24 | try {
25 | getClassesAndMethods();
26 | } catch (NoSuchMethodException e) {
27 | e.printStackTrace();
28 | } catch (ClassNotFoundException e) {
29 | e.printStackTrace();
30 | }
31 | }
32 |
33 | Object[] dustParam = {org.bukkit.Color.fromRGB(color.getRed(), color.getGreen(), color.getBlue()), 1};
34 |
35 | try {
36 | Object dust = dustConstructor.newInstance(dustParam);
37 | player.spawnParticle(Particle.REDSTONE, location, 1, dust);
38 | } catch (InstantiationException e) {
39 | e.printStackTrace();
40 | } catch (IllegalAccessException e) {
41 | e.printStackTrace();
42 | } catch (InvocationTargetException e) {
43 | e.printStackTrace();
44 | }
45 | }
46 |
47 | /*
48 | Get all the classes and constructors once.
49 | */
50 | private static void getClassesAndMethods() throws NoSuchMethodException, ClassNotFoundException {
51 | dustOptions = Class.forName("org.bukkit.Particle$DustOptions");
52 | dustConstructor = dustOptions.getConstructor(org.bukkit.Color.class, float.class);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/reflection/v1_12/Protocol_1_12.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.reflection.v1_12;
2 |
3 | import nl.martenm.servertutorialplus.helpers.Color;
4 | import nl.martenm.servertutorialplus.reflection.IProtocol;
5 | import org.bukkit.Location;
6 | import org.bukkit.Particle;
7 | import org.bukkit.entity.Player;
8 |
9 | /**
10 | * @author MartenM
11 | * @since 27-8-2018.
12 | */
13 | public class Protocol_1_12 implements IProtocol {
14 |
15 | /*
16 | This is the default. We will be using the 1.12 version of playing the redstone particle here.
17 |
18 | */
19 |
20 | @Override
21 | public void playRedstoneParticle(Player player, Location location, Color color) {
22 | player.spawnParticle(Particle.REDSTONE, location, 0, (double) color.getRed() / 255, (double) color.getGreen() / 255, (double) color.getBlue() / 255, 1);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/nl/martenm/servertutorialplus/reflection/v1_14/Protocol_1_14_V1.java:
--------------------------------------------------------------------------------
1 | package nl.martenm.servertutorialplus.reflection.v1_14;
2 |
3 | import nl.martenm.servertutorialplus.helpers.Color;
4 | import nl.martenm.servertutorialplus.reflection.IProtocol;
5 | import org.bukkit.Location;
6 | import org.bukkit.Particle;
7 | import org.bukkit.entity.Player;
8 |
9 | import java.lang.reflect.Constructor;
10 | import java.lang.reflect.InvocationTargetException;
11 |
12 | /**
13 | * @author MartenM
14 | * @since 27-8-2018.
15 | */
16 | public class Protocol_1_14_V1 implements IProtocol {
17 |
18 | private static Class> dustOptions;
19 | private static Constructor> dustConstructor;
20 |
21 | @Override
22 | public void playRedstoneParticle(Player player, Location location, Color color) {
23 | if(dustConstructor == null) {
24 | try {
25 | getClassesAndMethods();
26 | } catch (NoSuchMethodException e) {
27 | e.printStackTrace();
28 | } catch (ClassNotFoundException e) {
29 | e.printStackTrace();
30 | }
31 | }
32 |
33 | Object[] dustParam = {org.bukkit.Color.fromRGB(color.getRed(), color.getGreen(), color.getBlue()), 1};
34 |
35 | try {
36 | Object dust = dustConstructor.newInstance(dustParam);
37 | player.spawnParticle(Particle.REDSTONE, location, 1, dust);
38 | } catch (InstantiationException e) {
39 | e.printStackTrace();
40 | } catch (IllegalAccessException e) {
41 | e.printStackTrace();
42 | } catch (InvocationTargetException e) {
43 | e.printStackTrace();
44 | }
45 | }
46 |
47 | /*
48 | Get all the classes and constructors once.
49 | */
50 | private static void getClassesAndMethods() throws NoSuchMethodException, ClassNotFoundException {
51 | dustOptions = Class.forName("org.bukkit.Particle$DustOptions");
52 | dustConstructor = dustOptions.getConstructor(org.bukkit.Color.class, float.class);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/resources/config.yml:
--------------------------------------------------------------------------------
1 | # Server tutorial
2 | # by MartenM
3 | # For an example config with more explaining look at the spigot page!
4 | no permission command: "&cYou do not have permission to execute this command."
5 | no permission tutorial: "&cYou do not have enough permissions to play this tutorial."
6 | enable first join tutorial: false
7 | first join tutorial id: ""
8 |
9 | language: English
10 |
11 | # Settings for NPCs
12 | npc:
13 | # Whether the NPC should be removed if it is not found when starting the plugin.
14 | # Best to disable this when using Citizens plugin.
15 | remove-invalid: true
16 | # The time between the first attempt to scan for NPCs and the second time. (seconds)
17 | retry-time: 5
18 |
19 | # Blocked commands whitelist
20 | # These commands can still be used while in a tutorial, even if the tutorial is set to block commands.
21 | # Server tutorial commands are included by default to make sure you can still properly debug tutorials.
22 | # Use the command: servertutorial.tutorial.bypass to allow a user to use any commands while in the tutorial.
23 | command-whitelist:
24 | - w
25 | - msg
26 | - help
27 | - list
28 | - me
29 | - kittycannon #YES
30 |
31 |
32 | datasource:
33 | mysql:
34 | #Should we use MySql to store data?
35 | #If not: FlatFile option enabled.
36 | enabled: false
37 | username: root
38 | password: root
39 | host: localhost
40 | port: 3306
41 | database: minecraft
--------------------------------------------------------------------------------
/src/main/resources/plugin.yml:
--------------------------------------------------------------------------------
1 | main: nl.martenm.servertutorialplus.ServerTutorialPlus
2 | name: ServerTutorialPlus
3 | prefix: Server Tutorial Plus
4 | author: MartenM
5 | version: ${project.version}
6 | api-version: "1.20"
7 | description: "§6The plugin to guide players around your server using tutorials."
8 | softdepend: [PlaceholderAPI, Multiverse-Core, MultiWorld]
9 | commands:
10 | servertutorial:
11 | description: "All the servertutorial plus commands"
12 | aliases: [st]
13 |
14 | permissions:
15 | servertutorialplus.command.*:
16 | description: Allows you to use administrative ST+ commands.
17 | default: false
18 | children:
19 | servertutorialplus.command.help: true
20 | servertutorialplus.command.create: true
21 | servertutorialplus.command.remove: true
22 | servertutorialplus.command.addpoint: true
23 | servertutorialplus.command.removepoint: true
24 | servertutorialplus.command.play: true
25 | servertutorialplus.command.player: true
26 | servertutorialplus.command.quit: true
27 | servertutorialplus.command.playpoint: true
28 | servertutorialplus.command.setblock: true
29 | servertutorialplus.command.edit: true
30 | servertutorialplus.command.npc: true
31 | servertutorialplus.command.info: true
32 | servertutorialplus.command.reload: true
33 | servertutorialplus.command.save: true
34 | servertutorialplus.command.help:
35 | description: Allows you to view ST+ help.
36 | default: true
37 | servertutorialplus.command.create:
38 | description: Allows you to create ST+ tutorials.
39 | default: op
40 | servertutorialplus.command.remove:
41 | description: Allows you to remove ST+ tutorials.
42 | default: op
43 | servertutorialplus.command.addpoint:
44 | description: Allows you to add a point in an existing ST+ tutorial.
45 | default: op
46 | servertutorialplus.command.removepoint:
47 | description: Allows you to remove a point in an existing ST+ tutorial.
48 | default: op
49 | servertutorialplus.command.play:
50 | description: Allows you to play an existing ST+ tutorial.
51 | default: op
52 | servertutorialplus.command.player:
53 | description: Allows you view the ST+ stats of a player.
54 | default: op
55 | servertutorialplus.command.quit:
56 | description: Allows you to quit the current tutorial.
57 | default: true
58 | servertutorialplus.command.playpoint:
59 | description: Allows you to play a single point of an existing ST+ tutorial.
60 | default: op
61 | servertutorialplus.command.setblock:
62 | description: Allows you to set a block which will play an existing ST+ tutorial.
63 | default: op
64 | servertutorialplus.command.edit:
65 | description: Allows you to modify settings for an entire ST+ tutorial.
66 | default: op
67 | servertutorialplus.command.npc:
68 | description: Allows you to create, modify, and delete ST+ NPCs.
69 | default: op
70 | servertutorialplus.command.info:
71 | description: Allows you to list all ST+ tutorials, or info on a specific one.
72 | default: op
73 | servertutorialplus.command.reload:
74 | description: Allows you to reload the ST+ config, overwriting pending changes.
75 | default: op
76 | servertutorialplus.command.save:
77 | description: Allows you to overwrite the config with the current state.
78 | default: op
--------------------------------------------------------------------------------