lore = new ArrayList<>();
160 | for(String s : buttons.getStringList(prefix+bName+".lore")){
161 | lore.add(ChatColor.translateAlternateColorCodes('&', s));
162 | }
163 | XMaterial material = XMaterial.matchXMaterial(buttons.getString(prefix+bName+".material")).orElse(XMaterial.BARRIER);
164 | ItemStack item = null;
165 | if(material.parseMaterial().name().equalsIgnoreCase("SKULL_ITEM")||
166 | material.parseMaterial().name().equalsIgnoreCase("PLAYER_HEAD")){
167 | item = new ItemBuilder(material.parseMaterial())
168 | .name(ChatColor
169 | .translateAlternateColorCodes('&', buttons.getString(prefix + bName + ".displayName")))
170 | .lore(lore)
171 | .build();
172 | String skin = buttons.getString(prefix+bName+".skin");
173 | if (skin!=null && !skin.equals("")) {
174 | item = new ItemBuilder(SkullCreator.itemWithBase64(XMaterial.PLAYER_HEAD.parseItem(), skin))
175 | .name(ChatColor
176 | .translateAlternateColorCodes('&', buttons.getString(prefix + bName + ".displayName")))
177 | .lore(lore)
178 | .build();
179 | }
180 | }
181 | else {
182 | item = new ItemBuilder(material.parseMaterial())
183 | .name(ChatColor
184 | .translateAlternateColorCodes('&', buttons.getString(prefix + bName + ".displayName")))
185 | .lore(lore)
186 | .build();
187 | }
188 | NBTItem nbtItem = new NBTItem(item);
189 | nbtItem.setString("replay-addon-bw1058", buttons.getString(prefix+bName+".data"));
190 | item = nbtItem.getItem();
191 | Button button = new Button(item,bName,buttons.getInt(prefix+bName+".slot"));
192 | initializedButtons.put(bName, button);
193 | }
194 | }
195 |
196 |
197 | }
198 |
--------------------------------------------------------------------------------
/src/main/java/dev/mrflyn/replayaddon/versionutils/SkullCreator.java:
--------------------------------------------------------------------------------
1 | package dev.mrflyn.replayaddon.versionutils;
2 |
3 | import com.mojang.authlib.GameProfile;
4 | import com.mojang.authlib.properties.Property;
5 | import org.bukkit.Bukkit;
6 | import org.bukkit.Material;
7 | import org.bukkit.SkullType;
8 | import org.bukkit.block.Block;
9 | import org.bukkit.block.Skull;
10 | import org.bukkit.inventory.ItemStack;
11 | import org.bukkit.inventory.meta.SkullMeta;
12 |
13 | import java.lang.reflect.Field;
14 | import java.lang.reflect.InvocationTargetException;
15 | import java.lang.reflect.Method;
16 | import java.net.URI;
17 | import java.net.URISyntaxException;
18 | import java.util.Base64;
19 | import java.util.UUID;
20 |
21 | /**
22 | * A library for the Bukkit API to create player skulls
23 | * from names, base64 strings, and texture URLs.
24 | *
25 | * Does not use any NMS code, and should work across all versions.
26 | *
27 | * @author Dean B on 12/28/2016.
28 | */
29 | public class SkullCreator {
30 |
31 | private SkullCreator() {}
32 |
33 | private static boolean warningPosted = false;
34 |
35 | // some reflection stuff to be used when setting a skull's profile
36 | private static Field blockProfileField;
37 | private static Method metaSetProfileMethod;
38 | private static Field metaProfileField;
39 |
40 | /**
41 | * Creates a player skull, should work in both legacy and new Bukkit APIs.
42 | */
43 | public static ItemStack createSkull() {
44 | checkLegacy();
45 |
46 | try {
47 | return new ItemStack(Material.valueOf("PLAYER_HEAD"));
48 | } catch (IllegalArgumentException e) {
49 | return new ItemStack(Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
50 | }
51 | }
52 | /**
53 | * Creates a player skull item with the skin at a Mojang URL.
54 | *
55 | * @param url The Mojang URL.
56 | * @return The head of the Player.
57 | */
58 | public static ItemStack itemFromUrl(String url) {
59 | return itemWithUrl(createSkull(), url);
60 | }
61 |
62 | /**
63 | * Creates a player skull item with the skin based on a base64 string.
64 | *
65 | * @param base64 The Mojang URL.
66 | * @return The head of the Player.
67 | */
68 | public static ItemStack itemFromBase64(String base64) {
69 | return itemWithBase64(createSkull(), base64);
70 | }
71 |
72 |
73 | /**
74 | * Modifies a skull to use the skin at the given Mojang URL.
75 | *
76 | * @param item The item to apply the skin to. Must be a player skull.
77 | * @param url The URL of the Mojang skin.
78 | * @return The head associated with the URL.
79 | */
80 | public static ItemStack itemWithUrl(ItemStack item, String url) {
81 | notNull(item, "item");
82 | notNull(url, "url");
83 |
84 | return itemWithBase64(item, urlToBase64(url));
85 | }
86 |
87 | /**
88 | * Modifies a skull to use the skin based on the given base64 string.
89 | *
90 | * @param item The ItemStack to put the base64 onto. Must be a player skull.
91 | * @param base64 The base64 string containing the texture.
92 | * @return The head with a custom texture.
93 | */
94 | public static ItemStack itemWithBase64(ItemStack item, String base64) {
95 | notNull(item, "item");
96 | notNull(base64, "base64");
97 |
98 | if (!(item.getItemMeta() instanceof SkullMeta)) {
99 | return null;
100 | }
101 | SkullMeta meta = (SkullMeta) item.getItemMeta();
102 | mutateItemMeta(meta, base64);
103 | item.setItemMeta(meta);
104 |
105 | return item;
106 | }
107 |
108 | /**
109 | * Sets the block to a skull with the skin found at the provided mojang URL.
110 | *
111 | * @param block The block to set.
112 | * @param url The mojang URL to set it to use.
113 | */
114 | public static void blockWithUrl(Block block, String url) {
115 | notNull(block, "block");
116 | notNull(url, "url");
117 |
118 | blockWithBase64(block, urlToBase64(url));
119 | }
120 |
121 | /**
122 | * Sets the block to a skull with the skin for the base64 string.
123 | *
124 | * @param block The block to set.
125 | * @param base64 The base64 to set it to use.
126 | */
127 | public static void blockWithBase64(Block block, String base64) {
128 | notNull(block, "block");
129 | notNull(base64, "base64");
130 |
131 | setToSkull(block);
132 | Skull state = (Skull) block.getState();
133 | mutateBlockState(state, base64);
134 | state.update(false, false);
135 | }
136 |
137 | private static void setToSkull(Block block) {
138 | checkLegacy();
139 |
140 | try {
141 | block.setType(Material.valueOf("PLAYER_HEAD"), false);
142 | } catch (IllegalArgumentException e) {
143 | block.setType(Material.valueOf("SKULL"), false);
144 | Skull state = (Skull) block.getState();
145 | state.setSkullType(SkullType.PLAYER);
146 | state.update(false, false);
147 | }
148 | }
149 |
150 | private static void notNull(Object o, String name) {
151 | if (o == null) {
152 | throw new NullPointerException(name + " should not be null!");
153 | }
154 | }
155 |
156 | private static String urlToBase64(String url) {
157 |
158 | URI actualUrl;
159 | try {
160 | actualUrl = new URI(url);
161 | } catch (URISyntaxException e) {
162 | throw new RuntimeException(e);
163 | }
164 | String toEncode = "{\"textures\":{\"SKIN\":{\"url\":\"" + actualUrl.toString() + "\"}}}";
165 | return Base64.getEncoder().encodeToString(toEncode.getBytes());
166 | }
167 |
168 | private static GameProfile makeProfile(String b64) {
169 | // random uuid based on the b64 string
170 | UUID id = new UUID(
171 | b64.substring(b64.length() - 20).hashCode(),
172 | b64.substring(b64.length() - 10).hashCode()
173 | );
174 | GameProfile profile = new GameProfile(id, "Player");
175 | profile.getProperties().put("textures", new Property("textures", b64));
176 | return profile;
177 | }
178 |
179 | private static void mutateBlockState(Skull block, String b64) {
180 | try {
181 | if (blockProfileField == null) {
182 | blockProfileField = block.getClass().getDeclaredField("profile");
183 | blockProfileField.setAccessible(true);
184 | }
185 | blockProfileField.set(block, makeProfile(b64));
186 | } catch (NoSuchFieldException | IllegalAccessException e) {
187 | e.printStackTrace();
188 | }
189 | }
190 |
191 | private static void mutateItemMeta(SkullMeta meta, String b64) {
192 | try {
193 | if (metaSetProfileMethod == null) {
194 | metaSetProfileMethod = meta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
195 | metaSetProfileMethod.setAccessible(true);
196 | }
197 | metaSetProfileMethod.invoke(meta, makeProfile(b64));
198 | } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
199 | // if in an older API where there is no setProfile method,
200 | // we set the profile field directly.
201 | try {
202 | if (metaProfileField == null) {
203 | metaProfileField = meta.getClass().getDeclaredField("profile");
204 | metaProfileField.setAccessible(true);
205 | }
206 | metaProfileField.set(meta, makeProfile(b64));
207 |
208 | } catch (NoSuchFieldException | IllegalAccessException ex2) {
209 | ex2.printStackTrace();
210 | }
211 | }
212 | }
213 |
214 | // suppress warning since PLAYER_HEAD doesn't exist in 1.12.2,
215 | // but we expect this and catch the error at runtime.
216 | @SuppressWarnings("JavaReflectionMemberAccess")
217 | private static void checkLegacy() {
218 | try {
219 | // if both of these succeed, then we are running
220 | // in a legacy api, but on a modern (1.13+) server.
221 | Material.class.getDeclaredField("PLAYER_HEAD");
222 | Material.valueOf("SKULL");
223 |
224 | if (!warningPosted) {
225 | Bukkit.getLogger().warning("SKULLCREATOR API - Using the legacy bukkit API with 1.13+ bukkit versions is not supported!");
226 | warningPosted = true;
227 | }
228 | } catch (NoSuchFieldException | IllegalArgumentException ignored) {}
229 | }
230 | }
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/src/main/java/dev/mrflyn/replayaddon/guis/replaysessionguis/ViewerSettingsGUI.java:
--------------------------------------------------------------------------------
1 | package dev.mrflyn.replayaddon.guis.replaysessionguis;
2 |
3 | import de.tr7zw.changeme.nbtapi.NBTItem;
4 | import dev.mrflyn.replayaddon.advancedreplayhook.GameReplayHandler;
5 | import dev.mrflyn.replayaddon.guis.CustomReplaySessionSettings;
6 | import dev.mrflyn.replayaddon.ReplayAddonMain;
7 | import dev.mrflyn.replayaddon.spigui.SGMenu;
8 | import dev.mrflyn.replayaddon.spigui.buttons.SGButton;
9 | import dev.mrflyn.replayaddon.versionutils.ItemBuilder;
10 | import dev.mrflyn.replayaddon.versionutils.XMaterial;
11 | import org.bukkit.ChatColor;
12 | import org.bukkit.Material;
13 | import org.bukkit.entity.Player;
14 | import org.bukkit.inventory.ItemStack;
15 |
16 | public class ViewerSettingsGUI extends SGMenu {
17 | private final Player player;
18 | private final CustomReplaySessionSettings settings;
19 | public ViewerSettingsGUI(Player p, CustomReplaySessionSettings settings) {
20 | super(ReplayAddonMain.plugin,ReplayAddonMain.plugin.spiGUI, "Viewer Settings", 4, null);
21 | setAutomaticPaginationEnabled(false);
22 | this.player = p;
23 | this.settings = settings;
24 | setIcons();
25 | }
26 |
27 | private void setIcons(){
28 | //12,13,14,31
29 | ItemBuilder chatTimeline = new ItemBuilder(XMaterial.GRAY_DYE.parseItem())
30 | .name(ChatColor.RED + "Chat Timeline").lore(ChatColor.YELLOW + "Click to enable!");
31 | NBTItem nChatTimeLine = new NBTItem(chatTimeline.build());
32 | nChatTimeLine.setString("replay-addon", "disabled");
33 | SGButton iChatTimeline = new SGButton(nChatTimeLine.getItem())
34 | .withListener((e) ->
35 | {
36 | NBTItem ct = null;
37 | ItemStack item;
38 | if(!settings.isChatTimeline()){
39 | item = new ItemBuilder(XMaterial.LIME_DYE.parseItem())
40 | .name(ChatColor.GREEN + "Chat Timeline").lore(ChatColor.YELLOW + "Click to disable!").build();
41 | this.settings.setChatTimeline(true);
42 | ct = new NBTItem(item);
43 | ct.setString("replay-addon", "enabled");
44 | }else{
45 | item = new ItemBuilder(XMaterial.GRAY_DYE.parseItem())
46 | .name(ChatColor.RED + "Chat Timeline").lore(ChatColor.YELLOW + "Click to enable!").build();
47 | this.settings.setChatTimeline(false);
48 | ct = new NBTItem(item);
49 | ct.setString("replay-addon", "disabled");
50 | }
51 | getButton(12).setIcon(item);
52 | refreshInventory(e.getWhoClicked());
53 | });
54 | ItemBuilder showSpectators = new ItemBuilder(XMaterial.GRAY_DYE.parseItem())
55 | .name(ChatColor.RED + "Show Spectators").lore(ChatColor.YELLOW + "Click to enable!");
56 | NBTItem nShowSpectators = new NBTItem(showSpectators.build());
57 | nShowSpectators.setString("replay-addon", "disabled");
58 | SGButton iShowSpectators = new SGButton(nShowSpectators.getItem())
59 | .withListener((e) ->
60 | {
61 | NBTItem ct = null;
62 | ItemStack item;
63 | if (!settings.isShowSpectators()) {
64 | item = new ItemBuilder(XMaterial.LIME_DYE.parseItem())
65 | .name(ChatColor.GREEN + "Show Spectators").lore(ChatColor.YELLOW + "Click to disable!").build();
66 | this.settings.setShowSpectators(true);
67 | ct = new NBTItem(item);
68 | ct.setString("replay-addon", "enabled");
69 | } else {
70 | item = new ItemBuilder(XMaterial.GRAY_DYE.parseItem())
71 | .name(ChatColor.RED + "Show Spectators").lore(ChatColor.YELLOW + "Click to enable!").build();
72 | this.settings.setShowSpectators(false);
73 | ct = new NBTItem(item);
74 | ct.setString("replay-addon", "disabled");
75 | }
76 | getButton(13).setIcon(item);
77 | refreshInventory(e.getWhoClicked());
78 | });
79 | ItemBuilder flySpeed = new ItemBuilder(XMaterial.PAPER.parseItem())
80 | .name(ChatColor.RED + "Fly Speed")
81 | .lore(ChatColor.GREEN + "Currently Selected: "+ChatColor.GOLD+"1x",
82 | "",
83 | ChatColor.GRAY+"Click to set Fly Speed to "+ChatColor.GOLD+"2x.",
84 | "",
85 | ChatColor.YELLOW+"Click to cycle!"
86 | );
87 | NBTItem nFlySpeed = new NBTItem(flySpeed.build());
88 | nFlySpeed.setInteger("replay-addon", 1);
89 | this.settings.setFlySpeed(1);
90 | SGButton iFlySpeed = new SGButton(nFlySpeed.getItem())
91 | .withListener((e) ->
92 | {
93 | NBTItem ct = null;
94 | ItemStack item = null;
95 | float speed;
96 | if(this.settings.getFlySpeed()<5&&this.settings.getFlySpeed()>=1) {
97 | speed = this.settings.getFlySpeed() + 1;
98 | float nxtSpeed = this.settings.getFlySpeed()+2;
99 | if(nxtSpeed>5)nxtSpeed=1;
100 | item = new ItemBuilder(XMaterial.PAPER.parseItem())
101 | .name(ChatColor.RED + "Fly Speed")
102 | .lore(ChatColor.GREEN + "Currently Selected: "+ChatColor.GOLD+(int)speed+"x.",
103 | "",
104 | ChatColor.GRAY+"Click to set Fly Speed to "+ChatColor.GOLD+(int)nxtSpeed+"x.",
105 | "",
106 | ChatColor.YELLOW+"Click to cycle!"
107 | ).build();
108 | NBTItem item1= new NBTItem(item);
109 | item1.setFloat("replay-addon", speed);
110 | }
111 | else if(this.settings.getFlySpeed()==5){
112 | speed = 0.5F;
113 | item = new ItemBuilder(XMaterial.PAPER.parseItem())
114 | .name(ChatColor.RED + "Fly Speed")
115 | .lore(ChatColor.GREEN + "Currently Selected: "+ChatColor.GOLD+speed+"x.",
116 | "",
117 | ChatColor.GRAY+"Click to set Fly Speed to "+ChatColor.GOLD+"1x.",
118 | "",
119 | ChatColor.YELLOW+"Click to cycle!"
120 | ).build();
121 | NBTItem item1= new NBTItem(item);
122 | item1.setFloat("replay-addon", speed);
123 | }else if(this.settings.getFlySpeed()==0.5){
124 | speed = 1;
125 | item = new ItemBuilder(XMaterial.PAPER.parseItem())
126 | .name(ChatColor.RED + "Fly Speed")
127 | .lore(ChatColor.GREEN + "Currently Selected: "+ChatColor.GOLD+speed+"x.",
128 | "",
129 | ChatColor.GRAY+"Click to set Fly Speed to "+ChatColor.GOLD+"1x.",
130 | "",
131 | ChatColor.YELLOW+"Click to cycle!"
132 | ).build();
133 | NBTItem item1= new NBTItem(item);
134 | item1.setFloat("replay-addon", speed);
135 | }
136 | else {
137 | speed = 1;
138 | item = new ItemBuilder(XMaterial.PAPER.parseItem())
139 | .name(ChatColor.RED + "Fly Speed")
140 | .lore(ChatColor.GREEN + "Currently Selected: "+ChatColor.GOLD+speed+"x.",
141 | "",
142 | ChatColor.GRAY+"Click to set Fly Speed to "+ChatColor.GOLD+(speed+1)+"x.",
143 | "",
144 | ChatColor.YELLOW+"Click to cycle!"
145 | ).build();
146 | NBTItem item1= new NBTItem(item);
147 | item1.setFloat("replay-addon", speed);
148 | }
149 | this.settings.setFlySpeed(speed);
150 | getButton(14).setIcon(item);
151 | refreshInventory(e.getWhoClicked());
152 | });
153 | SGButton back= new SGButton(new ItemBuilder(Material.ARROW).name(ChatColor.GREEN+"Back to Main Menu.")
154 | .build())
155 | .withListener((e) -> {
156 | Player p = (Player) e.getWhoClicked();
157 | if (!GameReplayHandler.playingReplays.containsKey(p)) return;
158 | p.openInventory(MoreSettingsGUI.INSTANCE.getCachedInventory());
159 | });
160 | setButton(12, iChatTimeline);
161 | setButton(13, iShowSpectators);
162 | setButton(14, iFlySpeed);
163 | setButton(31, back);
164 | }
165 |
166 |
167 |
168 |
169 |
170 | }
171 |
--------------------------------------------------------------------------------
/src/main/java/dev/mrflyn/replayaddon/versionutils/Util.java:
--------------------------------------------------------------------------------
1 | package dev.mrflyn.replayaddon.versionutils;
2 |
3 | import com.comphenix.protocol.wrappers.WrappedGameProfile;
4 | import dev.mrflyn.replayaddon.ReplayAddonMain;
5 | import dev.mrflyn.replayaddon.advancedreplayhook.GameReplayCache;
6 | import dev.mrflyn.replayaddon.advancedreplayhook.PlayerInfo;
7 | import dev.mrflyn.replayaddon.configs.Messages;
8 | import me.jumper251.replay.replaysystem.replaying.Replayer;
9 | import me.jumper251.replay.replaysystem.replaying.ReplayingUtils;
10 | import net.md_5.bungee.api.chat.*;
11 | import org.apache.commons.lang.StringUtils;
12 | import org.bukkit.Bukkit;
13 | import org.bukkit.ChatColor;
14 | import org.bukkit.Location;
15 | import org.bukkit.entity.Player;
16 | import org.bukkit.entity.WitherSkull;
17 | import org.bukkit.inventory.ItemStack;
18 |
19 | import java.time.LocalDateTime;
20 | import java.time.format.DateTimeFormatter;
21 | import java.util.HashMap;
22 | import java.util.List;
23 | import java.util.Random;
24 | import java.util.concurrent.TimeUnit;
25 | import java.util.logging.Level;
26 | import java.util.stream.Collectors;
27 |
28 | import static dev.mrflyn.replayaddon.ReplayAddonMain.plugin;
29 |
30 | public class Util {
31 | static Random random = new Random();
32 |
33 | public static String generateID(String mapName, String gameMode, String date){
34 | return mapName+"-"+gameMode+"-"+date;
35 | }
36 |
37 | public static String getDate(){
38 | DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss");
39 | LocalDateTime now = LocalDateTime.now();
40 | return (dtf.format(now));
41 | }
42 |
43 |
44 | public static String formattedTime(long secs){
45 | long MM = TimeUnit.SECONDS.toMinutes(secs) % 60;
46 | long SS = TimeUnit.SECONDS.toSeconds(secs) % 60;
47 | return String.format("%02d:%02d", MM, SS);
48 | }
49 |
50 | public static String colorize(String s){
51 | return ChatColor.translateAlternateColorCodes('&', s);
52 | }
53 |
54 | public static void log(T msg){
55 | ReplayAddonMain.plugin.getLogger().log(Level.INFO, msg.toString());
56 | }
57 |
58 | public static void error(T msg) {
59 | ReplayAddonMain.plugin.getLogger().log(Level.SEVERE, msg.toString());
60 | }
61 |
62 | public static void debug(T msg) {
63 | if(ReplayAddonMain.plugin.mainConfig.getBoolean("debug")) {
64 | ReplayAddonMain.plugin.getLogger().log(Level.INFO, "[DEBUG]"+msg.toString());
65 | }
66 | }
67 |
68 | public static void setTime(Replayer replayer, int secs) {
69 | boolean isPaused = replayer.isPaused();
70 | replayer.getUtils().jumpTo(secs);
71 | replayer.setPaused(isPaused);
72 | }
73 |
74 | public static String translateLang(Messages m, Player p){
75 | // Util.debug(plugin.playerLang.toString());
76 | // Util.debug(plugin.allLanguages.toString());
77 | return plugin.playerLang.get(p.getUniqueId()).getCurrent(m, true);
78 | }
79 |
80 | public static List translateLangList(Messages m, Player p) {
81 | // Util.debug(plugin.playerLang.toString());
82 | // Util.debug(plugin.allLanguages.toString());
83 | return plugin.playerLang.get(p.getUniqueId()).getCurrentList(m);
84 | }
85 |
86 | public static Location lookAt(Location loc, Location lookat) {
87 | //Clone the loc to prevent applied changes to the input loc
88 | loc = loc.clone();
89 |
90 | // Values of change in distance (make it relative)
91 | double dx = lookat.getX() - loc.getX();
92 | double dy = lookat.getY() - loc.getY();
93 | double dz = lookat.getZ() - loc.getZ();
94 |
95 | // Set yaw
96 | if (dx != 0) {
97 | // Set yaw start value based on dx
98 | if (dx < 0) {
99 | loc.setYaw((float) (1.5 * Math.PI));
100 | } else {
101 | loc.setYaw((float) (0.5 * Math.PI));
102 | }
103 | loc.setYaw((float) loc.getYaw() - (float) Math.atan(dz / dx));
104 | } else if (dz < 0) {
105 | loc.setYaw((float) Math.PI);
106 | }
107 |
108 | // Get the distance from dx/dz
109 | double dxz = Math.sqrt(Math.pow(dx, 2) + Math.pow(dz, 2));
110 |
111 | // Set pitch
112 | loc.setPitch((float) -Math.atan(dy / dxz));
113 |
114 | // Set values, convert to degrees (invert the yaw since Bukkit uses a different yaw dimension format)
115 | loc.setYaw(-loc.getYaw() * 180f / (float) Math.PI);
116 | loc.setPitch(loc.getPitch() * 180f / (float) Math.PI);
117 |
118 | return loc;
119 | }
120 |
121 | public static BaseComponent[] getChatTimeLine(Player watcher,int totalBoxes, int totalDuration, double seperation, int currentTime,
122 | HashMap> deathTimes){
123 | // ComponentBuilder lines = new ComponentBuilder(StringUtils.repeat(" ", "\n", 99));
124 | ComponentBuilder component = new ComponentBuilder(StringUtils.repeat(" ", "\n", 99)+
125 | Util.translateLang(Messages.CHAT_TIMELINE_START, watcher));
126 | double boxTime = 0.0;
127 | for(int i = 0; itotalDuration)break;
129 | StringBuilder hoverTxt = new StringBuilder(ChatColor.GREEN + formattedTime(Math.round(Math.ceil(boxTime))));
130 | StringBuilder box = new StringBuilder();
131 | boolean deathBOX = false;
132 | int death = 0;
133 | for(int dT : deathTimes.keySet()){
134 | deathBOX = boxTime==dT||(boxTimedT);
135 | death = dT;
136 | }
137 | if(deathBOX){
138 | hoverTxt.append("\n").append(ChatColor.RED).append("Died!");
139 | for(String s : deathTimes.get(death)){
140 | hoverTxt.append("\n").append(ChatColor.WHITE).append(s).append(ChatColor.GRAY).append(" [")
141 | .append(ChatColor.GREEN).append(formattedTime(death)).append(ChatColor.GRAY).append("]");
142 | }
143 | box.append(Util.translateLang(Messages.CHAT_TIMELINE_DEATH_SYM,watcher));
144 | }
145 | else if(boxTime<=currentTime||currentTime+seperation>totalDuration){
146 | box.append(Util.translateLang(Messages.CHAT_TIMELINE_CURRENT_SYM,watcher));
147 | }
148 | else {
149 | box.append(Util.translateLang(Messages.CHAT_TIMELINE_SYM,watcher));
150 | }
151 | component = component.append(i==totalBoxes-1?StringUtils.stripEnd(box.toString(), " "):box.toString());
152 | ComponentBuilder hover = new ComponentBuilder(hoverTxt.toString());
153 | component = component.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover.create()))
154 | .event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/rp jumpTo "+Math.round(Math.ceil(boxTime))));
155 |
156 | boxTime = boxTime+seperation;
157 | }
158 | component.append(Util.translateLang(Messages.CHAT_TIMELINE_END, watcher));
159 | return component.create();
160 | }
161 |
162 | public static String parsePlayerInfoPlaceholders(String s, PlayerInfo info){
163 | //{tabPrefix}{playerName}{tabSuffix}
164 | return s.replace("{tabPrefix}", info.getTabPrefix()).replace("{tabSuffix}", info.getTabSuffix())
165 | .replace("{tagPrefix}", info.getTabPrefix()).replace("{tagSuffix}", info.getTabSuffix())
166 | .replace("{playerName}", info.getName());
167 | }
168 |
169 | public static List parsePlayerInfoPlaceholders(List s, PlayerInfo info) {
170 | //{tabPrefix}{playerName}{tabSuffix}
171 | return s.stream().map(value ->Util.colorize(
172 | value.replace("{tabPrefix}", info.getTabPrefix()).replace("{tabSuffix}", info.getTabSuffix())
173 | .replace("{tagPrefix}", info.getTabPrefix()).replace("{tagSuffix}", info.getTabSuffix())
174 | .replace("{playerName}", info.getName()))).collect(Collectors.toList());
175 | }
176 |
177 | public static List parseInternalPlaceholders(List s, GameReplayCache cache, Player p, String time) {
178 | //{tabPrefix}{playerName}{tabSuffix}
179 | String[] date = cache.getDate().split("_");
180 | return s.stream().map(value -> Util.colorize(value.replace("{date}", date[0] +" "+ date[1].replace("-",":"))
181 | .replace("{duration}", Util.formattedTime(cache.getTotalDuration()))
182 | .replace("{mode}", cache.getGameMode())
183 | .replace("{map}", cache.getMapName())
184 | .replace("{server}", Util.translateLang(Messages.SERVER_NAME, p))
185 | .replace("{players}", cache.getPlayersWithUUIDs().size() + "")
186 | .replace("{time}", time))
187 | ).collect(Collectors.toList());
188 | }
189 |
190 | public static String parseInternalPlaceholders(String s, GameReplayCache cache, Player p) {
191 | //{tabPrefix}{playerName}{tabSuffix}
192 | String[] date = cache.getDate().split("_");
193 | return s.replace("{date}", date[0] + " " + date[1].replace("-", ":"))
194 | .replace("{duration}", Util.formattedTime(cache.getTotalDuration()))
195 | .replace("{mode}", cache.getGameMode())
196 | .replace("{map}", cache.getMapName())
197 | .replace("{server}", Util.translateLang(Messages.SERVER_NAME, p))
198 | .replace("{players}", cache.getPlayersWithUUIDs().size() + "");
199 | }
200 |
201 |
202 |
203 | public static T getRandomElement(List list){
204 | return list.get(random.nextInt(list.size()));
205 | }
206 |
207 | public static String getConfigValue(String path){
208 | return plugin.mainConfig.getString(path, "");
209 | }
210 |
211 |
212 | }
213 |
--------------------------------------------------------------------------------
/src/main/java/dev/mrflyn/replayaddon/managers/playingmode/PlayingListener.java:
--------------------------------------------------------------------------------
1 | package dev.mrflyn.replayaddon.managers.playingmode;
2 |
3 |
4 | import de.tr7zw.changeme.nbtapi.NBTItem;
5 | import dev.mrflyn.replayaddon.ReplayAddonMain;
6 | import dev.mrflyn.replayaddon.advancedreplayhook.GameReplayCache;
7 | import dev.mrflyn.replayaddon.advancedreplayhook.GameReplayHandler;
8 | import dev.mrflyn.replayaddon.advancedreplayhook.StartQueue;
9 | import dev.mrflyn.replayaddon.guis.Button;
10 | import dev.mrflyn.replayaddon.guis.GuiHandler;
11 | import dev.mrflyn.replayaddon.guis.replaysessionguis.BookMarksGUI;
12 | import dev.mrflyn.replayaddon.guis.replaysessionguis.MoreSettingsGUI;
13 | import dev.mrflyn.replayaddon.versionutils.Util;
14 | import me.jumper251.replay.api.ReplaySessionFinishEvent;
15 | import me.jumper251.replay.api.ReplaySessionStartEvent;
16 | import me.jumper251.replay.replaysystem.Replay;
17 | import me.jumper251.replay.replaysystem.replaying.ReplayHelper;
18 | import me.jumper251.replay.replaysystem.replaying.Replayer;
19 | import me.jumper251.replay.utils.ReplayManager;
20 | import org.bukkit.Bukkit;
21 | import org.bukkit.Location;
22 | import org.bukkit.entity.Player;
23 | import org.bukkit.event.EventHandler;
24 | import org.bukkit.event.Listener;
25 | import org.bukkit.event.player.PlayerInteractEvent;
26 | import org.bukkit.event.player.PlayerJoinEvent;
27 | import org.bukkit.event.player.PlayerQuitEvent;
28 |
29 | import java.util.*;
30 |
31 | import static dev.mrflyn.replayaddon.ReplayAddonMain.plugin;
32 |
33 | public class PlayingListener implements Listener {
34 |
35 | @EventHandler
36 | public void onReplaySessionStart(ReplaySessionStartEvent e){
37 | Player p = e.getPlayer();
38 | if(!GameReplayHandler.playingReplays.containsKey(p))return;
39 | if(!e.getReplayer().getReplay().getId().equals(GameReplayHandler.playingReplays.get(p).getReplayID()))return;
40 | e.willHandleButtons(true);
41 | Util.debug("custom replay");
42 | for(Button b : plugin.initializedButtons.values()){
43 | if (!b.type.equals("HB_PLAY"))
44 | p.getInventory().setItem(b.slot, b.itemStack);
45 | }
46 | new BookMarksGUI(GameReplayHandler.playingReplays.get(p));
47 | if(GameReplayHandler.startQueue.containsKey(p)){
48 | e.getReplayer().setPaused(true);
49 | StartQueue task = GameReplayHandler.startQueue.get(p);
50 | if(task.startTime!=null)
51 | Util.setTime(e.getReplayer(), task.startTime-3);
52 | if(task.location!=null&&task.location.size()==3) {
53 | Location loc = new Location(p.getWorld(), task.location.get(0), task.location.get(1), task.location.get(2));
54 | Bukkit.getScheduler().runTaskLater(ReplayAddonMain.plugin, ()->{
55 | p.setFlying(true);
56 | p.teleport(Util.lookAt(loc.clone().add(3,1,3), loc));
57 | }, 2L);
58 | }
59 | GameReplayHandler.startQueue.remove(p);
60 | e.getReplayer().setPaused(false);
61 | }
62 | }
63 |
64 | @EventHandler
65 | public void onInteract(PlayerInteractEvent e){
66 | Player p = e.getPlayer();
67 | if(!GameReplayHandler.playingReplays.containsKey(p))return;
68 | if (!ReplayHelper.replaySessions.containsKey(p.getName()))return;
69 | if(e.getItem() == null)return;
70 | NBTItem item = new NBTItem(e.getItem());
71 | if(!item.hasKey("replay-addon-bw1058"))return;
72 | e.setCancelled(true);
73 | Replayer replayer = ReplayHelper.replaySessions.get(p.getName());
74 | switch (item.getString("replay-addon-bw1058")){
75 | case "HB_TP_PLAYER":
76 | ReplayHelper.createTeleporter(p, replayer);
77 | break;
78 | case "HB_MORE_SETT":
79 | p.openInventory(MoreSettingsGUI.INSTANCE.getCachedInventory());
80 | break;
81 | case "HB_PLAY":
82 | if(!replayer.isPaused())return;
83 | replayer.setPaused(false);
84 | ReplayHelper.sendTitle(p, " ", "§a➤", 20);
85 | Button pause = plugin.initializedButtons.get("HB_PAUSE");
86 | p.getInventory().setItem(pause.slot, pause.itemStack);
87 | break;
88 | case "HB_PAUSE":
89 | if(replayer.isPaused())return;
90 | replayer.setPaused(true);
91 | ReplayHelper.sendTitle(p, " ", "§c❙❙", 20);
92 | Button play = plugin.initializedButtons.get("HB_PLAY");
93 | p.getInventory().setItem(play.slot, play.itemStack);
94 | break;
95 | case "HB_DCR_SPD":
96 | if (replayer.getSpeed() == 4) {
97 | replayer.setSpeed(3);
98 | } else if (replayer.getSpeed() == 3) {
99 | replayer.setSpeed(2);
100 | } else if (replayer.getSpeed() == 2) {
101 | replayer.setSpeed(1);
102 | } else if (replayer.getSpeed() == 1) {
103 | replayer.setSpeed(0.5D);
104 | } else if (replayer.getSpeed() == 0.5D) {
105 | replayer.setSpeed(0.25D);
106 | }
107 | break;
108 | case "HB_INC_SPD":
109 | if (replayer.getSpeed() < 1) {
110 | replayer.setSpeed(1);
111 | }else if (replayer.getSpeed() == 1) {
112 | replayer.setSpeed(2);
113 | }else if (replayer.getSpeed() == 2) {
114 | replayer.setSpeed(3);
115 | }else if (replayer.getSpeed() == 3) {
116 | replayer.setSpeed(4);
117 | }
118 | break;
119 | case "HB_10s_FWD":
120 | replayer.getUtils().forward();
121 | ReplayHelper.sendTitle(p, " ", "§a»»", 20);
122 | break;
123 | case "HB_10s_BWD":
124 | replayer.getUtils().backward();
125 | ReplayHelper.sendTitle(p, " ", "§c««", 20);
126 | break;
127 | }
128 | }
129 |
130 |
131 | @EventHandler
132 | public void onReplaySessionEnd(ReplaySessionFinishEvent e){
133 | if(GameReplayHandler.playingReplays.containsKey(e.getPlayer())) {
134 | GameReplayHandler.playingReplays.get(e.getPlayer()).getChatTimelineHandler().terminate();
135 | GameReplayHandler.playingReplays.remove(e.getPlayer());
136 | }
137 | BookMarksGUI.replayIDBookmarks.remove(e.getReplay().getId());
138 | Bukkit.getScheduler().runTask(plugin, ()->{
139 | e.getPlayer().setFlySpeed(0.1F);
140 | });
141 |
142 | }
143 |
144 |
145 | @EventHandler
146 | public void onJoin(PlayerJoinEvent e){
147 | Player p = e.getPlayer();
148 | UUID uuid = p.getUniqueId();
149 | String name = p.getName();
150 | // String info = p.getName()+":"+p.getUniqueId().toString();
151 | Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
152 | String lang = plugin.db.getPlayerLanguage(uuid);
153 | if (lang == null) {
154 | plugin.playerLang.put(uuid, plugin.allLanguages.get("en"));
155 | } else {
156 | plugin.playerLang.put(uuid, plugin.allLanguages.get(lang));
157 | }
158 | List caches = plugin.db.getGameReplayCaches(name);
159 | GameReplayHandler.replayCachePerPlayer.put(uuid, caches);
160 | for (GameReplayCache cache : caches) {
161 | GameReplayHandler.replayCacheID.put(cache.getReplayName(), cache);
162 | }
163 | Util.debug("loaded on join.");
164 | Bukkit.getScheduler().runTask(plugin, () -> {
165 | GuiHandler.onJoin(p);
166 | });
167 |
168 | });
169 | }
170 |
171 | @EventHandler
172 | public void onLeave(PlayerQuitEvent e){
173 | if(GameReplayHandler.playingReplays.containsKey(e.getPlayer())) {
174 | GameReplayHandler.playingReplays.get(e.getPlayer()).getChatTimelineHandler().terminate();
175 | GameReplayHandler.playingReplays.remove(e.getPlayer());
176 | }
177 | for(GameReplayCache cache : GameReplayHandler.replayCachePerPlayer.get(e.getPlayer().getUniqueId())){
178 | GameReplayHandler.replayCacheID.remove(cache.getReplayName());
179 | }
180 | GameReplayHandler.replayCachePerPlayer.remove(e.getPlayer().getUniqueId());
181 | GuiHandler.onLeave(e.getPlayer());
182 | GameReplayHandler.startQueue.remove(e.getPlayer());
183 | e.getPlayer().setFlySpeed(0.1F);
184 | Player p = e.getPlayer();
185 | UUID uuid = p.getUniqueId();
186 | }
187 |
188 |
189 | }
190 |
--------------------------------------------------------------------------------
/src/main/java/dev/mrflyn/replayaddon/databases/SQLite.java:
--------------------------------------------------------------------------------
1 | package dev.mrflyn.replayaddon.databases;
2 |
3 |
4 | import com.google.gson.Gson;
5 | import dev.mrflyn.replayaddon.ReplayAddonMain;
6 | import dev.mrflyn.replayaddon.advancedreplayhook.GameReplayCache;
7 | import dev.mrflyn.replayaddon.advancedreplayhook.ProxyData;
8 |
9 | import java.io.File;
10 | import java.io.IOException;
11 | import java.sql.*;
12 | import java.util.ArrayList;
13 | import java.util.List;
14 | import java.util.UUID;
15 |
16 | public class SQLite implements IDatabase {
17 | Gson gson = new Gson();
18 | private String url;
19 |
20 | private Connection connection;
21 |
22 | @Override
23 | public String name() {
24 | return "SQLite";
25 | }
26 |
27 | @Override
28 | public boolean connect() {
29 | File folder = new File(ReplayAddonMain.plugin.getDataFolder() + "/Cache");
30 | if (!folder.exists()) {
31 | if (!folder.mkdir()) {
32 | ReplayAddonMain.plugin.getLogger().severe("Could not create /Cache folder!");
33 | }
34 | }
35 | File dataFolder = new File(folder.getPath() + "/cache.db");
36 | if (!dataFolder.exists()) {
37 | try {
38 | if (!dataFolder.createNewFile()) {
39 | ReplayAddonMain.plugin.getLogger().severe("Could not create /Cache/cache.db file!");
40 | }
41 | } catch (IOException e) {
42 | e.printStackTrace();
43 | return false;
44 | }
45 | }
46 | this.url = "jdbc:sqlite:" + dataFolder;
47 | try {
48 | Class.forName("org.sqlite.JDBC");
49 | this.connection = DriverManager.getConnection(url);
50 | } catch (SQLException | ClassNotFoundException e) {
51 | if (e instanceof ClassNotFoundException) {
52 | ReplayAddonMain.plugin.getLogger().severe("Could Not Found SQLite Driver on your system!");
53 | }
54 | e.printStackTrace();
55 | return false;
56 | }
57 | return true;
58 | }
59 |
60 | @Override
61 | public void init() {
62 | try {
63 | String sql = "CREATE TABLE IF NOT EXISTS game_replay (id INTEGER PRIMARY KEY AUTOINCREMENT, " +
64 | "replay_id VARCHAR(200), replay_data TEXT);";
65 | try (Statement statement = connection.createStatement()) {
66 | statement.executeUpdate(sql);
67 | }
68 | sql = "CREATE TABLE IF NOT EXISTS proxy_mode_data (id INTEGER PRIMARY KEY AUTOINCREMENT, " +
69 | "uuid VARCHAR(200), username VARCHAR(200), proxy_data TEXT);";
70 | try (Statement statement = connection.createStatement()) {
71 | statement.executeUpdate(sql);
72 | }
73 | sql = "DELETE FROM proxy_mode_data;";
74 | try (Statement statement = connection.createStatement()) {
75 | statement.executeUpdate(sql);
76 | }
77 | sql = "CREATE TABLE IF NOT EXISTS player_data (id INTEGER PRIMARY KEY AUTOINCREMENT, " +
78 | "uuid VARCHAR(200), username VARCHAR(200), language VARCHAR(200) NOT NULL DEFAULT 'en');";
79 | try (Statement statement = connection.createStatement()) {
80 | statement.executeUpdate(sql);
81 | }
82 |
83 | } catch (SQLException e) {
84 | e.printStackTrace();
85 | }
86 |
87 | }
88 |
89 | @Override
90 | public void saveGameReplayCache(GameReplayCache cache) {
91 | String sql = "INSERT INTO game_replay (replay_id, replay_data) VALUES (?, ?);";
92 | try {
93 | try(PreparedStatement statement = connection.prepareStatement(sql)){
94 | statement.setString(1, cache.getReplayName());
95 | statement.setString(2, gson.toJson(cache).toString());
96 | statement.executeUpdate();
97 | }
98 |
99 | } catch (SQLException e) {
100 | e.printStackTrace();
101 | }
102 | }
103 |
104 | @Override
105 | public List getGameReplayCaches(String player) {
106 | List caches = new ArrayList<>();
107 | String sql = "SELECT * FROM game_replay WHERE replay_data LIKE ?;";
108 | try {
109 | try(PreparedStatement statement = connection.prepareStatement(sql)){
110 | statement.setString(1, "%"+player+"%");
111 | ResultSet result = statement.executeQuery();
112 | while (result.next()){
113 | caches.add(gson.fromJson(result.getString("replay_data"), GameReplayCache.class));
114 | }
115 | }
116 |
117 | } catch (SQLException e) {
118 | e.printStackTrace();
119 | }
120 | return caches;
121 | }
122 | @Override
123 | public GameReplayCache getGameReplayCache(String id) {
124 | GameReplayCache cache = null;
125 | String sql = "SELECT * FROM game_replay WHERE replay_id=?;";
126 | try {
127 | try (PreparedStatement statement = connection.prepareStatement(sql)) {
128 | statement.setString(1, id);
129 | ResultSet result = statement.executeQuery();
130 | if(result.next()){
131 | cache = gson.fromJson(result.getString("replay_data"), GameReplayCache.class);
132 | }
133 | }
134 |
135 | } catch (SQLException e) {
136 | e.printStackTrace();
137 | }
138 | return cache;
139 | }
140 |
141 | @Override
142 | public String getPlayerLanguage(UUID uuid) {
143 | String sql = "SELECT * FROM player_data WHERE uuid=?;";
144 | try {
145 | try (PreparedStatement statement = connection.prepareStatement(sql)) {
146 | statement.setString(1, uuid.toString());
147 | ResultSet result = statement.executeQuery();
148 | if (result.next()) {
149 | return result.getString("language");
150 | }
151 | }
152 |
153 | } catch (SQLException e) {
154 | e.printStackTrace();
155 | }
156 | return null;
157 | }
158 |
159 | @Override
160 | public String getPlayerLanguage(String userName) {
161 | String sql = "SELECT * FROM player_data WHERE username=?;";
162 | try {
163 | try (PreparedStatement statement = connection.prepareStatement(sql)) {
164 | statement.setString(1, userName);
165 | ResultSet result = statement.executeQuery();
166 | if (result.next()) {
167 | return result.getString("language");
168 | }
169 | }
170 |
171 | } catch (SQLException e) {
172 | e.printStackTrace();
173 | }
174 | return null;
175 | }
176 |
177 | @Override
178 | public void updatePlayerLanguage(UUID uuid, String language) {
179 | String sql = "UPDATE player_data SET language=? WHERE uuid=?;";
180 | try {
181 | try(PreparedStatement statement = connection.prepareStatement(sql)){
182 | statement.setString(1, language);
183 | statement.setString(2, uuid.toString());
184 | statement.executeUpdate();
185 | }
186 | } catch (SQLException e) {
187 | e.printStackTrace();
188 | }
189 | }
190 |
191 | @Override
192 | public void createPlayerLanguage(UUID uuid,String userName, String language) {
193 | String sql = "INSERT INTO player_data (uuid, username, language) VALUES (?, ?, ?);";
194 | try {
195 | try (PreparedStatement statement = connection.prepareStatement(sql)) {
196 | statement.setString(1, uuid.toString());
197 | statement.setString(2, userName);
198 | statement.setString(3, language);
199 | statement.executeUpdate();
200 | }
201 | } catch (SQLException e) {
202 | e.printStackTrace();
203 | }
204 | }
205 | @Override
206 | public ProxyData getProxyData(UUID uuid) {
207 | String sql = "SELECT * FROM proxy_mode_data WHERE uuid=?;";
208 | try {
209 | try (PreparedStatement statement = connection.prepareStatement(sql)) {
210 | statement.setString(1, uuid.toString());
211 | ResultSet result = statement.executeQuery();
212 | if (result.next()) {
213 | return gson.fromJson(result.getString("proxy_data"), ProxyData.class);
214 | }
215 | }
216 |
217 | } catch (SQLException e) {
218 | e.printStackTrace();
219 | }
220 | return null;
221 | }
222 |
223 | @Override
224 | public ProxyData getProxyData(String userName) {
225 | String sql = "SELECT * FROM proxy_mode_data WHERE username=?;";
226 | try {
227 | try (PreparedStatement statement = connection.prepareStatement(sql)) {
228 | statement.setString(1, userName);
229 | ResultSet result = statement.executeQuery();
230 | if (result.next()) {
231 | return gson.fromJson(result.getString("proxy_data"), ProxyData.class);
232 | }
233 | }
234 |
235 | } catch (SQLException e) {
236 | e.printStackTrace();
237 | }
238 | return null;
239 | }
240 |
241 | @Override
242 | public void setProxyData(ProxyData data) {
243 | String sql = "INSERT INTO proxy_mode_data (uuid, username, proxy_data) VALUES (?, ?, ?);";
244 | try {
245 | try (PreparedStatement statement = connection.prepareStatement(sql)) {
246 | statement.setString(1, data.getUUID());
247 | statement.setString(2, data.getName());
248 | statement.setString(3, gson.toJson(data));
249 | statement.executeUpdate();
250 | }
251 | } catch (SQLException e) {
252 | e.printStackTrace();
253 | }
254 | }
255 |
256 | @Override
257 | public void deleteProxyData(ProxyData data) {
258 | String sql = "DELETE FROM proxy_mode_data WHERE uuid=?;";
259 | try {
260 | try (PreparedStatement statement = connection.prepareStatement(sql)) {
261 | statement.setString(1, data.getUUID());
262 | statement.executeUpdate();
263 | }
264 | } catch (SQLException e) {
265 | e.printStackTrace();
266 | }
267 | }
268 | }
269 |
--------------------------------------------------------------------------------
/src/main/java/dev/mrflyn/replayaddon/managers/proxymode/proxyplayingmode/ProxyPlayingListener.java:
--------------------------------------------------------------------------------
1 | package dev.mrflyn.replayaddon.managers.proxymode.proxyplayingmode;
2 |
3 |
4 |
5 | import de.tr7zw.changeme.nbtapi.NBTItem;
6 | import dev.mrflyn.replayaddon.ReplayAddonMain;
7 | import dev.mrflyn.replayaddon.advancedreplayhook.GameReplayHandler;
8 | import dev.mrflyn.replayaddon.advancedreplayhook.ProxyData;
9 | import dev.mrflyn.replayaddon.advancedreplayhook.StartQueue;
10 | import dev.mrflyn.replayaddon.guis.Button;
11 | import dev.mrflyn.replayaddon.guis.GuiHandler;
12 | import dev.mrflyn.replayaddon.guis.replaysessionguis.BookMarksGUI;
13 | import dev.mrflyn.replayaddon.guis.replaysessionguis.MoreSettingsGUI;
14 | import dev.mrflyn.replayaddon.managers.proxymode.ProxyModeManager;
15 | import dev.mrflyn.replayaddon.versionutils.Util;
16 | import me.jumper251.replay.api.ReplaySessionFinishEvent;
17 | import me.jumper251.replay.api.ReplaySessionStartEvent;
18 | import me.jumper251.replay.replaysystem.replaying.ReplayHelper;
19 | import me.jumper251.replay.replaysystem.replaying.Replayer;
20 | import org.bukkit.Bukkit;
21 | import org.bukkit.ChatColor;
22 | import org.bukkit.Location;
23 | import org.bukkit.entity.Player;
24 | import org.bukkit.event.EventHandler;
25 | import org.bukkit.event.Listener;
26 | import org.bukkit.event.player.PlayerInteractEvent;
27 | import org.bukkit.event.player.PlayerJoinEvent;
28 | import org.bukkit.event.player.PlayerQuitEvent;
29 | import java.io.ByteArrayOutputStream;
30 | import java.io.DataOutputStream;
31 | import java.util.*;
32 | import static dev.mrflyn.replayaddon.ReplayAddonMain.plugin;
33 |
34 | public class ProxyPlayingListener implements Listener {
35 |
36 | @EventHandler
37 | public void onReplaySessionStart(ReplaySessionStartEvent e){
38 | Player p = e.getPlayer();
39 | if(!GameReplayHandler.playingReplays.containsKey(p))return;
40 | if(!e.getReplayer().getReplay().getId().equals(GameReplayHandler.playingReplays.get(p).getReplayID()))return;
41 | e.willHandleButtons(true);
42 | Util.debug("custom replay");
43 | for(Button b : plugin.initializedButtons.values()){
44 | if (!b.type.equals("HB_PLAY"))
45 | p.getInventory().setItem(b.slot, b.itemStack);
46 | }
47 | new BookMarksGUI(GameReplayHandler.playingReplays.get(p));
48 | if(GameReplayHandler.startQueue.containsKey(p)){
49 | e.getReplayer().setPaused(true);
50 | StartQueue task = GameReplayHandler.startQueue.get(p);
51 | if(task.startTime!=null)
52 | Util.setTime(e.getReplayer(), task.startTime-3);
53 | if(task.location!=null&&task.location.size()==3) {
54 | Location loc = new Location(p.getWorld(), task.location.get(0), task.location.get(1), task.location.get(2));
55 | Bukkit.getScheduler().runTaskLater(ReplayAddonMain.plugin, ()->{
56 | p.setFlying(true);
57 | p.teleport(Util.lookAt(loc.clone().add(3,1,3), loc));
58 | }, 2L);
59 | }
60 | GameReplayHandler.startQueue.remove(p);
61 | e.getReplayer().setPaused(false);
62 | }
63 | }
64 |
65 | @EventHandler
66 | public void onInteract(PlayerInteractEvent e){
67 | Player p = e.getPlayer();
68 | if(!GameReplayHandler.playingReplays.containsKey(p))return;
69 | if (!ReplayHelper.replaySessions.containsKey(p.getName()))return;
70 | if(e.getItem() == null)return;
71 | NBTItem item = new NBTItem(e.getItem());
72 | if(!item.hasKey("replay-addon-bw1058"))return;
73 | e.setCancelled(true);
74 | Replayer replayer = ReplayHelper.replaySessions.get(p.getName());
75 | switch (item.getString("replay-addon-bw1058")){
76 | case "HB_TP_PLAYER":
77 | ReplayHelper.createTeleporter(p, replayer);
78 | break;
79 | case "HB_MORE_SETT":
80 | p.openInventory(MoreSettingsGUI.INSTANCE.getCachedInventory());
81 | break;
82 | case "HB_PLAY":
83 | if(!replayer.isPaused())return;
84 | replayer.setPaused(false);
85 | ReplayHelper.sendTitle(p, " ", "§a➤", 20);
86 | Button pause = plugin.initializedButtons.get("HB_PAUSE");
87 | p.getInventory().setItem(pause.slot, pause.itemStack);
88 | break;
89 | case "HB_PAUSE":
90 | if(replayer.isPaused())return;
91 | replayer.setPaused(true);
92 | ReplayHelper.sendTitle(p, " ", "§c❙❙", 20);
93 | Button play = plugin.initializedButtons.get("HB_PLAY");
94 | p.getInventory().setItem(play.slot, play.itemStack);
95 | break;
96 | case "HB_DCR_SPD":
97 | if (replayer.getSpeed() == 4) {
98 | replayer.setSpeed(3);
99 | } else if (replayer.getSpeed() == 3) {
100 | replayer.setSpeed(2);
101 | } else if (replayer.getSpeed() == 2) {
102 | replayer.setSpeed(1);
103 | } else if (replayer.getSpeed() == 1) {
104 | replayer.setSpeed(0.5D);
105 | } else if (replayer.getSpeed() == 0.5D) {
106 | replayer.setSpeed(0.25D);
107 | }
108 | break;
109 | case "HB_INC_SPD":
110 | if (replayer.getSpeed() < 1) {
111 | replayer.setSpeed(1);
112 | }else if (replayer.getSpeed() == 1) {
113 | replayer.setSpeed(2);
114 | }else if (replayer.getSpeed() == 2) {
115 | replayer.setSpeed(3);
116 | }else if (replayer.getSpeed() == 3) {
117 | replayer.setSpeed(4);
118 | }
119 | break;
120 | case "HB_10s_FWD":
121 | replayer.getUtils().forward();
122 | ReplayHelper.sendTitle(p, " ", "§a»»", 20);
123 | break;
124 | case "HB_10s_BWD":
125 | replayer.getUtils().backward();
126 | ReplayHelper.sendTitle(p, " ", "§c««", 20);
127 | break;
128 | }
129 | }
130 |
131 |
132 | @EventHandler
133 | public void onReplaySessionEnd(ReplaySessionFinishEvent e){
134 | Player p = e.getPlayer();
135 | if(GameReplayHandler.playingReplays.containsKey(e.getPlayer())) {
136 | GameReplayHandler.playingReplays.get(e.getPlayer()).getChatTimelineHandler().terminate();
137 | GameReplayHandler.playingReplays.remove(e.getPlayer());
138 | }
139 | BookMarksGUI.replayIDBookmarks.remove(e.getReplay().getId());
140 | Bukkit.getScheduler().runTask(plugin, ()->{
141 | e.getPlayer().setFlySpeed(0.1F);
142 | });
143 | if(!ProxyModeManager.proxyDataCache.containsKey(p.getUniqueId()))return;
144 | ProxyData data = ProxyModeManager.proxyDataCache.get(p.getUniqueId());
145 | try {
146 | ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
147 | DataOutputStream out = new DataOutputStream(byteArray);
148 | out.writeUTF("Connect");
149 | out.writeUTF(data.getLobbyName());
150 | p.sendPluginMessage(plugin, "BungeeCord", byteArray.toByteArray());
151 | Bukkit.getScheduler().runTaskLater(plugin, () -> {
152 | // if lobby server is unreachable
153 | if (p==null)return;
154 | if (p.isOnline()) {
155 | p.kickPlayer(ChatColor.RED+"You are not allowed here!");
156 | }
157 | }, 30L);
158 | }catch (Exception ex){
159 | ex.printStackTrace();
160 | }
161 |
162 | }
163 |
164 |
165 | @EventHandler
166 | public void onJoin(PlayerJoinEvent e){
167 | Player p = e.getPlayer();
168 | UUID uuid = p.getUniqueId();
169 | boolean hasPerm = p.hasPermission("replayAddon.admin");
170 | Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
171 | String lang = plugin.db.getPlayerLanguage(uuid);
172 | if (lang == null) {
173 | plugin.playerLang.put(uuid, plugin.allLanguages.get("en"));
174 | } else {
175 | plugin.playerLang.put(uuid, plugin.allLanguages.get(lang));
176 | }
177 | ProxyData data = plugin.db.getProxyData(uuid);
178 | if (data==null&&!hasPerm){
179 | Bukkit.getScheduler().runTask(plugin, ()->{
180 | p.kickPlayer(ChatColor.RED+"You are not authorized to enter this server!");
181 | });
182 | return;
183 | }
184 | if(data==null)return;
185 | ProxyModeManager.proxyDataCache.put(uuid,data);
186 | plugin.db.deleteProxyData(data);
187 | StringBuilder command = new StringBuilder("rp view "+data.getReplayID());
188 | if (data.getStartTime()!=null){
189 | command.append(" ").append(data.getStartTime());
190 | }
191 | if (data.getX()!=null&&data.getY()!=null&&data.getZ()!=null){
192 | command.append(" ").append(data.getX()).append(":").append(data.getY()).append(":").append(data.getZ());
193 | }
194 | Bukkit.getScheduler().runTaskLater(plugin, ()->{
195 | p.performCommand(command.toString());
196 | },20L);
197 | Util.debug("loaded on join.");
198 | });
199 | }
200 |
201 | @EventHandler
202 | public void onLeave(PlayerQuitEvent e){
203 | if(GameReplayHandler.playingReplays.containsKey(e.getPlayer())) {
204 | GameReplayHandler.playingReplays.get(e.getPlayer()).getChatTimelineHandler().terminate();
205 | GameReplayHandler.playingReplays.remove(e.getPlayer());
206 | }
207 | // for(GameReplayCache cache : GameReplayHandler.replayCachePerPlayer.get(e.getPlayer().getUniqueId())){
208 | // GameReplayHandler.replayCacheID.remove(cache.getReplayName());
209 | // }
210 | GameReplayHandler.replayCachePerPlayer.remove(e.getPlayer().getUniqueId());
211 | ProxyModeManager.proxyDataCache.remove(e.getPlayer().getUniqueId());
212 | GuiHandler.onLeave(e.getPlayer());
213 | GameReplayHandler.startQueue.remove(e.getPlayer());
214 | e.getPlayer().setFlySpeed(0.1F);
215 | }
216 |
217 |
218 | }
219 |
--------------------------------------------------------------------------------