a few fixes & optimizations

This commit is contained in:
9378062 2022-04-07 13:12:38 -04:00
parent 1496e5a55c
commit 3666379645
4 changed files with 32 additions and 8 deletions

View File

@ -17,10 +17,8 @@ import java.util.stream.Collectors;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;

View File

@ -18,6 +18,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.List; import java.util.List;
public class SpawnListener extends PlexListener public class SpawnListener extends PlexListener
@ -31,10 +32,8 @@ public class SpawnListener extends PlexListener
{ {
event.setCancelled(true); event.setCancelled(true);
Location location = event.getLocation(); Location location = event.getLocation();
for (Player player : location.getNearbyEntitiesByType(Player.class, 10)) Collection<Player> coll = location.getNearbyEntitiesByType(Player.class, 10);
{ PlexUtils.disabledEffectMultiple(coll.toArray(new Player[coll.size()]), location); // dont let intellij auto correct toArray to an empty array (for efficiency)
PlexUtils.disabledEffect(player, location);
}
} }
} }

View File

@ -74,6 +74,15 @@ public class PlexUtils extends PlexBase
player.playSound(location, org.bukkit.Sound.BLOCK_FIRE_EXTINGUISH, 0.5f, 0.5f); player.playSound(location, org.bukkit.Sound.BLOCK_FIRE_EXTINGUISH, 0.5f, 0.5f);
} }
public static void disabledEffectMultiple(Player[] players, Location location)
{
Particle.CLOUD.builder().location(location).receivers(players).extra(0).offset(0.5,0.5,0.5).count(5).spawn();
Particle.FLAME.builder().location(location).receivers(players).extra(0).offset(0.5,0.5,0.5).count(3).spawn();
Particle.SOUL_FIRE_FLAME.builder().location(location).receivers(players).offset(0.5,0.5,0.5).extra(0).count(2).spawn();
// note that the sound is played to everyone who is close enough to hear it
players[0].getWorld().playSound(location, org.bukkit.Sound.BLOCK_FIRE_EXTINGUISH, 0.5f, 0.5f);
}
public static ChatColor randomChatColor() public static ChatColor randomChatColor()
{ {
return CHAT_COLOR_POOL.get(RANDOM.nextInt(CHAT_COLOR_POOL.size())); return CHAT_COLOR_POOL.get(RANDOM.nextInt(CHAT_COLOR_POOL.size()));

View File

@ -8,6 +8,7 @@ import dev.plex.Plex;
import dev.plex.PlexBase; import dev.plex.PlexBase;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
@ -135,6 +136,23 @@ public class UpdateChecker extends PlexBase
} }
public void updateJar() public void updateJar()
{
updateJar(null);
}
private void sendOrLog(CommandSender sender, String message)
{
if (sender == null)
{
PlexLog.log(message);
}
else
{
sender.sendMessage(MiniMessage.miniMessage().deserialize(message));
}
}
public void updateJar(CommandSender sender)
{ {
CloseableHttpClient client = HttpClients.createDefault(); CloseableHttpClient client = HttpClients.createDefault();
HttpGet get = new HttpGet(DOWNLOAD_PAGE + "job/master/lastSuccessfulBuild/api/json"); HttpGet get = new HttpGet(DOWNLOAD_PAGE + "job/master/lastSuccessfulBuild/api/json");
@ -144,7 +162,7 @@ public class UpdateChecker extends PlexBase
JSONObject object = new JSONObject(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8)); JSONObject object = new JSONObject(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8));
JSONObject artifact = object.getJSONArray("artifacts").getJSONObject(0); JSONObject artifact = object.getJSONArray("artifacts").getJSONObject(0);
String name = artifact.getString("fileName"); String name = artifact.getString("fileName");
PlexLog.log("Downloading latest Plex jar file: " + name); sendOrLog(sender, "Downloading latest Plex jar file: " + name);
CompletableFuture.runAsync(() -> CompletableFuture.runAsync(() ->
{ {
try try
@ -153,7 +171,7 @@ public class UpdateChecker extends PlexBase
new URL(DOWNLOAD_PAGE + "job/master/lastSuccessfulBuild/artifact/build/libs/" + name), new URL(DOWNLOAD_PAGE + "job/master/lastSuccessfulBuild/artifact/build/libs/" + name),
new File(Bukkit.getUpdateFolderFile(), name) new File(Bukkit.getUpdateFolderFile(), name)
); );
PlexLog.log("Saved new jar. Please restart your server."); sendOrLog(sender, "Saved new jar. Please restart your server.");
} }
catch (IOException e) catch (IOException e)
{ {