Skip to content

Commit

Permalink
Merge branch 'Drak-God:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Drak-God authored Nov 5, 2024
2 parents 17528c3 + b067825 commit b00931f
Show file tree
Hide file tree
Showing 10 changed files with 638 additions and 125 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<img src="https://img.shields.io/badge/server-leaves_1.20.6-brightgreen"></br>
<img src="https://img.shields.io/badge/QQ群-941070901-cyan">
<img src="https://img.shields.io/badge/mc-ViaVersion支持版本(默认1.20.6)-green">
<img src="https://img.shields.io/badge/serverIP-game.kamc.monster-yellow">
<img src="https://img.shields.io/badge/服务器地址-game.kamc.monster-yellow">
<img src="https://img.shields.io/badge/游玩提示-需加入QQ群发送验证码游玩-red">

# 简介

Expand Down
Binary file added lib/EssentialsX.jar
Binary file not shown.
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.kamcdrakgod.utility</groupId>
<artifactId>kamc_utility_plugin</artifactId>
<version>Beta1.0.1</version>
<version>1.0</version>
<name>kamc_utility_plugin</name>

<properties>
Expand Down Expand Up @@ -38,6 +38,13 @@
<artifactId>gson</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>com.earth2me.essentials</groupId>
<artifactId>EssentialsX</artifactId>
<version>2.21.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/EssentialsX.jar</systemPath>
</dependency>
</dependencies>

<build>
Expand Down
185 changes: 181 additions & 4 deletions src/main/java/com/DrakGod/KaMCUP/AllUse.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,196 @@
package com.DrakGod.KaMCUP;

import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Server;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.PluginManager;

import com.earth2me.essentials.Essentials;

public class AllUse {
Server server = Bukkit.getServer();
Server server = Bukkit.getServer();
File pluginfolder = getMain().getDataFolder();
Logger logger = server.getLogger();
PluginManager pluginmanager = server.getPluginManager();
ConsoleCommandSender console = server.getConsoleSender();
Logger logger = server.getLogger();

public Main getMain() {
return Main.getCMain();
public static Main getMain() {return Main.getCMain();}
public static CheckUpdate getCheckUpdate() {return getMain().CCheckUpdate;}
public static CommandHandler geCommandHandler() {return getMain().CCommandHandler;}
public static Listeners getListeners() {return getMain().CListeners;}
public static TabCompleters getTabCompleters() {return getMain().CTabCompleters;}

public interface Tab_to_run {
public abstract List<String> run();
}

public List Load_File(File file) {
boolean out = false;
try {
out = file.createNewFile();
} catch(Exception e) {
logger.warning("[KaMC实用插件] 无法创建配置文件:"+file.getName());
}
return Arrays.asList(out,YamlConfiguration.loadConfiguration(file));
}

public void Save_File(FileConfiguration config,File file) {
try {
config.save(file);
} catch (Exception e) {
logger.warning("[KaMC实用插件] 无法保存配置文件:"+file.getName());
}
}

public static List<HashMap> get_All_Tasks() {
List<HashMap> tasks = (List<HashMap>) getMain().Daily_Tasks.get("daily_tasks");
if (tasks == null) {
return new ArrayList();
} else {
return tasks;
}
}

public static List<String> get_All_Task_Names() {
List out = new ArrayList<String>();
List<HashMap> tasks = (List<HashMap>) AllUse.getMain().Daily_Tasks.get("daily_tasks");
if (tasks == null) {return out;}
tasks.forEach((task) -> {out.add(new ArrayList<String>(task.keySet()).get(0));});
return out;
}

public static List<String> get_All_Items() {
List<String> space_name = Stream.of(Material.values())
.filter(material -> material.isItem())
.map(material -> material.getKey().toString())
.collect(Collectors.toList());
List<String> item_name = Stream.of(Material.values())
.filter(material -> material.isItem())
.map(Enum::name)
.collect(Collectors.toList());
item_name.forEach((name) -> {
space_name.add(name.toLowerCase());
});
return space_name;
}

public static List<String> get_Max_Daily_Task() {
Integer int_max = (int) AllUse.getMain().Daily_Tasks.get("max_daily_task");
if (int_max == null) {
return Arrays.asList("5");
} else {
return Arrays.asList(int_max.toString());
}
}

public static List<String> get_Random_Tasks() {
int max = new Integer(get_Max_Daily_Task().get(0));
List<String> AllTasks = get_All_Task_Names();
int AllTasks_len = AllTasks.toArray().length;
if (AllTasks_len <= max) {
return AllTasks;
} else {
List<String> out = new ArrayList<>();
String Temp = AllTasks.get(0);
for (int i=0;i<max;i++) {
while (out.contains(Temp)) {
Temp = AllTasks.get((int) (Math.random()*AllTasks_len));
}
out.add(Temp);
}
return out;
}
}

public static HashMap get_Daily_Task(String name) {
List<HashMap> tasks = (List) getMain().Daily_Tasks.get("daily_tasks");
HashMap out = new HashMap();
Iterator<HashMap> iterator = tasks.iterator();
while (iterator.hasNext()) {
HashMap<String,HashMap> task = iterator.next();
String task_name = new ArrayList<String>(task.keySet()).get(0);
if (task_name.equalsIgnoreCase(name)) {
out = task.get(task_name);
}
}
return out;
}

public ItemStack get_Item_At_Name(String name) {
NamespacedKey key = NamespacedKey.fromString(name);
Material material = Material.matchMaterial(key.getKey());
if (material == null) {
material = Material.matchMaterial(name.toUpperCase());
if (material == null) {
return null;
}
}
return new ItemStack(material);
}

public int get_Player_Item_Count(Player player,ItemStack item) {
int count = 0;Iterator iterator = player.getInventory().iterator();
while (iterator.hasNext()) {
ItemStack oitem = (ItemStack) iterator.next();
if (oitem != null && oitem.getType() == item.getType()) {
count = count + oitem.getAmount();
}
}
return count;
}

public boolean remove_Player_Amount_Item(Player player,ItemStack item,int count) {
int amount = count;PlayerInventory player_inventory = player.getInventory();
Iterator iterator = player_inventory.iterator();
boolean removed = false;int i = 0;
while (iterator.hasNext() & amount > 0) {
ItemStack oitem = (ItemStack) iterator.next();
if (oitem != null && oitem.getType() == item.getType()) {
Integer currentAmount = oitem.getAmount();
logger.info(currentAmount.toString());
if (currentAmount <= amount) {
amount -= currentAmount;
player_inventory.setItem(i,new ItemStack(Material.AIR));
} else {
oitem.setAmount(currentAmount - amount);
amount = 0;removed = true;break;
}
}
i = i + 1;
}
player.updateInventory();
return removed;
}

public Essentials get_Essentials() {
return getMain().essentials;
}

public BigDecimal get_Player_Money(Player player) {
return get_Essentials().getUser(player).getMoney();
}

public void set_Player_Money(Player player,BigDecimal money) {
try {
get_Essentials().getUser(player).setMoney(money);
} catch (Exception e) {}
}
}
Loading

0 comments on commit b00931f

Please sign in to comment.