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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
package com.earth2me.essentials;
import com.google.common.io.PatternFilenameFilter;
import java.io.File;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;
import net.ess3.api.*;
import net.ess3.user.User;
import org.bukkit.Material;
class UpdateUserFiles
{
private static final String BROKENNAME = "BROKENNAME";
private final IEssentials ess;
public UpdateUserFiles(File folder, IEssentials ess)
{
this.ess = ess;
for (String filename : folder.list(new PatternFilenameFilter(".+\\.yml")))
{
File file = new File(folder, filename);
String name = filename.substring(0, filename.length() - 4);
if (name.contains("_"))
{
String origName = name;
name = getRealName(name);
if (name.equals(BROKENNAME))
{
ess.getLogger().log(Level.WARNING, "Could not convert player {0}", origName);
continue;
}
}
UserData userData = new UserData(ess, file);
if (userData.isNPC())
{
ess.getEconomy().createNPC(name);
try
{
ess.getEconomy().setMoney(name, userData.getMoney());
}
catch (UserDoesNotExistException ex)
{
ess.getLogger().log(Level.WARNING, "Could not convert player " + name, ex);
}
catch (NoLoanPermittedException ex)
{
ess.getLogger().log(Level.WARNING, "Could not convert player " + name, ex);
}
}
else
{
IUser user = ess.getUserMap().getUser(name);
if (user == null)
{
try
{
user = new User(ess.getServer().getOfflinePlayer(name), ess);
}
catch (InvalidNameException ex)
{
ess.getLogger().log(Level.WARNING, "Could not convert player " + name, ex);
continue;
}
}
net.ess3.user.UserData data = user.getData();
data.setPowerToolsEnabled(userData.arePowerToolsEnabled());
data.getBan().setReason(userData.getBanReason());
data.getBan().setTimeout(userData.getBanTimeout());
userData.getHomes();
for (String playerName : userData.getIgnoredPlayers())
{
data.setIgnore(playerName.toLowerCase(Locale.ENGLISH), true);
}
data.setJail(userData.getJail());
data.setTimestamp(net.ess3.user.UserData.TimestampType.JAIL, userData.getJailTimeout());
for (String kit : userData.getKitTimestamps())
{
data.setTimestamp(net.ess3.user.UserData.TimestampType.KIT, kit, userData.getKitTimestamp(kit));
}
data.setTimestamp(net.ess3.user.UserData.TimestampType.LASTHEAL, userData.getLastHealTimestamp());
data.setLastLocation(userData.getLastLocation());
data.setTimestamp(net.ess3.user.UserData.TimestampType.LOGIN, userData.getLastLogin());
data.setIpAddress(userData.getLastLoginAddress());
data.setTimestamp(net.ess3.user.UserData.TimestampType.LOGOUT, userData.getLastLogout());
data.setTimestamp(net.ess3.user.UserData.TimestampType.LASTTELEPORT, userData.getLastTeleportTimestamp());
for (String mail : userData.getMails())
{
data.addMail(mail);
}
data.setMoney(userData.getMoney());
data.setTimestamp(net.ess3.user.UserData.TimestampType.MUTE, userData.getMuteTimeout());
data.setMuted(userData.getMuted());
data.setNickname(userData.getNickname());
for (String string : userData.getPowertools())
{
try
{
int id = Integer.parseInt(string);
Material mat = Material.getMaterial(id);
if (mat != null)
{
data.setPowertool(mat, userData.getPowertool(id));
}
}
catch (NumberFormatException ex)
{
}
}
for (Integer integer : userData.getUnlimited())
{
Material mat = Material.getMaterial(integer);
if (mat != null)
{
data.setUnlimited(mat, true);
}
}
data.setAfk(userData.isAfk());
data.setGodmode(userData.isGodModeEnabled());
data.setJailed(userData.isJailed());
data.setMuted(userData.isMuted());
data.setSocialspy(userData.isSocialSpyEnabled());
data.setTeleportEnabled(userData.isTeleportEnabled());
user.queueSave();
}
}
}
private String getRealName(String name)
{
String realname = getPlayer(name);
return realname == null ? BROKENNAME : realname;
}
private final Map<String, String> players = new HashMap<String, String>();
private String getPlayer(String check)
{
synchronized (players)
{
if (players.isEmpty())
{
File worldFolder = ess.getServer().getWorlds().get(0).getWorldFolder();
File playersFolder = new File(worldFolder, "players");
for (String filename : playersFolder.list(new PatternFilenameFilter(".+\\.dat")))
{
String name = filename.substring(0, filename.length() - 4).toLowerCase(Locale.ENGLISH);
String sanitizedName = Util.sanitizeFileName(name);
String mapName = players.get(sanitizedName);
if (mapName != null && !mapName.equals(name))
{
players.put(sanitizedName, BROKENNAME);
}
else
{
players.put(sanitizedName, name);
}
}
}
}
return players.get(check);
}
}
|