Skip to content

Commit

Permalink
- Fix player death message disappear
Browse files Browse the repository at this point in the history
- Now following Google's coding standards
  • Loading branch information
unldenis committed Aug 24, 2022
1 parent 0d3b799 commit e9790fc
Show file tree
Hide file tree
Showing 20 changed files with 956 additions and 943 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.unldenis.corpse</groupId>
<artifactId>Corpse</artifactId>
<version>1.0.8-SNAPSHOT</version>
<version>1.0.9-SNAPSHOT</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
65 changes: 33 additions & 32 deletions src/main/java/com/github/unldenis/corpse/CorpseP.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,45 @@

public class CorpseP extends JavaPlugin {

private static CorpseP instance;
private static CorpseP instance;

private DataManager configYml;
private CorpsePool pool;
@Override
public void onEnable() {
CorpseP.instance = this;
private DataManager configYml;
private CorpsePool pool;

//register commands
this.getCommand("spawncorpse").setExecutor(new SpawnCorpseCommand());
this.getCommand("removecorpse").setExecutor(new RemoveCorpseCommand());
@NotNull
public static CorpseP getInstance() {
return instance;
}

//load config
configYml = new DataManager(this, "config.yml");
@Override
public void onEnable() {
CorpseP.instance = this;

//load instance
pool = CorpsePool.getInstance();
}
//register commands
this.getCommand("spawncorpse").setExecutor(new SpawnCorpseCommand());
this.getCommand("removecorpse").setExecutor(new RemoveCorpseCommand());

@Override
public void onDisable() {
BukkitTask task = pool.getTickTask();
if(task != null) {
task.cancel();
}
for(Corpse c: pool.getCorpses()) {
c.getSeeingPlayers()
.forEach(c::hide);
}
}
//load config
configYml = new DataManager(this, "config.yml");

@NotNull
public static CorpseP getInstance() {
return instance;
}
//load instance
pool = CorpsePool.getInstance();
}

@NotNull
public FileConfiguration getConfigYml() {
return configYml.getConfig();
@Override
public void onDisable() {
BukkitTask task = pool.getTickTask();
if (task != null) {
task.cancel();
}
for (Corpse c : pool.getCorpses()) {
c.getSeeingPlayers()
.forEach(c::hide);
}
}

@NotNull
public FileConfiguration getConfigYml() {
return configYml.getConfig();
}
}
212 changes: 112 additions & 100 deletions src/main/java/com/github/unldenis/corpse/api/CorpseAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,114 +29,126 @@

public class CorpseAPI {

private static CorpseAPI instance;
private static CorpseAPI instance;

public CorpseAPI() {
throw new IllegalArgumentException();
}
public CorpseAPI() {
throw new IllegalArgumentException();
}

private CorpseAPI(Object dummy) { }
private CorpseAPI(Object dummy) {
}

/**
* Method that creates a corpse in the player's position and with its skin and inventory
* @param player The player to copy
* @return a new Corpse object
*/
public Corpse spawnCorpse(@NotNull Player player) {
Validate.notNull(player, "Player cannot be null");
return new Corpse(player);
/**
* Class method that allows you to use the API.
*
* @return an instance of this class
*/
@NotNull
public static synchronized CorpseAPI getInstance() {
if (instance == null) {
instance = new CorpseAPI(null);
}
return instance;
}

/**
* Method that creates a corpse in the given place and with the skin, name and inventory of the player
* @param player The player to copy
* @param location The location where to spawn the corpse
* @return a new Corpse object
*/
public Corpse spawnCorpse(@NotNull Player player, @NotNull Location location) {
Validate.notNull(player, "Player cannot be null");
Validate.notNull(location, "Spawn location cannot be null");
return new Corpse(location, WrappedGameProfile.fromPlayer(player), null, player.getName());
}
/**
* Method that creates a corpse in the player's position and with its skin and inventory
*
* @param player The player to copy
* @return a new Corpse object
*/
public Corpse spawnCorpse(@NotNull Player player) {
Validate.notNull(player, "Player cannot be null");
return new Corpse(player);
}

/**
* Method that creates a corpse in the given place and with the skin and name of the offlinePlayer
* @param offlinePlayer The offlinePlayer to copy
* @param location The location where to spawn the corpse
* @return a new Corpse object
*/
public Corpse spawnCorpse(@NotNull OfflinePlayer offlinePlayer, @NotNull Location location) {
Validate.notNull(offlinePlayer, "OfflinePlayer cannot be null");
Validate.notNull(location, "Spawn location cannot be null");
return new Corpse(location, offlinePlayer, null);
}
/**
* Method that creates a corpse in the given place and with the skin, name and inventory of the
* player
*
* @param player The player to copy
* @param location The location where to spawn the corpse
* @return a new Corpse object
*/
public Corpse spawnCorpse(@NotNull Player player, @NotNull Location location) {
Validate.notNull(player, "Player cannot be null");
Validate.notNull(location, "Spawn location cannot be null");
return new Corpse(location, WrappedGameProfile.fromPlayer(player), null, player.getName());
}

/**
* Method that creates a corpse in the given place and with the skin and name of the player
* with a custom inventory.
* @param player The player to copy
* @param location The location where to spawn the corpse
* @param helmet The helmet to put on the corpse
* @param chestPlate The chestPlate to put on the corpse
* @param leggings The leggings to put on the corpse
* @param boots The boots to put on the corpse
* @return a new Corpse object
*/
public Corpse spawnCorpse(
@NotNull Player player,
@NotNull Location location,
@Nullable ItemStack helmet,
@Nullable ItemStack chestPlate,
@Nullable ItemStack leggings,
@Nullable ItemStack boots
) {
Validate.notNull(player, "Player cannot be null");
Validate.notNull(location, "Spawn location cannot be null");
return new Corpse(location, WrappedGameProfile.fromPlayer(player), new ItemStack[]{boots, leggings, chestPlate, helmet}, player.getName());
}
/**
* Method that creates a corpse in the given place and with the skin and name of the
* offlinePlayer
*
* @param offlinePlayer The offlinePlayer to copy
* @param location The location where to spawn the corpse
* @return a new Corpse object
*/
public Corpse spawnCorpse(@NotNull OfflinePlayer offlinePlayer, @NotNull Location location) {
Validate.notNull(offlinePlayer, "OfflinePlayer cannot be null");
Validate.notNull(location, "Spawn location cannot be null");
return new Corpse(location, offlinePlayer, null);
}

/**
* Method that creates a corpse in the given place and with the skin and name of the offlinePlayer
* with a custom inventory.
* @param offlinePlayer The offlinePlayer to copy
* @param location The location where to spawn the corpse
* @param helmet The helmet to put on the corpse
* @param chestPlate The chestPlate to put on the corpse
* @param leggings The leggings to put on the corpse
* @param boots The boots to put on the corpse
* @return a new Corpse object
*/
public Corpse spawnCorpse(
@NotNull OfflinePlayer offlinePlayer,
@NotNull Location location,
@Nullable ItemStack helmet,
@Nullable ItemStack chestPlate,
@Nullable ItemStack leggings,
@Nullable ItemStack boots
) {
Validate.notNull(offlinePlayer, "OfflinePlayer cannot be null");
Validate.notNull(location, "Spawn location cannot be null");
return new Corpse(location, offlinePlayer, new ItemStack[]{boots, leggings, chestPlate, helmet});
}
/**
* Method that creates a corpse in the given place and with the skin and name of the player with a
* custom inventory.
*
* @param player The player to copy
* @param location The location where to spawn the corpse
* @param helmet The helmet to put on the corpse
* @param chestPlate The chestPlate to put on the corpse
* @param leggings The leggings to put on the corpse
* @param boots The boots to put on the corpse
* @return a new Corpse object
*/
public Corpse spawnCorpse(
@NotNull Player player,
@NotNull Location location,
@Nullable ItemStack helmet,
@Nullable ItemStack chestPlate,
@Nullable ItemStack leggings,
@Nullable ItemStack boots
) {
Validate.notNull(player, "Player cannot be null");
Validate.notNull(location, "Spawn location cannot be null");
return new Corpse(location, WrappedGameProfile.fromPlayer(player),
new ItemStack[]{boots, leggings, chestPlate, helmet}, player.getName());
}

/**
* Method that removes a corpse
* @param corpse The corpse to be removed
*/
public void removeCorpse(@NotNull Corpse corpse) {
Validate.notNull(corpse, "Corpse cannot be null");
CorpsePool.getInstance().remove(corpse.getId());
}
/**
* Method that creates a corpse in the given place and with the skin and name of the offlinePlayer
* with a custom inventory.
*
* @param offlinePlayer The offlinePlayer to copy
* @param location The location where to spawn the corpse
* @param helmet The helmet to put on the corpse
* @param chestPlate The chestPlate to put on the corpse
* @param leggings The leggings to put on the corpse
* @param boots The boots to put on the corpse
* @return a new Corpse object
*/
public Corpse spawnCorpse(
@NotNull OfflinePlayer offlinePlayer,
@NotNull Location location,
@Nullable ItemStack helmet,
@Nullable ItemStack chestPlate,
@Nullable ItemStack leggings,
@Nullable ItemStack boots
) {
Validate.notNull(offlinePlayer, "OfflinePlayer cannot be null");
Validate.notNull(location, "Spawn location cannot be null");
return new Corpse(location, offlinePlayer,
new ItemStack[]{boots, leggings, chestPlate, helmet});
}

/**
* Class method that allows you to use the API.
* @return an instance of this class
*/
@NotNull
public static synchronized CorpseAPI getInstance() {
if(instance == null) {
instance = new CorpseAPI(null);
}
return instance;
}
/**
* Method that removes a corpse
*
* @param corpse The corpse to be removed
*/
public void removeCorpse(@NotNull Corpse corpse) {
Validate.notNull(corpse, "Corpse cannot be null");
CorpsePool.getInstance().remove(corpse.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,40 @@

public class RemoveCorpseCommand implements CommandExecutor {

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, @NotNull String[] args) {
if(sender instanceof Player) {
Player player = (Player) sender;
if(player.hasPermission("corpses.remove")) {
if(args.length==1) {
try {
double radius = Math.pow(Double.parseDouble(args[0]), 2);
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd,
@NotNull String label, @NotNull String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (player.hasPermission("corpses.remove")) {
if (args.length == 1) {
try {
double radius = Math.pow(Double.parseDouble(args[0]), 2);

CorpsePool pool = CorpsePool.getInstance();
AtomicInteger count = new AtomicInteger(0);
pool.getCorpses()
.stream()
.filter(corpse -> corpse.getLocation().distanceSquared(player.getLocation()) <= radius)
.forEach(corpse -> {
pool.remove(corpse.getId());
count.incrementAndGet();
});
player.sendMessage("(" + count.get() + ") " + ChatColor.GREEN+"Corpses deleted");
return true;
}catch (NumberFormatException e) {
player.sendMessage(ChatColor.RED + "Radius must be a number");
}
return true;
}
sender.sendMessage(ChatColor.RED+"/removecorpse [radius] - Removes any coprse(s) in a radius of you.");
}
} else {
sender.sendMessage(ChatColor.RED+"Only players can run this command");
CorpsePool pool = CorpsePool.getInstance();
AtomicInteger count = new AtomicInteger(0);
pool.getCorpses()
.stream()
.filter(
corpse -> corpse.getLocation().distanceSquared(player.getLocation()) <= radius)
.forEach(corpse -> {
pool.remove(corpse.getId());
count.incrementAndGet();
});
player.sendMessage("(" + count.get() + ") " + ChatColor.GREEN + "Corpses deleted");
return true;
} catch (NumberFormatException e) {
player.sendMessage(ChatColor.RED + "Radius must be a number");
}
return true;
}


return false;
sender.sendMessage(
ChatColor.RED + "/removecorpse [radius] - Removes any coprse(s) in a radius of you.");
}
} else {
sender.sendMessage(ChatColor.RED + "Only players can run this command");
}

return false;
}
}
Loading

0 comments on commit e9790fc

Please sign in to comment.