Async changes & Bug fixes

Made diamond radius search async
Fixed join listener firing accept twice
master
Etzelia 2018-09-15 00:37:09 -05:00
parent 0920ecce90
commit 7cdf9509ae
4 changed files with 31 additions and 31 deletions

View File

@ -160,6 +160,14 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,11 +1,11 @@
package xyz.etztech.minecraftmanager.listeners;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -45,7 +45,9 @@ public class AsyncPlayerChatListener implements Listener {
String chat = event.getMessage();
boolean applyChat = MinecraftManager.inApplyMode(sender.getUniqueId().toString());
TextComponent pre = new TextComponent(ChatColor.GOLD + sender.getName() + " > ");
ComponentBuilder message = new ComponentBuilder("");
message.append(sender.getName() + " > ").color(ChatColor.GOLD);
if (!applyChat) {
boolean hasPermission = sender.hasPermission("minecraftmanager.staff");
boolean singlePrefix = false;
@ -65,19 +67,18 @@ public class AsyncPlayerChatListener implements Listener {
chat = chat.replaceFirst(Pattern.quote(prefix), "");
}
HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Staff Chat").create());
pre.setHoverEvent(hover);
TextComponent message = generateMessage(chat);
message.setHoverEvent(hover);
message.event(hover);
message.append(chat).color(ChatColor.GREEN).event(hover);
for (Player player : event.getRecipients()) {
if (player.hasPermission("minecraftmanager.staff")) {
player.spigot().sendMessage(pre, message);
player.spigot().sendMessage(message.create());
}
}
MCMUtil.log(MCMUtil.staffLog, componentText(pre, message));
MCMUtil.log(MCMUtil.staffLog, componentText(message.create()));
} else {
TextComponent message = generateMessage(chat);
message.append(chat);
if (!MinecraftManager.getLogOverride()) {
MCMUtil.log(MCMUtil.globalLog, componentText(pre, message));
MCMUtil.log(MCMUtil.globalLog, componentText(message.create()));
}
}
} else {
@ -153,13 +154,7 @@ public class AsyncPlayerChatListener implements Listener {
}
private TextComponent generateMessage(String message) {
TextComponent text = new TextComponent();
for (String part : message.split(" ")) {
text.addExtra(new TextComponent(ChatColor.GREEN + part + " "));
}
return text;
}
private List<String> trimmed(List<String> list) {
for (int i = 0; i < list.size(); i++) {

View File

@ -1,5 +1,6 @@
package xyz.etztech.minecraftmanager.listeners;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@ -25,15 +26,19 @@ public class BlockBreakListener implements Listener {
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
boolean isDiamond = Material.DIAMOND_ORE == block.getType();
if (isDiamond) {
boolean notify = MinecraftManager.addDiamond(getLocationString(block));
for (Block radiusBlock : getBlocks(block, 5)) {
MinecraftManager.addDiamond(getLocationString(radiusBlock));
}
if (notify) {
if (Material.DIAMOND_ORE == block.getType()) {
if (MinecraftManager.addDiamond(getLocationString(block))) {
plugin.log("[OreAlert]: " + event.getPlayer().getName());
}
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
for (Block radiusBlock : getBlocks(block, 5)) {
if (Material.DIAMOND_ORE == radiusBlock.getType()) {
MinecraftManager.addDiamond(getLocationString(radiusBlock));
}
}
});
}
}

View File

@ -45,14 +45,6 @@ public class SessionListener implements Listener {
Map<String, String> filters = MCMAPI.setup();
filters.put("username__iexact", player.getName());
CoreWeb.asyncGetCallback(plugin, MCMAPI.getModelUrl("application"), filters, new JoinCallback(player.getName()));
JsonArray query = MCMAPI.queryModel("application", filters);
if (query.size() == 1) {
JsonElement element = query.get(0).getAsJsonObject().get("accepted");
boolean accepted = !element.isJsonNull() && element.getAsBoolean();
if (accepted) {
MinecraftManagerThread.action(player.getName(), true);
}
}
}
}