1.0.0
This commit is contained in:
parent
7d9aae21df
commit
302f6a8338
|
@ -5,6 +5,7 @@ import com.yaohun.order.config.Config;
|
||||||
import com.yaohun.order.gui.ReceiveGui;
|
import com.yaohun.order.gui.ReceiveGui;
|
||||||
import com.yaohun.order.listener.PlayerListener;
|
import com.yaohun.order.listener.PlayerListener;
|
||||||
import com.yaohun.order.manage.OrderManager;
|
import com.yaohun.order.manage.OrderManager;
|
||||||
|
import com.yaohun.order.tabcommand.DorderTabCompleter;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -23,6 +24,7 @@ public class OrderMain extends JavaPlugin {
|
||||||
OrderManager.initOrderManager();
|
OrderManager.initOrderManager();
|
||||||
getServer().getPluginManager().registerEvents(new ReceiveGui(),this);
|
getServer().getPluginManager().registerEvents(new ReceiveGui(),this);
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(),this);
|
getServer().getPluginManager().registerEvents(new PlayerListener(),this);
|
||||||
|
getCommand("dorder").setTabCompleter(new DorderTabCompleter());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -39,6 +39,14 @@ public class Config {
|
||||||
return orderContentList;
|
return orderContentList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> getOrderKeyList(){
|
||||||
|
List<String> strings = new ArrayList<>();
|
||||||
|
for (OrderContent orderContent : orderContentList) {
|
||||||
|
strings.add(orderContent.getKey());
|
||||||
|
}
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
|
|
||||||
public static OrderContent getOrderContent(String key) {
|
public static OrderContent getOrderContent(String key) {
|
||||||
for (OrderContent orderContent : orderContentList) {
|
for (OrderContent orderContent : orderContentList) {
|
||||||
if (orderContent.getKey().equals(key)) {
|
if (orderContent.getKey().equals(key)) {
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.yaohun.order.tabcommand;
|
||||||
|
|
||||||
|
import com.yaohun.order.config.Config;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class DorderTabCompleter implements TabCompleter {
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
// 当输入了两个参数,并且第一个参数为"give"时,补全第二个参数
|
||||||
|
if (args.length == 3 && "kit".equalsIgnoreCase(args[0])) {
|
||||||
|
// 从配置中获取所有药水的键集合,并过滤出以当前输入开头的药水名
|
||||||
|
List<String> subcommands = new ArrayList<>(Config.getOrderKeyList());
|
||||||
|
if(sender instanceof Player){
|
||||||
|
Player player = (Player) sender;
|
||||||
|
player.playSound(player.getLocation(), Sound.BLOCK_COMPARATOR_CLICK,1,1);
|
||||||
|
}
|
||||||
|
return subcommands.stream()
|
||||||
|
.filter(s -> s.toLowerCase().startsWith(args[2].toLowerCase()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
// 如果不符合上述条件,则返回空列表
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,7 +14,14 @@ public class OrderAllocator {
|
||||||
public static Map<String, Integer> allocateOrdersTW(List<OrderContent> orders, int totalTW) {
|
public static Map<String, Integer> allocateOrdersTW(List<OrderContent> orders, int totalTW) {
|
||||||
orders.sort((a, b) -> Integer.compare(b.twPreic, a.twPreic)); // 从大到小
|
orders.sort((a, b) -> Integer.compare(b.twPreic, a.twPreic)); // 从大到小
|
||||||
Map<String, Integer> result = new LinkedHashMap<>();
|
Map<String, Integer> result = new LinkedHashMap<>();
|
||||||
|
if(totalTW < 100){
|
||||||
|
result.put("Coins_Custom", totalTW / 5);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
for (OrderContent order : orders) {
|
for (OrderContent order : orders) {
|
||||||
|
if(order.twPreic < 5){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
int count = totalTW / order.twPreic;
|
int count = totalTW / order.twPreic;
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
result.put(order.getKey(), count);
|
result.put(order.getKey(), count);
|
||||||
|
@ -30,7 +37,14 @@ public class OrderAllocator {
|
||||||
public static Map<String, Integer> allocateOrdersCN(List<OrderContent> orders, int totalTW) {
|
public static Map<String, Integer> allocateOrdersCN(List<OrderContent> orders, int totalTW) {
|
||||||
orders.sort((a, b) -> Integer.compare(b.cnPrice, a.cnPrice)); // 从大到小
|
orders.sort((a, b) -> Integer.compare(b.cnPrice, a.cnPrice)); // 从大到小
|
||||||
Map<String, Integer> result = new LinkedHashMap<>();
|
Map<String, Integer> result = new LinkedHashMap<>();
|
||||||
|
if(totalTW < 100){
|
||||||
|
result.put("Coins_Custom", totalTW);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
for (OrderContent order : orders) {
|
for (OrderContent order : orders) {
|
||||||
|
if(order.cnPrice < 1){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
int count = totalTW / order.cnPrice;
|
int count = totalTW / order.cnPrice;
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
result.put(order.getKey(), count);
|
result.put(order.getKey(), count);
|
||||||
|
@ -49,7 +63,7 @@ public class OrderAllocator {
|
||||||
orders.add(new OrderContent("Coins_300", 1200, 300, new ArrayList<>()));
|
orders.add(new OrderContent("Coins_300", 1200, 300, new ArrayList<>()));
|
||||||
orders.add(new OrderContent("Coins_1000", 4000, 1000, new ArrayList<>()));
|
orders.add(new OrderContent("Coins_1000", 4000, 1000, new ArrayList<>()));
|
||||||
orders.add(new OrderContent("Coins_2000", 8000, 2000, new ArrayList<>()));
|
orders.add(new OrderContent("Coins_2000", 8000, 2000, new ArrayList<>()));
|
||||||
int totalTW = 1350;
|
int totalTW = 1200;
|
||||||
Map<String, Integer> allocation = allocateOrdersCN(orders, totalTW);
|
Map<String, Integer> allocation = allocateOrdersCN(orders, totalTW);
|
||||||
allocation.forEach((k, v) -> System.out.println(k + " x " + v));
|
allocation.forEach((k, v) -> System.out.println(k + " x " + v));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user