use of thpmc.vanilla_source.api.player.EnginePlayer in project VanillaSource by TheHollowPlanetMC.
the class TickRunner method run.
@Override
public void run() {
if (beforeTime + TIME - 20 > System.currentTimeMillis())
return;
if (isStopped)
return;
if (i % TPS == 0) {
long time = System.currentTimeMillis();
tps = ((double) Math.round((20.0 / (((double) (time - beforeTime)) / 1000.0)) * 10)) / 10;
beforeTime = time;
}
currentThread = Thread.currentThread();
this.lastTickMS = System.currentTimeMillis();
// Should remove check
entities.removeIf(TickBase::shouldRemove);
tickOnlyEntities.removeIf(TickBase::shouldRemove);
// Add entities
if (addEntities.size() != 0) {
try {
ADD_LOCK.lock();
for (TickBase entity : addEntities) {
if (entity instanceof EngineEntity) {
entities.add((EngineEntity) entity);
} else {
tickOnlyEntities.add(entity);
}
}
addEntities.clear();
} finally {
ADD_LOCK.unlock();
}
}
// tick
tickOnlyEntities.forEach(TickBase::tick);
entities.forEach(TickBase::tick);
// Tracker
for (EnginePlayer enginePlayer : EnginePlayer.getAllPlayers()) {
EntityTracker entityTracker = getEntityTracker(enginePlayer);
entityTracker.tick(entities);
}
if (i % 40 == 0) {
// Remove offline player
trackerMap.keySet().removeIf(enginePlayer -> !enginePlayer.getBukkitPlayer().isOnline());
}
entities.forEach(EngineEntity::setPreviousPosition);
i++;
}
use of thpmc.vanilla_source.api.player.EnginePlayer in project VanillaSource by TheHollowPlanetMC.
the class parallelCommandExecutor method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (args == null)
return false;
if (args.length == 0)
return false;
if (args[0].equals("structure")) {
if (args.length < 3) {
return false;
}
// parallel structure set-data [structure-name] [data-name] [player]
if (args[1].equals("set-data")) {
if (args.length < 5) {
return false;
}
ParallelStructure parallelStructure = ParallelStructure.getParallelStructure(args[2]);
if (parallelStructure == null) {
sender.sendMessage(ChatColor.RED + "指定された名前の構造体は存在しません。");
return true;
}
ImplStructureData implStructureData = (ImplStructureData) ImplStructureData.getStructureData(args[3]);
if (implStructureData == null) {
sender.sendMessage(ChatColor.RED + "指定された名前の構造データは存在しません。");
return true;
}
Player player = Bukkit.getPlayer(args[4]);
if (player == null) {
sender.sendMessage(ChatColor.RED + "指定されたプレイヤーが見つかりませんでした。");
return true;
}
parallelStructure.setStructureData(player, implStructureData);
sender.sendMessage(ChatColor.GREEN + "適用しました。");
return true;
}
// parallel structure remove-data [structure-name] [player]
if (args[1].equals("remove-data")) {
if (args.length < 4) {
return false;
}
ParallelStructure parallelStructure = ParallelStructure.getParallelStructure(args[2]);
if (parallelStructure == null) {
sender.sendMessage(ChatColor.RED + "指定された名前の構造体は存在しません。");
return true;
}
Player player = Bukkit.getPlayer(args[3]);
if (player == null) {
sender.sendMessage(ChatColor.RED + "指定されたプレイヤーが見つかりませんでした。");
return true;
}
parallelStructure.clearStructureData(player, true);
sender.sendMessage(ChatColor.GREEN + "適用しました。");
return true;
}
}
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "このコマンドはコンソールから実行できません。");
return true;
}
if (args[0].equals("menu")) {
Player player = (Player) sender;
UniverseGUI.openUniverseGUI(player);
return true;
}
if (args[0].equals("join-universe")) {
if (args.length != 2)
return false;
String universeName = args[1];
ParallelUniverse universe = VanillaSourceAPI.getInstance().getUniverse(universeName);
if (universe == null) {
sender.sendMessage("§aThe universe is not found.");
return true;
}
EnginePlayer enginePlayer = EnginePlayer.getParallelPlayer((Player) sender);
if (enginePlayer == null)
return false;
enginePlayer.setUniverse(universe);
enginePlayer.getBukkitPlayer().sendMessage("§7Switched to §r" + universe.getName());
}
if (args[0].equals("leave-universe")) {
EnginePlayer enginePlayer = EnginePlayer.getParallelPlayer((Player) sender);
if (enginePlayer == null)
return false;
enginePlayer.setUniverse(null);
}
// parallel structure-data create [name]
if (args[0].equals("structure-data")) {
if (args.length < 3) {
return false;
}
if (args[1].equals("create")) {
Player player = (Player) sender;
com.sk89q.worldedit.entity.Player wePlayer = BukkitAdapter.adapt(player);
SessionManager sessionManager = WorldEdit.getInstance().getSessionManager();
LocalSession localSession = sessionManager.get(wePlayer);
com.sk89q.worldedit.world.World selectionWorld = localSession.getSelectionWorld();
Region region;
try {
if (selectionWorld == null)
throw new IncompleteRegionException();
region = localSession.getSelection(selectionWorld);
} catch (IncompleteRegionException ex) {
sender.sendMessage(ChatColor.GREEN + "範囲が選択されていません。");
return true;
}
BlockVector3 max = region.getMaximumPoint();
BlockVector3 min = region.getMinimumPoint();
World world = BukkitAdapter.adapt(region.getWorld());
Vector maxLocation = new Vector(max.getX(), max.getY(), max.getZ());
Vector minLocation = new Vector(min.getX(), min.getY(), min.getZ());
RegionBlocks regionBlocks = new RegionBlocks(minLocation.toLocation(world), maxLocation.toLocation(world));
ImplStructureData implStructureData = (ImplStructureData) StructureData.getStructureData(args[2]);
if (implStructureData != null) {
sender.sendMessage(ChatColor.RED + "指定された名前の構造データは既に存在しています。");
return true;
}
implStructureData = new ImplStructureData(args[2]);
implStructureData.setBlockData(minLocation.toLocation(world), regionBlocks.getBlocks());
sender.sendMessage(ChatColor.GREEN + "作成しました。");
return true;
}
if (args[1].equals("save")) {
ImplStructureData implStructureData = (ImplStructureData) ImplStructureData.getStructureData(args[2]);
if (implStructureData == null) {
sender.sendMessage(ChatColor.RED + "指定された名前の構造データは存在しません。");
return true;
}
implStructureData.saveData();
sender.sendMessage(ChatColor.GREEN + "保存しました。");
return true;
}
}
if (args[0].equals("structure")) {
if (args.length < 3) {
return false;
}
// parallel structure create [name]
if (args[1].equals("create")) {
Player player = (Player) sender;
com.sk89q.worldedit.entity.Player wePlayer = BukkitAdapter.adapt(player);
SessionManager sessionManager = WorldEdit.getInstance().getSessionManager();
LocalSession localSession = sessionManager.get(wePlayer);
com.sk89q.worldedit.world.World selectionWorld = localSession.getSelectionWorld();
Region region;
try {
if (selectionWorld == null)
throw new IncompleteRegionException();
region = localSession.getSelection(selectionWorld);
} catch (IncompleteRegionException ex) {
sender.sendMessage(ChatColor.GREEN + "範囲が選択されていません。");
return true;
}
BlockVector3 min = region.getMinimumPoint();
World world = BukkitAdapter.adapt(region.getWorld());
Vector minLocation = new Vector(min.getX(), min.getY(), min.getZ());
ParallelStructure parallelStructure = ParallelStructure.getParallelStructure(args[2]);
if (parallelStructure != null) {
sender.sendMessage(ChatColor.RED + "指定された名前の構造体は既に存在しています。");
return true;
}
parallelStructure = new ParallelStructure(args[2]);
parallelStructure.setBaseLocation(minLocation.toLocation(world));
sender.sendMessage(ChatColor.GREEN + "作成しました。");
return true;
}
// parallel structure save [name]
if (args[1].equals("save")) {
ParallelStructure parallelStructure = ParallelStructure.getParallelStructure(args[2]);
if (parallelStructure == null) {
sender.sendMessage(ChatColor.RED + "指定された名前の構造体は存在しません。");
return true;
}
parallelStructure.saveData();
sender.sendMessage(ChatColor.GREEN + "保存しました。");
return true;
}
}
return true;
}
use of thpmc.vanilla_source.api.player.EnginePlayer in project VanillaSource by TheHollowPlanetMC.
the class UniverseGUI method openUniverseGUI.
public static void openUniverseGUI(Player player) {
EnginePlayer enginePlayer = EnginePlayer.getParallelPlayer(player);
if (enginePlayer == null)
return;
Artist artist = new Artist(() -> {
ArtButton V = null;
ArtButton G = new ArtButton(new ItemBuilder(Material.GRAY_STAINED_GLASS_PANE).name("&a").build());
PageNextButton N = new PageNextButton(new ItemBuilder(Material.ARROW).name("&rNext page &7[{NextPage}/{MaxPage}]").build());
PageBackButton P = new PageBackButton(new ItemBuilder(Material.ARROW).name("&rPrevious page &7[{PreviousPage}/{MaxPage}]").build());
MenuBackButton B = new MenuBackButton(new ItemBuilder(Material.OAK_DOOR).name("&7Back to &r{PreviousName}").build());
ArtButton L = new ArtButton(new ItemBuilder(Material.BARRIER).name("&b&nLeave from current universe").build()).listener((inventoryClickEvent, menu) -> {
enginePlayer.setUniverse(null);
player.closeInventory();
});
return new ArtButton[] { V, V, V, V, V, V, V, G, G, V, V, V, V, V, V, V, G, N, V, V, V, V, V, V, V, G, P, V, V, V, V, V, V, V, G, G, V, V, V, V, V, V, V, G, L, V, V, V, V, V, V, V, G, B };
});
ArtMenu artMenu = artist.createMenu(VanillaSource.getPlugin().getArtGUI(), "&nUniverse list");
artMenu.asyncCreate(menu -> {
for (ParallelUniverse universe : VanillaSourceAPI.getInstance().getAllUniverse()) {
menu.addButton(new ArtButton(new ItemBuilder(Material.END_PORTAL_FRAME).name(universe.getName()).lore("&7Click to join.").build()).listener((inventoryClickEvent, menu1) -> {
enginePlayer.setUniverse(universe);
player.closeInventory();
player.sendMessage("§7Switched to §r" + universe.getName());
}));
}
});
artMenu.open(player);
}
use of thpmc.vanilla_source.api.player.EnginePlayer in project VanillaSource by TheHollowPlanetMC.
the class ImplEnginePlayer method onPlayerQuit.
public static void onPlayerQuit(Player player) {
EnginePlayer EnginePlayer = playerMap.get(player);
EnginePlayer.setUniverse(null);
playerMap.remove(player);
}
use of thpmc.vanilla_source.api.player.EnginePlayer in project VanillaSource by TheHollowPlanetMC.
the class ImplParallelUniverse method addDiffs.
@Override
public void addDiffs(ParallelUniverse universe) {
int indexStart = NMSManager.isHigher_v1_18_R1() ? -4 : 0;
int indexEnd = NMSManager.isHigher_v1_18_R1() ? 20 : 16;
for (ParallelWorld diffWorld : universe.getAllWorld()) {
for (ParallelChunk diffChunk : diffWorld.getAllChunk()) {
for (int i = indexStart; i < indexEnd; i++) {
ParallelWorld thisWorld = null;
ParallelChunk thisChunk = null;
SectionTypeArray sectionTypeArray = diffChunk.getSectionTypeArray(i);
if (sectionTypeArray != null) {
thisWorld = this.getWorld(diffWorld.getName());
thisChunk = ((ImplParallelWorld) thisWorld).createChunkIfAbsent(diffChunk.getChunkX(), diffChunk.getChunkZ());
SectionTypeArray thisType = ((ImplParallelChunk) thisChunk).createSectionTypeArrayIfAbsent(i);
sectionTypeArray.threadsafeIteration(thisType::setType);
}
SectionLevelArray blockLightLevelArray = diffChunk.getBlockLightSectionLevelArray(i);
if (blockLightLevelArray != null) {
if (thisWorld == null)
thisWorld = this.getWorld(diffWorld.getName());
if (thisChunk == null)
thisChunk = ((ImplParallelWorld) thisWorld).createChunkIfAbsent(diffChunk.getChunkX(), diffChunk.getChunkZ());
SectionLevelArray thisLevel = ((ImplParallelChunk) thisChunk).createBlockLightSectionLevelArrayIfAbsent(i);
blockLightLevelArray.threadsafeIteration(thisLevel::setLevel);
}
SectionLevelArray skyLightLevelArray = diffChunk.getSkyLightSectionLevelArray(i);
if (skyLightLevelArray != null) {
if (thisWorld == null)
thisWorld = this.getWorld(diffWorld.getName());
if (thisChunk == null)
thisChunk = ((ImplParallelWorld) thisWorld).createChunkIfAbsent(diffChunk.getChunkX(), diffChunk.getChunkZ());
SectionLevelArray thisLevel = ((ImplParallelChunk) thisChunk).createSkyLightSectionLevelArrayIfAbsent(i);
skyLightLevelArray.threadsafeIteration(thisLevel::setLevel);
}
}
}
}
for (EnginePlayer EnginePlayer : this.getResidents()) {
((ImplEnginePlayer) EnginePlayer).setUniverseRaw(null);
EnginePlayer.setUniverse(this);
}
}
Aggregations