Fix add commands, add %player% and {name} on item spawn

This commit is contained in:
Esophose 2019-05-18 23:01:12 -06:00
parent f98678ebfe
commit 25734f5415
3 changed files with 49 additions and 36 deletions

View File

@ -8,7 +8,7 @@
"SKOnSpawn": [
"&8&m-----*--------------------*-----",
"&7",
"&fA &e{boss} &fhas been spawned at &e{location}&f!",
"&fA &e{boss} &fhas been spawned by &e{name} &fat &e{location}&f!",
"&7",
"&8&m-----*--------------------*-----"
],

View File

@ -16,6 +16,7 @@ import com.songoda.epicbosses.utils.command.SubCommand;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@ -208,36 +209,36 @@ public class BossNewCmd extends SubCommand {
}
Message.Boss_New_InvalidArgs.msg(sender);
return;
}
private List<String> appendList(String[] args) {
int length = args.length;
List<String> listOfElement = new ArrayList<>();
StringBuilder current = new StringBuilder();
String[] params = Arrays.copyOfRange(args, 3, args.length);
for(int i = 4; i < length; i++) {
String arg = args[i];
if(arg.contains("||")) {
String[] split = arg.split("||");
current.append(split[0]);
listOfElement.add(current.toString());
if(split.length >= 2) {
current = new StringBuilder(split[1]);
} else {
current = new StringBuilder();
}
List<String> sections = new ArrayList<>();
StringBuilder currentSection = new StringBuilder();
for (String param : params) {
String[] split = param.split("\\|");
if (split.length == 1) {
currentSection.append(split[0]).append(" ");
continue;
}
current.append(arg);
boolean firstAdded = false;
for (String piece : split) {
currentSection.append(piece).append(" ");
if (!firstAdded) {
sections.add(currentSection.toString().trim());
currentSection = new StringBuilder();
firstAdded = true;
}
}
}
listOfElement.add(current.toString());
return listOfElement;
if (!currentSection.toString().trim().isEmpty())
sections.add(currentSection.toString().trim());
return sections;
}
}

View File

@ -9,11 +9,15 @@ import com.songoda.epicbosses.events.PreBossSpawnItemEvent;
import com.songoda.epicbosses.holder.ActiveBossHolder;
import com.songoda.epicbosses.managers.BossEntityManager;
import com.songoda.epicbosses.managers.BossLocationManager;
import com.songoda.epicbosses.managers.BossTargetManager;
import com.songoda.epicbosses.managers.BossTauntManager;
import com.songoda.epicbosses.utils.*;
import com.songoda.epicbosses.utils.Message;
import com.songoda.epicbosses.utils.MessageUtils;
import com.songoda.epicbosses.utils.NumberUtils;
import com.songoda.epicbosses.utils.ServerUtils;
import com.songoda.epicbosses.utils.StringUtils;
import com.songoda.epicbosses.utils.itemstack.ItemStackUtils;
import com.songoda.epicbosses.utils.version.VersionHandler;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -113,24 +117,32 @@ public class BossSpawnListener implements Listener {
BossEntity bossEntity = activeBossHolder.getBossEntity();
Location location = activeBossHolder.getLocation();
if(event instanceof PreBossSpawnItemEvent) {
PreBossSpawnItemEvent preBossSpawnItemEvent = (PreBossSpawnItemEvent) event;
ItemStack itemStack = preBossSpawnItemEvent.getItemStackUsed().clone();
Player player = preBossSpawnItemEvent.getPlayer();
itemStack.setAmount(1);
player.getInventory().removeItem(itemStack);
player.updateInventory();
}
List<String> commands = this.bossEntityManager.getOnSpawnCommands(bossEntity);
List<String> messages = this.bossEntityManager.getOnSpawnMessage(bossEntity);
int messageRadius = this.bossEntityManager.getOnSpawnMessageRadius(bossEntity);
ServerUtils serverUtils = ServerUtils.get();
if(commands != null) {
commands.forEach(serverUtils::sendConsoleCommand);
if(event instanceof PreBossSpawnItemEvent) {
PreBossSpawnItemEvent preBossSpawnItemEvent = (PreBossSpawnItemEvent) event;
ItemStack itemStack = preBossSpawnItemEvent.getItemStackUsed().clone();
Player player = preBossSpawnItemEvent.getPlayer();
if (player.getGameMode() != GameMode.CREATIVE) {
itemStack.setAmount(1);
player.getInventory().removeItem(itemStack);
player.updateInventory();
}
if (commands != null)
commands.replaceAll(s -> s.replaceAll("%player%", player.getName()));
if (messages != null && !activeBossHolder.isCustomSpawnMessage())
messages.replaceAll(s -> s.replace("{name}", player.getName()));
}
if (commands != null)
commands.forEach(serverUtils::sendConsoleCommand);
if(messages != null && !activeBossHolder.isCustomSpawnMessage()) {
if(activeBossHolder.getName() != null) messages.replaceAll(s -> s.replace("{boss}", activeBossHolder.getName()));
messages.replaceAll(s -> s.replace("{location}", StringUtils.get().translateLocation(location)));