mirror of
https://github.com/TotalFreedomMC/TF-Marriage.git
synced 2024-05-19 19:11:21 +00:00
Add some required internal mechanics
This commit is contained in:
parent
1b7ab6c551
commit
811e84034c
9
pom.xml
9
pom.xml
|
@ -60,14 +60,11 @@
|
|||
<!-- Resources -->
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/java/</directory>
|
||||
<directory>src/main/resources/</directory>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>**</include>
|
||||
<include>*</include>
|
||||
</includes>
|
||||
<!-- Don't add source files to target jar -->
|
||||
<excludes>
|
||||
<exclude>me/lenis0012/**/*.java</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
|
|
|
@ -4,9 +4,9 @@ import java.util.UUID;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.lenis0012.bukkit.marriage2.commands.Command;
|
||||
import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
|
||||
import com.lenis0012.bukkit.marriage2.misc.BConfig;
|
||||
|
||||
public interface Marriage {
|
||||
|
@ -60,5 +60,5 @@ public interface Marriage {
|
|||
*
|
||||
* @return Plugin instance.
|
||||
*/
|
||||
MarriagePlugin getPlugin();
|
||||
Plugin getPlugin();
|
||||
}
|
|
@ -6,7 +6,7 @@ import net.minecraft.util.com.google.common.collect.Lists;
|
|||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
|
||||
import com.lenis0012.bukkit.marriage2.internal.MarriageCore;
|
||||
|
||||
public class Settings<T> {
|
||||
private static final List<Settings<?>> cache = Lists.newArrayList();
|
||||
|
@ -43,14 +43,13 @@ public class Settings<T> {
|
|||
}
|
||||
}
|
||||
|
||||
public static final void reloadAll() {
|
||||
MarriagePlugin plugin = MarriagePlugin.getCore().getPlugin();
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
public static final void reloadAll(MarriageCore core) {
|
||||
FileConfiguration config = core.getPlugin().getConfig();
|
||||
for(Settings<?> setting : cache) {
|
||||
setting.reload(config);
|
||||
}
|
||||
|
||||
plugin.saveConfig();
|
||||
core.getPlugin().saveConfig();
|
||||
}
|
||||
|
||||
public static final List<Settings<?>> values() {
|
||||
|
|
|
@ -1,26 +1,42 @@
|
|||
package com.lenis0012.bukkit.marriage2.internal;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.lenis0012.bukkit.marriage2.MPlayer;
|
||||
import com.lenis0012.bukkit.marriage2.commands.CommandMarry;
|
||||
import com.lenis0012.bukkit.marriage2.config.Message;
|
||||
import com.lenis0012.bukkit.marriage2.config.Settings;
|
||||
import com.lenis0012.bukkit.marriage2.internal.data.DataManager;
|
||||
import com.lenis0012.bukkit.marriage2.internal.data.MarriageData;
|
||||
import com.lenis0012.bukkit.marriage2.internal.data.MarriagePlayer;
|
||||
import com.lenis0012.bukkit.marriage2.listeners.DatabaseListener;
|
||||
|
||||
public class MarriageCore extends MarriageBase {
|
||||
|
||||
private final Map<UUID, MarriagePlayer> players = Collections.synchronizedMap(new HashMap<UUID, MarriagePlayer>());
|
||||
private DataManager dataManager;
|
||||
|
||||
public MarriageCore(MarriagePlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Register(name = "config", type = Register.Type.ENABLE, priority = 0)
|
||||
public void loadConfig() {
|
||||
Settings.reloadAll();
|
||||
plugin.saveDefaultConfig();
|
||||
Settings.reloadAll(this);
|
||||
Message.reloadAll(this);
|
||||
}
|
||||
|
||||
@Register(name = "messages", type = Register.Type.ENABLE, priority = 1)
|
||||
public void loadMessages() {
|
||||
Message.reloadAll(this);
|
||||
@Register(name = "database", type = Register.Type.ENABLE)
|
||||
public void loadDatabase() {
|
||||
this.dataManager = new DataManager(this, plugin.getConfig());
|
||||
}
|
||||
|
||||
@Register(name = "listeners", type = Register.Type.ENABLE)
|
||||
public void registerListeners() {
|
||||
register(new DatabaseListener(this));
|
||||
}
|
||||
|
||||
@Register(name = "commands", type = Register.Type.ENABLE)
|
||||
|
@ -28,15 +44,21 @@ public class MarriageCore extends MarriageBase {
|
|||
register(CommandMarry.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MPlayer getMPlayer(UUID uuid) {
|
||||
// TODO: Everything...
|
||||
return null;
|
||||
MarriagePlayer player = players.get(uuid);
|
||||
if(player == null) {
|
||||
player = dataManager.loadPlayer(uuid);
|
||||
players.put(uuid, player);
|
||||
}
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void marry(MPlayer player1, MPlayer player2) {
|
||||
// TODO: Marry player1 with player2
|
||||
MarriageData mdata = new MarriageData(player1.getUniqueId(), player2.getUniqueId());
|
||||
((MarriagePlayer) player1).addMarriage(mdata);
|
||||
((MarriagePlayer) player2).addMarriage(mdata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,12 @@ import java.util.logging.Level;
|
|||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.lenis0012.bukkit.marriage2.Marriage;
|
||||
|
||||
public class MarriagePlugin extends JavaPlugin {
|
||||
private static MarriageCore core;
|
||||
|
||||
public static MarriageCore getCore() {
|
||||
public static Marriage getInstance() {
|
||||
return core;
|
||||
}
|
||||
|
||||
|
@ -59,13 +61,29 @@ public class MarriagePlugin extends JavaPlugin {
|
|||
}
|
||||
|
||||
private void executeMethods(Register.Type type) {
|
||||
for(Method method : methods[type.ordinal()]) {
|
||||
Register register = method.getAnnotation(Register.class);
|
||||
getLogger().log(Level.INFO, "Loading " + register.name() + "...");
|
||||
try {
|
||||
method.invoke(core);
|
||||
} catch (Exception e) {
|
||||
getLogger().log(Level.SEVERE, "Failed to load " + register.name(), e);
|
||||
List<Method> list = new ArrayList<Method>(methods[type.ordinal()]);
|
||||
while(!list.isEmpty()) {
|
||||
Method method = null;
|
||||
int lowestPriority = Integer.MAX_VALUE;
|
||||
for(Method m : list) {
|
||||
Register register = method.getAnnotation(Register.class);
|
||||
if(register.priority() < lowestPriority) {
|
||||
method = m;
|
||||
lowestPriority = register.priority();
|
||||
}
|
||||
}
|
||||
|
||||
if(method != null) {
|
||||
list.remove(method);
|
||||
Register register = method.getAnnotation(Register.class);
|
||||
getLogger().log(Level.INFO, "Loading " + register.name() + "...");
|
||||
try {
|
||||
method.invoke(core);
|
||||
} catch (Exception e) {
|
||||
getLogger().log(Level.SEVERE, "Failed to load " + register.name(), e);
|
||||
}
|
||||
} else {
|
||||
list.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public class MarriagePlayer implements MPlayer {
|
|||
}
|
||||
}
|
||||
|
||||
void addMarriage(MarriageData data) {
|
||||
public void addMarriage(MarriageData data) {
|
||||
this.marriage = data;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package com.lenis0012.bukkit.marriage2.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import com.lenis0012.bukkit.marriage2.internal.MarriageCore;
|
||||
|
||||
public class DatabaseListener implements Listener {
|
||||
private final MarriageCore core;
|
||||
|
||||
public DatabaseListener(MarriageCore core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerLogin(AsyncPlayerPreLoginEvent event) {
|
||||
if(event.getLoginResult() == Result.ALLOWED) {
|
||||
core.getMPlayer(event.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
core.getMPlayer(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
60
src/main/resources/plugin.yml
Normal file
60
src/main/resources/plugin.yml
Normal file
|
@ -0,0 +1,60 @@
|
|||
name: ${project.name}
|
||||
version: ${project.version}
|
||||
main: com.lenis0012.bukkit.marriage2.internal.MarriagePlugin
|
||||
author: lenis0012
|
||||
description: A plugin wich provides the function to start a relationship in minecraft.
|
||||
dev-url: http://dev.bukkit.org/bukkit-mods/marriage-reloaded/
|
||||
softdepend: [Vault]
|
||||
commands:
|
||||
marry:
|
||||
description: Marriage main command.
|
||||
usage: /marry <args>
|
||||
permissions:
|
||||
marry.*:
|
||||
description: Allows all Marriage Commands
|
||||
default: false
|
||||
children:
|
||||
marry.admin:
|
||||
description: Allows all admin commands
|
||||
default: false
|
||||
children:
|
||||
marry.reload:
|
||||
description: Allows to reload the config files
|
||||
defalt: op
|
||||
marry.priest:
|
||||
description: Allows player to marry 2 orther players.
|
||||
default: false
|
||||
marry.chatspy:
|
||||
description: Allows player to view all mchat.
|
||||
default: op
|
||||
marry.default:
|
||||
description: Allows default player commands
|
||||
default: true
|
||||
children:
|
||||
marry.marry:
|
||||
description: Allows to marry with players
|
||||
default: true
|
||||
marry.chat:
|
||||
description: Allows to chat with your partner
|
||||
default: true
|
||||
marry.tp:
|
||||
description: Allows to tp to your partner
|
||||
default: true
|
||||
marry.home:
|
||||
description: Allows to tp to your home if set
|
||||
default: true
|
||||
marry.sethome:
|
||||
description: Allwos to set your Marriage home
|
||||
default: true
|
||||
marry.gift:
|
||||
description: Allows to gift itesm to your partner
|
||||
default: true
|
||||
marry.chat:
|
||||
description: Allows to chat with your partner
|
||||
default: true
|
||||
marry.child:
|
||||
description: Allows everything with children in marriage.
|
||||
default: true
|
||||
marry.seen:
|
||||
description: Allows to see your last login from your partner
|
||||
default: true
|
Loading…
Reference in a new issue