mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
a few fixes & optimizations
This commit is contained in:
parent
1496e5a55c
commit
3666379645
@ -17,10 +17,8 @@ import java.util.stream.Collectors;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -18,6 +18,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class SpawnListener extends PlexListener
|
||||
@ -31,10 +32,8 @@ public class SpawnListener extends PlexListener
|
||||
{
|
||||
event.setCancelled(true);
|
||||
Location location = event.getLocation();
|
||||
for (Player player : location.getNearbyEntitiesByType(Player.class, 10))
|
||||
{
|
||||
PlexUtils.disabledEffect(player, location);
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,6 +74,15 @@ public class PlexUtils extends PlexBase
|
||||
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()
|
||||
{
|
||||
return CHAT_COLOR_POOL.get(RANDOM.nextInt(CHAT_COLOR_POOL.size()));
|
||||
|
@ -8,6 +8,7 @@ import dev.plex.Plex;
|
||||
import dev.plex.PlexBase;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
@ -135,6 +136,23 @@ public class UpdateChecker extends PlexBase
|
||||
}
|
||||
|
||||
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();
|
||||
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 artifact = object.getJSONArray("artifacts").getJSONObject(0);
|
||||
String name = artifact.getString("fileName");
|
||||
PlexLog.log("Downloading latest Plex jar file: " + name);
|
||||
sendOrLog(sender, "Downloading latest Plex jar file: " + name);
|
||||
CompletableFuture.runAsync(() ->
|
||||
{
|
||||
try
|
||||
@ -153,7 +171,7 @@ public class UpdateChecker extends PlexBase
|
||||
new URL(DOWNLOAD_PAGE + "job/master/lastSuccessfulBuild/artifact/build/libs/" + 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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user