Skip to content

Commit

Permalink
1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BenceX100 committed Jun 19, 2024
1 parent 6b8029c commit b1f851d
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 15 deletions.
20 changes: 9 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.artillexstudios</groupId>
<artifactId>AxSellwands</artifactId>
<version>1.3.3</version>
<version>1.4.0</version>
<packaging>jar</packaging>

<name>AxSellwands</name>
Expand All @@ -23,8 +23,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>12</source>
<target>12</target>
<source>17</source>
<target>17</target>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
Expand Down Expand Up @@ -156,7 +156,7 @@
<dependency>
<groupId>com.artillexstudios.axapi</groupId>
<artifactId>axapi</artifactId>
<version>1.4.238</version>
<version>1.4.242</version>
<scope>compile</scope>
<classifier>all</classifier>
</dependency>
Expand All @@ -175,7 +175,7 @@
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.3</version>
<version>2.11.6</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -187,36 +187,34 @@
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.3.2</version>
<version>4.3.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.16.0</version>
<version>4.17.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-legacy</artifactId>
<version>4.16.0</version>
<version>4.17.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.16.0</version>
<version>4.17.0</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.Zrips.CMI</groupId>
<artifactId>CMI</artifactId>
<version>LATEST</version>
<systemPath>${project.basedir}/libs/CMI-API9.5.0.8.jar</systemPath>
<scope>system</scope>
</dependency>

<dependency>
<groupId>com.Zrips.CMILib</groupId>
<artifactId>CMILib</artifactId>
Expand Down
37 changes: 35 additions & 2 deletions src/main/java/com/artillexstudios/axsellwands/AxSellwands.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.settings.general.GeneralSettings;
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.settings.loader.LoaderSettings;
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.settings.updater.UpdaterSettings;
import com.artillexstudios.axapi.nms.NMSHandlers;
import com.artillexstudios.axapi.utils.FastFieldAccessor;
import com.artillexstudios.axapi.utils.FeatureFlags;
import com.artillexstudios.axapi.utils.MessageUtils;
import com.artillexstudios.axapi.utils.StringUtils;
Expand All @@ -18,16 +20,26 @@
import com.artillexstudios.axsellwands.listeners.SellwandUseListener;
import com.artillexstudios.axsellwands.sellwands.Sellwand;
import com.artillexstudios.axsellwands.sellwands.Sellwands;
import com.artillexstudios.axsellwands.utils.CommandMessages;
import com.artillexstudios.axsellwands.utils.FileUtils;
import com.artillexstudios.axsellwands.utils.NumberUtils;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Warning;
import org.bukkit.entity.HumanEntity;
import revxrsal.commands.bukkit.BukkitCommandActor;
import revxrsal.commands.bukkit.BukkitCommandHandler;
import revxrsal.commands.bukkit.exception.InvalidPlayerException;
import revxrsal.commands.exception.CommandErrorException;
import revxrsal.commands.exception.SendMessageException;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

