Skip to content

Commit 60e3eb2

Browse files
committed
"fixed" null error when setting warps or warping somewhere
1 parent d9d5d66 commit 60e3eb2

File tree

7 files changed

+53
-21
lines changed

7 files changed

+53
-21
lines changed

resources/messages.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ player-already-invited: "%PREFIX% That player has already been invited!"
5151
warp-not-private: "%PREFIX% That warp is not private!"
5252
warp-invited: "%PREFIX% %PLAYERNAME% invited you to their private warp %WARPNAME%!"
5353
warp-uninvited: "%PREFIX% %PLAYERNAME% removed you from their invited list to warp %WARPNAME%."
54+
warp-has-invalid-world: "%PREFIX% &c%WARPNAME% has an invalid world! (%WORLDNAME%)"

resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Warpalicious
22
main: nl.datdenkikniet.warpalicious.WarpaliciousPlugin
33
authors: [datdenkikniet, TastyBlueberry, oskar3123]
4-
version: 1.7.3
4+
version: 1.7.4
55
commands:
66
delwarp:
77
description: delete a warp

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
6161
}
6262
if (handler.getWarp(args[0]) == null)
6363
{
64-
Warp warp = new Warp(handler.getPlugin(), player.getUniqueId(), player.getLocation(), args[0], handler.getDefaultFlags(), handler, 0, new ArrayList<>());
64+
Warp warp = new Warp(handler.getPlugin(), player.getUniqueId(), player.getLocation(), args[0], handler.getDefaultFlags(), handler, 0, new ArrayList<>(), player.getLocation().getWorld().getName());
6565
handler.saveWarps();
6666
if (args.length > 1 && args[1].equalsIgnoreCase("private") && str.checkPermission(sender, str.setPrivateWarpPerm))
6767
{

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public Strings(CustomConfig cu, Config cfg, WarpaliciousPlugin plugin)
105105
public String alreadyInvited;
106106
public String warpInvited;
107107
public String warpUninvited;
108+
public String invalidWorld;
108109

109110
/*
110111
String functions
@@ -185,6 +186,7 @@ public void loadMessages()
185186
notPrivate = s("warp-not-private");
186187
warpInvited = s("warp-invited");
187188
warpUninvited = s("warp-uninvited");
189+
invalidWorld = s("warp-has-invalid-world");
188190
}
189191

190192
private String s(String s)

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,23 @@ else if (timeLeft < 1)
4343
}
4444
else
4545
{
46-
if (mode.getEffect(Direction.DEPART) != null && !str.checkPermission(player, str.noParticlePerm))
46+
if (warp.getLocation(false) != null && warp.getLocation(false).getWorld() == null)
4747
{
48-
player.getLocation().getWorld().spawnParticle(mode.getEffect(Direction.DEPART), player.getLocation(), mode.getEffectCount(Direction.DEPART));
48+
if (mode.getEffect(Direction.DEPART) != null && !str.checkPermission(player, str.noParticlePerm))
49+
{
50+
player.getLocation().getWorld().spawnParticle(mode.getEffect(Direction.DEPART), player.getLocation(), mode.getEffectCount(Direction.DEPART));
51+
}
52+
player.teleport(warp.getLocation(true));
53+
player.sendMessage(str.warpToWarp.replace("%NAME%", warp.getName()).replace("%WORLDNAME%", warp.getWorldName()));
54+
if (mode.getEffect(Direction.ARRIVAL) != null && !str.checkPermission(player, str.noParticlePerm))
55+
{
56+
player.getLocation().getWorld().spawnParticle(mode.getEffect(Direction.ARRIVAL), player.getLocation(), mode.getEffectCount(Direction.ARRIVAL));
57+
}
58+
4959
}
50-
player.teleport(warp.getLocation(true));
51-
player.sendMessage(str.warpToWarp.replace("%NAME%", warp.getName()));
52-
if (mode.getEffect(Direction.ARRIVAL) != null && !str.checkPermission(player, str.noParticlePerm))
60+
else
5361
{
54-
player.getLocation().getWorld().spawnParticle(mode.getEffect(Direction.ARRIVAL), player.getLocation(), mode.getEffectCount(Direction.ARRIVAL));
62+
player.sendMessage(str.invalidWorld.replace("%WARPNAME%", warp.getName()));
5563
}
5664
}
5765
}

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

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

25-
public Warp(WarpaliciousPlugin instance, UUID owner, Location loc, String name, HashMap<Flag, Boolean> flags, WarpHandler handler, int time, ArrayList<UUID> invited)
26+
public Warp(WarpaliciousPlugin instance, UUID owner, Location loc, String name, HashMap<Flag, Boolean> flags, WarpHandler handler, int time, ArrayList<UUID> invited, String worldName)
2627
{
2728
this.owner = owner;
2829
this.loc = loc;
2930
this.name = name;
3031
this.flags = flags;
3132
handler.addWarp(this);
32-
timesWarpedTo = time;
33-
plugin = instance;
34-
invitedPlayers = invited;
33+
this.timesWarpedTo = time;
34+
this.plugin = instance;
35+
this.invitedPlayers = invited;
36+
this.worldName = worldName;
3537
}
3638

3739
public boolean isPrivate()
@@ -83,15 +85,22 @@ public void warp(Player player, TeleportMode mode, Strings str)
8385

8486
if (delay == 0)
8587
{
86-
if (mode.getEffect(Direction.DEPART) != null && !str.checkPermission(player, str.noParticlePerm))
88+
if (getLocation(false) != null && getLocation(false).getWorld() != null)
8789
{
88-
loc.getWorld().spawnParticle(mode.getEffect(Direction.DEPART), loc, mode.getEffectCount(Direction.DEPART));
90+
if (mode.getEffect(Direction.DEPART) != null && !str.checkPermission(player, str.noParticlePerm))
91+
{
92+
loc.getWorld().spawnParticle(mode.getEffect(Direction.DEPART), loc, mode.getEffectCount(Direction.DEPART));
93+
}
94+
player.teleport(getLocation(true));
95+
player.sendMessage(str.warpToWarp.replace("%NAME%", getName()));
96+
if (mode.getEffect(Direction.ARRIVAL) != null && !str.checkPermission(player, str.noParticlePerm))
97+
{
98+
loc.getWorld().spawnParticle(mode.getEffect(Direction.ARRIVAL), loc, mode.getEffectCount(Direction.ARRIVAL));
99+
}
89100
}
90-
player.teleport(getLocation(true));
91-
player.sendMessage(str.warpToWarp.replace("%NAME%", getName()));
92-
if (mode.getEffect(Direction.ARRIVAL) != null && !str.checkPermission(player, str.noParticlePerm))
101+
else
93102
{
94-
loc.getWorld().spawnParticle(mode.getEffect(Direction.ARRIVAL), loc, mode.getEffectCount(Direction.ARRIVAL));
103+
player.sendMessage(str.invalidWorld.replace("%WARPNAME%", getName()).replace("%WORLDNAME%", worldName));
95104
}
96105
}
97106
else
@@ -149,7 +158,12 @@ public void removeInvitedPlayer(Player p)
149158
{
150159
removeInvitedPlayer(p.getUniqueId());
151160
}
152-
ArrayList<UUID> getInvitedPlayers(){
161+
162+
ArrayList<UUID> getInvitedPlayers()
163+
{
153164
return invitedPlayers;
154165
}
166+
protected String getWorldName(){
167+
return worldName;
168+
}
155169
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.ArrayList;
1515
import java.util.HashMap;
1616
import java.util.UUID;
17+
import java.util.logging.Level;
1718

1819
public class WarpHandler
1920
{
@@ -76,11 +77,12 @@ private void loadWarps()
7677
}
7778
}
7879
UUID owner = UUID.fromString(c.getString(key + ".owner"));
80+
String worldName = c.getString(key + ".location").split(",")[0];
7981
Location loc = plugin.stringToLoc(c.getString(key + ".location"));
8082
int times = c.getInt(key + ".timeswarpedto");
8183
ArrayList<UUID> invitedPlayers = new ArrayList<>();
8284
c.getStringList(key + ".invited").stream().forEach(str -> invitedPlayers.add(UUID.fromString(str)));
83-
new Warp(getPlugin(), owner, loc, key, flags, this, times, invitedPlayers);
85+
new Warp(getPlugin(), owner, loc, key, flags, this, times, invitedPlayers, worldName);
8486
}
8587
}
8688
catch (Exception ex)
@@ -149,7 +151,12 @@ public void saveWarps()
149151
for (Warp warp : warps)
150152
{
151153
c.set(warp.getName() + ".owner", warp.getOwner().toString());
152-
c.set(warp.getName() + ".location", plugin.locationToString(warp.getLocation(false)));
154+
if (warp.getLocation(false).getWorld() != null)
155+
{
156+
c.set(warp.getName() + ".location", plugin.locationToString(warp.getLocation(false)));
157+
} else {
158+
plugin.getLogger().log(Level.WARNING, "Warning: warp \"" + warp.getName() + "\" has an invalid world!");
159+
}
153160
for (Flag flag : Flag.values())
154161
{
155162
c.set(warp.getName() + ".flags." + flag.name(), warp.getFlags().get(flag));

0 commit comments

Comments
 (0)