-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f8169c6
Showing
8 changed files
with
370 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto | ||
|
||
# Custom for Visual Studio | ||
*.cs diff=csharp | ||
*.sln merge=union | ||
*.csproj merge=union | ||
*.vbproj merge=union | ||
*.fsproj merge=union | ||
*.dbproj merge=union | ||
|
||
# Standard to msysgit | ||
*.doc diff=astextplain | ||
*.DOC diff=astextplain | ||
*.docx diff=astextplain | ||
*.DOCX diff=astextplain | ||
*.dot diff=astextplain | ||
*.DOT diff=astextplain | ||
*.pdf diff=astextplain | ||
*.PDF diff=astextplain | ||
*.rtf diff=astextplain | ||
*.RTF diff=astextplain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Build Folders # | ||
bin/ | ||
build/ | ||
target/ | ||
.externalToolBuilders/ | ||
# Eclipse Files # | ||
*.project | ||
*.classpath | ||
*.prefs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 3 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
*/ | ||
|
||
package tgchatchannels; | ||
|
||
import java.util.HashSet; | ||
import java.util.UUID; | ||
|
||
public class ChannelData { | ||
|
||
private UUID owner; | ||
private boolean privateChannel = true; | ||
private HashSet<UUID> players = new HashSet<UUID>(); | ||
|
||
protected ChannelData() { | ||
} | ||
|
||
public ChannelData(UUID owner) { | ||
this.owner = owner; | ||
} | ||
|
||
public UUID getOwner() { | ||
return owner; | ||
} | ||
|
||
public boolean isOwner(UUID uuid) { | ||
return owner != null ? owner.equals(uuid) : false; | ||
} | ||
|
||
public boolean isPrivate() { | ||
return privateChannel; | ||
} | ||
|
||
public void setPrivate() { | ||
privateChannel = true; | ||
} | ||
|
||
public void setPublic() { | ||
privateChannel = false; | ||
} | ||
|
||
public boolean isInChannel(UUID player) { | ||
return players.contains(player); | ||
} | ||
|
||
public void addPlayer(UUID player) { | ||
players.add(player); | ||
} | ||
|
||
public void removePlayer(UUID player) { | ||
players.remove(player); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 3 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
*/ | ||
|
||
package tgchatchannels; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.UUID; | ||
|
||
import org.bukkit.configuration.ConfigurationSection; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
|
||
public class ChannelsStorage { | ||
|
||
private TGChatChannels plugin; | ||
|
||
public ChannelsStorage(TGChatChannels plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
private HashMap<String, ChannelData> channels = new HashMap<String, ChannelData>(); | ||
private HashSet<String> defaultChannels = new HashSet<String>(); | ||
private HashMap<UUID, PlayerData> playersData = new HashMap<UUID, PlayerData>(); | ||
|
||
public void loadDefaultChannels() { | ||
File configfile = new File(plugin.getDataFolder(), "config.yml"); | ||
FileConfiguration config = YamlConfiguration.loadConfiguration(configfile); | ||
defaultChannels.addAll(config.getStringList("defaultchannels")); | ||
config = new YamlConfiguration(); | ||
config.set("defaultchannels", new ArrayList<String>(defaultChannels)); | ||
try { | ||
config.save(configfile); | ||
} catch (IOException e) { | ||
} | ||
} | ||
|
||
public void load() { | ||
File configfile = new File(plugin.getDataFolder(), "data.yml"); | ||
FileConfiguration config = YamlConfiguration.loadConfiguration(configfile); | ||
ConfigurationSection channels = config.getConfigurationSection("channels"); | ||
if (channels != null) { | ||
for (String channelName : channels.getKeys(false)) { | ||
ChannelData data = null; | ||
String uuidstring = channels.getString(channelName+".owner", null); | ||
if (uuidstring == null) { | ||
data = new ChannelData(); | ||
} else { | ||
data = new ChannelData(UUID.fromString(uuidstring)); | ||
} | ||
boolean privateChannel = channels.getBoolean(channelName+".private", false); | ||
if (!privateChannel) { | ||
data.setPublic(); | ||
} | ||
for (String playerUUIDString : channels.getStringList(channelName+".players")) { | ||
data.addPlayer(UUID.fromString(playerUUIDString)); | ||
} | ||
} | ||
} | ||
ConfigurationSection players = config.getConfigurationSection("players"); | ||
if (players != null) { | ||
for (String playerUUIDString : players.getKeys(false)) { | ||
UUID uuid = UUID.fromString(playerUUIDString); | ||
PlayerData data = new PlayerData(); | ||
data.setCurrentChannel(players.getString(playerUUIDString+".channel")); | ||
playersData.put(uuid, data); | ||
} | ||
} | ||
} | ||
|
||
public void save() { | ||
|
||
} | ||
|
||
public PlayerData getPlayerData(UUID playerUUID) { | ||
return playersData.get(playerUUID); | ||
} | ||
|
||
public void addToDefaultChannels(UUID uuid) { | ||
PlayerData data = new PlayerData(); | ||
if (!defaultChannels.isEmpty()) { | ||
data.setCurrentChannel(defaultChannels.iterator().next()); | ||
} | ||
playersData.put(uuid, data); | ||
for (String channelName : defaultChannels) { | ||
if (channels.containsKey(channelName)) { | ||
channels.get(channelName).addPlayer(uuid); | ||
} | ||
} | ||
} | ||
|
||
public boolean channelExists(String channelName) { | ||
return channels.containsKey(channelName); | ||
} | ||
|
||
public ChannelData getChannelData(String channelName) { | ||
return channels.get(channelName); | ||
} | ||
|
||
public void addChannel(UUID owner, String channelName) { | ||
channels.put(channelName, new ChannelData(owner)); | ||
} | ||
|
||
public void removeChannel(String channelName) { | ||
channels.remove(channelName); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 3 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
*/ | ||
|
||
package tgchatchannels; | ||
|
||
import java.util.Iterator; | ||
import java.util.UUID; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.AsyncPlayerChatEvent; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
|
||
public class ChatListener implements Listener { | ||
|
||
private ChannelsStorage storage; | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
public void onAsyncChat(AsyncPlayerChatEvent event) { | ||
UUID playerUUID = event.getPlayer().getUniqueId(); | ||
PlayerData data = storage.getPlayerData(playerUUID); | ||
if (data.getCurrentChannel() == null) { | ||
event.setCancelled(true); | ||
event.getPlayer().sendMessage(ChatColor.RED + "Вы не можете говорить в несуществующий канал"); | ||
return; | ||
} | ||
String channelName = data.getCurrentChannel(); | ||
if (!storage.channelExists(channelName)) { | ||
event.setCancelled(true); | ||
event.getPlayer().sendMessage(ChatColor.RED + "Вы не можете говорить в несуществующий канал"); | ||
return; | ||
} | ||
event.setFormat("["+channelName+"] "+event.getFormat()); | ||
ChannelData currentChannel = storage.getChannelData(channelName); | ||
Iterator<Player> recipientsIt = event.getRecipients().iterator(); | ||
while (recipientsIt.hasNext()) { | ||
UUID uuid = recipientsIt.next().getUniqueId(); | ||
if (!currentChannel.isInChannel(uuid)) { | ||
recipientsIt.remove(); | ||
} | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onJoin(PlayerJoinEvent event) { | ||
if (!event.getPlayer().hasPlayedBefore()) { | ||
storage.addToDefaultChannels(event.getPlayer().getUniqueId()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 3 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
*/ | ||
|
||
package tgchatchannels; | ||
|
||
public class Commands { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 3 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
*/ | ||
|
||
package tgchatchannels; | ||
|
||
public class PlayerData { | ||
|
||
private String currentChannel; | ||
|
||
public String getCurrentChannel() { | ||
return currentChannel; | ||
} | ||
|
||
public void setCurrentChannel(String channelName) { | ||
this.currentChannel = channelName; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 3 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
*/ | ||
|
||
package tgchatchannels; | ||
|
||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
public class TGChatChannels extends JavaPlugin { | ||
|
||
} |