Skip to content

Commit

Permalink
📦 同步主仓库 (3ae536bbd2e15596d4aaf412861fb4022b1e0e49)
Browse files Browse the repository at this point in the history
  • Loading branch information
INSide-734 committed Oct 26, 2024
1 parent 3f32c25 commit 447a0b6
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 50 deletions.
14 changes: 0 additions & 14 deletions MMOItems-API/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>

</build>
Expand Down Expand Up @@ -186,12 +178,6 @@
<version>2.9.2</version>
<scope>provided</scope>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Mythic -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.lumine.mythic.lib.version.VMaterial;
import net.Indyuce.mmoitems.stat.*;
import net.Indyuce.mmoitems.stat.annotation.DeprecatedStat;
import net.Indyuce.mmoitems.stat.block.*;
import net.Indyuce.mmoitems.stat.type.*;
import org.bukkit.Material;
Expand Down Expand Up @@ -234,5 +235,6 @@ public class ItemStats {
* custom durability is now {@link CustomDurability}
*/
@Deprecated
@DeprecatedStat
public static final ItemStat DURABILITY = ITEM_DAMAGE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class FormattedMessage {
private final boolean actionBar;
Expand All @@ -22,8 +23,8 @@ public class FormattedMessage {
*
* @param message Unformatted message
*/
public FormattedMessage(Message message) {
this.message = message.getUpdated();
public FormattedMessage(@NotNull Message message) {
this.message = message.getRaw();
this.actionBar = MMOItems.plugin.getConfig().getBoolean("action-bar-display." + message.getActionBarConfigPath());
}

Expand All @@ -40,8 +41,10 @@ public FormattedMessage(String message, boolean actionBar) {
}

@NotNull
public FormattedMessage format(ChatColor prefix, String... toReplace) {
message = prefix + message;
public FormattedMessage format(@Nullable ChatColor prefix, @NotNull String... toReplace) {
if (message.isEmpty()) return this;

if (prefix != null) message = prefix + message;
for (int j = 0; j < toReplace.length; j += 2)
message = message.replace(toReplace[j], toReplace[j + 1]);
return this;
Expand All @@ -54,16 +57,20 @@ public FormattedMessage format(ChatColor prefix, String... toReplace) {
* @param player Player receiving the message
*/
public void send(Player player) {
if (ChatColor.stripColor(message).isEmpty())
return;
if (message.isEmpty()) return;

// Finally apply color
message = MythicLib.plugin.parseColors(message);

// Send to action bar
if (actionBar) {
if (Bukkit.getPluginManager().isPluginEnabled("MMOCore"))
PlayerData.get(player).setLastActivity(PlayerActivity.ACTION_BAR_MESSAGE);

MythicLib.plugin.getVersion().getWrapper().sendActionBar(player, message);
} else
player.sendMessage(message);
}

// Send to chat
else player.sendMessage(message);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.lumine.mythic.lib.MythicLib;
import org.bukkit.ChatColor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

Expand Down Expand Up @@ -78,15 +79,14 @@ public enum Message {
UNABLE_TO_REPAIR("This item can't be repaired by this consumable!"),
;

private final String defaultMessage, path, actionBarConfigPath;
private final String defaultMessage, actionBarConfigPath;

@NotNull
private String current;
private String raw;

private Message(String defaultMessage, String actionBarConfigPath) {
this.defaultMessage = defaultMessage;
this.current = defaultMessage;
this.path = name().toLowerCase().replace("_", "-");
private Message(@NotNull String defaultMessage, @Nullable String actionBarConfigPath) {
this.defaultMessage = Objects.requireNonNull(defaultMessage);
this.raw = defaultMessage;
this.actionBarConfigPath = actionBarConfigPath;
}

Expand All @@ -98,12 +98,18 @@ public String getDefault() {
return defaultMessage;
}

public String getUpdated() {
return MythicLib.plugin.parseColors(current);
@NotNull
public String getFormatted() {
return MythicLib.plugin.parseColors(raw);
}

@NotNull
public String getRaw() {
return raw;
}

public void setCurrent(@NotNull String str) {
this.current = Objects.requireNonNull(str);
public void setRaw(@NotNull String str) {
this.raw = Objects.requireNonNull(str);
}

public boolean isActionBarMessage() {
Expand All @@ -115,11 +121,11 @@ public String getActionBarConfigPath() {
}

@Deprecated
public String formatRaw(ChatColor prefix, String... toReplace) {
public String formatRaw(@Nullable ChatColor prefix, String... toReplace) {
return format(prefix, toReplace).toString();
}

public FormattedMessage format(ChatColor prefix, String... toReplace) {
public FormattedMessage format(@Nullable ChatColor prefix, String... toReplace) {
return new FormattedMessage(this).format(prefix, toReplace);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.Indyuce.mmoitems.api.block.CustomBlock;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

Expand All @@ -31,6 +32,11 @@ public static boolean matches(Block block) {
return MMOItems.plugin.getCustomBlocks().isMushroomBlock(block.getType());
}

@Override
public @NotNull String display() {
return "MMOItems{" + id + "}";
}

@Override
public void place(RegeneratingBlock regeneratingBlock) {
Location loc = regeneratingBlock.getLocation();
Expand All @@ -45,11 +51,6 @@ public void regenerate(RegeneratingBlock regeneratingBlock) {
place(regeneratingBlock);
}

@Override
public String generateKey() {
return "mmoitems-custom-block-" + id;
}

@Override
public boolean breakRestrictions(Block block) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;

public class MythicMobsCompatibility implements Listener {

Expand All @@ -28,7 +29,8 @@ public MythicMobsCompatibility() {
try {
for (String faction : this.getFactions())
MMOItems.plugin.getStats().register(new FactionDamage(faction));
} catch (NullPointerException ignored) {
} catch (Exception exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Exception while enabling MythicMobs compatibility: " + exception.getMessage());
}

Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private void loadTranslations() {
if (!messages.getConfig().contains(path))
messages.getConfig().set(path, message.getDefault());

message.setCurrent(messages.getConfig().getString(path));
message.setRaw(messages.getConfig().getString(path));
}
messages.save();

Expand Down Expand Up @@ -239,7 +239,7 @@ public String getStatFormat(String path) {

@Deprecated
public String getMessage(String path) {
return Message.valueOf(UtilityMethods.enumName(path)).getUpdated();
return Message.valueOf(UtilityMethods.enumName(path)).getFormatted();
}

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ConfigFile;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.stat.annotation.DeprecatedStat;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.category.StatCategory;
import net.Indyuce.mmoitems.stat.type.*;
Expand Down Expand Up @@ -60,18 +61,19 @@ public void loadBuiltins() {
&& field.get(null) instanceof StatCategory)
registerCategory((StatCategory) field.get(null));
} catch (IllegalArgumentException | IllegalAccessException exception) {
MMOItems.plugin.getLogger().log(Level.SEVERE, String.format("Couldn't register category called '%s'", field.getName()), exception.getMessage());
MMOItems.plugin.getLogger().log(Level.SEVERE, String.format("Couldn't register category called '%s': %s", field.getName(), exception.getMessage()));
}

// Load builtin stats
for (Field field : ItemStats.class.getFields())
try {
if (Modifier.isStatic(field.getModifiers())
&& Modifier.isFinal(field.getModifiers())
&& field.get(null) instanceof ItemStat)
&& field.get(null) instanceof ItemStat
&& field.getAnnotation(DeprecatedStat.class) == null)
register((ItemStat<?, ?>) field.get(null));
} catch (IllegalArgumentException | IllegalAccessException exception) {
MMOItems.plugin.getLogger().log(Level.SEVERE, String.format("Couldn't register stat called '%s'", field.getName()), exception.getMessage());
MMOItems.plugin.getLogger().log(Level.SEVERE, String.format("Couldn't register stat called '%s': %s", field.getName(), exception.getMessage()));
}

// Custom stats
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEv
@Override
public ParticleData whenInitialized(Object object) {
Validate.isTrue(object instanceof ConfigurationSection, "必须指定配置部分");
if (((ConfigurationSection) object).getKeys(false).size() < 1) { throw new IllegalArgumentException(""); }
return new ParticleData((ConfigurationSection) object);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ public void whenApplied(@NotNull ItemStackBuilder item, @NotNull SoulboundData d
item.addItemTag(getAppliedNBT(data));

// Lore stuff
String formattedLoreTag = Message.SOULBOUND_ITEM_LORE.getUpdated().replace("#player#", ((SoulboundData) data).getName()).replace("#level#",
MMOUtils.intToRoman(data.getLevel()));
item.getLore().insert("soulbound", formattedLoreTag.split(Pattern.quote("//")));
String formattedLoreTag = Message.SOULBOUND_ITEM_LORE.getFormatted().replace("#player#", data.getName()).replace("#level#", MMOUtils.intToRoman(data.getLevel()));
item.getLore().insert("soulbound", formattedLoreTag.split(Pattern.quote("//")));
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.Indyuce.mmoitems.stat.annotation;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface DeprecatedStat {
}

0 comments on commit 447a0b6

Please sign in to comment.