public final class AxSellwands extends AxPlugin {
public static Config CONFIG;
Expand Down Expand Up @@ -65,7 +77,26 @@ public void enable() {
HookManager.setupHooks();
NumberUtils.reload();

final BukkitCommandHandler handler = BukkitCommandHandler.create(this);
Warning.WarningState prevState = Bukkit.getWarningState();
FastFieldAccessor accessor = FastFieldAccessor.forClassField(Bukkit.getServer().getClass().getPackage().getName() + ".CraftServer", "warningState");
accessor.set(Bukkit.getServer(), Warning.WarningState.OFF);
final BukkitCommandHandler handler = BukkitCommandHandler.create(instance);
accessor.set(Bukkit.getServer(), prevState);

handler.registerValueResolver(0, OfflinePlayer.class, context -> {
String value = context.pop();
if (value.equalsIgnoreCase("self") || value.equalsIgnoreCase("me")) return ((BukkitCommandActor) context.actor()).requirePlayer();
OfflinePlayer player = NMSHandlers.getNmsHandler().getCachedOfflinePlayer(value);
if (player == null && !(player = Bukkit.getOfflinePlayer(value)).hasPlayedBefore()) throw new InvalidPlayerException(context.parameter(), value);
return player;
});

handler.getAutoCompleter().registerParameterSuggestions(OfflinePlayer.class, (args, sender, command) -> {
return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).collect(Collectors.toSet());
});

handler.getTranslator().add(new CommandMessages());
handler.setLocale(new Locale("en", "US"));

handler.getAutoCompleter().registerSuggestionFactory(parameter -> {
if (parameter.hasAnnotation(com.artillexstudios.axsellwands.commands.annotations.Sellwands.class)) {
Expand All @@ -81,7 +112,9 @@ public void enable() {

handler.registerValueResolver(Sellwand.class, resolver -> {
final String str = resolver.popForParameter();
return Sellwands.getSellwands().get(str);
if (Sellwands.getSellwands().containsKey(str))
return Sellwands.getSellwands().get(str);
throw new CommandErrorException("invalid-command", str);
});

handler.register(new Commands());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.artillexstudios.axsellwands.hooks.HookManager;
import com.artillexstudios.axsellwands.sellwands.Sellwand;
import com.artillexstudios.axsellwands.sellwands.Sellwands;
import com.artillexstudios.axsellwands.utils.HistoryUtils;
import com.artillexstudios.axsellwands.utils.HologramUtils;
import com.artillexstudios.axsellwands.utils.NBTUtils;
import com.artillexstudios.axsellwands.utils.NumberUtils;
Expand All @@ -28,6 +29,7 @@

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import static com.artillexstudios.axsellwands.AxSellwands.CONFIG;
Expand Down Expand Up @@ -84,6 +86,7 @@ else if (block.getType() == Material.ENDER_CHEST)
double newSoldPrice = 0;

if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
final Map<Material, Integer> items = new HashMap<>();
for (ItemStack it : contents) {
if (it == null) continue;
double price = HookManager.getShopPrices().getPrice(player, it);
Expand All @@ -93,6 +96,11 @@ else if (block.getType() == Material.ENDER_CHEST)
newSoldPrice += price;
newSoldAmount += it.getAmount();

if (items.containsKey(it.getType()))
items.put(it.getType(), items.get(it.getType()) + it.getAmount());
else
items.put(it.getType(), it.getAmount());

it.setAmount(0);
}

Expand All @@ -106,6 +114,16 @@ else if (block.getType() == Material.ENDER_CHEST)
if (apiEvent.isCancelled()) return;
newSoldPrice = apiEvent.getMoneyMade();

StringBuilder str = new StringBuilder("[");
boolean first = true;
for (Map.Entry<Material, Integer> e : items.entrySet()) {
if (!first) str.append(", ");
first = false;
str.append(e.getValue()).append("x ").append(e.getKey().name());
}
str.append("]");
HistoryUtils.writeToHistory(String.format("%s sold %dx items %s and earned %s (multiplier: %s, uses: %d)", player.getName(), newSoldAmount, str, newSoldPrice, multiplier, uses - 1));

final HashMap<String, String> replacements = new HashMap<>();
replacements.put("%amount%", "" + newSoldAmount);
replacements.put("%price%", NumberUtils.formatNumber(newSoldPrice));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.artillexstudios.axsellwands.utils;

import com.artillexstudios.axapi.utils.StringUtils;
import revxrsal.commands.locales.LocaleReader;

import java.util.Locale;

import static com.artillexstudios.axsellwands.AxSellwands.CONFIG;
import static com.artillexstudios.axsellwands.AxSellwands.LANG;

public class CommandMessages implements LocaleReader {
@Override
public boolean containsKey(String s) {
return true;
}

@Override
public String get(String s) {
String res;
switch (s) {
case "invalid-enum", "invalid-number", "invalid-uuid", "invalid-url", "invalid-boolean": {
res = LANG.getString("commands.invalid-value")
.replace("%value%", "{0}");
break;
}
case "missing-argument": {
res = LANG.getString("commands.missing-argument")
.replace("%value%", "{0}");
break;
}
case "no-permission": {
res = LANG.getString("commands.no-permission");
break;
}
case "number-not-in-range": {
res = LANG.getString("commands.out-of-range")
.replace("%number%", "{0}")
.replace("%min%", "{1}")
.replace("%max%", "{2}");
break;
}
case "must-be-player": {
res = LANG.getString("commands.player-only");
break;
}
case "must-be-console": {
res = LANG.getString("commands.console-only");
break;
}
case "invalid-player": {
res = LANG.getString("commands.invalid-player")
.replace("%player%", "{0}");
break;
}
case "invalid-selector": {
res = LANG.getString("commands.invalid-selector");
break;
}
default: {
res = LANG.getString("commands.invalid-command");
break;
}
}
return StringUtils.formatToString(CONFIG.getString("prefix", "") + res);
}

private final Locale locale = new Locale("en", "US");

@Override
public Locale getLocale() {
return locale;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.artillexstudios.axsellwands.utils;

import com.artillexstudios.axsellwands.AxSellwands;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.time.ZonedDateTime;

public class HistoryUtils {

public static void writeToHistory(@NotNull String txt) {
final ZonedDateTime zdt = ZonedDateTime.now();
final File subdir = new File(AxSellwands.getInstance().getDataFolder().getPath() + System.getProperty("file.separator") + "logs");
subdir.mkdirs();
final File file = new File(subdir.getPath() + "/" + zdt.getYear() + "-" + twoDigit(zdt.getMonthValue()) + "-" + twoDigit(zdt.getDayOfMonth()) + ".log");

try (FileWriter fr = new FileWriter(file.getAbsoluteFile(), true)) {
try (PrintWriter pr = new PrintWriter(fr)) {
pr.print("[" + twoDigit(zdt.getHour()) + ":" + twoDigit(zdt.getMinute()) + ":" + twoDigit(zdt.getSecond()) + "] ");
pr.println(txt);
}
} catch (IOException ex) {
ex.printStackTrace();
}
}

private static @NotNull String twoDigit(int i) {
return i > 9 ? Integer.toString(i) : "0" + i;
}
}
14 changes: 12 additions & 2 deletions src/main/resources/lang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

help:
- " "
- "&#FF5500&lAxSellwands &7»"
- "<gradient:#FF5500:#FF7700><bold>AxSellwands</gradient> &7»"
- " &7- &f/axsellwands reload &7| &#FF5500Reload plugin"
- " &7- &f/axsellwands give <player> <sellwand> [amount] &7| &#FF5500Give sellwands"
- " "
Expand Down Expand Up @@ -63,5 +63,15 @@ sell-hologram:
- "&#FFAA55Sold &f%amount% &#FFAA55items"
- "&#DDDDDD+%price%$"

commands:
invalid-value: "&#FF0000Invalid parameter: &#BB0000%value%"
invalid-command: "&#FF0000Invalid command or subcommand!"
missing-argument: "&#FF0000Missing argument! You must specify a value for &#BB0000%value%&#FF0000."
no-permission: "&#FF0000You don't have permission to access this command!"
out-of-range: "&#FF0000The &#BB0000%number% &#FF0000must be between &#BB0000%min% &#FF0000and &#BB0000%max%&#FF0000!"
player-only: "&#FF0000You must be a player to use this command!"
invalid-player: "&#FF0000The player &#BB0000%player% &#FF0000can not be found!"
invalid-selector: "&#FF0000You can not use this selector in this command!"

# do not change this
version: 1
version: 2

0 comments on commit b1f851d

Please sign in to comment.