Skip to content

Commit 16aee95

Browse files
authored
Merge pull request #84 from Ben12345rocks/2.9.1
2.9.1
2 parents fb381c5 + 29684ea commit 16aee95

File tree

10 files changed

+183
-58
lines changed

10 files changed

+183
-58
lines changed

AdvancedCore/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.Ben12345rocks</groupId>
55
<artifactId>AdvancedCore</artifactId>
6-
<version>2.9</version>
6+
<version>2.9.1</version>
77
<packaging>jar</packaging>
88
<name>AdvancedCore</name>
99
<properties>

AdvancedCore/src/com/Ben12345rocks/AdvancedCore/AdvancedCoreHook.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.HashMap;
1313
import java.util.Timer;
1414
import java.util.TimerTask;
15+
import java.util.concurrent.ConcurrentHashMap;
1516
import java.util.zip.ZipEntry;
1617
import java.util.zip.ZipInputStream;
1718

@@ -29,6 +30,8 @@
2930
import com.Ben12345rocks.AdvancedCore.Listeners.PluginUpdateVersionEvent;
3031
import com.Ben12345rocks.AdvancedCore.Listeners.WorldChangeEvent;
3132
import com.Ben12345rocks.AdvancedCore.Objects.RewardHandler;
33+
import com.Ben12345rocks.AdvancedCore.Objects.UUID;
34+
import com.Ben12345rocks.AdvancedCore.Objects.User;
3235
import com.Ben12345rocks.AdvancedCore.Objects.UserStorage;
3336
import com.Ben12345rocks.AdvancedCore.ServerHandle.CraftBukkitHandle;
3437
import com.Ben12345rocks.AdvancedCore.ServerHandle.IServerHandle;
@@ -55,6 +58,8 @@ public static AdvancedCoreHook getInstance() {
5558
return instance;
5659
}
5760

61+
private ConcurrentHashMap<String, String> uuids;
62+
5863
private JavaPlugin plugin;
5964
private boolean placeHolderAPIEnabled;
6065
private boolean timerLoaded = false;
@@ -219,7 +224,9 @@ public void extraDebug(Plugin plug, String msg) {
219224
}
220225

221226
public void extraDebug(String msg) {
222-
debug(plugin, "[Extra] " + msg);
227+
if (extraDebug) {
228+
debug(plugin, "[Extra] " + msg);
229+
}
223230
}
224231

