Skip to content

Commit

Permalink
pref: some change.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mcayear committed Feb 11, 2025
1 parent fea6fc5 commit 0f09041
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>RcRPG.RcRPGMain</groupId>
<artifactId>RcRPG</artifactId>
<version>1.1.8</version>
<version>1.1.9</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
39 changes: 19 additions & 20 deletions src/main/java/RcRPG/RPG/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,64 @@ public class Level {
public static Level instance;
public static boolean enable = true;

public Level(){
public Level() {
instance = this;
}

public static boolean addExp(Player player,int exp){
public static boolean addExp(Player player, int exp) {
String name = player.getName();
if(Handle.getPlayerConfig(name) == null) {
if (Handle.getPlayerConfig(name) == null) {
return false;
}
Config config = Handle.getPlayerConfig(name);
int newExp = config.getInt("经验", 0) + exp;
int level = config.getInt("等级", 0);
int oldLevel = level;
while(newExp >= level * MainConfig.getExpIncrement()){
while (newExp >= level * MainConfig.getExpIncrement()) {
newExp -= level * MainConfig.getExpIncrement();
level++;
}
config.set("经验",newExp);
config.set("经验", newExp);
String text = MainConfig.getExpGainMessage();
if(!text.isEmpty()){
if(text.contains("@player")) text = text.replace("@player",name);
if(text.contains("@exp")) text = text.replace("@exp",String.valueOf(exp));
if (!text.isEmpty()) {
if (text.contains("@player")) text = text.replace("@player", name);
if (text.contains("@exp")) text = text.replace("@exp", String.valueOf(exp));
player.sendMessage(text);
}
config.save();
addLevel(player,level - oldLevel);
addLevel(player, level - oldLevel);
return true;
}

public static void addLevel(Player player, int level){
if(level == 0) return;
public static void addLevel(Player player, int level) {
if (level == 0) return;
String name = player.getName();
Config config = Handle.getPlayerConfig(name);
int newLevel = config.getInt("等级", 0) + level;
if(!MainConfig.getExpGainMessage().isEmpty()){
if (!MainConfig.getExpGainMessage().isEmpty()) {
String text = MainConfig.getExpGainMessage();
if(text.contains("@player")) text = text.replace("@player",name);
if(text.contains("@level")) text = text.replace("@level",String.valueOf(level));
if(text.contains("@newLevel")) text = text.replace("@newLevel",String.valueOf(newLevel));
if (text.contains("@player")) text = text.replace("@player", name);
if (text.contains("@level")) text = text.replace("@level", String.valueOf(level));
if (text.contains("@newLevel")) text = text.replace("@newLevel", String.valueOf(newLevel));
player.sendMessage(text);
}
config.set("等级",newLevel);
config.set("等级", newLevel);
config.save();

}

public static int getLevel(Player player){
public static int getLevel(Player player) {
Config config = Handle.getPlayerConfig(player.getName());
if (config == null) return 0;
return config.getInt("等级", 0);
}

public static int getExp(Player player){
public static int getExp(Player player) {
Config config = Handle.getPlayerConfig(player.getName());
if (config == null) return 0;
return config.getInt("经验", 0);
}

public static int getMaxExp(Player player){
public static int getMaxExp(Player player) {
Config config = Handle.getPlayerConfig(player.getName());
if (config == null) return 0;
int level = config.getInt("等级", 0);
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/RcRPG/RPG/Ornament.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ public static Item getItem(String name, int count) {
if (ornament == null) return Item.AIR_ITEM;
Item item = ornament.getItem();
item.setCount(count);
CompoundTag tag = item.getNamedTag();
if (tag == null) {
tag = new CompoundTag();
}
CompoundTag tag = item.hasCompoundTag() ? item.getNamedTag() : new CompoundTag();
tag.putString("type", "ornament");
tag.putString("name", name);
tag.putByte("Unbreakable", 1);
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/RcRPG/RPG/Stone.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ public static Item getItem(String name, int count) {
Stone stone = RcRPGMain.loadStone.get(name);
Item item = stone.getItem();
item.setCount(count);
CompoundTag tag = item.getNamedTag();
if (tag == null) {
tag = new CompoundTag();
}
CompoundTag tag = item.hasCompoundTag() ? item.getNamedTag() : new CompoundTag();
tag.putString("type", "stone");
tag.putString("name", name);
tag.putByte("Unbreakable", 1);
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/RcRPG/RPG/Weapon.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ public static Item getItem(String name, int count, LangCode langCode) {
Weapon weapon = RcRPGMain.loadWeapon.get(name);
Item item = weapon.getItem().clone();
item.setCount(count);
CompoundTag tag = item.getNamedTag();
if (tag == null) {
tag = new CompoundTag();
}
CompoundTag tag = item.hasCompoundTag() ? item.getNamedTag() : new CompoundTag();
tag.putString("type", "weapon");
tag.putString("name", name);
if (weapon.isUnBreak()) {
Expand Down

0 comments on commit 0f09041

Please sign in to comment.