Skip to content

Commit cf316d6

Browse files
committed
Added MyWarp importer
1 parent 3a604c4 commit cf316d6

File tree

4 files changed

+173
-13
lines changed

4 files changed

+173
-13
lines changed

resources/plugin.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: Warpalicious
22
main: nl.datdenkikniet.warpalicious.WarpaliciousPlugin
33
authors: [datdenkikniet, TastyBlueberry, oskar3123]
4-
version: 1.7.5
5-
softdepend: [Multiverse-Core, MultiWorld]
4+
version: 1.8.0
5+
softdepend: [Multiverse-Core, MultiWorld, MyWarp]
66
commands:
77
delwarp:
88
description: delete a warp
@@ -40,4 +40,5 @@ commands:
4040
usage: /<command> <privatewarp> <playername>
4141
warpuninvite:
4242
description: disallow players to warp to a private warp
43-
usage: /<command> <privatewarp> <playername>
43+
usage: /<command> <privatewarp> <playername>
44+
Lines changed: 161 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
package nl.datdenkikniet.warpalicious.commands;
22

3+
import me.taylorkelly.mywarp.MyWarp;
4+
import me.taylorkelly.mywarp.bukkit.MyWarpPlugin;
5+
import me.taylorkelly.mywarp.warp.EventfulPopulatableWarpManager;
6+
import me.taylorkelly.mywarp.warp.MemoryPopulatableWarpManager;
7+
import me.taylorkelly.mywarp.warp.PopulatableWarpManager;
8+
import me.taylorkelly.mywarp.warp.Warp;
39
import nl.datdenkikniet.warpalicious.WarpaliciousPlugin;
410
import nl.datdenkikniet.warpalicious.config.messages.Strings;
11+
import nl.datdenkikniet.warpalicious.handling.Flag;
12+
import org.bukkit.Bukkit;
13+
import org.bukkit.Location;
514
import org.bukkit.command.Command;
615
import org.bukkit.command.CommandExecutor;
716
import org.bukkit.command.CommandSender;
817

