Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3080bae
Improve alternate uuid lookup
BenCodez Sep 10, 2017
5906583
Improve broadcasts
BenCodez Sep 10, 2017
860df94
Performance improvements
BenCodez Sep 10, 2017
cccb347
Add chance support for priority system, closes #83
BenCodez Sep 10, 2017
fc7f277
Mysql improvement
BenCodez Sep 17, 2017
c4137f0
Improve batch updates
BenCodez Sep 17, 2017
b270a19
Bug fix
BenCodez Sep 17, 2017
7e376a6
Bug fix
BenCodez Sep 17, 2017
f498574
Add more debug for testing
BenCodez Sep 17, 2017
94965a7
Bug fix
BenCodez Sep 17, 2017
7d8044b
Bug fix
BenCodez Sep 17, 2017
a26be69
Bug fix
BenCodez Sep 17, 2017
613f174
Bug fix
BenCodez Sep 17, 2017
ae84f5d
Bug fix
BenCodez Sep 17, 2017
08b8b29
Bug fix
BenCodez Sep 17, 2017
a6f5af7
Bug fix
BenCodez Sep 17, 2017
081be81
Bug fix
BenCodez Sep 17, 2017
beaa09e
Bug fix
BenCodez Sep 17, 2017
03671bb
Bug fix
BenCodez Sep 17, 2017
af7beca
Bug fix
BenCodez Sep 17, 2017
30b17ea
Bug fix
BenCodez Sep 17, 2017
34988b1
Increase timeout
BenCodez Sep 17, 2017
8ef0ab4
Bug fix
BenCodez Sep 17, 2017
c766408
Improvements
BenCodez Sep 17, 2017
fa63abe
Bug fix
BenCodez Sep 17, 2017
0954e6c
Bug fix
BenCodez Sep 17, 2017
fdeb5e6
Bug fix
BenCodez Sep 17, 2017
596d687
Bug fix
BenCodez Sep 17, 2017
3668f9b
Bug fix
BenCodez Sep 17, 2017
3d2efe0
Bug fix
BenCodez Sep 17, 2017
fce7041
Improvements
BenCodez Sep 17, 2017
d016b08
Bug fixes
BenCodez Sep 17, 2017
c861565
Bug fixes
BenCodez Sep 17, 2017
4ac0d20
Add extra debug
BenCodez Sep 22, 2017
0f3480e
Minor improvement
BenCodez Sep 22, 2017
29684ea
Update version number
BenCodez Sep 22, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AdvancedCore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.Ben12345rocks</groupId>
<artifactId>AdvancedCore</artifactId>
<version>2.9</version>
<version>2.9.1</version>
<packaging>jar</packaging>
<name>AdvancedCore</name>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.HashMap;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

Expand All @@ -29,6 +30,8 @@
import com.Ben12345rocks.AdvancedCore.Listeners.PluginUpdateVersionEvent;
import com.Ben12345rocks.AdvancedCore.Listeners.WorldChangeEvent;
import com.Ben12345rocks.AdvancedCore.Objects.RewardHandler;
import com.Ben12345rocks.AdvancedCore.Objects.UUID;
import com.Ben12345rocks.AdvancedCore.Objects.User;
import com.Ben12345rocks.AdvancedCore.Objects.UserStorage;
import com.Ben12345rocks.AdvancedCore.ServerHandle.CraftBukkitHandle;
import com.Ben12345rocks.AdvancedCore.ServerHandle.IServerHandle;
Expand All @@ -55,6 +58,8 @@ public static AdvancedCoreHook getInstance() {
return instance;
}

private ConcurrentHashMap<String, String> uuids;

private JavaPlugin plugin;
private boolean placeHolderAPIEnabled;
private boolean timerLoaded = false;
Expand Down Expand Up @@ -219,7 +224,9 @@ public void extraDebug(Plugin plug, String msg) {
}

public void extraDebug(String msg) {
debug(plugin, "[Extra] " + msg);
if (extraDebug) {
debug(plugin, "[Extra] " + msg);
}
}

