Skip to content
This repository has been archived by the owner on Nov 10, 2021. It is now read-only.

Commit

Permalink
Merge branch 'feature/commands' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
0ddlyoko committed May 5, 2019
2 parents f3cdc75 + 53bb694 commit 037f07f
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 33 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.froxynetwork</groupId>
<artifactId>FroxyCore</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
<packaging>jar</packaging>

<name>FroxyCore</name>
Expand Down Expand Up @@ -75,12 +75,12 @@
<artifactId>froxygame</artifactId>
<version>0.0.1</version>
</dependency>

<!-- API -->
<dependency>
<groupId>com.github.froxynetwork</groupId>
<artifactId>froxyapi</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
</dependency>

<!--Spigot API -->
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/froxynetwork/froxycore/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.froxynetwork.froxycore;

/**
* MIT License
*
* Copyright (c) 2019 FroxyNetwork
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @author 0ddlyoko
*/
public final class Constants {
public static final String VERSION = "0.0.2";

private Constants() {
}
}
37 changes: 18 additions & 19 deletions src/main/java/com/froxynetwork/froxycore/FroxyCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import java.io.File;

import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.froxynetwork.froxyapi.Froxy;
import com.froxynetwork.froxyapi.language.LanguageManager;
import com.froxynetwork.froxycore.api.APIImpl;
import com.froxynetwork.froxycore.api.command.CommandManagerImpl;
import com.froxynetwork.froxycore.api.language.LanguageManagerImpl;

/**
Expand Down Expand Up @@ -34,30 +38,25 @@
*
* @author 0ddlyoko
*/
public class FroxyCore {
public class FroxyCore extends JavaPlugin {

private Logger log = LoggerFactory.getLogger(getClass());

/**
* TEST
*/
public FroxyCore() {
// String clientId = "WEBSOCKET_045cfff18fe0ab8393178e7b7826f227";
// String clientSecret = "SECRET_ecfdc21a8d5022e2db64b1315b087aaf";
// NetworkManager nm = new NetworkManager("http://localhost/", clientId, clientSecret);

APIImpl impl = new APIImpl(null, null, "0.0.3", log, new LanguageManagerImpl());
@Override
public void onEnable() {
log.info("Starting FroxyCore, please wait");
// String clientId = "WEBSOCKET_045cfff18fe0ab8393178e7b7826f227";
// String clientSecret = "SECRET_ecfdc21a8d5022e2db64b1315b087aaf";
// NetworkManager nm = new NetworkManager("http://localhost/", clientId,
// clientSecret);

LanguageManager languageManager = new LanguageManagerImpl();
CommandManagerImpl commandManager = new CommandManagerImpl();
Bukkit.getPluginManager().registerEvents(commandManager, this);
APIImpl impl = new APIImpl(null, null, Constants.VERSION, log, languageManager, commandManager);
Froxy.setAPI(impl);
File lang = new File(getClass().getClassLoader().getResource("lang").getFile());
Froxy.register(lang);
// Show "0.0.3"
System.out.println(Froxy.getVersion());
// Show "english"
System.out.println(Froxy.$("test.test"));
// TODO
}

public static void main(String[] args) {
new FroxyCore();
log.info("FroxyCore started !");
}
}
39 changes: 34 additions & 5 deletions src/main/java/com/froxynetwork/froxycore/api/APIImpl.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
/**
* Copyright (c) Smals
*/
package com.froxynetwork.froxycore.api;

import org.bukkit.plugin.java.JavaPlugin;
import org.slf4j.Logger;

import com.froxynetwork.froxyapi.API;
import com.froxynetwork.froxyapi.command.CommandManager;
import com.froxynetwork.froxyapi.language.LanguageManager;

/**
* @author Nathan Giacomello (nagi)
* MIT License
*
* Copyright (c) 2019 FroxyNetwork
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @author 0ddlyoko
*/

public class APIImpl implements API {

private JavaPlugin corePlugin;
Expand All @@ -25,12 +45,16 @@ public class APIImpl implements API {

private LanguageManager languageManager;

public APIImpl(JavaPlugin corePlugin, JavaPlugin gamePlugin, String version, Logger logger, LanguageManager languageManager) {
private CommandManager commandManager;

public APIImpl(JavaPlugin corePlugin, JavaPlugin gamePlugin, String version, Logger logger,
LanguageManager languageManager, CommandManager commandManager) {
this.corePlugin = corePlugin;
this.gamePlugin = gamePlugin;
this.version = version;
this.logger = logger;
this.languageManager = languageManager;
this.commandManager = commandManager;
}

@Override
Expand All @@ -57,4 +81,9 @@ public Logger getLogger() {
public LanguageManager getLanguageManager() {
return languageManager;
}

@Override
public CommandManager getCommandManager() {
return commandManager;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.froxynetwork.froxycore.api.command;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;

import com.froxynetwork.froxyapi.command.Command;
import com.froxynetwork.froxyapi.command.CommandManager;

/**
* MIT License
*
* Copyright (c) 2019 FroxyNetwork
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @author 0ddlyoko
*/
public class CommandManagerImpl implements CommandManager, Listener {
private List<Command> commands;

public CommandManagerImpl() {
commands = new ArrayList<>();
}

@Override
public void registerCommand(Command cmd) {
commands.add(cmd);
}

@Override
public void unregisterCommand(Command cmd) {
commands.remove(cmd);
}

@Override
public List<Command> getCommands() {
return commands;
}

private Command getCommand(String label) {
for (Command cmd : commands) {
if (label.equalsIgnoreCase(cmd.getCommand()))
return cmd;
if (cmd.getAliases() != null)
for (String alias : cmd.getAliases())
if (label.equalsIgnoreCase(alias))
return cmd;
}
return null;
}

@EventHandler
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
Player p = e.getPlayer();
String msg = e.getMessage();
if (p == null || msg == null)
return;
if (msg.startsWith("/")) {
String[] split = msg.split(" ");
String label = split[0].substring(1);
String[] args = new String[split.length - 1];
if (split.length >= 2)
for (int i = 1; i < split.length; i++)
args[i - 1] = split[i];
if (_onPlayerCommand(p, label, args))
e.setCancelled(true);
}
}

private boolean _onPlayerCommand(Player p, String label, String[] args) {
Command cmd = getCommand(label);
if (cmd == null)
return false;
String perm = cmd.getPermission();
if (perm != null && !p.hasPermission(perm)) {
cmd.noPermission(p);
return true;
}
return cmd.execute(label, p, args);
}
}
5 changes: 2 additions & 3 deletions src/main/resources/lang/en_US.lang
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
test.test : english
test.test3 : englishy
test.test4 : Test {}, Hi {}
command.nopermission : §cYou don't have permission to execute this command
command.syntaxerror : §cSyntax: {}
5 changes: 2 additions & 3 deletions src/main/resources/lang/fr_FR.lang
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
test.test : french
test.test2 : frenchy
test.test4 : Test {}, Salut {}
command.nopermission : §cVous n'avez pas la permission d'executer cette commande
command.syntaxerror : §cSyntaxe: {}

0 comments on commit 037f07f

Please sign in to comment.