-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a way to display hardcore hearts.
ProtocolLib needed.
- Loading branch information
1 parent
6683772
commit 28183be
Showing
10 changed files
with
297 additions
and
2 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
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
89 changes: 89 additions & 0 deletions
89
src/main/java/me/azenet/UHPlugin/integration/UHProtocolLibIntegration.java
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,89 @@ | ||
/** | ||
* Plugin UltraHardcore (UHPlugin) | ||
* Copyright (C) 2013 azenet | ||
* Copyright (C) 2014 Amaury Carrade | ||
* | ||
* 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, see [http://www.gnu.org/licenses/]. | ||
*/ | ||
|
||
package me.azenet.UHPlugin.integration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import me.azenet.UHPlugin.UHPlugin; | ||
import me.azenet.UHPlugin.listeners.UHLoginPacketsListener; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.plugin.Plugin; | ||
|
||
import com.comphenix.protocol.ProtocolLibrary; | ||
import com.comphenix.protocol.ProtocolManager; | ||
|
||
|
||
public class UHProtocolLibIntegration { | ||
|
||
private UHPlugin p = null; | ||
private ProtocolManager pm = null; | ||
|
||
public UHProtocolLibIntegration(UHPlugin p) { | ||
this.p = p; | ||
|
||
Plugin plTest = Bukkit.getServer().getPluginManager().getPlugin("ProtocolLib"); | ||
if(plTest == null || !plTest.isEnabled()) { | ||
this.p.getLogger().warning("ProtocolLib is not present, so the integration was disabled."); | ||
return; | ||
} | ||
|
||
|
||
this.pm = ProtocolLibrary.getProtocolManager(); | ||
|
||
if(isProtocolLibIntegrationEnabled() && p.getConfig().getBoolean("hardcore-hearts")) { | ||
pm.addPacketListener(new UHLoginPacketsListener(p)); | ||
} | ||
|
||
this.p.getLogger().info("Successfully hooked into ProtocolLib."); | ||
} | ||
|
||
public boolean isProtocolLibIntegrationEnabled() { | ||
return (this.pm != null); | ||
} | ||
|
||
/** | ||
* Checks if there are some enabled option which require ProtocolLib. | ||
* | ||
* @return A list of enabled options which requires ProtocolLib, or null | ||
* if there isn't any enabled option that requires ProtocolLib. | ||
*/ | ||
public List<String> isProtocolLibNeeded() { | ||
|
||
ArrayList<String> options = new ArrayList<String>(); | ||
options.add("hardcore-hearts"); | ||
|
||
ArrayList<String> enabledOptions = new ArrayList<String>(); | ||
|
||
for(String option : options) { | ||
if(p.getConfig().getBoolean(option)) { | ||
enabledOptions.add(option); | ||
} | ||
} | ||
|
||
if(enabledOptions.size() != 0) { | ||
return enabledOptions; | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
src/main/java/me/azenet/UHPlugin/integration/UHProtocolLibIntegrationWrapper.java
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,91 @@ | ||
/** | ||
* Plugin UltraHardcore (UHPlugin) | ||
* Copyright (C) 2013 azenet | ||
* Copyright (C) 2014 Amaury Carrade | ||
* | ||
* 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, see [http://www.gnu.org/licenses/]. | ||
*/ | ||
|
||
package me.azenet.UHPlugin.integration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import me.azenet.UHPlugin.UHPlugin; | ||
|
||
import org.bukkit.Bukkit; | ||
|
||
|
||
public class UHProtocolLibIntegrationWrapper { | ||
|
||
private UHPlugin p = null; | ||
private UHProtocolLibIntegration integration = null; | ||
|
||
public UHProtocolLibIntegrationWrapper(UHPlugin p) { | ||
this.p = p; | ||
|
||
// Needed to avoid a NoClassDefFoundError. | ||
// I don't like this way of doing this, but else, the plugin will not load without ProtocolLib. | ||
if(Bukkit.getServer().getPluginManager().getPlugin("ProtocolLib") != null) { | ||
integration = new UHProtocolLibIntegration(p); | ||
} | ||
else { | ||
p.getLogger().warning("ProtocolLib is not present, so the integration was disabled."); | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if ProtocolLib is installed and integrated into the plugin. | ||
* @return | ||
*/ | ||
public boolean isProtocolLibIntegrationEnabled() { | ||
return (this.integration != null); | ||
} | ||
|
||
/** | ||
* Checks if there are some enabled option which require ProtocolLib. | ||
* | ||
* @return A list of enabled options which requires ProtocolLib, or null | ||
* if there isn't any enabled option that requires ProtocolLib. | ||
*/ | ||
public List<String> isProtocolLibNeeded() { | ||
|
||
ArrayList<String> options = new ArrayList<String>(); | ||
options.add("hardcore-hearts"); | ||
|
||
ArrayList<String> enabledOptions = new ArrayList<String>(); | ||
|
||
for(String option : options) { | ||
if(p.getConfig().getBoolean(option)) { | ||
enabledOptions.add(option); | ||
} | ||
} | ||
|
||
if(enabledOptions.size() != 0) { | ||
return enabledOptions; | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the wrapped integration. | ||
* | ||
* @return | ||
*/ | ||
public UHProtocolLibIntegration getIntegration() { | ||
return integration; | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
src/main/java/me/azenet/UHPlugin/listeners/UHLoginPacketsListener.java
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,43 @@ | ||
/** | ||
* Plugin UltraHardcore (UHPlugin) | ||
* Copyright (C) 2013 azenet | ||
* Copyright (C) 2014 Amaury Carrade | ||
* | ||
* 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, see [http://www.gnu.org/licenses/]. | ||
*/ | ||
|
||
package me.azenet.UHPlugin.listeners; | ||
|
||
import me.azenet.UHPlugin.UHPlugin; | ||
|
||
import com.comphenix.protocol.PacketType; | ||
import com.comphenix.protocol.events.ListenerPriority; | ||
import com.comphenix.protocol.events.PacketAdapter; | ||
import com.comphenix.protocol.events.PacketEvent; | ||
|
||
|
||
public class UHLoginPacketsListener extends PacketAdapter { | ||
|
||
public UHLoginPacketsListener(UHPlugin p) { | ||
super(p, ListenerPriority.NORMAL, PacketType.Play.Server.LOGIN); | ||
} | ||
|
||
@Override | ||
public void onPacketSending(PacketEvent event) { | ||
// If its a login packet, write the hardcore flag (first boolean) to true. | ||
if (event.getPacketType().equals(PacketType.Play.Server.LOGIN)) { | ||
event.getPacket().getBooleans().write(0, true); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.