Skip to content
This repository has been archived by the owner on Feb 9, 2020. It is now read-only.

Add chat and plugin related stuff #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/pocketnode/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const ConsoleCommandReader = pocketnode("command/ConsoleCommandReader");
const HelpCommand = pocketnode("command/defaults/HelpCommand");
const StopCommand = pocketnode("command/defaults/StopCommand");
const PluginsCommand = pocketnode("command/defaults/PluginsCommand");
const SayCommand = pocketnode("command/defaults/SayCommand");

const EventHandler = pocketnode("event/EventHandler");
const TestEvent = pocketnode("event/TestEvent");

const Player = pocketnode("player/Player");
const PlayerList = pocketnode("player/PlayerList");
Expand Down Expand Up @@ -66,6 +70,7 @@ class Server {
this._players = new PlayerList();
this._loggedInPlayers = new PlayerList();
this._playerList = new PlayerList();
this._eventSystem = new EventHandler(this);

this._levels = new Map();

Expand Down Expand Up @@ -144,7 +149,6 @@ class Server {
}

start(){

//block banned ips

this._tickCounter = 0;
Expand All @@ -159,6 +163,7 @@ class Server {
this.getCommandMap().registerCommand(new HelpCommand());
this.getCommandMap().registerCommand(new StopCommand());
this.getCommandMap().registerCommand(new PluginsCommand());
this.getCommandMap().registerCommand(new SayCommand());
}

/**
Expand Down Expand Up @@ -353,6 +358,7 @@ class Server {
}

broadcastMessage(message, recipients = this.getOnlinePlayers()){
this.getLogger().info(message);
recipients.forEach(recipient => recipient.sendMessage(message));

return recipients.length;
Expand Down Expand Up @@ -607,6 +613,10 @@ class Server {
onPlayerCompleteLoginSequence(player){

}

getEventSystem(){
return this._eventSystem;
}
}

module.exports = Server;
module.exports = Server;
18 changes: 18 additions & 0 deletions src/pocketnode/command/defaults/SayCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const Command = pocketnode("command/Command");
const TextFormat = pocketnode("utils/TextFormat");

class SayCommand extends Command {
constructor(){
super("say", "Send a message to the server.", "pocketnode.command.say", []);
}

execute(sender, args){
let message = "";
args.forEach(elem => {
message += elem + " ";
});
sender.getServer().broadcastMessage("§b[SERVER] " + message);
}
}

module.exports = SayCommand;
51 changes: 51 additions & 0 deletions src/pocketnode/event/Event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* _____ _ _ _ _ _
* | __ \ | | | | | \ | | | |
* | |__) |__ ___| | _____| |_| \| | ___ __| | ___
* | ___/ _ \ / __| |/ / _ \ __| . ` |/ _ \ / _` |/ _ \
* | | | (_) | (__| < __/ |_| |\ | (_) | (_| | __/
* |_| \___/ \___|_|\_\___|\__|_| \_|\___/ \__,_|\___|
*
* @author PocketNode Team
* @link https://pocketnode.me
*/
class Event {

constructor(){
this.eventName = null;
this.isCancelled = false;
}

/**
* @return string
*/
getEventName(){
return this.eventName ? null : this.constructor.name;
}

/**
* @return bool
*
* @throws Error
*/
isCancelled(){
//if(!(this instanceof Cancellable)){
// throw new Error("Event is not Cancellable");
//}
return this.isCancelled === true;
}

/**
* @param bool value
*
* @throws Error
*/
setCancelled(value = true){
//if(!(this instanceof Cancellable)){
// throw new Error("Event is not Cancellable");
//}
this.isCancelled = value;
}

}
module.exports = Event;
37 changes: 37 additions & 0 deletions src/pocketnode/event/EventHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* _____ _ _ _ _ _
* | __ \ | | | | | \ | | | |
* | |__) |__ ___| | _____| |_| \| | ___ __| | ___
* | ___/ _ \ / __| |/ / _ \ __| . ` |/ _ \ / _` |/ _ \
* | | | (_) | (__| < __/ |_| |\ | (_) | (_| | __/
* |_| \___/ \___|_|\_\___|\__|_| \_|\___/ \__,_|\___|
*
* @author PocketNode Team
* @link https://pocketnode.me
*/
const EventEmitter = require('events').EventEmitter;
const Event = pocketnode("event/Event");

class EventHandler extends EventEmitter {

constructor(server){
super();
this.server = server;
this.emitter = new EventEmitter();
}

callEvent(ev){
if(typeof ev !== "string" && typeof ev !== "number" && typeof ev !== "boolean" && typeof ev.isEvent !== null){
this.emitter.emit(ev.getEventName(), ev);
} else {
this.server.getLogger().error("Calling event '" + ev.toString() + "' with non Event object");
}
}

getEmitter(){
return this.emitter;
}

}

module.exports = EventHandler;
21 changes: 21 additions & 0 deletions src/pocketnode/event/TestEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* _____ _ _ _ _ _
* | __ \ | | | | | \ | | | |
* | |__) |__ ___| | _____| |_| \| | ___ __| | ___
* | ___/ _ \ / __| |/ / _ \ __| . ` |/ _ \ / _` |/ _ \
* | | | (_) | (__| < __/ |_| |\ | (_) | (_| | __/
* |_| \___/ \___|_|\_\___|\__|_| \_|\___/ \__,_|\___|
*
* @author PocketNode Team
* @link https://pocketnode.me
*/
const Event = pocketnode("event/Event");

class TestEvent extends Event{

constructor(){
super();
}

}
module.exports = TestEvent;
26 changes: 26 additions & 0 deletions src/pocketnode/event/player/PlayerEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* _____ _ _ _ _ _
* | __ \ | | | | | \ | | | |
* | |__) |__ ___| | _____| |_| \| | ___ __| | ___
* | ___/ _ \ / __| |/ / _ \ __| . ` |/ _ \ / _` |/ _ \
* | | | (_) | (__| < __/ |_| |\ | (_) | (_| | __/
* |_| \___/ \___|_|\_\___|\__|_| \_|\___/ \__,_|\___|
*
* @author PocketNode Team
* @link https://pocketnode.me
*/
const Event = pocketnode("event/Event");

class PlayerEvent extends Event {

constructor(){
super();
this.player;
}

getPlayer(){
return this.player;
}

}
module.exports = PlayerEvent;
45 changes: 45 additions & 0 deletions src/pocketnode/event/player/PlayerJoinEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* _____ _ _ _ _ _
* | __ \ | | | | | \ | | | |
* | |__) |__ ___| | _____| |_| \| | ___ __| | ___
* | ___/ _ \ / __| |/ / _ \ __| . ` |/ _ \ / _` |/ _ \
* | | | (_) | (__| < __/ |_| |\ | (_) | (_| | __/
* |_| \___/ \___|_|\_\___|\__|_| \_|\___/ \__,_|\___|
*
* @author PocketNode Team
* @link https://pocketnode.me
*/
const PlayerEvent = pocketnode("event/player/PlayerEvent");

class PlayerJoinEvent extends PlayerEvent {


/**
* PlayerJoinEvent constructor.
*
* @param Player player
* @param TextContainer|string joinMessage
*/
constructor(player, joinMessage){
super();
this.player = player;
/** @var string|TextContainer */
this.joinMessage = joinMessage;
}

/**
* @param string|TextContainer joinMessage
*/
setJoinMessage(joinMessage){
this.joinMessage = joinMessage;
}

/**
* @return string|TextContainer
*/
getJoinMessage(){
return this.joinMessage;
}

}
module.exports = PlayerJoinEvent;
51 changes: 51 additions & 0 deletions src/pocketnode/event/player/PlayerQuitEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* _____ _ _ _ _ _
* | __ \ | | | | | \ | | | |
* | |__) |__ ___| | _____| |_| \| | ___ __| | ___
* | ___/ _ \ / __| |/ / _ \ __| . ` |/ _ \ / _` |/ _ \
* | | | (_) | (__| < __/ |_| |\ | (_) | (_| | __/
* |_| \___/ \___|_|\_\___|\__|_| \_|\___/ \__,_|\___|
*
* @author PocketNode Team
* @link https://pocketnode.me
*/
const PlayerEvent = pocketnode("event/player/PlayerEvent");

class PlayerQuitEvent extends PlayerEvent{


/**
* @param Player player
* @param TranslationContainer|string quitMessage
* @param string quitReason
*/
constructor(player, quitMessage, quitReason){
super();
this.player = player;
this.quitMessage = quitMessage;
this.quitReason = quitReason;
}

/**
* @param TranslationContainer|string quitMessage
*/
setQuitMessage(quitMessage){
this.quitMessage = quitMessage;
}

/**
* @return TranslationContainer|string
*/
getQuitMessage(){
return this.quitMessage;
}

/**
* @return string
*/
getQuitReason(){
return this.quitReason;
}

}
module.exports = PlayerQuitEvent;
2 changes: 1 addition & 1 deletion src/pocketnode/level/Position.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ class Position extends Vector3 {

}

module.exports = Position;
module.exports = Position;
2 changes: 1 addition & 1 deletion src/pocketnode/logger/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ class Logger {
}
}

module.exports = Logger;
module.exports = Logger;
2 changes: 1 addition & 1 deletion src/pocketnode/network/RakNetAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ class RakNetAdapter {
}
}

module.exports = RakNetAdapter;
module.exports = RakNetAdapter;
2 changes: 1 addition & 1 deletion src/pocketnode/network/minecraft/protocol/DataPacket.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,4 @@ class DataPacket extends BinaryStream {
}
}

module.exports = DataPacket;
module.exports = DataPacket;
Loading