Finished initial b1_7_3 implementation.
This commit is contained in:
parent
90d43ac3de
commit
4857bd155a
11 changed files with 291 additions and 7 deletions
|
|
@ -0,0 +1,13 @@
|
|||
package io.github.adrianvic.nemesiseye.impl;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.Events;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockListener;
|
||||
|
||||
public class BlockEventListener extends BlockListener {
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
Events.onBlockBreak(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
package io.github.adrianvic.nemesiseye.impl;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.Nemesis;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class ConfigurationEx extends Configuration {
|
||||
private final File configFile;
|
||||
private final Log logger;
|
||||
JavaPlugin plugin;
|
||||
|
||||
public ConfigurationEx(String fileName, Log _logger) {
|
||||
super(new File(Nemesis.getInstance().getDataFolder(), fileName));
|
||||
this.plugin = Nemesis.getInstance();
|
||||
logger = _logger;
|
||||
this.configFile = new File(plugin.getDataFolder(), fileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
createParentDirectories();
|
||||
|
||||
if (!configFile.exists()) {
|
||||
copyDefaultConfig();
|
||||
}
|
||||
|
||||
try {
|
||||
super.load();
|
||||
} catch (Exception e) {
|
||||
logger.severe(String.format("Failed to load config '%s': %s", configFile.getName(), e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
private void createParentDirectories() {
|
||||
try {
|
||||
Files.createDirectories(configFile.getParentFile().toPath());
|
||||
} catch (IOException e) {
|
||||
logger.severe(String.format("Failed to generate default config directory: %s", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
private void copyDefaultConfig() {
|
||||
// Load the config from the JAR directly (it is located at the root level)
|
||||
String resourcePath = "/" + configFile.getName(); // Root path of JAR
|
||||
|
||||
try (InputStream input = plugin.getClass().getResourceAsStream(resourcePath)) {
|
||||
if (input == null) {
|
||||
logger.severe(String.format("Default config '%s' wasn't found in the JAR.", configFile.getName()));
|
||||
return;
|
||||
}
|
||||
|
||||
Files.copy(input, configFile.toPath());
|
||||
if (Files.exists(configFile.toPath())) {
|
||||
logger.info(String.format("Default config '%s' generated successfully.", configFile.getName()));
|
||||
} else {
|
||||
logger.warning("We tried to generate the default config file, but it was not found even after the creation. Maybe your permissions are broken?");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.severe(String.format("Failed to generate default config '%s': %s", configFile.getName(), e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
try {
|
||||
this.load();
|
||||
logger.info(String.format("Config '%s' loaded successfully.", configFile.getName()));
|
||||
} catch (Exception e) {
|
||||
logger.severe(String.format("Failed to load config '%s': %s", configFile.getName(), e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
try {
|
||||
this.save();
|
||||
logger.info(String.format("Config '%s' saved successfully.", configFile.getName()));
|
||||
} catch (Exception e) {
|
||||
logger.severe(String.format("Failed to save config '%s': %s", configFile.getName(), e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public File getConfig() {
|
||||
return configFile;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package io.github.adrianvic.nemesiseye.impl;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.Events;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityListener;
|
||||
|
||||
public class EntityEventListener extends EntityListener {
|
||||
public void onEntityDamage(EntityDamageByEntityEvent event) {
|
||||
// Events.onEntityDamageByEntityEvent(event);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
41
src/b1_7_3/java/io/github/adrianvic/nemesiseye/impl/Log.java
Normal file
41
src/b1_7_3/java/io/github/adrianvic/nemesiseye/impl/Log.java
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package io.github.adrianvic.nemesiseye.impl;
|
||||
|
||||
import static org.bukkit.Bukkit.getServer;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.Nemesis;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Log {
|
||||
JavaPlugin plugin;
|
||||
PluginDescriptionFile pdf;
|
||||
|
||||
public Log() {
|
||||
plugin = Nemesis.getInstance();
|
||||
pdf = plugin.getDescription();
|
||||
}
|
||||
|
||||
public void info(String message) {
|
||||
getServer().getLogger().info("[" + pdf.getName() + "] " + message);
|
||||
}
|
||||
|
||||
public void infoc(String message) {
|
||||
getServer().getLogger().info("[" + pdf.getName() + "] " + message);
|
||||
}
|
||||
|
||||
public void warning(String message) {
|
||||
getServer().getLogger().warning("[" + pdf.getName() + "] " + message);
|
||||
}
|
||||
|
||||
public void warningc(String message) {
|
||||
getServer().getLogger().warning("[" + pdf.getName() + "] " + message);
|
||||
}
|
||||
|
||||
public void severe(String message) {
|
||||
getServer().getLogger().severe("[" + pdf.getName() + "] " + message);
|
||||
}
|
||||
|
||||
public void severec(String message) {
|
||||
getServer().getLogger().severe("[" + pdf.getName() + "] " + message);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package io.github.adrianvic.nemesiseye.impl;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.Events;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockListener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
|
||||
public class PlayerEventListener extends PlayerListener {
|
||||
@Override
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Events.onInteractionEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,19 +1,110 @@
|
|||
package io.github.adrianvic.nemesiseye.impl;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.Nemesis;
|
||||
import io.github.adrianvic.nemesiseye.impl.commands.Eye;
|
||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||
import io.github.adrianvic.nemesiseye.policy.PolicyParsers;
|
||||
import io.github.adrianvic.nemesiseye.policy.policies.LocationPolicy;
|
||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class b1_7_3 implements Glimmer {
|
||||
JavaPlugin plugin;
|
||||
PluginManager pm;
|
||||
ConfigurationEx config;
|
||||
|
||||
@Override
|
||||
public File loadConfigFile() {
|
||||
return null;
|
||||
config = new ConfigurationEx("settings.yml", new Log());
|
||||
config.load();
|
||||
return config.getConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Policy> loadPoliciesFromFile(File file) {
|
||||
return List.of();
|
||||
List<?> rawPolicies = config.getList("Policies");
|
||||
|
||||
if (rawPolicies == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<Map<?, ?>> result = new ArrayList<>(rawPolicies.size());
|
||||
|
||||
for (Object entry : rawPolicies) {
|
||||
if (entry instanceof Map<?,?> m) {
|
||||
result.add(m);
|
||||
}
|
||||
}
|
||||
|
||||
List<Policy> allPolicies = new ArrayList<>();
|
||||
for (Map<?, ?> map : result) {
|
||||
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||
if (entry.getKey() instanceof String k && entry.getValue() instanceof List<?> v) {
|
||||
List<Policy> parsed = PolicyParsers.get(k).parse(v);
|
||||
allPolicies.addAll(parsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
return allPolicies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Policy> getApplyingPoliciesForEntity(HumanEntity entity, List<Policy> policies) {
|
||||
List<Policy> result = new ArrayList<>();
|
||||
for (Policy p : policies) {
|
||||
if (p instanceof LocationPolicy lp) {
|
||||
for (List<Box> boxList : lp.locations()) {
|
||||
for (Box b : boxList) {
|
||||
if (b.contains(entity.getLocation().toVector())) result.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
plugin = Nemesis.getInstance();
|
||||
pm = Nemesis.getInstance().getPluginManager();
|
||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, new EntityEventListener(), Event.Priority.Normal, plugin);
|
||||
pm.registerEvent(Event.Type.BLOCK_BREAK, new BlockEventListener(), Event.Priority.Normal, plugin);
|
||||
pm.registerEvent(Event.Type.PLAYER_INTERACT, new PlayerEventListener(), Event.Priority.Normal, plugin);
|
||||
plugin.getCommand("eye").setExecutor(new Eye());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemInMainHandHumanEntity(HumanEntity entity) {
|
||||
return entity.getItemInHand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasItemMeta(ItemStack item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<World> getWorlds() {
|
||||
return plugin.getServer().getWorlds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasEnchantment(ItemStack item, Map<String, String> valuesmap) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAnyEnchantment(ItemStack itemStack) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package io.github.adrianvic.nemesiseye.impl.commands;
|
||||
|
||||
import io.github.adrianvic.nemesiseye.commands.EyeCore;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class Eye implements CommandExecutor {
|
||||
private EyeCore core;
|
||||
|
||||
public Eye() {
|
||||
core = new EyeCore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String [] strings) {
|
||||
return core.onCommand(commandSender, command, s, strings);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
name: "Eye-of-Nemesis"
|
||||
version: '1.0.2-SNAPSHOT'
|
||||
version: '1.0.3-SNAPSHOT'
|
||||
main: io.github.adrianvic.nemesiseye.Nemesis
|
||||
author: 'Adrian Victor'
|
||||
description: "Change what players can do based in custom criteria."
|
||||
description: "Change what players can do based in custom criteria."
|
||||
commands:
|
||||
eye:
|
||||
description: "Run /eye help to see all available commands."
|
||||
|
|
@ -18,8 +18,8 @@ public final class Nemesis extends JavaPlugin {
|
|||
public void onEnable() {
|
||||
instance = this;
|
||||
glim = loadGlim();
|
||||
Config.getInstance().load();
|
||||
glim.onLoad();
|
||||
Config.getInstance().load();
|
||||
}
|
||||
|
||||
private String readImplVersion() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
name: "Eye-of-Nemesis"
|
||||
version: '1.0.2-SNAPSHOT'
|
||||
version: '1.0.3-SNAPSHOT'
|
||||
main: io.github.adrianvic.nemesiseye.Nemesis
|
||||
api-version: '1.21'
|
||||
author: 'Adrian Victor'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue