Skip to content

Commit

Permalink
Merge pull request #12 from PixelOutlaw/develop
Browse files Browse the repository at this point in the history
Minimum deconstruct level, discordSrv loot messages, rare drop glow
  • Loading branch information
UltraFaceguy authored May 21, 2021
2 parents cd3db7c + c9939ab commit f5d948c
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 29 deletions.
24 changes: 22 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</parent>

<artifactId>loot</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
<packaging>jar</packaging>

<name>loot</name>
Expand Down Expand Up @@ -65,6 +65,14 @@
<id>inventive-repo</id>
<url>https://repo.inventivetalent.org/content/groups/public/</url>
</repository>
<repository>
<id>Scarsz-Nexus</id>
<url>https://nexus.scarsz.me/content/groups/public/</url>
</repository>
<repository>
<id>loohp-repo</id>
<url>https://repo.loohpjames.com/repository</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -81,7 +89,7 @@
<dependency>
<groupId>io.pixeloutlaw</groupId>
<artifactId>strife</artifactId>
<version>3.3.2</version>
<version>3.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -118,6 +126,18 @@
<artifactId>glowapi</artifactId>
<version>1.4.13-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.discordsrv</groupId>
<artifactId>discordsrv</artifactId>
<version>1.18.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.loohp</groupId>
<artifactId>InteractiveChatDiscordSrvAddon</artifactId>
<version>1.4.0.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.Mitsugaru</groupId>
<artifactId>PlayerPoints</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/info/faceland/loot/LootPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import info.faceland.loot.listeners.HeadHelmetsListener;
import info.faceland.loot.listeners.InteractListener;
import info.faceland.loot.listeners.ItemListListener;
import info.faceland.loot.listeners.ItemSpawnListener;
import info.faceland.loot.listeners.PawnMenuListener;
import info.faceland.loot.listeners.StrifeListener;
import info.faceland.loot.listeners.anticheat.AnticheatListener;
Expand Down Expand Up @@ -272,6 +273,7 @@ public void enable() {
Bukkit.getPluginManager().registerEvents(new ItemListListener(this), this);
Bukkit.getPluginManager().registerEvents(new HeadHelmetsListener(), this);
Bukkit.getPluginManager().registerEvents(new PawnMenuListener(this), this);
Bukkit.getPluginManager().registerEvents(new ItemSpawnListener(), this);
if (potionTriggersEnabled) {
Bukkit.getPluginManager().registerEvents(new SocketsListener(gemCacheManager), this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,20 @@ private void doCraftDeconstruct(LootDeconstructEvent event) {
sendMessage(player, plugin.getSettings().getString("language.craft.no-materials", ""));
return;
}
int quality = 1;
float quality = 1;
while (random.nextDouble() <= plugin.getSettings().getDouble("config.drops.material-quality-up", 0.1D)
&& quality < 5) {
quality++;
}
ItemStack craftMaterial = MaterialUtil.buildMaterial(material,
plugin.getCraftMatManager().getCraftMaterials().get(material), itemLevel, quality);
quality += Math.max(0, effectiveCraftLevel - itemLevel) / 100;
quality += (toolQuality - 1) * 0.1;
quality = Math.floor(quality) + Math.random() <= quality % 1 ? 1 : 0;

quality = Math.max(MaterialUtil.getItemRarity(targetItem) - 1, quality);
quality = Math.min(5, Math.max(1, quality));

ItemStack craftMaterial = MaterialUtil.buildMaterial(material, plugin.getCraftMatManager()
.getCraftMaterials().get(material), itemLevel, (int) quality);

player.playSound(player.getEyeLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 0.8F);
event.setTargetItem(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public void onEntityDeathEvent(EntityDeathEvent event) {
double vl = violationMap.get(killer).getViolationLevel();
penaltyMult *= Math.max(0.05, Math.min(1, 1.5 - vl * 0.06));

double distance = event.getEntity().getLocation().distanceSquared(event.getEntity().getWorld().getSpawnLocation());
double distance = event.getEntity().getLocation().distanceSquared(event.getEntity().getWorld()
.getSpawnLocation());

StrifeMob pStats = plugin.getStrifePlugin().getStrifeMobManager().getStatMob(killer);

Expand Down
34 changes: 34 additions & 0 deletions src/main/java/info/faceland/loot/listeners/ItemSpawnListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* The MIT License Copyright (c) 2015 Teal Cube Games
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package info.faceland.loot.listeners;

import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntitySpawnEvent;

public final class ItemSpawnListener implements Listener {

@EventHandler
public void onSpawnItem(EntitySpawnEvent event) {
if (event.getEntity() instanceof Item) {
event.getEntity().setInvulnerable(true);
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/info/faceland/loot/menu/pawn/SaleIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package info.faceland.loot.menu.pawn;

import com.tealcube.minecraft.bukkit.TextUtils;
import info.faceland.loot.LootPlugin;
import io.pixeloutlaw.minecraft.spigot.hilt.ItemStackExtensionsKt;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -50,7 +51,7 @@ public ItemStack getFinalIcon(Player player) {
ItemStack finalIcon = targetStack.clone();
List<String> newLore = new ArrayList<>(ItemStackExtensionsKt.getLore(finalIcon));
newLore.add("");
newLore.add(TextUtils.color("&6Sale Price: &f" + price + " &fBits"));
newLore.add(TextUtils.color("&6Sale Price: &e" + LootPlugin.getInstance().getEconomy().format(price)));
ItemStackExtensionsKt.setLore(finalIcon, newLore);
return finalIcon;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/info/faceland/loot/menu/pawn/SellIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class SellIcon extends MenuItem {
lore.add(TextUtils.color("&7Click to sell the items"));
lore.add(TextUtils.color("&7selected above!"));
lore.add("");
lore.add(TextUtils.color("&6Total: &f{total} Bits"));
lore.add(TextUtils.color("&6Total: &e{total}"));
}

@Override
Expand All @@ -60,9 +60,9 @@ public ItemStack getFinalIcon(Player player) {
int modifiedTotal = getModifiedTotal(total, tradeLevel);
String priceString;
if (tradeLevel < 5 || modifiedTotal == total) {
priceString = String.valueOf(total);
priceString = LootPlugin.getInstance().getEconomy().format(total);
} else {
priceString = TextUtils.color("&7&m" + total + "&r &f&l" + modifiedTotal);
priceString = TextUtils.color("&7&m" + total + "&r &e&l" + LootPlugin.getInstance().getEconomy().format(modifiedTotal));
}
for (String s : lore) {
newLore.add(s.replace("{total}", priceString));
Expand Down Expand Up @@ -95,7 +95,7 @@ public void onItemClick(ItemClickEvent event) {
if (total != 0) {
LootPlugin.getInstance().getEconomy().depositPlayer(event.getPlayer(), total);
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLOCK_CHAIN_PLACE, 1.0F, 1.3F);
MessageUtils.sendMessage(event.getPlayer(), "&e +" + total + " Bit(s)!");
MessageUtils.sendMessage(event.getPlayer(), "&e +" + LootPlugin.getInstance().getEconomy().format(total));
}
if (menu.getTotal() > 0) {
MessageUtils.sendMessage(event.getPlayer(),
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/info/faceland/loot/menu/upgrade/EnchantMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ public class EnchantMenu extends ItemMenu {

private LootPlugin plugin;

private int baseEnhanceRequirement;
private static int baseEnhanceRequirement;
private static int enhanceReqPerTwenty;

private int playerPointHelmetMergeCost;
private int enhanceReqPerTwenty;

private ItemStack selectedEquipment;
private ItemStack selectedUpgradeItem;
Expand Down Expand Up @@ -323,7 +324,7 @@ private void updateConfirmIcon(Player player) {

int enchantingLevel = plugin.getStrifePlugin().getChampionManager().getChampion(player)
.getLifeSkillLevel(LifeSkillType.ENCHANTING);
if (enchantingLevel < getEnhanceRequirement()) {
if (enchantingLevel < getEnhanceRequirement(MaterialUtil.getItemLevel(selectedEquipment))) {
confirmIcon.setDisplayName(noEnhanceLevel);
lore.addAll(noEnhanceLevelLore);
ItemStackExtensionsKt.setLore(confirmIcon.getIcon(), lore);
Expand Down Expand Up @@ -441,9 +442,9 @@ ItemStack getBlankItem() {
return blankItem;
}

private int getEnhanceRequirement() {
int tier = (int) Math.floor(((double) MaterialUtil.getLevelRequirement(selectedEquipment)) / 10);
return baseEnhanceRequirement + tier * enhanceReqPerTwenty;
public static int getEnhanceRequirement(int itemLevel) {
int eLevel = itemLevel / 20;
return baseEnhanceRequirement + eLevel * enhanceReqPerTwenty;
}

}
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/info/faceland/loot/utils/DropUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import land.face.strife.util.GlowUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
Expand Down Expand Up @@ -355,8 +356,12 @@ private static void dropItem(Location loc, ItemStack itemStack, Player looter, i
Color glowColor) {
Item drop = Objects.requireNonNull(loc.getWorld()).dropItemNaturally(loc, itemStack);
if (glowColor != null) {
GlowAPI.setGlowing(drop, true, looter);
GlowAPI.setGlowing(drop, glowColor, looter);
if (plugin.getStrifePlugin() == null) {
GlowAPI.setGlowing(drop, true, looter);
GlowAPI.setGlowing(drop, glowColor, looter);
} else {
GlowUtil.setGlow(looter, drop, glowColor);
}
}
if (ticksLived != 0) {
drop.setTicksLived(ticksLived);
Expand Down Expand Up @@ -417,7 +422,7 @@ private static List<Material> getWornMaterials(Player player) {
if (handItem.getType() != Material.AIR) {
materials.add(handItem.getType());
}
ItemStack offItem = player.getEquipment().getItemInMainHand();
ItemStack offItem = player.getEquipment().getItemInOffHand();
if (offItem.getType() != Material.AIR) {
materials.add(offItem.getType());
}
Expand Down
92 changes: 87 additions & 5 deletions src/main/java/info/faceland/loot/utils/InventoryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,122 @@
*/
package info.faceland.loot.utils;

import com.loohp.interactivechatdiscordsrvaddon.InteractiveChatDiscordSrvAddon;
import com.loohp.interactivechatdiscordsrvaddon.api.events.DiscordImageEvent;
import com.loohp.interactivechatdiscordsrvaddon.graphics.ImageGeneration;
import com.loohp.interactivechatdiscordsrvaddon.objectholders.DiscordMessageContent;
import com.loohp.interactivechatdiscordsrvaddon.utils.DiscordItemStackUtils;
import com.loohp.interactivechatdiscordsrvaddon.utils.DiscordItemStackUtils.DiscordDescription;
import com.loohp.interactivechatdiscordsrvaddon.utils.DiscordItemStackUtils.DiscordToolTip;
import github.scarsz.discordsrv.DiscordSRV;
import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel;
import info.faceland.loot.LootPlugin;
import info.faceland.loot.data.ItemStat;
import io.pixeloutlaw.minecraft.spigot.garbage.BroadcastMessageUtil;
import io.pixeloutlaw.minecraft.spigot.garbage.BroadcastMessageUtil.BroadcastItemVisibility;
import io.pixeloutlaw.minecraft.spigot.garbage.BroadcastMessageUtil.BroadcastTarget;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

public final class InventoryUtil {

private static TextChannel thechan;

private InventoryUtil() {
// meh
thechan = DiscordSRV.getPlugin().getMainTextChannel();
}

public static void broadcast(Player player, ItemStack his, String format) {
broadcast(player, his, format, true);
}

public static void broadcast(Player player, ItemStack his, String format, boolean sendToAll) {
public static void broadcast(Player player, ItemStack item, String format, boolean sendToAll) {
BroadcastTarget target = sendToAll ? BroadcastTarget.SERVER : BroadcastTarget.PLAYER;
BroadcastMessageUtil.INSTANCE.broadcastItem(format, player, his, target, BroadcastItemVisibility.SHOW);
BroadcastMessageUtil.INSTANCE
.broadcastItem(format, player, item, target, BroadcastItemVisibility.SHOW);
if (sendToAll) {
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChatDiscordSrvAddon.plugin, () -> {
try {
List<DiscordMessageContent> contents = new ArrayList<>();
BufferedImage image = ImageGeneration.getItemStackImage(item, player);
ByteArrayOutputStream itemOs = new ByteArrayOutputStream();
ImageIO.write(image, "png", itemOs);

DiscordDescription description = DiscordItemStackUtils.getDiscordDescription(item);

Color color = DiscordItemStackUtils.getDiscordColor(item);
DiscordMessageContent content = new DiscordMessageContent(description.getName(),
"attachment://Item.png", color);
content.addAttachment("Item.png", itemOs.toByteArray());
contents.add(content);

DiscordToolTip discordToolTip = DiscordItemStackUtils.getToolTip(item);
if (!discordToolTip.isBaseItem()
|| InteractiveChatDiscordSrvAddon.plugin.itemUseTooltipImageOnBaseItem) {
BufferedImage tooltip = ImageGeneration.getToolTipImage(discordToolTip.getComponents());
ByteArrayOutputStream tooltipOs = new ByteArrayOutputStream();
ImageIO.write(tooltip, "png", tooltipOs);
content.addAttachment("ToolTip.png", tooltipOs.toByteArray());
content.addImageUrl("attachment://ToolTip.png");
} else {
content.addDescription(description.getDescription().orElse(null));
}

broadcast("\uD83C\uDF1F **Dang Son!** " + player.getName() + " got an item!", contents);

} catch (Exception e) {
Bukkit.getLogger().warning("Failed to send dang son to discord");
}
});
}
}

private static void broadcast(String originalText, List<DiscordMessageContent> contents) {
Bukkit.getScheduler().runTaskAsynchronously(LootPlugin.getInstance(), () -> {

String text = originalText;

if (thechan == null) {
thechan = DiscordSRV.getPlugin().getMainTextChannel();
if (thechan == null) {
Bukkit.getLogger().warning("Could not load discord channel for dang sons");
return;
}
}

DiscordImageEvent discordImageEvent = new DiscordImageEvent(thechan, text, text, contents, false, true);
TextChannel textChannel = discordImageEvent.getChannel();
if (discordImageEvent.isCancelled()) {
String restore = discordImageEvent.getOriginalMessage();
textChannel.sendMessage(restore).queue();
} else {
text = discordImageEvent.getNewMessage();
textChannel.sendMessage(text).queue();
for (DiscordMessageContent content : discordImageEvent.getDiscordMessageContents()) {
content.toJDAMessageRestAction(textChannel).queue();
}
}
});
}

public static net.md_5.bungee.api.ChatColor getRollColor(ItemStat stat, double roll) {
return getRollColor(roll, stat.getMinHue(), stat.getMaxHue(), stat.getMinSaturation(), stat.getMaxSaturation(),
return getRollColor(roll, stat.getMinHue(), stat.getMaxHue(), stat.getMinSaturation(),
stat.getMaxSaturation(),
stat.getMinBrightness(), stat.getMaxBrightness());
}

public static net.md_5.bungee.api.ChatColor getRollColor(double roll, float minHue, float maxHue, float minSat,
public static net.md_5.bungee.api.ChatColor getRollColor(double roll, float minHue, float maxHue,
float minSat,
float maxSat, float minBright, float maxBright) {
float hue = minHue + (maxHue - minHue) * (float) roll;
float saturation = minSat + (maxSat - minSat) * (float) roll;
Expand Down
Loading

0 comments on commit f5d948c

Please sign in to comment.