Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TskResourceWorld v0.1 #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
out/

#idea

.idea/
*.iml
*.ipr
*.iws
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/spigot-plugin.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions ResourceWorld/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ResourceWorld

## 当前版本的使用说明 release 0.1

**功能**

1. 资源世界内岩浆附近生成远古残骸,钻石生成增加
2. 资源世界周期性自动更新,默认设置为两天刷新,一天空闲
3. 当资源世界存在时,玩家可通过站在激活的信标上(无透明方块阻挡光柱),进入资源世界,传送坐标临时设为(1145, y, 1419),在(0, y, 0)附近会生成返程的信标光柱,离开方式与进入方式相同。对于传送时下线有相应处理
4. 资源世界内禁止使用床(设置重生点),末影箱,禁止地狱门的生成
5. 玩家进入资源世界时,仅会保留物品栏最靠前的一件物品以及盔甲栏内物品,同时将无论位置直接移除鞘翅、信标、下界之星以及潜影箱相关物品。玩家离开资源世界时候将返还
6. 资源世界永夜,物品掉落
7. 当玩家在资源世界内而资源世界被销毁时,将会“落入虚空”,对于下线了的玩家有相关处理
8. 目前有调试指令test(带补全),其子命令
1. info 返回当前资源世界信息
2. rebuild 立即重建资源世界
3. destroy 立即销毁资源世界,进入“空闲”
4. join < player> 若资源世界存在,使玩家进入资源世界(无物品没收)
5. leave < player> 离开资源世界
6. check < player> 返回当前所在世界



**待测试内容**

1. 对于多人同时进行传送时的稳定性有待验证
2. 当前仅测试了玩家主动下线的意外情况,掉线、服务器崩溃、网络崩溃等情况均未测试



**已确认的问题及当前预期解决方案**

1. 世界创建时将会较长时间(半分钟)完全占用服务器进程,客户端将会出现服务器卡死的状态(交互无反应,掉落物无法捡起),这个状态未深入测试。当前解决方案考虑移除自动更新的功能,或写成接口,供自动维护时调用。(也可以考虑什么都不做,毕竟这种卡顿和正常卡顿完全一样)

15 changes: 15 additions & 0 deletions ResourceWorld/src/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
api-version: "1.16"
name: ResourceWorld
main: top.tsk.ResourceWorld
version: F0310d_dev_JvJv
author: JvJv, cckk
website: mc.tsktop.top
commands:
test:
usage: '/test <rebuild|destroy>; /test <join|leave|check> [name]'
description: 'for test'
permisson: 'test.use'
permisson-message: 'u dt have the permisson to use this command'
permissions:
test.use:
default: op
57 changes: 57 additions & 0 deletions ResourceWorld/src/top/tsk/ResourceWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package top.tsk;

import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
import top.tsk.core.Storage;
import top.tsk.core.Test;
import top.tsk.world.manager.SingleWorldManager;
import top.tsk.world.manager.WorldManager;

public class ResourceWorld extends JavaPlugin {

private static ResourceWorld instance = null;

public static Storage getStorage() {
return instance.storage;
}

public static WorldManager getWorldManager() {
return instance.worldManager;
}

//========================================================

private Storage storage = null;
private WorldManager worldManager = null;

@Override
public void onEnable() {
ResourceWorld.instance = this;

this.storage = new Storage(getDataFolder());

//TODO: 测试模块,release版本中应移除
Test testClass = new Test();
PluginCommand cmd = getCommand("test");
assert null != cmd;
cmd.setTabCompleter(testClass);
cmd.setExecutor(testClass);

this.worldManager = new SingleWorldManager(this);
worldManager.deploy(this);

getLogger().info("Plugin ResourceWorld has been deployed");
}

@Override
public void onDisable() {
this.worldManager.save();
this.storage.save();

this.worldManager = null;
this.storage = null;

ResourceWorld.instance = null;
getLogger().info("Plugin ResourceWorld has been removed");
}
}
125 changes: 125 additions & 0 deletions ResourceWorld/src/top/tsk/core/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package top.tsk.core;

import com.sun.istack.internal.NotNull;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;

