Skip to content

Commit

Permalink
Small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Apr 4, 2024
1 parent e924834 commit b5c32a1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
17 changes: 10 additions & 7 deletions src/main/java/me/lrxh/practice/Practice.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ public void onEnable() {
// Clear the droppedItems for each world
getServer().getWorlds().forEach(world -> {
world.setDifficulty(Difficulty.HARD);
clearEntities(world);
});

for (World world : getInstance().getServer().getWorlds()) {
Expand Down Expand Up @@ -183,13 +182,16 @@ public void onEnable() {
System.gc();
}

public void clearEntities(World world) {
for (Entity entity : world.getEntities()) {
if (!(entity.getType() == EntityType.PLAYER)) {
continue;
public void clearEntities() {
for (World world : practice.getServer().getWorlds()) {
for (Entity entity : world.getEntities()) {
if (!(entity.getType() == EntityType.PLAYER)) {
continue;
}
if(entity.getType().equals(EntityType.DROPPED_ITEM)){
entity.remove();
}
}

entity.remove();
}
}

Expand Down Expand Up @@ -248,6 +250,7 @@ private void registerPermissions() {

@Override
public void onDisable() {
clearEntities();
Match.cleanup();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public void tp(Player player, String arenaName) {
if (arena == null) return;

player.teleport(arena.getSpawnA());
player.sendMessage(CC.GREEN + "Teleported to arena " + arena.getDisplayName());
player.sendMessage(CC.GREEN + "Teleported to arena " + arena.getName());
}

@Subcommand("generate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void help(Player player) {
player.sendMessage(" ");
player.sendMessage(CC.translate("&7* &c/practice setspawn &7- &fSet server spawn"));
player.sendMessage(CC.translate("&7* &c/practice reload &7- &fReload all configs"));
player.sendMessage(CC.translate("&7* &c/practice clear &7- &fClear all items"));
player.sendMessage(" ");
player.sendMessage(CC.translate("&7&m-----------------------------------------"));
}
Expand Down Expand Up @@ -55,4 +56,9 @@ public void reload(Player player) {
Practice.getInstance().loadConfigs();
player.sendMessage(CC.translate("&aSuccessfully reloaded configs!"));
}

@Subcommand("clear")
public void clear(Player player) {
Practice.getInstance().clearEntities();
}
}
11 changes: 7 additions & 4 deletions src/main/java/me/lrxh/practice/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import me.lrxh.practice.queue.Queue;
import me.lrxh.practice.util.*;
import net.md_5.bungee.api.chat.BaseComponent;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
import org.bukkit.*;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Item;
Expand Down Expand Up @@ -249,8 +251,8 @@ public void start() {
public void end() {
for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) {
Player player = gamePlayer.getPlayer();
if (!gamePlayer.isDisconnected()) {
Player player = gamePlayer.getPlayer();
if (player != null) {
player.setFireTicks(0);
player.updateInventory();
Expand All @@ -261,7 +263,6 @@ public void end() {
profile.setEnderpearlCooldown(new Cooldown(0));
}
} else {
Player player = gamePlayer.getPlayer();
if (player != null) {
player.setFireTicks(0);
player.updateInventory();
Expand Down Expand Up @@ -294,9 +295,10 @@ public void end() {
removeSpectator(player);
}

droppedItems.forEach(Entity::remove);

if (kit.getGameRules().isBuild()) {
arena.restoreSnapshot();

arena.setActive(false);
}

Expand Down Expand Up @@ -500,11 +502,12 @@ public void onDisconnect(Player dead) {
}

public void onDeath(Player dead) {
PlayerUtil.animateDeath(dead);
// Don't continue if the match is already ending
if (!(state == MatchState.STARTING_ROUND || state == MatchState.PLAYING_ROUND)) {
return;
}
dead.getInventory().setContents(new ItemStack[36]);
PlayerUtil.animateDeath(dead);

MatchGamePlayer deadGamePlayer = getGamePlayer(dead);
Player killer = PlayerUtil.getLastAttacker(dead);
Expand Down
20 changes: 5 additions & 15 deletions src/main/java/me/lrxh/practice/match/MatchListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
import me.lrxh.practice.profile.hotbar.HotbarItem;
import me.lrxh.practice.util.*;
import org.apache.commons.lang.StringEscapeUtils;
import org.bukkit.Color;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
Expand All @@ -30,6 +27,7 @@
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -306,14 +304,16 @@ public void onPlayerPickUpEvent(PlayerPickupItemEvent event) {
public void onPlayerDeathEvent(PlayerDeathEvent event) {
Player player = event.getEntity();
event.setDeathMessage(null);

player.getInventory().setContents(new ItemStack[36]);

Profile profile = Profile.getByUuid(event.getEntity().getUniqueId());

if (profile.getState() == ProfileState.FIGHTING) {


Match match = profile.getMatch();
event.getDrops().clear();

boolean aTeam = match.getParticipantA().containsPlayer(player.getUniqueId());

boolean bedGone = aTeam ? match.bedBBroken : match.bedABroken;
Expand All @@ -328,16 +328,6 @@ public void onPlayerDeathEvent(PlayerDeathEvent event) {
return;
}

List<Item> entities = new ArrayList<>();

event.getDrops().forEach(itemStack -> {
if (!(itemStack.getType() == Material.BOOK || itemStack.getType() == Material.ENCHANTED_BOOK)) {
entities.add(event.getEntity().getLocation().getWorld()
.dropItemNaturally(event.getEntity().getLocation(), itemStack));
}
});

match.getDroppedItems().addAll(entities);
match.onDeath(event.getEntity());
}
}
Expand Down

0 comments on commit b5c32a1

Please sign in to comment.