225232
public String getDefaultRequestMethod() {
@@ -448,6 +455,7 @@ public void run() {
448455
*/
449456
public void loadBasicHook(JavaPlugin plugin) {
450457
this.plugin = plugin;
458+
loadUUIDs();
451459
permPrefix = plugin.getName();
452460
checkPlaceHolderAPI();
453461
loadHandle();
@@ -495,6 +503,7 @@ private void loadHandle() {
495503
*/
496504
public void loadHook(JavaPlugin plugin) {
497505
this.plugin = plugin;
506+
loadUUIDs();
498507
permPrefix = plugin.getName();
499508
loadUserAPI(UserStorage.SQLITE);
500509
checkPlaceHolderAPI();
@@ -512,6 +521,28 @@ public void loadHook(JavaPlugin plugin) {
512521
debug("Using AdvancedCore '" + getVersion() + "' built on '" + getTime() + "'");
513522
}
514523

524+
public ConcurrentHashMap<String, String> getUuids() {
525+
return uuids;
526+
}
527+
528+
private void loadUUIDs() {
529+
uuids = new ConcurrentHashMap<String, String>();
530+
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
531+
532+
@Override
533+
public void run() {
534+
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
535+
User user = UserManager.getInstance().getUser(new UUID(uuid));
536+
String name = user.getData().getString("PlayerName");
537+
if (uuids.containsKey(name)) {
538+
debug("Duplicate uuid? " + uuid + ":" + name + " Other key: " + uuids.get(name));
539+
}
540+
uuids.put(name, uuid);
541+
}
542+
}
543+
});
544+
}
545+
515546
/**
516547
* Load logger
517548
*/

AdvancedCore/src/com/Ben12345rocks/AdvancedCore/Objects/Reward.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,14 @@ public void givePriorityReward(User user, final HashMap<String, String> placehol
341341
for (String str : getPriority()) {
342342
Reward reward = RewardHandler.getInstance().getReward(str);
343343
if (reward.canGiveReward(user)) {
344-
new RewardBuilder(reward).withPlaceHolder(placeholders).send(user);
344+
new RewardBuilder(reward).withPlaceHolder(placeholders).ignoreChance(true).send(user);
345345
return;
346346
}
347347
}
348348
}
349349

350350
public boolean canGiveReward(User user) {
351-
if (hasPermission(user)) {
351+
if (hasPermission(user) && checkChance()) {
352352
return true;
353353
}
354354
return false;
@@ -1022,6 +1022,11 @@ public void giveReward(User user, boolean online, boolean giveOffline, boolean c
10221022
giveReward(user, online, giveOffline, checkTimed, null);
10231023
}
10241024

1025+
public void giveReward(User user, boolean online, boolean giveOffline, boolean checkTimed,
1026+
HashMap<String, String> placeholders) {
1027+
giveReward(user, online, giveOffline, checkTimed, false, placeholders);
1028+
}
1029+
10251030
/**
10261031
* Give reward.
10271032
*
@@ -1036,7 +1041,7 @@ public void giveReward(User user, boolean online, boolean giveOffline, boolean c
10361041
* @param placeholders
10371042
* placeholders
10381043
*/
1039-
public void giveReward(User user, boolean online, boolean giveOffline, boolean checkTimed,
1044+
public void giveReward(User user, boolean online, boolean giveOffline, boolean checkTimed, boolean ignoreChance,
10401045
HashMap<String, String> placeholders) {
10411046

10421047
PlayerRewardEvent event = new PlayerRewardEvent(this, user);
@@ -1064,7 +1069,7 @@ public void giveReward(User user, boolean online, boolean giveOffline, boolean c
10641069
return;
10651070
}
10661071

1067-
giveRewardReward(user, online, placeholders);
1072+
giveRewardReward(user, online, ignoreChance, placeholders);
10681073
}
10691074

10701075
/**
@@ -1077,7 +1082,8 @@ public void giveReward(User user, boolean online, boolean giveOffline, boolean c
10771082
* @param placeholders
10781083
* placeholders
10791084
*/
1080-
public void giveRewardReward(User user, boolean online, HashMap<String, String> placeholders) {
1085+
public void giveRewardReward(User user, boolean online, boolean ignoreChance,
1086+
HashMap<String, String> placeholders) {
10811087
plugin.debug("Attempting to give " + user.getPlayerName() + " reward " + name);
10821088

10831089
String type = getRewardType();
@@ -1093,7 +1099,7 @@ public void giveRewardReward(User user, boolean online, HashMap<String, String>
10931099
}
10941100
}
10951101

1096-
if (checkChance()) {
1102+
if (ignoreChance || checkChance()) {
10971103
giveRewardUser(user, placeholders);
10981104
}
10991105
}

AdvancedCore/src/com/Ben12345rocks/AdvancedCore/Objects/RewardBuilder.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class RewardBuilder {
1717
private boolean giveOffline;
1818
private boolean online;
1919
private boolean checkTimed = true;
20+
private boolean ignoreChance;
2021

2122
public RewardBuilder(FileConfiguration data, String path) {
2223
this.data = data;
@@ -85,10 +86,10 @@ public boolean isOnline() {
8586
public void send(User user) {
8687
if (reward == null) {
8788
RewardHandler.getInstance().giveReward(user, prefix, data, path, online, giveOffline, checkTimed,
88-
placeholders);
89+
ignoreChance, placeholders);
8990
} else {
9091
RewardHandler.getInstance().giveReward(user, reward, isGiveOffline(), isGiveOffline(), checkTimed,
91-
placeholders);
92+
ignoreChance, placeholders);
9293
}
9394
}
9495

@@ -136,4 +137,9 @@ public RewardBuilder withPrefix(String prefix) {
136137
return this;
137138
}
138139

140+
public RewardBuilder ignoreChance(boolean ignoreChance) {
141+
this.ignoreChance = ignoreChance;
142+
return this;
143+
}
144+
139145
}

AdvancedCore/src/com/Ben12345rocks/AdvancedCore/Objects/RewardHandler.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,18 @@ public void run() {
276276
});
277277
}
278278

279+
@Deprecated
280+
public void giveReward(User user, Reward reward, boolean online, boolean giveOffline, boolean checkTimed,
281+
boolean ignoreChance, HashMap<String, String> placeholders) {
282+
Bukkit.getScheduler().runTaskAsynchronously(plugin.getPlugin(), new Runnable() {
283+
284+
@Override
285+
public void run() {
286+
reward.giveReward(user, online, giveOffline, checkTimed, ignoreChance, placeholders);
287+
}
288+
});
289+
}
290+
279291
@Deprecated
280292
public void giveReward(User user, String reward) {
281293
if (!reward.equals("")) {
@@ -332,6 +344,14 @@ public void giveReward(User user, String reward, boolean online, boolean giveOff
332344
}
333345
}
334346

347+
@Deprecated
348+
public void giveReward(User user, String reward, boolean online, boolean giveOffline, boolean checkTimed,
349+
boolean ignoreChance, HashMap<String, String> placeholders) {
350+
if (!reward.equals("")) {
351+
giveReward(user, getReward(reward), online, giveOffline, checkTimed, ignoreChance, placeholders);
352+
}
353+
}
354+
335355
public void giveReward(User user, String prefix, FileConfiguration data, String path) {
336356
giveReward(user, prefix, data, path, user.isOnline(), true);
337357
}
@@ -345,12 +365,17 @@ public void giveReward(User user, String prefix, FileConfiguration data, String
345365
giveReward(user, prefix, data, path, online, giveOffline, null);
346366
}
347367

348-
@SuppressWarnings("unchecked")
349368
public void giveReward(User user, String prefix, FileConfiguration data, String path, boolean online,
350369
boolean giveOffline, boolean checkTimed, HashMap<String, String> placeholders) {
370+
giveReward(user, prefix, data, path, online, giveOffline, checkTimed, false, placeholders);
371+
}
372+
373+
@SuppressWarnings("unchecked")
374+
public void giveReward(User user, String prefix, FileConfiguration data, String path, boolean online,
375+
boolean giveOffline, boolean checkTimed, boolean ignoreChance, HashMap<String, String> placeholders) {
351376
if (data.isList(path)) {
352377
for (String reward : (ArrayList<String>) data.getList(path, new ArrayList<String>())) {
353-
giveReward(user, reward, online, giveOffline, checkTimed, placeholders);
378+
giveReward(user, reward, online, giveOffline, checkTimed, ignoreChance, placeholders);
354379
}
355380
} else if (data.isConfigurationSection(path)) {
356381
String rewardName = "";
@@ -367,10 +392,10 @@ public void giveReward(User user, String prefix, FileConfiguration data, String
367392
}
368393
reward.getConfig().setData(section);
369394
updateReward(reward);
370-
giveReward(user, rewardName, online, giveOffline, checkTimed, placeholders);
395+
giveReward(user, rewardName, online, giveOffline, checkTimed, ignoreChance, placeholders);
371396

372397
} else {
373-
giveReward(user, data.getString(path, ""), online, giveOffline, checkTimed, placeholders);
398+
giveReward(user, data.getString(path, ""), online, giveOffline, checkTimed, ignoreChance, placeholders);
374399
}
375400
}
376401

AdvancedCore/src/com/Ben12345rocks/AdvancedCore/Util/Misc/MiscUtils.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,10 @@ public void broadcast(String broadcastMsg) {
4747
if (broadcastMsg != null) {
4848
if (!broadcastMsg.equals("")) {
4949
for (Player player : Bukkit.getOnlinePlayers()) {
50-
final String msg = StringUtils.getInstance()
50+
String msg = StringUtils.getInstance()
5151
.colorize(StringUtils.getInstance().replacePlaceHolders(player, broadcastMsg));
52-
Bukkit.getScheduler().runTask(plugin.getPlugin(), new Runnable() {
52+
player.sendMessage(msg);
5353

54-
@Override
55-
public void run() {
56-
player.sendMessage(msg);
57-
}
58-
});
5954
}
6055
}
6156
}
@@ -83,15 +78,17 @@ public void executeConsoleCommands(final Player player, final ArrayList<String>
8378
placeholders.put("player", player.getName());
8479
final ArrayList<String> commands = ArrayUtils.getInstance().replaceJavascript(player,
8580
ArrayUtils.getInstance().replacePlaceHolder(cmds, placeholders));
86-
Bukkit.getScheduler().runTask(plugin.getPlugin(), new Runnable() {
81+
for (final String cmd : commands) {
82+
Bukkit.getScheduler().runTask(plugin.getPlugin(), new Runnable() {
8783

88-
@Override
89-
public void run() {
90-
for (String cmd : commands) {
84+
@Override
85+
public void run() {
9186
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd);
9287
}
93-
}
94-
});
88+
89+
});
90+
}
91+
9592
}
9693
}
9794

AdvancedCore/src/com/Ben12345rocks/AdvancedCore/Util/Misc/PlayerUtils.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.Ben12345rocks.AdvancedCore.Util.Misc;
22

3+
import java.util.concurrent.ConcurrentHashMap;
4+
35
import org.bukkit.Bukkit;
46
import org.bukkit.OfflinePlayer;
57
import org.bukkit.command.CommandSender;
@@ -125,23 +127,28 @@ public String getUUID(String playerName) {
125127
if (playerName == null) {
126128
return null;
127129
}
128-
129-
if (plugin.isAlternateUUIDLookUp()) {
130+
131+
OfflinePlayer p = Bukkit.getOfflinePlayer(playerName);
132+
133+
if (plugin.isAlternateUUIDLookUp() || (!p.hasPlayedBefore() && !p.isOnline())) {
134+
ConcurrentHashMap<String, String> uuids = plugin.getUuids();
135+
if (uuids != null) {
136+
String uuid = uuids.get(playerName);
137+
if (uuid != null) {
138+
return uuid;
139+
}
140+
}
130141
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
131142
User user = UserManager.getInstance().getUser(new UUID(uuid));
132143
String name = user.getData().getString("PlayerName");
133144
if (name.equals(playerName)) {
145+
plugin.getUuids().put(playerName, uuid);
134146
return uuid;
135147
}
136148
}
137149
}
138150

139-
Player player = Bukkit.getPlayer(playerName);
140-
if (player == null) {
141-
return Bukkit.getOfflinePlayer(playerName).getUniqueId().toString();
142-
} else {
143-
return player.getUniqueId().toString();
144-
}
151+
return p.getUniqueId().toString();
145152

146153
}
147154

AdvancedCore/src/com/Ben12345rocks/AdvancedCore/Util/Misc/StringUtils.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ public boolean isInt(String st) {
8585
return false;
8686
}
8787
}
88+
89+
public boolean isDouble(String st) {
90+
try {
91+
@SuppressWarnings("unused")
92+
double num = Double.parseDouble(st);
93+
return true;
94+
95+
} catch (NumberFormatException ex) {
96+
return false;
97+
}
98+
}
8899

89100
/**
90101
* Replace ignore case.

0 commit comments

Comments
 (0)