public class Storage {

private File playerFolder;
private File dataFile;
private Map<String, FileConfiguration> mp;

private FileConfiguration dataConfig = null;

public Storage(@NotNull File dataFolder) {
playerFolder = new File(dataFolder, "player");
dataFile = new File(dataFolder, "data.yml");
mp = new HashMap<>();
}

//==================================================================================================================

private void loadDataConfig() {
this.dataConfig = YamlConfiguration.loadConfiguration(this.dataFile);
}

private void loadPlayerConfig(String playerName) {
File playerFile = new File(playerFolder, playerName + ".yml");
this.mp.put(playerName, YamlConfiguration.loadConfiguration(playerFile));
}

private FileConfiguration getPlayerConfig(String playerName) {
if (!this.mp.containsKey(playerName)) {
loadPlayerConfig(playerName);
}
return this.mp.get(playerName);
}

private FileConfiguration getDataConfig() {
if (null == this.dataConfig) {
loadDataConfig();
}

return this.dataConfig;
}

//==================================================================================================================

public void save() {
try {
dataConfig.save(this.dataFile);
} catch (IOException e) {
Bukkit.getServer().getLogger().log(Level.SEVERE, "Could not save config to " + this.dataFile, e);
}

for (Map.Entry<String, FileConfiguration> it : mp.entrySet()) {
File playerFile = new File(playerFolder, it.getKey() + ".yml");
try {
it.getValue().save(playerFile);
} catch (IOException e) {
Bukkit.getServer().getLogger().log(Level.SEVERE, "Could not save config to " + playerFolder, e);
}
}
}

public void setData(String path, Object value) {
getDataConfig().createSection(path);
getDataConfig().set(path, value);
}

public int getInt(String path, int def) {
return getDataConfig().getInt(path, def);
}

public String getString(String path, String def) {
return getDataConfig().getString(path, def);
}

public Location getLocation(String path, Location def) {
return getDataConfig().getLocation(path, def);
}

public ItemStack getItemStack(String path, ItemStack def) {
return getDataConfig().getItemStack(path, def);
}

public boolean getBoolean(String path, boolean def) {
return getDataConfig().getBoolean(path, def);
}

public void setPlayerData(String playerName, String path, Object value) {
FileConfiguration config = getPlayerConfig(playerName);
config.createSection(path);
config.set(path, value);
}

public int getPlayerInt(String playerName, String path, int def) {
return getPlayerConfig(playerName).getInt(path, def);
}

public String getPlayerString(String playerName, String path, String def) {
return getPlayerConfig(playerName).getString(path, def);
}

public Location getPlayerLocation(String playerName, String path, Location def) {
return getPlayerConfig(playerName).getLocation(path, def);
}

public ItemStack getPlayerItemStack(String playerName, String path, ItemStack def) {
return getPlayerConfig(playerName).getItemStack(path, def);
}

public boolean getPlayerBoolean(String playerName, String path, boolean def) {
return getPlayerConfig(playerName).getBoolean(path, def);
}
}
83 changes: 83 additions & 0 deletions ResourceWorld/src/top/tsk/core/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package top.tsk.core;

import org.bukkit.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import top.tsk.ResourceWorld;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;

public class Test implements TabExecutor {
@Override
public boolean onCommand(@Nonnull CommandSender sender, @Nonnull Command cmd, @Nonnull String label, @Nonnull String[] args) {
if (1 == args.length) {
String str = args[0];
switch (str) {
case "info":
sender.sendMessage(ResourceWorld.getWorldManager().getWorldInfo());
break;
case "rebuild":
if (ResourceWorld.getWorldManager().rebuildWorldFromCommand()) {
sender.sendMessage("Successfully rebuild");
} else {
sender.sendMessage("Failed to rebuild");
}
break;
case "destroy":
if (ResourceWorld.getWorldManager().destroyWorldFromCommand()) {
sender.sendMessage("Successfully destroy");
} else {
sender.sendMessage("Failed to rebuild");
}
break;
default:
return false;
}
}

if (2 == args.length) {
String playerName = args[1];
Player player = Bukkit.getPlayer(playerName);
if (null == player) return false;

switch (args[0]) {
case "join":
if (!ResourceWorld.getWorldManager().playerJoinFromCommand(player)) {
sender.sendMessage("Failed to join");
}
break;
case "leave":
if (!ResourceWorld.getWorldManager().playerQuitFromCommand(player)) {
sender.sendMessage("Failed to leave");
}
break;
case "check":
sender.sendMessage(playerName + " is in world" + ResourceWorld.getWorldManager());
break;
default:
return false;
}
}

return true;
}

@Override
public List<String> onTabComplete(@Nonnull CommandSender sender, @Nonnull Command cmd, @Nonnull String label, @Nonnull String[] args) {
if (1 == args.length)
return new ArrayList<String>() {{
add("info");
add("rebuild");
add("destroy");
add("join");
add("leave");
add("check");
}};
else
return null;
}
}
Loading