Skip to content

Commit

Permalink
Add message to LimitationInformation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ste3et committed Aug 1, 2022
1 parent 8244d1c commit b909c58
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package de.Ste3et_C0st.FurnitureLib.LimitationManager;

import org.bukkit.entity.Player;

import de.Ste3et_C0st.FurnitureLib.Crafting.Project;
import de.Ste3et_C0st.FurnitureLib.Utilitis.LanguageManager;
import de.Ste3et_C0st.FurnitureLib.Utilitis.StringTranslator;

public class LimitationInforamtion {

private final String type;
Expand Down Expand Up @@ -32,4 +38,15 @@ public boolean isInfinite() {
return max < 1;
}

public void sendMessage(Player player, Project project, int amount) {
String name = isCanceld() ? ".reached" : ".info";
String messageName = "message.limit." + type + name;
player.sendMessage(LanguageManager.getInstance().getString(messageName,
new StringTranslator("#amount#", Integer.toString(amount)),
new StringTranslator("#size#", Integer.toString(getMax())),
new StringTranslator("#project#", project.getDisplayName()),
new StringTranslator("#world#", player.getWorld().getName())
));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,12 @@ public boolean canPlace(Player p, ObjectID obj) {
Optional<LimitationInforamtion> canceldLimit = informationList.stream().filter(LimitationInforamtion::isCanceld).findFirst();
if(canceldLimit.isPresent()) {
LimitationInforamtion object = canceldLimit.get();
p.sendMessage(LanguageManager.getInstance().getString("message.limit." + object.getType() + ".reached",
new StringTranslator("#amount#", Integer.toString(object.getAmount())),
new StringTranslator("#size#", Integer.toString(object.getMax())),
new StringTranslator("#project#", pro.getDisplayName()),
new StringTranslator("#world#", world.getName())
));
object.sendMessage(p, pro, object.getAmount());
return false;
}else {
LimitationInforamtion infoLimit = informationList.stream().findFirst().orElse(null);
if(Objects.nonNull(infoLimit)) {
p.sendMessage(LanguageManager.getInstance().getString("message.limit." + infoLimit.getType() + ".info",
new StringTranslator("#amount#", Integer.toString(infoLimit.getAmount() + 1)),
new StringTranslator("#size#", Integer.toString(infoLimit.getMax())),
new StringTranslator("#project#", pro.getDisplayName()),
new StringTranslator("#world#", world.getName())
));
infoLimit.sendMessage(p, pro, infoLimit.getAmount() + 1);
}
}
}
Expand Down

0 comments on commit b909c58

Please sign in to comment.