Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
a1640727878 committed Feb 14, 2020
1 parent 3af3e1c commit 4da299c
Show file tree
Hide file tree
Showing 18 changed files with 211 additions and 64 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pluginGroup=sky_bai.bukkit
pluginVersion=0.2.2
pluginVersion=0.2.4
28 changes: 14 additions & 14 deletions src/main/java/sky_bai/bukkit/baiteam/BaiTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import sky_bai.bukkit.baiteam.config.BTConfig;
import sky_bai.bukkit.baiteam.config.BTDefaultConfig;
import sky_bai.bukkit.baiteam.config.BTMessageConfig;
import sky_bai.bukkit.baiteam.config.gui.BTCAction;
import sky_bai.bukkit.baiteam.config.gui.BTCGui;
import sky_bai.bukkit.baiteam.config.gui.BTCModule;
import sky_bai.bukkit.baiteam.config.gui.BTGAction;
import sky_bai.bukkit.baiteam.config.gui.BTGGui;
import sky_bai.bukkit.baiteam.config.gui.BTGModule;
import sky_bai.bukkit.baiteam.listener.BaiTeamListener;
import sky_bai.bukkit.baiteam.message.BTMessage;
import sky_bai.bukkit.baiteam.team.TeamManager;
import sky_bai.bukkit.baiteam.team.TeamTeleport;
import sky_bai.bukkit.baiteam.team.TeamTeleportExpired;
import sky_bai.bukkit.baiteam.util.BTPlaceholderAPI;

