Skip to content

Commit

Permalink
help
Browse files Browse the repository at this point in the history
  • Loading branch information
EggAllocationService committed Mar 27, 2021
1 parent 742827e commit e208b6e
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 22 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ repositories {
maven {
url 'https://repo.minebench.de/'
}
maven { url 'https://raw.githubusercontent.com/JorelAli/CommandAPI/mvn-repo/'}
}

dependencies {
compile fileTree(include: ['slime*.jar'], dir: 'lib')
compile fileTree(include: ['*.jar'], dir: 'lib')
compile 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT'
shadow 'de.themoep:minedown:1.7.0-SNAPSHOT'

}

test {
Expand All @@ -28,5 +30,4 @@ test {

shadowJar {
configurations = [project.configurations.shadow];

}
47 changes: 47 additions & 0 deletions src/main/java/io/gitlab/kyleafmine/worldeditor/MainCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.gitlab.kyleafmine.worldeditor;

import com.grinderwolf.swm.api.SlimePlugin;
import com.grinderwolf.swm.api.exceptions.WorldAlreadyExistsException;
import com.grinderwolf.swm.api.loaders.SlimeLoader;
import com.grinderwolf.swm.api.world.SlimeWorld;
import com.grinderwolf.swm.api.world.properties.SlimeProperties;
import com.grinderwolf.swm.api.world.properties.SlimePropertyMap;
import de.themoep.minedown.MineDown;
import io.gitlab.kyleafmine.worldeditor.menus.WorldListMenu;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;

public class MainCommand implements CommandExecutor {


@Override
public boolean onCommand(@NotNull CommandSender player, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length == 2 && args[0].equalsIgnoreCase("create")) {
SlimePropertyMap slp = new SlimePropertyMap();
slp.setInt(SlimeProperties.SPAWN_Y, 64);
slp.setInt(SlimeProperties.SPAWN_X, 0);
slp.setInt(SlimeProperties.SPAWN_Z, 0);
slp.setBoolean(SlimeProperties.ALLOW_ANIMALS, false);
slp.setBoolean(SlimeProperties.ALLOW_MONSTERS, false);
SlimePlugin s = (SlimePlugin) Bukkit.getPluginManager().getPlugin("SlimeWorldManager");
SlimeLoader sl = s.getLoader("mongodb");
try {
SlimeWorld sw = s.createEmptyWorld(sl, args[1], false, slp);
s.generateWorld(sw);
player.spigot().sendMessage(MineDown.parse("&aCreated empty world &d" + args[1]));
} catch (WorldAlreadyExistsException | IOException e) {
e.printStackTrace();
}

} else {
new WorldListMenu((Player) player);
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void interact(PlayerInteractEvent e ) {
}
}
@EventHandler
public void bucket(PlayerBucketEvent e) {
public void bucket(PlayerBucketEmptyEvent e) {
if (readOnlyWorlds.contains(e.getPlayer().getWorld().getName())) {
e.setCancelled(true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package io.gitlab.kyleafmine.worldeditor;


import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

public class WorldEditorProfile extends JavaPlugin {
public static WorldEditorProfile instance;

@Override
public void onLoad() {
super.onLoad();
}

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

getLogger().info("So this is a bad idea i don't know if hotloading is great");
getCommand("worlds").setExecutor(new MainCommand());
Bukkit.getPluginManager().registerEvents(new ReadOnlyWorldListener(), this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
import com.grinderwolf.swm.api.world.properties.SlimePropertyMap;
import de.themoep.minedown.MineDown;
import io.gitlab.kyleafmine.worldeditor.ReadOnlyWorldListener;
import io.gitlab.kyleafmine.worldeditor.WorldEditorProfile;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
Expand All @@ -39,14 +42,17 @@ public class WorldListMenu implements Listener {
public HashMap<Integer, String> currentPageMap = new HashMap<>();
int requiredPages;
int currentPage = 0;
List<List<String>> pages;
List<String> toRender;
public WorldListMenu(Player ps) {
p = ps;
i = Bukkit.createInventory(null, 54, "Worlds");
sp = (SlimePlugin) Bukkit.getPluginManager().getPlugin("SlimeWorldManager");
assert sp != null;
sl = sp.getLoader("mongodb");
Bukkit.getPluginManager().registerEvents(this, WorldEditorProfile.instance);
init();
p.openInventory(i);
render();
}
public void init() {
List<String> worlds;
Expand All @@ -56,44 +62,57 @@ public void init() {
e.printStackTrace();
return;
}
requiredPages = (int) Math.ceil(worlds.size() / 45);
pages = Lists.partition(worlds, 45);
assert pages.size() == requiredPages;
//requiredPages = (int) Math.ceil(worlds.size() / 45);
toRender = worlds;


}
public void render() {
i.clear();
currentPageMap.clear();
List<String> toRender = pages.get(currentPage);
int index = 0;
for (String s : toRender) {
currentPageMap.put(index, s);
i.setItem(index, iconHelper(s, Bukkit.getWorld(s) != null));
index++;
}
}

public ItemStack iconHelper(String s, Boolean b) {


ItemStack h = new ItemStack(Material.GRASS_BLOCK, 1);
ItemStack h = new ItemStack(b ? Material.GRASS_BLOCK : Material.DIRT, 1);
ItemMeta hm = h.getItemMeta();
hm.setDisplayNameComponent(MineDown.parse("&#6bc900&" + s));
hm.setDisplayNameComponent(MineDown.parse("&r&#6bc900&" + s));
ArrayList<BaseComponent[]> lore = new ArrayList<>();
if (b) {
lore.add(MineDown.parse("&#919191&World is currently loaded."));
lore.add(MineDown.parse("&#ff3721&Q to unload world"));
h.addItemFlags(ItemFlag.HIDE_ENCHANTS);
h.addEnchantment(Enchantment.ARROW_INFINITE, 1);
if (ReadOnlyWorldListener.readOnlyWorlds.contains(s)) {

lore.add(MineDown.parse("&r&#919191&World is currently loaded. &7(Read Only)"));
} else {
lore.add(MineDown.parse("&r&#919191&World is currently loaded."));
}
lore.add(MineDown.parse("&r&#ff3721&Q to unload world"));
lore.add(MineDown.parse("&r&#7ce35d&Shift-Left-Click to teleport to world spawn"));
// h.addItemFlags(ItemFlag.HIDE_ENCHANTS);
//h.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 1);
} else {
lore.add(MineDown.parse("&#7ce35d&Left-Click to edit world"));
lore.add(MineDown.parse("&#dfe312&Right-Click to view world"));
lore.add(MineDown.parse("&r&#7ce35d&Left-Click to edit world"));
lore.add(MineDown.parse("&r&#dfe312&Right-Click to view world"));
}

hm.setLoreComponents(lore);
h.setItemMeta(hm);
return h;
}

@EventHandler
public void close(InventoryCloseEvent e) {
if (e.getInventory() == this.i) {
HandlerList.unregisterAll(this);
}
}

public void loadWorld(String s, Player p, Boolean lock) {
try {
SlimePropertyMap slp = new SlimePropertyMap();
Expand All @@ -102,7 +121,7 @@ public void loadWorld(String s, Player p, Boolean lock) {
slp.setInt(SlimeProperties.SPAWN_Z, 0);
slp.setBoolean(SlimeProperties.ALLOW_ANIMALS, false);
slp.setBoolean(SlimeProperties.ALLOW_MONSTERS, false);
SlimeWorld sw = sp.loadWorld(sl, s, lock, slp);
SlimeWorld sw = sp.loadWorld(sl, s, !lock, slp);
sp.generateWorld(sw);
p.closeInventory();
p.teleport(Bukkit.getWorld(s).getSpawnLocation());
Expand Down Expand Up @@ -133,6 +152,8 @@ public void loadWorld(String s, Player p, Boolean lock) {
public void click(InventoryClickEvent e) {
if (e.getClickedInventory() == i) {
e.setCancelled(true);
} else {
return;
}
if (e.getClick() == ClickType.LEFT) {
//left click on shit
Expand Down Expand Up @@ -173,14 +194,20 @@ public void click(InventoryClickEvent e) {
c.teleport(Bukkit.getServer().getWorlds().get(0).getSpawnLocation());
}
}
if (ReadOnlyWorldListener.readOnlyWorlds.contains(clicked)) {
Bukkit.unloadWorld(clicked, false);
ReadOnlyWorldListener.readOnlyWorlds.remove(clicked);
if (!ReadOnlyWorldListener.readOnlyWorlds.contains(clicked)) {
Bukkit.getWorld(clicked).save();
} else {
Bukkit.unloadWorld(clicked, true);
ReadOnlyWorldListener.readOnlyWorlds.remove(clicked);
}
Bukkit.unloadWorld(Bukkit.getWorld(clicked), false);

}
} else if (e.getClick() == ClickType.SHIFT_LEFT) {
// shift-left; teleport to world spawn
String clicked = currentPageMap.get(e.getSlot());
if (Bukkit.getWorld(clicked) != null) {
p.teleport(Bukkit.getWorld(clicked).getSpawnLocation());
}
}
}
}
9 changes: 8 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
name: WorldEditorPlugin
main: io.gitlab.kyleafmine.worldeditor.WorldEditorProfile
version: 1.0.0
version: 1.0.2
api-version: "1.16"
depend:
- SlimeWorldManager
commands:
worlds:
description: Worlds Menu
usage: /worlds

0 comments on commit e208b6e

Please sign in to comment.