9-
/**
10-
* Created by Jona on 21/10/2016.
11-
*/
18+
import java.lang.reflect.Field;
19+
import java.lang.reflect.Method;
20+
import java.util.ArrayList;
21+
import java.util.HashMap;
22+
import java.util.UUID;
23+
1224
public class WarpaliciousCommand implements CommandExecutor
1325
{
1426

@@ -23,16 +35,158 @@ public WarpaliciousCommand(WarpaliciousPlugin pl, Strings instance)
2335

2436
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
2537
{
26-
if (args.length == 1 && args[0].equalsIgnoreCase("reloadmessages") && str.checkPermission(sender, str.universalPerm))
38+
if (args.length == 1)
39+
{
40+
if (args[0].equalsIgnoreCase("reloadmessages") && str.checkPermission(sender, str.universalPerm))
41+
{
42+
plugin.getStrings().loadMessages();
43+
sender.sendMessage(str.prefix + " Succesfully reloaded messages!");
44+
return true;
45+
}
46+
else
47+
{
48+
sender.sendMessage(str.getUsage(cmd, label));
49+
return true;
50+
}
51+
}
52+
else if (args.length == 2)
2753
{
28-
plugin.getStrings().loadMessages();
29-
sender.sendMessage(str.prefix + " Succesfully reloaded messages!");
54+
if (args[0].equalsIgnoreCase("import"))
55+
{
56+
if (args[1].equalsIgnoreCase("mywarp"))
57+
{
58+
if (str.checkPermission(sender, str.universalPerm))
59+
{
60+
MyWarpPlugin mwp = (MyWarpPlugin) plugin.getServer().getPluginManager().getPlugin("MyWarp");
61+
if (mwp == null)
62+
{
63+
sender.sendMessage("The MyWarp plugin is not installed on this server!");
64+
return true;
65+
}
66+
try
67+
{
68+
Field myWarpField = mwp.getClass().getDeclaredField("myWarp");
69+
myWarpField.setAccessible(true);
70+
EventfulPopulatableWarpManager ewm = (EventfulPopulatableWarpManager) ((MyWarp) myWarpField.get(mwp)).getWarpManager();
71+
72+
Method delegateEPWM = ewm.getClass().getDeclaredMethod("delegate");
73+
delegateEPWM.setAccessible(true);
74+
PopulatableWarpManager pwm = (PopulatableWarpManager) delegateEPWM.invoke(ewm);
75+
76+
Method delegatePWM = pwm.getClass().getDeclaredMethod("delegate");
77+
delegatePWM.setAccessible(true);
78+
MemoryPopulatableWarpManager mpw = (MemoryPopulatableWarpManager) delegatePWM.invoke(pwm);
79+
80+
Field warpMapField = mpw.getClass().getDeclaredField("warpMap");
81+
warpMapField.setAccessible(true);
82+
83+
@SuppressWarnings("unchecked")
84+
HashMap<String, me.taylorkelly.mywarp.warp.Warp> warpMap = (HashMap<String, me.taylorkelly.mywarp.warp.Warp>) warpMapField.get(mpw);
85+
86+
int addedWarps = 0;
87+
int failedWarps = 0;
88+
int totalWarps = warpMap.size();
89+
for (String wName : warpMap.keySet())
90+
{
91+
92+
Object initialObj = warpMap.get(wName);
93+
94+
Field warpField = initialObj.getClass().getDeclaredField("delegate");
95+
warpField.setAccessible(true);
96+
97+
Warp delegateFirst = (Warp) warpField.get(initialObj);
98+
99+
Field warpFieldSecond = delegateFirst.getClass().getDeclaredField("delegate");
100+
warpFieldSecond.setAccessible(true);
101+
102+
Warp warpMyWarp = (Warp) warpFieldSecond.get(delegateFirst);
103+
104+
Field posField = warpMyWarp.getClass().getDeclaredField("position");
105+
Field rotField = warpMyWarp.getClass().getDeclaredField("rotation");
106+
Field worldUUIDField = warpMyWarp.getClass().getDeclaredField("worldIdentifier");
107+
posField.setAccessible(true);
108+
rotField.setAccessible(true);
109+
worldUUIDField.setAccessible(true);
110+
111+
UUID worldUUID = (UUID) worldUUIDField.get(warpMyWarp);
112+
113+
Field xField = posField.get(warpMyWarp).getClass().getDeclaredField("x");
114+
Field yField = posField.get(warpMyWarp).getClass().getDeclaredField("y");
115+
Field zField = posField.get(warpMyWarp).getClass().getDeclaredField("z");
116+
xField.setAccessible(true);
117+
yField.setAccessible(true);
118+
zField.setAccessible(true);
119+
120+
Field pitchField = rotField.get(warpMyWarp).getClass().getDeclaredField("x");
121+
Field yawField = rotField.get(warpMyWarp).getClass().getDeclaredField("y");
122+
yawField.setAccessible(true);
123+
pitchField.setAccessible(true);
124+
125+
double x = (double) xField.get(posField.get(warpMyWarp));
126+
double y = (double) yField.get(posField.get(warpMyWarp));
127+
double z = (double) zField.get(posField.get(warpMyWarp));
128+
129+
float yaw = (float) yawField.get(rotField.get(warpMyWarp));
130+
float pitch = (float) pitchField.get(rotField.get(warpMyWarp));
131+
132+
Location loc = new Location(Bukkit.getWorld(worldUUID), x, y, z, yaw, pitch);
133+
ArrayList<UUID> invitedPlayers = new ArrayList<>();
134+
invitedPlayers.addAll(warpMyWarp.getInvitedPlayers());
135+
136+
HashMap<Flag, Boolean> defFlags = plugin.getWarpHandler().getDefaultFlags();
137+
138+
if (warpMyWarp.getType() == Warp.Type.PRIVATE)
139+
{
140+
defFlags.put(Flag.PRIVATE, true);
141+
}
142+
143+
if (plugin.getWarpHandler().getWarp(wName) == null)
144+
{
145+
new nl.datdenkikniet.warpalicious.handling.Warp(plugin, warpMyWarp.getCreator(), loc, warpMyWarp.getName(), defFlags, plugin.getWarpHandler(), warpMyWarp.getVisits(), invitedPlayers, wName);
146+
System.out.println("Imported " + (defFlags.get(Flag.PRIVATE) ? "private" : "") + " warp with name " + wName + " at location x:" + x + ", y:" + y + ", z:" + z + ", yaw:" + yaw + ", pitch:" + pitch + " and " + invitedPlayers.size() + " invited players");
147+
addedWarps++;
148+
}
149+
else
150+
{
151+
System.out.println("Failed to add import warp " + wName + ". A warp with that name already exists!");
152+
failedWarps++;
153+
}
154+
}
155+
sender.sendMessage("Attempting to import " + totalWarps + " warps...");
156+
sender.sendMessage("Imported " + addedWarps + " warps from mywarp.");
157+
sender.sendMessage("Failed to add " + failedWarps + " warps (check the console for more information).");
158+
}
159+
catch (Exception ex)
160+
{
161+
ex.printStackTrace();
162+
sender.sendMessage("Something went wrong!");
163+
return true;
164+
}
165+
return true;
166+
}
167+
else
168+
{
169+
sender.sendMessage(str.noperm);
170+
return true;
171+
}
172+
}
173+
else
174+
{
175+
sender.sendMessage(str.getUsage(cmd, label));
176+
return true;
177+
}
178+
}
179+
else
180+
{
181+
sender.sendMessage(str.getUsage(cmd, label));
182+
return true;
183+
}
30184
}
31185
else
32186
{
33187
sender.sendMessage(str.prefix + " This server is running Warpalicious version " + plugin.getDescription().getVersion() + " by datdenkikniet.");
188+
return true;
34189
}
35-
return true;
36190
}
37191

38192
}

src/nl/datdenkikniet/warpalicious/config/messages/Strings.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,17 @@ public boolean checkPermission(Permissible p, String permission)
210210
{
211211
return p.hasPermission(permission) || p.hasPermission(universalPerm);
212212
} else {
213+
boolean hasNegator = false;
214+
boolean hasPerm = false;
213215
for (PermissionAttachmentInfo at : p.getEffectivePermissions()){
214216
if (at.getPermission().equalsIgnoreCase(permission)){
215-
return true;
217+
hasPerm = true;
218+
}
219+
if (at.getPermission().equalsIgnoreCase(permission) && !at.getValue()){
220+
hasNegator = true;
216221
}
217222
}
218-
return false;
223+
return hasPerm && !hasNegator;
219224
}
220225
}
221226
}

src/nl/datdenkikniet/warpalicious/handling/Warp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public Warp(WarpaliciousPlugin instance, UUID owner, Location loc, String name,
2929
this.loc = loc;
3030
this.name = name;
3131
this.flags = flags;
32-
handler.addWarp(this);
3332
this.timesWarpedTo = time;
3433
this.plugin = instance;
3534
this.invitedPlayers = invited;
3635
this.worldName = worldName;
36+
handler.addWarp(this);
3737
}
3838

3939
public boolean isPrivate()

0 commit comments

Comments
 (0)