public String getDefaultRequestMethod() {
Expand Down Expand Up @@ -448,6 +455,7 @@ public void run() {
*/
public void loadBasicHook(JavaPlugin plugin) {
this.plugin = plugin;
loadUUIDs();
permPrefix = plugin.getName();
checkPlaceHolderAPI();
loadHandle();
Expand Down Expand Up @@ -495,6 +503,7 @@ private void loadHandle() {
*/
public void loadHook(JavaPlugin plugin) {
this.plugin = plugin;
loadUUIDs();
permPrefix = plugin.getName();
loadUserAPI(UserStorage.SQLITE);
checkPlaceHolderAPI();
Expand All @@ -512,6 +521,28 @@ public void loadHook(JavaPlugin plugin) {
debug("Using AdvancedCore '" + getVersion() + "' built on '" + getTime() + "'");
}

public ConcurrentHashMap<String, String> getUuids() {
return uuids;
}

private void loadUUIDs() {
uuids = new ConcurrentHashMap<String, String>();
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {

@Override
public void run() {
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
User user = UserManager.getInstance().getUser(new UUID(uuid));
String name = user.getData().getString("PlayerName");
if (uuids.containsKey(name)) {
debug("Duplicate uuid? " + uuid + ":" + name + " Other key: " + uuids.get(name));
}
uuids.put(name, uuid);
}
}
});
}

/**
* Load logger
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,14 @@ public void givePriorityReward(User user, final HashMap<String, String> placehol
for (String str : getPriority()) {
Reward reward = RewardHandler.getInstance().getReward(str);
if (reward.canGiveReward(user)) {
new RewardBuilder(reward).withPlaceHolder(placeholders).send(user);
new RewardBuilder(reward).withPlaceHolder(placeholders).ignoreChance(true).send(user);
return;
}
}
}

public boolean canGiveReward(User user) {
if (hasPermission(user)) {
if (hasPermission(user) && checkChance()) {
return true;
}
return false;
Expand Down Expand Up @@ -1022,6 +1022,11 @@ public void giveReward(User user, boolean online, boolean giveOffline, boolean c
giveReward(user, online, giveOffline, checkTimed, null);
}

public void giveReward(User user, boolean online, boolean giveOffline, boolean checkTimed,
HashMap<String, String> placeholders) {
giveReward(user, online, giveOffline, checkTimed, false, placeholders);
}

/**
* Give reward.
*
Expand All @@ -1036,7 +1041,7 @@ public void giveReward(User user, boolean online, boolean giveOffline, boolean c
* @param placeholders
* placeholders
*/
public void giveReward(User user, boolean online, boolean giveOffline, boolean checkTimed,
public void giveReward(User user, boolean online, boolean giveOffline, boolean checkTimed, boolean ignoreChance,
HashMap<String, String> placeholders) {

PlayerRewardEvent event = new PlayerRewardEvent(this, user);
Expand Down Expand Up @@ -1064,7 +1069,7 @@ public void giveReward(User user, boolean online, boolean giveOffline, boolean c
return;
}

giveRewardReward(user, online, placeholders);
giveRewardReward(user, online, ignoreChance, placeholders);
}

/**
Expand All @@ -1077,7 +1082,8 @@ public void giveReward(User user, boolean online, boolean giveOffline, boolean c
* @param placeholders
* placeholders
*/
public void giveRewardReward(User user, boolean online, HashMap<String, String> placeholders) {
public void giveRewardReward(User user, boolean online, boolean ignoreChance,
HashMap<String, String> placeholders) {
plugin.debug("Attempting to give " + user.getPlayerName() + " reward " + name);

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

if (checkChance()) {
if (ignoreChance || checkChance()) {
giveRewardUser(user, placeholders);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class RewardBuilder {
private boolean giveOffline;
private boolean online;
private boolean checkTimed = true;
private boolean ignoreChance;

public RewardBuilder(FileConfiguration data, String path) {
this.data = data;
Expand Down Expand Up @@ -85,10 +86,10 @@ public boolean isOnline() {
public void send(User user) {
if (reward == null) {
RewardHandler.getInstance().giveReward(user, prefix, data, path, online, giveOffline, checkTimed,
placeholders);
ignoreChance, placeholders);
} else {
RewardHandler.getInstance().giveReward(user, reward, isGiveOffline(), isGiveOffline(), checkTimed,
placeholders);
ignoreChance, placeholders);
}
}

Expand Down Expand Up @@ -136,4 +137,9 @@ public RewardBuilder withPrefix(String prefix) {
return this;
}

public RewardBuilder ignoreChance(boolean ignoreChance) {
this.ignoreChance = ignoreChance;
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,18 @@ public void run() {
});
}

@Deprecated
public void giveReward(User user, Reward reward, boolean online, boolean giveOffline, boolean checkTimed,
boolean ignoreChance, HashMap<String, String> placeholders) {
Bukkit.getScheduler().runTaskAsynchronously(plugin.getPlugin(), new Runnable() {

@Override
public void run() {
reward.giveReward(user, online, giveOffline, checkTimed, ignoreChance, placeholders);
}
});
}

@Deprecated
public void giveReward(User user, String reward) {
if (!reward.equals("")) {
Expand Down Expand Up @@ -332,6 +344,14 @@ public void giveReward(User user, String reward, boolean online, boolean giveOff
}
}

@Deprecated
public void giveReward(User user, String reward, boolean online, boolean giveOffline, boolean checkTimed,
boolean ignoreChance, HashMap<String, String> placeholders) {
if (!reward.equals("")) {
giveReward(user, getReward(reward), online, giveOffline, checkTimed, ignoreChance, placeholders);
}
}

public void giveReward(User user, String prefix, FileConfiguration data, String path) {
giveReward(user, prefix, data, path, user.isOnline(), true);
}
Expand All @@ -345,12 +365,17 @@ public void giveReward(User user, String prefix, FileConfiguration data, String
giveReward(user, prefix, data, path, online, giveOffline, null);
}

@SuppressWarnings("unchecked")
public void giveReward(User user, String prefix, FileConfiguration data, String path, boolean online,
boolean giveOffline, boolean checkTimed, HashMap<String, String> placeholders) {
giveReward(user, prefix, data, path, online, giveOffline, checkTimed, false, placeholders);
}

@SuppressWarnings("unchecked")
public void giveReward(User user, String prefix, FileConfiguration data, String path, boolean online,
boolean giveOffline, boolean checkTimed, boolean ignoreChance, HashMap<String, String> placeholders) {
if (data.isList(path)) {
for (String reward : (ArrayList<String>) data.getList(path, new ArrayList<String>())) {
giveReward(user, reward, online, giveOffline, checkTimed, placeholders);
giveReward(user, reward, online, giveOffline, checkTimed, ignoreChance, placeholders);
}
} else if (data.isConfigurationSection(path)) {
String rewardName = "";
Expand All @@ -367,10 +392,10 @@ public void giveReward(User user, String prefix, FileConfiguration data, String
}
reward.getConfig().setData(section);
updateReward(reward);
giveReward(user, rewardName, online, giveOffline, checkTimed, placeholders);
giveReward(user, rewardName, online, giveOffline, checkTimed, ignoreChance, placeholders);

} else {
giveReward(user, data.getString(path, ""), online, giveOffline, checkTimed, placeholders);
giveReward(user, data.getString(path, ""), online, giveOffline, checkTimed, ignoreChance, placeholders);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,10 @@ public void broadcast(String broadcastMsg) {
if (broadcastMsg != null) {
if (!broadcastMsg.equals("")) {
for (Player player : Bukkit.getOnlinePlayers()) {
final String msg = StringUtils.getInstance()
String msg = StringUtils.getInstance()
.colorize(StringUtils.getInstance().replacePlaceHolders(player, broadcastMsg));
Bukkit.getScheduler().runTask(plugin.getPlugin(), new Runnable() {
player.sendMessage(msg);

@Override
public void run() {
player.sendMessage(msg);
}
});
}
}
}
Expand Down Expand Up @@ -83,15 +78,17 @@ public void executeConsoleCommands(final Player player, final ArrayList<String>
placeholders.put("player", player.getName());
final ArrayList<String> commands = ArrayUtils.getInstance().replaceJavascript(player,
ArrayUtils.getInstance().replacePlaceHolder(cmds, placeholders));
Bukkit.getScheduler().runTask(plugin.getPlugin(), new Runnable() {
for (final String cmd : commands) {
Bukkit.getScheduler().runTask(plugin.getPlugin(), new Runnable() {

@Override
public void run() {
for (String cmd : commands) {
@Override
public void run() {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd);
}
}
});

});
}

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.Ben12345rocks.AdvancedCore.Util.Misc;

import java.util.concurrent.ConcurrentHashMap;

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -125,23 +127,28 @@ public String getUUID(String playerName) {
if (playerName == null) {
return null;
}

if (plugin.isAlternateUUIDLookUp()) {

OfflinePlayer p = Bukkit.getOfflinePlayer(playerName);

if (plugin.isAlternateUUIDLookUp() || (!p.hasPlayedBefore() && !p.isOnline())) {
ConcurrentHashMap<String, String> uuids = plugin.getUuids();
if (uuids != null) {
String uuid = uuids.get(playerName);
if (uuid != null) {
return uuid;
}
}
for (String uuid : UserManager.getInstance().getAllUUIDs()) {
User user = UserManager.getInstance().getUser(new UUID(uuid));
String name = user.getData().getString("PlayerName");
if (name.equals(playerName)) {
plugin.getUuids().put(playerName, uuid);
return uuid;
}
}
}

Player player = Bukkit.getPlayer(playerName);
if (player == null) {
return Bukkit.getOfflinePlayer(playerName).getUniqueId().toString();
} else {
return player.getUniqueId().toString();
}
return p.getUniqueId().toString();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ public boolean isInt(String st) {
return false;
}
}

public boolean isDouble(String st) {
try {
@SuppressWarnings("unused")
double num = Double.parseDouble(st);
return true;

} catch (NumberFormatException ex) {
return false;
}
}

/**
* Replace ignore case.
Expand Down
Loading