mirror of
https://github.com/TotalFreedomMC/TF-Marriage.git
synced 2024-06-02 10:01:24 +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 -->
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>src/main/java/</directory>
|
<directory>src/main/resources/</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
<includes>
|
<includes>
|
||||||
<include>**</include>
|
<include>*</include>
|
||||||
</includes>
|
</includes>
|
||||||
<!-- Don't add source files to target jar -->
|
|
||||||
<excludes>
|
|
||||||
<exclude>me/lenis0012/**/*.java</exclude>
|
|
||||||
</excludes>
|
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<defaultGoal>clean install</defaultGoal>
|
<defaultGoal>clean install</defaultGoal>
|
||||||
|
|
|
@ -4,9 +4,9 @@ import java.util.UUID;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.lenis0012.bukkit.marriage2.commands.Command;
|
import com.lenis0012.bukkit.marriage2.commands.Command;
|
||||||
import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
|
|
||||||
import com.lenis0012.bukkit.marriage2.misc.BConfig;
|
import com.lenis0012.bukkit.marriage2.misc.BConfig;
|
||||||
|
|
||||||
public interface Marriage {
|
public interface Marriage {
|
||||||
|
@ -60,5 +60,5 @@ public interface Marriage {
|
||||||
*
|
*
|
||||||
* @return Plugin instance.
|
* @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 org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
import com.lenis0012.bukkit.marriage2.internal.MarriagePlugin;
|
import com.lenis0012.bukkit.marriage2.internal.MarriageCore;
|
||||||
|
|
||||||
public class Settings<T> {
|
public class Settings<T> {
|
||||||
private static final List<Settings<?>> cache = Lists.newArrayList();
|
private static final List<Settings<?>> cache = Lists.newArrayList();
|
||||||
|
@ -43,14 +43,13 @@ public class Settings<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void reloadAll() {
|
public static final void reloadAll(MarriageCore core) {
|
||||||
MarriagePlugin plugin = MarriagePlugin.getCore().getPlugin();
|
FileConfiguration config = core.getPlugin().getConfig();
|
||||||
FileConfiguration config = plugin.getConfig();
|
|
||||||
for(Settings<?> setting : cache) {
|
for(Settings<?> setting : cache) {
|
||||||
setting.reload(config);
|
setting.reload(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.saveConfig();
|
core.getPlugin().saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final List<Settings<?>> values() {
|
public static final List<Settings<?>> values() {
|
||||||
|
|
|
@ -1,26 +1,42 @@
|
||||||
package com.lenis0012.bukkit.marriage2.internal;
|
package com.lenis0012.bukkit.marriage2.internal;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.lenis0012.bukkit.marriage2.MPlayer;
|
import com.lenis0012.bukkit.marriage2.MPlayer;
|
||||||
import com.lenis0012.bukkit.marriage2.commands.CommandMarry;
|
import com.lenis0012.bukkit.marriage2.commands.CommandMarry;
|
||||||
import com.lenis0012.bukkit.marriage2.config.Message;
|
import com.lenis0012.bukkit.marriage2.config.Message;
|
||||||
import com.lenis0012.bukkit.marriage2.config.Settings;
|
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 {
|
public class MarriageCore extends MarriageBase {
|
||||||
|
private final Map<UUID, MarriagePlayer> players = Collections.synchronizedMap(new HashMap<UUID, MarriagePlayer>());
|
||||||
|
private DataManager dataManager;
|
||||||
|
|
||||||
public MarriageCore(MarriagePlugin plugin) {
|
public MarriageCore(MarriagePlugin plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(name = "config", type = Register.Type.ENABLE, priority = 0)
|
@Register(name = "config", type = Register.Type.ENABLE, priority = 0)
|
||||||
public void loadConfig() {
|
public void loadConfig() {
|
||||||
Settings.reloadAll();
|
plugin.saveDefaultConfig();
|
||||||
|
Settings.reloadAll(this);
|
||||||
|
Message.reloadAll(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(name = "messages", type = Register.Type.ENABLE, priority = 1)
|
@Register(name = "database", type = Register.Type.ENABLE)
|
||||||
public void loadMessages() {
|
public void loadDatabase() {
|
||||||
Message.reloadAll(this);
|
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)
|
@Register(name = "commands", type = Register.Type.ENABLE)
|
||||||
|
@ -28,15 +44,21 @@ public class MarriageCore extends MarriageBase {
|
||||||
register(CommandMarry.class);
|
register(CommandMarry.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MPlayer getMPlayer(UUID uuid) {
|
public MPlayer getMPlayer(UUID uuid) {
|
||||||
// TODO: Everything...
|
MarriagePlayer player = players.get(uuid);
|
||||||
return null;
|
if(player == null) {
|
||||||
|
player = dataManager.loadPlayer(uuid);
|
||||||
|
players.put(uuid, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void marry(MPlayer player1, MPlayer player2) {
|
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 org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import com.lenis0012.bukkit.marriage2.Marriage;
|
||||||
|
|
||||||
public class MarriagePlugin extends JavaPlugin {
|
public class MarriagePlugin extends JavaPlugin {
|
||||||
private static MarriageCore core;
|
private static MarriageCore core;
|
||||||
|
|
||||||
public static MarriageCore getCore() {
|
public static Marriage getInstance() {
|
||||||
return core;
|
return core;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,13 +61,29 @@ public class MarriagePlugin extends JavaPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeMethods(Register.Type type) {
|
private void executeMethods(Register.Type type) {
|
||||||
for(Method method : methods[type.ordinal()]) {
|
List<Method> list = new ArrayList<Method>(methods[type.ordinal()]);
|
||||||
Register register = method.getAnnotation(Register.class);
|
while(!list.isEmpty()) {
|
||||||
getLogger().log(Level.INFO, "Loading " + register.name() + "...");
|
Method method = null;
|
||||||
try {
|
int lowestPriority = Integer.MAX_VALUE;
|
||||||
method.invoke(core);
|
for(Method m : list) {
|
||||||
} catch (Exception e) {
|
Register register = method.getAnnotation(Register.class);
|
||||||
getLogger().log(Level.SEVERE, "Failed to load " + register.name(), e);
|
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;
|
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