Skip to content

Commit 697d994

Browse files
committed
Added warpalicious importer
1 parent f55fbab commit 697d994

File tree

5 files changed

+80
-99
lines changed

5 files changed

+80
-99
lines changed

src/nl/datdenkikniet/warpalicious/commands/SetWarpCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
5050
return true;
5151
}
5252
if (handler.getWarp(args[0]) == null){
53-
Warp warp = new Warp(handler.getPlugin(), player.getUniqueId(), player.getLocation(), args[0], handler.getDefaultFlags(), handler, 0, new ArrayList<>(), player.getLocation().getWorld().getName());
53+
Warp warp = new Warp(handler.getPlugin(), player.getUniqueId(), player.getLocation(), args[0], handler.getDefaultFlags(), 0, new ArrayList<>());
5454
handler.saveWarps();
5555
if ((args.length > 1 && args[1].equalsIgnoreCase("private") && str.checkPermission(sender, str.setPrivateWarpPerm)) || str.checkPermission(sender, str.onlySetPrivate)){
5656
System.out.println(sender.isPermissionSet(str.onlySetPrivate));

src/nl/datdenkikniet/warpalicious/commands/WarpaliciousCommand.java

Lines changed: 74 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -26,50 +26,36 @@
2626
import java.util.HashMap;
2727
import java.util.UUID;
2828

29-
public class WarpaliciousCommand implements CommandExecutor
30-
{
29+
public class WarpaliciousCommand implements CommandExecutor {
3130

3231
private WarpaliciousPlugin plugin;
3332
private Strings str;
3433

35-
public WarpaliciousCommand(WarpaliciousPlugin pl, Strings instance)
36-
{
34+
public WarpaliciousCommand(WarpaliciousPlugin pl, Strings instance) {
3735
str = instance;
3836
plugin = pl;
3937
}
4038

41-
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
42-
{
43-
if (args.length == 1)
44-
{
45-
if (args[0].equalsIgnoreCase("reloadmessages") && str.checkPermission(sender, str.universalPerm))
46-
{
39+
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
40+
if (args.length == 1) {
41+
if (args[0].equalsIgnoreCase("reloadmessages") && str.checkPermission(sender, str.universalPerm)) {
4742
plugin.getStrings().loadMessages();
4843
sender.sendMessage(str.prefix + " Succesfully reloaded messages!");
4944
return true;
50-
}
51-
else
52-
{
45+
} else {
5346
sender.sendMessage(str.getUsage(cmd, label));
5447
return true;
5548
}
56-
}
57-
else if (args.length == 2)
58-
{
59-
if (args[0].equalsIgnoreCase("import"))
60-
{
61-
if (args[1].equalsIgnoreCase("mywarp"))
62-
{
63-
if (str.checkPermission(sender, str.universalPerm))
64-
{
49+
} else if (args.length == 2) {
50+
if (args[0].equalsIgnoreCase("import")) {
51+
if (str.checkPermission(sender, str.universalPerm)) {
52+
if (args[1].equalsIgnoreCase("mywarp")) {
6553
MyWarpPlugin mwp = (MyWarpPlugin) plugin.getServer().getPluginManager().getPlugin("MyWarp");
66-
if (mwp == null)
67-
{
54+
if (mwp == null) {
6855
sender.sendMessage("The MyWarp plugin is not installed on this server!");
6956
return true;
7057
}
71-
try
72-
{
58+
try {
7359
Field myWarpField = mwp.getClass().getDeclaredField("myWarp");
7460
myWarpField.setAccessible(true);
7561
EventfulPopulatableWarpManager ewm = (EventfulPopulatableWarpManager) ((MyWarp) myWarpField.get(mwp)).getWarpManager();
@@ -91,8 +77,7 @@ else if (args.length == 2)
9177
int addedWarps = 0;
9278
int failedWarps = 0;
9379
int totalWarps = warpMap.size();
94-
for (String wName : warpMap.keySet())
95-
{
80+
for (String wName : warpMap.keySet()) {
9681

9782
Object initialObj = warpMap.get(wName);
9883

@@ -140,79 +125,92 @@ else if (args.length == 2)
140125

141126
HashMap<Flag, Boolean> defFlags = plugin.getWarpHandler().getDefaultFlags();
142127

143-
if (warpMyWarp.getType() == Warp.Type.PRIVATE)
144-
{
128+
if (warpMyWarp.getType() == Warp.Type.PRIVATE) {
145129
defFlags.put(Flag.PRIVATE, true);
146130
}
147131

148-
if (plugin.getWarpHandler().getWarp(wName) == null)
149-
{
150-
new nl.datdenkikniet.warpalicious.handling.Warp(plugin, warpMyWarp.getCreator(), loc, warpMyWarp.getName(), defFlags, plugin.getWarpHandler(), warpMyWarp.getVisits(), invitedPlayers, wName);
132+
if (plugin.getWarpHandler().getWarp(wName) == null) {
133+
new nl.datdenkikniet.warpalicious.handling.Warp(plugin, warpMyWarp.getCreator(), loc, warpMyWarp.getName(), defFlags, warpMyWarp.getVisits(), invitedPlayers);
151134
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");
152135
addedWarps++;
153-
}
154-
else
155-
{
136+
} else {
156137
System.out.println("Failed to add import warp " + wName + ". A warp with that name already exists!");
157138
failedWarps++;
158139
}
159140
}
160141
sender.sendMessage("Attempting to import " + totalWarps + " warps...");
161142
sender.sendMessage("Imported " + addedWarps + " warps from mywarp.");
162143
sender.sendMessage("Failed to add " + failedWarps + " warps (check the console for more information).");
163-
}
164-
catch (Exception ex)
165-
{
144+
} catch (Exception ex) {
166145
ex.printStackTrace();
167146
sender.sendMessage("Something went wrong!");
168147
return true;
169148
}
170149
return true;
171-
}
172-
else
173-
{
174-
sender.sendMessage(str.noperm);
175-
return true;
176-
}
177-
}
178-
else if (args[1].equalsIgnoreCase("warptastic")){
179-
try
180-
{
181-
warptastic wp = (warptastic) plugin.getServer().getPluginManager().getPlugin("warptastic");
182-
Field serviceField = wp.getClass().getDeclaredField("service");
183-
serviceField.setAccessible(true);
184-
DBConnection service = (DBConnection) serviceField.get(wp);
185-
186-
Connection stmt = service.getConnection();
187-
Statement rs = stmt.createStatement();
188-
ResultSet target = rs.executeQuery("PRAGMA table_info(W_Warps);");
189-
190-
while(target.next())
191-
{
192-
System.out.println(target.toString());
150+
} else if (args[1].equalsIgnoreCase("warptastic")) {
151+
int addedWarps = 0;
152+
int failedWarps = 0;
153+
int totalWarps = 0;
154+
try {
155+
warptastic wp = (warptastic) plugin.getServer().getPluginManager().getPlugin("warptastic");
156+
Field serviceField = wp.getClass().getDeclaredField("service");
157+
serviceField.setAccessible(true);
158+
DBConnection service = (DBConnection) serviceField.get(wp);
159+
160+
Connection stmt = service.getConnection();
161+
Statement rs = stmt.createStatement();
162+
ResultSet target = rs.executeQuery("SELECT * FROM W_Warps;");
163+
while (target.next()) {
164+
totalWarps++;
165+
String name = target.getString("warpname");
166+
UUID owner = Bukkit.getOfflinePlayer(target.getString("owner")).getUniqueId();
167+
String world = target.getString("world");
168+
double x = target.getDouble("x");
169+
double y = target.getDouble("y");
170+
double z = target.getDouble("z");
171+
float yaw = target.getFloat("f");
172+
float pitch = target.getFloat("p");
173+
boolean isPrivate = target.getBoolean("privacy");
174+
int timesWarpedTo = target.getInt("popularity");
175+
HashMap<Flag, Boolean> defFlags = plugin.getWarpHandler().getDefaultFlags();
176+
if (isPrivate) {
177+
defFlags.put(Flag.PRIVATE, true);
178+
}
179+
if (plugin.getWarpHandler().getWarp(name) == null) {
180+
new nl.datdenkikniet.warpalicious.handling.Warp(plugin, owner, new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch), name, defFlags, timesWarpedTo, new ArrayList<>());
181+
System.out.println("Imported " + (defFlags.get(Flag.PRIVATE) ? "private" : "") + " warp with name " + name + " at location x:" + x + ", y:" + y + ", z:" + z + ", yaw:" + yaw + ", pitch:" + pitch);
182+
addedWarps++;
183+
} else {
184+
System.out.println("Failed to add import warp " + name + ". A warp with that name already exists!");
185+
failedWarps++;
186+
}
187+
}
188+
target.close();
189+
rs.close();
190+
plugin.getWarpHandler().saveWarps();
191+
sender.sendMessage("Ateempted to import " + totalWarps + " warps...");
192+
sender.sendMessage("Imported " + addedWarps + " warps from warptastic.");
193+
sender.sendMessage("Failed to add " + failedWarps + " warps (check the console for more information).");
194+
return true;
195+
} catch (Exception ex) {
196+
ex.printStackTrace();
197+
sender.sendMessage("Something went wrong while trying to import warptastic warps!");
198+
return true;
193199
}
194-
target.close();
195-
rs.close();
196-
return true;
197-
} catch (Exception ex){
198-
ex.printStackTrace();
200+
} else {
201+
sender.sendMessage(str.getUsage(cmd, label));
199202
return true;
200203
}
201-
}
202-
else
203-
{
204-
sender.sendMessage(str.getUsage(cmd, label));
204+
} else {
205+
sender.sendMessage(str.noperm);
205206
return true;
206207
}
207-
}
208-
else
209-
{
208+
} else {
210209
sender.sendMessage(str.getUsage(cmd, label));
211210
return true;
212211
}
213-
}
214-
else
215-
{
212+
213+
} else {
216214
sender.sendMessage(str.prefix + " This server is running Warpalicious version " + plugin.getDescription().getVersion() + " by datdenkikniet.");
217215
return true;
218216
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void run(){
4141
player.getLocation().getWorld().spawnParticle(mode.getEffect(Direction.DEPART), player.getLocation(), mode.getEffectCount(Direction.DEPART));
4242
}
4343
player.teleport(warp.getLocation(true));
44-
player.sendMessage(str.warpToWarp.replace("%NAME%", warp.getName()).replace("%WORLDNAME%", warp.getWorldName()));
44+
player.sendMessage(str.warpToWarp.replace("%NAME%", warp.getName()).replace("%WORLDNAME%", warp.getLocation(false).getWorld().getName()));
4545
if (mode.getEffect(Direction.ARRIVAL) != null && !str.checkPermission(player, str.noParticlePerm)){
4646
player.getLocation().getWorld().spawnParticle(mode.getEffect(Direction.ARRIVAL), player.getLocation(), mode.getEffectCount(Direction.ARRIVAL));
4747
}

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ public class Warp
2121
private int timesWarpedTo;
2222
private WarpaliciousPlugin plugin;
2323
private ArrayList<UUID> invitedPlayers;
24-
private String worldName;
2524

26-
public Warp(WarpaliciousPlugin instance, UUID owner, Location loc, String name, HashMap<Flag, Boolean> flags, WarpHandler handler, int time, ArrayList<UUID> invited, String worldName)
25+
public Warp(WarpaliciousPlugin instance, UUID owner, Location loc, String name, HashMap<Flag, Boolean> flags, int time, ArrayList<UUID> invited)
2726
{
2827
this.owner = owner;
2928
this.loc = loc;
@@ -32,8 +31,7 @@ public Warp(WarpaliciousPlugin instance, UUID owner, Location loc, String name,
3231
this.timesWarpedTo = time;
3332
this.plugin = instance;
3433
this.invitedPlayers = invited;
35-
this.worldName = worldName;
36-
handler.addWarp(this);
34+
plugin.getWarpHandler().addWarp(this);
3735
}
3836

3937
public boolean isPrivate()
@@ -100,7 +98,7 @@ public void warp(Player player, TeleportMode mode, Strings str)
10098
}
10199
else
102100
{
103-
player.sendMessage(str.invalidWorld.replace("%WARPNAME%", getName()).replace("%WORLDNAME%", worldName));
101+
player.sendMessage(str.invalidWorld.replace("%WARPNAME%", getName()).replace("%WORLDNAME%", loc.getWorld().getName()));
104102
}
105103
}
106104
else
@@ -144,28 +142,14 @@ public void addInvitedPlayer(UUID u)
144142
invitedPlayers.add(u);
145143
}
146144

147-
public void addInvitedPlayer(Player p)
148-
{
149-
addInvitedPlayer(p.getUniqueId());
150-
}
151-
152145
public void removeInvitedPlayer(UUID u)
153146
{
154147
invitedPlayers.remove(u);
155148
}
156149

157-
public void removeInvitedPlayer(Player p)
158-
{
159-
removeInvitedPlayer(p.getUniqueId());
160-
}
161-
162150
public ArrayList<UUID> getInvitedPlayers()
163151
{
164152
return invitedPlayers;
165153
}
166154

167-
String getWorldName()
168-
{
169-
return worldName;
170-
}
171155
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,11 @@ private void loadWarps(){
6464
}
6565
}
6666
UUID owner = UUID.fromString(c.getString(key + ".owner"));
67-
String worldName = c.getString(key + ".location").split(",")[0];
6867
Location loc = plugin.stringToLoc(c.getString(key + ".location"));
6968
int times = c.getInt(key + ".timeswarpedto");
7069
ArrayList<UUID> invitedPlayers = new ArrayList<>();
7170
c.getStringList(key + ".invited").stream().forEach(str -> invitedPlayers.add(UUID.fromString(str)));
72-
new Warp(getPlugin(), owner, loc, key, flags, this, times, invitedPlayers, worldName);
71+
new Warp(getPlugin(), owner, loc, key, flags, times, invitedPlayers);
7372
}
7473
} catch (Exception ex){
7574
System.out.println("Error while loading flag " + key);

0 commit comments

Comments
 (0)