public final class BaiTeam extends JavaPlugin {
Expand All @@ -49,9 +49,9 @@ public void onEnable() {

BTConfig.setConfig(new BTDefaultConfig());
BTConfig.setMessage(new BTMessageConfig());
BTConfig.setGui(new BTCGui());
BTConfig.setAction(new BTCAction());
BTConfig.setModule(new BTCModule());
BTConfig.setGui(new BTGGui());
BTConfig.setAction(new BTGAction());
BTConfig.setModule(new BTGModule());

teamManager = new TeamManager();

Expand All @@ -67,16 +67,16 @@ public void onEnable() {
}

Bukkit.getPluginManager().registerEvents(new BaiTeamListener(), this);

new BukkitRunnable() {
@Override
public void run() {
for (Long time : TeamTeleport.UuidTime.keySet()) {
if (System.currentTimeMillis() - time >= BTConfig.getConfig().getConfig().getLong("ExpiredTime", 20000)) {
String uuid = TeamTeleport.UuidTime.get(time);
TeamTeleport.LocationMap.remove(uuid);
TeamTeleport.TeleportPlayer.remove(uuid);
TeamTeleport.UuidTime.remove(time);
for (Long time : TeamTeleportExpired.UuidTime.keySet()) {
if (System.currentTimeMillis() - time >= BTConfig.getConfig().getConfig().getLong("Time.Teleport.Expired", 20000)) {
String uuid = TeamTeleportExpired.UuidTime.get(time);
TeamTeleportExpired.LocationMap.remove(uuid);
TeamTeleportExpired.TeleportPlayer.remove(uuid);
TeamTeleportExpired.UuidTime.remove(time);
}
}
}
Expand Down
44 changes: 30 additions & 14 deletions src/main/java/sky_bai/bukkit/baiteam/command/BTCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import de.erethon.dungeonsxl.world.DGameWorld;
import de.erethon.dungeonsxl.world.DResourceWorld;
import sky_bai.bukkit.baiteam.BaiTeam;
import sky_bai.bukkit.baiteam.config.BTConfig;
import sky_bai.bukkit.baiteam.event.BTEAcceptPlayerApplyEvent;
import sky_bai.bukkit.baiteam.event.BTEAcceptTeamInviteEvent;
import sky_bai.bukkit.baiteam.event.BTECreateTeamEvent;
Expand All @@ -33,7 +34,9 @@
import sky_bai.bukkit.baiteam.gui.TeamGui;
import sky_bai.bukkit.baiteam.message.BTMessage;
import sky_bai.bukkit.baiteam.team.Team;
import sky_bai.bukkit.baiteam.team.TeamTeleport;
import sky_bai.bukkit.baiteam.team.TeamPromotional;
import sky_bai.bukkit.baiteam.team.TeamTeleportExpired;
import sky_bai.bukkit.baiteam.util.BTTools;

public class BTCommand {
private static boolean ifPlayerTeleport(Player player1, Player player2) {
Expand All @@ -45,7 +48,7 @@ private static boolean ifPlayerTeleport(Player player1, Player player2) {
double z = (player1.getLocation().getZ() > player2.getLocation().getZ()) ? (player1.getLocation().getZ() - player2.getLocation().getZ()) : (player2.getLocation().getZ() - player1.getLocation().getZ());
return ((x + y + z) >= 10);
}

public static boolean play(Player player, String[] args) {
DungeonsXL dungeonsXL = DungeonsXL.getInstance();
if (args.length < 3 || dungeonsXL.getDWorldCache().getResourceByName(args[2]) == null || dungeonsXL.getDPlayerCache().getByPlayer(player) instanceof DInstancePlayer) {
Expand Down Expand Up @@ -96,18 +99,18 @@ public static boolean teleport(Player sender, String[] args) {
World world = (args.length > 6 && Bukkit.getWorld(args[6]) != null) ? Bukkit.getWorld(args[6]) : player.getWorld();
Location location = new Location(world, x, y, z);
String uuid = UUID.randomUUID().toString();
while (TeamTeleport.LocationMap.containsKey(uuid)) {
while (TeamTeleportExpired.LocationMap.containsKey(uuid)) {
uuid = UUID.randomUUID().toString();
}
long time = System.currentTimeMillis();
while (TeamTeleport.UuidTime.containsKey(time)) {
while (TeamTeleportExpired.UuidTime.containsKey(time)) {
time = time + 1;
}
TeamTeleport.LocationMap.put(uuid, location);
TeamTeleportExpired.LocationMap.put(uuid, location);
Set<Player> tpPlayers = new HashSet<Player>();
tpPlayers.add(player);
TeamTeleport.TeleportPlayer.put(uuid, tpPlayers);
TeamTeleport.UuidTime.put(time, uuid);
TeamTeleportExpired.TeleportPlayer.put(uuid, tpPlayers);
TeamTeleportExpired.UuidTime.put(time, uuid);
player.teleport(location);
if (team != null && team.getLeader() == player) {
Set<Player> players = team.getMembers();
Expand All @@ -120,16 +123,16 @@ public static boolean teleport(Player sender, String[] args) {
}
} else if (args[1].equalsIgnoreCase("yes") && args.length > 2) {
String uuid = args[2];
if (TeamTeleport.LocationMap.containsKey(uuid) == false) {
if (TeamTeleportExpired.LocationMap.containsKey(uuid) == false) {
sender.sendMessage(BTMessage.Error.OnTeleportIsNo.getMes());
return false;
}
if (TeamTeleport.TeleportPlayer.get(uuid).contains(sender)) {
if (TeamTeleportExpired.TeleportPlayer.get(uuid).contains(sender)) {
sender.sendMessage(BTMessage.Error.OnTeleportIsNo.getMes());
return false;
}
sender.teleport(TeamTeleport.LocationMap.get(uuid));
TeamTeleport.TeleportPlayer.get(uuid).add(sender);
sender.teleport(TeamTeleportExpired.LocationMap.get(uuid));
TeamTeleportExpired.TeleportPlayer.get(uuid).add(sender);
}
return true;
}
Expand Down Expand Up @@ -169,7 +172,14 @@ public static boolean openGui(Player sender, String[] args) {
}

public static boolean create(Player player, String[] args) {
String name = player.getName();
String name = "";
boolean b = BTConfig.getConfig().getConfig().getBoolean("TeamNames.Enable",true);
if (b) {
List<String> names = BTConfig.getConfig().getConfig().getStringList("TeamNames.List");
name = BTTools.RandomString(names);
} else {
name = player.getName();
}
if (args.length > 1) {
name = args[1];
}
Expand Down Expand Up @@ -206,7 +216,7 @@ public static boolean apply(Player player, String[] args) {
if (args.length <= 2 || Bukkit.getPlayer(args[2]) == null) {
return false;
}
boolean b = args[1].toLowerCase() == "yes" ? true : false;
boolean b = args[1].toLowerCase().equalsIgnoreCase("yes") ? true : false;
Player player2 = Bukkit.getPlayer(args[2]);
if (BaiTeam.getTeamManager().getTeam(player, true) == null) {
BTMessage.send(player, BTMessage.Error.OnPlayerNoLeader, null);
Expand Down Expand Up @@ -235,7 +245,7 @@ public static boolean invite(Player player, String[] args) {
if (args.length <= 2 || BaiTeam.getTeamManager().ifTeam(args[2]) == false) {
return false;
}
boolean b = args[1].toLowerCase() == "yes" ? true : false;
boolean b = args[1].toLowerCase().equalsIgnoreCase("yes") ? true : false;
Team team = BaiTeam.getTeamManager().getTeam(args[2]);
Bukkit.getPluginManager().callEvent(new BTEAcceptTeamInviteEvent(team, player, b));
return true;
Expand Down Expand Up @@ -306,6 +316,9 @@ public static boolean promotional(Player player, String[] args) {
return false;
}
Team team = BaiTeam.getTeamManager().getTeam(args[1]);
if (TeamPromotional.PromotionalTime.containsKey(team) && (TeamPromotional.PromotionalTime.get(team) + BTConfig.getConfig().getConfig().getLong("Time.Promotional.CoolDown",20000)) >= System.currentTimeMillis()) {
return false;
}
Bukkit.getPluginManager().callEvent(new BTEPromotionalTeamEvent(team));
return true;
}
Expand All @@ -316,6 +329,9 @@ public static boolean guipromotional(Player player, String[] args) {
return false;
}
Team team = BaiTeam.getTeamManager().getTeam(args[1]);
if (TeamPromotional.PromotionalTime.containsKey(team) && (TeamPromotional.PromotionalTime.get(team) + BTConfig.getConfig().getConfig().getLong("Time.Promotional.CoolDown",20000)) >= System.currentTimeMillis()) {
return false;
}
Bukkit.getPluginManager().callEvent(new BTEPromotionalTeamEvent(team));
TeamGui.openGui(player, "Teaminfo", 0);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import sky_bai.bukkit.baiteam.config.BTConfig;

public class BTCommandCMD implements CommandExecutor {

@Override
Expand All @@ -17,15 +19,18 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
Player player = Bukkit.getPlayer(strs[0]);
String[] args = new String[strs.length - 1];
for (int i = 0; i < args.length; i++) {
args[i] = strs[i+1];
args[i] = strs[i + 1];
}
switch (strs[0].toLowerCase()) {
case "play":
return BTCommand.play(player, args);
case "opengui":
return BTCommand.openGui(player, args);
case "kickdun":
case "kickdun":
return BTCommand.kickTeamFoDungeon(player, args);
case "relaod":
BTConfig.reload();
return true;
}
}
return false;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/sky_bai/bukkit/baiteam/config/BTConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package sky_bai.bukkit.baiteam.config;

import java.io.File;
import java.io.IOException;

import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;

public class BTConfig {
Expand Down Expand Up @@ -54,7 +58,19 @@ public static void setModule(Config module) {
BTConfig.module = module;
}

public static void reload() {
try {
config.getConfig().load(config.getConfigFile());
message.getConfig().load(message.getConfigFile());
gui.getConfig().load(gui.getConfigFile());
action.getConfig().load(action.getConfigFile());
module.getConfig().load(module.getConfigFile());
} catch (IOException | InvalidConfigurationException e) {
}
}

public interface Config {
public FileConfiguration getConfig();
public File getConfigFile();
}
}
28 changes: 26 additions & 2 deletions src/main/java/sky_bai/bukkit/baiteam/config/BTDefaultConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
Expand All @@ -11,7 +13,7 @@
import sky_bai.bukkit.baiteam.BaiTeam;

public class BTDefaultConfig implements BTConfig.Config {
private File configFile = new File(BaiTeam.getInstance().getDataFolder(), "config.yml");
public final File configFile = new File(BaiTeam.getInstance().getDataFolder(), "config.yml");
private FileConfiguration config = new YamlConfiguration();

public BTDefaultConfig() {
Expand All @@ -27,8 +29,30 @@ public FileConfiguration getConfig() {
return config;
}

@Override
public File getConfigFile() {
return configFile;
}

public void reset() throws FileNotFoundException, IOException, InvalidConfigurationException {
BaiTeam.getInstance().saveDefaultConfig();
BaiTeam.getInstance().getDataFolder().mkdirs();
configFile.createNewFile();
config.load(configFile);

if (config.getKeys(false).size() > 0) {
return;
}

config.set("MesPrefix", "[BaiTeam] ");
config.set("Time.Teleport.Expired", 20000);
config.set("Time.Promotional.CoolDown", 20000);
config.set("TeamSize", 5);

List<String> names = Arrays.asList("队伍名","小队名","小组名");
config.set("TeamNames.Enable", true);
config.set("TeamNames.List", names);

config.save(configFile);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sky_bai.bukkit.baiteam.message.BTMessage;

public class BTMessageConfig implements BTConfig.Config {
private File configFile = new File(BaiTeam.getInstance().getDataFolder(), "message.yml");
public final File configFile = new File(BaiTeam.getInstance().getDataFolder(), "message.yml");
private FileConfiguration config = new YamlConfiguration();

public BTMessageConfig() {
Expand All @@ -25,6 +25,11 @@ public FileConfiguration getConfig() {
return config;
}

@Override
public File getConfigFile() {
return configFile;
}

public void reset() throws IOException, InvalidConfigurationException {
BaiTeam.getInstance().getDataFolder().mkdirs();
configFile.createNewFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sky_bai.bukkit.baiteam.BaiTeam;

public class BTConfigGui {
private static File guiConfigPath = new File(BaiTeam.getInstance().getDataFolder(), "gui");
private final static File guiConfigPath = new File(BaiTeam.getInstance().getDataFolder(), "gui");

public static File getGuiConfigPath() {
return guiConfigPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

import sky_bai.bukkit.baiteam.config.BTConfig;

public class BTCAction implements BTConfig.Config {
private File configFile = new File(BTConfigGui.getGuiConfigPath(), "action.yml");
public class BTGAction implements BTConfig.Config {
public final File configFile = new File(BTConfigGui.getGuiConfigPath(), "action.yml");
private FileConfiguration config = new YamlConfiguration();

public BTCAction() {
public BTGAction() {
try {
reset();
} catch (IOException | InvalidConfigurationException e) {
Expand All @@ -25,6 +25,11 @@ public FileConfiguration getConfig() {
return config;
}

@Override
public File getConfigFile() {
return configFile;
}

public void reset() throws FileNotFoundException, IOException, InvalidConfigurationException {
BTConfigGui.getGuiConfigPath().mkdirs();
configFile.createNewFile();
Expand All @@ -35,7 +40,7 @@ public void reset() throws FileNotFoundException, IOException, InvalidConfigurat
}

setConfig("创建队伍", "[创建队伍]", "/baiteam create", "创建你的队伍");
setConfig("加入队伍", "[加入队伍]", "/baiteam opengui TeamLis", "寻找可以加入的队伍");
setConfig("加入队伍", "[加入队伍]", "/baiteam opengui TeamList", "寻找可以加入的队伍");
setConfig("队伍人数", "[%baiteam_team_members_amount%/5]", null, "%baiteam_team_members%");
setConfig("邀请玩家true", "[邀请玩家]", "/baiteam OpenGui PlayerList", "点击查看未加入队伍的玩家");
setConfig("邀请玩家false", "[§7邀请玩家§r]", null, "只有队长可以邀请玩家");
Expand Down
Loading

0 comments on commit 4da299c

Please sign in to comment.